akhauriyash/Code-Regression huggingface dataset:
#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; cin >> n;
  vector<vector<pair<int, int>>> a(n);
  rep(i,n - 1){
    int u, v, w; cin >> u >> v >> w;
    u--;
    v--;
    a[u].push_back(make_pair(v, w));
    a[v].push_back(make_pair(u, w));
  }
  queue<int> q;
  vector<bool> visited(n, false);
  vector<int> dis(n);
  q.push(0);
  visited[0] = true;
  dis[0] = 0;
  while(q.size() > 0){
    int now = q.front(); q.pop();
    rep(i, a[now].size()){
      int next = a[now][i].first, disnext = a[now][i].second;
      if(visited[next] == true) continue;
      visited[next] = true;
      dis[next] = dis[now] + disnext;
      q.push(next);
    }
  }
  rep(i, n){
    if(dis[i] % 2 == 0) cout << 0 << endl;
    else cout << 1 << endl;
    //cout << dis[i] << endl;
  }
  return 0;
}


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

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

string ini = "MARCH";

int main(void){
  int32 N;
  int64 cnt[5] = {};
  cin >> N;
  REP(i, N){
    string s;
    cin >> s;
    if(ini.find(s[0]) == string::npos) continue;
    cnt[ini.find(s[0])]++;
  }
  int64 res = 0;
  REP(i, 5){
    FOR(j, i+1, 5){
      FOR(k, j+1, 5){
        res += cnt[i]*cnt[j]*cnt[k];
      }
    }
  }
  cout << res << endl;
}

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

string s;

int main()
{
    cin >> s;
    for(int i = 0; i < s.length() - 1; i++)
    {
        if(s[i] == s[i+1])
        {
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }
    for(int i = 0; i < s.length() - 2; i++)
    {
        if(s[i] == s[i+2])
        {
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int x;
    in(x);
    vector<int> vec={400,600,800,1000,1200,1400,1600,1800};
    int ans=8;
    rep(i,vec.size()-1){
        if(x>=vec[i]&&x<vec[i+1]){
            break;
        }
        ans--;
    }
    out(ans);
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S;

int hoge(string S) {
	int ret=0;
	FORR(c,S) ret+=c-'0';
	return ret;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	int ma=hoge(S);
	
	for(i=0;i<S.size();i++) {
		string T=S;
		if(S[i]!='0') {
			T[i]--;
			for(j=i+1;j<S.size();j++) T[j]='9';
		}
		ma=max(ma,hoge(T));
	}
	cout<<ma<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* liblary */

/* main */

signed main() {
    ll N, X;
    cin >> N >> X;
    vl L(N);
    FOR(i, 0, N) {
        cin >> L[i];
    }
    vl D(N + 1, 0);
    ll ans = 1;
    FOR(i, 1, N + 1) {
        D[i] = D[i - 1] + L[i - 1];
        if (D[i] <= X) ans++;
    }
    cout << ans << endl;
}

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

vector<int> v[100005];
int vis[100005]={0};

void dfs(int s) {
	vis[s]=1;
	vector<int>::iterator i;
	for(i=v[s].begin();i!=v[s].end();i++) {
		if(vis[*i]==0) dfs(*i);
	}
}
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,m,i,c,d,ans=0;
	cin>>n>>m;
	for(i=0;i<m;i++) {
		cin>>c>>d;
		v[c-1].push_back(d-1);
		v[d-1].push_back(c-1);
	}
	for(i=0;i<n;i++) {
		if(vis[i]==0) {
			ans++;
			dfs(i);
		}
	}
	cout<<ans-1;
	
}

Measured memory_bytes: 9964
class Map(dict):
    default_value = 0

    def __missing__(self, key):
        self[key] = self.default_value
        return self.default_value


def main():
    int(input())

    d = Map()
    ans = 0
    for i, height in enumerate(input().split()):
        height = int(height)
        d[i + height] += 1
        ans += d[i - height]

    return ans


if __name__ == '__main__':
    print(main())

# 大いに参考にした。
# https://kmjp.hatenablog.jp/entry/2020/05/03/1030


Measured memory_bytes: 67192
import java.io.*;
import java.util.*;
import java.math.*;
class Main{
    public static void main(String[] args){
    BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
    try {
		while(true){
		String[] st = sc.readLine().split(" ");
		int n = Integer.valueOf(st[0]);
		int m = Integer.valueOf(st[1]);
		if(n==0 && m==0)
			break;
		int sumA=0, sumB=0, min = 300, first=0, last=0, flag = 0;
		int a[] = new int[n];
		int b[] = new int[m];
		for(int i=0; i<n; i++){
			a[i] = Integer.valueOf(sc.readLine());
			sumA += a[i];
			}
		for(int i=0; i<m; i++){
			b[i] = Integer.valueOf(sc.readLine());
			sumB += b[i];
			}
		for(int i=0; i<n; i++)
			for(int j=0; j<m; j++){
				if((sumA-a[i]+b[j] == sumB+a[i]-b[j]) && (a[i]+b[j]<min)){
					first = a[i];
					last = b[j];
					min = a[i]+b[j];
					flag = 1;
					}
				}
		if(flag==1)
			System.out.println(first+" "+last);
		else
			System.out.println(-1);
		}
    }catch(Exception e){
        System.out.println("Error");
    }
    }
}

Measured memory_bytes: 17972
while True:
    (n, x) = [int(i) for i in input().split()]
    if n == x == 0: break
    count = 0
    for i in range(1,n - 1):
        for j in range(i + 1 ,n):
            for k in range(j + 1 ,n + 1):
                if i + j + k == x: 
                    count += 1
                    break 
    print(count)

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int hoge,huga;
string s;

signed main() {
    cin >> s;
    rep(i,s.size()) {
        if (i%2) {
            if (s[i] == '0') hoge++;
            else huga++;
        } else {
            if (s[i] == '0') huga++;
            else hoge++;
        }
    }
    cout << min(hoge,huga) << endl;
}


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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  
  for(int i=0; i<K; i++){
    if(A+i<=B){
      cout << A+i << endl;
    }
  }
  
  for(int i=K-1; i>=0; i--){
    if(B-i>A+K-1){
      cout << B-i << endl;
    }
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll ans = 0;
    ll last = 0;
    vi edges[200001];
    int n; cin >> n;
    FOR(i,n-1){
        int u,v; cin >> u >> v;
        if(u > v) swap(u,v);
        edges[u].push_back(v);
    }
    for(int i = n; i >0; i--){
        ll cur = last; cur += n-i+1;
        for(auto &a: edges[i]) cur -= n-a+1;
        ans += cur; last = cur;
    }
    cout << ans << "\n";
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int ans =0,t=0;
    string s;
    cin >> s;
        forx(j,1,n)
        {
            if(s[j]=='E'){
                t++;
                ans++;
            }
        }
      forx(i,0,n-1){
          
          if(s[i]=='W'&&s[i+1]=='W') t++;

          if (s[i] == 'E' && s[i + 1] == 'E')  t--;
          
          ans = min(t, ans);
      }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 900
s = set()
s |= { i*i for i in range(1, 33) }
s |= { i*i*i for i in range(1, 11) }
s |= { i*i*i*i*i for i in range(1, 5) }
s |= { i*i*i*i*i*i*i for i in range(1, 5) }
#print(sorted(s))
X = int(input())
r = max(filter(lambda i: i <= X, s))
print(r)


Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iomanip>
using namespace std;
const int maxn = 555;
char mp[maxn][maxn];
int vis[maxn][maxn];


int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d\n",a-1+(a<=b?1:0));

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

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

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

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

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

    bool flg = false;
    for( int i = 0; i <= n && !flg; ++i ) {
        for( int j = 0; j <= n - i && !flg; ++j ) {
            int a = i, b = j, c = n - ( i + j );
            if( a * 10000 + b * 5000 + c * 1000 == y ) {
                flg = true;
                cout << a << " " << b << " " << c << endl;
            }
        }
    }

    if( !flg ) cout << "-1 -1 -1" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int n;
vector<ll> r, c;
auto memo = make_vec<ll>(110, 110);
ll dp(int i, int j) {
    if (memo[i][j] != -1) return memo[i][j];
    if (i == j) return memo[i][j] = 0;
    ll ret = LINF;
    for (int k = i; k < j; k++) {
        chmin(ret, dp(i, k) + dp(k + 1, j) + r[i] * c[k] * c[j]);
    }
    return memo[i][j] = ret;
}
int main() {
    cin >> n;
    r.resize(n);
    c.resize(n);
    rep(i, n) cin >> r[i] >> c[i];
    rep(i, 110) rep(j, 110) memo[i][j] = -1;
    cout << dp(0, n - 1) << endl;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<int MOD> struct modnum {
    int v;
    modnum() : v(0) {}
    modnum(ll _v) : v(_v % MOD) { if (v < 0) v += MOD; }
    explicit operator int() const { return v; }
    friend ostream& operator << (ostream& o, const modnum& n) { return o << n.v; }
    friend istream& operator << (istream& i, modnum& n) { ll v; i >> v; n = modnum(v); return i; }

    friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
    friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

    modnum& operator += (const modnum& o) { v += o.v; if (v >= MOD) v -= MOD; return *this; }
    modnum& operator -= (const modnum& o) { v -= o.v; if (v < 0) v += MOD; return *this; }
    modnum& operator *= (const modnum& o) { v = int(ll(v) * ll(o.v) % MOD); return *this; }
    modnum operator - () { modnum res; if (v) res.v = MOD - v; return res; }
    friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
    friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
    friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }

    modnum pow(int e) const {
        if (e == 0) return 1;
        if (e & 1) return *this * this->pow(e-1);
        return (*this * *this).pow(e/2);
    }

    modnum inv() const {
        int g = MOD, x = 0, y = 1;
        for (int r = v; r != 0; ) {
            int q = g / r;
            g %= r; swap(g, r);
            x -= q * y; swap(x, y);
        }

        assert(g == 1);
        assert(y == MOD || y == -MOD);
        return x < 0 ? x + MOD : x;
    }
    modnum& operator /= (const modnum& o) { return (*this) *= o.inv(); }
    friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= modnum(b); }
};

using mn = modnum<998244353>;

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

    const int MAXV = 3.1e5;
    vector<mn> fact(MAXV);
    fact[0] = 1;
    for (int v = 1; v < MAXV; v++)
        fact[v] = v * fact[v - 1];

    auto ncr = [&fact](int n, ll r) {
        if (r > n || r < 0) return mn(0);
        return fact[n] / (fact[r] * fact[n-r]);
    };

    int N, A, B;
    ll K;

    cin >> N >> A >> B >> K;

    mn ans = 0;

    for (int ac = 0; ac <= N; ac++) {
        ll rem = K - ll(ac) * A;
        if (rem % B) continue;

        ll bc = rem / B;
        ans += ncr(N, ac) * ncr(N, bc);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1536
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <math.h>

#define ll long long
#define ull unsigned long long

using namespace std;

const int inf = 1000000000;
const double eps = 1e-7;

void solve() {
	int n, m, k;
	cin >> n >> m >> k;
	vector<string> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	
	int ans = inf;
	for (int mask = 0; mask < (1 << (n - 1)); ++mask) {
		vector<int> last;
		for (int i = 0; i < n - 1; ++i)
			if (mask & (1 << i))
				last.push_back(i);
		last.push_back(n - 1);
		int sz = last.size();
		
		vector<vector<int>> b(sz, vector<int>(m));
		for (int i = 0, c = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j)
				b[c][j] += (a[i][j] - '0');
			if (i == last[c])
				++c;
		}
		
		bool f = true;
		for (int i = 0; i < sz; ++i)
			for (int j = 0; j < m; ++j)
				f &= (b[i][j] <= k);
		if (!f)
			continue;
		
		int res = 0;
		vector<int> sum(sz);
		for (int i = 0; i < sz; ++i)
			sum[i] = b[i][0];
		
		for (int j = 1; j < m; ++j) {
			bool g = true;
			for (int i = 0; i < sz; ++i)
				g &= (sum[i] + b[i][j] <= k);
			
			if (!g) {
				++res;
				for (int i = 0; i < sz; ++i)
					sum[i] = b[i][j];
			}
			else
				for (int i = 0; i < sz; ++i)
					sum[i] += b[i][j];
		}
		
		ans = min(ans, sz - 1 + res);
	}
	
	cout << ans << endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include <math.h>
#include<algorithm>
#include<vector>
#include<bitset>
using namespace std ;
typedef long long int ll ;
int gcd(int a, int b) 
{ 
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
    if (a == b) 
        return a;  
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 
int main (){
	ll sum = 0  ;
	int  a ;
	cin >> a ;
	for (int i = 1; i <= a; i++)
	{
		for (int j = 1; j <= a; j++)
		{
			for (int k = 1; k <= a; k++)
			{
				sum += gcd(i,gcd(j,k)) ;
				//cout<< sum<< endl ;
			}	
		}
	}
	cout << sum << endl ;
	
return 0 ;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	priority_queue<pair<int, int>> que;
	for (int i = 0; i < N; ++i) {
		if (A[i] < B[i]) {
			que.emplace( B[i], i );
		}
	}

	Int ans = 0;
	while (!que.empty()) {
		auto p = que.top(); que.pop();
		int b = p.first, idx = p.second;
		int l = B[(idx-1+N) % N];
		int r = B[(idx+1) % N];
		
		if ((b - A[idx]) / (l + r) <= 0) { break; }
		ans += (b - A[idx]) / (l + r);
		B[idx] = A[idx] + (b - A[idx]) % (l + r);
		
		if (B[idx] <= A[idx]) { continue; }
		que.emplace( B[idx], idx );
	}

	for (int i = 0; i < N; ++i) {
		if (A[i] == B[i]) { continue; }
		cout << "-1\n";
		return 0;
	}
	cout << ans << "\n";

	return 0;
}


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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

int main()
{
    string S;
    cin >> S;
    if(S=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}

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

int main() {
  
  int N;
  cin >> N;
  
  int x = 0;
  string color;
  
  for (int i=0; i < N; i++) {
    cin >> color;
    
    if (color == "Y") {
      x += 1;
    }
    
    else {
      x += 0;
    }
  }
  
  if (x > 0) {
    cout << "Four" << endl;
  }
  
  else {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())

def calc_x3_y3():
    if (x2 - x1) >= 0 and (y2 - y1) >= 0:
        return [x2 - abs(y2 - y1), y2 + abs(x2 - x1)]
    elif (x2 - x1) >= 0:
        return [x2 + abs(y2 - y1), y2 + abs(x2 - x1)]
    elif (x2 - x1) < 0 and (y2 - y1) >= 0:
        return [x2 - abs(y2 - y1), y2 - abs(x2 - x1)]
    else:
        return [x2 + abs(y2 - y1), y2 - abs(x2 - x1)]

def cakc_x4_y4():
    if (x2 - x1) >= 0 and (y2 - y1) >= 0:
        return  [x1 - abs(y2 - y1), y1 + abs(x2 - x1)]
    elif (x2 - x1) >= 0:
        return  [x1 + abs(y2 - y1), y1 + abs(x2 - x1)]
    elif (x2 - x1) < 0 and (y2 - y1) >= 0:
        return  [x1 - abs(y2 - y1), y1 - abs(x2 - x1)]
    else:
        return  [x1 + abs(y2 - y1), y1 - abs(x2 - x1)]

print(calc_x3_y3()[0], calc_x3_y3()[1],  cakc_x4_y4()[0],  cakc_x4_y4()[1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(int i=(int)(st),i##end=(int)(ed);i<=i##end;++i)
#define DREP(i,st,ed) for(int i=(int)(st),i##end=(int)(ed);i>=i##end;--i)
template<typename T>bool chkmin(T &x,const T &y){return x>y?x=y,1:0;}
template<typename T>bool chkmax(T &x,const T &y){return x<y?x=y,1:0;}
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
template<typename T>T read(){
	T x=0,f=1;
	char c=getchar();
	while((c<'0')||(c>'9')){if(c=='-')f=-1;c=getchar();}
	while((c>='0')&&(c<='9'))x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
#define read() read<int>()
template<typename T>void write(T x,char c){
	static char t[25];
	static int tlen;
	t[tlen=1]=c;
	if(x<0)putchar('-'),x=-x;
	do t[++tlen]=(x%10)^48;
	while(x/=10);
	while(tlen)putchar(t[tlen--]);
}
#define pb push_back
typedef long long ll;
typedef double lf;
const int inf=0x3f3f3f3f;
int n,m,A,B,d[15][15],f[105][105];
int main(){
	A=read(),B=read();
	REP(i,1,A)
		REP(j,1,B)
			d[i][j]=read();
	REP(i,0,100)
		REP(j,0,100)
			REP(x,1,A)
				REP(y,1,B)
					chkmax(f[i][j],d[x][y]-i*x-j*y);
	REP(x,1,A)
		REP(y,1,B){
			int dis=inf;
			REP(i,0,100)
				REP(j,0,100)
					chkmin(dis,f[i][j]+i*x+j*y);
			if(dis>d[x][y])return puts("Impossible"),0;
		}
	n=202,m=10401;
	puts("Possible");
	write(n,' '),write(m,'\n');
	REP(i,2,n/2)
		printf("%d %d X\n",i-1,i);
	REP(i,n/2+2,n)
		printf("%d %d Y\n",i-1,i);
	REP(i,0,100)
		REP(j,0,100)
			printf("%d %d %d\n",1+i,n-j,f[i][j]);
	printf("%d %d\n",1,n);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<stack>

using namespace std;

static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int>G[MAX];
int color[MAX];

void dfs(int r,int c) {
	
	stack<int> S;

	S.push(r);
	color[r] = c;


	while (!S.empty()) {
		int u = S.top(); S.pop();
		for(int i=0;i<G[u].size();i++){
			int v = G[u][i];
			if (color[v] == NIL) {
				color[v] = c;
					S.push(v);
				}
			}
		}
	
	}

void assignColor() {
	int id = 1;
	for (int i = 0; i < n;i++) color[i]=NIL;
	for (int u = 0; u < n; u++) {
		if (color[u] == NIL)dfs(u, id++);
	}
}

int main() {
	
	int  u, k, v,q;
	cin >> n >>v;

	for (int i = 0; i < v; i++) {
		cin >> u >> k;
		G[u].push_back(k);
		G[k].push_back(u);
	}
	assignColor();

	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> u >> k;
		if (color[u] == color[k]) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 9008
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    long long n;
    cin >> n;
    vector <long long> qw (n);
    for (int i=0; i<n; ++i)
        cin >> qw[i];
    vector <long long> dp (n);
    dp[0]=1000;
    long long r=1000/qw[0];
    long long j=0;
    for (int i=1; i<n; ++i)
    {
        long long q=dp[j]%qw[j];
        dp[i]=max(dp[i-1], q+qw[i]*r);
        if (dp[i]/qw[i]>=r)
        {
            r=dp[i]/qw[i];
            j=i;
        }
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define loop(i,n) for(int i=0; i<n; i++)
int main(){
  int n,m,k=0;
  int h[200],m1[200];
  cin >> n;
  loop(i,n){
    cin >> h[i] >> m1[i];
    k++;
  }
  cin >> m;
  loop(i,m){
    cin >> h[i+k] >> m1[i+k];
  }
  vector<pair<int, int> > p(n+m);
  loop(i,n+m){
    p[i] = make_pair(h[i],m1[i]);
  }
  sort(p.begin(),p.end());
  loop(i,n+m){

  }
  loop(i,n+m){
    if(p[i] == p[i-1] && i>0) continue;
    if(p[i].second>=10){
      if(i==0) cout << p[i].first << ":" << p[i].second;
      else cout << " " << p[i].first << ":" << p[i].second;
    }
    else{
      if(i==0) cout << p[i].first << ":" << "0" << p[i].second;
      else cout << " " << p[i].first << ":" << "0" << p[i].second;
    }
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 3116
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            array = array.OrderByDescending(o => o).ToArray();

            var alice = array.Where((z, ind) => ind % 2 == 0).Sum();
            var bob = array.Sum() - alice;

            Console.WriteLine(alice - bob);
        }
    }
}


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

int main() {
 int N;
 cin >>N;
 vector<int> A(N);
 for(int i = 0;i<N;i++){
   cin >> A[i];
 }
 vector<pair<int,int>> p(N);
 for(int i = 0;i<N;i++){
  p[i].first = A[i];
  p[i].second = i+1;
 }
  sort(p.begin(),p.end());
  p.push_back(make_pair(1000000,1000000));
  
  vector<int> q;
  for(int i = 0;i<N;i++){
    if(p[i].first != p[i+1].first){
      q.push_back(p[i].first);
    }
  }
  
  ll M = 1000000000+7;
  
  if(N%2 ==0){
    bool flag1 = false;
    bool flag2 = true;
    vector<int> d(N/2);
    for(int i = 0;i<N/2;i++){
      d[i] = 2*i+1;
    }

    if(q == d) flag1 = true;
    
    int c = 1;
    for(int i = 0;i<N;i++){//同じA[i]に対してペアが二つずつかどうかを確認
      if(p[i].first == p[i+1].first){
        c++;
      }
      else if(p[i].first != p[i+1].first){
        if(c != 2){
          flag2 = false;
          break;
        }
        c = 1;
      }
    }
    if(flag1 && flag2){
      ll ans = 1;
      for(int i = 0;i<N/2;i++){
        ans = ans*2 % M;
    }
    cout << ans << endl;
    }
    else cout << 0 << endl;
 } 
   
   if(N%2 ==1){
    bool flag3 = false;
    bool flag4 = true;
    vector<int> e(N/2 + 1);//Aが0,2,4...N-1から成るかどうかを確認
    for(int i = 0;i<=N/2;i++){
      e[i] = 2*i;
    }

    if(q == e) flag3 = true;
    
    if(p[1].first != 0){ //A[i] = 0の要素が二個以上ある場合を除外
    int f = 1;
    for(int i = 1;i<N;i++){//同じA[i]に対してペアが二つずつかどうかを確認
      if(p[i].first == p[i+1].first){
        f++;
      }
      else if(p[i].first != p[i+1].first){
        if(f != 2){
          flag4 = false;
          break;
        }
        f = 1;
      }
     }
    }
     else if(p[1].first == 0) flag4 = false;
     
    if(flag3 && flag4){
      ll ans2 = 1;
      for(int i = 0;i<N/2;i++){
        ans2 = ans2*2 % M;
    }
    cout << ans2 << endl;
    }
    else cout << 0 << endl;
 } 
  
}



Measured memory_bytes: 2176
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;

int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readll(n); readll(m);

        ll ret = 0;
        ll k = 0;
        for(int x = -2; x <= 2; ++x) {
            ll cand = k+x;
            if ((2*cand<=m) && (cand>=0)) {
                ret = max(ret, min((m-2*cand)/2, n+cand));
            }
        }
        k = m/2;
        for(int x = -2; x <= 2; ++x) {
            ll cand = k+x;
            if ((2*cand<=m) && (cand>=0)) {
                ret = max(ret, min((m-2*cand)/2, n+cand));
            }
        }
        k = (m/2-n)/2;
        for(int x = -2; x <= 2; ++x) {
            ll cand = k+x;
            if ((2*cand<=m) && (cand>=0)) {
                ret = max(ret, min((m-2*cand)/2, n+cand));
            }
        }

        cout << ret << endl;

    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}


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

int n,ans,p[100001];

int main(){
	cin>>n;
	for (int i=1;i<=n;++i)
	cin>>p[i];
	sort(p+1,p+1+n);
	printf("%d\n",p[n/2+1]-p[n/2]);
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    A,B = map(int, lines.pop(0).split(' '))
    if A <= B:
        print(A)
    else:
        print(A-1)
#
# main
#
lines = [x.strip() for x in sys.stdin.readlines()]
#
 # solve !!
#
solve(lines)


Measured memory_bytes: 2940
S = list(input())
S_len = len(S)
S_reverse = list(S[::-1])

ans = 'Yes'

# 条件1 Sは回文である
if S == S_reverse:
    pass
else:
    ans = 'No'

# 条件2
S_2 = S[0:(S_len - 1) // 2]
S_2_reverse = S_2[::-1]
if S_2 == S_2_reverse:
    pass
else:
    ans = 'No'

# 条件3
S_3 = S[(S_len + 3) // 2 - 1:]
S_3_reverse = S_3[::-1]
if S_3 == S_3_reverse:
    pass
else:
    ans = 'No'
 
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)
            r=(r*a)%m;
        b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

int main(){
    ll n,m; cin>>n>>m;
    priority_queue<pair<ll,ll> >q;
    rep(i,0,n)
    {
        ll a; cin>>a;
        q.push(mp(a,a));
        
    }
    while(m--)
    {
        pair<ll,ll> t=q.top();
        q.pop();
        t.first = t.first>>1;
        q.push(mp(t.first,t.first));
    }
    ll sum=0;
    while(!q.empty())
    {
        pair<ll,ll> t = q.top();
        sum+=t.first;
        q.pop();
    }
    cout<<sum<<endl;
    return 0;
    
}

Measured memory_bytes: 2420
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
public:
  ll *fac,*finv,*inv;
  Comb(){
    fac = new ll[1000001];
    finv = new ll[1000001];
    inv = new ll[1000001];
    fac[0] = 1;
    for(int i=1;i<1000001;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000001;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000001;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

ll powmod(ll x,ll n){
  if(n == 0) return 1;
  if(n == 1) return x%MOD;
  if(n%2 == 0){
    ll temp = powmod(x,n/2);
    return (temp*temp)%MOD;
  }
  else{
    ll temp = powmod(x,n/2);
    temp = (temp*temp)%MOD;
    return (temp*x)%MOD;
  }

}

int main(){
   int n,k;
   cin >> n >> k;
   ll a[k+1];
   ll ans = 0;
   for(int i=k;i>0;i--){
     ll temp = powmod(k/i,n);
     for(int j=2;j<k+1;j++){
       if(i*j > k) break;
       temp -= a[i*j];
     }
     a[i] = temp;
     ans += (temp*i)%MOD;
   }
   ans += 2*MOD;
   ans %= MOD;
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 4304
from collections import deque

n = int(input())
li = [list(map(int, input().split())) for _ in range(n)]

graph = [[] for _ in range(n+1)]
for u, k, *v in li:
    for i in v:
        graph[u].append(i)

ans = [-1] * (n+1)

ans[1] = 0
stack = deque([1])
while stack:
    num = stack.popleft()

    for s in graph[num]:
        if ans[s] == -1:
            stack.append(s)
            ans[s] = ans[num] + 1
            
for i, v in enumerate(ans[1:]):
    print(i+1, v)


Measured memory_bytes: 6052
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pci pair<char, int>
#define pic pair<int, char>
#define plvl pair<long long, vector<long long> >
#define pcvc pair<char, vector<char> >


using namespace std;

const int mod = 1e9 + 7;

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

template <typename T>
void show1(vector<T> dp) {
	for(auto d : dp) {
		cout << d << " ";
	}
	cout << endl;
}

template <typename T>
void show2(vector<vector<T> > dp) {
	for(auto d : dp) {
		for(auto dd : d) {
			cout << dd << " ";
		}
		cout << endl;
	}
}

void executeCode() {
	ll n;
	cin >> n;
	vector<ll> A(n);
	ll ans = 0;
	for(int i = 0 ; i < n ; i++) {
		cin >> A[i];
		ans = ans ^ A[i];
	}
	for(int i = 0 ; i < n ; i++) {
		cout << (ans ^ A[i]) << " ";
	}
	cout << endl;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int tt = 1;
	// cin >> tt;
	while(tt--) {
		executeCode();	
	}
	return 0;
}

Measured memory_bytes: 4764
#include<stdio.h>
int main()
{
	int H,i,j,W;
	for(;1;){
		scanf("%d%d",&H,&W);
		if(H==0 && W==0)
		{

			break;
		}
			for(i=1;i<=H;i++){
				for(j=1;j<=W;j++){
					printf("#");
				}
				printf("\n");

			}
			printf("\n");
	}


	return 0;
}



Measured memory_bytes: 2044
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n;
ll K;

int main()
{
	char a;
	int ans=0;
	for(int i=0;i<4;i++){
		scanf("%c",&a);
		if(a == '+')ans ++;
		else ans--;
	}
	printf("%d\n",ans);
	return 0;
}


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

using namespace std;

void coloring(int cur, int par, int ex, vector<int> &res, vector<vector<pair<int, int>>> &G) {
  int nx_color = 1;
  for (auto p : G.at(cur)) {
    int nx = p.first, ind = p.second;
    if (nx == par) continue;
    while (nx_color == ex) ++nx_color;
    res.at(ind) = nx_color;
    coloring(nx, cur, nx_color++, res, G);
  }
}

int main() {
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> G(n);
  for (int i=0; i<n-1; ++i) {
    int a, b;
    cin >> a >> b;
    G.at(a-1).push_back(make_pair(b-1, i));
    G.at(b-1).push_back(make_pair(a-1, i));
  }
  
  int num = -1;
  for (int i=0; i<n; ++i) if (num < (int)G.at(i).size()) num = (int)G.at(i).size();
  
  vector<int> res(n-1);
  coloring(0, -1, -1, res, G);
  cout << num << endl;
  for (int i=0; i<n-1; ++i) cout << res.at(i) << endl;
  return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <string.h>
#include <bitset>

#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define allr(x) x.begin(),x.end(),greater<int>()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << max(a*b,c*d) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,k;cin>>n>>k;
  ll ans=0;
  ll l;
  if(k%2==0){
    l=k/2;
  }
  else{
    l=k;
  }
    for(ll a=l;a<=n;a+=l){
      ll u=floor((double)(n+a)/k);
      ll d=ceil((double)(a+1)/k);
      ans+=(u-d+1)*(u-d+1);
    }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N,K = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

def minat(a)
  point = 0
  for i in 0..a.length-1
    if a[point] > a[i]
      point = i
    end
  end
  point
end

min = minat(a)
if (N-1)%(K-1) == 0
  puts (N-1)/(K-1)
else
  puts (N-1)/(K-1)+1
end


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

int main() {
int a,b,c,d;
	int ab,cd;
	cin >> a >> b >> c >> d;
	ab=a*b;
	cd=c*d;
	if(ab>=cd){
		cout << ab;
	}
	else{
		cout << cd;
	}
	return 0;
}

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

int main() {
	long long n, k; cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	long long tmp = 0, tmp1 = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (a[i] > a[j]) tmp++;
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (a[i] > a[j]) tmp1++;
		}
	}
	cout << ((tmp * k) % MOD + (tmp1 * ((k * (k - 1) / 2) % MOD))) % MOD << endl;

	return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
int n,s;
int rec(int sum,int dig,int cnt);
int main(){
while(1){
scanf("%d %d",&n,&s);
if(n==0&&s==0)break;
printf("%d\n",rec(0,0,0));
}
return 0;
}
int rec(int sum,int dig,int cnt){
if(cnt>n||sum>s) return 0;
if(cnt==n&&sum==s) return 1;
if(dig>9) return 0;
int ret=0;
ret+=rec(sum+dig,dig+1,cnt+1);
ret+=rec(sum,dig+1,cnt);
return ret;
}

Measured memory_bytes: 596
/*author* Priyanshu Shrivastav (from IIT Palakkad) *
 * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
 * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
 * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
 * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
 ** * * * * * * * Now, only God knows * * * * * * */
#include      <bits/stdc++.h>
#include      <ext/pb_ds/assoc_container.hpp>
#include      <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC   optimize ("Ofast")
#pragma GCC   optimize ("unroll-loops")
#pragma GCC   target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define IOS   ios_base::sync_with_stdio(false); cin.tie (nullptr)
#define PREC  cout.precision (10); cout << fixed
#define bg(x) " [ " << #x << " : " << (x) << " ] "
#define x     first
#define y     second
using   ll  = long long;
using   ff  = long double;
using   pii = pair<int,int>;
using   pil = pair<int,ll>;

typedef tree
< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;

struct chash {
   int operator()(pii x) const { return x.x*31 + x.y; }
};
gp_hash_table <pii, int, chash> mp;

#define debug(args...) { \
   /* WARNING : do NOT compile this debug func calls with following flags: // \
    * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \
   string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
   stringstream _ss(_s); \
   istream_iterator<string> _it(_ss); err(_it, args); \
}
void err(istream_iterator<string> it) {
   it->empty(); cerr << " (Line : " << __LINE__ << ")" << '\n';
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
   cerr << fixed << setprecision(15)
      << " [ " <<  *it << " : " << a  << " ] "<< ' ';
   err(++it, args...);
}

const ll inf = (ll)1e18;
const int N = 17;
int n;
int a[N][N];
ll dp[1 << N];
ll wgt[1 << N];
// dp[mask] := max weight that can be achieved if we have grouped 'mask' in optimal way
// wgt[mask] := weight of that mask

void solve() {
   //preprocessing in O(2^n * n^2)
   for (int mask = 0; mask < (1 << n); ++mask) {
      wgt[mask] = 0;
      for (int i = 0; i < n; ++i)
         for (int j = i + 1; j < n; ++j)
            if ((mask & (1 << i)) && (mask & (1 << j)))
               wgt[mask] += a[i][j];
   }

   // O(3^n)
   dp[0] = 0;
   for (int mask = 1; mask < (1 << n); ++mask) {
      for (int sub_mask = mask; sub_mask > 0; sub_mask = (sub_mask - 1) & mask) { // how to get subset of a mask
         dp[mask] = max(dp[mask], dp[mask - sub_mask] + wgt[sub_mask]);
      }
   }
   cout << dp[(1 << n) - 1] << '\n';
}

signed main() {
   IOS; PREC;
   cin >> n;
   for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
         cin >> a[i][j];
   solve();
   return EXIT_SUCCESS;
}



Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  	int N;cin>>N;
  	int A;cin>>A;
  	int B;cin>>B;
  	int C;cin>>C;
  	int D;cin>>D;
  	string S;cin>>S;
  	int iwa;iwa=0;
  	for(int i=A-1;i<C;i++){
    	if(S[i]=='#'){
          iwa+=1;
        }else{
          iwa=0;
        }
      	if(iwa==2){
        	cout<<"No"<<endl;
          return 0;
        }
    }  	
  	for(int i=B-1;i<D;i++){
    	if(S[i]=='#'){
          iwa+=1;
        }else{
          iwa=0;
        }
      	if(iwa==2){
        	cout<<"No"<<endl;
          return 0;
        }
    }
  	int space;space=0;
  	if(C>D){
    	for(int i=B-2;i<D+1;i++){
        	if(S[i]=='.'){
            	space+=1;
            }else{
            	space=0;
            }
          	if(space>2){
            	cout<<"Yes"<<endl;
              	return 0;
            }
        }
    }else{
    	cout<<"Yes"<<endl;
        return 0;    
    }
  	cout<<"No"<<endl;
  	return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    
    int dimA[n][m] = {0};
    int dimb[m] = {0};
    
    int dimans[n] = {0};
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> dimA[i][j];
        }
    }
    
    for(int i = 0; i < m; i++){
        cin >> dimb[i];
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            dimans[i] += dimA[i][j]*dimb[j];
        }
    }
    
    for(int i = 0; i < n; i++){
        cout << dimans[i] << endl;
    }
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

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

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    CINS(int, A, N);
    vector<int> S(N, 0);
    S = A;
    sort(S.begin(), S.end());

    int mid = N / 2;
    for (int i = 0; i < N; i++) {
        if (A[i] < S[mid]) {
            cout << S[mid] << "\n";
        } else {
            cout << S[mid - 1] << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 3712
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
a.sort()
acc = [0]*(n+1)
for i in range(1,n):
    acc[i] = acc[i-1]+a[i-1]
#ddprint(a)
#ddprint(acc)
for i in range(n-1,-1,-1):
    if a[i]>2*acc[i]:
        print(n-i)
        exit()


Measured memory_bytes: 85316