akhauriyash/Code-Regression huggingface dataset:
x,y=map(int,input().split())
if (x+y)%3!=0:
    print(0)
    exit()

def com(n,r):
    r=min(r,n-r)
    c=1
    mod=10**9+7
    for i in range(1,r+1):
        c=(c*(n+1-i)*pow(i,mod-2,mod))%mod
    return c

n=(2*y-x)//3
m=(2*x-y)//3
if n<0 or m<0:print(0)
else:print(com(n+m,n))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
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()
{
    int N, W;
    cin >> N>>W;

    vector<int> v(N+1);
    vector<int> w(N+1);

    REP(i, N) cin >> w[i]>>v[i];

    vector<vector<ll>> dp(N+1, vector<ll>(100010, 0));
    
    for (int i = 0; i < N; i++){
        for (int wsum = 0; wsum <= W; wsum++){
            if(w[i]<=wsum){
                chmax(dp[i+1][wsum], dp[i][wsum-w[i]]+v[i]);
            }
            chmax(dp[i+1][wsum], dp[i][wsum]);
        }
    }

    cout << dp[N][W] << endl;

    return 0;
}

Measured memory_bytes: 80256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring> 
#include<queue>
#include<stack> 
#include<string.h>
#include<set>
#define ll long long
using namespace std;
int main()
{
	int a,b,c;
	while(~scanf("%d%d%d",&a,&b,&c))
	{
		int flag=0;
		for(int i=1;i<=1000005;i++)
		{
			if((i*a)%b==c%b)
			{
				printf("YES\n");
				flag=1;
				break;
			}
		}
		if(!flag)
		{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std ;
int main()
{
    int n,d,y,z;
    cin >> n >> d ;
    y = 2*d+1;
    if(n<=y){z=1;}
    else if (n%y==0)
    {
        z=n/y;
    }
    else
    {
        z=(n/y)+1;
    }
    cout << z << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int main(){
    long long  w,h,x,y;
    while(~scanf("%lld%lld%lld%lld",&w,&h,&x,&y)){
        double ans=(w*h)/2.0;
        int flag=0;
        if((x==w/2.0)&&(y==h/2.0)){
            flag=1;
        }
        printf("%lf %d\n",ans,flag);
    }
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int N = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        int[] X = new int[N];
        for(int i=0;i<N;i++){
            X[i] = int.Parse(str[i]);
        }
        int[] a = new int[N];
        for(int i=0;i<N;i++){
            a[i] = i;
        }
        Array.Sort(a,(x,y) => X[x]-X[y]);
        int[] L = new int[N];
        for(int i=0;i<N;i++){
            L[i] = N;
        }
        int[] Y = new int[N*N];
        bool[] finished = new bool[N*N];
        int p = 0;
        bool b = true;
        for(int i=0;i<N;i++){
            int d = a[i] + 1;
            finished[X[a[i]]-1] = true;
            Y[X[a[i]]-1] = a[i] + 1;
            L[a[i]] -= a[i] + 1; 
            for(int j=0;j<a[i];j++){
                while(p < N*N && finished[p]){
                    p++;
                }
                Y[p] = d;
                p++;
                if(p > X[a[i]] - 1){
                    b = false;
                }
            }
        }
        int q = 0;
        for(;p<N*N;p++){
            if(finished[p]){
                continue;
            }
            while(q < N && L[a[q]] == 0){
                q++;
            }
            if(q == N){
                b = false;
                break;
            }
            else{
                Y[p] = a[q]+1;
                if(p < X[a[q]]){
                    b = false;
                }
                L[a[q]]--;
            }
        }
        if(b){
            sb.Append("Yes\n");
            for(int i=0;i<N*N;i++){
                sb.Append(Y[i]+" ");
            }
            sb.Append("\n");
        }
        else{
            sb.Append("No\n");
        }
    }
}

Measured memory_bytes: 12856
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>

using namespace std;
typedef pair<int, int> pii;
static const int INF = 1000000000;

int main(){
	ios_base::sync_with_stdio(false);
	int n, x;
	cin >> n >> x;
	vector<int> d(n), c(n);
	for(int i = 0; i < n; ++i){ cin >> d[i] >> c[i]; }
	const int offset = 100001, limit = offset + offset + x;
	vector<int> dist(offset + x + offset, INF);
	priority_queue< pii, vector<pii>, greater<pii> > pq;
	dist[offset] = 0;
	pq.push(pii(0, offset));
	while(!pq.empty()){
		const pii p = pq.top();
		pq.pop();
		if(p.first > dist[p.second]){ continue; }
		for(int i = 0; i < n; ++i){
			const int x0 = p.second - d[i];
			const int x1 = p.second + d[i];
			const int y = p.first + c[i];
			if(x0 >= 0 && y < dist[x0]){
				dist[x0] = y;
				pq.push(pii(y, x0));
			}
			if(x1 < limit && y < dist[x1]){
				dist[x1] = y;
				pq.push(pii(y, x1));
			}
		}
	}
	if(dist[offset + x] >= INF){
		cout << -1 << endl;
	}else{
		cout << dist[offset + x] << endl;
	}
	return 0;
}


Measured memory_bytes: 7896
import java.util.Scanner;
public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int N;
    int A;
    N=sc.nextInt();
    A=sc.nextInt();
    while(N>=500){
      N=N-500;
    }
    if(A>=N){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }

  }
}

Measured memory_bytes: 22868
#include<stdio.h>
#include<string.h>
#define MAX 102
int main(void) {
	char s[MAX], p[MAX];
	int i, j, length, flag = 0;
	char tmp;

	fgets(s, MAX, stdin);
	fgets(p, MAX, stdin);

	length = strlen(s);
	length -= 1;
	s[length] = '\0';
	p[strlen(p)-1] = '\0';

	for (i = 0; i < length && flag == 0; i++) {
		if (strstr(s, p) != NULL)
			flag = 1;
		tmp = s[0];
		for (j = 0; j < length - 1; j++)
			s[j] = s[j+1];
		s[length - 1] = tmp;
	}

	if (flag == 1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}



Measured memory_bytes: 2140
n = int(input())
numlist = list(map(int, input().split()))
cal = 0
for i in numlist:
  cal = cal + i
ave = cal / (n)
dummy = abs(numlist[0]-ave)
index = 0
count = 0
for j in numlist:
  kyori = abs(j-ave)
  if dummy > kyori:
    dummy = kyori
    index = count
  count = count + 1 
print(index)


Measured memory_bytes: 3060
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>


using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

int main()
{

	//解答方針：
	//和の最大値を貪欲的に計算。
	//各ビットの1の個数がなるべく多くなるようにする。
	//（1の個数 < n/2の場合は、XORを使用して、1の個数 > n/2とできる）
	//ただし、x <= kの制限があるため、上位ビットを優先して置き換える。
	//（桁数が大きいほうが大きな数を作れる）
	int n;
	cin >> n;

	ll k;
	cin >> k;

	vector<ll> as(n);
	rep(i, n)
	{
		cin >> as[i];
	}

	//各Aを2進数に変換して、桁の1の数をカウント
	//nが10^12≒(2^10)^4なので40桁とる
	const int C = 41;

	vector<ll> counts(C);
	for (ll a : as)
	{
		ll d = a;
		rep(i, C)
		{
			counts[i] += d % 2;
			d = d / 2;
		}
	}

	//和の計算
	ll s = 0;
	ll limit = k;

	//上位ビットから処理
	revrep(i, C)
	{
		//2の累乗をビットシフトで計算
		ll x = (ll)1 << i;

		//各Aのiビット目の1の個数
		ll y = counts[i];

		if (x <= limit)
		{
			//1より0の方が多い場合は、xと各AのXORをとる
			if (y < n - counts[i])
			{
				y = n - counts[i];
				//xがkを超えないように調整
				limit -= x;
			}
		}

		s += y * x;
	}

	cout << s << endl;

	return 0;
}

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

int main() {
    ll N;
    cin >> N;
    ll mod = pow(10,9)+7;

    //
    if (N==1) {
        cout << 0 << endl;
        exit(0);
    }
    else if (N==2) {
        cout << 2 << endl;
        exit(0);
    }

    ll ans10 = 1;
    ll ans8 = 1;
    ll ans9 = 1;
    for (ll i=0; i<N; i++) {
        ans10 *= 10;
        ans10 %= mod;
    }
    if(ans10<0) {
        ans10+=mod;
    }
    for (ll i=0; i<N; i++) {
        ans9 *= 9;
        ans9 %= mod;
    }
    if(ans9<0) {
        ans9+=mod;
    }
    for (ll i=0; i<N; i++) {
        ans8 *= 8;
        ans8 %= mod;
    }
    if(ans8<0) {
        ans8+=mod;
    }

    ll ans;
    ans = ans10;
    if(ans<0) {
        ans+=mod;
    }
    ans -= ans8;
    ans %= mod;
    if(ans<0) {
        ans+=mod;
    }
    ans -= ans9-ans8;
    ans %= mod;
    if(ans<0) {
        ans+=mod;
    }
    ans -= ans9-ans8;
    ans %= mod;
    if(ans<0) {
        ans+=mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3620
class Problem
  attr_accessor :a, :b, :n, :m, :h, :w

  def initialize
    @n, @k = gets.to_s.split.map{ |v| v.to_i }
    @a = Array.new(n){ gets.to_s.split.map{ |v| v.to_i } }
  end

  def solve
    @a.sort.each do |a,b|
      @k -= b
      return a if @k <= 0
    end
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end


Measured memory_bytes: 22340
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int dp[3005][3005];

int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  for(int i = 0; i < s.size(); i++){
    for(int j = 0; j < t.size(); j++){
      if(s[i] == t[j]) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
      dp[i + 1][j + 1] = max({dp[i][j + 1], dp[i + 1][j], dp[i + 1][j + 1]});
    }
  }

  string ans = "";
  int x = s.size(), y = t.size();
  while(dp[x][y]){
    while(dp[x][y] == dp[x - 1][y]) x--;
    while(dp[x][y] == dp[x][y - 1]) y--;
    x--, y--;
    ans += s[x];
  }
  
  reverse(all(ans));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 35456
def main():
    from collections import Counter
    import sys

    input = sys.stdin.readline

    N = int(input())  # <= 10**5
    a = [int(input()) for _ in range(N)]
    ctr = Counter(a)

    ans = 0
    for cnt in ctr.values():
        ans += cnt % 2
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 16640
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#define ll long long
#define INF 1e+7
#define MOD 1000000007
using namespace std;

ll cor(ll n){
    if(n==0){
        return 1;
    }else if(n==1){
        return 1;
    }else{
        return (cor(n-2)+cor(n-1))%MOD;
    }
}

int main(){
    ll H, W, K;
    cin >> H >> W >> K;
    K--;
    
    if(W==1){
        cout<<1<<endl;
        return 0;
    }
    
    ll num[101][9]={}; //hのときにでw-1番目の棒に到達している通り数
    
    num[0][0]=1;
    for(int i=1; i<W; i++){
        num[0][i]=0;
    }
    
    for(int h=1; h<=H; h++){
        for(int w=0; w<W; w++){
            
            if(w==0){
                num[h][w]=(num[h-1][w]*cor(W-1))%MOD + (num[h-1][w+1]*cor(W-2))%MOD;
            }else if(w==W-1){
                num[h][w]=(num[h-1][w]*cor(W-1))%MOD + (num[h-1][w-1]*cor(W-2))%MOD;
            }else{
                num[h][w]=(num[h-1][w]*((cor(w)*cor(W-w-1))%MOD))%MOD + (num[h-1][w-1]*(cor(w-1)*cor(W-w-1))%MOD)%MOD + (num[h-1][w+1]*(cor(w)*cor(W-w-2))%MOD)%MOD;
            }
            
            num[h][w]%=MOD;
        }
    }
    
    cout << num[H][K] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define P pair<LL, int>
#define fs first
#define sc second
#define mk_p make_pair
const int N = 1e5 + 11;
int n;
LL a[N], b[N], sum[N];
P c[N+N];
bool mark[N];
int main(){
	cin>>n;
	for(int i = 1;i <= n; i++){
		scanf("%lld%lld", &a[i], &b[i]);
		c[i] = mk_p(a[i], i);
		c[i+n] = mk_p(b[i], i + n);
	}
	sort(c + 1, c + 1 + n + n);
	bool flag = 0, flag2 = 1, flag3 = 1;
	for(int i = 1;i <= n; i++){
		LL v = c[i].fs;
		int pos = c[i].sc;
		if(pos > n)pos -= n, flag2 = 0;
		else flag3 = 0;
		if(mark[pos])flag = 1;
		mark[pos] = 1;
		sum[i] = sum[i-1] + v;
	}
	if(flag || flag2 || flag3){
		cout<<sum[n]<<endl;
		return 0;
	}
	LL ans = 1e18;
	for(int i = 1;i <= n; i++){
		P now1 = mk_p(a[i], i);
		P now2 = mk_p(b[i], i + n);
		int pos1 = lower_bound(c + 1, c + 1 + n, now1) - c;
		int pos2 = lower_bound(c + 1, c + 1 + n, now2) - c;
		if(pos1 >= n && pos2 >= n)ans = min(ans, a[i] + b[i] + sum[n-2]);//, printf("a+b+sum=%lld\n", a[i] + b[i] + sum[n-2]);
		else if(pos1 < n)ans = min(ans, sum[n-1] + b[i]);//, printf("b+sum=%lld\n", sum[n-1] + b[i]);
		else ans = min(ans, sum[n-1] + a[i]);//, printf("a+sum=%lld\n", sum[n-1] + a[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
const LL LINF = 0x3f3f3f3f3f3f3f3f; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const ULL P = 131;
const int N = 2e5+7;


int main()
{
	LL a,b,c;
	scanf("%lld%lld.%lld",&a,&b,&c);
	LL ans = a*b;
	LL t = a*c;
	ans+=t/100;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
typedef double D;
typedef complex<D> P;
typedef pair<P, P> L;
typedef vector<P> VP;
const D EPS = 1e-9;
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
D dot(P a, P b) {return (conj(a)*b).X; }
D cross(P a, P b) {  return (conj(a)*b).Y;}
int ccw(P a, P b, P c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;
  if (cross(b,c) < -EPS) return -1;
  if (dot(b,c)   < -EPS) return +2;
  if (norm(b) < norm(c)) return -2;
  return 0;
}
bool isecSP(P a1, P a2, P b) {
  return !ccw(a1, a2, b);
}
P proj(P a1, P a2, P p) {
  return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}
D distSP(P a1, P a2, P p) {
  P r = proj(a1, a2, p);
  if (isecSP(a1, a2, r)) return abs(r-p);
  return min(abs(a1-p), abs(a2-p));
}
D distSC(P a1, P a2, P c, D r) {
  D dSqr1 = norm(c-a1), dSqr2 = norm(c-a2);
  if (dSqr1 < r*r ^ dSqr2 < r*r) return 0;
  if (dSqr1 < r*r & dSqr2 < r*r) return r - sqrt(max(dSqr1, dSqr2));
  return max(distSP(a1, a2, c) - r, 0.0);
}
int n,m;
double x[111],y[111],ax,bx,ay,by,r[111];
int main(){
   while(cin>>n,n){
    rep(i,n)cin>>x[i]>>y[i]>>r[i];
    cin>>m;
    while(m--){
      int f=0;
      cin>>ax>>ay>>bx>>by;
      rep(i,n)if(!distSC(P(ax,ay),P(bx,by),P(x[i],y[i]),r[i]))f++;
      cout<<(f?"Safe":"Danger")<<endl;
    }
   }
}

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

int ans[100];

class G{
public:
	int id,n,a,d; //O[vÔ,l,,HÔ

	G(int i){
		id = i;
		n = (i % 5 == 1 ? 5 : 2);
		a = 5 * i;
		d = 17 * (i % 2) + 3 * (i % 3) + 19;
	}
};

//nlA±ÅÈðmÛÅ«éêðÔ·
int indexOfSeat(int *seat,int n){
	int count = 0;

	for(int i=0;i<17;i++){
		if(!seat[i]){
			count++;
			if(count == n) return i - n + 1;
		}
		else{
			count = 0;
		}
	}

	return -1;
}

void solve(void){
	vector<G> v; //Ò¿sñ
	for(int i=0;i<100;i++) v.push_back(G(i));

	int time = 0; //»ÝÌ
	int seat[17]; //Èîñ
	memset(seat,0,sizeof(seat));

	while(!v.empty()){
		while(!v.empty() && v[0].a<=time){
			int idx = indexOfSeat(seat,v[0].n);
			if(idx != -1){
				for(int i=idx;i<idx+v[0].n;i++) seat[i] = v[0].d;
				ans[v[0].id] = time - v[0].a;
				v.erase(v.begin());
			}
			else{
				break;
			}
		}

		time++;
		for(int i=0;i<17;i++) if(seat[i] > 0) seat[i]--;
	}
}

int main(void){
	solve();

	int n;
	while(cin>>n) cout<<ans[n]<<endl;

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>

int main (){

  double A = 0, B = 0, H = 0, M = 0;
  scanf("%lf %lf %lf %lf", &A, &B, &H, &M);

  double lad_h = 0, lad_m = 0;
  lad_m = 2 * M_PI * ( M / 60 );
  lad_h = 2 * M_PI * ( H / 12 ) + 2 * M_PI * ( M / 60 ) / 12;

  double lad;
  if ( lad_m >= lad_h ){
    lad = lad_m - lad_h;
  }
  else{
    lad = lad_h - lad_m;
  }

  double res = 0;
  res = A*A + B*B - 2*A*B * cos(lad);
  res = sqrt(res);

  printf("%.10lf \n", res);

  return 0;
}

Measured memory_bytes: 2584
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! pop {
    ($x:expr) => (-$x.pop().unwrap());
}
macro_rules! push {
    ($x:expr, $y:expr) => {{ $x.push(-($y)); }};
}

fn main() {

    let mut sc = Scanner::new();
    let k: usize = sc.cin();
    let mut q = std::collections::BinaryHeap::new();

    for i in 1..10 { push!(q, i as i64) }

    for _ in 1..k {
        let x = pop!(q);
        let last = x % 10;
        if last > 0 { push!(q, x * 10 + last - 1); }
        push!(q, x * 10 + last);
        if last < 9 { push!(q, x * 10 + last + 1); }
    }

    println!("{}", pop!(q));

}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 6396
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

bool[] seen, finished;
int pos = -1;
int[] hist;

void dfs(int[][] adj, int v) {
    seen[v] = true;
    hist ~= v;
    foreach (nv ; adj[v]) {
        if (finished[nv]) continue;

        if (seen[nv] && !finished[nv]) {
            pos = nv;
            return;
        }

        dfs(adj, nv);

        if (pos != -1) return;
    }

    hist.popBack();
    finished[v] = true;
}

void main() {
    int N, M;
    scan(N, M);
    auto adj = new int[][](N, 0);
    foreach (i ; 0 .. M) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        adj[ai] ~= bi;
    }

    seen = new bool[](N);
    finished = new bool[](N);
    foreach (v ; 0 .. N) {
        dfs(adj, v);
        if (pos != -1) break;
    }

    if (pos == -1) {
        writeln(-1);
        return;
    }

    int[] cycle;
    while (!hist.empty) {
        int t = hist.back;
        cycle ~= t;
        hist.popBack();
        if (t == pos) break;
    }
    cycle.reverse();

    while (true) {
        auto ord = new int[](N);
        ord[] = -1;
        foreach (i ; 0 .. cycle.length) {
            ord[cycle[i]] = i.to!int;
        }
        int from = -1, to = -1;
        foreach (i ; 0 .. cycle.length) {
            foreach (nv ; adj[cycle[i]]) {
                if (nv != cycle[(i + 1) % cycle.length] && ord[nv] != -1) {
                    from = i.to!int;
                    to = ord[nv];
                    break;
                }
            }
            if (from != -1) break;
        }
        if (from == -1) break;

        int[] ncycle;
        ncycle ~= cycle[from];
        int i = to;
        while (i != from) {
            ncycle ~= cycle[i];
            i = (i + 1) % cycle.length.to!int;
        }
        cycle = ncycle;
    }

    writeln(cycle.length);
    cycle.each!(v => writeln(v + 1));
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 2428
# あるアルファベットがN個あったとき、
# N個から一つ選ぶ or 選ばないのN + 1通り。これを全て掛け合わせ、1(一つも選ばない)を引く

import sys
readline = sys.stdin.readline

N = int(readline())
S = readline().rstrip()

from collections import defaultdict
dic = defaultdict(int)

for c in S:
  dic[c] += 1

ans = 1
DIV = 10 ** 9 + 7
for val in dic.values():
  ans *= ((val + 1) % DIV) 
  ans %= DIV
print(ans - 1)

Measured memory_bytes: 3444
#include <stdio.h>
#include <string.h>
int main(){
  int count,oorc,flag,n,m,i,j,k,len;
  char u[258][11],t[258][11];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",u[i]);
  }
  oorc=0;
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%s",t[i]);
    flag=0;
    len=strlen(t[i]);
  
 
    for(j=0;j<n;j++){
      count=0;
      for(k=0;k<len;k++){
	if(t[i][len]=='\0'&&u[j][len]!='\0'){
          break;
	}
	if(t[i][k]==u[j][k]){
	  count++;
	}
        if(count==len){
          flag=1;
          break;
	}
      }
    }
    if(flag==1&&oorc==0){
      oorc=1;
      printf("Opened by ");
      for(j=0;j<len;j++){
	printf("%c",t[i][j]);
      }
      printf("\n");
    }
    else if(flag==1&&oorc==1){
      oorc=0;
      printf("Closed by ");
      for(j=0;j<len;j++){
	printf("%c",t[i][j]);
      }
      printf("\n");
    }   
    else if(flag==0){
      printf("Unknown ");
      for(j=0;j<len;j++){
	printf("%c",t[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

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

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  long h, w; readV(h, w);

  auto m = h*w;

  foreach (i; 1..h) {
    m = min(m, sub3(div2(h-i, w, true), i*w));
    m = min(m, sub3(div2(h-i, w, false), i*w));
  }

  foreach (i; 1..w) {
    m = min(m, sub3(div2(h, w-i, true), i*h));
    m = min(m, sub3(div2(h, w-i, false), i*h));
  }

  writeln(m);
}

auto div2(long h, long w, bool hv)
{
  if (hv)
    return [(h/2)*w, (h-h/2)*w];
  else
    return [h*(w/2), h*(w-w/2)];
}

auto sub3(long[] s1, long s2)
{
  auto t = (s1 ~ s2).sort();
  return t[2] - t[0];
}


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

using namespace std;

int main() {
    long long int n, m, h[100001]={}, a[100001]={}, b[100001]={}, i, j, dap=0, ob[100001];
    cin>>n>>m;
    for(i=1;i<=n;i++)
    cin>>h[i];
    for(i=1;i<=n;i++)
    ob[i]=1;
    for(i=1;i<=m;i++)
    {
    cin>>a[i]>>b[i];
    if(h[a[i]]<h[b[i]])
    ob[a[i]]=0;
    else if(h[a[i]]>h[b[i]])
    ob[b[i]]=0;
    else
    {
        ob[a[i]]=0;
        ob[b[i]]=0;
    }
    
    }
    
    
    for(i=1;i<=n;i++)
    dap+=(ob[i]==1);
    cout<<dap;
    return 0;
}

Measured memory_bytes: 6748
#include <math.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define all(vec) (vec).begin(), (vec).end()
#define yn(formula) (formula) ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(formula) (formula) ? (cout << "YES" << endl) : (cout << "NO" << endl)
#define MIN(a, b) ((a) < (b)) ? (a) : (b)
#define LLONG_MAX     9223372036854775807i64

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vp> vvp;
typedef vector<vpl> vvpl;

constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 29;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };

struct edge { ll to; ll cost; };

ll Pow(ll a, ll b) {
	ll x = 1;
	while (b > 0) {
		if (b & 1) x = x * a;
		a = a * a;
		b = b >> 1;
	}
	return x;
}

/*<ここから>***********************************************************/


int main()
{
	int N, K;
	cin >> N >> K;
	vi A(N);
	rep(i, N) cin >> A[i];
	
	int one = 0;
	rep(i, N) {
		if (A[i] == 1) one = i;
	}

	int ans1 = 0;
	int p1 = one, p2 = one;
	while (p1 > 0) {
		p1 -= K - 1; 
		ans1++;
	}
	p2 -= p1;
	while (p2 < N - 1) {
		p2 += K - 1;
		ans1++;
	}
	
	int ans2 = 0;
	p1 = one, p2 = one;
	while (p2 < N - 1) {
		p2 += K - 1;
		ans2++;
	}
	p1 -= p2;
	while (p1 > 0) {
		p1 -= K - 1;
		ans2++;
	}
	


	cout << max(ans1, ans2) << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include<string>
using namespace std;
int main()
{  int n, x = 0, max = 0;
				cin >> n;
				string s;
				char arr[1000];
				//s.length() = n;
			for (int i = 0; i < n; i++)
			{
				cin >> arr[i];
				if (arr[i] == 'I')
				{
					x += 1;
					if (x > max)
						max = x;
				}
				else
				{
					x -= 1;
					if (x > max)
						max = x;
				}
			}
			cout << max;
    return 0;
}

Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int main(){
    int H,i,N,sum=0,A;
    cin>>H;
    cin>>N;
    for(i=1;i<=N;i++){
        cin>>A;
        sum=sum+A;
    }
    if (sum>=H){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}

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

const int gray = 399, brown = 799, green = 1199, lb = 1599, blue = 1999, yell = 2399, dai = 2799, red = 3199;
int n, col[9];

int getmax()
{
	int max = 0;
	for (int i = 0; i < 8; i++) {
		if (col[i]) max++;
	}
	max += col[8];
	return max;
}

int getmin()
{
	int min = 0;
	for (int i = 0; i < 8; i++) {
		if (col[i]) min++;
	}
	if(min == 0 && col[8] > 0){
		return 1;
	}
	return min;
}

int getCol(int a)
{
	int r = 0;
	if (a <= gray){
		return 0;
	}
	if (a <= brown){
		return 1;
	}
	if (a <= green){
		return 2;
	}

	if (a <= lb){
		return 3;
	}

	if (a <= blue){
		return 4;
	}

	if (a <= yell){
		return 5;
	}

	if (a <= dai){
		return 6;
	}
	if (a <= red){
		return 7;
	}
	return 8;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		col[getCol(a)]++;
	}
	cout << getmin() << " " << getmax() << endl;
}


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

int main() {
  string S;
  cin >> S;
  
  if(S=="a" || S=="i" || S=="u" || S=="e" || S=="o"){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
  
}

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

int main() {
  string S; cin>>S;
  int s=S.size();
  vector<char> A(26);
  rep(i, s) {
    int a=S[i]-'a';
    A[a]++;
  }
  int ans = -1;
  rep(i, 26) {
    if (A[i]==0) {
      ans = i;
      break;
    }
  }
  if (ans==-1) cout<<"None"<<endl;
  else cout<<(char)(ans+'a')<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
typedef long long ll;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

bool check(vector<vector<char>> C, vector<int> rows, vector<int> cols, int K){
    int bcount=0;
    for(int i : rows){
        for(int j : cols){
            if(C[i][j] == '#') bcount++;
        }
    }
    if(bcount == K) return true;
    else return false;
}
void solve() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> C(H, vector<char>(W));
    rep(i, H) rep(j, W){
        cin >> C[i][j];
    }
    int count=0;
    for(int biti=0; biti < (1<<H); ++biti){
        vector<int> rows;
        rep(i, H){
            if(biti & (1<<i)) rows.push_back(i);
        }
        for(int bitj=0; bitj < (1<<W); ++bitj){
            vector<int> cols;
            rep(j, W){
                if(bitj & (1<<j)) cols.push_back(j);
            }
            if(check(C, rows, cols, K)) count++;
        }
    }
    out(count);

}
int main() {
    INCANT;
    solve();
    return 0;
}




Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
     
int main()
{
  int n;
  int A[500000];
  cin >> n;
     
  int N = 1;
  for(int i=0; i<n; i++) {
    N *= 2;
  }
  //cout << N << endl;
  for(int i=0; i<N; i++) cin >> A[i];
     
  for(int i=0; i<=n; i++) {
    for(int j=0; j<N; j+=(int)pow(2, i+1)) {
     
      if( A[j] < A[j+(int)pow(2, i)] ) {
    	A[j] = A[j+(int)pow(2, i)] - A[j];
    	A[j+(int)pow(2, i)] = 0;
      }
      else if( A[j] > A[j+(int)pow(2, i)] ) {
    	A[j] = A[j] - A[j+(int)pow(2, i)];
    	A[j+(int)pow(2, i)] = 0;
      }
      else {
    	A[j+(int)pow(2, i)] = 0;
           
      }
      //cout << A[j] << endl;
    }
  }
     
      
  for(int i=0; i<N; i++) {
    if( A[i] != 0 ) {
      cout << A[i] << endl;
    }
  }
      
}


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

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define int long long

using namespace std;

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

const long long INF = LLONG_MAX/3;

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; }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[a]+=siz[b];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

signed main(){
	int k,x;
	cin>>k>>x;
	if(k*500>=x)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
using System;
class Program{
    static void Main(string[]args){
        string N=Console.ReadLine();
        string[]t=N.Split(' ');
        int a=int.Parse(t[0]);
        int b=int.Parse(t[1]);
        int s=a-1;
        if(b>=a){
            s=s+1;
        }
        Console.WriteLine(s);
    }
}

Measured memory_bytes: 11092
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,i;
	long long a[100000],x;
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%lld",&a[i]);
	sort(a,a+n);
//	for(i=0;i<n;i++) printf("%lld,",a[i]);
	printf("\n");
	
	x=0;
	for(i=n-1;i>0;i--){
		if(a[i]==a[i-1]){
			if(x!=0) break;
			x=a[i];
			i--;
		}
	}
	x=x*a[i];
	printf("%lld",x);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
using namespace std;

const int INF=1000000;

int main()
{
	int k,x;
	cin>>k>>x;
	for(int i=max(x-k+1,-INF);i<=min(x+k-1,INF);i++)
		cout<<i<<" ";
	cout<<endl;
	return 0;
}

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

using namespace std;

string S;

long long int MOD = 1000000007;

long long int dp[100005][13];

int N;

long long int A[100005];

int VAL(int k, int i) {

	long long int ret = k;

	/*for (int p = 1; p <= i; p++) {
		k *= 10;
		k %= 13;
	}*/

	

	return (k*A[i])%13;
}

int main(void) {

	cin >> S;
	N = S.size();

	A[0] = 1;
	

	for (int i = 1; i <= N + 1; i++) {
		A[i] = (A[i - 1] * 10) % 13;
	}


	dp[N][0] = 1;
	//===============================

	for (int i = 0; i <= N - 1; i++) {
		int n = N - i - 1;

		if (S[i] == '?') {
			for (int j = 0; j <= 9; j++) {
				int m = VAL(j, n);
				for (int k = 0; k <= 12; k++) {
					dp[n][(k + m) % 13] += dp[n + 1][k];
					dp[n][(k + m) % 13] %= MOD;
				}
			}

		}
		else {
			int v = S[i] - '0';
			int m = VAL(v, n);
			//cout << "v= " << v << endl;
			//cout << "m= " << m << endl;
			for (int k = 0; k <= 12; k++) {
				dp[n][(k + m) % 13] += dp[n + 1][k];
				dp[n][(k + m) % 13] %= MOD;
			}
		}
	}

	cout << dp[0][5] << endl;

	return 0;
}

Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i];
    }
    int x = accumulate(a.begin(), a.end(), 0);
    cout << max(n - x, -1) << '\n';
    return 0;
}

Measured memory_bytes: 3660
n,k = map(int, input().split())
x = list(map(int, input().split()))
d = [None]*(n-k+1)
for i in range(n-k+1):
  d[i] = min(abs(x[i]),abs(x[i+k-1]))*2+max(abs(x[i]),abs(x[i+k-1])) if  x[i] <= 0 <= x[i+k-1] else max(abs(x[i]),abs(x[i+k-1]))

print(min(d))

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



int main()
{
	const int MOD=1e9+7;
	string S;
	cin>>S;
	reverse(S.begin(),S.end());
	int N=S.size();
	vector<vector<int>> dp(N+1,vector<int>(13,0));
	int x=1;
	dp[0][0]=1;
	rep(i,N)
	{
		if(S[i]=='?')
		{
			rep(j,10)
			{
				rep(k,13)
				{
					(dp[i+1][(j*x+k)%13]+=dp[i][k])%=MOD;
				}
			}
		}
		else
		{
			rep(j,13)
			{
				(dp[i+1][((S[i]-'0')*x+j)%13]+=dp[i][j])%=MOD;
			}
		}
		(x*=10)%=13;
	}
	cout<<dp[N][5]<<endl;
	return 0;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
  if ((x += a.x) >= mod) x -= mod;
  return *this;
  }
  mint& operator-=(const mint a) {
  if ((x += mod-a.x) >= mod) x -= mod;
  return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
  if (!t) return 1;
  mint a = pow(t>>1);
  a *= a;
  if (t&1) a *= *this;
  return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A.at(i);
    vector<mint> acc(N+1);
    acc.at(0) = 0;
    rep(i, N){
        acc.at(i+1) = acc.at(i) + A.at(i);
    }
    mint ans = 0;
    rep(i, N-1){
        ans += (acc.at(N) - acc.at(i+1)) * A.at(i);
    }
    cout << ans << endl;
}

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

using namespace std;

int arr[100];

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

	int ans = 1e9;
	for (int i = -100; i <= 100; ++i) {
		int tot = 0;
		for (int j = 0; j < n; ++j)
			tot += (arr[j] - i) * (arr[j] - i);

		ans = min(ans, tot);
	}

	printf("%d", ans);

	return 0;
}

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



int main(){
    ll n,m;cin>>n>>m;
    if(m*n==1){
        cout<<0<<endl;
        return 0;
    }
    cout<<n*(n-1)/2+m*(m-1)/2<<endl;
    
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 333;
char g[maxn][maxn];
int ans[maxn][maxn];
int main(){
	int h, w, k; cin >> h >> w >> k;
	int last = -1, cur = 1;
	for(int i = 0; i < h; i++){
		vector<int> wh;
		wh.push_back(-1);
		for(int j = 0; j < w; j++){
			cin >> g[i][j];
			if(g[i][j] == '#') wh.push_back(j);
		}
		int len = wh.size();
		if(len > 1){
			for(int j = 1; j < len; j++){
				int to = wh[j];
				if(j == len - 1) to = w - 1;
				for(int k = last + 1; k <= i; k++){
					for(int l = wh[j-1]+1; l <= to; l++){
						ans[k][l] = cur;
					}
				}
				cur++;
			}
			last = i;
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(ans[i][j] == 0){
				ans[i][j] = ans[i - 1][j];
			}
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++)
			cout << ans[i][j] << " ";
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
long long INF = (1LL<<62);
typedef long long LL;

static LL P = 1000000007LL;

int S[2002] = {0};
int T[2002] = {0};

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

	LL N, K;
	cin >> N >> K;
	vector<LL> A;
	for(int i=0; i<N; i++){
		LL a; cin >> a;
		A.push_back(a);
	}

	for(int i=0; i<N; i++){
		LL a = A[i];
		for(int j=0; j<N; j++){
			LL b = A[j];
			if(b < a){
				S[i]++;
				if(j > i){
					T[i]++;
				}
			}
		}
	}
	LL ans = 0;
	if(K == 1){
		for(int i=0; i<N; i++){
			ans += T[i];
			ans %= P;
		}
		ans %= P;
		printf("%lld\n", ans);
		return 0;
	}

	for(int i=0; i<N; i++){
		LL s = S[i];
		LL t = T[i];
		K %= P;
		LL u = (t * K) % P;
		ans += u;
		ans %= P;
		LL v = (K*(K-1))/2;
		v %= P;
		v *= s;
		v %= P;
		ans += v;
		ans %= P;
	}
	ans %= P;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
const int N=100005,mod=1e9+7;
#define inf 0x7fffffff
vector<int>G[N];
int vis[N][3];
int dis[N][3];
int S,T;
struct node
{
    int id,dis;
};
queue<node>q;
void dijstra()
{
 
    for(int i=1;i<=N-5;i++)
        for(int j=0;j<3;j++)
            dis[i][j]=inf,vis[i][j]=0;
    q.push({S,0});
    dis[S][0]=0;
    while(!q.empty())
    {
        int u=q.front().id;
        int d=q.front().dis;
        q.pop();
        if(vis[u][d])continue;
        vis[u][d]=1;
        for(auto v:G[u])
        {
            int len=(d+1)%3;
            if(dis[v][len]>dis[u][d]+1)
            {
                dis[v][len]=dis[u][d]+1;
                q.push({v,len});
            }
 
        }
    }
}
int main()
{
    int n,m,u,v;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
    }
    scanf("%d%d",&S,&T);
    dijstra();
    if(dis[T][0]==inf)
        puts("-1");
    else
        printf("%d\n",dis[T][0]/3);
    return 0;
}

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

using namespace std;

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

    long long n,k;

    cin >> n >> k;

    if(n * 500 >= k)
        cout <<"Yes";
    else
        cout <<"No";

    return 0;
}


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

int main(void){
    int n;
    cin >> n;
    vector<vector<int>> table(10,vector<int>(10,0));
    int top,tail;
    for(int i=1; i<=n; i++){
        tail = i%10;
        top = to_string(i).at(0) - '0';
        table[top][tail]++;
    }
    ll ans=0;
    for(int i=0;i<10;i++){
        ans += table[i][i] * table[i][i];
        for(int j=i+1;j<10;j++){
            ans += table[i][j] * table[j][i] * 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from math import gcd

N = int(input())
A = list([int(x) for x in input().split()])

max_a = max(A)

before = 0
result = [0 for _ in range(max_a + 1)]

for i in A:
    before = gcd(before, i)
    result[i] += 1

is_pairwise = True

for i in range(2, max_a + 1):
    cnt = 0
    for j in range(i, max_a + 1, i):
        cnt += result[j]
    if cnt > 1:
        is_pairwise = False
        break

if is_pairwise:
    print('pairwise coprime')
    exit()
if before == 1:
    print('setwise coprime')
else:
    print('not coprime')


Measured memory_bytes: 133320
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1010;
int main(){
	int a,b,c,k;
    cin >> a>>b>>c>>k;
    long long x=0;
    if(k<=a) x = k;
    else if(a<k&&k<=a+b) x = a;
    else if(a+b<k&&k<=a+b+c) x= a-(k-a-b);
    cout <<x<<endl;
	return 0;
}

Measured memory_bytes: 3596
fun main(args: Array<String>) = IO().exec {
    val s = string().toCharArray()
    val cnt = count(s)
    val cntarr = arrayOf(cnt['a'] ?: 0, cnt['b'] ?: 0, cnt['c'] ?: 0)
    val minv = cntarr.min()!!
    for (i in 3) {
        cntarr[i] -= minv
    }
    println(if (cntarr.any { it >= 2 }) "NO" else "YES")
}

fun count(arr: CharArray): MutableMap<Char, Int> {
    val hmap = mutableMapOf<Char, Int>()
    for (item in arr) {
        hmap[item] = (hmap[item] ?: 0) + 1
    }
    return hmap
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}
// endregion

Measured memory_bytes: 34072