akhauriyash/Code-Regression huggingface dataset:
<?php
  fscanf(STDIN,"%d%d",$h,$w);
  $top = "";
  for($i=0; $i<$w+2; $i++){
      $top .= "#";
  }
  echo $top."\n";
  
  for($i=0; $i<$h; $i++){
      $a = trim(fgets(STDIN));
      echo "#".$a."#\n";
  }
  echo $top."\n";
?>


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

int main()
{
  int n,x,ans;
  cin>>n>>x;
  ans=0;
  vector<int> dis(n);
  vector<int> bound(n+1);
  for(int i=0;i<n;i++)
  {
    cin>>dis.at(i);
  }
  bound.at(0)=0;
  for(int i=0;i<n;i++)
  {
    bound.at(i+1)=bound.at(i)+dis.at(i);
  }
  for(int i=0;i<n+1;i++)
  {
    if(bound.at(i)<=x)
    {
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
S = list(input())
s = len(S)-1
from itertools import product
a = list(product(["+",""],repeat=s))
ans = 0
for i in a:
    b = ""
    for j in range(len(S)):
        if j<=s-1:
            b += S[j]
            b += i[j]
        else:
            b += S[j]
    ans += eval(b)
print(ans)

Measured memory_bytes: 39024
#include<iostream>
#include<vector>
#include<stack>
#include<set>
using namespace std;

void set_color(const vector<vector<int> >& G, vector<int>& color,
                int color_name, int a, int i) {
    if (i >= G[a].size()) return;
    if (color[G[a][i]] == -1) {
        color[G[a][i]] = color_name;
        set_color(G, color, color_name, G[a][i], 0);
    }
    set_color(G, color, color_name, a, i + 1);
}


bool DFS(const vector<vector<int> >& G, int a, int b) {
    if (G[a].size() == 0 || G[b].size() == 0) return false;
    static vector<int> color(G.size(), -1);
    static int color_name = 0;
    if (color[a] != color[b]) return false;
    if (color[a] == -1) {
        set_color(G, color, color_name++, a, 0);
    }
    if (color[a] == color[b]) return true;
    return false;
}


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

    vector<vector<int> > G(n);

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

// for (int i = 0; i < n; i++) {
//     cout << i << " : ";
//     for (vector<int>::iterator it = G[i].begin(); it != G[i].end(); it++){
//         cout << *it << " ";
//     }
//     cout << endl;
// }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int a, b;
        cin >> a >> b;
        if (DFS(G, a, b)) {
           cout << "yes" << endl;
        } else {
           cout << "no"  << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 12796
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(n):
    if B[i] >= A[i]:
        ans += A[i]
        B[i] -= A[i]
        A[i] = 0
        if B[i] >= A[i + 1]:
            ans += A[i + 1]
            A[i + 1] = 0
        elif B[i] < A[i + 1]:
            ans += B[i]
            A[i + 1] -= B[i]
    elif B[i] < A[i]:
        ans += B[i]
        A[i] -= B[i]

print(ans)


Measured memory_bytes: 24144
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(), (a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(), (a).end())

//文字列の足し算を実際に計算させる
//掛け算とかでもできるはず
int64_t calc(string s){
    int l = s.length();
    int64_t sum=0;
    string t="";
    rep(i,l){
        t = t + s[i];
        if(i==l-1){
            sum += stoi(t);
        }
        else{
        if(s[i]=='+'){
            sum += stoi(t);
            //stringをlong longに
            t = "";
        }
        if(s[i]=='-'){
            sum += stoi(t);
            t ="-";
        }
        }
    }
    return sum;
}
int main(){
    string s;
    cin>>s;
    //ビット全探索
    for (int tmp = 0; tmp < (1 << 3); tmp++) { 
    //1を左に3ビットずらすと1000=8
    //1<<kで2のk乗
        bitset<3> bi(tmp);
    // ビット列を出力
        string t = s.substr(0,1);
        for(int i=0;i<3;i++){
            if(bi.test(i)){
                t += '+';
            }
            else{
                t += '-';
            }
            t += s[i+1];
        }
        if(calc(t)==7){
        cout<<t<<"="<<calc(t)<<endl;
        break;
        }
    }
}


Measured memory_bytes: 256
s = int(input())


def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1


i = 0
a = [0]
while True:
    if i == 0:
        a[0] = s
    else:
        a.append(f(a[i-1]))
    if a[i] in a[:i]:
        break
    i += 1
print(i + 1)


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007

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

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

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


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

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

//ここまでライブラリ
//ここから本文

long long int tpimin(vector<int> a) {
	int MIN = 1000000000;
	int number = 0;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
		number = i;
	}
	return number;
}


int main() {
	int ansx = 0, ansy = 0;
	int w, h;
	int n;
	cin >> w >> h >> n;
	int ansx2 = w, ansy2 = h;
	for (int i = 0; i < n; i++) {
		int x, y, a;
		cin >> x >> y >> a;
		if (a == 1) ansx = max(ansx , x);
		if (a == 2) ansx2 = min(ansx2 , x);
		if (a == 3) ansy = max(ansy , y);
		if (a == 4) ansy2 = min(ansy2 , y);
	}
	cout << max(ansx2 - ansx,0) * max((ansy2 - ansy),0) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int main (){
  char c;
  int i,stack[N];

for(i=0;i < N;i++){

  stack[i]=0;

}
i=0;
while((c = getchar()) != '\n'){
  if(c>='0'&&c<='9'){

stack[i]=10*stack[i]+(c-'0');

  }
  if(c == ' ')
  i++;

  if(c == '+'){
  i--;
  stack[i-1]+=stack[i];
  stack[i]=0;
  i--;
  }
  if(c == '-'){
  i--;
  stack[i-1]-=stack[i];
  stack[i]=0;
  i--;
  }
if(c == '*'){
  i--;
  stack[i-1]*=stack[i];
  stack[i]=0;
  i--;
  }
  }
printf("%d\n",stack[0]);
return 0;
}


Measured memory_bytes: 2124
#include<cstdio>
const int N=3005,mo=1e9+7;
int n,m,i,j,sum[N],r[N],f[N][N];char s[N];
void add(int &x,int k){x=(x+k)%mo;}
int main(){
	scanf("%d%d%s",&n,&m,s+1);s[n+1]='0';
	for (i=1;i<=n+1;i++)
		r[i]=i,sum[i]=sum[i-1]+s[i]-48;
	for (;m--;){
		int x,y;scanf("%d%d",&x,&y);
		if (y>r[x]) r[x]=y;
	}
	for (i=2;i<=n+1;i++)
		if (r[i-1]>r[i]) r[i]=r[i-1];
	f[1][sum[r[1]]]=1;
	for (i=1;i<=n;i++) for (j=0;j<=n;j++) if (f[i][j]){
		int k=sum[r[i+1]]-sum[r[i]];
		if (r[i]-i+1-j) add(f[i+1][j+k],f[i][j]);
		if (j) add(f[i+1][j+k-1],f[i][j]);
	}
	printf("%d",f[n+1][0]);
}

Measured memory_bytes: 33792
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==v.size()?"":" ");
    return os;
}

set<ll> fill(int a,int b){
    if(b>a) return set<ll>();
    // k>b
    set<ll> dp[a+1];
    dp[a].insert(0);
    for(int i=a;i>0;i--){
        for(auto x:dp[i]){
            for(int j=1;j<=i;j++){
                dp[i%j].insert(x+(1ll<<j));
            }
        }
    }
    return dp[b];
}

const int bs=20;
void bitout(set<ll> a){
    for(auto x:a) cout<<bitset<bs>(x)<<endl;
}

signed main(){
    
    int n;cin>>n;
    vector<int> a(n),b(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    

    vector<set<ll>> v;
    rep(i,n){
        if(a[i]==0) continue;
        auto res=fill(a[i],b[i]);
        // cout<<a[i]<<" "<<b[i]<<endl;
        // bitout(res);
        if(res.empty()){
            cout<<-1<<endl;
            return 0;
        }
        v.push_back(res);
    }

    n=(int)v.size();

    ll ans=0;
    for(int b=51;b>0;b--){
        bool can=true;
        rep(i,n){
            bool f=false;
            if(v[i].empty()) f=true;
            for(auto x:v[i]){
                // 無くてもいいよ
                if(((x>>b)&1)==0) f=true;
            }
            if(!f) can=false;
        }
        if(can){
            rep(i,n){
                for(auto ite=v[i].begin();ite!=v[i].end();){
                    ll num=*ite;
                    if((num>>b)&1) ite=v[i].erase(ite);
                    else ite++;
                }
            }

        }else{
            ans+=1ll<<b;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4280
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];

const int mod = 1000000007;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}


signed main() {
	int n, a=0,b;
	cin >> n;
	b = n;
	while (b != 0) {
		a += b % 10;
		b /= 10;
	}
	if (n % a == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <utility>

using namespace std;
typedef long long ll;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  bool flag = false;
  for(int i=0;i<=n;i++) {
    for(int j=0;j<=m;j++) {
      ll ans = i*m+j*(n-i*2);
      ll ans2 = j*n+i*(m-j*2);
      if(ans == k || ans2 == k) {
        flag = true;
        break;
      }
    }
  }

  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

using namespace std;

int main(){
    int N;
	cin >> N;
    int F[N][10];
	for(int i = 0; i < N; i++){
		for(int j = 0; j < 10; j++){
			cin >> F[i][j];
		}
	}
    int P[N][11];
	for(int i = 0; i < N; i++){
		for(int j = 0; j < 11; j++){
			cin >> P[i][j];
		}
	}


	int ans = INT32_MIN;
    int c;
    int r;
	for(int bit = 1; bit < (1<<10); bit++){
		r = 0;
		for(int i = 0; i < N; i++){
			c = 0;
			for(int j = 0; j < 10; j++){
				if(((bit>>j) & 1) && F[i][j]){
                    c++;
                }
			}
			r += P[i][c];
		}
        ans = max(ans, r);
	}

	cout << ans << endl;


	return 0;
}


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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }
#define looppu(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . push_back (x) ;}
#define loopin(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . insert (x) ;}

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

signed main ()
{
    fastio
    lli a , b , k , m = 0 ;
    cin >> a >> b >> k ;
    vi ss ;
    m = min ( a , b ) ;
    for (lli i = 1 ; i <= m ; i ++){
        if (a % i == 0 && b % i == 0){
            ss . push_back (i) ;
            //cout << i << ' ' ;
        }
    }
    cout << ss[ss. size() - k] << endl ;
    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
int main() {
	char s[1001];
	bool isN = false, isW = false, isS = false, isE = false;
	scanf("%s", s);
	int n = strlen(s);
	for (int i = 0; i < n; i++) {
		if (s[i] == 'N') {
			isN = true;
		} else if (s[i] == 'W') {
			isW = true;
		} else if (s[i] == 'S') {
			isS = true;
		} else {
			isE = true;
		}
	}
	if ((isN != isS) || (isW != isE)) {
		printf("No\n");
	} else {
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
  int n;
  cin >> n;
  long long a[n];
  for(int i=0;i<n;i++)cin >> a[i];
 
  long long ans_a=0, sum_a=0;
  for(int i=0;i<n;i++){
    sum_a+=a[i];
    //cout << i << ":"<<sum_a << endl;
    if((i%2!=0)&&(sum_a>=0)){
      ans_a+=abs(sum_a)+1;
      sum_a-=abs(sum_a)+1;
    }
    else if((i%2==0)&&(sum_a<=0)){
      ans_a+=abs(sum_a)+1;
      sum_a+=abs(sum_a)+1;
    }
    //cout << i << ":"<<sum_a << endl;
    //cout << "tans"<<ans_a << endl;
  }
  //out << "ansa"<<ans_a << endl;
 
  long long ans_b=0, sum_b=0;
  for(int i=0;i<n;i++){
    sum_b+=a[i];
    //cout << i << ":"<< sum_b << endl;
    if((i%2!=0)&&(sum_b<=0)){
      ans_b+=abs(sum_b)+1;
      sum_b+=abs(sum_b)+1;
    //cout << i << ":"<<sum_b << endl;
    }
    else if((i%2==0)&&(sum_b>=0)){
      ans_b+=abs(sum_b)+1;
      sum_b-=abs(sum_b)+1;
    }
    //out << "tansb" <<ans_b << endl;
  }
  //cout << "ansb" <<ans_b << endl;
 
  long long ans = ans_a < ans_b ? ans_a : ans_b;
 
  cout << ans << endl;
}

Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll B, ll mod){
  if (B == 0) return 1;
  else{
    if (B % 2 == 0){
      return Pow(A * A % mod, B / 2, mod) % mod;
    }else{
      return A * Pow(A * A % mod, B / 2, mod) % mod;
    }
  }
}

ll nCr(ll N, ll R, ll mod){
  ll ans = 1; R = min(R, N - R);
  for (ll i = 1; i <= R; i++){
    ans *= N - i + 1; ans %= mod;
    ans *= Pow(i, mod - 2, mod); ans %= mod;
  }
  return ans;
}

int main(){
  int H, W; cin >> H >> W;
  ll DP[H][W]; bool visited[H][W];
  char S[H][W];

  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> S[i][j];
      DP[i][j] = 0;
      visited[i][j] = false;
      if (S[i][j] == '#') visited[i][j] = true;
    }
  }

  int di[2] = {1, 0}, dj[2] = {0, 1};
  queue <Pii> que; que.push(make_pair(0, 0));
  visited[0][0] = true; DP[0][0] = 1;

  while (!que.empty()){
    Pii now = que.front(); que.pop();
    int i = now.first, j = now.second;

    for (int k = 0; k < 2; k++){
      int I = i + di[k], J = j + dj[k];
      if (0 <= I && I < H && 0 <= J && J < W){
        if (S[I][J] == '.'){
          DP[I][J] += DP[i][j];
          DP[I][J] %= nmax;
        }
        if (visited[I][J] == false){
          que.push(make_pair(I, J));
          visited[I][J] = true;
        }
      }
    }
  }
  
  cout << DP[H - 1][W - 1] << endl;
  
  return 0;
}


Measured memory_bytes: 9984
#include<stdio.h>
int main(){
int W,H,x,y,r;
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
if (W >= x+r && x-r >= 0 && H >= y+r && y-r >= 0){
    printf("Yes\n");
}else {
printf("No\n");
}
    return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

struct LCA{
    vector<vector<int>>& g;
    const int V;
    vector<int> depth;
    vector<vector<int>> table;
    const int ub_log;

    LCA(vector<vector<int>>& g) : g(g), V(g.size()), ub_log(32 - __builtin_clz(g.size())) {
        depth.resize(V);
        table.resize(ub_log, vector<int>(V));
    }

    void dfs(int from, int d = 0, int par = -1){
        table[0][from] = par;
        depth[from] = d;
        for(int to : g[from]){
            if(to == par)   continue;
            dfs(to, d + 1, from);
        }
        return;
    }

    void build(int root = 0){
        dfs(root);
        for(int k = 0; k + 1 < ub_log; ++k){
            for(int i = 0; i < V; ++i){
                if(table[k][i] == -1)   table[k + 1][i] = -1;
                else    table[k + 1][i] = table[k][table[k][i]];
            }
        }
    }

    int query(int u, int v){
        if(depth[u] > depth[v]) swap(u, v);
        int d = depth[v] - depth[u];
        for(int i = ub_log - 1; i >= 0; --i){
            if(d >> i & 1)  v = table[i][v];
        }
        if(u == v)  return u;
        for(int i = ub_log - 1; i >= 0; --i){
            if(table[i][u] != table[i][v]){
                u = table[i][u];
                v = table[i][v];
            }
        }
        return table[0][u];
    }

    int dist(int u, int v){
        return depth[u] + depth[v] - depth[query(u, v)] * 2;
    }
};

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

    int n;
    cin >> n;
    vector<vector<int>> graph(n);
    for(int i = 0; i < n; ++i){
        int k;
        cin >> k;
        for(int j = 0; j < k; ++j){
            int v;
            cin >> v;
            graph[i].emplace_back(v);
            graph[v].emplace_back(i);
        }
    }
    LCA lca(graph);
    lca.build();
    int q;
    cin >> q;
    for(int i = 0; i < q; ++i){
        int u, v;
        cin >> u >> v;
        cout << lca.query(u, v) << '\n';
    }
}


Measured memory_bytes: 18264
#include<iostream>
using namespace std;
 
int main(){
    int n, x, i, j, k, s;
     
    while(1){
        cin >> n >> x;
         
        if(n == 0 && x == 0){
            break;
        }
         
        s = 0;
        for(i = 1; i <= n - 2; i++){
            for(j = i + 1; j <= n; j++){
                for(k = j + 1; k <= n; k++){
                    if(i + j + k == x){
                        s++;
                    }
                }
            }
        }
        cout << s << endl;
    }
     
    return 0;   
}

Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
using namespace std;
typedef long long ll;

int main(){
	ios::sync_with_stdio(false);
	ll A,B,Q;
	cin>>A>>B>>Q;
	vector<ll> s(A),t(B),x(Q);
	for(int i=0;i<A;i++) cin>>s[i];
	for(int i=0;i<B;i++) cin>>t[i];
	for(int i=0;i<Q;i++) cin>>x[i];
	for(int i=0;i<Q;i++){
		ll idx1,idx2,ans=LLONG_MAX;
		idx1=lower_bound(s.begin(),s.end(),x[i])-s.begin();
		idx2=lower_bound(t.begin(),t.end(),x[i])-t.begin();
		if(idx1!=0 && idx2!=0){
			for(int j=0;j<2;j++){
				for(int k=0;k<2;k++){
					ll tmp;
					tmp=min( abs(x[i]-s[idx1-j])+abs(s[idx1-j]-t[idx2-k]) , abs(x[i]-t[idx2-k])+abs(s[idx1-j]-t[idx2-k]) );
					ans=min(ans,tmp);
				}
			}
		}else if(idx1==0 && idx2!=0){
			for(int j=0;j<2;j++){
				ll tmp;
				tmp=min( abs(x[i]-s[idx1])+abs(s[idx1]-t[idx2-j]) , abs(x[i]-t[idx2-j])+abs(s[idx1]-t[idx2-j]) );
				ans=min(ans,tmp);
			}
		}else if(idx1!=0 && idx2==0){
			for(int j=0;j<2;j++){
				ll tmp;
				tmp=min( abs(x[i]-s[idx1-j])+abs(s[idx1-j]-t[idx2]) , abs(x[i]-t[idx2])+abs(s[idx1-j]-t[idx2]) );
				ans=min(ans,tmp);
			}			
		}else{
			ll tmp;
			tmp=min (abs(x[i]-s[idx1])+abs(s[idx1]-t[idx2]) , abs(x[i]-t[idx2])+abs(s[idx1]-t[idx2]) );
			ans=min(ans,tmp);
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(11);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int w, h;
  cin >> w >> h;
  int n;
  cin >> n;

  int lw = 0, lh = 0;
  rep(i, n) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) chmax(lw, x); // debuged, lw = x
    else if (a == 2) chmin(w, x);
    else if (a == 3) chmax(lh, y);
    else chmin(h, y);
  }

  if (lw >= w || lh >= h) cout << 0 << endl;
  else {
    cout << (w - lw) * (h - lh) << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#define ll long long
#define mod 1000000007
using namespace std;
int solve(vector<int>& v,int n,int k)
{
    ll dp[n+2][k+2];
    for(int j=0;j<=k;j++)
    {
        dp[1][j]=(j>v[1])?0:1;
    }
    for(int i=2;i<=n;i++)
    {
        for(int j=0;j<=k;j++)
        {
            if(j==0)
            dp[i][j]=dp[i-1][j];
            else
            dp[i][j]=(mod+dp[i][j-1]+dp[i-1][j]-((j-v[i]-1>=0)?dp[i-1][j-v[i]-1]:0))%mod;
        }
    }
    return dp[n][k];
}
int main() {
   int n,k;
   cin>>n>>k;
   vector<int> v(n+1);
   for(int i=1;i<=n;i++)
    cin>>v[i];
  cout<<solve(v,n,k);
}


Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,ans("No");
  
  cin >> s;
  for(int i = 0;i<s.length()-1;i++){
    if(s.at(i) != s.at(i+1)){
      ans = "Yes";
      break;
    }
  }
  
  cout << ans << endl;
}

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

int main() {
    int64_t n, k;
    cin >> n >> k;

    int64_t answer = 0;
    if (k == 0) {
        answer = n * n;
    } else {
        for (int64_t b = k + 1; b <= n; b++) {
            int64_t x = ((n + 1) % b >= k ? k : (n + 1) % b) + (n + 1) / b * k;
            answer += n + 1 - x;
        }
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>s;
    rep(i,Size(s)){
        if(s[i]=='o')ans++;
    }
    ans+=(15-Size(s));
    if(ans>=8)Cout("YES");
    else Cout("NO");
    return 0;
}


Measured memory_bytes: 256
from collections import deque

N, M = [int(x) for x in input().split()]

friends_map = {n: set() for n in range(N)}
remain_user = set()
for m in range(M):
    a, b = [int(x) - 1 for x in input().split()]

    friends_map[a].add(b)
    friends_map[b].add(a)
    remain_user.add(a)
    remain_user.add(b)

stack = deque()
stack.appendleft(0)

max_group = 1
watch = set()
while stack:
    now = stack.popleft()

    if not now in watch:
        remain_user.discard(now)
        watch.add(now)

        for next_node in friends_map[now]:
            if not next_node in watch:
                stack.appendleft(next_node)

    if not stack:
        max_group = max(len(watch), max_group)

        if remain_user:
            stack.appendleft(remain_user.pop())
            watch = set()

print(max_group)


Measured memory_bytes: 105920
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let even = vec!['L', 'U', 'D'];
    let odd = vec!['R', 'U', 'D'];
    for (i, c) in s.into_iter().enumerate() {
        if i % 2 == 1 {
            if !check(c, &even) {
                println!("No");
                return
            }
        } else {
            if !check(c, &odd) {
                println!("No");
                return
            }
        }
    }

    println!("Yes");
}

fn check(c: char, v: &Vec<char>) -> bool {
     c == v[0] || c == v[1] || c == v[2]
}

Measured memory_bytes: 4352
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int main()
{
	long long A, B, C;
	scanf("%lld%lld%lld", &A, &B, &C);
	long long count = 0;
	long long tmpA = A, tmpB = B, tmpC = C;
	if (A == B && A == C && A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
		printf("-1");
		return 0;
	}

	while (true) {
		A = tmpA, B = tmpB, C = tmpC;
		if (tmpA % 2 == 1) break;
		if (tmpB % 2 == 1) break;
		if (tmpC % 2 == 1) break;
		tmpA = B / 2 + C / 2;
		tmpB = A / 2 + C / 2;
		tmpC = A / 2 + B / 2;
		count++;
	}
	printf("%lld", count);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int S(long long n){
  string s = to_string(n);
  int d = s.size();
  int ans = 0;
  for (int i = 0; i < d; i++){
    ans += s[i] - '0';
  }
  return ans;
}
int main(){
  int K;
  cin >> K;
  vector<long long> p;
  for (int i = 1; i < 1000; i++){
    string s = to_string(i);
    while (s.size() <= 15){
      p.push_back(stoll(s));
      s += '9';
    }
  }
  sort(p.rbegin(), p.rend());
  p.erase(unique(p.begin(), p.end()), p.end());
  long long tmp = 1000000000000000;
  int s = 1;
  vector<long long> snuke;
  for (long long i : p){
    if (tmp * S(i) >= s * i){
      snuke.push_back(i);
      tmp = i;
      s = S(i);
    }
  }
  sort(snuke.begin(), snuke.end());
  for (int i = 0; i < K; i++){
    cout << snuke[i] << endl;
  }
}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<int,P>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
signed main(){
	string s;
	cin>>s;
	sort(s.begin(),s.end());
	if(s=="abc") puts("Yes");
	else puts("No");
	return 0;
}


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

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	ll money = 1000;
	rep(i,n-1){
		ll stock = 0;
		if(a[i] < a[i+1]) stock = money / a[i];
		money += stock * (a[i+1] - a[i]);
	}
	cout << money << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <complex>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)

typedef long long ll;
typedef unsigned long long ull;

int main(){
  ios_base::sync_with_stdio(0);
  int n, m;
  while(cin >> n >> m, n || m){
    int vote[100] = {0};
    for(int i = 0; i < n; i++){
      for(int j = 0; j < m; j++){
        int a; cin >> a;
        if(a == 1) vote[j]++;
      }
    }
    for(int s = 0; s < m; s++){
      if(s) cout << " ";
      int M = -1;
      int p = 0;
      for(int i = 0; i < m; i++){
        if(vote[i] > M) { M = vote[i]; p = i + 1; }
      }
      vote[p-1] = -1;
      cout << p;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 2e9;



int main() {
	int h, w, n; cin >> h >> w >> n;
	vector<P> a(n),idx;
	map<P, int> ans;
	rep(i, 0, n) cin >> a[i].first >> a[i].second;
	rep(i, 0, n)rep(j, -1, 2)rep(k, -1, 2) {
		if (a[i].first + j > 1 && a[i].first + j < h && a[i].second + k > 1 && a[i].second+k < w) {
			ans[{a[i].first + j, a[i].second + k}]++;
			idx.push_back({ a[i].first + j,a[i].second + k });
		}
	}
	sort(idx.begin(), idx.end());
	idx.erase(unique(idx.begin(), idx.end()), idx.end());
	ll cnt[10] = {};
	ll sub = 1LL * (h - 2) * (w - 2);
	rep(i, 0, idx.size()) {
		cnt[ans[idx[i]]]++;
	}
	rep(i, 1, 10) sub -= cnt[i];
	cnt[0] = sub;
	rep(i, 0, 10) {
		cout << cnt[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 73572
while hws = gets.chomp
    h,w = hws.split(' ').map{|n| n.to_i}
    if h==0 && w==0
        break
    else
        1.upto h do |i|
            if i.odd?
                if w.even?
                    puts "#."*(w/2)
                else
                    puts "#."*(w/2) + "#"
                end
            else
                if w.even?
                    puts ".#"*(w/2)
                else
                    puts ".#"*(w/2) + "."
                end
            end
        end
        puts ""
    end
end

Measured memory_bytes: 6108
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

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

  int n, a, b;
  cin >> n >> a >> b;

  cout << min(n*a, b) << endl; 

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
const int MD=1e9+7;
int a[N],fac[N],inv[N];
int quick_pow(int x,int y) {
	int ans=1;
	while(y) {
		if(y&1) ans=1LL*ans*x%MD;
		y>>=1;
		x=1LL*x*x%MD;
	}
	return ans;
}
int C(int n,int m) {
	if(n<m) return 0;
	return 1LL*fac[n]*inv[m]%MD*inv[n-m]%MD;
}
int add(int &x,int y) {
	x+=y;
	if(x>=MD) x-=MD;
	if(x<0) x+=MD;
}
int main() {
	fac[0]=1;
	for(int i=1;i<N;i++) fac[i]=1LL*fac[i-1]*i%MD;
	inv[N-1]=quick_pow(fac[N-1],MD-2);
	for(int i=N-2;i>=0;i--) inv[i]=1LL*inv[i+1]*(i+1)%MD;
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++) {
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	int ans=0;
	for(int i=0;i<n;i++) {
		add(ans,1LL*a[i]*C(i,k-1)%MD);
		add(ans,1LL*(-1)*a[i]*C(n-i-1,k-1)%MD);
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
    string s; cin >> s;
    bool ans = false;
    for(char c : s){
        if(c == '7') ans = true;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

const int N = 100000 + 5;
vector<pair<int,int>> vp;
struct Node{
	int x, y, id;
}node[N];
bool cmp1(const Node &a, const Node &b) {
	return a.x < b.x;
}
bool cmp2(const Node &a, const Node &b) {
	return a.y < b.y;
}
struct Edge{
	int u, v, dis;
	bool operator < (const Edge &e) const {
		return dis < e.dis;
	}
}G[2*N];

int f[N];
int find(int u) {
	return u == f[u] ? u : f[u] = find(f[u]);
}
void merge(int u, int v) {
	u = find(u);
	v = find(v);
	f[u] = v;
}
int main(){
	int n, cnt = 0;
	cin >> n;
	rep(i,0,n) {
		int x, y;
		cin >> node[cnt].x >> node[cnt].y;
		node[cnt++].id = i;
	}
	sort(node, node+n, cmp1);
	cnt = 0;
	rep(i,1,n) {
		int dis = abs(node[i].x - node[i-1].x);
		G[cnt++] = Edge{node[i].id, node[i-1].id, dis};
	}
	sort(node, node+n, cmp2);
	rep(i,1,n) {
		int dis = abs(node[i].y - node[i-1].y);
		G[cnt++] = Edge{node[i].id, node[i-1].id, dis};
	}
	sort(G, G+cnt);
	rep(i,0,N) f[i] = i;
	cnt = 0;
	int num = 0;
	long long ans = 0;
	while(num < n - 1) {
		int u = G[cnt].u;
		int v = G[cnt].v;
		int t = G[cnt++].dis;
		if(find(u) != find(v)) num++, merge(u, v), ans += t;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4096
def solve():
    N, M, X = map(int, input().split())
    ans = 1000000000
    C = [0 for _ in range(N)]
    A = [[0 for _ in range(M)] for _ in range(N)]
    for j in range(N):
        C[j], *A[j] = map(int, input().split())

    for i in range(2 ** N):
        tmp = 0
        algorithm = [0 for _ in range(M)]
        for j in range(N):
            if (i >> j) & 1:
                for k in range(M):
                    algorithm[k] += A[j][k]
                tmp += C[j]
        if min(algorithm) >= X:
            ans = min(ans, tmp)

    if ans == 1000000000:
        print(-1)
    else:
        print(ans)
















if __name__ == '__main__':
    solve()


Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
#include <string>

int main()
{
    std::string a, b, c;
    int n, cnt = 0, total = 0;

    std::cin >> n >> a >> b >> c;

    for(int i = 0;i < n;i++){
        if(a[i] != b[i]){
            cnt++;
        }
        if(b[i] != c[i]){
            cnt++;
        }
        if(a[i] != c[i]){
            cnt++;
        }
        if(cnt == 2){
            total += 1;
        }
        else if(cnt == 3){
            total += 2;
        }
    cnt = 0;
    }
    std::cout << total;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#define ULL unsigned long long
using namespace std;

int main() {
    int n, x = 0, max = 0;
    cin >> n;
    char ch;
    ch = getchar();
    while ((ch = getchar()) != '\n') {
        if (ch == 'I') {
            x++;
        }
        else {
            x--;
        }
        if (max < x) {
            max = x;
        }
    }
    cout << max << endl;
    return 0;
}

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

int main(){
  
  long long N, i, h1, h2, mx = 0, cu = 0;
  cin >> N;
  
  cin >> h1;
  for(i = 0; i < N - 1; i++){
    
    cin >> h2;
    if (h1 >= h2){
      cu++;
    }else{
      cu = 0;
    }
    h1 = h2;
    if(mx < cu) mx = cu;
  }
 
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
#include<random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
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; }
const lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };
typedef pair<double, lint> Pa;
typedef pair<plint, lint> tlint;
struct edge {
	lint cost;
	lint u, v;
};

using namespace atcoder;

lint N, M;
char mp[50][50];
lint pos(lint i, lint j) {
	return i * M + j;
}
const lint MAX_C = 200;
lint cnt = 0;
int main() {
	cin >> N >> M;
	mcf_graph<lint, lint> flow(N * M * 2 + 2);
	lint s = N * M * 2, t = s + 1;
	REP(i, N) {
		REP(j, M) {
			cin >> mp[i][j];
			if (mp[i][j] == 'o') {
				flow.add_edge(s, pos(i, j), 1, 0);
				cnt++;
			}
			if(mp[i][j] != '#') flow.add_edge(pos(i, j) + M * N, t, 1, 0);
		}
	}
	REP(i, N) {
		REP(j, M) {
			if (mp[i][j] != 'o') continue;
			queue<plint> que;
			que.push({ i, j });
			flow.add_edge(pos(i, j), pos(i, j) + M * N, 1, MAX_C);
			vector<vector<lint>> dist(N, vector<lint>(M, INF));
			dist[i][j] = 0;
			while (!que.empty()) {
				plint curr = que.front(); que.pop();
				{
					lint ny = curr.first + 1, nx = curr.second;
					if (ny < N && nx < M && mp[ny][nx] != '#' && dist[ny][nx] > dist[i][j] + 1) {
						if(mp[ny][nx] != 'o') flow.add_edge(pos(i, j), pos(ny, nx) + M * N, 1, MAX_C - (ny - j + nx - i));
						dist[ny][nx] = dist[i][j] + 1;
						que.push({ ny, nx });
					}
				}
				{
					lint ny = curr.first, nx = curr.second + 1;
					if (ny < N && nx < M && mp[ny][nx] != '#' && dist[ny][nx] > dist[i][j] + 1) {
						if (mp[ny][nx] != 'o') flow.add_edge(pos(i, j), pos(ny, nx) + M * N, 1, MAX_C - (ny - j + nx - i));
						dist[ny][nx] = dist[i][j] + 1;
						que.push({ ny, nx });
					}
				}
			}
		}
	}
	auto v = flow.flow(s, t, cnt);
	cout << cnt * MAX_C - v.second << endk;
	
}


Measured memory_bytes: 8876
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main(){
    
    // 1. 入力情報.
    LL A, B, C;
    scanf("%lld %lld %lld", &A, &B, &C);
    
    // 2. 赤いブロックの個数と青いブロックの個数の差を小さくする.
    // 2-1. A, B, C の いずれかが偶数なら, 差は 0 のはず.
    LL ans = 0;
    if((A % 2) * (B % 2) * (C % 2) == 0) ans = 0;
    
    // 2-2. A, B, C が すべて奇数の場合は, A * B, B * C, C * A の 最小値.
    if((A % 2) * (B % 2) * (C % 2) == 1) ans = min({A * B, B * C, C * A});
    
    // 3. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 3812
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	static final long MAX = 1000000;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int N = sc.nextInt();
		int K = sc.nextInt();
		int Q = sc.nextInt();
		int[] elems = new int[N];
		long[] sort = new long[N];
		for (int i = 0; i < elems.length; i++) {
			elems[i] = sc.nextInt();
			sort[i] = elems[i] * MAX + i;
		}
		Arrays.sort(sort);
		long ans = Integer.MAX_VALUE;
		int[] forb = new int[N+1];
		boolean[] got = new boolean[N+1];
		int[] real = new int[N];
		got[N] = true;
		forb[Math.max(0, N - K + 1)]++;
		forb[N]--;
		for (int i = 1; i <= N; i++) {
			int size = 0, tot0 = 0, lastFrom = 0;
			int open = 0, last0 = -(int)MAX;
			for (int j = 0; j <= N; j++) {
				open += forb[j];
				if (open == 0 && j < N) {
					tot0++;
					last0 = j;
				}
				if (j < N && j <= last0 + K - 1) real[size++] = elems[j];
				if (got[j]) {
					Arrays.sort(real, lastFrom, size);
					size = lastFrom + tot0;
					lastFrom = size;
					tot0 = 0;
				}
			}
			if (size >= Q) {
				Arrays.sort(real, 0, size);
				ans = Math.min(ans, real[Q-1] - real[0]);
//				System.out.println(ans + " real = " + Arrays.toString(real));
			} else break;
			got[(int)(sort[i-1] % MAX)] = true;
			forb[Math.max(0, (int)(sort[i-1] % MAX) - K + 1)]++;
			forb[Math.min(N, (int)(sort[i-1] % MAX) + 1)]--;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 37552
#include <iostream>
#include <map>
#include <cmath>
using namespace std;

long long frequencyCount[100005];
/* Index = ascii value of s[i]
	Value at i-th index = count of that character */

void findFrequency(long long n , string s){
	long long ans = 1; 
	long long temp = pow(10,9) + 7;
	frequencyCount[(long long)s[0]] = 1;

	for(long long i = 1; i < n; i++){
		frequencyCount[(long long)s[i]]++;
	}
	for(long long i = (int)'a'; i <= (int)'z'; i++){
		frequencyCount[i]++;
		ans*=frequencyCount[i];
		ans = ans % temp;
	}
	ans--; 
	cout << ans << endl; 
}

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

	findFrequency(n , s);
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int a;
    string s;
    cin >> a;
    cin >> s;
    if(a < 3200) {
        cout << "red" << endl;
    }else{
        cout << s << endl;
    }
    return 0;
}



Measured memory_bytes: 256
using System;

public class Program
{
	public static void Main(string[] args)
	{
		var ss = new StreamScanner();
		//---------------------------------
		while (true)
		{
			var x = ss.Next<int>();
			var y = ss.Next<int>();
			if (x == 0 && y == 0)
			{
				break;
			}
			for (int j = 0; j < x; j++)
			{
				for (int i = 0; i < y; i++)
				{
					Console.Write("#");
				}
				Console.WriteLine("");

			}
			Console.WriteLine("");

		}
		/*
		//????????????int, double, string?????????????????£????????????
		int i = ss.Next<int>();
		double d = ss.Next<double>();
		string s = ss.Next<string>();

		//?????°???????????????????????¨?????????????????????????????????????????????????´???????
		int[] array = ss.Next<int>(10);
		*/
		//---------------------------------
	}
}

public class StreamScanner
{
	private readonly char[] _c = { ' ' };
	private int _index = -1;
	private string[] _input = new string[0];
	private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

	public T Next<T>()
	{
		if (_index == _input.Length - 1)
		{
			_index = -1;
			while (true)
			{
				string rl = _sr.ReadLine();
				if (rl == null)
				{
					if (typeof(T).IsClass) return default(T);
					return (T)typeof(T).GetField("MinValue").GetValue(null);
				}
				if (rl != "")
				{
					_input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
					break;
				}
			}
		}
		return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
	}

	public T[] Next<T>(int x)
	{
		var ret = new T[x];
		for (var i = 0; i < x; ++i) ret[i] = Next<T>();
		return ret;
	}

	public T[][] Next<T>(int x, int y)
	{
		var ret = new T[y][];
		for (var i = 0; i < y; ++i) ret[i] = Next<T>(x);
		return ret;
	}
}

Measured memory_bytes: 9908
N = int(input())
list = [3, 5, 7]
num = 0

def dfs(S):
  num_S = 0
  for i in range(len(S)):
    num_S += S[len(S)-i-1]*10**i
  if num_S > N:
    return
  else:
    a = [0, 0, 0]
    for i in range(len(S)):
      if S[i] == 3:
        a[0] += 1
      elif S[i] == 5:
        a[1] += 1
      else:
        a[2] += 1
    if a[0] >= 1 and a[1] >= 1 and a[2] >= 1:
      global num
      num += 1
    dfs(S+[3])
    dfs(S+[5])
    dfs(S+[7])
    return

dfs([])
print(num)

Measured memory_bytes: 74272
#include <bits/stdc++.h>
const int U=2e5+5;
using namespace std;
using ll = long long;
 
int main() {
    int N; cin>>N;
    ll a[U];
    map<ll,int>m;
    for(int i=0; i<N; i++)cin >> a[i];
    ll ans=0;
    for(int i=0;i<N;i++)
    {
        ans+=m[i+1-a[i]];
        m[i+1+a[i]]++;
    }
  cout <<  ans  <<endl;
  return 0;
}

Measured memory_bytes: 27772