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

enum State {
    NOT,
    VISITED,
};

class E {
public:
    E(int i_in) : i(i_in) {
        for (int j = 0; j < 8; ++j) {
            s[j] = NOT;
        }
    }

    E(const E& e) {
        this->i = e.i;
        for (int j = 0; j < 8; ++j) {
            this->s[j] = e.s[j];
        }
    }


    int s[8];
    int i;
};

int main() {
    int N, M;
    std::cin >> N >> M;

    std::vector<int> v[N];
    int a, b;
    for (int i = 0; i < M; ++i) {
        std::cin >> a >> b;
        --a;
        --b;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    std::queue<E> que;
    que.push(E(0));
    int cnt = 0;
    while (que.empty() == false) {
        E e = que.front(); que.pop();
        e.s[e.i] = VISITED;
        
        bool complete = true;
        for (int i = 0; i < N; ++i) {
            if (e.s[i] != VISITED) {
                complete = false;
                break;
            }
        }

        if (complete) {
            ++cnt;
            continue;
        }

        for (int d : v[e.i]) {
            if (e.s[d] == NOT) {
                E e1(e);
                e1.i = d;
                que.push(e1);
            }
        }
    }

    std::cout << cnt << std::endl;

    return 0;
}


Measured memory_bytes: 384
import numpy as np

X, N = map(int, input().split())
p = list(map(int, input().split()))

abslis = [[]for i in range(102)]*102
for n in range(N):
    abslis[abs(p[n]-X)].append(p[n])

if len(abslis[0]) == 0 :
    print(X)
else :
    # if len(abslis[1])==0:
    #     print()
    for i in range(1,N+1):
        if len(abslis[i]) != 2: 
            if len(abslis[i]) == 0:
                print(X-i)
            elif len(abslis[i]) ==1:
                print( X+(X-abslis[i][0]) )   
            break


Measured memory_bytes: 27252
#D
q=int(input())
C=[]
for i in range(q):
    C.append(list(map(int, input().split())))
for i in C:
    k=min(i[0],i[1])
    score=i[0]*i[1]
    sqrt=int(score**0.5)
    if abs(i[0]-i[1])<=1:
        ans=(k-1)*2
    elif sqrt**2==score:
        ans=sqrt*2-3
    elif sqrt*(sqrt+1)>=score:
        ans=(sqrt-1)*2
    else:
        ans=sqrt*2-1
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define pint pair<int,int>
using namespace std;

ll fact[200001],inv[100001];

ll gcd(ll a,ll b,ll*x,ll*y){
	if(a%b==0){
		*x=0;	*y=1;
		return b;
	}
	ll x1,y1,ans=gcd(b,a%b,&x1,&y1);
	*x=y1;	*y=x1-(a/b)*y1;
	return ans;
}

ll ncr(int n, int r){
	ll ans=fact[n];
	ans*=inv[r];	ans%=mod;
	ans*=inv[n-r];	ans%=mod;
	return ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int i,j,h,w,a,b;	cin>>h>>w>>a>>b;
	h--;	w--;
	fact[0]=1;
	for(i=1;i<=200000;i++){
		fact[i]=(i*fact[i-1])%mod;
	}

	ll x,y;
	gcd(fact[100000],mod,&x,&y);
	inv[100000]=((x%mod)+mod)%mod;

	for(i=100000;i>0;i--){
		inv[i-1]=(i*inv[i])%mod;
	}

	ll ans=0;
	for(j=b;j<=w;j++){
		ans+=(ncr(h-a+j,j)*ncr(a-1+w-j,w-j))%mod;	ans%=mod;
		//cout<<ans<<endl;
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 2560
import Control.Applicative
import Data.List
import System.Exit

comb :: Int -> [a] -> [[a]]
comb 0 _ = [[]]
comb _ [] = []
comb n (x:xs) = [x:y | y <- comb (n-1) xs] ++ comb n xs

solve :: Int -> Int -> Int
solve x y = length $ filter (==y) $ map sum $ comb 3 [1..x]

main = do
    [x, y] <- map (read :: String -> Int) . words <$> getLine
    if x == 0 && y == 0 then exitSuccess
                        else print $ solve x y
    main


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

typedef long long ll;

int main(){
    cout << setprecision(10);
    int N;
    cin >> N;
    long double ans = 0;
    for(int i = 0; i < N; i++){
        long double x;
        cin >> x;
        ans += 1 / x;
    }

    cout << 1 / ans << endl;
    

}


Measured memory_bytes: 256
import itertools
N, D = map(int, input().split())
count = 0

X = []
for i in range(N):
    X.append(list(map(int, input().split())))
for i in list(itertools.combinations(X, 2)):
    f = 0
    for j in range(D):
        f += (i[0][j]-i[1][j])**2
    f **= 0.5
    if f.is_integer():
        count += 1
print(count)


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int a , b , c ;
int main () {
	cin >> a >> b >> c ;
	if ( a == b ) cout << c ;
	else if ( b == c ) cout << a ;
	else cout << b ;
	return 0; 
}

Measured memory_bytes: 256
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n;
  cin >> n;
  if (n >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3132
def chmin(a,b):
    if a > b:
        return b
    else:
        return a

N = int(input())
H = list(map(int, input().split()))

inf = float('inf')
dp = [inf] * N

dp[0] = 0
dp[1] = abs(H[1] - H[0])

for i in range(2,N):
    dp[i] = chmin(dp[i], dp[i-1] + abs(H[i] - H[i-1]))
    dp[i] = chmin(dp[i], dp[i-2] + abs(H[i] - H[i-2]))

print(dp[N-1])

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

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

int a[101010];

int main() {
  int n;cin>>n;
  for(int i=1; i<=n; i++){
    cin>>a[i];
  }
  // int now = 0, next = 1;
  int ans = 0;
  for(int now=0; now<=n; now++){
    if(a[now] < a[now+1]){
      ans += a[now+1]-a[now];
    }
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    ll q;

    cin >> s >> q;

    ll t[q], f[q] = {};
    char c[q];

    rep(i, q){
        cin >> t[i];

        if(t[i] == 1) continue;

        cin >> f[i] >> c[i];
    }

    bool is_inverted = false;

    string prefix = "", suffix = "";

    rep(i, q){
        if(t[i] == 1){
            is_inverted = !is_inverted;
            continue;
        }

        if(is_inverted){
            if(f[i] == 1){
                suffix.append(1, c[i]);
            }
            else{
                prefix.append(1, c[i]);
            }
        }
        else{
            if(f[i] == 1){
                prefix.append(1, c[i]);
            }
            else{
                suffix.append(1, c[i]);
            }
        }
    }

    string ans = "";

    if(is_inverted){
        reverse(suffix.begin(), suffix.end());
        reverse(s.begin(), s.end());
        ans = suffix + s + prefix;
    }
    else{
        reverse(prefix.begin(), prefix.end());
        ans = prefix + s + suffix;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main() {
    short a, b;
    char op;

    int res;
    while (true){
        // input
        cin >> a >> op >> b;

        // process
        if (op == '?'){
            break;
        } else if (op == '+'){
            res = a + b;
        } else if (op == '-'){
            res = a - b;
        } else if (op == '*'){
            res = a * b;
        } else if (op == '/'){
            res = a / b;
        }

        // output
        cout << res << endl;
    }

    return 0;
}



Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include <cmath>

using namespace std;
#define rep(i, s, n) for(int i = s;i<n;i++)
#define repe(i, s, n) for(int i = s;i<=n;i++)
using ll = long long int;

int main(void) {
    int N, Y;
    cin >> N >> Y;
    bool is_find = false;
    repe(x, 0, N && !is_find) {
        repe(y, 0, N) {
            int z = N - x - y;
            ll sum = 10000 * x + 5000 * y + 1000 * z;
            if (sum == Y && z>=0) {
                cout << x << " " << y << " " << z << endl;
                is_find = true;
                break;
            }
        }
    }
    if (!is_find) {
        cout << "-1 -1 -1" << endl;
    }
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc126/tasks/abc126_c

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x])
                swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
};

// X, Yのグループが何個あるか調べればいい
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;

    UnionFind tree(n + 1);
    set<int> st;

    for (int i = 0; i < m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        tree.unionSet(x, y);
    }
    for (int i = 1; i <= n; i++) {
        st.insert(tree.root(i));
    }
    cout << st.size() << endl;

    return 0;
}

Measured memory_bytes: 5376
#include <stdio.h>
#include <algorithm>
int main( void )
{
	int A,B,K ;
	scanf("%d %d %d", &A, &B, &K ) ;
	int d = std::min(A,B)+1;
	while( K ) {
		for( d-- ; d >= 0 ; d-- ) {
			if( A % d == 0 && B % d == 0 ) break ;
		}
		K-- ;
	}
	printf("%d\n", d ) ;
	return 0 ;
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    in a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    if(t*(v-w)>=abs(a-b)) cout<<"YES";
    else cout<<"NO";
  cout<<endl;
}/*
./problem.exe
*/

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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

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

    bool ok = true;
    for(int i = 0; i < n; i++)
    {
        if(a[i] != i + 1)
        {
            if(a[a[i] - 1] != i + 1 || !ok)
            {
                cout << "NO";
                return 0;
            }
            swap(a[i], a[a[i] - 1]);
            ok = false;
        }
    }
    cout << "YES";

    return 0;
}


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

bool solve(int n) {
  int cnt = 0;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (i == n % i) {
        cnt++;
      } else {
        cnt += 2;
      }
    }
  }
  if (cnt == 8) {
    return true;
  } else {
    return false;
  }
}

int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i += 2) {
    if (solve(i)) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()


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

	if (N == M)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> values(N + 1);
    vector<int> ruisekiValues(N + 2);
    vector<int> revRuisekiValues(N + 2);
    //value, index
    vector<pair<int, int>> minusValues(0);
    for (int i = 1; i <= N; i++)
    {
        int v;
        cin >> v;
        values[i] = v;
        if (values[i] < 0)
        {
            minusValues.push_back(make_pair(values[i], i));
        }
    }
    sort(minusValues.begin(), minusValues.end());
    ruisekiValues[0] = 0;
    for (int i = 1; i <= N; i++)
    {
        ruisekiValues[i] = values[i] + ruisekiValues[i - 1];
    }
    revRuisekiValues[N + 1] = 0;
    for (int i = N; i >= 1; i--)
    {
        revRuisekiValues[i] = values[i] + revRuisekiValues[i + 1];
    }
    int answer = 0;

    int maxAddMove = min(K, N);
    for (int i = 1; i <= maxAddMove; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            int left = j;
            int right = N + 1 - (i - j);
            int count = ruisekiValues[left] + revRuisekiValues[right];
            int removeCount = K - i;
            for (pair<int, int> minusValue : minusValues)
            {
                if(removeCount == 0){
                    break;
                }
                if (minusValue.second <= left || right <= minusValue.second){
                    count -= minusValue.first;
                    removeCount--;
                }
            }
            answer = max(answer, count);
        }
    }
    cout << answer << endl;
    return 0;
}

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

int main(void)
{
	long long int A, B, K;
	cin >> A >> B >> K;
	long long int a, b;
	if (A >= K) {
		a = A - K;
		b = B;
	}
	else {
		a = 0;
		b = (A + B > K) ? (A + B - K) : 0;
	}
	cout << a << " " <<b << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
from copy import deepcopy
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,r = LI()
if n >= 10:
  print(r)
else:
  print(r+100*(10-n))


Measured memory_bytes: 38384
#include<cstdio>

int main(){
	int A, B;
	scanf("%d %d", &A, &B);
	int answer = 0;
	for (int i = A; i <= B; ++i){
		int number = i;
		int ichi = number%10;
		number /= 10;
		int juu = number%10;
		number /= 10;
		int hyaku = number%10;
		number /= 10;
		int sen = number%10;
		number /= 10;
		int man = number%10;
		if(ichi == man && juu == sen)
			answer++;
	}
	printf("%d\n", answer);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <functional>

int main() {
  size_t N, K;
  scanf("%zu %zu", &N, &K);

  std::vector<intmax_t> a(N);
  for (size_t i=0; i<N; ++i)
    scanf("%jd", &a[i]);

  std::vector<intmax_t> b;
  b.reserve(N*N);
  for (size_t i=0; i<N; ++i) {
    intmax_t cur=0;
    for (size_t j=i; j<N; ++j) {
      cur += a[j];
      b.push_back(cur);
    }
  }

  // for (size_t i=0; i<b.size(); ++i)
  //   fprintf(stderr, "%jd%c", b[i], i+1<b.size()? ' ':'\n');

  for (size_t i=42; i--;) {
    std::vector<intmax_t> bb;
    for (size_t j=0; j<b.size(); ++j) {
      if (b[j]>>i & 1) bb.push_back(b[j]);
    }
    if (bb.size() >= K)
      b = std::move(bb);
  }

  // for (size_t i=0; i<b.size(); ++i)
  //   fprintf(stderr, "%jd%c", b[i], i+1<b.size()? ' ':'\n');

  std::sort(b.begin(), b.end(), std::greater<>());
  intmax_t res=b[0];
  for (size_t i=1; i<K; ++i)
    res &= b[i];
  printf("%jd\n", res);
}


Measured memory_bytes: 7036
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define prin(arg) cout<<arg
#define scan(arg) cin>>arg
#define newl cout<<"\n"
using namespace std;
typedef vector<int> vi;
int N,M;
vi d;
vi divisor(int a){//aの約数が全列挙されたベクトルを返す
  vi res;
  for(int i=1;i*i<=a;i++){//iはsqrt(a)まで調べれば十分
    if(a%i==0){
      res.push_back(i);
      if(i!=a/i) res.push_back(a/i);
    }
  }
  return res;
}
bool C(int x){//二分探索における条件
  return x>=N;
}
int binary_search(int a,int b){//[a,b]で二分探索
  int lb=a,ub=b;
  while(ub-lb>1){
    int mid=(lb+ub)/2;
    if(C(d[mid])) ub=mid;
    else lb=mid;
    //    prin(lb);prin(" ");prin(ub);newl;
  }
  return d[ub];
}
int main(){
  scan(N);scan(M);
  d=divisor(M);
  sort(d.begin(),d.end());
  int ub=binary_search(-1,d.size()-1);
  prin(M/ub);newl;
  
  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 3e18;
const double INFD = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1);
const int MOD = 998244353;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 200005;
const int MAXV = 3;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;

int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        int cnt = 0;
        for (int x = 1; x * x <= i; x++) {
            for (int y = 1; y * y <= i - x * x; y++) {
                for (int z = 1; z * z <= i - x * x - y * y - x * y; z++) {
                    if (x * x + x * y + x * z + y * y + y * z + z * z == i) {
                        cnt++;
                    }
                }
            }
        }
        printf("%d\n", cnt);
    }
    return 0;
}

Measured memory_bytes: 3712
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int N = scanner.nextInt();
        int i = scanner.nextInt();
        System.out.println(N-(i-1));
    }

    private class MyScanner {
        String[] s;int i;BufferedReader br;String reg = " ";
        MyScanner () { s = new String[0];i = 0;br = new BufferedReader(new InputStreamReader(System.in)); }
        public String next() {
            try {
                if (i < s.length) return s[i++]; String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0); i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 23124
s = input()
n = (len(s)-1)//2
s = list(s)
rs = s[::-1]
lw = s[0:n]
rw = s[n+1:]
lws = lw[::-1]
rws = rw[::-1]

if s != rs:
    print("No")
elif (rw != rws) or (lw != lws):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using i64 = long long;

std::vector<long long> fact, inv;

constexpr auto pow(long long x, long long n, const long long mod) {
    long long ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

constexpr auto inverse(const long long x, const long long p) {
    return pow(x, p - 2, p);
}

void init_factorial(const int n, const long long mod) {
    fact.resize(n + 1);
    inv.resize(n + 1);
    fact[0] = 1;
    for (long long i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    inv[n] = inverse(fact[n], mod);
    for (long long i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

int main() {
    constexpr i64 mod = 1000000007;
    int n, k;
    std::cin >> n >> k;
    init_factorial(n, mod);
    std::vector<int> a(k);
    for(auto &e : a) std::cin >> e;

    auto f = [&](const int c, const int j) { return fact[n - j] * inv[n - c] % mod * inv[c - j] % mod; };

    std::vector<i64> dp(n + 1);
    dp[0] = 1;
    for (const auto c : a) {
        std::vector<i64> next(n + 1);
        for (int j = 0; j <= n; j++) for (int l = 0; j + l <= n && l <= c; l++) {
            next[j + l] = (next[j + l] + dp[j] * f(c, l) % mod * inv[l] % mod) % mod;
        }
        std::swap(dp, next);
    }

    std::cout << dp[n] * fact[n] % mod << std::endl;

    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use rand::random;

const MOD: usize = 1_000_000_007;

#[fastout]
fn main() {
    input! {
    n: usize,
    a: [usize; n]
    }
    let mut a_max = *(a.iter().max().unwrap());
    let mut k = 0;
    while a_max > 0 {
        a_max /= 2;
        k += 1;
    }
    let mut ans = 0;
    for i in 0..k {
        let (mut p, mut q) = (0, 0);
        for j in 0..n {
            if a[j] & 1 << i > 0 {
                p += 1;
            } else {
                q += 1;
            }
        }
        ans += (p * q) % MOD * (2usize.pow(i as u32) % MOD);
        ans %= MOD;
    }
    println!("{}", ans);
}


Measured memory_bytes: 9864
#include<bits/stdc++.h>
#define FIO "RGB Coloring"
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double llf;
typedef std::pair<int,int> pr;
template<typename T> inline T gcd(T a,T b){T t;if(a<b){while(a){t=a;a=b%a;b=t;}return b;}else{while(b){t=b;b=a%b;a=t;}return a;}}
template<typename T> inline T sqr(T x){return x*x;}
template<typename T> inline bool Min(T &x , T y) {return x>y?x=y,1:0;}
template<typename T> inline bool Max(T &x , T y) {return x<y?x=y,1:0;}
#define pb push_back
#define MP make_pair
#define xx first
#define yy second
using namespace std;
inline ll read()
{
	ll x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}

const int mod = 998244353;
const int maxn = 3e5 + 10;
ll ans = 0 , n , a , b , k , fac[maxn] , inv[maxn];

inline ll qpow(ll x , int y)
{
	ll res = 1;
	for(; y; y >>= 1 , x = x * x % mod)
		if(y & 1) res = res * x % mod;
	return res;
}

inline ll C(int n , int m) {if(n < m) return 0LL; return fac[n] * inv[m] % mod * inv[n - m] % mod;}

int main()
{
	n = read(); a = read() , b = read() , k = read();
	if(k > (a + b) * n) return puts("0") , 0; 
	fac[0] = inv[0] = 1;
	for(int i = 1; i <= 300000; i ++) fac[i] = fac[i - 1] * i % mod;
	inv[300000] = qpow(fac[300000] , mod - 2);
	for(int i = 300000 - 1; i; i --) inv[i] = inv[i + 1] * (i + 1) % mod;
	for(int i = 0; i <= n; i ++)
	{
		ll now = 1LL * i * a , left = k - now;
		if(now > k) continue;
		if(left % b) continue;
		int p = left / b;
		ans = (ans + C(n , i) * C(n , p) % mod) % mod;
	}
	printf("%lld\n" , ans);

	return 0;
}

Measured memory_bytes: 4992
/*

Coded and Decoded by : Yash Kapoor

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

// s.find_by_order(index);
// s.order_of_key(value);

#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll, ll>
#define vl vector<ll>
#define sl set<ll>
#define vll vector<pll>
#define ml map<ll, ll>
#define mll map<pll, ll>
#define all(a) a.begin(), a.end()
#define F first
#define S second
#define sz(x) (ll) x.size()
#define dl '\n'
#define elasped_time  1.0 * clock() / CLOCKS_PER_SEC
#define why (ll)1000000007
//#define why (ll)998244353
#define lp(i, a, b) for (ll i = a; i < b; ++i)
#define lpr(i, a, b) for (ll i = a; i >= b; i--)
#define lpd(i, x) for (auto i : x)
#define ios                                                                                                            \
  ios_base::sync_with_stdio(false);                                                                                    \
  cin.tie(0);                                                                                                          \
  cout.tie(0);

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base, ll power, ll mod)
{
  ll result = 1;
  while (power) {
    if (power % 2)
      result = (result * base) % mod;
    base = (base * base) % mod;
    power /= 2;
  }
  return result;
}

ll inverse(ll base, ll mod) { return fast_power(base, mod - 2, mod); }
int test = 1;
vl adj[200005];
vl visited(200005);
ll n,ans,m,c,v;

void solve() {
  cin >> n;
  vl a(n); lp(i,0,n) cin >> a[i];
  ll dp[n];
  dp[0] = a[0];
  lp(i,1,n){
    dp[i] = dp[i-1] + a[i];
  }
  ll ans = 0;
  lp(i,1,n){
    ans += (dp[i-1]%mod * a[i]%mod ) % mod;
    ans %= mod;
  }
  cout << ans%mod << dl;
} 

int main()
{
  // #ifndef ONLINE_JUDGE 
  //   freopen("input.txt", "r", stdin);
  //   freopen("output.txt", "w", stdout);
  // #endif
  ios 
  ll t = 1;
  //cin >> t;
  while (t--) 
  {
    //cout << "Case #" << test++ << ": ";
    solve();
  }
  //cerr<<endl<<"समय गुज़रा : "<<elasped_time<<dl;
}

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

int main(){
	vector<int> s(10000,0);
	vector<int> t(500,0);
	int n,q,cnt=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	cin>>q;
	for(int j=0;j<q;j++){
			cin>>t[j];
	}
	for(int i=0;i<q;i++){
		for(int j=0;j<n;j++){
			if(t[i]==s[j]){
				cnt++;
				break;
			}
		}
	}cout<<cnt<<endl;
}


Measured memory_bytes: 3144
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long 
const int mod=1e9+7;
const int inf=1e9+7;

//const int maxn=
 
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    int n;
    cin>>n;
    string str;
    cin>>str;
    
    int cnt=1;
    
    char now=str[0];
    
    for(int i=1;i<str.size();i++)
    {
    	if(str[i]!=now)
    	{
    		cnt++;
    		now=str[i];
		}
	}
    
    cout<<cnt<<endl;
     
    return 0;
}

Measured memory_bytes: 512
from collections import defaultdict, deque


def main():
    N, M = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(M)]

    route = defaultdict(list)
    for ab in AB:
        route[ab[0]].append(ab[1])
        route[ab[1]].append(ab[0])

    ans = [-1] * N
    ans[0] = 0
    que = deque([1])

    while(len(que) != 0):
        v = que.popleft()

        for nv in route[v]:
            if ans[nv-1] != -1:
                continue

            ans[nv-1] = v
            que.append(nv)

    if -1 in ans:
        print('No')
        exit()

    print('Yes')
    for i in range(1, N):
        print(ans[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 62132
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define dump(a) cout << a << endl; 

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文
int main() {
	string a,b;
	cin >> a >> b;
	string s = a + b;
	bool ans = true;
	for (int i = 0; i < 5; i++) {
		if (s.at(i) != s.at(5 - i)) ans = false;
	}
	ansYES(ans);
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC118_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = ab[0];
            var b = ab[1];
            Console.WriteLine(b % a == 0 ? a + b : b - a);
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<string>

int Swap(int* a,int* b);

int main()
{
    int A,B,C;
    int X,Y,Z;
    std::cin >> X >> Y >> Z;

    A=X;
    B=Y;
    C=Z;

    Swap(&A,&B);
    Swap(&A,&C);
 
    std::cout << A <<" "<< B <<" "<< C;

    return 0;
}

int Swap(int* a,int* b)
{
    int buf;
    buf = *a;
    *a = *b;
    *b = buf;

    return 0;
}

Measured memory_bytes: 3572
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long n = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			char[] c = new char[] { '?', 'A', 'B', 'C' };
			long[,] dp = new long[s.Length + 1, 4];
			dp[0, 0] = 1;
			for (int i = 1; i <= s.Length; i++) {
				dp[i, 0] = (s[i - 1] == '?' ? 3 : 1) * dp[i - 1, 0] % mod;
				for (int j = 1; j < 4; j++) {
					dp[i, j] = ((s[i - 1] == '?' || s[i - 1] == c[j] ? 1 : 0) * dp[i - 1, j - 1] + (s[i - 1] == '?' ? 3 : 1) * dp[i - 1, j]) % mod;
				}
			}
			//for (int j = 0; j < dp.GetLength(1); j++) {
			//	for (int i = 0; i < dp.GetLength(0); i++) {
			//		System.Diagnostics.Debug.Write($"{dp[i, j]} ");
			//	}
			//	System.Diagnostics.Debug.WriteLine($"");
			//}
			Console.WriteLine(dp[s.Length,3]);


			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 14432
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
int main(){
    set<string>s1;
    int n,ans=0;
    string s;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
         if(s1.find(s)==s1.end())
        {
            s1.insert(s);
            ans++;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 19180
<?php

$inp = str_split(trim( fgets( STDIN ) ));
$inp2 = str_split(trim( fgets( STDIN ) ));

$count = 0;

for ($i = 0; $i < count($inp); $i++) {
  if ($inp[$i] !== $inp2[$i]) {
    ++$count;
  }
}

echo $count;

?>

Measured memory_bytes: 41164
#include <bits/stdc++.h>
 
using namespace std;
#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

int a,b,c;
void solve() {
  swap(a,b);
  swap(a,c);
  cout << a << " "  << b << " " << c;
}

void input() {
  cin >> a >> b >> c;
}
 
int main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
//Shell sort

import java.util.*;
import java.lang.*;


public class Main {

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

        int n = sc.nextInt();
        a = new int[n];
        
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        
        //System.out.println("---");
        
        count = 0;
        int m = 0;
        ArrayList<Integer> g = new ArrayList<>();
        g.add(1);
        while (true) {
            int h = 3 * g.get(m) + 1;
            //System.out.println("h = " + h);
            
            if (h < n) {
                g.add(h);
            } else {
                break;
            }
            m++;
        }
        m++;
        System.out.println(m);
        for (int i = m - 1; i >= 0; i--) {
            System.out.print(g.get(i));
            if (i != 0) {
                System.out.print(' ');
            }
        }
        System.out.println();
        
        for (int i = m - 1; i >= 0; i--) {
            insertionSort(n, g.get(i));
        }
        System.out.println(count);
        for (int i = 0; i < n; i++) {
            System.out.println(a[i]);
        }
    }
    
    static void insertionSort(int n, int g) {
        for (int i = g; i < n; i++) {
            int v = a[i];
            int j = i - g;
            while (j >= 0 && a[j] > v) {
                a[j + g] = a[j];
                j = j - g;
                count++;
            }
            a[j + g] = v;
        }
        
    }
}


Measured memory_bytes: 302428
#include <stdio.h>
#define stn 200000000;
typedef struct{
  char mk;
  int num;
}C;
void merge(C A[],int n,int left,int mid,int right);
void mergeSort(C A[],int n,int left,int right);
int partition(C A[],int n,int p,int r);
void quickSort(C A[],int n,int p,int r);
int isStable(C in[],C out[]);
C L[50000],R[50000];
int n;

int main(){

  int i;
  C A[100001],A2[100001];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c%d",&A[i].mk,&A[i].num);
    A2[i]=A[i];
  }
  
  mergeSort(A,n,0,n);
  quickSort(A2,n,0,n-1);
  
  if(isStable(A,A2)) printf("Stable\n");
  else printf("Not stable\n");

  for(i=0;i<n;i++) printf("%c %d\n",A2[i].mk,A2[i].num);
  
  return 0;
}

int partition(C A[],int n,int p,int r)
{
  int i,j;
  C x,temp;
  
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j].num<=x.num){
      i=i+1;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
    }
  }
  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp;

  return i+1;

}

void quickSort(C A[],int n,int p,int r)
{
  int q;
  
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}
 
void merge(C A[],int n,int left,int mid,int right)
{
  int i,j=0,k;  
  int n1=mid-left;
  int n2=right-mid;
 
  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1].num=R[n2].num=stn;
  i=0;
  for(k=left;k<right;k++){
    if(L[i].num<=R[j].num){
      A[k]=L[i++];
    }
    else A[k]=R[j++];
  }
}
 
void mergeSort(C A[],int n,int left,int right)
{
  int mid;
 
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int isStable(C A[],C A2[])
{
  int i;
  
  for(i=0;i<n;i++){
    if( A[i].num != A2[i].num || A[i].mk != A2[i].mk )
      return 0;
  }

  return 1;
}

Measured memory_bytes: 2948
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int N,D;
	scanf("%d %d",&N,&D);

	bool check[25];
	for(int i = 0; i < N; i++){

		check[i] = false;
	}

	int ans = 0;

	for(int i = 0; i < N; i++){
		if(check[i])continue;

		ans++;

		for(int k = 0; k <= 2*D && i+k < N; k++){

			check[i+k] = true;
		}
	}

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


	return 0;
}


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

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    while(true) {
        C -= B;
        if (C <= 0) {
            cout << "Yes" << endl;
            break;
        }
        A -= D;
        if (A <= 0) {
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<int> A(N);
  map<ll,ll> mp;
  for(int i=0;i<N;i++)cin>>A[i];
  ll sum=0ll;
  for(int i=0;i<N;i++){
    sum+=A[i];
    mp[sum]++;
  }
  mp[0]++;
  ll ans=0ll;
  for(auto e : mp){
    ans+=e.second*(e.second-1)/2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 13568
from collections import defaultdict
N = int(input())

A = list(map(int, input().split()))

ans = 1
d = defaultdict(int)

for i,n in enumerate(A):
    if n == 0:
        ans *= (3-d[n])
        d[n] += 1
    else:
        ans *= (d[n-1] - d[n])
        d[n] += 1

print(ans % (10**9+7))

Measured memory_bytes: 18656
/*
 * Matheus Oliveira
 * 16/06/2018
 * b.cpp
*/
 
#include <bits/stdc++.h>
using namespace std;

int main() {
	int d, n, ans = 1, aux;
	scanf("%d %d", &d, &n);

	if(n == 100) {
		if(d == 0) printf("101\n");
		if(d == 1) printf("10100\n");
		if(d == 2) printf("1010000\n");
		return 0;
	}

	while(d > 0) {
		ans *= 100;
		d--;
	}

	aux = ans;
	while(n > 1) {
		ans += aux;
		n--;
	}

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

Measured memory_bytes: 256
n = int(input())
x = list(map(int, input().split()))
     
sx = sorted(x)
xm = sx[n//2-1]
xp = sx[n//2]
     
for i in range(n):
    if x[i] <= xm:
        b = xp
    else:
        b = xm
    print(b)

Measured memory_bytes: 25220
INF = 10**10


def partition(ary, p, r):
    x = ary[r][1]
    i = p - 1
    for j in range(p, r):
        if ary[j][1] <= x:
            i += 1
            ary[i], ary[j] = ary[j], ary[i]

    ary[i + 1], ary[r] = ary[r], ary[i + 1]

    return i + 1


def quick_sort(ary, p, r):
    if p < r:
        q = partition(ary, p, r)
        quick_sort(ary, p, q - 1)
        quick_sort(ary, q + 1, r)


def merge(ary, left, mid, right):
    lry = ary[left:mid]
    rry = ary[mid:right]
    lry.append(('INF', INF))
    rry.append(('INF', INF))

    i = 0
    j = 0
    for k in range(left, right):
        if lry[i][1] <= rry[j][1]:
            ary[k] = lry[i]
            i += 1
        else:
            ary[k] = rry[j]
            j += 1

    return right - left


def merge_sort(ary, left, right):
    cnt = 0
    if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(ary, left, mid)
        cnt += merge_sort(ary, mid, right)
        cnt += merge(ary, left, mid, right)

    return cnt


if __name__ == '__main__':
    import sys
    from copy import deepcopy

    n = int(input())
    ary = [(lambda x: (x[0], int(x[1])))(line.strip().split()) for line in sys.stdin]

    qary = deepcopy(ary)
    mary = deepcopy(ary)
    quick_sort(qary, 0, n - 1)
    merge_sort(mary, 0, n)

    if qary == mary:
        print('Stable')
    else:
        print('Not stable')
    [print(*_) for _ in qary]



Measured memory_bytes: 19292
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;
import java.util.stream.Stream;;

public class Main {

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

  public void run() {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String[] lines = br.readLine().split(" ");
      int  n = Integer.parseInt(lines[0]);
      long z = Long.parseLong(lines[1]);

      final Pattern delim = Pattern.compile(" ");
      long d = delim
        .splitAsStream(br.readLine())
        .mapToLong(Long::parseLong)
        .map(l -> Math.abs(l-z))
        .reduce((e1,e2) -> gcd(e1, e2))
        .getAsLong();
      
      System.out.println(d);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
  
  public long gcd(long x, long y) {
    if( x<y ) {
      long tmp = x; x = y; y = tmp;
    }
    if( (x%y) == 0 ) return y;
    else return gcd(y,x%y);
  }
}

Measured memory_bytes: 39372
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] b = new int[n];
		int k = sc.nextInt();
		int q = sc.nextInt();
		int a;
		for(int i = 0; i < q; i++){
			a = sc.nextInt();
			b[a-1] ++;
		}
		for(int i = 0; i < n; i++){
			if(b[i] > q-k){
				System.out.println("Yes");
			}
			else{
				System.out.println("No");
			}
		}


	}

}

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

int main(){
	int n,a;
	set<int> s;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		s.insert(a);
	}
	//cout<<s.size()<<endl;
	int ans=n-s.size();
	if(ans%2==1)ans+=1;
	cout<<n-ans<<endl;
	return 0;
}
	
	
	

Measured memory_bytes: 4864
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
long long pow2(int n) {
  if (n == 0) {
	  return 1;
	}
  if (n % 2 == 1) {
	  return 2 * pow2(n - 1);
	}
  else {
	  long long a = pow2(n / 2);
	  return a * a;
	}
}

long long ans(long long N, long long X) {
  if (N == 0) {
	  return 1;
	}
  if (X == 1) {
	  return 0;
	}
  if (X <= pow2(N + 1) - 2) {
	  return ans(N - 1, X - 1);
	}
  if (X == pow2(N + 1) - 1) {
	  return pow2(N);
	}
  if (X <= pow2(N + 2) - 4) {
	  return pow2(N) + ans(N - 1, X - (pow2(N + 1) - 1));
	}
  return pow2(N + 1) - 1;
}

int main() {
  long long N, X;
  cin >> N >> X;
  cout << ans(N, X) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
          #include <chrono>
        
          using namespace std;
          using namespace std::chrono; 
       
          typedef long long int ll;
       
          #define MOD (ll)(1e9+7)
          #define endl "\n"
          #define pb push_back
          #define TEST_CASES  ll t;cin>>t;while(t--)
          #define forn(i,a,n) for (int i = a; i < n; ++i)
          #define f first
          #define s second
          #define all(x) x.begin(), x.end()


          
          ll powD(ll x,ll y){
            ll res = 1;
            while(y > 0){
              if(y & 1)
                res = (res*x);
              x = (x*x);
              y = y>>1;
            }
            return res;
          }
          int main()
          {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            int n;
            cin>>n;
            vector<int> a(n);
            int total = 0;
            forn(i,0,n){
              cin>>a[i];
              total ^= a[i];
            }
            vector<int> ans(n);
            forn(i,0,n){
              ans[i] = total^a[i];
            }
            forn(i,0,n){
              cout<<ans[i]<<" ";
            }
            cout<<endl;

          }

          
        


Measured memory_bytes: 4736