akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int main() {
	int q, money, special, common, specialLimit, sWeight, cWeightMax, restWeightMax, i;

	while (cin >> q, q) {
		cin >> money >> special >> common >> specialLimit;

		cWeightMax = min(money / special, specialLimit);
		//cout << "最大会津Chicken=" << cWeightMax << endl;
		for (i = cWeightMax; i > 0; --i) {
			restWeightMax = (money - special * i) / common;
			//cout << i << " " << restWeightMax << endl;
			if (restWeightMax < 0 || i + restWeightMax < q) {
				continue;
			}
			break;
		}
		if (i == 0) {
			cout << "NA" << endl;
		}
		else {
			cout << i << " " << restWeightMax << endl;
		}
		
	}

	return 0;
}


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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int A = stdIn.nextInt();
		int B = stdIn.nextInt();
		int P = 0;
		if(A <= 5) {
			P = 0;
			System.out.println(P);
		}
		else if(A >= 6 && A <= 12) {
			P = B/2;
			System.out.println(P);
		}
		else {
			P = B;
			System.out.println(P);
		}

	}

}

Measured memory_bytes: 21332
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <tuple>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rep1(i, n) for(int i=1; i<=n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
#define countof(array) (sizeof(array) / sizeof(array[0]))
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string ab = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string as = {"abcdefghijklmnopqrstuvwxyz"};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

void yes() {
  cout << "Yes" << endl;
}

void no() {
  cout << "No" << endl;
}

void print_array(int array[], int len) {

  for(int i=0; i<len; ++i) {
    cout << array[i] << endl;
  }

}

ll absolute(ll x) {
  return (x<0)? (-1)*x : x;
}

//g++ AtCoder.cpp -o AtCoder
//AtCoder

//--------------------------

int main() {

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

  ll small;
  while(true) {
    sort(a.begin(), a.end());
    small = a[0];
    bool flag = true;

    for(int i=1; i<n; ++i) {
      if(small>a[i]%small&&a[i]%small!=0) {
        a[i] = a[i]%small;
        flag = false;
        break;
      }
    }

    if(flag) break;
  }

  cout << small << endl;


  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include<limits.h>
#include<algorithm>
#include<queue>
#include<set>
#include<math.h>


#define MOD 1000000007

using namespace std;

long long int modpow(long long int a, long long int n) {
	if (n == 0)return 1;
	if (n == 1)return (a % MOD);

	long long int hanbun = n / 2;
	long long int amari = n % 2;

	long long int ans = (a * a) % MOD;
	ans = modpow(ans, hanbun);

	if (amari == 1)ans *= a;

	ans %= MOD;

	return ans;

}

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}

	long long int amari = a % b;

	if (amari == 0)return b;

	return gcd(b, amari);
}

long long int lcm(long long int a, long long int b) {
	long long int ans = (a * b) % MOD;
	long long int wari = modpow(gcd(a, b), MOD - 2);
	ans = (ans * wari) % MOD;
	return ans;
}

long long int factElement[10000] = { 0 };

long long int factrial(int n) {

	if (factElement[n] != 0)return factElement[n];

	if (n == 0) {
		factElement[0] = 1;
		return factElement[n];
	}

	long long int ans = n * factrial(n - 1);
	factElement[n] = ans;
	return factElement[n];

}


int main()
{

	long long int h, w;
	cin >> h >> w;

	if (h == 1 || w == 1) {
		cout << "1" << endl;
		return 0;
	}

	long long int a, b;
	a = (h + 1) / 2;
	b = h / 2;

	long long int c, d;
	c = (w + 1) / 2;
	d = w / 2;

	long long int ans = a * c + b * d;

	cout << ans << endl;





	return 0;

}



Measured memory_bytes: 256
// Tue May 26 19:06:02 IST 2020 
#include <bits/stdc++.h>        
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(ii,a,b)        for(int ii = (int)a ; ii < (int)b  ; ii++ )
#define debug(x)           cerr << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int64              long long    
#define MOD                998244353 
#define pb                 push_back
#define f1                 first 
#define s1                 second    
#define all(x)             (x).begin(),(x).end() 
#define precise(x)         cout << fixed << setprecision(12) << x << '\n'; 
#define tough_nut          numeric_limits<int64>::min()

const double pi = 3.141592653589793238;
using namespace  std ;       
using namespace __gnu_pbds;
 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
const int N = 3e5+7; 
const int INF = INT_MAX;
struct comp{
    bool operator()(const pair<int,int> A,const pair<int,int>& B )const{
        if(A.first == B.first)
            return A.second < B.second ;
        return A.first > B.first;
    } 
};   
int tests(){ 
    int a ;
    cin >> a ;
    cout << a + a*a + a*a*a << '\n';
    return 0;
    // cout << (n+1-min(a,b)+max(a,b)-1)/max(a,b) << '\n';
} 
int32_t main(){
    I__O ;     
    int cases = 1 ;  
    // cin >> cases ;  
    while(cases--) 
        tests(); 
     
    return 0 ; 
}
 // g++ -std=c++17 -O2 -Wall test.cpp  


Measured memory_bytes: 3648
X = int(input())
max1 = 1
max2 = 0

for b in range(1, X+1):
    for q in range(2, X+1):
        
            
        if b**q > X:
            break
        
        max1 = b**q
        
    if max1 > max2:
        max2 = max1
        
print(max2)

Measured memory_bytes: 2940
n = int(input())
sozai = list(map(int, input().split()))

sozai = sorted(sozai)

ans = 0
for i, value in enumerate(sozai):
  if i >= 2:
    ans = (ans + value) / 2    
  else:
    ans = (sozai[0] + sozai[1]) / 2

print(ans)

Measured memory_bytes: 3064
N, = map(int, input().split())
X = [(i+1, x) for i, x in enumerate(map(int, input().split()))]
dp = [[0]*(N+1) for _ in range(N+1)]
X = sorted(X, key=lambda x:x[1])[::-1]
for i in range(1, N+1):
    ai, a = X[i-1]
    dp[i][0] = dp[i-1][0]+a*abs(ai-(N-i+1))
    for j in range(1, i):
        dp[i][j] = max(dp[i-1][j-1]+a*abs(ai-j), dp[i-1][j]+a*abs(ai-(N-(i-j)+1)))
    dp[i][i] = dp[i-1][i-1]+a*abs(ai-i)
print(max(dp[-1]))


Measured memory_bytes: 100472
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

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

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

void solve() {
    lli n;
    cin >> n;
    vlli v(n), pre(n), suf(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    pre[0] = v[0];
    suf[n - 1] = v[n - 1];

    for (int i = 1; i < n; ++i) {
        pre[i] = max(pre[i - 1], v[i]);
    }
    for (auto i = n - 2; i >= 0; --i) {
        suf[i] = max(suf[i + 1], v[i]);
    }

    for (int i = 0; i < n; ++i) {
        if (i == 0) {
            cout << suf[i + 1] << endl;
        } else if (i == n - 1) {
            cout << pre[i - 1] << endl;
        } else {
            cout << max(pre[i - 1], suf[i + 1]) << endl;
        }
    }
}

int main()
{
    IOS;
    lli t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)

// https://ei1333.github.io/algorithm/cumulative-sum2d.html
template <class T> struct CumulativeSum2D {
    T data[2001][2001];
    int w, h;

    CumulativeSum2D(int W, int H) {
        w = W;
        h = H;
    }

    void add(int x, int y, T z) {
        ++x, ++y;
        if (x >= w || y >= h)
            return;
        data[x][y] += z;
    }

    void build() {
        FOR(i, 1, w) FOR(j, 1, h) {
            data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
        }
    }

    T query(int sx, int sy, int gx, int gy) {
        return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
    }

    void print() {
        for (auto &x : data) {
            for (auto &y : x) {
                cout << y << " ";
            }
            cout << endl;
        }
    }
};

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    char c;
    int n, k, x, y;
    cin >> n >> k;
    CumulativeSum2D<int> s(k * 2, k * 2);
    REP(i, n) {
        cin >> x >> y >> c;
        if (c == 'W') {
            y += k;
        }
        y %= 2 * k;
        if (y >= k) {
            y -= k;
            x += k;
        }
        x %= 2 * k;
        s.add(x, y, 1);
        s.add((x + k) % (2 * k), y + k, 1);
    }
    // 二次元累積和
    s.build();
    // s.print();
    int maxv = 0;
    REP(x, k) REP(y, k) {
        int t = s.query(x, y, x + k, y + k);
        maxv = max({maxv, t, n - t});
    }
    cout << maxv << endl;
    return 0;
}


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a+b>=c){
    cout << "Yes";
  }
  else if(a+b<c){
    cout << "No";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
// D - Face Produces Unhappiness
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 1; i < n; i++)
		if (s[i] == s[i - 1]) ans++;
	cout << min(ans + k * 2, n - 1) << endl;

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

ll fac[200007],finv[200007],inv[200007];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<200007;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;
    }
}
ll com(ll n,ll 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() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    cominit();
    ll h,w,a,b;
    cin>>h>>w>>a>>b;
    a=h-a;
    b++;
    ll ans=0;
    while(a>=1&&b<=w){
    	(ans+=(com(a+b-2,a-1)*com(w-b+h-a,w-b))%mod)%=mod;
    	a--;
    	b++;
    }
    cout << ans << endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
const int INF = 1e9;
const llint llINF = 1e18;

int main () {
    llint n, k;
    cin >> n >> k;
    vint h(n);
    llint sum = 0;
    rep(i, n) {
        cin >> h[i];
        sum += h[i];
    }
    sort(h.begin(), h.end());
    if (k != 0) {
        for (int i = 0; i < k; i++) {
            if (sum <= 0) break;
            llint last = h.back();
            sum -= last;
            h.pop_back();
        }
    } else {
        cout << sum << endl;
        return 0;
    }

    if (sum <= 0) cout << 0 << endl;
    else cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1024
import bisect

n, k = map(int, input().split())
a = sorted(map(int, input().split()))

def count(t):
    c = 0
    for x in a:
        if x == 0:
            c += len(a) - 1 if t >= 0 else 0
        elif x > 0:
            c += bisect.bisect_left(a, (t // x) + 1) - (x * x <= t)
        else:
            c += len(a) - bisect.bisect_left(a, -(t // -x)) - (x * x <= t)
    return c

lo = -1000000000000000001
hi = 1000000000000000001
while hi - lo > 1:
    mid = (lo + hi) // 2
    if count(mid) < k * 2:
        lo = mid
    else:
        hi = mid
print(hi)


Measured memory_bytes: 104360
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int a[3];
	for (int i = 0; i < 3; ++i){
		cin >> a[i];
	}
	sort(a, a + 3);
	
	if (a[0] == a[1] && a[0] != a[2] || a[1] == a[2] && a[0] != a[2]){
		cout << "Yes\n";
	}
	else{
		cout << "No\n";
	}
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

  int a, b, r, tmp;

  scanf("%d%d", &a,&b);
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  printf("%d\n", b);

  return 0;
}


Measured memory_bytes: 2104
#include<stdio.h>

int main(void){
  long long a[100];
  int i,n;

  a[0]=2;
  a[1]=1;

  scanf("%d",&n);

  for(i=2;i<=n;i++)
    a[i]=a[i-1]+a[i-2];

  printf("%lld\n",a[n]);

  return 0;
}


Measured memory_bytes: 128
n = int(input())
h =list(map(int, input().split()))

if n==1:
    print('Yes')
    exit(0)
if n==2:
    if h[0] >= h[1]-1:
        print('Yes')
        exit(0)
    else:
        print('No')
        exit(0)

h[0] -=1

for i in range(1, n-1):
    if h[i-1] == h[i] and h[i] <=h[i+1]:
        continue
    elif h[i-1] == h[i] and h[i] >h[i+1]:
        print('No')
        exit(0)

    elif h[i] <= h [i+1]+1:
        h[i] -= 1
    elif h[i] > h [i+1]+1:
        print('No')
        exit(0)


print('Yes')

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

typedef long long ll;
const ll kMOD = 1000 * 1000 * 1000 + 7;
const int kMAX_H = 100010;

ll memo[kMAX_H * 2];

ll ModFactorial(ll n, ll mod) {
    if (memo[n] > 0) return memo[n];
    ll res = 1;
    while (n > 1) {
        res = (res * n) % mod;
        n--;
        if (memo[n] > 0) {
            res = (res * memo[n]) % mod;
            break;
        }
    }
    return memo[n] = res;
}

ll ModPow(ll a, ll b, ll mod) {
    if (b == 0) return 1;
    else if (b % 2 == 0) {
        ll d = ModPow(a, b / 2, mod);
        return (d * d) % mod;
    } else {
        return (a * ModPow(a, b - 1, mod)) % mod;
    }
}

ll InverseElement(ll n, ll mod) {
    return ModPow(n, mod - 2, mod);
}

ll ModPermutation(ll n, ll r, ll mod) {
    if (n < r) return 0;
    return (ModFactorial(n, mod) * InverseElement(ModFactorial(n - r, mod), mod)) % mod;
}

ll ModCombination(ll n, ll r, ll mod) {
    if (n < r) return 0;
    r = min(r, n - r);
    return (ModPermutation(n, r, mod) * InverseElement(ModFactorial(r, mod), mod)) % mod;
}

ll ModHomogeneousProduct(ll n, ll r, ll mod) {
    if (n == 0 && r == 0) return 1;
    return ModCombination(n + r - 1, r, mod);
}

int main() {
    // 先に階乗を計算しておく
    ll res = 1;
    for (int i = 0; i < kMAX_H * 2; i++) {
        if (i > 1) {
            res = (res * i) % kMOD;
        }
        memo[i] = res;
    }
    ll H, W, A, B;
    cin >> H >> W >> A >> B;
    ll all = ModCombination((H - 1) + (W - 1), (H - 1), kMOD);
    for (int w = 0; w < B; w++) {
        ll forbidden = ModCombination((H - A - 1) + w, (H - A - 1), kMOD);
        forbidden *= ModCombination((A - 1) + (W - w) - 1, (A - 1), kMOD);
        forbidden %= kMOD;
        all = (all - forbidden + kMOD) % kMOD;
    }
    cout << all << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <limits>
#include <bits/stdc++.h>
#include<queue>
#include<type_traits>
#include<cstdint>
using namespace std;
long long gcd(long long a,long long b){
     if(a==0||b==0){
        if(a==0)return b;
        if(b==0)return a;
    }
    if(a>b){
        return gcd(a%b,b);
    }else if(a<b){
        return gcd(b%a,a);
    }
}

int main() {
    int n;
    cin >> n;
    long long x;
    cin >> x;
    long long gcd0 = x;
    for(int i=0;i<n;i++){
        long long y;
        cin >> y;
        gcd0=gcd(gcd0,y);
    }
    cout << gcd0 << endl;
}


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

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    vector<ll> cumsum(N + 1, 0);
    rep(i, N) cumsum[i + 1] = cumsum[i] + A[i];
    double half = cumsum[N] / 2.;
    ll ans = 0;
    rep(i, N) {
        if (cumsum[i + 1] >= half) {
            ans = 2 * min(cumsum[i + 1] - half, half - cumsum[i]);
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
char a[55][55],b[55][55];
int main(){
   int found = 0;
    int n,m;
    scanf("%d%d",&n,&m);
      int x,y,i,j;
    for(i=0;i<n;i++)
        scanf("%s",&a[i]);
    for(i=0;i<m;i++)
        scanf("%s",&b[i]);

    
        for(x=0;x<n;x++)
            {
            if(x+m>n)break;
            for(y=0;y<n;y++)
                {
                if(y+m>n)break;
                    int valid = 1;
               // printf("point %d %d\n",x,y);
                for(i=0;i<m;i++)
                    {
                    for(j=0;j<m;j++)
                        {
                        if(a[x+i][y+j]!=b[i][j])
                            {
                            valid = 0; break;
                        }
                    }
                    if(valid==0)break;
                }
              //  printf("%d \n",valid);
                if(valid)
                    {
                    found =1 ;
                    break;
                }
            }
            if(found==1)break;
        }
    
    if(found==0)printf("No\n");
    else printf("Yes\n");
    return 0;
}


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

std::vector<int> GetInput() {
    int n = 0;
    std::vector<int> values;
    std::cin >> n;
    values.resize(n, 0.0);

    for (auto it = values.begin(); it < values.end(); it++) {
        std::cin >> *it;
    }
    return values;
}


int main(int argc, char const* argv[])
{

    auto values = GetInput();
    long int used_min_ix = -1;
    long int cur_min_ix = -1;
    long int used_max_ix = -1;
    long int cur_min = -1;
    long int max = -1;
    long int max_profit = -10000000000;
    if (values.size() == 0) {
        return 0;
    }
    used_min_ix = 0;
    cur_min_ix = 0;
    cur_min = values[0];
    for(int i = 1; i < values.size(); i++) {
        long int profit = values[i] - cur_min;
        if (max_profit < profit) {
            max_profit = profit;
            used_min_ix = cur_min_ix;
            used_max_ix = i;
        }
        if(values[i] < cur_min) {
            cur_min = values[i];
            cur_min_ix = i;
        }
    }

    std::cout << max_profit << std::endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int N; cin >> N;
    ll x=0;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];
    rep(i,N) x ^= a[i];

    set<int> st;
    rep(i,N){
        ll t = a[i] ^ (a[i] - 1);
        st.insert(__builtin_popcount(t));
    }

    int ans = 0;
    for(int i=30;i>=0;i--){
        if((x>>i) & 1){
            if(st.count(i+1)){
                x ^= (1 << (i+1)) - 1;
                ans++;
            }
        }
    }

    if(x != 0){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <iterator>

static int createListOfInputData(std::vector<int>& vec);
static int switchingRailroadCars(std::vector<int>& vec, std::vector<int>& data);
static void showData(std::vector<int>& vec);

int main()
{
    std::vector<int> v;
    std::vector<int> r;

    if (createListOfInputData(v)) {
        std::cout << "Failure";
        exit (8);
    }

    if (switchingRailroadCars(v, r)) {
        std::cout << "Failure";
        exit (8);
    }

    showData(r);

    return 0;
}

static int createListOfInputData(std::vector<int>& vec)
{
    int t = 0;

    if ( 0x00 == &vec ) {
        return 1;
    }

    while (std::cin >> t) {
        if ( 100 < t ) {
            return 1;
        }
        vec.push_back(t);
    }

    return 0;
}

static int switchingRailroadCars(std::vector<int>& vec, std::vector<int>& data)
{
    std::vector<int>::iterator it;

    if ( 0x00 == &vec ) {
        return 1;
    }

    it = vec.begin();

    while (vec.end() != it) {
        if ( 0 == *it ) {
            data.push_back(*(it - 1));
            vec.erase(it);
            it = vec.erase(it - 1);
        } else {
            it++;
        }
    }

    return 0;
}

static void showData(std::vector<int>& vec)
{
    if ( 0x00 == &vec ) {
        return;
    }

    for ( unsigned int i = 0; i < vec.size(); i++ ) {
        std::cout << vec.at(i) << std::endl;
    }
}

Measured memory_bytes: 3016
p1 = 0
p2Tmp = 0
p3Tmp = 0
pInfElement = []
dataNum = int(input())
x = [float(i) for i in input().split()]
y = [float(i) for i in input().split()]

for index in range(dataNum):
    p1 += abs(x[index] - y[index])
    p2Tmp += ((x[index] - y[index])**2)
    p3Tmp += (abs(x[index] - y[index])**3)
    pInfElement.append(abs(x[index] - y[index]))

p2 = p2Tmp **(1/2)
p3 = p3Tmp **(1/3)
pInf = max(pInfElement)

print(p1)
print(p2)
print(p3)
print(pInf)


Measured memory_bytes: 5668
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=9999999999999999;

int main() {
   int N;
   cin>>N;
   vector<int>h(N);
   for(int i=0;i<N;i++){
      cin>>h[i];
   }
   int count=0;
   while(true){
      if(*max_element(h.begin(),h.end())==0){break;}
      int i=0;
      while(i<N){
         if(h[i]==0){i++;}
         else{
            count++;
            while(i<N&&h[i]>0){
               h[i]--;
               i++;
            }
         }
      }
   }
   cout<<count<<endl;
return 0;}

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

using namespace std;

int main(void){
//string S;
int N;
cin >> N;
int K;
cin >> K;
long long mincost = 0;
vector<int> H(N);

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

sort(H.begin(), H.end(), greater<int>());

for(int i = K; i < H.size(); i++){
  mincost += H[i];
}
cout << mincost << endl;

return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N, K;
    cin >> N >> K;
    int M, D;
    int tmp;
    cin >> tmp;
    D = tmp;
    M = tmp;
    for (int i = 1; i < N; i++) {
        cin >> tmp;
        D = __gcd(tmp, D);
        M = max(tmp, M);
    }
    if(K <= M && K % D == 0){
        printf("POSSIBLE\n");
    }
    else{
        printf("IMPOSSIBLE\n");
    }
    
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

void read(int &x){
	x=0;int f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
	while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c-'0');c=getchar();}
	x*=f;
}

int main(){
	int ans=0;
	int x,y,a,b,c;
	read(a);read(b);read(c);read(x);read(y);
	if(a+b<c*2){
		ans=x*a+y*b;
	}
	else {
			ans=min(x,y)*2*c;
		if(x!=y){
			if(x>y){
				if(a*abs(y-x)<c*2*abs(x-y)) ans+=a*abs(y-x);
				else ans+=abs(x-y)*c*2;
			}
			else {
				if(b*abs(x-y)<c*2*abs(x-y)) ans+=b*abs(x-y);
				else ans+=abs(x-y)*c*2;
			}
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;


int N;
string S;
int acc[300010];


signed main(){
    cin >> N;
    cin >> S;

    rep(i, 0, N){
        if(S[i] == 'E') acc[i+1]++;
        acc[i+1] += acc[i];
    }

    int ans = INF;
    rep(i, 0, N) chmin(ans, i-(acc[i]-acc[0])+acc[N]-acc[i+1]);

    cout << ans << endl;

    return 0;
}

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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    n = 1 << n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.rbegin(), a.rend());
    vector<bool> z(n);
    z[0] = true;
    vector<int> b = {a[0]};
    int c = 1;
    while (c < n) {
        int j = 0;
        for (int i = 0; i < c; i++) {
            while (j < n && (z[j] || a[j] >= b[i])) j++;
            if (j == n) {
                cout << "No";
                return 0;
            }
            z[j] = true;
            b.push_back(a[j]);
        }
        sort(b.rbegin(), b.rend());
        c *= 2;
    }
    cout << "Yes";

    return 0;
}

Measured memory_bytes: 2424
/* stack構造を用いて逆ポーランド記法を行うプログラム */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 101

/* プロトタイプ宣言 */
void Push(int[], int);
int Pop(int[]);

/* グローバル変数宣言 */
int cnt = 0;

int main(){

  /* 変数宣言 */
  int x, y;
  int val1=0, val2=0, val3=0;
  int i=0;

  /* 数字か演算子か調べる配列を宣言 */
  char s[N];


  /* 重要！！ stack配列を宣言 */
  int stack_Arr[N];


  /* 標準入力がEOFになるまでループ */
  while( scanf("%s", s) != EOF )
    {

    /* もし入力されたものが演算子 + ならば */
    if ( s[0] == '+' ){

      /* Pop関数で数字を２つ引っこ抜いて足し算 */
      val1 = Pop(stack_Arr);
      val2 = Pop(stack_Arr);
      val3 = val1 + val2;

      /* 新しくできた数字をまた詰めなおす */
      Push(stack_Arr, val3);
    } 
    

    /* もし入力されたものが演算子 - ならば */
    else if ( s[0] == '-' ){

      /* Pop関数で数字を２つ引っこ抜いて引き算 */
      val1 = Pop(stack_Arr);
      val2 = Pop(stack_Arr);
      val3 = val2 - val1;
      
      /* 新しくできた数字をまた詰めなおす */
      Push(stack_Arr, val3);
	} 
    

    /* もし入力されたものが演算子 * ならば */
    else if ( s[0] == '*' ){

      /* Pop関数で数字を２つ引っこ抜いてかけ算 */
      val1 = Pop(stack_Arr);
      val2 = Pop(stack_Arr);
      val3 = val1 * val2;
      
      /* 新しくできた数字をまた詰めなおす */
      Push(stack_Arr, val3);
	} 

    
    /* もし演算子でなければ入力された値をint型にしてxに代入する */
    else {
      x = atoi(s);
      
      /* Push関数で数字を詰める */
      Push(stack_Arr, x);
    }
    }


  printf("%d\n", stack_Arr[cnt]);
 
  return 0;
}



/* Push関数 
 * 
 * Stack_Arrに数字を詰めていく関数
 */
void Push(int s_A[], int x)
{
  int i;//カウンター変数

  s_A[cnt+1] = x;
  cnt++;

  return;
}



/* Pop関数
 *
 * Stack_Arrから数字を抜き出す関数
 */
int Pop(int s_A[]) 
{
  int i;
  int x;//格納用

  if(cnt == 0) {
    printf("under flow\n");
    exit(1);  
    } 

    else {
    x = s_A[cnt];
    cnt--;
    return x;
    }
}

Measured memory_bytes: 548
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
  int n;
  cin>>n;	
  string s;
  cin>>s;
  for(int i=0;i<s.length();i++){
  	if(s[i]+n <='Z'){
  		s[i]=s[i]+n;
  	}
  	else {
  		s[i]=s[i]+(n-26);
  	}
  }
  for(auto i :s)cout<<i;
  return 0;
}
  

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N; cin >> N;
    vector <ll> count(N+1, 0); 
    for (ll i=1; i<=100; ++i)
    {
        for (ll j=1; j<=100; ++j)
        {
            for (ll k=1; k<=100; ++k)
            {
                if (i*i+j*j+k*k+i*j+i*k+k*j <= N) count[i*i+j*j+k*k+i*j+i*k+k*j]++; 
            }
        }
    }
    loop(i,1,N+1) cout << count[i] << "\n";
    return 0;
}

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

using namespace std;
typedef long long LL;
using Graph = vector<vector<LL>>;
static LL INF = (1LL<<62);
using LLPair = pair<LL, LL>;

const int MAX = 100004;
int PARENT[MAX] = {0};
int RANK[MAX] = {0};
int CHLDS[MAX] = {0};

void init(int L){
	if(L<1) return;
	for(int i=0; i<L; i++){
		PARENT[i]=i;
		RANK[i]=0;
		CHLDS[i] = 1;
	}
}

int root(int x){
	if(x<0) return -1;
	if(PARENT[x]==x){
		return x;
	}
	else{
		int p = root(PARENT[x]);
		if(p != PARENT[x]){
			if(CHLDS[x] != 0){
				CHLDS[p] += CHLDS[x];
				CHLDS[x] = 0;
			}
			CHLDS[x] = 0;
			PARENT[x] = p;
		}
		return PARENT[x];
	}
}

int same(int x, int y){
	if(x==y) return 1;
	if(root(x)==root(y)){
		return 1;
	}
	else{
		return 0;
	}
}

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

	int a = root(x);
	int b = root(y);
	if(a==b) return;

	if(RANK[x]<RANK[y]){
		PARENT[b] = a;
		CHLDS[a] += CHLDS[b];
		CHLDS[b] = 0;
	}
	else{
		PARENT[a] = b;
		if(RANK[x]==RANK[y]) RANK[x] += RANK[y];
		CHLDS[b] += CHLDS[a];
		CHLDS[a] = 0;
	}
}

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

	cin >> N >> M;
	vector<pair<int, int>> V;
	for(int i=0; i<M; i++){
		int a, b; cin >> a >> b;
		a--; b--;
		V.push_back(make_pair(a, b));
	}

	init(N);

	vector<LL> A;
	LL w = (N*(N-1))/2;
	A.push_back(w);
	for(int i=V.size()-1; i>=0; i--){
		LL tmp = A[A.size()-1];
		auto br = V[i];
		int x = br.first;
		int y = br.second;
		int rx = root(x);
		int ry = root(y);
		LL ca = CHLDS[rx];
		LL cb = CHLDS[ry];
		if(same(rx, ry) != 1){
			tmp -= (ca*cb);
		}
		if(i > 0){
			A.push_back(tmp);
		}
		combine(x, y);
	}

	for(int i=A.size()-1; i>=0; i--){
		printf("%lld\n", A[i]);
	}
	return 0;
}


Measured memory_bytes: 7084
using System;

class ITP1_2 {
    public static void Main() {

        string[] Input = Console.ReadLine().Split(' ');

        int a = int.Parse(Input[0]);
        int b = int.Parse(Input[1]);

        Console.Write("a ");
        if (a > b) Console.Write(">");
        if (a == b) Console.Write("==");
        if (a < b) Console.Write("<");
        Console.WriteLine(" b");

    }
}

Measured memory_bytes: 8852
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int D = sc.nextInt();
	int count = 0;
	long x,y;
	for (int i=0; i<N; i++) {
	    x = sc.nextLong();
	    y = sc.nextLong();
	    if (Math.sqrt(x*x + y*y) <= (double)D) count++;
	}
	System.out.print(count);
    }
}


Measured memory_bytes: 60600
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int main(){
	int num;
	int i;
	int min, max;
	long long sum=0;
	int temp;

	scanf("%d", &num);

	for(i=0; i<num; i++){
		scanf("%d", &temp);
		if(i==0){
			min = temp;
			max = temp;
			sum = temp;
		}else{

			if(min > temp)
				min = temp;
			else if(max < temp)
				max = temp;
			
			sum += (long long)temp;
		}
	}

	printf("%d %d %ld\n", min, max, sum);
	
	return 0;

}


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

//int gcd_buf[200][200] = {};

int gcd_two(int a,int b){
    //if(gcd_buf[a][b] != 0) return gcd_buf[a][b];
    if(b == 0){
        //gcd_buf[a][b] = a;
        return a;
    }
    else{
        //gcd_buf[a][b] = gcd_two(b,a % b);
        //return gcd_buf[a][b];
        return gcd_two(b,a % b);
    }
}

int gcd_three(int a,int b,int c){
    return gcd_two(gcd_two(a,b),c);
}

int main(){
    int K; cin >> K;
    int ans = 0;
    if(K == 1)ans = 1;
    else if(K == 2)ans = 9;
    else{
        //all same
        for(int i = 1;i <= K;i++){
            ans += i;
        }

        //two-one
        for(int i = 1;i < K;i++){
            for(int j = i+1;j <=K;j++){
                ans += gcd_two(i,j) * 6;
            }
        }

        //one-one-one
        for(int i = 1;i < K-1;i++){
            for(int j = i+1;j < K;j++){
                for(int k = j+1;k <=K;k++){
                    ans += gcd_three(i,j,k) * 6;
                }
            }
        }
    }
    cout << ans;

    return 0;
}

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

int main() {
	int n;
    cin >> n;
    vector<int> a(n), b(n), counter(n+1, 0);
    vector<int> c(n+1, 0), d(n+1, 0);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        counter[a[i]]++;
        c[a[i]]++;
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
        counter[b[i]]++;
        d[b[i]]++;
    }

    for (int i = 0; i <= n; ++i) {
        if(counter[i] > n) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    for (int i = 0; i < n; ++i) {
        c[i+1] += c[i];
        d[i+1] += d[i];
    }

    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans = max(ans, c[i] - d[i-1]);
    }

    for (int i = 0; i < n; ++i) {
        cout << b[(i + n - ans) % n] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 7176
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N;
	cin >> N;
	int inf = 1e8;
	VV<int> d(N,V<int>(N,inf)); rep(i,N) d[i][i] = 0;
	rep(i,N){
		string s;
		cin >> s;
		rep(j,N) if(s[j] == '1') d[i][j] = 1;
	}
	rep(i,N) rep(j,N) rep(k,N) chmin(d[j][k],d[j][i]+d[i][k]);

	int x=0,y=0;
	rep(i,N) rep(j,N) if(d[x][y] < d[i][j]) x = i, y = j;
	
	rep(i,N) rep(j,N) if(d[i][j] == 1){
		if(abs(d[x][i]-d[x][j]) != 1){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << d[x][y]+1 << endl;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
	int c;
	while (scanf("%d",&c) != EOF){
		c = c % 39;
		if (c == 0){
			c = 39;
		}
		if (c < 10){
			printf("3C0%d\n",c);
		}
		else{
			printf("3C%d\n",c);
		}
	} 
	return 0;
}
//aoj 0148

Measured memory_bytes: 596
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
int D;
int c[27], s[400][27];
int L[27];
int last[27];
long long ANS = 0;
long long ans = 0;
int T[400];
long long test(){
    for (int i = 1; i <= 26; i++){
        last[i] = 0;
    }
    long long ans = 0;
    for (int i = 1; i <= D; i++){
        ans += s[i][T[i]];
        last[T[i]] = i;
        for (int j = 1; j <= 26; j++){
            ans -= c[j]*(i-last[j]);
        }
    }
    return ans;
}
int main(){
    auto begin_time=chrono::steady_clock::now().time_since_epoch().count();
    scanf("%d",&D);
    for (int i = 1; i <= 26; i++) scanf("%d",&c[i]);
    for (int i = 1; i <= D; i++){
        for (int j = 1; j <= 26; j++) scanf("%d",&s[i][j]);
    }
    for (int i = 1; i <= D; i++){
        int b1 = -1;
        long long ok = 0;
        for (int t = 1; t <= 26; t++){
            for (int x = 1; x <= 26; x++){
                for (int y = 1; y <= 26; y++){
                    ans = ANS;
                    for (int j = 1; j <= 26; j++){
                        last[j] = L[j];
                    }

                        ans += s[i][t];
                        last[t] = i;

                        for (int j = 1; j <= 26; j++){
                            ans -= c[j]*(i-last[j]);
                        }

                    if (i != D){
                        ans += s[i+1][x];
                        last[x] = i+1;
                        for (int j = 1; j <= 26; j++){
                            ans -= c[j]*(i+1-last[j]);
                        }
                    }

                    if (i < D-1){
                        ans += s[i+2][y];
                        last[y] = i+2;
                        for (int j = 1; j <= 26; j++){
                            ans -= c[j]*(i+2-last[j]);
                        }
                    }

                    if (b1 == -1 || ans > ok){
                        b1 = t;
                        ok = ans;
                    }
                }
            }
            //printf("for %d: %lld\n",t,ans);
        }
        T[i] = b1;
        ANS += s[i][b1];
        L[b1] = i;
        for (int j = 1; j <= 26; j++){
            ANS -= c[j]*(i-L[j]);
        }
        //printf("%d\n",b1);
        //printf("score %lld\n",ANS);
    }
    long long best = ANS;
    //printf("from %lld\n",best);
    srand(time(NULL));
    while (chrono::steady_clock::now().time_since_epoch().count()-begin_time<1950000000){
        int rD = rand()%365+1;
        int rV = rand()%26+1;
        int oldV = T[rD];
        T[rD] = rV;
        long long cur = test();
        if (cur > best){
            best = cur;
        }
        else{
            T[rD] = oldV;
        }
    }
    //printf("to %lld\n",best);
    for (int i = 1; i <= D; i++){
        printf("%d\n",T[i]);
    }
}


Measured memory_bytes: 3884
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	long long x,k;
	cin >> x >> k;
	if(x>k){
		cout << min(abs((x%k)-k),x%k) << endl;
	}
	else if(x==k) cout << 0 << endl;
	else if(x<k){
		cout << min(x,abs(k-x)) << endl;
	}
	return 0;
} 

Measured memory_bytes: 256
-- Try AtCoder
-- author: Leonardone @ NEETSDKASU

import Data.List (sort)

main = getContents >>= print . solve . map read . words

solve (n:a) = ans where
    f (i, os, es) v = if even i then (i + 1, os, v : es) else (i + 1, v : os, es)
    (_, os, _) = foldl f (div n n, [], []) a
    g c _ _      []     = c
    g c i (x:xs) (y:ys)
        | x < y     = g c       (i + 1) xs (y:ys)
        | even i    = g (c + 1) (i + 1) xs ys
        | otherwise = g c       (i + 1) xs ys
    ans = g 0 1 (sort a) (sort os)


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

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){

}

void solve(){
    
   ll n;
   cin>>n;
   ll sum=0;
   for(ll i=1;i<=n;i++){
       for(ll j=1;j<=n;j++){
           for(ll k=1;k<=n;k++){
               ll g = __gcd(i,j);
               g = __gcd(g,k);
               sum += g;
           }
       }
   }

   cout << sum ;
    
}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3656
import bisect
A,B,Q = map(int,input().split())
S = [-float('inf')]+list(int(input())for i in range(A))+[float('inf')]
T = [-float('inf')]+list(int(input())for i in range(B))+[float('inf')]
x = list(int(input())for i in range(Q))

for i in x:
    si = bisect.bisect_left(S,i)
    ti = bisect.bisect_left(T,i)
    ans = min(max(S[si],T[ti])-i,i-min(S[si-1],T[ti-1]),\
            2*S[si]-i-T[ti-1],2*T[ti]-i-S[si-1],\
             T[ti]+i-2*S[si-1],S[si]+i-2*T[ti-1])
    print(ans)

Measured memory_bytes: 16140
#include <bits/stdc++.h>
#define Phuong ios_base::sync_with_stdio(0); cin.tie(0);
#define mpp make_pair
#define pb push_back

typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<int,int> pii;

/// problem's variable


///--------------------



int main()
{
    Phuong;
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i) cin >> a[i];
    sort(a.begin(),a.end());
    bool can=true;
    for(int i=0; i<n-1; ++i)
        if (a[i]==a[i+1])
    {
        can=false;
        break;
    }
    if (can) cout << "YES"; else cout << "NO";
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
std::vector<int>A['   '];int N,M,S['   '],B,L,R,I;int U(int z,int u){while(z<=N)S[z]+=u,z+=z&-z;}main(){scanf("%d%d",&M,&N);for(;~scanf("%d%d",&L,&R);)A[R-L+1].push_back(L);for(L=1;L<=N;L++){for(B=M,I=L;I<=N;I+=L){for(R=I;R;)B+=S[R],R-=R&-R;}for(int u:A[L])U(u,1),U(u+L,-1),M--;printf("%d\n",B);}}

Measured memory_bytes: 53760
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  long long ans = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a+n);
  if (n == 2) {
    ans = a[1];
  }
  else {
    ans += a[n-1];
    for (int i = n-2; i >= n-1-(n-2)/2; i--) {
      ans += 2*a[i];
    }
  }
  if (n%2 == 1) ans += a[n-2-(n-2)/2];
  cout << ans;
}

Measured memory_bytes: 4476
#include<stdio.h>

int main(){
  int N,M;
  int i,j,k,ans=0;  
  scanf("%d %d",&N,&M);
  int han[N];
  int flg[N][M];
  
  for(i=0;i<N;i++){
    for(j=0;j<M;j++)
      flg[i][j]=0;
  }
  

  for(i=0;i<N;i++){
    scanf("%d ",&han[i]);
    for(j=0;j<han[i];j++){
      scanf("%d ",&k);
      flg[i][k-1] = 1;
    }
  }
  
  for(i=0;i<M;i++){
    for(j=0;j<N;j++){
      if(flg[j][i] == 0)
        break;
    }
    if(j == N)
      ans++;
  }
  
  printf("%d\n",ans);
  return 0;
}


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

#define ll long long

ll n,a[200001],ans,ans1[200001],ans2[200001],c[200001];
map<ll,ll>mp;

int main()
{
//    freopen("a.in","r",stdin);
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
        c[a[i]]++;
    }
    for(ll i=1;i<=n;i++)
    {
        ans1[i]=(c[i]*(c[i]-1))/2;
        ans+=ans1[i];
        if(ans)
            ans2[i]=((c[i]-2)*(c[i]-1))/2;
    }
    for(ll i=1;i<=n;i++)
    {
        cout<<ans-ans1[a[i]]+ans2[a[i]]<<endl;
    }
}




Measured memory_bytes: 7808
from collections import deque

ope={'+':lambda a,b:b+a,'-':lambda a,b:b-a,'*':lambda a,b:b*a}

A=list(map(str,input().split()))

n=len(A)
D=deque()
for i in A:
    if i not in ope:
        D.append(i)
    else:
        D.append(ope[i](int(D.pop()),int(D.pop())))

print(D.pop())


Measured memory_bytes: 6000
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
int64_t INF = 1000000007;
// int64_t INF = 9223372036854775807;
// int64_t INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n;
    cin >> n;
    vi a(1001);
    // 2^a*3^b*...っていう形にして、(a+1) * (b+1) * ...
    for(ll i=2; i<n+1; i++){
        ll k=i;
        for(ll j=2; j<i+1; j++){
            while(k%j==0){
                a.at(j)++;
                k = k/j;
            }
        }
    }
    ll res = 1;
    rep(i,a.size()){
        if(a.at(i)!=0){
            res *= a.at(i)+1;
            res %= INF;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int n,a=0; cin>>n;
  for(int i=1; i<=n; i++){
    int c=0;
    for(int j=1; j<=i; j+=2) if(i%j==0) c++;
    if(c==8) a++; 
  }
  cout<<a;
}

Measured memory_bytes: 3564
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
	char S;
	int R=0;
	for(int i=0;i<4;i++){
		cin>>S;
		if(S=='+')R++;
		if(S=='-')R--;
	}

	cout<<R<<endl;
	return 0;
}


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

int main(void) {
  int A, B;
  cin >> A >> B;
  A = A == 1 ? 14 : A;
  B = B == 1 ? 14 : B;
  if (A < B)
    cout << "Bob" << endl;
  else if (A > B)
    cout << "Alice" << endl;
  else
    cout << "Draw" << endl;
  return 0;
}

Measured memory_bytes: 256