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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

LL big_mod(LL val,LL pow,LL mod);
LL mod_inverse(LL val,LL mod);
string sum_of_two_strings(string a,string b);
string division_of_string(string a,LL divisor);






int main()
{
    FAST();

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

    int n,d,ans=0;
    cin >> n >> d;
    while(n > 0)
    {
        n-=(2*d+1);
        ++ans;
    }
    cout << ans;
    return 0;
}








LL big_mod(LL val,LL pow,LL mod)
{
    LL res = 1;
    val = val % mod;
    while(pow > 0)
    {
        if(pow & 1)
        {
            res = (res*val) % mod;
        }
        pow = pow >> 1;
        val = (val*val) % mod;
    }
    return res;
}

LL mod_inverse(LL val,LL mod)
{
    LL mod1 = mod;
    if(mod == 1)
    {
        return 0;
    }
    LL y = 0;
    LL x = 1;
    LL quotient,temp;
    while(val > 1)
    {
        quotient = val / mod;
        temp = mod;
        mod = val % mod;
        val = temp;
        temp = y;
        y = x - quotient * y;
        x = temp;
    }
    if(x < 0)
    {
        x += mod1;
    }
    return x;
}

string sum_of_two_strings(string a,string b)
{
    reverse(a.B,a.E);
    reverse(b.B,b.E);
    char c;
    string ans="";
    int length_of_a=a.SZ,length_of_b=b.SZ;
    int i,carry=0,sum,length=max(length_of_a,length_of_b);
    for(i=0; i<length; i++)
    {
        if(i >= length_of_a)
        {
            sum=(b[i]-48)+carry;
        }
        else if(i >= length_of_b)
        {
            sum=(a[i]-48)+carry;
        }
        else
        {
            sum=(a[i]-48)+(b[i]-48)+carry;
        }
        carry=sum/10;
        sum%=10;
        c=sum+48;
        ans+=c;
    }
    if(carry > 0)
    {
        ans+=(carry+48);
    }
    reverse(ans.B,ans.E);
    return ans;
}

string division_of_string(string a,LL divisor)
{
    string ans="";
    int i=0,l=a.SZ;
    LL temp=a[0]-'0';
    while(temp < divisor)
    {
        temp=temp*10+(a[++i]-'0');
    }
    while(i < l)
    {
        ans+=((temp/divisor)+'0');
        temp=(temp%divisor)*10+(a[++i]-'0');
    }
    if(ans.SZ == 0)
    {
        return "0";
    }
    return ans;
}


Measured memory_bytes: 256
import sys
from collections import deque
from operator import itemgetter

input = sys.stdin.readline

N = int(input())
W = list(map(int, input().split()))
summ = []

for i in range(N):
    summ.append(abs(sum(W[:i+1]) - sum(W[i+1:])))

print(min(summ))

Measured memory_bytes: 3444
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))

neg = np.count_nonzero(A < 0)
zero = int(0 in A)

# 負の数が奇数個のときは全部正の数にできない。sum( abs(A) ) - 2*min(abs(A))
# 負の数が偶数個の時 or ０があるときはできる。

if zero > 0 or (neg % 2) == 0:
    ans = sum(abs(A))
else:
    ans = sum(abs(A)) - 2 * min(abs(A))
    # print(S, idx, A[idx], res)

print(ans)




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

int p(int x){
	int k=0;
	while(1){
		if(x==(1<<k))return x;
		else if(x<(1<<k))return (1<<k)-x;
		else k++;
	}
}

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for(auto &i:A)cin >> i;
	
	sort(A.begin(),A.end());
	
	int ans=0;
	while(!A.empty()){
		auto last=A.end();
		last--;
		int x=*last;
		int y=p(x);
		A.erase(last);
		if(binary_search(A.begin(),A.end(),y)){
			ans++;
			auto it=lower_bound(A.begin(),A.end(),y);
			A.erase(it);
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {

	int N=0,M=0;
	
	cin >> N>>M;
	vector<int> aaaa(N);

	int c = 0;
	int p = 0;

	for (int i = 0; i < M; i++)
	{
		int t = 0;
		string st;
		cin >> t;
		t--;
		cin >> st;
		
		if (st.compare("WA")==0) {
			if (aaaa[t] != -1) {
				
				aaaa[t]++;
			}
		}
		else {
			if (aaaa[t] != -1) {
				p += aaaa[t];
				aaaa[t] = -1;
				c++;
			}
		}

	}


	cout << c << " " << p << endl;
	return 0;
}




Measured memory_bytes: 640
n = int(input())
d_list = [input() for i in range(n)]

unique_num_dict = {}
for i in range(n):
    if d_list[i] in unique_num_dict.keys():
        unique_num_dict[d_list[i]] += 1
    else:
        unique_num_dict[d_list[i]] = 1

print(len(unique_num_dict))


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


int main() {
  int k, s;
  cin >> k >> s;

  int ans = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      int now = s -(x + y);
      if (now >= 0 && now <= k) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1e9 + 5
using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector<int> h(n);

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

    vector<int> dp(n, INT_MAX);
    dp[0] = 0;

    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j <= i + 2; j++)
        {
            if (j < n)
                dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));
        }
    }

    cout << dp[n - 1] << "\n";
}

int main()
{
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    /*
    int t;
    cin >> t;

    while (t--)
    */
    solve();

    return 0;
}

Measured memory_bytes: 3972
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int nx[4]={0,1,-1,0};
int ny[4]={1,0,0,-1};
int main(){
  ll n;
  cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  ll cu=0;
  ll k=0;
  ll ans=INF;
  rep(i,n){
    if(i%2==0){
      if(cu+a[i]<0){
        k+=abs(cu+a[i])+1;
        cu=1;
      }
      else if(cu+a[i]==0){
        cu=1;
        k++;
      }
      else{
        cu+=a[i];
      }
    }
    else{
      if(cu+a[i]>0){
        k+=cu+a[i]+1;
        cu=0;
        cu--;
      }
      else if(cu+a[i]==0){
        cu=0;
        cu--;
        k++;
      }
      else{
        cu+=a[i];
      }
    }
  }
  ans=min(ans,k);
  k=0;
  cu=0;
  rep(i,n){
    if(i%2==1){
      if(cu+a[i]<0){
        k+=abs(cu+a[i])+1;
        cu=1;
      }
      else if(cu+a[i]==0){
        cu=1;
        k++;
      }
      else{
        cu+=a[i];
      }
    }
    else{
      if(cu+a[i]>0){
        k+=cu+a[i]+1;
        cu=0;
        cu--;
      }
      else if(cu+a[i]==0){
        cu=0;
        cu--;
        k++;
      }
      else{
        cu+=a[i];
      }
    }
  }
  ans=min(ans,k);
  COUT(ans);
}



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

struct Matrix{
  int x, y;
};

int dp[111][111];
vector<Matrix> v;
Matrix matrix[111][111];

int main(){

  int n, r, c;

  cin >> n;

  for(int i = 0; i < n; i++){
    cin >> r >> c;
    v.push_back((Matrix){r,c});
  }

 
  for(int i = 0; i < n; i++) dp[i][i] = 0;
  for(int i = 1; i < n; i++){
    for(int j = 0; j < n - i; j++){
      int s = j + i;
      dp[j][s] = INT_MAX;
      for(int l = j; l < s; l++){
	dp[j][s] = min(dp[j][s],dp[j][l] + dp[l+1][s] + v[j].x * v[s].y * v[l].y);
      }
    }
  }
  cout << dp[0][n-1] << endl;
 }

Measured memory_bytes: 1260
S = input()
a = int(S[:2])
b = int(S[2:])

if 1 <= a and a <= 12 and 1 <= b and b <= 12:
    print("AMBIGUOUS")
elif 1 <= a and a <= 12 and (b > 12 or b < 1):
    print("MMYY")
elif (a > 12 or a < 1) and 1 <= b and b <= 12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3064
# https://atcoder.jp/contests/abc108/tasks/abc108_b
x1, y1, x2, y2 = [int(x) for x in input().split()]
x3 = x2 + (y1 - y2)
y3 = y2 + (x2 - x1)
x4 = x1 + (y1 - y2)
y4 = y1 + (x2 - x1)
print(x3, y3, x4, y4)


Measured memory_bytes: 2940
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    
    int N, K, Q;
    cin >> N >> K >> Q;

    vector<int> A(N, 0);

    rep(i,Q) {
        int x;
        cin >> x;
        A[x - 1]++;
    }

    rep(i,N) {
        if (K - (Q - A[i]) > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,s=1;
	cin>>a>>b;
	if(a>b)swap(a,b);
	for(int i=a;i<=b;i++)
	{  
	  if(i<0)s*=-1;
	  if(i==0){cout<<"Zero"<<endl;return 0;}
	  if(i>0)continue;
	}
	if(s>0)cout<<"Positive"<<endl;
    if(s<0)cout<<"Negative"<<endl;
    if(s==0)cout<<"Zero"<<endl;
	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define mii make_pair<int, int>
#define mll make_pair<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define all(v) (v).begin(), (v).end()

//ofstream out("debug.txt");

const int MxN = 1e5, md = 1e9 + 7;

const int MAX = 1000001;

int factor[MAX] = {0};

void generatePrimeFactors()
{
    factor[1] = 1;

    for (int i = 2; i < MAX; i++)
        factor[i] = i;

    for (int i = 4; i < MAX; i += 2)
        factor[i] = 2;

    for (int i = 3; i * i < MAX; i++)
    {
        if (factor[i] == i)
        {

            for (int j = i * i; j < MAX; j += i)
            {

                if (factor[j] == j)
                    factor[j] = i;
            }
        }
    }
}

int calculateNoOFactors(int n)
{
    if (n == 1)
        return 1;

    int ans = 1;

    int dup = factor[n];

    int c = 1;

    int j = n / factor[n];

    while (j != 1)
    {

        if (factor[j] == dup)
            c += 1;

        else
        {
            dup = factor[j];
            ans = ans * (c + 1);
            c = 1;
        }

        j = j / factor[j];
    }

    ans = ans * (c + 1);

    return ans;
}

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

    int n;
    generatePrimeFactors();
    vl v(1e6 + 1, 0);
    for (int i = 1; i < 1e6; ++i)
        v[i] = v[i - 1] + calculateNoOFactors(i);

    cin >> n;
    cout << v[n - 1];
}

Measured memory_bytes: 15016
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n,d,a;
  cin >> n >> d >> a;
  vector<P> p(n+1,{INF,0});
  vl x(n+1,INF),h(n+1,0);
  rep(i,n){
    cin >> x[i] >> h[i];
    h[i]=(h[i]-1)/a+1;
    p[i].first=x[i];
    p[i].second=h[i];
  }
  rep(i,n){
    p[i].first=x[i];
    p[i].second=h[i];
  }
  sort(p.begin(),p.end());
  vl DIS(n);
  vl delta(n,0);
  ll atk=0;
  ll R=0;
  rep(i,n){
    while(p[R+1].first<=2*d+p[i].first){
      R++;
    }
    DIS[i]=R;
  }
  ll cnt=0;
  rep(i,n){
    if(delta[i]<0){
      atk+=delta[i];
    }
    if(p[i].second>atk){
      cnt+=(p[i].second-atk);
      delta[DIS[i]+1]-=p[i].second-atk;
      atk=p[i].second;
    }
  }
  cout << cnt << endl;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

#define MOD 1000000007

int main(void)
{
    int N;
    cin >> N;

    ll ans = 1;
    FOR(i,1,N){
        ans = ans*i % MOD;
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    int N, Y;
    cin >> N >> Y;
    
    int c;
    bool res = false;
    for(int a=0;a<=N;a++){
        if(res==true) break;
        for(int b=0;b<=(N-a);b++){
            c = N - (a + b);
            if(10000 * a + 5000 * b + 1000 * c == Y){
                res = true;
                cout << a << " " << b << " " << c << endl;
                break;
            }
        }
    }
    if(res == false){
        cout << -1 << " "  << -1 << " "  << -1 << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

	long long a, b, x;
	long long ans = 0 ;

	cin >> a >> b >> x;

	if (a > 0) {
		ans = b / x - (a - 1) / x;
	}
	else {
		ans = b / x + 1;
	}
	cout << ans << endl;

	return 0;

}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	long long int N, K, p, r, count = 0;
	cin >> N >> K;
	if(K == 0){
		cout << N * N << endl;
		return 0;
	}
	for(long long int b = K + 1; b <= N; ++b){
		//N = pb + r
		p = N / b;
		r = N % b;
		//余りは周期bの列(0,1,...b-1)がp回繰り返された後に長さb未満の列(0,1,...r)が1つ加わる
		//周期列のうち余りがK以上なのはmax(0,b-K)個, 最後の列のうち余りがK以上なのはmax(0,r-K+1)個
		count += p * (b-K) + ((r-K+1 >= 0) ? r-K+1 : 0);
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<stack>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include <iomanip>
#include<unordered_map>
#include<set>
using namespace std;
typedef long long ll;
const int maxn=15;

string str[maxn];
bool f[maxn][maxn];
int h,w;

int main() {
    //freopen("in.cpp","r",stdin);
    cin>>h>>w;
    for(int i=0; i<h; i++)cin>>str[i];
    if(str[0][0]!='#') {
        cout<<"Impossible"<<endl;
    } else {
        f[0][0]=1;
        for(int i=0;i<h;i++)
        for(int j=0;j<w;j++){
            if(f[i][j]){
                int cnt=0;
                if(j+1<w&&str[i][j+1]=='#'){
                    f[i][j+1]=1;
                    cnt++;
                }
                if(i+1<h&&str[i+1][j]=='#'){
                    f[i+1][j]=1;
                    cnt++;
                }
                if(cnt==2){
                    f[i][j+1]=f[i+1][j]=0;
                }
            }
        }
        bool sign=0;
        for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
        if(str[i][j]=='#'&&!f[i][j])sign=1;
        if(sign)cout<<"Impossible"<<endl;
        else cout<<"Possible"<<endl;
    }
    return 0;
}


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

double a, b, c, d, e, f;
void solve(double &x, double &y)
{
    if (b == 0)
    {
        x = c / a;
        y = (f - d * x) / e;
    }
    else
    {
        x = (b * f - e * c) / (b * d - e * a);
        y = (c - a * x) / b;
    }
}

int main()
{
    while (cin >> a >> b >> c >> d >> e >> f)
    {
        double x, y;
        solve(x, y);
        if (x == 0) x = 0;
        if (y == 0) y = 0;
        printf("%.3f %.3f\n", x, y);
    }
    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int B=315;
const int SZ=318;

int dat[SZ][B]={};
int sumF[SZ]={}, sumG[SZ]={};
int flg[SZ];

void init(int n, string s)
{
    rep(i,SZ)rep(j,B)
    {
        int idx = i*B+j;
        if(idx<n) dat[i][j] = s[idx]-'0';
    }

    memset(flg,-1,sizeof(flg));

    // sumF
    rep(i,SZ)
    {
        rep(j,B) sumF[i]+=dat[i][j];
    }

    // sumG
    rep(i,SZ)
    {
        rep(j,B-1) sumG[i]+=dat[i][j]*dat[i][j+1];
    }
}

void update(int l, int r, int b)
{
    int lb = l/B, rb = r/B;
    if(lb==rb)
    {
        if(flg[lb]!=-1)
        {
            rep(i,B) dat[lb][i] = flg[lb];
            flg[lb] = -1;
        }

        for(int i=l-lb*B; i<=r-lb*B; ++i) dat[lb][i]=b;

        sumF[lb]=sumG[lb]=0;
        rep(i,B) sumF[lb]+=dat[lb][i];
        rep(i,B-1) sumG[lb]+=dat[lb][i]*dat[lb][i+1];
    }
    else
    {
        if(flg[lb]!=-1)
        {
            rep(i,B) dat[lb][i] = flg[lb];
            flg[lb] = -1;
        }
        for(int i=l-lb*B; i<B; ++i) dat[lb][i]=b;
        sumF[lb]=sumG[lb]=0;
        rep(i,B) sumF[lb]+=dat[lb][i];
        rep(i,B-1) sumG[lb]+=dat[lb][i]*dat[lb][i+1];

        for(int i=lb+1; i<rb; ++i)
        {
            flg[i]=b;
            sumF[i]=B*b;
            sumG[i]=(B-1)*b;
        }

        if(flg[rb]!=-1)
        {
            rep(i,B) dat[rb][i] = flg[rb];
            flg[rb] = -1;
        }
        for(int i=0; i<=r-rb*B; ++i) dat[rb][i]=b;
        sumF[rb]=sumG[rb]=0;
        rep(i,B) sumF[rb]+=dat[rb][i];
        rep(i,B-1) sumG[rb]+=dat[rb][i]*dat[rb][i+1];
    }
}

int F()
{
    int ret=0;
    rep(i,SZ) ret+=sumF[i];
    return ret;
}

int G()
{
    int ret=0;
    rep(i,SZ) ret+=sumG[i];

    rep(i,SZ-1)
    {
        int p=dat[i][B-1];
        if(flg[i]!=-1) p=flg[i];

        int q=dat[i+1][0];
        if(flg[i+1]!=-1) q=flg[i+1];

        ret+=p*q;
    }
    return ret;
}

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

    init(n,s);

    int q;
    scanf(" %d", &q);
    while(q--)
    {
        int l,r,b;
        scanf(" %d %d %d", &l, &r, &b);
        --l;
        --r;
        update(l,r,b);
        printf("%d\n", F()-G());
    }

    return 0;
}

Measured memory_bytes: 3784
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Map<String, Integer> mp = new HashMap<>();

        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        mp.put("AC", 0);
        mp.put("WA", 0);
        mp.put("TLE", 0);
        mp.put("RE", 0);

        while (t>0){

            String in = sc.next();

            mp.put(in, mp.get(in)+1);

            t--;
        }

        System.out.println("AC x " + mp.get("AC"));
        System.out.println("WA x " + mp.get("WA"));
        System.out.println("TLE x " + mp.get("TLE"));
        System.out.println("RE x " + mp.get("RE"));

    }
}


Measured memory_bytes: 58204
program  ABC_089_B_HinaArare
   implicit none
   integer N ,i
   character(1), allocatable :: S(:)
   read(*, *) N
   allocate(S(1: N))
   read(*, *) S(1: N)
   do i =1, N
      if(S(i) == 'Y') then
	      write(*, *) 'Four'
		  exit
	  else if(i == N) then
	      write(*, *) 'Three'
	  end if
   end do
end program  ABC_089_B_HinaArare

Measured memory_bytes: 256
def solve():
    MOD = 10**9 + 7

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

    ds = []
    for i in range(N-1):
        d = xs[i+1] - xs[i]
        ds.append(d)

    nums = [1, 1]
    num = 1
    for i in range(2, N-1):
        num *= i
        num %= MOD
        nums.append(num)

    ms = [N-1]
    m = N-1
    for i in reversed(range(2, N-1)):
        m *= i
        m %= MOD
        ms.append(m)
    ms.reverse()
    ms.append(1)

    ks = []
    k = 0
    for num, m in zip(nums, ms):
        k += num*m % MOD
        k %= MOD
        ks.append(k)

    ans = 0
    for d, k in zip(ds, ks):
        ans += d*k % MOD
        ans %= MOD

    print(ans)

solve()


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

using namespace std;
int main()
{
    int h, w;
    int H, W, cnt = 0;
    cin >> H >> W;

    int array[H][W];

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            array[i][j] = 0;
        }
    }

    cin >> h >> w;

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < W; j++)
        {
            array[i][j] = 1;
        }
    }
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < w; j++)
        {
            array[i][j] = 1;
        }
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (array[i][j] == 0)
            {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
n, W = map(int, input().split())
w = []
v = []
V = 0
for i in range(n):
    tmp1, tmp2 = map(int, input().split())
    w.append(tmp1)
    v.append(tmp2)
    V += tmp2

dp = [[float('inf') for _ in range(V+1)] for _ in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(V+1):
        if j-v[i] >= 0: dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]]+w[i])
        else: dp[i+1][j] = dp[i][j]

ans = 0
for i in range(V+1):
    if dp[-1][i] <= W: ans = i

#print(dp)
print(ans)

Measured memory_bytes: 319808
import java.util.Scanner;

public class Main{
  public static void main(String[]args){
  	Scanner sc=new Scanner(System.in);
  	while(true){
  		int n=sc.nextInt();
  		int r=sc.nextInt();

  		if(n==0&&r==0){break;}
  		
  		int card[]=new int[n];
  		int dummy[]=new int[n];


  		for(int i=0;i<n;i++){
  			card[i]=n-i;
  			dummy[i]=n-i;
  		}

  		for(int i=0;i<r;i++){
  		int p=sc.nextInt();
  		int c=sc.nextInt();

  			for(int j=0;j<p+c-1;j++){
  				if(j<c){
  					card[j]=dummy[p+j-1];
  				}else{
  					card[j]=dummy[j-c];
  				}
  			}

  			for(int j=0;j<p+c-1;j++){
  				dummy[j]=card[j];
  			}
  		}
  		System.out.println(card[0]);
  	}
  }
}

Measured memory_bytes: 28404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 4e18;
const ll MOD = 1e9+7;
int n;
pair<ll,pair<ll,ll>> a[100010];

int main(){
//  ios::sync_with_stdio(false);
//  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].second.first >> a[i].second.second;
    a[i].first = a[i].second.first + a[i].second.second;
  }
  sort(a,a+n);
  reverse(a,a+n);
  ll ans1 = 0, ans2 = 0;
  for (int i = 0; i < n; i++) {
    if (i&1) {
      ans2 += a[i].second.second;
    } else {
      ans1 += a[i].second.first;
    }
  }
  cout << ans1 - ans2 << endl;
  return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const int maxn = 1e5+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
char c[maxn];
int main(){
	n=read();
	scanf("%s",c+1);
	int num=0;
	for(register int i=1;i<=n;i++){
		if(c[i]!=c[i-1])num++;
	}
	printf("%d\n",num);
	return 0;
}

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

int n, a[100100], d[100100];
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    int sum = 0, evensum = 0;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        sum += a[i];
        if (i % 2 == 0) evensum += a[i];
    }
    d[1] = sum - (evensum * 2); 
    for(int i = 2; i <= n; ++i) {
        d[i] = a[i-1] * 2 - d[i-1];
    }
    for(int i = 1; i <= n; ++i) {
        cout << d[i] << ' ';
    }
}


Measured memory_bytes: 5168
//---------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//                                                        NEVER  GIVE  UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define testcases() ll t; cin>>t; while(t--)
#define debug cout<<"Hello\n";
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
//------------------------------------------------------------------------------------------------------------------------------

int main()
{
	
	#ifndef ONLINE_JUDGE
	freopen("C:/Users/DELL/Desktop/input.txt", "r", stdin);
	#endif

	fast;
	string str;
	cin>>str;
	if(str.back() == 's')
		str += "es";
	else
		str += "s";
	cout<<str;	
	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;

int main(){
    string S;
    cin >> S;
    int n = 0, k = S.size(), m, Max = 0;
    int len[10];
    for(int i = 0; i < k; i++) len[i] = 0;
    for(int i = 0; i < k; i++){
        m = i;
        while(S[i] == 'A' || S[i] == 'C'|| S[i] == 'G'|| S[i] == 'T'){
            len[m]++;
            i++;
        }
    }
    for(int i = 0; i < k;i++){
        if(Max < len[i]) Max = len[i];
    }
    cout  << Max << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

ll dfs(int k, const vector<vector<int>> &g, int now, int prev) {
	int colorNum = prev == -1 ? k - 1 : k - 2;

	if (k < g[now].size()) {
		return 0;
	}

	ll cnt = 1;
	for (auto e : g[now]) {
		if (e == prev) {
			continue;
		}

		cnt *= colorNum--;
		cnt %= MOD;
	}

	for (auto e : g[now]) {
		if (e == prev) {
			continue;
		}

		cnt *= dfs(k, g, e, now);
		cnt %= MOD;
	}

	return cnt;
}

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

	int n, k;
	cin >> n >> k;

	vector<vector<int>> g(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;

		g[a].push_back(b);
		g[b].push_back(a);
	}

	ll ans = k * dfs(k, g, 0, -1);
	ans %= MOD;

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 11648
A,B,C,K = map(int,input().split())
ans = 0
if A >= K:
    print(K)
    exit()
else:
    ans += A
    K -= A
    if B >= K:
        print(ans)
        exit()
    else:
        K -= B
        if C >= K:
            ans -= K
            print(ans)
        else:
            print(ans)




Measured memory_bytes: 9188
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

//#define __int64 long long
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

int a[100001];
	
int main(){
	int n;
	int ans = 0;
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> a[i];
	}
	
	for(int i=1; i<=n; i++){
		if(a[a[i]] == i){
			ans ++;
		}
	}
	
	cout << (ans / 2) << endl;
    
    return 0;
}

Measured memory_bytes: 640
N=int(input())
x=[0]*N
y=[0]*N
for i in range(N):
  x[i],y[i]=map(int,input().split())
answer=0
kaijou=1
junretu=0
for i in range(2,N+1):
  kaijou*=i
junretu=int(N*(N-1)/2)
a=int(kaijou*(N-1)/(junretu*2))

for i in range(N):
  for j in range(N):
    if i!=j:
      answer+=((x[i]-x[j])**2+(y[i]-y[j])**2)**(1/2)
print((answer*a)/kaijou)

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


using namespace std;

const int M = 1000005;

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

    int ans(0);
    vector<int> dp(M,0);
    int p;

    for(auto e:A){
        if(dp[e] != 0){
            dp[e] = 2;
            continue;
        }
        for(p = e; p < M; p += e){
            dp.at(p)++;
        }
    }

    for(auto e:A){
        if(dp[e] == 1) ans++;
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 7944
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()0
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=100009;
 
// Happy Coding!


void solve(){
    int n;
    cin>>n;
    priority_queue<int> pq;
    while(n-->0){
        int x;
        cin>>x;
        pq.push(x);
    }
    int sum=0;
    int p=0;
    while(!pq.empty()){
        if(!p){
            sum+=pq.top();
        }
        else{
            sum-=pq.top();
        }
        pq.pop();
        p=!p;
    }
    cout<<sum<<endl;
}

 
int main() {
    faster;
    int t=1;
    // cin>>t;
    
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define a first.first
#define b first.second
#define c second

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	const int MAX = 1100;
	
	int N, Ma, Mb;
	int ans = INF;
	vector<pair<pair<int,int>,int>> in;
	vector<vector<int>> dp;
	cin>>N>>Ma>>Mb;
	
	in.resize(N);
	dp.resize(MAX, vector<int>(MAX, INF));
	
	for(int i = 0; i < N; i++){
		cin>>in[i].a>>in[i].b>>in[i].c;
	}
	
	dp[0][0] = 0;
	
	for(int i = 0; i < N; i++){
		for(int j = MAX-1; j >= 0; j--){
			for(int k = MAX-1; k >= 0; k--){
				if(j + in[i].a < MAX && k + in[i].b < MAX) {
					dp[j + in[i].a][k + in[i].b] = min(dp[j + in[i].a][k + in[i].b], dp[j][k] + in[i].c);
				}
			}
		}
	}
	
	for(int j = 1; j < MAX; j++){
		for(int k = 1; k < MAX; k++){
			if(Ma * k == Mb * j){
				ans = min(dp[j][k], ans);
			}
		}
	}
	
	if(ans == INF) cout<<-1<<endl;
	else cout<<ans<<endl;
		
	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //freopen("data.in", "r", stdin);

  string s;
  cin >> s;
  int max_ = s.length()/2;
  int c = 0;
  int i = 0, l = s.length()-1;
  while (max_--) {
    if (s[i] != s[l-i]) c++;
    i++;
  }

  cout << c << endl;

  return 0;
}

Measured memory_bytes: 3660
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC102_B solver = new ABC102_B();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC102_B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long max = Long.MIN_VALUE;
            long min = Long.MAX_VALUE;

            for (int i = 0; i < n; i++) {
                long tmp = in.nextLong();

                max = Math.max(max, tmp);
                min = Math.min(min, tmp);
            }

            out.print(max - min);
        }

    }
}



Measured memory_bytes: 23252
#include<stdio.h>

int main()
{ 
int m,flag=0;
    scanf("%d",&m);
    
    for(int i=1;i<=9;i++)
    {for(int j=1;j<=9;j++){
            if(i*j==m)
            {flag=1;break;}
            
        }}
    if(flag==1) printf("Yes");
    else printf("No");
return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  if(s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(3)){
    cout << "Bad" << endl;
  }
  else{
    cout << "Good" << endl;
  }
}

Measured memory_bytes: 256
from math import sqrt, ceil
n, m = map(int, input().split())

M = set()
for i in range(1, ceil(sqrt(m))+1):
    if m % i == 0:
        M.add(i)
        M.add(m//i)
M = sorted(list(M), reverse=True)
#print(M)
for i in M:
    if i <= m // n:
        print(i)
        break


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<int> vei;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

    int N, M, X, Y; cin >> N >> M >> X >> Y;
    vei x(N); rep(i,N) cin >> x[i];
    vei y(M); rep(i,M) cin >> y[i];

    if(X >= *min_element(y.begin(),y.end()) or Y <= *max_element(x.begin(),x.end())){
        cout << "War" << endl;
        return 0;
    }
    rep(i,N) {
        rep(j,M) {
            if (x[i] >= y[j]) {
                cout << "War" << endl;
                return 0;
            }
        }
    }
    cout << "No War" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict

cnt = defaultdict(int)

def main():
    n, *a = map(int, sys.stdin.read().split())
    a.sort()
    l = a[0]
    r = a[-1]

    for val in a:
        cnt[val] += 1
    
    ans = 0
    for i in range(l, r+1):
        ans = max(ans, cnt[i-1] + cnt[i] + cnt[i+1])

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 18352
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a < c)
        a = c;
    if(b > d)
        b = d;
    if(a < b)
        printf("%d\n",b-a);
    else
        printf("0\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;
ll a[100010],b[100010],ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for (int i=1;i<=n;i++)
	{
		ans+=(a[i]+b[i-1])/2;
		if ((a[i]+b[i-1])&1 && a[i])
		{
			b[i]=1;
		}
		//cout<<i<<" "<<ans<<" "<<b[i]<<endl;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1e+9;


int main()
{
	int n = 0;
	cin >> n;
    int ct = 0;
    vector<tuple<string, int, int>> p;
    // pair <pair<string, int>, int> p[110];

    for (int i = 1; i <= n; i++)
    {
        string name = "";
        int score = 0;
        cin >> name >> score;
        score *= -1;
        p.push_back(tie(name, score, i));
    }

    sort(p.begin(), p.end());

    for (int i = 0; i < n; i++)
    {
        cout << get<2>(p[i]) << "\n";
    }

	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main{
	static Scanner s=new Scanner(System.in);

	void solve(){
		int n=gInt();
		int[] c=INTS(n).toArray();
		int[]cc=Arrays.copyOf(c,n);
		Arrays.sort(cc);

		int l=cc[(n-1)/2],r=cc[n/2];
		
		for(int i:c)
			System.out.println(i<=l?r:l);
	}
	public static void main(String[] A){
		new Main().solve();
	}

	static int gInt(){
		return Integer.parseInt(s.next());
	}
	static long gLong(){
		return Long.parseLong(s.next());
	}
	static double gDouble(){
		return Double.parseDouble(s.next());
	}

	SupplyingIterator<Integer> ints(int n){
		return new SupplyingIterator<>(n,Main::gInt);
	}
	SupplyingIterator<Long> longs(int n){
		return new SupplyingIterator<>(n,Main::gLong);
	}
	SupplyingIterator<Double> doubles(int n){
		return new SupplyingIterator<>(n,Main::gDouble);
	}
	SupplyingIterator<String> strs(int n){
		return new SupplyingIterator<>(n,s::next);
	}

	Range rep(int i){
		return Range.rep(i);
	}
	Range rep(int f,int t,int d){
		return Range.rep(f,t,d);
	}
	Range rep(int f,int t){
		return rep(f,t,1);
	}
	Range rrep(int f,int t){
		return rep(t,f,-1);
	}

	IntStream REP(int v){
		return IntStream.range(0,v);
	}
	IntStream REP(int l,int r){
		return IntStream.rangeClosed(l,r);
	}

	IntStream INTS(int n){
		return IntStream.generate(Main::gInt).limit(n);
	}
	Stream<String> STRS(int n){
		return Stream.generate(s::next).limit(n);
	}

}
class SupplyingIterator<T> implements Iterable<T>,Iterator<T>{
	int			t;
	Supplier<T>	supplier;

	SupplyingIterator(int t,Supplier<T> supplier){
		this.t=t;
		this.supplier=supplier;
	}

	@Override
	public Iterator<T> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return t>0;
	}

	@Override
	public T next(){
		--t;
		return supplier.get();
	}

}
class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
	int to,cur,d;

	Range(int from,int to,int d){
		this.cur=from-d;
		this.to=to;
		this.d=d;
	}

	Range(int n){
		this(0,n-1,1);
	}

	@Override
	public Iterator<Integer> iterator(){
		return this;
	}

	@Override
	public boolean hasNext(){
		return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
	}

	@Override
	public int nextInt(){
		return cur+=d;
	}

	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}

}


Measured memory_bytes: 65904
# -*- coding: utf-8 -*-
"""
Created on Fri Apr  3 14:23:44 2020

@author: liang
"""

N, M = map(int,input().split())
bulbs = [list(map(int,input().split()))[1:] for _ in range(M)]
p = list(map(int,input().split()))
ans = 0
for i in range(2**N):
    lights = [1 if (i>>j)&1 == 1 else 0 for j in range(N)]
    if all(sum(lights[x-1] for x in bulbs[k])%2 == p[k] for k in range(len(bulbs))):
            ans += 1
#print(bulbs)
#print(p)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;

#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rrep(i,N) for(int i=(int)(N)-1;i>=0;--i)
#define debug(x) cout<<#x<<"="<<x<<endl;
constexpr ll MOD=1000000007;
constexpr ll INF=1LL<<60;
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;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end
int W,H;
bool inside(int h,int w){return 0<=h&&h<H&&0<=w&&w<W;}
int gh[]={1,-1,0,0,1,1,-1,-1},gw[]={0,0,1,-1,-1,1,-1,1},use[51][51],G[51][51];
void dfs(int h,int w){
    rep(k,8){
        int i=gh[k]+h,j=gw[k]+w;
        if(!inside(i,j)||use[i][j]||G[i][j]==0)continue;
        use[i][j]=1;
        dfs(i,j);
    }
}
void solve(){
    while((cin>>W>>H,W|H)){
        rep(i,51)rep(j,51)use[i][j]=0;
        rep(i,H)rep(j,W)cin>>G[i][j];
        int res=0;
        rep(i,H)rep(j,W)if(!use[i][j]&&G[i][j]){dfs(i,j);res++;}
        cout<<res<<endl;
    }
}

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


Measured memory_bytes: 3200
import java.util.Scanner;

import java.util.Arrays;
import java.util.ArrayList;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String [] s = new String[N];
		int cnt = 0;
		int cntA = 0;
		int cntB = 0;
		int cntboth = 0;
		for (int i = 0; i < N; i++) {
			 s[i] = sc.next();
			 if(s[i].charAt(0) == 'B') {
				 cntB++;
				 if(s[i].charAt(s[i].length()-1) == 'A') {
					 cntA++;
					 cntboth++;
				 }
			 }
			 else if(s[i].charAt(s[i].length()-1) == 'A') {
				 cntA++;
			 } 
			 for (int j = 0; j < s[i].length() - 1; j++) {
				 if (s[i].charAt(j) == 'A') {
					 if(s[i].charAt(j+1) == 'B') {
						 cnt++;
					 }
				 }
			 }
		}
		if (cntA == 0 || cntB == 0) {
			System.out.println(cnt);
		}
		else if (cntA == cntB && cntA == cntboth) {
			System.out.println(cnt + cntA - 1);
		}
		else if(cntA < cntB) {
			System.out.println(cnt + cntA);
		}
		else {
			System.out.println(cnt + cntB);
		}

	}
}	


Measured memory_bytes: 30080
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define substr(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  vector<pair<ll,ll> > num(n);
  for(int i=0;i<n;i++){cin>>num[i].F;num[i].S=i;}
  sort(ALL(num));
  ll ans=0;
  for(int i=0;i<n;i++){
    if(i%2!=num[i].S%2)ans++;
  }
  cout<<ans/2<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    int H, W;
    cin >> H >> W;
    int a[500][500];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> a[i][j];
        }
    }

    int N = 0;
    int x1[250000], y1[250000], x2[250000], y2[250000];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W-1; j++){
            if(a[i][j] % 2 == 1){
                a[i][j]--;
                a[i][j+1]++;
                x1[N] = j+1;
                y1[N] = i+1;
                x2[N] = j+2;
                y2[N] = i+1;
                N++;
            }
        }
    }
    for(int i = 0; i < H-1; i++){
        if(a[i][W-1] % 2 == 1){
            a[i][W-1]--;
            a[i+1][W-1]++;
            x1[N] = W;
            y1[N] = i + 1;
            x2[N] = W;
            y2[N] = i + 2;
            N++;
        }
    }

    cout << N << endl;
    for(int i = 0; i < N; i++){
        cout << y1[i] << " " << x1[i] << " " << y2[i] << " " << x2[i] << endl;
    }


    return 0;

}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll m=ll(sqrt(2*n));
    m++;
    if(m*(m-1)/2!=n){
        cout << "No"<<endl;
        return 0;
    }
    cout << "Yes"<<endl;
    vector<vector<ll> > v(m);
    for(ll i=1;i<m;i++){
        ll ri=i*(i+1)/2,le=(i*(i-1)/2)+1;
        for(ll j=le;j<=ri;j++){v[j-le].pb(j);v[i].pb(j);}
    }
    cout << m<<endl;
    for(int i=0;i<m;i++){
        int maki=v[i].size();
        cout << maki<<" "; 
        for(int j=0;j<maki;j++){
            cout << v[i][j] <<" ";
        }
        cout <<endl;
    }
    return 0;
}


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

using namespace std;

int main() {
  int n; cin >> n;
  int a[n+1];
  int max_node = -1;
  memset(a, 0, sizeof a);
  for(int i = 0; i < n; i++) {
    int c; cin >> c;
    if(i == 0) {
      if(c != 0) {
        a[0] = -1000000;
      }
    }
    a[c]++;
    max_node = max(max_node, c);
  }
  
  int M = 998244353;
  long long ans = 1;
  for(int i = 1; i <= max_node; i++) {
    long long tmp = 1;
    for(int j = 0; j < a[i]; j++) {
      tmp = (tmp * a[i-1]) % M;
    }
    if(a[i-1] == 0) tmp = 0;
   // cout << i << " " << tmp << endl;
    ans  = (ans * tmp) % M;
    if(ans == 0) break;
  }
  if(a[0] != 1) cout << 0 << endl;
  else cout << ans << endl;
  return 0;
}
  


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define pb         push_back
#define mp         make_pair
#define F          first 
#define S          second
#define mod        998244353
#define all(x)     x.begin(),x.end()    
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
ll power(ll x, ll y){ll out = 1;while (y > 0){if (y & 1) out=(out*x)%mod;y = y>>1;x = (x*x)%mod;}return out%mod;}
ll inverse(ll a){return power(a,mod-2)%mod;}
void comp() {
	ll i,j,k,m,n;
	cin>>n;
	string s;
	map<string,ll>m1;
	m1["AC"]=0;
	m1["WA"]=0;
	m1["TLE"]=0;
	m1["RE"]=0;
	fl(i,n) {
		cin>>s;
		m1[s]++;
	}
	cout<<"AC x "<<m1["AC"]<<"\n";
	cout<<"WA x "<<m1["WA"]<<"\n";
	cout<<"TLE x "<<m1["TLE"]<<"\n";
	cout<<"RE x "<<m1["RE"]<<"\n";
}
int main() {
    speedup;
    ll i=0,t;
    t=1;
    //cin>>t;
    while(t--) {
        comp();
    }
    return 0;
}

Measured memory_bytes: 3668