akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ip pair<ll,ll>
#define vii vector<ll>
#define vpp vector<ip>
#define vdd vector<ld>
#define vb vector<bool>
#define pi  pair<ll,ip>
#define sc(x) scanf("%lli",&x)
#define c(x) cin >> x
#define fo(i,k,n) for( int i=k;i<n;i++)
#define hu 200010
#define pq priotity_queue<ll>
#define pqs priority_queue<ll,vii,greater<ll>>
#define ppq priority_queue<ip,vpp,greater<ip>>
#define INF INT_MAX
#define ff first
#define ss second
using namespace std;
const ll M = 1000000000+7;
//Grid Movement
ll dx[] = {-1, 0, 1, 0};
ll dy[] = {0, -1, 0, 1};

ld Pi= acos(-1);

ll lcm(ll a,ll b)
{
    return (a*b)/(__gcd(a,b));
}

ll mex(ll x, ll y) 
{ 
	ll res = 1;	  
	x = x % M; 
	if (x == 0) return 0; 
	while (y > 0) 
	{ 
		if (y & 1) 
		res = (res*x) % M; 
		y = y>>1; 
		x = (x*x) % M; 
	} 
	return res; 
} 

bool comp(ll comp1,ll comp2)
{
    return comp1>comp2;
}

void yes()
{
    printf("YES\n");
}

void no()
{
    printf("NO\n");
}

ll inv(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
 
    if (m == 1)
      return 0;
 
    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
 
    if (x < 0)
       x += m0;
 
    return x;
}

void sieve(ll n)
{
    vii primes(n+1);
    vb is_prime(n+1);
	is_prime.resize(n+1);
	primes.resize(n+1);
 
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i<=n; i++)
	{
	    if(is_prime[i])
	    {
	    	primes.pb(i);
	        for (int j = i*i; j<=n; j+=i)
	            is_prime[j] = false;
	    }
	}
}

void solve()
{
    ll l,r,d,cnt=0;
    sc(l);
    sc(r);
    sc(d);
    for(ll i=l;i<=r;i++)
    {
        if(i%d==0)cnt++;
    }
    printf("%lli\n",cnt);
}

int main()
{
    ll t=1;
 //   sc(t);
    while(t--) solve();
}





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

int main(){
    int n,k;
    cin >> n >> k;
    double ans=0;
    int cnt,j;
    double kouhan;
    for(int i = 1;i < n+1;i ++){
        j = i;
        cnt = 0;
        while(j < k){
            j *= 2;
            cnt ++;
        }
        kouhan = 1;
        for(int x = 0;x < cnt;x ++){
            kouhan /= 2;
        }
        ans += kouhan / n;
    }
    cout << fixed << setprecision(12) << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,K;cin>>N>>K;
  cout << ((N+1)/2>=K? "YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;


int main() {
    int k;
    cin >> k;
    int num = 7;
    int cnt = 1;
    if(7 % k == 0) {
        cout << 1 << endl;
        return 0;
    }
    while(true) {
        if(cnt > k) {
            cout << -1 << endl;
            return 0;
        }
        num = (num * 10 + 7) % k;
        ++cnt;
        if((num == 0)) {
            cout << cnt << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3608
#include <iostream>
using namespace std;
#define CIN(n) int n; cin>>(n);
int main()
{
	char s[5];
	for (int i = 0; i < 4; i++) {
		cin >> s[i];
	}
	int f = 0;
	for (int i = 0; i < 4; i++) {
		if (s[i] == '+')f++;
	}
	int k;
		k = -4 + f * 2;
	cout << k;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
v_l = list(map(int, input().split()))
c_l = list(map(int, input().split()))

sa = []
sum = 0
for i in range(n):
    xy = v_l[i]-c_l[i]
    if xy >0:
        sum = sum+xy

print(sum)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

int main() {
  ll n;
  cin >> n;
  int res = 0;

  for (ll a = 1; a <= n; a++) {
    for (ll b = 1; b <= (n + a - 1) / a; b++) {
      if (n - (a * b) > 0) res++;
    }
  }
  cout << res << endl;
  return 0; 
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
bool exist[200001];
void Calc(){
	int N = rei();
	for(int i=1;i<=N;i++){
		exist[i] = (rei() == 1);
	}
	int d = 0;
	for(int i=N;i>=1;i--){
		int c = 0;
		for(int j=i;j<=N;j+=i){
			if(exist[j]){
				c++;
			}
		}
		exist[i] = (c & 1) == 1;
		if(c & 1){
			d++;
		}
	}
	cout << d << "\n";
	for(int i=1;i<=N;i++){
		if(exist[i]){
			cout << i << " ";
		}
	}
	cout << "\n";
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 1280
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        ArrayList<Task> tasks = new ArrayList<>();
        for (int i = 1; i <= N; i++) {
            tasks.add(new Task(sc.nextInt(), sc.nextInt()));
        }

        Collections.sort(tasks, new Comparator<Task>() {
            public int compare(Task t1, Task t2) {
                return ((Integer)t1.getEnd()).compareTo(t2.getEnd());
            }
        });

        int time = 0;
        boolean isOver = false;
        for (int i = 0; i < N; i++) {
            Task task = tasks.get(i);
            time += task.getCost();
            if (time > task.getEnd()) {
                isOver = true;
                break;
            }
        }

        if (isOver) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }

    private static class Task{
        private int a;
        private int b;

        private Task(int a, int b) {
            this.a = a;
            this.b = b;
        }

        private int getCost() {
            return a;
        }

        private int getEnd() {
            return b;
        }
    }
}

Measured memory_bytes: 160648
A = []
for i in range(6):
    A.append(int(input()))
st = 4 
s = 'Yay!'
for i in range(4): 
    for j in range(st):
        if A[st] - A[st-1-j] > A[5]:
            s = ':('
    if s == ':(':
        break
    st -= 1
print(s)


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

#define likely(x)   __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)

using LL = int;
inline LL R(){
    char c='!';LL x=0,z=1;
    for( ; c>'9'||c<'0';c=getchar()) if(c=='-')z=-1;
    for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
    return x*z;
}

int main(void) {
  int n;

  std::cin >> n; /* 1 to 3*10^5 */

  size_t A[n];

  //int* A = new int[n];
  for (size_t i = 0; i < n; i++) {
    A[i] = R();
    //std::cin >> A[i];
  }

  size_t count = 0;

  size_t lsum = 0;
  size_t rsum = 0;
  size_t l, r;
  size_t offset = 0;
  size_t i = 0;
  while(i < n) {
    size_t lcount = 0;
    for (size_t j = i + offset; j < n; ++j) {
      l = lsum ^ A[j];
      r = rsum + A[j];
      if (likely(l != r)) {
        break;
      }
      lcount++;
      lsum = l;
      rsum = r;
    }

    count += lcount + offset;

    offset += lcount;
    if (unlikely(offset)) {
      --offset;
    }

    lsum ^= A[i];
    rsum -= A[i];
    ++i;
  }

  std::cout << count << std::endl;;

  return 0;
}

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

int main(){
  int N;
  int a=0, b=0, c=0, d=0;
  cin >> N;
  vector<string> strs(N);
  for(int i=0; i<N; i++){
    cin >> strs.at(i);
  }
  
  for(string s : strs){
    if(s == "AC") a++;
    else if(s == "WA") b++;
    else if(s == "TLE") c++;
    else if(s == "RE") d++;
  }
  
  cout << "AC x " << a << endl;
  cout << "WA x " << b << endl;
  cout << "TLE x " << c << endl;
  cout << "RE x " << d << endl;
}

Measured memory_bytes: 6372
#include<string>
#include<cctype>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
#define inf 0x3f3f3f3f
const int maxn = 200000 + 8;

int a[maxn];
int n;

int main()
{
    scanf("%d",&n);
    for(int i = 0; i < n; ++i){
        scanf("%d",&a[i]);
    }

    int minv = a[0];
    int maxv = -2000000000;
    for(int i = 1; i < n; ++i){
        maxv = max(maxv,a[i] - minv);
        minv = min(minv,a[i]);
    }
    printf("%d\n",maxv);
    return 0;
}

Measured memory_bytes: 3984
s = input()
n = len(s)

a = [0]*(n)

rc = 1
lc = 0

q = []

for i in range(1,n):
    if rc > 0:
        if s[i] == 'R':
            rc +=1
        else:
            a[i-1] += (rc // 2) + (rc % 2)
            a[i] += rc // 2 
            q.append(i)
            rc = 0
            lc += 1
            if i == n-1:
                a[n-1] += 1
    elif lc > 0:
        if s[i] == 'L':
            lc += 1
            if i == n-1:
                j = q.pop()
                a[j-1] += (lc // 2)
                a[j] += lc // 2 + (lc%2)
        else:
            j = q.pop()
            a[j] += (lc //2) + (lc%2)
            a[j-1] += lc // 2            
            lc = 0
            rc = 1


a = map(str,a)
print(' '.join(a))
            

Measured memory_bytes: 50672
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;
 
int main(){
    int n;
    cin>>n;
    vector<char> s(n);
    rep(i,n) cin>>s[i];
    set<int> l;
    rep(i,n) l.insert((int)s[i]);
    
    if(l.size() == 4) cout<<"Four"<<endl;
    else cout<<"Three"<<endl;
    return 0;
}


Measured memory_bytes: 256
n,k = list(map(int, input().split()))#n = 払いたい金額  k = 嫌いな数字の個数（len(ln)）
ln = list(map(int, input().split()))
pay = n

while True:
    counter = 0
    for i in str(pay):
        if int(i) in ln:
            counter +=1
    if counter == 0:
        print(pay)
        break
    else:
        pay += 1
        
            
            

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

int main(void) {
    int N, K;
    std::cin >> N >> K;
    int A[200];
    for (int i = 0; i < N + 10; i++) {
        A[i] = 0;
    }
    for (int i = 0; i < K; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            ++A[a - 1];
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] == 0) {
            ++ans;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 3764
<?php
fscanf(STDIN, '%s', $s);
$n = strlen($s);
$ans = 'Yes';
for ($i = 0; $i < $n; $i++) {
    if (($i % 2 === 0 && $s[$i] === 'L') || ($i % 2 === 1 && $s[$i] === 'R')) {
        $ans = 'No';
        break;
    }
}
echo $ans . PHP_EOL;

Measured memory_bytes: 4728
import java.util.*;
public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long N=sc.nextInt();
      	long ans=0;
      	long all=1;
      	long minas=1;
      	long plus=1;
      	long mod=1000000007;
      	for(int i=0;i<N;i++){
          all=all*10%mod;
          minas=minas*9%mod;
          plus=plus*8%mod;
        }
		ans=all-minas*2+plus;
      	ans%=mod;
      	ans=(ans+mod)%mod;
		System.out.println(ans);
	}
}



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

using namespace std;


int main(){
    
    
    int N,M;
    cin >> N >> M;
    vector<int> P(M), Y(M);
    pair<pair<int, int>, int> city[M];
    
    for (int i = 0; i < M; i++) {
        cin>>P[i]>>Y[i];
        city[i].first.first = P[i];
        city[i].first.second = Y[i];
        city[i].second = i;
    }
    
    sort(city, city+M);
    
    
    pair<int, pair<int, int> > num[M];
    
    int kk = 1;
    for (int i = 0; i<M; i++) {
        num[i].first = city[i].second;
        num[i].second.first = city[i].first.first;
        num[i].second.second = kk;
       
        
        if (i != M-1 && city[i].first.first == city[i+1].first.first) {
            kk += 1;
        }else if(i != M-1 && city[i].first.first != city[i+1].first.first){
            kk = 1;
        }
        
    }
    
    
    
    sort(num, num+M);
    
    
    
    for (int i = 0; i < M; i++) {
        cout.fill('0');
        cout << setw(6) << num[i].second.first;
        cout << setw(6) << num[i].second.second << endl;;
        
    }
    
}


Measured memory_bytes: 4608
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int X,Y;

    private void solve() {
        X = nextInt();
        Y = nextInt();

        int ans = X + Y / 2;

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21204
n,m=map(int,input().split())
q=[]
for i in range(m):
    s=list(map(int,input().split()))
    res=0
    for i in range(s[0]):
        res+=2**(s[i+1]-1)
    q.append(res)
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    cnt=0
    for j in range(m):
        cnt0=0
        for k in range(n):
            if ((q[j]&i)>>k)&1==1:
                cnt0+=1
        if cnt0%2==p[j]:
            cnt+=1
        else:
            break
    if cnt==m:
        ans+=1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  long long x, money = 100, year = 0;
  cin >> x;
  while(x>money) {
    money*=1.01;
    year++;
  }
  cout << year << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cmath>
#include <map>

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  int k;
  string s;
  cin >> k;
  cin >> s;
  
  if (s.size() <= k) {
    cout << s << endl;
  } else {
    string temp = s.substr(0, k);
    temp.push_back('.');
    temp.push_back('.');
    temp.push_back('.');
    cout << temp << endl;
  }
  return 0; 
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int a[10005];
int read() {
	char c=getchar(); int x=0,f=1;
	while (c<'0' || c>'9') {
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int main() {
	int n=read(),x=read();
	for (int i=1; i<=n; i++) a[i]=a[i-1]+read();
	int ans=0;
	for (int i=1; i<=n; i++) if (a[i]<=x) ++ans;
	printf("%d\n", ans+1);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

#define all(x) begin(x),end(x)

using namespace std;

template<typename T>
T gcd(T a, T b) {
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

bool search(vector<int> &A, int depth, int res, int M) {
    if (depth == A.size()) {
        return false;
    }

    int new_res = res + A[depth];
    if (new_res == M) {
        return true;
    }
    bool t1 = search(A, depth+1, new_res, M);
    if (t1) {
        return true;
    }
    bool t2 = search(A, depth+1, res, M);
    if (t2) {
        return true;
    }

    return false;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    int Q;
    cin >> Q;
    vector<int> M(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> M[i];
    }

    for (int i = 0; i < Q; ++i) {
        bool t = search(A, 0, 0, M[i]);
        if (t) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = INT32_MAX;
const ll INFL = INT64_MAX;
const int mod = 1e9 + 7;

template <typename T>
void print_vec(vector<T> v) {
  for (T i : v) cout << i << " ";
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  map<string, vector<P> > r;
  map<string, int> cities;
  rep(i, n) {
    string s;
    int p;
    cin >> s >> p;
    cities[s] = p;
    r[s].push_back(P(p, i + 1));
  }
  for (auto c : cities) {
    auto list = r[c.first];
    sort(list.rbegin(), list.rend());
    for (P p : list) {
      // cout << p.first << endl;
      cout << p.second << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var N = sc.nextInt();
        var A = sc.ArrayLong(N);
        var L = new long[N+1];
        var R = new long[N+1];
        for (int i = 0; i < N; i++) {
            L[i+1] = Gcd(L[i], A[i]);
        }
        for (int i = N-1; i >= 0; i--) {
            R[i] = Gcd(R[i + 1], A[i]);
        }

        var ans = 1L;
        for (int i = 0; i < N; i++) {
            ans = Math.Max(Gcd(L[i], R[i + 1]), ans);
        }
        WriteLine(ans);

    }

    public long Lcm(long a, long b) {
        return a * b / Gcd(a, b);
    }

    public long Gcd(long a, long b) {
        if (a < b)
            return Gcd(b, a);
        while (b != 0) {
            var tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }
}

class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 24924
package main

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

const (
	maxBufSize = 1024 * 1024
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, 1)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	out = bufio.NewWriter(os.Stdout)
)

func square(n int64) int64 {
	return n * n
}

func subSolve(as []int64, avg int64) int64 {
	ret := int64(0)
	for _, a := range as {
		ret += square (a - avg)
	}
	return ret

}

func solve(n int64, as []int64) int64 {
	if n == 1 {
		return 0
	}

	if n == 2 {
		return subSolve(as, (as[0] + as[1]) / 2)
	}
	sum := int64(0)
	for _, a := range as {
		sum += a
	}
	avg1 := sum / n
	var avg2  int64
	if sum > 0 {
		avg2 = (sum + n - 1) / n
	} else {
		avg2 = (sum - n + 1) / n
	}

	ret1 :=  subSolve(as, avg1)
	ret2 :=  subSolve(as, avg2)
	if ret1 < ret2 {
		return ret1
	}
	return ret2
}

func main() {
	defer out.Flush()

	n := nextInt()
	as := nextInts(n)
	res := solve(n, as)
	fmt.Fprintln(out, res)
}

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

func nextStringAsBytes() []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

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

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

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


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

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

    int ans = 0;
    int outlet = 1;

    while(outlet < B) {
        --outlet;
        outlet += A;
        ++ans;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	string S;

	cin >> S;

	long long x =
	(S[0] - '0')*10000000 +
	(S[1] - '0')*1000000 +
	(S[2] - '0')*100000 +
	(S[3] - '0')*10000 +
	(S[5] - '0')*1000 +
	(S[6] - '0')*100 +
	(S[8] - '0')*10 +
	(S[9] - '0')*1;

	if(x <= 20190430){
		cout << "Heisei" << endl;
	} else {
		cout << "TBD" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	if n >= 30 {
		Fprintln(out, "Yes")
	} else {
		Fprintln(out, "No")
	}
}

func main() { run(os.Stdin, os.Stdout) }


Measured memory_bytes: 1848
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<limits.h>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
using namespace std;

long long  mod = 1000000007;

long max(long x, long y) {
	return x > y ? x : y;
}

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

long factorial(long n) {
	if (n == 1) {
		return 1;
	}
	else {
		return n * factorial(n - 1);
	}
}

long long  fel(long long  n,long long  f) {

		if (f == 1) {
			return n % mod;
		}
		else if (f % 2 == 0) {
			return (fel(n,f / 2) * fel(n,f / 2)) % mod;
		}
		else {
			return ((n  * fel(n,f / 2) %mod) * fel(n,f / 2))% mod;
		}
	

}


int main(){
	
	int a, b;
	
	cin >> a;
	cin >> b;

	
	cout << a * b;

}







Measured memory_bytes: 3184
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
#include <math.h>
const int INF = 1e9+7;

int main(int argc, char **argv)
{
	double r;
	scanf("%lf", &r);
	printf("%f %f\n", M_PI*r*r, 2*M_PI*r);
	return 0;
}

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  cout << (N-1) / 2 << endl;

  return 0;
}



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

#define INF 1e9

vector<int> split_s2i(const std::string &str, char sep){
  vector<int> v;
  stringstream ss(str);
  string buffer;
  while(getline(ss, buffer, sep)){ v.push_back(stoi(buffer)); }
  return v;
}

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

  vector<vector<int> > dp(n, vector<int>(n, INF));
  string input;
  for(int i = 0; i < m; i++){
    cin >> input;    
    vector<int> inp = split_s2i(input, ',');
    dp[inp[0] - 1][inp[1] - 1] = inp[2];
    dp[inp[1] - 1][inp[0] - 1] = inp[3];
  }
  for(int i = 0; i < n; i++)
    dp[i][i] = 0;

  // ???????????£???????????????
  for(int k = 0; k < n; k++)
    for(int i = 0; i < n; i++)
      for(int j = 0; j < n; j++)
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);  

  // ?????¨?????????
  cin >> input;
  vector<int> query = split_s2i(input, ',');
  int s = query[0] - 1;
  int g = query[1] - 1;
  int v = query[2];
  int p = query[3];
  int ans = v - (dp[s][g] + p + dp[g][s]);

  // ??????
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3156
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)

signed main(){
    int X,A,B;

    cin>>X>>A>>B;

    if(B-A<=X&&B-A>0) cout<<"safe"<<endl;
    else if(B-A<=0) cout<<"delicious"<<endl;
    else cout<<"dangerous"<<endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    char s[101], t[101];

    scanf("%s%s", s, t);

    int lens = strlen(s), lent = strlen(t);

    for(int i = 0; i < lens; i++){
        for(int j = i+1; j < lens; j++){
            char k[2];
            if(s[i] > s[j]){
                k[0] = s[i];
                s[i] = s[j];
                s[j] = k[0];
            }
        }
    }

    for(int i = 0; i < lent; i++){
        for(int j = i+1; j < lent; j++){
            char l[2];
            if(t[i] < t[j]){
                l[0] = t[i];
                t[i] = t[j];
                t[j] = l[0];
            }
        }
    }

    if(strcmp(s, t) < 0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1648
from sys import stdin
from collections import defaultdict
from heapq import heappush, heappop

N, K = [int(x) for x in stdin.readline().rstrip().split()]
S = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
d = defaultdict(list)

for i in range(N):
    S[i][0] -= 1
    d[S[i][0]].append(S[i][1])

max_d = [None] * N

for k, v in d.items():
    max_d[k] = max(v)

S.sort(key=lambda x: x[1], reverse=True)
priority_queue1 = []
flag = [0] * N
ans = 0

for ti, di in S[:K]:
    ans += di
    flag[ti] = 1

    if di != max_d[ti]:
        heappush(priority_queue1, di)

syuruisuu = flag.count(1)
ans += syuruisuu ** 2
ans_l = [ans]
priority_queue2 = []

for i in range(N):
    if flag[i] == 0 and max_d[i] != None:
        heappush(priority_queue2, -max_d[i])

while len(priority_queue1) and len(priority_queue2):
    add_sushi = -heappop(priority_queue2)
    remove_sushi = heappop(priority_queue1)
    ans_cand = ans_l[-1] - syuruisuu**2 + (syuruisuu+1)**2 + add_sushi - remove_sushi
    ans_l.append(ans_cand)
    syuruisuu += 1

print(max(ans_l))

Measured memory_bytes: 85340
#![allow(non_snake_case, unused)]
use std::io::*;
use std::str::FromStr;
use std::collections::*;

const MOD: i64 = 1000000007;

fn main() {
    let cin = stdin();
    let mut sc = Scanner::new(cin.lock());

    let n: usize = sc.next();
    let a: Vec<i64> = sc.vec(n);
    let init: i64 = 0;

    let cs = cumulative_sum::CumulativeSum1D::new(&a, init);
    let mut ans = 0;
    for i in 0..(n - 1) {
	let tmp = a[i] * (cs.get_sum(i + 1, n - 1) % MOD);
	let tmp = tmp % MOD;
	ans += tmp;
	ans %= MOD;
    }
    println!("{}", ans);
}

pub mod cumulative_sum {
    pub struct CumulativeSum1D<T> {
	n: usize,
	sums: Vec<T>,
    }

    impl<T> CumulativeSum1D<T>
    where
    T: Copy + std::ops::Add<Output = T> + std::ops::Sub<Output = T> {
	pub fn new(base: &Vec<T>, init: T) -> CumulativeSum1D<T> {
	    let n = base.len();
	    let mut sums = vec![init; n + 1];
	    for i in 1..=n {
		sums[i] = sums[i - 1] + base[i - 1];
	    }
	    CumulativeSum1D { n, sums }
	}

	pub fn get_sum(&self, from: usize, to: usize) -> T {
	    assert!(from <= to);
	    assert!(to < self.n);
	    self.sums[to + 1] - self.sums[from]
	}
    }
}


// Scanner
struct Scanner<R: std::io::Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
	Scanner { reader: reader }
    }

    fn read<T: FromStr> (&mut self) -> Option<T> {
	let token = self
	    .reader
	    .by_ref()
	    .bytes()
	    .map(|c| c.unwrap() as char)
	    .skip_while(|c| c.is_whitespace())
	    .take_while(|c| !c.is_whitespace())
	    .collect::<String>();
	if token.is_empty() {
	    None
	} else {
	    token.parse::<T>().ok()
	}
    }

    fn next<T: FromStr>(&mut self) -> T {
	if let Some(s) = self.read() {
	    s
	} else {
	    writeln!(stderr(), "Terminated with EOF").unwrap();
	    std::process::exit(0);
	}
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
	(0..n).map(|_| self.next()).collect()
    }

    fn char(&mut self) -> char {
	self.next::<String>().chars().next().unwrap()
    }
}


Measured memory_bytes: 5180
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>(b);--i)
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
  ll n,m,ans=0;cin>>n>>m;
  vll h(n);
  vb ok(n,true);
  rep(i,0,n){cin>>h[i];}
  rep(i,0,m){
    ll a,b;cin>>a>>b;
    a--;b--;
    if(h[a]>h[b]){ok[b]=false;}
    if(h[a]<h[b]){ok[a]=false;}
    if(h[a]==h[b]){ok[a]=false;ok[b]=false;}
  }
  rep(i,0,n){
    if(ok[i]){ans++;}
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 4000
def f_select_half():
    # 参考: https://at274.hatenablog.com/entry/2020/04/14/002124
    from collections import defaultdict
    N = int(input())
    A = [int(i) for i in input().split()]

    # dp[(i, j, flag)]: A の i 番目の要素まで見たとき、j 個の要素を選んでいるときの和の最大値
    # flag == 1 のときは、i 番目の要素を採用したものとする
    # 初めて指した遷移前が影響してほしくないので、この値で初期化
    dp = defaultdict(lambda: -float('inf'))
    dp[(0, 0, 0)] = 0

    for k, a in enumerate(A, 1):
        j = k // 2
        for x in range(j - 1, j + 2):
            dp[(k, x, 0)] = max(dp[(k - 1, x, 0)], dp[k - 1, x, 1])
            # k-1 番目の要素を選んでいないときだけ、k 番目の要素を選べる
            dp[(k, x, 1)] = dp[(k - 1, x - 1, 0)] + a
    return max(dp[(N, N // 2, f)] for f in (0, 1))

print(f_select_half())

Measured memory_bytes: 300340
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long N, power = 1; cin >> N;
    rrep (i, 1, N) {
        power = power * i % MOD;
    }
    cout << power << endl;
}

Measured memory_bytes: 256
N = gets.to_i

strings = Hash.new {0}

N.times.map do
  sorted = gets.chomp.chars.sort.join
  strings[sorted] += 1
end

ans = 0

strings.each do |k, v|
  if v >= 2
    (1..v-1).each do |i|
      ans += i
    end
  end
end

puts ans


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

int main() {
  int N;
  cin >> N;
  int ans = 1;
  for (int i = 2; i * i < N; i++) {
    for (int j = i; j <= N; j *= i) {
      ans = max(ans, j);
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3552
const Main = input => {
  const S_list = input.split('\n');
  const N = Number(S_list.shift());
  //if(S_list.slice(-1) === '') S_list.pop();
  const set = new Set(S_list);
  set.delete('');
  console.log(set.size);
};

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
/*Main(`3
apple
orange
apple`);
Main(`5
grape
grape
grape
grape
grape`)
Main(`4
aaaa
a
aaa
aa`);*/


Measured memory_bytes: 54464
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=80;
int a[N];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	ll yen=1000;
	for(int i=1;i<=n;i++)
	{
		int st=i;
		while(i+1<=n&&a[i+1]>=a[i])i++;
		ll num=yen/a[st];
		yen=yen+num*(a[i]-a[st]);
	}
	printf("%lld\n",yen);
	return 0;
}


Measured memory_bytes: 3812
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define D 1000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.14159265358979323
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"
 
ll dp[305][305];

int main() 
{
    FAST;
    ll n,k;
    cin>>n>>k;
    ll a[n+1];
    a[0]=0;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=0;i<305;i++)
        for(int j=0;j<305;j++)
            dp[i][j]=C;
    dp[0][0]=0;
    dp[1][0]=a[1];
    for(int i=2;i<=n;i++)
        for(int j=0;j<i;j++)
            for(int p=i-1;p>=i-j-1;p--)
                if(dp[p][p-i+1+j]!=C)
                    dp[i][j]=min(dp[i][j],dp[p][p-i+1+j]+max(0ll,a[i]-a[p]));
    ll ans=C;
    for(int i=n;i>=n-k;i--)
        ans=min(ans,dp[i][k+i-n]);
    cout<<ans;
    subt;
    return 0;
}

Measured memory_bytes: 1024
# Initializing variables
strA, strB = input().split()
Aballs, Bballs = map(int, input().split())
u = input()

# Calculating remaining balls
if u == strA:
    print(str(int(Aballs - 1)) + " " + str(Bballs))
else:
    print(str(Aballs) + " " + str(int(Bballs - 1)))

# Check out my Youtube channel! https://www.youtube.com/channel/UCMOKVyAbTZOpKikTrX5dy_A


Measured memory_bytes: 2940
N, Y = map(int, input().split())

x = -1
y = -1
z = -1

for i in range(N + 1):
    for j in range(N - i + 1):
        if (0 <= N - i - j) and (Y == 10000 * i + 5000 * j + 1000 * (N - i - j)):
            x = i
            y = j
            z = N - i - j

print(x, y, z)

Measured memory_bytes: 3188
#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() {
  ll n;
  int k;
  cin >> n >> k;
  vector<ll> p(n);
  vector<ll> c(n);
  rep(i,n){
    cin >> p[i];
    p[i]-=1;
  }
  rep(i,n){
    cin >> c[i];
  }
  ll res=-10000000000000;
  vector<ll> r(n,0);
  rep(i,n){
    if (r[i]==0){
      vector<ll> a;
      ll b=i;
      while (r[b]==0){
        a.push_back(b);
        r[b]=1;
        b=p[b];
      }
      ll y=0;
      rep(z,a.size()){
        y+=ll(c[a[(z)%a.size()]]);
      }
      if(y>0){
        rep(j,a.size()){
          ll x=0;
          int h=0;
          if((k/a.size()-1)>0)  h=k/a.size()-1;
          x+= h*y;
          rep(z,k-a.size()*h){
            x+=ll(c[a[(j+z)%a.size()]]);
            if (x>res) res=x;
          }
        }
      }else{
        rep(j,a.size()){
          ll x=0;
          rep(z,a.size()){
            x+=ll(c[a[(j+z)%a.size()]]);
            if (x>res) res=x;
          }
        }
      }



    }
  }
  cout << res << endl;
  return 0;
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;


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

  d *= 2;
  d++;

  ll res = n/d;
  if(n%d != 0) res++;

  cout << res << endl;



  return 0;
}



Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.*;
import java.awt.*;
import java.awt.geom.*;
import java.math.*;
import java.text.*;
import java.math.BigInteger.*;
import java.util.Arrays; 

public class   Main
{
  BufferedReader in;
  StringTokenizer as;
  int nums[],nums2[];
  int[] nums1[];
  boolean con = true;
 
  ArrayList < Integer >  ar = new ArrayList < Integer >();
  ArrayList < Integer >  fi = new ArrayList < Integer >();
  Map<Integer,Integer > map = new HashMap<Integer, Integer>();
  public static void main (String[] args)
  {
    new Main  ();
  }
  
  public int GCD(int a, int b) {
    if (b==0) return a;
    return GCD(b,a%b);
  }
  
  
  
  
  
  public Main  ()
  {
    try
    {
      
      in = new BufferedReader (new InputStreamReader (System.in));
      int a = nextInt();
      int b = nextInt()-1;
      String c = nextLine();
      System.out.println(c.substring(0,b) + (char)(c.charAt(b)+32) + c.substring(b+1));
      
    }
    catch(IOException e)
    {

    }
  }
  
  
  
  
  
  
  
  String next () throws IOException
  {
    while (as == null || !as.hasMoreTokens ())
    {
      as = new StringTokenizer (in.readLine ().trim ());
    }
    
    
    return as.nextToken ();
  }
  
  
  
  long nextLong () throws IOException
  {
    return Long.parseLong (next ());
  }
  
  
  int nextInt () throws IOException
  {
    return Integer.parseInt (next ());
  }
  
  
  double nextDouble () throws IOException
  {
    return Double.parseDouble (next ());
  }
  
  
  String nextLine () throws IOException
  {
    return in.readLine ().trim ();
  }
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
int N; 
cin >> N;
int a[314159], b[314159]; 
for(int i = 0; i < N; i++){
cin >> a[i];
b[i] = a[i] - (i+1);
}
sort(b, b + N);
long long int M; 
for(int j = 0; j< N; j++){
M += abs(b[(N - 1) / 2] - b[j]); 
}
cout << M << endl;
} 

Measured memory_bytes: 2688
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;

ll A, B, C;

int main(){
	scanf("%lld %lld %lld", &A, &B, &C);
	printf("%lld\n", B + C - max(C - (A + B + 1), 0LL));
	return 0;
}

Measured memory_bytes: 128
def nCkpow(n,k):
    if n<k:
        return 0
    y=1
    for i in range(k):
        y*=n-i
        y//=i+1
        y*=9
    return y
def f(s,m,k):
    #print(m,k)
    if len(s)-m<k:
        return 0
    if  k==0:
        return 1
    if s[m]=='0':
        return f(s,m+1,k)
    l=len(s)-m
    y=nCkpow(l-1,k)
    y+=(int(s[m])-1)*nCkpow(l-1,k-1)
    return y+f(s,m+1,k-1)
N=input()
K=int(input())
print(f(N,0,K))

Measured memory_bytes: 9096
#include <stdio.h>
#define A 20
#define M 200


int solve(int, int);
int n,a[A],f=0;

main()
{

  int i,j;
  int b[M];
  int q;
  
  scanf("%d",&n);
  
  for(i = 0; i < n; i++){
    scanf("%d",&a[i]);
  }

  scanf("%d",&q);
  
  for(j = 0; j < q; j++){
    scanf("%d",&b[j]);
  }
  
  
  for(i = 0; i < q; i++){
    f =0;
    solve(0,b[i]);

      
      
    if(f == 1){   
      printf("yes\n");
    }
    else  {
      printf("no\n");
    }
  }

  return 0;
}


int solve(int i, int m)
{

  if(m == 0){
    f = 1;
 
  return 1;
  }
  
  else if(i < n){
    solve(i+1, m);
    solve(i+1, m - a[i]);
  }
}

Measured memory_bytes: 580
from math import ceil, floor
from fractions import gcd

A, B, C, D = map(int, input().split())

def div_count(n, p, q):
  lcm = p*q // gcd(p, q)
  return n - n//p - n//q + n//lcm

print(div_count(B, C, D) - div_count(A-1, C, D))

Measured memory_bytes: 5048
#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 rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}
class S{
	public:
	lli w,s,v;
	S(){
		w=0,s=0,v=0;
	}
	S(lli a,lli b,lli c){
		w=a;
		s=b;
		v=c;
	}
};
bool cmp(S a, S b){
	return a.s+a.w<b.s+b.w;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	lli maxw=0;
	vector<S> vv(n);
	for(int i=0;i<n;i++){
		lli w,s,v;
		cin>>w>>s>>v;
		setmax(maxw,s+w);
		vv[i]=S(w,s,v);
	}
	sort(all(vv),cmp);
	vector<lli> dp(maxw+1);
	for(int i=0;i<n;i++){
		vector<lli> newdp=dp;
		for(int w = 0;w+vv[i].w<=maxw&&w<=vv[i].s;w++){
			setmax(newdp[w+vv[i].w],dp[w]+vv[i].v);
		}
		dp=newdp;
	}
	cout<<*max_element(all(dp))<<endl;
}


Measured memory_bytes: 640
def solve():
    N, *A = map(int, open(0).read().split())
    B = [a for a in A if a % 2 == 0]
    
    for b in B:
        if b % 3 != 0 and b % 5 != 0:
            print('DENIED')
            exit()
    print('APPROVED')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] x = new int[n];
		for (int i = 0; i < n; ++i)
			x[i] = sc.nextInt();

		long all = 0;
		for (int i = 0; i < n; ++i)
			all += x[i];
		SegmentTree seg = new SegmentTree(n + 1);
		for (int i = 0; i < n; ++i) {
			long pre = seg.query(0, x[i]);
			seg.set(x[i], pre + x[i]);
		}
		long fix = seg.query(0, n + 1);
		System.out.println(all - fix);
	}

	static class SegmentTree {
		int n = 1;
		long[] val;

		public SegmentTree(int n) {
			while (this.n < n)
				this.n *= 2;
			val = new long[2 * this.n - 1];
		}

		void set(int k, long l) {
			k += n - 1;
			val[k] = l;
			while (k > 0) {
				k = (k - 1) / 2;
				val[k] = Math.max(val[2 * k + 1], val[2 * k + 2]);
			}
		}

		long query(int a, int b) {
			return query(a, b, 0, n, 0);
		}

		long query(int a, int b, int l, int r, int k) {
			if (r <= a || b <= l)
				return 0;
			else if (a <= l && r <= b) {
				return val[k];
			} else {
				long vl = query(a, b, l, (l + r) / 2, 2 * k + 1);
				long vr = query(a, b, (l + r) / 2, r, 2 * k + 2);
				return Math.max(vl, vr);
			}
		}
	}
}

Measured memory_bytes: 69516