akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/perl

$c500 = <STDIN>;
$c100 = <STDIN>;
$c50 = <STDIN>;
$amount = <STDIN>;
$count = 0;

for ($i = 0; $i <= $c500; $i++) {
        for ($j = 0; $j <= $c100; $j++) {
                for ($k = 0; $k <= $c50; $k++) {
                        if ($i * 500 + $j * 100 + $k * 50 == $amount) {
                                $count++;
                                last;
                        }
                }
        }
}

print "$count\n";

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

using namespace std;

int main() {
    string b;
    cin >> b;
    if(b == "A") {
        cout << "T" << endl;
    } else if(b == "T") {
        cout << "A" << endl;
    } else if(b == "C") {
        cout << "G" << endl;
    } else if(b == "G") {
        cout << "C" << endl;
    }
}


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

struct UnionFind{
  vector<int> par;
  UnionFind(int N) : par(N){
    for(int i = 0; i < N; i++){
      par[i] = i;
    }
  }
  int root(int x){
    if(par[x] == x) return x;
    else return root(par[x]);
  }
  void unite(int x, int y){
    int rx = root(x), ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
  }
  bool same(int x, int y){
    return root(x) == root(y);
  }
};

int main(){
  int N, Q;cin >> N >> Q;
  UnionFind tree(N);
  
  for(int i = 0; i < Q; i++){
    int p, x, y;
    cin >> p >> x >> y;
    if(p == 0){
      tree.unite(x, y);
    }else{
      if(tree.same(x, y)){
        cout << 1 << endl;
      }
      else cout << 0 << endl;
    }
  }
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

int n;
vector<string> s;

void input(){
    cin >> n;
    s.resize(n);
    for(int i=0;i<n;i++) cin >> s[i];
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    string az = "abcdefghijklmnopqrstuvwxyz";
    int cnt[26];
    for(int i=0;i<26;i++){
        int rec = INF;
        int tmp;
        for(int j=0;j<n;j++){
            tmp = count(s[j].begin(), s[j].end(), az[i]);
            rec = min(rec, tmp);
        }
        cnt[i] = rec;
    }
    
    for(int i=0;i<26;i++){
        for(int j=0;j<cnt[i];j++){
            cout << az[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
N = int(input())
X = [int(_) for _ in input().split()]
b = np.polyfit([0 for _ in range(N)], X, 0) #切片だけ
# y = ax + b
P = round(b[0])
res = [(x-P)*(x-P) for x in X]
print(int(sum(res)))

Measured memory_bytes: 14344
#include<stdio.h>
#include<math.h>

int main() {
	int i, j, k;
	int	n, m, h, g, a, b, c, d;
	int f = 0;
	int x[15][15];
	int w;

	scanf("%d %d", &n, &d);

	for (i = 0;i < n;i++) {
		for (j = 0;j < d;j++) {
			scanf("%d", &x[i][j]);
		}
	}

	for (i = 0;i < n;i++) {
		for (j = i+1;j < n;j++) {
			h = 0;
			for (k = 0;k < d;k++) {
				h = h + (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
			}
			w = sqrt(h);
			if (w*w == h) {
				f = f + 1;
			}
		}
	}

	printf("%d",f);


	return 0;
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> to[200005];
vector<ll> ans;
void dfs(int v, int p = -1){
    for(auto x : to[v]){
        if(x == p) continue;
        ans[x] += ans[v];
        dfs(x, v);
    }
}

int main(){
    ll N, Q; cin >> N >> Q;
    for (ll i = 0; i < N - 1; i++) {
        ll a, b; cin >> a >> b;
        to[a-1].push_back(b-1);
        to[b-1].push_back(a-1);
    }
    ans.resize(N);

    for (ll i = 0; i < Q; i++) {
        ll p, x; cin >> p >> x;
        ans[p-1] += x;
    }

    dfs(0);

    for (ll i = 0; i < N; i++) {
        printf("%lld ", ans[i]);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 177408
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int H, W;
    cin >> H >> W;
    vector<string> v(H);
    for (int i = 0; i < H; i++) cin >> v[i];
    vector<int> delRow(H), delCol(W);

    bool isWhite;
    for (int i = 0; i < H; i++) {
        isWhite = true;
        for (int j = 0; j < W; j++) if (v[i][j] == '#') isWhite = false;
        if (isWhite) delRow[i] = 1;
    }
    for (int i = 0; i < W; i++) {
        isWhite = true;
        for (int j = 0; j < H; j++) if (v[j][i] == '#') isWhite = false;
        if (isWhite) delCol[i] = 1;
    }

    for (int i = 0; i < H; i++) {
        if (delRow[i]) continue;
        for (int j = 0; j < W; j++) if (!delCol[j]) cout << v[i][j];
        cout << '\n';
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int m1, d1, m2, d2;


    scanf("%d %d", &m1, &d1);
    scanf("%d %d", &m2, &d2);
    
    if( m1 != m2 )
    {
    	printf("1\n");
    }
    else
    {
    	printf("0\n");
    }
    return 0;
}

Measured memory_bytes: 128
import queue
n,m=map(int, input().split())
q = queue.Queue()
edgelist = [[] for _ in range(n)]
for i in range(m):
    a,b=map(int, input().split())
    edgelist[a-1].append(b-1)
    edgelist[b-1].append(a-1)
res = [-1]*n
visited = [-1]*n
for v in edgelist[0]:
    q.put([v,0])
res[0]=1
while not q.empty():
    x = q.get()
    #print(x)
    if visited[x[0]]==1:
        continue
    else:
        visited[x[0]]=1
        res[x[0]]=x[1]+1
        for i in edgelist[x[0]]:
            if visited[i]==-1:
                q.put([i, x[0]])
print("Yes")
for i in range(1,n):
    print(res[i])



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

int main(){
    int n;
    cin >> n;
    int a[100];
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(i!=n-1) printf("%d ",a[i]);
        else printf("%d\n",a[i]);
    }
    for(int i=1;i<n;i++){
        int v=a[i];
        int j=i-1;
        while(j>=0 && a[j]>v){
            a[j+1]=a[j];
            j--;
            a[j+1]=v;
        }
    for(int k=0;k<n;k++){
        if(k!=n-1) printf("%d ",a[k]);
        else printf("%d\n",a[k]);
    }
    }
}


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

const ll MOD=1e9+7;
const double EPS=1e-9;
const double PI=acos(-1.0);
//const long double PI=acos(-1.0L);

struct Point{
    double x,y;
    Point(){}
    Point(double x,double y):x(x),y(y){}

    Point operator +(const Point &b) const {return Point(x+b.x,y+b.y);}
    Point operator -(const Point &b) const {return Point(x-b.x,y-b.y);}
    Point operator *(const double b) const {return Point(x*b,y*b);}
    Point operator /(const double b) const {return Point(x/b,y/b);}
};

struct Line{
    Point a,b;
    Line(){}
    Line(Point a,Point b):a(a),b(b){}
};

int sgn(double a) {return (a>EPS)-(a<-EPS);}
int sgn(double a,double b) {return sgn(a-b);}

double dot(const Point &a,const Point &b) {return (a.x*b.x+a.y*b.y);}
double cross(const Point &a,const Point &b) {return (a.x*b.y-a.y*b.x);}
double norm(const Point &p) {return dot(p,p);}
double abs(const Point &p) {return sqrt(norm(p));}

Point projection(const Point &p,const Line &l){
    double r=dot(p-l.a,l.b-l.a)/norm(l.b-l.a);
    return l.a+(l.b-l.a)*r;
}

Point reflection(const Point &p,const Line &l){
    return p+(projection(p,l)-p)*2;
}

//1:Counter_Clockwise -1:Clockwise
//2:a-b-c -2:c-a-b 0:a-c-b
int ccw(const Point &p,const Point &q){
    int s=sgn(cross(p,q));
    if(s!=0) return s;
    if(dot(p,q)<0) return -2;
    if(norm(p)<norm(q)) return 2;
    return 0;
}
int ccw(const Point &a,const Point &b,const Point &c){return ccw(b-a,c-a);}

bool isParallel(const Line &l,const Line &r){
    if(sgn(cross(l.b-l.a,r.b-r.a))==0) return true;
    return false;
}
bool isOrthogonal(const Line &l,const Line &r){
    if(sgn(dot(l.b-l.a,r.b-r.a))==0) return true;
    return false;
}

bool isIntersected(const Line &l,const Line &r){
    if(ccw(l.b-l.a,r.a-l.a)*ccw(l.b-l.a,r.b-l.a)>0) return false;
    if(ccw(r.b-r.a,l.a-r.a)*ccw(r.b-r.a,l.b-r.a)>0) return false;
    return true;
}

Point crosspoint(const Line &l,const Line &r){
    Point v=r.b-r.a;
    double d1=abs(cross(v,l.a-r.a));
    double d2=abs(cross(v,l.b-r.a));
    double t=d1/(d1+d2);
    return l.a+(l.b-l.a)*t;
}

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

    for(int q=0;q<Q;q++){
        Point P1,P2;
        cin>>P1.x>>P1.y>>P2.x>>P2.y;
        Point P3,P4;
        cin>>P3.x>>P3.y>>P4.x>>P4.y;

        Line L1(P1,P2);
        Line L2(P3,P4);
        Point ans=crosspoint(L1,L2);
        cout<<fixed<<setprecision(10)<<ans.x<<" "<<ans.y<<endl;
    }

    return 0;
}



Measured memory_bytes: 3296
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    int k;
    cin >> k;

    int r = 0;
    forn1(i,TEN(7)) {
        r = (10 * r + 7) % k;
        if (r == 0) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}

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

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll s; cin >> s;
    ll q = 1000000000;
    ll r = s % q;
    ll a = (s - r) / q + 1;
    ll b = q-r;
    if (r == 0) {
        a--;
        b = 0;
    }
    cout << 0 << " " << 0 << " " << 1 << " " << q << " " << a << " " << b;
    return 0;
}


Measured memory_bytes: 256
/* author : akshatjai258 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define mod int(1e9 + 7)
#define inf int(1e9)
#define endl "\n"
#define rep(i,n) for (int(i) = (0); (i) < (n); ++(i))
#define fi first
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define memf(a) memset(a, false, sizeof(a))
#define all(v) v.begin(), v.end()
#define se second
#define mp make_pair
#define pb push_back
#define w(x)  \
	int x;    \
	cin >> x; \
	while (x--)
#define ps(x, y) fixed << setprecision(y) << x
void prep()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
}	
int main()
{
	prep();
    int a[5];
    int ans;
    for(int i=0;i<5;i++){
    cin>>a[i];
    if(a[i]==0)
    ans=i+1;
    }
    cout<<ans;
	return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <functional>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 3000000;

long long fac[MAX], finv[MAX], inv[MAX];


ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
            prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
} 


int main() {
    string s,t;
    cin >> s;
    cin >> t;

    vector<ll> dp(t.size(), 0);

    map<char, vector<ll>> m;
    for(ll i = 0; i < s.size(); i++) {
        m[s[i]].push_back(i);
    }

    for(ll i = 0; i < t.size(); i++) {
        if(m[t[i]].size() == 0) {
            cout << -1 << endl;
            return 0;
        }
    }
    
    dp[0] = m[t[0]][0];
    // cout << dp[0] << endl;
    for(ll i = 1; i < t.size(); i++) {
        auto itr = upper_bound(m[t[i]].begin(), m[t[i]].end(), dp[i-1] % s.size());
        if(itr != m[t[i]].end()) {
            dp[i] = dp[i-1] -  (dp[i-1] % s.size()) + *itr;
            // cout << "found: plus -> " <<   -  (dp[i-1] % s.size()) + *itr << endl;
        }
        else {
            dp[i] = dp[i-1] +  (s.size() - dp[i-1] % s.size()) + m[t[i]][0];
            // cout << "not found: plus -> " <<  (s.size() - dp[i-1] % s.size()) + m[t[i]][0] << endl;
        }
    }

    cout << dp[t.size()-1] + 1 << endl;

    return 0;    
}




Measured memory_bytes: 5484
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        int N = intRead();
        string ans = "NO";
        if (N == 7 || N == 5 || N == 3) ans = "YES";
        Console.WriteLine(ans);
    }
}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static long LCM(long a, long b)
    {
        long c = a * b;
        if (a < b) Swap(ref a, ref b);
        long d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static int[] SpIntRead(char c)
    {
        return Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
    }
    public static string ToConvertBit(int N, int e)
    {
        string ret = "";
        int r = 0;
        while (N != 0)
        {
            r = N % e;
            ret += r.ToString();
            N -= r;
            N /= e;
        }
        ret = strReverce(ret);
        return ret;
    }

}


Measured memory_bytes: 11092
E, Y = gets.split.map &:to_i

DATE = [0, 1868, 1912, 1926, 1989]
PERIOD = [1867, 44, 14, 63, 28]
ERA = %w!AD M T S H!

if E.zero?
  (1..4).each do |i|
    y = Y - DATE[i] + 1
    next unless (1..PERIOD[i]).include? y
    print ERA[i]
    p y
  end
else
  p DATE[E] + Y - 1
end

Measured memory_bytes: 8652
#include <stdio.h>

int main(void) {
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	if(a>=1&&a<=1000000000&&b>=1&&b<=1000000000){
		d=a/b;
		r=a%b;
		f=(double)a/(double)b;
		printf("%d %d %f\n",d,r,f);
	}
	return 0;
}



Measured memory_bytes: 2068
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vi x(N);
    cin >> x;
    ans = INF;
    REPS(i, 100) {
        int e = 0;
        REP(n, N) {
            e += (x[n] - i) * (x[n] - i);
        }
        ans = min(e, int(ans));
    }
    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i ++) {
    int tmp; cin >> tmp;
    a.at(i) = tmp - i - 1;
  }

  sort(a.begin(), a.end());
  int med = a.at(n / 2);
  LL ans = 0;
  for (int i = 0; i < n; i ++) {
    ans += abs(a.at(i) - med);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>

int main()
{
	int a, b, c, count = 0;

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

	for (int i = a; i < b + 1; ++i)
		if (c%i == 0)
			++count;

	std::cout << count << std::endl;
	return 0;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 5;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const ll N = 12;
vector<ll> v[N];
ll n,m,num;
ll k[N],s[N][N],p[N];
int flag[N];

int solve() {
  rep(i,(int)pow(2,n)) {
    memset(flag, 0, sizeof flag);
    bool f = true;
    rep(j,n) {
      rep(kk, m) {
        rep(l,k[kk]) {
          flag[kk] = (i>>j) & 1 &&  j == s[kk][l]-1 ? (flag[kk]+1)%2 : flag[kk];
        } 
      }
    }
    rep(j,m) {
      if (flag[j] != p[j]) {
        f = false;
        break;
      }
    }
    if(f) num++;
    // cout << i << " : " << num << endl;
  }
  return num;
}

int main () {
  ios::sync_with_stdio(false);cin.tie(nullptr);
  cin >> n >> m;
  rep(i,m) {
    cin >> k[i];
    rep(j,k[i]) cin >> s[i][j];
  }
  rep(i,m) cin >> p[i];
  
  cout << solve() << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const int mod = 1000000007;

ll dp[3001][3001] = { 0 };

int main()
{
    string s, t;
    cin >> s >> t;

    for (int i = 1; i <= s.size(); i++) {
        for (int j = 1; j <= t.size(); j++) {
            if (s[i-1] == t[j-1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    
    int i = s.size();
    int j = t.size();
    string ans;
    while (dp[i][j]) {
        if (s[i-1] == t[j-1]) {
            ans += s[i-1];
            i--;
            j--;
        }
        else {
            if (dp[i][j - 1] == dp[i][j]) {
                j--;
            }
            else {
                i--;
            }
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 73956
#include <stdio.h>
#define NOT_FOUND 0

int binarySearch(int data[], int key, int n);

int main(void)
{
    int num1, num2, i, key, data[100000], count = 0;

    scanf("%d", &num1);
    for (i = 0; i < num1; i++) {
        scanf("%d", &data[i]);
    }

    scanf("%d", &num2);
    for (i = 0; i < num2; i++) {
        scanf("%d", &key);
        if (binarySearch(data, key, num1) != NOT_FOUND) count++;
    }

    printf("%d\n", count);

    return 0;
}

int binarySearch(int data[], int key, int n)
{
    int left = 0;
    int right = n;
    while (left < right) {
        int mid = (left + right) / 2;

        if (data[mid] == key) {
            return 1;
        } else if (key < data[mid]) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    return NOT_FOUND;
}



Measured memory_bytes: 2160
import java.util.*;//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
public class Main{//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
        public static void main(String[] args){//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
                Scanner sc = new Scanner(System.in);//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
                int x = sc.nextInt();//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
                int a = sc.nextInt();//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
                if(x < a){//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
                        System.out.println(0);//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
                }else{//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
                        System.out.println(10);//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
                }//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
                sc.close();//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
        }//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
}//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww

Measured memory_bytes: 35592
#include <stdio.h>

int main(void)
{
  int a[2000], b[2000], c[2000];
  int n, i, max, judge;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
  }

  for(i = 0; i < n; i++){
    max = 0;
    if(a[i] > b[i])
      max = a[i];
    else
      max = b[i];

    if(c[i] > max)
      max = c[i];

    if(max == a[i]){
      if(a[i]*a[i] == b[i]*b[i] + c[i]*c[i])
	judge = 1;
      else
	judge = 0;
    }
    else if(max == b[i]){
      if(b[i]*b[i] == a[i]*a[i] + c[i]*c[i])
	judge = 1;
      else
	judge = 0;
    }
    else if(max == c[i]){
      if(c[i]*c[i] == b[i]*b[i] + a[i]*a[i])
	judge = 1;
      else
	judge = 0;
    }

    if(judge)
      printf("YES\n");
    else
      printf("NO\n");
  }

  return(0);
}

Measured memory_bytes: 600
//// A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
////
//
//#include <iostream>
//using namespace std;
//
//int main()
//{
//
//    int n;
//    int h[100005];
//    int sage[100005] = { 0 };
//    cin >> n;
//    h[0] = -10;
//    for (int i = 1; i <= n; i++) {
//        cin >> h[i];
//    }
//    bool judge = true;
//    for (int i = 2; i <= n; i++) {
//        if (h[i] >= h[i - 1]) {
//            continue;
//        }
//        else {
//            if ((h[i - 1] - 1 == h[i])) {
//                
//                if (h[i - 2] < h[i - 1]) {
//                    h[i - 1]--;
//                    sage[i - 1] = 1;
//                }
//                else if (h[i - 2] = h[i - 1] && sage[i - 2] != 1) {
//                    h[i - 2]--;
//                    h[i - 1]--;
//                    sage[i - 2] = sage[i - 1] = 1;
//                }
//                else {
//                    judge = false;
//                    break;
//                }
//
//            }
//            else {
//                judge = false;
//                break;
//            }
//        }
//        
//    }
//
//    if (judge) {
//        cout << "Yes" << endl;
//    }
//    else {
//        cout << "No" << endl;
//    }
//    return 0;
//}
//


#include<iostream>

using namespace std;

int main() {

	int n;
	cin >> n;
	int h[100005];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	h[0]--;
	bool judge = true;
	for (int i = 1; i < n; i++) {
		if (h[i] > h[i - 1]) {
			h[i]--;
		}
		else if (h[i] == h[i - 1]) {
			continue;
		}
		else {
			judge = false;
			break;
		}
	}

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

Measured memory_bytes: 3992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll h,w,n;
  cin >> h >> w >> n;
  vector<priority_queue<ll,vec,greater<ll>>> p(h+2);
  for(ll i=0;i<n;i++) {
    ll x,y;
    cin >> x >> y;
    p[x].push(y);
  }
  p[h+1].push(1);
  ll th=1;
  for(ll i=1;i<=h;i++) {
    if(p[i+1].size()) {
      if(p[i+1].top()<=th) {
        cout << i << endl;
        return 0;
      }
    }
    th++;
    if(p[i+1].size()) {
      if(p[i+1].top()==th) {
        th--;
      }
    }
  }
}

Measured memory_bytes: 15496
#include <iostream>
#include <string>

using namespace::std;

int N, A, B;

int main() {
	cin >> N;

	if (N > 89||(N - 9) % 10 == 0) {
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}
	return 0;
		}


	

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <queue>
 
using namespace std;
typedef long long int ll;

#define MOD 1000000007LL

ll N;
ll A, B, C;
vector<int> s;
vector<char> aq;

bool exec(int, int, int, int);

int main()
{
  int i;
  string si;

  cin >> N >> A >> B >> C;
  s.resize(N);
  for (i=0; i<N; i++) {
    cin >> si;
    if (si == "AB") {s[i] = 1; continue;}
    if (si == "AC") {s[i] = 2; continue;}
    if (si == "BC") {s[i] = 3; continue;}
  }

  aq.resize(N);
  if (!exec(0, A, B, C))
    printf("No\n");

  return 0;
}

bool exec(int i, int a, int b, int c) {
  bool r = false;
  if (i == N) {
//printf("%d (%d, %d, %d)\n", i, a, b, c);
    printf("Yes\n");
    for (int j=0; j<N; j++) {
      printf("%c\n", aq[j]);
    }
    return true;
  }
//printf("%d [%d] (%d, %d, %d)\n", i, s[i], a, b, c);
  switch(s[i]) {
  case 1:
    if (b>0) {
      aq[i] = 'A';
      r = exec(i+1, a+1, b-1, c);
      if (!r) {
        if (a>0) {
          aq[i] = 'B';
          r = exec(i+1, a-1, b+1, c);
        }
      }
    } else if (a>0) {
      aq[i] = 'B';
      r = exec(i+1, a-1, b+1, c);
    }
    break;
  case 2:
    if (c>0) {
      aq[i] = 'A';
      r = exec(i+1, a+1, b, c-1);
      if (!r) {
        if (a>0) {
          aq[i] = 'C';
          r = exec(i+1, a-1, b, c+1);
        }
      }
    } else if (a>0) {
      aq[i] = 'C';
      r = exec(i+1, a-1, b, c+1);
    }
    break;
  case 3:
    if (b>0) {
      aq[i] = 'C';
      r = exec(i+1, a, b-1, c+1);
      if (!r) {
        if (c>0) {
          aq[i] = 'B';
          r = exec(i+1, a, b+1, c-1);
        }
      }
    } else if (c>0) {
      aq[i] = 'B';
      r = exec(i+1, a, b+1, c-1);
    }
    break;
  }
  return r;
}



Measured memory_bytes: 11692
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;

#define ll long long

const int mxN = 1e5;

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

    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R') cnt++;
    }

    int ans = cnt;
    for (int i = 0; i < cnt; i++)
    {
        if (s[i] == 'R') ans--;
    }
    
    cout << ans << "\n";
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    int mount[N];

    for(int i = 0; i < N; i++) {
        cin >> mount[i];
    }

    int MAX = mount[0];
    int counter = 0;

    for(int i = 0; i < N; i++) {
        if(MAX <= mount[i]) {
            counter++;
            MAX = mount[i];
        }
    }

    cout << counter << endl;

}

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

typedef long long ll;
ll a[233333];
int n;

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%lld", &a[i]), a[i] -= i;
	sort(a + 1, a + 1 + n);
	ll Mid = 0, ans = 0;
	if(n % 2 == 0) Mid = (a[n / 2] + a[n / 2 + 1]) / 2;
	else Mid = a[n / 2 + 1];
	for(int i = 1; i <= n; i++) ans += abs(a[i] - Mid);
	printf("%lld\n", ans);
	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t = 1;
    // while (t--) {
        ll h, n;
        cin >> h >> n;
        vector<ll> a(n);
        for (ll i = 0; i < n; i++) {
            cin >> a[i];
            h -= a[i];
        }
        cout << (h <= 0 ? "Yes\n" : "No\n");
    
    return 0;
}


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

int main()
{
    int i,j,a[5],k,d;
    bool b = 0;

    for(i=0; i<5; i++)
        scanf("%d",&a[i]);
    scanf("%d",&k);

    for(i=0; i<4; i++) {
        for(j=i+1; j<5; j++) {
            d = abs(a[i]-a[j]);
            if(d > k) b = 1;
        }
    }

    if(b) printf(":(\n");
    else printf("Yay!\n");

    return 0;
}


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

static class CodeJam
{
    private const int M = 1000000007;

    class Modulo
    {
        private readonly int[] m_facs;
        public int Mul(int a, int b)
        {
            return (int)(Math.BigMul(a, b) % M);
        }
        public Modulo(int n)
        {
            m_facs = new int[n + 1];
            m_facs[0] = 1;
            for (int i = 1; i <= n; ++i)
            {
                m_facs[i] = Mul(m_facs[i - 1], i);
            }
        }
        public int Fac(int n)
        {
            return m_facs[n];
        }
        public int Pow(int a, int m)
        {
            switch (m)
            {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                int p1 = Pow(a, m / 2);
                int p2 = Mul(p1, p1);
                return ((m % 2) == 0) ? p2 : Mul(p2, a);
            }
        }
        public int Div(int a, int b)
        {
            return Mul(a, Pow(b, M - 2));
        }
        public int Ncr(int n, int r)
        {
            if (n < r) { return 0; }
            if (n == r) { return 1; }
            int res = Fac(n);
            res = Div(res, Fac(r));
            res = Div(res, Fac(n - r));
            return res;
        }
    }

    static long Solve(Modulo mod, int r, int b, int i)
    {
        int R = mod.Ncr(r + 1, i);
        int B = mod.Ncr(b - 1, i - 1);
        return (int)(Math.BigMul(R, B) % M);
    }

    static void Main(string[] args)
    {
        int[] V = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int N = V[0], K = V[1];
        var mod = new Modulo(2000);
        for (int i = 1; i <= K; ++i)
        {
            Console.WriteLine(Solve(mod, N - K, K, i));
        }
    }
}


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

using namespace std;

int n;
int a[10010],b[10010],co[10010];

int solve(int l,int r){
    
    while(co[l] == co[r] && a[l]+b[r] >= 4){
        l = l-a[l];
        r = r+b[r];
    }
    
    return (l+n-r+1);
}

int main(){
    
    int ans;
    while(cin >> n,n!=0){
        
        co[0] = -1;
        co[n+1] = -1;
        a[0] = 0;
        a[n+1] = 0;
        for(int i=1;i<=n;i++){
            cin >> co[i];
            if(co[i] == co[i-1]) a[i] = a[i-1]+1;
            else a[i] = 1;
        }
    
        b[0] = 0;
        b[n+1] = 0;
        for(int i=n;i>0;i--){
            if(co[i] == co[i+1]) b[i] = b[i+1]+1;
            else b[i] = 1;
        }
        
        ans = n;
        for(int i=1;i<=n;i++){
        
            if(a[i-1] >= 3 || b[i+1] >= 3 || co[i-1] == co[i+1] && a[i-1]+b[i+1] >= 3){
                
                int l = (i-1)-a[i-1];
                int r = (i+1)+b[i+1];
            
                if(co[i-1] == co[i+1]) ans = min(ans,solve(l,r));
                else {
                    if(a[i-1] >= 3) ans = min(ans,solve(l,i+1));
                    if(b[i+1] >= 3) ans = min(ans,solve(i-1,r));
                }
        
            }
        
        }
        cout << ans << endl;
    }
    
    return(0);
}


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

using namespace std;

int main(int argc, char *argv[]) {
	int a, b;
	cin >> a >> b;
	
	float ans = 0;
	if (b >= 2) {
		b -= a;
		ans += 1;
		if (b > 0) {
			ans += ceil((float)b / (float)(a - 1));
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 以下から
const int MAX_N = 100000;
struct Edge {
    int to;
    int id;
};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c=-1, int p=-1) {
    int k=1;
    rep(i,g[v].size()) {
        int u = g[v][i].to, ei = g[v][i].id;
        if (u==p) continue;
        if (k == c) ++k;
        ans[ei] = k; ++k;
        dfs(u,ans[ei],v);
    }
}
int main() {
    string s; cin >> s;
    int ans = 0;
    rep(i,s.size()/2) {
        if (s[i] != s[s.size()-i-1]) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

template<class T> constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }

typedef long long ll;
int const inf = 1<<29;

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

int H, W, N;
vector<string> G;

bool solve() {

  auto mark = [](const int y, const int x, vector<vector<bool>>& vis) {
    bool ok = 0;
    char c = G[y][x];
    vis[y][x] = 1;
    int sx = -1, tx = -1;
    for(int i=x; i>=-1; i--) if(i == -1 || G[y][i] != c) { sx = i+1; break; }
    for(int i=x; i<=W;  i++) if(i == W  || G[y][i] != c) { tx = i-1; break; }
    assert((sx + 1) && (tx + 1));
    if(tx - sx + 1 >= N) {
      ok = 1;
      REP(i, sx, tx+1) { vis[y][i] = 1; }
    }
    int sy = -1, ty = -1;
    for(int i=y; i>=-1; i--) if(i == -1 || G[i][x] != c) { sy = i+1; break; }
    for(int i=y; i<=H;  i++) if(i == H  || G[i][x] != c) { ty = i-1; break; }
    assert((sy + 1) && (ty + 1));
    if(ty - sy + 1 >= N) {
      ok = 1;
      REP(i, sy, ty+1) { vis[i][x] = 1; }
    }
    if(!ok) { vis[y][x] = 0; }
    return ok;
  };

  auto fill = [](vector<vector<bool>>& vis) {
    rep(i, H) rep(j, W) {
      if(vis[i][j]) { G[i][j] = '.'; }
    }
  };

  auto drop = []() {
    rep(j, W) {
      vector<char> col;
      for(int i=H-1; i>=0; i--) {
        if(G[i][j] != '.') { col.push_back(G[i][j]); }
      }
      for(int i=H-1; i>=H-(int)col.size(); i--) {
        G[i][j] = col[H-1-i];
      }
      for(int i=H-1-(int)col.size(); i>=0; i--) {
        G[i][j] = '.';
      }
    }
  };

  std::function<void()> simulate = [&]() {
    drop();
    while(1) {
      vector<vector<bool>> vis(H, vector<bool>(W));
      bool ok = 0;
      rep(i, H) rep(j, W) {
        if(!vis[i][j] && G[i][j] != '.') {
          if(mark(i, j, vis)) { ok = 1; }
        }
      }
      if(ok) {
        fill(vis);
        drop();
      }
      else {
        break;
      }
    }
  };

  simulate();

  rep(i, H) rep(j, W) {
    if(G[i][j] != '.') { return false; }
  }
  return true;
}

int main() {

  cin >> H >> W >> N;
  vector<string> F(H);
  rep(i, H) { cin >> F[i]; }

  rep(i, H) rep(j, W) {
    G = F;
    if(!in_range(i, j+1, H, W)) { continue; }
    swap(G[i][j], G[i][j+1]);
    if(solve()) {
      cout << "YES" << endl;
      return 0;
    }
  }

  cout << "NO" << endl;
  
  return 0;
}

Measured memory_bytes: 3228
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())


n = ni()
p = li_()

a = [i*n + 1 for i in range(n)]
b = a[::-1]

ad = 0
for pi in p:
    a[pi] += ad
    b[pi] += ad
    ad += 1
    
print(*a)
print(*b)

Measured memory_bytes: 6396
#include <stdio.h>
int main (){
char a[3],b[3];
scanf ("%s",a);
scanf ("%s",b);
if (a[0]==b[2] & a[1]==b[1] & a[2]==b[0]){
printf ("YES");
}
  else {
  printf ("NO");
  }
return 0;
}

Measured memory_bytes: 128
### main

loop do
  x, y, sx = gets.split.map(&:to_i)
  break if (x | y | sx) == 0

  max_sy = 0
  for a in (1..sx)
    af = a.to_f
    ax = (af * (100 + x) / 100).to_i
    ay = (af * (100 + y) / 100).to_i
    for b in (1..sx)
      bf = b.to_f
      bx = (bf * (100 + x) / 100).to_i
      by = (bf * (100 + y) / 100).to_i
      if ax + bx == sx
        sy = ay + by
        max_sy = sy if max_sy < sy
      elsif ax + bx > sx
        break
      end
    end
  end

  puts max_sy
end

Measured memory_bytes: 6124
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans = 0;

            int A = int.Parse(Console.ReadLine());

            if (A % 2 == 0)
                ans = A;
            else
                ans = A * 2;

            Console.WriteLine(ans.ToString());
        }
    }


}


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

struct edge{ll to,cap,rev;};

const int MAX_V=222;
const ll INF=LLONG_MAX/2;
vector<edge> G[MAX_V];
bool used[MAX_V];
void add_edge(int from,int to,ll cost){
  G[from].push_back((edge){to,cost,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

ll dfs(int v,int t,ll f){
  if(v==t) return f;
  used[v]=1;
  for(int i=0;i<G[v].size();i++){
    edge &e=G[v][i];
    if(!used[e.to] && e.cap>0){
	     ll d=dfs(e.to,t,min(f,e.cap));
	      if(d>0){
	         e.cap-=d;
	         G[e.to][e.rev].cap+=d;
	         return d;
	      }
	  }
  }
  return 0;
}

ll max_flow(int s,int t){
  ll flow=0;
  while(1){
    memset(used,0,sizeof(used));
    ll f=dfs(s,t,INF);
    if(f==0) return flow;
    flow+=f;
  }
}


int main(){
  int N; cin>>N;
  ll A[N+1], sum=0;
  for(int i=1;i<=N;i++){
    cin>>A[i];
    if(A[i]>=0){
      sum+=A[i];
      add_edge(i,N+1,A[i]);
    }else{
      add_edge(0,i,-A[i]);
    }
  }
  for(int i=1;i<=N;i++){
    for(int j=2*i;j<=N;j+=i) add_edge(i,j,INF);
  }
  cout<<sum-max_flow(0,N+1)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int N, M;
  cin >> N >> M;
  
  if (min(N, M) == 1) {
    if (max(N, M) == 1) {
      cout << 1 << '\n';
    } else {
      cout << max(N, M) - 2 << '\n';
    }
    return 0;
  }
  
  cout << 1LL * (N - 2) * (M - 2) << '\n';
  
  return 0;
}


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

using namespace std;

int main()
{
    long long a, b;
    cin >> a >> b;
    
    if (a * b <= 0) {
        cout << "Zero" << endl;
    } else if (a > 0 && b > 0) {
        cout << "Positive" << endl;
    } else { // a < 0 && b < 0
        const long diff = b - a;
        if (diff == 0) {
            cout << "Positive" << endl;
        } else if (diff % 2 == 0) {
            cout << "Negative" << endl;
        } else {
            cout << "Positive" << endl;
        }
    }
}

Measured memory_bytes: 256
def main():
    N, M = map(int, input().split(" "))
    S = []
    for _ in range(M):
        tmp = list(map(int, input().split(" ")))[1:]
        binary_s = 0
        for t in tmp:
            binary_s += 2 ** (t - 1)
        S.append(binary_s)
    P = list(map(int, input().split(" ")))
    result = 0
    for i in range(2 ** N):
        for s, p in zip(S, P):
            if not bin(s & i).count("1") % 2 == p:
                break
        else:
            result += 1
    print(result)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 2000000

int H, A[MAX + 1];
void maxHeap(int k) {
	int l, t, Largest;
	l = 2 * k;
	t = 2 * k + 1;

	if (l <= H && A[l] > A[k]) Largest = l;
	else Largest = k;
	if (t <= H && A[t] > A[Largest]) Largest = t;

	if (Largest != k) {
		swap(A[k], A[Largest]);
		maxHeap(Largest);
	}
}
int main() {
	cin >> H;
	for (int i = 1; i <= H; i++) cin >> A[i];
	for (int i = H / 2; i >= 1; i--) maxHeap(i);
	for (int i = 1; i <= H; i++) {
		cout << " " << A[i];
	}
	cout << endl;
}


Measured memory_bytes: 5048
from collections import defaultdict
#木の根を得る
def root(x):
    while par[x] >= 0:
        x = par[x]
    return x

#木の併合
def unite(x,y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        if rx > ry:
            rx, ry = ry, rx
        par[rx] += par[ry]
        par[ry] = rx

N, M = map(int, input().split())
par = [-1]*N
for i in range(M):
    A, B = map(int, input().split())
    A, B = A - 1, B - 1
    unite(A, B)

T = defaultdict(int)
for i in range(N):
    T[root(i)] = 1
print(len(T)-1)

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define INF INT_MAX/2

int main()
{
	while (1)
	{
		int n; cin >> n;
		if (n == 0) return 0;

		int sum = 0;
		int _max = -1;
		int _min = INF;
		rep(i, 0, n)
		{
			int s; cin >> s;
			sum += s;
			_max = max(_max, s);
			_min = min(_min, s);
		}
		sum -= _max;
		sum -= _min;
		cout << sum / (n - 2) << endl;
	}
}

Measured memory_bytes: 3088
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

import bisect
def isin(arr,x):
	#print(bisect.bisect_left(arr,x))
	return arr[min(bisect.bisect_left(arr,x),len(arr)-1)]==x

n,m = readInts()
ab = [readInts() for i in range(m)]
go1 = []
for i in range(m):
	if ab[i][0]==1:
		go1.append(ab[i][1])
go1.sort()
for i in range(m):
	if isin(go1,ab[i][0]) and ab[i][1]==n:
		print("POSSIBLE")
		exit()

print("IMPOSSIBLE")

Measured memory_bytes: 45632
#include <bits/stdc++.h>
using namespace std;
typedef  long long  ll;
	int mod=1e9+7;
	ll power(ll n,ll b){
		ll ans=1;
		while(b>0){
			
			if(b&1){
				ans=(ans*n)%mod;
			}
			n=(n*n)%mod;
			b>>=1;
		}

		return ans;
	}

	int main() {

		#ifndef ONLINE_JUDGE
	        freopen("input.txt","r",stdin);
	        // freopen("output.txt","w",stdout);
	    #endif
	    ios::sync_with_stdio(false);
	    cin.tie(0);
	    cout.tie(0);
	   
	  	int n;
	  	cin>>n;
	  	
	  	ll ans= (power(10,n)-(1LL*2*power(9,n))%mod+power(8,n) +mod)%mod;

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





Measured memory_bytes: 3652