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

using namespace std;
#define ll long long

int main()
{
  int n,m;
  cin>>n>>m;
  vector<int>a(n);
  int sum=0;
  for (int i=0;i<n;i++)
  {
          cin>>a[i];
      sum+=a[i];
  }
  sort(a.rbegin(),a.rend());
  for (int i=0;i<m;i++)
    if (a[i]<((double)sum/m)/4.0)
  {
      cout<<"No";
      return 0;
  }
  cout<<"Yes";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
 
using namespace std;
 
const int MAX_N = int(1e6) + 10;
const long long int MOD=1e9+7;
const long long int INF=1e18;
 
 
typedef long long int ll;
typedef unsigned long long int llu;


ll max(ll a,ll b){
	return a>b?a:b;
}
int main()
{
	ll n; cin>>n;
  map<int,int> m;
  for(int i=2;i<=sqrt(n);++i){
    if(n%i==0){
      while(n%i==0){
        n/=i;
        m[i]++;
      }
    }
  }
  if(n!=1){
    m[n]++;
  }
  ll cnt=0;
  ll a[10000]={0};
  a[1]=1;
  int sum=1;
  for(int i=2;i<=100;++i)a[sum+i]=a[sum]+1,sum+=i;
  for(int i=2;i<10000;++i)if(a[i]==0)a[i]=a[i-1];
  for(auto x: m){
    cnt=cnt+a[x.second];
  }
  cout<<cnt;
}

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

#define deb(x) cerr<<"["#x<<" : "<<x<<" ]\n";

int main()
{
	int n;
	cin >> n;
	int cnt = 0;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		while(x % 2 == 0) {
			x /= 2;
			cnt++;
		}
	}
	cout << cnt;
}


Measured memory_bytes: 3608
W,H,N=map(int,input().split())

# 左下の座標
X=Y=0

for i in range(N):
  # 入力
  x,y,a=map(int,input().split())

  if a==1:
    X=max(X,x)
  elif a==2:
    W=min(W,x)
  elif a==3:
    Y=max(Y,y)
  else:
    H=min(H,y)

# 出力
print(max(W-X,0)*max(H-Y,0))

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

long long int cnt;
int l;
int A[1000000];
int n;
vector<int>G;
//間隔Gを指定した挿入ソート
void insertSort(int A[], int n, int g) {
	for (int i = g;i < n;i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void ShellSort(int A[], int n) {
	//数列G={1,4,13,40,121,364,1093,...}を生成
	for (int h = 1; ;) {
		if (h > n)break;
		G.push_back(h);
		h = 3 * h + 1;
	}
	for (int i = G.size() - 1;i >= 0;i--) {//逆順にG[i]=gを指定
		insertSort(A, n,G[i]);
	}
}

int main() {
	cin >> n;
	//より速い入力scanf関数を使用
	for (int i = 0;i < n;i++)scanf("%d", &A[i]);
	cnt = 0;

	ShellSort(A, n);

	cout << G.size() << endl;
	for (int i = G.size() - 1;i >= 0;i--) {
		printf("%d", G[i]);
		if (i)printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for (int i = 0;i < n;i++)printf("%d\n", A[i]);

	return 0;
}


Measured memory_bytes: 7180
#include<bits/stdc++.h>
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	int n,k;
	cin>>n>>k;
	string str;
	cin>>str;
	string s;
	for(int i=0;i<n;i++)
	{
		//cout<<str[i]<<" ";
		if(i == k-1)
		{
			str[i] = str[i] + 32;
			//cout<<s<<endl;
		}
		//cout<<s<<endl;
	}
	for(int i=0;i<n;i++)
	{
		cout<<str[i];
	}
}

Measured memory_bytes: 256
#include <cstdio>

int sys5;
int sys7;

void Judge(int x)
{
    if(x == 5) sys5++;
    if(x == 7) sys7++;
}

int main()
{
    int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
    Judge(A);
    Judge(B);
    Judge(C);

    if(sys5 == 2 && sys7 == 1) printf("YES\n");
    else printf("NO\n");

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=200005;
ll n,m,q,x[N],f[N],ans,que[N],h,t=1,in[N];
struct edge{
	ll s,t,v;
};
bool cmp(edge a,edge b){
	return a.v<b.v;
}
ll find(ll v){
	if(!(~f[v]))return v;
	return f[v]=find(f[v]);
}
edge e[N<<1];
int main(){
	scanf("%lld%lld",&n,&q);
	for(ll i=0;i<n;i++)x[i]=1ll<<60,f[i]=-1;
	while(q--){
		ll a,b,c;
		scanf("%lld%lld%lld",&a,&b,&c);
		e[m++]=(edge){a,b,c};
		x[a]=min(x[a],c+1);
		x[b]=min(x[b],c+2);
	}
	for(ll i=0;i<n;i++)in[que[++h]=i]=1;//,printf("in %lld\n",i);
	//for(ll i=0;i<n;i++)printf("%lld ",x[i]);printf("\n");
	while(t<=h){
		ll v=que[(t++)%N];
		in[v]=0;
		if(x[v]+2<x[(v+1)%n]){
			x[(v+1)%n]=x[v]+2;//printf("x[%lld]=%lld\n",(v+1)%n,x[v]+2);
			if(!in[(v+1)%n])que[(++h)%N]=(v+1)%n,in[(v+1)%n]=1;//printf("in %lld\n",(v+1)%n);
		}
	}
	for(ll i=0;i<n;i++)e[m++]=(edge){i,(i+1)%n,x[i]};
	sort(e,e+m,cmp);//printf("============\n");
	//for(ll i=0;i<m;i++)printf("%lld %lld %lld\n",e[i].s,e[i].t,e[i].v);
	for(ll i=0,j=0;j<n-1;i++){
		ll v=find(e[i].s),u=find(e[i].t);
		if(v!=u)j++,f[v]=u,ans+=e[i].v;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;
 
void testCase() {
    int n, m;
    cin >> n >> m;
    ll ans = 0;
    if (n >= 2) {
        ans += (n*(n-1)/2);
    }
    if (m >= 2) {
        ans += (m*(m-1)/2);
    }
    cout << ans << endl;
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N, K = lr()
answer = 0
for i in range(K, N+2):
    low = i * (i-1) // 2
    high = i * (N+N-i+1) // 2
    answer += high - low + 1
    answer %= MOD

print(answer%MOD)


Measured memory_bytes: 9052
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
#include <cmath>
#include <iomanip>
#include <set>
#include <queue>
const int MOD = 1000000007;

ll POWER(ll x,ll y)
{
	ll ret=1;
	ll p=x;
	for (ll i=y;i>0;i/=2)
	{
		if (i%2) ret=(ret*p)%MOD;
		p=(p*p)%MOD;
	}
	return ret;
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
	
	ll r=1;
	for (int i=0;i<k;i++)
	{
		r =(((r*(n-i))%MOD)*POWER(i+1,1000000005))%MOD;
	}
	return r;
}


int main(int argc, char *argv[])
{
	int n;
	cin>>n;

	ll ret=0;
	for (int i=1;i*3<=n;i++)
	{
		int m=n-i*3;
		ll r=COM(m+i-1,i-1);
		ret=(ret+r)%MOD;
		// m, i-1 c(m+i-1,i-1)
	}


	cout<<ret<<endl;
}


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

int calc(int n, const vector<int>& org) {
	vector<int> v = org;
	sort(v.begin(), v.end());

	int cnt = 0;
	do {
		cnt++;
		bool f = true;
		rep(i, n) {
			if (v[i] != org[i]) {
				f = false;
			}
		}
		if (f) {
			break;
		}
	} while(next_permutation(v.begin(), v.end()));

	return cnt;
}

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	vector<int> p(n), q(n);
	rep(i, n) cin >> p[i];
	rep(i, n) cin >> q[i];
	cout << abs(calc(n, p) - calc(n, q)) << endl;
	return 0;
}


Measured memory_bytes: 256
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
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;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

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

int main()
{
	ios_init();
	int h,w,k;
	while(cin >> h >> w >> k) {
		vector<string> a(h);
		REP(i,h) cin >> a[i];

		int si = -100, sj = -100;
		REP(i,h) REP(j,w){
			if(a[i][j] == 'S'){
				si = i;
				sj = j;
				a[i][j] = '.';
				break;
			}
		}

		auto check = [&](int x, int y) -> bool {
			return 0 <= x and x < h and 0 <= y and y < w;
		};

		using T = tuple<int,int,int>;
		queue<T> qu;
		qu.emplace(si, sj, 0);
		vector<vector<bool>> used(h, vector<bool>(w, false));
		int ans = INF;
		while(!qu.empty()){
			int x, y, d;
			tie(x,y,d) = qu.front();
			qu.pop();
			if(d > k) break;
			int mi = min({abs(h-1-x), abs(x), abs(w-1-y), abs(y)});
			chmin(ans, 1+(mi+k-1)/k);
			REP(k, 4){
				int nx = x+dx[k];
				int ny = y+dy[k];
				if(check(nx, ny) and !used[nx][ny] and a[nx][ny] == '.'){
					used[nx][ny] = true;
					qu.emplace(nx, ny, d+1);
				}
			}
		}

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


Measured memory_bytes: 1024
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//                       _oo0oo_                         //
//                      o8888888o                        //
//                      88" . "88      ------ hzt1       //
//                      (| -_- |)                        //
//                      0\  =  /0                        //
//                    ___/`---'\___                      //
//                  .' \|     |// '.                     //
//                 / \|||  :  |||// \                    //
//                / _||||| -:- |||||- \                  //
//               |   | \  -  /// |     |                 //
//               | \_|  ''\---/''  |_/ |                 //
//               \  .-\__  '-'  ___/-. /                 //
//             ___'. .'  /--.--\  `. .'___               //
//          ."" '<  `.___\_<|>_/___.' >' "".             //
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |           //
//         \  \ `_.   \_ __\ /__ _/   .-` /  /           //
//     =====`-.____`.___ \_____/___.-`___.-'=====        //
//                       `=---='                         //
//                                                       //
//                                                       //
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       //
//                                                       //
//                 God-He Bless All.                     //
//           This Code Will Never Explode.               //
//                                                       //
//                                                       //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define mp make_pair
#define xx first
#define yy second
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
const int Size=1<<16;
char buffer[Size],*head,*tail;
inline char Getchar() {
    if(head==tail) {
        int l=fread(buffer,1,Size,stdin);
        tail=(head=buffer)+l;
    }
    if(head==tail) return -1;
    return *head++;
}
inline int read() {
    int x=0,f=1;char c=Getchar();
    for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
    return x*f;
}
typedef long long ll;
const int maxn=200010; 
int r,c,n,vis[maxn];
int is(int x,int y) {
	if(!x) return y;
	if(y==c) return x+c;
	if(x==r) return r+c+c-y;
	if(!y) return 2*r+2*c-x;
	return -1;
}
pair<int,int> P[maxn],S[maxn];
void GG() {puts("NO");exit(0);}
int main() {
	srand(52501);
	r=read();c=read();int m=read();
	rep(i,1,m) {
		int x1=read(),y1=read(),x2=read(),y2=read();
		if(is(x1,y1)>=0&&is(x2,y2)>=0) {
			P[++n]=mp(is(x1,y1),i);
			P[++n]=mp(is(x2,y2),i);
		}
	} 
	sort(P+1,P+n+1);
	int top=0;
	rep(i,1,n) if(vis[P[i].yy]) {
		if(S[top].yy!=P[i].yy) GG();
		top--;
	}
	else vis[P[i].yy]=1,S[++top]=P[i];
	puts("YES");
	return 0;
}

Measured memory_bytes: 2688
#include <stdio.h>

void swap(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

int bubbleSort(int A[],int N) {
    int i,j;
    int sw = 0;
    unsigned short flag = 1;
    for(i=0;flag;i++) {
        flag = 0;
        for(j=N-1;j>=i+1;j--) {
            if(A[j]<A[j-1]) {
                swap(&A[j],&A[j-1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main(void) {
    int i, A[100], N, sw;
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

    sw = bubbleSort(A,N);

    for(i=0;i<N;i++) {
        if (i) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n%d\n",sw);

    return 0;
}



Measured memory_bytes: 1976
def main():
  mod=998244353
  n,m,k=map(int,input().split())
  def cmb(n, r, mod):
      if ( r<0 or r>n ):
          return 0
      r = min(r, n-r)
      return g1[n] * g2[r] * g2[n-r] % mod
  g1 = [1, 1] 
  g2 = [1, 1] 
  inverse = [0, 1]
  for i in range( 2, n + 1 ):
      g1.append( ( g1[-1] * i ) % mod )
      inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
      g2.append( (g2[-1] * inverse[-1]) % mod )

  ans=m*pow(m-1,n-1,mod)
  ans%=mod
  for i in range(1,k+1):
    ans+=(m*pow(m-1,n-1-i,mod))%mod*cmb(n-1,i,mod)
    ans%=mod
  print(ans)
  
if __name__=='__main__':
  main()


Measured memory_bytes: 109316
n = int(input())
A = sorted([int(input()) for i in range(n)])

if n % 2 == 0:
    ans = (sum(A[n//2+1:])-sum(A[:n//2-1]))*2 + A[n//2] - A[n//2-1]
else:
    ans = max((sum(A[n//2+2:])-sum(A[:n//2]))*2 + A[n//2] + A[n//2+1],
              (sum(A[n//2+1:])-sum(A[:n//2-1]))*2 - A[n//2] - A[n//2-1])

print(ans)


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

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    int ans = 0;
    int mini = 525252555;
    int maxn = -1000000;
    rep(i, m) {
        cin >> x[i];
        mini = min(mini, x[i]);
        maxn = max(maxn, x[i]);
    }
    ans = abs(maxn - mini);

    sort(x.begin(), x.end());

    vector<int> diff(m - 1);
    rep(i, m - 1) {
        diff[i] = abs(x[i] - x[i + 1]);
    }
    sort(diff.begin(), diff.end());

    for (int i = m - 2; (i > m - 2 - n + 1) && (i >= 0); i--) {
        ans -= diff[i];
    }

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

/*���C�u�����ő����*/
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <list>

using namespace std;

int main(int, char**){
    int n;
    cin >> n;
    //vector<int> vec;
    int vec[10];
    for(int as(0);as<n;++as){
	for(int i(0);i<10;++i){
	    int tmp;
	    cin >> tmp;
	    vec[i] = tmp;
	}
	int a(0),b(0);
	for(int i(0);i<10;++i){
	    if(vec[i]<min(a,b)){
		cout << "NO" << endl;
     		goto hai;
     	    }
	    if(a>b) swap(a,b);
	    if(b>vec[i]) a = vec[i];
	    else b = vec[i];
	}
	cout << "YES" << endl;
	hai:;
    }
    //string tmp;
    
    // while(getline(cin,tmp)){
    // 	istringstream is(tmp);
    // 	int m;
    // 	list<int> vec;
    // 	while(is >> m) vec.push_back(m);
    // 	int a(0),b(0);
    // 	for(auto it=begin(vec);it!=end(vec);++it){
    // 	    if(*it>min(a,b)){
    // 		
    // 	    if(a>b){ swap(a,b);}
    // 	    b = *it;
    // 	}
    // 	cout << "YES" <<endl;
    // hai:;
    // 	vec.clear();
    // }
    return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
int a, b;

int sol1(int a, int b) {
  int sockets = 1;
  int strips = 0;
  while (sockets < b) {
    sockets -- ;
    sockets += a;
    strips ++;
  }
  return strips;
}

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

  cin>>a>>b;

  cout<<sol1(a,b)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>

using namespace std;

int X,Y,Z,K;

vector<long long> A,B,C;
priority_queue<long long> Q;

int main()
{
  cin >> X >>Y>>Z>>K;
  
  int i,j,k;
  
  long long num;

  A.assign(X,0);
  B.assign(Y,0);
  C.assign(Z,0);
  
  for(i=0;i<X;i++)
  {
    cin >> A[i];
  }
  for(i=0;i<Y;i++)
  {
    cin >> B[i];
  }
    for(i=0;i<Z;i++)
  {
    cin >> C[i];
  }

  sort(A.begin(),A.end(),greater<long long>());
  sort(B.begin(),B.end(),greater<long long>());
  sort(C.begin(),C.end(),greater<long long>());

  for(i=0;i<X;i++)
  {
    for(j=0;j<Y;j++)
    {
      for(k=0;k<Z && (i+1)*(j+1)*(k+1)<=K;k++)
      {
        num=A[i]+B[j]+C[k];
        Q.push(num);
      }
    }
  }
  
      for(i=0;i<K;i++)
  {
    cout << Q.top() << endl;
        Q.pop();
  }
  
}

Measured memory_bytes: 1404
A, B, C = map(int, input().split())
S = [A, B, C]
D = max(S)
less = [0, 0, 0]
for i in range(3):
  less[i] = D - S[i]
less = sorted(less)

ans = less[1]
remain = less[2] - less[1]
if remain % 2 == 0:
  ans += remain // 2
else:
  ans += (remain // 2) + 2

print(int(ans))


Measured memory_bytes: 9124
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {

		try {
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

			String[] x = bf.readLine().trim().split(" ");
			int a = Integer.parseInt(x[0]);
			int b = Integer.parseInt(x[1]);
			
			int c = a - b * 2;
			if ( c< 0 ) c=0;
			System.out.println(c);
		}catch(Exception e) {
			
		}
	}
}

Measured memory_bytes: 21204
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(new BufferedInputStream(System.in));
		List<String> output = new ArrayList<String>();
		while (scan.hasNext()) {
			String input = scan.nextLine();
			String[] in = input.split(" ");
			int m = Integer.parseInt(in[0]);
			int f = Integer.parseInt(in[1]);
			int r = Integer.parseInt(in[2]);
			if (m == -1 && f == -1 && r == -1) {
				break;
			} else {
				if (m == -1 || f == -1) {
					output.add("F");
				} else {
					int total = m + f;
					if (total >= 80) {
						output.add("A");
					} else if (total >= 65 && total < 80) {
						output.add("B");
					} else if (total >= 50 && total < 65) {
						output.add("C");
					} else if (total >= 30 && total < 50) {
						if (r >= 50) {
							output.add("C");
						} else {
							output.add("D");
						}
					} else if (total < 30) {
						output.add("F");
					}
				}
			}
		}
		for (String out : output) {
			System.out.println(out);
		}
	}
}

Measured memory_bytes: 26256
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int n,k;
ll a[1000000];
ll asum[1000000];
ll b[1000000];
ll ans = -1;

int main(){
  cin>>n>>k;
  rep(i,n){
    cin>>a[i+1];
    asum[i+1]=a[i+1];
    b[i+1]=max((ll)0,a[i+1]);
    asum[i+1]+=asum[i];
    b[i+1]+=b[i];
  }
  rep(i,n-k+1){
    ans=max(ans,(b[i]-b[0])+max((ll)0,asum[k+i]-asum[i])+(b[n]-b[k+i]));
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 9216
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        String s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";
        String[] a = s.split(", ");

        int k = sc.nextInt();
        System.out.println(Integer.parseInt(a[k-1]));
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 21332
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for i in range(Q)]

A = [0]*(N+1)
flag = 0
for i in range(N):
    if S[i] == "A":
        flag = 1
        A[i+1] = A[i]
    elif S[i] == "C" and flag == 1:
        A[i+1] = A[i] + 1
        flag = 0
    else:
        flag = 0
        A[i+1] = A[i]
for i in range(Q):
    l,r = LR[i]
    print(A[r] - A[l])

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

using namespace std;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  vector<int> count(alphabet.size(), 0);
  for (auto s : S)
    count[s - 'a'] += 1;
  for (auto s : alphabet) {
    if (count[s - 'a'] == 0) {
      cout << S << s << '\n';
      return 0;
    }
  }
  string cand = "", res = "";
  for (int i = S.size() - 1; i > 0; i--) {
    cand += S[i];
    for (auto s : cand) {
      if (res != "" && res < S.substr(0, i - 1) + s)
        continue;
      else if (s > S[i - 1])
        res = S.substr(0, i - 1) + s;
    }
    if (res != "") {
      cout << res << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}


Measured memory_bytes: 256
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B = map(int, readline().split())

print((A+B+1)//2)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
	int n, k, ans=0;
  	cin>>n>>k;
  	vi h(n);
  	rep(i,n){
      	cin >> h[i];
      	if(h[i]>=k)ans++;
    }
  	cout<<ans<<endl;
}

Measured memory_bytes: 640
import heapq
inf = float('INF')

def dijkstra(graph, n, s):
    costs = [[inf for j in range(3)] for i in range(n+1)]
    costs[s][0], Q = 0, []
    heapq.heappush(Q, [costs[s][0], 0, s])

    while(Q != []):
        c, num, u = heapq.heappop(Q)
        next_ = (num+1)%3
        if u not in graph:
            continue
        for v, three in graph[u].items():
            if costs[u][num] + 1 < costs[v][next_]:
                heapq.heappush(Q, [costs[u][num] + 1, three[next_], v])
                costs[v][next_] = costs[u][num] + 1
    return costs

N,M = map(int, input().split())
graph = {}
for i in range(M):
    u,v = map(int, input().split())
    if u not in graph:
        graph[u] = {}
    graph[u][v] = {}
    graph[u][v][0] = 0
    graph[u][v][1] = 1
    graph[u][v][2] = 2
S,T = map(int,input().split())

di = dijkstra(graph, N, S)
if di[T][0] == inf:
    print(-1)
else:
    print(di[T][0]//3)


Measured memory_bytes: 96732
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

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

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

int main() {

    int N, M;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;
    ll L = lcm(N, M);
    ll g = gcd(N, M);

    for(int i = 0; i < g; i++) {
        if (S[i*N/g] != T[i*M/g]) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << L << endl;

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

Measured memory_bytes: 512
use std::io;


/// https://beta.atcoder.jp/contests/agc002/tasks/agc002_a
fn main() {
    let (a, b) = {
        let i = read::<isize>();
        (i[0], i[1])
    };
    if a * b <= 0 { println!("Zero"); }
    else if a > 0 { println!("Positive"); }
    else if b < 0 {
        if (b - a) % 2 == 0 { println!("Negative"); }
        else { println!("Positive"); }
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

H, W = MAP()
S = [input() for _ in range(H)]

ans = 0
dy = [1, 0, -1, 0]
dx = [0, -1, 0, 1]
check = [[0]*W for _ in range(H)]

for y0 in range(H):
	for x0 in range(W):
		if S[y0][x0] ==  "." or check[y0][x0] == 1:
			continue
		cnt_black = 1
		cnt_white = 0
		check[y0][x0] = 1
		q = deque([(y0, x0, 1)])
		while q:
			#print(q)
			y, x, color = q.popleft()
			for i in range(4):
				ny = y + dy[i]
				nx = x + dx[i]
				if 0 <= ny < H and 0 <= nx < W:
					if color == 1 and S[ny][nx] == "." and check[ny][nx] == 0:
						check[ny][nx] = 1
						#print((y0, x0), (ny, nx))
						cnt_white += 1
						q.append((ny, nx, 0))
					if color == 0 and S[ny][nx] == "#" and check[ny][nx] == 0:
						check[ny][nx] = 1
						cnt_black += 1
						q.append((ny, nx, 1))
		ans += cnt_white*cnt_black
print(ans)

Measured memory_bytes: 11748
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,k;
int main()
{
	scanf("%d",&k);
	if(k==1)return puts("1"),puts("1"),0;
	n=(k+3)/4*2;
	printf("%d\n",n);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i&1)printf("%d ",(i+j)%n+n<k?(i+j)%n+n+1:(i+j)%n+1);
			else printf("%d ",(i+j)%n+1);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1152
#pragma region
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define dump(x) cerr << #x << " = " << x << endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);
int dig(int n){return (int)(log10(n) + 1);}
int abc(char x){return (int)(x)-(int)('a');} // 0~25
char abc(int x){return (char)(x+(int)('a'));} 
int ABC(char x){return (int)(x)-(int)('A');}
char ABC(int x){return (char)(x+(int)('A'));}
void solve();
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}
#pragma endregion

void solve() {
	int N; cin >> N;
	vi W(N); rep(i, N) cin >> W[i];
	int sum = 0;
	int ans = INF;
	rep(i, N) sum += W[i];
	repi(T, 0, N - 1) {
		int s = 0;
		rep(i, T + 1) {
			s += W[i];
		}
		ans = min(ans, abs(sum - 2 * s));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayList;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
        int[] dishes = new int[5];
        for (int i=0;i<5;i++){
            str = br.readLine();
            dishes[i] = Integer.parseInt(str);
        }
        ArrayList<Integer> time = new ArrayList<Integer>();
        for (int i=0;i<5;i++){
            for (int j=0;j<5;j++){
                if (i==j){
                    continue;
                }
                for (int k=0;k<5;k++){
                    if (i==k || j==k){
                        continue;
                    }
                    for (int l=0;l<5;l++){
                        if (i==l || j==l || k==l){
                            continue;
                        }
                        for (int m=0;m<5;m++){
                            if (i==m || j==m || k==m || l==m){
                                continue;
                            }
                            time.add((dishes[i]+9)/10*10 + (dishes[j]+9)/10*10 + (dishes[k]+9)/10*10 + (dishes[l]+9)/10*10 + dishes[m]);
                        }
                    }
                }
            }
        }
        Integer[] ti = time.toArray(new Integer[time.size()]);
        int ans = ti[0];
        for (int i:time){
            if (i<ans){
                ans = i;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
int main () {
  int A, B;
  cin >> A >> B;
  if(A == 1) A += 13;
  if(B == 1) B += 13;
  string ans;
  if(A < B) ans = "Bob";
  else if(A > B) ans = "Alice";
  else ans = "Draw";
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(){
    long long n, q, ans = 0;
    cin >> n;
    vector<int > a(100001, 0);
    for (int i = 0; i < n; ++i){
        int x; cin >> x;
        ans += x;
        a[x]++;
    }
    cin >> q;
    while (q--){
        long long b, c, k;
        cin >> b >> c;
        k = a[b];
        ans += k*(c-b);
        cout << ans << '\n';
        a[b] = 0;
        a[c] += k;
    }
    return 0;
}

Measured memory_bytes: 3756
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
chk = []
for i in range(n):
  a,b =  map(int,input().split())
  if a <= m:
    chk.append((a,b))

from heapq import heappop, heappush
from operator import itemgetter
chk = sorted(chk,key=itemgetter(0),reverse=True)

q = []
ans = 0
for i in range(1, m + 1):
    while chk and chk[-1][0] <= i:
        a,b = chk.pop()
        heappush(q,-b)
    if q:
        ans -= heappop(q)
print(ans)


Measured memory_bytes: 19020
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        char[] s = sc.next().toCharArray();
        sc.close();
        if(n==1){
            System.out.println(1);
            return;
        }
        Integer count = 0;
        List<Integer> zero = new ArrayList<>();
        List<Integer> one = new ArrayList<>();
        int i=0;
        if(s[0]=='0'){
            one.add(0);
        }
        while(true){
            while(i < n && s[i]=='0'){
                count++;
                i++;
            }
            if(count > 0){
                zero.add(count);
                count = 0;
            }
            
            while(i < n && s[i]=='1'){
                count++;
                i++;
            }
            if(count > 0){
                one.add(count);
                count = 0;
            }
            if(i==n){
                break;
            }
        }
        //1010...1に合わせる
        if(s[n-1]=='0'){
            one.add(0);
        }
        int idx = 0,head = 0;
        int sum = 0;
        while(idx < zero.size() && idx < k){
            sum+=one.get(idx)+zero.get(idx);
            idx++;
        }
        sum+=one.get(idx);
        int max = sum;
        while(idx < zero.size()){
            sum = sum-zero.get(head)-one.get(head)+zero.get(idx)+one.get(idx+1);
            max = Math.max(max,sum);
            idx++;
            head++;
        }
        System.out.println(max);

    }

}

Measured memory_bytes: 27628
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
 
int main()
{
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int block = 1;
  rep(i, n-1) {
    if (s[i]!=s[i+1]) block++;
  }
  block -= 2*k;
  block = max(1, block);
  int ans = n - block;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = 410000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
//invの要素にはiの逆元が格納されている
//前処理
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;//i!(mod MOD)を計算
        inv[i] = MOD - inv[MOD%i]* (MOD / i) % MOD;//iの逆元を計算
        finv[i] = finv[i - 1] * inv[i] % MOD;//i!(mod MOD)の逆元を計算
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;//nCk = n!/(k!*(n-k)!)を計算
}
//例のアレ
long long nPm(int n, int m){
    if(n < m) return 0;
    if(n < 0 || m < 0) return 0;
    return fac[n] * finv[n - m] % MOD;
}

int main(){
    long long N, K;
    COMinit();
    cin >> N >> K;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    long long ans = 0;
    for(int i = 0; i < N; i++){
        if(i >= K - 1) ans = (ans + A[i] * COM(i, K - 1)) % MOD;
        if(i <= N - K) ans = (ans - A[i] * COM(N - i - 1, K - 1) + MOD) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 13500
def gcd(a,b):
    while b!=0:
        a,b=b, a%b
    return a

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

r=[-1]*N
l=[-1]*N
l[0]=a[0]
r[-1]=a[-1]

if N==2:
    print(max(a))

else:
    for i in range(1,N):
        l[i]=gcd(l[i-1],a[i])
    for i in range(N-2,-1,-1):
        r[i]=gcd(r[i+1],a[i])
    ans=r[1]
    for k in range(1,N):
        if k==N-1:
            ans=max(ans,l[-2])
        else:
            ans=max(ans,gcd(l[k-1],r[k+1]))
    print(ans)

Measured memory_bytes: 14432
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
  
    int n = ri();
    int a[n];
    INPUT(a);
    
    int res = INF;
    FROMTO(i,-100,100) {
      int cur = 0;
      FOR(j,n) {
        cur += (a[j]-i)*(a[j]-i);
      }
      res = min(res,cur);
    }
    cout << res << endl;
  
  return 0;
}

    

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=4e5+5;
const int MOD=1e9+7;
ll a[N],sum[N];

ll run(int x){
    ll s=0;
    while(x){
        s+=x%10;
        x/=10;
    }
    return s;
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll t;
    cin >> t;
    ll tot=run(t);
    if(t%tot!=0)    cout <<"No"<<"\n";
    else    cout<<"Yes"<<"\n";


    return 0;
}


Measured memory_bytes: 256
def prime_factorize(n):
    """
    trial_division
    試し割り法で因数分解
    2 と奇数で試し割りする
    [[素因数, 指数]...]

    ref. https://en.wikipedia.org/wiki/Trial_division
    """
    a = []
    f = 2
    while f * f <= n:
        count = 0
        while n % f == 0:
            count += 1
            n //= f
        if count:
            a.append([f, count])
        # 3 からは奇数のみ
        f += 2 if f != 2 else 1
    if n != 1:
        a.append([n, 1])
    return a

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

# ref. https://drken1215.hatenablog.com/entry/2018/12/23/012300
res = 1
for p in prime_factorize(P):
    for _ in range(p[1] // N):
        res *= p[0]
print(res)

Measured memory_bytes: 9192
S = input()
Q = int(input())

prefix = ''
suffix = ''
mode = 0
for _ in range(Q) :
  Query = list(input().split())
  if Query[0] == '1' :
    mode ^= 1
  else :
    _, F, C = Query
    F = int(F) - 1
    
    if mode != F :
      suffix += C
    else :
      prefix += C
      

if mode == 0 :
  print(prefix[::-1] + S + suffix)
else :
  print(suffix[::-1] + S[::-1] + prefix)

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

bool uni(char *s)
{
	char c = *s;
	while(*s != '\0'){
		if(*s != c) return false;
		s++;
	}
	return true;
}

int f(char c, char *s)
{
	char str[101];
	strcpy(str, s);
	int len = strlen(str);
	int ret = 0;

	while(!uni(str)){
		ret++;
		len--;
		for(int i = 0; i < len; i++){
			if(str[i + 1] == c) str[i] = c;
		}
		str[len] = '\0';
	}
	return ret;
}

int main(int n)
{
	char s[101];
	cin >> s;

	int ans = 1000;
	for(char c = 'a'; c <= 'z'; c++){
		int num = f(c, s);
		if(num < ans) ans = num;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]



def main():
    a,b=map(int,input().split())
    ans=-1
    for i in range(1,10001):
        if i*0.08//1==a and i*0.1//1==b:
            ans=i
            break
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 39856
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    bool ans=true;
    if(abs(c-a)>d) if(abs(b-a)>d || abs(c-b)>d) ans=false;
    if(ans) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int dis(long long int a,long long int b){
  if(a>=b){
    return a-b;
  }else{
	return b-a;
  }
}

int main() {
  long long int N,K,ans;
  cin >> N >> K;
  ans=N%K;
  if(ans>=dis(ans,K)){
    cout << dis(ans,K);
  }else{
    cout << ans;
  }
}


Measured memory_bytes: 3600
//////////////////////////
/*      _        ____   */
/*  U  /"\  u U /"___|  */
/*   \/ _ \/  \| | u    */
/*   / ___ \   | |/__   */
/*  /_/   \_\   \____|  */
/*   \\    >>  _// \\   */
/*  (__)  (__)(__)(__)  */
/*  Compro by NULL_CT©  */
//////////////////////////
/*STL Libs*/
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

/*Boost to boost compile time*/
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#define int long long // Black Magic
#define REP(I, LIM) for (int I = 0; I < LIM; I++)
#define ALL(LIST) (LIST.begin()), (LIST.end())

using namespace std;
using bint = boost::multiprecision::cpp_int;

constexpr int MOD = 10000007;

vector<int> divisor(int n) {
  vector<int> head, tail;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      head.push_back(i);
      if (i * i != n)
        tail.push_back(n / i);
    }
  }
  head.insert(head.end(), tail.rbegin(), tail.rend());
  return (head);
}

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

void execute() {
  int n;
  string s;
  cin>>n>>s;
  REP(i,s.size()){
    s[i]=char(s[i])+n;
    if(90<char(s[i]))s[i]=char(s[i]-26);
  }
  cout<<s<<endl;
}

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

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  // cout<<fixed<<setprecision(20);

  execute();

  return (0);
}


Measured memory_bytes: 3156
l=gets.chomp.split(" ").map(&:to_i)
a = l[0]
b = l[1]
c = l[2]
k = l[3]

if k % 2 == 1
ans = b - a
else
ans = a - b
end

if ans >= 10**18 || ans <= -(10**18)
  puts "Unfair"
else
  puts ans
end


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

int main(){
	int n;
	cin>>n;
	vector<int> h(n);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int dp[n]={0};
	dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++){
		dp[i]=min((dp[i-1]+abs(h[i]-h[i-1])),(dp[i-2]+abs(h[i]-h[i-2])));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
import sys

def main():
    S = input()
    l = len(S)
    
    ans = 0
    for i in range(l):
        for j in range(i, l):
            if all(['ATGC'.count(c) == 1 for c in S[i:j+1]]):
                ans = max(ans, j-i+1)
            
    print(ans)
main()

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

typedef long long ll;

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

  int q;  cin >> q;
  for(int i=0; i<q; i++){
    int k; cin >> k;
    auto itr = lower_bound(a.begin(),a.end(),k);
    
    cout << itr-a.begin() << endl;
  }

}


Measured memory_bytes: 3120
def turn_progress(person):
    newperson = cards[person][0]
    cards[person] = cards[person][1:]
    return newperson

cards = {'a': input(), 'b': input(), 'c':input()}

turn = 'a'
while 1:
    ans = turn
    if len(cards[turn]) == 0:
        break
    else:
        turn = turn_progress(turn)

print(ans.upper())

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define SIZE 100
#define PI acosl(-1)//3.14159265358979323846264338327950L 
#define rep(i, N) for (i = 0; i < N; i++) //制御変数iを用いてN回転
#define array(N, t) (t*)calloc(N, sizeof(t)) //t型N要素の1次元配列を動的確保後0クリア(freeを忘れずに)
#define zero(a); {int iter; rep(iter, sizeof(a)/sizeof((a)[0])) (a)[iter]=0;} //1次元配列aのゼロ初期化?
typedef long long ll;
void print_log(); //とりあえず文字を出力してどこまで実行できているか確認(for debug)
void printa_int(int *a, int size); //int型の1次元配列aを出力(for debug)

int main() {
    long A, B, H, M;
    long double angle, dsq;
    scanf("%ld %ld %ld %ld", &A, &B, &H, &M);
    angle = 2.0L * PI * (H / 12.0L - 11.0L * M / 720.0L);
    dsq = A * A + B * B - 2 * A * B * cosl(angle);
    printf("%.20llf\n", sqrtl(dsq));
    return 0;
}

void print_log() {
    printf("===finish!===\n");
}

void printa_int(int *a, int size) {
    int i;
    printf("[");
    for (i = 0; i < size; i++)
        printf("%d, ", a[i]);
    printf("]\n");
}

Measured memory_bytes: 2584