akhauriyash/Code-Regression huggingface dataset:
/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define all(a)      (a).begin(),(a).end()
#define si(x)       (int)((x).size())
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
#define se second 
#define endl        '\n'
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mem(a,x)          memset(a,x,sizeof(a))

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===


// const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=1000000+6;
#define M_PI           3.14159265358979323846
void inp(ll *arr,ll n)
{
  for(int i=0;i<n;i++)
    cin>>arr[i];
}
void inp_mat(ll *arr,ll n,ll m)
{
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        {
          ll x;cin>>x;
          *((arr+i*m) + j)=x;
        }
}
// syntax for inp_mat inp_mat((ll *)arr,n,m);
// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //  #ifndef ONLINE_JUDGEc
    //   freopen ("INPUT.txt" , "r" , stdin);
    //   freopen ("OUTPUT.txt", "w" , stdout);
    // #endif 
    int t=1;
    // cin>>t;
    while(t--)
    {
      ll n,k=2;
      cin>>n;ll arr[n];inp(arr,n);
      ll ans[n];
      f(i,0,n)
      ans[i]=mod;
      ans[0]=0;
      f(i,1,n)
      {
        int x=1;
        while(x<=k and i-x>=0)
        {
          ans[i]=min(ans[i],ans[i-x]+abs(arr[i]-arr[i-x]));
          x++;
        }
        dbg(ans[i]);
      }
      cout<<ans[n-1];
    }    
} 

Measured memory_bytes: 5100
#include<stdio.h>

int main(void){
  // double data = 0.0123;
  //printf("%f %e",data,data);
  int data[10],i,j,k;
  for(i=0;i<10;i++)
    scanf("%d",&data[i]);
  for(i=0;i<10;i++){
    for(j=i+1;j<10;j++){
      if(data[i] < data[j]){
	k =data[i];
	data[i] = data[j];
	data[j] =k;
	  }
    }
  }
  for(i=0;i<3;i++)
    printf("%d\n",data[i]);
}

Measured memory_bytes: 2728
<?php
list($n) = ints();
$a = ints();
for ($i = 0; $i < $n; ++$i) {
    for ($j = $a[$i] - 1; $j <= $a[$i] + 1; ++$j) {
        if (isset($cnt[$j])) $cnt[$j]++;
        else $cnt[$j] = 1;
    }
}
echo max($cnt);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 19188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int a[3][3];
  int h[3][3] = {};
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> a[i][j];
    }
  }
  int n;
  cin >> n;
  while(n--){
    int x;
    cin >> x;
    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
        if(a[i][j] == x) h[i][j] = 1;
      }
    }
  }
  bool ok = 0;
  for(int i = 0; i < 3; i++){
    bool k = 1;
    for(int j = 0; j < 3; j++){
      k &= h[i][j];
    }
    ok |= k;
  }
  for(int i = 0; i < 3; i++){
    bool k = 1;
    for(int j = 0; j < 3; j++){
      k &= h[j][i];
    }
    ok |= k;
  }
  if(h[0][0] && h[1][1] && h[2][2]) ok = 1;
  if(h[2][0] && h[1][1] && h[0][2]) ok = 1;
  cout << (ok ? "Yes" : "No");
}

Measured memory_bytes: 256
S = input()
T = input()
t = len(T)
def check(a,b):
    temp = 0
    for i in range(len(a)):
        if a[i] != b[i]:
            temp += 1
    return temp

ans = 10**5
for j in range(len(S) - len(T) + 1):
    ans = min(ans, check(S[j:j+t], T))

print(ans)

Measured memory_bytes: 9128
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,W = LI()
    g = LIR(n)
    dp = [0]*(W+1)
    for i in range(n):
        v,w = g[i]
        for j in range(W+1)[::-1]:
            nj = j+w
            if nj <= W:
                nd = dp[j]+v
                if dp[nj] < nd:
                    dp[nj] = nd
    print(dp[W])
    return

#Solve
if __name__ == "__main__":
    solve()



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

const int MAX = 5100000;
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;
}

int main(){
    int x,y;cin>>x>>y;
    int a,b;
    ll ans=0;
    COMinit();
    if((2*y-x)%3==0 && (2*x-y)%3==0){
        a=(2*y-x)/3;
        b=(2*x-y)/3;
        cout<<COM(a+b,a)<<endl;
    }
    else cout<<0<<endl;


}


Measured memory_bytes: 119808
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    char op;

    while (cin >> a >> op >> b, op != '?')
    {
        int result;
        switch (op) {
            case '+':
                result = a + b;
                break;
            case '-':
                result = a - b;
                break;
            case '*':
                result = a * b;
                break;
            case '/':
                result = a / b;
                break;
        }
        cout << result << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
import java.io.*;
import java.util.StringTokenizer;

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;

		try {
			while (!(buf = br.readLine()).equals("0")) {
				int n = Integer.parseInt(buf);
				for (int i=0;i<n;i++) {
					StringTokenizer st = new StringTokenizer(br.readLine());
					int pm = Integer.parseInt(st.nextToken());
					int pe = Integer.parseInt(st.nextToken());
					int pj = Integer.parseInt(st.nextToken());
					System.out.println(classify(pm,pe,pj));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static String classify(int pm,int pe,int pj) {
		if (pm==100||pe==100||pj==100) return "A";
		if ((pm+pe)/2>=90) return "A";
		int ave = (pm+pe+pj)/3;
		if (ave>=80) return "A";
		if (ave>=70) return "B";
		if (ave>=50) {
			if (pm>=80||pe>=80) return "B";
		}
		return "C";
	}
}

Measured memory_bytes: 27620
string = input()

before = ""
before2 = ""
ans = 0
while len(string) > 1:
    if before == string[0]:
        temp = string[0:2]
        string = string[2:len(string)]
    else:
        temp = string[0]
        string = string[1:len(string)]
    before2 = before
    before = temp
    ans += 1
if not len(string) == 0 and not before == string and not before2 == before:
    ans += 1
print(ans)

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

int main() {
	int n, m;
  cin >>n;
  cin >>m;
  int a = 0;
  for(int i = 1 ; i < n ; i++)
  {
    a = a + i;
  }
  for(int k = 1 ;k < m ;k++)
  {
    a = a + k;
  }
  
  cout<<a;
  return 0;
}


Measured memory_bytes: 3596
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l3=list(map(int,input().split()))
l=[l1,l2,l3]
c=l[0][0]
for i in range(3):
    for j in range(3):
        l[i][j] -=c
if (l[1][1]==l[0][1]+l[1][0]) and (l[2][1]==l[0][1]+l[2][0]) and (l[1][2]==l[0][2]+l[1][0])and (l[2][2]==l[2][0]+l[0][2]):
    print('Yes')
else:
    print("No")


Measured memory_bytes: 38384
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,m = LI()
def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])
    return par[x]

def same(x,y):
    return root(x) == root(y)

def union(x,y):
    x = root(x)
    y = root(y)

    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

par = [i for i in range(n)]
rank = [0 for _ in range(n)]

xyz = [LI() for _ in range(m)]
for x,y,z in xyz:
    if root(x-1) != root(y-1):
        union(x-1,y-1)
f = defaultdict(int)
for i in range(n):
    f[root(i)] = 1

ans = 0
for i,j in f.items():
    if j != 1:
        continue
    ans += 1
print(ans)




Measured memory_bytes: 90160
#include <iostream>
#include <cstdint>
#include <cmath>
#include <iomanip>

int main() {
  double x;
  std::cin >> x;
  std::cout << std::fixed << std::setprecision(0) << std::ceil((std::sqrt(8.0 * x + 1.0) - 1.0) / 2.0) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

bool isok(ll mid, ll key, const vector<ll>& C, bool smaller){
  if(smaller){
    if(C[mid] < key) return true;
    else return false;
  }
  else{
    if(C[mid] > key) return true;
    else return false;
  }
}

ll bs(ll key, ll ok, ll ng, const vector<ll>& C, bool smaller){
  while(abs(ok-ng)> 1){
    ll mid = (ok+ng)/2;
    if(isok(mid, key, C, smaller)) ok = mid;
    else ng = mid;
  }
  return ok;
}

vector<ll> S;
vector<ll> T;

int main(){
  ll A, B, Q; cin >> A >> B >> Q;
  S.resize(A+2); S[0] = -1e18; rep(i,A) cin >> S[i+1]; S[A+1] = 1e18;
  T.resize(B+2); T[0] = -1e18; rep(i,B) cin >> T[i+1]; T[B+1] = 1e18;

  rep(i,Q){
    ll pos; cin >> pos;
    ll leftS, rightS, leftT, rightT;
    // leftS
    leftS = S[bs(pos, 0, A+2, S, true)];
    rightS = S[bs(pos, A+2, 0, S, false)];
    leftT = T[bs(pos, 0, B+2, T, true)];
    rightT = T[bs(pos, B+2, 0, T, false)];
    //cout << leftS << " " << leftT  << " " << rightS << " " << rightT << " " << endl;
    ll l_l = pos - min(leftT, leftS);
    ll r_r = max(rightT, rightS) - pos;
    ll r_l = min(2*(rightT-pos)+pos-leftS, 2*(rightS-pos)+pos-leftT);
    ll l_r = min(2*(pos-leftT)+rightS-pos, 2*(pos-leftS)+rightT-pos);
    ll ans = min({l_l, r_r, l_r, r_l});
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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

	int K, A, B;
	cin >> K >> A >> B;
	int ans = 1;

	if (B - A <= 2)ans += K;
	else if (A >= K)
		ans += K;
	else{
		K -= A;
		ans = A;
		K++;
		if (K % 2 == 1) {
			ans++;
			K--;
		}
		K /= 2;
		ans += (B - A)*K;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
 
int main() {
   int a,b,c,d;
   cin>>a>>b>>c>>d;
   
   if(b<c || d<a) {
       cout << '0' << endl;
   }
   else if(a<=c && b>=d){
       cout << d-c << endl;
   }
   else if(c<=a && d>=b){
       cout << b-a << endl;
   }
   else if(d>b) {
       cout << b-c << endl;
   }
   else if(b>d) {
       cout << d-a << endl;
   }
  return 0;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

int main() {
    int n;
    cin >> n;
    ll a[n];
    rep (i, n) cin >> a[i];
    sort (a, a + n);
    ll ans = 0;
    if (n % 2 == 0) {
        rep (i, n) {
            if (i < n / 2 - 1) ans -= a[i] * 2;
            else if (i == n / 2 - 1)
                ans -= a[i];
            else if (i == n / 2 && n % 2 == 0)
                ans += a[i];
            else if (i == n / 2 && n % 2 == 1)
                ans -= a[i];
            else
                ans += 2 * a[i];
        }
    } else {
        ll sum1 = 0, sum2 = 0;
        rep (i, n) {
            if (i < n / 2 - 1) ans -= a[i] * 2;
            else if (i == n / 2 - 1) {
                sum1 -= a[i];
                sum2 -= 2 * a[i];
            } else if (i == n / 2) {
                sum1 -= a[i];
                sum2 += a[i];
            } else if (i == n / 2 + 1) {
                sum1 += 2 * a[i];
                sum2 += a[i];
            } else
                ans += 2 * a[i];
        }
        ans += max (sum1, sum2);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	int a,b; cin >> a >> b;
	cout << max({a+b,a-b,a*b});
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    if (B % A == 0) {
      System.out.println(A + B);
    } else {
      System.out.println(B - A);
    }
  }
}

Measured memory_bytes: 20948
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("in.txt",  "r",  stdin);
        freopen("out.txt", "w", stdout);
    #endif
//*/

        
    int n;
    cin>>n;
        
    vi v(n);


    forn(i,0,n)
    {
        cin>>v[i];
    }    

    sort(all(v)); 

    int count = 0;

    forr(i,n-1,1)
    {
        int l = 0,r = i-1;

        while(l < r)
        {
            if((v[l]+v[r]) > v[i])
            {
                count += r-l;
                r--;
            }
            else l++;
        }
    }

    cout<<count;



    return 0;
}

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

int main() {
    int n, k, temp;
    cin >> n >> k;
    set<int> st;
    rep(i, 11) st.insert(i);
    rep(i, k){
        cin >> temp;
        st.erase(temp);
    }
    while(true) {
        bool flag = true;
        temp = n;
        while(temp) {
            for(int t : st) {
                if(temp % 10 == t) break;
                if(t == 10) flag = false;
            }
            temp /= 10;
        }
        if(flag) break;
        else n++;
    }
    cout << n << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long 
using namespace std;
int n,m,cnt,tot,c[27][200010];
ll ans;
char ss[200010];
struct node
{
	int l,r;
}q[100010];
struct seg
{
	int v[800010],lz[1000000];
	void pd(int i)
	{
		if(lz[i])
		{
			lz[i*2]+=lz[i];lz[i*2+1]+=lz[i];
			v[i*2]+=lz[i]; v[i*2+1]+=lz[i];
			lz[i]=0;
		}
	}
	void bu(int i,int l,int r)
	{
		if(l==r){v[i]=l;return ;}
		bu(i*2,l,(l+r)/2);bu(i*2+1,(l+r)/2+1,r);
	}
	void add(int i,int l,int r,int ql,int qr)
	{
		if(l>qr || ql>r)return ;
		if(ql<=l && r<=qr)
		{
			v[i]--;lz[i]--;
			return ;
		}
		pd(i);
		add(i*2,l,(l+r)/2,ql,qr);
		add(i*2+1,(l+r)/2+1,r,ql,qr);
	}	
	int qy(int i,int l,int r,int k)
	{
		if(l==r)return v[i];
		pd(i);
		if(k<=(l+r)/2)return qy(i*2,l,(l+r)/2,k);
		return qy(i*2+1,(l+r)/2+1,r,k);
	}
}tr;
bool cmp(node a,node b)
{
	return a.l<b.l;
}
int dic(int k)
{
	return k-'a'+1;
}
int main()
{
	int i,s,a,b,j,k;
	int st,ed;
	scanf(" %s",ss);n=strlen(ss);
	for(i=1;i<=n;i++)k=dic(ss[i-1]),c[k][++c[k][0]]=i;
	for(i=1;i<=26;i++)cnt+=(c[i][0]&1);
	if(cnt>1){printf("-1");return 0;}
	for(i=1;i<=26;i++)
		if(c[i][0]&1)
		{
			k=c[i][(c[i][0]+1)/2];
			for(s=1;s<=26;s++)
			{
				for(j=1;j<=c[s][0]/2;j++)
				{
					if(c[s][j]>k)ans++;
					if(c[s][c[s][0]-j+1]<k)ans++;
				}
			}
			n--;
			for(s=k-1;s<n;s++)ss[s]=ss[s+1];
			for(s=1;s<=26;s++)c[s][0]=0;
			for(s=1;s<=n;s++)k=dic(ss[s-1]),c[k][++c[k][0]]=s;
			break;
		}
	//cout<<"Ans "<<ans<<endl;
	for(i=1;i<=26;i++)
	{
		st=1;ed=c[i][0];
		while(st<ed)q[++tot].l=c[i][st++],q[tot].r=c[i][ed--];
	}
	if(n)
	{
		sort(q+1,q+1+tot,cmp);tr.bu(1,1,n);
		//for(i=1;i<=tot;i++)cout<<" "<<q[i].l<<" "<<q[i].r<<endl;
		for(i=1;i<=tot;i++)
		{
			//cout<<" "<<i<<" "<<q[i].l<<" "<<tr.qy(1,1,n,q[i].l)<<" "<<q[i].r<<" "<<tr.qy(1,1,n,q[i].r)<<endl;
			ans+=abs(n-i+1-tr.qy(1,1,n,q[i].r));
			tr.add(1,1,n,q[i].r,n);
			//cout<<" "<<ans<<endl;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 28928
N = int(input())
V = [int(s) for s in input().split() if s.isdigit()]
C = [int(s) for s in input().split() if s.isdigit()]
VC = [int(i - j) for i, j in zip(V, C)]

dp = [0 for _ in range(N+1)]
for i in range(N):
    dp[i+1] = max(dp[i], dp[i] + VC[i])
print(dp[N])


Measured memory_bytes: 3064
fun main (args : Array<String>) {
	val (H, W) = readLine()!!.split(" ").map(String::toInt)
	val (h, w) = readLine()!!.split(" ").map(String::toInt)
	val Height : Int = H.toInt()
	val Width : Int = W.toInt()
	val hei : Int = h.toInt()
	val wid : Int = w.toInt()
	println("${(Height - hei) * (Width - wid)}")
}

Measured memory_bytes: 37936
import * as fs from "fs";
const input = (fs.readFileSync("/dev/stdin", "utf8") as string)
  .split(/\n/)
  .map(Number);

let x = input[3];
let count = 0;
for (let a = 0; a <= input[0]; a++) {
  for (let b = 0; b <= input[1]; b++) {
    for (let c = 0; c <= input[2]; c++) {
      if (a * 500 + b * 100 + c * 50 === x) count++;
    }
  }
}

console.log(count);

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 2e5 + 10;
int n, c[N], cnt[N], siz[N];
	inline LL cal(int n) {
		// C(n,2) + n
		return 1LL*n*(n+1)/2;
	}
LL ans[N];
vector<int>G[N];
	void dfs(int v, int fa) {
		int tmp = cnt[c[v]];
		siz[v] = 1;
		for(int u:G[v]) {
			if(u==fa) continue;
			cnt[c[v]] = 0;
			dfs(u, v);
			siz[v] += siz[u];
			ans[c[v]]+=cal(siz[u]-cnt[c[v]]);
		}
		cnt[c[v]] = tmp + siz[v];
	}
int main() {
	//scanf("%d", &n);
	std::ios::sync_with_stdio(false);
	cin>>n;
	for (int i = 1; i <= n; i++)
		//scanf("%d", &c[i]);
		cin>>c[i];
	for (int i = 1; i < n; i++) {
		int u, v;
		//scanf("%d%d", &u, &v);
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i++) {
		cout<< cal(n) - ans[i] - cal(n - cnt[i])<<endl;
	}
	return 0;
}


Measured memory_bytes: 37108
#include <bits/stdc++.h>
#define ll long long
#define var auto
using namespace std;

vector<ll> p(10);
vector<ll> point(10);

bool solve(){
  ll n, k;
  cin >> n >> k;
  if (n == 0) return false;

  for (int i = 0; i < p.size() - 1; i++){
    if (n <= point[i + 1]){
      var start = p[i] + (n - point[i] - 1) / (i + 1);
      var offset = (n - point[i] - 1) % (i + 1);

      string s = "";
      for (ll j = start; j <= start + k * 2; j++){
	s += to_string(j);
      }
      s = s.substr(offset, k);
      cout << s << endl;
      return true;
    }
    
  }

  
  return true;
}

int main(){
  p[0] = 1;
  point[0] = 0;
  for (int i = 1; i < p.size(); i++){
    p[i] = p[i - 1] * 10;
    point[i] = point[i - 1] + p[i - 1] * 9 * i;
  }
  while(solve());
}



Measured memory_bytes: 3124
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

using ld = long double;
using ll = long long;

constexpr int mod = 1000 * 1000 * 1000 + 7;
constexpr int odw2 = (mod + 1) / 2;

void OdejmijOd(int& a, int b) { a -= b; if (a < 0) a += mod; }
int Odejmij(int a, int b) { OdejmijOd(a, b); return a; }
void DodajDo(int& a, int b) { a += b; if (a >= mod) a -= mod; }
int Dodaj(int a, int b) { DodajDo(a, b); return a; }
int Mnoz(int a, int b) { return (ll) a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }
int Pot(int a, int b) { int res = 1; while (b) { if (b % 2 == 1) MnozDo(res, a); a = Mnoz(a, a); b /= 2; } return res; }
int Odw(int a) { return Pot(a, mod - 2); }
void PodzielDo(int& a, int b) { MnozDo(a, Odw(b)); }
int Podziel(int a, int b) { return Mnoz(a, Odw(b)); }
int Moduluj(ll x) { x %= mod; if (x < 0) x += mod; return x; }

template <typename T> T Maxi(T& a, T b) { return a = max(a, b); }
template <typename T> T Mini(T& a, T b) { return a = min(a, b); }

struct Wyn {
  int x, y;
  int vx, vy;

  Wyn() : x(0), y(0), vx(-1), vy(-1) {}

  void Dodaj(int val, int v) {
    if (v == vx or v == vy) return;
    if (val > x) {
      y = x;
      vy = vx;
      x = val;
      vx = v;
    } else if (val > y) {
      y = val;
      vy = v;
    }
  }

  void Polacz(const Wyn& w) {
    Dodaj(w.x, w.vx);
    Dodaj(w.y, w.vy);
  }

  int Oblicz() const {
    return x + y;
  }
};

int n;
int A[1 << 18];
Wyn dp[1 << 18];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < (1 << n); i++) {
    cin >> A[i];

    Wyn& w = dp[i];
    w.Dodaj(A[i], i);

    for (int j = 0; j < n; j++) {
      if ((i >> j) & 1) {
        w.Polacz(dp[i ^ (1 << j)]);
      }
    }
    debug() << imie(i) imie(w.x) imie(w.vx) imie(w.y) imie(w.vy);
  }

  for (int i = 1; i < (1 << n); i++) {
    int odp = dp[i].Oblicz();;
    for (int j = 0; j < n; j++) {
      if ((i >> j) & 1) {
        Maxi(odp, dp[(i ^ (1 << j)) | ((1 << j) - 1)].Oblicz());
      }
    }
    cout << odp << '\n';
  }
  return 0;
}


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

int main() {
    string S;

    cin >> S;

    int ans = 0;
    int zero_c = 0;
    int one_c  = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == '0') zero_c++;
        else            one_c++;
    }
    ans = min(zero_c, one_c)*2;

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


Measured memory_bytes: 512
// Snippets
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! stdin {
    () => ({
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    })
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => (
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input.to_string()), $output);
            )*
        }
    )
}

// End Snippets

fn main() {
    println!("{}", solve(stdin!()));
}

fn solve(src: String) -> String {
    input!{
        source = src,
        a: i32, b: i32, c: i32,
    }
    let vec = vec![a,b,c];
    let max = vec.iter().max().unwrap();
    let min = vec.iter().min().unwrap();
    let ans = if c == *max || c == *min {
        "No"
    } else {
        "Yes"
    };
    ans.to_string()
}

test! {
    "3 8 5" => "Yes",
    "7 3 1" => "No",
    "10 2 4" => "Yes",
    "31 41 59" => "No",
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        int cnt = 0;
        for (int i = x; i <= y; i++) {
            String num = Integer.toString(i);
            boolean isKaibun = true;
            for (int j = 0; j < 2; j++) {
                if (num.charAt(j) != num.charAt(4 - j) ) {
                    isKaibun = false;
                }
            }
            if (isKaibun) cnt++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 26836
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::{BufWriter, Write};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    input!(
        n: usize,
        l: [usize; n],
    );

    let mut l: Vec<usize> = l;
    l.sort();

    let mut ans = 0;

    for i in 0..n {
        let mut p = 0;
        for j in (0..i).rev() {
            while p < n && l[p] <= l[i] - l[j] {
                p += 1;
            }
            ans += max(0, j as i32 - p as i32);
        }
    }

    println!("{}", ans);
}

// c-b < a

fn main() {
    let stack_size = 1 << 28;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
typedef long long ll;
const int N=2e5+5;
const int p=1e9+7;
#define PI acos(-1)
ll qpow(ll a,ll n){ll res=1;while(n){if(n&1)res=res*a%p;a=a*a%p;n>>=1;}return res;}
int a[N];
void work()
{
    int n;
    scanf("%d",&n);
    for(int i=2;i<=n;i++){
        int x;
        scanf("%d",&x);
        a[x]++;
    }
    for(int i=1;i<=n;i++){
        printf("%d ",a[i]);
    }
    printf("\n");
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T=1;
    //scanf("%d",&T);
    //cin>>T;
    while(T--){
        work();
    }
}

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

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	while ( true ) {
	    final int n = stdin.nextInt();

	    if ( n == 0 ) {
		break;
	    }
	    
	    int[] array = new int[n];
	    for ( int i = 0; i < n; i++ ) {
		array[i] = stdin.nextInt();
	    }

	    int count = 0;
	    for ( int i = 0; i < n; i++ ) {
		for ( int j = 0; j < n - i - 1; j++ ) {
		    if ( array[j] > array[j + 1] ) {
			count++;
			final int copyOfAJ = array[j];
			array[j] = array[j + 1];
			array[j + 1] = copyOfAJ;
		    }
		}
	    }
	    System.out.println( count );
	}
	
    }
    
}

Measured memory_bytes: 19048
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if i%2==0 or i==0:
                if j==0 or j%2==0:
                    print("#",end="")
                else:
                    print(".",end="")
            else:
                if j==1 or j%2!=0:
                    print("#",end="")
                else:
                    print(".",end="")
        print()
    print()
                


Measured memory_bytes: 7004
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL<<60;
#define rev(s) (string((s).rbegin(), (s).rend()))

int h,w;
const int inf = 300000;
vector<string> field(110);
int dx[] = {1,0};
int dy[] = {0,1};
vector<vector<int>> cost(110,vector<int>(110,inf));

void bfs() {
    int cs;
    queue<P> q;
    q.push(P(0,0));
    if (field[0][0]=='#') {
        cost[0][0]=1;
    } else {
        cost[0][0]=0;
    }
    while (q.size()) {
        P pa = q.front();q.pop();
        rep(i,2) {
            int ny = pa.first+dy[i];
            int nx = pa.second+dx[i];
            if (ny>=0&&ny<h&&nx>=0&&nx<w) {
                if (field[ny][nx]=='#'&&field[pa.first][pa.second]=='.') {
                    cs=1;
                }
                else {
                    cs=0;
                }
                if (cost[ny][nx]>cost[pa.first][pa.second]+cs) {
                    cost[ny][nx]=cost[pa.first][pa.second]+cs;
                    q.push(P(ny,nx));
                }
            }
        }
    }
}


int main() {
    cin>>h>>w;
    rep(i,h) {
        cin>>field[i];
    }
    // rep(i,h) {
    //     rep(j,w) {
    //         if (field[i][j]=='s') {
    //             sy=i;sx=j;
    //         }if (field[i][j]=='g') {
    //             gy=i;gx=j;
    //         }
    //     }
    // }
    bfs();
    // if (cost[gy][gx]<=2) {
    //     cout<<"YES"<<endl;
    // }
    // else {
    //     cout<<"NO"<<endl;
    // }

    cout<<cost[h-1][w-1]<<endl;

}


Measured memory_bytes: 256
#include <cstdio>

int n,q;
int s[100001];

int search(int key){
	int l=0,r=n;
	while(r-l>1){
		int mid=(l+r)/2;
		if(s[mid]>key)r=mid;
		else l=mid;
	}
	return s[l]==key?1:0;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&s[i]);
	}
	scanf("%d",&q);
	int cnt=0;
	for(int i=0;i<q;i++){
		int t;
		scanf("%d",&t);
		cnt+=search(t);
	}
	printf("%d\n",cnt);
	return 0;
}

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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    ll n, a, b;
    cin >> n >> a >> b;
    if(a > b){
        cout << 0;
        return 0;
    }
    if(n == 1){
        if(a == b) cout << 1;
        else cout << 0;
        return 0;
    }
    cout << ((n-1)*b+a) - ((n-1)*a+b) + 1;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
import sys

n, m = map(int, input().split())

if math.fabs(n - m) == 1:
    k = 1
elif n == m:
    k = 2
else:
    k = 0

print(math.factorial(n) * math.factorial(m) % 1000000007 * k % 1000000007)


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;

  if(s == u){
    a--;
  }else{
    b--;
  }

  cout << a << " " << b << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)
ll k;
ll logz(ll x){
    ll y = 0;
    while((1ll<<y)*x<k){
        y++;
    }
    return y;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10); cout<<fixed;  // prints x digits after decimal in val

    ll n,x,t,m,y,z;
    cin>>n>>k;
    double ans = 0;
    for(int i=1;i<=n;i++){
        ans += pow(0.5, logz(i))/n;
    }
    cout<<ans;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    sort(a.rbegin(), a.rend());
    ll sum = accumulate(a.begin(), a.end(), 0LL);

    int ans = 0;
    for (int i = 0; i < N; i++) {
        sum -= a[i];
        ans++;
        if (a[i] > 2 * sum) break;
    }
    cout << ans << '\n';
}


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

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

using namespace std;

int main(void)
{
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    vector<int> diff(N);

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

    rep(i, N-1){
        diff[i] = A[i+1] - A[i];
    }
    diff[N-1] = A[0] + K - A[N-1];

    sort(diff.begin(), diff.end());
    
    int sum  = 0;
    rep(i, N-1) sum += diff[i];

    cout << sum << endl;

    return 0;
}

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


int main() {
    string s,t;
    cin >> s>>t;
    t.pop_back();
    if (s==t){
      cout<<"Yes"<<endl;
    }else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 3628
from heapq import *
n,k=map(int,input().split())
s=[0]*26
for i in range(n):
    s[ord(input()[0])-65]-=1
s=[i for i in s if i<0]
d=0
while len(s)>=k:
    t=[]
    for i in range(k):
        a=heappop(s)
        if a+1!=0:
            t.append(a+1)
    for j in t:
        heappush(s,j)
    d+=1
print(d)

Measured memory_bytes: 3188
#include <stdio.h>
#define N 100

int main(){
  int arry[N];
  int key,i,j,k,in;
  
  scanf("%d",&in);
  
  for(i = 0; i < in; i++){
    scanf("%d",&arry[i]);
  }

  for(k = 0; k < in; k++){
    if(k > 0) printf(" ");
    printf("%d", arry[k]);
  }
  printf("\n");
  
  for(i = 1; i < in; i++){
    key = arry[i];
    j = i -1;
    
    while(j >= 0 && arry[j] > key){
      arry[j+1] = arry[j];
      j--;
    }
    arry[j+1] = key;

    for(k = 0; k < in; k++){
      if(k > 0) printf(" ");
      printf("%d", arry[k]);
    }
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int N,M;
    cin>>N>>M;
    vi A(N);
    int sum=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    }
    int ans=0;
    for(int i=0;i<N;i++){
        if(A[i]*4*M>=sum){
            ans++;
        }
    }
    cout<<((ans>=M)?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
N = 5 * 10**6


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(input())
print(a + a**2 + a**3)


Measured memory_bytes: 12720
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args){

		solve_abc158_b();
	}
  
  	public static void solve_abc158_b(){

		Scanner sc = new Scanner(System.in);


		long N = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();



		long x = Math.floorDiv(N, a+b) * a;
		long y = (N % (a + b));

		if(y > a) y = a;

		long ans = x + y;

		System.out.println(ans);

		sc.close();

	}
}

Measured memory_bytes: 22740
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <numeric>
#include <iomanip>


int main(void) {
	int n, m;

	std::cin >> n >> m;

	std::vector<std::pair<long long, long long> > v(n);

	for (size_t i = 0; i < n; i++) {
		long long a, b;

		std::cin >> a >> b;

		v[i] = {a, b};
	}

	std::sort(v.begin(), v.end());

	long long ans = 0;
	for (size_t i = 0; i < n; i++) {
		if (v[i].second <= m) {
			ans += v[i].first * v[i].second;
			m -= v[i].second;
		}
		else {
			ans += v[i].first * m;
			break;
		}

	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){

  int c[4][4];

  for(int i=1;i<=3;i++){
    for(int j=1;j<=3;j++){
      cin>>c[i][j];
    }
  }
  int judge=0;

 
  if((c[1][1]-c[1][2])==(c[2][1]-c[2][2])&&(c[2][1]-c[2][2])==(c[3][1]-c[3][2])){
    if((c[1][2]-c[1][3])==(c[2][2]-c[2][3])&&(c[2][2]-c[2][3])==(c[3][2]-c[3][3])){
      judge=1;
    }
  }

  if(judge==1){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

  return (0);
}  


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
 
using namespace std;
typedef long long int lli;
const int MAX=1e5;
 
int main(){
	int N;
	cin>>N;
	string s,t;
	cin>>s>>t;
	int ans=2*N;
	rep(i,N){
		bool same=true;
		rep(j,N-i)if(s[i+j]!=t[j])same=false;
		if(same){
			ans=N+i;
			break;
		}
	}
	cout<<ans<<endl;
}

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

  using namespace std;
  using namespace std::chrono; 

  typedef long long int ll;

  #define MOD (ll)(1e9+7)
  #define endl "\n"
  #define pb push_back
  #define TEST_CASES  ll t;cin>>t;while(t--)
  #define forn(i,a,n) for (int i = a; i < n; ++i)
  #define f first
  #define s second
  #define all(x) x.begin(), x.end()

  void __print(int x) {cerr << x;}
  void __print(long x) {cerr << x;}
  void __print(long long x) {cerr << x;}
  void __print(unsigned x) {cerr << x;}
  void __print(unsigned long x) {cerr << x;}
  void __print(unsigned long long x) {cerr << x;}
  void __print(float x) {cerr << x;}
  void __print(double x) {cerr << x;}
  void __print(long double x) {cerr << x;}
  void __print(char x) {cerr << '\'' << x << '\'';}
  void __print(const char *x) {cerr << '\"' << x << '\"';}
  void __print(const string &x) {cerr << '\"' << x << '\"';}
  void __print(bool x) {cerr << (x ? "true" : "false");}

  template<typename T, typename V>
  void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
  template<typename T>
  void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
  void _print() {cerr << "]\n";}
  template <typename T, typename... V>
  void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
  #ifndef ONLINE_JUDGE
  #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
  #else
  #define debug(x...)
  #endif
  
  ll powD(ll x,ll y){
    ll res = 1;
    while(y > 0){
      if(y & 1)
        res = (res*x)%MOD;
      x = (x*x)%MOD;
      y = y>>1;
    }
    return res;
  }


  /*CHECK FOR CORNER CASES FOR GOD'S SAKE*/
  int main()
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    cin>>k;
    vector<int> visited(k,0);
    if(k%7 == 0)
      k /= 7;
    int n = 1;
    int r = n%k;
    while(r != 0){
      r = r*10 + 1;
      r %= k;
      if(visited[r]){
        cout<<"-1"<<endl;
        return 0;
      }
      else
        visited[r] = 1;
      n++;
    }
    cout<<n<<endl;
  }
   
  


Measured memory_bytes: 7156