akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

#define NUM_LIMIT (1<<10)

#define OP_ADD   (-1)
#define OP_SUB   (-2)
#define OP_MUL   (-3)
#define OP_KAKKO (-4)

int stack_num;
int stack[100];
int rp_num;
int rp[100];

int rp_compile(const char* statement) {
	const char* now;
	int expectOperator=0;
	int nownumber;
	stack_num=0;
	rp_num=0;
	for(now=statement;*now;now++) {
		switch(*now) {
			case '+':
				if(!expectOperator)return 0;
				while(stack_num>0 && stack[stack_num-1]!=OP_KAKKO) {
					rp[rp_num++]=stack[--stack_num];
				}
				stack[stack_num++]=OP_ADD;
				expectOperator=0;
				break;
			case '-':
				if(!expectOperator)return 0;
				while(stack_num>0 && stack[stack_num-1]!=OP_KAKKO) {
					rp[rp_num++]=stack[--stack_num];
				}
				stack[stack_num++]=OP_SUB;
				expectOperator=0;
				break;
			case '*':
				if(!expectOperator)return 0;
				while(stack_num>0 && stack[stack_num-1]==OP_MUL) {
					rp[rp_num++]=stack[--stack_num];
				}
				stack[stack_num++]=OP_MUL;
				expectOperator=0;
				break;
			case '(':
				if(expectOperator)return 0;
				stack[stack_num++]=OP_KAKKO;
				expectOperator=0;
				break;
			case ')':
				if(!expectOperator)return 0;
				if(stack_num<=0 || stack[stack_num-1]==OP_KAKKO)return 0;
				while(stack_num>0 && stack[stack_num-1]!=OP_KAKKO) {
					rp[rp_num++]=stack[--stack_num];
				}
				if(stack_num>0)stack_num--; else return 0;
				expectOperator=1;
				break;
			case '0':
			case '1':
				if(expectOperator)return 0;
				nownumber=0;
				for(;*now=='0' || *now=='1';now++) {
					nownumber=nownumber*2+(*now)-'0';
					if(nownumber>=NUM_LIMIT)return 0;
				}
				now--;
				expectOperator=1;
				rp[rp_num++]=nownumber;
				break;
		}
	}
	while(stack_num>0) {
		stack_num--;
		if(stack[stack_num]==OP_KAKKO)return 0;
		rp[rp_num++]=stack[stack_num];
	}
	return 1;
}

int rp_calc(void) {
	int i;
	stack_num=0;
	for(i=0;i<rp_num;i++) {
		switch(rp[i]) {
			case OP_ADD:
				if(stack_num<2)return -1;
				stack[stack_num-2]+=stack[stack_num-1];
				if(stack[stack_num-2]>=NUM_LIMIT)return -1;
				stack_num--;
				break;
			case OP_SUB:
				if(stack_num<2)return -1;
				stack[stack_num-2]-=stack[stack_num-1];
				if(stack[stack_num-2]<0)return -1;
				stack_num--;
				break;
			case OP_MUL:
				if(stack_num<2)return -1;
				stack[stack_num-2]*=stack[stack_num-1];
				if(stack[stack_num-2]>=NUM_LIMIT)return -1;
				stack_num--;
				break;
			default:
				stack[stack_num++]=rp[i];
				break;
		}
	}
	if(stack_num!=1)return -1;
	return stack[0];
}

int main(void) {
	char input[200];
	const char* mozi="01+-*()";
	int pos[5]={150,150,150,150,150};
	int i,j;
	int posnum;
	int search_max;
	int result;
	scanf("%s",input);
	posnum=0;
	search_max=1;
	for(i=0;input[i];i++) {
		if(input[i]=='.') {
			pos[posnum++]=i;
			search_max*=7;
		}
	}
	result=-1;
	for(i=0;i<search_max;i++) {
		int temp=i;
		for(j=0;j<posnum;j++) {
			input[pos[j]]=mozi[temp%7];
			temp/=7;
		}
		if(!rp_compile(input))continue;
		temp=rp_calc();
		if(temp>result)result=temp;
	}
	printf("%d\n",result);
	return 0;
}

Measured memory_bytes: 536
#include <algorithm>
#include <iostream>
using namespace std;
#define M 1000000007

int main() {
    int n; cin >> n;
    int a[n][n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> a[i][j];
    int S[1<<n] = {0}, card[1<<n] = {0};
    for (int s = 1; s < 1<<n; s++) {
        S[s] = s;
        for (int i = 0; ; i++) if (s&(1<<i)) { card[s] = 1 + card[s^(1<<i)]; break; }
    }
    sort(S, S+(1<<n), [&](int s, int t) { return card[s] < card[t]; });

    long long dp[1<<n] = {};
    dp[0] = 1;
    for (int i = 0, j = 0; i < n; i++) {
        while (card[S[j]] == i) {
            int s = S[j++];
            for (int j = 0; j < n; j++) {
                if (((1<<j)&s) || a[i][j]==0) continue;
                int s1 = s^(1<<j);
                dp[s1] += dp[s];
                if (dp[s1] >= M) dp[s1] -= M;
            }
        }
    }
    cout << dp[(1<<n)-1] << endl;
}


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

int dp[3005][3005];
int main(){
  memset(dp,0,sizeof(dp));
  string a,b;
  cin >> a >> b;
  int la = a.size();
  int lb = b.size();
  if(la==0 || lb==0){
    cout<<""<<endl;
    return 0;
  }
  for(int i=1;i<=la;i++){
    for(int j=1;j<=lb;j++){
      if(a[i-1]==b[j-1]){
        dp[i][j] = dp[i-1][j-1]+1;
      }
      else{
        dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      }
    }
  }
  int r = la;
  int c = lb;
  string ans = "";
  if(dp[la][lb]==0){
    cout<<""<<endl;
    return 0;
  }
  while(r>0 && c>0){
    if(a[r-1]==b[c-1]){
      ans+=a[r-1];
      r--;c--;
    }
    else{
      if(dp[r-1][c]>dp[r][c-1]){
        r--;
      }
      else{
        c--;
      }
    }
  }
  reverse(ans.begin(),ans.end());
  cout << ans << endl;
}


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

long long pow(int n)
{
    long long k = 1;
    for(int i = 0; i < n; i++){
        k *= 2;
    }
    return k;
}

int main()
{
    long long n, a, even = 0, odd = 0, ans = 0;
    bool p;
    cin >> n >> p;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a % 2 == 0) even += 1;
        else           odd  += 1;
    }
    if(odd == 0) cout << (p == 0 ? pow(n) : 0) << endl;
    else cout << pow(n-1) << endl;
    return 0;
}

Measured memory_bytes: 256
import math
n, m = map(int, input().split())

ans = 1
for i in range(1,math.ceil(math.sqrt(m))):
	if m%i == 0:
		if m >= n*i:
			ans = max(ans, i)
		j = m//i
		if m >= n*j:
			ans = max(ans,j)

print (ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(50)

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

int dp[110][100010];

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

  int N, K, A[100]; cin >> N >> K;
  REP(i, N) cin >> A[i];
  dp[0][K] = 1; // i番目まででj個のこってる
  REP(i, N) REP(j, K+1){
    int M = min(K-j, A[i]);
    int tmp;
    if(j == 0){
      tmp = dp[i][j+M];
      dp[i+1][j] = tmp;
    } else {
      tmp = (dp[i][j+M] + MOD - dp[i][j-1]) % MOD;
      dp[i+1][j] = dp[i+1][j-1] + tmp;
    }
    dp[i+1][j] %= MOD;
  }
  cout << dp[N][0] << endl;
}


Measured memory_bytes: 79360
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    ans=(n-1)*sum(A)
    ans%=MOD

    for d in range(60,-1,-1):
        cnt=sum((a>>d)&1 for a in A)
        k=cnt*(cnt-1)
        ans-=k<<d
        ans%=MOD
    print(ans)
resolve()

Measured memory_bytes: 124688
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class ATwoCoins {
public:
	void solve(istream& in, ostream& out) {
        int a,b,c; in >> a >> b >> c;
        if(a + b >= c) out << "Yes" << endl;
        else out << "No" << endl;
	}
};

int main() {
	ATwoCoins solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define lld long double
using namespace std;
lld dist(pair<ll,ll>A,pair<ll,ll>B)
{
	lld s;
	s=(A.first-B.first)*(A.first-B.first)+(A.second-B.second)*(A.second-B.second);
	s*=1.0;
	s=sqrt(s);
	return s;
}
ll fact(ll n)
{
	ll value=1;
	for(ll i=2;i<=n;i++)
	value*=i;
	return value;
}
ll nc2(ll n)
{
	return (n*(n-1))/2;
}
int main()
{
	vector<pair<ll,ll> >vect;
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++)
	{
		ll x,y;
		cin>>x>>y;
		vect.push_back(make_pair(x,y));
	}
	lld ave=0;
	ll count=0;
	for(ll i=0;i<n-1;i++)
	{
		for(ll j=i+1;j<n;j++)
		{
			ave+=dist(vect[i],vect[j]);
			count++;
		}
	}
	ave/=count;
	ave*=(n-1);
	//ave=ave*(fact(n));
	cout<<fixed<<setprecision(10)<<ave<<endl;
	return 0;
}

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

int main() {
    int H, W, D, Q;
    cin >> H >> W >> D;
    vector<int> x(H*W + 1), y(H * W + 1);
    for(int i = 1; i <= H; i++) {
        for(int j = 1; j <= W; j++) {
            int a;
            cin >> a;
            x[a] = i;
            y[a] = j;
        }
    }
    cin >> Q;

    vector<int> dist(H*W + 1, 0);
    for(int i = 0; i <= H * W; i++) {
        if(i > D) {
            dist[i] = dist[i - D] + abs(x[i] - x[i - D]) + abs(y[i] - y[i - D]);
        }
    }

    int L, R;
    for(int i = 0; i < Q; i++) {
        cin >> L >> R;
        cout << dist[R] - dist[L] << endl;
    }

    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1000000007, INF = 1e9;

int main()
{
    int n; 
    ll ans = 1e10;
    cin >> n;
    vector<int> v(n);
    rep(i, n)cin >> v[i];
    sort(v.begin(), v.end());
    for(int i = 1; i < 101; i++){
        ll temp = 0;
        for(int j = 0; j < n; j++){
            temp += abs(i-v[j])*abs(i-v[j]);
        }
        ans = min(ans, temp);
    }
    cout << ans << endl;
    system("pause");
}

Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include <string>


using namespace std;

int main() {
    string S;
    cin >> S;
    vector <int> screen;
    for (int i = 0; i < S.size(); i++) {
        if(S[i] == '0') {
            screen.push_back(0);
        } else if(S[i] == '1') {
            screen.push_back(1);
        } else if (S[i] == 'B') {
            if (screen.size() == 0) {
               
            } else {
                screen.pop_back();
            }
        }
    }
    for (auto x: screen){
        cout << x;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll A[200010];

bool C( ll c ) {
  std::map<ll, ll> mp;

  rep( i, N-1 ) {
    if( A[i] >= A[i+1] ) {
      if( c == 1 )
        return false;

      auto d = mp.lower_bound(A[i+1]);

      while( d != mp.end() ){
        auto nxt = std::next(d);
        mp.erase(d);
        d = nxt;
      }

      ll x = A[i+1]-1;

      while( true ) {
        if( x < 0 )
          return false;

        if( mp[x]+1 < c ) {
          ++mp[x];

          break;
        } else {
          mp.erase(x);
          --x;
        }
      }
    }
  }

  return true;
}

int main() {
  std::cin >> N;

  rep( i, N )
    std::cin >> A[i];

  ll ng = 0, ok = N;

  while( ok-ng > 1 ) {
    ll mid = (ng+ok)>>1;

    (C(mid) ? ok : ng) = mid;
  }

  std::cout << ok << endl;

  return 0;
}

Measured memory_bytes: 5160
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  1000LL
#define tmod            998244353
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll SUMD(ll n);
ll BS(vector<ll> &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
bool P[N+1];
void Sieve(int n=N);
ll Powb(ll b,ll n);

int main()
{
fast;
ll q=1,t;
//cin >> q;
t = q;
while(q--)
{

    ll h,n,m,k,i,j,l,r,c=0,b,a,g,counter=0,u,v,d,e,w,p,x,y,z,fl=1;
    //n=m=i=j=l=r=a=t=b=c=u=v=w=p=x=y=0;
    cin >> n >> m ;
    cout << max(0LL,n-2*m);
}
    return 0;
}

//*****************************************************************************************************************************************

ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}

ll SUMD(ll n)
{   ll sum=0;
    while(n>0){sum += n%10;n = n/10;}
    return sum;

}
ll BS(vector<ll> &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid]==ser)
    {
        return mid;
    }
    else if(PS[mid] > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

void Sieve(int n)
{
    memset(P,true,sizeof(P));
    P[0] = false;
    P[1]= false;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i])
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                P[j]=false;
            }
        }
    }

}


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

void Main()
{
	string s, p;
	cin >> s >> p;
	rep(i, s.size()){
		if(s.substr(0, p.size()) == p){
			cout << "Yes" << endl;
			return;
		}
		s += s[0];
		s.erase(0, 1);
	}
	cout << "No" << endl;
}

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


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

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

    int lose = 0;
    for(int i=0; i<s.length(); i++){
        if(s[i] == 'x') lose += 1;
    }

    if(lose < 8) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3504
#include <stdio.h>
#include <string.h>
 
int main(){
  int n,x=0,i,j;
  int d[105];
  scanf("%d",&n);
  for(i=0;i<=n-1;i++){
    scanf("%d",&d[i]);
  }
  for(i=0;i<=n-1;i++){
    j=i+1;
    for(j=i+1;j<=n-1;j++){
      if(d[i] == d[j]){
        x += 1;
        j=2000;
      }
    }
  }
  printf("%d\n",n-x);
  return 0;
}
      

Measured memory_bytes: 128
N = int(input())

p = []
for i in range(N):
  a,b = map(int,input().split())
  p.append([max(0,a - b),a + b])
  
q = sorted(p,key=lambda x:x[1])  

cnt = 0
d = q[0][1]
for j,k in q[1:]:
  if j < d:
    cnt += 1
  else:
    d = k

print(N-cnt) 

Measured memory_bytes: 22104
import math

def checkKaibun(s):
    ret = True
    length = len(s)
    for i in range(math.floor(length / 2)):
        if s[i] != s[length-1-i]:
            return False
    return ret

s = input()
ret1 = checkKaibun(s)
#print("{}".format(ret1))

length = len(s)
s2 = s[0:(int)((length-1)/2)]
#print("{}".format(s2))
ret2 = checkKaibun(s2)
#print("{}".format(ret2))

s3 = s[(int)((length+1)/2):length]
#print("{}".format(s3))
ret3 = checkKaibun(s3)
#print("{}".format(ret3))

ret = "No"
if (ret1 and ret2 and ret3):
    ret = "Yes"
print("{}".format(ret))



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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 20;

int n, a[MAXN+10], b[MAXN+10];

int main()
{
    int i, j;

    scanf("%d", &n);
    for(i=1; i<=n; i++) scanf("%d", &a[i]);
    for(i=1; i<=n; i++) scanf("%d", &b[i]);

    int ans=0;
    for(i=1; i<=n; i++) ans+=max(0, a[i]-b[i]);
    printf("%d", ans);
}


Measured memory_bytes: 256
import fractions

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

#print(A,B)

def prime_factorize(n):
	a = []
	while n % 2 == 0:
		a.append(2)
		n //= 2
	f = 3
	while f * f <= n:
		if n % f == 0:
			a.append(f)
			n //= f
		else:
			f += 2
	if n != 1:
		a.append(n)
	return a

g = fractions.gcd(A,B)
#print(g)
p = prime_factorize(g)
p = list(set(p))
#print(p)
print(len(p)+1)

Measured memory_bytes: 64208
#include "bits/stdc++.h"

#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,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int  log3(int n) {
	double a = n;
	int ret = 0;
	while (a >1) {
		a /= 3;
		ret++;
	}
	return ret;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	cout << log3(n) << endl;
	return 0;
}

Measured memory_bytes: 3184
import sys
def input(): return sys.stdin.readline().rstrip()
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

def main():
    n=int(input())
    n_list=make_divisors(n)
    len_list=len(n_list)
    if len_list%2==1:print(2*n_list[len_list//2]-2)
    else:
        print(n_list[len_list//2-1]+n_list[len_list//2]-2)

if __name__=='__main__':
    main()

Measured memory_bytes: 3292
#include <bits/stdc++.h>
#define ll long long
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define inf 1000000007
using namespace std;
ll prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997};
map<ll,ll> mp,power;
int main()
{
    ll i,j,k,n,t;
    string s;
    for(auto z: prime) mp[z]=1, power[z]=0;
    cin>>n;
    FOR(i,2,n)  {
        if(mp[t]==1) power[t]++;
        else    {
            for(auto z:prime)   {
                t=i;
                while(t%z==0 && t>1) {
                    power[z]++;   
                    t=t/z ;
                }
                if(t==1) break;
            }
        }
    }
    k=1;
    for(auto z:prime)  k = (k*(power[z]+1))%inf;
    cout<<k<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  S.push_back('A');
  int c = 0;
  for(int i = 0;i<S.size()-1;i++){
    if(S[i] != S[i+1]) c++;
  }
  cout << c-1 << endl;
}

Measured memory_bytes: 512
// C - 白昼夢 / Daydream
#include <bits/stdc++.h>
using namespace std;

int main(){
	map<string,string> T{
		{"erase","esare"},
		{"eraser","resare"},
		{"dream","maerd"},
		{"dreamer","remaerd"},
	};

	string s; cin>>s;
	reverse(s.begin(),s.end());
	bool ok = true;
	int i = 0;
	while(i<s.size()){
		if(s[i]=='r'){
			if(T["eraser"]==s.substr(i,6)) i += 6;
			else if(T["dreamer"]==s.substr(i,7)) i += 7;
			else ok = false;
		}
		else if(s[i]=='m'){
			if(T["dream"]==s.substr(i,5)) i += 5;
			else ok = false;
		}
		else if(s[i]=='e'){
			if(T["erase"]==s.substr(i,5)) i += 5;
			else ok = false;
		}
		else ok = false;
		if(!ok) break;
	}
	cout<< (ok?"YES":"NO") <<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>

#define div 1000000000+7

typedef long long ll;

using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    if(a == b){
        cout << "Draw" << endl;
    }else if(b == 1 || ((b > a)&&(a!=1))){
        cout << "Bob" << endl;
    }else if(a == 1 || ((a > b)&&(b!=1))){
        cout << "Alice" << endl;
    }
}

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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;
int main(int argc, char const *argv[])
{
	char text[1004];
	scanf("%s",text);
	int len = strlen(text);
	if(text[len - 1] == 's')
	{
		for(register int i = 0;i < len;i++)
			putchar(text[i]);
		puts("es");
	}else{
		for(register int i = 0;i < len;i++)
			putchar(text[i]);
		puts("s");
	}
	return 0;
}

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

int main()
{
  ll n,i,j;
  cin>>n;
  ll x[n+1],y[n+1],h[n+1];
  for(i=0;i<n;i++)
  {
      cin>>x[i]>>y[i]>>h[i];
  }
  ll cx,cy,ch,acx,acy,ach;
  bool f;
  for(i=0;i<=100;i++)
  {
      for(j=0;j<=100;j++)
      {
        //   cout<<i<<" "<<j<<endl;
          cx = i, cy = j;
          f = true;
          ll p = 1, q = 1999999999;
          
          ll poi = 0;
          for(ll k = 0;k<n;k++)
          {
              if(h[k]>h[poi])
              {
                poi = k;
              }
          }
          
          while(p<=q)
          {
              ll mid = (p+q)/2;
              ll th = max(mid - abs(x[poi]-cx) - abs(y[poi]-cy),0LL);
              if(th==h[poi])  break;
              else if(th<h[poi])
                p = mid+1;
              else
                q = mid-1;
          }
          if(p>q)
          {
            f = false;continue;
          }
          ll mid = (p+q)/2;
          ll th = max(mid - abs(x[poi]-cx) - abs(y[poi]-cy),0LL);
          if(th==h[poi])
          {
            //   cout<<cx<<" "<<cy<<" "<<mid<<" "<<th<<" "<<h[0]<<endl;
              ch = mid;
          }
          else
          {
            f = false;continue;
          }
          
          if(ch<1)
          {
              f =false;continue;
          }

          for(p=0;p<n;p++)
          {
            ll th = max(ch - abs(x[p]-cx) - abs(y[p]-cy),0LL);
            if(th!=h[p])
            {
                f = false;break;
            }
          }
          if(f)
          {
              acx = cx;
              acy = cy;
              ach = ch;
          }
      }
  }
  cout<<acx<<" "<<acy<<" "<<ach;
  /*else
    cout<<(1/0);*/
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
string str;
int n,A=0,B=0,O=0,AB=0;

int main(){
	while(cin>>str){
		n=str.size();
		if(n==1)break;
		if(str[n-2]==','){
			if(str[n-1]=='A')A++;
			else if(str[n-1]=='B')B++;
			else O++;
		}else{
			AB++;
		}
	}
	cout<<A<<endl<<B<<endl<<AB<<endl<<O<<endl;
	return 0;
}



Measured memory_bytes: 3004
n=int(input())
g=0
for i in range(n):
  a,b=map(int,input().split(" "))
  if a==b:
    g=g+1
    if g==3:
      break
      break
  else:
    g=0


if g==3:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
int L;
struct Front_star{
	int u,v,w;
}e[90];
int ecnt=0;
void add(int u,int v,int w){
	ecnt++;
	e[ecnt].u=u;
	e[ecnt].v=v;
	e[ecnt].w=w;
}
int main(){
	cin>>L;
	int cnt=0;
	int tmp=L;
	while(tmp)cnt++,tmp/=2;
	for(int i=1;i<cnt;i++){
		add(i,i+1,0);
		add(i,i+1,(1<<(i-1)));
	}
	cnt--;
	int ret=L-(1<<cnt);
	int Use=(1<<cnt);
	for(int i=0;i<cnt;i++){
		if((1<<i)&ret){
			add(i+1,cnt+1,Use);
			Use+=(1<<i);
		}
	}
	cout<<cnt+1<<" "<<ecnt<<'\n';
	for(int i=1;i<=ecnt;++i){
		cout<<e[i].u<<" "<<e[i].v<<" "<<e[i].w<<'\n';
	}
} 

Measured memory_bytes: 256
import sys
from collections import deque

s = input()
q = int(input())
is_reverse = False
ds = deque(s)

for _ in range(q):
  tf = sys.stdin.readline().split()
  if len(tf) == 1:
    is_reverse = False if is_reverse else True
  else:
    if tf[1] == '1':
      if is_reverse:
        ds.append(tf[2])
      else:
        ds.appendleft(tf[2])
    else:
      if is_reverse:
        ds.appendleft(tf[2])
      else:
        ds.append(tf[2])
if is_reverse:
  ds.reverse()
ans = ''.join(list(ds))
print(ans)

Measured memory_bytes: 8820
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		int max=0;
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
			max=Math.max(a[i],max);
		}
		Arrays.parallelSort(a);

		int c=0;
		for(int x=0;x<n;x++) {
			for(int y=x+1;y<n;y++) {

				for(int z=y+1;z<n;z++) {
					if(a[z]<a[x]+a[y])
						c++;
					else
						break;

				}

			}
		}
		System.out.println(c);

	}

}


Measured memory_bytes: 26620
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
f_l=[False]*K #Trueなら連続している

ans = 0
for i in range(N):
  if i<=K-1:
    if T[i]== "r":
      ans += P
    elif T[i]=="s":
      ans += R
    else:
      ans += S
    #print(i,ans)
  else:
    #print(i,f_l[i%K])
    if T[i]==T[i-K]:
      if f_l[i%K]==True: 
        f_l[i%K]=False
      else:
        f_l[i%K]=True
    else:
      f_l[i%K]=False
    if f_l[i%K]==False:
      if T[i]== "r":
        ans += P
      elif T[i]=="s":
        ans += R
      else:
        ans += S
    #print(i,ans)
print(ans)

Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  int a;
  rep(i, n){
    cin >> a;
    if(a%2==0 && (a%3!=0 &&a%5!=0 )){
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    int k = sc.nextInt();
	    int r;
	    int count = 1;
	    r = n / k;
	    while(r != 0){
	        count ++;
	        r = r / k;
        }
        System.out.println(count);
    }
}

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

using namespace std;

int main() {
	// your code goes here
	string s;
	cin >> s;
	
	if(s == "a" || s == "i" || s == "u" || s == "e" || s == "o") cout << "vowel" << endl;
	else cout << "consonant" << endl;
	
	return 0;
}

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

int
main()
{
	int x,y;
	char buf[20];

	while(scanf("%d %d", &x, &y) == 2){
		sprintf(buf, "%d", (x + y));
		printf("%ld\n", strlen(buf));
	}
	
	return(0);
}

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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/


#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("d",&a,&b)
#define sfff(a,b,c)     scanf("d%d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int z=1 ; z<=t ; z++)
#define PRINT_CASE printf("Case %d: ",z)
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2



int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/


const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;
int arr[maxn],n,k;
ll DP[maxn];

ll cal(int pos){

    if(pos==n-1){
        return 0LL;
    }

    ll &res = DP[pos];
    if(res!=-1){
        return res;
    }

    res= cal(pos+1)+ abs(arr[pos+1]-arr[pos]);

    for(int i=2 ; i<=k ; i++){
        if(pos+i<n){
            res= min(res,cal(pos+i) + abs(arr[pos+i]-arr[pos]));
        }
    }

    return res;
}


int main() {
    CIN
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin>>n>>k;

    f0(i,n)
    {
        cin>>arr[i];
    }

    memset(DP , -1 , sizeof(DP));


    cout<<cal(0)<<endl;



    return 0;
}



Measured memory_bytes: 6912
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func gcd(x int, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x % y)
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()

	buttons := make([]int, n+1)

	for i := 1; i <= n; i++ {
		buttons[i] = nextInt()
	}

	idx := buttons[1]
	count := 1

	for {
		if idx == 2 {
			break
		}
		if count > n {
			fmt.Println(-1)
			return
		}
		count++
		idx = buttons[idx]
	}
	
	fmt.Println(count)
}


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

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

    vector<vector<int>> x(n, vector<int>(d));
    for (auto& e : x) {
        for (auto& f : e) {
            cin >> f;
        }
    }

    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            double n = 0;
            for (int k = 0; k < d; k++) {
                n += pow(x[i][k] - x[j][k], 2);
            }

            double s = sqrt(n);
            if (s - (int) s == 0) ans++;
        }
    }

    cout << ans << endl;
}


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

using namespace std;
#define mp(a,b) make_pair(a,b)
#define fast cin.tie(0);cout.tie(0);std::ios_base::sync_with_stdio(0);
#define fuf -1;
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define min3(a,b,c) min(min(a,b),c)
#define max3(a,b,c) max(max(a,b),c)
#define mid3(a,b,c) a+b+c-max3(a,b,c)-min3(a,b,c)
#define nullptr NULL
//typedef long long int ll;
#define int long long

const double EPS = 0.0000000001;
const int mod1 = 998244353;
const int mod2 = 1000000007;
const int mod3 = 1000000009;
const int inf = 1000000000000000000;
using namespace std;

signed main(){
    int n;
    cin >> n;
    int mass[n];
    for(int i = 0;i<n;i++) cin >> mass[i];
    int maxi = -1;
    int c = 0;
    for(int i = 0;i<n;i++){
        if(mass[i] >= maxi){
            c++;
        }
        maxi = max(maxi,mass[i]);
    }
    cout << c;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#define inf 1e9+7
#define pb push_back
#define make make_pair
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
typedef pair<ll,ll> Pair;
 
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}
 
 
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll maxhw=2001;

ll l[maxhw][maxhw],r[maxhw][maxhw],u[maxhw][maxhw],d[maxhw][maxhw];

ll h,w;
char  maze[maxhw][maxhw];

void lcount(){
    rep(i,h){
        rep(j,w){
            l[i][j]=0;
        }
    }
    rep(i,h){
           rep(j,w){
               
            if(j==0 && maze[i][j]=='.') l[i][j]++;
            else if(maze[i][j]=='.') l[i][j]=l[i][j-1]+1;
               
           }
       }
}
void rcount(){
    rep(i,h){
        rep(j,w){
            r[i][j]=0;
        }
    }
    rep(i,h){
        for(ll j=w-1;j>=0;j--){
            if(j==w-1 && maze[i][j]=='.') r[i][j]++;
            else if(maze[i][j]=='.') r[i][j]=r[i][j+1]+1;
        }
    }
}
    
void ucount(){
    rep(i,h){
        rep(j,w){
            u[i][j]=0;
        }
    }
    
    rep(j,w){
        rep(i,h){
            if(i==0 && maze[i][j]=='.') u[i][j]++;
            else if(maze[i][j]=='.') u[i][j]=u[i-1][j]+1;
        }
    }
}
void dcount(){
    rep(i,h){
        rep(j,w){
            d[i][j]=0;
        }
    }
    rep(j,w){
        for(ll i=h-1;i>=0;i--){
            if(i==h-1 && maze[i][j]=='.') d[i][j]++;
            else if(maze[i][j]=='.') d[i][j]=d[i+1][j]+1;
        }
    }
}

int main(){
    cin >> h >> w;
    rep(i,h){
        rep(j,w) cin >> maze[i][j];
    }
    lcount();
    rcount();
    ucount();
    dcount();
    ll ans=0;
    rep(i,h){
        rep(j,w){
            ll score=l[i][j]+r[i][j]+u[i][j]+d[i][j];
            score-=3;
            ans=max(ans,score);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 129280
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int h, w, d;
  cin >> h >> w >> d;
  vector<vector<int>> a(h, vector<int>(w));
  vector<pair<int, int>> vp(h*w);
  rep(i, h){
    rep(j, w){
      int in;
      cin >> in;
      in--;
      vp.at(in) = make_pair(i, j);
      a.at(i).at(j) = in;
    }
  }
  vector<vector<int>> cost(d, vector<int>());
  rep(i, d){
    cost.at(i).push_back(0);
    int bf = i;
    for(int j = 1; ; j++){
      int nw = i + d*j;
      if(nw >= h*w) break;
      int add = abs(vp.at(nw).first - vp.at(bf).first) + abs(vp.at(nw).second - vp.at(bf).second);
      int bk = cost.at(i).back();
      cost.at(i).push_back(add+bk);
      bf = nw;
    }
  }
  // rep(i, d){
  //   for(auto j : cost.at(i)){
  //     cerr << j << " ";
  //   }
  //   cerr << endl;
  // }
  int q;
  cin >> q;
  rep(_q, q){
    int l, r;
    cin >> l >> r;
    l--; r--;
    int pos = l % d;
    l /= d;
    r /= d;
    // cerr << l << " " << r << " " << pos << endl;
    cout << cost.at(pos).at(r) - cost.at(pos).at(l) << endl;
  }
  return 0;
}

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

struct Node{
  int key;
  Node* next;
  Node* prev;
  // string to_str() {
  //   return to_string(key);
  // }
};

Node *head;

void init() {
  head = (Node*)malloc(sizeof(Node));
  head->key = -1;
  head->next = head;
  head->prev = head;
}
Node* search(int key) {
  Node *cursor = head->next;
  while(cursor != head && cursor->key != key)
    cursor = cursor->next;
  return cursor;
}

void deleteNode(Node* node) {
  if (node == head) return;
  node->prev->next = node->next;
  node->next->prev = node->prev;
  free(node);
}

void deleteFirst() {
  deleteNode(head->next);
}
void deleteLast() {
  deleteNode(head->prev);
}

void insert(int key) {
  Node* temp = (Node*)malloc(sizeof(Node));
  temp->key = key;
  temp->next = head->next;
  temp->prev = head;
  head->next->prev = temp;
  head->next = temp;
}

int main() {
  init();
  int N;
  cin >> N;
  char line[30];
  int key;
  rep(i, N) {
    scanf("%s%d", line, &key);
    if (line[0] == 'i')
      insert(key);
    else if (line[6] == 'F')
      deleteFirst();
    else if (line[6] == 'L')
      deleteLast();
    else
      deleteNode(search(key));
  }
  Node* current = head->next;
  bool first = true;
  while(current != head) {
    if (first) {
      cout << current->key;
      first = false;
    } else {
      cout << " " << current->key;
    }
    current = current->next;
  }
  cout << endl;
  return 0;
}




Measured memory_bytes: 34488
#!/usr/bin/env python3
#ABC113 B

n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))

mi = float('inf')
for i in range(n):
    if mi > abs(a-(t-h[i]*0.006)):
        mi = abs(a-(t-h[i]*0.006))
        ans = i
print(ans+1)


Measured memory_bytes: 38384
use proconio::input;
use std::collections::{HashMap, VecDeque};

fn main() {
    input! {
        n: usize,
        ab: [(usize, usize); n-1],
        mut cc: [usize; n],
    }

    if n == 1 {
        println!("{}", cc[0]);
        println!("{}", cc[0]);
        return;
    }

    let mut map = HashMap::new();

    for &(a, b) in ab.iter() {
        map.entry(a).or_insert_with(|| vec![]).push(b);
        map.entry(b).or_insert_with(|| vec![]).push(a);
    }

    cc.sort();
    let score = cc.iter().take(cc.len()-1).sum::<usize>();

    let mut nums = vec![None; n];

    let mut queue = VecDeque::new();
    queue.push_back(1);

    while let Some(vert) = queue.pop_front() {
        if nums[vert - 1].is_some() {
            continue;
        }
        let c = cc.pop().unwrap();
        nums[vert - 1] = Some(c);
        for &e in &map[&vert] {
            queue.push_back(e);
        }
    }

    let dd = nums
        .into_iter()
        .map(|d| d.unwrap().to_string())
        .collect::<Vec<_>>()
        .join(" ");

    println!("{}", score);
    println!("{}", dd);
}


Measured memory_bytes: 4148
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String p = sc.next();
		char[] characterS = s.toCharArray();
		char[] characterC = p.toCharArray();
		int i, j, l;
		int count = 0;
		top: for (i = 0; i < s.length(); i++) {
			for (j = 0, l = 0; j < p.length();) {
				try {
					if (characterC[j] == characterS[j + i]) {
						count++;
					}
				} catch (java.lang.ArrayIndexOutOfBoundsException e) {
					if (characterC[j] == characterS[l]) {
						count++;
						l++;
					}
				} finally {
					j++;
				}
			}
			if (count == p.length()) {
				break top;
			} else {
				count = 0;
			}
		}
		if (count == p.length()) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}
}


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

int main() {
  char tmp;
  for (int i = 0; i < 3; i++) {
    scanf("%c", &tmp);
    if (tmp == '7') {
      cout << "Yes" << endl;
      return 0;
    } 
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h> 
using namespace std;
#define int long long int
#define float double
#define pb push_back
#define FF first
#define SS second
#define N 100005
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i++)
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define pii pair<int,int>
#define mp make_pair
#define INF 9223372036854775807
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)


signed main() 
{
    speed;
    //freopen("input.tXt","r",stdin);
    //freopen("output.tXt","w",stdout);

    string s,t;
    cin>>s>>t;

    int n=s.size();
    int m=t.size();

    int dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
                continue;
            }
            if(s[i-1]==t[j-1]) dp[i][j]=1+dp[i-1][j-1];
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int i=n,j=m;
    string ans="";
    while(i>0 && j>0)
    {
        if(dp[i][j]==dp[i-1][j]) i--;
        else if(dp[i][j]==dp[i][j-1]) j--;
        else
        {
            ans+=s[i-1];
            i--;
            j--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}   

Measured memory_bytes: 73984
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,h[100005];
ll dp[100005];
 
int main()  {

  int N,A,B;
  // 空白文字で区切られた数字を 3 つ取得
  std::cin >> N;
  std::cin >> A >> B;
  std::vector<int> point(N);
  
  for (int i = 0; i < N; i++) {
    std::cin >> point[i];   
  }
  
  int ans;
  ans =0;
  int low,mid,high;
  low=mid=high=0;
  
  for (int i = 0; i < N; i++) {
    if(point[i]<=A){
		low++;
	}
	if(point[i]>=A+1 && point[i]<=B){
		mid++;
	}
	if(point[i]>=B+1){
		high++;
	}
  }
  
  int preans;
  preans=min(low,mid);
  printf("%d\n",min(preans,high));
   
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<ll> sum(n);
    sum[0] = a[0];
    for(int i = 1; i < n; ++i){
        sum[i] += sum[i-1] + a[i];
    }

    ll ans = INF18;
    for(int i = 0; i < n-1; ++i){
        chmin(ans, abs(sum[i]*2 - sum[n-1]));
    }

    cout << ans << endl;

return 0;
}

Measured memory_bytes: 5524
#include<stdio.h>

int main(){

  int i,m,j;
  int ba[100];
  int flag;
  int cnt = 0;
  int c = 0;
  int k;
  int ak = 0;

  scanf("%d",&i);

  for(m = 0; m < i; m++){
    scanf("%d",&ba[m]);
  }

  flag = 1;
  for(k = 0; k < i; k++){
  while(flag){
       flag = 0;
       for( j =i-1; j >= k+1; j--){
	 if( ba[j] < ba[j-1]){
	   ak = ba[j];
	   ba[j] = ba[j-1];
	   ba[j-1] = ak;
	   cnt++;
	   flag = 1;
	 }
       }
     }
  }

 
   for(c = 0; c < i; c++){
     printf("%d",ba[c]);
     if(c != i-1){
       printf(" ");
   }
  }
   printf("\n%d\n",cnt);

   return 0;
}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
 
#define  ff     first
#define  ss     second
#define  pb     push_back
#define  all(x) (x).begin(), (x).end()
#define  rep(i,a,b) for(int i=a ; i<b ; ++i)
#define  deb(x) cout << #x << " - " << x << "\n";
#define  IOS    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  D2(x)  cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]\n"; 
#define  D2p(x)	cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << "\n";
#define  ps(x,y) fixed<<setprecision(y)<<x

int main() {
    IOS;
    string s; cin>> s;
    if(s=="ARC") cout << "ABC";
    else cout << "ARC";
}

Measured memory_bytes: 3576