akhauriyash/Code-Regression huggingface dataset:
// 7/3
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

    int mx = (N-1)*(N-2)/2;  // max
    if (mx < K) {
        puts("-1");
        return 0;
    }

    // 辺（u, v）をpairで表現する。
    vector<P> ans;

    // 頂点Nを真ん中にしてスター（うに）を作る。
    rep(i, N-1) {
        ans.push_back(P(i+1, N));
    }
    int add = mx-K;  // これだけ追加したい。
    
    // 辺の候補を列挙する。
    vector<P> edge;
    rep(i, N-1) rep(j, i) edge.push_back(P(i+1, j+1));
    
    // 必要な数だけansにへんを突っ込む。
    rep(i, add) ans.push_back(edge[i]);
    cout << ans.size() << endl;
    rep(i, ans.size()) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }

    return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
    char s[12];
    scanf("%s", s);
    int min = 1000;
    int i;
    int x;
    for (i = 0; i < strlen(s) - 2; i++)
    {
        x = 100 * ((int)(s[i] - '0')) + 10 * ((int)(s[i + 1] - '0')) + (int)(s[i + 2] - '0');
        x = abs(753 - x);
        if (min > x)
            min = x;
    }
    printf("%d\n", min);
    return 0;
}

Measured memory_bytes: 128
q = gets.to_i
q.times do
  a,b = gets.split.map(&:to_i)
  r = ((a*b-1)**0.5).to_i
  r += 1 while (r+1)*(r+1) <= a*b-1
  r -= 1 while r*r > a*b-1
  ans = r * 2
  if ans > 0
    ans -= 1 if (a*b-1)/r == r
    ans -= 1 if [a,b].min <= r
  end
  p ans
end

Measured memory_bytes: 1788
import numpy as np
import scipy.sparse
n = int(input())
s = np.array([list(map(int, list(input()))) for i in range(n)])
d = scipy.sparse.csgraph.floyd_warshall(scipy.sparse.csr_matrix(s))
l = d[:, np.argmax(d) % n]
for i in range(n):
    for j in range(i + 1, n):
        if s[i, j] == 1 and abs(l[i] - l[j]) != 1:
            exit(print(-1))
print(int(np.amax(d) + 1))

Measured memory_bytes: 38948
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  map<char, int> cnt;
  rep(i, H) {
    cin >> S[i];
    rep(j, W) cnt[S[i][j]]++;
  }
  bool ok = true;
  int count[4] = {0};
  for(auto ele: cnt) count[ele.second%4]++;
  if(H%2 && W%2) {
    if(count[1]+count[3]!=1 || count[2]+count[3]>H/2+W/2) ok = false;
  } else if(H%2) {
    if(count[1]+count[3] || count[2]+count[3]>W/2) ok = false;
  } else if(W%2) {
    if(count[1]+count[3] || count[2]+count[3]>H/2) ok = false;
  } else {
    if(count[1]+count[2]+count[3]) ok = false;
  }
  cout << (ok ? "Yes" : "No") << "\n";
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl ;
typedef pair<ll,ll> pl;
 
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define rep(i,N) for(int i=0; i < (N); i++)
#define all(v) (v).begin(),(v).end()
//#define max(a,b) (a>b ? a : b)
//#define min(a,b) (a<b ? a : b)
 
const int MOD = 998244353;
const int INF = 100000002;
const double PI =4*atan(1);
const double eps = 1e-7;
const long long oo = 1e18;

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    rep(i,H)cin >> S[i];
    int ans = INF;
    rep(div, 1<<(H-1)){
        int g = 0;
        vector<int> id(H);
        rep(i,H){
          id[i] = g;
          if(div>>i & 1) ++g;
        }
        ++g;
        vector<vi> c(g, vi(W, 0));
        rep(i,H)rep(j,W) c[id[i]][j] += (S[i][j]-'0');

        vector<int> now(g);
        int cnt = g-1;
        
        auto add = [&](int j){
            rep(i,g) now[i] += c[i][j];
            rep(i,g) if(now[i]>K) return false;
            return true;
        };

        rep(j,W){
            if(!add(j)){
                cnt++;
                now = vector<int>(g);
                if(!add(j)){
                    cnt = INF;
                    break;
                }
            } 
        }
        ans = min(ans, cnt);
    } 
    cout << ans << endl;
}

Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
//#define int ll
#define pll pair<ll, ll> 
#define pdd pair<ld, ld> 
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 1000000007
using namespace std;

void dfs(vector<int> adj[], int sv, vector<bool> &vis){
	vis[sv] = true;
	for(int i = 0; i < adj[sv].size(); i++){
		if(!vis[adj[sv][i]]){
			dfs(adj, adj[sv][i], vis);
		}
	}
}
ll power(ll x, ll y){  
	if(x == 1 || y == 0)
		return 1;
    ll res = 1;   
    x = x % mod; 
    if (x == 0) 
		return 0;  
    while (y > 0){  
        if (y & 1)  
            res = (res * x) % mod;  
        y = y >> 1; 
        x = (x * x) % mod;  
    }  
    return res;  
}  
ll nCr(ll n, ll r) {
    ll x = 1, y = 1;
    rep(i, 0, r) {
        x = x * (n - i) % mod;
        y = y * (i + 1) % mod;
    }
    return x * power(y, mod - 2) % mod;
}
int n, m, q, ans;
int a[50], b[50], c[50], d[50];
int v[11];
void solve(int st, int prev){
	if(st == n){
		int temp = 0;
		rep(i, 0, q){
			if(v[b[i]] - v[a[i]] == c[i])
				temp += d[i];
		}
		ans = max(ans, temp);
		return;
	}
	rep(i, prev, m + 1){
		v[st+1] = i;
		solve(st + 1, i);
	}
	
}

signed main(){
	FASTIO
	cin >> n >> m >> q;
	rep(i, 0, q){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	
	solve(0, 1);
	cout << ans;
    return 0;
}


Measured memory_bytes: 3640
import heapq
from collections import defaultdict, deque
from math import ceil, factorial, gcd
import sys
import bisect


sys.setrecursionlimit(10 ** 7)
INF = float("inf")
MOD = 10 ** 9 + 7

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
smii = lambda: sorted(map(int, input().split()))


N = ii()
S = si()

r_cnt = S.count('R')
g_cnt = S.count('G')
b_cnt = S.count('B')

ans = r_cnt * g_cnt * b_cnt

for i in range(N):
    for dist in range(N):
        j = i + dist
        k = j + dist
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1

print(ans)

Measured memory_bytes: 9492
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
using namespace std;

int main()
{
    int a,b;
    cin >>a>>b;
            if(a+b>=10)
                printf("error\n");
            else
                cout <<a+b<<endl;
    return 0;
}


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

#define llint long long int

using namespace std;

int main()
{
    int K;

    cin >> K;

    llint seven = 0;
    llint add = 7;

    for (int i = 1; i <= K; i++)
    {
        seven += add;
        seven %= K;

        if (seven == 0)
        {
            cout << i << endl;

            return 0;
        }
        add *= 10;
        add %= K;
    }
    cout << -1 << endl;
}

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

const int N = 1E5 + 1;
vector<int> adj[N], in(N), dist(N);
vector<bool> vis(N);
int ans;

void dfs(int a) {
        vis[a] = 1;
        for (auto b: adj[a]) {
                ans = max(ans, dist[b] = max(dist[b], dist[a] + 1));
                if (!--in[b]) dfs(b);
        }
}

int main() {
        int n, m;
        scanf("%d%d",&n, &m);
        while (m--) {
                int a, b; scanf("%d%d", &a, &b);
                in[b]++;
                adj[a].emplace_back(b);
        }

        for (int i = 1; i <= n; i++) {
                if (!vis[i] && !in[i]) dfs(i);
        }


        printf("%d", ans);
}

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define push push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
int main(){
    int n;
    int ans=0;
    cin >>n;
    string s,t;
    cin>>s>>t;
    int legth=0;
    int pre=s.size();
    while (not((t.size() >= s.size() && std::equal(std::begin(s), std::end(s), std::begin(t))) or s == "")){
            s.erase(s.begin());
         //   cout<<s<<" "<<t<<endl;
    }
        legth = s.size();
        cout << (pre + t.size() - legth) << endl;
      //  cout << pre << endl;
      //  cout << legth << endl;
       // cout << t.size() << endl;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long LL;
using namespace std;

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

	if (a >= b) {
		rep(i, a) {
			cout << b;
		}
	}
	else {
		rep(i, b) {
			cout << a;
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;


signed main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    vector<int> a, b;
    int n; cin >> n;
    for(int i = 1; i * i <= n; i++){
        if (n % i == 0){
            a.push_back(i);
            b.push_back(n/i);
        }
    }
    int ans = INF;
    rep(i,a.size()){
        ans = min(ans, a[i]+b[i]-2);
    }
    cout << ans << endl;
}


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

int main() {
  string S; cin >> S;
  string WEEK[] =
    {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
  for (int i = 0; i < 7; i++) {
    if (S == WEEK[i]) {
      cout << i + 1 << endl; break;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pint;
typedef vector<int>vint;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int to[6][2]={{1,2},{-1,3},{1,-1},{4,5},{5,2},{2,1}};

int main(){
    string str;
    while(cin>>str,str!="#"){
        int v=0;
        rep(i,str.size()){
            if(v==-1)continue;
            if(str[i]=='0')v=to[v][0];
            else v=to[v][1];
        }
        if(v==5)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <queue>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

//yakusuu rekkyo
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // push its partner
            if (N/i != i) res.push_back(N/i);
        }
    }

    sort(res.begin(), res.end());
    return res;
}


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // exponential

        // divide as much as you can
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // push the result
        res.push_back({a, ex});
    }

    // last num (if the lasting n is prime number and not 1)
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main() {
    double q,h,s,d,n;
    ll ans = 0;
    vector<pair<double,double>> v;

    cin >> q >> h >> s >> d >> n;
    v.push_back(make_pair(q*8,0.25));
    v.push_back(make_pair(h*4,0.5));
    v.push_back(make_pair(s*2,1));
    v.push_back(make_pair(d,2));
    sort(v.begin(),v.end());

    rep(i,v.size()){
        pair<double,double> tmp;
        tmp = v[i];
        ll t = (ll)(n/tmp.second);
        n -= t*tmp.second;
        ans += ((int)((tmp.first/(2/tmp.second)))*t);
    }
    cout << ans;


    return 0;
}











Measured memory_bytes: 3704
N = int(input())

AC_count = 0
WA_count = 0
TLE_count = 0
RE_count = 0

for i in range(N):
  S = input()
  if S == 'AC':
    AC_count = AC_count + 1
  elif S == 'WA':
    WA_count = WA_count + 1
  elif S == 'TLE':
    TLE_count = TLE_count + 1
  else:
    RE_count = RE_count + 1

print('AC x ' + str(AC_count))
print('WA x ' + str(WA_count))
print('TLE x ' + str(TLE_count))
print('RE x ' + str(RE_count))

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int A[4][110];
  for(int i=1;i<=N;i++){cin >> A[1][i];}
  for(int i=1;i<=N;i++){cin >> A[2][i];}
  int S[110];
  for(int i=1;i<=N;i++){S[i]=0;}
  int ans=0;
  for(int i=1;i<=N;i++){
    for(int j=1;j<=i;j++){S[i]+=A[1][j];}
    for(int k=i;k<=N;k++){S[i]+=A[2][k];}
    if(ans<S[i]){ans=S[i];}
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintStream out = new PrintStream(System.out);
        int a, b, c, min;

        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();

        min = a + b;
        if (min > a + c) {
            min = a + c;
        }
        if (min > b + c) {
            min = b + c;
        }
        
        out.println(min);
        sc.close();
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#define INF 100000000
using namespace std;
typedef pair<int,int> P;
struct edge {
  int to,cost;
};

int n,m;
vector<edge> G[100];
int mincost[100];
bool used[100];

int prim() {
  for(int i=0;i<n;i++) {
    mincost[i] = INF;
    used[i] = false;
  }
  mincost[0] = 0;
  int res = 0;
  while(true) {
    int v = -1;
    for(int i=0;i<n;i++) {
      if(!used[i] && (v == -1 || mincost[i] < mincost[v] ) ) v = i;
    }

    if(v == -1) break;
    res += mincost[v];
    used[v] = true;

    for(int i=0;i<G[v].size();i++) {
      edge e = G[v][i];
      if(mincost[e.to] > e.cost) {
	mincost[e.to] = e.cost;
      }
    }
  }
  return (res/100) - n + 1;
}

int main() {
  while(cin >> n) {
    if(n==0) break;
    cin >> m;
    for(int i=0;i<m;i++) {
      int f,t,c;
      scanf("%d,%d,%d",&f,&t,&c);
      //      cout << f << " " << t << " " << c << endl;
      edge temp;
      temp.to = t;
      temp.cost = c;
      G[f].push_back(temp);
      temp.to = f;
      G[t].push_back(temp);
    }
    cout << prim() << endl;
    for(int i=0;i<n;i++) {
      G[i].clear();
    }
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
const ll infinity = 9e18;

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast


        
    int a,b,c;
    cin>>a>>b>>c;

    cout<<((a*b)/2);    












    return 0;
}

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

int a_to_index[1000001];

int next(int n){
  if (n % 2 == 0){
    return n / 2;
  }else{
    return 3 * n + 1;
  }
}

int main(){
  int s;
  cin >> s;
  int a_now = s, idx = 1;
  while(a_to_index[a_now] == 0){
    a_to_index[a_now] = idx;
    a_now = next(a_now);
    idx++;
  }
  cout << idx << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(114514,0);
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        a.at(k)++;
        a.at(k+1)++;
        a.at(k+2)++;
    }
    int ans=0;
    for(int i=0;i<114514;i++){
        ans=max(ans,a.at(i));
    }
    cout<<ans<<endl;
    return 0;
}



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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = x * 10 + (c ^ 48), c = nc;
  return x;
  #undef nc
}

typedef long long ll;

void solve() {
  int x = read();
  cout << 360 / __gcd(x, 360);
}

int main() {
//  int T = read();
//  while (T--) solve();
  solve();
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>

int main(int argc, char** argv)
{
	int A, B, H, M;
	double_t A_r, B_r;
	std::pair<double_t, double_t> A_v, B_v;
	static const double_t pi = 3.1415926535;
	std::cin >> A >> B >> H >> M;
	B_r = M / 60.0;
	A_r = (H+B_r) / 12.0;
	A_r *= pi*2;
	B_r *= pi*2;
	A_v = std::pair<double_t, double_t>(A * std::sin(A_r), A * std::cos(A_r));
	B_v = std::pair<double_t, double_t>(B * std::sin(B_r), B * std::cos(B_r));
	std::cout << std::fixed << std::setprecision(9);
	std::cout << std::sqrt(std::pow(A_v.first - B_v.first, 2.0) + std::pow(A_v.second - B_v.second, 2.0)) << std::endl;
	return 0;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

ll mod=1e9+7;

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b) {
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  u%=mod; if(u<0) u+=mod;
  return u;
}

ll com(ll n, ll k) {
  ll a=1,b=1;
  rep(i,k) {
    a=(a*(n-i))%mod;
    b=(b*(i+1))%mod;
  }
  return (a*modinv(b))%mod;
}

ll solve(ll n) {
  n-=5;
  ll ret=0,m;
  rep(i,12) {
    m=n-i;
    if(m<0||m%2!=0) continue;
    ret=(ret+com(m/2+15,15)*com(11,i))%mod;
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll T,n;cin>>T;
  rep(i,T) {
    cin>>n;
    print(solve(n));
  }
  return 0;
}


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

using namespace std;

class Dsu {
 public:
  int n; // number of componet
  vector<int> sz, p;
  
  Dsu(int n) : n(n), sz(n, 1), p(n, -1) { }

  int find(int i) {
    if (p[i] == -1) return i;
    return p[i] = find(p[i]);
  }

  bool merge(int u, int v) {
    u = find(u), v = find(v);
    if (u == v) return false;
    n--;
    if (sz[u] < sz[v]) {
      p[u] = v;
      sz[v] += sz[u];
    } else {
      p[v] = u;
      sz[u] += sz[v];
    }
    return true;
  }

  bool same(int u, int v) { return find(u) == find(v); }
};

int main() {
  ios_base::sync_with_stdio(false);

  int n, m, op, u, v;
  cin >> n >> m;

  Dsu dsu(n);

  for (int i = 0; i < m; i++) {
    cin >> op >> u >> v;
    if (op == 0) {
      dsu.merge(u, v);
    } else {
      cout << dsu.same(u, v) << '\n';
    }
  }

  return 0;
}


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

int main(){
  int N;
  cin >> N;
  int A = 0;
  int a = 0;
  int y;
  
  for (int i = 0; i < N; i++){
    cin >> y;
    a = 0;
    while (y % 2 == 0){
      y /= 2;
      a++;
    }
    if (i == 0){
      A = a;
    }
    else{
      A = min(A, a);
    }
  }
  cout << A << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}


ll count(ll s){
  ll ret=0;
  for(ll i=1;i*(i+1)/2<=s;i++){
    if(i&1){
      if(s%i!=0){continue;}
      ll m=s/i;
      if(m-i/2>0){ret++;}
    }
    else{
      if(s*2%i!=0){continue;}
      ll m=s*2/i;
      if(m%2!=1){continue;}
      if(m-i>0){ret++;}
    }
  }
  return ret;
}

int main(){
  ll s;
  cin>>s;
  ll ans=0;
  for(ll i=1;i<=s;i++){
    if(s%i==0){
      ans+=count(i)*count(s/i);
    }
  }
  cout<<ans<<endl;
  
  return 0;
}



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

using namespace std;

int main(void)
{
	int a[3];
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	sort(a, a + 3);

	int ans = a[2] - a[0];
	cout << ans << endl;
	
	return 0;
}

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

int main()
{
    array<int,3> arr;
    for(int i=0;i<3;i++){
        cin >> arr[i];
    }
    sort(arr.begin(),arr.end());

    if(arr[0]+arr[1]==arr[2]){
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
const double EPS = 1e-10;
bool equals(double a, double b) {
	return fabs(a - b) < EPS;
}
struct Point {
	double x, y;
	Point(double x = 0, double y = 0) :x(x), y(y) {}
	Point operator + (Point rhs) {
		return Point(x + rhs.x, y + rhs.y);
	}
	Point operator - (Point rhs) {
		return Point(x - rhs.x, y - rhs.y);
	}
	Point operator * (double k) {
		return Point(k * x, k * y);
	}
	bool operator < (const Point& rhs) const {
		return x != rhs.x ? x < rhs.x : y < rhs.y;
	}
	bool operator == (const Point& rhs) const {
		return equals(x, rhs.x) && equals(y, rhs.y);
	}
	double norm() {
		return x * x + y * y;
	}
	double abs() {
		return sqrt(norm());
	}
};
typedef Point Vector;
struct Segment {
	Point p1, p2;
	Segment(Point p1 = Point(), Point p2 = Point()) :p1(p1), p2(p2) {}
};
typedef Segment Line;
struct Circle {
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0) :c(c), r(r) {}
};
typedef vector<Point> Polygon;
double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}
double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}
bool isOrthogonal(Vector a, Vector b) {
	return equals(dot(a, b), 0);
}
bool isOrthogonal(Segment a, Segment b) {
	return isOrthogonal(Vector(a.p2.x - a.p1.x, a.p2.y - a.p1.y), Vector(b.p2.x - b.p1.x, b.p2.y - b.p1.y));
}
bool isParallel(Vector a, Vector b) {
	return equals(cross(a, b), 0);
}
bool isParallel(Segment a, Segment b) {
	return isParallel(Vector(a.p2.x - a.p1.x, a.p2.y - a.p1.y), Vector(b.p2.x - b.p1.x, b.p2.y - b.p1.y));
}
Point project(Point p, Segment s) {
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + (base * r);
} 
int main() {
    int q;
	double x1, y1, x2, y2;
	scanf("%lf%lf%lf%lf%d", &x1, &y1, &x2, &y2, &q);
	Segment s = Segment(Point(x1, y1), Point(x2, y2));
	while (q--) {
		scanf("%lf%lf", &x1, &y1);
		Point ans = project(Point(x1, y1), s);
		printf("%.010lf %.010lf\n", ans.x, ans.y);
	}
	return 0;
}


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

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

	fenwick_tree<int64_t> fw(N);

	rep(i, N){
		int a; cin>>a;
		fw.add(i, a); // init: A[i] += a
	}

	rep(i, Q){
		int t, a, b; cin>>t>>a>>b;
		if(t) cout<< fw.sum(a, b) <<endl; // sum(l, r): sum(A[l, r-1])
		else fw.add(a, b); // update(p, x): A[p] += x
	}
}


Measured memory_bytes: 8236
// A - Eating Symbols Easy
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S; cin>>S;
	int ans = 0;
	ans += S[0]=='+'? 1:-1;
	ans += S[1]=='+'? 1:-1;
	ans += S[2]=='+'? 1:-1;
	ans += S[3]=='+'? 1:-1;
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) x.begin(),x.end()
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, n, m) for(int i = n; i >= m; i--)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;

int main(){

  int N;
  cin >> N;

  if(N<10){
    std::cout << N << '\n';
  }
  else if(N<100){
    std::cout << 9 << '\n';
  }
  else if(N<1000){
    std::cout << N-90 << '\n';
  }
  else if(N<10000){
    std::cout << 909 << '\n';
  }
  else if(N<100000){
    std::cout << N-9090 << '\n';
  }
  else std::cout << 90909 << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;
const int AMAX = 100000;
ll cnt[AMAX + 1];

int main(void) {
    int N;
    ll K;
    cin >> N >> K;
    for (int i = 0; i < N; ++i) {
        int A, B;
        cin >> A >> B;
        cnt[A] += B;
    }

    for (int ans = 1; ans <= AMAX; ++ans){
        if (K <= cnt[ans]) {
            cout << ans << endl;
            break;
        }
        K -= cnt[ans];
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

int main() {
	long A, B, K;
	std::cin >> K;
	std::cin >> A >> B;
	if ((A % K == 0) || (B % K == 0) || (B - A > B % K)) { std::cout << "OK"; }
	else { std::cout << "NG"; }
	return 0;
}


Measured memory_bytes: 3068
mod = 998244353
inv = pow(2, mod-2, mod)
n, s = map(int, input().split())
a = list(map(int, input().split()))
dp = [0]*(s+1)
dp[0] = pow(2, n, mod)
for i in a:
  for j in range(s, i-1, -1):
    dp[j] = (dp[j] + dp[j-i] * inv) % mod
print(dp[s])


Measured memory_bytes: 68388
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int a,b;
    cin>>a>>b;
    b-=a;
    if(b%2){
    	cout<<"Borys"<<endl;
    }
    else{
    	cout<<"Alice"<<endl;
    }
    
    return 0;  
    
}



Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
using namespace std;
string s; int x; vector<pair<string, int> > a, b, c;
vector<pair<string, int> > shift(vector<pair<string, int> > v) {
	vector<pair<string, int> > w;
	for (int i = 0; i < v.size(); i++) {
		if (v[i].second > 0) w.push_back(v[i]);
	}
	v = w;
	vector<pair<string, int> > ret;
	int sum = v[0].second;
	for (int i = 1; i <= v.size(); i++) {
		if (i == v.size() || v[i - 1].first != v[i].first) {
			ret.push_back(make_pair(v[i - 1].first, sum));
			sum = 0;
		}
		if (i != v.size()) sum += v[i].second;
	}
	return ret;
}
int main() {
	while (cin >> s, s != "$") cin >> x, a.push_back(make_pair(s, x));
	while (cin >> s, s != "$") cin >> x, b.push_back(make_pair(s, x));
	while (cin >> s, s != "$") cin >> x, c.push_back(make_pair(s, x));
	for (int i = 0; i <= (int)(a.size() - b.size()); i++) {
		bool ok = true;
		for (int j = 0; j < b.size(); j++) {
			if (a[i + j].first != b[j].first) ok = false;
		}
		for (int j = 2; j < b.size(); j++) {
			if (a[i + j - 1].second != b[j - 1].second) ok = false;
		}
		if (a[i].second < b[0].second) ok = false;
		if (a[i + b.size() - 1].second < b[b.size() - 1].second) ok = false;
		if (ok) {
			vector<pair<string, int> > d(a.begin(), a.begin() + i);
			if(b.size() != 1) d.push_back(make_pair(a[i].first, a[i].second - b[0].second));
			d.insert(d.end(), c.begin(), c.end());
			d.push_back(make_pair(a[i + b.size() - 1].first, a[i + b.size() - 1].second - b[b.size() - 1].second));
			d.insert(d.end(), a.begin() + i + b.size(), a.end());
			a = shift(d);
			break;
		}
	}
	for (int i = 0; i < a.size(); i++) cout << a[i].first << ' ' << a[i].second << ' ';
	cout << "$" << endl;
	return 0;
}

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

int main(){
   
    int N;cin>>N;
    int a0=0,a2=0,a4=0;
    for(int i=0;i<N;i++){
        int b;cin>>b;
        if(b%4==0) a4++;
        else if(b%2==0) a2++;
        else a0++;
    }
    if(a4>=a0||(a4+1==a0&&a2==0)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 764
[<EntryPoint>]
let main argv =
    //printfn "Gokigenyou!" 
    let cs = System.Console.ReadLine().ToCharArray()
    let odd =
        [0 .. 2 .. cs.Length-1]
        |> List.map (fun i -> cs.[i])
    let even =
        [1 .. 2 .. cs.Length-1]
        |> List.map (fun i -> cs.[i])
    let ans = if (odd |> List.contains 'L') || (even |> List.contains 'R') then "No" else "Yes" 
    System.Console.WriteLine(ans)
    0


Measured memory_bytes: 14176
def q2():
    N, M = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    sum_A = sum(A)
    if N >= sum_A:
        ans = N - sum_A
    else:
        ans = -1
    print(ans)


if __name__ == '__main__':
    q2()

Measured memory_bytes: 9892
import java.util.*;

class Main{
	static int mod=1000000007;

	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		System.out.println(new String[] {"Sunny","Cloudy","Rainy"}["RSC".indexOf(s.next().charAt(0))]);
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

struct Book {
  int c;
  vector<int> a;
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M, X;
  cin >> N >> M >> X;
  vector<Book> books(N);
  REP(i, N) {
    cin >> books[i].c;
    books[i].a.resize(M);
    REP(j, M) { cin >> books[i].a[j]; }
  }
  const int L = 1 << N;
  const i64 INF = 1LL << 40;
  i64 mincost = INF;
  for (int i = 0; i < L; ++i) {
    i64 cost = 0;
    vector<i64> xs(M, X);
    REP(j, N) {
      if (i & (1 << j)) {
        cost += books[j].c;
        REP(k, M) { xs[k] -= books[j].a[k]; }
      }
    }
    if (cost >= mincost) continue;
    bool ok = true;
    REP(k, M) {
      if (xs[k] > 0) {
        ok = false;
        break;
      }
    }
    if (ok) {
      mincost = cost;
    }
  }
  cout << (mincost == INF ? -1LL : mincost) << endl;
}

Measured memory_bytes: 3664
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var a = input[1].split(" ").map(i => parseInt(i));
  var ans = 0;
  var dp = new Array(N);
  var sum = new Array(N);
  sum[0]=a[0];
  for(var i=0;i<N;i++){
    var tmp=new Array(N).fill(0);
    dp[i]=tmp;
    if(i>0){
      sum[i]=sum[i-1]+a[i];
    }
  }
  for(var k=1;k<N;k++){
    for(var i=0,j=k;i<N&&j<N;i++,j++){
      var tmp=Math.pow(10,19);
      for(var l=i;l<j;l++){
        if(i!=0){
          tmp=Math.min(tmp,dp[i][l]+dp[l+1][j]+sum[j]-sum[i-1]);
        }else{
          tmp=Math.min(tmp,dp[i][l]+dp[l+1][j]+sum[j]);
        }
      }
      dp[i][j]=tmp;
    }
  }
  var ans=dp[0][N-1];

  console.log('%s', ans);
  return ans;
}
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 14896
N = int(input())
a = list(map(int, input().split()))

alice = 0
bob = 0

while len(a) != 0:
    alice += max(a)
    a.remove(max(a))
    if len(a) == 0:
        break
    bob += max(a)
    a.remove(max(a))

print(alice-bob)

Measured memory_bytes: 9124
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  if ((a == b && a != c) || (a == c && a != b) || (b == c && b != a))
    puts("Yes");
  else
    puts("No");
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;

using namespace std;

int main() 
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    
    cout << min(a,b)+min(c,d) << endl;

    return 0;
}
    



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

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

using namespace std;

typedef long double ld;

int main() {
  int n,m;
  double l;
  cin>>n>>m>>l;
  vector<vector<ld>> prob(n, vector<ld>(m+1));
  vector<vector<ld>> tm(n, vector<ld>(m+1));
  REP(i,n) {
    ld p,t,v;
    cin>>p>>t>>v;
    p /= 100.0;
    prob[i][0] = 1.0;
    REP(j,m) {
      vector<ld> tmp(m+1);
      tmp[0] = prob[i][0] * (1-p);
      REP(k,m)
        tmp[k+1] = prob[i][k] * p + prob[i][k+1] * (1-p);
      swap(prob[i], tmp);
    }
    REP(j,m+1)
      tm[i][j] = l/v + t*j;
  }
  REP(i,n) {
    ld psum = 0.0;
    REP(j,m+1) {
      ld T = tm[i][j];
      ld p = prob[i][j];
      REP(k,n) {
        if(i==k) continue;
        ld sp = 0.0;
        REP(l,m+1){
          if (tm[k][l] > T) sp += prob[k][l];
        }
        p *= sp;
      }
      psum += p;
    }
    cout << setprecision(10) << fixed << psum << endl;
  }
  return 0;
}

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

//幅優先探索
int main()
{
    ll k;
    cin >> k;
    vector<ll> store;
    queue<ll> que; //まずqを用意
    for (int i = 1; i < 10; i++)
    {
        que.push(i);
    }
    while (store.size() != k)
    {
        if (que.front()%10 != 0 && que.front()%10 != 9)
        { //こいつが一の位の時を考える。
            que.push(que.front() * 10 + que.front() % 10 - 1);
            que.push(que.front() * 10 + que.front() % 10);
            que.push(que.front() * 10 + que.front() % 10 + 1);
        }
        else if (que.front()%10 == 0)
        {
            que.push(que.front() * 10 + que.front() % 10);
            que.push(que.front() * 10 + que.front() % 10 + 1);
        }
        else if (que.front()%10 == 9)
        {
            que.push(que.front() * 10 + que.front() % 10 - 1);
            que.push(que.front() * 10 + que.front() % 10);
                }
        //これで探索したものをstoreに
        store.push_back(que.front());
        que.pop();
    }
    //k番目になったものに関しては
 
     cout<<store[k-1];
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int NMAX = 50 + 10, AMAX = 50 + 10;

int N;
vector<int> A;

ll cost(int x, vector<int> a) {
  ll ans = 0;
  for (int i = 0; i < a.size(); i++) {
    ans += (x - a[i]) * (x - a[i]);
  }
  return ans;
}

ll lowmean(vector<int> a) {
  ll sum = 0;
  for (int i = 0; i < a.size(); i++) {
    sum += a[i];
  }
  if (sum < 0) {
    return -sum / a.size() * -1;
  } else {
    return sum / a.size();
  }
}

ll highmean(vector<int> a) {
  ll sum = 0;
  for (int i = 0; i < a.size(); i++) {
    sum += a[i];
  }
  if (sum < 0) {
    return -(sum + a.size() - 1) / a.size() * -1;
  } else {
    return (sum + a.size() - 1) / a.size();
  }
}

void abc043c() {
  ll m1 = lowmean(A), m2 = highmean(A);
  ll cost1 = cost(m1, A), cost2 = cost(m2, A);
  cout << min(cost1, cost2) << '\n';
  return;
}

int main() {
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  abc043c();
  return 0;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    ll n, k;
    cin >> n >> k;
    vector<pair<int,int>> v;
    ll sum = 0;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        v.push_back({a,b});
    }
    sort(v.begin(), v.end());
    for(auto x: v){
        sum += x.second;
        if(sum >= k){
            ans = x.first;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4320
#include <iostream>
#include <queue>

using namespace std;

int main() {
    long N, T;
    cin >> N >> T;
    long total = 0l;
    long prev = -1l, arrival = -1;
    for (long n = 0l; n < N; ++n) {
      cin >> arrival;
      if (prev >= 0l) {
        if (prev + T <= arrival) {
          total += T;
        } else {
          total += arrival - prev;
        }
      }
      prev = arrival;
    }
    total += T;
    cout << total << endl;
    return 0;
}


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

#define printl(s) cout << s << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using vvi = vector<vector<int>>;

const ll modSeed = pow(10,9) + 7;
const int INF = 1'000'000'000;

template <typename T>
vector<T> getVector(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

string S;
ll N,D,ans;

double dist(vector<int> p1, vector<int> p2, int dim){
  int res = 0;
  rep(i,dim){
    res+=pow(p1[i]-p2[i],2);
  }
  return sqrt(res);
}

int main(){
  ans = 0;
  cin >> N>>D;
  vvi points(N,vector<int>(D));
  rep(i,N){
    points[i] = getVector<int>(D);
  }
  rep(i,N){
    for(int j=i+1;j<N;j++){
      double dis = dist(points[i],points[j],D);
      if(floor(dis)==dis){
        ans++;
      } 
    }
  }
  printl(ans);
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
ll euclidean_lcm(ll a, ll b) {
  return a/euclidean_gcd(a,b)*b;
}

ll binary(ll bina){
    ll ans = 0;
    for (ll i = 0; bina>0 ; i++)
    {
        ans += bina%2;
        bina = bina/2;
    }
    return ans;
}
void revStr(char* str){
	int size = strlen(str);
	int i,j;
	char tmp = {0};
	
	for(i = 0, j = size - 1; i < size / 2; i++, j--){
		tmp = str[i];
		str[i] = str[j];
		str[j] = tmp;
	}
	return;	
}
int main(void){
  ll n,z=0;
  cin >> n;
  char s[n+1];
  cin >> s;
  revStr(s);
  rep(i,n){
    if(s[i]=='1'){
      z++;
    }
  }
  ll g=z-1,h=z+1;
  ll dp[250001];
  ll w[250001],e[250001];
  ll t=1,u=1;
  rep(i,250001){
    w[i]=t;
    e[i]=u;
    if(g>0)t=(t*2)%g;
    if(h>0)u=(u*2)%h;
  }
  ll ww=0,ee=0;
  rep(i,n){
    if(s[i]=='1'){
      ww+=w[i];
      if(g>0)ww%=g;
      ee+=e[i];
      if(h>0)ee%=h;
    }
  }
  dp[0]=0;
  dp[1]=1;
  rep(i,250001){
    if(i>1){
      dp[i]=dp[i%binary(i)]+1;
    }
  }
  ll jj,kk;
  rep(i,n){
    if(s[n-1-i]=='1'){
      if(g==0)cout << 0 << endl;
      else{
        jj=(ww+g-w[n-1-i])%g;
        cout << 1+dp[jj] << endl;
      }
    }
    else{
      if(h==0)cout << 0 << endl;
      else{
        kk=(ee+h+e[n-1-i])%h;
        cout << 1+dp[kk] << endl;
      }
    } 
  }
}

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

using namespace std;

const long nmax=40;
const long mmax=400;
const long inf=100000000;

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

int main(){
  long n,ma,mb;
  cin >> n >> ma >> mb;
  long a[nmax],b[nmax],c[nmax];
  rep(i,n) cin >> a[i] >> b[i] >> c[i];
  
  long dp[nmax+1][mmax+1][mmax+1];
  rep(i,n+1){
    rep(ca,mmax+1){
     rep(cb,mmax+1){
      dp[i][ca][cb]=inf;
     }
     }
  }

 dp[0][0][0]=0;
  
  rep(i,n){
    rep(ca,mmax+1){
     rep(cb,mmax+1){
       if(dp[i][ca][cb]==inf) continue;
      dp[i+1][ca][cb]=min(dp[i+1][ca][cb],dp[i][ca][cb]);
      dp[i+1][ca+a[i]][cb+b[i]]=min(dp[i+1][ca+a[i]][cb+b[i]],dp[i][ca][cb]+c[i]);
     }
     }
  }
  
   long res=inf;
    for(long ca=1;ca<mmax+1;ca++){
     for(long cb=1;cb<mmax+1;cb++){
       if(ca*mb==cb*ma) res=min(res,dp[n][ca][cb]);
     }
    }
  if(res==inf) res=-1;
  
  cout << res << endl;

}


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

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

    int N;
    cin >> N;
    int a[100001];
    bool passed[100001] = {false};

    rep(i, N)
        cin >> a[i+1];

    int next = 1;
    int count = 0;
    rep (i, N+1) {
        ++count;
        
        if (a[next] == 2) {
            cout << count << "\n";
            return 0;
        }
        else if (passed[next]) {
            cout << -1 << "\n";
            return 0;
        }
        
        passed[next] = true;
        next = a[next];
    }

    cout << -1 << "\n";
}

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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> ans(N, 0);
  rep(i,Q) {
    int a;
    cin >> a;
    a--;
    ans[a]++;
  }

  rep(i,N) {
    if (K-Q+ans[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
string s;
int main()
{
	cin>>s;
	if(s=="SUN")
		cout<<7<<endl;
	else if(s=="MON")
		cout<<6<<endl;
	else if(s=="TUE")
		cout<<5<<endl;
	else if(s=="WED")
		cout<<4<<endl;
	else if(s=="THU")
		cout<<3<<endl;
	else if(s=="FRI")
		cout<<2<<endl;
	else 
		cout<<1<<endl;						
}

Measured memory_bytes: 256
/*
  no pain, no gain
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define pii pair<int, int>
#define all(s) s.begin(), s.end()
#define prev myrza4321
#define y1 myrza1234
#define OK puts("OK")
#define double long double
#define int long long
using namespace std;

const int N = (int)1e5 + 5;
const int INF = 0x3f3f3f3f;

double dp[N];

main() {
  double x;
  cin >> x;
  dp[1] = 100;
  for (int i = 2; ; i++) {
    dp[i] = dp[i - 1] * 1.01;
    dp[i] = (int)dp[i];
    if (dp[i] >= x) {
      cout << i - 1;
      break;
    }
  }
}


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

int main () {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  
  sort (a.begin(), a.end());
  reverse (a.begin(), a.end());
  
  int n = 1;
  for (int i = 0; i < N - 1; i++) {
    if (a.at(i+1) < a.at(i)) 
      n++;
  }
  
  cout << n << endl;
  
}

Measured memory_bytes: 256