akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 
string str;
bool f(string s){
	for(int i = 1; i <s.size(); i++){
		if(s[i] != s[i-1]) return false;
	}
	return true;
}

string calc(int i,string s){
	string ret = s;
	if(s[i] != s[i+1]){
		if((ret[i]=='g' && ret[i+1] == 'r') ||(ret[i]=='r' && ret[i+1] == 'g')) ret[i] = ret[i+1] ='b';
		else if((ret[i]=='b' && ret[i+1] == 'r') ||(ret[i]=='r' && ret[i+1] == 'b')) ret[i] = ret[i+1] ='g';
		else if((ret[i]=='g' && ret[i+1] == 'b') ||(ret[i]=='b' && ret[i+1] == 'g')) ret[i] = ret[i+1] ='r';
	}
	return ret;
}

int main(){
	while(cin>>str){
		if(str == "0") break;
		set<string> s;
		queue<pair<string,int> > q;
		int ans = 0;
		bool flag = false;
		pair<string,int> p;
		s.insert(str);
		q.push(pair<string,int>(str,0));
		while(!q.empty()){
			p = q.front();
			q.pop();
			if(f(p.fi)) {
				ans = p.se;
				flag = true;
				break;
			}
			for(int i = 0; i< str.size()-1; i++){
				if(!s.count(calc(i,p.fi))){
					q.push(pair<string,int>(calc(i,p.fi),p.se+1));
					s.insert(calc(i,p.fi));
				}
			}
		}
		if(flag) cout<<ans<<endl;
		else cout<<"NA"<<endl;
	}
}

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

int main() {
	int N,M;
	cin >> N >> M;
	
	char A[N][N];
	char B[M][M];
	for(int i=0; i<N; i++){
	for(int j=0; j<N; j++){
		cin >> A[i][j];
	}
	}
	for(int i=0; i<M; i++){
	for(int j=0; j<M; j++){
		cin >> B[i][j];
	}
	}
	
	int ans=0;
	for(int i=0; i<N-M+1; i++){
	for(int j=0; j<N-M+1; j++){
		ans=1;
		for(int k=0; k<M; k++){
		for(int l=0; l<M; l++){
			if(A[i+k][j+l]!=B[k][l]){
				ans=0;
			}
		}
		}
		if(ans==1){
			cout << "Yes"<<endl;
			return 0;
		}
	}
	}
	
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]

a.sort()
Max = a[-1]
memo = [1] * (Max+1)
count = 0

# i<n-1
for i in range(n-1):
    t = a[i]
    if memo[t] == 1:
        if a[i] != a[i+1]:
            count += 1
        for j in [t*k for k in range(1, Max//t+1)]:
            memo[j] = 0
# i=n-1
if memo[a[n-1]] == 1:
    count += 1

print(count)

""" #Time over
a.sort(reverse=True)

count = 0
# i<n-1
for i in range(n-1):
    if a[i] != a[i+1] and a[i] != a[i-1]:
        for j in range(n-1, i, -1):
            if a[i] % a[j] == 0:
                break
            if j == i+1:
                count += 1

# i==n-1
if a[n-2] != a[n-1]:
    count += 1

if n != 1:
    print(count)
elif n == 1:
    print(1)
"""

Measured memory_bytes: 65872
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    cin>>a>>b>>c;
    if (a<=b && b<=c){
        cout<<a<<" "<<b<<" "<<c<<endl;
    }
    else if (a<=c && c<=b){
        cout<<a<<" "<<c<<" "<<b<<endl;
    }
    else if (b<=a && a<=c){
        cout<<b<<" "<<a<<" "<<c<<endl;
    }
    else if (b<=c && c<=a){
        cout<<b<<" "<<c<<" "<<a<<endl;
    }
    else if (c<=a && a<=b){
        cout<<c<<" "<<a<<" "<<b<<endl;
    }
    else if (c<=b && b<=a){
        cout<<c<<" "<<b<<" "<<a<<endl;
    }
    return 0;
}



Measured memory_bytes: 3092
n = gets.to_i
num = gets.split.map(&:to_i)
gc = Array.new(2).map{Array.new(n,0)}
ans = Array.new(n,0)
for i in 1..n-1
  gc[0][i] = gc[0][i-1].gcd(num[i-1])
end
for i in 2..n
  gc[1][-i] = gc[1][-i+1].gcd(num[-i+1])
end
for i in 0..n-1
  ans[i] = (gc[0][-i]).gcd(gc[1][-i])
end
ans.sort!
puts ans[-1]


Measured memory_bytes: 11776
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<unordered_map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok = true, flag = false;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222


ll a[MAX];

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


  cin >> n >> m;
  rep(i, n) cin >> a[i+1];
  FOR(i, 1, n) a[i + 1] += a[i];
  vll sum, an[55];
  rep(i, n + 1)FOR(j, i + 1, n + 1) {
    sum.pb(a[j] - a[i]);
  }
  rep(i, sum.size()) an[53].pb(sum[i]);
  rrep(i, 53) {
    cnt = 0;
    rep(j, an[i + 1].size()) if (an[i + 1][j] >> i & 1) cnt++;
    if (cnt >= m) {
      rep(j, an[i + 1].size()) if (an[i + 1][j] >> i & 1) an[i].pb(an[i + 1][j]);
      ans += powl(2, i);
    }
    else {
      rep(j, an[i + 1].size()) an[i].pb(an[i + 1][j]);
    }
  }
  cout << ans << endl;

  return 0;
}

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

char c1[5],c2[5];
int ans=0;

int main(void){
	scanf("%s",c1);
	scanf("%s",c2);
	for(int i=0;i<3;i++)
	if(c1[i]==c2[i])ans++;
	printf("%d",ans);
} 

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

//写経２回目　何も見ずに//

void doubling(ll N, ll K, const vector<ll> &A, vector<vector<ll>> &a){
  //ここでaを作る
  
  vector<ll> used(200010,-1); //-1はまだ当該の数字が出たことがないのを意味
  
  //先ずはa[0][i]を作る
  
  for(ll k = 0; k < 2; k++){
    
    for(ll i = 0; i < N; i++){ 
      
      if(used[A[i]] != -1 ){ 
        
        a[0][(used[A[i]])%N] = k*N+i-used[A[i]]+1;
        
      }
      
      used[A[i]] = k*N+i; 
      
    }// for-i
  }//for-k
  
  
  //次にa[k][i]を構築
  
  for(ll k = 1; k < 60; k++){
    for(ll i = 0; i < N; i++){
      
      a[k][i] = a[k-1][i]+a[k-1][(i+a[k-1][i])%N];
      
    }
  }

  return ;
} 

deque<ll> simulate(const ll &start, const ll &N, const vector<ll> &A){
  
  deque<ll> D;  vector<bool> used(200010,false);
  
  for(ll i = start; i < N; i++){
    if( !used[A[i]] ){ used[A[i]] = true; D.push_back(A[i]);}
    else{
      
      while(true){
        auto x = *D.rbegin();
        used[x] = false;
        D.pop_back();
        if(x == A[i]){ break;}
        
      }//while-とじ
    }//else-とじ
    
  }//for-i
  
  return D;
}
      
      
ll pos( const ll &N, const ll &K, const vector<ll> &A,const vector<vector<ll>> &a){
  
  ll sum = 0; ll now = 0;
  ll SIZE = N*K;
  
  while(true){
    
    ll ind = 0;
    
    for(ll i = 0; i < 60; i++){ //nowから何個先のブロックまでダブリングでいけるか調べる
    
     if( sum+a[i][now] >= SIZE ){ 
      
       ind = i-1;
      
       break;
     }
    }
    
    if(ind == -1){ //ここから先は直接シミュレーションしてしまった方が早い
      deque<ll> D = simulate(now,N,A);
      for(auto ne : D ){ cout << ne << " ";}
      cout << endl;
      
      return 0;
    }
    
    sum += a[ind][now]; //手前までは進む
    now = sum%N;
    
  }
  
}
    
  
      
      

int main(){ 
  ll N,K; cin >> N >> K;
  vector<ll> A(N);
  for(ll i = 0; i < N; i++){ cin >> A[i];}
  
  vector<vector<ll>> a(60,vector<ll>(200010));
  
  doubling(N,K,A,a);
  
  pos(N,K,A,a); //手前まで行く
  
  return 0;
}
  

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

using namespace std;

int n, m; 
int occ[200005];
int arr[200005];
int intv[200005];
int zeros;

inline void update(int pos, int v){
	if(pos < 0) return;
	if(intv[pos] == 0) zeros--;
	intv[pos] += v;
	if(intv[pos] == 0) zeros++;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	zeros = n;
	
	for(int i = 0;i < n;i++){
		int a; cin >> a;
		arr[i+1] = a;
		occ[a]++;
		update(a - occ[a], 1);
	}

	for(int i = 0;i < m;i++){
		int x, a; cin >> x >> a;
		int preA = arr[x];
		
		update(preA - occ[preA], -1);
		occ[preA]--;
		
		arr[x] = a;
		
		occ[a]++;
		update(a - occ[a], 1);
		
		cout << zeros << "\n";
	}
}


Measured memory_bytes: 3840
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<vector>

using namespace std;

#define LL long long
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };
bool IA(int x, int y, int H, int W) { return (0<=x && x<=H) && (0<=y && y<=W); }

LL N,K,a[15],sum=(1ll<<60);

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

	for(int b=1;b<(1<<N);b++){
		LL tmp=0ll,hi=0ll,on=0ll;
		for(int d=0;d<15;d++)if(b&(1<<d))on++;
		if(on<K)continue;
		for(int i=0;i<N;i++){
			if(i){
				hi=max(hi,a[i-1]);
				if((b&(1<<i)) && hi>=a[i]){
					hi++;
					tmp+=hi-a[i];
				}
			}
		}
		sum=min(sum,tmp);
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <cstdio>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define irep(i, a) for (int i = 1; i <= a; i++)
#define mp make_pair
#define pb push_back
#define P pair<int, int>
#define ll long long

int r,g,b,n;

int main()
{
  cin>>r>>g>>b>>n;
  int ans=0;

  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      int nokori=n-i*r-j*g;
      if(nokori<0)continue;
      if(nokori%b==0){
        ans++;
        //cout<<i<<" "<<j<<" "<<endl;
      }
    }
  }

  cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,x,t;
   cin >> n >> x >> t;
   cout << t*((n+x-1)/x);
   return 0;
} 


Measured memory_bytes: 3636
h, n = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
A = [x[1] for x in AB]

DP = [float("inf") for _ in range(h+1)]
DP[0] = 0

for i in range(h):
    for damage, cost in AB:
        next_index = min(i+damage, h)
        DP[next_index] = min(DP[next_index], DP[i]+cost)

print(DP[-1])

Measured memory_bytes: 74480
#include <iostream>
#include <iomanip>
#include <queue>
#include <deque>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

template<class T>bool chmax(T &a, const T &b) {
   if (a < b) {
      a = b;
      return 1;
   }
   return 0;
}
template<class T>bool chmin(T &a, const T &b) {
   if (a > b) {
      a = b;
      return 1;
   }
   return 0;
}

using namespace std;
using ll = long long;

const int kInf = 2e9;
const ll kLInf = 2e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N;
bool A[1000000010];

int main()
{
   cout << fixed << setprecision(10);
   cin >> N;
   int a;
   REP(i, N) {
      cin >> a;
      if (A[a]) {
         cout << "NO" << endl;
         return 0;
      } else {
         A[a] = true;
      }
   }
   cout << "YES" << endl;
   return 0;
}



Measured memory_bytes: 975360
#include<iostream>
#include<string>
using namespace std;
int main(){
	char a[10];
	int b;
	while(cin>>a[1]){
		for(int i=2;i<10;i++)
			cin>>a[i];
		b=2;
		if(a[1]=='o'&&a[2]=='o'&&a[3]=='o')
			b=0;
		if(a[4]=='o'&&a[5]=='o'&&a[6]=='o')
			b=0;
		if(a[7]=='o'&&a[8]=='o'&&a[9]=='o')
			b=0;
		if(a[1]=='o'&&a[4]=='o'&&a[7]=='o')
			b=0;
		if(a[2]=='o'&&a[5]=='o'&&a[8]=='o')
			b=0;
		if(a[3]=='o'&&a[6]=='o'&&a[9]=='o')
			b=0;
		if(a[1]=='o'&&a[5]=='o'&&a[9]=='o')
			b=0;
		if(a[3]=='o'&&a[5]=='o'&&a[7]=='o')
			b=0;
		if(a[1]=='x'&&a[2]=='x'&&a[3]=='x')
			b=1;
		if(a[4]=='x'&&a[5]=='x'&&a[6]=='x')
			b=1;
		if(a[7]=='x'&&a[8]=='x'&&a[9]=='x')
			b=1;
		if(a[1]=='x'&&a[4]=='x'&&a[7]=='x')
			b=1;
		if(a[2]=='x'&&a[5]=='x'&&a[8]=='x')
			b=1;
		if(a[3]=='x'&&a[6]=='x'&&a[9]=='x')
			b=1;
		if(a[1]=='x'&&a[5]=='x'&&a[9]=='x')
			b=1;
		if(a[3]=='x'&&a[5]=='x'&&a[7]=='x')
			b=1;
		if(b==0)
			cout<<"o"<<endl;
		if(b==1)
			cout<<"x"<<endl;
		if(b==2)
			cout<<"d"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1132
N = int(input())
nums = [int(s) for s in input().split()]
 
min_breaks = -1
 
count_num = 1
break_index = 1

for i in range(N):
  if nums[i] == count_num:
      if min_breaks == -1:
          min_breaks = 0
      if count_num == 1:
      	 min_breaks += ((i+1) - break_index)
      else:
         min_breaks += ((i+1) - break_index - 1)
      
      break_index = (i+1)
      count_num+=1

if break_index < N and min_breaks != -1:
  min_breaks += ((i+1) - break_index)
  
print(min_breaks)

Measured memory_bytes: 25768
#include<iostream>
using namespace std;
long long int MOD = 1000000007;
long long modpow(long long a, long long n, long long mod);
long long modinv(long long a, long long mod);

int main() {
	
	//A
	int n, r;
	cin >> n >> r;
	if (n >= 10) {
		cout << r << endl;
	}
	else {
		cout << r + 100 * (10 - n) << endl;
	}
	return 0;

	//B
	/*int n;
	cin >> n;
	int k;
	cin >> k;
	int i = 0;
	while (n > 0) {
		n = (int)(n / k);
		i++;
	}
	cout << i << endl;
	return 0;*/
	//C
	/*int n;
	cin >> n;
	int x[100];
	int i;
	for (i = 0; i < n; i++) {
		cin >> x[i];
	}
	int sum, j, summin = 100000000;
	for (i = 0; i <= 100; i++) {
		sum = 0;
		for (j = 0; j < n; j++) {
			sum = sum + (x[j] - i) * (x[j] - i);
		}
		if (sum < summin)summin = sum;
	}
	cout << summin << endl;
	return 0;
	*/
	//D
	/*
	long long int n;
	cin >> n;
	long long int a, b;
	cin >> a >> b;
	if (n == 2) {
		cout << 0 << endl;
		return 0;
	}
	long long int sum = 1;
	int i;
	long long int x = 2, m = n;
	//2^nを計算
	while (m > 0) {
		if (m % 2 == 1) {
			sum = (sum * x) % MOD;
		}
		m = (int)(m / 2);
		x = (x * x) % MOD;
	}

	//cout << 1 << endl;
	
	long long int sum1 = 1;
	for (i = 1; i <= a; i++) {
		sum1 = (sum1 * (n + 1 - i)) % MOD;
	}
	for (i = 1; i <= a; i++) {
		sum1 = (sum1 * modinv(i, MOD)) % MOD;
	}
	sum = (sum - sum1 + MOD) % MOD;
	//cout << 2 << endl;

	sum1 = 1;
	for (i = 1; i <= b; i++) {
		sum1 = (sum1 * (n + 1 - i)) % MOD;
	}
	for (i = 1; i <= b; i++) {
		sum1 = (sum1 * modinv(i, MOD)) % MOD;
	}
	sum = (sum - sum1 + MOD) % MOD;
	sum = (sum + MOD - 1) % MOD;
	cout << sum << endl;
	return 0;
	*/
}
// a^n mod を計算する
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;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
	return modpow(a, mod - 2, mod);
}

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

using namespace std;

typedef long long ll;

static const ll md = 1e9+7;
static const ll mx = 100000;


int main(int, char**)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	
	int n, m;
	cin >> n >> m;
	vector<int> s(n);
	vector<int> t(m);
	for (int i = 0; i < n; ++i)
		cin >> s[i];
	for (int i = 0; i < m; ++i)
		cin >> t[i];

	vector<ll> x1(n+1, 0);
	vector<ll> x2(n+1);

	x2[0] = 0;
	ll* y1;
	ll* y2;
	for (int i = 0; i < m; ++i) {
		if (i % 2 == 0) {
			y1 = &(x1[0]); y2 = &(x2[0]);
		} else {
			y1 = &(x2[0]); y2 = &(x1[0]);
		}
		for (int j = 0; j < n; ++j) {
			if (s[j] == t[i]) {
				y2[j+1] = (y2[j] + y1[j+1] + 1);
			} else {
				y2[j+1] = (y2[j] + y1[j+1] - y1[j]);
			}
			if (y2[j+1] >= md) y2[j+1] %= md;
			else if (y2[j+1] < 0) y2[j+1] += md;
		}
	}

	cout << (y2[n] + 1) << endl;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, al, bo int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	for i := range a {
		if i%2 == 0 {
			al += a[i]
			continue
		}
		bo += a[i]
	}
	fmt.Println(al - bo)
}


Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var scan *bufio.Scanner
var writer io.Writer

func init() {
	scan = bufio.NewScanner(os.Stdin)
	writer = os.Stdout
	scan.Split(bufio.ScanWords)
}

func main() {
	solve()
}

func solve() {
	var s string
	fmt.Scan(&s)
	var k int
	fmt.Scan(&k)

	res := 0
	c := 1
	cs := 1
	csf := true
	for i := 1; i < len(s); i++ {
		if s[i] == s[i-1] {
			c++
			if csf {
				cs++
			}
		} else {
			res += c / 2
			c = 1
			csf = false
		}
	}
	res += c / 2
	res = res * k
	if s[0] == s[len(s)-1] && c%2 == 1 && cs%2 == 1 {
		res += k - 1
	}
	if csf {
		res = len(s) * k / 2
	}
	fmt.Fprint(writer, res)
}

func nextWord() string {
	scan.Scan()
	str := scan.Text()
	return str
}

func nextInt() int {
	i, e := strconv.Atoi(nextWord())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 640
def main()->None:
    N = int(input())
    range_N = range(N)
    s = []
    for _ in range_N:
        s.append(input())
    M = int(input())
    range_M = range(M)
    t = []
    for _ in range_M:
        t.append(input())
    
    
    max_total = 0
    for i in s:
        s_count = s.count(i)
        t_count = t.count(i)
        total = s_count - t_count
        if total > max_total:
            max_total = total

    print(max_total)




if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
int h,w,k;
char mp[12][1000+10];
int sum[12][1000+10];
int count(int x)
{
	int res=0;
	while(x){
		res++;
		x-=(x&-x);
	}
	return res;
}
int calsum(int r1,int c1,int r2,int c2){
	return sum[r2][c2]-sum[r2][c1]-sum[r1][c2]+sum[r1][c1];
}
bool cal(int lastcut,int curcut,int S)
{
	int lr=0;
	for(int i=0;i<h;i++){
		if(S>>i&1||i==h-1){
			int tmp=calsum(lr,lastcut,i+1,curcut);
			//printf("%d %d %d %d   %d\n",lr,lastcut,i+1,curcut,tmp);
			if(calsum(lr,lastcut,i+1,curcut)>k)return false;
			lr=i+1;
		}
	}
	return true;
}
int solve(int lastcut,int S)
{
	if(cal(lastcut,w,S))return 0;
	int nexcut=lastcut;
	for(int b=(1<<16);b>0;b>>=1){
		if(b+nexcut>=w)continue;
		if(!cal(lastcut,nexcut+b,S))continue;
		nexcut+=b;
	}
	if(nexcut==lastcut)return h*w*10;
	return 1+solve(nexcut,S);
}
int main()
{
    //freopen("a.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>h>>w>>k;
    for(int i=1;i<=h;i++)for(int j=1;j<=w;j++)cin>>mp[i][j];
    for(int i=1;i<=h;i++)for(int j=1;j<=w;j++)sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+(mp[i][j]=='1');
    int ans=h*w*10;
	for(int S=0;S<(1<<h);S++){
		int tmp=solve(0,S)+count(S);
		//cout<<tmp<<"\n";
		ans=min(ans,tmp);
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 384
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  n = int(input())
  su_ = 0
  tmp = n
  for _ in range(n):
    su_ += tmp % 10
    tmp //= 10
    if tmp == 0:
      break
  if n % su_ == 0:
    print('Yes')
  else:
    print('No')
    
if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>

int main(void) {
  int n, i, x=0, x_2=0, t;
  scanf("%d", &n);
  for(i=0; i<n; i++) {
    scanf("%d", &t);
    x += t;
    x_2 += (int)pow(t, 2);
  }
  int p = (int)round((double)x/n);
  printf("%d\n", x_2 - 2*p*x + n * (int)pow(p, 2));
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m,a;
    cin>>n>>m;
    vector<P>cb(m+n);
    rep(i,0,n){
        cin>>cb[i].first;
        cb[i].second=1;
    }
    rep(i,n,m+n){
        cin>>cb[i].second>>cb[i].first;
    }
    sort(lla(cb));
    int ans = 0,tmp = n;
    rep(i,0,m+n){
        if(cb[i].second<=tmp){
            ans += cb[i].first*cb[i].second;
            tmp-=cb[i].second;
        }
        else{
            ans+=tmp*cb[i].first;
            tmp=0;
        }
        if(tmp==0){break;}
    }
    cout<<ans<<"\n";
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    int N; cin >>N;
    string S, T; cin >> S >> T;

    rep(i, N) {
        cout << S[i] << T[i];
    }
    cout << endl;
}


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

int main() {
  int N;
  int p=0;
  int w=0;
  int g=0;
  int y=0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    if(s=="P")
      p++;
    else if(s=="W")
      w++;
    else if(s=="G")
      g++;
    else if(s=="Y")
      y++;
  }
  if(y>=1)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =1e5+10;
const int mod=1e9+7;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    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<<'\n';



}


Measured memory_bytes: 3652
#include <iostream>

int n;
int cmb;
int dp[31];

/*
int func(int now){
  if(now > n)
    return 0;
  if(now == n){
    dp[now] = 1;
    return 1;
  }


  return func(now+1) + func(now+2) + func(now+3);
}
*/

int func(int now){
  int a[3];
  if(now < 0){
    return 0;
  }
  if(now == 0){
    return 0;
  }
  if(now == 1){
    return 1;
  }
  if(now == 2){
    return 2;
  }
  if(now == 3){
    return 4;
  }

  for(int i=1; i <= 3; i++){
    if(dp[now-i] != -1){
      a[i-1] = dp[now-i];
    }else{
      a[i-1] = func(now-i);
      dp[now-i] = a[i-1];
    }
  }

  return a[0] + a[1] + a[2];

}

int main(void){
  while(1){
    int ans;
    std::cin >> n;

    for(int i=0; i < 31; i++){
      dp[i] = -1;
    }

    if(n == 0){
      return 0;
    }

    cmb = 0;
    ans = func(n);

    std::cout << ans / 10 / 365 + 1 << std::endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int m1,d1,m2,d2;cin>>m1>>d1>>m2>>d2;
    if(m1!=m2)cout<<1<<endl;
    else cout<<0<<endl;
}


Measured memory_bytes: 256
Scanf.scanf "%d %d %d %d" (fun n a b c ->
    let s = Array.init n (fun _ -> Scanf.scanf " %s" (fun s -> s)) in 
    let ans = Array.make n "" in

    let rec loop i a b c =
        if i = n then true else
            match s.(i) with
            | "AB" -> if a = 0 && b = 0 then false else
                      if a = 0 then (ans.(i) <- "A";    loop (i + 1) (a + 1) (b - 1) c) else
                      if b = 0 then (ans.(i) <- "B";    loop (i + 1) (a - 1) (b + 1) c) else
                                    (ans.(i) <- "A"; if loop (i + 1) (a + 1) (b - 1) c then true else 
                                    (ans.(i) <- "B";    loop (i + 1) (a - 1) (b + 1) c))
            | "BC" -> if b = 0 && c = 0 then false else
                      if b = 0 then (ans.(i) <- "B";    loop (i + 1) a (b + 1) (c - 1)) else
                      if c = 0 then (ans.(i) <- "C";    loop (i + 1) a (b - 1) (c + 1)) else
                                    (ans.(i) <- "B"; if loop (i + 1) a (b + 1) (c - 1) then true else 
                                    (ans.(i) <- "C";    loop (i + 1) a (b - 1) (c + 1)))
            | "AC" -> if a = 0 && c = 0 then false else
                      if a = 0 then (ans.(i) <- "A";    loop (i + 1) (a + 1) b (c - 1)) else
                      if c = 0 then (ans.(i) <- "C";    loop (i + 1) (a - 1) b (c + 1)) else
                                    (ans.(i) <- "C"; if loop (i + 1) (a - 1) b (c + 1) then true else 
                                    (ans.(i) <- "A";    loop (i + 1) (a + 1) b (c - 1)))
            | _ -> failwith "??"

    in
    if loop 0 a b c then (print_endline "Yes"; Array.iter print_endline ans)
                    else print_endline "No"
)

Measured memory_bytes: 13928
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vec<int> H(N);
    for(int i=0;i<N;i++) cin >> H[i];
    vec<int> ma(N,-1);
    for(int i=0;i<M;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        ma[a] = max(ma[a],H[b]);
        ma[b] = max(ma[b],H[a]);
    }
    int ans = 0;
    for(int i=0;i<N;i++) ans += H[i]>ma[i];
    cout << ans << "\n";
}

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

using namespace std;
class CompareFirst
{
public:
  bool operator()(pair<int,int> n1,pair<int,int> n2) {
    return n1.first>n2.first; //>:desc <:asc
  }
};


int main(){

  string s;
  int i,j,k,l,n,m;
  vector<string> vs;
  vector<int> vi;
  pair<int,int> pr;
  //unordered_map<string,int> mp;
  //priority_queue<int> pq; // default ‘å‚«‚¢‡
  //priority_queue<pair<int,int>,vector<pair<int,int>>,CompareFirst> pq;

  cin >> n;
  
  long a[n+1],b[n],ans=0.0;
  
  rep(i,0,n)cin >> a[i]; 
  rep(i,0,n-1)cin >> b[i];
  
  rep(i,0,n-1){
    if(b[i]==0)continue;
    if(b[i] <= a[i]){
      ans += b[i];
      continue;
    }
    if(b[i] <= a[i] + a[i+1]){
      ans += b[i];
      b[i] -= a[i];
      a[i+1] -= b[i];
      continue;
    }
    ans += a[i]+a[i+1];
    a[i+1]=0;
  }

  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N, T; cin >> N >> T;
    vector<int> ts(N); for(auto &ti : ts) cin >> ti;
    int ans = 0;
    int start = 0, stop = T;
    for(int i = 1; i < N; ++i)
    {
        int ti = ts[i];
        if(stop < ti)
        {
            ans += stop - start;
            start = ti;
            stop = ti + T;
        }
        else
        {
            stop = ti + T;
        }
    }
    ans += stop - start;
    cout << ans << endl;
}


Measured memory_bytes: 3964
// ctrl+shift+b
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll A, B; cin >> A >> B;
    cout << (A - 1) * (B - 1) << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3576
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if ((a*b) % 2 == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
   string s; cin>>s;
   int n=s.length();
   string ans;
   for(int i=0;i<n;i+=2){
      if(s[i]=='L') ans="No";
   }
   for(int i=1;i<n;i+=2){
      if(s[i]=='R') ans="No";
   }
   if(ans=="No") cout<<ans<<endl;
   else cout<<"Yes"<<endl;
   return 0;
}



Measured memory_bytes: 256
/*****************************************************
 				*	Logged in : HABIBUR RAHMAN						 *
				*	Dept	  : COMPUTER SCIENCE AND ENGINEERING	 *
				*													 *
				*	KHULNA UNIVERSITY OF ENGINEERING AND TECHNOLOGY  *
				******************************************************/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<string> vs;
typedef pair<ll,ll> pll;
#define fast_io 			ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) 				v.begin(),v.end()
#define allr(v) 			v.rbegin(),v.rend()
#define rep(i,a,b) 			for(ll i=a;i<=b;i++)
#define rep0(i,n)			for(ll i=0;i<n;i++)
#define rrep0(i, n) 		for(ll i=(ll)(n);i>0;--i)
#define rrep(i, a, b) 		for(ll i=(ll)(a);i>=(ll)(b);--i)
#define pb(z) 				emplace_back(z)
#define ff					first
#define ss 					second
#define caset 				int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define sz(X) 				((ll)(X).size())
#define scan(X) 			scanf("%s", (X))
#define ms(v,val)			memset((v),(val),sizeof((v)))
#define ms0(X) 				memset((X), 0, sizeof((X)))
#define ms1(X) 				memset((X), -1, sizeof((X)))
#define m_p(a,b)            make_pair(a,b)
#define get_pos(c,x) 		(lower_bound(c.begin(),c.end(),x)-c.begin())
#define lcm(a,b)            (a*b)/__gcd(a,b)
#define INF9                1000000010
#define INF18               4000000000000000010
#define bpll(a)             __builtin_popcountll(a)
#define sqr(a)              ((a)*(a))
#define nl					"\n"
//#define mod					1e9+7;
#define mx_el(v)			*max_element(all(v));
#define mn_el(v)			*min_element(all(v));
#define pcase(z,x)    		cout<<"Case "<<z<<": "<<x<<"\n"
const double pi = 2*acos(0) ;
#define display(v)			vi :: iterator it;for(it=(v).begin();it!=(v).end();it++){cout << *it << " " ;}cout << endl;
#define taking(n,v) 		for(ll i=0;i<(n);i++){ll inp;cin>>inp;(v).push_back(inp);}
/*-------------------------some important functions--------------------------------------------------------------------*/
ull binpow(ull b,ull n){if(n==0)return 1;if(n==1)return b;if(n&1) return binpow(b,n-1)*b;else return binpow(b*b,n/2);}
ll bigmod(ll a,ll n,ll mod){if(n==0)return 1;ll res=bigmod(a,n/2,mod);if(n&1){return ((res%mod)*(res%mod)*a)%mod;}else return ((res%mod)*(res%mod))%mod;}
/*--------------------------------------------x----------------------------------------------x--------------------------*/
void start(){
      #ifndef ONLINE_JUDGE 
      freopen("input.txt" , "r" , stdin) ;
      freopen("output.txt" , "w" , stdout) ;
      #endif
}
void solve(){
	ll n;cin>>n;
	unordered_map<string,int>mp;
	for(auto x:{"AC","WA","TLE","RE"}){
		mp[x]=0;
	}
	while(n--){
		string s;cin>>s;
		mp[s]++;
	}
	for(auto x:{"AC","WA","TLE","RE"}){
		cout << x << " " << "x" << " " << mp[x] << nl;
	}
}
 	 
int main() {
	fast_io
	//start();
    //caset{
    	//cout << "Case " << tt << ": ";
		  solve();
	//}
	
	return 0;
}

Measured memory_bytes: 3672
from collections import deque

H,W = map(int,input().split())
s = [['#'] * (W+2) for i in range(H+2)]
black = 0
for h in range(H):
    S = input()
    for w in range(W):
        s[h+1][w+1] = S[w]
        if S[w] == '#':
            black += 1

dxy = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def bfs(gh,gw):
    st = deque()
    sts = deque()
    push,pop = st.append, st.pop
    pushs,pops = sts.append, sts.pop
    cnt = 1
    push([-1,-1])
    pushs([-1,-1])
    push([1,1])
    g = 0
    while g < 1:
        t = 0
        for i in range(999999):
            now = pop()
            if now == [-1,-1]:
                push([-1,-1])
                break
            pushs(now)
        cnt += 1
        c = 0
        while t < 1:
            now = pops()
            #print(now,c)
            if now == [-1,-1]:
                if c == 0:
                    return -1
                    break
                pushs([-1,-1])
                t = 1
                break
            c = 1

            
            for dx,dy in dxy:
                if s[now[0]+dx][now[1]+dy] == '#':
                    continue
                if [now[0]+dx,now[1]+dy] == [gh,gw]:
                    g = 1
                    #print(cnt,black)
                    return H*W-black-cnt
                if s[now[0]+dx][now[1]+dy] == '.':
                    push([now[0]+dx,now[1]+dy])
                    s[now[0]+dx][now[1]+dy] = '#'

print(bfs(H,W))

Measured memory_bytes: 41328
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int X;
int n, q;
const int N = 200000;
int ri[N];
struct P3
{
    LL a, b, c;
} L[N];
P3 change(P3 a, int d)
{
    if (d <= 0)
    {
        if (a.c + d >= 0) return (P3){a.a, a.b, a.c + d};
        else if (a.c + a.b + d >= 0) return (P3){a.a + (-d) - a.c, a.b + a.a - (a.a + (-d) - a.c), 0};
        else return (P3){X, 0, 0};
    }
    else
    {
        if (a.c + a.b + d <= X) return (P3){a.a, a.b, a.c + d};
        else if (a.c + d <= X) return (P3){a.a, X - d - a.c, a.c + d};
        else return (P3){X, 0, X};
    }
}
int main()
{
    cin >> X >> n;
    L[0] = (P3){0, X, 0};
    for (int i = 1; i <= n; ++ i)
    {
        cin >> ri[i];
        if (i & 1) L[i] = change(L[i - 1], -(ri[i] - ri[i - 1]));
        else L[i] = change(L[i - 1], ri[i] - ri[i - 1]);
    }
    cin >> q;
    while (q --)
    {
        int t, a;
        cin >> t >> a;
        P3 nw;
        int p = upper_bound(ri, ri + n + 1, t) - ri - 1;
        if ((p + 1) & 1) nw = change(L[p], -(t - ri[p]));
        else nw = change(L[p], t - ri[p]);
        if (a <= nw.a) cout << nw.c;
        else if (a <= nw.a + nw.b) cout << nw.c + (a - nw.a);
        else cout << nw.c + nw.b;
        cout << endl;
    }

}


Measured memory_bytes: 5632
#import math
#def main(S, b):
if __name__ == '__main__':
    s, w = map(int, input().split())

    # a = list(map(int, input().split()))

    # s = sum(a)

    if (w >= s):
        print("unsafe")
    else:
        print("safe")

    #print(n * 2 * pi)


Measured memory_bytes: 9156
#include <iostream>
#include <vector>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define endl "\n" // TODO: remove
#define int long long

const int N = (int)(1e6) + 322;
const int inf = (int)(2e18);
const int mod = (int)(1e9) + 7; // check modulo


void solve() {
    int x; cin >> x;
    if (x <= 599) {
        cout << 8;
        return;
    }
    if (x <= 799) {
        cout << 7;
        return;
    }
    if (x <= 999) {
        cout << 6;
        return;
    }

    if (x <= 1199) {
        cout << 5;
        return;
    }
    if (x <= 1399) {
        cout << 4;
        return;
    }
    if (x <= 1599) {
        cout << 3;
        return;
    }
    if (x <= 1799) {
        cout << 2;
        return;
    }
    if (x <= 1999) {
        cout << 1;
        return;
    }
}

signed main () {
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("travel_restrictions_input.txt", "r", stdin);
//    freopen("A.out", "w", stdout);
//    int test; cin >> test;
//    for(int t = 1; t <= test; ++t) {
//        cout << "Case #" << t << ":" << endl;
        solve();
//    }
    return 0;
}



Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=998244353;
int dp[4][310*310],a[310];
inline int add_mod(int x){
	return x<mod?x:x-mod;
}
int main(){
	int n,ret=1,sum=0,minus=1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		ret=(ll)ret*3%mod;
		minus=add_mod(minus+minus);
		sum+=a[i];
	}
	ret=add_mod(ret+mod-3);
	minus=add_mod(minus+mod-2);
	ret=add_mod(ret+mod-(ll)minus*3%mod);
	memset(dp,0,sizeof dp);
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=sum;j>=a[i];j--){
			for(int s=0;s<4;s++){
				dp[s|1][j]=add_mod(dp[s|1][j]+dp[s][j-a[i]]);
				dp[s|2][j]=add_mod(dp[s|2][j]+dp[s][j-a[i]]);
			}
		}
	}
	for(int i=1;i+i<=sum;i++)
		ret=add_mod(ret+mod-(ll)dp[3][i]*3%mod);
	printf("%d\n",ret);
	return 0;
}

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

using namespace std;

complex<double> naive(vector<double> angles) {
    int n = (int) angles.size();
    complex<double> total_sum(0);
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                total_sum += polar(1., (angles[i]+angles[j])/2) + polar(1., (angles[j]+angles[k])/2) - polar(1., (angles[i]+angles[k])/2);
            }
        }
    }
    return total_sum / ((double) n * (n-1) * (n-2) / 6);
}

complex<double> smart(vector<double> angles) {
    int n = (int) angles.size();
    complex<double> ij_sum;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            ij_sum += polar(1., (angles[i]+angles[j])/2) * ((double) (n-j-1));
        }
    }
    complex<double> jk_sum;
    for (int j = 0; j < n; ++j) {
        for (int k = j + 1; k < n; ++k) {
            jk_sum += polar(1., (angles[j]+angles[k])/2) * ((double) j);
        }
    }
    complex<double> ik_sum;
    for (int i = 0; i < n; ++i) {
        for (int k = i + 1; k < n; ++k) {
            ik_sum += polar(1., (angles[i]+angles[k])/2) * ((double) k-i-1);
        }
    }
    complex<double> total_sum = ij_sum + jk_sum - ik_sum;
    return total_sum / ((double) n * (n-1) * (n-2) / 6);
}

complex<double> simpler(vector<double> angles) {
    int n = (int) angles.size();
    complex<double> total_sum;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            total_sum += polar(1., (angles[i]+angles[j])/2) * ((double) n - 2*j + 2*i);
        }
    }
    return total_sum / ((double) n * (n-1) * (n-2) / 6);
}

complex<double> faster(vector<double> angles) {
    int n = (int) angles.size();
    complex<double> simple_sum, square_sum, total_sum;
    complex<double> running_i, running_i_sq;
    for (int i = 0; i < n; ++i) {
        simple_sum += polar(1., angles[i]/2);
        square_sum += polar(1., angles[i]);
        total_sum += 4. * running_i * polar(1., angles[i]/2);
        running_i += polar(1., angles[i]/2) * ((double) i);
        running_i_sq += polar(1., angles[i]) * ((double) i);
    }
    total_sum += (simple_sum*simple_sum - square_sum) * ((double) n / 2.);
    total_sum -= 2. * running_i * simple_sum - 2. * running_i_sq;
    return total_sum / ((double) n * (n-1) * (n-2) / 6);
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, L;
    cin >> n >> L;
    double pi = atan(1)*4;
    vector<double> angles(n);
    for (auto& angle : angles) {
        cin >> angle;
        angle *= 2*pi/L;
    }
    complex<double> result = faster(angles);
    cout << setprecision(20) << real(result) << " " << imag(result) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int x[210000];
int v[210000];
pair<int,int> p[210000];
pair<int,int> q[210000];
int segtree[2][524288];
int query(int a,int b,int c,int d,int e,int f){
	if(d<a||b<c){
		if(f==0)return mod;
		return 0;
	}
	if(c<=a&&b<=d)return segtree[f][e];
	if(f==0){
		return min(query(a,(a+b)/2,c,d,e*2,f),query((a+b)/2+1,b,c,d,e*2+1,f));
	}
	return max(query(a,(a+b)/2,c,d,e*2,f),query((a+b)/2+1,b,c,d,e*2+1,f));
}
void update(int a,int b,int c){
	a+=262144;
	while(a){
		if(c==0)segtree[c][a]=min(segtree[c][a],b);
		else segtree[c][a]=max(segtree[c][a],b);
		a/=2;
	}
}
int L[210000];
int R[210000];
int rev[210000];
pair<int,int>z[210000];
long long dp[210000];
long long sum[210000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d%d",x+i,v+i);
		p[i]=make_pair(x[i],v[i]);
	}
	std::sort(p,p+a);
	for(int i=0;i<a;i++){
		q[i]=make_pair(p[i].second,i);
	}
	std::sort(q,q+a);
	for(int i=0;i<a;i++)rev[q[i].second]=i;
	for(int i=0;i<524288;i++){
		segtree[0][i]=mod;
		segtree[1][i]=0;
	}
	for(int i=0;i<a;i++){
		update(i,q[i].second,0);
		update(i,q[i].second,1);
	}
	for(int i=0;i<a;i++){
		L[i]=query(0,262143,rev[i],a-1,1,0);
		R[i]=query(0,262143,0,rev[i],1,1);
		z[i]=make_pair(L[i],R[i]);
	//	printf("%d %d\n",L[i],R[i]);
	}
	std::sort(z,z+a);
	int at=0;
	int need=-1;
	for(int i=0;i<a;i++){
		while(at<a&&z[at].second<i){
			need=z[at].first;
			at++;
		}
		if(need==-1)dp[i]=(1+sum[i])%mod;
		else dp[i]=(dp[i]+mod+sum[i]-sum[need])%mod;
		sum[i+1]=(sum[i]+dp[i])%mod;
	}
	while(at<a){
		need=z[at].first;at++;
	}
	printf("%lld\n",(sum[a]+mod-sum[need])%mod);
}

Measured memory_bytes: 16512
# A=gets.to_i
# B=gets.split.map(&:to_i)
# C=N.times.map{gets.to_i}
# D=N.times.map{gets.split.map(&:to_i)}
# S=gets.chomp
# MOD=1000000007


A,B=gets.split.map(&:to_i)

puts [A+B,A-B,A*B].max

Measured memory_bytes: 1916
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine(); line = sc.nextLine();
String s[]=line.split(" ",0);
int num=s.length;
int m[]=new int[num];
double ans=0.0;
for(int i=0;i<num;i++){
m[i]=Integer.parseInt(s[i]);
ans+=m[i];
}
ans/=num;
int ans2=(int)ans;
if(ans%1>0.5){
ans2=(int)ans+1;
}
int an=0;
for(int i=0;i<num;i++){
an+=(m[i]-ans2)*(m[i]-ans2);
}
System.out.println(an);
}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A, B;
    cin >> A >> B;

    int s = 1, rev = 0;
    while (s < B) {
        s += A - 1;
        rev++;
    }

    cout << rev << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main() {
    int i, n, f[45];
    scanf("%d", &n);
    f[0] = 1, f[1] = 1;
    for (i = 2; i <= n; i++) {
        f[i] = f[i-1] + f[i-2];
    }
    printf("%d\n", f[n]);
     
    return 0;
}


Measured memory_bytes: 2052
#define _USE_MATH_DEFINES  // M_PI等のフラグ

#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>

#define MOD 1000000007
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

string replace_with_str(string str, string str_from, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(str_from, pos), pos != string::npos) {
        str.replace(pos, str_from.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

void solve(){
    long long N, P;
    cin >> N >> P;

    if(N == 1){
        cout << P << endl;
        return;
    }

    vector<long long> v(1, 1);
    v[0] = P;
    long long p = 2;
    long long ans = 1;

    while(true){
        if(p >= v[0]){
            break;
        }

        long long tmp = v[0];
        bool flag = true;
        for(int i=0; i<N; i++){
            if(tmp%p == 0){
                tmp = tmp/p;
            }
            else{
                flag = false;
                break;
            }
        }

        if(!flag){
            p++;
            continue;
        }

        v[0] = tmp * p;
        ans *= p;
    }

    cout << ans << endl;
    return;
}

int main(int argc, char const *argv[]){
    #define BIG_NUM 1000001 // 10**6 + 1
    long long N, P;
    scanf("%lld %lld", &N, &P);

    if(N == 1){
        cout << P << endl;
        return 0;
    }
    if(P == 1){
        cout << P << endl;
        return 0;
    }

    long long p = 2;
    long long ans = 1;

    while(true){
        if(p >= P){
            break;
        }

        if(p >= BIG_NUM){
            // 2乗した時点でPより大きくなる
            break;
        }
        if(N >= 40){
            // 40以上で10**12を超えるの確定
            break;
        }
        long long pn = pow(p, N);
        if(pn < 0 || pn > 1000000000000){
            // 10**12を超えてたら捨ててよい
            // オーバーフローしてたらpn>P確定なので捨ててよい
            break;
        }
        if(pn > P){
            break;
        }


        while(true){
            if(P%pn == 0){
                P = (long long)(P/pn);
                ans *= p;
            }
            else{
                break;
            }
        }
        p++;
    }

    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256