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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int main(){
    int N;
    string str;
    cin >> N >> str;
    string RGB = "RGB";
    vector<int> S(3*N);
    for(int i=0; i<3*N; i++) S[i] = RGB.find(str[i]);

    vector<bool> start(3*N), term(3*N);
    for(int t=0; t<2; t++){
        int num[3] = {0};
        for(int i=0; i<3*N; i++){
            num[S[i]]++;
            if(num[0] && num[1] && num[2]){
                (t ? start : term)[i] = 1;
                for(int k=0; k<3; k++) num[k]--;
            }
        }
        reverse(S.begin(), S.end());
    }
    reverse(start.begin(), start.end());
    
    int64_t ans = 1;
    int st[3] = {0}, ready[3] = {0};
    for(int i=0; i<3*N; i++){
        int a = S[i];
        if(start[i]){
            st[a]++;
        }else if(term[i]){
            mul(ans, ready[a]);
            ready[a]--;
        }else{
            int s = (a+1)%3, t = (a+2)%3;
            if(st[t]) swap(s, t);
            mul(ans, st[s]);
            st[s]--;
            ready[t]++;
        }
    }
    for(int i=1; i<=N; i++) mul(ans, i);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1796
n,y=gets.split.map(&:to_i)
ans=[0,0,0]
ok=false
0.upto(n) { |i|
  0.upto(n-i) { |j|
    k=n-i-j
    if i*1000+j*5000+k*10000 == y
      ans = [k,j,i]
      ok=true
      break
    end
  }
  break if ok
}
puts ok ? ans*" " : [-1]*3*" "


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cout << fixed << setprecision(10);

    int n;
    cin >> n;
    vector<int> a(n);
    vector<ll> cnt(n);
    rep(i, n){
        int x;
        cin >> x;
        a[i] = x - 1;
        cnt[x-1]++;
    } 

    ll sum = 0;
    rep(i, n){
        sum += (ll)(cnt[i] * (cnt[i]-1) / 2);
    }

    rep(i, n){
        ll ans = sum - (ll)(cnt[a[i]] * (cnt[a[i]]-1) / 2) + (ll)((cnt[a[i]]-1)*(cnt[a[i]]-2) / 2);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
int main()
{
    string a;
    cin >> a;
    if (a[0] != 'A')
    {
        printf("WA\n");
        return 0;
    }
    int c = 0, indc = 0;
    for (int i = 2; i < a.length() - 1; ++i)
    {
        if(a[i] == 'C')
        {
            ++c;
            indc = i;
        }
    }
    if (c != 1)
    {
        printf("WA\n");
        return 0;
    }
    for (int i = 1; i < a.length(); ++i)
    {
        if (i == indc)
        {
            continue;
        }
        if ('a' > a[i] || a[i] > 'z')
        {
            printf("WA\n");
            return 0;
        }
    }
    printf("AC\n");
}


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

using namespace std;

class Solution {
public:
	/* time: O(n^2), space: O(n^2) */
	int league(const vector<vector<int>>& A) {
		/* Build the dependency graph of all matches */
		const int n = A.size();
		vector<vector<int>> adjLists(n * n);
		for (int i = 1; i <= n; ++i) {
			int prevMatch = -1;
			for (int j : A[i - 1]) {
				const int playerX = min(i - 1, j - 1), playerY = max(i - 1, j - 1);
				const int currMatch = playerX * n + playerY;
				if (prevMatch != -1)
					adjLists[prevMatch].push_back(currMatch);
				prevMatch = currMatch;
			}
		}

		/* Run topological sort (Kahn's algorithm) */
		vector<int> inDegree(n * n);
		for (const auto& adjList : adjLists) {
			for (int v : adjList)
				++inDegree[v];
		}

		queue<int> q;
		for (int i = 0; i < n * n; ++i) {
			if (!inDegree[i])
				q.push(i);
		}

		int ans = 0, nVisited = 0;
		for (int depth = 1; !q.empty(); ++depth) {
			for (int i = q.size(); i > 0; --i) {
				const int u = q.front();
				++nVisited, q.pop();
				for (int v : adjLists[u]) {
					if (inDegree[v] && !--inDegree[v])
						q.push(v);
				}
			}
			++ans;
		}
		if (nVisited < n * n)
			return -1; /* failed */
		return ans;
	}
};

int main() {
	int n;
	cin >> n;
	vector<vector<int>> A(n, vector<int>(n - 1));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n - 1; ++j)
			cin >> A[i][j];
	}

	Solution sol;
	int ans = sol.league(A);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 49188
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define INF 1000000000000000LL
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	int N,M,K;cin>>N>>M>>K;
	vector<set<int>>f(N+1);
	vector<set<int>>b(N+1);
	rep(i,0,M){
		int A,B;cin>>A>>B;
		f[A].insert(B);
		f[B].insert(A);
	}
	rep(i,0,K){
		int A,B;cin>>A>>B;
		b[A].insert(B);
		b[B].insert(A);
	}
	
	ll ans;
	queue<int> q;
	vi check(N+1);
	vi cnt(N+1);
	rep(i,1,N+1){
		ans=0;
		if(check[i]>0){
			ans=cnt[check[i]]-f[i].size()-1;
			for( auto u:b[i] ){
				if(check[i]==check[u]){
					ans--;
				}
			}
			cout<<ans<<' ';
			continue;
		}
		else{
			check[i]=i;
			cnt[i]=1;
		}

		for( auto u:f[i] ){
			DBG("i=",i,"u=",u);
			q.push(u);
		}
		while(!q.empty()){
			int v=q.front();q.pop();
			if(check[v]>0){
				continue;
			}
			else{
				check[v]=i;
				cnt[i]++;
				for( auto w:f[v] ){
					DBG("w=",w,"","");
					if(check[w]>0){
						continue;
					}
					else{
						q.push(w);
					}
				}
			}
		}
		DBG("i=",i,"cnt[i]=",cnt[i]);
		ans=cnt[check[i]]-f[i].size()-1;
		for( auto u:b[i] ){
			if(check[i]==check[u]){
				ans--;
			}
		}
		cout<<ans<<' ';
	}
	return 0;
}


Measured memory_bytes: 30208
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

int main(){
	
	double x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	
	double vx = x2 - x1, vy = y2 - y1;
	double norm = vx * vx + vy * vy;
	
	int q;
	cin >> q;
	
	for(int loop = 0; loop < q; loop++){
		double x, y, vx2, vy2;
		cin >> x >> y;
		vx2 = x - x1;
		vy2 = y - y1;
		double inn = vx * vx2 + vy * vy2;
		printf("%.10f %.10f\n", x1 + vx * inn / norm, y1 + vy * inn / norm);
	}
	
	return 0;
}


Measured memory_bytes: 3208
import java.util.*;

public class Main {

  public static void main(String args[]) {
    int rep = 1;
    if( args.length > 0 ) { rep = Integer.parseInt(args[0]); }
    (new Main()).__solve(rep);
  }

  void __solve(int rep) {

    try (
      Scanner cin = new Scanner(System.in);
    ) {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    }

  }

  void __solve(Scanner cin) {

	  String s = cin.next();
	  int K = cin.nextInt();
	  
	  int N = s.length();
	  String array[] = new String[N];
	  
	  for( int i = 0; i < N; ++i ) {
		  array[i] = s.substring(i);
	  }
	  
	  Arrays.sort(array);
	  
	  ans = null;
	  solve(0, 0, N, array, 0, K);
	  System.out.println(ans);

  }
  
  String ans = null;
  
  int solve(int depth, int start, int end, String array[], int total, int K) {
	  
	  if( ans != null ) {
		  return -1;
	  }
	  
	  // $ detected (skip);
	  if( array[start].length() == depth ) {
		  ++start;
	  }
	  
	  while( start < end ) {
		  char c = array[start].charAt(depth);
		  int next = start + 1;
		  for( ; next < end; ++next ) {
			  if( array[next].charAt(depth) != c ) {
				  break;
			  }
		  }
		  ++total;
		  if( total == K ) {
			  ans = array[start].substring(0, depth + 1);
			  return -1;
		  }
		  total = solve(depth + 1, start, next, array, total, K);
		  start = next;
	  }
	  
	  return total;

  }

}


Measured memory_bytes: 54868
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		string s;
		cin>>s;
		ll curr=0;
		ll ans=0;
		if(s[0]=='R')curr=1;
		ans=curr;
		rep(i,1,sz(s)){
			if(s[i]=='R')curr++;
			else {
				ans=max(curr,ans);
				curr=0;
			}
		}
		ans=max(curr,ans);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
#define dbg(x...) do { cout << "\033[32;1m" << #x <<" -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<class T, class... Ts> void err(const T& arg,const Ts&... args) { cout << arg << " "; err(args...); }

typedef long double db;
const db eps = 1e-8;
const db pi = acosl(-1.0);
int sgn(db x){if(fabs(x) < eps) return 0; return x < 0 ? -1 : 1;}
struct Point{
    db x, y;
    Point(){}
    Point(db x, db y):x(x), y(y){}
    void input(){cin >> x >> y;}
    Point operator - (const Point &b) const{
        return Point(x - b.x, y - b.y);
    }
    Point operator + (const Point &b) const{
        return Point(x + b.x, y + b.y);
    }
    db operator ^ (const Point&b)const{
        return x * b.y - y * b.x;
    }
    db operator * (const Point &b) const{
        return x * b.x + y * b.y;
    }
    db len2(){
        return x * x + y * y;
    }
    db len(){
        return sqrtl(len2());
    }
};
struct Line{
    Point s, e;
    Line(){};
    Line(Point s, Point e) :s(s), e(e){}
    void input(){ s.input(); e.input(); }

    int getPointPos(Point p) {
        return sgn((e - s) ^ (p - s));
    }
    bool isPointOnSeg(Point p) {
        return getPointPos(p) == 0 && sgn((p - s) * (p - e)) <= 0;
    }
    int getCrossTypeofSeg(Line v) {
        int d1 = getPointPos(v.s);
        int d2 = getPointPos(v.e);
        int d3 = v.getPointPos(s);
        int d4 = v.getPointPos(e);

        if((d1 ^ d2) == -2 && (d3 ^ d4) == -2) return 2;
        return isPointOnSeg(v.s) || isPointOnSeg(v.e) || v.isPointOnSeg(s) || v.isPointOnSeg(e);
    }
}l1, l2;


int main(){
#ifndef ONLINE_JUDGE
//   freopen("i.in","r",stdin);
//  freopen("o.out","w",stdout);
#endif
    
    int T;scanf("%d", &T);
    while(T--){
        l1.input(); l2.input();
        cout << (l1.getCrossTypeofSeg(l2) > 0 ? 1 : 0) << endl;
    }

    return 0;
}


Measured memory_bytes: 3308
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <bitset>
using namespace std;
#define N 200005
#define ll long long
#define mod 1000000007
struct node{int x,v,l,r;}a[N];
int n,maxx[N],f[N],sum[N];
int find(int i,int op)
{
	if(!op)
	{
		int l=1,r=i;
		while(l<r)
		{
			int m=(l+r)>>1;
			if(maxx[m]>=a[i].x)r=m;
			else l=m+1;
		}return l;
	}else
	{
		int l=i+1,r=n+1;
		while(l<r)
		{
			int m=(l+r)>>1;
			if(maxx[m]>a[i].x)r=m;
			else l=m+1;
		}return l-1;
	}
		
}
bool cmp(const node &a,const node &b){return a.v<b.v;}
bool cmp1(const node &a,const node &b){return a.r<b.r||(a.r==b.r&&a.l<b.l);}
void fix(int x,int v){for(;x<N;x+=x&-x)sum[x]=(sum[x]+v)%mod;}
int find(int x){int ret=0;for(;x;x-=x&-x)ret=(ret+sum[x])%mod;return ret;}
int main()
{
	// freopen("Problem.in","r",stdin);freopen("Problem.out","w",stdout);
	scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].v);sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		if(i==1)a[i].l=1,maxx[i]=a[i].x;
		else maxx[i]=max(maxx[i-1],a[i].x),a[i].l=find(i,0);
	}
	for(int i=n;i;i--)
	{
		if(i==n)a[i].r=n,maxx[i]=a[i].x;
		else maxx[i]=min(maxx[i+1],a[i].x),a[i].r=find(i,1);
	}
	// for(int i=1;i<=n;i++)printf("%d %d %d %d\n",a[i].x,a[i].v,a[i].l,a[i].r);
	sort(a+1,a+n+1,cmp1);
	for(int i=1;i<=n;i++)
	{
		f[a[i].r]=(find(a[i].r)-find(max(a[i].l-2,0))+mod)%mod+(a[i].l==1);
		fix(a[i].r,f[a[i].r]);
	}printf("%d\n",(find(n)-find(n-1)+mod)%mod);
}

Measured memory_bytes: 5760
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		LinkedList<Integer> A = new LinkedList<>();
		for(int i = 0; i < N; i++) {
			int a = sc.nextInt();
			A.add(a);
		}

		Collections.sort(A);

		System.out.println(A.getLast() - A.getFirst());
	}
}

Measured memory_bytes: 23124
#include <iostream>
                #include <vector>
                #include <algorithm>
                #include <cstdio>
                #include <queue>
                using namespace std;
                 
                const int MAX_N = 10000;
                #define ll long long
                int N, A, B;
                vector<int> h;
                bool enough(int T)
                {
                	ll cnt = 0;
                	for (int i = 0; i < N; i++)
                	{
                		if (h[i] <= B*T) continue;
                		cnt += (h[i]-B*T) / (A-B);
                		if( (h[i]-B*T) % (A-B) ) cnt++;
                	}
                	return cnt <= T;
                }
                 
                 
                main()
                {
                	//widespread
                	
                	cin >> N >> A >> B;
                	h.resize(N);
                	
                	for (int i = 0; i < N; i++)
                	{
                		cin>>h[i];
                	}
                	sort(h.begin(), h.end());
                	int l = -1;
                	int r = h.back() / B + 1;
                	while (r-l>1)
                	{
                		int m = (r+l) / 2;
                		(enough(m) ? r : l) = m;
                	}
                	cout << r << endl;
     
                }

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

int main() {
	// your code goes here
	int n;
	cin >> n;
	for (int i=0;i<n;i++) {
		int a,b,c;
		cin >> a >> b >>c;
		int aa = a*a;
		int bb = b*b;
		int cc = c*c;
		if (aa==bb+cc||bb==aa+cc||cc==aa+bb) {
			cout <<"YES"<<endl;
		}
		else {
			cout <<"NO"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;
typedef long long ll;

int main()
{
//	freopen("input.txt", "r", stdin);
	//提交时注释，调试时取消注释！！！ 
	int n;
	cin>>n;
	string str[N];
	map<string,ll> mp;
	for(int i=0;i<n;i++)
	{
		cin>>str[i];
		sort(str[i].begin(),str[i].end());
		mp[str[i]]++;
	} 
	ll ans=0;
	for(auto m:mp) ans+=m.second*(m.second-1)/2;
	cout<<ans; 
	return 0;
 }
 

Measured memory_bytes: 18176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n;cin >> n;
vector<string>s(n);
for(int i = 0;i<n;i++) cin >> s[i];
int a = 0,b = 0,c = 0,d = 0;
for(int i = 0;i<n;i++){
    if(s[i]=="AC") a++;
    else if(s[i]=="WA") b++;
    else if(s[i]=="TLE") c++;
    else d++;
}
cout << "AC"<<' '<<'x'<<' '<<a<<endl;
cout << "WA"<<' '<<'x'<<' '<<b<<endl;
cout << "TLE"<<' '<<'x'<<' '<<c<<endl;
cout << "RE"<<' '<<'x'<<' '<<d<<endl;
return 0;
}

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

int main()
{
  string c1, c2;
  cin >> c1 >> c2;
  if(c1.at(0) == c2.at(2) && c1.at(1) == c2.at(1) && c1.at(2) == c2.at(0))
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
// After contest.
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <functional>

using namespace std;

const int maxn = 1002;
const int mo = 1e9 + 7;

int n, m, a[maxn], b[maxn];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> m;

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

	for (int i = 0; i < m; ++i)
		cin >> b[i];

	sort(a, a+n, greater<int>());
	sort(b, b+m, greater<int>());

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

	for (int i = 0; i < m-1; ++i)
		if (b[i] == b[i+1]) {
			cout << 0 << endl;
			return 0;
		}
	
	int x = 0, y = 0;
	long long ans = 1;
	for (int i = n*m; i >= 1; --i) {
		if (a[x] == i && b[y] == i) {
			++x;
			++y;
		} else if (a[x] == i) {
			++x;
			ans = ans * y % mo;
		} else if (b[y] == i) {
			++y;
			ans = ans * x % mo;
		} else {
			ans = ans * (x*y - (n*m - i)) % mo;
		}
	}

	cout << ans << endl;

	return 0;
}

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

#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for(int (i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for(int (i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> Vec;

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	vector<string> s = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	string in;
	cin >> in;
	rep(i, 7){
		if(in == s[i]){
			co(7-i);
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 256
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split(|c| c == '/' || c == '\n');
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    let y = get!();
    let m = get!();
    let d = get!();
    let ymd = y * 10000 + m * 100 + d;
    if ymd > 20190430 {
    	println!("TBD");
    } else {
    	println!("Heisei");
    }
    
}

Measured memory_bytes: 4352
#include <stdio.h>
int main()
{   int n,l,min=20000,sum=0;
    scanf("%d%d",&n,&l);
    for(int i=1;i<=n;i++){
        sum+=(l+i-1);
        
    }
    if(l>=0){
        sum-=l;
    }else if(l+n-1<0){
        sum-=(l+n-1);
    }else{
        
    }
    printf("%d",sum);
    return 0;
}


Measured memory_bytes: 128
let n=Int(readLine()!)!
var arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}
#if swift(>=3.0)
arr=arr.sorted{$0>$1}
#else
arr=arr.sort{$0>$1}
#endif
var r=0
var t=1
for i in 0..<n {
	r+=t*arr[i]
	t=(-t)
}
print(r)

Measured memory_bytes: 896
# -*- coding: utf-8 -*-
"""
D - Xor Sum 4
https://atcoder.jp/contests/abc147/tasks/abc147_d

"""
import sys


def solve(N, A):
    MOD = 10**9 + 7
    bit_len = max(map(int.bit_length, A))
    ans = 0
    for i in range(bit_len):
        zeros, ones = 0, 0
        for a in A:
            if (a & 1<<i):
                ones += 1
            else:
                zeros += 1
        ans = (ans + (ones * zeros * 2**i)) % MOD
    return ans % MOD


def main(args):
    N = int(input())
    A = list(map(int, input().split()))
    ans = solve(N, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

const int MX = 200002;
int xs[MX];
int ys[MX];

int main() {
    int N, W, H;
    cin >> N >> W >> H;

    int x, y, w;
    for (int i=0; i<N; ++i) {
        cin >> x >> y >> w;
        xs[max(2*(x-w), 0)] ++;
        xs[min(2*(x+w)+1, MX-1)] --;
        ys[max(2*(y-w), 0)] ++;
        ys[min(2*(y+w)+1, MX-1)] --;
    }

    for (int i=1; i<MX; ++i) {
        xs[i] += xs[i-1];
        ys[i] += ys[i-1];
    }

    bool xok = true;
    for (int i=0; i<=2*W; ++i) {
        if (xs[i] <= 0) xok = false;
    }
    bool yok = true;
    for (int i=0; i<=2*H; ++i) {
        if (ys[i] <= 0) yok = false;
    }

    cout << ((xok || yok) ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 4648
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int n,p=0,w=0,g=0,y=0;
    char s;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s=='P' && p!=1)
            p=1;
        if(s=='W' && w!=1)
            w=1;
        if(s=='G' && g!=1)
            g=1;
        if(s=='Y' && y!=1)
            y=1;
    }
    if(p+w+g+y==4)
        cout<<"Four"<<endl;
    else
        cout<<"Three"<<endl;
    return(0);
}

Measured memory_bytes: 3568
N,M=map(int,input().split())
L=["" for i in range(N)]
#print(L)
if N==1 and M==0:
    print(0)
    exit()
for i in range(M):
    a,b=map(int,input().split())
    if N>=2 and a==1 and b==0:
        print(-1)
        exit()
    if L[a-1]=="":
        L[a-1]=b
    else:
        if L[a-1]==b:
            continue
        else:
            print(-1)
            exit()

for i in range(N):
    if i==0:
        if L[i]=="":
            L[i]=1
    else:
        if L[i]=="":
            L[i]=0

if N==1:
    if L[0]==0:
        print(0)
        exit()

ans=0
for i in range(N):
    ans+=L[i]*10**(N-1-i)
print(ans)

Measured memory_bytes: 3192
fun main(args: Array<String>){
    val (n, k, q) = readLine()!!.split(' ').map { it.toInt() }
    val pts: MutableList<Int> = mutableListOf()

    repeat(n){
        pts.add(0)
    }

    repeat(q) {
        pts[readLine()!!.toInt() - 1]++
    }

    pts.forEach {
        println(if(k + it - q > 0) "Yes" else "No")
    }
}

Measured memory_bytes: 44080
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001


int main(){
  LL n,m,p[1000];
  while(true){
    cin >> n >> m;
    if(n==0 and m==0)break;
    for(LL i=0;i<n;i++){
      cin >> p[i];
    }
    sort(p,p+n);
    LL res,res1,res2,res3,res4;
    res = res1 = res2 = res3 = res4 = 0;
    for(LL i=0;i<n;i++){
      if(p[i] > m)break;
      res1 = p[i];
    }
    res = max(res,res1);
    LL p2[1000000];
    for(LL i=0;i<n;i++){
      for(LL j= 0;j<n;j++){
        p2[i*n+j] = p[i]+p[j];
      }
    }
    LL p2num = n*n;
    sort(p2,p2+p2num);
    res2 = p2[upper_bound(p2,p2+p2num,m)-p2-1];
    res = max(res,res2);
    for(LL i=0;i<n;i++){
      if(p[i] > m)continue;
      res3 = max(res3,p[i] + p2[upper_bound(p2,p2+p2num,m-p[i]) - p2 -1]);
    }
    res = max(res,res3);
    for(LL i=0;i<p2num;i++){
      if(p2[i] > m)continue;
      res4 = max(res4,p2[i] + p2[upper_bound(p2,p2+p2num,m-p2[i]) - p2 -1]);
    }
    res = max(res,res4);
    cout << res << endl;

  }
	return 0;
}



Measured memory_bytes: 10976
N, K = map(int, input().split())

E = [(x*(x+1))/2/x for x in range(1, 1001)]
E = [0.0] + E

P = [E[int(p)] for p in input().split()]

ans = sum_ = sum(P[:K])

for i in range(K, N):
    sum_ = sum_ - P[i-K] + P[i]
    ans = max(ans, sum_)

print(ans)


Measured memory_bytes: 18852
while True:
    n=int(input())
    if n==0:
        break
    m=[0 for s in range(10)]
    for i in range(n):
        a=int(input())
        m[a]+=1
    for a in m:
        if a>0:
            print("*"*a)
        else:
            print("-")


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

int main(){
	int n, m;
	cin >> n >> m;
	string a[n], b[m];
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < m; i++) cin >> b[i];
	for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){
		bool f = true;
		for(int k = 0; k < m; k++) for(int l = 0; l < m; l++) f &= i + k < n && j + l < n && a[i + k][j + l] == b[k][l];
		if(f){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>


void call(int n){
	int i;
	int x;
	for(i=3;i<=n;i++){
		x=i;
		if(x%3==0){
				printf(" %d",i);
		}else{
			do{
				if(x/10==3){
					printf(" %d",i);
					break;
				}
				if(x%10==3){
					printf(" %d",i);
					break;
				}
				x/=10;
			}while(x>10);
		}
	}
	printf("\n");
}

int main(){
	int n;
	
	scanf("%d",&n);
	call(n);
	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define int long long
template <typename T, typename U>
istream &operator>>(istream &in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	const int MOD=1e9+7;
	int n;
	map<P,int> mp;
	cin>>n;
	rep(i,1,n+1){
	    string s=to_string(i);
	    mp[{s[0]-'0',s[s.size()-1]-'0'}]++;
	}
	int ans=0;
	for(auto it:mp){
	    P p=it.first;
	    ans+=mp[p]*mp[{p.second,p.first}];
	}
	cout<<ans<<endl;
}

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


using namespace std;
typedef long long ll;
int main(){
	string a,b;
  cin>>a>>b;
  ll x = stoll(a+b);
  for(ll i = 1;i*i<=x;i++){
   	if(x == (i*i))cout<<"Yes",exit(0); 
  }
	cout<<"No";
	
	
	
	return 0;
}

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

int main(void){
    int A,B,H,M;
    cin >> A >> B >> H >> M;
    long double ans = 0;
    long double rad = M_PI * 2*(
        (long double) H/12.0 +(long double) M/(60.0)/12.0 - (long double)M/60
        );
    ans = (long double)(A*A + B*B) - (long double)(2*A*B*cos(rad));
    cout << fixed << setprecision(20) << sqrt(ans) << endl;
    return 0;
}

Measured memory_bytes: 4148
N, K = map(int, input().split())
P = list(map(int, input().split()))
e = []

def expect(x):
    return ((x*(x+1))//2) / x

for p in P:
    e.append(expect(p))

ans = sum(e[:K])
tmp = ans
#print(e, e[:K])
for i in range(K, N):
    tmp = tmp - e[i-K] + e[i]
    ans = max(ans, tmp)
    #print(tmp, ans, e[i-K], e[i])

print(ans)

Measured memory_bytes: 24804
// 2020-07-18 08:46:27
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

const int MX = 200020;
vector<int> G[MX];
int c[MX], tsz[MX];
stack<int> st[MX];
ll inv[MX];
ll com(int x) { return ll(x) * (x+1) / 2; }
int tfs(int u, int p) {
  int cur = 0;
  for(int v : G[u]) if(v != p) {
    cur += tfs(v, u);
  }
  return tsz[u] = cur + 1;
}
void dfs(int u, int p) {
  st[c[u]].push(u);
  for(int v : G[u]) if(v != p) {
    dfs(v, u);
    int sz = tsz[v], w;
    while((w = st[c[u]].top()) != u) {
      st[c[u]].pop();
      sz -= tsz[w];
    }
    inv[c[u]] += com(sz);
  }
}
void answer() {
  int n;
  cin >> n;
  rep(i, n) {
    cin >> c[i];
    c[i]--;
  }
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  tfs(0, -1);
  dfs(0, -1);
  rep(i, n) {
    int sz = n;
    while(!st[i].empty()) {
      int w = st[i].top(); st[i].pop();
      sz -= tsz[w];
    }
    inv[i] += com(sz);
  }
  ll tot = com(n);
  rep(i, n) {
    cout << tot - inv[i] << '\n';
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 171652
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    s = []
    for i in range(m):
        a = LI()[1:]
        for j in range(len(a)):
            a[j] -= 1
        s.append(a)
    p = LI()
    ans = 0
    for b in range(1<<n):
        su = [0]*m
        for i in range(m):
            for j in s[i]:
                if b&(1<<j):
                    su[i] ^= 1
        if su == p:
            ans += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


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

int main(){
  int n,k,ans=0;cin>>n>>k;
  vector<int> p(n,0);
  REP(i,n) cin>>p.at(i);
  sort(p.begin(),p.end());
  REP(i,k) ans+=p.at(i);

  cout<<ans<<endl;
}

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

int par[200005];
long long xs[200005];
long long ys[200005];
int getpar(int x){
    if(par[x] != x){
        par[x] = getpar(par[x]);
    }
    return par[x];
}

void join(int x, int y){
    int xp = getpar(x);
    int yp = getpar(y);
    if(xp == yp) return;
    xs[xp] += xs[yp];
    ys[xp] += ys[yp];
    par[yp] = xp;
    xs[yp] = 0;
    ys[yp] = 0;
}

int main(){
    int N;
    scanf("%d", &N);
    for(int i = 1; i <= 100000; i++){
        par[i] = i;
        xs[i] = 1;
        ys[i] = 0;
    }
    for(int i = 100001; i <= 200000; i++){
        par[i] = i;
        xs[i] = 0;
        ys[i] = 1;
    }
    for(int i = 0; i < N; i++){
        int tx, ty;
        scanf("%d %d", &tx, &ty);
        ty += 100000;
        join(tx, ty);
    }
    long long tal = 0;
    for(int i = 1; i <= 200000; i++){
        tal += xs[i] * ys[i];
    }
    long long n = N;
    printf("%lld", tal - n);
}


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

int main(void){
	int N;
	cin >> N;
	int a[N];
	rep(i,N) cin >> a[i];
	sort(a,a+N,greater<int>());
	int Pa = 0, Pb = 0;
	rep(i,N){
		if (i%2==0) Pa += a[i];
		else Pb += a[i];
	}
	cout << Pa-Pb << endl;


	return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <climits>

using namespace std;

typedef long long ll;
typedef vector<int> ivec;
typedef pair<int, int> ipair;

int N, M;
bool ab[10][10];

int main() {
    int a, b;
    cin >> N >> M;
    memset(ab, 0, sizeof ab);
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        ab[a-1][b-1] = true;
        ab[b-1][a-1] = true;
    }

    ivec p(N);
    p[0] = 0;
    for (int i = 1; i < N; i++) {
        p[i] = i;
    }
    int count = 0;
    do {
        count++;
        for (int i = 0; i < N - 1; i++) {
            a = p[i];
            b = p[i+1];
            if (!ab[a][b]) {
                count--;
                break;
            }
        }
    } while (next_permutation(p.begin()+ 1, p.end()));

    cout << count << endl;

    return 0;
}


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

using namespace std;

int main(){
	string s[3];
	cin >> s[0] >> s[1] >> s[2];
	
	char name[3] = {'A', 'B', 'C'};
	int pt[3] = {0, 0, 0};
	
	int t = 0;
	while(true){
		if(pt[t] == s[t].size()){
			cout << name[t] << endl;
			break;
		}
		
		char x = s[t][pt[t]];
		
		pt[t]++;
		
		if(x == 'a'){
			t = 0;
		}else if(x == 'b'){
			t = 1;
		}else t = 2;
	}
	
	return 0;
}

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

using ll = long long;
const int N = 100010;

int a[N];
int n, m, v, p;

bool check(int mid){
    std::vector <int> vec;
    int cnt = 0;
    for (int i = 0; i < n; ++ i){
        if (i == mid){
            continue;
        }
        if (a[i] > a[mid] + m){
            ++ cnt;
        }
        else{
            vec.push_back(a[i]);
        }
    }
    ll left = 1ll * m * (v - 1 - cnt);
    int remain = p - 1 - cnt;
    if (remain < 0){
        return false;
    }
    if (left < 0){
        return true;
    }
    for (auto u : vec){
        if (remain > 0){
            -- remain;
            left -= std::min(left, ll(m));
            continue;
        }
        ll diff = a[mid] + m - u;
        ll x = std::min(diff, ll(m));
        x = std::min(x, left);
        left -= x;
    }
    return left == 0;
}

int main(){
    scanf("%d%d%d%d", &n, &m, &v, &p);
    for (int i = 0; i < n; ++ i){
        scanf("%d", &a[i]);
    }
    std::sort(a, a + n, std::greater <int>());
    int left = 0, right = n - 1;
    while (left < right){
        int mid = (left + right + 1) / 2;
        if (check(mid)){
            left = mid;
        }
        else{
            right = mid - 1;
        }
    }
    printf("%d\n", left + 1);
    return 0;
}


Measured memory_bytes: 1596
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define pi acos(-1)
#define lli long long int
using namespace std;

int main() 
{
    FIO
    lli t,n, b,i,j,d,a;
    cin >> n;
    int arr[n+2];
    int cnt = 0;
    for ( i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int tmp = arr[0];
    for ( i = 0; i < n; i++)
    {
        if(arr[i] < tmp)  {
            cnt ++;
            tmp = arr[i];
        }
    }
    

    cout << cnt+1 << endl;
    return 0;
}
    

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <cmath>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
  char N;
  cin >> N;
  
  if(islower(N)){
    cout << 'a' << endl;
  }else{
    cout << 'A' << endl;
  }
  
}

Measured memory_bytes: 3572
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>

using namespace std;

int main()
{
    int N;
    cin >> N;
    int a = N % 1000;
    if (a) {
        cout << (1000 - a) << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()


template<typename T> class BinaryIndexedTree {
  private:
    int S;
    std::vector<T> v;
  public:
    BinaryIndexedTree<T> (int _S) {
      S = _S;
      v.resize(S+1);
    }
    void update(int i, T k) {
      for(i++; i <= S; i += i&-i) v[i] = v[i] + k;
    }
    T read(int i) {
      T sum = 0;
      for(i++; i; i -= i&-i)  sum = sum + v[i];
      return sum;
    }
    T read(int l, int r) {
      return read(r) - read(l-1);
    }
};

int main() {

  int N;  std::cin >> N;
  long long threshold = N * 1LL * (N + 1) / 2;

  std::vector<int> A(N);
  for (int i = 0; i < N; i++) std::cin >> A[i];

  auto vals = A;
  std::sort(vals.begin(), vals.end());
  vals.erase(std::unique(vals.begin(), vals.end()), vals.end());

  int lo = 1, hi = vals.size()-1, ans = 0;
  while (lo <= hi) {
    int mi = (lo + hi) / 2;

    long long num = 0;
    BinaryIndexedTree<int> bit(2*N+1);
    bit.update(N + 0, 1);

    int bal = 0;
    for (auto& v : A) {
      if (v >= vals[mi]) bal++;
      else bal--;
      num += bit.read(bal+N);
      bit.update(bal+N, 1);
    }

    if (2*num >= threshold) {
      ans = mi;
      lo = mi + 1;
    }
    else {
      hi = mi - 1;
    }
  }

  std::cout << vals[ans] << std::endl;
  return 0;
}

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

struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

std::ostream& operator<<(std::ostream& stream, const mint& m){
    stream << m.v;
    return stream;
}

void solve(long long N, long long K, std::vector<long long> A){
    vector<mint> x(N, 0), y(N, 0);
    REP(i, N){
        REP(j, N){
            x.at(i) += (A.at(i) < A.at(j));
        }
        REP(j, i){
            y.at(i) += (A.at(i) < A.at(j));
        }
    }
    mint ans = 0;
    REP(i, N){
        ans += x.at(i) * (K * (K - 1) / 2) + y.at(i) * K;
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N-1-0+1);
    for(int i = 0 ; i < N-1-0+1 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}


Measured memory_bytes: 256
### constant

N = 3
NN = N * N

MCHARS = [['R', 'r'], ['G', 'g'], ['B', 'b'], ['W', 'w']]

### subroutines

def count_rec(x, y)
  return 1 if y >= N

  x0 = x + 1
  y0 = y
  if x0 >= N
    x0 = 0
    y0 += 1
  end

  id = y * N + x
  count = 0

  for i in (0...NN)
    next if $used[i]

    for pc in $pcs[i]
      next if x > 0 && $matches[$grds[id - 1][1]][pc[3]].nil?
      next if y > 0 && $matches[$grds[id - N][2]][pc[0]].nil?

      $used[i] = true
      $grds[id] = pc

      count += count_rec(x0, y0)

      $used[i] = false
    end
  end

  count
end

### main

$matches = {}
for mch in MCHARS
  c0, c1 = mch
  $matches[c0] = {c1 => true}
  $matches[c1] = {c0 => true}
end

n = gets.to_i

n.times do
  $pcs = []
  for pc in gets.strip.split
    pns = pc.split('')
    rots = [pns.clone]
    for i in (1..3)
      rots << pns.rotate(i)
    end
    $pcs << rots
  end
  #p $pcs

  $used = NN.times.map{false}
  $grds = []

  c = count_rec(0, 0)
  puts c
end

Measured memory_bytes: 6132
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**9
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    N = I()
    a = LI()
    r = 0
    f = True
    while f:
        f = False
        for i in range(N):
            if a[i] < N:
                continue
            f = True
            t = a[i] // N
            r += t
            for j in range(N):
                if i == j:
                    continue
                a[j] += t
            a[i] -= t * N
    return r



print(main())



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


using namespace std;

#define all(v)              v.begin(),v.end()
#define allr(v)             v.rbegin(),v.rend()
#define sz(v)               (int)sizeof(v)
#define pb(x)               push_back(x)
#define mkpr(x,y)           make_pair(x,y)
#define oo                  INT_MAX
#define noo                 INT_MIN
#define forn(i, n)          for(ll i=0;i<n;i++)
#define fore(i,b,e)         for(ll i=b;i<=e;i++)
#define ford(i,n)           for(ll i=n-1;i>=0;i--)


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

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

void dance()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void file()
{
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
}

ll gcd(ll a, ll b)
{
    return !b ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

template<typename t>
void printV(vector<t> v)
{
    for (int i = 0; i < v.size(); i++)
    {
        cout << v[i] << ' ';
    }
    cout << endl;
}

bool isPrime(int n)
{

    if (n == 2)
        return true;
    if (n < 2 || n % 2 == 0)
        return false;
    for (int i = 3; i * i <= n; i += 2)
        if (n % i == 0)
            return false;
    return true;
}

/**
 *****code begins here*****
**/
ull ncr(ull n,ull r)
{
    r=max(r,n-r);
    ull u=1,d=1;
    for(ull i=r+1; i<=n; i++)
        u*=i;
    for(ull i=1; i<=n-r; i++)
        d*=i;
    return u/d;
}

int main()
{
    dance();
    int d;
    cin>>d;
    if(d==22)
        cout<<"Christmas Eve Eve Eve"<<endl;
    else if(d==23)
        cout<<"Christmas Eve Eve"<<endl;
    else if(d==24)
        cout<<"Christmas Eve"<<endl;
    else if(d==25)
        cout<<"Christmas"<<endl;
    return 0;
}


Measured memory_bytes: 256
n, k = list(map(int, input().split()))
# d_list = []
# a_matrix = []
is_sunuke_have_sweets_list = [False for _ in range(n)]
for i in range(k):
    d = int(input())
    a_list = list(map(int, input().split()))

    for a in a_list:
        is_sunuke_have_sweets_list[a-1] = True

    # d_list.append(d)
    # a_matrix.append(a_list)

print(is_sunuke_have_sweets_list.count(False))


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

using namespace std;

using ll = long long;

struct UnionFind {
    //各要素が属する集合の代表(根)を管理する
    //もし、要素xが根であればdata[x]は負の値を取り、-data[x]はxが属する集合の大きさに等しい
    vector<int> data;
    vector<ll> cntx, cnty, cnte;

    UnionFind(int sz) : data(2 * sz, -1), cntx(2 * sz, 0), cnty(2 * sz, 0), cnte(2 * sz, 0) {
        for (int i = 0; i < sz; i++) cntx[i]++;
        for (int i = sz; i < sz * 2; i++) cnty[i]++;
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        bool is_union = (x != y);
        if (is_union) {
            if (data[x] > data[y]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
            cntx[x] += cntx[y];
            cnty[x] += cnty[y];
            cnte[x] += cnte[y];
            cnte[x]++;
            cntx[y] = 0;
            cnty[y] = 0;
            cnte[y] = 0;
        } else {
            cnte[x]++;
        }
        return is_union;
    }

    int find(int x) {
        if (data[x] < 0) { //要素xが根である
            return x;
        } else {
            data[x] = find(data[x]); //data[x]がxの属する集合の根でない場合、根になるよう更新される
            return data[x];
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return -data[find(x)];
    }

    ll calc() {
        ll res = 0;
        for (int i = 0; i < data.size(); i++) {
            if (i == find(i)) {
                res += cntx[i] * cnty[i] - cnte[i];
            }
        }
        return res;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    UnionFind uf(100000);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        uf.unite(x[i] - 1, 100000 + y[i] - 1);
    }

    cout << uf.calc() << endl;
    return 0;
}

Measured memory_bytes: 6528
inpl = lambda: list(map(int,input().split()))
MOD = 10**9 + 7
N, M = inpl()
 
def factorize(n):
  prime_list = []
  factorize_list = []
  i = 2
  while i*i <= n:
    for p in prime_list:
      if i % p == 0:
        break
    else:
      prime_list.append(i)
      k = 0
      while n % i == 0:
        n //= i
        k += 1
      factorize_list.append(k)
    i += 1
  if n > 1:
    factorize_list.append(1)
  return(factorize_list)

def H(n,k):
  h = 1
  L = n + k - 1
  k = min(n-1,k)
  for j in range(k):
    h *= L-j
  for j in range(k):
    h //= j+1
  return h

ans = 1
for k in factorize(M):
  ans *= H(N,k) % MOD
  ans %= MOD

print(ans)

Measured memory_bytes: 3064
use proconio::input;

fn main() {
    input!{
        n: usize,
        d: [[i32; 2]; n],
    }
    for i in 0..n-2 {
        if d[i][0] == d[i][1] && d[i+1][0] == d[i+1][1] && d[i+2][0] == d[i+2][1] {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


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

using namespace std;

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

    string n;
    int sum = 0;
    cin >> n;
    for (int i = 0; i < n.size(); ++i) {
        sum += n[i]- '0';
    }
    if(sum % 9 == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 3692
N,X,MOD = map(int,input().split())
L = [X%MOD]
S = set(L)
for i in range(1000000):
  X = pow(X,2,MOD)
  if X not in S:
    L.append(X)
    S.add(X)
  else:
    loop = X
    break
ans = 0
#print(L,loop)
k = len(L)
if k >= N: #ループよりもNが短い
  for i in range(N):
    ans += L[i]
  print(ans);exit()
for i in range(k):
  if L[i] != loop:
    ans += L[i]
    if i+1 == N:
      print(ans);exit()
  else: #ループに戻ってきた
    #print(i)
    loop_syuki = k-i
    saisyo = i
    loop_kosu = (N-saisyo)//loop_syuki
    amari = (N-saisyo)%loop_syuki
    nokori = loop_kosu*sum(L[saisyo:]) + sum(L[saisyo:saisyo+amari])
    ans += nokori
    #print(loop_syuki,saisyo,amari)
    print(ans);exit()

Measured memory_bytes: 76692
n,m = map(int,input().split())
li=[0]*n
for i in range(n):
    li[i] = list(map(int,input().split()))
count=0
for i in range(n):
    if li[i][0]**2+li[i][1]**2 <= m**2:
        count+=1


print(count)

Measured memory_bytes: 45256