akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()
 
#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>
 
#define debug(x) {cerr <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}
 
#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue
 
#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
 
 
using namespace std;

const int max_n = 1e5 + 5;




void solve() {
	string s; cin >> s;
	int n = s.length();
	if (n == 1) {
		cout << s << endl;
		return;
	}
	lint sum = 0;
	FOR(i,0,n) {
		lint p10 = 1;
		int left = (1<<i);
		int right = (1<<(n-1-i));
		if (right > 1) right = right/2;
		FOR(j,i+1,n+1) {
			sum += left * 1LL * p10 * 1LL * right * (s[i] - '0');
			p10 = p10 * 1LL * 10;
			if (right > 1) right = right / 2;
		}
	}
	printf("%lld\n", sum);
}


int main() {
	int z = 1;
	// read(z);
	while (z--) {
		solve();
	}
}


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

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);

	int n, k;
	cin >> n >> k;

	int c = (n - 1) * (n - 2) / 2;
	if (c < k) {
		cout << -1 << "\n";
	} else {
		vector<pair<int, int> > a;
		for (int i = 2; i <= n; i++)
			a.push_back(make_pair(1, i));
		bool done = false;
		int m = 0;
		for (int i = 2; i <= n && !done; i++)
			for (int j = i + 1; j <= n && !done; j++)
				if (m < (c - k)) {
					a.push_back(make_pair(i, j));
					m++;
				} else done = true;
		cout << a.size() << "\n";
		for (int i = 0; i < a.size(); i++)
			cout << a[i].first << ' ' << a[i].second << "\n";
	}

	return 0;
}


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

int main() {
  int a,b,c,d,e,f,g,h,i;
  cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;
  if(a+e==b+d&&a+f==c+d&&a+h==b+g&&a+i==c+g) cout << "Yes" << endl;
  else cout << "No" << endl;;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  
  
  for(int i = 1; i <= n; i++){
    if( (int)(floor(log10(i)) + 1) % 2 == 1){
      ans += 1;
    }
  }
 
  
  cout << ans << endl;
  


}



Measured memory_bytes: 512
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    //cout << "Hello world!" << endl;
    ll t,i,j,k,m,n,a,b,d;
   cin>>n;
    ll ar[n];
for(i=0;i<n;i++)
{
    cin>>ar[i];
}
vector<ll>v;
   for(i=0;i<n;i++)
   {
       k=ar[i];j=0;
       while(k%2==0)
       {
           j++;
           k/=2;


       }
       v.push_back(j);
   }
   ll an=0;
   for(i=0;i<v.size();i++)
   {
     an+=v[i];
      //cout<<v[i]<<" ";;
   }
   cout<<an;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,k,ans=2e16+7;
  cin >> n >> k;
  ll x[n];
  for(ll i=0;i<n;i++) cin >> x[i];
  for(ll i=0;i<n-k+1;i++){
    ll c;
    if(x[i]<0&&0<x[i+k-1]) c=x[i+k-1]-x[i]+min(-x[i],x[i+k-1]);
    else if(0<=x[i]) c=x[i+k-1];
    else if(x[i+k-1]<=0) c=-x[i];
    ans = min(ans,c);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

using Graph=vector<vector<int>>;
Graph G;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  string s,t;
  cin >> s>> t;
  rep(i,n){
    cout<<s[i]<<t[i];
  }
  cout<<endl;
}
    

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int t = sc.nextInt();
		int max = 0;
		for (int i = 0; i < t; i++) {
			int a = sc.nextInt();
			if (max < a) {
				max = a;
			}
		}
		System.out.println(Math.max(max - (k - max) - 1, 0));
	}
}


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



int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S.at(i) >> P.at(i);
    }

    vector<string> sorted(N);
    sorted = S;
    sort(sorted.begin(), sorted.end());

    vector<int> flags(N, true);
    for (int i = 0; i < N; i++) {
        int max = 0;
        int syuturyoku = 0;
        for (int j = 0; j < N; j++) {
            if (sorted.at(i) == S.at(j)) {
                if (max <= P.at(j) && flags.at(j)) {
                    max = P.at(j);
                    syuturyoku = j;
                }
            }
        }
        cout << syuturyoku + 1 << endl;
        flags.at(syuturyoku) = false;
    }
}

Measured memory_bytes: 256
a = [ 0] * 5
for i in range(int(input())):
  s = input()
  if s[0] == 'M':
    a[0] += 1
  elif s[0] == 'A':
    a[1] += 1
  elif s[0] == 'R':
    a[2] += 1
  elif s[0] == 'C':
    a[3] += 1
  elif s[0] == 'H':
    a[4] += 1

m = 0
for i in range(5):
  for j in range(i+1, 5):
    for k in range(j+1,5):
      m += a[i]*a[j]*a[k]
print(m)
    

Measured memory_bytes: 3064
def gcd(x, y)
  while true
    r = x % y
    break if r == 0
    x = y
    y = r
  end
  return y
end

a, b = gets.split.map(&:to_i)
g = gcd(a, b)

count = 1
flag = false
while g % 2 == 0 do
  g /= 2
  flag = true
end
count += 1 if flag

sqr = Math.sqrt(g).to_i
3.step(sqr, 2) do |d|
  flag = false
  while g % d == 0 do
    g /= d
    flag = true
  end
  count += 1 if flag
end
count += 1 if g > 1
puts count


Measured memory_bytes: 1788
v, e = map(int, input().split())

dp = [[float("inf")] * (v) for _ in range(1 << v)]
edges = [[float("inf")] * v for _ in range(v)]


for edge in range(e):
    frm, to, w = map(int, input().split())
    edges[frm][to] = w

dp[1][0] = 0

for i in range(1 << v):
    for j in range(v):
        if dp[i][j] == float("inf"):
            continue
        for k in range(v):
            if (i >> k) % 2 == 1:
                continue
            next_d = dp[i][j] + edges[j][k]
            next_i = i | (1 << k)

            dp[next_i][k] = min(dp[next_i][k], next_d)

all = (1 << v) - 1
ans = float("inf")

for i in range(1, v):
    ans = min(ans, dp[all][i] + edges[i][0])

if ans == float("inf"):
    print(-1)
else:
    print(ans)



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

int main() {
	int H , W ;
  	cin >> H >> W ;
  	string S;
    vector<char> vec(W);
    for(int i = 0; i < W + 2; i++){
    	cout << "#";
    }
    cout << endl;
    for(int i = 0 ; i < H ; i++){
        cout << "#";
    	cin >> S;
        cout << S ;
        cout << "#";
        cout << endl;
    }
    for(int i = 0; i < W + 2; i++){
    	cout << "#";
    }
}


Measured memory_bytes: 256
// Last Change: 01/20/2019 21:15:00.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}

vector<ll> dp(1000005, 0);

ll Cal(int pos) {
  if (dp.at(pos) == 0) {
    //計算
    ll before = Cal(pos - 1);
    //偶数
    if (before % 2 == 0) {
      dp.at(pos) = before / 2;
    }
    //奇数
    else {
      dp.at(pos) = 3 * before + 1;
    }
  }
  return dp.at(pos);
}

int main() {
  cin >> dp.at(1);

  // posは2スタート
  int pos = 1;
  bool go = true;
  while (go) {
    ++pos;
    for (int i = 1; i < pos; ++i) {
      if (dp[i] == Cal(pos)) {
        go = false;
        break;
      }
    }
  }

  cout << pos << endl;

  //LoopUntilZeroInpput();
}


Measured memory_bytes: 8064
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  [a, b] <- map (read::String -> Int) . words <$> getLine
  s <- getLine
  let valid = snd $ foldl (\(index, isValid) c -> if (index == a && c == '-') || (index /= a && isDigit c) then (index + 1, isValid) else (index + 1, False)) (0, True) s
  putStrLn $ if valid then "Yes" else "No"




Measured memory_bytes: 508
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}



int main() {
  int N,A,B;
  cin >> N >> A >> B;
  vector<ll> H(N);
  ll s=0;
  rep(i,N){
    cin >> H[i];
  }
  ll ng=0,ok=1e10,now;
  while (ok-ng>1) {
    now=(ok+ng)/2;
    ll cnt=0;
    rep(i,N) {
      if (H[i]-now*B>0) cnt+=(H[i]-now*B+A-B-1)/(A-B);
    }
    // cout << now << ' ' << cnt << endl;
    if (cnt<=now) ok=now;
    else ng=now;
  }
  cout << ok << endl;
}

Measured memory_bytes: 1024
#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>;

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

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}

mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

int main() {
  //すぬけさんの丸パクリ
  
  int n, a, b;
  cin >> n >> a >> b;
  mint ans = f(n);
  ans -= 1;
  ans -= choose(n,a);
  ans -= choose(n,b);
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

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

  vector<long long> c(n, 0), s(n, 0), f(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> c[i] >> s[i] >> f[i];
  }

  for (int i = 0; i < n; i++) {
    long long cur_time = s[i];
    cur_time += c[i];
    for (int j = i + 1; j < n - 1; j++) {
      long long train_time;   // 電車に乗る時間
      if (cur_time <= s[j]) { // 始発より早く着いたら, 始発で Go
        train_time = s[j];
      } else { // 始発より遅く着いたら s[j] + k f[j] >= cur_time を満たす最小の
               // s[j] + k f[j] に出発
               // cur_time - s[j] <= k f[j]
               // (cur_time - s[j]) / f[j] <= k
               // k = ceil((cur_time - s[j]) / f[j])
        long long k = (cur_time - s[j] + f[j] - 1) / f[j];
        train_time = s[j] + f[j] * k;
      }
      cur_time = train_time + c[j];
    }
    cout << cur_time << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
//This is getting accepted!
#include<bits/stdc++.h>
#define ll long long
#define oo 1000000009
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define INARR(a,n) for (int i = 1; i <= (n); ++i) cin >> a[i];
#define ITE(x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define isset(x, i) (((x)>>(i))&1)
#define setbit(x, i) ((x)^(1ll<<(i)))
#define clearbit(x, i) ((x)&(~(1ll<<(i))))
#define twoexp(i) (1ll<<(i))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define FI first
#define SE second
#define son1 (id*2)
#define son2 (id*2+1)

using namespace std;

const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = 2 * acos(0);
const int MAXN = 1e6 + 6;



void input() {
	int u, v, w, x, y, qtype;
	
	
	
}


void preprocess() {
	
	
	
}

void process(int itest) {
	int u, v, w, x, y, qtype;
	
	cin >> x >> y;
	
	cout << max(x+y, max(x-y, x*y)) << endl;
	
}

void oneTest() {
	
	input();
	preprocess();
	process(0);
	
}

void multiTest() {
	
	int t;
	cin >> t;
	
	for (int it = 1; it <= t; ++it) {
		input();
		preprocess();
		process(it);
	}
}

int main(){
    #ifndef ONLINE_JUDGE
//    freopen("../out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	oneTest();
//	multiTest();

    return 0;

}


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

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


    int n, k;
    cin >> n >> k;
    int digits = 0;
    while (n > 0) {
        n /= k;
        digits++;
    }

    cout << digits << endl;

    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1; 
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	int n;
	cin >> n;
	n = n % 10;
	if (n == 0 || n == 1 || n == 6 || n == 8) {
		cout << "pon";
	}
	else if (n == 3) {
		cout << "bon";
	}
	else {
		cout << "hon";
	}
}

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

int par[100010];
int depth[100010];

void init(int n) {
    for(int i = 0; i < n; i++)
    {
        par[i] = i;
        depth[i] = 0;
    }
}

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

void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;

    if (depth[x] < depth[y]) par[x] = y;
    else {
        par[y] = x;
        if (depth[x] == depth[y]) depth[x]++;
    }
}

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


struct edge {long long u, v, cost;};

bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}

edge es[(100000 - 1) * 2];
int V, E;

long long kruskal() {
    sort(es, es + E, comp);
    init(V);
    long long res = 0;
    for (int i = 0; i < E; i++) {
        edge e = es[i];
        if (!same(e.u, e.v)) {
            unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    V = n;
    E = (n - 1) * 2;
    vector<pair<int, int>> xv(n), yv(n);
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;

        xv.at(i) = make_pair(x, i + 1);
        yv.at(i) = make_pair(y, i + 1);
    }

    sort(xv.begin(), xv.end());
    sort(yv.begin(), yv.end());
    
    for (int i = 0; i < n - 1; i++) {
        es[i * 2] = edge{xv.at(i).second, xv.at(i + 1).second, abs(xv.at(i).first - xv.at(i + 1).first)};
        es[i * 2 + 1] = edge{yv.at(i).second, yv.at(i + 1).second, abs(yv.at(i).first - yv.at(i + 1).first)};
    }

    cout << kruskal() << endl;
}

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

using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int d, e;
    d = min(a, min(b, c));
    e = max(a, max(b, c));
    if(d == a){
        if(e == b) e = c;
        else e = b;
    }
    else if(d == b){
        if(e == a) e = c;
        else e = a;
    }
    else{
        if(e == a) e = b;
        else e = a;
    }
    cout << d * e / 2 << endl;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
Tree=[[] for i in range(N)]
MOD=10**9+7
import sys
sys.setrecursionlimit(10**9)
for i in range(N-1):
  a,b=map(int,input().split())
  Tree[a-1].append(b-1)
  Tree[b-1].append(a-1)
def P(n,m):
  _=n
  for i in range(m-1):
    n-=1
    _*=n
    _%=MOD
  return _%MOD
def dfs(p,i):
  global Tree,ans
  n=len(Tree[i])-1
  if n==0:
    return
  if i==0:
    ans*=P(K-1,n)
  else:
    ans*=P(K-2,n)
    ans%=MOD
  for j in Tree[i]:
    if j==p:
      continue
    dfs(i,j)
Tree[0].append(-1)
ans=K
dfs(-1,0)
print(ans%MOD)

Measured memory_bytes: 87340
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define INF         1e9
#define fastRead    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

const int MAX = 1e6 + 6;
int main()
{
    fastRead;
    int n, k;
    cin>>n>>k;
    vector<int>vec(n), dp(k+1);
    for(int i =0 ; i < n; i++ ) cin>>vec[i];
    
    for(int i =0 ; i <= k ; i++) {
        
        for(auto x : vec) {
            if(i - x < 0) continue;
            dp[i] |= !dp[i-x];
        }
    }
    if(dp[k]) cout<<"First\n";
    else cout<<"Second\n";
    return 0;
}

Measured memory_bytes: 3704
#define _USE_MATH_DEFINES
#include <math.h>
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    string s;
    cin >> s;
    vector<char> v;
    for(int i = 0;i < s.size();i++)
    {
        if(s[i] == '0' || s[i] == '1')
        {
            v.push_back(s[i]);
        }
        else if(!v.empty())
        {
            v.pop_back();
        }
    }
    for(int i = 0;i < v.size();i++)
    {
        cout << v[i];
    }
    cout << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ans,a;
multiset<int>st;
multiset<int>:: iterator it;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a);
		if(st.empty()||a<=*st.begin())ans++;
		else {
			it=st.lower_bound(a);
			it--;
			st.erase(it);
		}st.insert(a);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 4992
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
char ch[10000];
int main(){
	scanf("%s",ch+1); int n=strlen(ch+1); n-=8;
	for (int i=1;i<=n;i++) putchar(ch[i]);
}

Measured memory_bytes: 256
#include<stdio.h>
	int main(){
		int n,m,a[10000],k,i,j,h;
		while(scanf("%d %d",&n,&m),n||m){
			k=0;
			for(i=1;i<=n;i++)
				a[i]=i;
			for(i=0;i<n-1;i++){
				
				
				
				for(j=0;j<m;j++){
					for(h=0;h<n;h++){
						k++;
						if(k>n)
							k=k%n;
						if(a[k]>0){
							break;
						}
					}
				}				
				
				a[k]=0;
				
			}
			for(i=1;i<=n;i++)
				if(a[i]>0){
					printf("%d\n",a[i]);
				}
		}
		return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    // 制約の厳しい方から見る。貪欲に近い

    int n,m,a,b; cin >> n >> m;
    minheap<PII> ab;
    rep(i,n) {
        cin >> a >> b;
        ab.emplace(a,b);
    }

    int cnt = 0;
    maxheap<int> que;
    for(int i = 1; i <= m; ++i) {
        while (1) {
            auto p = ab.top();
            if(p.first > i || ab.empty()) break;
            ab.pop();
            que.push(p.second);
        }
        if(que.empty()) continue;
        cnt += que.top();
        que.pop();
    }

    cout << cnt << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 1908
N=int(input())
S=str(input())
list_R=[]
list_G=[]
list_B=[]
count=0
for i in range(N):
    if S[i]=="R":
        list_R.append(i)
    if S[i]=="G":
        list_G.append(i)
    if S[i]=="B":
        list_B.append(i)
for i in range(N):
    for j in range(N):
        if i+2*j>N-1:
            break
        if S[i]!=S[i+j] and S[i+j]!=S[i+j*2] and S[i+2*j]!=S[i]:
            count=count+1

print(len(list_B)*len(list_G)*len(list_R)-count)
        


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

int main() 
{	
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	int a;
	cin>>a;
	cout<<ceil(double(a)/2);	
	
	return 0;	
}

Measured memory_bytes: 256
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
//conversion
//------------------------------------------
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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
int main(void){
	int n;
	int sum=0;
	cin >> n;
	n = 24 - n;
	cout << 24 + n << endl;
	return 0;
}



Measured memory_bytes: 256
// best coder in the world do not mess with me!!
    #include <bits/stdc++.h>
    #define REP(i,n) for(int i=0;i<n;i++)
    #define FOR(i, a, b) for (int i = (a); i < (b); i++)
    #define FORD(i, a, b) for(int i = (a); i > (b); i--)
    #define pb(a) push_back(a)
    #define mp(a,b) make_pair(a,b)
    typedef long long int ll;
    using namespace std;
    ll mod=1000000007;
    void generate(int per[],int t)
    {
    	
    	for(int i=t-1;i>0;i--)
    	{
    		int k=rand()%i;
    		swap(per[k],per[i]);
    	}
    }
    int main()
    {
        
        
        	int x,Y;
        	cin>>x>>Y;
        	cout<<(x+Y-1)/Y<<'\n';
        
    }

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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; }

const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1e9 + 7;


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


int main() {

	int n;
	cin >> n;

	vector<pair<ll,ll>> p(n);
	vector<pair<ll,ll>> q(n);


	REP(i, n) {
		int a, b;
		cin >> a >> b;
		p[i] = { a,b };
		q[i] = { b,a };
	}
	sort(ALL(p));
	sort(ALL(q));


	if (n % 2 == 1) {
		ll l = p[n / 2].first;
		ll r = q[n / 2].first;
		cout << r - l + 1 << endl;
		return 0;
	}
	ll l = p[n / 2 - 1].first;
	ll r = q[n / 2 - 1].first;


	ll la = p[n / 2].first;
	ll ra = q[n / 2].first;

	
	cout << ra + r - la - l + 1 << endl;
	

	


}


Measured memory_bytes: 9520
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            string T = "";
            //Console.WriteLine(str.Substring(T.Length, 5) + "\n" + str.Substring(T.Length + 5, 5));
            char[] work = str.ToCharArray();
            Array.Reverse(work);
            str = new string(work);
            while (true)
            {
                if (str.Length == T.Length)
                {
                    Console.WriteLine("YES");
                    break;
                }
                try
                {
                    if (str.Substring(T.Length, 5) == "maerd" || str.Substring(T.Length, 5) == "esare")
                    {
                        T += str.Substring(T.Length, 5);
                    }
                    else if (str.Substring(T.Length, 6) == "resare")
                    {
                        T += "resare";
                    }

                    else if (str.Substring(T.Length, 7) == "remaerd")
                    {
                        T += "remaerd";
                    }
                    else
                    {
                        Console.WriteLine("NO");
                        break;
                    }
                }
                catch
                {
                    Console.WriteLine("NO");
                    break;
                }
            }
        }// End_function
    }// End_class
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define LLINF LLONG_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

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

const int MAX_N = 110;
const int MAX_V = 100100;

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input values
    ll N, W;
    cin >> N >> W;

    vector<ll> w(N), v(N);
    rep (i, N) {
        cin >> w[i] >> v[i];
    }

    // dp table
    vector<vector<ll>> dp(MAX_N, vector<ll>(MAX_V, INF));

    // init dp table

    // init condition
    dp[0][0] = 0;

    // loop
    rep (i, N) {
        rep (sum_v, MAX_V) {
            if (sum_v - v[i] >= 0) {
                chmin(dp[i+1][sum_v], dp[i][sum_v-v[i]]+w[i]);
            }
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    ll ans = 0;
    rep (sum_v, MAX_V) {
        if (dp[N][sum_v] <= W) {
            ans = sum_v;
        }
    }

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

Measured memory_bytes: 87296
import { readFileSync } from 'fs'
import { reverse } from 'dns'
import { start } from 'repl'
 
let lines: string[] = [];
const reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
 
reader.on('line', function (line: string) {
    lines.push(line);
});
reader.on('close', function () {
    let [n, k] = lines[0].split(' ').map( _ => parseInt(_))
    let p = lines[1].split(' ').map( _ => parseInt(_))

    p.sort((a:number, b:number) => a - b)
    let ans = 0
    for(let i = 0; i < k; i++) {
        ans += p[i]
    }

    console.log(ans)
});

Measured memory_bytes: 30060
h,w = map(int,input().split())
ss = []
ssc = []
for i in range(h):
    ss.append(list(input()))
    ssc.append([0]*w)

def hfunc1(i,j):
    if ss[i][j] != "#":
        ssc[i][j] += 1

def hfunc2(i,j):
    xs = -1
    xe = 2
    ys = -1
    ye = 2

    if i == 0:
        xs = 0
    if i == h-1:
        xe = 1
    if j == 0:
        ys = 0
    if j == w-1:
        ye = 1 

    for x in range(xs,xe):
        for y in range(ys,ye):
                hfunc1(i+x,j+y)
    
for i in range(h):
    for j in range(w):
        if ss[i][j] == "#":
            ssc[i][j] = "#"
            hfunc2(i,j)

ans = ""
for x in ssc:
    for y in x:
        ans += str(y)
    ans += "\n"
print(ans)

Measured memory_bytes: 3064
from collections import deque


def make_list(length, repeat):
    result = [[] for _ in range(length)]
    for _ in range(repeat):
        a, b = map(lambda x: int(x) - 1, input().split())
        result[a].append(b)
        result[b].append(a)
    return result


def main():
    n, m, k = map(int, input().split())
    friend = make_list(n, m)
    block = make_list(n, k)
    group_id = 1
    group = [0 for _ in range(n)]

    def dfs(start, group_id):
        q = deque([start])
        connection = 0
        if group[start] == 0:
            connection += 1
            while q:
                now = q.pop()
                group[now] = group_id
                for nn in friend[now]:
                    if group[nn] == 0:
                        group[nn] = group_id
                        q.append(nn)
                        connection += 1
        return connection

    count = {}
    for i in range(n):
        if group[i] == 0:
            count[group_id] = dfs(i, group_id)
            group_id += 1

    answer = [0 for _ in range(n)]
    for i in range(n):
        answer[i] = count[group[i]] - len(friend[i]) - 1
        for b in block[i]:
            if group[i] == group[b]:
                answer[i] -= 1
    print(" ".join(map(str, answer)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 52060
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, l;
int sum, minl = HINF<int>(), pos;
int main(){
	cin >> n >> l;
	for(int i = 1;i <= n;i++){
		int num = l + i - 1;
		sum += num;
		if(minl > abs(num)){
			minl = abs(num);
			pos = num;
		}
		
	}
	cout << sum - pos << endl;
}

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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,s2;
    s2 = s;
    cin >> s;
    char ch;
    int ct1=0,ct2=0;
    for(int i=0; i<s.length()-1; ++i){
        if(s[i] == s[i+1]){
            if(s[i] == '0') s[i+1] = '1';
            else s[i+1] = '0';
            ++ct1;
        }
    }
    for(int i=s.length()-1; i>=1; --i){
        if(s[i] == s[i-1])
            if(s[i] == '0') s[i-1] = '1';
            else s[i-1] = '0';
            ++ct2;
    }
    cout << min(ct1, ct2);
    return 0;
}


Measured memory_bytes: 512
package main

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

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, x, y := nextInt(), nextInt()-1, nextInt()-1

	// d := make([][]int, n)
	// for i := range d {
	// 	d[i] = make([]int, n)
	// }
	// for i := range d {
	// 	if i < n-1 {
	// 		d[i][i+1] = 1
	// 	}
	// 	for j := i + 2; j < n; j++ {
	// 		d[i][j] = 2 * n
	// 	}
	// }
	// d[x][y] = 1

	ans := map[int]int{}
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			// if i <= x && y <= j {
			// 	d[i][j] = min(d[i][j], d[i][j-1]+1, d[i][x]+1+d[y][j])
			// } else {
			// 	d[i][j] = min(d[i][j], d[i][j-1]+1)
			// }
			d := min(j-i, abs(x-i)+1+abs(y-j))
			ans[d]++
		}
		// puts(d[i])
	}

	for i := 1; i < n; i++ {
		puts(ans[i])
	}
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 896
#include <stdio.h>
#include<iostream>
using namespace std;
int main()
{
    int a[10000], b[10000],i;
    char c[10000];
    i = 1;
    while (1) {
        cin >> a[i] >> c[i] >> b[i];
        if (c[i] == '?' ) { break; }
        else if (c[i] == '+') { printf("%d\n", a[i] + b[i]); }
        else if (c[i] == '-') { printf("%d\n", a[i] - b[i]); }
        else if (c[i] == '*') { printf("%d\n", a[i] * b[i]); }
        else if (c[i] == '/') { printf("%d\n", a[i] / b[i]); }
       
        i++;
    }
    return 0;
}


Measured memory_bytes: 3236
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a, a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
void debug(ll* a, ll n) { for ( ll k = 0; k < n; k++ ){ cerr << a[k] << " ";} cout << "\n"; }
#define PI 3.14159265358979323846

int main(){
	FASTIO;
	ll n; cin >> n;
	string s; cin >> s;
	ll a[n]; for ( int k = 0; k < n; k++ ) if (s[k] == 'R') a[k] = 0; else if (s[k] == 'G') a[k] = 1; else a[k] = 2;
	ll suf[n + 1][3]; suf[n][0] = suf[n][1] = suf[n][2] = 0;
	for ( int k = n - 1; k >= 0; k--){
		suf[k][0] = suf[k + 1][0];
		suf[k][1] = suf[k + 1][1];
		suf[k][2] = suf[k + 1][2];
		suf[k][a[k]]++;
	}
	ll ans = 0;
	for ( int k = 0; k < n; k++ ){
		for ( int j = 0; j < 3; j++ ){
			//cout << suf[k][j] << " ";
		}
		//cout << endl;
	}
	for ( int i = 0; i < n; i++ ){
		for ( int j = i + 1; j < n; j++ ){
			if (a[j] != a[i]) {
				ll last = 3 - a[i] - a[j];
				//cout << j << "_" << last << " ";
				ll d = j - i;
				ans += suf[j + 1][last];
				if (j + d < n && a[j + d] == last)
					ans--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

  bool mmyy = false;
  bool yymm = false;

  if(S[0]=='0'&&S[1]!='0'){mmyy = true;}
  if(S[0]=='1'&&(S[1]=='0'||S[1]=='1'||S[1]=='2')){mmyy = true;}

  if(S[2]=='0'&&S[3]!='0'){yymm = true;}
  if(S[2]=='1'&&(S[3]=='0'||S[3]=='1'||S[3]=='2')){yymm = true;}

  if(yymm&&mmyy){cout << "AMBIGUOUS" << endl;}
  else if(yymm&&mmyy!=true){cout << "YYMM" << endl;}
  else if(mmyy&&yymm!=true){cout << "MMYY" << endl;}
  else if(mmyy==false&&yymm==false){cout << "NA" <<endl;}
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    string a,b; cin >> a >> b;
    string str = a+b;
    int num;
    num = stoi(str);
    int sq = sqrt(num);
    if(num == sq*sq){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

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

bool has_key_using_count(map<char, char> &m, char n){
    if (m.count(n) == 0){
        return false;
    }
    else{
        return true;
    }
}
void secToMin(int orgSec, int *sec, int *min) {
	*sec = orgSec % 60;
	*min = orgSec / 60;
}

int main()
{	
	//ifstream cin("sample.txt");

	int n = 0, t = 0, min = 0, sec = 0, sumSec = 0;
	
	// 秒数を全て足す
	while(cin >> t) {
		sumSec += t;
	}

	// 分・秒形式に直して出力
	secToMin(sumSec, &sec, &min);
	cout << min << endl;
	cout << sec << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
vector<pair<int, int>> seg;
int query(int node, int l, int r, int q_l, int q_r)
{
	if (q_l > r || q_r < l)
		return 0;
	if (seg[node].second != 0)
	{
		if (l == r)
		{
			seg[node].first = max(seg[node].first, seg[node].second);
			seg[node].second = 0;
		}
		else
		{
			seg[node].first = max(seg[node].first, seg[node].second);
			seg[node * 2].second = max(seg[node * 2].second, seg[node].second);
			seg[node * 2 + 1].second = max(seg[node * 2 + 1].second, seg[node].second);
			seg[node].second = 0;
		}
	}
	if (l >= q_l && r <= q_r)
		return seg[node].first;
	return max(query(node * 2, l, (l + r) / 2, q_l, q_r), query(node * 2 + 1, (l + r) / 2 + 1, r, q_l, q_r));
}
void update(int node, int l, int r, int q_l, int q_r, int val)
{
	if (q_l > r || q_r < l)
		return;
	if (seg[node].second != 0)
	{
		if (l == r)
		{
			seg[node].first = max(seg[node].first, seg[node].second);
			seg[node].second = 0;
		}
		else
		{
			seg[node].first = max(seg[node].first, seg[node].second);
			seg[node * 2].second = max(seg[node * 2].second, seg[node].second);
			seg[node * 2 + 1].second = max(seg[node * 2 + 1].second, seg[node].second);
			seg[node].second = 0;
		}
	}
	if (l >= q_l && r <= q_r)
	{
		seg[node].first = max(seg[node].first, val);
		if (l != r)
		{
			seg[node * 2].second = max(seg[node * 2].second, val);
			seg[node * 2 + 1].second = max(seg[node * 2 + 1].second, val);
			seg[node].second = 0;
		}
		return;
	}
	update(2 * node, l, (l + r) / 2, q_l, q_r, val);
	update(2 * node + 1, 1 + (l + r) / 2, r, q_l, q_r, val);
	seg[node].first = max(seg[node * 2].first, seg[node * 2 + 1].first);
	return;
}
void solve()
{
	int n, k;
	cin >> n >> k;
	int maxl = 300000 * 4 + 1;
	vector<int> arr(n);
	for (int c = 0; c < n; c++)
		cin >> arr[c];
	seg.assign(maxl, make_pair(0, 0));
	int ans = 1;
	update(1, 0, 300000, arr[0], arr[0], 1);
	for (int c = 1; c < n; c++)
	{
		int a = query(1, 0, 300000, max(0, arr[c] - k), min(300000, arr[c] + k));
		ans = max(ans, a + 1);
		update(1, 0, 300000, arr[c], arr[c], a + 1);
	}
	cout << ans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t;
	t = 1;
	for (; t > 0; t--)
		solve();
}


Measured memory_bytes: 13768
package main

import (
  "fmt"
  "container/list"
  )

type move struct {
  x, y int
}

func main() {
  h, w := 0, 0
  fmt.Scan(&h, &w)

  mapdata := [][]int{}
  wtcnt := 0
  line  := ""

  for i:=0; i < h; i++ {
    fmt.Scan(&line)
    xl := make([]int, w)
    for x, ch := range line {
      if ch=='#' {
        xl[x] = 1
      } else {
        wtcnt++
      }
    }
    mapdata = append(mapdata, xl)
  }

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

  queue := list.New()
  queue.PushBack(move{0, 0})
  mapdata[0][0]=1

  result := -1

  for queue.Len() > 0 {
    q := queue.Remove(queue.Front()).(move)
    if q.x==(w-1) && q.y==(h-1) {
      result = wtcnt - mapdata[h-1][w-1]
      break
    } else {
      for i:=0; i<4; i++ {
        nx := q.x + dx[i]
        ny := q.y + dy[i]
        if nx>=0 && nx<w && ny>=0 && ny<h && mapdata[ny][nx]==0 {
          queue.PushBack(move{nx, ny})
          mapdata[ny][nx] = mapdata[q.y][q.x] + 1
        }
      }
    }
  }

  fmt.Println(result)
}


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

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

    long int H[N];
    for(int i=0; i<N; i++) cin >> H[i];

    int i = 0;
    int flag = 0;
    while(flag == 0 && i < N){
        if(H[i+1] - H[i] >= 0){
            i++;
        }
        else{
            for(int j=i+1; j<N; j++){
                if(H[i] - H[j] >= 2){
                    cout << "No";
                    flag = 1;
                    break;
                }
            }
            i++;
        }
    }
    if(flag == 0) cout << "Yes";
}



Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a * n, b) << endl;
}

Measured memory_bytes: 256
#coding:utf-8
#カツサンドくん

n, m = map(int, input().split())
#各食べ物ごとの解答集計用
count = [0] * m

for i in range(n):
    enq = list(map(int, input().split()))
    for j in range(1, len(enq)):
        food = enq[j] - 1
        count[food] += 1

ans = 0
for item in count:
    if item == n:
        ans += 1

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>

bool flag[1001] = {};
int temp, x;

int main() {
	flag[1] = 1;
	for (int i = 2; i < 32; ++i) {
		temp = i*i;
		while(temp <= 1000) {
			flag[temp] = 1;
			temp = temp * i;
		}
	}
	scanf("%d", &x);
	while(!flag[x]) x--;
	printf("%d", x);
	return 0;
}

Measured memory_bytes: 128