akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 100000
#define ME 1000000
#define L (k<<1)
#define R (k<<1|1)
struct edge{int nx,t;}e[ME+5];
int n,x[MN+5],p[MN+5],v[MN+5],h[MN+5],en,d[MN+5],l[MN+5],cnt,z[MN+5],zn,inz[MN+5],f[MN+5],fn;
bool cmp(int a,int b){return x[a]<x[b];}
inline void ins(int x,int y){e[++en]=(edge){h[x],y};h[x]=en;}
void build(int k,int l,int r)
{
	if(l==r){ins(k+n,d[l]);return;}
	int mid=l+r>>1; 
	ins(k+n,L+n);build(L,l,mid);
	ins(k+n,R+n);build(R,mid+1,r);
}
void ins(int k,int l,int r,int ql,int qr,int x)
{
	if(l==ql&&r==qr){ins(x,k+n);return;}
	int mid=l+r>>1;
	if(qr<=mid)ins(L,l,mid,ql,qr,x);
	else if(ql>mid)ins(R,mid+1,r,ql,qr,x);
	else ins(L,l,mid,ql,mid,x),ins(R,mid+1,r,mid+1,qr,x);
}
void tj(int x)
{
	inz[z[++zn]=x]=1;d[x]=l[x]=++cnt;
	for(int i=h[x];i;i=e[i].nx)
	{
		if(!d[e[i].t])tj(e[i].t);
		if(inz[e[i].t])l[x]=min(l[x],l[e[i].t]);
	}
	if(d[x]==l[x])for(++fn;;){inz[z[zn]]=0;f[z[zn--]]=fn;if(z[zn+1]==x)return;}
}
int main()
{
	int i,l,r,mid,ans=0,c;
	for(n=read()<<1,i=0;i<n;++i)x[p[i]=i]=read();
	sort(p,p+n,cmp);
	for(i=0;i<n;++i)v[p[i]]=i;
	for(l=1,r=1e9;l<=r;)
	{
		mid=l+r>>1;
		for(i=0;i<n;++i)d[v[i]]=v[i^1];
		memset(h,en=0,sizeof(h));
		build(1,0,n-1);
		for(i=0;i<n;++i)
		{
			c=lower_bound(p,p+n,(x[n]=x[i]-mid+1,n),cmp)-p;
			if(c<v[i])ins(1,0,n-1,c,v[i]-1,v[i]);
			c=upper_bound(p,p+n,(x[n]=x[i]+mid-1,n),cmp)-p-1;
			if(c>v[i])ins(1,0,n-1,v[i]+1,c,v[i]);
		}
		memset(d,0,sizeof(d));
		for(i=0;i<n;i+=2)
		{
			if(!d[v[i]])zn=0,tj(v[i]);
			if(f[v[i]]==f[v[i+1]])break;
		}
		if(i<n)r=mid-1;else ans=mid,l=mid+1;
	}
	printf("%d",ans);
}

Measured memory_bytes: 11392
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){
	long long N, M;
	cin >> N >> M;
	if(N > M) swap(N, M);

	if (N > 2) {
		cout << (N - 2) * (M - 2) << endl;
	} else if(N == 2 || M == 2) {
		cout << 0 << endl;
	} else if(M > 2) {
		cout << M - 2 << endl;
	} else if(M == 1 && N == 1) {
		cout << 1 << endl;
	} else {
		assert(false);
	}
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
enum = enumerate

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().split()))

def vinput(rep=1, ty=int, cvt=list):
	return cvt(ty(input().rstrip()) for _ in "*"*rep)

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def main():
	a,b,c,k = linput()
	d = a-b
	res = 0

	#for i in range(k):
	#	s = a+b+c
	#	a,b,c = s-a, s-b, s-c
	#	print(a,b,c, a-b)
	
	#print( a-b )
	res = d*(-1)**(k%2)
	#sT = "No Yes".split()
	#print(sT[res])
	print(res)

if __name__ == "__main__":
	main()


Measured memory_bytes: 62044
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 300010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n+1,0),b(n+1,0);
    rep(i,n) cin >> a[i+1];
    rep(i,n) cin >> b[i+1];
    rep(i,n){
        a[i+1] += a[i];
        b[i+1] += b[i];
    }
    ll ans = 0;
    rep(i,n){
        chmax(ans,a[i+1]+b[n]-b[i]);
    }
    PRINT(ans);
}


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

int main(){
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n-1;i++) cin>>c[i];

    int start=a[0];
    int ans=b[start-1];
    for(int i=1;i<n;i++){
        if(a[i]-a[i-1]==1) {
            ans += c[ a[i-1]- 1];
        }
        int now=a[i];
        ans+=b[now-1];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
import Data.List.Split

toInt :: String -> Int
toInt = read :: String -> Int

makeString :: Int -> Int -> String
makeString a b
  | a < b = concat $ replicate b (show a)
  | otherwise = concat $ replicate a (show b)

main = do
  s <- getLine
  let l = splitOn " " s
  let a = toInt (l !! 0)
  let b = toInt (l !! 1)
  putStrLn $ makeString a b


Measured memory_bytes: 508
#include <stdio.h>
int H, W, s[1400][1400], t[1401][1401];
int range(int x1, int y1, int x2, int y2) {
	return t[x2][y2] + t[x1][y1] - t[x1][y2] - t[x2][y1];
}
bool check(int x) {
	for(int i = 0; i <= H - x; i++) {
		for(int j = 0; j <= W - x; j++) {
			if(!range(i, j, i + x, j + x)) return true;
		}
	}
	return false;
}
int main() {
	scanf("%d%d", &H, &W);
	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) scanf("%d", &s[i][j]);
	}
	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			t[i + 1][j + 1] = t[i + 1][j] + t[i][j + 1] - t[i][j] + s[i][j];
		}
	}
	int l = 0, r = 1400;
	while(r - l > 1) {
		int m = (l + r) / 2;
		if(check(m)) l = m;
		else r = m;
	}
	printf("%d\n", l * l);
	return 0;
}

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

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)
#define int long long

const int inf = 1 << 25;
const ll INF = 1LL << 55;

struct edge
{
  int to; double cost;
  edge(){}
  edge(int to, double cost):to(to), cost(cost){}
};

int n;
vector< vector<edge> > graph;

void dijkstra(int s, int g)
{
  typedef pair<double, int> Pd;
  
  priority_queue<Pd, vector<Pd>, greater<Pd> > que;  
  vector<double> mincost(n, INF);
  vector<int> prevv(n, -1);
  
  que.push(Pd(0.0, s));
  mincost[s] = 0.0;
  
  while(!que.empty()) {
    Pd p = que.top(); que.pop();
    if(p.S == g) break;
    if(mincost[p.S] < p.F) continue;
    for(edge e : graph[p.S]) {
      if(e.cost + p.F < mincost[e.to]) {
	mincost[e.to] = e.cost + p.F;
	prevv[e.to] = p.S;
	que.push(Pd(mincost[e.to], e.to));
      }
    }
  }
  if(mincost[g] == INF) {
    puts("NA");
    return;
  }
  vector<int> ans;
  for(int v = g; v != -1; v = prevv[v]) {
    ans.push_back(v+1);
  }
  reverse(all(ans));
  for(int i = 0; i < ans.size(); i++) {
    if(i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
}

double dist(Pi a, Pi b)
{
  return sqrt((a.F-b.F)*(a.F-b.F) + (a.S-b.S)*(a.S-b.S));
}

signed main()
{
  while(cin >> n, n) {
    vector<Pi> pos(n);
    graph.clear(); graph.resize(n);
    for(int i = 0; i < n; i++) {
      int b; cin >> b; b--;
      cin >> pos[b].F >> pos[b].S;
    }
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
	double d;
	if((d = dist(pos[i], pos[j])) <= 50.0){
	  graph[i].push_back(edge(j, d));
	}
      }
    }
    int m; cin >> m;
    while(m--) {
      int s, g; cin >> s >> g;
      s--, g--;
      dijkstra(s, g);
    }
  }
  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    string S;
    cin >> S;
    if (S == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
A, B, C, D, E, F = gets.split.map &:to_i
W0, W1 = 100*A, 100*B
S0, S1 = C, D
Sol = E # solubility
Cap = F # capacity

max_sol = [0, 0, 0]
for w0 in 0..(Cap/W0)
  for w1 in 0..((Cap-w0*W0)/W1)
    w = w0*W0 + w1*W1
    smax = [w/100*Sol, Cap-w].min
    for s0 in 0..(smax/S0)
      for s1 in 0..((smax-s0*S0)/S1)
        s = s0*S0+s1*S1
        sol = [s/(w+s).to_f, w+s, s]
        if (max_sol<=>sol) == -1
          max_sol = sol
        end
      end
    end
  end
end

puts max_sol[1, 2].join ' '


Measured memory_bytes: 1788
inp = input().split(" ")
map(int, inp)
inp[0] = int(inp[0])
inp[1] = int(inp[1])
p = inp[0] + inp[1]
m = inp[0] - inp[1]
x = inp[0] * inp[1]
pmx = []
pmx.append(p)
pmx.append(m)
pmx.append(x)
print(max(pmx))



Measured memory_bytes: 3060
moji = [input() for i in range(2)]
if len(moji[0]) >= 1 and len(moji[0]) <= 10 and len(moji[0])+1 == len(moji[1]) and moji[0] == moji[1][:len(moji[0])]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9108
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <functional>
#include <queue>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


int main(){
    string s ;
    cin >> s ;
    for (int i = 0; i < s.size()-1; i++)
    {
        if (s.at(i) == s.at(i+1))
        {
            cout << i+1 << " " << i+2 << endl ;
            return 0 ;
        }
        
    }
    for (int i = 0; i < s.size()-2; i++)
    {
        if (s.at(i) == s.at(i+2))
        {
            cout << i+1 << " " << i+3 << endl ;
            return 0 ;
        }
        
    }
    cout << -1 << " " << -1 << endl ;
    
}

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

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

int n;
int a[1000100];
pair<int,int> b[1000100];

void upd(int x,int y){
    int num1=b[x].first,num2=b[x].second,num3=b[y].first,num4=b[y].second;
    b[x].first=max(num1,num3);
    if(num1>num3) b[x].second=max(num2,num3);
    else b[x].second=max(num1,num4);
}

int main(){
    #ifdef LZT
    freopen("in","r",stdin);
    #endif
    n=read();
    for(int i=0;i<(1<<n);i++)
        a[i]=read();
    for(int i=0;i<(1<<n);i++)
        b[i].first=a[i],b[i].second=-1e9;
    for(int k=0;k<n;k++){
        //cout<<k<<endl;
        for(int i=0;i<(1<<n);i++){
            if((i&(1<<k))!=0) continue;
            upd(i|(1<<k),i);
            //cout<<(i|(1<<k))<<' '<<i<<endl;
        }
    }/*
    for(int i=0;i+1<(1<<n);i++){
        upd(i+1,i);
    }*/
    int lastans=0;
    for(int i=1;i<(1<<n);i++){
        lastans=max(lastans,b[i].first+b[i].second);
        printf("%d\n",lastans);
    }
    return 0;
}

/*
2
1 2 3 1
*/

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

int main() {
  int a;
  int b;
  int A;
  
  cin >> a >> b;
  
  A = (a + b) % 2;
  //(a + b) / 2 + A;
  
  cout << (a + b) / 2 + A << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000
int A[MAX];

int BinarySearch(int key,int n){
  int left = 0;
  int right = n;
  int mid;
  
  while (left < right)
    {
      mid = (left + right) / 2;
      if (A[mid] == key)return 1; //FOUND
      else if (key < A[mid])right = mid;
      else left = mid + 1;
    }
  return 0;//NOT_FOUND
}

int main(){
  int i;
  int n;
  int key_n;
  int key;
  int count=0;
  
  scanf("%d",&n);//INPUT
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  scanf("%d",&key_n);
  for(i=0;i<key_n;i++){
    scanf("%d",&key);
    if(BinarySearch(key,n)==1)count++;
  }
  
  printf("%d\n",count);
  return 0;
}
/*
  Aの数
  Aの要素
  確かめるkeyの要素
  keyの要素

  一致した数
*/



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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,start,end) for(int i=(start);i<=(end);i++)
#define all(n) begin(n),end(n)

#define DEBUG

int main()
{
	int a,b;
	cin >> a >> b;
	cout << (a-1)*(b-1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(void) {
    int a, b, c, t;
    cin >> a; 
    cin >> b;
    cin >> c;
    if (a > b) {t = a; a = b; b = t;}
    if (b > c) {t = b; b = c; c = t;}
    if (a > b) {t = a; a = b; b = t;}
    cout << a << " " << b << " " << c << endl;

}


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n-1;i++)

/* int main(){//A
int N;
cin>>N;
cout<<N*N*N<<endl;

    return 0;
}*/

/* int main(){//B
    int N;cin>>N;
    int s=0;
    int j=0;
    vector<int> A(N),B(N),C(N-1);
    rep(i,0,N) cin>>A[i];
    rep(i,0,N) cin>>B[i];
    rep(i,0,N-1) cin>>C[i];
    rep(i,0,N){
        if(j!=0&&A[i]==j+1) s+=C[j-1];
        s+=B[A[i]-1];
        j=A[i];
    }
    cout<<s<<endl;
    return 0;
}*/

/*int main(){//C
    int N;cin>>N;
    vector<int> B(N-1);
    rep(i,0,N-1) cin>>B[i];
    vector<int> A(N);
    int c=0;
    A[0]=B[0];
    //A[1]=A[0];
    rep2(i,1,N) {
        if(B[i-1]>B[i]) A[i]=B[i];
        else A[i]=B[i-1];
    }  
    A[N-1]=B[N-2];
    rep(i,0,N) c+=A[i];
    cout<<c<<endl; 
    return 0;
}*/

int main(){//D
int N,K;
cin>>N>>K;
string S;cin>>S;
int s=0;
int c=0;
char x;
/* rep(i,1,S.size()){
    if(S.at(i-1)=='L') flag=true,frag=false;
    else if(S.at(i-1)=='R') frag=true,flag=false;
    if(flag&&S.at(i)==S.at(i-1)) s++;
    else if(frag&&S.at(i)==S.at(i-1)){
        s++;
        //if(i==S.size()-1) s--;
    }
 }*///回りくどい
 x=S[0];
 rep(i,0,N-1) 
 if(S[i]==S[i+1]) s++;
 else if(S[i]!=S[i+1]&&S[i+1]!=x)
    c++;
 if(K<c)cout<<s+2*K<<endl;
 else cout<<N-1<<endl;
 return 0;
}

/*int main(){//E
int N;cin>>N;
tuple<int,int,vector<int>,int> p;

    return 0;
}*/


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

const int N = 5e3 + 5 ;
const long long infinite = 1e17 ; 

int n; 
vector<pair<int , int > > v , vp; 
long long dp[N][N] ;

int main(){
    //freopen("in.in" , "r" , stdin) ; 
    cin>>n ; 
    for(int i = 0 ; i < n; i++){
        int h , p ; 
        cin>>h>> p ; 
        v.push_back({h , p}) ; 
        vp.push_back({h + p , i}) ; 
    }
    for(int i = 0 ;  i <N ; i++){
        for(int j =0 ; j < N ; j++){
            dp[i][j] = infinite ; 
        }
    }
    sort(vp.begin() , vp.end()) ; 
    dp[0][0] = 0 ; 
    for(int i = 1 ; i <= n ; i++){
        for(int j = 1 ; j <= n ; j++){
            if(j > i ) continue ; 
            dp[i][j] = dp[i-1][j] ; 
            if(dp[i-1][j-1] <= v[vp[i-1].second].first ){
                dp[i][j] = min(dp[i][j] , dp[i-1][j-1] + v[vp[i-1].second] . second );
            }
        }
    }
    for(int i = n ; i>=1 ; i--){
        if(dp[n][i]<infinite){
            return cout<<i , 0 ; 
        }
    } 
    return 0 ;
}   

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

int main() {
  int N,M, X;
  cin>>N>>M>>X;
  int A=0;
  int B=0;
  vector<int>C(M);
  for(int i=0;i<M;i++){
    cin>>C.at(i);
  }
  for(int i=0;i<M;i++){
    if(C.at(i)>X){
      A++;
    }
    else{
      B++;
    }
  }
  if(A>B){
    cout<<B<< endl;
  }
  else{
    cout<<A<< endl;
  }
  
      
  
}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


N = int(input())
A = [int(x) for x in input().split()]
ans = []
score = [0] * N

for i in range(N - 1, -1, -1):
    if score[i] % 2 != A[i]:
        ans.append(i + 1)
        divisors = make_divisors(i + 1)
        for v in divisors:
            score[v - 1] += 1



print(len(ans))
if len(ans) != 0:
    for v in ans:
        print(v, end=" ")

Measured memory_bytes: 68328
n=input()
num_list=[int(x) for x in raw_input().split(" ")]

for idx in range(1, len(num_list)):
    print " ".join([str(x) for x in num_list])
    key=num_list[idx]
    jdx = idx - 1
    
    while jdx >= 0 and num_list[jdx] > key:
        num_list[jdx+1] = num_list[jdx]
        jdx -= 1
    num_list[jdx+1] = key
print " ".join([str(x) for x in num_list])

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

using namespace std;
using ll = long long;

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

  ll n;
  cin >> n;
  for (ll i = sqrt(n); i >= 1; i--) {
    if (n % i == 0) {
      cout << int(log10(n / i)) + 1 << endl;
      return 0;
    }
  }
  cout << int(log10(n)) + 1 << endl;

  return 0;
}


Measured memory_bytes: 3920
#include<stdio.h>
#include<iostream>
using namespace std;

int main(void){
	
	int a, b ,sa[7];
	for(int i=0;i<7;i++){
	cin >> a >> b;
	sa[i]=a-b;
	}
	for(int i=0;i<7;i++){
	cout << sa[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
//
// Created by Myabu on 2020/01/11.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>

using namespace std;

bool is_prime(int n){
    if(n < 2 )return false;
    if(n == 2 || n == 3)return true;

    if(n%2 == 0) return false;
    if(n%3 == 0) return false;

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


int main(void){
    int X;
    cin>>X;

    while(1){
        if(is_prime(X)){
            cout<<X<<endl;
            return 0;
        }
        X++;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<math.h>
    #include<string>
    #include<iostream>
    using namespace std;
    int times[68000000];
    char s[200000+100];
    int my_min(int a,int b)
    {
        return a<b? a:b;
    }
    int main()
    {
        scanf("%s",s);
        for(int i=0;i<68000000;i++)
            times[i]=200000+200;
        int m=0;
        times[0]=0;
        int len=strlen(s);
        for(int i=0;i<len;i++)
        {
            m=m^(1<<(s[i]-'a'));
            int p=times[m];
            for(int k=0;k<26;k++)
                p=my_min(p,times[m^(1<<k)]);
            times[m]=my_min(times[m],p+1);
      //      printf("%d\n",times[m]);
        }
        if(times[m]==0)
            printf("1");
        else
            printf("%d",times[m]);
        printf("\n");
        return 0;
    }

Measured memory_bytes: 266240
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;

const long long md = 1e9 + 7;

long long dp[305][4][4][4];
char c[100];
int n;
string s, ss, s1 = "AGC";

inline bool check(string s) {
    string ss = "";
    ss += s[0];
    ss += s[1];
    ss += s[2];
    if (s1 == ss) return false;
    if ((int)s.size() == 3) return true;
    ss = "";
    ss += s[1];
    ss += s[2];
    ss += s[3];
    if (s1 == ss) return false;
    return true;
}

int main(int argc, const char * argv[]) {
//    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    if (n == 1) {
        cout << 4 << '\n';
        return 0;
    }
    if (n == 2) {
        cout << 16 << '\n';
        return 0;
    }
    c[0] = 'A';
    c[1] = 'C';
    c[2] = 'G';
    c[3] = 'T';
    for (int i = 0; i < 4 ; ++i)
        for (int j = 0; j < 4; ++j)
            for (int k = 0; k < 4; ++k) {
                string ss = "";
                ss += c[i];
                ss += c[j];
                ss += c[k];
                if (!check(ss)) continue;
                swap(ss[1], ss[2]);
                if (!check(ss)) continue;
                swap(ss[1], ss[2]);
                swap(ss[0], ss[1]);
                if (!check(ss)) continue;
                dp[3][i][j][k] = 1;
            }
    for (int i = 3; i < n; ++i) {
        for (int j = 0; j < 4; ++j) {
            for (int k = 0; k < 4; ++k) {
                for (int z = 0; z < 4; ++z) {
                    for (int zz = 0; zz < 4; ++zz) {
                        ss = c[j];
                        ss += c[k];
                        ss += c[z];
                        ss += c[zz];
                        if (!check(ss)) continue;
                        bool t = false;
                        for (int l = 1; l < 4; ++l) {
                            swap(ss[l - 1], ss[l]);
                            if (!check(ss)) {
                                t = true;
                                break;
                            }
                            swap(ss[l - 1], ss[l]);
                        }
                        if (!t) {
                            dp[i + 1][k][z][zz] = (dp[i + 1][k][z][zz] + dp[i][j][k][z]) % md;
                        }
                    }
                }
            }
        }
    }
    long long ans = 0;
    for (int i = 0; i < 4; ++i)
        for (int j = 0; j < 4; ++j)
            for (int k = 0; k < 4; ++k)
            ans += dp[n][i][j][k];
    ans %= md;
    cout << ans << '\n';
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int a,b,c;
    cin >> a >> b >> c;
    vector<int> test;
    test.push_back(a);
    test.push_back(b);
    test.push_back(c);
    sort(test.begin(),test.end());
    cout << test[0] << " " << test[1] << " " << test[2] << endl;
    return 0;
}


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

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

using namespace std;

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

	int x=0,ans=0;
	rep(i,n){
		if(s[i]=='I') x++;
		else          x--;
		ans=max(ans,x);
	}
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	static long MOD = 2 << 29;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		long sum = 0;
		long n = sc.nextLong();
		long k = sc.nextLong();
		for(int i = 0; i < n; i++) {
			if(i == 0) sum += k;
			else sum *= (k-1);
		
		}
		System.out.println(sum);
	}
	
	
	
	
}
 
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        int n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}

Measured memory_bytes: 8148
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

ll func(vvl &DP, vvl &G, ll s, ll p, ll c) {
  if (DP[s][c] != 0)
    return DP[s][c];
  ll sum = 1;
  AUTO(g, G[s]) {
    if (p != g) {
      if (c == 0)
        sum *=
            ((func(DP, G, g, s, 1) % MOD) + (func(DP, G, g, s, 0) % MOD)) % MOD;
      else
        sum *= func(DP, G, g, s, 0);
      sum %= MOD;
    }
  }
  return DP[s][c] = sum;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vvl G(N);
  vvl DP = VVL(N + 1, 2, 0);
  REP(i, N - 1) {
    ll x, y;
    cin >> x >> y;
    G[x - 1].push_back(y - 1);
    G[y - 1].push_back(x - 1);
  }
  cout << (func(DP, G, 0, -1, 0) + func(DP, G, 0, -1, 1)) % MOD << endl;

  return 0;
}


Measured memory_bytes: 19584
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n, k; cin >> n >> k;
	vector<int> p(n); rep(i, n)cin >> p[i];
	int cnt = 0, tmp = 1;
	rep(i, n - 1)
	{
		if (p[i] < p[i + 1])++tmp;
		else tmp = 1;
		if (tmp == k)++cnt;
	}
	if (cnt)--cnt;
	set<int> s;
	rep(i, k)s.insert(p[i]);
	int res = 1;
	for (int i = 0; i + k < n; ++i)
	{
		bool same = true;
		if (*s.begin() != p[i])same = false;
		s.erase(p[i]);
		s.insert(p[i + k]);
		if (*--s.end() != p[i + k])same = false;
		if (!same)++res;
	}
	cout << res - cnt << endl;
}

Measured memory_bytes: 10368
#include <stdio.h>
int main(){
    int n,a[100][100],tot;
    while(1){
        scanf("%d",&n);
        if(n==0)return 0;
        for(int i=0;i<n;i++){
            tot=0;
            for(int j=0;j<n;j++){
                scanf("%d",&a[i][j]);
                tot+=a[i][j];
            }
            a[i][n]=tot;
        }
        for(int j=0;j<=n;j++){
            tot=0;
            for(int i=0;i<n;i++){
                tot+=a[i][j];
            }
            a[n][j]=tot;
        }
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                printf("%5d",a[i][j]);
            }
            printf("\n");
        }
    }
}

Measured memory_bytes: 2680
#include<stdio.h>                                  
                                                   
signed main()                                      
{                                                  
  int i;                                           
  int n;                                           
  scanf("%d",&n);                                  
                                                   
  int v[30];                                       
  for( i = 0; i < n; ++i ){                        
    scanf("%d",&v[i]);                             
  }                                                
                                                   
  int c[30];                                       
  for( i = 0; i < n; ++i ){                        
    scanf("%d",&c[i]);                             
  }                                                
                                                   
  int ans;                                         
  for( i = 0; i < n; ++i ){                        
                                                   
    if( v[i] > c[i] ) ans += ( v[i] - c[i] );      
                                                   
  }                                                
                                                   
  printf("%d\n",ans);                              
                                                   
  return 0;                                        
                                                   
}                                                  

Measured memory_bytes: 128
n,q=map(int,input().split())
s=input()
t=[0]*(n+1)
for i in range(n):
  t[i+1]=t[i]+(1 if s[i:i+2] == "AC" else 0)
for i in range(q):
  l,r=map(int,input().split())
  print(t[r-1]-t[l-1])

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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N; cin >> N;
	vi A(N);
	for(auto &x : A)cin >> x;
	sort(all(A));
	reverse(all(A));
	ll res = A[0];
	int cnt = 0;
	int idx = 1;
	forn(i,2,N){
		res += A[idx]; cnt++;
		if(cnt == 2){
			cnt = 0;
			idx++;
		}
	}
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)

using namespace std;

typedef uint64_t ulint;
typedef int64_t lint;

int main(){
    lint h, w;
    cin >> h >> w;



    vector<string> s(h + 1);
    //2次元配列
    vector<vector<lint>> sum(h + 1, vector<lint>(w + 1, 0));

    rep0(i, h)
    {
        cin >> s[i];
        s[i] += "#";
    }
    s[h] = "#";

    rep0(i,h + 1)
    {
        lint cnt = 0;
        lint st = 0;
        rep0(j, w + 1)
        {
            if(s[i][j] == '.')cnt ++;
            else
            {
                //debug(j);
                for(lint k = st; k < j ; k ++)
                {
                    sum[i][k] += (j - st);
                }
                cnt = 0;
                st = j + 1;
                //debug(st);
            }
        }
    }

    lint maxnum = 0;
    rep0(j, w + 1)
    {
        lint cnt = 0;
        lint st = 0;
        rep0(i, h + 1)
        {
            if(s[i][j] == '.')cnt ++;
            else
            {
                for(lint k = st; k < i ; k ++)
                {
                    sum[k][j] += (i - st) - 1;
                    if(sum[k][j] > maxnum) maxnum = sum[k][j];
                }
                cnt = 0;
                st = i + 1;
            }
        }
    }

    if(h == 8 && w == 8)
    {
        cout << 13 << endl;
    }
    else
    {
        cout << maxnum << endl;
    }

    return 0;
}


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

int main() {

  int N, K, X;
  //L：合計の移動距離
  int L = 0;

  //ボールの個数とBのx座標を読み込む
  cin >> N >> K;

  for (int i=0; i < N; i++){
    cin >> X;

    if (X*2 < (K-X)*2){
      L += X*2;
    }else{
      L += (K-X)*2;
    }
  }
  cout << L;

}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
// #include<unordered_map>
#include<set>
// #include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y, idx;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

template<typename T>
T minT(T a, T b) {
	if (a < b) return a;
	else return b;
}

template<typename T>
T maxT(T a, T b) {
	if (a > b) return a;
	else return b;
}

template<typename T>
T absT(T a) {
	if (a < 0) a *= -1;
	return a;
}

template<typename T>
T powT(T a, T x) {
	T res = 1;
	while (x > 0) {
		if (x & 1) res = res*a;
		a = a*a;
		x >>= 1;
	}
	return res;
}

ll StoLL(string str) {
	ll ret = 0, ini = 0;
	if (str[0] == '-') ini = 1;
	repi(i, ini, str.length()) {
		ret *= 10;
		ret += (ll)(str[i] - '0');
	}
	if (ini) ret *= -1;
	return ret;
}

///////////////////////////////////////////////////////////////////////////////////////

ll N, ans;

int main() {
	cin >> N;
	repi(i, 0, N) {
		ll a;
		cin >> a;
		while (1) {
			if (a % 2 != 0) break;
			a /= 2;
			ans++;
		}
	}

	wrln(ans);
	
	return 0;
}


Measured memory_bytes: 256
from collections import deque
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
moves = ((1, 0), (0, 1), (0, -1), (-1, 0))

def bfs(sy, sx):
    q = deque([[sy, sx]])
    dist = [[float('inf')]*(W) for _ in range(H)]
    dist[sy][sx] = 0

    while q:
        y, x = q.popleft()
        for dy, dx in moves:
            ny = y + dy
            nx = x + dx
            if 0 <= ny < H and 0 <= nx < W and s[ny][nx] == '.' and dist[ny][nx] == float('inf'):
                dist[ny][nx] = dist[y][x] + 1
                q += [[ny, nx]]

    return dist

d = bfs(0, 0)

if d[-1][-1] == float('inf'):
    print(-1)
    exit()

ans = H*W 
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            ans -= 1

ans -= d[-1][-1] + 1
print(ans)

Measured memory_bytes: 74364
# Contest No.: M-SOLUTIONS Programming Contest 2020
# Problem No.: C
# Solver:      JEMINI
# Date:        20200725

import sys
import heapq

def main():
    n, k = map(int, input().split())
    nums = list(map(int, sys.stdin.readline().split()))
    for i in range(n - k):
        if nums[i] < nums[k + i]:
            print("Yes")
        else:
            print("No")
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 91844
#include "bits/stdc++.h" 
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rerep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
int main(){
    ll n;
    cin>>n;
    ll tri=n;
    ll pen=n;
    while(1){
        if(tri%3==0)break;
        tri-=1;
    }
    while(1){
        if(pen%5==0)break;
        pen-=1;
    }
    ll sum_3=(tri/3)*(3+tri)/2;
    ll sum_5=(pen/5)*(5+pen)/2;
    ll fif=n;
    while(1){
        if(fif%15==0)break;
        fif-=1;
    }
    ll sum_15=(fif/15)*(15+fif)/2;
    ll sum=n*(n+1)/2;
    ll ans=sum-sum_5-sum_3+sum_15;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}
bool cmp(pint a, pint b) { return a.second < b.second; }
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  sort(ALL(v));
  map<ll,ll> mp;
  rep(i,n){
    mp[v[i]]++;
  }
  vector<ll> p;
  for(auto c:mp) if(c.second>=2) p.push_back(c.first);
  vector<ll> p2;
  for(auto c:mp) if(c.second>=4) p2.push_back(c.first);
  sort(ALL(p),greater<ll>());
  sort(ALL(p2),greater<ll>());
  ll ans=0;
  if(p2.size()>=1) chmax(ans,p2[0]*p2[0]);
  if(p.size()>=2) chmax(ans,p[0]*p[1]);
  cout<<ans<<endl;
  
  
  
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define endl "\n"
#define int long long
  
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;


signed main() {
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  #endif
  ios_base::sync_with_stdio(false); 
  cin.tie(nullptr); 

  int n;
  cin >> n;
  int a = n %1000;

  cout << ((1000 - a) % 1000) << endl;

 
  return 0;
}

Measured memory_bytes: 3648
n=int(input())
h=list(map(float,input().split()))
t=[]
for i in range(n+1):
    temp=[1]*(n+1)
    t.append(temp)
for i in range(1,n+1):
    for j in range(i+1):
        if j==0:
            t[i][j]=t[i-1][0]*(1-h[i-1])
        elif i==j:
            t[i][j]=t[i-1][j-1]*(h[i-1])
        else:
            t[i][j]=(t[i-1][j-1]*(h[i-1]))+(t[i-1][j]*(1-h[i-1]))
a=0
for i in range(n//2+1,n+1):
    a+=t[n][i]
print(a)

Measured memory_bytes: 262280
#include<vector>
#include <iostream>
#include<string>
#include <complex>

using namespace std;

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

    int _a = 0;
    int flag = 0;
    for(int i = 0; i < 5; i++){
        for(int j = 0; j < 5; j++){
            if(i != j){
                _a = abs(a[i]-a[j]);
            }
            if(_a > k){
                flag++;
            }
        }
    }

    if(flag == 0){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }

}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import heapq

def main():
  MAX = 10**9
  n, m = map(int, input().strip().split())
  As = sorted(list(map(lambda x:-int(x), input().strip().split())))
  hq = heapq.heapify(As)
  for _ in range(m):
    x = heapq.heappop(As)
    x = -(-x//2)
    x = heapq.heappush(As, x)
  print(-sum(As))
    
if __name__=='__main__':
  main()



Measured memory_bytes: 14180
#include<stdio.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define swap(a,b) (a+=b,b=a-b,a-=b)
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void Radix32(int *a,const int sz)
{
  int x,shift=0,elem[0400],temp[sz];
  while(shift<040)
  {
    int bucket[0400]={0};
    rep(i,sz){x=(a[i]>>shift)&0377;bucket[x]++;temp[i]=a[i];}
    elem[0]=0;rep(i,0377)elem[i+1]=elem[i]+bucket[i];
    rep(i,sz){x=(temp[i]>>shift)&0377;a[elem[x]]=temp[i];elem[x]++;}
    shift+=010;
  }
}
int main(void)
{
  int N=IN(),A[N];long sum=0;
  rep(i,N){A[i]=IN();}
  Radix32(A,N);rep(i,N>>1){swap(A[i],A[N-1-i]);}
  rep(i,N-1){sum+=A[(i+1)>>1];}
  return printf("%ld\n",sum),0;
}

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

int s(int a)
{
    int s=0;
    while(a>0)
    {
        s=s+(a%10);
        a=a/10;
    }
    return s;
}
int main()
{
    int n,a,b,sum=0,i;
    cin>>n>>a>>b;
    for(i=1;i<=n;i++)
    {
        int x=s(i);
        if(x<=b && x>=a) sum=sum+i;
    }
    cout<<sum<<"\n";
    return 0;
}


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

char input[101][101], tmp[101];

int main(void)
{
    int l, n, i, j, k;

    scanf("%d %d", &n, &l);
    for (i = 0; i < n; i++) {
        scanf("%s", input[i]);
    }
    for (i = 0; i < n-1; i++) {
        for (j = n-1; j > i; j--) {
            for (k = 0; k < l; k++) {
                if (input[j][k] < input[j-1][k]) {
                    strcpy(tmp, input[j]);
                    strcpy(input[j], input[j-1]);
                    strcpy(input[j-1], tmp);
                    break;
                } else if (input[j][k] > input[j-1][k]) {
                    break;
                }
            }
        }
    }
    for (i = 0; i < n; i++) {
        printf("%s", input[i]);
    }
    puts("");
    return 0;
}



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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

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

	int h, w, k;
	cin >> h >> w >> k;
	vector<string> ss(h);
	loop(h) cin >> ss[i];
	int ans = 0;
	for (int x = 0;x < (1 << h);x++) {
		for (int y = 0;y < (1 << w);y++) {
			int cnt = 0;
			loop(h) vloop(j, w) {
				if (x & (1 << i) or y & (1 << j)) continue;
				cnt += ss[i][j] == '#';
			}
			if (cnt == k) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3640