akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 

ll n,m,i,j,k,in,cnt = 0,l,r,u,v,x,y,tc = 1,mod = 1000000007  ;
const ll  mx = 100001 ;
ll power(ll x, ll y, ll p = mod) 
{ 
    ll res = 1;
    x = x % p;
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
  
        y = y>>1;  
        x = (x*x) % p; 
    } 
    return res; 
} 

ll modInverse(ll n, ll p = mod) 
{ 
    return power(n, p-2, p); 
} 
ll fac[mx*10]; 
ll nCrModPFermat(ll n, ll r, ll p = mod) 
{ 
   
   if (r==0) 
      return 1;
    return (fac[n]* modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p; 
} 

void solve(){
    ll x,y;
    cin>>x>>y;
    if((x+y)%3!=0){
        cout << 0 << endl;
        return;
    }
    else{
        ll ans = 0ll;
        for (ll i = 0; i <= (x+y)/3; ++i)
        {
            // cout << (x-2*i)*2 + i << " "  <<y << endl;
            if(((x-2*i)*2 + i) == y)
                ans = (ans+ nCrModPFermat((x+y)/3,i))%mod;
        } 
        cout << ans << endl;
    }
    
}
signed main(){                                          //F
    clock_t time = clock();                             //A
    ios_base::sync_with_stdio(0);                       //S
    cin.tie(0);                                         //T
    cout.tie(0);                                        //I
    cerr.tie(0);                                        //O
    if(0) cin>>tc;
    fac[0] = 1; 
    for (ll i=1 ; i<=mx*10; i++) 
        fac[i] = (fac[i-1]*i)%mod ;
    for (int i = 0; i < 1000; ++i)
    {
        // cout << fac[i] << endl;
    }
    while(tc--)
        solve();
}

Measured memory_bytes: 8064
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int s;
  	cin >> s;
  	
  	vector<int>	value;
  
  	bool flg = true;
  
  	int num = 1;
  
  	value.resize(0);	
  	
  	value.push_back(s);
  
  	while(flg)
    {
      	num++;	
      
    	if(s%2==0)
        {
			s /= 2;
        }
      	else
      	{
      		s = 3*s + 1;
        }
      
      	for(int i=0;i<value.size();i++)
        {
        	if(value[i] == s)
            {
            	printf("%d",num);	
              
              flg = false;
              break;
            }
        }
      
      	value.push_back(s);
    }

  	return 0;
}


Measured memory_bytes: 256
while True:
  a, op, b = input().split()
  a=int(a)
  b=int(b)
  if op=='+':
    print(a+b)
  elif op=='-':
    print(a-b)
  elif op=='*':
    print(a*b)
  elif op=='/':
    print(a//b)
  elif op=='?':
    exit()


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  string s;
  cin>>s;

  using A = array<Int, 2019>;
  A dp,nx;
  fill(dp.begin(),dp.end(),0);

  Int ans=0;
  for(char c:s){
    fill(nx.begin(),nx.end(),0);
    dp[0]++;
    for(Int i=0;i<2019;i++)
      nx[(i*10+c-'0')%2019]+=dp[i];

    swap(dp,nx);
    ans+=dp[0];
  }
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 3816
#include <cstdio>
#include <string>
#include <iostream>
#include <map>
 
using namespace std;
 
int main(){
  map<string,int> table;
  string word,ans1,ans2;
  int freq=0,len=0;
  while(cin >> word){
 
 
    if(table.find(word)==table.end()){
      table[word] = 1;
    }else{
      table[word]++;
    }
    if(table[word]>freq){
      freq = table[word];
      ans1 = word;
    }
    if(word.size()>len){
      len = word.size();
      ans2 = word;
    }
  }
  cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 3064
n = int(input())
data = list(map(int, [input() for i in range(n)]))
inf = -float("inf")
dp = [inf for i in range(n)]
tsum = 0
for i in range(1, n):
    t = data[i]-data[i-1]
    tsum += t
    if(dp[i] < tsum):
        dp[i] = tsum
    else:
        dp[i] = dp[i-1]
    if tsum < 0:
        tsum = 0
print(max(dp))


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

typedef long long int ll;

int main(){

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

    int m;
    cin>>m;

    unordered_map<int,int>mp;

    vector<int>v(m);
    for(int &x:v)cin>>x,mp[x]++;

     int g = __gcd(v[0],v[1]);

     for(int i = 2; i < m ; i++){
         g = __gcd(g,v[i]);
     }

     if(g > 1){
         cout<<"not coprime";
         return 0;
     }

    int n = 1000000;
    vector<char> is_prime(n+1, true);
    is_prime[0] = is_prime[1] = false;

    vector<int>res(n+1,0);

    for (int i = 2; i <= n; i++) {

        if (is_prime[i]) {

            for (int j = i; j <= n; j += i){
                is_prime[j] = false;

                if(mp[j])res[i] += mp[j];

            }
        }
    }

    int c = 0;

    for(int i = 1; i <= n ; i++){
        if(res[i] > 1)c++;
    }

    if(c){
        cout<<"setwise coprime";
        return 0;
    }

    cout<<"pairwise coprime";

    return 0;

}



Measured memory_bytes: 51484
#include<iostream>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(s==u)
    {
        a--;
    }
    else if(t==u)
    {
        b--;
    }
    cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
   int a,b,x;

   scanf("%d%d%d",&a,&b,&x);

   if(a>x)
    printf("NO\n");
   else{
     x -= a;
     if(b>x)
       printf("YES\n");
     else
       printf("NO\n");
   }

   return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

typedef struct Team {
  int WA[20] = {};
  int AC = 0;
  int score = 0;
  int ID;
  bool operator<(const Team &o) const {
    if (AC == o.AC) {
      if (score == o.score) {
        return ID < o.ID;
      } else {
        return score < o.score;
      }
    } else {
      return AC > o.AC;
    }
  }
} team;

signed main() {
  int T, P, R;
  while (1) {
    cin >> T >> P >> R;
    if (T == 0 && P == 0 && R == 0) break;
    vector<team> tm(T);
    rep(i, T) tm[i].ID = i + 1;

    rep(i, R) {
      int t, p, times;
      string s;
      cin >> t >> p >> times >> s;
      t--;
      p--;
      if (s == "CORRECT") {
        tm[t].AC++;
        tm[t].score += tm[t].WA[p] * 1200 + times;
      } else {
        tm[t].WA[p]++;
      }
    }
    sort(all(tm));
    rep(i, T) { cout << tm[i].ID << ' ' << tm[i].AC << ' ' << tm[i].score << endl; }
  }
  return 0;
}



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

int main() {
    int n;
    cin >> n;
    int d[n];
    rep(i, n) cin >> d[i];

    int sum = 0;
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            sum += d[i] * d[j];
        }
    }

    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int x;
		int y;
		if(a >= b) {
			x = a;
			y = b;
		}else {
			x = b;
			y = a;
		}
		int gcd;
		while ((gcd = x % y) != 0) {
			x = y;
			y = gcd;
		}
		System.out.println(y);
	}

}


Measured memory_bytes: 26344
#include <iostream>

using namespace std;

int main()
{
   int N;
   cin >> N;
   int A[N],B[N],i;
   for(i=1;i<N;i++){
       cin >> A[i];
       B[i] = 0;
   }
   for(i=1;i<N;i++){
       B[A[i]]+=1;
   }
   for(i=1;i<N;i++){
       cout << B[i] << endl;
   }
   cout << "0";
   return 0;
}

Measured memory_bytes: 5188
#include "bits/stdc++.h"
using namespace std;
#define lint long long
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, n) for (int i = int(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to; double cost; };
#define P pair<int, int>
#define D pair<double, double>
#define DI pair<double, int>
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3LL * mod * mod;

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

lint modpow(lint x, lint n, lint m) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (m <= ans) ans %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint inver[1000000]; bool inve[100000];
lint inv(lint x) {
	if (x == 0) return 0;
	else if (inve[x]) return inver[x];
	else {
		inve[x] = true;
		return inver[x] = modpow(x, mod - 2, mod);
	}
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * inv(fact[n - r]) % mod * inv(fact[r]) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

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

bool pri(lint p) {
	for (lint i = 2; i * i <= p; i == 2 ? ++i : i += 2) if (p % i == 0) return false;
	return p > 1;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

int n, a, w = 1e9 + 7, cnt;
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a;
		if (w < a) ++cnt;
		w = a;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    int H, W;
    cin >> H >> W;
    vector<vector<char>> C(H, vector<char>(W));
    for (int j = 0; j < H; j++){
      for (int k = 0; k < W; k++){
        cin >> C[j][k];
      }
    }
    vector<int> Y_min(26, H);
    vector<int> Y_max(26, -1);
    vector<int> X_min(26, W);
    vector<int> X_max(26, -1);
    for (int j = 0; j < H; j++){
      for (int k = 0; k < W; k++){
        if (C[j][k] != '.'){
          int c = C[j][k] - 'A';
          Y_min[c] = min(Y_min[c], j);
          Y_max[c] = max(Y_max[c], j);
          X_min[c] = min(X_min[c], k);
          X_max[c] = max(X_max[c], k);
        }
      }
    }
    bool ok = true;
    vector<set<int>> E(26);
    for (int j = 0; j < 26; j++){
      if (Y_min[j] != H){
        for (int k = Y_min[j]; k <= Y_max[j]; k++){
          for (int l = X_min[j]; l <= X_max[j]; l++){
            if (C[k][l] == '.'){
              ok = false;
            } else {
              int c = C[k][l] - 'A';
              if (c != j){
                E[c].insert(j);
              }
            }
          }
        }
      }
    }
    if (!ok){
      cout << "SUSPICIOUS" << endl;
    } else {
      vector<int> deg(26, 0);
      for (int j = 0; j < 26; j++){
        for (int k : E[j]){
          deg[k]++;
        }
      }
      queue<int> Q;
      for (int j = 0; j < 26; j++){
        if (deg[j] == 0){
          Q.push(j);
        }
      }
      while (!Q.empty()){
        int v = Q.front();
        Q.pop();
        for (int w : E[v]){
          deg[w]--;
          if (deg[w] == 0){
            Q.push(w);
          }
        }
      }
      for (int j = 0; j < 26; j++){
        if (deg[j] != 0){
          ok = false;
        }
      }
      if (ok){
        cout << "SAFE" << endl;
      } else {
        cout << "SUSPICIOUS" << endl;
      }
    }
  }
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,m;cin >> n >>m;
    ll x[n][3];
    ll ans=0;
    rep(i,n)cin >> x[i][0] >>x[i][1]>>x[i][2];
    rep(bit,8){
        ll c=0;
        vl p(n);
        rep(i,n){
            ll tmp=0;
            rep(j,3){
                if(bit&(1<<j))tmp+=x[i][j];
                else tmp-=x[i][j];
            }
            p[i]=tmp;
        }
        sort(all(p));
        rev(all(p));
        rep(i,m){
            c+=p[i];
        }
        chmax(ans,c);
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)                                                         

using namespace std;
#define ll long long

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
program brick_break
  implicit none
  integer :: n, a(200000) = 0, i, k = 0
  read(*,*) n
  read(*,*) a(1:n)
  do i = 1, n
    if (a(i) == k+1) then
      k = k+1
    end if
  end do
  if (k == 0) k = n+1
  write(*,'(i0)') n-k
end program brick_break

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  string s;
  cin >> s;
  if(s[0] == 'S') cout << "Cloudy";
  else if(s[0] == 'C') cout << "Rainy";
  else cout << "Sunny";
}

Measured memory_bytes: 256
#include<iostream> 
#include<algorithm> 
using namespace std; 
int main(){ 
  int t[20001],n,s,g,L,R,M,sum,m; 
  t[0]=-1; 
  while(1){ 
    cin>>n>>s; 
    if(n==0&&s==0)break; 
    for(int i=1;i<=n;i++)cin>>t[i]; 
    sort(t+1,t+n+1); 
    //cout<<"---"<<endl; 
    sum=0; 
    for(int i=1;i<=n-1;i++){ 
      g=s-t[i]+1; 
      if(g<0)g=0; 
      L=1; 
      R=n+1; 
      M=(L+R)/2; 
  
      while(1){ 
    if(t[M]>=g&&t[M-1]<g){ 
      if(i<M){ 
        m=M; 
      }else{ 
        m=i+1; 
      } 
      sum+=(n-m+1); 
      // cout<<t[M]<<" "<<m<<" "<<sum<<endl; 
      break; 
    }else if(L>=R-1){ 
      break; 
    }else if(t[M]<g){ 
      L=M;M=(L+R)/2; 
    }else{ 
      R=M;M=(L+R)/2; 
    } 
      } 
    } 
    cout<<sum<<endl; 
    //for(int i=0;i<=n;i++)cout<<t[i]<< " "; 
    //cout<<endl; 
      
      
  } 
  return 0; 
} 

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int H,N;
  cin >> H >> N;
  
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  
  for(int i=0; i<N; i++){
    
    H-=A.at(i);
    
  }
  
  if(H<=0){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
  
  
}

Measured memory_bytes: 640
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;

struct edge{
  int from,to,cost;
};
typedef vector<vector<edge> > AdjList;
AdjList graph;
typedef pair<int , int> P;
typedef long long int ll;
bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}
int E,V;
edge es[100001];
ll kruskal(){
  sort(es,es+E,comp);
  init(V);
  ll res = 0;
  for(int i=0;i<E;i++){
    edge e = es[i];
    if(!same(e.to,e.from)){
      unite(e.to,e.from);
      res += e.cost;
    }
  }
  return res;
}


int main()
{
  ll N,A,B,x[100001],b=0,res=0;
  cin >> N >> A >> B;
  REP(i,N){
    cin >> x[i];
  }
  for(int i=1;i<N;i++){
    res += min((x[i]-x[i-1])*A ,  B);
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 1024
#include<stdio.h>

int main(void) {
  int i;
  char s[3], t[3];
  scanf("%s %s", &s, &t);

  if (s[0] != t[0] && s[1] != t[1] && s[2] != t[2]) printf("0");
  else if (s[0] == t[0] && s[1] != t[1] && s[2] != t[2]) printf("1");
  else if (s[1] == t[1] && s[0] != t[0] && s[2] != t[2]) printf("1");
  else if (s[2] == t[2] && s[0] != t[0] && s[1] != t[1]) printf("1");
  else if (s[0] == t[0] && s[1] == t[1] && s[2] != t[2]) printf("2");
  else if (s[0] == t[0] && s[2] == t[2] && s[1] != t[1]) printf("2");
  else if (s[1] == t[1] && s[2] == t[2] && s[0] != t[0]) printf("2");
  else {printf("3");}
  
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1e18;

vl divisor(ll n) {
  vl ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  //
  ll n;
  cin >> n;
  vl d = divisor(n);
  ll ans = n;
  for (auto &x : d) {
    if (x * x > n) break;
    ll y = n / x;
    ans = min(ans, (x - 1) + (y - 1));
  }
  cout << ans << endl;
  return 0;
}


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

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

int main(){
  int a;
  cin >> a;
  string s;
  cin >> s;
  if(a>=3200){
    cout << s << endl;
  }else{
    cout << "red" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset> 
using namespace std;
typedef long long ll;
ll a[1003][1003],c[1003];
ll n,m,x;
ll mi=1e18;
void dfs(ll now,vector<ll> b)
{
//	printf("%lld %lld\n",now,n);
	if(now==n)
	{
		ll m1[20]={0};
		ll sum=0;
		for(ll i=0;i<b.size();i++)
		{
//			printf("%lld ",b[i]);
			sum+=c[b[i]];
			for(ll j=0;j<m;j++)
			{
				m1[j]+=a[b[i]][j];
			}
		}
//		printf("\n");
		for(ll i=0;i<m;i++) if(m1[i]<x) return;
		mi=min(mi,sum);
		return;
	}
//	printf("1");
	dfs(now+1,b);
	for(ll i=now+1;i<n;i++)
	{
		b.push_back(i);
		dfs(i,b);
		b.pop_back();
	}
}
int main(void)
{
	scanf("%lld %lld %lld",&n,&m,&x);
	for(ll i=0;i<n;i++)
	{
		scanf("%lld",&c[i]);
		for(ll j=0;j<m;j++) scanf("%lld",&a[i][j]);
	}
	vector<ll> b;
	dfs(-1,b);
	if(mi==1e18)
	{
		printf("-1");
	}
	else
	{
		printf("%lld",mi);
	}
}

Measured memory_bytes: 3844
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var date = ReadLine().Split("/").Select(long.Parse).ToArray();
            if (20190430 < date[0] * 10000 + date[1] * 100 + date[2])
                WriteLine("TBD");
            else
                WriteLine("Heisei");
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define all(c) begin(c),end(c)
const ll INF = 1e10;

int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	vector<ll>A(N);
	vector<ll>p;
	rep(i, N) {
		cin >> A[i];
	}
	sort(A.begin(),A.end(),greater<ll>());
	ll x = A[0] , y = 0;
	bool flag = false;
	reps(i,1, N) {
		if (x == A[i] && !flag) {
			y = A[i];
			if (i != N - 1) {
				x = A[i + 1];
				i++;
			}
			flag = true;
		}
		else if (x == A[i] && flag) {
			cout << x*y << endl;
			return 0;
		}
		x = A[i];
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using ll = unsigned long long;
using namespace std;

int main(void) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int xlen = x2 - x1;
    int ylen = y2 - y1;

    cout << x2 - ylen << " " << y2 + xlen <<" " << x1 - ylen << " " << y1 + xlen << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
int main(void)
{
	int n,a=0;
	char w[10],r[100][21],cpy[21],tem;
	cin >> w;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> r[i];
		strcpy(cpy,r[i]);
		strcat(r[i],cpy);
		if(tem=strstr(r[i],w) != NULL){
			a++;
		}
	}
	cout << a << endl;
	
	return 0;
}

Measured memory_bytes: 3076
// Problem : C - One Quadrillion and One Dalmatians
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll MX = 1000000000000001LL; //check the limits, dummy
 
int main() 
{
	//incomplete
	ios_base::sync_with_stdio(0); cin.tie(0); 
	ll N;
	cin>>N;
	vi ans;
	while(N!=0)
	{
		N--;
		ans.pb(N%26);
		N/=26;
	}
	// ans.pb(N-1);
	F0Rd(x,sz(ans))//reverse?
	{
		cout<<(char)(ans[x]+'a');
	}
	// cout<<endl<<mul/26<<endl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3656
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define mp std::make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007
typedef long long ll; 
struct data
{
	int u, v, w; 
	inline bool operator <(const data &a) const
	{
		return w < a.w; 
	}
} arr[2005]; 
int fa[1005]; 
inline ll quick_pow(ll a, int n)
{
	ll res = 1; 
	while (n)
	{
		if (n & 1)
			res = res * a % MOD; 
		a = a * a % MOD; 
		n >>= 1; 
	}
	return res; 
}
int getfa(int u)
{
	if (u == fa[u])
		return u; 
	return fa[u] = getfa(fa[u]); 
}
inline bool unite(int u, int v)
{
	u = getfa(u); 
	v = getfa(v); 
	fa[u] = v; 
	return u != v; 
}
int main()
{
	// freopen("ARC093-E.in", "r", stdin); 
	int n, m; 
	ll x; 
	scanf("%d%d%lld", &n, &m, &x); 
	if (n <= 2)
	{
		puts("0"); 
		return 0; 
	}
	for (int i = 0; i < m; i++)
	{
		scanf("%d%d%d", &arr[i].u, &arr[i].v, &arr[i].w); 
		arr[i].u--; 
		arr[i].v--; 
	}
	std::sort(arr, arr + m); 
	int cntx = 0, cnty = 0; 
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
			fa[j] = j; 
		ll sum = arr[i].w * unite(arr[i].u, arr[i].v); 
		for (int j = 0; j < m; j++)
			sum += arr[j].w * unite(arr[j].u, arr[j].v); 
		if (sum < x)
			cntx++; 
		if (sum <= x)
			cnty++; 
	}
	printf("%lld\n", (quick_pow(2, std::min(m, m - cntx + 1))
		 - quick_pow(2, std::min(m, m - cnty + 1)) + MOD) % MOD);
	return 0; 
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>
using namespace std;
int m,n;
int d[500];
int dp[500][500];
int main(void){
	while(1){
		scanf("%d",&m);
		if(m==0)break;
		scanf("%d",&n);
		memset(d,0,sizeof(d));
		memset(dp,0,sizeof(dp));
		for(int i=1;i<=n;i++)scanf("%d",&d[i]);
		for(int i=0;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(d[i+j]==0)dp[i][i+j]=1;
				if(d[i+j]>=1)dp[i][min(i+j+d[i+j],n+1)]=1;
				if(d[i+j]<=-1)dp[i][max(0,i+j+d[i+j])]=1;
			}
		}
		for(int k=0;k<=n+1;k++){
			for(int i=0;i<=n+1;i++){
				for(int j=0;j<=n+1;j++){
					if(dp[i][k]==1 && dp[k][j]==1)dp[i][j]=1;
				}
			}
		}
		bool f=true;
		/*
		for(int i=0;i<=n+1;i++){
			for(int j=0;j<=n+1;j++)printf("%d%c",dp[i][j],j==n+1?'\n':' ');
		}
		*/
		for(int i=0;i<=n;i++){
			if(dp[0][i]==1 && dp[i][n+1]==0)f=false;
		}
		if(f)puts("OK");
		else puts("NG");
	}
	return 0;
}

Measured memory_bytes: 2152
#include<iostream>
#include<vector>
#include<numeric>

using namespace std;

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

    vector<int>B;
    int temp;
    for(int i=0;i<n-1;i++){
        cin >> temp;
        B.push_back(temp);
    }

    vector<int>A(n,0);
    for(int i=0;i<n-1;i++){
        if(i==0){
            A[i] = B[i];
            A[i+1] = B[i];
        }else{
            if(A[i]>B[i]){
                A[i] = B[i];
            }
            A[i+1] = B[i];
        }
    }
    /* 
    cout << "B[";
    for(int i=0;i<n-1;i++){
        cout << B[i] << ",";
    }
    cout << "]" << endl;


    cout << "A[";
    for(int i=0;i<n;i++){
        cout << A[i] << ",";
    }
    cout << "]" << endl;
    */

    cout << accumulate(A.begin(),A.end(),0) << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def err():
    print('Impossible')
    quit()
n,m = inpl()
g = [list(input()) for _ in range(n)]
su = 0
for i in range(n):
    for j in range(m):
        if g[i][j] == '#':
            su += 1 
if g[0][0] == '.' or su != n+m-1:
    err()
for fl in itertools.permutations(range(n+m-2), n-1):
    # print(fl)
    now = [0,0]
    for i in range(n+m-2):
        if i in fl:
            now[0] += 1
        else:
            now[1] += 1
        y,x = now
        if g[y][x] == '.':
            break
    else:
        print('Possible')
        quit()
err()
    

Measured memory_bytes: 79084
s = gets.chomp
t = gets.chomp
u = s.size
v = t.size
p = Array.new(u+1,0)
q = Array.new(v+1,0)
for i in 1..u
  p[i] = s[i-1] == "A" ? 1 : 2
  p[i] += p[i-1]
end
for i in 1..v
  q[i] = t[i-1] == "A" ? 1 : 2
  q[i] += q[i-1]
end

gets.to_i.times do
  a,b,c,d = gets.split.map(&:to_i)
  puts (p[b]-p[a-1])%3 == (q[d]-q[c-1])%3 ? "YES" : "NO"
end

Measured memory_bytes: 4092
n=int(input())

#隣接リスト表現
es=[[] for i in range(n)]
for i in range(n-1):
  u,v,w=list(map(int,input().split()))
  es[u-1].append([v-1,w])
  es[v-1].append([u-1,w])


# 再帰の深さが1000を超えそうなときはこれをやっておく
import sys
sys.setrecursionlimit(10**7)

#頂点vから初めて白なら１、黒なら−１、未探索なら０
colors=[0 for i in range(n)]
def search(v,color):
  colors[v]=color
  #vから行ける辺について考える
  for to in es[v]:
    if colors[to[0]]==0 and to[1]%2==0:
      search(to[0],color)
    elif colors[to[0]]==0 and to[1]%2==1:
      search(to[0],-color)
  return colors

search(0,1)
for i in colors:
  if i==-1:
    print(0)
  else:
    print(1)
    
  
  



Measured memory_bytes: 181980
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n;cin>>n;
  string a,b,c;cin>>a>>b>>c;
  int ans=0;
  for(int i=0;i<n;i++){
    if(a[i]==b[i]&&a[i]==c[i])continue;
    else if(a[i]==b[i])ans++;
    else if(b[i]==c[i])ans++;
    else if(a[i]==c[i])ans++;
    else ans+=2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{ 
int n=5,j=0;
int aa[5];
for(int i=0;i<5;i++)
{
    cin>>aa[i];

    if(aa[i]==0)
     j=i+1;
}
cout<<j<<endl;
   return 0;
}

Measured memory_bytes: 3604
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define print_time cerr << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
    if(y==0)
	return x;
    else
	return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
	if(m%2)
	    r=(r*n)%p;
	n=(n*n)%p;
	m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
	if (n%i == 0 || n%(i+2) == 0)
	   return false;
 
    return true;
}
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
	if (i <= r)
	    z[i] = min (r - i + 1, z[i - l]);
	while (i + z[i] < n && s[z[i]] == s[i + z[i]])
	    ++z[i];
	if (i + z[i] - 1 > r)
	    l = i, r = i + z[i] - 1;
    }
    return z;
}
int32_t main()
{
   IOS;
  /* #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ***********************/     
   int a,b,c;
   cin>>a>>b>>c;
   int ans=inf;
   ans=abs(a-b)+abs(b-c);
   ans=min(ans,abs(a-c)+abs(b-c));
   ans=min(ans,abs(b-a)+abs(b-c));
   ans=min(ans,abs(b-c)+abs(c-a));
   ans=min(ans,abs(c-a)+abs(a-b));
   ans=min(ans,abs(c-b)+abs(a-b));
   cout<<ans<<endl;
}      	


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int A= sc.nextInt();
		int count = H/A;
		if (H%A>0) {
			count ++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21844
#include <iostream>
using namespace std;
 
int main(){
long long a[51]={0},n;
cin>>n;
for(long long i=1;i<=50;i++){
	a[i]=(n/50)+i-1;
}n%=50;
for(long long i=1;i<=n;i++){
	for(int j=1;j<=50;j++){
		a[j]--;
	}
	a[i]+=51;
}
cout<<50<<endl;
for(int i=1;i<50;i++)cout<<a[i]<<" ";cout<<a[50];
return 0;
}

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

int main()
{
  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<int>> t(n + 1, vector<int>(n + 1));
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = 1; j <= l; j++) {
      t.at(j).at(r)++;
    }
  }
  for (int i = 0; i < q; i++) {
    int l, r, count = 0;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      count += t.at(l).at(j);
    }
    cout << count << endl;
  }
}


Measured memory_bytes: 1920
#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! get_chars {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().chars().collect::<Vec<_>>()
        }
    };
    ($n:expr) => {
        {
            (0..$n)
                .map(|_| get_chars!())
                .collect::<Vec<_>>()
        }
    };
}

use std::collections::HashMap;

fn main() {
    get!(usize);
    let a = get!(usize;;);

    let mut m = HashMap::new();
    let mut ans = 0usize;

    for (i, aa) in a.into_iter().enumerate() {
        *(m.entry(i + aa).or_insert(0)) += 1;
        if i >= aa {
            ans += m.get(&(i - aa)).unwrap_or(&0);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 12264
#include <bits/stdc++.h>
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
 
constexpr int INF = 1e9;
constexpr int MOD = 1e9+7;

int main() {
    int x;
    cin >> x;
    cout << (x ? 0 : 1) << endl;
    return 0;
}

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

int main() {
  int N, b = 0;
  cin >> N;
  vector<int> a(8, 0);
  for (int i = 0; i < N; i++) {
    int c, check = 0;
    cin >> c;
    for (int j = 0; j < 8; j++) {
      if (c < 400*(j + 1) && check == 0) {
        a.at(j) = 1;
        check = 1;
      }
    }
    if (c >= 3200) {
      b++;
    }
  }
  int ans = 0;
  for (int i = 0; i < 8; i++) {
    ans += a.at(i);
  }
  cout << max(ans, 1) << " " << ans + b << endl;
}

Measured memory_bytes: 256
result = []
while True:
    m = str(input())
    if m == "-":
        break
    n = int(input())
    for i in range(n):
        p = int(input())
        tmp = m[p:]
        tmp += m[:p]
        m = tmp 
    result.append(m)

for j in range(len(result)):
    print(result[j])


Measured memory_bytes: 5600
//#include<stdio.h>
#include<bits/stdc++.h>
#include<cstdio>
#include<stdlib.h>

using namespace std;

int a[21];
int b[21];
int fun(int a1,int b1,int c1)
{
	 //printf("%d %d %d\n",a1,b1,c1);
	 int temp;
	 int temp2;
	 int result;
	 temp = max(a1,b1);
	 temp = max(temp,c1);
	 temp2 = min(a1,b1);
	 temp2 = min(temp2,c1);
	 
	 result = (a1+b1+c1) - temp - temp2;
	 return result;
	}
	int main(void)
	{
	 int n;
	 scanf("%d",&n);
	 int i;
	 int count = 0;
	 for(i = 0;i<n;i++)
	  scanf("%d",&a[i]);
	 for(i = 1;i<n-1;i++)
	 {
//	  if(i == n)
//	   break;
	  int a1 = a[i-1];
	  int b1 = a[i];
	  int c1 = a[i+1];
	  int k = fun(a1,b1,c1);
//	  /("%d %d ",b1,k);
	  if(k == b1){
	   count++;
	  }
	 }
	 printf("%d",count);
	 return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define MODNUM (INT(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
void chmax(T& m, T x) {
	m = max(m, x);
}

template <typename T>
void chmin(T& m, T x) {
	m = min(m, x);
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int digit(int n, int k) {
	int i = 1;
	while((n /= k) > 0) {
		i++;
	}
	return i;
}

int main() {
	int n, k;
	scanf("%d %d", &n, &k);
	printf("%d\n", digit(n, k));
	return 0;
}

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


int N;

int A,B;
int main(void)
{

    cin >> N >> A >> B;
    if(A+B<=N)cout << min(A,B) <<" "<< 0 << endl;
    else if(A+B>N) cout << min(A,B) <<" "<< abs(N-(A+B)) << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A, B, res;
  rd(A);
  rd(B);
  res = A;
  if(B < A){
    res--;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190822-2

// --- original code ---
// {
//   int A, B, res;
//   rd(A,B);
//   res = A;
//   if(B < A) res--;
//   wt(res);
// }


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int a, p;
    cin >> a >> p;

    int ans = (a * 3 + p) / 2;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int x, y, z ;

    cin >> x >> y >> z;
    for(int i=0 ; i< 10 ;++i)
    {
        z = x*z-y  ;

        cout << z <<endl;
    }

    return 0  ;
}

Measured memory_bytes: 256
#include <cstdint>
#include <string>

using namespace std;

#define ARRAY_SIZE 256
int32_t array[ARRAY_SIZE];
int32_t index = 0;

void stack_push(int32_t data)
{
  array[index] = data;
  index++;
}

bool stack_pop(int32_t &data)
{
  if (index > 0) {
    index--;
    data = array[index];
    return true;
  }

  return false;
}

#if !defined(TEST)
#include <cstdio>
#include <iostream>

int32_t main()
{
  string str;

  while (cin >> str) {
    if (cin.eof()) break;
    int32_t data1, data2;
    switch (str.front()) {
    case '+':
      stack_pop(data2);
      stack_pop(data1);
      stack_push(data1 + data2);
      break;
    case '-':
      stack_pop(data2);
      stack_pop(data1);
      stack_push(data1 - data2);
      break;
    case '*':
      stack_pop(data2);
      stack_pop(data1);
      stack_push(data1 * data2);
      break;
    default:
      stack_push(stoi(str));
      break;
    }
    str.clear();
  }

  int32_t data;
  stack_pop(data);
  cout << data << endl;

  return 0;
}
#endif

Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)

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

using namespace std;

int main(void){
	int n;
	while(cin>>n,n) {
		int res = 0;
		rep(i,2,n) {
			if(i%2) {
				if(n%i == 0) {
					if(n/i - ((i+1)/2) >= 0) res++;
				}
			}
			else {
				if(n%i && (2*n)%i==0) {
					if((((2*n)/i)-1)/2 - i/2 >= 0) res++;
				}
			}
		}
		cout << res << endl;
	}
        
	return 0;
}

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

long long int pr(int p, int i){
  long long int a=1;
  rep(j,i){
    a=a*p;
  }
  
  return a;
}
  
int main(){
  long long int N;
  int a;
  int n=0;
  cin>>N>>a;
  rep(i,50){
    if(pr(a,i)>N){
      n=i;
      break;
    }
  }
  cout<<n<<endl;
}
  
  

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

int main() {
    ll n,d;
    cin >> n >> d;
    int ans = 0;
    REP(i,n){
        ll x,y;
        cin >> x >> y;
        if(x*x+y*y<=d*d){
            ans++;
        }
    }
    cout << ans << endl;
}

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

int gcd(int a, int b) {return b ? gcd(b, a%b) : a; }

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

    //累積gcd(左と右)
    vector<int> left(n + 1, 0), right(n + 1, 0);
    for (int i = 0; i < n; i++) left[i + 1] = gcd(left[i], a[i]);
    for (int i = n - 1; i >= 0; i--) right[i] = gcd(right[i + 1], a[i]);

    int res = 0;
    for (int i = 0; i < n; i++) {
        int l = left[i];
        int r = right[i + 1];
        res = max(res, gcd(l, r));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1408
N = 8
def readdata():
    x = ""
    while x=="":
        try: x = raw_input()
        except: return []
    for i in range(N-1):
        x += raw_input()
    return x

def f0036(x):
    ptn = [18, 48, 6, 30, 20, 34, 16]
    try: return "ABCDEFG"[ptn.index(sum(x)-x[0]*4)]
    except: return False

while True:
    dt = readdata()
    if dt==[]: break
    dt = [i for i,c in enumerate(dt) if c=="1"]
    print f0036(dt)

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

int main () {
  int n;
  cin>>n;
  double ans=0;
  
  for (int i=0;i<n;i++){
    ans = pow(2,i);
    if(ans>n){
      ans = ans/2;
      break;
    }
  }
  cout<<ans<<endl;
}


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

bool binarySearch(vector<int> A, int i) {
  int l = 0;
  int r = A.size();
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (A[mid] == i) {
      return true;
    } else if (A[mid] > i) {
      r = mid;
    } else {
      l = mid;
    }
  }
  return false;
};

int main() {
  int n, q;
  cin >> n;
  vector<int> S(n);
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  cin >> q;
  int T[q];
  for (int i = 0; i < q; i++) {
    cin >> T[i];
  }

  int ans = 0;
  for (int i = 0; i < q; i++) {
    if (binarySearch(S, T[i])) {
      ans += 1;
    }
  }

  cout << ans << endl;
};



Measured memory_bytes: 3748