akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
ll fact(int n) {
  ll ret{1};
  for (int i = 1; i <= n; ++i) ret = ret * i % MOD;
  return ret;
}
int main() {
  ll N, M, ans{};
  cin >> N >> M;
  if (abs(M - N) < 2) {
    ans = fact(M) % MOD * fact(N) % MOD;
    if (M == N) ans = 2 * ans % MOD;
  }
  cout << ans << endl;
}


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

using namespace std;

const int MAXN = 105;

int n, sol;
int a[MAXN];

int f (int x) {
    int res = 0;
    for (int i=0; i<n; i++) {
        res += (a[i] - x) * (a[i] - x);
    }
    return res;
}

int main () {
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        sol += a[i];
    }
    sol /= n;
    cout << min(f(sol), f(sol + 1));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int N; cin >> N;
	if (N%10 == 3) cout << "bon" << endl;
	else if (N%10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8) cout << "pon" << endl;
	else cout << "hon" << endl;
	return 0;
}


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

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

int main() {
    int n; cin >> n;
    int ans = 0;
    REP(i, n){
        int a; cin >> a;
        ans += a - 1;
    }
    cout << ans;
}

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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define output(x) cout << ( x ? "YES" : "NO" ) << '\n' ;
#define mxn 200005
using namespace std;


int n,m,cnt = 0,ans = 0;
vector<int> a[mxn];
vector<int> vis(mxn);
map<pair<int,int>,int> mp;

void dfs(int u)
{
    cnt++;
    vis[u] = 1;
    for(int i : a[u])
    {
        if(!vis[i])
        {
            dfs(i);
        }
    }
}

void solve(){
    cin >> n >> m ;
    for(int i = 0; i < m; i++){
        int u,v;
        cin >> u >> v;
        if(mp[{u,v}] == 1);
        else{
            a[u].pb(v);
            a[v].pb(u);
            mp[{u,v}] = 1;
            mp[{v,u}] = 1;
        }
    }
    for(int i = 1; i <= n; i++){
        if(vis[i] == 0){
            cnt = 0;
            dfs(i);
            ans = max(ans,cnt);
        }
    }
    cout << ans ;
}

int32_t main()
{
    FLASH
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 47012
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
class DIJ{
	public:
	struct edge{
		int to,cost;
	};
	vector<vector<edge> >G;
	int n,L;
	vvi d;//distance
	vi ok;
	DIJ(int size,int l){
		n=size;
		L=l;
		ok=vi(n);
		G=vector<vector<edge> >(n);
	}
	void add(int a){
		ok[a]=true;
	}
	void add_edge(int a,int b,int c){
		edge e={b,c},ee={a,c};
		G[a].pb(e);
		G[b].pb(ee);
	}
	void dij(int s){
		d=vvi(n,vi(L+1,inf));
		d[s][L]=0;//now oktime ->time
		priority_queue<pip>q;
		q.push(pip(0,pii(s,L)));//time now oktime
		while(!q.empty()){
			pip p=q.top();
			q.pop();
			int pos=p.second.first,cost=-p.first,nu=p.second.second;
			if(cost>d[pos][nu])continue;
			rep(i,G[pos].size()){
				edge e=G[pos][i];
				int to=e.to;
				int nowcost=cost+e.cost;
				int nownu=nu-e.cost;
//				cout<<to<<" "<<nowcost<<" "<<nownu<<endl;
				if(nownu<0)continue;
				rep(j,L-nownu+1){
//					if(nownu+j==0)continue;
					if(nowcost+j<d[to][nownu+j]){
						d[to][nownu+j]=nowcost+j;
						q.push(pip(-nowcost-j,pii(to,nownu+j)));
					}
					if(ok[to]==0)break;
				}
			}
		}
	}
};
int main(){
	int n,m,l,k,s,g;
	while(cin>>n>>m>>l>>k>>s>>g,n){
		DIJ dij(n,m);
		rep(i,l){
			int a;cin>>a;
			dij.add(a);
		}
		while(k--){
			int a,b,c;
			cin>>a>>b>>c;
			dij.add_edge(a,b,c);
		}
		dij.dij(s);
		int out=inf;
		rep(i,m+1)out=min(out,dij.d[g][i]);
		if(out!=inf)cout<<out<<endl;
		else cout<<"Help!"<<endl;
	}
}

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

int main(){
  int n,icnt[100000] = {},jcnt[100000] = {};
  string s;
  cin >> n;
  cin >> s;
  if(s[0] == 'J') jcnt[0]++;
  for(int i = 1;i < n;i++){
    jcnt[i] = jcnt[i - 1];
    if(s[i] == 'J') jcnt[i]++;
  }
  if(s[n - 1] == 'I') icnt[n - 1]++;
  for(int i = n - 2;i >= 0;i--){
    icnt[i] = icnt[i + 1];
    if(s[i] == 'I') icnt[i]++;
  }
  long long int maxij = 0,maxnum[3] = {};
  for(int i = 0;i < n;i++){
    long long int ij = icnt[i] * jcnt[i];
    if(s[i] == 'O') {
      maxnum[1] += ij;
      maxnum[0] += (icnt[i] + 1) * jcnt[i];
      maxnum[2] += icnt[i] * (jcnt[i] + 1);
    }
    maxij = max(ij,maxij);
  }
  maxnum[1] += maxij;
  cout << max(max(maxnum[0],maxnum[1]),maxnum[2]) << endl;
  return 0;
}

Measured memory_bytes: 4096
import sys
import bisect
import itertools as it
def LI(): return [int(x) for x in sys.stdin.readline().split()]


n, x = LI()
a = LI()
a.sort()
if x == sum(a):
    print(n)
elif x > sum(a):
    print(n-1)
else:
    i = bisect.bisect_right([y for y in it.accumulate(a)], x)
    print(i)


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

int main() {
	int c[3][3];
	for (int i = 0;i < 9;i ++) cin >> c[i / 3][i % 3];
	for (int i = 0;i < 2;i ++) {
		for (int j = 0;j < 2;j ++) {
			if (c[i][j] - c[i][j + 1] != c[i + 1][j] - c[i + 1][j + 1]) {
				cout << "No";
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

まず、a_1を0とする
この時b_1=c_11、b_2=c_12、b_3=c_13となる
その時、c_21とc_22とc_23の差は式よりc_11とc_12とc_13に等しい c_3jも同様
上が成立するなら全てのaとbのパターンが存在するし、成立しないなら矛盾がある
よってこれは必要十分条件を満たす
*/

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

int main()
{
	int N;
	cin >> N;
	vector<int> d(N);
	for (int i = 0; i < N; i++)
	{
		cin >> d.at(i);
	}
	sort(d.begin(), d.end());

	int dansuu = 1;
	int ue = d.at(0);
	for (int i = 1; i < N; i++)
	{
		if (ue < d.at(i))
			dansuu++;
		ue = d.at(i);
	}
	cout << dansuu << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
     
long long int N, total;
std::vector<bool> flag;
std::vector<long long int> sosu;
std::vector<long long int> sosu_num;

int main() {
  std::cin >> N;
  for (int i = 0; i <= std::sqrt(N); i++) {
    flag.push_back(true);
  }

  // 素数判定
  long long int n = N;
  flag[0] = false;
  flag[1] = false;
  for (int i = 2; i <= std::sqrt(N); i++) {
    if (flag[i] == true) {
      for (int j = i * 2; j <= std::sqrt(N); j += i) {
        flag[j] = false;
      }
    }
  }

  // 素数格納
  for (int i = 2; i <= std::sqrt(N); i++) {
    if (flag[i] == true) {
      long long int num = 0, count = 0, line = 1;
      while (n % i == 0) {
        n /= i;
        num++;
        if (num >= line) {
          num -= line;
          line++;
          count++;
        }
      }
      total += count;
    }
  }

  if (n != 1) {
    total++;
  }

  std::cout << total << std::endl;

  return 0;
}

Measured memory_bytes: 3812
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
const ll inf = 1e9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const ll MAX = 1e7 + 20;
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define rrep(i,a,n)     for(int i=a;i<=n;i++)
#define per(i,n,a)      for(int i=n;i>=a;i--)
#define pf(n)           printf("%lld",n)
#define pfi(n)          printf("%d",n)
#define sp              printf(" ")
#define ln              "\n"

#define pi acos(-1.0)
#define mod 1000000007

///Library
#define mem(a,b) memset(a,b,sizeof(a))
#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define SortA(ar,s) sort(ar,ar+s)
#define SortD(ar,s) sort(ar,ar+s,greater<int>())
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sq(x) (x)*(x)


///vector
#define Lower_bound(vec,value) lower_bound(vec.begin(),vec.end(),value)
#define Upper_bound(vec,value) upper_bound(vec.begin(),vec.end(),value)


/*template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
*/
int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast

    ll a,b;
    cin>>a>>b;
    if(500*a>=b)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,unroll-all-loops")
// #pragma GCC option("arch=native","tune=native")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")

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

#define f(_i, _n) for (auto _i = 0; _i < _n; _i++)
#define F(_i, _k, _n) for (auto _i = _k; _i < _n; _i++)
#define re return
#define pb push_back
#define all(_v) _v.begin(), _v.end()
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; }
#define fi first
#define se second

typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;

ll a[10050], b[10050];

int main() {
  int n;
  cin >> n;
  ll sum = 0;
  f(i, n) {
    cin >> a[i];
    sum -= a[i];
  }
  f(i, n) {
    cin >> b[i];
    sum += b[i];
  }
  ll cnta = 0;
  ll cntb = 0;
  f(i, n) {
    if (a[i] > b[i]) {
      cntb += a[i] - b[i];
    }
    if (a[i] < b[i]) {
      if ((b[i] - a[i]) & 1) {
        cntb++;
      }
      cnta += (b[i] - a[i] + 1) / 2;
    }
  }
  if (cnta <= sum && cntb <= sum) {
    cout << "Yes";
  } else {
    cout << "No";
  }

}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

int N,H,a,b,a_max_id=0,b_min_id=-1,t=0;
mp c[100010];

int main(void){
	scanf("%d%d",&N,&H);
	rep(i,N){
		scanf("%d%d",&a,&b);
		c[i]=make_pair(b,a);
	}
	sort(c,c+N);
	rep(i,N)if(c[a_max_id].second < c[i].second)a_max_id=i;

	rep(i,a_max_id){
		if(c[a_max_id].second >= c[i].first)b_min_id=i;//i番目は使わない
		else break;
	}
	ireg(i,b_min_id+1,N-1){
		H-=c[i].first;
		t++;
		if(H<=0)break;
	}
	if(H>0){
		t+=H/c[a_max_id].second;
		if(H%c[a_max_id].second!=0)t++;
	}
	printf("%d\n",t);

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pqll;
typedef priority_queue<vi> pqvi;
typedef priority_queue<vll> pqvll;
typedef priority_queue<int, vi, greater<int>> pqi_G;
typedef priority_queue<ll, vll, greater<ll>> pqll_G;
typedef priority_queue<vi, vvi, greater<vi>> pqvi_G;
typedef priority_queue<vll, vvll, greater<vll>> pqvll_G;

string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int n, m;
  cin >> n >> m;
  if (n == m) Yes();
  else No();
}

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


int top, S[10000];

void push(int x){
  S[++top] = x;
}

int pop(){
  top--;
  return S[top+1];
}

int main(void)
{
  int a, b;
  top = 0;
  char s[100];
  
  while(scanf("%s", s) != EOF){
    if ( s[0] == '+' ){
      a = pop();
      b = pop();
      push(a+b);
    }
    else if (s[0] == '-'){
      b = pop();
      a = pop();
      push(a-b);
    }
    else if (s[0] == '*'){
      b = pop();
      a = pop();
      push(a*b);
    }
    else{
      push(atoi(s));
    }
  } 
  printf("%d\n", pop() );
  return (0);
}



Measured memory_bytes: 2108
s = str(input())
mae = int(s[0:2])
ato = int(s[2:4])

if mae>0 and mae<13 and ato>0 and ato<13:
  print("AMBIGUOUS")
elif mae>0 and mae<13:
  print("MMYY")
elif ato>0 and ato<13:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3060
n = int(input())
a = list(map(int, input().split()))

allowed = True
for v in a:
    if v & 1 == 0:
        if v % 3 != 0 and v % 5 != 0:
            allowed = False
            break

if allowed:
    print("APPROVED")
else:
    print("DENIED")


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

int main(){
  int N;
  cin >> N;
  vector<double> A(N);
  double ans=0;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    ans+=1.0/A.at(i);
  }
  cout << 1.0/ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int64_t  n,k;
  cin >> n >> k;
  int64_t cnt = 0;
  while(n > 0){
    n = n / k;
    cnt++;
  }
  cout << cnt << endl;
}
    

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

ll gd(ll x, ll y) {
  if (x < y) return gd(y, x);

  if (x % y == 0)
    return y;
  else
    return gd(min(x, y), max(x, y) % min(x, y));
}

ll lm(ll x, ll y) { return (x * y) / gd(x, y); }

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  cout << b - a + 1 - (b / c - (a - 1) / c) - (b / d - (a - 1) / d) +
              (b / lm(c, d) - (a - 1) / lm(c, d))
       << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)(n);++i)
#define rep1(i, n) for (int i=1;i<=(int)(n);++i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=r-1;i>=(int)(l);--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using ll=long long;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

const int inf = 1e9 + 10;
const int mod = 1e9 + 7;

int A[1010][1010];
int dist[1010][1010];
int H, W;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, -1, 0, 1};

bool inside(int h, int w)
{
	return 0 <= h and h < H and 0 <= w and w < W;
}

signed main()
{
	cin >> H >> W;

	queue<pii> q;

	rep(i, H) rep(j, W) dist[i][j] = inf;

	rep(i, H) rep(j, W) {
		char c; cin >> c;
		A[i][j] = (c == '#');
		if (A[i][j]) {
			q.push(pii(i, j));
			dist[i][j] = 0;
		}
	}

	while (q.size()) {
		pii p = q.front(); q.pop();
		int y = p.fst, x = p.scd;

		rep(i, 4) {
			int ny = y + dy[i], nx = x + dx[i];

			if (inside(ny, nx) and dist[ny][nx] == inf) {
				dist[ny][nx] = dist[y][x] + 1;
				q.push(pii(ny, nx));
			}
		}
	}

	int mx = 0;

	rep(i, H) rep(j, W) chmax(mx, dist[i][j]);

	cout << mx << endl;
}



Measured memory_bytes: 32436
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

// 解説は条件付き期待値
// （ゲームの回数の期待値）= 
// Σ(ゲーム中AかBが出る回数がM回である確率(A Bは正規化する)) * (ゲーム中AかBが出る回数がM回である時に、Cが出る回数も含めた総合回数の期待値)
// https://www.creativ.xyz/best-of-2n-1-1080/


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

    int x, y; cin >> x >> y;
    int ans = 0;

    if(x == 3) ans += 1e5;
    if(x == 2) ans += 2e5;
    if(x == 1) ans += 3e5;
    if(y == 3) ans += 1e5;
    if(y == 2) ans += 2e5;
    if(y == 1) ans += 3e5;
    if(x == 1 && y == 1) ans += 4e5;

    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
from bisect import bisect_left

N = int(input())

cum = [0]
now = 1

while cum[-1] <= N:
    cum.append(now + cum[-1])
    now += 1

# print(len(cum))
# cum[i]; cum[i]までの数はiまでの和で表せる
idx = bisect_left(cum, N)
# print(cum, idx)
# idxまでの数の中から選んで和をNにする
ans = []
tmp = 0
i = idx
while i > 0:
    # print(i, tmp)
    tmp += i
    ans.append(i)
    if tmp == N:
        print(*ans)
        exit()
    elif tmp > N:
        tmp -= i
        i -= 1
        ans.pop()
    else:
        i -= 1


Measured memory_bytes: 9456
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
const long long MAXN = 2e5+5;
long long ans=1e18;
multiset<long long> a;
multiset<long long> b;
pair<long long,long long> arr[MAXN];
int main(){
    long long n;
    cin>>n;
    for(long long i=1;i<=n;i++){
        cin>>arr[i].first>>arr[i].second;
        if(arr[i].first>arr[i].second){
            swap(arr[i].first,arr[i].second);
        }
        a.insert(arr[i].first);
        b.insert(arr[i].second);
    }
    ans = (*a.rbegin()-*a.begin())*(*b.rbegin()-*b.begin());
    sort(arr+1,arr+n+1);
    for(long long i=1;i<=n;i++){
        long long x = arr[i].first;
        long long y = arr[i].second;
        a.erase(a.find(x));
        b.erase(b.find(y));
        a.insert(y);
        b.insert(x);
        ans = min(ans,(*a.rbegin()-*a.begin())*(*b.rbegin()-*b.begin()));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 24192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 210, mod = 998244353;
int n;
int x[N], y[N];
ll ans;
ll p[N];
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d%d", &x[i], &y[i]);
	p[0] = 1;
	for(int i = 1; i <= n; ++i) p[i] = (p[i - 1] << 1) % mod;
	ans = p[n] - n * (n - 1) / 2 - n - 1;
	for(int i = 1; i <= n; ++i)  
		for(int j = i + 1; j <= n; ++j)
		{
			int cnt = 0;   
			for(int k = j + 1; k <= n; ++k) if((y[k] - y[i]) * (x[k] - x[j]) == (y[k] - y[j]) * (x[k] - x[i])) ++cnt;
			ans = ((ans - p[cnt] + 1) % mod + mod) % mod;
		}
	cout << ans;
	return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    int K; cin>>K;
    int res = 1;
    int S = 7;
    if(K%2==0){
        cout<<-1<<endl;
        return 0;
    }
    while(S%K!=0){
        S = S*10 + 7;
        res++;
        S%=K;
        if(res>K+10){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2 ;
    int l1,l2;
    l1 = (x2 -x1);
    l2 = (y2 -y1);
    int x3,y3,x4,y4;
    x3 = x2 + (y1 -y2);
    y3 = y2 + (x2 -x1);
    x4 = x1 + (y1 -y2);
    y4 = y1 + (x2 -x1);
    double center_x_1,center_x_2,center_y_1,center_y_2;
    center_x_1 = (double)((x1+x3)/2);
    center_y_1 = (double)((y1+y3)/2);
    center_x_2 = (double)((x2+x4)/2);
    center_y_2 = (double)((y2+y4)/2);
    if((center_x_1!=center_x_2)||(center_y_1!=center_y_2)){
        cout << "error" << endl;
    }
    else{
        cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    }
}

Measured memory_bytes: 3592
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    ll a,b;
    cin>>a>>b;
    ll x;
    cin>>x;
    ll ans=0;
   ll aa=a/x+1;
   ll bb=b/x+1;
   ans=bb-aa;
   if(a%x==0){ans++;}
   cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;

	struct max_t
	{
		template<class T>T operator()(T&& lhs, T&& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>T operator()(T&& lhs, T&& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min(); 
}

void Main()
{
	std::string str;
	std::cin >> str;
	std::cout << (str == "ABC" ? "ARC" : "ABC") << std::endl;
}

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

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<LINE<<")"<<endl;
#define vdeb(x) {cout<<#x<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<" (L"<<LINE<<")"<<endl;}
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;

int main()
{
    ll M;
    cin >> M;
    vll d(M), c(M);
    rep(i, 0, M) {
        cin >> d[i] >> c[i];
    }
    ll tmp = accumulate(c.begin(), c.end(), 0LL);
    ll sm = 0;
    rep(i, 0, M) {
        sm += d[i] * c[i];
    }
//    sm = (sm-1) / 9;
    cout << tmp + (sm-1)/9 - 1 << endl;

}

Measured memory_bytes: 6340
//writer：Sakura
//problem：Plane 2N Points
//id：abc_092c
//from：Atcoder

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

struct RED{
	int x,y;
}red[105];

struct BLUE{
	int x,y;
}blue[105];

int n;
int colour[105];

bool cmp1(RED p,RED q){
	if(p.x==q.x)return p.y<q.y;
	return p.x<q.x;
}

bool cmp2(BLUE p,BLUE q){
	if(p.x==q.x)return p.y<q.y;
	return p.x<q.x;
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d",&red[i].x,&red[i].y);
	}
	for(int i=0;i<n;i++){
		scanf("%d %d",&blue[i].x,&blue[i].y);
	}
	//sort(red+1,red+1+n,cmp1);
	sort(blue,blue+n,cmp2);
	/*
	puts("");
	for(int i=1;i<=n;i++){
		printf("%d %d\n",red[i].x,red[i].y);
	}
	puts("");
	for(int i=1;i<=n;i++){
		printf("%d %d\n",blue[i].x,blue[i].y);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(red[i].x<blue[i].x && red[i].y<blue[i].y)ans++;
	}
	printf("%d\n",ans);*/
	//puts("");
	memset(colour,0,sizeof(colour));
	int ans=0;
	for(int i=0;i<n;i++){
		int Max=-1,id=-1;
		for(int j=0;j<n;j++){
			if(!colour[j] && red[j].x<blue[i].x && red[j].y<blue[i].y && red[j].y>Max){
				Max=red[j].y;
				id=j;
			}
		}
		if(Max!=-1){
			colour[id]=1;
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<int> cnt(N,0);
  int mx = 0;
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    cnt[a]++;
    chmax(mx,a);
  }
  bool can = true;
  if(mx%2){
    if(cnt[(mx+1)/2] != 2) can = false;
    for(int i=(mx+1)/2+1; i<=mx; i++){
      if(cnt[i] < 2) can = false;
    }
  }else{
    if(cnt[mx/2] != 1) can = false;
    for(int i=mx/2+1; i<=mx; i++){
      if(cnt[i] < 2) can = false;
    }
  }
  if(can){
    cout << "Possible\n";
  }else{
    cout << "Impossible\n";
  }
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

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

int main() {
  int n, a;
  cin >> n;
  REP(i, n){
    cin >> a;
    if (a % 2 == 0) {
      if (a % 3 == 0 || a % 5 == 0) {

      } else {
        cout << "DENIED";
        return 0;
      }
    }
  }
  cout << "APPROVED";
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max() / 2;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<Edge>>g;
vector<edge>edges;
vector<Pll>v;
map<string, LL>ma;
multiset<LL>st;
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans, a[210000], b[210000], d[10000];
string str, ss;
bool f[110000];
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
int main() {
	cin >> n >> m >> p;
	rep(i, m) {
		LL x, y, z;
		cin >> x >> y >> z;
		x--, y--;
		edges.push_back(edge{ x,y,-(z - p) });
	}
	rep(i, 10000)d[i] = INF;
	d[0] = 0;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < (int)edges.size(); j++) {
			struct edge e = edges[j];
			if (d[e.from] != INF)
				if (d[e.to] > d[e.from] + e.cost) {  //移動した後のコストが小さいと、頂点のコストを更新
					d[e.to] = d[e.from] + e.cost;
				}
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < (int)edges.size(); j++) {
			struct edge e = edges[j];
			if (d[e.from] != INF)
				if (d[e.to] > d[e.from] + e.cost) {  //移動した後のコストが小さいと、頂点のコストを更新
					d[e.to] = -INF;
				}
			if (d[e.from] == -INF) {
				d[e.to] = -INF;
			}
		}
	}
	if (-d[n - 1] == INF) {
		cout << -1 << endl;
	}
	else {
		cout << max(0LL, -d[n - 1]) << endl;
	}
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>

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

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

using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N,M;
    cin>>N>>M;
    vll a(M),b(M);
    for(ll i=0;i<M;i++){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
    }
    ll ans=0;
    for(ll i=0;i<M;i++){
        vll done(N,false);
        vll open;
        open.push_back(0);
        done[0]=true;
        while(open.size()>0){
            ll node=open[0];
            open.erase(open.begin());
            
            for(ll j=0;j<M;j++){
                if(j==i)continue;
                if(a[j]==node && !done[b[j]]){
                    open.push_back(b[j]);
                    done[b[j]]=true;
                }
                if(b[j]==node && !done[a[j]]){
                    open.push_back(a[j]);
                    done[a[j]]=true;
                }
            }
        }
        
        bool ok=true;
        for(ll j=0;j<N;j++){
            if(!done[j]){
                ok=false;
                break;
            }
        }
        if(!ok){
            ans++;
            //printf("i=%d\n",i);
        }
        
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int h, m, s;
	
	scanf("%d", &s);
	
	h = s / 3600;
	m = (s % 3600) / 60;
	s = (s % 3600) % 60;
	
	printf("%d:%d:%d\n", h, m, s);
	
	return (0);
}

Measured memory_bytes: 592
def examB():
    X = S()
    sumS = 0
    for i in X:
        sumS += int(i)
    judge = int(X)%sumS
    if judge==0:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)

import sys,copy,bisect,itertools
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()


Measured memory_bytes: 3520
def sec(m):
  hour = int(m[0:2])
  minute = int(m[3:5])
  second = int(m[6:8])
  s= 60 * 60 * hour + 60 * minute + second
  return s
  
p = 0
while p == 0:
  N = int(input())
  if N == 0:
    p = 1
    quit()
  time = [0] * (86500)
  for i in range(N):
    a, b = map(str, input().split())
    time[sec(a)] += 1
    time[sec(b)] -= 1
  ans = 1
  now = 0
  for i in range(len(time)):
    now += time[i]
    ans = max(ans, now)
  print(ans)
    
    


Measured memory_bytes: 6804
n=int(input())
if n<1000:
    print(1000-n)
else:
    str1=""
    k=n//1000
    l=len(str(n))-len(str(k))
    str1=str(k)+'0'*l
    if str1==str(n):
        print(0)
    else:
        p=int(str1)+1000
        print(p-n)

Measured memory_bytes: 9092
#include<iostream>
#include<string>

using namespace std;

int main(){

    string s; cin >> s;

    if(s=="hi" || s== "hihi" || s=="hihihi" || s=="hihihihi" || s=="hihihihihi"){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

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

int main(){
  string s,t; cin >> s >> t;
  int ps[130];
  int pt[130];
  memset(ps,0,sizeof(ps));
  memset(pt,0,sizeof(pt));
  for(int i=0; i<s.size(); i++){
    if(ps[s.at(i)]==0){
      if(pt[t.at(i)]==0||pt[t.at(i)]==s.at(i)){
        ps[s.at(i)] = t.at(i);
        pt[t.at(i)] = s.at(i);
      }else{
        cout << "No" << endl;return 0;
      }
    }else if(ps[s.at(i)]==t.at(i)){
      continue;
    }else{cout << "No" << endl;return 0;}
  }
  cout << "Yes" << endl;
}
  

Measured memory_bytes: 776
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {

    double r, s, l;
    const double pi = 3.141592653589;

    cin >> r;

    s = r * r * pi;
    l = 2 * r * pi;

    printf("%f %f\n", s, l);

    return 0;
}

Measured memory_bytes: 3280
import math
a=int(input())
b=[list(map(int,input().split())) for i in range(a)]
ans=0
def dist(i,j):
  return ((i[0]-j[0])**2+(i[1]-j[1])**2)**0.5

for i in range(a):
  for j in range(a):
    if i==j:
      continue
    else:
      ans+=dist(b[i],b[j])*math.factorial(a-1)
      
print(ans/math.factorial(a))

Measured memory_bytes: 38384
#include<stdio.h>

int main(){
  int i,n;
  int sum = 100000;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    sum=sum*1.05;
    if(sum%1000!=0)
      { 
	sum=sum/1000;
	sum=(sum+1)*1000;
      }
    
  }
  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 2568
n, h,w = gets.split(" ").map!{|i| i.to_i}
sum = 0
n.times do |j|
  c,d = gets.split(" ").map!{|o| o.to_i}
  if c >= h
    if d >= w
      sum += 1
    end
  end
end
puts sum

  

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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    s += "_"; // dummy
    
    int R[2] = {}, W[2] = {};
    for (int i=0; i<N; ++i) {
        if (s[i] == 'W') W[1] ++;
        else R[1] ++;
    }

    int mn = min(R[1], W[1]);

    for (int i=0; i<N; ++i) {
        if (s[i] == 'W') {
            W[0] ++;
            W[1] --;
        } else {
            R[0] ++;
            R[1] --;
        }
        mn = min(mn, W[0] + R[1] - min(W[0], R[1]));
    }
    cout << mn << endl;

    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    priority_queue<double, vector<double>, greater<double> > que;
    rep(i, n){
        int v; cin>>v;
        que.push((double)v);
    }
    while(que.size()>=2){
        double v1 = que.top(); que.pop();
        double v2 = que.top(); que.pop();
        que.push((v1+v2)/2);
    }
    cout<<setp(9)<<que.top()<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
signed main(){
    int x;cin>>x;
    int a; cin>>a;
    int b; cin>>b;
    cout<<(x-a)%b<<endl;
}


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

int main(void){
    char s[100010];
    int ans = 0;
    cin >> s;
    for (int i = 1; s[i] != '\0'; i++) {
        if (s[i - 1] != s[i]) ans++;
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 384
function main(input){
  const args=input.split("\n");
  const n=parseInt(args[0], 10);
  const arr=args[1].split(" ").map((n) => parseInt(n, 10));
  var ans=0;
  for(i=1; i<n-1; i++){
    if((arr[i-1]>=arr[i] && arr[i]>arr[i+1]) || (arr[i-1]<arr[i] && arr[i]<=arr[i+1])){
      ans++;
    }
  }
console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7372
N, K = [int(x) for x in input().split()]

d = {}

for i in range(N):
    a, b = [int(x) for x in input().split()]
    cnt = d.get(a, 0)
    d[a] = cnt + b

keys = list(d.keys())
keys.sort()

idx = 0
sum = 0
while sum + d[keys[idx]] < K:
    sum += d[keys[idx]]
    idx += 1
    # print("idx:{}, sum:{}".format(idx, sum))

print(keys[idx])


Measured memory_bytes: 10580
<?php
fscanf(STDIN, "%d %d", $N, $L);
$a = [];
$b = [];
for ($i = 0; $i < $N; $i++) {
    $t = $L + $i;
    $a[] = $t;
    $b[] = abs($t);
}
asort($b);
reset($b);
$first_key = key($b);
echo array_sum($a) - $a[$first_key];



Measured memory_bytes: 5112
#include<bits/stdc++.h>
using namespace std;
const int N=500005;
int n,q,a[N],l[N],r[N],b[N],c[N],ans[N];
vector<pair<int,int>>x[N];
void add(int x,int v)
{
	for(int i=x;i<=n;i+=i&(-i))
		b[i]+=v;
}
int sum(int x)
{
	int v=0;
	for(int i=x;i;i-=i&(-i))
		v+=b[i];
	return v;
}
int main()
{
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=q;i++)
	{
		scanf("%d%d",&l[i],&r[i]);
		x[r[i]].emplace_back(l[i],i);
	}
	for(int i=1;i<=n;i++)
	{
		if(c[a[i]])
			add(c[a[i]],-1);
		c[a[i]]=i;
		add(i,1);
		for(auto [u,v]:x[i])
			ans[v]=sum(i)-sum(u-1);
	}
	for(int i=1;i<=q;i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 37044
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
string s;
int k;
long long ans;

int main(){
	//freopen("input.txt","r",stdin);
	vector<int>v;
	char last = '-';
	cin >> s >> k;
	for(auto i : s)
		if(last == i)v.back()++;
		else{
			v.push_back(1);
			last = i;
		}
	if(v.size() == 1){
		printf("%lld\n",k*1LL*v.back()/2);
		return 0;
	}
	for(auto i : v)ans+=i/2;
	ans*=k;
	if(s[0] == s.back()){
		ans-=(v.back()/2 + v.front()/2)*(k - 1LL);
		ans+=(v.back() + v.front())/2*(k - 1LL);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int cnt = 0;
    REP(i, s.size())if(s[i] == 'o') cnt++;
    cout << 700 + 100 * cnt << endl;
    
    return 0;
}


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

int main()
{
    long long a, b, c;
    cin >> a >> b >> c;

    if (a > c)  {
        cout << a - c << " " << b << "\n";
    }
    else {
        if (a == c) {
            cout << 0 << " " << b << "\n";
        }
        else {
            cout << "0" << " ";
            if (a + b - c < 0)
                cout << 0 << "\n";
            else
                cout << a + b - c << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    map<string,int> m;
    int n;
    cin>>n;
    rep(i,n){
        string s;
        cin>>s;
        m[s]++;
    }
    vector<pair<int,string>> v;
    for(auto &&a:m){
        v.push_back({a.second*-1,a.first});
    }
    sort(v.begin(),v.end());
    int ma = v[0].first;
    rep(i,v.size()){
        if(v[i].first==ma) {
            cout << v[i].second << endl;
        }
    }




return 0;
}


Measured memory_bytes: 29428
import sys
#sys.exit()
#sorted( ,reverse=True)
#N = int(input())
N, K = map(int, input().split())
P = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]

#cnt = 0
#cnt += 1
P.sort()
ans=0
for i in range(K):
    ans += P[i]
    

#print(N)
#print(S,T)
#print(A)
#print('Yes')
#print('No')
print(ans)

Measured memory_bytes: 9252
#include <iostream>
#include<bits/stdc++.h>
 
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
 
const long long INF = 1LL << 60;
 
typedef long long ll;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
int main(){
    int n,m;
    cin >> n >> m;
    //vector<int> a;
    int cnt = 0;
    int tmp ;
    rep(i,m){
        cin >> tmp;
        cnt += tmp;
    }
    cout << max(n - cnt,-1) << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    //  cout << x << " ";
    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
int lcm(int a, int b)
{
    return (a * b) / __gcd(a, b);
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc;
    tc = 1;
    while (tc--)
    {
        int n;
        cin >> n;
        if (n % 2)
        {
            cout << 0;
            return 0;
        }
        int ans = 0;
        for (int i = 10; i <=n;i=i*5){
            //cout << i << " ";
            ans += n / i;
        }
            cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def judge(n, k, pre):
  if n > k:
    sa = n - k * (n // k)
  else:
    sa = k - n
  
  if sa > pre:
    return pre
  else:
    return judge(sa, k, sa)
    

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

print(judge(N, K, N))

Measured memory_bytes: 2940