akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef long long LL;
//-------------------------------------------------------------------LYYY↓
namespace LYYY{
	int read()
	{
		int s=0;char c=getchar();int f=1;
		while(c<48||c>57)
		{
			if(c==45) f=-1;
			c=getchar();
		}
		while(c>=48&&c<=57) s=(s<<3)+(s<<1)+(c^48),c=getchar();
		return s*f;
	}
	void write(int x)
	{
		if(x>=10) write(x/10);
		putchar(x%10+48);
	}
	void W(int x)
	{
		if(x<0) x=-x,putchar(45);
		write(x);
	}
}using namespace LYYY;
//-------------------------------------------------------------------bianliang↓
set<int> sst;
int A[222222],f[222222];
//-------------------------------------------------------------------hanshu↓
//-------------------------------------------------------------------main()↓
int main()
{
	int N=read(),K=read();
	int ans=0,flg=0,f=0;
	for(int i=1;i<=K;++i) sst.insert(A[i]=read()+1),A[i]>A[i-1]?++f:f=1;
	if(f==K) flg=1;
	else ans=1;
	for(int i=K+1;i<=N;++i)
	{
		A[i]=read()+1,A[i]>A[i-1]?++f:f=1;
		if(f>=K) flg=1;
		else if(A[i]<(*sst.rbegin())) ++ans;
		else if(A[i-K]!=(*sst.begin())) ++ans;
		sst.erase(A[i-K]),sst.insert(A[i]);
	}
	write(ans+flg);
	return 0;
}

Measured memory_bytes: 10368
<?php

$N = trim(fgets(STDIN));
$A = trim(fgets(STDIN));
$array = explode(" ", $A);

$combination = 0;
$countEachNum = array_count_values($array);

foreach($countEachNum as $value) {
  if ($value > 1) {
    $combination += ($value * ($value - 1)) / 2;
  }
}

for ($i = 0; $i < $N; $i++) {
  
  $k = $array[$i];
  $combinationOfK = $countEachNum[$k] - 1;
 
  echo $combination - $combinationOfK . PHP_EOL;
}

Measured memory_bytes: 25328
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

vector<int> tree[100005];

int dfs(int v, int from){
  if(tree[v].size()==1 && from != -1) return 0;
  int ret = 0;
  for(auto to : tree[v]) if(to != from) ret ^= dfs(to, v)+1;
  return ret;
}

int main(){
  int n;
  cin>>n;
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    tree[a].pb(b);
    tree[b].pb(a);
  }

  if(dfs(0,-1) == 0) cout << "Bob" << endl;
  else cout << "Alice" << endl;

  return 0;
}


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

public class Main{
    public static void main(String[] args)throws IOException{
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();

        int maxdis=0;
        int i=1;

        while(true){
            maxdis=maxdis + i;
            if(maxdis >= x){
                System.out.println(i);
                break;
            }
            else{
                i++;
            }
        }


    }
}


Measured memory_bytes: 24020
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int n;
  cin >> n;
  int l, r, res = 0;
  for (int i = 0; i < n; ++i) {
    cin >> l >> r;
    res += r - l + 1;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
 
int main() {
	string s;
	cin>>s;
	int ans[2];
	ans[0]=-1;
	REP(i,s.size()-1){
		if(s[i]==s[i+1]){
			ans[0]=i+1;
			ans[1]=i+2;
			break;
		}
	}
	REP(i,s.size()-2){
		if(s[i]==s[i+2]){
			ans[0]=i+1;
			ans[1]=i+3;
			break;
		}
	}
	if(ans[0]==-1)cout<<-1<<" "<<-1<<endl;
	else cout<<ans[0]<<" "<<ans[1]<<endl;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {// Main
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    if((a+b+c)>=22){
      System.out.println("bust");
    }
    else{
      System.out.println("win");
    }
    }
}

Measured memory_bytes: 21844
#include<stdio.h>
#define N 100
main()
{
  int A[N],i,j,x,n,flag,minj,count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<=n-1;i++){
    minj=i;
    flag=0;
    for(j=i;j<=n-1;j++){
      if(A[j]<A[minj]){
	minj=j;
	flag=1;
      }
    }
    if(flag==1){
      x=A[i];
      A[i]=A[minj];
      A[minj]=x; 
      count++;
    }
  }
  
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i==n-1)
      printf("\n");
    else
      printf(" ");
  }
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

const ll MOD = 1e9 + 7;

//素因数分解
vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for(ll i = 2; i * i <= n; i++) {
        if(n % i != 0) continue;
        ll ex = 0;

        while(n % i == 0) {
            ex++;
            n /= i;
        }

        res.push_back({i, ex});
    }

    if(n != 1) res.push_back({n, 1});
    return res;
}
//const auto &res = prime_factorize(n);

//二項係数 nCk mod p
//aのp乗を求める
ll modpow(ll a, ll p) {
   if(p == 0) return 1;
   if(p % 2 == 0) {
      int halfP = p / 2;
      ll half = modpow(a, halfP);
      //a^(p/2)をhalfとして、half*halfを計算
      return half * half % MOD;
   } else {
      //pが奇数のときは偶数にするために1減らす
      return a * modpow(a, p-1) % MOD;
   }
}
//二項係数の計算
//10C3 (10*9*8) / (3*2*1)
//(10*9*8):ansMul (3*2*1):ansDiv
ll calcComb(ll a, ll b) {
   if(b > a - b) return calcComb(a, a - b);

   ll ansMul = 1;
   ll ansDiv = 1;
   rep(i, b) {
       ansMul *= (a - i);
       ansDiv *= (i + 1);
       ansMul %= MOD;
       ansDiv %= MOD;
   }
   //ansMul / ansDiv をしたい
   //ansDivの逆元を求める
   ll ans = ansMul * modpow(ansDiv, MOD - 2) % MOD;

   return ans;
}

int main() {
    ll n, m;
    cin >> n >> m;

    ll ans = 1;
    const auto &res = prime_factorize(m);
    for(auto p : res) {
        ll x = p.second;
        ll tmp = calcComb(x + n - 1, n - 1);
        ans = (ans * tmp) % MOD;
    }

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


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

int main(){
    string s;
    int k;
    cin >> s >> k;
    vector<string> vec;
    int size = s.size();
    for(int i = 1 ; i <= min(k, size) ; i++){
        for(int j = 0 ; j <= s.size()-i ; j++){
            vec.push_back(s.substr(j, i));
        }
    }
    sort(vec.begin(), vec.end());
    int l = 0;
    while(l < vec.size()-1){
        if(vec[l] == vec[l+1]){
            vec.erase(vec.begin()+l);
            continue;
        }
        l++;
    }
    cout << vec[k-1] << endl;
    return 0;
}

Measured memory_bytes: 1660
#include<iostream>
using namespace std;
# define MAX 2000000

int H, A[MAX+1];

void maxHeapify(int i) {
  int l, r, largest;
  l = 2 * i;
  r = 2 * i + 1;

  // 左の子、自分、右の子で値が最大のノードを選ぶ
  // まずは左に関して、自分=iより大きいか判定
  if (l <= H && A[l] > A[i] ) largest = l;
  else largest = i;
  // 右に関して、一番大きいやつより大きいか判定
  if (r <= H && A[r] > A[largest]) largest = r;
  // 一番大きいのが自分でない時
  if (largest != i) {
    // swapは配列とかベクトルに格納されている値の交換
        swap(A[i], A[largest]);
        maxHeapify(largest);
  }
}

int main() {
  cin >> H;
  
  for (int i = 1;i <= H; i++) cin >> A[i];

  for (int i = H / 2; i >= 1; i--) maxHeapify(i);

  for (int i = 1; i <= H; i++) {
    cout << " " << A[i];
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 5032
#include<bits//stdc++.h>
using namespace std;
void dfs1(vector<vector<int> >&g,vector<int>&st,int pres,vector<bool>&vis)
{
  vis[pres]=1;
  for(int i=0;i<g[pres].size();i++)
  if(!vis[g[pres][i]])
  dfs1(g,st,g[pres][i],vis);
  st.push_back(pres);
}
void dfs2(vector<vector<int> >&g,vector<int>&ts,int pres,vector<bool>&vis)
{
  vis[pres]=1;
  ts.push_back(pres);
  for(int i=0;i<g[pres].size();i++)
  if(!vis[g[pres][i]])
  dfs2(g,ts,g[pres][i],vis);
}
int main()
{
  int n,m;
  cin>>n>>m;
  vector<int>tmp;
  vector<vector<int> >g(n+1,tmp);
   int xx,yy;
  for(int i=0;i<m;i++)
  {
     cin>>xx>>yy;
     g[xx].push_back(yy);
  }
  vector<bool>vis(n+1,0);
  vector<int>st,ts;
  for(int i=1;i<=n;i++)
  if(!vis[i])
  dfs1(g,st,i,vis);
  //vis.clear();
  //vis.resize(n+1,0);
  ////for(int i=n-1;i>=0;i--)
  //{
  //  if(!vis[st[i]])
  //  dfs2(g,ts,st[i],vis); 
  //}

  // for(int i=0;i<n;i++)
  //{
  //   cout<<ts[i]<<" ";
  //}
  //return 0;
  vector<int>dis(n+1,0);
  dis[st[0]]=0;int ans=0;
  for(int i=n-1;i>=0;i--)
  {
    for(int j=0;j<g[st[i]].size();j++)
    {
       dis[g[st[i]][j]]=max(1+dis[st[i]],dis[g[st[i]][j]]);
    } 
    ans=max(ans,dis[st[i]]);
   // cout<<st[i]<<"-"<<dis[st[i]]<<" ";
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 9336
#include<iostream>
#include<cstring>
#include<vector>
#include<stack>
#include<cstdio>
using namespace std;
int v[100007];
int maybe[100007];
int main()
{
	int i,n,m,x,y,ans=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)
	{
		v[i]=1;
		maybe[i]=0;
	}
	maybe[1]=1;
	for(i=0;i<m;++i)
	{
		scanf("%d%d",&x,&y);
		if(maybe[x]==1)
		{
			maybe[y]=1;
		}
		v[x]-=1;
		v[y]+=1;
		if(v[x]==0) maybe[x]=0;
	}
	for(i=1;i<=n;++i) if(maybe[i]==1) ++ans;
	printf("%d\n",ans);
	return 0;
}


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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()
#define YES()         printf("YES\n")
#define NO()          printf("NO\n")
#define Yes()         printf("Yes\n")
#define No()          printf("No\n")
#define in(a,x,b)     ((a) <= (x) && (x) < (b))

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
template<class T = int> using V = vector<T>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

const int dxs[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dys[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

int prime[1001001];
bool is_prime[1001001];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i < n; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < n; i++){
    if (is_prime[i]){
      prime[p++] = i;
      for (int j = 2*i; j < n; j+=i) is_prime[j] = false;
    }
  }
  return p;
}

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

  int N,K;
  cin >> N >> K;
  V<int> a(N);
  REP(i,N) cin >> a[i];

  ll ans = LLONG_MAX, cost = 0;
  int current_highest;
  REP(bits,1<<N) {
    if (__builtin_popcount(bits) < K) continue;
    if ((bits & 1) == 0) continue;
    cost = 0;
    current_highest = a[0];
    FOR(i,1,N) {
      if (current_highest < a[i]) {
        current_highest = a[i];
      } else if (bits & 1<<i) {
        cost += current_highest - a[i] + 1;
        current_highest++;
      }
    }
    chmin(ans, cost);
  }

  print(ans);
}



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

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

    vector<int> answer;
    int sum = 0;
    for (int p = 1; p <= N; p++) {
        if (sum + p > N) break;
        sum += p;
        answer.push_back(p);
    }
    int diff = N - sum,
        m = answer.size();
    int idx = m - 1;
    while (diff > 0) {
        answer[idx]++;
        diff--;
        idx = (idx - 1 + m) % m;
    }
    for (int a : answer) {
        cout << a << endl;
    }

    return 0;
}


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

//int _; 
 
int n;
set<int> st;

int main()
{
	//for(scanf("%d",&_);_;_--)
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int a;
		cin >> a;
		st.insert(a);	
	}
	puts(st.size() == n ?"YES":"NO");
	return 0;
}

Measured memory_bytes: 9600
s = input()
s = [int(s[:2]),int(s[2:])]

l = ['', '']
for i in range(2):
    if (1 <= s[i] <= 12):
        l[i] = 'MM'
    else:
        l[i] = 'YY'
else:
    if (l.count('MM') == 2):
        print('AMBIGUOUS')
    elif (l.count('MM') == 1):
        print(l[0]+l[1]) 
    else:
        print('NA')

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

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

  if (r <1200) cout << "ABC" << endl;
  else if (r <2800) cout << "ARC" << endl;
  else if (r >=2800) cout << "AGC" << endl;
  
    

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int i,N,nr;
int a[100001];
bool b[100001];

int main()
{
    cin >> N;
    for(i = 1; i <= N; ++i)
        cin >> a[i];
    i = nr = 1;
    while(!b[a[i]])
    {
        if(a[i] == 2)
        {
            cout << nr;
            return 0;
        }
        if(!b[a[i]])
            ++nr,b[a[i]] = 1,i = a[i];
    }
    cout << -1;
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <limits>
#include <cfenv>
#include <cmath>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <tuple>
#include <queue>
#include <vector>
#include <cmath>
#include <random>
#include <math.h>
#include <random>
#include <functional>


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

using lli = long long int;
using pii = std::pair<int, int>;

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;
}



// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



std::vector<std::pair<int, int>> D;
std::vector<lli> A, B;

int main(void){
    int n, k; scanf("%d%d", &n, &k);
    D.resize(n);
    REP(i, n) scanf("%d%d", &D[i].first, &D[i].second);
    std::sort(D.begin(), D.end(), [](pii& a, pii& b){
        if(a.first != b.first) return a.first < b.first;
        return a.second > b.second;
    });
    int idx = 0;
    while(idx < n){
        A.push_back(D[idx].second);
        while(idx + 1 < n and D[idx].first == D[idx+1].first){
            idx++; B.push_back(D[idx].second);
        }
        idx++;
    }
    std::sort(A.begin(), A.end(), std::greater<int>());
    std::sort(B.begin(), B.end(), std::greater<int>());
    lli res = 0;
    
    const int mA = A.size();
    FOR(i, 1, mA) A[i] += A[i-1];
    const int mB = B.size();
    FOR(i, 1, mB) B[i] += B[i-1];


    const int N = mA > k ? k : mA;
    for(int x = 1; x <= N; ++x){
        // x種類, k-x個
        if(not (0 < x and x <= mA)) continue;
        if(not (0 <= k-x and k-x <= mB)) continue;
        lli val = x; val *= x;
        val += A[x-1];
        val += (x == k ? 0 : B[k - x - 1]);

        chmax(res, val);
    }
    printf("%lld\n", res);

    
  
    return 0;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

int N;

signed main()
{
  cin >> N;
  if(N%2 == 1) {
    cout << 0 << endl;
    return 0;
  }

  int ans = N/10;
  N /= 10;

  while(N) {
    ans += N/5;
    N /= 5;
  }

  cout << ans << endl;

  return 0;
}


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

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

struct Edge {
    int to, i, color;
};

void dfs(vector<vector<Edge>> &G, int u, int par, Edge prev) {
    int color = 1;
    for (Edge& e : G[u]) {
        if (e.to == par) continue;
        if (color == prev.color) color ++;
        e.color = color;
        dfs(G, e.to, u, e);
        color ++;
    }
}

int main() {
    int N;
    cin >> N;
    int a, b;
    vector<vector<Edge>> G(N);
    for (int i=0; i<N-1; ++i) {
        cin >> a >> b;
        a--; b--;
        G[a].push_back((Edge){b, i, -1});
        G[b].push_back((Edge){a, i, -1});
    }

    Edge dummy = Edge{-1, -1, -1};
    dfs(G, 0, -1, dummy);

    int mx = 0;
    vector<int> ans(N-1);
    for (int i=0; i<N; ++i) {
        for (Edge &e : G[i]) {
            mx = max(mx, e.color);
            if (e.color != -1) {
                ans[e.i] = e.color;
            }
        }
    }

    cout << mx << endl;
    for (int i=0; i<N-1; ++i) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 8320
#include <iostream>
#include <string>
//#include <math.h> 
#include <iomanip>
//#include <vector>

using namespace std;

int answer = 0;
void cal(unsigned long long n){
    unsigned long long  a = 2;
    int trigger=1;
    int omomi=2;
    int loop_num=0;
    while (n >= a * a) {

        if (n % a == 0) {
            loop_num +=1;
            if(loop_num == trigger){
                ++answer;
                trigger = trigger+ omomi;
                ++omomi;
                //loop_num = 0;
            }
            n /= a;
        } 
        else {
            trigger=1;
            omomi=2;
            loop_num=0;
            if(a==2){
                a++;
            }
            else{
                a+=2;
            }
        }
    }
    if(n != a){
        ++answer;
    }
    else{
        loop_num += 1;
        if(loop_num == trigger){
            ++ answer;
            //cout << "innn" << endl;
        }
    }
}

int main(){
    unsigned long long N;
    cin >> N;
    //soinsu bunkai
    if (N == 1){
        cout << 0 << endl;
        return 0;
    }
    cal(N);
    //cout << m[2] << endl;


    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.*;


public class Main {
    private static String queue = "";
    private static boolean finished = false;
    
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        int row = 2;
        int col = sc.nextInt();
        int[][] candies = new int[row][col];
        for (int x = 0; x < row; x++) {
            for (int y = 0; y < col; y++) {
                candies[x][y] = sc.nextInt();
            }
        }
        
        int maxCount = 0;
        
        for (int i = 0; i < col; i++) {
            int count = 0;
            int x = 0;
            for (int y = 0; y < col; y++) {
                count += candies[x][y];
                if (i == y) {
                    count += candies[++x][y];
                }
            }
            
            maxCount = Math.max(maxCount, count);
        }
        
        System.out.println(maxCount);
    }
}

Measured memory_bytes: 22996
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

void load(void);
void output(void);

char alpha;

int main(){
	load();
	output();
	return 0;
}

void load(void){
	cin >> alpha;
}

void output(void){
	if('a' <= alpha && 'z' >= alpha){
		cout << "a";
	}else if('A' <= alpha && 'Z' >= alpha){
		cout << "A";
	}
}

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

using namespace std;

const int MaxN = 200005;

int n;
pair<int, int> a[MaxN];
map<int, int> mp;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].first;
        a[i].second = i;
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int u = a[i].first - a[i].second;
        u = -u;
        ans = ans + mp[u];
        mp[a[i].first + i]++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 22136
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef unsigned long long ull;
typedef   signed long long sll;

#define N_MAX 100

int comp (const void *x, const void *y) {
	return *(int*)x - *(int*)y;
}

int min (int x, int y) {
	return (x < y) ? x : y;
}

int solve (void) {
	return 0;
}

int main (void) {
	int l[N_MAX * 2];
	int n, i;
	int answer;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d%d", &l[i*2], &l[i*2+1]);
	}
	qsort(l, n * 2, sizeof(int), comp);
	answer = 0;
	for (i = 0; i < n * 2; i += 2) answer += l[i];
	printf("%d\n", answer);
	return 0;
}


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

using namespace std;

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, a, b) for (int i = a; i < b; i++)

int K , N;
int A[1000000];
int T;

int main()
{
	cin >> N >> K;
	rep(i, N) {
		cin >> A[i];
		if (A[i] == 1) T = i;
	}
	int T2 = N - 1 - T;
	int res = 0;
	if (T != 0) res += (T - 1) / (K - 1) + 1;
	T = res * (K - 1);
	T = N - 1 - T;
	if (T != 0) res += (T - 1) / (K - 1) + 1;

	int res2 = res;
	res = 0;
	T = T2;
	if (T != 0) res += (T - 1) / (K - 1) + 1;
	T = res * (K - 1);
	T = N - 1 - T;
	if (T != 0) res += (T - 1) / (K - 1) + 1;

	cout << min(res, res2) << endl;
	return 0;
}


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

    # divisors.sort()
    return divisors

def check_xy(alpha, beta):
    if alpha**2 + 4*beta < 0:
        return []

    x = (alpha + (alpha**2 + 4*beta)**0.5) // 2
    y = - (alpha - (alpha**2 + 4*beta)**0.5) // 2

    if (x - y) == alpha and x*y == beta:
        return [int(x), int(y)]
    else:
        return []


X = int(input())
divisor = get_divisor(X)


def check_beta(alpha, beta):
    if alpha**5 + 5*(alpha**3)*beta + 5*alpha*(beta**2) == X:
        return 1
    else:
        return 0

for alpha in divisor:
    rem = X // alpha
    # rem = a^4 + 5ba^2 + 5b^2
    rem -= alpha**4
    # rem = 5ba^2 + 5b^2
    if rem % 5 != 0:
        continue
    
    rem //= 5
    # rem = ba^2 + b^2

    if alpha**4 + 4*rem < 0:
        continue


    o_beta = int(( (alpha**4 + 4*rem)**0.5 - alpha**2) // 2)
    u_beta = int(( -(alpha**4 + 4*rem)**0.5 - alpha**2) // 2)

    # print(alpha, o_beta, u_beta, rem)

    if check_beta(alpha, o_beta) == 1:
        ans = check_xy(alpha, o_beta)
        
        if len(ans) == 2:
            print(ans[0], ans[1])
            break

    if check_beta(alpha, u_beta) == 1:
        ans = check_xy(alpha, u_beta)

        if len(ans) == 2:
            print(ans[0], ans[1])
            break

Measured memory_bytes: 9504
n = int(input())
a = [int(input()) for i in range(n)]
i = 0
cnt = 0
while i<n-1:
    cnt+=a[i]//2
    if a[i]%2 and a[i+1]:
        cnt+=1
        a[i+1]-=1
    i+=1
print(cnt+a[-1]//2)

Measured memory_bytes: 7076
#include <bits/stdc++.h>
using namespace std;
void main_sub(void);
int main(int argc, char* argv[]) {
    main_sub();
    return 0;
}
// int を int64_t にする
// g++ に -DUSE_STRICT_INT をつけるか、
// 下のコメントアウトを外すと無効化
// #define USE_STRICT_INT
using i64 = int64_t;
#ifndef USE_STRICT_INT
#define int i64
#endif
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF = (1 << 30);
constexpr i64 INFL = (1LL << 62);
constexpr i64 MOD = 1000000007;

void main_sub(void) {
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    rep(i, n) {
        int u, k;
        cin >> u;
        u--;
        cin >> k;
        rep(j, k) {
            int v;
            cin >> v;
            v--;
            g[u].push_back(v);
        }
    }
    queue<pair<int, int>> q;
    vector<int> dist(n, INF);
    q.push({0, 0});
    while (!q.empty()) {
        int from, d;
        tie(from, d) = q.front();
        q.pop();
        if (dist[from] > d) {
            dist[from] = d;
        }
        for (auto& to : g[from]) {
            if (dist[to] > d + 1) {
                dist[to] = d + 1;
                q.push({to, d + 1});
            }
        }
    }
    rep(i, n) {
        cout << i + 1 << " " << (dist[i] == INF ? -1 : dist[i]) << endl;
    }

    return;
}


Measured memory_bytes: 3164
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
#define Q 44
#define i16 short
#define Min(xxx,yyy) xxx=min(xxx+0,yyy)
i16 sm[Q][Q],f[Q][Q][Q][Q];
char aa[Q];
inline i16 G(int x1,int y1,int x2,int y2)
{--x1,--y1;return sm[x2][y2]+sm[x1][y1]-sm[x1][y2]-sm[x2][y1];}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int sx=-1,sy=-1;
	for(int i=1;i<=n;i++){
		scanf("%s",aa+1);
		for(int j=1;j<=m;j++){
			sm[i][j]=sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]+(aa[j]=='#');
			if(aa[j]>='A'&&aa[j]<='Z')sx=i,sy=j;
		}
	}
	if(min(sx,sy)<0)cerr<<"Err!!\n";
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			for(int k=1;k<=n;k++)
				for(int l=1;l<=m;l++)
					f[i][j][k][l]=10000;
	f[1][1][n][m]=0;
	i16 ans=10000;
	for(int x1=1;x1<=sx;x1++)
	for(int y1=1;y1<=sy;y1++)
	for(int x2=n;x2>=sx;--x2)
	for(int y2=m;y2>=sy;--y2){
		i16 val=f[x1][y1][x2][y2];
		Min(ans,val+min(min(G(x1,y1,sx,sy),G(sx,sy,x2,y2)),min(G(x1,sy,sx,y2),G(sx,y1,x2,sy))));
		for(int px=sx;px<=x2;px++)
			for(int py=y1;py<=sy;py++)
				Min(f[x1][py][px][y2],val+G(x1,y1,px,py-1)+G(px+1,py,x2,y2));
		for(int px=sx;px<=x2;px++)
			for(int py=sy;py<=y2;py++)
				Min(f[x1][y1][px][py],val+G(x1,py+1,px,y2)+G(px+1,y1,x2,py));
		for(int px=x1;px<=sx;px++)
			for(int py=y1;py<=sy;py++)
				Min(f[px][py][x2][y2],val+G(x1,py,px-1,y2)+G(px,y1,x2,py-1));
		for(int px=x1;px<=sx;px++)
			for(int py=sy;py<=y2;py++)
				Min(f[px][y1][x2][py],val+G(x1,y1,px-1,py)+G(px,py+1,x2,y2));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6784
import scala.io.StdIn.readInt

object Main extends App {
  def getNum(i:Int) = i match {
    case 4 => 5
    case 5 => 7
    case 6 => 8
    case 7 => 9
    case x => x
  }

  def scan(n:Int,b:Long,p:Long):Long = {
    val (m,r) = (n/8, n%8)
    if(m==0) b + getNum(r)*p
    else scan(m, b+getNum(r)*p, p*10)
  }

  Iterator.continually(readInt).takeWhile( _ != 0 ).foreach { n=>
    println(scan(n,0,1))
  }
}

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

using namespace std;

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		string snake;
		cin >> snake;
		if(snake.size() < 4)
		{
			cout << "NA" << endl;
		}
		else if(snake[0] == '>' && snake[1] == '\'' && snake[snake.size() - 1] == '~')
		{
			bool first = true;
			int count1 = 0;
			int count2 = 0;
			for(int i = 2; i < snake.size() - 1; ++i)
			{
				if(snake[i] == '=')
				{
					if(first)
					{
						++count1;
					}
					else
					{
						++count2;
					}
				}
				else if(snake[i] == '#')
				{
					first = false;
				}
				else
				{
					cout << "NA" << endl;
					goto END;
				}
			}
			if(count1 == count2 && count1 >= 1)
			{
				cout << "A" << endl;
			}
			else
			{
				cout << "NA" << endl;
			}
		}
		else if(snake[0] == '>' && snake[1] == '^' && snake[snake.size() - 2] == '~' && snake[snake.size() - 1] == '~')
		{
			bool flag = true;
			int count = 0;
			for(int i = 2; i < snake.size() - 2; i += 2)
			{
				if(snake[i] != 'Q' || snake[i + 1] != '=')
				{
					flag = false;
					break;
				}
				if(snake[i] == 'Q' && snake[i + 1] == '=')
				{
					++count;
				}
			}
			if(flag && count)
			{
				cout << "B" << endl;
			}
			else
			{
				cout << "NA" << endl;
			}
		}
		else
		{
			cout << "NA" << endl;
		}
END:
		;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
int maxi = 0, mini = INT_MAX;
int main(){
	int n, read;
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> read;
		mini = min(mini, read);
		maxi = max(maxi, read);
	}
	cout << maxi - mini << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main(){
    int a,b;
    cin >> a >> b;
    if(a % 2 == 0 || b % 2 == 0) cout << "No\n";
    else cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
//Insertion Sort
#include <iostream>

using namespace std;

void print(int A[], int n) {
    for(int i=0; i<n-1; i++) cout << A[i] << " ";
    cout << A[n-1] << endl;
}

void insertionSort(int A[], int n) {
    print(A, n);

    for(int i=1; i<n; i++) {
        int key = A[i];
        int j = i-1;
        while(j >= 0 && A[j] > key) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = key;
        print(A, n);
    }
}

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

    insertionSort(A, n);

    return 0;
};



Measured memory_bytes: 3100
#include <cstdio>
#include <set>
#include <functional>

using namespace std;

typedef long long ll;

int main() {
    int n, m, a;
    scanf("%d%d", &n, &m);
    multiset<int, greater<int>> d;
    for (int i = 0; i < n; ++i) scanf("%d", &a), d.insert(a);
    for (int i = 0; i < m; ++i) {
        d.insert(*d.begin() / 2);
        d.erase(d.begin());
    }
    ll ans = 0;
    for (auto i = d.begin(); i != d.end(); ++i) ans += *i;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
	if (b == 0) return a;
  return gcd(b, a%b);
}
int ggcd(int a, int b, int c) {
	return gcd(a, gcd(b, c));
}
int main() {
  	int k;
  cin >> k;
  long long answer = 0ll;
  for (int a=1; a<=k; a++) {
    for (int b=1; b<=k; b++) {
      for (int c=1; c<=k; c++) {
        answer += (long long) ggcd(a, b, c);
      }}}
  cout << answer << '\n';
 	return 0; 
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
#define REP(i,st,num)for(int i=(st);i<(num);++i)
#define ll long long
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int A,B;
    cin >> A >> B;
    cout<< max(A+B,max(A-B,A*B));
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

class Main{
	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}	
}

class Solve{
	Solve(){}
	
	Scanner in = new Scanner(System.in);

	void solve(){
		int q = in.nextInt();
		for(int i = 0; i < q; i++){
			int c = in.nextInt(), a = in.nextInt(), n = in.nextInt();
			int ans = 0;
			int k = Math.min(c, Math.min(a, n));
			ans += k;
			c -= k;
			a -= k;

			k = Math.min(c / 2, a);
			if( k < 0) k = 0;
			ans += k;
			c -= k * 2;

			if(c < 0) c = 0;
			ans += c / 3;

			System.out.println(ans);
		}
	}
	
}

// while(in.hasNext()){
		// 	int n = in.nextInt();
		// 	if(n == 0) return;
			
		// }

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

using namespace std;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)

struct SuffixArray {
  int N, k;
  string S;
  vector<int> sa, rank, tmp;
  SuffixArray(string S) : S(S) {
    N = S.size();
    sa.resize(N+1), rank.resize(N+1), tmp.resize(N+1);
    construct_sa();
  }

  bool compare_sa(int i, int j) {
    if (rank[i] != rank[j]) {
      return rank[i] < rank[j];
    } else {
      int ri = i + k <= N ? rank[i + k] : -1;
      int rj = j + k <= N ? rank[j + k] : -1;
      return ri < rj;
    }
  }

  void construct_sa() {
    for (int i = 0; i <= N; i++) {
      sa[i] = i;
      rank[i] = i < N ? S[i] : -1;
    }

    for (k = 1; k <= N; k *= 2) {
      sort(sa.begin(), sa.end(), [&] (const int & i, const int & j) { return compare_sa(i, j); });

      tmp[sa[0]] = 0;
      for (int i = 1; i <= N; i++) {
        tmp[sa[i]] = tmp[sa[i-1]] + (compare_sa(sa[i-1], sa[i]) ? 1 : 0);
      }
      for (int i = 0; i <= N; i++) rank[i] = tmp[i];
    }
  }
};

int main() {
  int K; cin >> K;
  string S; cin >> S;
  int N = S.size();
  SuffixArray sa(S);

  vector<int> cand;
  int L = ((int)S.size() + K) / (K + 1);
  REP(i, sa.sa.size()) {
    if (sa.sa[i] + L <= N) cand.push_back(sa.sa[i]);
  }

  function<bool (int)> check = [&](int mid) {
    int cnt = 0, cur = 0;
    while (cur < N) {
      if (sa.rank[cur] <= sa.rank[cand[mid]]) {
        cur += L;
      } else {
        cur += L - 1;
      }
      cnt++;
      if (cnt - 1 > K) return false;
    }
    return cnt - 1 <= K;
  };

  int left = -1, right = cand.size() - 1;
  while (left + 1 < right) {
    int mid = (left + right) / 2;
    (check(mid) ? right : left) = mid;
  }

  cout << S.substr(cand[right], L) << endl;
  return 0;
}


Measured memory_bytes: 2300
#include <iostream>
using namespace std;
int gcd(int a,int b)
{
    if(b==0)
    return a;
    else return gcd(b,a%b);
}
int main() {
  int n;
  cin>>n;
  long long int res=0;
  for(int i=1;i<=n;i++)
  {
      for(int j=1;j<=n;j++)
      {
          for(int k=1;k<=n;k++)
          {
              if(i==1||j==1||k==1)
              res+=1;
              else res+=gcd(k,gcd(i,j));
          }
      }
  }
  cout<<res;
}

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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

void ALLOUT_NUMBER(vector<ll> V)
{
    ll N = V.size();
    for(ll i=0;i<N;i++)
    {
        cout << V[i];
        if(i<N-1) cout << ' ';
    }
    cout << endl;
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

int main()
{
    char c;
    cin >> c;

    if(c>='a')
    {
        OUT0("a");
    }
    else
    {
        OUT0("A");
    }
    

    return 0;
}

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

using namespace std;

int main(){
    string s,t;
    cin>>s>>t;
    int value = -1;
    for(int i=0;i<s.size()-t.size()+1;i++){
        bool flag = true;
        for(int j=0;j<t.size();j++){
            if(t[j]==s[i+j]||s[i+j]=='?'){
                continue;
            }else{
                flag = false;
                break;
            }
        }
        if(flag) value = i;
    }
    if(value!=-1){
        for(int i=0;i<t.size();i++){
            s[value+i] = t[i];
        }
        for(int j=0;j<s.size();j++){
            if(s[j]=='?'){
                s[j] = 'a';
            }
        }
        cout<<s<<endl;
    }else{
        cout<<"UNRESTORABLE"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
        String[] inputs = Io.read();
        String[] meta = inputs[0].split(" ");

        int N = Integer.parseInt(meta[0]);
        int M = Integer.parseInt(meta[1]);

        long[][] parsed = parse(inputs, N);

        Arrays.sort(parsed, (a, b) -> Long.compare(a[0], b[0]));

        long cost = 0;
        for (int i = 0; i < parsed.length; i++) {
            if (M <= parsed[i][1]) {
                cost += parsed[i][0] * M;
                M = 0;
                break;
            }
            cost += parsed[i][0] * parsed[i][1];
            M -= parsed[i][1];
        }
        Io.write(cost);
    }

    private static long[][] parse(String[] lines, int N) {
        long[][] parsed = new long[N][2];
        for (int i = 0; i < N; i++) {
            String[] line = lines[i + 1].split(" ");
            parsed[i][0] = Long.parseLong(line[0]);
            parsed[i][1] = Long.parseLong(line[1]);
        }

        return parsed;
    }
}

class Io {

    /**
     * 標準入力から1行ずつ受け取る
     * @return
     * @throws IOException
     */
    public static String[] read() throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        List<String> inputs = new ArrayList<>();
        String line;
        while ((line = br.readLine()) != null) {
            if (line.equals(""))
                break;

            inputs.add(line);
        }
        br.close();
        return inputs.toArray(new String[0]);
    }

    /**
     * 標準出力
     * @param answer
     */
    public static void write(long answer)
    {
        System.out.println(answer);
    }
}


Measured memory_bytes: 54920
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cout<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int cnt[222222],n,k,ans,b,c;

main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++)cnt[i%k]++;
    for(int a=0;a<k;a++){
        b=(k-a)%k;
        c=(k-a)%k;
        if((b+c)%k!=0)continue;
        ans+=cnt[a]*cnt[b]*cnt[c];
    }
    dans;
}



Measured memory_bytes: 1024
#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 pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n, l, p;
    cin >> n >> l;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    bool ok = false;
    REP(i, n-1){
        if(a[i-1]+a[i] >= l){
            ok = true;
            p = i;
        }
    }
    if(!ok)cout << "Impossible" << endl;
    else{
        cout << "Possible" << endl;
        REP(i, p-1)cout << i << endl;
        for(int i = n-1; i > p; i--)cout << i << endl;
        cout << p << endl;
    }
}   

Measured memory_bytes: 1664
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()

p = [input() for i in range(N)]

print sum(p) - max(p) / 2

Measured memory_bytes: 2812
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;
	int n,m;
	cin>>n>>m;

	vector<int>vis(n+1,0);
	vector<int>level(n+1,0);
	vector<int>g[n+1];

	queue<int>q;

	bool flag=0;

	for(i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);

		if(u==1||v==1)
		{
			flag=1;
		}
	}

	if(!flag)
	{
		cout<<"No"<<endl;
	}
	else
	{
		cout<<"Yes"<<endl;
		q.push(1);
		vis[1]=1;
		level[1]=0;

		while(!q.empty())
		{
			int node=q.front();
			q.pop();

			for(auto it:g[node])
			{
				if(!vis[it])
				{
					vis[it]=1;
					level[it]=node;
					q.push(it);
				}
			}
		}

		for(i=2;i<=n;i++)
		{
			cout<<level[i]<<endl;
		}
	}







}

Measured memory_bytes: 13900
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	cout << (n - 1) * (m - 1) << endl;
	return 0;
}
	

Measured memory_bytes: 256
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>
#include <limits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
//エイリアス
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

//定数
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 1e9 + 7;
const double pi = M_PI;

int main()
{
  string s, t;
  cin >> s >> t;
  rep(i, s.size()) {
    if(s[i] != t[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3624
# -*- coding: utf-8 -*-
s = input()
ret = 'Yes'
if len(s) % 2 == 1:
    ret = 'No'
else:
    for i in range(len(s)):
        if i % 2 == 0 and s[i] == 'h': continue
        elif i % 2 == 1 and s[i] == 'i': continue
        else:
            ret = 'No'
            break
print(ret)


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

using namespace std;

string A = "keyence";

int main(){
    string S;
    cin >> S;
    int N = S.size();
    
    if(N < 7) cout << "NO" << endl;
    else{
        for(int i = 0; i <= 7; i++){
            int cnt = 0;
            for(int j = 0; j < N; j++){
                if(j < i || j >= i+(N-7)){
                    if(S[j] != A[cnt]) break;
                    cnt++;
                }
                if(cnt == 7) {
                    cout << "YES" << endl;
                    return 0;
                }
            }
        }
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
from itertools import combinations, accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,K=MAP()
A=LIST()

acc=list(accumulate(A, max))

ans=INF
for comb in combinations(range(N), K):
    sm=0
    for i, n in enumerate(comb):
        if i==0:
            cost=max(acc[n]-A[n], 0)
            if n!=0 and acc[n-1]==acc[n]:
                cost+=1
        else:
            cost=max(prev-A[n]+1, acc[n-1]-A[n]+1, 0)
        sm+=cost
        prev=A[n]+cost
    ans=min(ans, sm)
print(ans)


Measured memory_bytes: 3064