akhauriyash/Code-Regression huggingface dataset:
#include    <bits/stdc++.h>
using   namespace   std;

int GCD(int a, int b) {
    while(0!=b) {
        a %=b;
        swap(a, b);
    }
    return a;
}

int main() {
    int N;
    cin >>N;
    int S=0;
    for (int i=0; i<N; i++) {
        int a;
        cin >>a;
        bool OK=true;
        for (int j=2; j*j<=a; j++)
            if (0==a%j) {
                OK=false;
                break;
            }
        if (OK)
            S++;
    }
    cout <<S <<endl;
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return(1);
    ll sol=power(a,b/2,m);
    sol=(sol*sol)%m;
    if(b%2==1)
        sol=(sol*a)%m;
    return(sol);
}
void solve()
{
    int n;
    cin>>n;
    if(n%2==0)
        cout<<n;
    else
        cout<<2*n;
}
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>
#include <tuple>
#include <queue>
#include <cassert>
//#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define el '\n'
 

 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	ll n, s = 0, a, cur = LLONG_MIN;
	cin >>n;
	for (int i = 0; i < n; i++){
		cin >> a;
		if (cur < a){
			cur = a;
		} else{
			s += cur - a;
		}
	}
	cout << s<< el;
    return 0;
}

Measured memory_bytes: 3232
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int A, B;
        A=sc.nextInt();
        B=sc.nextInt();
        if (A>9 || B>9){
            System.out.println(-1);
        }else{
            System.out.println(A*B);
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#define popcount(x) __builtin_popcount(x)
#define oddparity(x) __builtin_parity(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define sf scanf
#define pf printf
using namespace std;

int i;
string s, x;

int main()
{
    cin >> s;
    for (i = 0; i < s.size(); i++) {
        if (i == 0) x += s[i];
        else if (s[i] != x[x.size()-1]) x += s[i];
    }
    pf("%d\n", x.size()-1);
    return 0;
}

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

void call(int n)
{
	for( int i = 1; i <= n; i++ ) {
		int x = i;
		if( x % 3 == 0 ) {
			cout << " " << i;
		}
		else {
			while( x ) {
				if( x % 10 == 3 ) {
					cout << " " << i;
					break;
				}
				x /= 10;
			}
		}
	}

	cout << endl;
}

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

	call( n );
}



Measured memory_bytes: 3108
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int sum = 0;
        int i = 0;
        do {
            i = a[i];
            i = i - 1;
            sum++; 
            if (sum == n) {
                sum = -1;
                break;
            }
        } while (i != 1);
        System.out.println(sum);      
    }
}


Measured memory_bytes: 51412
#include<iostream>

using namespace std;

int main(){

    int n;
    cin >> n;
    string s;
    cin >> s;
    int count = 0;
    int j = n - 1;
    for (int i = 0; i < n; i++) {
        if(j <= i) break;
        if (s[i] == 'W' && s[j] == 'W')
        {   
            i--;
            j--;
            continue;
        }     
        if(s[i] == 'W' && s[j] == 'R') {
            {
                swap(s[i], s[j]);
                count++;
                j--;
            }
        }  
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 3396
#include <iostream>
 
#include <iomanip>
#include <stdio.h>
using namespace std;
 
int main()
{
    int N, h;
    cin >> h >> N;
    int a[N];
    for (int i = 0; i < N; i++)
    {
        cin>>a[i];
        h -= a[i];
    }
    if (h > 0)
        printf("No");
    else
        printf("Yes");
 
}

Measured memory_bytes: 640
// 模板
// #include "bits/stdc++.h"
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <queue>
#include <map>
#include <deque>
#include <stack>
#include <cmath>
using namespace std;
#define mm(a,n) memset(a, n, sizeof(a))
#define gcd(a,b) __gcd(a,b) 
#define INF 0x3f3f3f3f  
#define EXP 1e-8  
#define lowbit(x) (x&-x)
typedef long long ll;
typedef unsigned long long ull;
 
void Main();
 
int main() {
    //应清除注释
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w", stdout);
    Main();
    // fclose(stdin);
    // fclose(stdout);
    //system("pause");  //应注释
    return 0;
}
 
void Main() {
    int n;
    cin >> n;
    string str;
    cin >> str;
    int l = 0, r = str.length() - 1, ans = 0;
    while (l < r){
        if(str[l] == 'R') {
            l++;
            continue;
        } else if(str[r] == 'W') {
            r--;
            continue;
        }
        l++;
        r--;
        ans++;
    }
    cout << ans << "\n";
    
}

Measured memory_bytes: 3724
n, m = gets.split.map &:to_i
a = []
b = []
for _ in 1 .. n
  a << gets.chomp
end
for _ in 1 .. m
  b << gets.chomp
end

for i in 0 .. n - m
  for j in 0 .. n - m
    # check match
    ok = true
    for k in 0 ... m
      if a[i + k][j .. j + m - 1] != b[k]
        ok = false
      end
    end
    if ok
      puts "Yes"
      exit 0
    end
  end
end
puts "No"


Measured memory_bytes: 1916
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#define ll long long
#define ull unsigned long long
#define mn 1000020
#define FOR(a,b,c) for (int a=b;a<=c;a++)
#define FORD(a,b,c) for (int a=b;a>=c;a--)
using namespace std;
inline ll read(){
    ll x=0,f=1;
    char c=getchar();
    while (c<'0'||c>'9'){
        if (c=='-')f=-1;
        c=getchar();
    }
    while (c>='0'&&c<='9'){
        x=x*10+c-'0';
        c=getchar();
    }
    return x*f;
}
int Max(int a,int b){return (a>b)?a:b;}
int Min(int a,int b){return (a<b)?a:b;}
char s1[20],s[20];
int main(){
	scanf("%s",s+1);
	int l=strlen(s+1),c=0;
//	cout<<l<<endl;
	if(s[1]!='A'){printf("WA\n");return 0;}
	FOR(i,2,l)if(i<3||i>l-1){
		if(s[i]<'a'||s[i]>'z'){printf("WA\n");return 0;}
	}else{
		if(s[i]=='C')c++;else 
		if(s[i]<'a'||s[i]>'z'){printf("WA\n");return 0;}
		if(c>1){printf("WA\n");return 0;}
	}
	
	if(c==0)printf("WA\n");else printf("AC\n");
	return 0;
}


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

using namespace std;

long long int A, B;

long long int C[48];

int main(void) {

	cin >> A >> B;

	long long int M = 1;
	for (int i = 0; i <= 44; i++) {

		long long int num1 = (A) / (M * 2)*M + max((A) % (M * 2) - M, (long long int) 0);
		long long int num2 = (B+1) / (M * 2)*M + max((B+1) % (M * 2) - M, (long long int) 0);
		
		C[i] = num2 - num1;
		M *= 2;
	}



	/*for (int i = 0; i <= 4; i++) {
		cout << "C[" << i << "]= " << C[i] << endl;
	}*/

	long long int ans = 0;
	for (int i = 44; i >= 0; i--) {
		ans *= 2;
		if ((C[i] % 2) == 1) { ans++; }
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 200001
#define int ll
int N;
int A[maxn],num[maxn];

int32_t main(){
	fast;
	
	cin>>N;
	
	FOR(i,0,N-1){
		cin>>A[i];
		num[A[i]]++;
	}
	int sm = 0;
	
	FOR(i,1,N){
		if (num[i] > 1){
			sm += (num[i] * (num[i] - 1)) / 2;
		}
	}
	
	FOR(i,0,N-1){
		int ans = sm;
		ans -= (num[A[i]] * (num[A[i]] - 1)) / 2;
		ans += ((num[A[i]] - 1) * (num[A[i]] - 2)) / 2;
		
		cout<<ans<<'\n';
	}
		
		
	
}



Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //10^19 < 9223372036854775807
typedef unsigned long long ull; //10^20 < 18446744073709551615

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

#define MOD 1000000007

int main(void)
{
    ll N,K;
    cin >> N >> K;

    vector<int> H(N);
    REP (i,N) {
        cin >> H[i];
    }

    ll ans = 0;
    sort(H.begin(),H.end());
    REP (i,N-K) {
        ans += H[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4048
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] a = new int[n];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			sum += a[i];
		}
		int m = sc.nextInt();
		int[] b = new int[m];
		int[] c = new int[m];
		for (int i = 0; i < m; i++) {
			b[i] = sc.nextInt() - 1;
			c[i] = sc.nextInt();
		}

		for (int i = 0; i < m; i++) {
			System.out.println(sum - a[b[i]] + c[i]);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 10324
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    int n =s.size();
    if (t.substr(0,n) == s)cout << "Yes" << endl;
    else cout << "No" << endl; 
}

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

int main()
{
    string s;
    cin >> s;
    int k;
    cin >> k;
    set<string> se;
    for(int i=0;i<s.size();i++)
    {
        for(int j=i;j<s.size();j++)
        {
            if (j - i >= k)
            {
                continue;
            }
            string t = s.substr(i, j - i + 1);
            se.insert(t);
        }
    }
    auto ite = se.begin();
    for(int i=0;i<k - 1;i++)
    {
        ite++;
    }
    cout << *ite << endl;
    return 0;
}

Measured memory_bytes: 1664
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll dp[45];
dp[0] = dp[1] = 1;
ll n;
cin >> n;
for(ll i = 2; i < 45; i++){
    dp[i] = dp[i - 1] + dp[i - 2];
}
cout << dp[n] << endl;
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
#define cs const 
#define int long long
#define low(i) (i&(-i))
#define mid ((l+r)>>1)
#define ls (now<<1)
#define rs (now<<1|1)
#define par pair<int,int>
#define mp make_pair
#define fr first 
#define se second
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define drep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])
cs int base = 233;
cs int ff = 3e6+1;
cs int mod = 998244353;
cs int inf = 1e9+1;
int n, m; 
void init()
{
	cin >> n;
	printf("%.6lf", (double) ( (double)n /(double) 3 ) *  ( (double)n /(double) 3 ) *  ( (double)n /(double) 3 ) );
}
signed main()
{
	int T = 1;
	while(T--) 
		init();
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    vector<ll>x(n),y(n);
    vector<ll>xary,yary;

    REP(i,n){
        cin>>x[i]>>y[i];
        xary.push_back(x[i]);
        yary.push_back(y[i]);
    }
    VSORT(xary);
    VSORT(yary);
    ll ans=1LL*(xary[n-1]-xary[0])*(yary[n-1]-yary[0]);

    for(int xl=0;xl<n;xl++){
        for(int xr=xl+1;xr<n;xr++){
            for(int yb=0;yb<n;yb++){
                for(int yu=yb+1;yu<n;yu++){
                    int sum=0;
                    for(int i=0;i<n;i++){
                        if(xary[xl]<=x[i]&&x[i]<=xary[xr]&&yary[yb]<=y[i]&&y[i]<=yary[yu]) sum++;
                    }
                    //cout<<sum<<endl;
                    if(sum>=k){
                        chmin(ans,1LL*(yary[yu]-yary[yb])*(xary[xr]-xary[xl]));
                        //cout<<(yary[yu]-yary[yb])*(xary[xr]-xary[xl])<<endl;
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <set>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IFOR(v,it) for(auto it=(v).begin();it!=(v).end();++it)
#define RIFOR(v,it) for(auto it=(v).rbegin();it!=(v).rend();++it)
#define IN_LL(v) LL v;cin>>v;
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl
#define MOD 1000000007


void insertionSort(VI& A, int N) {
  FOR(i, 1, N) {
    cout << A[0];
    FOR(i, 1, N) {
      cout << " " << A[i];
    }
    cout << endl;
    int v = A[i];
    int j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      --j;
    }
    A[j+1] = v;
  }
  cout << A[0];
  FOR(i, 1, N) {
    cout << " " << A[i];
  }
  cout << endl;
}

int main() {
  IN(N);

  VI A;
  REP(i, N) {
    IN(a);
    A.PB(a);
  }
  insertionSort(A, N);

  return 0;
}



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

using namespace std;

int mp[90][90];

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

int m, n;

int dfs(int y, int x)
{
	if (y < 0 || y >= n || x < 0 || x >= m) return 0;

	if (mp[y][x] == 0) return 0;

	int res = 0;

	mp[y][x] = 0;
	for (int i = 0; i < 4; ++i) res = max(res, 1 + dfs(y + dy[i], x + dx[i]));
	mp[y][x] = 1;

	return res;
}

int main()
{
	while (cin >> m >> n, m || n) {
		for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> mp[i][j];

		int ans = 0;

		for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) ans = max(ans, dfs(i, j));

		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1172
def unique(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


imori = list(map(int, input().split()))
n = imori.pop(0)
tsuru = list(map(int, input().split()))
m = tsuru.pop(0)

time = []
for _ in range(n):
    k = imori.pop(0)
    g = imori.pop(0)
    time.append([k, g])

for _ in range(m):
    k = tsuru.pop(0)
    g = tsuru.pop(0)
    time.append([k, g])

time = unique(time)
time = sorted(time, key=lambda x: (x[0], x[1]))
ans = []
for t in time:
    ans.append(str(t[0]) + ":" + str(t[1]).zfill(2))

print(' '.join(ans))



Measured memory_bytes: 5628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int n,k; cin >> n >> k;
	vector<int> h(n);
	rep(i,n) cin >> h[i];
	vector<int> dp(n,INF);
	dp[0] = 0;
	//配るDPにする
	rep(i,n){
		rep2(j,i+1,min(i+1+k,n)) dp[j] = min(dp[j],dp[i]+abs(h[j]-h[i]));
	}
	out(dp[n-1]);
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

void solve(long long a, long long b, long long c, long long d, long long e, long long k)
{
    if (e - a > k)
    {
        cout << ":(" << endl;
    }
    else
    {
        cout << "Yay!" << endl;
    }
}

int main()
{
    long long a;
    scanf("%lld", &a);
    long long b;
    scanf("%lld", &b);
    long long c;
    scanf("%lld", &c);
    long long d;
    scanf("%lld", &d);
    long long e;
    scanf("%lld", &e);
    long long k;
    scanf("%lld", &k);
    solve(a, b, c, d, e, k);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define repj(begin, end) for (j=begin;j<end;j++)
#define init(arr, end, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
ll i, n, k;
ll a[200001];
vector<ll> v;
set<ll> s;

int main() {
    scanf(" %lld %lld", &n, &k);
    rep(0,n) scanf(" %lld", &a[i+1]);
    ll dest = 1;
    ll leninit = -1;
    ll lenloop = -1;
    auto loopstart = v.begin();
    while (true) {
        dest = a[dest];
        if (s.find(dest) != s.end()) {
            auto it = v.begin();
            for (it = v.begin(); *it != dest && it != v.end(); it++);
            if (it == v.end()) it = v.begin();
            leninit = it - v.begin();
            lenloop = v.end() - it;
            loopstart = it;
            break;
        }
        v.push_back(dest);
        s.insert(dest);
    }
    if (k < v.size()) {
        printf("%lld\n", v[k-1]);
    } else {
        k -= leninit;
        ll mod = k % lenloop == 0 ? lenloop - 1 : k % lenloop - 1;
        printf("%lld\n", *(loopstart + mod));
    }
}

Measured memory_bytes: 15424
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s1, s2;

	cin >> s1 >> s2;

	for ( int i = 0; i < s1.size(); i++ )
	{
		if ( s1[i] == s2[i] )
		{
			continue;
		}
		else {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 3592
use proconio::{fastout, input};
use std::collections::BTreeMap;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [i64; n],
        q: usize,
        bc: [(i64, i64); q],
    }

    let mut map = BTreeMap::new();
    let mut sum: i64 = a.iter().sum();

    for a in a {
        map.entry(a).and_modify(|e| *e += 1).or_insert(1);
    }

    for (b, c) in bc.into_iter() {
        if let Some(count_b) = map.remove(&b) {
            let count_b_plus_c = map.remove(&c).unwrap_or(0) + count_b;
            map.insert(c, count_b_plus_c);
            sum += (c - b) * count_b;
        }
        println!("{}", sum);
    }
}


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

using namespace std;
static const int INF = 1e9;
int dp[21][50001];

void solve()
{
	int n, m;
	cin >> n >> m;
	vector<int> coin(m);
	for (int i = 0; i < m; ++i)
	{
		cin >> coin[i];
	}
	for (int i = 0; i < 50001; ++i)
	{
		dp[0][i] = INF;
	}
	for (int i = 0; i < 21; ++i)
	{
		dp[i][0] = 0;
	}
	for (int i = 1; i <= m; ++i)
	{
		for (int j = 1; j <= n; ++j)
		{
			if (j < coin[i - 1])
			{
				dp[i][j] = dp[i - 1][j];
			}
			else
			{
				dp[i][j] = min(dp[i - 1][j], dp[i][j - coin[i - 1]] + 1);
			}
		}
	}
	cout << dp[m][n] << endl;
}

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

Measured memory_bytes: 5292
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>

using namespace std;
 
#define rep(i,m,n) for(int i=m;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    int n=s.size();
    int cnt=0,res=0;
    rep(i,0,n){
        if(s[i]=='S')cnt++;
        else if(cnt > 0)cnt--,res++;
    }
    cout<<n-res*2<<endl;
}

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

#define ll long long 

void max_self(ll& a, ll b) {
    a = max(a, b);
}

int main() {
    string s1, s2;
    cin>>s1>>s2;
    int n1 = s1.length(), n2 = s2.length();
    int dp[n1+1][n2+1];
    for(int i = 0; i<=n1; i++){
		for(int j = 0; j<=n2; j++){
			if(i==0 || j== 0)
				dp[i][j] = 0;
			else{
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
				if(s1[i-1] == s2[j-1])
					dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1);
				}
			}
		}
	stack<char> ch;
	int i = n1, j = n2;
	while(i>0 && j>0){
		if(s1[i-1] == s2[j-1] && dp[i][j] == dp[i-1][j-1] + 1)
		{
			 ch.push(s1[i-1]);
			 i--;
			 j--;
			}
		else if(dp[i-1][j] == dp[i][j])
		{
			//ch.push(s1[i-1]);
			i--;
			}
		
		else{
			//ch.push(s2[j-1]);
			j--;
			}
		}
			
		while(!ch.empty()){
			cout<<ch.top();
			ch.pop();
			
			}
        
    }


Measured memory_bytes: 35456
#pragma GCC optimize ("-O3")
    #include <bits/stdc++.h>  
     
    using namespace std;
     
    typedef long long ll;
    typedef long double ld;
    typedef pair<int,int> p32;
    typedef pair<ll,ll> p64;
    typedef pair<double,double> pdd;
    typedef vector<ll> v64;
    typedef vector<int> v32;
    typedef vector<vector<int> > vv32;
    typedef vector<vector<ll> > vv64;
    typedef vector<vector<p64> > vvp64;
    typedef vector<p64> vp64;
    typedef vector<p32> vp32;
    ll MOD = 998244353;
    #define forn(i,e) for(ll i = 0; i < e; i++)
    #define forsn(i,s,e) for(int i = s; i < e; i++)
    #define rforn(i,s) for(ll i = s; i >= 0; i--)
    #define rforsn(i,s,e) for(ll i = s; i >= e; i--)
    #define ln "\n"
    #define dbg(x) cout<<#x<<" = "<<x<<ln
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define INF 1e18
    #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
    #define all(x) (x).begin(), (x).end()
    #define sz(x) ((ll)(x).size())
     
    ll mpow(ll a, ll b){
        if(b >= (MOD-1)) b %= (MOD-1);
        if(b==0) return 1;
        ll t1 = mpow(a,b/2);
        t1 *= t1;
        t1 %= MOD;
        if(b%2) t1 *= a;
        t1 %= MOD;
        return t1;
    }
     
    ll mpow(ll a, ll b, ll p){
        if(b==0) return 1;
        ll t1 = mpow(a,b/2,p);   t1 *= t1;
        t1 %= p;
        if(b%2) t1 *= a;
        t1 %= p;
        return t1;
    }
    ll modinverse(ll a, ll m){
        ll m0 = m; 
        ll y = 0, x = 1; 
        if (m == 1) return 0; 
        while (a > 1){
            ll q = a / m; 
            ll t = m; 
            m = a % m, a = t; 
            t = y; 
            y = x - q * y; 
            x = t; 
        }
        if (x < 0) x += m0; 
        return x; 
    }
    ll range(ll l, ll r){
        return l + rand()%(r-l+1);
    }

    int main()
    {
        int n,m;
        cin>>n>>m;
        vector<int>h(n);
        for(int i=0;i<n;i++)cin>>h[i];
        vector<vector<int>>al(n);
        for(int i=0;i<m;i++)
        {
            int a,b;
            cin>>a>>b;
            a--;b--;
            al[a].push_back(b);
            al[b].push_back(a);
        }
        int ans = 0;
        for(int i=0;i<n;i++)
        {
            bool fg = true;
            for(auto it : al[i])
            {
                if(h[it]>=h[i])fg=false;
            }
            if(fg)ans++;
        }
        cout<<ans<<endl;
        return 0;
    }

Measured memory_bytes: 8740
from math import sqrt

N = int(input())
M = N
p=2
ans=0

while p <= sqrt(M):
  z = p
  while N % z == 0:
    N //= z
    z *= p
    ans += 1
  while N % p == 0:
    N //= p
  p+=1
if N > 1:
  ans+=1
print(ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    string s;
    cin >> s;
    ll n = s.size();
    vector<vector<ll>> dp(n + 1, vector<ll>(13));
    dp[0][0] = 1;
    loop(i, n)
    {
        if (s[i] == '?')
        {
            loop(j, 10)
            {
                loop(k, 13)
                {
                    dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
                    dp[i + 1][(k * 10 + j) % 13] %= mod;
                }
            }
        }
        else
        {
            ll x = ctoi(s[i]);
            loop(k, 13)
            {
                dp[i + 1][(k * 10 + x) % 13] += dp[i][k];
                dp[i + 1][(k * 10 + x) % 13] %= mod;
            }
        }
    }
    putout(dp[n][5]);
    return 0;
}


Measured memory_bytes: 16740
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);

lli n, ar[N], ans, tot;

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> n;
	n = 3 * n;
	for(int i = 1; i <= n; i++)
		cin >> ar[i];
	sort(ar + 1, ar + n + 1);

	for(int i = n; i >= 1; i--) {
		if(i % 2 != n % 2) {
			ans += ar[i];
			tot++;
		}
		if(tot == n / 3)
			break;
	}
	cout << ans;
}

Measured memory_bytes: 4352
//INCLUDE
//------------------------------------------
#include <stdio.h>
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <cstring>
#include <vector>
//DEFINE
//------------------------------------------
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------

int main(void){
    ll x;
    for(int i=1;cin>>x;i++){
        if(x==0)break;
        printf("Case %d: %lld\n",i,x);
    }
  return 0;
}



Measured memory_bytes: 3116
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <math.h>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <ctime>
#include <iomanip>
#include <fstream>
using namespace std;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define IN(x,c) (find(c.begin(),c.end(),x) != (c).end())
#define REP(i,n) for (int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define INIT(a,v) memset(a,v,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
template<class A, class B> A cvt(B x) { stringstream ss; ss<<x; A y; ss>>y; return y; }

#define SPC << " " <<
#define DEBUG(x) cerr << #x << " = "; cerr << x << endl;
#define DEBUG_ITER(x) cerr << #x << " = "; for (auto _ : x) cerr << _ << ' '; cerr << endl;

typedef pair<int,int> PII;
typedef long long int64;
typedef vector<int> VI;

int main() {
	int n,x,k=0;
	cin >> n;
	FOR (i,1,n) {
		cin >> x;
		if (i%2==1 && x%2==1) k++;
	}
	cout << k << endl;
	return 0;
}


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

int main() {
  int n; cin >> n;
  vector<int> diameter(n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int d; cin >> d;
    int check = 0;
    for (int j = 0; j < n; j++) {
      if (d == diameter.at(j)) break;
      else check++;
    }
    if (check == n) {
      diameter.at(i) = d;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=int64_t;
using vll=vector<ll>;
using vi=vector<int>;
int main(){
  int a,b,c=0,i;
  cin>>a>>b;
  for(i=0;i<2;i++){
    if(a>=b){c+=a;a--;}
    else{c+=b;b--;}
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
n = input()
if n[-1] == "2" or n[-1] == "4" or n[-1] == "5" or n[-1] =="7" or n[-1] == "9":
    print("hon")
elif n[-1] == "0" or n[-1] == "1" or n[-1] == "6" or n[-1] == "8":
    print("pon")
else:
    print("bon")


Measured memory_bytes: 9036
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pie 3.142857143
#define ll long long int
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define vi vector<int>
#define vlli vector<ll>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fv(i,a) for(auto i:a)
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define frv(i,c) for(auto i = c.begin(); i != c.end(); i++)

void solve()
{
	int n, k;
	cin >> n >> k;
	int h[n];
	fr(i, 0, n)
	cin >> h[i];
	vi d(n, 1e9 + 7);
	d[0] = 0;
	if (k >= n)
	{
		k = n - 1;
	}
	fr(i, 1, k + 1)
	{
		fr(j, 0, i)
		{
			d[i] = min(d[i], d[j] + abs(h[j] - h[i]));
		}
	}
	if (k < n)
	{
		fr(i, k + 1, n)
		{
			fr(j, i - k, i)
			{
				d[i] = min(d[i], d[j] + abs(h[j] - h[i]));
			}
		}
	}

	cout << d[n - 1] << endl;
}


int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	//cin>>t;
	t = 1;
	while (t--)
	{
		solve();
	}


	return 0;
}

Measured memory_bytes: 3984
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
N = len(S)
for l in range(N):
	for r in range(l, N):
		if S[:l] + S[r:] == "keyence":
			print("YES")
			exit()
print("NO")


Measured memory_bytes: 5456
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;

    cout << (m1 == m2 ? 0 : 1) << "\n";
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const long double INF = 1e19;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;

ll n, k;
vector<pair<long double, long double>> v;
vector<long double> x, y;

long double cnt(int x1, int x2, int y1, int y2)
{
    int r = 0;
    REPALL(i,v) {
        if (x[x1] <= v[i].e1 && v[i].e1 <= x[x2] && y[y1] <= v[i].e2 && v[i].e2 <= y[y2]) {
            r++;
        }
    }

    return r >= k ? (x[x2] - x[x1]) * (y[y2] - y[y1]) : INF;
}

int main()
{
    cin>>n>>k;
    x.resize(n); y.resize(n);
    REP(i,n) {
        cin>>x[i]>>y[i];
        v.push_back(make_pair(x[i], y[i]));
    }
    SORT(x); SORT(y);

    long double ans = INF;
    REP(x1,n) {
        FOR(x2,x1+1,n) {
            REP(y1,n) {
                FOR(y2,y1+1,n) {
                    MIN(ans, cnt(x1,x2,y1,y2));
                }
            }
        }
    }

    cout<<fixed << setprecision(0)<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string.h>
using namespace std;
typedef long long int llint;
int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	int ans = 0;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		ans += a[i];
	}
	sort(a.begin(), a.end());
	cout << ans - a[n - 1] / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())


N = int(input())
a = LI()

if len(set(a)) == 1:
    print(0)
    exit()
ans = mod
for i in range(min(a),max(a)):
    tmp = 0
    for j in range(len(a)):
        tmp += (a[j]-i)**2
    ans = min(ans,tmp)
print(ans)


Measured memory_bytes: 5460
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int h,a,b;
  cin>>h>>a>>b;
  int cnt=0;
  for(int i=a;i<=b;i++)
    cnt+=(h%i==0);
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 3096
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;


static class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int count = 0;
        for (int i = 1; i < n - 1; i++)
        {
            if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || p[i - 1] > p[i] && p[i] > p[i + 1])
                count++;
        }
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int lN[] = new int[N];
		int rN[] = new int[N];
		for(int i = 0;i < N;i++) {
			lN[i] = sc.nextInt();
			rN[i] = sc.nextInt();
		}
		int sum = 0;
		for(int i = 0;i < N;i++) {
			sum += rN[i] - lN[i]+1;
		}
		System.out.println(sum);
	}

}

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

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

  int a[100];
  for(int i=0;i<n;i++) cin>>a[i];


  for(int i=0;i < n-1-i;i++) swap(a[i],a[n-1-i]);
  for(int i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<a[i];
  }
  cout<<endl;

  return 0;
}



Measured memory_bytes: 3080
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;
struct query {
	int a, b, c, d;
};

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> M >> Q;
	vector< query > Qs(Q);
	rep(i, Q) {
		cin >> Qs[i].a >> Qs[i].b >> Qs[i].c >> Qs[i].d;
		--Qs[i].a;
		--Qs[i].b;
	}
	int ans = 0;
	vector< int > A;
	auto dfs = [&](auto &&dfs) -> void {
		//cout << A.size() << endl;
		if (A.size() == N) {
			int tmp = 0;
			for (auto q : Qs) {
				if (A[q.b] - A[q.a] == q.c)
					tmp += q.d;
			}
			chmax(ans, tmp);
		} else {
			int m = (A.size() > 0 ? A.back() : 0);
			for (int x = m; x < M; x++) {
				A.push_back(x);
				dfs(dfs);
				A.pop_back();
			}
		}
	};
	dfs(dfs);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3604
// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set                            \
    tree<ll, null_type, less<ll>, rb_tree_tag, \
         tree_order_statistics_node_update>

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

    string str;
    cin >> str;

    ll n = sz(str);

    ll count = 0;
    ll curr = 0;
    for (int i = 1; i < n; i++) {
        if (str[i] != str[0]) {
            curr++;
        } else {
            count += curr - 1;
            curr = 0;
        }
    }

    if (curr != 0) {
        count += curr - 1;
        curr = 0;
    }

    if (count & 1) {
        cout << "First\n";
    } else {
        cout << "Second\n";
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

string s;
int N,K;

int memo[310][310][310];
int calc(int l,int r,int k){
	if(memo[l][r][k]!=-1) return memo[l][r][k];

	int& v = memo[l][r][k];
	v = 0;

	if(l>0) chmax(v,calc(l-1,r,k));
	if(r>0) chmax(v,calc(l,r-1,k));
	if(k>0) chmax(v,calc(l,r,k-1));
	if(l>0 && r>0){
		if(s[l-1] == s[N-r]){
			chmax(v,calc(l-1,r-1,k)+1);
		}
		if(k>0){
			chmax(v,calc(l-1,r-1,k-1)+1);
		}
	}
	return v;
}

int main(){
	cin>>s>>K;
	N = s.size();
	rep(i,310) rep(j,310) rep(k,310) memo[i][j][k] = -1;
	int ans = 0;
	rep(l,N+1){
		int r = N-l;
		int tmp = calc(l,r,K);
		chmax(ans,tmp*2);
	}
	rep(l,N){
		int r = N-l-1;
		int tmp = calc(l,r,K);
		chmax(ans,tmp*2+1);
	}
	cout<<ans<<endl;
}


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

void writeEdge(int x, int y)
{
  cout << x << ' ' << y << '\n';
}

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

  int n;
  cin >> n;
  if (n == 1) cout << "No\n";
  else
  {
    int x = 0;
    if (n % 2) x = -1;
    else
      for (int i = 1; i < n; i++)
        if ((n ^ i) < n)
          x = i;

    if (!x) cout << "No\n";
    else
    {
      cout << "Yes\n";
      for (int i = 2; i < n; i += 2)
      {
        writeEdge(i, i + 1);
        writeEdge(i + 1, 1);
        writeEdge(1, i + n);
        writeEdge(i + n, i + n + 1);
      }
      writeEdge(n + 1, 2);
      if (x > 0)
      {
        if (x % 2) writeEdge(n, x);
        else writeEdge(n, x + n);
        int y = n ^ x ^ 1;
        if (y % 2) writeEdge(n + n, y);
        else writeEdge(n + n, y + n);
      }
    }
  }
}


Measured memory_bytes: 2304
N = gets.to_i
A = gets.split.map(&:to_i)
H = Hash.new(0)
A.each_with_index do |a,j|
  H[j + 1 - a] += 1
end
ans = 0
A.each_with_index do |a, i|
  ans += H[a + (i + 1)]
  H[i + 1 - a] -= 1
end
puts ans

Measured memory_bytes: 36940
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;

int mem[100];

int main()
{
	char c;
	for(int i = 0; i < 4; i++)
	{
		cin >> c;
		mem[c-'A']++;
	}

	int cnt = 0;
	for(int i = 0; i < 100; i++)
	{
		if(mem[i] == 2) cnt++;
	}
	if(cnt == 2) printf("Yes\n");
	else printf("No\n");
} 

Measured memory_bytes: 256