akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,k,a[N],f[N],b[N],F,le,ri,l,r;
int main(){
	cin>>n;
	for(k=1;k<=n;k++){
		cin>>a[k];
		f[a[k]]++;
	}
	for(k=1;k<=n;k++){
		cin>>b[k];
		f[b[k]]++;
		if(f[b[k]]>n){
		F=1;
		} 
	}
	if(F) cout<<"No"<<endl;
	else
	{
		reverse(b+1,b+n+1);
		for(k=1;k<=n;k++){
			if(a[k]==b[k])F=a[k];
		}
	    
		if(F){ l=n;
			for(k=1;k<=n;k++){
				if(a[k]==F) l=min(l,k);
				if(b[k]==F) l=min(l,k);
			}le=1; ri=n;
			for(k=1;k<=n;k++){
				if(b[k]==F && a[k]==F){
					if(le<l){
					swap(b[k],b[le]);le++;
					}
					else {
						swap(b[k],b[ri]); 
						ri--;
					}
				}
			}
		}
		cout<<"Yes"<<endl;
		for(k=1;k<=n;k++){
			cout<<b[k]<<" ";
		}
	}
}

Measured memory_bytes: 5936
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		int x = (a + b)*c/2;
		System.out.println(x);
	}
}

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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> v(n, vector<int>(3, 0));
  vector<vector<int>> dp(n+1, vector<int>(3, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> v[i][j]; // day, activity
    }
  }

  for (int day = 1; day <= n; day++) {
    for (int i = 0; i < 3; i++) { // take activity
      for (int j = 0; j < 3; j++) {
        if (j != i)
          dp[day][i] = max(dp[day][i], dp[day-1][j] + v[day-1][i]);
      }
    }
  }

  int _max = 0;
  for (int i = 0; i < 3; i++)
    _max = max(dp[n][i], _max);

  cout << _max << endl;
  
  return 0;
}

Measured memory_bytes: 11136
import math
a, b, x = map(float, input().split())
vol = a * a * b
if x <= vol/2:
    height = (x * 2.0) / (b * a)
    ans = math.atan(b / height) * 180 / math.pi
else:
    height = ((vol - x) * 2.0) / (a * a)
    ans = math.atan(height / a) * 180 / math.pi
print(ans)

Measured memory_bytes: 9316
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
inline char tc(){
  static char fl[100],*A=fl,*B=fl;
  return A==B&&(B=(A=fl)+fread(fl,1,100,stdin),A==B)?EOF:*A++;  
}
inline int read(){
  int a=0;static char c;
  while((c=tc())<48||c>57);
  while(c>=48&&c<=57)a=a*10+c-48,c=tc();
  return a;
}
int a[2000001];
int main(){
  int n=read(),i;
  rep(i,n)a[i]=read();
  for(i=n-1;i>=0;i-=2)printf("%d ",a[i]);
  for(i=n%2;i<=n-1;i+=2)printf("%d ",a[i]);
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
#define forn(i,p,n) for(int i=(int)p;i<(int)n;++i)

int main() {
    fast;
    ll n, k;
    cin >> n >> k;
    vector<ll> arr;
    forn(i,0,n){
    	int ele;
    	cin >> ele;
    	arr.push_back(ele);
    }
    sort(arr.begin(),arr.end());
    ll sum = 0;
    forn(i,0,k){
    	sum+=arr[i];
    }
    cout<<sum;
        
}	

Measured memory_bytes: 3648
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  int r, g;
  scan(r, g);
  print(g * 2 - r);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();//パスタを食べる期間
		int K = sc.nextInt();//決まってる日数
		int x[][] = new int[6][N];
		int m[] = new int[N];
		int sum = 0;
		int i,y;
		int z = 10000;//割る数
		
		for(i = 0; i < K; i++){
			y = sc.nextInt();//決まってる日
			m[y-1] = sc.nextInt();//メニュー
		}
		if(m[0] == 0){
			x[1][0] = 1;
			x[3][0] = 1;
			x[5][0] = 1;
		}
		else if(m[0] == 1){
			x[1][0] = 1;
		}
		else if(m[0] == 2){
			x[3][0] = 1;
		}
		else if(m[0] == 3){
			x[5][0] = 1;
		}
		for(i = 1; i < N; i++){
			if(m[i] == 1){
				x[0][i] = x[1][i-1];
				x[1][i] = (x[2][i-1] + x[3][i-1] + x[4][i-1] + x[5][i-1])%z;
			}
			else if(m[i] == 2){
				x[2][i] = x[3][i-1];
				x[3][i] = (x[0][i-1] + x[1][i-1] + x[4][i-1] + x[5][i-1])%z;
			}
			else if(m[i] == 3){
				x[4][i] = x[5][i-1];
				x[5][i] = (x[0][i-1] + x[1][i-1] + x[2][i-1] + x[3][i-1])%z;
			}
			else{
				x[0][i] = x[1][i-1];
				x[1][i] = (x[2][i-1] + x[3][i-1] + x[4][i-1] + x[5][i-1])%z;
				x[2][i] = x[3][i-1];
				x[3][i] = (x[0][i-1] + x[1][i-1] + x[4][i-1] + x[5][i-1])%z;
				x[4][i] = x[5][i-1];
				x[5][i] = (x[0][i-1] + x[1][i-1] + x[2][i-1] + x[3][i-1])%z;
			}
		}
		sum = x[0][N-1] + x[1][N-1] + x[2][N-1] + x[3][N-1] + x[4][N-1] + x[5][N-1];
		System.out.println(sum%10000);
	}

}

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

bool f() {
  string s; cin >> s;
  string a = "keyence";
  int l = s.size();
  if (l < 7) return false;
  for (int i = 0; ; i++) {
    if (s.substr(0, i) != a.substr(0, i)) return false;
    int j = 7-i;
    if (s.substr(l-j, j) == a.substr(7-j, j)) return true;
  }
}

int main() {
  if (f()) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

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

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/aryan/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a,b,c;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n;
    b.resize(n,0);
    c.resize(n,0);
    fo(i,n)
        cin>>b[i];
    fo(i,n)
        cin>>c[i];
    
    fo(i,n)
        a.pb(i+1);
    i=0,j=0;
    do{
        if(a==b)
            j-=i;
        if(a==c)
            j+=i;
        i++;
    }while(next_permutation(all(a)));
    cout<<abs(j)<<endl;
}   aryanc403();
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include<cstdio>
#include <vector>
#include<queue>
#include<limits.h>
#include<string.h>
#include<functional>
using namespace std;

signed main() {
	int a, b; 
	while (cin >> a >> b, a | b) {
		while (a--) {
			for (int c = 0; c < b; c++) {
				cout << '#';
			}
			puts("");
		}
		puts("");
	}
}

Measured memory_bytes: 3016
import java.io.*;

public class Main {
    public static void main(String[] args) {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        try {
            String[] str = br.readLine().split(" ");
            int W = Integer.parseInt(str[0]);
            int H = Integer.parseInt(str[1]);
            int x = Integer.parseInt(str[2]);
            int y = Integer.parseInt(str[3]);
            int r = Integer.parseInt(str[4]);
            if(x >= r && y >= r && (H - r) >= y && (W - r) >= x) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 17072
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    a = kwargs["a"]
    b = kwargs["b"]
    c = kwargs["c"]
    k = kwargs["k"]

    if k <= a:
        res = k
    elif k <= a + b:
        res = a
    else:
        res = 2 * a - k + b

    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["a"], kwargs["b"], kwargs["c"], kwargs["k"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 31172
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();

            System.out.println((A * B) % 2 == 0 ? "No" : "Yes");
        }
    }
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

int main() {
  i64 N;
  cin >> N;
  dynarr<i64> P(N + 1);
  rep(i,1,N + 1) cin >> P[i];
  dynarr<pair<i64, i64>> vec;
  rep(i,1,N + 1) vec.push_back({P[i], i});
  sort(all(vec));
  reverse(all(vec));
  i64 ans = 0;
  
  set<i64> st;
  st.insert(vec[0].second);
  st.insert(0);
  st.insert(-1);
  st.insert(N + 1);
  st.insert(N + 2);
  vec.erase(vec.begin());
  for(auto p: vec) {
    i64 i = p.second;
    i64 a = p.first;
    auto iter = st.lower_bound(i);
    auto iter2 = iter;
    auto Ri = *iter;
    auto R2i = *(++iter);
    auto Li = *(--iter2);
    auto L2i = *(--iter2);
    if(R2i == N + 2) R2i = N + 1;
    if(L2i == -1) L2i = 0;
    //cout << a << " " << L2i << " " << Li << " " << Ri << " " << R2i << endl;
    i64 L = Li - L2i;
    i64 l = (i - 1) - Li;
    i64 R = (R2i - 1) - (Ri - 1);
    i64 r = (R2i - 1) - R - i;
    //cout << L << " " << l << " " << r << " " << R << endl;
    //cout << " + " << a * (L * (r + 1) + (l + 1) * R + L * R) << endl;
    ans += a * (L * (r + 1) + (l + 1) * R);
    st.insert(i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 7280
'use strict'
function main(inp) {
  inp = inp.trim().split('\n')
  const N = Number(inp[0])
  const S = inp[1]
  const alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
  let ans = ''
  for (let i = 0; i < S.length; i++) {
    ans += alp[alp.indexOf(S[i]) + (N%26)]
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 22844
#include<stdio.h>
 
int main(){
    int i,ch,a[50],w,n,p,q,tmp;
    for(i=1;i<50;i++) a[i]=i;
    scanf("%d",&w);
    while((ch=getchar())!='\n');
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d,%d",&p,&q);
        tmp=a[q];
        a[q]=a[p];
        a[p]=tmp;
    }
    for(i=1;i<=w;i++) printf("%d\n",a[i]); 
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
using namespace std;
int a=1;
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		if(a+k>a*2)a*=2;
		else a+=k;
	}
	cout<<a;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define Maxn 2010
#define Maxm 10010

char a[Maxn], b[Maxn], c[Maxn];
bool Cmp_ab[Maxm], Cmp_ac[Maxm], Cmp_bc[Maxm];

inline bool Compare(char x, char y) { return ((x == y) || (x == '?') || (y == '?')); }

int main()
{
	scanf("%s", a); int l_a = strlen(a);
	scanf("%s", b); int l_b = strlen(b);
	scanf("%s", c); int l_c = strlen(c);
	
	for (int i=0; i<l_a; i++) for (int j=0; j<l_b; j++) if (!Compare(a[i], b[j])) Cmp_ab[i - j + 4000] = 1;
	for (int i=0; i<l_a; i++) for (int j=0; j<l_c; j++) if (!Compare(a[i], c[j])) Cmp_ac[i - j + 4000] = 1;
	for (int i=0; i<l_b; i++) for (int j=0; j<l_c; j++) if (!Compare(b[i], c[j])) Cmp_bc[i - j + 4000] = 1;
	
	int Res = INF;
	for (int i=-4000; i<=4000; i++)
		for (int j=-4000; j<=4000; j++)
			if ((!Cmp_ab[i + 4000]) && (!Cmp_ac[j + 4000]) && (!Cmp_bc[j - i + 4000]))
				Res = min(Res, max(l_a, max(l_c + j, l_b + i)) - min(0, min(i, j)));
				
	printf("%d\n", Res);
}

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

static const int MOD=1e9+7;

int main(){
    int N,M; cin >> N >> M;
    vector<bool> used(N,false);
    for(int i=0;i<M;i++){
        int a; cin >> a;
        used[a]=true;
    }
    long long dp[N+1]={};
    dp[0]=1;
    for(int i=0;i<N;i++){
        if(!used[i+1]){
            dp[i+1]=dp[i]%MOD;
            used[i+1]=true;
        }
        if(!used[i+2]){
            dp[i+2]=(dp[i]+dp[i+1])%MOD;
            used[i+2]=true;
        }
        //cout << dp[i] << endl;
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
using namespace std;
int main() {
	vector<int> ant;
	for (int i = 0; i < 6; i++) {
		int x; cin >> x;
		ant.push_back(x);
	}
	int num = 0;
	for (int j = 0; j < 4; j++) {
		for (int k = j+1; k < 5; k++) {
			if (ant[k] - ant[j] > ant[5]) {
				num = num + 1;
			}
		}
	}
	if (num == 0) {
		cout << "Yay!";
	}
	else {
		cout << ":(";
	}
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep_1(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define rep_2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main()
{
  int x,y,z;cin >> x >> y>>z;
  cout <<z <<" " <<x <<" " <<y<<endl;
  return 0;
}

Measured memory_bytes: 256
h,w,k=map(int, input().split())
grid=[]
for i in range(h):
    grid.append([1 if s=='#' else 0 for s in input()])
ans=0
for i in range(1<<h):
    for j in range(1<<w):
        cnt=0
        for ih in range(h):
            for iw in range(w):
                if (i>>ih)%2==0 and (j>>iw)%2==0 and grid[ih][iw]==1:
                    cnt+=1
        if cnt==k:
            ans+=1
print(ans)

Measured memory_bytes: 68136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0; i<x; i++)
#define repn(i,x) for(int i=1; i<=x; i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main() {
    int n, y;
    cin >> n >> y;
    bool has_found = false;
    for (int i = 0; i <= n && !has_found; i++)
        for (int j = 0; j <= n && !has_found; j++) {
            int k = n - i - j;
            if (k < 0)
                continue;
            else if (i * 10000 + j * 5000 + k * 1000 == y) {
                cout << i << " " << j << " " << k;
                has_found = true;
            }
        }
    if (!has_found)
        cout << "-1 -1 -1";
}

Measured memory_bytes: 256
#define errOut(s) \
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << std::endl; }

#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
//#include <boost/multi_array.hpp>
//#include <boost/optional.hpp>
//#include <boost/range/adaptors.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

using row_t = struct {
  int64_t index;
  int64_t count;
};

using column_t = struct {
  int64_t index;
  int64_t count;
};

int64_t solve(int64_t h, int64_t w, int64_t m, std::vector<int64_t> ys,
              std::vector<int64_t> xs) {
  std::vector<row_t> rows(h);
  std::vector<column_t> columns(w);
  std::unordered_map<int64_t, unordered_set<int64_t>> columnsIdxesInRow;
  for (int y = 0; y < h; y++) {
    rows[y].index = y;
    rows[y].count = 0;
  }
  for (int x = 0; x < w; x++) {
    columns[x].index = x;
    columns[x].count = 0;
  }

  for (int i = 0; i < m; i++) {
    rows[ys[i]].count++;
    columns[xs[i]].count++;
    columnsIdxesInRow[ys[i]].insert(xs[i]);
  }

  std::sort(rows.begin(), rows.end(), [](row_t const& lhs, row_t const& rhs) {
    return lhs.count > rhs.count;
  });
  std::sort(columns.begin(), columns.end(),
            [](column_t const& lhs, column_t const& rhs) {
              return lhs.count > rhs.count;
            });

  auto const maximumCountOfRow = rows.front().count;
  auto const maximumCountOfColumn = columns.front().count;
  auto const ret = maximumCountOfRow + maximumCountOfColumn;
  for (auto const& column : columns) {
    if (column.count != maximumCountOfColumn) {
      break;
    }
    for (auto const& row : rows) {
      if (row.count != maximumCountOfRow) {
        break;
      }
      if (columnsIdxesInRow[row.index].count(column.index) == 0) {
        return ret;
      }
    }
  }

  return ret - 1;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t h;
  std::cin >> h;
  int64_t w;
  std::cin >> w;
  int64_t m;
  std::cin >> m;
  std::vector<int64_t> hs(m);
  std::vector<int64_t> ws(m);
  for (int i = 0; i < m; i++) {
    std::cin >> hs[i];
    hs[i]--;
    std::cin >> ws[i];
    ws[i]--;
  }
  auto const res = solve(h, w, m, std::move(hs), std::move(ws));
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 63616
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
ll ebob(ll a, ll b){
	if(!a)return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (a*b)/ebob(a, b);
}
void cr(string& s, vector<pair<int, int>>& v, vector<vector<int>>& cnt, int c, int l, int r){
	v[c] = {l, r};
	for(int i = l; i <= r; i++){
		cnt[c][s[i] - 'a']++;
	}
	if(l == r) return;
	cr(s, v, cnt, 2*c, l, (l+r)/2);
	cr(s, v, cnt, 2*c+1, (l+r)/2+1, r);
}
void change(string& s, vector<pair<int, int>>& v, vector<vector<int>>& cnt, int c, int target, char ch){
	if(v[c].first <= target && target <= v[c].second){
		cnt[c][s[target] - 'a']--;
		cnt[c][ch - 'a']++;
	}else return;
	if(v[c].first == v[c].second) return;
	change(s, v, cnt, 2*c, target, ch);
	change(s, v, cnt, 2*c+1, target, ch);
}
void fonk(vector<pair<int, int>>& v, vector<vector<int>>& cnt, int c, int l, int r, vector<bool>& seen){
	if(l <= v[c].first && v[c].second <= r){
		for(int i = 0; i < 26; i++){
			if(cnt[c][i]) seen[i] = true;
		}
		return;
	}
	if(l > v[c].second || r < v[c].first) return;
	if(v[c].first == v[c].second) return;
	fonk(v, cnt, 2*c, l, r, seen);
	fonk(v, cnt, 2*c+1, l, r, seen);
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	string s; cin>>s;
	vector<pair<int, int>> v(4*n+1);
	vector<vector<int>> cnt(4*n+1, vector<int>(26, 0));
	cr(s, v, cnt, 1, 0, n-1);
	int q; cin>>q;
	while(q--){
		int type;
		cin>>type;
		if(type == 1){
			int l; char c; cin>>l>>c;
			l--;
			change(s, v, cnt, 1, l, c);
			s[l] = c;
		}else{
			vector<bool> seen(26, 0);
			int a, b; cin>>a>>b;
			a--, b--;
			int res = 0;
			fonk(v, cnt, 1, a, b, seen);
			for(int i = 0; i < 26; i++){
				if(seen[i]){
					//cout<<(char)(i+'a')<<endl;
					res++;
				}
			}
			cout<<res<<"\n";
		}
	}
}

Measured memory_bytes: 282140
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var a = vals[0];
        var b = vals[1];
        var k = vals[2];

        var t = Math.Min(k, a);
        a = a - t;
        k -= t;
        b = Math.Max(b - k, 0);

        Console.WriteLine($"{a} {b}");
    }
}

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

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  vector<int> D(N - 1);
  for (int i = 1; i <= N - 1; i++) {
    for (int j = i + 1; j <= N; j++) {
      if (i <= X && j >= Y) {
        D.at(X - Y - i + j)++;
      }
      else if (i > X && i < Y && j > X && j < Y) {
        D.at(min(j - i, Y - X + i - j + 1) - 1)++;
      }
      else if (i <= X && j > X && j < Y) {
        D.at(min(j - X, Y - j + 1) + X - i - 1)++;
      }
      else if (i > X && i < Y && j >= Y) {
        D.at(min(Y - i, i - X + 1) + j - Y - 1)++;
      }
      else {
        D.at(j - i - 1)++;
      }
    }
  }
  for (int i = 0; i < N - 1; i++) {
    cout << D.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 1000000000
using namespace std;
vector<int> w;
vector<int> p;
vector<vector<int>> dp;
int knapsack2(int r,int i){
    if(r<=0)return 0;
    if(i<0)return N;
    if(dp[i][r])return dp[i][r];

    dp[i][r] = min(knapsack2(r,i-1),w[i]+knapsack2(r-p[i],i-1));
    return dp[i][r];
}
int main(){
    int n,W;
    cin>>n>>W;
    w.resize(n);
    p.resize(n);
    int p_sum = 0;
    for(int i=0;i<n;i++){
        cin>>w[i]>>p[i];
        p_sum+=p[i];
    }
    dp = vector<vector<int>>(n,vector<int>(p_sum+1,0));
    for(int i=p_sum;i>=0;i--){
        int res = knapsack2(i,n-1);
        // cout<<res<<" "<<W<<"\n";
        if(res<=W){
            cout<<i<<"\n";
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 39808
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int n=in();int k=in();
	string s;cin>>s;
	int l=0,cnt=0;if(s[0]=='0')cnt=1;int ans=0;
	if(s.length()==1){cout<<1;return 0;}
	for(int r=1;r<n;r++)
	{
		if(s[r-1]=='1' and s[r]=='0')
		cnt++;
		
		while(cnt>k)
		{
			l++;
			if(s[l]=='1' and s[l-1]=='0')cnt--;
		}
		
		if(cnt<=k)ans=max(ans,r-l+1);
	}
	cout<<ans;
	
}

Measured memory_bytes: 3808
#[test]
fn test_solve() {
   assert_eq!(solve("?tc????\ncoder\n"), "atcoder\n");
   assert_eq!(solve("???????\ncoder\n"), "aacoder\n");
   assert_eq!(solve("??p??d??\nabc\n"), "UNRESTORABLE\n");
}
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let s = sc.get().to_owned();
    let t = sc.get().to_owned();

    let n = s.len();
    let k = t.len();

    for i in (0..n-k+1).rev() {
        if mat(&s[i..i+k], &t) {
            let s = s.replace("?", "a");
            return format!("{}{}{}\n", &s[..i], &t, &s[i+k..])
        }
    }

    format!("UNRESTORABLE\n")
}
fn mat(s: &str, t: &str) -> bool {
    let n = s.len();
    if t.len() == s.len() {
        for (s,t) in s.chars().zip(t.chars()) {
            if s != '?' && s != t {
                return false;
            }
        }
    } else {
        panic!("not eq len");
    }
    true
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}

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

int main() {
  long long a,b,k;
  cin >> a >> b >> k;
  
  if (a >= k){
    cout << a-k << " " << b << endl;
  }
  else if (b >= (k-a)) {
    cout << "0 " << b-(k-a) << endl;
  }
  else{
    cout << "0 0" << endl;
  }
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  while(cin>>s,s!="-")
  {
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
      int h;
      cin>>h;
      string tmp=s+s;
      for (int j = 0; j < s.size(); ++j)
      {
         s.at(j)=tmp.at(h+j);
      }
    }
    cout<<s<<endl;
  }
}


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

int main(){
  string s;
  std::cin >> s;
  if(s=="AKIHBR"||s=="KIHBR"||s=="KIHABR"||s=="KIHBAR"||s=="KIHBRA"||s=="AKIHABR"||s=="AKIHBAR"||s=="AKIHBRA"||\
s=="KIHABAR"||s=="KIHABRA"||s=="AKIHABAR"||s=="AKIHABRA"||s=="AKIHBARA"||s=="KIHABARA"||\
s=="AKIHABARA"||s=="KIHBR")std::cout << "YES" << std::endl;
  else std::cout << "NO" << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>


using namespace std;
using ll = long long;

template<typename T> void print(T t) { cout << t << endl; }

int N;

bool mizu(vector<int>& hs) {
	int l=0, r;
	for (l = 0; l < N; l++) {
		if (hs[l] != 0)break;
	}
	if (l == N)return false;

	for (int i=l; i < N; i++) {
		if (hs[i] != 0)hs[i]--;
		else break;
	}
	return true;
}
int main() {
	cin >> N;
	vector<int> hs(N);
	for (auto& h : hs) cin >> h;

	int count = 0;
	while (mizu(hs)) {
		count++;
	}
	print(count);
}

Measured memory_bytes: 3636
#include<iostream>

using namespace std;
int main()
{
	int n, k;
	char s[50];
	cin >> n >> k >> s;
	if (s[k - 1] == 'A')
    {
        s[k - 1] = 'a';
    }
	if (s[k - 1] == 'B')
    {
        s[k - 1] = 'b';
    }
	if (s[k - 1] == 'C')
	{
        s[k - 1] = 'c';
	}
	cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  int sum = a+b; //aとbの和
  if(sum%2 == 0) //和が偶数，すなわち平均は2で割り切れる
    cout << sum/2 << endl;
  else //和が奇数，すなわち平均は2で割り切れないため，切り上げ
    cout << sum/2+1 << endl;

    
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,ans;
char s[200010];
int main(){
	scanf("%s",s);
	n=strlen(s);
	ll c=n-1;
	while(c>=0&&s[c]=='B')c--;
	ll cb=c+1;
//	printf("%d %d\n",c,cb);
	for(;c>=0;c--)if(s[c]=='B')ans+=--cb-c;
    printf("%lld",ans);
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
  Scanner sc = new Scanner(System.in);
 
  public static void main(String[] args) {
    new Main().run();
  }


  void run() {
   int a=sc.nextInt();
   int b=sc.nextInt();
   int c=sc.nextInt();
   int result=0;
   if(a==b&&a==c){
	   result=1;
   }else if(a==b&&a!=c){
	   result=2;
   }else if(a==c&&a!=b){
	   result=2;
   }else if(b==c&&a!=b){
	   result=2;
   }else {
	   result=3;
   }
   System.out.println(result);
   
  }
 

 
  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 9680
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>

ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}
ll INF = 10010001010;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    ll A,B,C,D;
    cin >> A >> B >> C >> D;
    ll ans = 0;
    ll Tans = 0;
    ans += (B / C);

    ans -= ((A-1) / C);

    ans += (B / D);

    ans -= ((A-1) / D);

    ll LCM = lcm(C, D);
    ll lcmmi = B / LCM;
    lcmmi = lcmmi - (A-1) / LCM;
    ans  -= lcmmi;
    Tans = (B - A) - ans;
    cout << Tans+1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MAX 100000000000000000
int main()
{

    //freopen("inputfile.txt","r",stdin);
    ll n,m;cin>>n>>m;
    ll count = 0;
    while(n--)
    {
        ll a,b;cin>>a>>b;
        ll h = abs(a*a)+abs(b*b);
        if(ceil(sqrt(h))<=m)count++;
    }
    cout<<count<<endl;
    return 0;
}


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

int main(){
	
	int n; cin>>n;
	bitset<4000010> bt;
	bt[0] = 1;
	int sum = 0;
	for(int i=0;i<n;i++){
		int a; cin>>a;
		sum += a;
		bt|=(bt<<a);
	}
	
	for(int i=(sum+1)/2;i<sum+1;i++){
		if(bt[i]){ cout<<i<<endl; return 0; }
	}
	
	
	return 0;
}


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

int main() {
    string tmp;
    deque<char> S;
    cin >> tmp;
    for (int i = 0; i < tmp.length(); i++)
    {
        S.push_back(tmp[i]);
    }
    int Q;
  	cin >> Q;
    bool isT = true;
    for (int i = 0; i < Q; i++)
    {
        int t;
        cin >> t;
        if(t==1) isT = !isT;
        if(t==2){
            int f;
            char c;
            cin >> f >> c;
            bool a = (isT&&f==1)||(!isT&&f==2);
            if(a) S.push_front(c);
            else S.push_back(c);
        }
    }
    if(!isT){
        for (int i = 0; i < S.size()/2; i++)
        {
            char c = S[S.size()-i-1];
            S[S.size()-i-1] = S[i];
            S[i] = c;
        }
    }
	
    for(int i = 0; i < S.size(); i++)cout << S[i];
    cout << endl;   
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define endl '\n'
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	if (s == "SSS")
		cout << "0" << endl;
	else if (s == "RRR")
		cout << "3" << endl;
	else if (s == "RRS" || s == "SRR")
		cout << "2" << endl;
	else
		cout << "1" << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    string S;
    cin >> N >> S;
    
    int ans = 0;
    REP(i, N) {
        string X = S.substr(0, i);
        string Y = S.substr(i, N - i);
        int cnt = 0;
        rep(i, 26) {
            if (count(X.begin(), X.end(), 'a' + i) && count(Y.begin(), Y.end(), 'a' + i)) ++cnt;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
if (a+b > c+d) {
cout << "Left" << endl;
}
  else if (a+b < c+d) {
  cout << "Right" << endl;
  }
  else {
  cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
N, M = map(int, input().split())

if (N == 1) or (M == 1):
  if max(N, M) == 1:
    ans = 1
  else:
    ans = max(N, M) - 2
elif (N == 2) or (M == 2):
  ans = 0
else:#N, M共に3以上
  ans = (N - 2) * (M - 2)
print(ans)
  

Measured memory_bytes: 3060
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n, k = MAP()
a = LIST()
for j in range(k):
    prea = [i for i in a]
    num = [0 for _ in range(n + 2)]
    for i in range(n):
        l = max(1, i + 1 - a[i])
        r = min(n + 1, i + 1 + a[i] + 1)
        num[l] += 1
        num[r] -= 1
    for i in range(1, n + 2):
        num[i] += num[i - 1]
    #print(num)
    a = [i for i in num[1:n + 1]]
    if a == prea:
        break
a = [str(i) for i in a]
print(' '.join(a))

Measured memory_bytes: 189488
N, M = map(int, input().split())

H = list(map(int, input().split()))

ls = [1 for _ in range(N)]

for m in range(M):
    A, B = map(int, input().split())

    if ls[A - 1]: 
        ls[A - 1] = 0
        if H[A - 1] > H[B - 1]:
            ls[A - 1] = 1

    if ls[B - 1]: 
        ls[B - 1] = 0
        if H[B - 1] > H[A - 1]:
            ls[B - 1] = 1


print(sum(ls))


Measured memory_bytes: 91588
#include <iostream>
#include <algorithm>
#include <tuple>
#include <cmath>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>

#define mt make_tuple
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define readline(s) getline(cin, s)

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

int main() {
	int d, g;
	int idx[11];
	for(int i=0;i<10;i++) idx[i] = i;
	int p[11], c[11];
	scanf("%d%d", &d, &g);
	for(int i=0;i<d;i++) {
		scanf("%d%d", &p[i], &c[i]);
	}
	int mn = 999999999;
	do {
		int gg = g;
		int ans = 0;
		for(int i=0;i<d;i++) {
			int x = p[idx[i]] * (idx[i]+1) * 100;
			if(x <= gg) {
				gg -= x;
				gg -= c[idx[i]];
				ans += p[idx[i]];
			} else if(gg > 0){
				for(int j=0;j<p[idx[i]];j++) {
					ans++;
					gg -= (idx[i]+1) * 100;
					if(gg<=0) break;
				}
			}
		}
		if(mn > ans) mn = ans;
	}while(next_permutation(idx, idx + d));
	printf("%d\n", mn);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long double pi = acos(-1.0); 
typedef long long ll;

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

	int x;
	cin >> x;
	if(x == 1) {
		cout << 0 << endl;
	}else {
		cout << 1 << endl;
	}
}

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

int main()
{
	int a,b,c;
    cin>>a>>b>>c;
    int cnt[10]={0};
    cnt[a]++;
    cnt[b]++;
    cnt[c]++;
    if(cnt[5]==2 && cnt[7]==1)
        cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
using namespace std;
typedef long long ll;
#define MOD 1000000007

int fact(int n) {
  int res = 1;
  for (int i = 2; i <= n; i++) {
    res = (ll)res * i % MOD;
  }
  return res;
}

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

  if (n < m) swap(n, m);
  if (n - m > 1) {
    cout << 0 << endl;
    return 0;
  }

  int res = fact(m);
  res = (ll)res * res % MOD;
  if (n == m)
    cout << 2LL * res % MOD << endl;
  else
    cout << (ll)n * res % MOD;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

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

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}



int main(){
    int n; cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    vector<int> s(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    rep(i,n) s[i]=i+1;
    
    int p_p=0;
    int q_p=0;
    int i=1;
    while(next_permutation(s.begin(),s.end())){
        if(p==s){
            p_p=i;
        }
        if(q==s){
            q_p=i;
        }
        i++;
    }
    cout << abs(p_p-q_p) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int sum[114514];
signed main(){
	int n,m;
	cin>>n>>m;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort( a.begin(), a.end() );
	sum[0] = a[0];
	for(int i=1;i<n;i++){
		sum[i] = sum[i-1] + a[i];
	}
	int ok = LINF, ng = -1; // ok iff less than m pairs of (i,j) satisfy ai*aj >= t
	while( ok - ng > 1 ){
		int mid = ( ok + ng ) / 2;
		int cnt = 0;
		for(int i=0;i<n;i++){
			int thr = mid-a[i];
			auto it = lower_bound( a.begin(), a.end(), thr );
			cnt += a.end() - it;
		}
		if( cnt < m ){
			ok = mid;
		}
		else{
			ng = mid;
		}
	}
	//cout<<ok<<endl;
	int sh = 0, ans = 0;
	for(int i=0;i<n;i++){
		int thr = ok - a[i];
		auto it = lower_bound( a.begin(), a.end(), thr );
		int idx = it - a.begin();
		sh += n - idx;
		ans += a[i] * ( n - idx );
		ans += sum[n-1];
		if( idx > 0 ) ans -= sum[idx-1];
	}
	//cout<<sh<<" "<<ans<<endl;
	int amari = m - sh;
	ok = -1, ng = LINF; // ok iff m or more pairs of (i,j) satisfy ai*aj >= t
	while( ng - ok > 1 ){
		int mid = ( ok + ng ) / 2;
		int cnt = 0;
		for(int i=0;i<n;i++){
			int thr = mid-a[i];
			auto it = lower_bound( a.begin(), a.end(), thr );
			cnt += a.end() - it;
		}
		if( cnt >= m ){
			ok = mid;
		}
		else{
			ng = mid;
		}
	}
	ans += amari * ok;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1920
import math as mt
import sys, string
from collections import Counter, defaultdict
input = sys.stdin.readline

# input functions
I = lambda : int(input())
M = lambda : map(int, input().split())
ARR = lambda: list(map(int, input().split()))
MOD = int(1e9 + 7)

n = I()
if n < 2:
    print(0)
else:
    ans = (10 ** n)  # all comb
    ans %= MOD
    ans -= 2 * (9 ** n)  # without 9 or 0
    ans %= MOD
    ans += 8 ** n  # without 9 and 0
    ans %= MOD
    print(ans)
    

Measured memory_bytes: 86444
N = int(input())
A = tuple(map(int, input().split()))
MOD = 10 ** 9 + 7

ans = 0
x = 1
for d in range(60):
    odd = 0
    even = 0
    for a in A:
        if a & (1 << d):
            odd += 1
        else:
            even += 1
    ans += odd * even * x
    ans %= MOD
    x <<= 1
print(ans)

Measured memory_bytes: 131144
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
long long n;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	cout<<n*(n-1)/2LL<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
#include <list>
#include <deque>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll MOD = 1000000007;
ll INF = 1LL << 60;


long long dp[55][3000][55];
int main() {
    int N, A;
    cin >> N >> A;
    vector<int> x(N);
    for (int i = 0; i < N; ++i) cin >> x[i];

    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int i = 0; i < N; ++i) {
        for (int s = 0; s <= N*A; ++s) {
            for (int k = 0; k <= N; ++k) {
                if (dp[i][s][k] == 0) continue;
                dp[i+1][s][k] += dp[i][s][k];
                dp[i+1][s+x[i]][k+1] += dp[i][s][k];
            }
        }
    }
    long long res = 0;
    for (int k = 1; k <= N; ++k) res += dp[N][A*k][k];
    cout << res << endl;
}

Measured memory_bytes: 71168
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;
/*
終わった後だけど0と1の個数を数えて小さい方掛ける2を出力で行ける??
*/
int main(){
    std::string S; cin >> S;
    int cnt=0;
    int c=0;
    for(int i=0;i<S.length();i++){
        if(S[i] == 48) cnt++;
        else c++;
    }
    if(cnt<c) cout << cnt*2 << endl;
    else    cout << c*2 << endl;

    return 0;
}


Measured memory_bytes: 512
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(A[K-1])

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
#define F first
#define S second
#define fi(a, b) for(ll i=(a);i<=b;i++)
#define fj(a, b) for(ll j=(a);j<=b;j++)
#define fid(a, b) for(ll i=(a);i>=b;i--)
#define fjd(a, b) for(ll i=(a);i>=b;j--)

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    os << "]";
	return os;
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class T> ostream& operator<<(ostream &os, multiset<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, unordered_map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}

// Kevin Mathew T
// Birla Institute of Technology, Mesra
// LinkedIn - https://www.linkedin.com/in/KevinMathewT/
// GitHub - https://github.com/KevinMathewT
// CodeForces - https://codeforces.com/profile/KevinMathew
// CodeChef - https://www.codechef.com/users/KevinMathew
// HackerRank - https://www.hackerrank.com/KevinMathew

const ll N = 500010, M = 1e9 + 7;
ll n, a[N];
string s;

void solve(){
	cin >> s;
	n = s.size();

	s = "$" + s;

	// cout << "  ";
	// fi(1, n) cout << s[i] << ' ';
	// cout << "\n";
	fi(0, n) a[i] = -1;
	if(s[1] == '<') a[0] = 0;
	if(s[n] == '>') a[n] = 0;

	fi(1, n - 1) if(s[i] == '>' && s[i + 1] == '<') a[i] = 0;
	fi(1, n - 1) if(s[i] == '<' && s[i + 1] == '<') a[i] = a[i - 1] + 1;
	fid(n, 2) if(s[i] == '>' && s[i - 1] == '>') a[i - 1] = a[i] + 1;
	fi(1, n - 1) if(s[i] == '<' && s[i + 1] == '>') a[i] = max(a[i - 1], a[i + 1]) + 1;

	if(s[1] == '>') a[0] = a[1] + 1;
	if(s[n] == '<') a[n] = a[n - 1] + 1;

	// fi(0, n) cout << a[i] << ' ';
	// cout << '\n';
	cout << accumulate(a, a + n + 1, 0LL) << "\n";
}

int main(){
	// freopen("input.txt", "r", stdin);		//Comment
	// freopen("output.txt", "w", stdout);		//this out.
	ios::sync_with_stdio(false);			//Not
	cin.tie(NULL);							//this.
	cout.tie(0);							//or this.

	// ll T;
	// cin >> T;
	// while(T--)
		solve();

	return 0;
}

Measured memory_bytes: 4784