akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
using Tree = vector<vector<int>>;

int N;
vector<long long> D;
map<long long, int> dtoi;
vector<int> subtree_size;

long long rec(const Tree &G, int v) {
    long long res = 0;
    for (auto c : G[v]) {
        res += rec(G, c) + subtree_size[c];
    }
    return res;
}

void solve() {
    subtree_size.assign(N, 1);
    vector<int> par(N, -1);
    Tree G(N);

    // greedy from leaves
    sort(D.begin(), D.end(), greater<long long>());
    for (int i = 0; i < N-1; ++i) {
        int id = dtoi[D[i]];
        int s = subtree_size[id];
        long long l = N - s * 2;
        long long nextD = D[i] - l;


        //cout << D[i] << ", " << id << ": " << s << ", " << l << ", " << nextD << endl;
        
        if (!dtoi.count(nextD)) {
            cout << -1 << endl;
            return;
        }
        int nid = dtoi[nextD];
        par[id] = nid;
        subtree_size[nid] += subtree_size[id];
        G[nid].push_back(id);
    }

    // final check
    long long DD = rec(G, dtoi[D.back()]);
    if (DD != D.back()) {
        cout << -1 << endl;
        return;
    }

    // output
    for (int i = 0; i < N; ++i) {
        if (par[i] == -1) continue;
        cout << i+1 << " " << par[i]+1 << endl;
    }
}

int main() {
    cin >> N;
    D.resize(N);
    for (int i = 0; i < N; ++i) cin >> D[i], dtoi[D[i]] = i;
    solve();
}
    


Measured memory_bytes: 19072
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int H,W;
main()
{
	cin>>H>>W;
	vector<pair<int,bool> >A;
	for(int i=0;i<H+W;i++)
	{
		int a;cin>>a;
		A.push_back(make_pair(a,i<H));
	}
	sort(A.begin(),A.end());
	long ans=0;
	int s=H+W;
	for(int i=0;i<s;i++)
	{
		if(!A[i].second)
		{
			ans+=1L*A[i].first*(H+1);
			W--;
		}
		else
		{
			ans+=1L*A[i].first*(W+1);
			H--;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2420
<?php
while ($line = fgets(STDIN)) {
    $data = explode(" ", rtrim($line)); 
    if($data[1] == '+') printf("%d\n", $data[0] + $data[2]);
    if($data[1] == '-') printf("%d\n", $data[0] - $data[2]);
    if($data[1] == '/') printf("%d\n", $data[0] / $data[2]);
    if($data[1] == '*') printf("%d\n", $data[0] * $data[2]);
    if($data[1] == '?') exit();
}

Measured memory_bytes: 15520
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FASTIO ios::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())

int main() {
    FASTIO;
    int n, d, cnt = 0;
    cin >> n >> d;
    rep(i, n) {
        ll x, y;
        cin >> x >> y;
        if(sqrt(x * x + y * y) <= d) cnt++;
    }
    cout << cnt << "\n";
}


Measured memory_bytes: 3600
n = [int(c) for c in input()]

ans = 7
plus = "+"
minus = "-"
equal = "="
func = ""
for i in range(1 << 3):
    op = []
    for j in range(3):
        op.append(plus if i & (1 << j) else minus)
    calc = n[0]
    for j in range(3):
        if op[j] == plus:
            calc += n[j + 1]
        else:
            calc -= n[j + 1]
    if calc == ans:
        func = str(n[0])
        for j in range(3):
            func += op[j] + str(n[j + 1])
        func += equal + str(ans)
        break

print(func)

Measured memory_bytes: 3064
n = int(input())
a = [int(x) for x in input().split()]

res = 0

find = a[0]
cnt = {a[0]: 0}
for v in a:
  if v not in cnt:
    cnt[v] = 0
  cnt[v] += 1

for k,v in cnt.items():
  if v >= k:
    res += v - k
  else:
    res += v

print(res)


Measured memory_bytes: 18168
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;
using namespace std;

int main() {
	int K;
	cin >> K;
	string S;
	for (int i = 0; i < K; i++) {
		S += "ACL";
	}
	cout << S << endl;
}


Measured memory_bytes: 3032
n = int(input())
if n<0:
    x = abs(n*2)
else:
    x = n
for i in range(1,100):
    if x<=(4**i-1)//3:
        ord = 2*i-1
        break
dif = -x
ans = []
for i in range(ord-1,-1,-1):
    if i%2 == 0:
        if dif < -(2**i-1)//3:
            ans.append(1)
            dif += 2**i
        else:
            ans.append(0)
    else:
        if dif > 2*(2**(i-1)-1)//3:
            ans.append(1)
            dif -= 2**i
        else:
            ans.append(0)
if n<0:
    del ans[-1]
print(*ans,sep="")

Measured memory_bytes: 3064
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <=0){
                return false;
            }
        }
        return true;
    }

    private int readByte(){
        if(hasNextByte())return buffer[ptr++];
        else return -1;
    }

    private static boolean isPrintableChar(int c){
        return 33<=c && c<=126;
    }
    public boolean hasNext(){
        while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;
        return hasNextByte();
    }

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

    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b<='9'){
                n*=10;
                n+=b-'0';
            }else if(b==-1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDoutble(){return Double.parseDouble(next());}
}
public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        int[] l = new int[n];
        for(int i=0;i<n;i++)l[i] = fs.nextInt();
        Arrays.sort(l);
        int res = 0;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                int lb = j;
                int rb = n;
                while(rb-lb>1){
                    int mid = (lb+rb)/2;
                    if(l[mid]>=l[i]+l[j]){
                        rb = mid;
                    }else{
                        lb = mid;
                    }
                }
                res+=(lb-j);
            }
        }
        System.out.println(res);
    }
}

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

int main() {
  int n,m;
  long long ans=1;
  cin>>n>>m;
  int b[m];
  rep(i,m){
    cin>>b[i];
    if(i>0&&b[i]==b[i-1]+1)
      ans=0;
  }
  if(ans==0)
    cout<<ans<<endl;
  
  
  else{
    long long a[n];

    a[0]=1;a[1]=1;
    rep(i,n-1){
      a[i+2]=a[i]+a[i+1];
      a[i+2]%=1000000007;
    }
  
    rep(i,m+1){
      if(i==0){
        if(m==0)
          ans*=a[n];
        else
          ans*=a[b[0]-1];
      }else if(i==m){
        ans*=a[n-1-b[m-1]];
      }else {
        ans*=a[b[i]-b[i-1]-2];
      }
      ans%=1000000007;
      
    }
    cout<<ans%1000000007<<endl;
    
  }
  
}

Measured memory_bytes: 1280
import Data.Maybe
import qualified Data.ByteString.Char8 as B

readInts = (map (fst. fromJust. B.readInteger) . B.words) <$> B.getLine

f a b
    | m == 0 = 2 * a - b
    | otherwise = 2 * a + f a' b'
    where
    m = a `mod` b
    a' = max m (b - m)
    b' = min m (b - m)

main = do
    [n, x] <- readInts
    let a = max x (n - x)
        b = min x (n - x)
    print $ n + f a b


Measured memory_bytes: 380
#include<cstdio>
#include<vector>
#include<algorithm>
#include<climits>
using namespace std;
struct data{
    int cnt,p;
    bool operator<(const data &d)const{
        return cnt<d.cnt||(cnt==d.cnt&&p>d.p);
    }
};
class Seg{
    int n;
    vector<data>dat;
public:
    void init(int n_){
        n=1;
        while(n<n_)n*=2;
        dat.resize(n*2-1);
        for(int i=0;i<n*2-1;i++){
            dat[i]=(data){0,max(0,i-n+1)};
        }
    }
    Seg(int n_=0){
        init(n_);
    }
    void update(int x,int val){
        x+=n-1;
        dat[x].cnt+=val;
        while(x){
            x=(x-1)/2;
            dat[x]=max(dat[x*2+1],dat[x*2+2]);
        }
    }
    data query(int a,int b,int k=0,int l=0,int r=-1){
        if(r==-1)r=n;
        if(a<=l&&b>=r)return dat[k];
        if(a>=r||b<=l)return (data){-1,-1};
        return max(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
    }
};

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    Seg seg(n);
    for(int i=0;i<m;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        a--;
        seg.update(a,b);
        data d=seg.query(0,n);
        printf("%d %d\n",d.p+1,d.cnt);
    }
    return 0;
}

Measured memory_bytes: 17160
n=int(input())
a=list()
for i in range(n):
    s,t=input().split()
    a.append([s,int(t)])
x=input()
flag=False
ans=0
for i in a:
    if flag:
        ans+=i[1]
    if i[0]==x:
        flag=True
print(ans)

Measured memory_bytes: 9120
#include<bits/stdc++.h>
using namespace std;
int n;
string s[100010];
int tmp[26];
int main(){
    cin>>n;
    string t;
    for(int i=0;i<n;i++){
        cin>>t;
        memset(tmp,0,sizeof(tmp));
        for(int i=0;i<10;i++){
            tmp[t[i]-'a']++;
        }
        t="";
        for(int i=0;i<26;i++){
            for(int j=0;j<tmp[i];j++){
                t=t+(char)('a'+i);
            }
        }
        s[i]=t;
    }
    sort(s,s+n);
    //for(int i=0;i<n;i++)cout<<s[i]<<endl;
    t=s[0];
    long long ans=0,cnt=1;
    for(int i=1;i<n;i++){
        if(s[i]==t)cnt++;
        else{
            t=s[i];
            ans+=(cnt*(cnt-1))/2;
            cnt=1;
        }
        //cout<<cnt<<endl;
    }
    ans+=(cnt*(cnt-1))/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5760
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();

    sc.close();

    long sum = 0;

    for (int i = 0; i < N; i++) {
      if (i != N - 1){
        sum += i + 1;
      }
    }

    System.out.println(sum);

  }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n; cin>>n;
    vector<ll> a(n),b(n),c(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n) cin>>c[i];
    sort(a.begin(),a.end()); //昇順にソート
    sort(b.begin(),b.end()); //昇順にソート
    sort(c.begin(),c.end()); //昇順にソート
    ll ans;
    vector<ll> d(n);
    rep(i,n){ //B,Cについて
        d[i]=c.end()-upper_bound(c.begin(),c.end(),b[i]);
    }
    rep(i,n-1){
        d[n-i-2]+=d[n-i-1];
    }
    rep(i,n){
        ans+=d[upper_bound(b.begin(),b.end(),a[i])-b.begin()];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define M_PI 3.14159265358979323846
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ipair;
typedef pair<ll, ll> llpair;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
    
/*
    Author: Koushik Sahu
    Created: 18 Sep 2020 09:55:59
*/

ll n;

ll binExpo(ll a, ll b){
    ll ans = 1;
    while(b){
        if(b%2==1){
            ans *= a;
            ans %= MOD;
        }
        a *= a;
        a %= MOD;
        b /= 2;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin>>n;
    ll ans = ((((binExpo(10, n) - 2ll*binExpo(9, n))%MOD)+MOD)%MOD + binExpo(8, n))%MOD;
    cout<<ans<<"\n";
    return 0;
}

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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); //数
		int W = stdIn.nextInt(); //ナップサックの容量
		
		int[]w = new int[n+10];
		int[]v = new int[n+10];
		
		for(int i = 0; i < n; i++) {
			w[i] = stdIn.nextInt();
			v[i] = stdIn.nextInt();
		}
		
		
		long[][] dp = new long[n+1][(int)1e5+10];
		
		//dpループ
		for(int i = 0; i < n; i++) {
			
			for(int sumw = 0; sumw <= W; sumw++) {
				
				if(w[i] <= sumw) {
					dp[i+1][sumw] = Math.max(dp[i][sumw],dp[i][sumw - w[i]]+v[i] );
				}
				
				dp[i+1][sumw] = Math.max(dp[i+1][sumw],dp[i][sumw] );
				
			}
			
		}
		
		System.out.println(dp[n][W]);
		
	}

}


Measured memory_bytes: 125140
int main(void){
    int X,Y,Z,temp1,temp2;
    scanf("%d %d %d",&X,&Y,&Z);
    temp1=X;
    X=Y;
    Y=temp1;
    temp2=X;
    X=Z;
    Z=temp2;
    printf("%d %d %d\n",X,Y,Z);
    return 0;
}

Measured memory_bytes: 128
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr);
  console.log(arr.reduce((s, e) => s += ' ' + e, ''));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  let left, right, largest;
  const maxHeapify = (i) => {
    right = (left = 2 * i + 1) + 1;
    if (left < n && arr[left] > arr[i]) largest = left;
    else largest = i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 140176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<ll> A(N+1),sum(N+2);
    for(int i=0;i<N+1;i++) cin>>A[i];
    
    if(N==0){
        if(A[0]==1){
            cout<<1<<endl;
        }else{
            cout<<-1<<endl;
        }
        return 0;
    }
    
    for(int i=N;i>=0;i--){
        sum[i]=sum[i+1]+A[i];
    }
    
    ll ans=1,now=1;
    bool ok=true;
    
    if(A[0]){
        cout<<-1<<endl;
        return 0;
    }
    
    for(int i=1;i<=N;i++){
        now=now*2;
        chmin(now,sum[i]);
        ans+=now;
        now-=A[i];
        if(now<0) ok=false;
        
        //cout<<ans<<" "<<now<<endl;
    }
    if(!ok) ans=-1;
    cout<<ans<<endl;
    
    
}



Measured memory_bytes: 4792
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h> 
typedef unsigned long long ll;
#define length 100000   //10万
#define kw_len 10
ll factor[300];
ll memory[300]; 
/*素朴法で計算
factorは必ずmemset(factor,0,sizeof(factor));
グローバルであるmemoryに個数を書き込む
memory配列の走査にはfactorの要素を使う*/
void primefac(ll num){
    int i = 0,kosuu=0;
    while(*(factor+i) != 0){
        while(num % *(factor+i)==0){
            num /= *(factor+i);
            memory[*(factor+i)] +=1;
        }
        if(num==1)break;
        i++;
    }
}
/*グローバルにあるfactorに素数書き込む.個数を返すので配列は-1しろ*/
int elast(ll number){    
    ll tmp=0;
    int flag=0;
    *factor = 2;
    for(int i=3;i <= number;i++){
        flag=0;
        for(int j=0;j <= tmp ;j++){
            if(i % (*(factor+j)) == 0){
                flag=1;
                break;
            }
        }
        if(flag)continue;
        tmp += 1;
        *(factor+tmp) = i;
    }
        return tmp+2;
}

int compare(const int*a,const int *b){
    if(*a<*b)
      return -1;
    else if(*a>*b)
      return 1;
    return 0;
}

ll nCr(int n,int r){
  ll val=1;
  int i;
  if(r==0)return 1;
  for(i=0;i<n-r;i++){
		val *= (n-i);
		val /= (i+1);
	}
  return val;
}

ll nPr(int n,int r){
  ll val=1;
  int i;
  for(i=0;i<r;i++){
    val *= (n-i);
  }
  return val;
}
/*
qsort(array,length,sizeof(int),(int(*)(const int*, const int*))compare);
使う時これをコピペ
*/
int main(){
    int N,K,i,j,A=1,B;
    int *inp;
    char *chp;
    ll sum=0;
    scanf("%d",&N);
    if(N>81){
        puts("No");
        return 0;
    }
    for(i=2;i<=9;i++){
        if(N%i==0){
            A = i;
        }
    }
    if((N / A)<10){
        puts("Yes");
        return 0;
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 128
a = list(map(int,input().split()))
n = a[0]
k = a[1]


member = list(range(1,n+1))

for i in range(k):
  num = int(input())
  c = list(map(int,input().split()))
  for j in c:
    if j in member:
      member.remove(j)
print(len(member))

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

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

  int L = A + B;
  int R = C + D;

  if(L > R){
    cout << "Left" << endl;
  }
  else if(L == R){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

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

int arr[100][100];

int main(){

	int w,h,n;
	cin>>w>>h>>n;

	while(n--){
		int x,y,z;
		cin>>x>>y>>z;
		
		if(z==1) {
			for(int i=0;i<x;i++)for(int j=0;j<h;j++)arr[i][j] = 1;
		}
		if(z==2){
			for(int i=x;i<w;i++)for(int j=0;j<h;j++)arr[i][j] = 1;
		}
		if(z==3){
			for(int i=0;i<w;i++)for(int j=0;j<y;j++)arr[i][j] = 1;
		}
		if(z==4){
			for(int i=0;i<w;i++)for(int j=y;j<h;j++)arr[i][j] = 1;
		}
	}

	int res = 0;

	for(int i=0;i<w;i++)for(int j=0;j<h;j++)if(arr[i][j]==0) res++;

	cout<<res;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,X;
  cin >> N >> X;
  
  int min;
  
  cin >> min;
  
  X -= min;
  
  for(int i=1;i<N;i++){
    int g;
    cin >> g;
    X -= g;
    if(min>g){
      min=g;
    }
  }
  
  cout << X/min + N << endl;
}


Measured memory_bytes: 3620
#include<iostream>
using namespace std;
string s;
bool a,b;
int main(){
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='C'){
			a=1;
		}
		if(s[i]=='F'&&a){
			b=1;
		}
	}
	if(a&&b)	cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

int main(){
    char s[2000000];
    char t[2000000];
    int i,j,k=0;

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

    i = strlen(s);

    for(j=0;j<i;j++){
        if(strncmp(&t[j],&s[j],1)!=0){
            k++;
        }     
    }
    
    printf("%d\n",k);

    return 0;

}

Measured memory_bytes: 2096
#include<cstdio>
#include<algorithm>
using namespace std;
long long a[200001],qzh[200001],ans=3000000000000000,n;
int main()
{
	scanf("%lld",&n);for(long long i=1;i<=n;++i) {scanf("%lld",&a[i]);a[i]-=i;}
	sort(a+1,a+1+n);
	for(long long i=1;i<=n;++i) qzh[i]=qzh[i-1]+a[i];
	for(long long i=1;i<=n;++i) if(ans>(i-(long long)1)*a[i]-qzh[i-(long long)1]+(qzh[n]-qzh[i])-a[i]*(n-i)) ans=(i-(long long)1)*a[i]-qzh[i-(long long)1]+(qzh[n]-qzh[i])-a[i]*(n-i);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
int main(){
	int a,b,c,d,p,x,y;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&p);
	x=a*p;
	if(p<c){
		y=b;
	}
	else if(p>c){
		y=b+(p-c)*d;
	}

	if(x<y){
		printf("%d\n",x);
	}else{
		printf("%d\n",y);
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define int long long
using namespace std;
typedef pair<int,int> P;
constexpr int mod=1e9+7;
int N,K;
int a[100];
int dp[101][200002]={};

signed main(){
    cin>>N>>K;
    REP(i,N) cin>>a[i];
    dp[N][K]=1;
    for(int i=N-1;i>=0;--i) for(int j=K;j>=0;--j){
        dp[i][j]=dp[i+1][j]+dp[i][j+1]-dp[i+1][j+a[i]+1];
        dp[i][j]=(dp[i][j]+mod)%mod;
    }
    cout<<dp[0][0]<<endl;
}


Measured memory_bytes: 157184
from collections import Counter


N = int(input())
c = Counter(map(int, input().split()))
usables = sorted([(k, v) for k, v in c.items() if v >= 2])
if len(usables) <= 1:
    print(0)
else:
    if usables[-1][1] >= 4:
        print(usables[-1][0] ** 2)
    else:
        print(usables[-1][0] * usables[-2][0])


Measured memory_bytes: 24224
using System;
using System.Collections.Generic;
using System.Linq;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            bool[] flag = new bool[200];
            for (int i = 0; i < n; i++) flag[int.Parse(Console.ReadLine())] = true;
            int ret = 0;
            for (int i = 0; i < 200; i++)
            {
                if (flag[i]) ret++;
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

int n;
multiset<int> s;

void input(){
    cin >> n;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        s.insert(x);
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    int ans = 0;
    for(int x=0;x<100000;x++){
        ans = max(ans, int(s.count(x-1)+s.count(x)+s.count(x+1)));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

// https://en.wikipedia.org/wiki/Negative_base
int[] negativeBase(int n, int base) {
    if (n == 0) return [0];

    int[] ret;
    while (n != 0) {
        int m = n % base;
        n /= base;
        if (m < 0) {
            m += abs(base);
            n++;
        }
        ret ~= m;
    }
    ret.reverse();
    return ret;
}

void main() {
    int n = readint;

    auto bin = negativeBase(n, -2);
    auto ans = bin.map!(to!string).join();
    writeln(ans);
}


Measured memory_bytes: 256
m = mod = 10 ** 9 + 7

class Combination
  
  attr_accessor :n_max, :mod
  
  def initialize(n_max,mod)
    @n_max, @mod = n_max, mod
    @fact = [1, 1]
    @inv = [0,1]
    @factinv = [1, 1]
    f(2, n_max)
  end
  
  def f(s,t)
    @n_max = t
    s.upto(t) do |i|
      @fact.push( @fact[-1] * i % mod )
      @inv.push( -@inv[mod % i] * (mod / i) % mod )
      @factinv.push( @factinv[-1] * @inv[-1] % mod )
    end
  end
  
  def cmb(n,r,mod)
    return 0 if r < 0 || n < r
    f(n_max+1, n) if n_max < n
    @fact[n] * (@factinv[r] * @factinv[n-r] % mod) % mod
  end
end

ans = 0

n, k = gets.to_s.split.map{|i|i.to_i}
a    = gets.to_s.split.map{|i|i.to_i}.sort

inst = Combination.new(n, m)

(n-k+1).times do |i|
  t = inst.cmb( n-i-1, k-1, mod)
  mi = a[i] * t % m
  ma = a[n-(i+1)] * t % mod
  ans += (ma - mi)
  ans %= m if ans < 0 || m <= ans
end

puts ans

Measured memory_bytes: 14204
from bisect import bisect_left

n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0

for i in range(n-2):
  for j in range(i+1, n-1):
    ans += bisect_left(l[j+1:], l[j]+l[i])
    
print(ans)

Measured memory_bytes: 50652
#coding: utf-8

n, q = map(int, input().split())
totaltime = 0
queue = list()
for i in range(n):
    name, time = map(str, input().split())
    queue.append([name, int(time)])

idx = 0
while True:
    lenQ = len(queue)
    if idx >= lenQ:
        break
    if queue[idx][1] <= q:
        totaltime += queue[idx][1]
        print(queue[idx][0] + ' {}'.format(totaltime))
        idx += 1
    else:
        totaltime += q
        name = queue[idx][0]
        time = queue[idx][1] - q
        queue.append([name, time])
        idx += 1


Measured memory_bytes: 28456
#include <iostream>
#include <string>
#include <unordered_map>
#include <algorithm>

int main()
{
	std::unordered_map<int, int> mapa;
	mapa.insert(std::make_pair(0, 0));
	std::string str;
	std::getline(std::cin, str);
	
	int n = str.length();
	int xoring = 0;
	
	for (int i = 0; i < n; ++i)
	{
		int place = str[i] - 'a';
		xoring ^= (1 << place);
		int min = i + 1;
		
		if (mapa.count(xoring))
		{
			min = std::min(min, mapa[xoring] + 1);
		}
		
		for (int j = 0; j < 26; ++j)
		{
			if (mapa.count(xoring ^ (1 << j)))
			{
				min = std::min(min, mapa[xoring ^ (1 << j)] + 1);
			}
		}
		
		if (mapa.count(xoring))
			mapa[xoring] = std::min(mapa[xoring], min);
		else
			mapa[xoring] = min;
		
		if (i == n - 1)
			std::cout << min;
	}
}

Measured memory_bytes: 8652
#include <iostream>
using namespace std;
#define MAX 26
#define NIL -1

int D[MAX];

struct Node{
  int parent, left, right;
};

struct Node T[MAX];

void setDepth(int u, int p){
  D[u] = p;
  if(T[u].left != NIL) setDepth(T[u].left, p+1);
  if(T[u].right != NIL) setDepth(T[u].right, p+1);
}

int setHeight(int H[], int u){
  int h1 = 0, h2 = 0;
  if(T[u].right != NIL) h1 = setHeight(H, T[u].right) + 1;
  if(T[u].left != NIL) h2 = setHeight(H, T[u].left) + 1;
  return H[u] = ((h1 > h2) ? h1 : h2);
}

void print(int H[], int n){
  for(int i=0; i<n; i++){
    cout << "node " << i << ": ";
    cout << "parent = " << T[i].parent << ", ";
    cout << "sibling = ";
    if(T[i].parent == NIL) cout << NIL << ", ";
    else if(T[T[i].parent].right != i) cout << T[T[i].parent].right << ", ";
    else cout << T[T[i].parent].left << ", ";
    cout << "degree = ";
    if(T[i].left != NIL && T[i].right != NIL) cout << "2, ";
    else if(T[i].left == NIL && T[i].right == NIL) cout << "0, ";
    else cout << "1, ";
    cout << "depth = " << D[i] << ", ";
    cout << "height = " << H[i] << ", ";
    if(T[i].parent == NIL) cout << "root" << endl;
    else if(T[i].left == NIL && T[i].right == NIL) cout << "leaf" << endl;
    else cout << "internal node" << endl;
  }
  return;
}

int main(void){
  int n, id, l, r, root;
  int H[MAX];
  cin >> n;
  // 初期化
  for(int i=0; i<n; i++){
    T[i].parent = T[i].left = T[i].right = NIL;
  }

  for(int i=0; i<n; i++){
    cin >> id >> l >> r;
    T[id].left = l;
    T[id].right = r;
    T[l].parent = id;
    T[r].parent = id;
  }

  // rootを見つける
  for(int i=0; i<n; i++){
    if(T[i].parent == NIL) root = i;
  }

  setDepth(root, 0);
  setHeight(H, root);

  print(H, n);
  return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;
 
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
 
typedef long long ll;
typedef pair<ll, int> ll_i;

int main() {
    ll N;
    cin >> N;
    std::vector<ll> a(N);
    rep(i,N) cin >> a[i];
    ll ans=0;
    for(ll i=0;i < N-1;i++){
        if(a[i] == a[i+1]){
            if(i < N-2)a[i+1] = a[i+2]+1;
            ans++;
        }
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long;
using ll = long long;
#define rep(i,n) for(lint (i) = 0;(i) < (lint)(n);(i)++)
#define repInRange(i,start,end) for(lint (i) = (start);(i) < (end);++(i))
using lpair = pair<lint,lint>;
using Vecint = vector<lint>;
using Llist = list<lint>;


ll pow(ll k,ll l) {
	ll ret = 1;
	rep(i,l) {
		ret *= k;
	}
	return ret;
}

template <typename T>
T sum(vector<T> vec) {
	ll ret = 0;
	rep(i,vec.size()) {
		ret += vec.at(i);
	}
	return ret;
}

void Main() {
	ll N;
	cin >> N;
	cout << pow(N,3) << '\n';
}

signed main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	Main();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

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

  vi k(m);
  vector<vi> s(m);
  for (int i = 0; i < m; i++) {
    cin >> k.at(i);
    for (int j = 0; j < k.at(i); j++) {
      int x;
      cin >> x;
      s.at(i).push_back(x);
    }
  }

  vi p(m);
  for (int i = 0; i < m; i++) cin >> p.at(i);

  string bits;
  for (int i = 0; i < n; i++) bits.push_back('0');

  ll cnt = 0;

  for (int i = 0; i < pow(2, n); i++) {
    for (int j = 0; j < m; j++) {
      int sum = 0;
      for (int l = 0; l < k.at(j); l++)
        if (bits.at(s.at(j).at(l) - 1) == '1') sum++;
      if (sum % 2 != p.at(j)) break;
      if (j == m - 1) cnt++;
    }
    if (i == pow(2, n) - 1) break;
    int x = 0;
    while (bits.at(n - 1 - x) == '1') {
      bits.at(n - 1 - x) = '0';
      x++;
    }
    bits.at(n - 1 - x) = '1';
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
import sys
inputs = sys.stdin.readline
N, K= map(int,inputs().split())
V = list(map(int,inputs().split()))

maxim = 0
if K <= 2*N - 1:
	for i in range(0,K+1):
		for j in range(i+1):
			if j == i:
				a = V[:j] + [0]
			else:
				a = V[:j] + V[j-i:] + [0]
			a.sort()
			b = a.index(0)
			if b <= K - i:
				maxim = max(sum(a[b:]),maxim)
			else:
				maxim = max(sum(a[K-i:]),maxim)
else:
	V.append(0)
	V.sort()
	maxim = sum(V[V.index(0):])
print(maxim)

Measured memory_bytes: 3064
import java.util.Scanner;


public class Main{

	static int[][] ban;
	static boolean[] fix;
	static boolean flg = false;
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int cnt = Integer.parseInt(s.nextLine());
		ban = new int[8][8];
		fix = new boolean[8];
		for(int i=0 ; i<cnt ; i++) {
			String[] tmp = s.nextLine().split(" ");
			ban[Integer.parseInt(tmp[1])][Integer.parseInt(tmp[0])] = 1;
			fix[Integer.parseInt(tmp[1])] = true;
		}
		solve(ban, fix);

		for(int i=0 ; i<8 ; i++) {
			StringBuilder sb = new StringBuilder();
			for(int j=0 ; j<8 ; j++) {
				if(ban[j][i]==0)
					sb.append(".");
				else
					sb.append("Q");
			}
			System.out.println(sb.toString());
		}
	}

	public static void solve(int[][] ban, boolean[] fix) {
		put(0);
	}

	public static void put(int index) {

		if(index==8){
			flg = true;
			return;
		}

		if(fix[index])
			put(index+1);
		else {
		outer : for(int i=0 ; i<8 ; i++) {
			for(int j=0 ; j<8 ; j++) {
				if(index!=j) {
					if(ban[j][i]==1)
						continue outer;
				}
			}
			int record = i;
			for(int k=index+1 ; k<8 ; k++) {
				record++;
				if(k<8 && record<8) {
					if(ban[k][record]==1)
						continue outer;
				}
			}

			record = i;
			for(int l=index+1 ; l<8 ; l++) {
				record--;
				if(l<8 && record>=0) {
					if(ban[l][record] == 1)
						continue outer;
				}
			}
			record = i;
			for(int m=index-1 ; m>=0 ; m--) {
				record++;
				if(m>=0 && record<8) {
					if(ban[m][record]==1)
						continue outer;
				}
			}
			record = i;
			for(int n=index-1 ; n>=0 ; n--) {
				record--;
				if(n>=0 && record>=0) {
					if(ban[n][record]==1)
						continue outer;
				}
			}
			ban[index][i] = 1;
			put(index+1);
			if(!fix[index] && !flg)
				ban[index][i] = 0;
		}
		}
	}
}

Measured memory_bytes: 17324
from heapq import heappush, heappop
def dijkstra(graph:list, node:int, start:int) -> list:
    # graph[node] = [(cost, to)]
    inf = float('inf')
    dist = [inf]*node

    dist[start] = 0
    heap = [(0,start)]
    while heap:
        cost,thisNode = heappop(heap)
        for NextCost,NextNode in graph[thisNode]:
            dist_cand = dist[thisNode]+NextCost
            if dist_cand < dist[NextNode]:
                dist[NextNode] = dist_cand
                heappush(heap,(dist[NextNode],NextNode))
    return dist

N = int(input())

g = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    g[a].append((1,b))
    g[b].append((1,a))
d = dijkstra(g,N,0)
r = 0
n = 0
for i in range(N):
    if r < d[i]:
        r = d[i]
        n = i
r = max(dijkstra(g,N,n))
if r%3==0 or r%3==2:
    print('First')
else:
    print('Second')

Measured memory_bytes: 83884
N, M, K = map(int, input().split(' '))
A_ls = [0] + list(map(int, input().split(' ')))
for i in range(N):
    A_ls[i + 1] += A_ls[i]
B_ls = [0] + list(map(int, input().split(' ')))
for i in range(M):
    B_ls[i + 1] += B_ls[i]
b_cnt, rst = M, 0
for a_cnt in range(N + 1):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K and b_cnt >= 0:
        b_cnt -=1
    rst = max(rst, a_cnt + b_cnt)
print(rst)

Measured memory_bytes: 45292
n,k = map(int,input().split())
p = list(map(int,input().split()))
P = [0 for x in range(n-k+1)]
P[0] = sum([p[i] for i in range(k)])

for i in range(n-k):
    P[i+1] = P[i] - p[i] + p[i+k]

m = max(P)
print((m+k)/2)

Measured memory_bytes: 25060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

template<typename T>
struct Imos2D {
	vector<vector<T>> board;
	const int h, w;
	Imos2D(int h, int w) : 
		board(vector<vector<T>>(h + 2, vector<T>(w + 2, 0))),
		w(w + 2),
		h(h + 2)
		{}
	// 範囲外許さないマン
	bool able(int y, int x) {
		if(y <= 0 or h < y) return false;
		if(x <= 0 or w < x) return false;
		return true;
	}
	bool able(int y1, int x1, int y2, int x2) {
		if(not able(y1, x1)) return false;
		if(not able(y2, x2)) return false;
		if(make_pair(y1, x1) > make_pair(y2, x2)) return false;
		return true;
	}
	// 1点加算
	void add(int y, int x, T z) {
		assert(able(y, x));
		board[y][x] += z;
	}
	// 矩形加算
	void add(int y1, int x1, int y2, int x2, T z) {
		assert(able(y1, x1, y2, x2));
		board[y1][x1] += z;
		board[y1][x2 + 1] -= z;
		board[y2 + 1][x1] -= z;
		board[y2 + 1][x2 + 1] += z;
	}
	// 累積和
	void build() {
		for(int y = 1; y < h; ++y) {
			for(int x = 1; x < w; ++x) {
				board[y][x] += board[y][x - 1];
			}
		}
		for(int y = 1; y < h; ++y) {
			for(int x = 1; x < w; ++x) {
				board[y][x] += board[y - 1][x];
			}
		}
	}
	// 1点取得
	T get(int y, int x) {
		assert(able(y, x));
		return board[y][x];
	}
	// 矩形取得
	T get(int y1, int x1, int y2, int x2) {
		assert(able(y1, x1, y2, x2));
		return board[y2][x2] - board[y2][x1 - 1] - board[y1 - 1][x2]+board[y1 - 1][x1 - 1];
	}
	void debug() {
		for(int y = 1; y < h - 1; ++y) {
			for(int x = 1; x < w - 1; ++x) {
				cout << board[y][x] << " ";
			}
			cout << '\n';
		}
	}
};


int main() {
	int n, m; cin >> n >> m;
	map<int, int> mpx, mpy;
	int x[n], y[n];
	rep(i,n) {
		cin >> x[i] >> y[i];
		mpx[x[i]]++;
		mpy[y[i]]++;
	}
	int rectx[m * 2], recty[m * 2];
	rep(i,m * 2) {
		cin >> rectx[i] >> recty[i];
	}
	int h, w;
	{
		int cnt = 1;
		for(auto &e : mpx) {
			e.second = cnt;
			++cnt;
		}
		w = cnt;
	}
	{
		int cnt = 1;
		for(auto &e : mpy) {
			e.second = cnt;
			++cnt;
		}
		h = cnt;
	}
	Imos2D<int> imos(h, w);
	rep(i,n) {
		imos.add(mpy[y[i]], mpx[x[i]], 1);
	}
	imos.build();
	rep(i,m) {
		auto itry = mpy.lower_bound(recty[2 * i]);
		auto itrx = mpx.lower_bound(rectx[2 * i]);
		int y1;
		if(itry == mpy.end()) {
			y1 = h;
		} else {
			y1 = (*itry).second;
		}
		int x1;
		if(itrx == mpx.end()) {
			x1 = w;
		} else {
			x1 = (*itrx).second;
		}
		itry = mpy.upper_bound(recty[2 * i + 1]);
		itrx = mpx.upper_bound(rectx[2 * i + 1]);
		int y2;
		if(itry != mpy.begin()) {
			itry = prev(itry);
			y2 = (*itry).second;
		} else {
			y2 = 0;
		}
		int x2;
		if(itrx != mpx.begin()) {
			itrx = prev(itrx);
			x2 = (*itrx).second;
		} else {
			x2 = 0;
		}
		if(make_pair(y1, x1) > make_pair(y2, x2) or y1 * y2 * x1 * x2 == 0) {
			cout << 0 << endl;
		} else {
			// cerr << y1 << " " << x1 << " " << y2 << " " << x2 << endl;
			cout << imos.get(y1, x1, y2, x2) << '\n';
		}
	}
	return 0;
}


Measured memory_bytes: 109188
#include <iostream>
#include <cmath>
#include <climits>

typedef long long ll;

bool isPrime(ll num){
    bool flag=true;
    for(ll i = 2; i <= sqrt(num); i++) {
        if(num % i == 0) {
            flag = false;
            break;
        }
    }
    return flag;
}


int main(){
    ll n , res = LLONG_MAX;
    std :: cin >> n;

    auto x = ceil(sqrt(n));

    if(isPrime(n))
        std :: cout << n - 1 << '\n';
    else{
        for(int i = 2 ; i <= x ; i++)
            if(n % i == 0)
                res = (res < i + (n / i) - 2 ? res : i + (n / i) - 2);
        std :: cout << res << '\n';
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <functional>
#include <iterator>

using namespace std;

struct v {
  vector<int> tos;
  int counter;
};

int main() {

  string s,t;
  cin >> s >> t;

  // 事前にsを処理して、アルファベット毎に出現位置を記録しておく
  unordered_map<char, vector<int>> char_pos;
  for (int i = 'a'; i <= 'z'; i++) {
    char_pos.emplace(i, vector<int>());
  }

  for (int i = 0; i < s.size(); i++) {
    char_pos[s[i]].emplace_back(i);
  }
  
  int t_pos = 0;
  long long int result = -1;

  for (int i = 0; ; i++) { // sの繰り返し回数。10**100なので、無限ループと変わらない
    int before_t_pos = t_pos;
    
    for (int s_pos = 0; s_pos < s.size(); s_pos++) {
      // 1ずつでは間に合わないので、次の出現位置を2分探索で探す
      const auto& next_t = t[t_pos];
      const auto& next_char_pos = char_pos[next_t];
      auto ite = lower_bound(next_char_pos.begin(), next_char_pos.end(), s_pos);
      if (ite == next_char_pos.end()) {
        // 見つからなかった。
        break;
      }

      s_pos = *ite;
      t_pos++;
        
      if (t_pos == t.size()) {
        // 全部見つかった
        result = i * s.size() + s_pos + 1;
        goto finish;
      }
    }
    
    if (t_pos == before_t_pos) {
      // 今回のsでは見つからなかったので、もう見つかる可能性はない
      break;
    }
  }
  
  finish:
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 1216
import sys

n = int(input())
a = list(map(int, input().split()))

cnt = [0] * n

while 1:
    for i in range(n):
        if a[i] % 2 == 0:
            a[i] /= 2
            cnt[i] += 1
        else:
            print(min(cnt))
            sys.exit()

Measured memory_bytes: 9248
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int x = a+b;
        int y = a-b;
        int z = a*b;

        System.out.println(Math.max(x,Math.max(y,z)));
    }
}

Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

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

    ll ans = 0;
    map<ll, ll> m;
    REP(i, N) {
        ll A; cin >> A;
        ans += m[i - A];
        m[A + i]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 26372
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];

  unordered_map<int, int> odd, even;
  rep(i, 0, n) {
    if (i & 1)
      odd[a[i]]++;
    else
      even[a[i]]++;
  }

  vector<pair<int, int>> o, e;
  for (auto p : odd) { o.emplace_back(p.second, p.first); }
  for (auto p : even) { e.emplace_back(p.second, p.first); }
  sort(o.rbegin(), o.rend());
  sort(e.rbegin(), e.rend());
  o.emplace_back(0, n / 2);
  e.emplace_back(0, n / 2);

  if (o[0].second == e[0].second) {
    cout << n - o[0].first - max(o[1].first, e[1].first) << endl;
  } else {
    cout << n - o[0].first - e[0].first << endl;
  }
  return 0;
}

Measured memory_bytes: 9116
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif 


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

    ll N; cin >> N;

    ll ans = N*(N-1)/2;
    cout << ans << endl;

    return 0;
}

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    bool ng= false;
    if(s.size()%2 == 1)ng=true;
    for(int i=0;i<(int)s.size();i+=2){
        if(s.substr(i,2) != "hi"){
            ng=true;
            break;
        }
    }
    if(ng)cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
const char letters[]="123456789paswordqetyilvumnbchfg0kzxjEATIOSNRHLDCUMPFGYWBVKJXQZ";
char query[129];
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline int ask(void){printf("? %s\n",query);fflush(stdout);return IN();}
int main(void)
{
  int l=0,len=0,mid=0,r=0,total=0,diff[62];char pw[129];
  rep(i,62){rep(j,128){query[j]=letters[i];}query[128]=0;diff[i]=128-ask();total+=diff[i];}
  rep(i,62)
  {
    if(len==0){len=diff[i];rep(j,diff[i])pw[j]=letters[i];}
    else
    {
      l=0;
      rep(k,diff[i])
      {
        r=len;
        while(l<r)
        {
          mid=(l+r+1)/2;
          rep(j,mid)query[j]=pw[j];
          rep(j,diff[i]-k)query[mid+j]=letters[i];
          query[mid+diff[i]-k]=0;
          if(ask()==total-mid-diff[i]+k)l=mid;else r=mid-1;
        }
        len++;rep(j,len-l){pw[len-j]=pw[len-j-1];}pw[l]=letters[i];
      }
    }
  }
  pw[len]=0;printf("! %s\n",pw);return fflush(stdout),0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    char s[20];

    Scs(s);

    s[5] = ' ';
    s[13] = ' ';

    printf ("%s\n", s);

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
    #include<stdlib.h>
    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<vector> 
    #include<limits>
    #include<numeric>
    #include<type_traits>
    #include<math.h>
    using namespace std;
    typedef long long ll;

    #define rep(i, n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define in(x) cin >> x
    #define out(str) cout << str << endl

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

    int A,B,K;

    int main(){
        vector<int> ans;
        cin>>A>>B>>K;
        if(B-A+1<=2*K){
            repi(i,A,B+1){
                out(i);
            }
            return 0;
        }
        repi(i,A,A+K){
            out(i);
        }
        repi(i,B-K+1,B+1){
            out(i);
        }
    }


Measured memory_bytes: 256
count_a = []
pos = 0
while True:
    n, x = list(map(int, input().split()))
    count = 0
    if n == x == 0:
        break
    else:
        for i in range(1, (n+1)):
            for j in range(i+1, (n+1)):
                for k in range(j+1, (n+1)):
                    if (i != j) and (j != k) and (i != k):
                        if (i+j+k) == x:
                            count += 1
        count_a.append(count)
        pos = pos+1

for i  in count_a:
    print(i)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main() {
long double M, H;
long double A, B;
cin >> A >> B >> M >> H;
long double pie = 3.1415926535897932384626433832795028841971;
long double D = 0.03055555555555555555555*(60*M + H)*pie;
if(5.5*(60*M + H) > 360){
while(D >= 0 && D <= pie){
D -= 2*pie;}}
cout << fixed << setprecision(10) << sqrtl(A*A + B*B - 2*A*B*cosl(D));}

Measured memory_bytes: 4160