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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;
#define fastio ios_base::sync_with_stdio(false); \
		cin.tie(0);							     \
		cout.tie(0);
#define sz(arr) (int)arr.size()

using namespace std;
using ll = long long;
const ll MOD = 998244353;
const ll INF = 1e9 + 9;
const double PI = 4.0 * atan(1.0);

ll powmod(ll a, ll b,const ll MOD) { ll res = 1; a %= MOD; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a % MOD; a = a * a % MOD; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p);}




int main() {

		//  ======= FAST I/O =========
	fastio;
	//  ==========================
	int a[4][4];
	for (int i = 1; i <= 3; ++i) {
		for (int j = 1; j <= 3; ++j)
			cin >> a[i][j];
	}
	int n;
	cin >> n;
	while (n--) {
		int x;
		cin >> x;
		for (int i = 1; i <= 3; ++i) {
			for (int j = 1; j <= 3; ++j) {
				if (x == a[i][j]) {
					a[i][j] = -1; // marked
					break;
				}
			}
		}
	}
	int r1 = a[1][1] + a[1][2] + a[1][3];
	int r2 = a[2][1] + a[2][2] + a[2][3];
	int r3 = a[3][1] + a[3][2] + a[3][3];
	int c1 = a[1][1] + a[2][1] + a[3][1];
	int c2 = a[1][2] + a[2][2] + a[3][2];
	int c3 = a[1][3] + a[2][3] + a[3][3];
	int d1 = a[1][1] + a[2][2] + a[3][3];
	int d2 = a[1][3] + a[2][2] + a[3][1];
	if (r1 == -3 || r2 == -3 || r3 == -3
		|| c1 == -3 || c2 == -3 || c3 == -3 || d1 == -3 || d2 == -3) {
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
using namespace std;
signed main(){
	int a,b,c,ans;
	cin >> a >> b >> c;
	if(a%2 == 0 || b%2 == 0 || c % 2 == 0){
		ans = 0;
	}
	else{
		int x = max({a,b,c});
		if(x == a){
			ans = b*c;
		}else if(x==b){
			ans = a*c;
		}else{
			ans = a*b;
		}
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main () {
  int n,m;
  cin >> n >> m;
  vector<string> a(n), b(m);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < m; i++) {
    cin >> b.at(i);
  }
  bool ans = false;
  for (int i = 0; i < n - m + 1; i++) {
    for(int j = 0; j < n - m + 1; j++) {
      for(int k = 0; k < m; k++) {
        bool next = false;
        for(int l = 0; l < m; l++) {
          if (a.at(i + k).at(j + l) != b.at(k).at(l)) {
            next = true;
            break;
          } else if (k == m - 1 && l == m - 1) {
            ans = true;
          }
        }
        if (next) {
          break;
        }
      }
    }
  }
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using i64 = int_fast64_t;
constexpr i64 MAX = 510000;
constexpr i64 MOD = 998244353;
i64 fac[MAX], finv[MAX], inv[MAX];
template <i64 modulus>
class modcal
{

public:
  i64 a;

  constexpr modcal(const i64 x = 0) noexcept : a(x % modulus) {}
  constexpr i64 &value() noexcept { return a; }
  constexpr const i64 &value() const noexcept { return a; }
  constexpr modcal operator+(const modcal rhs) const noexcept
  {
    return modcal(*this) += rhs;
  }
  constexpr modcal operator-(const modcal rhs) const noexcept
  {
    return modcal(*this) -= rhs;
  }
  constexpr modcal operator*(const modcal rhs) const noexcept
  {
    return modcal(*this) *= rhs;
  }
  constexpr modcal operator/(const modcal rhs) noexcept
  {
    return modcal(*this) /= rhs;
  }
  constexpr modcal &operator+=(const modcal rhs) noexcept
  {
    a += rhs.a;
    if (a >= modulus)
    {
      a -= modulus;
    }
    return *this;
  }
  constexpr modcal &operator-=(const modcal rhs) noexcept
  {
    if (a < rhs.a)
    {
      a += modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modcal &operator*=(const modcal rhs) noexcept
  {
    a = a * rhs.a % modulus;
    return *this;
  }
  constexpr modcal &operator/=(modcal rhs) noexcept
  {
    i64 exp = modulus - 2;
    while (exp)
    {
      if (exp % 2)
      {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }

  void COMninit()
  {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
      fac[i] = fac[i - 1] * i % modulus;
      inv[i] = MOD - inv[modulus % i] * (modulus / i) % modulus;
      finv[i] = finv[i - 1] * inv[i] % modulus;
    }
  }
  i64 COMn(i64 n, i64 k)
  {
    if (n < k)
      return 0;
    if (n < 0 || k < 0)
      return 0;
    return fac[n] * (finv[k] * finv[n - k] % modulus) % modulus;
  }
  constexpr modcal<998244353> modpow(const modcal<998244353> &a, i64 n)
  {
    if (n == 0)
      return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1)
      t = t * a;
    return t;
  }
};
using modc = modcal<998244353>;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 n;
cin >> n;
map<i64,i64> mp;
set<i64> st;

for(i64 i = 0; i < n; i++){
    i64 k;
    cin >> k;
    if(i == 0 && k != 0 || i != 0 && k == 0){
        cout << 0 << endl;
        return 0;
    }
    else{
        mp[k]++;
        st.insert(k);
    }
}
modc ans = 0;
ans.a = 1;
modc tmp = 0;
tmp.a = mp[1];
ll div = 1;
for(auto v : st) {
    if (v > 1){
        if(v - div != 1){
            cout << 0 << endl;
            return 0;
        }
        ans *= tmp.modpow(tmp, mp[v]);
        tmp.a = mp[v];
        div = v;
        
}
}
cout << ans.a << endl;
}

Measured memory_bytes: 11264
#include<stdio.h>
double min(double a, double b)
{
	if (a < b)return a;
	else return b;
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	double t[102], v[102];
	for (i = 0; i < n; i++)
		scanf("%lf", &t[i]);
	for (i = 0; i < n; i++)
		scanf("%lf", &v[i]);
	double vm[102];
	vm[n] = 0;
	for (i = n - 1; i > 0; i--)
		vm[i] = min(min(v[i], v[i - 1]), vm[i + 1] + t[i]);
	double vn = 0;
	double ans = 0;
	double dt;
	for (i = 0; i < n; i++)
	{
		if (vn + t[i] <= vm[i + 1])
		{
			ans += vn * t[i] + t[i] * t[i] / 2.0;
			vn += t[i];
		}
		else if (vm[i + 1] == v[i])
		{
			dt = v[i] - vn;
			ans += vn * dt + dt * dt / 2.0;
			vn = v[i];
			ans += vn * (t[i] - dt);
		}
		else if (vn - t[i] == vm[i + 1])
		{
			ans += vn * t[i] - t[i] * t[i] / 2.0;
			vn -= t[i];
		}
		else if (vn <= vm[i + 1])
		{
			dt = vm[i + 1] - vn;
			dt += (t[i] - dt) / 2;
			if (vn + dt <= v[i])
			{
				ans += vn * dt + dt * dt / 2.0;
				vn += dt;
				dt = t[i] - dt;
				ans += vn * dt - dt * dt / 2.0;
				vn -= dt;
			}
			else
			{
				dt = v[i] - vn;
				ans += vn * dt + dt * dt / 2.0;
				vn += dt;
				dt = t[i] - dt - v[i] + vm[i + 1];
				ans += dt * vn;
				dt = vn - vm[i + 1];
				ans += vn * dt - dt * dt / 2.0;
				vn -= dt;
			}
		}
		else
		{
			dt = t[i] - vn + vm[i + 1];
			dt /= 2.0;
			if (vn + dt <= v[i])
			{
				ans += vn * dt + dt * dt / 2.0;
				vn += dt;
				dt = t[i] - dt;
				ans += vn * dt - dt * dt / 2.0;
				vn -= dt;
			}
			else
			{
				dt = v[i] - vn;
				ans += vn * dt + dt * dt / 2.0;
				vn += dt;
				dt = t[i] - dt - v[i] + vm[i + 1];
				ans += dt * vn;
				dt = vn - vm[i + 1];
				ans += vn * dt - dt * dt / 2.0;
				vn -= dt;
			}
		}
	}
	printf("%.20lf\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int max_B = min(A, B);
    int min_B = max(A + B - N, 0);
    cout << max_B << " " << min_B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111


	int dp[100][4][4][4];
	int mo  = 1000000007;
	void solve(){

		
		ini(n);
		dp[0][3][3][3] = 1;
		FOR(i,0,n){
			FOR(i1,0,4)
				FOR(i2,0,4)
					FOR(i3,0,4)
						FOR(i4,0,4){
							if(i2 == 0 and i3 == 1 and i4 == 2)continue;
							if(i2 == 0 and i3 == 2 and i4 == 1)continue;
							if(i2 == 1 and i3 == 0 and i4 == 2)continue;
							if(i1 == 0 and i3 == 1 and i4 == 2)continue;
							if(i1 == 0 and i2 == 1 and i4 == 2)continue;
							dp[i+1][i2][i3][i4] +=dp[i][i1][i2][i3];
							dp[i+1][i2][i3][i4] %=mo;
						}
		}
		int rick = 0;
		FOR(i,0,4)FOR(i1,0,4)FOR(i2,0,4)rick+=dp[n][i][i1][i2];
		out(rick%mo);
		
		









	}	























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n)for(int i=0; i<n; i++)
using namespace std;

int main(){
    int a, b, k;
    vector<int> divisor;
    cin >> a >> b >> k;
    int j=0;
    for(int i=1; i<=a || i<=b; i++){
        if(a%i==0 && b%i==0){
            divisor.push_back(i);
            j++;
        }
    }

    reverse(divisor.begin(), divisor.end());
    cout << divisor[k-1] << endl;

    return 0;
}


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

int main() {
  int n;
  while(cin >> n && n) {
    int a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    int ans=1;
    for(int k=1; k<=500; k++) {
      vector<int> v;
      bool f=1;
      for(int i=0; i<n; i++) {
        if(a[i]%k==0) {
          for(int j=0; j<10; j++) {
            if(a[i]/k==(1<<j)) {
              v.push_back(1<<j);
              if(!j) f=0;
              break;
            }
          }
        }
      }
      if(f) continue;
      int s=0;
      for(int i=0; i<v.size(); i++) s+=v[i];
      int dp[s+1];
      fill(dp,dp+s+1,-(1<<29));
      dp[0]=0;
      for(int i=0; i<v.size(); i++) {
        for(int j=s/v[i]*v[i]; j-v[i]>=0; j-=v[i]) dp[j]=max(dp[j],dp[j-v[i]]+1);
      }
      for(int i=0; (1<<i)<=s; i++) ans=max(ans,dp[1<<i]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3564
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0
for i in range(0,A+1):
    for j in range(0,B+1):
        for k in range(0,C+1):
            if 500*i + 100*j + 50*k == X:
                count += 1

print(count)

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

typedef pair<int, int> P;
int n;
vector<P> G[20];

int dist[20];
int t[20];
int sum;

void dfs(int v, int p, int d) {
	dist[v] = d;
	bool all_leaf = true;
	for(auto c : G[v]) {
		int u = c.first, cost = c.second;
		if(u == p) continue;
		dfs(u, v, d + cost);
		if(G[u].size() != 1) {
			all_leaf = false;
			sum += cost * 2;
		}
	}
	if(v != 0 && G[v].size() != 1 && all_leaf) {
		t[v] = 1;
	}
}

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

	while(cin >> n, n) {
		for(int i = 0; i < n; i++) G[i].clear(), t[i] = 0;
		for(int i = 0; i < n - 1; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			a--, b--;
			G[a].push_back({ b, c });
			G[b].push_back({ a, c });
		}

		sum = 0;
		dfs(0, -1, 0);

		int max_dist = 0;
		for(int i = 1; i < n; i++) {
			if(t[i]) {
				max_dist = max(max_dist, dist[i]);
			}
		}
		cout << sum - max_dist << endl;
	}
}

Measured memory_bytes: 3020
/**
*    author:  yuya1234
*    created: 01.07.2020 09:41:50
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#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 FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define ALL(v) (s).begin(), (s).end()
#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

    ll n,k;
    cin>>n>>k;

    ll ans;
    ans=n%k;

    if(ans>abs(ans-k))ans=abs(ans-k);

    cout<<ans<<endl;    

    return 0;
}

Measured memory_bytes: 3664
# include "iostream"
# include "cstdio"
# include "algorithm"
 
using namespace std;

const int maxm=1e3+10; 

int N,A[maxm];

int main(){
	register int i,Ans=0; 
	scanf("%d",&N);
	for(i=1;i<=2*N;i++) scanf("%d",&A[i]);
	sort(A+1,A+1+2*N); 
	for(i=1;i<=2*N;i++) if(i%2==1) Ans+=A[i];
	cout<<Ans;
	return 0; 
} 

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

int n, a[105], res[105];

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];

	for (int q = 0; q < n; q++) {
		int ind = -1;
		
		for (int i = n - q; i; i--)
			if (a[i] == i) {
				ind = i;
				break;
			}

		if (ind == -1) {
			cout << -1 << endl;
			return 0;
		}
		
		res[n - q] = ind;
		for (int i = ind; i < n; i++)
			a[i] = a[i+1];
	}

	for (int i = 1; i <= n; i++)
		cout << res[i] << endl;
	
	return 0;
}

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

int main()
{
  int n, k,p, sum = 0;
  cin>>n>>k;
  vector<int>prices;
  for(int i =0 ; i<n; i++)
  {
    cin>>p;
    prices.push_back(p);
  }

  sort(prices.begin(), prices.end());

  for(int i = 0; i<k ; i++)
  {
    sum += prices[i];
  }

  cout<<sum;


  return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>

int main(int argc, char const *argv[])
{

  int A, B, cost;

  scanf("%d", &A);
  scanf("%d", &B);

  if (A>=13)
  {
    cost = B;
  }else if (A>=6&&A<=12)
  {
    cost = B/2;
  }else
  {
    cost = 0;
  }
  
  printf("%d", cost);
  

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm.*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
// #define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define debug() cout << "Hi" << endl	// write debug(); in main()
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
const int inf = 2e9;
int max(int a,int b){	if(a > b)return a; else return b; }
int min(int a, int b){	if(a < b)return a; else return b; }
/*		0. Go to main function first.
		1. Take all the inputs................................................
		2. Check Once whether the graph given is directed or undirected.......
		3. Tree can also be undirected.
		4. Whenever you do multiplication and division in the same line, beware.
*/
void solve(){
	//debug();
	int n,x,y;
	cin >> n >> x >> y;
	int ans[n+1];
	for(int ii=0; ii<=n; ++ii) ans[ii] = 0;
	
	int q,p;
	
	for(int i=1; i<n; ++i){
		for(int j=i+1; j<=n; ++j){
			q = j - i;
			p = abs(x-i) + 1 + abs(y-j);
			int d = min(q,p);
			ans[d]++;
		}
	}
	
	for(int z=1; z<n; ++z)
		cout << ans[z] << endl;
}
/*	memset() can be used to set all values as 0 or -1 for integer data types.*/

int main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(12); std::cout << std::fixed;
	int t;
	// cin >> t;
	t = 1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<double,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 100000000000007;
ll fac[MAX], finv[MAX], inv[MAX];
//ダイクストラ法は負の経路があるとき使えない→ベルマンフォード法
int main(){
  ll xs,ys,xt,yt;cin>>xs>>ys>>xt>>yt;
  ll v;cin>>v;
  vector<vector<double> > g(v+2,vector<double>(v+2,0));vll x(v+2),y(v+2),r(v+2,0);
  vector<double> dis(v+2,MOD);
  vb seen(v+2,false);
  rep(i,1,v+1){
    cin>>x[i]>>y[i]>>r[i];
  }
  x[0]=xs;x[v+1]=xt;y[0]=ys;y[v+1]=yt;
  rep(i,0,v+2){
    rep(j,i,v+2){
      if(i==j)continue;
      g[i][j]=g[j][i]=pow(pow(x[i]-x[j],2)+pow(y[i]-y[j],2),0.5)-r[i]-r[j];
      if(g[i][j]<0)g[i][j]=0;
      if(g[j][i]<0)g[j][i]=0;
    }
  }
  priority_queue<P,vector<P>,greater<P> > pq;
  dis[0]=0;
  pq.push(make_pair(dis[0],0));
  while(!pq.empty()){
    P p=pq.top();
    pq.pop();
    ll from=p.second;
    if(seen[from]){continue;}
    seen[from]=true;
    if(dis[from]<p.first)continue;
    rep(i,0,v+2){
      if(dis[i]>dis[from]+g[from][i]){
        dis[i]=dis[from]+g[from][i];
        pq.push(make_pair(dis[i],i));
      }
    }
  }
  cout<<fixed<<setprecision(12)<<dis[v+1]<<endl;
}




Measured memory_bytes: 14324
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<char> ans;
    ll x=0;
    // n--;
    while(n)
    {
    	ll x=(n%26);
    	if (!x)
    	{
    		ans.push_back('z');
    		n-=1;
    		// cout << 'z';
    	}
    	else
		{
    		ans.push_back(char(x+96));
			// cout << ;
		}
		n/=26;
		// x*=26;
		// x+=int((int)ans[ans.size()-1]-97);
		// cout << x;
    }
    for (int i = ans.size()-1; i >=0; --i)
    {
    	cout << ans[i];
    }
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
 
LL n,A,B;
LL a[N];
bool judge(LL x){
    LL temp=x*B;
    LL sub=A-B;
    LL sum=0;
    for(LL i=n;i>=1;i--){
        if(a[i]>temp){
            if((a[i]-temp)%sub)
                sum+=(a[i]-temp)/sub+1;
            else
                sum+=(a[i]-temp)/sub;
        }
    }
    if(sum<=x)
        return true;
    return false;
}
int main() {
    scanf("%lld%lld%lld",&n,&A,&B);
 
    LL right=0;
    for(LL i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        right+=a[i]/B+1;
    }
    sort(a+1,a+1+n);
 
    LL left=1;
    while(left<right){
        LL mid=(left+right)>>1;
        if(judge(mid))
            right=mid;
        else
            left=mid+1;
    }
    printf("%lld\n",left);
 
    return 0;
}


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

int main() {
    int N;
    int D;
    long long a,b;
    cin >> N >> D;

    int cnt=0;

    for (int i =0;i<N;i++){
        cin >> a >> b;
        if(sqrt(a*a+b*b)<=D){
            cnt++;
        }else if((a == 0)&&(b == 0)){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;

}

Measured memory_bytes: 3668
#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,x,t;cin>>n>>x>>t;
	cout<<(n+x-1)/x*t<<endl;
}

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

int main()
{
	int n, a, b, p1 = 0, p2 = 0, p3 = 0;

	cin >> n >> a >> b;

	for (int i = 0; i < n; i++) {
		int p;

		cin >> p;

		if (p <= a)
			p1++;
		else if (p <= b)
			p2++;
		else
			p3++;
	}

	cout << min({p1, p2, p3}) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll md = 1000000007;

int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k, cnt = 0;
    cin >> n >> k;
    for(ll i = k; i <= n+1; i++) {
        cnt += ((n-i+1+md)%md * i %md) %md + 1;
        cnt %= md;
    }
    cout << cnt << "\n";
    return 0; 
}

Measured memory_bytes: 3632
def main():
    S=lambda:input()
    I=lambda:int(input())
    L=lambda:list(map(int,input().split()))
    LS=lambda:list(map(str,input().split()))
    
    n,m=L()
    penanum=[0]*n
    acflag=[False]*n
    acsum=0
    penasum=0
    for i in range(m):
        tmp=LS()
        if tmp[1]=='WA':
            penanum[int(tmp[0])-1]+=1
        elif acflag[int(tmp[0])-1]==False:
            penasum+=penanum[int(tmp[0])-1]
            acsum+=1
            acflag[int(tmp[0])-1]=True
            
    print(acsum,penasum)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 4724
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
using namespace std;
char s[1010];
int main(){
    scanf("%s", s);
    int n = strlen(s);
    int flag = 1;
    for(int i = 0; i < (n - i - 1); i ++){
        if(s[i] != s[n - i - 1]){
            flag = 0;
            break;
        }
    }
    int temp = n;
    if(flag){
        n = (n - 1) / 2;
        for(int i = 0; i < (n - i - 1); i ++){
            if(s[i] != s[n - i - 1]){
                flag = 0;
                break;
            }
        }
    }
    if(flag){
        n = temp;
        int start = (n + 3) / 2 - 1;
        for(int i = start; i < (n - (i - start) - 1); i ++){
            if(s[i] != s[n - (i - start) - 1]){
                flag = 0;
                break;
            }
        }
    }
    if(flag){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#define ll long long

using namespace std;

const int NMAX = 100005;
ll h[NMAX], nxt[NMAX], sum[NMAX];
ll poz, n, k;

void fct(int m) {
    int ok = 0;
    for(int i = 1; i <= k && i + m <= n; i++) {
        if((abs(h[m + i] - h[m]) + sum[m + i] <= abs(h[nxt[m]] - h[m]) + sum[nxt[m]]) || !ok) {
            ok = 1;
            nxt[m] = m + i;
            sum[m] = sum[m + i] + abs(h[m + i] - h[m]);
        }
    }
}

int main()
{
    int i;
    cin >> n >> k;
    for(i = 1; i <= n; i++) {
        cin >> h[i];
    }
    sum[n] = 0; nxt[n] = 0;
    for(i = n - 1; i >= 1; i--) {
        fct(i);
    }
    cout << sum[1];
    return 0;
}


Measured memory_bytes: 5876
/**
*   @author: Kshitiz Srivastava (Pirate_ksh) @ MNNIT Allahabad
*/
#include<bits/stdc++.h>
using namespace std;
 
// General
#define ll long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define mod_ 998244353 
#define endl "\n"
#define debug(x) cout<<x<<endl
#define REP(i,n) for(i=0;i<n;++i)
#define FOR(i,x,n) for(i=x;i<n;++i)
 
// Bounds
#define lb(a, x) a.lower_bound(x)
#define ub(a, x) a.upper_bound(x)
#define all(a) a.begin(),a.end()
 
// Vector
#define vi vector <int>
#define pb(v, x) v.push_back(x)
#define vsi vector <set <int> >
 
// Map
#define mii map <int, int>
 
// Set
#define si set <int>
 
// Pair
#define vpii vector<pair < int, int > >
#define pii pair < int, int >
#define F first
#define S second

ll t, i, j, k, N, M;
vi graph[100005];

void addDirectedEdge() {
    ll a,b;
    cin >> a >> b;
    pb(graph[a], b);
}

bool visited[100005] = {false};
/* Depth First Search */
int dp[100005];
int dfs(int n) {
    visited[n] = true;
    if(dp[n]==-1) {
        int max_length = 0;
        for(int i: graph[n]) max_length = max(max_length, 1+dfs(i));
        dp[n] = max_length;
    }
    return dp[n];
}

int main(){
    io;
    t=1;
    // cin >> t;
    while(t--) { 
        cin >> N >> M;
        REP(i,M) addDirectedEdge();
        memset(dp, -1, sizeof(dp));
        FOR(i,1,N+1) if(!visited[i]) dfs(i);
        cout << *max_element(dp+1,dp+1+N) << endl;
    }
    return 0;
}


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

long long GCD(long long a, long long b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

int main() {
    long long N, M;
    cin >> N >> M;
    string s1, s2;
    cin >> s1 >> s2;
    long long g = GCD(N, M);
    long long res = N / g * M;
    N /= g, M /= g;
    bool judge = true;
    for (long long i = 0; i < g; ++i) {
        if (s1[i * N] != s2[i * M])
            judge = false;
    }

    if (judge)
        cout << res << endl;
    else
        cout << -1 << endl;
}

Measured memory_bytes: 512
N = int(input())
t0, x0, y0 = [0, 0, 0]
for _ in range(N):
  t, x, y = map(int, input().split())
  d = (t - t0) - (abs(x - x0) + abs(y - y0))
  if d < 0 or d % 2 == 1:
    print('No')
    exit()
  else:
    t0 = t
    x0 = x
    y0 = y
print('Yes')

Measured memory_bytes: 3064
N = int(input())
X = input()
popcount_X = X.count('1')
numX = int(X, 2)
a, b = numX % (popcount_X + 1), numX % (popcount_X - 1) if popcount_X != 1 else 0
for i, x in enumerate(X, 1):
    if x == '1' and popcount_X == 1:
        print(0); continue
    ans = 1
    if x == '1':
        temp = (b - pow(2, N - i, popcount_X - 1)) % (popcount_X - 1)
    else:
        temp = (a + pow(2, N - i, popcount_X + 1)) % (popcount_X + 1)
    while temp:
        p = format(temp, 'b').count('1')
        temp %= p
        ans += 1
    print(ans)

Measured memory_bytes: 9544
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n, a, b = map(int, readline().split())
ans = n + 1
if (b - a) % 2 == 0:
    ans = min(ans, (b - a) // 2)
ans = min(b -1, ans)
ans = min(n - a, ans)
ans = min((n-b) + 1 + (n - (a+(n-b) +1))// 2, ans)
ans = min((a-1) + 1 + ((b - 1 - (a-1)) - 1) // 2, ans)



print(ans)


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

long long N, M;

int main(){
	cin >> N >> M;
	long long rest = M;

	long long small = 1;
	long long large = M;
	while(rest > 0 && small < large) {
		cout << small << " " << large << endl;
		small++;
		large--;
		rest--;
	}
	small = M+1;
	large = 2*M+1;
	while(rest > 0 && small < large) {
		cout << small << " " << large << endl;
		small++;
		large--;
		rest--;
	}
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

#define YES(condition) if(condition) cout << "YES" << endl; else cout << "NO" << endl
#define Yes(condition) if(condition) cout << "Yes" << endl; else cout << "No" << endl
#define POSS(condition) if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl
#define Poss(condition) if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl
#define First(condition) if(condition)cout << "First" << endl; else cout << "Second" << endl
#define negative(condition, num) if(condition)cout << -1 << endl; else cout << num << endl
long power(long base, long exponent, long mod){ if(exponent % 2){ return power(base, exponent - 1, mod) * base % mod; }else if(exponent){ long root_ans = power(base, exponent / 2, mod); return root_ans * root_ans % mod; }else{ return 1; }}

int main(){
    int N;
    cin >> N;
    long grundy_xor = 0;
    set<long, greater<long>> nums_standing_lsb;
    for(int i = 0; i < N; i++){
        long num;
        cin >> num;
        grundy_xor ^= num;
        nums_standing_lsb.insert(num & -num);
    }
    int ans = 0;
    while(!nums_standing_lsb.empty()){
        if(grundy_xor & *(nums_standing_lsb.begin())){
            grundy_xor ^= *(nums_standing_lsb.begin()) * 2 - 1;
            ans++;
        }
        nums_standing_lsb.erase(nums_standing_lsb.begin());
    }
    negative(grundy_xor, ans);
}


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

int dp[1010][10010];

int main(){
    int H,N;
    cin>>H>>N;
    int A[N],B[N];
    rep(i,N) cin>>A[i]>>B[i];

    vector<vector<ll>> dp(N+1,vector<ll>(H+1,INF));
    dp[0][0]=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<=H;j++){
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
            dp[i+1][min(j+A[i],H)]=min(dp[i+1][min(j+A[i],H)],dp[i+1][j]+B[i]);
        }
    }
    cout<<dp[N][H]<<endl;
}

Measured memory_bytes: 78592
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
struct dice {
    int v[6];
    void mov(const char c) {
        int buf;
        switch (c) {
            case 'N':
                buf = v[0];
                v[0] = v[1];
                v[1] = v[5];
                v[5] = v[4];
                v[4] = buf;
                break;
            case 'E': {
                buf = v[0];
                v[0] = v[3];
                v[3] = v[5];
                v[5] = v[2];
                v[2] = buf;
                break;
            }
            case 'W': {
                buf = v[0];
                v[0] = v[2];
                v[2] = v[5];
                v[5] = v[3];
                v[3] = buf;
                break;
            }
            case 'S': {
                buf = v[0];
                v[0] = v[4];
                v[4] = v[5];
                v[5] = v[1];
                v[1] = buf;
                break;
            }
            case 'R': {
                buf = v[1];
                v[1] = v[2];
                v[2] = v[4];
                v[4] = v[3];
                v[3] = buf;
            }
        }
    }
    int top() { return v[0]; }
    int right() { return v[2]; }
    int left() { return v[3]; }
    int front() { return v[1]; }
    bool compare(dice a) {
        for (int i = 0; i < 6; i++) {
            if (v[i] != a.v[i]) {
                return false;
            }
        }
        return true;
    }
};

bool same(dice a, dice b) {
    for (int i = 0; i < 6; i++) {
        if (a.v[i] != b.v[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    dice d[100];
    bool have_same = true;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 6; j++) {
            cin >> d[i].v[j];
        }
    }

    for (int k = 0; k < n - 1; k++) {
        for (int l = k + 1; l < n; l++) {
            bool tmp = false;
            for (int i = 0; i < 4; i++) {
                d[l].mov('E');
                for (int j = 0; j < 4; j++) {
                    d[l].mov('N');
                    if (same(d[k], d[l])) {
                        tmp = true;
                    }
                }
            }
            d[l].mov('R');
            for (int i = 0; i < 4; i++) {
                d[l].mov('E');
                for (int j = 0; j < 4; j++) {
                    d[l].mov('N');
                    if (same(d[k], d[l])) {
                        tmp = true;
                    }
                }
                if (tmp) {
                    have_same = false;
                }
            }
        }
    }
    cout << (have_same ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3156
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
char p[6010];
int n;
struct point {
	int a, b;
}w[3010];
int A[6010], Num[6010], cA, cB;
string D[6010];
char q[6010];
int main() {
	int i, j;
	scanf("%d", &n);
	scanf("%s", p + 1);
	for (i = 1; i <= n+n; i++) {
		if (p[i] == 'a')w[++cA].a = i;
		if (p[i] == 'b')w[++cB].b = i;
	}
	for (i = 1; i <= n; i++) {
		Num[w[i].a] = Num[w[i].b] = i;
	}
	for (i = n+n - 1; i >= 1; i--) {
		int pv = Num[i];
		D[i] = D[i + 1];
		if (p[i] == 'a') {
			if (w[pv].b < w[pv].a)continue;
			if (!D[i + 1].size() || D[i + 1][0] == 'a') {
				D[i] = max(D[i], "ab" + D[w[pv].b + 1]);
			}
			continue;
		}
		else {
			if (w[pv].a < w[pv].b)continue;
			int c = 0;
			for (j = pv+1; j <= n; j++) {
				if (min(w[j].a,w[j].b) > max(w[j-1].a,w[j-1].b))break;
			}
			int ed = j - 1, last = 0;
			for (j = i; j <= n + n; j++) {
				if (Num[j] >= pv && Num[j] <= ed) q[c++] = p[j], last = j;
			}
			q[c] = 0;
			D[i] = max(D[i], q + D[last + 1]);
		}
	}
	printf("%s\n", D[1].c_str());
}

Measured memory_bytes: 12544
#include <atcoder/dsu>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll solve() {
    ll N, Q;
    cin >> N >> Q;
    int t , u , v;
    atcoder::dsu d(N);
    vector<int> ans;
    for ( int i = 0; i < Q; i++ ) {
        cin >> t >> u >> v;
        if ( t == 0 ) {
            d.merge(u,v);
        } else {
            int x = d.same(u,v) ? 1 : 0;
            ans.push_back(x);
        }
    }
    for ( int i = 0; i < ans.size(); i++ ) {
        cout << ans[i] << "\n";
    }

    return 0;
}

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

Measured memory_bytes: 4392
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(int i=j;i<(n);++i)
#define bk(i,j,n)   for(int i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define MOD 1000000007
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>

typedef long long  ll;

ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}


int main()
{
    run;
    ll n;
    cin>>n;
    ll a[n];
    map<ll,ll> m;
    fr(i,0,n)
    {
        cin>>a[i];
        m[a[i]]++;
    }
    ll ans=0;
    for(auto it=m.begin();it!=m.end();it++)
    {
        ll p=it->S;
        ll aa=p*(p-1);
        aa/=2;
        ans+=aa;
    }
    fr(i,0,n)
    {
        ll o=m[a[i]];
        ll aa=o*(o-1);
        aa/=2;
        ll ao=(o-1)*(o-2);
        ao/=2;
        if(ao<0)
            ao=0;
        cout<<ans-aa+ao<<endl;

    }


}


Measured memory_bytes: 11136
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順 大きい順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから
#define MIN(vec) min_element(ALL((vec)))  // 値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする
#define zero_pad(num) setfill('0') << std::right << setw(num)  // 直後の要素をパディング
#define space_pad(num) setfill(' ') << std::right << setw(num)  // 直後の要素をパディング

// queue
class Schedules {
public:
    string name;
    int time;
};

vector<Schedules> vec(1000000);

int head = 0;
int tail = 0;
void initialize() {
    head = tail = 0;
}
void enqueue(string name, int time) {
    vec[tail].name = name;
    vec[tail].time = time;
    tail++;
}
Schedules dequeue() {
    head++;
    return vec[head - 1];
}

int main() {
    int n, quantum;
    cin >> n >> quantum;
    string name;
    int time;
    REP(i, n) {
        cin >> name >> time;
        enqueue(name, time);
    }
    /*
    REP(i, n) {
        cout << vec.at(i).name << "\n";
        cout << vec.at(i).time << "\n";
    }
    */
    Schedules sch;
    int process, total_time = 0;
    while (head != tail) {
        sch = dequeue();
        if (sch.time > quantum) {
            total_time += quantum;
            sch.time -= quantum;
            enqueue(sch.name, sch.time);
        } else{
            total_time += sch.time;
            cout << sch.name << " " << total_time << "\n";
        }
    }
    
    return 0;
}



Measured memory_bytes: 20928
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());



int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n;
		// n=s.length();
		ll a[n];
		rep(i,n)
		{
			cin>>a[i];
		}
		sort(a,a+n);
		m=(a[0]+a[n-1])/2;
		c=inf;
		repe(m,1,101)
		{
			k=0;
			rep(i,n)
				k+=((m-a[i])*(m-a[i]));
			c=min(c,k);
		}
		
		cout<<c;

		
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
typedef long long ll;

#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define MIN(x, y)	(((x) < (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define REPI(x,y)	for (int i=(x);i<(y);i++)
#define REPJ(x,y)	for (int j=(x);j<(y);j++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;
typedef vector<vector<pair<int, int> > > GRA;

int i,j,a,b;

int main() {
	cin >> a >> b;

	if ( ( a == 100 ) && ( b == 100 ) ) a = 100100;
	else if ( a == 100 && b >= 10) a = 10000 + b;
	else if ( a == 100 && b < 10 ) a = 1000 + b;
	else if ( a >= 10 && b == 100) a = 1000*a + 100;
	else if ( a >= 10 && b >= 10 ) a = 100*a +b;
	else if ( a >= 10 && b < 10 ) a = 10*a +b;
	else if ( a < 10 && b == 100 ) a = 1000*a +100;
	else if ( a < 10 && b >= 10 ) a = 100*a +b;
	else if ( a < 10 && b < 10 ) a = 10*a +b;

	for (i = 1; i <= a; i++)
	if ( i * i == a ) {
		cout << "Yes" << endl;
		return 0;
	}
	
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 764
s=input()
if "N" in s and "S" in s and "E" in s and "W" in s:
    print("Yes")
elif "N" in s and "S" in s and "E" not in s and "W" not in s:
    print("Yes")
elif "N" not in s and "S" not in s and "E" in s and "W" in s:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
const int N = 2e2+ 10, mod = 1e9 + 7;

void solve() {
	ll x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	ll y = x/d;
	x -= min (y, k) * d;
	k -= min (y, k);
	if (k&1) {
		x -= d;
	}
	cout << abs(x);
}

int main() {
	int tt = 1;
	// cin >> tt;
	for (int tc = 1; tc <= tt; tc++) {
		solve();
	}
}

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

int N;
vector<int> v;

void init()
{
	cin >> N;
	CINV(v, N);
}

void solve()
{
	int res = 0;
	bool f = true;
	while (f) {
		f = false;
		rep(i, N) {
			if (v[i]) {
				f = true;
				res++;
				reps(j, i, N) {
					if (v[j] == 0) break;
					v[j]--;
				}
				break;
			}
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz=1e9+7;

int main()
{
	string s;
	ll i, len, a=0, b=0;
	cin>>s;
	len=s.size();

	for(i=0;i<len; i++)
	{
		if(s[i]=='A')a++;
		else b++;
	}
	if(a==0||b==0)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}

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

int N, Q, T[300001];

int main(){
	cin >> N >> Q;
	for(int i=0 ; i < N ; i++ ){
		int c;
		cin >> c;
		T[c] = c;
	}
	for(int i=1 ; i <= 300000 ; i++ ){
		T[i] = max(T[i], T[i-1]);
	}
	for(int i=0 ; i < Q ; i++ ){
		int q;
		cin >> q;
		
		int ans = 0;
		for(int j = q ; j <= 300000 ; j += q ){
			ans = max(ans, T[j-1] % q);
		}
		ans = max(ans, T[300000] % q);
		cout << ans << endl;
	}
}

Measured memory_bytes: 2332
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

//global
const int MAX_N = 10;
int a[MAX_N];



bool dfs(int i, int b, int c) {
	if (i == MAX_N)return true;
	if (b < a[i] && dfs(i + 1, a[i], c))return true;
	if (c < a[i] && dfs(i + 1, b, a[i]))return true;
	return false;

}


//solve
void solve()
{
	int b = a[0];
	int c = 0;
	cout << (dfs(1, b, c) ? "YES" : "NO") << endl;
}



//main
int main()
{
	int tcase;
	cin >> tcase;
	while (tcase--) {
		for (int i = 0; i < 10; i++) {
			cin >> a[i];
		}
		solve();
	}
    return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
    #include<algorithm>
    using namespace std;
    #define mod 1e9+7
    #define FOR(a,c)   for ( int (a)=0; (a)<(c); (a)++)
    #define FORL(a,b,c)  for ( int (a)=(b); (a)<=(c); (a)++)
    #define FORR(a,b,c)  for (  int (a)=(b); (a)>=(c); (a)--)
    #define INF 1000000000000000003
    typedef long long int ll;
    typedef vector<long long int> vi;
    typedef pair<long long int,long long int> pi;
    typedef priority_queue<long long int> max_pq;
    typedef priority_queue<long long int, vector<long long int>, greater<long long int>> min_pq;
    #define F first
    #define S second
    #define PB push_back
    #define POB pop_back
    #define MP make_pair
    #define pi 3.1415926535
    #define buff cin.ignore(numeric_limits<streamsize>::max(),'\n')

    // Use inbuilt function  __gcd(a,b), __builtin_popcount(n), Use (x&-x) for last set Bit;
    
    int main()
    {
        ios::sync_with_stdio(NULL);
        cin.tie(NULL);
        cout.tie(NULL);

        ll n,k;
        cin>>n>>k;
        ll arr[n+1];
        for(ll i=1;i<=n;i++)
            cin>>arr[i];
        ll dp[n];
        
        dp[0]=0;
        dp[1]=0;
        for(ll i=2;i<=n;i++)
        {
            dp[i]=LLONG_MAX;
            for(ll j=i-1;j>=max(i-k,ll(1));j--)
            {
                dp[i]=min(dp[i],dp[j]+abs(arr[i]-arr[j]));
            }
        }
        // for(int i=1;i<=n;i++)
        //     cout<<dp[i]<<" ";
        cout<<dp[n]<<endl;
        return 0;
    }

Measured memory_bytes: 1792
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //StringBuilder answer=new StringBuilder();
        //input
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        for (int i = 1;i < (n+1)/2;++i)
        {
            int a = n-i;
            if (n!=a) ++count;
        }
        System.out.println(count);
        sc.close();
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define int long long
#define double long double
#define vi vector<int>
#define vpi vector<pair<int,int> >
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define msi map<string,int>
#define set set<int>
#define u_set unordered_set<int>
#define pb push_back
#define endl "\n"
#define ll long long int
#define vll vector<long long int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define umap unordered_map 
#define mod 1000000007
#define fori(a,n) for(int i=a;i<n;i++)
#define forj(a,n) for(int j=a;j<n;j++)
#define MAX 300303
using namespace std;
int n,m,u,v;
vi dp(100001,0);
vvi graph(100001);
int rec(int i){
    if(i >= n || graph[i].size()==0)return 0;
    if(dp[i] != 0)return dp[i];
    forj(0,graph[i].size())
    {
        dp[i] = max(dp[i],1+rec(graph[i][j]));
    }
    return dp[i];
}
signed main()
{
    io
    cin >> n >> m;
    fori(0,m){
        cin >> u >> v;
        graph[u-1].pb(v-1);
    }
    int mx = 0;
    fori(0,n)
    {
        mx = max(mx,rec(i));
    }
    cout << mx << endl;
}

Measured memory_bytes: 8576
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
route = [a[0]]
count = 1
flag = 0
for i in range(1, N+2):
    count += 1
    route.append(a[route[i-1]-1])
    if route[i] == 2:
        flag = 1
        break

if route[0] == 2:
    print(1)
elif flag == 0:
    print(-1)
else:
    print(len(route))


Measured memory_bytes: 7888