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

int main()
{
	int H, W;
	cin >> H >> W;
	string s[50];
	int sum;
	int di[8] = { 1,1,0,-1,-1,-1,0,1 };
	int dj[8] = { 0,1,1,1,0,-1,-1,-1 };

	for (int i = 0; i<H; i++) cin >> s[i];

	for (int i = 0; i<H; i++) {
		for (int j = 0; j<W; j++) {
			if (s[i].at(j) == '.') {
				sum = 0;
				for (int k = 0; k < 8; k++) {
					if (i + di[k]< H && i+ di[k] >=0 && j+ dj[k]  <W && j+ dj[k]  >=0)
						if (s[i + di[k]].at(j + dj[k]) == '#')  sum += 1;
				}
				cout << sum;
			}else{
				cout << "#";
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
signed main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  
  ll x,y,lcm=c/gcd(c,d)*d;
  x=(b-b/c-b/d)+b/lcm;
  a--;
  y=(a-(a/c+a/d))+(a/lcm);

  ll ans=x-y;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
  
  
int cnt = 0;
int a[1000000];
  
void insertionSort(int a[], int n, int g){
  int i, j, key;
  
  for(i = g;i < n;i++){
    key = a[i];
    j = i - g;
    while(j >= 0 && a[j] > key){
      a[j+g] = a[j];
      j = j - g;
      cnt++;
    }
    a[j+g] = key;
  }
}
  
void shellSort(int a[], int n){
  int m = 13; 
  int g[13] = {1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 165720, 797161};
  int i;
  
  cnt = 0;
  while(g[m-1] > n){
    m--;
  }
  printf("%d\n", m);
  for(i = m-1;i >= 1;i--){
    printf("%d ", g[i]);
  }
  printf("%d\n", g[0]);
  for(i = m-1;i >= 0;i--){
    insertionSort(a, n, g[i]);
  }
}
 
main(){
  int n, i;
  
  scanf("%d", &n);
  for(i = 0;i < n;i++){
    scanf("%d", &a[i]);
  }
  shellSort(a, n);
  printf("%d\n", cnt);
  for(i = 0;i < n;i++){
    printf("%d\n", a[i]);
  }
  return 0 ;
}


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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 1e5;
const int INF = (int) 1e9 + 7;

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	ll ans = 0;
	int n;
	sf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		if (i % 5 != 0 && i % 3 != 0) ans += i;
	}
	printf("%lld", ans);

	return 0;
}


Measured memory_bytes: 3816
def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)

def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max,mod=DIV):
    fac,finv,inv = [0]*max, [0]*max, [0]*max
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod -inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    class CONV:
        def __init__(self):
            pass
        def ncr(self,n,k):
            if(n<k):
                return 0
            if(n<0 or k<0 ):
                return 0
            return fac[n]*(finv[k]*finv[n-k]%mod)%mod
    return CONV()



def main():
    N,K = isRaw()
    Hs = isRaw()
    Hs.sort()
    ans = 0
    for eidx in range(0,N-K):
        ans+=Hs[eidx]
    return ans


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


Measured memory_bytes: 87244
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <algorithm>
#include <random>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it;}cout<<endl;}

int main(){
    string s;
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin>>a[i];
    sort(alll(a));
    ll sum1=0,sum2=0;
    rep(i, n){
        if (i%2==0) {
            sum1+=a[i];
        }else sum2+=a[i];
        
    }
    pr(abs(sum2-sum1));
    return 0;
}


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

#define int long long int
using namespace std;
#define MOD 1000000007
using namespace std;
 
 
int n,m,s[2001],t[2001],sumarray[2001]={0};

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> t[i];
    }
    int out = 1;
 
    for (int i = 0; i < m; i++) {
        int temp = 0;
        for (int j = 0; j < n; j++) {
            if(j){
                if (t[i] == s[j]) {
                    int prev = temp + sumarray[j];
                    sumarray[j] += (temp + 1) % MOD;
                    temp = prev;
                } else {
                    temp += sumarray[j];
                }
            } else {
                temp += sumarray[j];
                if (t[i] == s[j]) {
                    sumarray[j] += 1;
                }
            }
        }
    }
    for (int i = 0; i < n; i++) {
        out += sumarray[i];
        out %= MOD;
    }
    cout << out << endl;
    return 0;
}



Measured memory_bytes: 3684
<?php
  /*
    AOJ 0174
    title:Badminton
    @kankichi573
  */
function my_count($str,$c)
{
  $cnt=0;
  while($str=strpbrk($str,$c))
    {
      //echo "str=".$str;
      $str=substr($str,1);
      $cnt++;
    }
  return($cnt);
}
$i=0;
$first[1]="0";
while(fscanf(STDIN,"%s",$record) && $record != "0")
{
  $record=substr($record,-(strlen($record)-1),strlen($record)-1);
  $a=my_count($record,"A");
  $b=my_count($record,"B");
  if($a > $b)
    $a++;
  else
    $b++;
  fprintf(STDOUT,"%d %d\n",$a,$b);
}

return(0);
?>

Measured memory_bytes: 6596
#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 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))
#define WRAP(y,x,h,w) (0<=y && y<h && 0<=x && x<w)

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

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((b * 10 + c) % 4 == 0)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
 
int main()
{    string x;
     cin>>x;
     long long s=0;
    
     for(long long i=0; i<(long long)x.size(); i++)
     { // cout<<(int)x[i]-'0'<<endl;
     	s+=(int)(x[i])-'0';}

     if(s%9==0)
     	cout<<"Yes"<<endl;
     else
     	cout<<"No"<<endl;
 
 }
 

Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n; cin >> n;
    n++;
    string s = to_string(n);
    int ans = (s.size() - 1) * 9 + s[0] - '1';
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxn 1000010

int n,sum[maxn],msum[maxn];
char s[maxn];

int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n;i++)sum[i]=sum[i-1]+(s[i]=='1'?1:-1);
	msum[n]=sum[n];for(int i=n-1;i>=1;i--)msum[i]=max(msum[i+1],sum[i]);
	int mx=max(msum[1],0),mn,now,ans=n+1;
	for(int j=1;j<=2;j++)
	{
		now=mn=0;
		for(int i=1;i<=n;i++)
		{
			if(s[i]=='?'){if(msum[i]-sum[i-1]+now+2<=mx)now++; else now--;}
			else if(s[i]=='1')now++; else now--;
//			printf("%c : %d %d %d\n",s[i],now,msum[i],sum[i-1]);
			mn=min(mn,now);
		}
		ans=min(ans,mx-mn);mx++;
	}
	printf("%d",ans);
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0; i<N; i++) cin >> a[i];
  int ans = 10000000;
  for (int i=-100; i<101; i++){
    int check = 0;
    for (int j=0; j<N; j++) check += (a[j] - i)*(a[j] - i);
    ans = min(ans, check);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
vector <int> sw(100005);
vector <int> bg(100005);
vector <int> hw(100005);
int dp[100005][3];
int solve(int i, int t){
    if(i>n){
        return 0;
    }
    if(dp[i][t]!=-1){
        return dp[i][t];
    }
    int q = 0;
    if(t==1){
        q = sw[i]+ max(solve(i+1,2), solve(i+1, 3));
    }
    else if(t==2){
         q = bg[i]+ max(solve(i+1,1), solve(i+1, 3));
    }
    else{
         q = hw[i]+ max(solve(i+1,2), solve(i+1, 1));
    }
    dp[i][t] = q;
    return q;
}
void initialize(){
    for(int i=0; i<100005;i++){
        for(int j=0; j<3;j++){
            dp[i][j]=-1;
        }
    }
}
int main(){
    initialize();
    cin>>n;
    for(int i=1; i<=n;i++){
        cin>>sw[i]>>bg[i]>>hw[i];
    }
    int ans = solve(1,1);
    ans = max(solve(1,2), ans);
    ans = max(solve(1,3), ans);
    cout<<ans<<endl;
}


Measured memory_bytes: 7296
n,m=map(int, input().split())
H=list(map(int, input().split()))
A=[]
for i in range(m):
    a,b=map(int, input().split())
    if H[a-1]<=H[b-1]:
        A.append(a)
    if H[a-1]>=H[b-1]:
        A.append(b)
A=set(A)
print(n-len(A))


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

using namespace std;

int main() {
  int N;
  cin >> N;
  int d[N];
  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }
  sort(d, d + N);
  reverse(d, d + N);

  vector<int> vec;
  vec.push_back(d[0]);
  for (int i = 1; i < N; i++) {
    if (vec.back() > d[i]) {
      vec.push_back(d[i]);
    }
  }
  cout << vec.size() << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
ans = [0 for i in range(n)]
for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    for j in range(d):
        ans[a[j]-1] += 1
cnt = 0
for i in range(n):
    if ans[i] == 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 9200
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    string s;

    cin >> s;

    int a, b;

    a = 10 * (s[0] - '0') + s[1] - '0';

    b = 10 * (s[2] - '0') + s[3] - '0';

    if (a <= 12 && b <= 12 && a > 0 && b > 0)
    {
        cout << "AMBIGUOUS" << endl;
    }
    else if (a <= 12 && a > 0)
    {
        cout << "MMYY" << endl;
    }
    else if (b <= 12 && b > 0)
    {
        cout << "YYMM" << endl;
    }
    else
    {
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
//2問目	
int main(){
	int table[]={1,5,10,50,100,500},n;
	int sum=0;
	for(int i=0;i<6;i++){
	cin>>n;
	sum+=n*table[i];
	}
	cout<<(sum>=1000)<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


int comb(int n, int k) {
	return (n&k) == k;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int N;
	cin >> N;
	string S;
	cin >> S;


	int ch = 0;
	for (int i = 0; i < N; i++) {
		ch += comb(N-1,i) * (S[i]-'0');
		ch %= 2;
	}
	if (ch == 1) { puts(1); return 0; }

	
	vector<int>a(N - 1);
	set<int>st;
	int cnt = 0;
	for (int i = 0; i < N - 1; i++) {
		a[i] = abs((S[i+1]-'0')-(S[i]-'0'));
		st.insert(a[i]);
		if (a[i] == 2 && comb(N - 2, i))cnt++;
	}

	if (st.count(1)) { puts(0); return 0; }

	if (cnt % 2 == 0)puts(0);
	else puts(2);

	return 0;
}

Measured memory_bytes: 5276
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    for(int i=0;i<B;i++){
        for(int j=0;j<W;j++){
            if(j < A) cout << 1;
            else cout << 0;
        }
        cout << endl;
    }
    for(int i=B;i<H;i++){
        for(int j=0;j<W;j++){
            if(j >= A) cout << 1;
            else cout << 0;
        }
        cout << endl;
    }
}


Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

// 素因数分解; 返り値は(素数, 乗数)のvector配列
vector<pair<ll, int>> factorize(ll n) {
	vector<pair<ll, int>> res;
	for (ll i = 2; i * i <= n; ++i) {
		if (n % i) continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1) res.emplace_back(n, 1);
	return res;
}

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
constexpr auto MAX = 100010;

// ──────────────────────────────────────────────────────────────────────────────

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

	vvl info(3);
	ll res = 0;
	rep(i, n) {
		rep(j, 3) {
			ll num; cin >> num;
			info[j].push_back(num);
		}
	}

	for (int bit = 0; bit < (1 << 3); ++bit) {
		vl all(n);
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 3; ++j) {
				if ((bit >> j) & 1) all[i] += info[j][i];
				else all[i] -= info[j][i];
			}
		}
		sort(DESC(all));
		ll ans = 0;
		rep(i, m) ans += all[i];
		res = max(res, ans);
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;
int main(){
    ll n;
    cin>>n;
    string s[110000];
    rep(i,0,n)cin>>s[i];
    rep(i,0,n) sort(s[i].begin(),s[i].end());
    sort(s,s+n);
    ll fuck=0,cnt=1,ans=0;
    while(fuck<n-1){
        
        if(s[fuck]==s[fuck+1])cnt++;
        else {ans+=cnt*(cnt-1)/2;cnt=1;}
        fuck++;
    }
    ans+=cnt*(cnt-1)/2;
    cout<<ans;
}


Measured memory_bytes: 7296
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int main(){
	const int MAX=200001;
	int N;
	cin>>N;
	ll a[MAX]={};
	ll sum=0;
	for(int i=0;i<N;i++){
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=1;i<N;i++){
		a[i]+=a[i-1];
	}
	ll mini=9223372036854775807;
	for(int i=0;i<N-1;i++){
		mini=min(mini,llabs(a[i]-(sum-a[i])));
	}
	cout<<mini<<endl;
	return 0;
}

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

class program
{
    static void Main()
    {
        var nk = Console.ReadLine().Split().Select(x => byte.Parse(x)).ToArray();
        byte n = nk[0], k = nk[1];
        byte[] istrick = new byte[n];
        for(byte i = 0; i < k; i++)
        {
            var d = byte.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(x => byte.Parse(x)).ToArray();
            for(byte j = 0; j < d; j++)
            {
                istrick[a[j] - 1]++;
            }
        }
        byte ans = 0;
        for(byte i = 0; i < n; i++)
        {
            if (istrick[i] == 0) ans++;
        }
        Console.Write(ans);
    }
}

Measured memory_bytes: 28260
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			int n = sc.nextInt();
			
			for(int i=0;i<n;i++){
				int[] t = new int[9];
				int[][] m = new int[3][10];
				for(int j=0;j<9;j++) t[j] = sc.nextInt();
				
				int rc = 0;
				int gc = 0;
				int bc = 0;
				String s;
				for(int j=0;j<9;j++){
					s = sc.next();
					if(s.compareTo("R")==0){
						rc++;
						m[0][t[j]]++;
					}else if(s.compareTo("G")==0){
						gc++;
						m[1][t[j]]++;
					}else{
						bc++;
						m[2][t[j]]++;
					}
				}
				if(rc%3==0 && gc%3==0 && bc%3==0){
					boolean flag = true;
					for(int k=0;k<3;k++){
						if(flag==true){
							for(int j=1;j<=9;j++){
								if(m[k][j]<0 || (j>7 && m[k][j]%3!=0)){
									flag = false;
									break;
								}
								if(m[k][j]==1 || m[k][j]==4){
									m[k][j]--;
									m[k][j+1]--;
									m[k][j+2]--;
								}else if(m[k][j]==2){
									m[k][j]-=2;
									m[k][j+1]-=2;
									m[k][j+2]-=2;	
								}
							}
						}
					}
					if(flag==true) System.out.println(1);
					else System.out.println(0);
				}else{
					System.out.println(0);
				}	
			}	
		}	
	}	
}

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

typedef long long ll;

ll ans;

void slv(ll a, ll b)
{
	if (a == 0) return;
	ll tmp = a/(b-a)*(b-a);
	ans += 2*tmp;
	a -= tmp;
	b -= tmp;
	if (a == 0) return;
	ans += b;
	slv(b-2*a, b-a);
}

int main()
{
	ll n, x;
	scanf("%lld%lld", &n, &x);
	ans = x;
	slv(x, n);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;
import java.math.*;
public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader()
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next()
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine();
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    static long[] ans=new long[100001];
     public static void main (String[] args) throws java.lang.Exception {
        FastReader sc=new FastReader();
        PrintWriter pw=new PrintWriter(System.out);
    	int t=1;//sc.nextInt();
        while (t-- > 0){
            //int n = sc.nextInt();
            List<Integer> l=new ArrayList<>();
            for(int i=0;i<2;i++) l.add(sc.nextInt());
            if(l.get(0)*2==l.get(1) || l.get(0)*4==l.get(1))
            pw.println("Yes");
            else if(l.get(1)%2==0 && (l.get(1)>2*l.get(0) && l.get(1)<4*l.get(0)))
            pw.println("Yes");
            else pw.println("No");
        }
    pw.close();
     }
}

  

Measured memory_bytes: 33544
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x, i, j) cerr << #x << "------------" << "\n";cerr << "from " << i << " to " << j << "\n";for(ll k=i; k<=j; k++) cerr << x[k] << " ";cerr << "\n"; cerr.flush();
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
 
const ll mod = 1e9 + 7;
const ll inf = 1e11 + 5;
const int MaxN = 2e5 + 5;

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

	int n, k, q;
	cin >> n >> k >> q;
	vi cnt(n + 1);
	for(int i = 1; i <= q; i++){
		int x;
		cin >> x;
		cnt[x]++;
	}
	for(int i = 1; i <= n; i++){
		cout << ((k + cnt[i] - q) > 0 ? "Yes": "No") << endl;
	}
	return 0;
}	


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
 int N;
 int A[210];
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> A[i];
  int res = 0;
  while(true){
   	bool exist_odd = false;
    
    for(int i=0;i<N;++i){
      if (A[i] % 2 != 0) exist_odd = true;
    }
    if(exist_odd) break;
    
    for (int i = 0; i < N; ++i) {
            A[i] /= 2;
    }
    ++res;
  }
  cout << res << endl;
}

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

using namespace std;

int w, h;
char area[55][55];
int whose[55][55];
bool visited[2][55][55];

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

void dfs(int x, int y, int c)
{
  visited[c][y][x] = true;
  if(area[y][x] == '.'){
    if(c == 0) whose[y][x]++;
    else if(c == 1) whose[y][x]--;
  }
  for(int i = 0; i < 4; i++){
    int nx = x + dx[i], ny = y + dy[i];
    if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
    if(area[ny][nx] == 'B' || area[ny][nx] == 'W') continue;
    if(visited[c][ny][nx]) continue;
    dfs(nx, ny, c);
  }
  return;
}

int main()
{
  while(cin >> w >> h, w || h){
    memset(area, '\0', sizeof(area));
    memset(whose, 0, sizeof(whose));
    memset(visited, false, sizeof(visited));
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++) cin >> area[i][j];
    }    
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(area[i][j] == 'B') dfs(j, i, 0);
	else if(area[i][j] == 'W') dfs(j, i, 1);
      }
    }
    int bc = 0, wc = 0;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	//printf("%2d", whose[i][j]);
	if(whose[i][j] == 1) bc++;
	else if(whose[i][j] == -1) wc++;
      }
      //cout << endl;
    }
    cout << bc << " " << wc << endl;
  }
  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h, w;cin>>h>>w;
	string s[h];
	for(int i = 0; i < h;++i) cin>>s[i];
	int dp[h][w]= {0};
	for(int i = 0; i < h;++i){
		for(int j = 0; j < w; ++j){
			dp[i][j] = 0;
		}
	}
	for(int i = 0; i < h; ++i){
		string temp = s[i];
		for(int j = 0; j < w;++j){
			set<int>s;
			if(temp[j]=='.'){
				while(j < w && temp[j]=='.'){
					s.insert(j);
					++j;
				}
			}
			if(s.size()){
				for(auto x : s){
					dp[i][x] += s.size();
				}
			}

		}
	}
	for(int i = 0; i < w; ++i){
		string temp = "";
		for(int j = 0; j < h;++j){
			temp += s[j][i];
		}
		for(int j = 0; j < h;){
			set<int>s;
			if(temp[j]=='.'){
				while(j < h && temp[j]=='.'){
					s.insert(j);
					++j;
				}
				--j;
			}
			if(s.size()){
				for(auto x : s){
					dp[x][i] += s.size();
				}
			}
			++j;
		}
	}
	int mx = 0;
	for(int i = 0; i < h;++i){
		for(int j = 0; j < w; ++j){
			mx = max(mx, dp[i][j]);
		}
	}
	cout<<mx - 1<<endl;
	return 0;
}



Measured memory_bytes: 20224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,end) for(ll i = 0; i < end ; i++ )
#define print(ans) cout << fixed << setprecision(15) << ans << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N, ans;
string S;


int main() {
  cin >> S;
  if (S == "Sunny"){
    print("Cloudy");
  }
  else if (S == "Cloudy"){
    print("Rainy");
  }
  else{
    print("Sunny");
  }
}



Measured memory_bytes: 3520
#include<stdio.h>
#include<math.h>
#ifdef DEBUG
#include<conio.h>
#endif // DEBUG


int main () {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif // DEBUG
    
    int a;
    scanf("%d", &a);
    printf("%d\n", (int)pow(a, 3));

#ifdef DEBUG
    getch();
#endif // DEBUG
    return 0;
}




Measured memory_bytes: 2044
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll n,m;cin>>n>>m;
    vp a;
    rep(i,m){
        ll from,to;cin>>from>>to;
        a.emplace_back(to,from);
    }
    sort(all(a));

    ll ans=0,mx=-1;
    rep(i,m){
        if(mx<a[i].second){
            ++ans;
            mx=a[i].first-1;
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

int c[100];
int tmax[100];

int main(){
	int n,k;
	while(cin>>n>>k&&n){
		for(int i=0;i<n;i++){
			cin>>c[i];
		}
		tmax[n-1]=-1;
		for(int i=n-2;i>=0;i--){
			tmax[i]=max(tmax[i+1],c[i+1]);
		}
		int m=1,cdush,cn,hmax=0;
		for(int i=0;i<k;i++)m*=c[i];
		cdush=m;
		for(int i=k;i<n;i++){
			m=m/c[i-k]*c[i];
			cdush=max(cdush,m);
		}
		m=1;
		for(int i=0;i<k;i++)m*=c[i];
		cn=cdush;
		cn=max(cn,m/ *min_element(c,c+k)*tmax[k-1]);
		for(int i=k;i<n;i++){
			m=m/c[i-k]*c[i];
			hmax=max(hmax,c[i-k]);		
			int mi=c[i];
			for(int j=i-k+1;j<=i;j++){
				mi=min(mi,c[j]);
			}
			cn=max(cn,m/mi*max(hmax,tmax[i]));
		}
		cout<<cn-cdush<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			var temp = int.Parse(Console.ReadLine());
			var data = new int[temp];
			for (int i = 0; i < temp; i++)
			{
				data[i] = int.Parse(Console.ReadLine());
			}
			int Search = 0;
			int cnt = 1;
			while (cnt <= temp)
			{
				if (data[Search] == 2)
				{
					Console.WriteLine(cnt);
					return;
				}
				else
				{
					Search = data[Search]-1;
					cnt++;
				}
			}
			Console.WriteLine("-1");
		}
	}
}


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MAX 1000010

using namespace std;

int n,A[MAX],cnt;

void insertionSort(int g){
  REP(i,g,n){
    int v = A[i];
    int j = i - g;
    while( j >= 0 && A[j] > v ){
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void shellSort(){
  cnt = 0;
  /*
  int m = rand() % min(n,100) + 1;
  int *G = new int[m];
  G[0] = 1;
  set<int> used;
  used.insert(1);
  REP(i,1,m){
    int v = rand() % n + 1;
    while( used.find(v) != used.end() ) v = rand() % n + 1;
    used.insert(v);
    G[i] = v;
  }
  sort(G,G+m);
  */
  int m = 1;
  vector<int> G;
  G.push_back(1);
  while( G.back()*3+1 <= n && m < 100 ){
    m++;
    G.push_back(G.back()*3+1);
  }
  reverse(G.begin(),G.end());
  rep(i,m)insertionSort(G[i]);
  cout << m << endl;
  rep(i,m){
    if( i ) cout << ' '; 
    cout << G[i];
  } cout << endl;
  cout << cnt << endl;
  rep(i,n)cout << A[i] << endl;
  //delete [] G;
}

int main(){
  srand((unsigned int)time(NULL));
  cin >> n;
  rep(i,n)cin>>A[i];
  shellSort();
  return 0;
}

Measured memory_bytes: 5124
#include<stdio.h>
int main(void){
	int a,b;
	int ans1,ans2;
	scanf("%d %d",&a,&b);
	ans1 = a * b;
	ans2 = (a + b) * 2;
	printf("%d %d\n",ans1,ans2);
	return 0;
}


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

int convert2int(string str) {
    int num = 0, a = 1;
    // 1文字ずつ見ていく
    for(unsigned int i = 0; i < str.size(); ++i) {
        // 入力されたものが数値だった場合、係数に入れる
        if('0' <= str[i] && str[i] <= '9') {
            a = str[i] - '0';
        }
        // 入力されたものが文字だった場合、適切に変換する
        else {
            switch(str[i]) {
            case 'm':
                num += a * 1000;
                break;
            case 'c':
                num += a * 100;
                break;
            case 'x':
                num += a * 10;
                break;
            case 'i':
                num += a;
                break;
            }
            // 係数を1に初期化する
            a = 1;
        }
    }
    return num;
}

string convert2mcxi(int num) {
    string str;
    int buf;
    // 整数値1桁ずつ回していく
    int cnt = 0;
    for(int i = 1000; i > 0; i /= 10) {
        // iの位をbufに入れる
        buf = num / i;
        // numからiの位を取り除く
        num %= i;
        // 2以上だったら数字を明記
        if(buf > 1) {
            str.push_back(buf + '0');
        }
        // 対応する位の文字を表示
        if(buf > 0) {
            str.push_back("mcxi"[cnt]);
        }
        ++cnt;
    }

    return str;
}


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

    string buf;
    int numA, numB;
    for(int i = 0; i < n; ++i) {
        // 入力を受け取って変換
        cin >> buf;
        numA = convert2int(buf);
        cin >> buf;
        numB = convert2int(buf);
        // そのまま足す
        numA += numB;

        cout << convert2mcxi(numA) << endl;
    }
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}






    
void test_case() {


   string s;
   cin>>s;

    vecl cnt(2019,0);

    ll sum = 0, p =1;
    for(int i=s.size() - 1; i>=0; i--) {
        sum = ((s[i]-'0') * p + sum) % 2019;
        p = ( p*10 ) % 2019;
        cnt[sum]++;
    }

    ll ans = cnt[0];
    for(int i=0; i<2019; i++) {
        ans+= cnt[i] * (cnt[i]-1)  /2;

    } 

    cout<<ans<<endl;



   

    


   

    

}


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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

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


int main(void){
  int n,c,cakes;
  
  cin >> n >> c;
  cakes = 0;
  for (int i=0; i<c; i++){
    int t; cin >> t;
    cakes += t;
  }  
  cout << (cakes+n)/(n+1) << endl;
  return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 998244353
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll pw(ll x,ll y){
	ll res=1;
	while(y){
		if(y&1)res=res*x%M;
		x=x*x%M;
		y>>=1;
	}
	return res;
}
void upd(ll &x,ll y){
	x=(x+y)%M;
}
ll n,m,cnt,z[100005],q[100005],p[100005],dp[100005][2];
bool uq[100005],up[100005];
map<P,ll>o;
int main(void){
    scanf("%lld%lld",&n,&m);
    for(int i=0;i<=n;i++)z[i]=-1,q[i]=-1,p[i]=-1;
    for(int i=0;i<m;i++){
		ll a,b,c;
		scanf("%lld%lld%lld",&b,&a,&c);
		a--,b--;
		ll x=a+b,y=abs(a-b);
		if(y>=3){
			if(o.find(P(x,y))==o.end()){
				o[P(x,y)]=c;
				cnt++;
			}else if(o[P(x,y)]!=c){
				printf("0\n");
				return 0;
			}
		}else if(y==2){
			x/=2;
			if(p[x]==-1)p[x]=c;
			else p[x]^=c,up[x]=true;
		}else if(y==1){
			x=(x-1)/2;
			if(q[x]==-1)q[x]=c;
			else q[x]^=c,uq[x]=true;
		}else z[x/2]=c;
	}
	dp[0][0]=1,dp[0][1]=1;
	for(int i=0;i<n;i++){
		if(z[i]!=-1)dp[i][z[i]^1]=0;
		if(p[i]==-1&&i>0&&i<n-1)dp[i][0]=dp[i][0]*2%M,dp[i][1]=dp[i][1]*2%M;
		else if(up[i])dp[i][p[i]^1]=0;
		if(uq[i]){
			upd(dp[i+1][q[i]],dp[i][0]);
			upd(dp[i+1][q[i]^1],dp[i][1]);
		}else{
			ll k=dp[i][0]+dp[i][1];
			if(q[i]==-1)k*=2;
			upd(dp[i+1][0],k);
			upd(dp[i+1][1],k);
		}
	}
	if(n==2)printf("%lld\n",(dp[n-1][0]+dp[n-1][1])%M);
	else printf("%lld\n",(dp[n-1][0]+dp[n-1][1])%M*pw(2,n*(n+1)/2-n*3+3-cnt)%M);
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define w(x)            int x; cin>>x; while(x--)
#define fr(i,a,b)       for(int i = a; i < b; i++)
#define mod				1000000007
void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

vi tree[100002];
int dp[100002][2];

int independent(int src, bool is_black, int pr)
{
	if (dp[src][is_black] != -1)
		return dp[src][is_black];

	int ans = 0, w1 = 1, w2 = 1;
	for (auto child : tree[src])
	{
		if (child != pr)
		{
			// subtree with its parent is black
			w1 = (w1 * independent(child, 0, src)) % mod;
		}
	}

	ans += w1;
	if (!is_black)
	{
		for (auto child : tree[src])
		{
			if (child != pr)
			{
				//subtree with its parent is not black
				w2 = (w2 * independent(child, 1, src)) % mod;
			}
		}
		ans = (ans + w2) % mod;
	}

	return dp[src][is_black] = ans;

}
void solve()
{
	int n, x, y;
	cin >> n;
	fr(i, 1, n)
	{
		cin >> x >> y;
		tree[x].pb(y);
		tree[y].pb(x);
	}
	memset(dp, -1, sizeof(dp));
	cout << independent(1, 0, -1) << endl;
}

int32_t main()
{
	c_p_c();
	solve();
	return 0;
}

Measured memory_bytes: 17508
n,d=map(int,input().split())
ans=0
X=[list(map(int,input().split())) for _ in range(n)]
for i ,j  in enumerate(X):
  for k in X[i+1:] :
    res=0
    for l in range(d):
       res+=(j[l]-k[l])**2
    if res**0.5-int(res**0.5)<10e-10:
          ans+=1
print(ans)
      
  

Measured memory_bytes: 38512
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define rev reverse
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define endl '\n'
#define ull unsigned long long
#define sz(x) (int)x.size()

template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll inf = 1e9+7;
const ll N = 1e5+1;
const ll mod = 1e9+7;
const ll P = 31;

int main() {
    IOS
    bool ok = 0;
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] != t[i]) {
            cout << "No" << endl;
            ok = 1;
            break;
        }
    }
    if(ok == 0) {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int K = scanner.nextInt();
    int[] l = new int[N];
    for (int i = 0; i < N; i++) {
      l[i] = scanner.nextInt();
    }
    Arrays.sort(l);
    long sum = 0;
    for (int i = 0; i < K; i++) {
      sum += l[N - i - 1];
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 22484
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
   
struct edge_t {
  int from;
  int to;
  int cost;
};
 
typedef struct edge_t Edge;
   
int main(){
  int num, i, k, from, to, cost, update;
  int nedge = 0;
  int dis[10000];
  Edge *edges, *p;
   
  edges = malloc(sizeof(Edge) * 500000);
   
  scanf("%d", &num);
   
  for (i = 0; i < num; i++){
    scanf("%d %d", &from, &k);
   
    while(k--){
      scanf("%d %d", &to, &cost);
   
      p = &edges[nedge++];
      p->from = from;
      p->to = to;
      p->cost = cost;
    }
    dis[i] = INT_MAX;
  }
  dis[0] = 0;
   
  update = 1;
  while(update){
    update = 0;
    for(i = 0; i < nedge; i++){
      from = edges[i].from;
      to = edges[i].to;
      cost = edges[i].cost;
      if(dis[from] < INT_MAX && dis[to] > cost + dis[from]){
	dis[to] = cost + dis[from];
	update = 1;
      }
    }
  }
  for(i = 0; i < num; i++){
    printf("%d %d\n", i, dis[i]);
  }
 
  return 0;
}

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

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

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;


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

    ll cnt=0;
    while(x<=y){
        x*=2;
        cnt++;
    }

    cout<<cnt<<endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#define reg register
#define ri reg int
#define rep(i, x, y) for(ri i = x; i <= y; ++i)
#define nrep(i, x, y) for(ri i = x; i >= y; --i)
#define DEBUG 1
#define ll long long
#define max(i, j) (i) > (j) ? (i) : (j)
#define min(i, j) (i) < (j) ? (i) : (j)
struct IO {
	#define MAXSIZE (1 << 20)
	#define isdigit(x) (x >= '0' && x <= '9')
	char buf[MAXSIZE], *p1, *p2;
	char pbuf[MAXSIZE], *pp;
	#if DEBUG
	#else
		IO() : p1(buf), p2(buf), pp(pbuf) {}
		~IO() {
			fwrite(pbuf, 1, pp - pbuf, stdout);
		}
	#endif
	inline char gc() {
		#if DEBUG
    		return getchar();
		#endif
    	if(p1 == p2)
			p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin);
    	return p1 == p2 ? ' ' : *p1++;
	}
	inline bool blank(char ch) {
    	return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
	}
	template <class T>
	inline void read(T &x) {
    	register double tmp = 1;
    	register bool sign = 0;
    	x = 0;
    	register char ch = gc();
    	for(; !isdigit(ch); ch = gc())
    		if(ch == '-') sign = 1;
    	for(; isdigit(ch); ch = gc())
			x = x * 10 + (ch - '0');
    	if(ch == '.')
			for(ch = gc(); isdigit(ch); ch = gc())
        		tmp /= 10.0, x += tmp * (ch - '0');
    	if(sign) x = -x;
	}
	inline void read(char *s) {
		register char ch = gc();
		for(; blank(ch); ch = gc());
		for(; !blank(ch); ch = gc())
			*s++ = ch;
    	*s = 0;
	}
	inline void read(char &c) {
    	for(c = gc(); blank(c); c = gc());
	}
	inline void push(const char &c) {
		#if DEBUG
    		putchar(c);
		#else
    		if(pp - pbuf == MAXSIZE) {
				fwrite(pbuf, 1, MAXSIZE, stdout);
				pp = pbuf;
			}
    		*pp++ = c;
		#endif
	}
	template <class T>
	inline void write(T x) {
    	if(x < 0) {
			x = -x;
			push('-');
		}
    	static T sta[35];
    	T top = 0;
    	do {
			sta[top++] = x % 10;
			x /= 10;
    	}while(x);
    	while(top)
			push(sta[--top] + '0');
	}
	template <class T>
	inline void write(T x, char lastChar) {
    	write(x);
		push(lastChar);
	}
} io;
char a, b, c;
int main() {
	scanf("%c%c%c", &a, &b, &c);
	if(a == 'R' && b == 'R' && c == 'R') io.write(3);
	else if(a == 'R' && b == 'R' || b == 'R' && c == 'R') io.write(2);
	else if(a == 'R' || b == 'R' || c == 'R') io.write(1);
	else io.write(0);
}

Measured memory_bytes: 1584
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

import java.util.*;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

		int D = in.nextInt();
		int[] c = new int[26];
		int[][] s = new int[D][26];
		for (int i=0;i<D;i++) {
			int max_val = 0;
			int max_ind = 0;
			for (int j=0;j<26;j++) {
				s[i][j] = in.nextInt();
				if (max_val <= s[i][j]) {
					max_val = s[i][j];
					max_ind = j;
				}
			}
			out.println(max_ind+1);
		}
		out.close();
	}

	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


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

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

using namespace std;

int main(){
	int a; cin>>a;
	bool vis[100000]={};
	int m;
	for(m=1;!vis[a];m++){
		vis[a]=true;
		if(a%2==0) a=a/2;
		else       a=3*a+1;
	}
	printf("%d\n",m);

	return 0;
}


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

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

  long long res;
  if (K >= A){
    res = A;
    K -= A;
    if (K >= B){
      K -= B;
      res -= K;
    }
  }
  else
    res = K;
  cout << res << "\n";

  return 0;
}

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

using namespace std;

using ll = long long;

const int MX = 200 * 1000 + 7;

ll a[MX], ps[MX];

ll ans = 0;
void solve(int l, int r) {
    if (l == r) {
        return;
    }

    int m = (l + r) / 2;
    vector<ll> lp, rp;
    for (int i = l; i <= m; i++) {
        lp.push_back(ps[i]);
    }
    for (int i = m + 1; i <= r; i++) {
        rp.push_back(ps[i]);
    }
    sort(lp.begin(), lp.end());
    sort(rp.begin(), rp.end());
    int ptr = 0;
    for (ll x : rp) {
        while (ptr < lp.size() && lp[ptr] <= x) {
            ptr++;
        }
        ans += ptr;
    }
    solve(l, m);
    solve(m + 1, r);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    int n;
    cin >> n;
    int k;
    cin >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] = a[i] - k;
        ps[i] = ps[i - 1] + a[i];
    }
    solve(0, n);
    cout << ans << endl;
}




Measured memory_bytes: 6712
a, b, c = map(int, raw_input().split())
if(a % 2 is 0 or b % 2 is 0 or c % 2 is 0):
  print 0
else:
  if(a > b):
    a, b = b, a
  if(b > c):
    b, c = c, b
  if(a > b):
    a, b = b, a
  print a * b

Measured memory_bytes: 2568