akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define print(a) cout<<(a)<<endl
#define to_ll(b) stoll(b)
#define MOD 1000000007

ll f(int N,vl &K){
	ll ans=0;
	rep(i,0,N){
		rep(j,1,N){
			int k=i+j;
			if(k>=N){
				break;
			}
			ans+=K[i]*K[k];
		}
	}
	return ans;
}


int main(){
	ll N,ans;cin>>N;
	vl K(N);
	rep(i,0,N){
		int a;cin>>a;
		K[i]=a;
	}
	ans=f(N,K);
	print(ans);
	
}

Measured memory_bytes: 256
#include <stdio.h>
 
int Obsession(int num,int d[],int k){
	int c;
	for(c=0;c<k;c++){
		if(num == d[c]){
			return 1;
		}
	}
	return 0;
}
 
int main(void){
	int n,k,h,i,j,l,m,res;
	int d[10];
	scanf("%d %d",&n,&k);
	for(i=0;i<k;i++){
		scanf("%d",&d[i]);
	}
	for(h=0;h<10;h++){
		for(i=0;i<10;i++){
			for(j=0;j<10;j++){
				for(l=0;l<10;l++){
					for(m=0;m<10;m++){
						if(Obsession(m,d,k)==1)continue;
						res = m;
						if(res>=n){
							printf("%d\n",res);
							return 0;
						}
						if(Obsession(l,d,k)==1)continue;
						res += 10*l;
						if(res>=n){
							printf("%d\n",res);
							return 0;
						}
						if(Obsession(j,d,k)==1)continue;
						res += 100*j;
						if(res>=n){
							printf("%d\n",res);
							return 0;
						}
						if(Obsession(i,d,k)==1)continue;
						res += 1000*i;
						if(res>=n){
							printf("%d\n",res);
							return 0;
						}
						if(Obsession(h,d,k)==1)continue;
						res += 10000*h;
						if(res>=n){
							printf("%d\n",res);
							return 0;
						}
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b)
{
    if (a % b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int main() {
  int x,y,z;
  cin >> x >> y >> z;
  cout << (x-z)/(y+z) << endl;
}


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

constexpr int64_t MOD = 1e9 + 7;

int main() {
    int64_t n;
    cin >> n;
    vector<int64_t> a(n);
    for (auto& e : a) cin >> e;

    int64_t ans = 0;
    for (int64_t i = 0; i < 60; i++) {
        int64_t c = 0;
        for (auto& e : a) c += ((e >> i) & 1);
        ans += (1l << i) % MOD * c % MOD * (n - c) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 2560
import java.util.Arrays;
import java.util.Scanner;

import java.util.List;

public class Main {

	public static void main(String[] args) {

		String line = null;
		try (Scanner sc = new Scanner(System.in)) {
			line = sc.nextLine();

			String[] tmpArray = line.split(" ");
			int price = Integer.parseInt(tmpArray[0]);
			int errNum = Integer.parseInt(tmpArray[1]);
			line = sc.nextLine();
			List<String> errNumVal = Arrays.asList(line.split(" "));
			String tmpStr = "";
			int result = 0;
			for (int i = price; i <= 99999; i++) {
				tmpStr = Integer.toString(i);
				boolean flg = true;
				for (String tmps : errNumVal) {
					if (tmpStr.indexOf(tmps) >= 0) {
						flg = false;
						//break;
					}
				}
				if (flg){
					result = i;
					break;
				}
			}

			System.out.println(result);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 29476
#include<bits/stdc++.h>
using namespace std;
	
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define per(i , j , n) for(ll i = j ; i >= n ; i--)
 
 
 
int main(){
    ll n,k;
    cin >> n >> k;
    ll sum = 0;
    ll m = (ll)1000000007;
    n += 1;
    rep(i,k,n + 1){
        ll maxe = (((n * (n + (ll)1))/(ll)2) - (((n - i)*(n - i + (ll)1))/(ll)2));
        ll mini = ((i*(i + (ll)1))/(ll)2);
        sum = (sum + maxe - mini + (ll)1)%m;
    }
    cout << sum;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}



//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;

int main(){
  int N;cin>>N;vi x(N),y(N),h(N);
  
  bool ok=false;
  
  rep(i,N)cin>>x[i]>>y[i]>>h[i];
  rep(i,N){
    if(h[i]==0)ok=true;
  }
  for(int X =0;X<=100;X++){
    for(int Y=0;Y<=100;Y++){
      int max_h=1000000000;
      set<int> H;
      for(int i=0;i<N;i++){
        if(h[i]==0){
          max_h=min(max_h,abs(x[i]-X)+abs(y[i]-Y));
        }
        else{          
          H.insert(h[i]+abs(x[i]-X)+abs(y[i]-Y));
        }
      }
      if(H.size()==1 &&*begin(H)>=1 &&ok==false){
        cout<<X<<" "<<Y<<" "<<*begin(H)<<endl;
        return 0;
      }
       else if(H.size()==1 &&*begin(H)>=1&&ok&&max_h>=*begin(H)){
        cout<<X<<" "<<Y<<" "<<*begin(H)<<endl;
        return 0;
      }
     
      
    }
  }
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define db cout<<"db: "
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;

    cin>>i;
    cout<< (i^1);

    return 0;
}

Measured memory_bytes: 3636
function Main(input) {
  lines = input.split('\n')
  N = lines[0] * 1
  s = lines[1].split(" ").map(function(a) { return a * 1 }).sort(function(a, b) { return a - b }) 
  f = s.shift()
  ans = s.reduce(function(i, a) {
      return (i + a) / 2
  }, f)
  console.log(ans)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))

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

import sys


class Die:
    def __init__(self, pips):
        self.pips = pips

    def move_die(self, direction):
        if direction == 'N':
            tmp = self.pips[0]
            self.pips[0] = self.pips[1]
            self.pips[1] = self.pips[5]
            self.pips[5] = self.pips[4]
            self.pips[4] = tmp
            del tmp
        elif direction == 'S':
            tmp = self.pips[0]
            self.pips[0] = self.pips[4]
            self.pips[4] = self.pips[5]
            self.pips[5] = self.pips[1]
            self.pips[1] = tmp
            del tmp
        elif direction == 'E':
            tmp = self.pips[0]
            self.pips[0] = self.pips[3]
            self.pips[3] = self.pips[5]
            self.pips[5] = self.pips[2]
            self.pips[2] = tmp
            del tmp
        elif direction == 'W':
            tmp = self.pips[0]
            self.pips[0] = self.pips[2]
            self.pips[2] = self.pips[5]
            self.pips[5] = self.pips[3]
            self.pips[3] = tmp
            del tmp

    def spin_die_clockwise(self):
        tmp = self.pips[1]
        self.pips[1] = self.pips[2]
        self.pips[2] = self.pips[4]
        self.pips[4] = self.pips[3]
        self.pips[3] = tmp
        del tmp


def init_die():
    pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
    die = Die(pips)

    return die


def roll_die(die):
    directions = list(sys.stdin.readline().strip('\n'))

    for direction in directions:
        die.move_die(direction)

    return die


def question_rightside(die):
    q = int(sys.stdin.readline().strip('\n'))

    for question in range(q):
        q_pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]

        if q_pips[0] == die.pips[1]:
            die.move_die('N')
        elif q_pips[0] == die.pips[2]:
            die.move_die('W')
        elif q_pips[0] == die.pips[3]:
            die.move_die('E')
        elif q_pips[0] == die.pips[4]:
            die.move_die('S')
        elif q_pips[0] == die.pips[5]:
            die.move_die('N')
            die.move_die('N')

        while die.pips[1] != q_pips[1]:
            die.spin_die_clockwise()

        print(die.pips[2])


def main():
    die = init_die()
    question_rightside(die)


if __name__ == '__main__':
    main()

Measured memory_bytes: 7836
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
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; }
 
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
//int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};


int main(){
    int N;
    cin >> N;
    ll ans = 0;
    int x[10][10] = {0};
    for(int i = 1; i <= N; i++){
        vector<int>d;
        int p = i;
        while(p > 0){
            d.push_back(p % 10);
            p /= 10;
        }
        int a = d.at(0);
        int b = d.back();
        if(a == 0 || b == 0) continue;
        x[a][b]++;
    }
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            ans += x[i][j] * x[j][i];
        }
    }
    print(ans);
    return 0;
}

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

int main() {
	ios::sync_with_stdio(0),cin.tie(0);
	int n,len=0,result=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int temp;
		cin>>temp;
		len=max(len,temp);
		if(temp>=len)
			result++;
	}
	cout<<result<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    if ((a <= c) && (c <= b)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }
}

Measured memory_bytes: 35732
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;

#define INF 1e9

int main(){
  long long a,b;
  cin >> a >> b;
  long long ans;
  if(b-a < 10){
    ans = a;
    for(int i=1;i<b-a+1;i++){
      ans = ans^(a+i);
    }
    cout << ans << endl;
    return 0;
  }
  long long count;
  if(a%2 == 0){
    count = (b-a+1)%4;
    if(count == 0){
      cout << 0 << endl;
    }
    else{
      ans = 0;
      for(int i=0;i<count+4;i++){
        ans = ans^(b-i);
      }
      cout << ans << endl;
    }
    return 0;
  }

  count = (b-a+1)%4;
  ans = a;
  ans = a^0;
  for(int i=0;i<count-1+4;i++){
    ans = ans^(b-i);
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int H, W;
	cin >> H >> W;
	vector<vector<char>> C(H, vector<char>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> C[i][j];
		}
	}
	for (int i = 0; i < 2 * H; i++) {
		for (int j = 0; j < W; j++) {
			cout << C[i / 2][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main() {
	int sx, sy, tx, ty, cx, cy, gx, gy;
	scanf("%d %d %d %d", &sx, &sy, &tx, &ty);
	cx = sx;
	cy = sy;
	gx = tx;
	gy = ty;
	while (cy != gy) {
		cy++;
		printf("U");
	}
	while (cx != gx) {
		cx++;
		printf("R");
	}
	gx = sx;
	gy = sy;
	while (cy != gy) {
		cy--;
		printf("D");
	}
	while (cx != gx) {
		cx--;
		printf("L");
	}
	gx = tx;
	gy = ty;
	gy++;
	cx--;
	printf("L");
	while (cy != gy) {
		cy++;
		printf("U");
	}
	while (cx != gx) {
		cx++;
		printf("R");
	}
	cy--;
	printf("D");

	gx = sx;
	gy = sy;
	gy--;
	cx++;
	printf("R");
	while (cy != gy) {
		cy--;
		printf("D");
	}
	while (cx != gx) {
		cx--;
		printf("L");
	}
	cy++;
	printf("U");
//	printf("%4d %4d", cx, cy);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;

int h,w,n;
vector<int> v;

int main(){
  cin>>h>>w>>n;
  rep(i,n){
    int a;
    cin>>a;
    rep(j,a) v.push_back(i+1);
  }

  int ans[h][w],cnt=0;
  rep(i,h){
    if(i%2) //逆
    {
      int pos=w-1;
      while(pos>=0){
        ans[i][pos]=v[cnt];
        cnt++,pos--;
      }
    }
    else //順
    {
      int pos=0;
      while(pos<w){
        ans[i][pos]=v[cnt];
        cnt++,pos++;
      }
    }
  }

  rep(i,h){
    rep(j,w){
      cout<<ans[i][j];
      if(j==w-1) cout<<endl;
      else cout<<" ";
    }
  }
}

Measured memory_bytes: 384
import math
import itertools
N = int(input())
x = [list(map(int,input().split(' '))) for i in range(N)]
length = range(N)
ans = []

for i in itertools.permutations(length): #1,2,3 231

   result = []
   for i1 in range(len(i)-1):
       result.append(math.sqrt((x[i[i1]][0]-x[i[i1+1]][0])**2 + (x[i[i1]][1]-x[i[i1+1]][1]) **2))


   ans.append(sum(result))

print(sum(ans)/len(ans))


Measured memory_bytes: 42332
N = int(input())
s = input()
t = input()

cnt = 0
for i in range(N):
    if s[i]==t[0]:
        for j in range(N):
            if s[i+j]!=t[j]:
                break
            if i+j>=N-1:
                cnt = max(cnt, j+1)
                break
ans = N+N-cnt
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

template <typename T>
struct fenwick_tree {
    int n, power; // min power s.t. n <= power && power = 2^k;
    vector<T> data;
    fenwick_tree(int n=0) : n(n), data(n+1) {
        power = 1;
        while (power < n) power <<= 1;
    }
    void add(int i, T x=1) {
        for (i++; i <= n; i += i&-i) data[i] += x;
    }
    // [0, i)
    T sum(int i) {
        T res = 0;
        for (; i; i -= i&-i) res += data[i];
        return res;
    }
    // [l, r)
    T sum(int l, int r) { return sum(r) - sum(l);} 
    // min x s.t. v0 + v1 + v2 + ... + vx　>= w
    int lower_bound(T w) {
        if (w <= 0) return 0;
        int x = 0;
        for (int i = power; i; i >>= 1) {
            if (i+x <= n && data[i+x] < w) {
                w -= data[i+x];
                x += i;
            }
        }
        return x;
    }
};

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

    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    rep(i, n) cin >> a[i], a[i]--;

    vector<int> left(n+1, -1);
    auto ys = make_vec<int>(n+1, 0);
    rep(i, n) {
        ys[left[a[i]] + 1].push_back(i);
        left[a[i]] = i;
    }
    
    auto qs = make_vec<pair<int, int>>(n+1, 0);
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        qs[l].emplace_back(r, i);
    }

    fenwick_tree<int> ft(n+1);
    vector<int> ans(q);
    for (int l = 0; l <= n; ++l) {
        for (int y : ys[l]) ft.add(y);
        for (auto [r, id] : qs[l]) ans[id] = ft.sum(l, r+1);
    }
    rep(i, q) cout << ans[i] << endl;
}


Measured memory_bytes: 59832
import sys
from math import sin, cos, pi, sqrt
S = sys.stdin.read()
A, B, H, M = [int(x) for x in S.split()]

angle_a = 2 * pi / 60 * M
angle_b = 2 * pi * (H / 12 + M / 60 / 12)
ax = sin(angle_a) * A
ay = cos(angle_a) * A
bx = sin(angle_b) * B
by = cos(angle_b) * B
d = sqrt((ax - bx) ** 2 + (ay - by) ** 2)
print(d)


Measured memory_bytes: 9580
#include <stdio.h>
int main(void){
	while(1){
		int h,w;
		scanf("%d %d\n",&h,&w);
		if(h==0 && w==0){
			break;
		}else{
			int n,m;
			for(n=0;n<h;n++){
				for(m=0;m<w;m++){
					printf("#");
				}
				printf("\n");
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 576
import sys
sys.setrecursionlimit(10**6)
INF = 10**10
 
def dfs(edge, visited, n):
    if visited[n]:
        return
    visited[n] = True
    for to, _ in edge[n]:
        dfs(edge, visited, to)

def bellman_ford(edge, mask):
    dist = [INF] * n
    dist[0] = 0

    for _ in range(n):
        update = False
        for i, es in enumerate(edge):
            if not mask[i]:
                continue
            for to, cost in es:
                if not mask[to]:
                    continue
                if dist[i] != INF and dist[i] + cost < dist[to]:
                    dist[to] = dist[i] + cost
                    update = True
        if not update:
            return dist
    else:
        # Found minus loops
        return -INF

if __name__ == "__main__":
    n, m, p = [int(item) for item in input().split()]
    edge = [[] for _ in range(n)]
    redge = [[] for _ in range(n)]
    for i in range(m):
        a, b, c = [int(item) for item in input().split()]
        # Think as penalty costs per walk
        a -= 1; b -= 1; c -= p
        # Reverse cost to assume as shortest path problem
        c *= -1
        edge[a].append((b, c))
        redge[b].append((a, c)) 
    
    # Is the node can be arrived from start?
    visited = [False] * n
    dfs(edge, visited, 0)
    # Is the node can go to the end?
    rvisited = [False] * n
    dfs(redge, rvisited, n-1)
    mask = [forward and backward for forward, backward in zip(visited, rvisited)]

    dist = bellman_ford(edge, mask)
    if dist == -INF:
        print(-1)
    else:
        print(max(0, -dist[n-1]))

Measured memory_bytes: 66136
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		long D = Integer.parseInt(sc.get());
		int count = 0;
		for (int i = 0; i < N; i++) {
			long X = Long.parseLong(sc.get());
			long Y = Long.parseLong(sc.get());
			if (X * X + Y * Y <= D * D) {
				count++;
			}
		}
		System.out.println(count);
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		new Solver().solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

Measured memory_bytes: 53388
//chiragjn
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define gibe_de_fast_io_b0ss ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const ll mod = 1e9 + 7;
const ll INF = 0x7FFFFFFFFFFFFFFF/2;
double cache[301][301][301] = {0};
int N;
double recur(int i, int j, int k) {
	if(i <= 0 && j <= 0 && k <= 0) {
		return 0;
	}
	if(cache[i][j][k] >= 0) return cache[i][j][k];
	cache[i][j][k] = 0;
	double t = (i + j + k);
	double a = 0, b = 0, c = 0, d = 0;
	if(i > 0) a = i * (1.0 + recur(i - 1, j + 1, k));
	if(j > 0) b = j * (1.0 + recur(i, j - 1, k + 1));
	if(k > 0) c = k * (1.0 + recur(i, j, k - 1));
	d = N - t;
	cache[i][j][k] = (a + b + c + d)/t;
	return cache[i][j][k];
}
int main(){
    gibe_de_fast_io_b0ss;
    cin>>N;
    for(int i = 0; i <= N; i++) {
    	for(int j = 0; j <= N; j++) {
    		for(int k = 0; k <= N; k++) {
    			cache[i][j][k] = -1;
    		}
    	}
    }
    int cs[4] = {0};
    int t;
    for(int i = 0; i < N; i++) {
    	cin>>t;
    	cs[t]++;
    } 
    cache[0][0][0] = 0;
    cout<<fixed<<setprecision(16)<<recur(cs[3], cs[2], cs[1]);
    return 0;
}


Measured memory_bytes: 213376
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n;cin>>n;
    int d[n];
    if(n%2==1){
     cout<<0;
     return 0;
    }
    for(int i = 0;i<n;i++) cin >> d[i];
    sort(d,d+n);
    int dm = d[n/2];
    int sm = d[n/2-1];
    if(dm == sm){
     cout<<0;
     return 0;
    }
    else{
      cout<<dm-sm;
    }
    return 0;
}

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

int main(void){
    int n,m,X,Y,x[101],y[101],war=1;
    int maxx=-200,miny=101;
    cin >> n >> m >> X >> Y;
    for(int i=0;i<n;i++){
        cin >> x[i];
        if(x[i]>maxx) maxx = x[i];
    }
    for(int i=0;i<m;i++){
        cin >> y[i];
        if(y[i]<miny) miny = y[i];
    }
    for(int i=X+1; i<=Y; i++){
        if(i>maxx && i<=miny){
            war = 0;
        }
    }
    if(war){
        cout << "War" << endl;
    }else{
        cout << "No War" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
// C - Candies
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
int in(){int x;scanf("%d",&x);return x;}

int main(){
	int N=in();
	int A[N+1],B[N+1],ans=0; A[0]=0, B[0]=0;
	rp(i, 1, N+1) A[i]=in()+A[i-1];
	rp(i, 1, N+1) B[i]=in()+B[i-1];
	rp(i, 1, N+1) ans = max(ans, A[i]+B[N]-B[i-1]);
	printf("%d\n",ans);
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

// 入力変数, グローバルに使うのでここで定義teigi
int h,w,k;
vector<vector<char>> s(310, vector<char>(310));
// 出力用の変数
vector<vector<int>> ans(310, vector<int>(310, 0));
// いちごがある行を保持するvector
vector<int> has_s_line;

int solve(int line, int now) {
    bool first_berry=false;
    rep(j, w) {
        if(s[has_s_line[line]][j] == '#') {
            if(!first_berry) first_berry=true;
            else now++;
        }
        // 最初と最後だけ特殊な処理になる
        if(line == 0) {
            // 0行目にいちごがない可能性がある
            // いちごが1つしかない場合の対応
            if(has_s_line.size() == 1) {
                for(int i=0; i<h; i++) {
                    ans[i][j] = now;
                }
            } else {
                for(int i=0; i<has_s_line[line+1]; i++) {
                    ans[i][j] = now;
                }
            }
        } else if(line == has_s_line.size()-1) {
            // 次のlineが見れないので、hを直接いれる
            for(int i=has_s_line[line]; i<h; i++) {
                ans[i][j] = now;
            }
        } else {
            // 通常はline行にだけ、いちごがあるので、そこを見ればいい
            for(int i=has_s_line[line]; i<has_s_line[line+1]; i++) {
                ans[i][j] = now;
            }
        }
    }

    // 次の行にいくときにインクリメントする
    now++;
    return now;
}

int main() {
    // 入力
    cin >> h >> w >> k;
    rep(i, h) rep(j, w) cin >> s[i][j];

    // いちごがある行を求めていく
    rep(i, h) rep(j, w) if(s[i][j] == '#') {
        has_s_line.push_back(i);
        break;
    }

    // 現在のケーキの切り分けたケーキ番号を管理数r
    int now = 1;
    // 求める
    rep(i, has_s_line.size()) {
        now = solve(i, now);
    }

    // 出力, AtCoderでは改行=スペースなので、普通に全部改行でいい、
    rep(i, h) rep(j, w) {
        cout << ans[i][j] << endl;
    }

    // 自分で確認用に見やすくした場合
//    rep(i, h) {
//        rep(j, w) {
//            cout << ans[i][j] << " ";
//        }
//        cout << endl;
//    }

    return 0;
}



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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  if ((r * 100 + g * 10 + b) % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    int n;
    int q;
    cin >> n >> q;
    string s;
    cin >> s;
    vi sum(n + 1, 0);
    repi(i, 1, n)
    {
        if (s[i - 1] == 'A' && s[i] == 'C')
        {
            sum[i + 1] = sum[i] + 1;
        }
        else
        {
            sum[i + 1] = sum[i];
        }
    }
    rep(i, q)
    {
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l] << endl;
    }
    return 0;
}

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

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

using namespace std;
using ll = long long;
using P = pair<int,int>;


void calc_primefactorization(long long in, vector<vector<long long> >& out){
	
	long long N = in, Ntmp;
	long long p,e,p_init = 2;
	vector<long long> out_tmp(2);
	
	if( in == 1 ){
		out_tmp[0] = 1;
		out_tmp[1] = 1;
	}
	else{
		while( 1 ){

			Ntmp = N;
				
			p = N;
			e = 1;

			for(long long i = p_init;i * i <= N;i++){
						
				if( Ntmp % i == 0 ){
					e = 0;
					while( 1 ){
						if( Ntmp % i != 0 ){
							break;
						}
						else{
							Ntmp = Ntmp / i;
							e++;
						}
					}
					p = i;
					break;
				}
				
			}
			
			out_tmp[0] = p;
			out_tmp[1] = e;
			out.push_back(out_tmp);
			
			for(int i = 0;i < e;i++){
				N = N / p;
			}
			
			if( N == 1 ){
				break;
			}
			
		}
	}
	
}

int bitmask(int n){
	
	int a = 1;
	
	return ( a << (n - 1) );
	
}

bool judge(int a, int b){
	
	if( (a & bitmask(b)) > 0 ){
		return true;
	}
	else{
		return false;
	}
	
}

int main(){
	
	int N;
	cin >> N;
	
	vector<int> a(N);
	
	int ans = 0;
	
	for(int i = 0;i < N;i++){
		cin >> a[i];
		if( ( ( i % 2 ) == 0 ) && ( ( a[i] % 2 ) == 1 ) ){
			ans++;
		}
	}

	cout << ans;

	return 0;
	
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define rep(i,a,m) for((i) = (a) ; (i) < (m) ; ++(i))
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.end(),x.begin()
#define sz(x) ((int)x.size())
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pi;
int a, b, c, i, j, k;
long long ans = 0LL;
int main ()
{
	int t,T,n;

    pair<int,int> A[101];
    string yes = "Yes";
    int foo[3][3] = {{-1,-1,-1}, {-1,-1,-1}, {-1,-1,-1}};
    for(int i = 0; i < 101; ++ i) A[i] = mp(-1,-1);
    int B[101] = {0};
    for(int i = 0; i < 3; ++ i){
        for(int j = 0; j < 3; ++ j){
            scanf("%d",&a);
            A[a].fi = i; A[a].se = j;
        }
    }
    scanf("%d",&n);
    for(int i = 0; i < n; ++ i){
        scanf("%d",&a);
        B[a] ++;
        if (A[a].fi != -1 && A[a].se != -1){
            foo[A[a].fi][A[a].se] = a;
        }
    }
    int count = 0;
    for(int i = 0; i < 3; ++ i){
        count = 0;
        for(int j = 0; j < 3; ++ j){
            if (foo[i][j] != -1) { count ++;}
            else break;
        }
        if (count == 3) { cout << yes << endl; return 0;}
    }

    for(int j = 0; j < 3; ++ j){
        count = 0;
        for(int i = 0; i < 3; ++ i){
            if (foo[i][j] != -1) { count ++;}
            else break;
        } 
        if (count == 3) { cout << yes << endl; return 0;}
    }
    count = 0;
    for(int i = 0; i < 3; ++ i){
        if (foo[i][i] != -1) count ++;
        else break;
        if (count == 3) { cout << yes << endl; return 0;}
    }
    count = 0;
    for(int i = 0, j = 2; i < 3 && j >= 0; ++ i, -- j){
        if (foo[i][j] != -1) count ++;
        else break;
        if (count == 3) { cout << yes << endl; return 0;}
    }
    cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
//This is getting accepted!
#include<bits/stdc++.h>
#define ll long long
#define oo 1000000009
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define INA(a,n) for (int i = 1; i <= (n); ++i) cin >> a[i];
#define ITE(x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define isset(x, i) (((x)>>(i))&1)
#define setbit(x, i) ((x)^(1ll<<(i)))
#define clearbit(x, i) ((x)&(~(1ll<<(i))))
#define twoexp(i) (1ll<<(i))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) >= 0 ? (a) : -(a))
#define FI first
#define SE second
#define son1 (id*2)
#define son2 (id*2+1)

using namespace std;

const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = 2 * acos(0);
const int MAXN = 2006;

int res;
string s[MAXN];
int le[MAXN][MAXN];
int ri[MAXN][MAXN];
int up[MAXN][MAXN];
int down[MAXN][MAXN];
int n, m;

void input() {
	int u, v, w, x, y, qtype;
	
	cin >> n >> m;
	FOR(i, 0, n-1)
		cin >> s[i];
	
}


void preprocess() {
	
	res = 0;
	
	FOR(i, 0, n-1) {
		FOR(j, 0, m-1) {
			if (s[i][j] == '.')
				le[i][j] = (j > 0 ? le[i][j-1] + 1 : 1);
			else
				le[i][j] = 0;
		}
	}
	
	FOR(i, 0, n-1) {
		for(int j = m-1; j >= 0; --j) {
			if (s[i][j] == '.')
				ri[i][j] = (j < m-1 ? ri[i][j+1] + 1 : 1);
			else
				ri[i][j] = 0;
		}
	}
	
	FOR(j, 0, m-1) {
		FOR(i, 0, n-1) {
			if (s[i][j] == '.')
				down[i][j] = (i > 0 ? down[i-1][j]+1 : 1);
			else
				down[i][j] = 0;
		}
	}
	
	FOR(j, 0, m-1) {
		for (int i = n-1; i >= 0; --i) {
			if (s[i][j] == '.')
				up[i][j] = (i < n-1 ? up[i+1][j] + 1 : 1);
			else
				up[i][j] = 0;
		}
	}
	
}

void process(int itest) {
	int u, v, w, x, y, qtype;
	
	FOR(i, 0, n-1) {
		FOR(j, 0, m-1) 
			if (s[i][j] == '.') {
				res = MAX(res, le[i][j] + ri[i][j] + up[i][j] + down[i][j] - 3);
			}
	}
	
	cout << res << endl;
	
}

void oneTest() {
	
	input();
	preprocess();
	process(0);
	
}

void multiTest() {
	
	int t;
	cin >> t;
	
	for (int it = 1; it <= t; ++it) {
		input();
		preprocess();
		process(it);
	}
}

int main(){
    #ifndef ONLINE_JUDGE
//    freopen("../out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	oneTest();
//	multiTest();

    return 0;

}


Measured memory_bytes: 67328
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

static const double eps = 1e-8;

int main(){
	double n;	
	while(~scanf("%lf",&n)){
		if(n==-1.0) break;
		int a = n;
		double b = n - (double)a;

		bitset<8> front;
		for(int i=0;i<8;i++){
			if(a & (1<<i)) front |= (1<<i);
		}

		bitset<4> rear;
		for(int i=0;i<4;i++){
			b*=2.0;
			if(b + eps > 1.0){
				rear |= (1<<i);
				b -= 1.0;
			}
		}

		if(!(b+eps > 0.0 && b-eps < 0.0) || a != front.to_ulong()) {
			printf("NA\n");
		}
		
		
		else {
			string r = rear.to_string();
			reverse(r.begin(),r.end());
			printf("%s.%s\n",front.to_string().c_str(),r.c_str());
		}
	}
}

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

#define ll long long
#define ar array

const int mxN=2e3;
int n, m;
ll iv[3*mxN+1], f2[3*mxN+1], ans;

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

	cin >> n >> m;
	iv[1]=1;
	for(int i=2; i<=3*mxN; ++i)
		iv[i]=m-m/i*iv[m%i]%m;
	f2[0]=1;
	for(int i=1; i<=3*mxN; ++i)
		f2[i]=f2[i-1]*iv[i]%m;
	ll p1=1;
	for(int x=0; x<=n; ++x, p1=p1*iv[3]%m) {
		ll p2=1;
		for(int y=0; x+y<=n; ++y, p2=p2*iv[2]%m) {
			int z=n-x-y;
			ans=(ans+p1*p2%m*f2[y]%m*f2[y+3*z]%m*f2[x])%m;
			//cout << x << " " << y << " " << z << endl;
			//cout << p1*p2%m*720%m*f2[y]%m*f2[y+3*z]%m*f2[x]%m << endl;
		}
	}
	for(int i=2; i<=3*n; ++i)
		ans=ans*i%m;
	cout << ans;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ii> P;
typedef unsigned long long int ull;
const int MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e9;

int main(){
    int n,m;cin>>n>>m;
    int a[m];
    for(int i=0;i<m;i++) cin>>a[i];
    string dp[n+10];
    for(int i=0;i<n+10;i++) dp[i]="";
    for(int i=0;i<n;i++){
        if(i!=0&&dp[i]=="") continue;
        for(int j=0;j<m;j++){
            int b;
            if(a[j]==1) b=2;
            else if(a[j]==7) b=3;
            else if(a[j]==4) b=4;
            else if(a[j]==2||a[j]==3||a[j]==5) b=5;
            else if(a[j]==6||a[j]==9) b=6;
            else if(a[j]==8) b=7;
            string t=dp[i]+(char)(a[j]+'0');
            if((int)t.size()>(int)dp[i+b].size()) dp[i+b]=t;
            else if((int)t.size()==(int)dp[i+b].size()){
                if(t>dp[i+b]) dp[i+b]=t;
            }
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 54792
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto N = readln.chomp;
    auto DP = new int[][](N.length+1, 2);
    DP[0][0] = 0;
    DP[0][1] = 1;
    foreach (i; 0..N.length) {
        auto n = (N[i] - '0').to!int;
        DP[i+1][0] = min(DP[i][0] + n, DP[i][1] + 10-n);
        DP[i+1][1] = min(n == 9 ? int.max : (DP[i][0] + n+1), DP[i][1] + 10-n-1);
    }
    writeln(DP[N.length][0]);
}

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

int compare_int(const void *a, const void *b)
{
  return *(int*)a - *(int*)b;
}

int main(void)
{
  int n;
  scanf("%d", &n);
  int v[n];
  int i = 0;
  while (i < n)
  {
    scanf("%d", &v[i]);
    i++;
  }
  
  qsort(v, n, sizeof(int), compare_int);
  
  double ans = ((double)v[0] + v[1]) / 2;
  i = 2;
  while (i < n)
  {
    ans = (ans + v[i]) / 2;
    i++;
  }
  
  printf("%lf", ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    ll ans = 0;
    int right = 0, sum = 0;
    for (int left = 0; left < n; left++) {
        while (right < n && (sum ^ a[right]) == (sum + a[right])) {
            sum ^= a[right];
            right++;
        }
        ans += right - left;
        if (left == right) {
            right++;
        } else {
            sum ^= a[left];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut av = vec![0i32; n];
    for i in 0..n - 1 {
        av[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    av[n - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    let mut cv = vec![0i32; n];
    for i in 0..n {
        let j = n - i - 1;
        let x = j + 1;

        let mut index = 2;
        let mut count = 0;
        while index * x <= n {
            count += cv[index * x - 1];
            index += 1;
        }

        if (count % 2) != (av[j] % 2) {
            cv[j] = 1;
        }
    }

    let mut ans = Vec::new();
    for i in 0..n {
        if cv[i] > 0 {
            ans.push(i + 1);
        }
    }

    println!("{}", ans.len());
    if ans.len() > 0 {
        let mut first = true;
        for i in 0..ans.len() {
            if first {
                first = false;
                print!("{}", ans[i]);
            } else {
                print!(" {}", ans[i]);
            }
        }
        println!();
    }
}


Measured memory_bytes: 9084
#include <stdio.h>

int main(){
	int tanka,kazu,price,sum,ave,cnt;

	sum = 0;
	price = 0;
	cnt = 0;
	while(scanf("%d,%d",&tanka,&kazu) != EOF){
		price += (tanka*kazu);
		sum += kazu;
		cnt++;
	}

	ave = sum/cnt;
	ave += ((sum%cnt)*2 >= cnt) ? 1 : 0;

	printf("%d\n%d\n",price,ave);

	return 0;
}

Measured memory_bytes: 592
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i, b in enumerate(B):
    an = min(b, A[i])
    b -= an
    A[i] -= an
    ans += an

    an_ = min(b, A[i+1])
    A[i+1] -= an_
    ans += an_
print(ans)


Measured memory_bytes: 18624
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>



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

  int p,q;
  cin>>p>>q;
  int ans=1;
  q=q/__gcd(p,q);
  for(int i=2;i*i<=q;i++){
    if(q%i==0){
      ans*=i;
      while(q%i==0){
        q/=i;
      }
    }
  }

  ans*=q;
  cout<<ans<<endl;

}



Measured memory_bytes: 3208
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> S(H+2);
  for(int i = 1;i <H+1;i++){
    cin >> S.at(i);
  }
  //周りを’。’で覆ったものが完成
  for(int i =1;i<H+1;i++){
    S.at(i) = '.' + S.at(i) + '.';
  }
  S.at(0) =  S.at(1);
  S.at(H+1) = S.at(1);

  rep(i,W+2){
    S.at(0).at(i) = '.';
    S.at(H+1).at(i) = '.';
  }

  //rep(i,H+2) cout << S.at(i) <<endl;

  bool hantei = true;
  int dx[4] = {1,-1,0,0};
  int dy[4] = {0,0,1,-1};
  for(int i = 1;i < H+1;i++){
    for(int j = 1;j< W+1;j++){
      if(S.at(i).at(j) == '.') continue;
      for(int k = 0;k<4;k++){
        int i2 = i + dx[k];
        int j2 = j + dy[k];
        if(i2 >= 1 && i2 < H+1 && j2 >= 1 && j2 < W+1 && S.at(i2).at(j2) == '#'){
          hantei = true;
          break;
        }
        else{
          hantei = false;
        }
      }
      /*
      if(S.at(i-1).at(j) == '#' || S.at(i+1).at(j) == '#' || S.at(i).at(j+1) == '#' || S.at(i).at(j-1) == '#'){
        hantei = true;
      }
      else{
        hantei = false;
        break;
      }
      */
      if(!hantei)break;
    }if(!hantei)break;
  }

  /*
  vector<vector<char>> data(H+2,vector<char>(W+2));
  rep(i,W+2){
    data.at(0).at(i) = '.';
  }
  for(int i = 1;i < H+1;i++){
    for(int j = 1;j < W+1;j++){
      data.at(i).at(j) = S.at(i).at(j);
    }
  }
  for(int i = 1;i < H+1;i++){
    data.at(i).at(0) = '.';
  }
  for(int i = 1;i < H+1;i++){
    data.at(i).at(W+2) = '.';
  }
  rep(i,W+2){
    data.at(H+2).at(i) = '.';
  }
  bool hantei = false;

  for(int i = 1;i < H+1;i++){
    for(int j = 1;j < W+1;j++){
      if(data.at(i-1).at(j) == '#' || data.at(i+1).at(j) == '#' || data.at(i).at(j+1) == '#' || data.at(i).at(j-1) == '#'){
        hantei = true;
      }
      else{
        hantei = false;
        break;
      }
    }
  }
  */

  if(hantei) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main(){
    int N,K;
    int count=0;
    cin >> N >> K;
    
    vector<int> h(N);
    for(int i=0;i<N;i++) cin >> h[i];
    
    for(int i=0;i<N;i++){
        if(h.at(i) >= K) count++;
    }
    cout << count << endl;
    return 0;
}

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

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

    int n;
    cin >> n;
    string s[n];
    rep(i,n) cin >> s[i];
    
    map<char, ll> m;
    
    rep(i,n){
        if(s[i][0]=='M' || s[i][0]=='A' || s[i][0]=='R' || s[i][0]=='C' || s[i][0]=='H'){
            m[s[i][0]]++;
        }
    }
    ll a = m['M'];
    ll b = m['A'];
    ll c = m['R'];
    ll d = m['C'];
    ll e = m['H'];
    
    cout << a*b*c + a*b*d + a*b*e + a*c*d + a*c*e + a*d*e + b*c*d + b*c*e + b*d*e + c*d*e << endl;

    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  int ans = C - (A - B);
  if(ans <= 0){
  	cout << 0 << endl;
  }else{
  	cout << ans << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

ll score(ll a,int pos){
	if(pos==0||pos==4) return a;
	if(pos==1||pos==3){
		if(a==0)return 2;
		else return a%2;
	}
	return (a+1)%2;
}

int main()
{
	ll l;
	cin >> l;
	vector<ll> a(l);
	for(int i = 0; i < l; i++){
		cin >> a[i];
	}

	vector<vector<ll> > dp(l+1,vector<ll>(5,INF*INF));
	for(int i = 0; i < 5; i++){
		dp[0][i] = 0;
	}
	for(int i = 0; i < l; i++){
		for(int j = 0; j < 5; j++){
			if(j>0) dp[i][j] = min(dp[i][j],dp[i][j-1]);
			dp[i+1][j] = min(dp[i+1][j],dp[i][j] + score(a[i],j));
		}
	}
	ll ans = INF*INF;
	for(int i = 0; i < 5; i++){
		ans = min(ans,dp[l][i]);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 15872