akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define rep(I,N) up(I,0,N-1)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<"\n";}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<"\n";}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<"\n";}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<"\n";}
inline void                                              out(ld p){printf("%.12Lf\n",p);}
template<class T>inline void outml(T p){for_each(all(p),out<decltype(p[0])>);}//ml=multi line
template<class T>inline void outol(T V){auto n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}//ol=one line
inline void solve(void){
  ll N,K;
  in(N,K);
  vector<ll>A(N+1);
  rep(i,K){
    ll d;
    in(d);
    rep(j,d){
      ll a;
      in(a);
      A[a]++;
    }
  }
  ll cnt=0;
  up(i,1,N)if(A[i]==0)cnt++;
  out(cnt);
}
int main(void){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 3656
#include <stdio.h>
#include <queue>

#define ll long long

using namespace std;

priority_queue<ll> mx_heap, mn_heap;
ll constant;

ll mx_heap_sum, mn_heap_sum;

int main()
{
	int Q;

	scanf("%d", &Q);

	int update_q_cnt = 0;

	for (int i = 0; i < Q; ++i)
	{
		int cmd;

		scanf("%d", &cmd);

		if (cmd == 1)
		{
			ll a, b;

			scanf("%lld %lld", &a, &b);

			update_q_cnt++;

			constant += b;

			if (update_q_cnt & 1)
			{
				mx_heap.push(a);
				mx_heap_sum += a;
			}
			else
			{
				mn_heap.push(-a);
				mn_heap_sum += a;
			}
			while (!mx_heap.empty() && !mn_heap.empty() && mx_heap.top() > -mn_heap.top())
			{
				ll temp = mx_heap.top();
				
				mx_heap_sum -= mx_heap.top();
				mx_heap.pop();
				
				mx_heap_sum += -mn_heap.top();
				mx_heap.push(-mn_heap.top());
				
				mn_heap_sum -= -mn_heap.top();
				mn_heap.pop();

				mn_heap_sum += temp;
				mn_heap.push(-temp);
			}
		}
		else printf("%lld %lld\n", mx_heap.top(), ((ll)mx_heap.top()*(ll)mx_heap.size() - mx_heap_sum) + (mn_heap_sum - (ll)mx_heap.top()*(ll)mn_heap.size()) + constant);
	}

	return 0;
}

Measured memory_bytes: 3828
fn main() {
    let (a, b, k) = read();
    let (ax, bx) = solve(a, b, k);
    write(ax, bx);
}

fn read() -> (i64, i64, i64) {
    let mut l1 = String::new();
    std::io::stdin().read_line(&mut l1).ok();
    let mut iter = l1.trim().split_whitespace();
    let a: i64 = iter.next().unwrap().parse().unwrap();
    let b: i64 = iter.next().unwrap().parse().unwrap();
    let k: i64 = iter.next().unwrap().parse().unwrap();

    (a, b, k)
}

fn write(a: i64, b: i64) {
    println!("{} {}", a, b);
}

fn solve(mut a: i64, mut b: i64, k: i64) -> (i64, i64) {
    if a >= k {
        a -= k;
    } else {
        b -= k - a;
        a = 0;
    }

    a = if a < 0 {0} else {a};
    b = if b < 0 {0} else {b};
    (a, b)
}


Measured memory_bytes: 2120
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		scan.close();
		int n = b - a;
		int ans = (n * (n + 1)) / 2 - b;
		System.out.println(ans);

	}
}

Measured memory_bytes: 21972
from collections import deque
n, m, k =map(int, input().split())

directcount = [0] * n # node_iが直接接続しているノードの数
visited = [-1]  * n # nodeの色,
colorcount = [-1] * n # 各色が何個のノードを持つか
# グラフの初期化
g = []
for _ in range(n):
    g.append(deque(list()))

# グラフの生成
for i in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1 # 1origin -> 0 origin
    g[a].append(b)
    g[b].append(a)
    # 直接接続されているノードの数
    directcount[a] += 1
    directcount[b] += 1

# dfs 連結したグラフごとにそのグラフの最初に探索したnodeの色に染める
q = deque(list()) #探索キュー
for i in range(n):
    q.append(i)
    color = i
    cnt = 1
    while len(q) > 0:
        nextnode = q.popleft() # 次の探索
        if visited[nextnode] != -1:
            continue
        visited[nextnode] = color
        q.extend(g[nextnode]) # nextnodeの辺を足す
        cnt += 1
    # 探索が終わったらその色のノードの数を記録
    colorcount[color]  = cnt - 1

# res[i] = ノードの色, その色のノードの数 - そのノードが直接接続しているノード数 - 自分自身(1)　で初期化する
res = [[visited[i], colorcount[visited[i]] - (directcount[i] + 1)] for i in range(n)]

# ブロックリスト
for i in range(k):
    c, d = map(int, input().split())
    c, d = c - 1, d - 1 # 1 origin -> 0 origin
    # ブロック関係が同じ色だとするなら
    if res[c][0] == res[d][0]:
        # 友達になれると思っていた数を1つ減らす
        res[c][1] -= 1
        res[d][1] -= 1

# 各ノードから「直接つながっているノード」と「自分自身=1」を抜く
#for i in range(n):
#    res[i][1] -= (directcount[i] + 1)

# 結果の表示
print(" ".join(list(map(lambda x: str(x[1]), res))))


Measured memory_bytes: 125832
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll q,h,s,d,n,o;scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n);
  o = min({q*4,h*2,s});
  if(d<o*2) printf("%lld\n",n/2*d+o*(n%2));
  else printf("%lld\n",o*n);
}

Measured memory_bytes: 3796
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,ans=0,i;
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		int a;
		scanf("%d",&a);
		while (a%2==0) {ans++;a/=2;}
	}
	printf("%d",ans);
	return 0;
}

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

using namespace std;

int main() {
    string S;
    cin >> S;

    vector<long long> dp(2019, 0);

    long long ans = 0;
    for(int i=0; i<S.size(); i++) {
        vector<long long> next(2019, 0);
        int t = S[i] - '0';

        for(int j=0; j<2019; j++) {
            next[(j * 10 + t) % 2019] += dp[j];
        }
        next[t]++;

        dp = next;

        ans += dp[0];
    }

    cout << ans << endl;
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream& operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto& vv : V) os << vv << ","; os << "]";
  return os;
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 100101;
int n;
vector<PII> d[MAX*2];
bool cz[MAX*2];
int war[MAX*2];
int inf = 1e12;
PII dfs(int v,int wa){
  if(cz[v]){
    if(war[v] != wa){
      debug(v, war[v], wa);
      cout << "No\n";
      exit(0);
    }
    return {inf,inf};
  }
  war[v] = wa;
  cz[v] = 1;
  int w1 = wa,w2 = inf;
  for(PII ak:d[v]){
    int p1,p2;
    tie(p1,p2) = dfs(ak.FI, ak.SE - wa);
    mini(w1,p2);
    mini(w2,p1);
  }
  return {w1,w2};
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> n;
  cin >> n;
  R(i,n){
    int a,b,c;
    cin >> a >> b >> c;
    b+=MAX;
    d[a].PB({b, c});
    d[b].PB({a, c});
  }
  R(i,MAX*2){
    if(!cz[i]){
      PII pom = dfs(i,0);
      if(pom.FI + pom.SE < 0){
        cout << "No\n";
        return 0;
      }
    }
  }
  cout << "Yes\n";
}


Measured memory_bytes: 16640
#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 main(){
  char s[4];
  int n[4];
  rep(i,4){
    cin>>s[i];
    n[i]=s[i]-'0';
  }
  string ans;

  int a=n[0]*10+n[1],b=n[2]*10+n[3];
  if(a==0 || a>12){
    if(b==0 || b>12) ans="NA";
    else ans="YYMM";
  }
  else{
    if(b>0 && b<13) ans="AMBIGUOUS";
    else ans="MMYY";
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;

namespace AOJ.Volume0
{
    public class Thief
    {
        public static int Main()
        {
            int dataset_cnt = 0;
            while (true)
            {
                int w = int.Parse(Console.ReadLine());
                if (w == 0) { break; }
                dataset_cnt++;

                int n = int.Parse(Console.ReadLine());

                var dp = new long[n + 1, w + 1];
                for (int i = 0; i <= n; i++)
                {
                    for (int j = 0; j <= w; j++) { dp[i, j] = -1; }
                }
                dp[0, 0] = 0;

                for (int i = 1; i <= n; i++)
                {
                    var input = Console.ReadLine().Split(',');
                    int value = int.Parse(input[0]);
                    int weight = int.Parse(input[1]);
                    for (int j = 0; j <= w; j++)
                    {
                        if (dp[i - 1, j] < 0) { continue; }
                        dp[i, j] = Math.Max(dp[i - 1, j], dp[i, j]);
                        if (j + weight > w) { continue; }
                        dp[i, j + weight] = Math.Max(dp[i - 1, j] + value, dp[i, j + weight]);
                    }
                }

                long answer = -1;
                long total_weight = 0;
                for (int i = 0; i <= w; i++)
                {
                    if (answer < dp[n, i])
                    {
                        answer = dp[n, i];
                        total_weight = i;
                    }
                }
                Console.WriteLine(string.Format("Case {0}:", dataset_cnt));
                Console.WriteLine(answer);
                Console.WriteLine(total_weight);
            }

            return 0;
        }
    }
}

Measured memory_bytes: 17432
import java.io.IOException;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        Integer input = Integer.valueOf(sc.nextLine());
        Long output = 1L;
        for(int i=input; 1<input ; input--) {
            output = input * output;
        }
        System.out.println(output);
    }
}

Measured memory_bytes: 26196
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =1001001001;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




/*10億7。　　　100000007
2*2行列 H*W
vector<vector<int>> vec(H,vector<int>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>vec[i][j];
  }
}

文字列→数列
string S;int A=atoi(S.c_str());
数列→文字列
int A;string S=to_string(A);
数字判定　isdigit(a)
pair宣言　pair<int,int> p(5,7);
ソート　sort(vec.begin(),vec.end());
キュー　queue<int> q;
   q.push(7);　//７が入る
   cout << q.front() << endl;  // 先頭の値を出力
   q.pop();  // 先頭の値を削除
   q.empty();
*/
//座標　corrdinateト深さヲ保持スルタメノ構造体
struct Coor{
  ll y;
  ll x;
  ll depth;
};
 ll N,M;  
 ll sy,sx,gy,gx;
 ll y,x,depth;//キューから取り出した座標
vector<string> vec;
queue<Coor> q;
vector<ll> y_vec={0,0,-1,+1};//technique
vector<ll> x_vec={-1,+1,0,0};

int BFS(){
  while(!q.empty()){
    Coor now=q.front();q.pop();//キューの先頭を取り出す
    y=now.y,x=now.x,depth=now.depth;
    
    //停止条件
    if(y==gy&&x==gx){return depth;}
    
    //上下左右４方向を探索、進むことができればキューに格納
    for(int i=0;i<4;i++){
      Coor next={y+y_vec[i],x+x_vec[i],depth+1};
      if(0<=next.y&&next.y<=N-1&&0<=next.x&&next.x<=M-1&&vec[next.y][next.x]=='.'){
        vec[next.y][next.x]='x';//同じ場所を探索しないようにする
        q.push(next);
      }
    }
  }
  return 0;
}
                   
  


int main(void){
cout<<fixed<<setprecision(14);
//cin.tie(0); ios::sync_with_stdio(false);

int X,A,B;cin>>X>>A>>B;
  
  ll ans=(X-A)%B;
  cout<<ans<<endl;

  
  
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


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

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n := r.nextInt()

	fmt.Fprintln(stdout, n+n*n+n*n*n)
}


Measured memory_bytes: 1744
#include <bits/stdc++.h>
using namespace std;
#define max1 1000000007

int main()
{  int n;
cin>>n;
double p[n];
for(int i=0;i<n;i++)
{
    cin>>p[i];
}
	double arr[n+1][n+1];
	for(int i=0;i<=n;i++)
	{
	    if(i==0)
	    {
	        arr[0][0]=1.0;
	       
	    }
	    if(i!=0)
	    {
	        arr[i][i]=p[i-1]*arr[i-1][i-1];
	        arr[0][i]=arr[0][i-1]*(1.0-p[i-1]);
	    }
	}
	for(int i=1;i<=n;i++)
	{
	    for(int j=i+1;j<=n;j++)
	    {
	       arr[i][j]=(arr[i][j-1]*(1.0-p[j-1])+arr[i-1][j-1]*p[j-1]);
	    }
	}
	int k=(n+1)/2;
	double ans=0.0;
	for(int i=k;i<=n;i++)
     {ans+=arr[i][n];
    }
    cout<<setprecision(10)<<ans<<"\n";
}


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

int main() {
	string S;
	cin >> S;

	repeat(i, S.length()) {
		cout << "x";
	}
	cout << endl;
	return 0;
}


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

import sys
import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    avg = sum(L) / n
    avg = math.ceil(avg) if math.ceil(avg) - avg <= avg - math.floor(avg) else math.floor(avg)
    print(sum([(elm - avg) ** 2 for elm in L]))


if __name__ == "__main__":
    main()


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

public class Main {
	static int n;
	static int m;
	static long x;
	static int[] c;
	static int[][] a;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		x = sc.nextInt();
		
		c = new int[n];
		a = new int[n][m];
		
		for (int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
			Arrays.setAll(a[i], idx -> sc.nextInt());
		}
		
		int minCost = Integer.MAX_VALUE;
		for (int i = 0; i < 1 << n; i++) {
			int sumC = 0;
			int[] sumA = new int[m];
			
			for (int j = 0; j < n; j++) {
				if ((i >> j & 1) == 1) {
					sumC += c[j];
					learn(sumA, a[j]);
				}
			}
			
			if (isEnoughSkill(sumA)) {
				minCost = Math.min(minCost, sumC);
			}
		}
		
		int ans = minCost == Integer.MAX_VALUE ? -1 : minCost;
		System.out.println(ans);
		
		sc.close();
	}
	
	static boolean isEnoughSkill(int[] sum) {
		for (int i = 0; i < m; i++) {
			if (sum[i] < x) return false;
		}
		return true;
	}
	
	static void learn(int[] sum, int[] a) {
		for (int i = 0; i < m; i++) {
			sum[i] += a[i];
		}
	}
	
}




Measured memory_bytes: 32816
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;

int main()
{
 int n;
 ll c=0;
 cin >> n;
 int l[n];
 for(int i=0;i<n;i++) cin >> l[i];
 sort(l,l+n);
 for(int i=2;i<n;i++){
   for(int j=i-1;j>0;j--){
     int *pos = lower_bound(l, l+n, l[i]-l[j]+1);
     int idx = pos-l;
//     cout <<l[i] <<" " <<l[j]<<" "<<  idx << endl;
     if(idx<j) c+=j-idx; 
   }
 }
 cout << c;
 return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){int a,b,c,d,x=0,y=0;scanf("%d%d%d%d",&a,&b,&c,&d);for(int i=1;100>=i;++i){if(a-i*d>0)++x;}for(int i=1;100>=i;++i){if(c-i*b>0)++y;}if(x>=y)printf("Yes");else
printf("No");}

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

Measured memory_bytes: 1028
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int x, y;
    while (1){
        cin >> x >> y;
        if (x == y and y == 0) {
            break;
        }
        else {
            if (x > y){
                cout << y << " " << x << endl; 
            }
            else {
                cout << x << " " << y << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3092
#include<iostream>

int main(int argc, char **argv){

    int A, B, C, D;

    std::cin >> A >> B >> C >> D;

    for(;;){
        C -= B;
        if(C <= 0){
            std::cout << "Yes" << std::endl;
            return 0;
        }
        A -= D;
        if(A <= 0){
            std::cout << "No" << std::endl;
            return 0;
        }
    }
}


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

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

  int sum = 0;
  for(int i=0; i<N; i++){
    int l, r;
    cin >> l >> r;
    sum += (r-l)+1;
  }
  cout << sum << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

const int MOD = 1000000007;

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

    ll N, K;
    cin >> N >> K;

    vector<ll> layer;
    for (ll i = 1; i <= N;) {
        ll j = N / i;
        if (j > i) {
            layer.push_back(1);
            i++;
        } else {
            ll num = N / j - i + 1;
            layer.push_back(num);
            i += num;
        }
    }

    ll fig = layer.size();
    vector<vector<ll>> dp(K, vector<ll>(fig, 0));
    vector<ll> s(fig + 1, 0);
    Rep (i, fig) dp[0][i] = layer[i];
    Rep (i, fig) s[i+1] = (s[i] + dp[0][i]) % MOD;
    Rep (i, K-1) {
        Rep (j, fig) {
            dp[i+1][j] = s[fig - j] * layer[j] % MOD;
        }
        Rep (j, fig+1) s[j] = 0;
        Rep (j, fig) s[j+1] = (s[j] + dp[i+1][j]) % MOD;
    }

    // for (auto e : dp) {
    //     for (auto f : e) cout << f << " ";
    //     cout << "\n";
    // }

    cout << s[fig] << "\n";
}

Measured memory_bytes: 50936
#include "bits/stdc++.h"
using namespace std;

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

class Team{
    public:
    vector<ll>flg, tim;
    ll name;
    P score;
    Team(ll _name, ll P){
        name = _name;
        flg = vector<ll>(P + 1, 0);
        tim = vector<ll>(P + 1, 0);
    }
    void calc(){
        score.first = 0;
        score.second = 0;
        for(ll i = 0; i < flg.size(); i++){
            if(flg[i]){
                score.first--;
                score.second += tim[i];
            }
        }
    }
    bool operator < (const Team &t)const{
        if(score == t.score)return name > t.name;
        return score < t.score;

    }
};

int main(){
    
    for(ll M, T, P, R; cin >> M >> T >> P >> R, M;){
        vector<Team>teams;
        for(ll i = 0; i <= T; i++)teams.push_back(Team(i, P));
        for(ll i = 0; i < R; i++){
            ll m, t, p, j;
            cin >> m >> t >> p >> j;
            if(teams[t].flg[p])continue;
            if(j == 0){
                teams[t].tim[p] += m;
                teams[t].flg[p] = 1;
            }
            else{
                teams[t].tim[p] += 20;
            }
        }
        vector<Team>vec;
        for(ll i = 1; i <= T; i++){
            teams[i].calc();
            vec.push_back(teams[i]);
        }    
        sort(vec.begin(), vec.end());
        for(ll i = 0; i < T; i++){
            cout << vec[i].name;
            if(i + 1 == T)cout << endl;
            else if(vec[i].score == vec[i+1].score)cout << "=";
            else cout << ",";
        }
    }
    
    return 0;    
}


Measured memory_bytes: 3136
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();

        int min = Math.min(a, b);
        int max = Math.max(a, b);
        
        boolean ans = false;
        if (min < c && c < max)
            ans = true;
        System.out.println(ans ? "Yes" : "No");
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n" 
#define pb push_back
#define mp make_pair
typedef long long int ll;
 
int main()
{
    fast;
    // ll t;
    // cin >> t;
    // while(t--){
        ll n;
        cin >> n;
        string str = to_string(n);
        if(str[0] == '7' || str[1] == '7'  || str[2] == '7'){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    // }


    return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <vector>
#include <cmath>

int main()
{
    long long N, K;
    std::cin >> N >> K;
    std::vector<long long> A(N);
    for(int i=0; i<N; i++) scanf(" %lld", &A[i]);

    long long X = K;
    std::vector<int> bitnum;
    std::vector<long long> A1(A);
    while(X != 0){
        X >>= 1;
        int num = 0;
        for(int i=0; i<N; i++){
            if(A[i] % 2 == 1) num++;
            A[i] >>= 1;
        }
        bitnum.push_back(num);
    }

    for(int i=bitnum.size()-1; i>=0; i--){
        if(X + std::pow(2, i) > K) continue;
        if(bitnum[i]*2 < N) X += std::pow(2, i);
    }

    // std::cout << "X = " << X << std::endl;
    long long sum = 0;
    for(int i=0; i<N; i++) sum += A1[i]^X;
    std::cout << sum << std::endl;
}

Measured memory_bytes: 1792
A=[]
k=[[0,0,0],[0,0,0],[0,0,0]]

for i in range(3):
  A.append(list(map(int,input().split())))
n=int(input())
for i in range(n):
  b=int(input())
  for j in range(3):
    for l in range(3):
      if A[j][l]==b:
        k[j][l]=1

        
if k[0]==[1,1,1] or k[1]==[1,1,1] or k[2]==[1,1,1] or (k[0][0]==1 and k[1][0]==1 and k[2][0]==1)or(k[0][1]==1 and k[1][1]==1 and k[2][1]==1)or(k[0][2]==1 and k[1][2]==1 and k[2][2]==1)or(k[0][0]==1 and k[1][1]==1 and k[2][2]==1)or(k[0][2]==1 and k[1][1]==1 and k[2][0]==1):
  print("Yes")
else:
  print("No")
  
        
      

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>
#define maxn 65
#define eps 1e-8
double x[maxn],y[maxn],c[maxn],X[65*65*2],Y[65*65*2],r[maxn];
int tot,N,K;
double dis(double x,double y,double c,double X,double Y){
	return c*sqrt((X-x)*(X-x)+(Y-y)*(Y-y));
}
void cal(double x1,double y1,double r1,double x2,double y2,double r2){//计算两圆交点坐标
	double D;//A=a*a,H=h*h,D=d*d;
	double ad,h;//ad=a*d;
	D=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
//	if(D==0)return;
	ad=(r1*r1+D-r2*r2)/2;//2*a*d=r1*r1+D-r2*r2
	h=D*r1*r1-ad*ad;
	//if(h<0)return;//漏了此句的判定
	h=sqrt(h);
	tot++,X[tot]=x1+ad*(x2-x1)/D-(y2-y1)*h/D,Y[tot]=y1+ad*(y2-y1)/D+(x2-x1)*h/D;
	tot++,X[tot]=x1+ad*(x2-x1)/D+(y2-y1)*h/D,Y[tot]=y1+ad*(y2-y1)/D-(x2-x1)*h/D;
}
int judge(double t){
	int i,j,cnt;
	for(i=1;i<=N;i++)r[i]=t/c[i];
	tot=0;
	for(i=1;i<=N;i++){//计算出不同圆之间的交点坐标
		tot++,X[tot]=x[i],Y[tot]=y[i];//别忘了将圆心坐标放入交点坐标//此处错写成tot++,X[i]=x[i],Y[i]=y[i];
		for(j=i+1;j<=N;j++)
			cal(x[i],y[i],r[i],x[j],y[j],r[j]);
	}
	for(i=1;i<=tot;i++){
		cnt=0;
		for(j=1;j<=N;j++)
			if(dis(x[j],y[j],c[j],X[i],Y[i])<t+eps)cnt++;//浮点比大小无等于的情况，这是由浮点误差决定的。
		if(cnt>=K)return 1;
	}
	return 0;
}
int main(){
	double l,r,mid;
	int i;
	scanf("%d%d",&N,&K);
	for(i=1;i<=N;i++)scanf("%lf%lf%lf",&x[i],&y[i],&c[i]);
	l=0,r=1000010;
	while(l+eps<r){
		mid=(l+r)/2;
		if(judge(mid))r=mid;
		else l=mid;
	}
	printf("%.6f\n",r);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int dx[] = {0, 1, -1, 0};
const int dy[] = {1, 0, 0, -1};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;
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;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int ans = 0;
    for (int x = 1; x <= sqrt(n); x++) {
      for (int y = x; y <= sqrt(n); y++) {
        for (int z = y; z * (z + x + y) <= i - x * x - y * y - x * y; z++)
          if (x * x + y * y + z * z + x * y + y * z + z * x == i) {
            map<int, int> mp;
            mp[x]++;
            mp[y]++;
            mp[z]++;
            if (mp.size() == 1) ans++;
            if (mp.size() == 2) ans += 3;
            if (mp.size() == 3) ans += 6;
          }
      }
    }
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

const int INF = 1e9 + 19;
const int maxSize = 1e5 + 17;


main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;

    if(n / 2 + n % 2 >= k)
        cout << "YES\n";
    else
        cout << "NO\n";

}






Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  ll t=(c-a-1)*60;
  t+=d+(60-b);
  COUT(t-e);
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;

int main(){
  int n, p; cin >> n >> p;
  string s; cin >> s;
  ll ans = 0;
  ll x = 1;
  vector<int> d(n+1, 0);
  vector<int> cnt(p, 0);
  
  if(p == 2 || p == 5){
    for(int i = 0; i < n; i++){
      if((s[i]-'0') % p == 0) ans += 1LL * (i+1);
    }
  }
  else{
    for(int i = n-1; i >= 0; i--){
      d[i] = (d[i+1]+(s[i]-'0') * x) % p;
      x = x * 10LL % p;
    }
    for(int i = n; i >= 0; i--){
      ans += cnt[d[i]];
      cnt[d[i]]++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 1412
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }
    vector<vector<ll>> dp(N + 1, vector<ll>(3, -LINF));
    // 最後に選んだ要素がA_iであって、パスした回数がj回
    dp[0][0] = A[0];
    dp[0][1] = 0;
    dp[0][2] = 0;
    if(N % 2 == 0) {
        dp[1][1] = A[1];
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < 2; j++) {
                // dp[i][j]からの遷移
                if(i + 2 < N)
                    dp[i + 2][j] = max(dp[i + 2][j], dp[i][j] + A[i + 2]);
                if(i + 3 < N && j + 1 < 2)
                    dp[i + 3][j + 1] =
                        max(dp[i + 3][j + 1], dp[i][j] + A[i + 3]);
            }
        }
        cout << max(dp[N - 2][0], dp[N - 1][1]) << endl;
    } else {
        dp[1][1] = A[1];
        dp[2][2] = A[2];
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < 3; j++) {
                // dp[i][j]からの遷移
                if(i + 2 < N)
                    dp[i + 2][j] = max(dp[i + 2][j], dp[i][j] + A[i + 2]);
                if(i + 3 < N && j + 1 < 3)
                    dp[i + 3][j + 1] =
                        max(dp[i + 3][j + 1], dp[i][j] + A[i + 3]);
                if(i + 4 < N && j + 2 < 3)
                    dp[i + 4][j + 2] =
                        max(dp[i + 4][j + 2], dp[i][j] + A[i + 4]);
            }
        }
        cout << max(dp[N - 3][0], max(dp[N - 2][1], dp[N - 1][2])) << endl;
    }

    return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n,-1);
    rep(i,m){
        int s,c;
        cin >> s >> c;
        s--;
        if(a.at(s) != -1 && a.at(s) != c){
            cout << -1 << endl;
            return 0;
        }else{
            a.at(s) =c;
        }
    }
    if(m == 0){
        if(n==1)cout << 0 << endl;
        if(n==2)cout << 10 << endl;
        if(n==3)cout << 100 << endl;
        return 0;
    }
    if(a.at(0)==0){
        if(n==1)cout << 0 << endl;
        else cout << -1 << endl;
        return 0;
    }
    int ans = 0;
    rep(i,n){
        if(i==0){
            if(a.at(i)==-1)ans=1;
            else ans= a.at(i);
        }else{
            if(a.at(i)!=-1){
                ans += a.at(i);
            }
        }
        ans *= 10;
    }
    ans /= 10;
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>
#include <set>
#include <numeric>

using namespace std;
bool points[5][5][4];
int main()
{
    for (int i = 0; i < 9; ++i){
        int y = i/2;
        if (i%2 == 0){
            for (int j = 0; j < 4; ++j){
                int e;
                scanf("%1d", &e);
                if (e)
                    points[y][j][1] = points[y][j+1][3] = true;
            }
		} else {
            for (int j = 0; j < 5; ++j){
                int e;
                scanf("%1d", &e);
                if (e)
                    points[y][j][2] = points[y+1][j][0] = true;
            }
        }
    }
 
    int x, y;
    x = 1;
    y = 0;
    int dir = 1;
    int dx[] = { 0, 1, 0, -1 };
    int dy[] = { -1, 0, 1, 0 };
    char* ds = "URDL";
    putchar(ds[dir]);
    while (!(x == 0 && y == 0)) {
        if (points[y][x][(dir+3)%4])
            dir = (dir+3)%4;
        else if (points[y][x][dir])
            ;
        else if (points[y][x][(dir+1)%4])
            dir = (dir+1)%4;
        else
            dir = (dir+2)%4;
 
        x += dx[dir];
        y += dy[dir];
        putchar(ds[dir]);
    }
    putchar('\n');
 
    return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    double START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    // Point
    // ある操作を繰り返したりするとき
    // ☆全体を通して不変な量を見つける
    // 今回はAの総和が一定
    // A全体の分割の仕方を考えるのでAの総和の約数全てを調べればよい
    // ...fin

    i64 n,k; cin >> n >> k;
    vl a(n); rep(i,n) cin >> a[i];

    i64 sum = 0; rep(i,n) sum += a[i];
    vl div;
    for(i64 d = 1; d * d <= sum; ++d) if(sum%d == 0) {
        div.push_back(d);
        if(d != sum/d) div.push_back(sum/d);
    }

    i64 ans = 1;
    for(auto d : div) {
        vl a_mod(n, 0);
        vl csum(n+1, 0);
        rep(i,n) a_mod[i] = a[i]%d;
        sort(all(a_mod));
        rep(i,n) csum[i+1] = csum[i] + a_mod[i];
        i64 tmp = 0;
        rep(i,n) {
            tmp = csum[i+1] - csum[0];
            if(tmp == d*(n-1-i) - (csum[n] - csum[i+1])) break;
        }
        if(tmp <= k) chmax(ans, d);
        a_mod.clear();
        csum.clear();
    }

    cout << ans << '\n';

//     printf("ElapsedTime: %5.3f ms\n",1000*((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
struct compare
{
    bool operator()(const string& first, const string& second)
    {
        return first.size()>second.size();
    }
};
void solve()
{
    long n;
    cin>>n;
    vector<double>v(n);
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    double res = v[0];

        for(int i=1; i<n; i++)
        {
           res = (res+v[i])/2.00;
        }

        cout<<res<<endl;
}

int main()
{
    int t;
    t=1;
    while(t--)
    {
        solve();

    }
}


Measured memory_bytes: 256
A, B, C, X = map(int, [input() for _ in range(4)])

count = 0
for a in range(A + 1):
	for b in range(B + 1):
		value = 500 * a + 100 * b
		#print(value)
		if value <= X and (X - value) // 50 <= C:
			count += 1
print(count)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,K;
int H[111111];

signed main(){
    cin>>N>>K;
    rep(i,N)cin>>H[i];
    sort(H,H+N);
    int ans=1001001001;
    for(int i=0;i+K<=N;i++)chmin(ans,H[i+K-1]-H[i]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{    
    int n;
    cin >> n;
    // n = 3;
    int a[n];
    for(int i=0; i<n; ++i) cin >> a[i];
    // a[0] = 1, a[1] = 1, a[2] = 3;

    // 基本的には平均値に持っていけば良いはず
    // 少数になる場合が難しい?
    double ave = 0;
    for(int i=0; i<n; ++i){
        ave += a[i];
    }
    int int_ave = round(ave / n);
        
    int cost = 0;
    for(int i=0; i<n; ++i){
        cost += (a[i]-int_ave) * (a[i]-int_ave);
    }

    cout << cost << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define null NULL
#define S 100005
#define INF 100000000000
typedef long long int lli;
#define newline cout<<"\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test lli t;  cin>>t; while(t--)

lli dp[300][S];

void ans(lli *v,lli *wt,lli n,lli tw)
{
    lli i,j;
    for(i=0;i<=n;i++)
    for(j=0;j<=tw;j++)
   { 
      if(j==0)
      dp[i][j]=0;
      else
      dp[i][j]=INF;
   }
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=tw;j++)
        {
            if(v[i-1]<=j)
            dp[i][j]=min(wt[i-1]+dp[i-1][j-v[i-1]],dp[i-1][j]);
            else  
            dp[i][j]=dp[i-1][j];
        }
    }

}

int main()
{
    lli n,w,i,tw=0,tv=0;
    cin>>n>>w;
    lli wt[n],v[n];
    for(i=0;i<n;i++)
    {
    cin>>wt[i]>>v[i];
    tw=tw+v[i];
    tv=tv+wt[i];
    }
    ans(v,wt,n,tw);
    for(i=tw;i>=0;i--)
    {
        if(dp[n][i]<=w)
        {
          //cout<<dp[n][i]<<"\n";
           cout<<i;
            return 0;
        }
    }
  
}


Measured memory_bytes: 80128
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(long long)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);

unordered_map<long long,long long> ass;

void prime_factor(long long n){
    for(long long i=2;i*i<=n;i++){
        while(n%i==0){
            ass[i]++;;
            n/=i;
        }
    }
    if(n != 1)ass[n]++;
}

signed main(){
    long long n;
    cin>>n;
    for(long long i=2;i<=n;i++)prime_factor(i);
    long long res = 1;
    for(auto it:ass){
        res*=it.second+1;
        res%=mod;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int n;
	int i;

	scanf("%d", &n);

	for (i = 1; i <= n; i++) {
		if (i % 3 == 0)printf(" %d", i);
		else {
			int x = i;
			while (x) {
				if (x % 10 == 3) {
					printf(" %d", i);
					break;
				}
				x /= 10;
			}
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 2748
// https://atcoder.jp/contests/apc001/tasks/apc001_b
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];
    ll max1 = 0, max2 = 0;
    REP(i, n) {
        max1 += max(0, a[i] - b[i]);
        max2 += max(0, b[i] - a[i]) / 2;
    }
    if (max1 <= max2) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<functional>
#include<list>
using namespace std;

#define INF 1<<21
#define DIV 1000000007

using namespace std;

int main() {
  int n,a;
  list<int> b;
  cin >> n;
  if (n % 2 == 1) {
	for (int i = 1; i <= n; i++) {
	  cin >> a;
	  if (i % 2)b.push_front(a);
	  else b.push_back(a);
	}
  }
  else {
	for (int i = 1; i <= n; i++) {
	  cin >> a;
	  if (i % 2)b.push_back(a);
	  else b.push_front(a);
	}
  }

  for (auto it = b.begin(); it != b.end(); it++) {
	cout << *it << " " ;
  }
  cout << endl;

}

Measured memory_bytes: 8448
#include<iostream>
#include<cstdio>
using namespace std;
int n,s,count;

int solve(int i,int sum,int used){
	if(i==10){
		if(s==sum&&used==n){
			
		count++;
		}
		return count;
	}
	solve(i+1,sum+i,used+1);
	
	solve(i+1,sum,used);
	
	
	return count;
}

int main(){
	
	while(cin>>n>>s,n||s){
	count=0;
	
	cout<<solve(0,0,0)<<endl;
	}

return 0;
}

Measured memory_bytes: 1160