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

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

long long MOD = 1000000000 + 7;

ll pow2mod(ll x, ll y){
  // 2^x を yで割ったあまり
  ll ret = 0;

  if(y == 0) return 0;
  if(y == 1) return 0;
  if(x == 0) return 1;
  if(x == 1) return 2%y;

  if(x%2 == 0) {
    ret = pow2mod(x/2, y);
    return (ret*ret)%y;
  } 
  if(x%2 == 1){
    ret = pow2mod(x-1, y) * 2;
    return ret%y;
  }
  return 0;
}

map<ll, int> m;

int solve(int x, int num){
  if(x==0) return num;
  if(x==1) return (num+1);
  ll p =  __builtin_popcount(x);

  if(p==0){
    return num;
  }

  if(x%p == 0){
    return (num+1);
  } else { 
    return solve(x%p, num+1);
  }
}

int main(){
  cout << setprecision(10);

  int N; cin >> N;
  string X; cin >> X;

  ll y = 0;
  for(char c: X){
    if(c=='1') y++;
  }

  // X % (y+1)と、X%(y-1)を調べておく

  int modyp1 = 0; 
  int modym1 = 0; 
  for(int i = 0; i < N; i++){
    if(X[i] == '0') continue;

    modyp1 += pow2mod( N-i-1, y+1);
    modyp1 %= (y+1);
    modym1 += pow2mod( N-i-1, y-1);
    if(y-1==0){
      modym1 = 0;
    } else { 
      modym1 %= y-1;
    }
  }

  cerr << modyp1 << " " << modym1 << endl;

  for(int i = 0; i < N; i++){
    int j = N - i - 1;
    if(X[i] == '0'){
      int tmp = modyp1; // X%(y+1)
      tmp += pow2mod(j, y+1); // y+1でわったあまりが得られた
      tmp %= (y+1);
      // cerr << "i: " << i << " tmp: " << tmp  << " y+1: " << y+1 << endl;
      cout << solve(tmp, 1) << endl;
    } else { 
      int tmp = modym1; // X%(y-1)
      tmp -= pow2mod(j, y-1); // y-1でわったあまりが得られた
      tmp += y-1;
      if(y-1==0){
        cout << 0 << endl;
      } else {
        tmp %= (y-1);
        // cerr << "i: " << i << " tmp: " << tmp  << " y-1: " << y-1 << endl;
        cout << solve(tmp, 1) << endl;
      }
    }
  }

}


Measured memory_bytes: 3724
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace
trace _ = id

solve :: Int -> [Int] -> Int
solve n as = answer
  where
  va = VU.fromListN n as 
  posLst :: VU.Vector Int
  posLst = trace ("posLst " ++ show posLst0) posLst0
  posLst0 = VU.reverse $ costLst n $ VU.reverse va
  negLst :: VU.Vector Int
  negLst = trace ("negLst " ++ show negLst0) negLst0
  negLst0 = costLst n va
  answer = VU.minimum $ VU.izipWith f posLst negLst
    where f i pos neg = 2 * (pos + neg) + i

costLst :: Int -> VU.Vector Int -> VU.Vector Int
costLst n xs = VU.scanl' (+) 0 eVec
  where
    initAcc :: (Int, [(Int, Int)])
    initAcc = (0, [(0, big)])
    f :: (Int, [(Int,Int)]) -> Maybe (Int, (Int, [(Int,Int)]))
    f (i, steps@((len, gap):rem))
      | i == n = Nothing
      | 4 * x <= xNext = Just (0, (i+1, (1, costF xNext x):steps))
      | x <= xNext = Just (0, (i+1, (len+1, gap):rem))
      | otherwise = Just (c, (i+1, newSteps))
      where
        x = xs VU.! i
        xNext | i == 0    = big
              | otherwise = xs VU.! (i-1)
        (newSteps, c) = g (costC x xNext) 0 1 steps
        g :: Int -> Int -> Int -> [(Int,Int)] -> ([(Int,Int)], Int)
        g h cost len step = trace ("g " ++ show (h,cost,len,step,a)) a
          where a = g0 h cost len step
        g0 !h !cost !len ((tLen,gap):rem)
          | h <= gap = ((newLen, gap-h):rem, newCost)
          | otherwise = g (h-gap) newCost newLen rem
          where newCost = cost + h*tLen
                newLen = len + tLen
    eVec = trace ("eVec " ++ show eVec0) eVec0
    eVec0 = VU.unfoldrN n f initAcc

big = 10 ^ 10

epsilon = 2 ** (-64)

log4 :: Int -> Double
log4 x = logBase 4 (fromIntegral x)

costC x y = ceiling (log4 x - log4 y - epsilon)
costF x y = floor (log4 x - log4 y + epsilon)

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
      line2:remLines2 = remLines1
      as = map readBInt line2
  in solve n as

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 13180
#include <stdio.h>
#include <math.h>

int main(void){
  int x,h;
  double S;
  while(scanf("%d",&x)!=EOF){
    scanf("%d",&h);
    if(x==0&&h==0)  break;
    else{
      S=(double)x*((double)x+sqrt(4*h*h+x*x));
      printf("%.6f\n",S);
    }
  }
  return 0;
}

Measured memory_bytes: 636
import itertools
import math

def main():
    N = int(input())
    XY = []
    for i in range(N):
        x, y = list(map(int, input().split()))
        XY.append([x, y])
    
    CITY = [i for i in range(N)]
    # print(CITY)
    p = list(itertools.permutations(CITY, N))
    # print(p)

    ds = []
    for pi in p:
        dist = 0
        for i in range(N-1):
            cs = pi[i]
            ns = pi[i+1]

            x1 = XY[cs][0]
            y1 = XY[cs][1]
            x2 = XY[ns][0]
            y2 = XY[ns][1]
            d = math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
            dist += d
        ds.append(dist)
    ans = sum(ds) / len(ds)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9252
#include<stdio.h>
#include<math.h>

int main(){
	int i,j,a[4],b[4];
	int hit,blow;
	while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])!=EOF){
		scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);
		hit=blow=0;
		for(i=0;i<4;i++){
			for(j=0;j<4;j++){
				if(a[i]==b[j]) blow++;
			}
		}
		for(i=0;i<4;i++){
			if(a[i]==b[i]){
				hit++;
				blow--;
			}
		}
		printf("%d %d\n",hit,blow);
	}
	return 0;
}

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

using namespace std;

int main(){
  int a, b, c, k;
	cin >> a >> b >> c >> k;
	if(a < b) swap(a, b);
	if(a < c) swap(a, c);
	if(a < b) swap(a, b);
	cout <<a * (1<<k) + b + c << endl;
	return 0;
}


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

int main(){
    long long A; cin >> A;
    long long V; cin >> V;
    long long B; cin >> B;
    long long W; cin >> W;
    long long T; cin >> T;

    if(V <= W){
        cout << "NO" << endl;
        exit(0);
    }
    else if(A < B){
        if(A + V*T >= B + W*T){
            cout << "YES" << endl;
            exit(0);
        }
    }
    else{
        if(A - V*T <= B - W*T){
            cout << "YES" << endl;
            exit(0);
        }
    }

    cout << "NO" << endl;

    return 0;
}

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

using namespace std;

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

int main(void) {
  int x, y;
  cin >> x >> y;

  int g = gcd(x, y);
  cout << (x / g + y / g) * g - (g - 1) << endl;

  return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
int N;
#define N 8
#define FREE -1
#define NOT_FREE 1
void ini();
void putQueen(int);
void printBoard();
int row[N],col[N],dpos[2*N-1],dneg[2*N-1],X[N][N];

int main(){
  ini();
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      X[i][j]=-1;
    }
  }
  int n,c,k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&c,&k);
    X[c][k]=1;
  }
  putQueen(0);
  return 0;
}
void putQueen(int i){
  int j;
  if(i==N){
    printBoard();
    return ;
  }
  for(j=0;j<N;j++){
    if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE)continue;
  row[i]=j;
  col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
  putQueen(i+1);
  col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}
void ini(){
  int i;
  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
  }
  for(i=0;i<N*2-1;i++){
    dpos[i]=FREE;
    dneg[i]=FREE;
    
  }
}
void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]==1){
	if(row[i]!=j)return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j){
	printf("Q");
      }else{
	printf(".");
      }
    }
    printf("\n");
  }
}



Measured memory_bytes: 2104
#include <stdio.h>
int main(void){
	int L, R, min = 2018, l, r;
    scanf("%d %d", &L, &R);
  	l = L % 2019;
  	r = R % 2019;
  	if(R - L >= 2019){
      printf("0\n");
      return 0;
    }
  	if(l > r) {
      l = R % 2019;
      r = L % 2019;
    }
    for(int i = l; i < r; i++){
    	for(int j = i + 1; j <= r; j++){
        	if((i * j) % 2019 < min) min = (i * j) % 2019;
        }
    }
    printf("%d", min);
    return 0;
}
          
    

Measured memory_bytes: 128
#include<iostream>
using namespace std;
static const int  N = 100;

int main()
{
    int M[N][N];  // オリジンの隣接行列
    int n, u, k, v;

    cin >> n;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }

    // 頂点iが頂点jへのパスが存在するということ
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;  // 0オリジンへの変換
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;  // 0オリジンへの変換
            M[u][v] = 1;  // uとvの間に辺を張る
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j) {
                cout << " ";
            }
            cout << M[i][j];
        }
        cout << endl;
    }

    return 0;
}


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

int main(){
  int A,B;
  string S;
  cin >> A >> B >> S;

  string code= S.substr(0,A)+ S.substr(A+1);

  bool is_punctuated= S.at(A)=='-';
  bool is_numbered= true;
  for(auto c:code){
    if(!isdigit(c)){
      is_numbered= false;
      break;
    }
  }

  string ans= (is_punctuated && is_numbered) ? "Yes"
                                             : "No";
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
ListH = list(map(int,input().split()))
result = 0
for i in range(N):
    out = False
    for k in range(i):
        if k >= 0:
            if ListH[k] > ListH[i]:
                out = True
    if not out :
        result += 1
print(result)

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

using namespace std;

int main()
{
  string s;
  cin >> s;
  
  int price = 700;
  if (s[0] == 'o') price += 100;
  if (s[1] == 'o') price += 100;
  if (s[2] == 'o') price += 100;
  
  printf("%d\n", price);
 
  return 0;
}

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

typedef long long ll;

template<typename T>
set<T> div_count(T x) {
  set<T> st;
  for (int i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      st.insert(i);
      st.insert(x/i);
    }
  }
  return st;
}

int main() {
  int n;
  cin >> n;
  ll ans = 0;  
  for (int i = 1; i <= n; ++i) {
    set<int> s = div_count(i);
    if (s.size() == 8 and i % 2 == 1) ans += 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    string s;
    cin >> s;
    int q;
    cin >> q;
    int flipped = 0;
    vec<char> front, back, hontai;
    rep(i, s.size()) hontai.push_back(s[i]);
    rep(i, q) {
        int type;
        cin >> type;
        if (type==1) {
            flipped++;
        } else if (type==2) {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1 && flipped %2 == 0 || f == 2 && flipped %2 == 1 ) front.push_back(c);
            else back.push_back(c);
        }
    }
    if (flipped %2 == 0) {
        reverse(front.begin(), front.end());
        for(auto c : front) cout << c;
        cout << s;
        for(auto c : back) cout << c;
        cout << endl;
    } else {
        reverse(back.begin(), back.end());
        reverse(hontai.begin(), hontai.end());
        for(auto c : back) cout << c;
        for(auto c : hontai) cout << c;
        for(auto c : front) cout << c;
        cout << endl;
    }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<double> VD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1000 * 1000 * 1000 + 7;

inline int add(int x, int y)
{
	if (x + y < mod)
		return x + y;
	return x + y - mod;
}

inline int mult(int x, int y)
{
	return x * (LL) y % mod;
}

const int N = 1 << 11;
int n, k;
int a[N];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("In.txt", "w", stdout);
	
	cin >> n >> k;
	FOR(i, 0, n)
		cin >> a[i];
	
	int ans = 0;
	int cnt = 0;
	FOR(i, 0, n)
		FOR(j, i + 1, n)
			if (a[i] > a[j])
				++cnt;
	
	ans = mult(cnt, k);
	
	int val = k * (LL) (k - 1) / 2 % mod;
	FOR(i, 0, n)
	{
		int tut = 0;
		FOR(j, 0, n)
			tut += a[i] > a[j];
		
		ans = add(ans, mult(tut, val));
	}	
	
	cout << ans << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


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

int main() {
    string S, T; cin>>S>>T;
    int mn = 100000;
    for (int i=0; i<S.length() - T.length() + 1; i++) {
        int hamd = 0;
        for (int j=0; j<T.length(); j++) {
            if (S.at(i+j) != T.at(j)) hamd++;
        }
        mn = min(hamd, mn);
    }
    cout<<mn;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define MAX 300005
int n,m;
char s[MAX],q[100];
ll B=1000000007LL;

ll t[MAX];
ll po[MAX];

ll calc(ll L,ll R){
  ll a=t[L-1];
  ll b=t[R];
  ll c=R-L+1;
  return b-a*po[c];
}

int main(){
  po[0]=1;
  for(int i=1;i<MAX;i++)po[i]=po[i-1]*B;
  
  cin>>n>>m;
  scanf("%s",s);

  for(int i=1;i<=n;i++)t[i]=t[i-1]*B+s[i-1];
  int L=1,R=1;

  set<ll> T;
  for(int i=0;i<m;i++){
    scanf("%s",q);
    if(q[0]=='L'&&q[1]=='+'){
      L++;
    }else if(q[0]=='L'&&q[1]=='-'){
      L--;
    }else if(q[0]=='R'&&q[1]=='+'){
      R++;
    }else{
      R--;
    }
    T.insert(calc(L,R));
  }
  cout<<T.size()<<endl;
  return 0;
}

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

#define fori( tt,aa)      for(long long i= tt; i<aa; i++)
#define forj( yy,bb)      for(long long j=yy; j<bb; j++)
#define fork( uu,cc)      for(long long k=uu; k<cc; k++)
#define sz(v)    v.size()
#define all(v)   v.begin(), v.end()
#define endl "\n";
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define EPS 1e-7
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE; fast();

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef string String;
typedef string str;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef pair<int, int> pii;

void fast(){
    cin.tie(0);
    cout.tie(0);
    cin.sync_with_stdio(0);
}

ld pow (ll a, ll b);
ll numOfDigits(ll n);
ll BN (ll arr[], ll j, ll val);
ll n, d, p1, p2, p3, cnt;
int main()
{

    THINK_TWICE_CODE_ONCE;
    //freopen("test cases\\Points on Line.txt", "r", stdin);
    int a, b, c; cin>>a>>b>>c;
    if((c<a && c> b) || (c>a && c<b))cout<<"Yes";
    else cout<<"No";
    return 0;
}
ld pow (ll a, ll b){
    ld pow = 1;
    fori(0,b)
        pow *=a;
    return pow;
}
/*
ll BN (ll arr[], ll j, ll val){
int low = j;
int up = n-1;
ll ans = -1;
while(low<=up){
    ll mid = ((ll)low+ up)/2;
    if(abs(arr[mid]-val)<=d){
        ans = mid;
        low = mid+1;
    }else up = mid-1;
}
return ans;
}*/

ll numOfDigits(ll n){
    if(!n) return 1;
    return (ll)(log10(n)+1);
}


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


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
string s;
vector < int > v;
vector < pair < int, int > > ans;
int n, mx, ls = 1, sz = 1;

int main () {
	cin >> s;
	n = sz(s);
	if (s[n - 1] == '1' || s[0] == '0') {
	    cout << "-1";
	    exit(0);
	}
	
	For (i, 0, n - 2) {
	    int rev = n - 2 - i;
	    if (s[i] != s[rev]) {
	        cout << "-1";
	        exit(0);
	    }
	}
	
	For (i, 2, n) {
	    v.pb(i);
	}
	reverse(every(v));
	
	For (i, 1, n - 2) {
	    if (s[i] == '1') {
	        if (!mx) mx = i;
	        int last = ls;
	        while (sz <= i + 1) {
	            ans.pb(mp(ls, v.back()));
	            last = v.back();
	            v.pop_back();
	            sz ++;
	             
	        }
	        ls = last;
	    }
	}
	
	for (auto it : ans) {
	    cout << it.F << ' ' << it.S << '\n';
	}
}

Measured memory_bytes: 2868
#include <bits/stdc++.h>
using namespace std;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define INF 100000000
typedef long long ll;

int main(){
    ll A,B,C;
    cin>>A>>B>>C;
    cout<<(A*B)/2<<endl;
    return 0;
}

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

using namespace std;

int main(){
    string T; cin >> T;
    vector<int> s;
    vector<int> pos;
    int ones = 0;
    for(int i=0;i<T.size();i++){
        if(T[i] == '0'){
            if(ones > 0 && ones%2 == 1){
                s.push_back(i);
            } else {
                pos.push_back(i);
            }
            ones = 0;
        } else {
            s.push_back(i);
            ++ones;
        }
    }
    int turn = s.size();
    long long res = 0;
    while(!pos.empty()){
        int b = pos.back(); pos.pop_back();
        int idx = s.size() - 1;
        while(idx >= 0 && b < s[idx]){
            int p = s[idx];
            int v = T[p] - '0';
            if(idx%2 == 0) res += v * (turn - idx);
            res += (T.size() - turn + idx%2) / 2 * v;
            s.pop_back();
            --idx;
        }
        ++turn;
    }
    for(int i=0;i<s.size();i+=2){
        res += (T.size()-i) * (T[i]-'0');
    }
    cout << res << endl;
}

Measured memory_bytes: 4856
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))

A,B,Q=rl()
s=[0]*(A+2)
t=[0]*(B+2)
X=[0]*Q
for i in range(1,A+1):
    s[i]=ri()
s[0],s[A+1]=-float('inf'),float('inf')
s.sort()
for i in range(1,B+1):
    t[i]=ri()
t[0],t[B+1]=-float('inf'),float('inf')
t.sort()
for i in range(Q):
    X[i]=ri()

import bisect
for x in X:
    s_i = bisect.bisect_left(s,x)
    t_i = bisect.bisect_left(t,x)
    s_l = x-s[s_i-1]
    s_r = s[s_i]-x
    t_l = x-t[t_i-1]
    t_r = t[t_i]-x
    ans = min(
        [max(s_l,t_l), s_l+t_r+min(s_l,t_r), s_r+t_l+min(s_r,t_l), max(s_r,t_r)]
    )
    print(ans)

Measured memory_bytes: 117336
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

char s[200123];
int x[200123], y[200123];

int main()
{
	int n, k, c;
	cin >> n >> k >> c >> s+1;
	int cur = 1, cnt = 0;
	while(cnt < k) {
		if(s[cur] == 'o') x[++cnt] = cur, cur += c;
		++cur;
	}
	cur = n, cnt = k;
	while(cnt) {
		if(s[cur] == 'o') y[cnt--] = cur, cur -= c;
		--cur;
	}
	Rep(i, k) if(x[i] == y[i]) cout << x[i] << '\n';
	return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define int long long int
#define MOD 1000000007
using namespace std;
void solve() {
        int n;
        string s;
        cin >> n >> s;
        if(n >= 3200)
                cout << s << endl;
        else
                cout << "red" << endl;

        return ;
}

int32_t main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        solve();
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  ll N,K;
  cin>>N>>K;
  string D[K];
  ll ans=100000;
  FOR(i,0,K-1){
    cin>>D[i];
  }


  FOR(i,N,100000){
    int flag=0;
    string tmp = to_string(i);


    FOR(j,0,K-1){
      if(tmp.find(D[j])!=string::npos){
        flag=1;

      }
    }
    if(flag==0){
      ans=min(ans,i);
    }
  }


  cout<<ans<<endl;



  return 0;
}
 


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

int main(){
  int H,W;
  cin >> H >> W;
  
  vector<vector<char>> vec(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> vec.at(i).at(j);
    }
  }

  bool ans = true;
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (vec.at(i).at(j)=='#'){
        int count=0;
        if(i-1>=0 && vec.at(i-1).at(j)=='#') count+=1;
        if(i+1<H && vec.at(i+1).at(j)=='#') count+=1;
        if(j-1>=0 && vec.at(i).at(j-1)=='#') count+=1;
        if(j+1<W && vec.at(i).at(j+1)=='#') count+=1;
        if(count==0){
          ans=false;
          break;
        }
      }
    }
    if (ans==false) break;
  }
  
  if (ans) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int N = 2e5 + 5;
int n;
int a , b;
vector < int > v[N];
double sub[N];
double ans[N];
void dfs1(int node , int parent){
	sub[node] = 0;
	int child = 0;
	for(int next : v[node]){
		if(next != parent){
			dfs1(next , node);
			++child;
			sub[node] += sub[next] + 1;
		}
	}
	if(child){
		sub[node] /= child;
	}
}
void dfs2(int node , int parent , double val){
	if(parent){
		ans[node] = (sub[node] * (v[node].size() - 1) + (val + 1)) / v[node].size(); 
	}
	else{
		ans[node] = sub[node];
	}
	for(int next : v[node]){
		if(next != parent){
			if(v[node].size() == 1){
				dfs2(next , node , 0);
			}
			else{
				dfs2(next , node , (ans[node] * v[node].size() - sub[next] - 1) / (v[node].size() - 1));
			}
		}
	}
}
int main(){
	scanf("%d" , &n);
	for(int i = 1 ; i < n ; ++i){
		scanf("%d %d" , &a , &b);
		v[a].emplace_back(b);
		v[b].emplace_back(a);
	}
	dfs1(1 , 0);
	dfs2(1 , 0 , 0);
	for(int i = 1 ; i <= n ; ++i){
		printf("%.9lf\n" , ans[i]);
	}
}

Measured memory_bytes: 19968
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 52;
ll i,j,k,n;
ll a[N], b[N];
bool p;
bool perm(ll x[N]){
    for(ll i = 1;i <= n;i += 1) if(x[i] != i) return 0;
    return 1;
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,1,n + 1) cin>>a[i];
    p = perm(a);
    if(!p){
        for(i = 1;i <= n && !p;i += 1) for(j = i + 1;j <= n && !p;j += 1){
            rep(k,1,n + 1) b[k] = a[k];
            swap(b[i], b[j]);
            p = perm(b);
        }
    }
    cout<<(p ? "YES" : "NO");
    return 0;
}

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

string s[110],t[110];

int main() {
  int N,M;
  cin >> N;
  for(int i=0;i<N;i++) cin >> s[i];
  cin >> M;
  for(int i=0;i<M;i++) cin >> t[i];
  int ans = 0;
  
    for(int i=0;i<N;i++){
  	int score = 0;
    for(int j=0;j<N;j++) if(s[j]==s[i])score++;
    for(int j=0;j<M;j++) if(t[j]==s[i])score--;
    ans = max(ans,score);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
typedef long long int lli;

#define all(arr) arr.begin(),arr.end()
#define f first
#define s second
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define nl cout<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cout<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define MOD 1000000007

template <typename T>
void input(vector<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.push_back(temp);
}

template <typename T>
void output(vector<T> arr) {
  for(auto x:arr) cout<<x<<" ";
  cout<<endl;
}


template <typename T>
void input_set(set<T> &arr,lli n) {
  T temp;
  for(lli i=0;i<n;i++) cin>>temp, arr.insert(temp);
}

lli mul(lli a, lli b) {
  return (a%MOD*b%MOD)%MOD;
}

lli power(lli num,lli base) {
  lli ans = 1;
  while(base>0) {
    if(base&1)
      ans = mul(ans, num);

    num = mul(num, num);
    base >>= 1;
  }

  return ans;
}

void solve() {
  lli n;
  cin >> n;
  vector<lli> a(n);
  vector<lli> b(n);
  for(int i=0; i<n; i++) {
    lli x, y;
    cin >> x >> y;
    a[i] = x;
    b[i] = y;
  }

  sort(all(a));
  sort(all(b));
  if(n%2!=0) {
    cout << b[n/2] - a[n/2] +1<< endl;
  } else {
    lli x = n/2 - 1, y = n/2;
    cout << b[y] - a[y] + 1 + b[x] - a[x] << endl; 
  }
}

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

  lli testcases=1;
  while(testcases--) {
    solve();
  }
}



Measured memory_bytes: 6368
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string.h>

using namespace std;

const double PI = 3.14159265358979;

struct Node {
	int parent = -1;
	int left = -2, right = -3;
	int depth = 0;
};

void setDepth(Node *tree, int id, int deep) {

	tree[id].depth = deep;

	if (tree[id].right >= 0)
		setDepth(tree, tree[id].right, deep);
	if (tree[id].left >= 0)
		setDepth(tree, tree[id].left, deep + 1);
}

void printChildren(Node *tree, int id) {

	printf("[");
	
	bool first = true;
	while (id >= 0) {
		if (first) {
			printf("%d", id);
			first = false;
		}
		else {
			printf(", %d", id);
		}
		id = tree[id].right;
	}
	printf("]\n");
}

int main() {

	int n; cin >> n;

	Node* tree = new Node[n];

	int root = -1;
	for (int i = 0; i < n; i++) {
		int id, k; scanf("%d%d", &id, &k);
		if (k > 0) {
			int c1; scanf("%d", &c1);
			tree[id].left = c1;
			tree[c1].parent = id;
			for (int j = 1; j < k; j++) {
				int c2; scanf("%d", &c2);
				tree[c1].parent = id;
				tree[c1].right = c2;
				c1 = c2;
			}
			tree[c1].parent = id;
		}
	}
	for (int i = 0; i < n; i++) {
		if (tree[i].parent == -1) {
			root = i;
			break;
		}
	}

	setDepth(tree, root, 0);

	for (int i = 0; i < n; i++)	{
		char type[20];	// 0 root   1 internal node   2 leaf
		if (tree[i].parent == -1) {
			strcpy(type, "root");
		}
		else if (tree[i].left < 0) {
			strcpy(type, "leaf");
		}
		else {
			strcpy(type, "internal node");
		}
		Node node = tree[i];
		printf("node %d: parent = %d, depth = %d, %s, ", i, node.parent, node.depth, type);
		
		printChildren(tree, node.left);
		
	}

	return 0;
}



Measured memory_bytes: 7908
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){
    int a;
    cin>>a;
    int b=a/1000*1000+1000;
    if(b-a==1000) cout<<"0";
    else cout<<b-a;
}

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

int main()
{
	long long a, b; cin >> a >> b;
	long long ans;
	
	for (long long i = 1; i <= b; i++) {

		if ((a*i) % b == 0) {
			ans = a*i;
			break;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i64 = read();
    let x: i64 = read();
    let y: i64 = read();
    let mut ans: Vec<i64> = (1..n).map(|_| 0).collect();
    for i in 1..n+1 {
        for j in i+1..n+1 {
            let mut min = j - i;
            let mut tmp = (x-i).abs() + 1 + (j-y).abs();
            if tmp < min {
                min = tmp;
            }
            tmp = (y-i).abs() + 1 + (j-x).abs();
            if tmp < min {
                min = tmp;
            }
            //println!("{} {} {}", i, j, min);
            ans[min as usize - 1] += 1;
        }
    }

    for a in ans {
        println!("{}", a);
    }
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
int n;
vector<vector<ll>> mult(vector<vector<ll>>& m1,vector<vector<ll>>& m2){
  vector<vector<ll>> m(n,vector<ll>(n));
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      for(int k = 0; k < n; ++k){
        m[i][j] = (m[i][j]+m1[i][k]*m2[k][j])%mod;
      }
    }
  }
  return m;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll k;
  cin >> n >> k;
  vector<vector<ll>> a(n,vector<ll>(n));
  vector<vector<ll>> m(n,vector<ll>(n));
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j) cin >> a[i][j];
    m[i][i] = 1;
  }
  while(k > 0){
    if(k&1) m = mult(m,a);
    a = mult(a,a);
    k >>= 1;
  }
  ll ans = 0;
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j) ans = (ans+m[i][j])%mod;
  }
  cout << ans;
  return 0;
}

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

int main(){
    int n,x;
    cin>>n>>x;
    int cnt=1;
    int lc=0;
    rep(i,n){
        int l;
        cin>>l;
        lc+=l;
        if(lc<=x) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<string>in(n);
  rep(i,n)cin>>in[i];
  rep(i,n)rep(j,m)in[i][j]-='0';
  int dp[51][51];
  rep(i,51)rep(j,51)dp[i][j]=1000000;
  dp[1][0]=0;
  rep(i,n)rep(j,m){
    dp[i+1][j+1]=min(dp[i][j+1],dp[i+1][j])+in[i][j];
    //cout<<dp[i+1][j+1]<<endl;
  }
  cout<<dp[n][m]<<endl;

}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,K,MOD=1e9+7; cin>>N>>K;
  vector<ll> S(N+1,0);
  for(int i=1; i<=N; i++) S[i]=i;  
  for(int i=1; i<=N; i++) (S[i]=S[i-1]+S[i])%=MOD;
  ll ans=0;
  for(ll i=K-1; i<=N; i++){
    (ans=ans+(S[N]-S[max(0LL,N-i-1)])-S[i]+1)%=MOD;
//    cout<<"i:"<<i<<" ans:"<<ans<<endl;
  }
  if(ans<0)
    ans+=MOD;
  cout<<ans<<endl;
}

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

int main() {
    int n, m, x; cin >> n >> m >> x;
    vector<int> a(m);
    int cost = 0;
    for (auto& e : a) {
        cin >> e;
        if (x > e) cost++;
    }
    cout << min(cost, m-cost) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  int A, B, C;
  cin >> A >> B >> C;

  if( ((A == B) && (A != C)) ||
      ((A == C) && (A != B)) ||
      ((B == C) && (A != B))){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }

  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.Vector;
 
public class Main {
	
	public static void main(String[] args) {
		Scanner ob=new Scanner(System.in);
		int n=ob.nextInt();
		String s="";
		for (int i=0; i<n; i++) {
			char c1=ob.next().charAt(0);
			s=s+c1;
			char c2=ob.next().charAt(0);
			s=s+c2;
		}
		for(int i=0;i<=s.length()-6;i+=2)
		{
		if((s.charAt(i)==s.charAt(i+1))&&(s.charAt(i+2)==s.charAt(i+3))&&(s.charAt(i+4)==s.charAt(i+5)))
		{System.out.println("Yes");System.exit(0);}
		}
		System.out.println("No");
	}
}

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

int get_index(char c)
{
  if (c >= 'A' && c <= 'Z')
  {
    return c - 'A';
  }
  else if (c >= 'a' && c <= 'z')
  {
    return c - 'a';
  }
  return 26;
}

int main()
{
  vector<int> A(27, 0);
  char c;
  while ((c = getchar()) != EOF)
  {
    A.at(get_index(c))++;
  }

  for (int i = 0; i < 26; i++)
  {
    printf("%c : %d\n", 'a' + i, A.at(i));
  }
}


Measured memory_bytes: 3204
n=gets.to_i
m1=0
m2=0
a=[]
n.times do |i|
  a[i]=gets.to_i
  if a[i]>m1 then
    m2=m1
    m1=a[i]
  elsif a[i]>m2
    m2=a[i]
  end
end
n.times do |i|
  p (a[i]==m1)? m2:m1
end  


Measured memory_bytes: 5832
n = int(input())
a = list(map(int, input().split()))
node = [0 for i in range(n+1)]
if n == 0:
    if a[0] != 1:
        print(-1)
        exit()
    else:
        print(1)
        exit()
if a[0] != 0:
    print(-1)
    exit()
node[0] = 1
count = 1
for i in range(1,n+1):
    count = min(count * 2, 10**18)
    if a[i] > count:
        print(-1)
        exit()
    node[i] = node[i-1] - a[i-1]
    node[i] *= 2
if node[-1] < a[-1]:
    print(-1)
    exit()
node[-1] = a[-1]
for i in range(n-1, -1, -1):
    if a[i] > node[i]:
        print(-1)
        exit()
    node[i] = min(node[i], node[i+1] + a[i])
print(sum(node))


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

// Optimization

//#pragma GCC optimize("O3")
#define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl;
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl;
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 1e5 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e18 + 7;
const ll infll = 1e18 + 7;

int n, k;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    int t = n / k;
    int ans = (t * t * t);
    if (k % 2 == 0){
        n += k / 2;
        t = n / k;
        ans += t * t * t;
    }
    cout << ans;
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 256
// @author :: Amirul Islam 

#include <bits/stdc++.h>
using namespace std;
#define LLI long long int

const int mx = 1e5;
const double pi = acos(-1.0);

string makeLower(string s) {
    for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]);
    return s;
}

int main() {
    // freopen("in", "r", stdin);
    
    string x, y;
    cin >> x;
    x = makeLower(x);
    int cnt = 0;
    while (cin >> y && y != "END_OF_TEXT") {
        y = makeLower(y);
        if (x == y) cnt++;
    }
    cout << cnt << endl;
}


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

int main()
{
  	int n;
	cin >> n;
  
  	int ac = 0;
  	int wa = 0;
  	int tle = 0;
   	int re = 0;
  
  	for (int i=0; i<n; ++i) {
      string s;
      cin >> s;
      if ( s == "AC" ) {
        ++ac;
      }
      else if (s == "WA"){
        ++wa;
      }
      else if (s == "TLE") {
        ++ tle;
      }
      else if (s == "RE" ) {
        ++ re;
      }
    }
  
  	cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re ;
  	
  
    return 0;
}

Measured memory_bytes: 3628
n=int(input())
def soinsu(n):
    arr = []
    now = n
    for i in range(2, -int(-n**0.5)+1):
        if now%i==0:
            cnt=0
            while now%i==0:
                cnt+=1
                now //= i
            arr.append([i, cnt])
    if now>1:
        arr.append([now,1])
    return arr

soi = soinsu(n)
cand=[ s[1] for s in soi]

aida = [(i)*(i+1)//2 for i in range(1,45)]
import bisect

print(sum(bisect.bisect(aida,c) for c in cand) )

Measured memory_bytes: 63544
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
typedef long long LL;

int main()
{
	map <char, int> mp;
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		char c;
		cin >> c;
		mp[c] = 1;
	}
	int si = mp.size();
	if(si == 1) cout << "One" << endl;
	else if(si == 2) cout << "Two" << endl;
	else if(si == 3) cout << "Three" << endl;
	else if(si == 4) cout << "Four" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args){
		Scanner sc= new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[] y= new int[m];
		
		int ans=0;
		
		if(n>=m){
			System.out.println(ans);
			System.exit(0);
		}
		
		/*if(m==2){
			if(n==1)ans=Math.abs(y[1]-y[0]);
			System.out.println(ans);
			System.exit(0);
		}*/
		
		for(int i=0;i<m;i++){
			y[i]=sc.nextInt();
		}
		Arrays.sort(y);
		
		int[] x= new int [m-1];
		
				
		for(int i=0;i<m-1;i++){
			x[i]=y[i+1]-y[i];
			ans=ans+x[i];
		}
		
		Arrays.sort(x);
		

		
		
		for(int i=0; i<n-1;i++){
			ans=ans-x[m-i-2];
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 47964
import itertools
n = int(input())
p = list(map(int,input().split()))

memo = 0
mode = 1
for k in range(n):
	if memo > p[k]:
		mode = 0
		break
	memo = p[k]
if mode:
	print("YES")
	exit()

for i,j in itertools.combinations(range(n), 2):
	memo = 0
	mode = 1
	for k in range(n):
		if k == i:
			k = j
		elif k == j:
			k = i
		if memo > p[k]:
			mode = 0
			break
		memo = p[k]
	if mode:
		print("YES")
		exit()
print("NO")

Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k;
	cin>>n>>k;
	ll cnt=(n-1)*(n-2)/2;
	if(cnt<k){
		cout << -1;
		return 0;
	}
	cnt=cnt-k;
//	cout <<cnt<<endl;
	cout << n-1+cnt<<endl;
	for(ll i=0;i<n-1;i++){
		cout << 1<<" "<<i+2<<endl;
	}
	for(ll i=2;i<=n;i++){
		for(ll j=i+1;j<=n;j++){
			if(cnt==0){
				return 0;
			}
			cout << i<<" "<<j<<endl;
			cnt--;
		//	cout <<cnt<<endl;
		}
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){

    int N,M,R;cin>>N>>M>>R;
    int r[R];REP(i,R)cin>>r[i];
    REP(i,R)--r[i];

    LL dis[N][N];
    fill(dis[0],dis[N],LONG_MAX/10);
    REP(i,M){
        int a,b,c;cin>>a>>b>>c;
        dis[--a][--b]=c;
        dis[b][a]=c;
    }
    REP(k,N)REP(i,N)REP(j,N)dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);

    LL dp[R][(1<<R)];
    fill(dp[0],dp[R],LONG_MAX/10);
    REP(i,R)dp[i][(1<<i)]=0;

    for(int i=1;i<R;i++){
        for(int comb = (1<<i)-1;comb<(1<<R);comb = ((comb&~(comb+(comb&-comb)))/(comb&-comb)>>1)|comb+(comb&-comb)){
            REP(j,R){
                if((comb>>j)&1)continue;
                REP(k,R){
                    if((comb>>k)&1)dp[j][comb|(1<<j)] =min(dp[j][comb|(1<<j)], dp[k][comb] + dis[r[k]][r[j]]);
                }
            }
        }
    }

    LL ans =LONG_MAX;
    REP(i,R)ans = min(ans,dp[i][(1<<R)-1]);
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdio.h>
#include<stdlib.h>

int main(){
    int d, k[100] = {0}, i, n, ans = 0;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &d);
        k[d - 1]++;
    }
    for(i = 0; i < 100; i++){
        if(k[i]) ans++;
    }
    printf("%d\n", ans);
    return 0;
}

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

int t = 0;

class Node{
  public:
  int _id, _findTime, _finishTime;
  vector<int> _edgeId;  // 隣接する頂点
  int _isFound;

  void init(){
    int dim;
    _findTime = _finishTime = 0;
    _isFound = false;
    cin >> _id >> dim;

    for(auto j = 0; j < dim; j++){
      int in;
      cin >> in;
      _edgeId.push_back(in);
    }
  }
};

void DepthFirstSearch(vector<Node>& vertices, int key){
  vertices[key]._isFound = true;
  vertices[key]._findTime = ++t;
  for(auto i = 1; i < vertices.size(); i++){
    auto result = find(vertices[key]._edgeId.begin(), vertices[key]._edgeId.end(), i);
    if(result == vertices[key]._edgeId.end()) continue;
    if(!vertices[i]._isFound){
      DepthFirstSearch(vertices, i);
    }
  }
  vertices[key]._isFound = true;
  vertices[key]._finishTime = ++t;
}

void PrintResult(vector<Node> vertices){
  for(auto i = 1; i < vertices.size(); i++){
    cout << vertices[i]._id << " " << vertices[i]._findTime << " " << vertices[i]._finishTime << '\n';
  }
}

int main(){
  int n;
  cin >> n;
  vector<Node> vertices(n + 1);

  for(auto i = 1; i <= n; i++){
    vertices[i].init();
  }

  for(auto i = 1; i <= n; i++) {
    if(!vertices[i]._isFound)
      DepthFirstSearch(vertices, i);
  }
  PrintResult(vertices);

  return 0;
}


Measured memory_bytes: 3156