akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

signed main(){
	int N, M;
	cin >> N >> M;
	vector< pair<int, int> > conds[N+1];
	rep(M){
		int l, r, x;
		cin >> l >> r >> x;
		conds[r].emplace_back(l, x);
	}

	vector< vector< vector<int> > > dp(N+1, vector< vector<int> >(N+1, vector<int>(N+1, 0)));

	dp[0][0][0] = 1;
	rep(N){
		repp(j, N){
			repp(k, N){
				int r = max(i, max(j, k));
				int add = dp[i][j][k];
				dp[r+1][j][k] += add;
				if(dp[r+1][j][k] > MOD) dp[r+1][j][k] -= MOD;
				dp[i][r+1][k] += add;
				if(dp[i][r+1][k] > MOD) dp[i][r+1][k] -= MOD;
				dp[i][j][r+1] += add;
				if(dp[i][j][r+1] > MOD) dp[i][j][r+1] -= MOD;

				for(auto p : conds[r+1]){
					int l = p.first, x = p.second;
					int ii = 0, jj = 0, kk = 0;
					if(l <= i) ii = 1;
					if(l <= j) jj = 1;
					if(l <= k) kk = 1;
					if(jj + kk + 1 != x) dp[r+1][j][k] = 0;
					if(ii + kk + 1 != x) dp[i][r+1][k] = 0;
					if(ii + jj + 1 != x) dp[i][j][r+1] = 0;
				}
			}
		}
	}

	ll ans = 0;
	repp(i, N){
		repp(j, N){
			if((i > 0 && i == j)) continue;
			ans += dp[i][j][N];
			if(ans > MOD) ans -= MOD;
			ans += dp[i][N][j];
			if(ans > MOD) ans -= MOD;
			ans += dp[N][i][j];
			if(ans > MOD) ans -= MOD;
		}
	}
	cout << ans % MOD << endl;
	return 0;
}



Measured memory_bytes: 110336
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int N, K;
  cin >> N >> K;
  int h[N + 10];
  REP(i, N) cin >> h[i];
  int dp[N + K + 10];
  REP(i, N + K + 10) dp[i] = 1e9;
  dp[0] = 0;
  REP(i, N) {
    REP1(j, K) dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
  }
  cout << dp[N - 1] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

int main() {
	int s, w;
	cin >> s >> w;
	if (w >= s) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int N;
  cin>>N;
  vector<int> A(N),B(N);
  rep(i,N)cin>>A[i];
  rep(i,N)cin>>B[i];
  int ans=0;
  rep(i,N){
    int Mans=0;
    rep(j,N){
      if(j<=i){
        Mans+=A[j];
      }
      if(j>=i){
        Mans+=B[j];
      }
    }
    ans=max(Mans,ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

long long A, B, C, D;

void solve()
{
    cin >> A >> B >> C >> D;
    if (A < B || D < B) {
        cout << "No" << endl;
        return;
    }
    if (B - C <= 1) {
        cout << "Yes" << endl;
        return;
    }
    // C < x < B <= D
    long long delta = D % B;
    if (delta == 0) {
        if (A % B > C) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    } else {
        delta = __gcd(delta, B);
        A %= B;
        A += (B - A - 1) / delta * delta;
        if (A > C) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
}

int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        solve();
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<'\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define sz(A) (int)A.size()
#define N 1014159
#define  vi vector<int>
#define  v  vector
#define die exit(0)
#define alln(arr) arr+1 , arr+1+n
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update> oset; 

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).

#define in input_int()
#define ins input_string()
int input_int(){int a;cin>>a;return a;}
string input_string(){string s;cin>>s;return s;}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};



int n,m,k,a,b,c,d,x,y,arr[N];
string s;

vi adj[N];

void solve()
{
    cin>>n;
        

    int ans=0;

    forn(i,1,n)
    {
        ans+=i*(n-i+1);
    }

    forn(i,1,n-1)
    {
        cin>>a>>b;
        if(a>b)swap(a,b);
        ans-=a*(n-b+1);
    }
    cout<<ans;

}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    forn(i,1,t)
    {
        solve();
        nl;
    }



    return 0;

}
//       clang++ c.cpp ; ./a.out < a.txt ;  

Measured memory_bytes: 27400
#include <stdio.h>
int selectionSort(int*,int);
int main(){
  int A[100],i,j,N,s;
  scanf("%d",&N);
  for(i=0;i<N;i++)
    scanf("%d",&A[i]);
  s=selectionSort(A,N);

  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i==N-1)break;
    printf(" ");
  }
  printf("\n");
  
  printf("%d\n",s);
  return 0;
}

int selectionSort(int A[],int N){
  int i,j,tmp,minj,count=0;
  for(i=0;i<N;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj])
	minj=j;
    }
    if(minj!=i)count++;
      tmp=A[i];
      A[i]=A[minj];
      A[minj]=tmp;
    
  }
  return count;
}



Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
// #include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }



void solve(void)
{ 
  int N,K;cin>>N>>K;
  string str;cin>>str;
  vector<pair<int,int> > vp;
  vp.emplace_back(-1,0);
  for (int i = 0; i < str.size(); i++)
  {
    int X = str[i] -'0';
    if(i == 0)
    {
      vp.emplace_back(X,1);
      continue;
    }
    if(vp.back().first == X)
    {
      vp.back().second++;
    }
    else
    {
      vp.emplace_back(X,1);
    }
  }
  for (int i = 0; i < vp.size()-1; i++)
  {
    vp[i+1].second += vp[i].second;
  }
  int res = 0;
  for (int i = 1; i <= vp.size()-1; i++)
  {
    int P = -1;
    if(vp[i].first == 0)
    {
      P = i + 2*K-1;
    }
    else
    {
      P = i + 2*K ;
    }
    if(P >= vp.size()) P = (int)vp.size()-1;
    chmax(res,vp[P].second - vp[i-1].second);
  }
  // for (auto &&i : vp)
  // {
  //   cout<<i.first<<" "<<i.second<<endl;
  // }
  
  cout<<res<<endl;
  
  
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 5404
import fractions

a, b, k = map(int, input().split())
gcd = fractions.gcd(a, b)
divisor_list = []

if gcd == 1:
    divisor_list = [1]
else:
    divisor_list.append(1)
    for i in range(2, gcd // 2 + 1):
        if gcd % i == 0:
            divisor_list.append(i)
    divisor_list.append(gcd)

print(divisor_list[len(divisor_list)-1-k+1])


Measured memory_bytes: 5048
from collections import deque
N = int(input())
A = deque(sorted([int(input()) for i in range(N)]))

X = deque([A.popleft()])
ans = 0
for i in range(N - 1):
    # Aのどちらから取り出してXのどちらに入れるか
    left_left = abs(X[0] - A[0])
    left_right = abs(X[-1] - A[0])
    right_left = abs(X[0] - A[-1])
    right_right = abs(X[-1] - A[-1])

    if left_left >= max(left_right, right_left, right_right):
        ans += left_left
        X.appendleft(A.popleft())

    elif left_right >= max(left_left, right_left, right_right):
        ans += left_right
        X.append(A.popleft())

    elif right_left >= max(left_left, left_right, right_right):
        ans += right_left
        X.appendleft(A.pop())

    else:
        ans += right_right
        X.append(A.pop())

print(ans)


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

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

	int ans = INT32_MAX / 2;;
	for( char c = 'a'; c <= 'z'; c++ ) {
		int n = s.size();
		string ss = s;
		int ans1 = 0;
		while( 1 ) {
			int flag = 0;
			char cc = ss[0];
			for( int i = 1; i < n; i++ ) {
				if( ss[i] != cc ) flag = 1;
			}
			if( flag == 0 ) break;
			n--;
			for( int i = 0; i < n; i++ ) {
				if( ss[i] == c ) {
					ss[i] = ss[i];
				}
				else if( ss[i + 1] == c ) {
					ss[i] = ss[i + 1];
				}
				else ss[i] = ss[i + 1];
			}
			ans1++;
		}
		ans = min( ans, ans1 );
	}

	cout << ans  << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long   ll;
int main(){
	ll n,weight;
	cin>>n>>weight;
	ll w[109];
	ll v[109];
	int sum=0;
	for(int i=1;i<=n;i++){
		cin>>w[i]>>v[i];
		sum+=v[i];
 
	}
	ll dp[sum+1];
	fill(dp,dp+sum+1,1e9+9);
	dp[0]=0;
	for(int i=1;i<=n;i++){
		for(int j=sum;j>=v[i];j--){
			dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
		}
	}
	ll ans=0;
	for(ll i=1;i<=sum;i++){
		if(dp[i]<=weight)
		ans=max(ans,i);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;

int n,a[210],x[70];
char c[210];

signed main()
{
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i];
		for(int i=1;i<=n;i++) cin>>c[i];
		memset(x,0,sizeof(x));
		bool flag=false;
		for(int i=n;i>=1;i--){
			if(c[i]=='0'){
				for(int j=60;j>=0;j--){
					if(a[i]&(1ll<<j)){
						if(!x[j]){
							x[j]=a[i];
							break;
						}
						else a[i]^=x[j];
					}
				}
			}
			else{
				for(int j=60;j>=0;j--){
					if(a[i]&(1ll<<j)){
						a[i]^=x[j];
					}
				}
				if(a[i]!=0){
					flag=true;break;
				}
			}
		}
		if(flag) cout<<1<<endl;
		else cout<<0<<endl; 
	}
	return 0;
}

Measured memory_bytes: 3520
N, M = map(int, input().split())
T = [[""] for i in range(N)]
S = [[""] for i in range(M)]
for i in range(N):
    a = input()
    T[i] = a

for i in range(M):
    b = input()
    S[i] = b

flag = False
for i in range(N - M + 1):
    for j in range(N - M + 1):
        if T[i][j] == S[0][0]:
            flag1 = True
            for k in range(M):
                for l in range(M):
                    if T[i + k][j + l] != S[k][l]:
                        flag1 = False
            if flag1:
                flag = True

if flag:
    print("Yes")
else:
    print("No")




Measured memory_bytes: 3064
using System;
class Program
{
	static void Main(string[] args)
	{
      int n = int.Parse(Console.ReadLine());
      string[] in2 = Console.ReadLine().Split(' ');
      int[] a = new int[n];
      int[] b = new int[n];
      for(int i = 0; i < n; i++) b[i] = 0;
      for(int i = 0; i < n; i++)
      {
        a[i] = int.Parse(in2[i]);
        b[a[i] - 1] += 1;
      }
      long sum = 0;
      foreach(int tmpi in b)
      {
        long tmp = tmpi;
        if(tmp > 1) sum += tmp * (tmp - 1) /2;
      }
      
      foreach(int ak in a)
      {
        long ans = sum;
        if(ans > 0)
        {
          long bak = b[ak - 1];
          ans -= bak - 1;
        } 
        Console.WriteLine(ans);
      }
      
	}
}




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

using namespace std;

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

    // solution comes here
    int x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dy=y2-y1, dx=x2-x1;
    cout << x2-dy << " " << y2+dx << " " << x1-dy << " " << y1+dx << "\n";
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        h: [i64; n]
    }
    let mut h = h;
    h.reverse();

    let mut ans = 0;
    let mut crr = 0;
    for i in 0..n {
        if i == 0 || h[i - 1] > h[i] {
            crr = 0;
        } else {
            crr += 1;
        }
        if crr > ans {
            ans = crr;
        }
    }

    println!("{}", ans);
}


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int ans = 0;
	rep(i, n) ans += a[i] - 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v){stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n<<=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}
void YN(bool z){cout<<(z?"YES\n":"NO\n");}
void Yn(bool z){cout<<(z?"Yes\n":"No\n");}
void yn(bool z){cout<<(z?"yes\n":"no\n");}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 50001;
int n, m, d, dp[N];

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  Fill(dp, iinf);
  dp[0] = 0;
  FOR(i, 0, m){
    cin >> d;
    FOR(i, d, N) mins(dp[i], dp[i-d] + 1);
  }
  cout << dp[n] << endl;
  return 0;
}



Measured memory_bytes: 3372
/*
h s, d't skp th si tll i's sved
 * ABC141 E
*/
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
ll n;
cin>>n;
ll ans=n-1;
for(ll i=sqrt(n);i>=2;i--)
{
if(n%i==0)
{
ans=min(ans,i-1+n/i-1);break;
}
}
cout<<ans;
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int N, M, R;
int r[10];
int A, B, C;
int d[201][201];
bool used[10];
int res;

void dfs(int c, int las, int dist)
{
	if (c == R + 1)
	{
		if (res > dist) res = dist;
		return;
	}
	for (int i = 1; i <= R; i++)
	{
		if (!used[i]) {
			used[i] = true;
			if (las == -1) dfs(c + 1, i, 0);
			else dfs(c + 1, i, dist + d[r[las]][r[i]]);
			used[i] = false;
		}
	}
}

int main()
{
	cin >> N >> M >> R;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if (i != j) d[i][j] = INF;
		}
	}
	for (int i = 1; i <= R; i++) cin >> r[i];
	for (int i = 1; i <= M; i++)
	{
		cin >> A >> B >> C;
		if (d[A][B] > C) d[A][B] = d[B][A] = C;
	}
	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				if (d[i][j] > d[i][k] + d[k][j]) {
					d[i][j] = d[i][k] + d[k][j];
				}
			}
		}
	}
	res = INF;
	dfs(1, -1, 0);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin>>n;
    cout<<n*n*n<<endl;

    return 0;
}


Measured memory_bytes: 888
/// Author : HASEBUL HASSAN TANIM ///
#include <bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define pp pop_back
#define scan(t) scanf("%d",&t)
#define sscan(t) scanf("%lld",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define LL long long
#define ull unsigned long long
#define rock(cont) cont.begin(), cont.end()
#define roll(a,n) arr,arr+n
#define rep(i,n) for(int i=0 ; i<n ; i++)
#define repp(i, n) for(int i=1 ; i<=n ; i++)
#define print(t) printf("%d",t)
#define pprint(t) printf("%lld",t)
#define co(x) cout<<x
#define nl printf("\n")
#define el cout<<endl
#define INF (int)1e9

const int RT = 10000000;

vector<int>prime;
vector<LL>factor;
bitset<10000003> status;



int gcd(LL a,LL b){ return b==0 ? a: gcd(b,a%b);}
int lcm(LL a,LL b) { return a* (b/gcd(a,b));}

vector<int> Divisors(int n)
{
    vector<int> v;
    int limit=sqrt(n);
    for (int i=1; i<=limit; i++)
    {
        if (n%i==0)
        {
            if (n/i == i)
                v.push_back(i);
            else
            {
                v.push_back(i);
                v.push_back(n/i);
            }
        }
    }
    return v;
}

void sieve()
{
    int rt = sqrt(RT);
    //for(int i = 4; i <= rt; i+=2) status[i]=true;
    for(int i = 3; i <= rt; i+=2)
        if(!status[i])
            for(int j = i*i; j < RT; j+=(i<<1))
                status[j] = true;

    prime.push_back(2);

    for(int i = 3; i <= RT; i+=2)
        if(!status[i])
            prime.push_back(i);
}

LL primefac(LL n)
{
    int pf_idx=0,pf=prime[pf_idx],SIZE=prime.size();
    LL ANS=1,step=0;
    while(pf*pf<=n&&pf<SIZE)
    {
        if(n%pf==0)
        {
            while(n%pf==0) {n/=pf;}
            ANS=pf;
            step++;
        }
        pf=prime[++pf_idx];
        //cout<<pf<<" "<<n<<" "<<ANS<<endl;
    }
    if(n!=1) { ANS=max(ANS,n); step++; }
    if(step>1)
    {
      return ANS;
    }
    else
    {
        return -1;
    }
}

int main()
{
    int n;
    scan(n);
    LL sum=0;
    repp(i,n)
    {
        if(!(i%3==0&&i%5==0||i%3==0||i%5==0))
        {
            sum+=i;
        }
    }
    printf("%lld\n",sum);
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
int n,d,x[15][15],ans;
bool squa(int x)
{
	for(int i=1;i*i<=x;i++)
		if(i*i==x)
			return true;
	return false;
}
int main()
{
	cin>>n>>d;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=d;j++)
			cin>>x[i][j];
	for(int a=1;a<=n;a++)
		for(int b=a+1;b<=n;b++)
		{
			int sum=0;
			for(int i=1;i<=d;i++)
				sum+=abs(x[a][i]-x[b][i])*abs(x[a][i]-x[b][i]);
			if(squa(sum))
				ans++;
		}
	cout<<ans<<endl;
	return 0;
}


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

set<int> divisor(int n) {
    set<int> ret;
    for (auto i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.insert(i);
            if (n % (n / i) == 0) ret.insert(n / i);
        }
    }
    return ret;
}
int main() {
    int64_t n, m, ans = 1;
    cin >> n >> m;
    auto s = divisor(m);
    for (auto itr = s.rbegin(); itr != s.rend(); itr++) {
        if (m < n * *itr) continue;
        ans = *itr;
        break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>

int main(void) {
   int n;
   scanf("%d",&n);

   if(n%10 == 2 || n%10 == 4 || n%10 == 5 || n%10 == 7 || n%10 == 9) {
      printf("hon");
   } else if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8) {
      printf("pon");
   } else {
      printf("bon");
   }
   return 0;
}

Measured memory_bytes: 1692
n = int(input())
a = [int(x) for x in input().split()]
ans = 0
s = 0
x = 0
r = 0
for l in range(n):
    while r<n and s+a[r]==x^a[r]:
        s += a[r]
        x ^= a[r]
        r += 1
    ans += (r-l)
    if l==r:
        r += 1
    else:
        s -= a[l]
        x ^= a[l]
print(ans)

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

int main()
{
  int n, i, j;
  char s[101];
  int a[26];
  int b[26];
  cin >> n >> s;
  int ans = 0;
  for (i = 0; i < n-1; i++) {
    int cnt = 0;
    for (j = 0; j < 26; j++) {
      a[j] = 0;
      b[j] = 0;
    }
    for (j = 0; j <= i; j++) {
      a[s[j]-'a']++;
     }
    for (j = i+1; j < n; j++) {
      b[s[j]-'a']++;
     }
    for (j = 0; j < 26; j++) {
      if (a[j] > 0 && b[j] > 0)
	cnt++;
    }
    if (cnt > ans)
      ans = cnt;
  }
  cout << ans << endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/15  Problem: 064_abc_d / Link: https://abc064.contest.atcoder.jp/tasks/abc064_d?lang=en ----- */
/* ------問題------

( と ) で構成される N 文字の文字列 S が与えられる。S にいくつかの ( または ) を挿入することで正しい括弧列を作りたい。
ただし、正しい括弧列は次のように定義されている：

() は正しい括弧列である。
X が正しい括弧列であるとき、(、X、) をこの順につなげたものは正しい括弧列である。
X、Y が正しい括弧列であるとき、X と Y をこの順につなげたものは正しい括弧列である。
それ以外の括弧列は正しくない。
そのとき、作れる最も文字数が少ない正しい括弧列を求めなさい。このようなものが複数ある場合は、辞書順最小のものを求めなさい。

-----問題ここまで----- */
/* -----解説等-----

存在する数はDPでできるけど、辞書順最小なので前に（を、後ろに）をたくさんつけたほうがいい感じになる。

----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	string s;
	cin >> s;
	stack<int>st1; // (
	stack<int>st2; // )
	FOR(i, 0, N) {
		if (s[i] == '(') {
			st1.push(1);
		}
		else { // )
			if (SZ(st1))st1.pop();
			else st2.push(1);
		}
	}
	FOR(i, 0, SZ(st2)) {
		cout << "(";
	}
	cout << s;
	FOR(i, 0, SZ(st1)) {
		cout << ")";
	}
	cout << endl;



	return 0;
}


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

int main(void){
    int N; cin >> N;
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        int a; cin >> a;
        ans += a-1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin >> q;
    int l[q] , r[q] , p[100005] = {0} , a[100005] = {0} , b[100005] = {0};
    for (int i = 0 ; i < q ; i++) cin >> l[i] >> r[i];
    for (int i = 2 ; i <= 100000 ; i++) {
        p[i] = 1;
        for ( int j = 2 ; j * j <= i ; j++ ) if ( i % j == 0 ) p[i] = 0;
    }
    for( int i = 1 ; i <= 100000 ; i++ ) if( p[i] && p[(i + 1) / 2] ) a[i] = 1;
    for( int i = 1 ; i <= 100000 ; i++ ) b[i] = b[i - 1] + a[i];
    for( int i = 0 ; i < q ; i++ ) cout << b[r[i]] - b[l[i] - 1] << endl;
}


Measured memory_bytes: 5632
x,y = map(int,input().split())
 
if abs(y) > abs(x):
  if x >= 0 and y >= 0:
    print(y-x)
  elif x < 0 and y <0:
    print(abs(y)-abs(x)+2)
  else:
    print(abs(y)-abs(x)+1)
elif abs(y) < abs(x):
  if x > 0 and y > 0:
    print(x - y + 2)
  elif x <= 0 and y <=0:
    print(abs(abs(y)-abs(x)))
  else:
    print(abs(abs(y)-abs(x))+1)
else:
  if x == y:
    print("0")
  else:
    print("1")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
int n, r, b, g, am[6010][3];
#undef int
int main()
{
	#define int ll
	scanf("%lld%lld%lld%lld", &r, &b, &g, &n);
	am[r][0]++;
	am[b][1]++;
	am[g][2]++;
	for (int i = 0; i <= n; i++)
	{
		am[i+r][0] += am[i][0];
	}
	for (int i = 0; i <= n; i++)
	{
		am[i+b][1] += am[i][0]+am[i][1];
	}
	for (int i = 0; i <= n; i++)
	{
		am[i+g][2] += am[i][1]+am[i][2]+am[i][0];
	}
	printf("%lld\n", am[n][2] + am[n][1] + am[n][0]);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
#define double long double
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<int> lml;
    rep(i, n)if(s[i] == 'L' && s[i-1] == 'R') lml.push_back(i);

    int ans[n];
    memset(ans, 0, sizeof(ans));
    int cur = lml.size()-1;
    rrep(i, n)if(s[i] == 'R'){
        if(cur > 0 && i <= lml[cur-1]) --cur;
        if(i%2 == lml[cur] %2) ++ans[lml[cur]];
        else ++ans[lml[cur]-1];
    }
    cur = 0;
    rep(i, n)if(s[i] == 'L'){
        if(cur < lml.size()-1 && lml[cur+1] <= i) ++cur;
        if(i%2 == lml[cur] %2) ++ans[lml[cur]];
        else ++ans[lml[cur]-1];
    }
    rep(i, n) printf("%d ", ans[i]);
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()
 
#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>
 
#define debug(x) {cerr <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}
 
#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue
 
#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
 
 
using namespace std;

const int mod = 1e9 + 7;

const int max_n = 2e5 + 5;

int n, k, l;

int p[max_n];
int p2[max_n];

int fu(int a) {
	return p[a] == a ? a : (p[a] = fu(p[a]));
}

int fu2(int a) {
	return p2[a] == a ? a : (p2[a] = fu2(p2[a]));
}

map<PII, int> sz;



int main() {
	read3(n, k, l);
	FOR(i,0,n) p[i] = i;
	FOR(i,0,n) p2[i] = i;
	FOR(i,0,k) {
		make2(a, b);
		a--; b--;
		a = fu(a);
		b = fu(b);
		if (a != b) {
			p[b] = a;
		}
	}
	FOR(i,0,l) {
		make2(a, b);
		a--; b--;
		a = fu2(a);
		b = fu2(b);
		if (a != b) {
			p2[b] = a;
		}
	}
	FOR(i,0,n) {
		PII par = mp(fu(i), fu2(i));
		sz[par]++;
	}

	FOR(i,0,n) {
		printf("%d ", sz[mp(fu(i), fu2(i))]);
	}
	printf("\n");
}


Measured memory_bytes: 13568
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
#define int long long

signed main() {
  while (true) {
    int n;
    cin >> n;
    if (!n) return 0;
    string s[n];
    for (int i = 0; i < n; i++) {
      cin >> s[i];
    }
    for (int i = 0; i < n; i++) {
      int count;
      int res = 0;
      count = 0;
      int j = i;
      while (res < 5) {
        count += s[j].size();
        if (res == 0 || res == 2) {
          if (count > 5) break;
          else if (count == 5) {
            res++;
            count = 0;
          }
        } else {
          if (count > 7) break;
          else if (count == 7) {
            res++;
            count = 0;
          }
        }
        j++;
      }
      if (res == 5) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
}



Measured memory_bytes: 3168
#include <iostream>
//#include <iomanip>
#include <string>
//#include <algorithm>
//#include <utility>
//#include <stack>
//#include <queue>
//#include <tuple>
//#include <set>
//#include <map>
//#include <unordered_map>
#include <vector>
//#include <functional>
//#include <bitset>
//#include <cmath>
using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
#define MOD 1000000007

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

    bool chk[200001][26];
    vector<int> beg;
    int r=26,K=0;
    for(int i=0;i<26;i++) chk[s.size()][i]=false;

    for(int at=s.size()-1;at>=0;at--){
        for(int i=0;i<26;i++) chk[at][i]=chk[at+1][i];
        if(!chk[at][s[at]-'a']){
            chk[at][s[at]-'a']=true;
            r--;
        }
        if(r==0){
            r=26;
            for(int i=0;i<26;i++) chk[at][i]=false;
            K++;
            beg.push_back(at);
        }
    }

    string ans="";
    for(char c='a';c<='z';c++){
        if(!chk[0][c-'a']){
            ans=c;
            break;
        }
    }
    for(int i=beg.size()-1;i>=0;i--){
        char last=ans.back();
        int j;
        for(j=beg[i];s[j]!=last;j++);
        for(char c='a';c<='z';c++){
            if(!chk[j+1][c-'a']){
                ans=ans+c;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 4e5+5;

bitset <sz> bst;

int main()
{
    int n, m;
    cin >> n >> m;
    for(int i=1, j=n-1; i<=m; i++, j--) {
        if(bst[j-i] || j-i==n+i-j) j--;
        bst[j-i] = bst[n+i-j] = 1;
        printf("%d %d\n", i, j);
    }
}


Measured memory_bytes: 3764
class UnionFind():
    # コンストラクタ
    def __init__(self, n):
        # 要素数
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        self.parents = [-1] * n

    # 要素xが属するグループの根を返す(経路圧縮)
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 要素xが属するグループと要素yが属するグループとを併合する
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y: return

        if self.parents[x] > self.parents[y]: x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 要素xが属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)]

    # 要素x,yが同じグループに属するかどうかを返す
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    # 全ての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    # グループの数を返す
    def group_count(self):
        return len(self.roots())

    # 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

N,M = map(int, input().split())
UF = UnionFind(N)

cnt = 0
for _ in range(M):
    a, b = map(int, input().split())
    UF.union(a - 1, b - 1)

ans = 0
for c in UF.roots():
    ans = max(ans, UF.size(c))

print(ans)

Measured memory_bytes: 87312
//Solution By SlavicG
#include "bits/stdc++.h"
using namespace std;
 
#define ll                          long long
 
#define forn(i,n)                   for(int i=0;i<n;i++)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
	
#define pb                          push_back
#define sz(a)                       (int)a.size()
 
#define   endl                       "\n"
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


int  main()
{
	int a,b;
	cin >>a>>b;
	cout << (a<=b ? "unsafe":"safe");
}

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

#define rep(i, x, n) for(int i=(x);i<(n);i++)
#define reps(i, x, n) for(int i=(x);i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){ return (y != 0 ? gcd(y, x % y) : x); }
//最小公倍数
lol lcm(lol x, lol y){ return ((x * y) / gcd(max(x, y), min(x, y))); }

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int a[n + 5];
  reps(i, 1, n){
    cin >> a[i];
  }
  int ans = INF;
  reps(i, -100, 100){
    int sum = 0;
    reps(j, 1, n){
      sum += (i - a[j]) * (i - a[j]);
    }
    ans = min(ans, sum);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3616
#import numpy as np

h, n = map(int, input().split())

a = []
b = []
m = []
for i in range(n):
    at, bt = map(int, input().split()) # a_tmp, b_tmp
    a.append(at)
    b.append(bt)

#dp = np.zeros((n+1,h+1))
dp = [[0]*(h+1) for _ in range(n+1)]
for i in range(n):
    for j in range(h):
        # print("Test")
        if j - a[i] < 0:
            o = b[i]
        else:
            o = dp[i+1][j+1-a[i]] + b[i]
        if i != 0:
            dp[i+1][j+1] = min(dp[i][j+1], o)
        else:
            dp[i+1][j+1] = o

print(int(dp[n][h]))


Measured memory_bytes: 120940
_=int(input())
a=list(map(int,input().split()))
a.sort()
n=max(a)
a=a[:-1]

rc=float('inf')
rd=0
r=0
for i in a:
  if rc>abs(i-n/2):
    r=i
  rc=min(rc,abs(i-n/2))
  
print(n,r)

Measured memory_bytes: 19904
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

int N, M, D[1010], C[1010];
vector<int> G[1010];

void go(int x, int d)
{
	D[x] = d;

	int v = 0;
	for (auto &y : G[x]){
		C[y]++;
		v = max(v, D[y]);
	}

	if (v){
		d = 0;
		for (int i = 1; i <= N; i++) if (D[i] >= v) d++;
		printf ("%d\n", d);
		for (int i = 1; i <= N; i++) if (D[i] >= v) printf ("%d\n", i);
		exit(0);
	}

	for (auto &y : G[x]){
		C[y]--;
		if (C[y] == 0) go(y, d + 1);
		C[y]++;
	}
	for (auto &y : G[x]) C[y]--;

	D[x] = 0;
}

int main()
{
	scanf ("%d %d", &N, &M);
	for (int i = 1; i <= M; i++){
		int x, y; scanf ("%d %d", &x, &y);
		G[x].push_back(y);
	}

	for (int i = 1; i <= N; i++) go(i, 1);
	puts("-1");
	return 0;
}

Measured memory_bytes: 384
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    LL a[n + 1];
    a[0] = 0;
    set< LL > st;
    for( int i = 1; i <= n; ++i ) {
        cin >> a[i];
        a[i] += a[i - 1];
        st.insert( a[i] );

    }

    map< LL, int > mp;
    for( int i = 1; i <= n; ++i ) {
        mp[a[i]]++;

    }

    LL res = 0;
    for( auto it = st.begin(); it != st.end(); ++it ) {
        LL dat = *it;
        LL mpd = mp[dat];
        if( dat == 0 ) {
            res += mpd;
            res += ( mpd * ( mpd - 1 ) ) / 2;

        } else {
            res += ( mpd * ( mpd - 1 ) ) / 2;

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



Measured memory_bytes: 23680
N,M,Q=map(int,input().split())
A=[[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
  L,R=map(int,input().split())
  A[L][R]+=1
  
for i in range(1,N+1):
  for j in range(1,N+1):
    A[i][j]+=A[i][j-1]
for i in range(1,N+1):
  for j in range(1,N+1):
    A[i][j]+=A[i-1][j]

for i in range(Q):
  L,R=map(int,input().split())
  ans=A[R][R]-A[L-1][R]-A[R][L-1]+A[L-1][L-1]
  print(ans)

Measured memory_bytes: 57432
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

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

Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func main() {
	scanner.Split(bufio.ScanWords)
	points := make([]int, 6)
	for i := 0; i < 6; i++ {
		points[i] = nextInt()
	}
	// fmt.Println(points)
	sort.Slice(points[:4], func(i, j int) bool { return points[i] > points[j] })
	// fmt.Println(points)
	points2 := points[4:]
	sort.Slice(points2, func(i, j int) bool { return points2[i] > points2[j] })
	// fmt.Println(points)

	fmt.Println(points[0] + points[1] + points[2] + points2[0])
}



Measured memory_bytes: 1148
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>ca;
    if(ca=='A')cout<<'T';
    if(ca=='C')cout<<'G';
    if(ca=='G')cout<<'C';
    if(ca=='T')cout<<'A';


    

    return 0;
}


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

using namespace std ;

const int mod = 1e9 + 7 ;
const int N = 900010 ;
#define ll long long 

int n , m , k ;
ll fac[ N ] , ifac[ N ] , p[ N ] ; 

ll mul( ll x , ll  y ) {
	return ( 1ll * x * y ) % mod ;
}

ll add( ll x , ll y ) {
	return ( x + y ) % mod ;
}

ll power( ll a , ll b ) {
	int ans = 1 , base = a ;
	while( b ) {
		if( b&1 ) ans = mul( ans , base ) ;
		base = mul( base , base ) ; 
		b >>= 1 ;
	}
	return ans ;
}

ll inv( ll x ) {
	return power( x , mod - 2 ) % mod ;
}

ll C( ll x , ll y ) {
	return ( fac[ x ] * ifac[ y ] % mod * ifac[ x - y ] % mod ) % mod ;
}

int main() {
	scanf( "%d%d%d" , &n , &m , &k ) ;
	fac[ 0 ] = 1ll ;
	p[ 0 ] = 1ll ;
	for( int i = 1 ; i < N ; i ++ ) {
		fac[ i ] = fac[ i - 1 ] * i % mod ;
		p[ i ] = p[ i - 1 ] * 3ll % mod ;
	}
	for( int i = 0 ; i < N ; i ++ ) {
		ifac[ i ] = inv( fac[ i ] ) ;
	}
	ll ans = 0 , x = 1ll ;
	n -- ;
	if( m < k ) swap( m , k ) ;
	for( int i = 0 ; i <= m + k ; i ++ ) {
		ans = ( ans + C( n + i , n ) * p[ m + k - i ] % mod * x )  % mod  ;
		/*
		for( int j = 0 ; j <= min( i , m  ) ; j ++ ) {
			if( i - j > k || i - j < 0 ) break ;
			x = add( x , C( i , j ) ) ;
		}
		*/
		if( i < k ) x = ( x * 2ll ) % mod ;
		else if( i < m ) x = ( x * 2ll - C( i , k ) ) % mod ;
		else  x = ( x * 2ll - C( i , k ) - C( i , m ) ) % mod ;
	}
	printf( "%lld\n" , add( ans , mod ) ) ;
	return 0 ;
} 

Measured memory_bytes: 21376
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
int N,x[1000010],y[1000010],f[1000010],H,W;
vector<int> vec[1000010];
int main()
{
	H=read(),W=read(),N=read();
	for(rint i=1;i<=N;++i)
	{
		x[i]=read(),y[i]=read();
		vec[y[i]].pb(x[i]);
	}
	for(rint i=1;i<=W;++i) vec[i].pb(H+1);
//	for(rint i=1;i<=H;++i,cout<<endl)
//	for(rint j=1;j<=W;++j) cout<<vis[i][j]<<" "; 
	for(rint i=1;i<=W;++i)
	{
		sort(vec[i].begin(),vec[i].end());
	}f[1]=1;
	for(rint i=2;i<=W;++i)
	{
		int sz=vec[i].size();
		int tmp=f[i-1]+1;if(tmp==-1) continue;
		for(rint j=0;j<sz;++j)
		{
			int pos=vec[i][j];
			if(pos==tmp) tmp++;
		}
		f[i]=tmp;
	}int ans=1e9;
//	cout<<f[i]<<"\n";
	for(rint i=1;i<=W;++i)
	{
//		cout<<f[i]<<"\n";
		int x=f[i];if(x==-1) continue;
		int cur=lower_bound(vec[i].begin(),vec[i].end(),f[i])-vec[i].begin();
		if(cur<vec[i].size())
		ans=min(vec[i][cur]-1,ans);
	} cout<<ans;
	return 0;
}


Measured memory_bytes: 35328