akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;


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

	vector<int> v(n+1, 0);

	for(int i = 1; i < n; ++i)
	{
	    for(int j = i + 1; j <= n; ++j)
	    {
		int dist1 = j - i;
		int dist2 =  abs(x - i) + 1 + abs(y-j);
		v[min(dist1, dist2)] += 1;
	    }
	}

	for(int i = 1; i < n; ++i)
		cout << v[i] << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1001
using namespace std;
int V,d;
int used[1010];
int f[1010]={2,3};

void dfs(int pos){
  if(used[pos])return;
  used[pos]=1;
  for(int i=0;i<V;i++)if(abs(f[pos]-f[i])<d) dfs(i);
}


int main(){

  for(int i=2;i<1010;i++) f[i]=(f[i-2]+f[i-1])%N;
  
  while(cin>>V>>d){
    memset(used,0,sizeof(used));
    int ans=0;
    for(int i=0;i<V;i++) if(!used[i])ans++,dfs(i);
    cout <<ans<<endl;
  }

  return 0;
}

Measured memory_bytes: 1196
// In the Name of Allah
// Ya Ali

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define F first
#define S second
#define pb push_back
#define all( x ) x.begin() , x.end()
#define mp make_pair

const int maxn = 210 ;
const int INF = 1e18 ;

int n , t , a[ maxn ] ;
bool use[ maxn ] ;
vector< int > vv ;
string s ;

bool ok( int x )
{
  memset( use , false , sizeof use ) ;
  int now = 0 ;

  vector< int > v1 ;
  for(auto x : vv)v1.pb( x );

  for(int i = 62 ; i >= 0 ; i --){

     int po = -1 ;
     for(int j = 0 ; j < v1.size() ; j ++)
       if( (v1[ j ]&(1ll<<i)) && !use[ j ] )
          po = j ;

     bool t1 = (x&(1ll<<i)) , t2 = (now&(1ll<<i));

     if( t1!=t2 && po != -1 )now ^= v1[ po ] ;

     if( po != -1 ){
       use[ po ] = true ;
       for(int j = 0 ; j < v1.size() ; j ++)
         if( j != po && (v1[ j ]&(1ll<<i)) )
           v1[ j ] ^= v1[ po ] ;
     }
  }

  return ( now == x ) ;
}

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

 cin >> t ;
 while( t -- ){
   cin >> n ;
   for(int i = 1 ; i <= n ; i ++)
     cin >> a[ i ] ;
   cin >> s ;

   bool ans = 0 ;
   vv.clear();

   for(int i = n ; i >= 1 ; i --){
      if( s[ i-1 ] == '0' )vv.pb( a[ i ] ) ;
      else{
         if( !ok( a[ i ] ) ){
           ans = 1 ;
           break ;
         }
      }
   }

   cout << ans << "\n" ;

 }

  return 0;
}


Measured memory_bytes: 3668
n = int(input())
A = list(int(x) for x in input().split())
ans = 0
while max(A) >= n:
    m = max(A)
    index = A.index(m)
    count = m // n
    ans += count
    A = [a + count for a in A]
    A[index] -= n * count + count

print(ans)

Measured memory_bytes: 73872
#ifndef CLASS_MODINT
#define CLASS_MODINT

#include <cstdint>

template <std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::int64_t n_) : n((n_ >= 0 ? n_ : mod - (-n_) % mod) % mod) {};
	static constexpr std::uint32_t get_mod() { return mod; }
	std::uint32_t get() const { return n; }
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint inv() const { return (*this).pow(mod - 2); }
	modint pow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
};

#endif // CLASS_MODINT

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
using mint = modint<1000000007>;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N + 1);
	for (int i = 1; i <= N; ++i) {
		cin >> A[i];
		A[i] ^= A[i - 1];
	}
	int mx = *max_element(A.begin(), A.end());
	vector<vector<int> > g(mx + 1);
	for (int i = 0; i <= N; ++i) {
		g[A[i]].push_back(i);
	}
	vector<int> S(N + 2);
	for (int i = 0; i <= N; ++i) {
		if (A[i] == 0) ++S[i + 1];
		S[i + 1] += S[i];
	}
	mint ans = 0;
	for (int i = 1; i <= mx; ++i) {
		if (g[i].empty()) continue;
		vector<mint> dpa(g[i].size()), dpb(g[i].size());
		for (int j = 0; j < g[i].size(); ++j) {
			if (j >= 1) dpb[j] = dpb[j - 1] + dpa[j - 1] * (S[g[i][j]] - S[g[i][j - 1]]);
			dpa[j] = dpb[j] + 1;
			if (j >= 1) dpa[j] += dpa[j - 1];
		}
		if (A[N] == 0 || A[N] == i) {
			ans += dpa.back();
			if (A[N] == i && dpa.size() >= 2) ans -= dpa[dpa.size() - 2];
		}
	}
	if (A[N] == 0) ans += mint(2).pow(S[N + 1] - 2);
	cout << ans.get() << endl;
	return 0;
}

Measured memory_bytes: 38388
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    A, B = map(int, input().split())
    if A + B >= 10:
        print("error")
    else:
        print(A + B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3952
while True:
    n,x = map(int,input().split(" "))
    if n == 0 and x == 0:
        break
    countn = 0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i+j+k == x:
                    countn += 1
    print(countn)


Measured memory_bytes: 5596
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
int main() {
	std::cin.tie(nullptr); std::cin.sync_with_stdio(false);
	std::string str; std::cin >> str;
	std::deque<char> deque;
	for (const auto c : str) deque.push_back(c);
	bool is_reversed = false;
	int q; std::cin >> q;
	for (auto i = 0; i < q; ++i) {
		int t; std::cin >> t;
		if (t == 1) {
			is_reversed = !is_reversed;
		}
		else {
			int f; char c; std::cin >> f >> c;
			const auto pos = (is_reversed) ? 3 - f : f;
			if (pos == 1) {
				deque.push_front(c);
			}
			else {
				deque.push_back(c);
			}
		}
	}
	while (!deque.empty()) {
		if (is_reversed) {
			std::cout << deque.back();
			deque.pop_back();
		}
		else {
			std::cout << deque.front();
			deque.pop_front();
		}
	}
	std::cout << '\n';
}

Measured memory_bytes: 960
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int A, V, B, W, T; cin >> A >> V >> B >> W >> T;
  
  if(abs(A-B) <= T*(V-W)) cout << "YES" << endl;
  else cout << "NO" << endl;
  

}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    int a,b;
    cin >> a >> b ;
    if (a%3==0||b%3==0||(a+b)%3==0){
        cout << "Possible" << endl;
    }
    else cout << "Impossible" << endl;
    return 0;
}

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

int main(){
	int N,W;
	int v[101],w[101];
	cin>>N>>W;
	for(int i=0;i<N;i++){
		cin>>v[i]>>w[i];
	}
	int DP[N+1][W+1];
	for(int j=0;j<=W;j++)
		DP[0][j]=0;

	for(int i=1;i<=N;i++)
		for(int j=0;j<=W;j++)
			if(j<w[i-1])
				DP[i][j]=DP[i-1][j];
			else{
				if(DP[i-1][j]>DP[i-1][j-w[i-1]]+v[i-1])
					DP[i][j]=DP[i-1][j];
				else
					DP[i][j]=DP[i-1][j-w[i-1]]+v[i-1];
			}
		cout<<DP[N][W]<<endl;

		return 0;
}

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

string stlip[4] ={"dream","dreamer","eraser","erase"};

int main(){
  string s;
  cin >> s;
  reverse(s.begin(),s.end());
  bool can = true;
  for (int i = 0; i < s.size();){
    can = false;
    for (int j = 0; j < 4; j++){
      string si = stlip[j];
      reverse(si.begin(),si.end());
      if (s.substr(i,si.size()) == si) {
        can = true;
        i += si.size();
      }
    }
    if(!can){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
    

Measured memory_bytes: 512
x,y = map(int,input().split())
ch = max(abs(x),abs(y)) - min(abs(x),abs(y))
if x <= 0 and y == 0 or x == y or x == 0 and y > 0:
    print(ch)
elif x*y <= 0:
    print(ch+1)
elif x*y >= 0 and x >= y:
    print(ch+2)
else:
    print(ch)

Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

#define N_MAX 100100
deque<int> g[N_MAX];
int dp[N_MAX];
int N,M;
bool used[N_MAX];

int dfs(int s){
  if(used[s]) return dp[s];
  used[s]=true;
  int ret=0;
  for(auto t:g[s]){
    ret=max(ret,dfs(t)+1);
  }
  return dp[s]=ret;
}


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

  cin >> N >> M;

  //int x[N_MAX],y[N_MAX];
  for(int i=0;i<N_MAX;i++){
    used[i]=false;
  }

  /*for(int i=0;i<N_MAX;i++){
    for(int j=0;j<N_MAX;j++){
      x[i][j]=0;
      //if(i==j)x[i][j]==1;
    }
  }*/


  for(int i=0;i<N_MAX;i++){
    dp[i]=0;
  }
  int x,y;
  for(int i=0;i<M;i++){
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y);
  }

  int ans=0;
  for(int i=0;i<N;i++){
    ans=max(ans,dfs(i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 70784
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



a,b,c,d = map(int, input().split())

dp = [[0]*(d+1) for _ in range(c+1)]
dp[a][b] = 1
M = 998244353
for x in range(a+1, c+1):
    dp[x][b] = b*dp[x-1][b]
    dp[x][b] %= M
for y in range(b+1, d+1):
    dp[a][y] = a*dp[a][y-1]
    dp[a][y] %= M
for x in range(a+1, c+1):
    for y in range(b+1, d+1):
        dp[x][y] = dp[x-1][y]+dp[x][y-1]+(x-1)*dp[x][y-1]+(y-1)*dp[x-1][y]-(x-1)*(y-1)*dp[x-1][y-1]
        dp[x][y] %= M
print(dp[c][d])

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

int main(){
    int n,m,a[100][100],b[100],c[100];
    
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++) cin>>a[i][j];
    }for(int i=0;i<m;i++) cin>>b[i];
    
    for(int i=0;i<n;i++){
        c[i]=0;
        for(int j=0;j<m;j++){
            c[i]+=a[i][j]*b[j];
        }
    }
    for(int i=0;i<n;i++) cout<<c[i]<<endl;
    return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long LL;

int f[110][20];
int p[110][20];

int main(){
	
	int n,flag=0;
	LL ans;
	cin>>n;
	for(int i=0;i<n;i++)
	for(int j=0;j<10;j++)
	scanf("%d",&f[i][j]);
	
	for(int i=0;i<n;i++)
	for(int j=0;j<11;j++)
	scanf("%d",&p[i][j]);
	
	for(int z=1;z<=1023;z++){
		LL m=0;
		for(int i=0;i<n;i++){
			int sa=0,x=z;
			for(int j=0;j<10;j++){
				if(f[i][j]==1&&(x&1)){
					sa++;
				}
				x>>=1;
			}
			m+=p[i][sa];
		}
		if(flag==0){
			ans=m;flag=1;
		}else{
			ans=max(m,ans);
		}
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 256
#include <complex>
#include <vector>
#include <cstdio>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

typedef vector<P> G;

struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;                               // a--c--b on line
}

const char *z[]={"ONLINE_FRONT","CLOCKWISE","ON_SEGMENT","COUNTER_CLOCKWISE","ONLINE_BACK"};
int main(){
	double x,y;
	int q;
	scanf("%lf%lf",&x,&y);P p0(x,y);
	scanf("%lf%lf%d",&x,&y,&q);P p1(x,y);
	for(;q--;){
		scanf("%lf%lf",&x,&y);P p(x,y);
		puts(z[ccw(p0,p1,p)+2]);
	}
}

Measured memory_bytes: 1064
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string str, atoz;
  	int a, z;
  	cin >> str;
  	for (int i = 0; i < str.size(); i++){
    	if (str[i] == 'A'){
        	a = i;
          	break;
        } 
    }
  	for (int i = str.size(); i > 0; i--){
    	if (str[i - 1] == 'Z'){
        	z = i;
          	break;
        } 
    }
  	atoz = str.substr(a, z - a);
  	cout << atoz.size();
}

Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;
 
int main() {
long long N,A,B  ;
    cin >> N >> A >> B ;
 
long long count;
long long amari=0;
  count=N/(A+B)*A;
  amari=N%(A+B);
   if (amari>=A){
    amari=A;
   }
  count+=amari;
  
  cout << count << endl;  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<int,int>;
int main(){
    int n;cin>>n;
    string s;cin>>s;
    vector<vector<int>> v(n+10);
    for(int i=0;i<n;i++){
        if(s[i]=='1'){
           if(i>1&&s[i-1]=='0'){
			   int id=i-2;
			   while(id>=0&&s[id]=='1'){
				   v[i+1].push_back(id+1);
				   id--;
			   }
		   }
		   if(i<n-2&&s[i+1]=='0'){
			   int id=i+2;
			   while(id<n&&s[id]=='1'){
				   v[id+1].push_back(i+1);
				   id++;
			   }
		   }
			   
	   }
    }
    vector<int> dp(n+10),ma(n+10);
    for(int r=1;r<=n;r++){
		for(auto l:v[r]){
			int c=r-l-1;
			dp[r]=max(dp[r],ma[l-1]+c);
		}
		ma[r]=max(ma[r-1],dp[r]);
	}
    cout<<ma[n]<<endl;
}


Measured memory_bytes: 34564
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main() {
	int n, ans;
	cin >> n;
	cout << pow(n, 3) << endl;



	return 0;
}

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

int main() {

	int a, b; cin >> a >> b;
	int d = b - a;
	int i = 1;
	int sum = 0;
	while (d--) {
		sum += i;
		i++;
	}
	cout << sum - b << endl;
	return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);

  ll n,m,l;
  cin>>n>>m>>l;
  vector<vector<ll>> dist1 (n,vector<ll>(n,INF));
  vector<vector<ll>> dist2 (n,vector<ll>(n,INF));
  rep(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    chmin(dist1[a][b],c);
    chmin(dist1[b][a],c);
  }
  ll q;
  cin>>q;
  vector<pair<ll,ll>> query;
  rep(i,q){
    ll s,t;
    cin>>s>>t;
    s--;t--;
    query.emplace_back(s,t);
  }

  rep(k,n)rep(i,n)rep(j,n){
    //if(dist1[i][k]==INF||dist1[k][j]==INF)continue;
    chmin(dist1[i][j],dist1[i][k]+dist1[k][j]);
  }

  rep(i,n)rep(j,n){
    if(dist1[i][j]<=l)dist2[i][j]=1;
  }

  rep(k,n)rep(i,n)rep(j,n){
    //if(dist2[i][k]==INF||dist2[k][j]==INF)continue;
    chmin(dist2[i][j],dist2[i][k]+dist2[k][j]);
  }

  rep(i,q){
    ll s,t;tie(s,t)=query[i];
    if(dist2[s][t]<INF)cout<<(dist2[s][t]-1)<<endl;
    else cout<<(-1)<<endl;
  }

}


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

int main()
{
  int n;
  cin >> n;
  int a[n];
  int b = 0;
  rep(i, n){
    cin >> a[i];
    b += a[i];
  }
  int x = ceil((double)b / n);
  int y = floor((double)b / n);
  //cout << x << y << endl;
  int c = 0;
  int d = 0;
  rep(i, n){
    c += (a[i] - x) * (a[i] - x);
    d += (a[i] - y) * (a[i] - y);
  }
  cout << min(c, d) << endl;

  return 0;
}

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

class Main {

	void solve() {

		char[] a = incharar();
		if ((a[0] == a[1] && a[1] == a[2]) || (a[1] == a[2] && a[2] == a[3])) {
			out.println("Yes");
			return;
		}
		out.println("No");

	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

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

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}
	
	public String instr() {
		return in.next();
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}

Measured memory_bytes: 21332
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n, m, start, goal;
	cin>> n>> m>> start>> goal;
	start--;
	goal--;
	vvi root(n);
	REP(i,m) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		root[a].push_back(b);
		root[b].push_back(a);
	}

	vi start_dis(n,1e9);
	vi sdn(100001,0);
	start_dis[start] = 0;
	sdn[0]++;
	queue<int> Q;
	Q.push(start);
	while (!Q.empty()) {
		int q = Q.front();Q.pop();
		REP(i, root[q].size()) {
			if (start_dis[root[q][i]] > start_dis[q] + 1) {
				start_dis[root[q][i]] = start_dis[q] + 1;
				Q.push(root[q][i]);
				sdn[start_dis[q] + 1]++;
			}
		}
	}
	vi goal_dis(n, 1e9);
	vi gdn(100001,0);
	goal_dis[goal] = 0;
	gdn[0]++;
	Q.push(goal);
	while (!Q.empty()) {
		int q = Q.front();Q.pop();
		REP(i, root[q].size()) {
			if (goal_dis[root[q][i]] > goal_dis[q] + 1) {
				goal_dis[root[q][i]] = goal_dis[q] + 1;
				Q.push(root[q][i]);
				gdn[goal_dis[q] + 1]++;
			}
		}
	}
	int dis = start_dis[goal];
	long long ercnt = 0;
	REP(i, n)
		if (start_dis[i] + goal_dis[i]+1 == dis-1)
			ercnt++;
	long long ans = 0;
	REP(i, dis-1) {
		ans += (long long)sdn[i] * (long long)gdn[dis - i-2];
	}
	cout << ans - ercnt << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}

template<typename T>
T gcd(T x, T y){
    if (x == 0 || y == 0) {
        return 0;
    }

    while (x != y){
        if (x > y) {
            x -= y;
        }else{
            y -= x;
        }
    }
    return x;
}

// }}}
/* vim:set foldmethod=marker: */

void solve(){
    string s,t;
    cin >> s >> t;
    
    int n = s.length();
    for (int i = 0; i < n; i++) {
        string str="";
        str = s.substr(n-i,i) + s.substr(0,n-i);
        // cout << str << endl;
        if (str == t) {
            cout << "Yes" << endl;
            return;
        }
    }

    cout << "No" << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


// map の key, value を全て抜き出す。
// for (auto itr = mp.begin(); itr != mp.end(); itr++) {
//     cout << "key" << itr->first << " value" << itr->second << endl;
// }


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;

const int inf = (int)1e9; 

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


int main(void){
	int a,b,c;
	cin>>a>>b>>c;
	int k;
	cin>>k;
	int t = 0;
	while(a>=b){
		b*=2;
		t++;
	}
	while(b>=c){
		c*=2;
		t++;
	}
	if(t<=k)cout<<"Yes";
	else cout<<"No";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3632
import queue
import sys
input = sys.stdin.readline
from collections import defaultdict as dd
sys.setrecursionlimit(1000000)
N,M = map(int,input().split())
ab = [ tuple(map(int,input().split())) for i in range(M)]

edge = dd(list)

for i in range(M):
    tmp1 = ab[i][0]
    tmp2 = ab[i][1]
    edge[tmp1].append(tmp2)
    edge[tmp2].append(tmp1)
q = queue.Queue()
q.put((1,0))
res = [0]*N
mita = set()
mita.add(1)
# BFS
while not q.empty():
    tmp = q.get()
    now = tmp[0]
    depth = tmp[1]
    for elem in edge[now]:
        if elem not in mita:
            mita.add(elem)
            q.put((elem,depth+1))
            res[elem-1] = now
            

if 0 not in res[1:]:
    print('Yes')
    for val in res[1:]:
        print(val)
else:
    print('No')

Measured memory_bytes: 63720
import sys
def I(): return int(sys.stdin.readline().rstrip())

K = I()
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
if K % 7 == 0:
    K //= 7

s = 1
for i in range(1,K+1):
    if s % K == 0:
        print(i)
        exit()
    else:
        s *= 10
        s += 1
        s %= K


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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int n, m;
V<V<int> > g;
V<bool> seen;
int ans = 0, cnt = 0;

void dfs(int v){
    seen[v] = true;
    cnt++;
    if(cnt == n) ans++;
    for(auto next_v : g[v]){
        if(seen[next_v]) continue;
        dfs(next_v);
    }
    seen[v] = false;
    cnt--;

}

int main() {
    cin >> n >> m;
    g.resize(n + 1);
    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    seen.resize(n + 1, false);
    dfs(1);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int cnt[26];
int N, K;
string P[10004];

int next(int &S) {
    int ret = -1;
    int maxi = 0;
    rep(i, 26) {
        if (S >> i & 1) continue;
        if (cnt[i] && maxi < cnt[i]) {
            maxi = cnt[i];
            ret = i;
        }
    }
    if (ret != -1) S |= 1 << ret;
    return ret;
}

int main() {
    cin >> N >> K;
    rep(i, N) cin >> P[i];
    rep(i, N) cnt[P[i][0] - 'A']++;
    int ans = 0;

    bool isfinish = true;
    while (isfinish) {
        int S = 0;
        rep(i, K) {
            int c = next(S);
            if (c == -1) isfinish = false;
            cnt[c]--;
        }
        ans++;
    }
    cout << ans - 1 << endl;

    return 0;
}


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    deque<int> b;
    int x = 0;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if(x==0) b.push_back(a);
        else b.push_front(a);
        x = 1 - x;
    }
    if(n%2==0) {
        for(int i = 0; i < n; i++) {
            cout << b.at(i);
            if(i==n-1) cout << endl;
            else cout << " ";
        }
    }
    else {
        for(int i = n-1; i >= 0; i--) {
            cout << b.at(i);
            if(i==0) cout << endl;
            else cout << " ";
        }
    }
    
}


Measured memory_bytes: 2944
N = int(input())
score = [list(map(int, input().split())) for _ in range(N)]
players = [0 for _ in range(N)]
for play in list(zip(*score)):
    for i, p in enumerate(play):
        if play.count(p) == 1:
            players[i] += p
print(*players, sep='\n')

Measured memory_bytes: 7724
import collections
N=int(input())
A=[int(x) for x in input().split()]
c=collections.Counter(A)
P=list(c.keys())
Q=list(c.values())
count=0
for i in range(len(P)):
  if P[i]<=Q[i]:
    count += Q[i]-P[i]
  else:
    count +=Q[i]
print(count)


Measured memory_bytes: 18676
//ProblemF.cpp

#include <iostream>

static std::istream & ip = std::cin;
static std::ostream & op = std::cout;

#if OJ_MYPC
#include <ojio.h>
#endif

#ifndef OPENOJIO
#define OPENOJIO
#endif

#if 1 || DEFINE
/***************************************************************/
typedef unsigned long long u64;
typedef long long s64;

typedef unsigned uint;

#define ABS(a) ((a) > 0 ? (a) : -(a))

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))

#define MIN3(a, b, z) MIN(a, MIN(b, z))
#define MAX3(a, b, z) MAX(a, MAX(b, z))

#define FillZero(arr) memset(arr, 0, sizeof(arr));

/***************************************************************/
#endif //1 || DEFINE

#include <string>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>

//001
//op << setfill('0') << setw(3) << setiosflags(ios::right) << 1;

//op << fixed << setprecision(20);

using namespace std;

//ProblemF.cpp

typedef pair<int, int> coor;
int cw(int a, int b, const set<coor>& sw) {
	coor c;
	int& i = c.first;
	int& j = c.second;

	int rst = 0;
	for(i = a;i < a + 3;++i)
		for (j = b; j < b + 3; ++j)
		{
			if (sw.find(c) != sw.end()) ++rst;
		}
	return rst;
}

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

	s64 h, w, n;
	s64 rst[10];

	
	set<coor> ws;

	ip >> h >> w >> n;
	rst[0] = (h - 2) * (w - 2);
	for (int i = 1; i <= 9; ++i) rst[i] = 0;


	for (int i = 0; i < n; ++i) {
		int a, b;
		ip >> a >> b;

		for (int da = -2; da <= 0; ++da) {
			if (a + da < 1 || a + da + 2 > h) continue;

			for (int db = -2; db <= 0; ++db) {
				if (b + db < 1 || b + db + 2 > w) continue;

				int tc = cw(a + da, b + db, ws);
				--rst[tc];
				++rst[tc + 1];
			}
		}
		ws.insert(make_pair(a, b));
	}

	for (int i = 0; i <= 9; ++i) {
		cout << rst[i] << endl;
	}

	return 0;
}
/***************************************************************/


Measured memory_bytes: 4992
package main

// https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/all/ALDS1_9_B

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var infty = 2000000000 + 10

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

// LeftChild returns index of the left child of the current node
func LeftChild(i int) int {
	return 2*i + 1
}

// RightChild returns index of the right child of the current node
func RightChild(i int) int {
	return 2 * (i + 1)
}

// Parent returns index of the parent node of the current node
func Parent(i int) int {
	return (i - 1) / 2
}

// NewMaxHeap creates MaxHeap object
func NewMaxHeap(content []int) *MaxHeap {
	maxheap := &MaxHeap{content: content}
	return maxheap
}

// MaxHeap is
// - content: zero-indexed array
type MaxHeap struct {
	heapSize int
	content  []int
}

func (h MaxHeap) maxHeapify(i int) {
	l := LeftChild(i)
	r := RightChild(i)

	// fmt.Println(i, l, r, a)

	var largest int
	if (l < h.heapSize) && (h.content[l] > h.content[i]) {
		largest = l
	} else {
		largest = i
	}
	if (r < h.heapSize) && (h.content[r] > h.content[largest]) {
		largest = r
	}

	if largest != i {
		h.swap(i, largest)
		h.maxHeapify(largest)
	}
}

func (h MaxHeap) swap(i, j int) {
	temp := h.content[i]
	h.content[i] = h.content[j]
	h.content[j] = temp
}

// BuildMaxHeap returns max-heapified heap
func BuildMaxHeap(a []int) MaxHeap {
	h := MaxHeap{heapSize: len(a), content: a}
	for i := h.heapSize/2 - 1; i >= 0; i-- {
		h.maxHeapify(i)
	}
	return h
}

// NewPriorityQueue creates PriorityQueue object
func NewPriorityQueue(content []int) *PriorityQueue {
	maxHeap := BuildMaxHeap(content)
	pq := &PriorityQueue{maxHeap}
	return pq
}

// PriorityQueue is MaxHeap based priority queue
type PriorityQueue struct {
	maxHeap MaxHeap
}

func (pq PriorityQueue) getMaximum() int {
	return pq.maxHeap.content[0]
}

func (pq *PriorityQueue) dropMaximum() int {
	if pq.maxHeap.heapSize < 1 {
		fmt.Println("heap under flow")
	}

	max := pq.getMaximum()
	pq.maxHeap.content[0] = pq.maxHeap.content[pq.maxHeap.heapSize-1]
	pq.maxHeap.heapSize--
	pq.maxHeap.maxHeapify(0)

	return max
}

func (pq *PriorityQueue) increaseKey(i, key int) {
	if key < pq.maxHeap.content[i] {
		fmt.Errorf("key = %v < %v = a[i]", key, pq.maxHeap.content[i])
		return
	}
	pq.maxHeap.content[i] = key
	for (i >= 1) && (pq.maxHeap.content[Parent(i)] < pq.maxHeap.content[i]) {
		pq.maxHeap.swap(i, Parent(i))
		i = Parent(i)
	}
}

func (pq *PriorityQueue) insert(key int) {
	pq.maxHeap.heapSize++
	if len(pq.maxHeap.content) >= pq.maxHeap.heapSize {
		pq.maxHeap.content[pq.maxHeap.heapSize-1] = -infty
	} else {
		pq.maxHeap.content = append(pq.maxHeap.content, -infty)
	}
	pq.increaseKey(pq.maxHeap.heapSize-1, key)
}

func main() {
	scanner.Split(bufio.ScanWords)

	pq := NewPriorityQueue([]int{})

	for {
		command := nextString()
		if command == "extract" {
			fmt.Println(pq.dropMaximum())
		} else if command == "insert" {
			key, _ := nextInt()
			pq.insert(key)
		} else {
			break
		}
	}
}



Measured memory_bytes: 38372
n = int(input().rstrip())

line = input().rstrip().split(' ')
a = []
for i in range(n):
    a.append(int(line[i]))

total_xor = 0
for i in a:
    total_xor = total_xor ^ i

for i in a:
    ans = total_xor ^ i
    print(ans, end = ' ')

print()


Measured memory_bytes: 31576
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int K;
    cin >> K;
    ll ans = 0;
    rep(a, 1, K + 1) rep(b, 1, K + 1) rep(c, 1, K + 1) {
        ans += gcd(gcd(a, b), c);
    }
    write(ans);
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define INF         1e9
#define fastRead    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

const int MAX = 1e6 + 6;
int ara[10][10];

int main()
{
    fastRead;
    int n, m , k;
    cin>>n>>m>>k;
    
    for(int i =0 ; i < n ; i++ ) {
        string str;
        cin>>str;
        for(int j =0 ; j < m ; j++ ) {
            if(str[j] == '#') ara[i][j] = 1;
        }
    }
    
    int ans = 0;
    
    for(int i =0  ;i < (1<<n) ; i++ ) {
        
        for(int j =0 ; j < (1<<m) ; j++ ) {
            
            int cnt = 0;
            for(int ii = 0 ; ii < n ; ii++ ) {
                for(int jj =0 ; jj < m ; jj++ ) {
                    
                    if(ara[ii][jj] == 0) continue;
                    
                    if( (i &(1<<ii)) || (j &(1<<jj)) ) continue;
                    cnt++;
                }
            }
            if(cnt == k) ans++;
        }
    }
    cout<<ans<<'\n';
    return 0;
}

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

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

int main(){

  while(1){
    int m,nmin,nmax;
    cin>>m>>nmin>>nmax;
    if(m+nmin+nmax==0)break;
    vector<int> P(m);
    rep(i,m)cin>>P[i];

    int res = -1;
    int diff = 0;
    repl(i,nmin-1,nmax){
      int score = P[i]-P[i+1];
      if(diff<=score){
        diff = score;
        res = i;
      }
    }
    cout<<res+1<<endl;
  }

  return 0;
}



Measured memory_bytes: 3072
#https://atcoder.jp/contests/dp/tasks/dp_c

def c_vacation(n):
    dp=[[0 for i in xrange(3)] for j in xrange(n)]
    dp[0][0],dp[0][1],dp[0][2]=map(int,raw_input().split())
    for i in xrange(1,n):
        a,b,c=map(int,raw_input().split())
        dp[i][0]=max(a+dp[i-1][1],a+dp[i-1][2])
        dp[i][1]=max(b+dp[i-1][0],b+dp[i-1][2])
        dp[i][2]=max(c+dp[i-1][0],c+dp[i-1][1])
    print max(dp[-1])
n=int(input())
c_vacation(n)

Measured memory_bytes: 23556
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n,m,k[11],p[11],status[11],tmp;
    vi sk[11];
    cin>>n>>m;
    FOR(i, 0, m) {
    	cin>>k[i];
    	FOR(j, 0, k[i]) {
    		cin>>tmp; tmp--;
    		sk[i].push_back(tmp);
    	}
    }
    FOR(i, 0, m) cin>>p[i];
    int ans = 0;
    FOR(i, 0, (1<<n)) {
    	memset(status, 0, sizeof(status));
    	FOR(j, 0, n) {
    		if(i & (1 << j)) {
    			status[j] = 1;
    		}
    	}
    	bool poss = true;
    	FOR(j, 0, m) {
    		int cnt = 0;
    		FOR(x, 0, k[j]) {
    			if(status[sk[j][x]]) cnt++;
    		}
    		cnt %= 2;
    		if(cnt != p[j]) {
    			poss = false; break;
    		}
    	}
    	if(poss) ans++;
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"math/big"
	"os"
	"strconv"
)

func main() {
	n := readInt64()
	a := readInt64Slice(n)

	answer := big.NewInt(1)
	max := big.NewInt(10).Exp(big.NewInt(10), big.NewInt(18), nil)

	for _, v := range a {
		if v == 0 {
			fmt.Println(0)
			return
		}
	}

	for _, v := range a {
		answer.Mul(answer, big.NewInt(v))
		if answer.Cmp(max) > 0 {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(answer)
}

var (
	scanner *bufio.Scanner
)

func init() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}

func readInt64() int64 {
	var t string

	if scanner.Scan() {
		t = scanner.Text()
	}

	n, err := strconv.ParseInt(t, 10, 64)
	if err != nil {
		log.Fatal(err)
	}

	return n

}

func readInt64Slice(n int64) []int64 {
	s := make([]int64, n)
	var t string

	for i := 0; i < int(n); i++ {
		if scanner.Scan() {
			t = scanner.Text()
		}

		num, err := strconv.ParseInt(t, 10, 64)
		if err != nil {
			log.Fatal(err)
		}
		s[i] = num
	}

	return s
}


Measured memory_bytes: 6084
n, k, l, r = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
sum = a.inject(:+)
if k > n / 2
  k = n - k
  l, r = sum - r, sum - l
end
b = a[0..n/2]
c = a[n/2+1..-1]

hb = (0..b.size).map { Hash.new(0) }
hb[0][0] = 1
subset_sum = Array.new(2**b.size, 0)
one_count = Array.new(2**b.size, 0)
(1..2**b.size-1).each do |x|
  i = Math.log2((x ^ (x - 1)) + 1).to_i - 1
  y = x & (x - 1)
  subset_sum[x] = subset_sum[y] + b[i]
  one_count[x] = one_count[y] + 1
  hb[one_count[x]][subset_sum[x]] += 1
end

hc = (0..c.size).map { Hash.new(0) }
hc[0][0] = 1
subset_sum = Array.new(2**c.size, 0)
one_count = Array.new(2**c.size, 0)
(1..2**c.size-1).each do |x|
  i = Math.log2((x ^ (x - 1)) + 1).to_i - 1
  y = x & (x - 1)
  subset_sum[x] = subset_sum[y] + c[i]
  one_count[x] = one_count[y] + 1
  hc[one_count[x]][subset_sum[x]] += 1
end

answer = 0
(0..k).each do |m|
  next if !hb[m] || !hc[k - m]
  keys1 = hb[m].keys.sort
  keys2 = hc[k - m].keys.sort
  count_accum = [0]
  keys2.each {|x| count_accum << count_accum[-1] + hc[k - m][x] }

  keys1.each do |x|
    break if x > r
    i = (0..keys2.size-1).bsearch {|i| l <= x + keys2[i] } || keys2.size
    j = ((0..keys2.size-1).bsearch {|j| r <  x + keys2[j] } || keys2.size) - 1
    answer += hb[m][x] * (count_accum[j + 1] - count_accum[i])
  end
end
p answer



Measured memory_bytes: 161960
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
   fastio;
   ll n;
   cin>>n;
   ll c=n%1000;
   if(c!=0)
   {
       c=1000-c;
   }
   cout<<c<<endl;
   return 0;
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const long long MOD = 1e9 + 7;
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;
}

///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    ll X; cin >> X;
    ll A,B;
    bool ok = false;
    for(ll a = -1000; a <= 1000; a++){
        for(ll b = -1000; b <= 1000; b++){
            if (a*a*a*a*a-b*b*b*b*b == X) {
                A = a;
                B = b;
            }
        }
    }
    cout << A << " " << B << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);

        int max_x = sc.nextInt();
        int max_y = sc.nextInt();
        int min_x = 0;
        int min_y = 0;
        int n = sc.nextInt();

        for (int i = 0; i < n; i++)
        {
            int x = sc.nextInt();
            int y = sc.nextInt();
            int t = sc.nextInt();

            if (t == 1)
                min_x = Math.max(x, min_x);
            else if (t == 2)
                max_x = Math.min(x, max_x);
            else if (t == 3)
                min_y = Math.max(y, min_y);
            else if (t == 4)
                max_y = Math.min(y, max_y);
        }

        if ((max_x - min_x) < 0 || (max_y - min_y) < 0)
            System.out.println(0);
        else
            System.out.println((max_x - min_x) * (max_y - min_y));
    }
}


Measured memory_bytes: 21972
a,b,c,d,e,f=gets.split.map &:to_i
w={}
for i in 0..30
    for j in 0..30
        next if i==0 && j==0
        next if f<100*a*i+100*b*j
        w[100*a*i+100*b*j]=true
    end
end

s={}
for i in 0..(f+c-1)/c
    for j in 0..(f+d-1)/d
        next if c*i+d*j>f
        s[c*i+d*j]=true
    end
end

res=[]
w.each{|x,_| s.each{|y,_| res<<[x+y, y] if (100+e)*y<=e*(x+y) && x+y<=f } }
puts res.sort_by{|a, b|b.to_r/a}[-1]*' '


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  while (true) {
    int w, h; cin >> w >> h;
    if (!w) break;
    VV<> a(h, V<>(w));
    int si = -1, sj = -1, ti = -1, tj = -1;
    for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) {
      cin >> a[i][j];
      if (a[i][j] == 2) si = i, sj = j;
      if (a[i][j] == 3) ti = i, tj = j;
    }
    V<> di{1, 0, -1, 0}, dj{0, 1, 0, -1};
    auto in = [&](int i, int j) -> bool { return 0 <= i and i < h and 0 <= j and j < w; };
    int res = 11;
    auto dfs = [&](const auto& dfs, int k, int i, int j, int d) -> void {
      if (k == 10) return;
      int ni = i + di[d], nj = j + dj[d];
      if (!in(ni, nj) or a[ni][nj] == 1) return;
      i = ni, j = nj;
      while (true) {
        if (i == ti and j == tj) {
          res = min(res, k + 1);
          return;
        }
        ni = i + di[d], nj = j + dj[d];
        if (!in(ni, nj)) return;
        if (a[ni][nj] == 1) {
          a[ni][nj] = 0;
          for (int d = 0; d < 4; ++d) {
            dfs(dfs, k + 1, i, j, d);
          }
          a[ni][nj] = 1;
          return;
        }
        i = ni, j = nj;
      }
    };
    for (int d = 0; d < 4; ++d) dfs(dfs, 0, si, sj, d);
    cout << (res == 11 ? -1 : res) << '\n';
  }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


int main2() {
  string str;
  cin >> str;
  int N = (int)str.size();
  ll ans = 1;
  vector<int> cnt(26);
  REP(i, N) cnt[ str[i] - 'a' ]++;
  for (int i = 0; i < N; i++) {
    REP(c, 26) if (str[i] - 'a' != c) ans += cnt[c];
    cnt[str[i] - 'a']--;
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 640