akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <complex>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef complex<double> P;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag();
    }
}
double cross(const P& a, const P& b) { return imag(conj(a)*b); }
double dot(const P& a, const P& b) { return real(conj(a)*b); }
int ccw(const P& a, P b, P c) {
    b -= a, c -= a;
    if (cross(b, c) > 0) return 1;
    if (cross(b, c) < 0) return -1;
    if (dot(b, c) < 0) return 2;
    if (norm(b) < norm(c)) return -2;
    return 0;
}

vector<P> convex_hull(vector<P> ps) {
    int n = ps.size(), k = 0;
    sort(ps.begin(), ps.end());
    vector<P> v(2*n);
    for (int i = 0; i < n; v[k++] = ps[i++]) {
        while (k > 1 && ccw(v[k-2], v[k-1], ps[i]) <= 0) k--;
    }
    for (int i = n-2, t = k; i >= 0; v[k++] = ps[i--]) {
        while (k > t && ccw(v[k-2], v[k-1], ps[i]) <= 0) k--;
    }
    v.resize(k-1);
    return v;
}

int main() {
    for (;;) {
        int n;
        scanf("%d", &n);
        if (n == 0) return 0;
        vector<P> ps;
        rep (i, n) {
            double x, y;
            scanf("%lf,%lf", &x, &y);
            ps.push_back(P(x, y));
        }
        vector<P> qs = convex_hull(ps);
        printf("%d\n", (int)(ps.size()-qs.size()));
    }
}

Measured memory_bytes: 0
from collections import Counter

N=int(input())
A=Counter(list(map(int,input().split())))
nmax=10**6
iscop=[True]*(nmax+1)

for k in A.keys():
    if iscop[k]==False:
        continue

    for j in range(2,nmax//k+1):
        iscop[k*j]=False
ans=0
for k,v in A.items():
    if v<2 and iscop[k]:
        ans+=1

print(ans)

Measured memory_bytes: 131536
#include<stdio.h>
int main(void){
	int x;
	scanf("%d", &x);
	int y = x;
	while(1){
		int n = 2;
		int flg = 1;
		while(n*n < y){
			if(y%n == 0){
				flg = 0;
				break;
			}
			n++;
		}
		if(flg == 1){
			break;
		}
		y++;
	}
	printf("%d\n", y);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
signed main(void)
{
	 long long int r,c;
	 cin>>r>>c;
     
     if(r == 1 || c == 1)
     	cout<<1<<endl;
     else{
	 long long int ans = (r*c+1)/2;	
	 
	 cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <random>
#include <iomanip>
#include <functional>
#include <list>
#include <unordered_map>
using namespace std;

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

    if (n == 1)
    {
        cout << "Hello World";
    }
    else
    {
        int a, b;
        cin >> a >> b;

        cout << a + b;
    }
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int h, w;
    cin>>h>>w;
    vector<string> v(h);
    rep(i, h) cin>>v[i];
    vector<int> xvec = {1, 0, -1, 0};
    vector<int> yvec = {0, 1, 0, -1};
    rep(i, h){
        rep(j, w){
            if(v[i][j] == '#'){
                bool ok = false;
                rep(xi, 4){
                    int nowi = i + xvec[xi];
                    int nowj = j + yvec[xi];
                    if(nowi < 0 || nowi > h-1 || nowj<0 || nowj > w-1) continue;
                    if(v[nowi][nowj] == '#') ok = true;
                }
                if(!ok){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

bool solve() {
    int a, b;
    cin >> a >> b;
    for (int x = 0; x <= 100; x++) {
        for (int y = 0; y <= 100; y++) {
            if (x + y == a && 2 * x + 4 * y == b)
                return true;
        }
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (solve())
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

int selectionSort(int A[], int N){
    int sw = 0;
    for (int i = 0; i < N; i++){
        int minj = i;
        for (int j = i; j < N; j++){
            if (A[j] < A[minj]) minj = j;
        }
        if (minj != i){
            swap(A[i], A[minj]);
            sw++;
        }
    }
    return sw;
}

int main(){
    int N;
    cin >> N;
    int A[N];
    for ( int i = 0; i < N; i++) cin >> A[i];
    
    int sw = selectionSort(A, N);
    
    for (int i = 0; i < N; i++){
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;
    
    return 0;
}


Measured memory_bytes: 3108
#include<stdio.h>
int main()
{
    int h, w;
    scanf("%d %d", &h, &w);
    int a[555][555];
    int i, j;
    for (i = 0; i < h; i++)
        for (j = 0; j < w; j++)
            scanf("%d", &a[i][j]);
    int n = 0;
    int y[250000], x[250000], yd[250000], xd[250000];
    for (i = 0; i < h; i++)
    {
        for (j = 0; j < w; j++)
        {
            if (j < w - 1)
            {
                if (a[i][j] % 2 == 1)
                {
                    y[n] = i;
                    x[n] = j;
                    yd[n] = i;
                    xd[n] = j + 1;
                    n++;
                    a[i][j + 1]++;
                }
            }
            else
            {
                if (i < h - 1)
                {
                    if (a[i][j] % 2 == 1)
                    {
                        y[n] = i;
                        x[n] = j;
                        yd[n] = i + 1;
                        xd[n] = j;
                        n++;
                        a[i + 1][j]++;
                    }
                }
            }
        }
    }
    printf("%d\n", n);
    for (i = 0; i < n; i++)
        printf("%d %d %d %d\n", y[i] + 1, x[i] + 1, yd[i] + 1, xd[i] + 1);
    return 0;
}

Measured memory_bytes: 7040
#include<iostream>
#include<list>
using namespace std;
int main()
{
  int n,f,q,t,x,s;
  cin>>n>>q;
  list<int>L[n];
  list<int>::iterator it;
  while(q--)
{
    cin>>f;
    switch(f)
 {
  case 0:
            cin>>t>>x;
            L[t].push_back(x);
            break;
  case 1:
            cin>>t;
            for(it=L[t].begin(); it !=L[t].end(); it++){
            if(it!=L[t].begin())
              cout<<' ';
              cout<<*it;
            }

            cout<<endl;
            break;
  case 2:
            cin>>s>>t;
            if(! L[s].empty())
            L[t].splice(L[t].end(),L[s]);
            break;

 }

}

  return 0;
}



Measured memory_bytes: 18632
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    while(a>0 && c>0) {
        c -= b;
        if (c <= 0) {
            puts("Yes");
            return 0;
        } 
        a -= d;
        if (a <= 0) {
            puts("No");
            return 0;
        } 
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int main() {
    string s, t;
    cin >> s >> t;
    string ans = "";
    for(int i = s.size()-t.size(); i > -1; i--) {
        int flag = 0;
        //cout << "i: " << i << endl;
        int pos = i;
        for(int j = 0; j < t.size(); j++) {
            //cout << "j: " << j << endl;
            //cout << s[j+i] << " " << t[j] << endl;
            if(s[j+i] == t[j] || s[j+i] == '?') {
                //pos = i;
            }
            else {
                flag = 1;
                break;
            }
        }
        if(flag == 0) {
            for(int j = 0; j < i; j++) {
               if(s[j] == '?') ans += 'a';
               else ans += s[j];
            }
            for(int j = i; j < i+t.size(); j++) {
                ans += t[j-i];
            }
            for(int j = ans.size(); j < s.size(); j++) {
                if(s[j] == '?') ans += 'a';
                else ans += s[j];
            }
            //ans += t;
            cout << ans << endl;
            return 0;
        }
    }
    cout << "UNRESTORABLE" << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

const ll MAX_N=1e5;


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

  ll n,a,b,c;
  cin>>n>>a>>b>>c;

  vector<string> s(n);
  REP(i,n)cin>>s[i];

  vector<string> ans(n);
  REP(i,n){
    if(s[i]=="AB"){
      if((a==1 && b==1) && i!=n-1){
        if(s[i+1]=="AC"){
          a++;
          b--;
          ans[i]="A";
        }
        else{
          a--;
          b++;
          ans[i]="B";
        }
      }
      else if(a<b){
        a++;
        b--;
        ans[i]="A";
      }
      else{
        a--;
        b++;
        ans[i]="B";
      }
    }


    if(s[i]=="BC"){
      if((b==1 && c==1) && i!=n-1){
        if(s[i+1]=="AB"){
          b++;
          c--;
          ans[i]="B";
        }
        else{
          b--;
          c++;
          ans[i]="C";
        }
      }
      else if(b<c){
        b++;
        c--;
        ans[i]="B";
      }
      else{
        b--;
        c++;
        ans[i]="C";
      }
    }


    if(s[i]=="AC"){
      if((a==1 && c==1) && i!=n-1){
        if(s[i+1]=="AB"){
          a++;
          c--;
          ans[i]="A";
        }
        else{
          a--;
          c++;
          ans[i]="C";
        }
      }
      else if(a<c){
        a++;
        c--;
        ans[i]="A";
      }
      else{
        a--;
        c++;
        ans[i]="C";
      }
    }

    if(a<0 || b<0 || c<0){
      cout<<"No"<<endl;
      return 0;
    }
  }


  cout<<"Yes"<<endl;
  REP(i,n)cout<<ans[i]<<endl;
}



Measured memory_bytes: 9536
A,B,C,D,E,F=map(int,input().split())
d=0
ans=(100*A,0)
for x in range(F//(100*A)+1):
    for y in range((F-x*100*A)//(100*B)+1):
        if x+y==0:
            continue
        for z in range((F-x*100*A-y*100*B)//C+1):
            for w in range((F-x*100*A-y*100*B-z*C)//D+1):                
                if (x*A+y*B)*E>=(z*C+w*D) and d<100*(z*C+w*D)/(100*(x*A+y*B)+(z*C+w*D)):                    
                    d=100*(z*C+w*D)/(100*(x*A+y*B)+(z*C+w*D))
                    # print((x,y,z,w))                
                    # print((100*(x*A+y*B)+(z*C+w*D),(z*C+w*D),d))
                    ans=(100*(x*A+y*B)+(z*C+w*D),(z*C+w*D))

print(*ans)

Measured memory_bytes: 42220
#include <stdio.h>

int main() {
  int i, j, number_n, flag, count = 0;
  scanf("%d", &number_n);
  for(i = 1; i <= number_n; i += 2) {
    flag = 0;
    for(j = 1; j <= i; j++) {
      if(i % j == 0) {
        flag++;
      }
    }
    if(flag == 8) count++;
  }
  printf("%d\n", count);
  return 0;
}


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

int main(int argc, char const *argv[]) {
    int K;
    string S;
    cin >> K >> S;

    if (S.size() <= K) {
        cout << S << endl;
        return 0;
    }else{
        S.erase(S.begin()+K, S.end());
        S += "...";
        cout << S << endl;
        return 0;
    }
}


Measured memory_bytes: 3636
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
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 (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール

// 処理内容
int main() {
    
    ll n; cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    vector<ll> imos(n+1, 0);
    REP(i, n) imos[i+1] = imos[i] + a[i];

    ll ans = INF;
    RANGE(rb, 2, n-2) {

        const ll pq = imos[rb];
        const ll rs = imos[n] - imos[rb];

        const auto qb0 = upper_bound(imos.begin(), imos.begin() + rb, pq/2);
        const auto qb1 = qb0 - 1;
        const auto qbitr = abs(pq - *qb0 * 2) <= abs(pq - *qb1 * 2) ? qb0 : qb1;
        const ll qb = qbitr - imos.begin();

        const auto sb0 = upper_bound(imos.begin() + rb, imos.end(), pq + rs/2);
        const auto sb1 = sb0 - 1;
        const auto sbitr = abs(rs - (*sb0 - imos[rb]) * 2) <= abs(rs - (*sb1 - imos[rb]) * 2) ? sb0 : sb1;
        const ll sb = sbitr - imos.begin();

        const ll p = imos[qb];
        const ll q = imos[rb] - imos[qb];
        const ll r = imos[sb] - imos[rb];
        const ll s = imos[n ] - imos[sb];
        
        const ll diff = max({p, q, r, s}) - min({p, q, r, s});
        chmin(ans, diff);
        
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3328
//https://ykmaku.hatenablog.com/entry/2018/08/30/181652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const ll MAXN = 8020;
string s;
int x, y;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> s;
    cin >> x >> y;

    vector<int> t;
    int cnt = 0;
    //文字列を変形する
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'T')
        {
            if (cnt != 0)
                t.push_back(cnt);
            t.push_back(0);
            cnt = 0;
        }
        else
        {
            cnt++;
            if (i == s.size() - 1)
                t.push_back(cnt);
        }
    }

    bool dp_x[MAXN][MAXN * 2] = {false}, dp_y[MAXN][MAXN * 2] = {false};
    dp_x[0][8000] = true;
    dp_y[0][8000] = true;

    bool flag = false;
    bool xy = true; // trueならx軸について見ている
    int cnt_x = 0, cnt_y = 0;

    for (int i = 0; i < t.size(); i++)
    {
        if (t[i] == 0)
        {
            xy = !xy;
        }
        else if (xy)
        {
            cnt_x++;
            for (int j = 0; j < MAXN * 2; j++)
            {
                if (dp_x[cnt_x - 1][j])
                {
                    if (j + t[i] < MAXN * 2)
                        dp_x[cnt_x][j + t[i]] = true;
                    if (j - t[i] >= 0 && flag)
                        dp_x[cnt_x][j - t[i]] = true;
                }
            }
        }
        else if (!xy)
        {
            cnt_y++;
            for (int j = 0; j < MAXN * 2; j++)
            {
                if (dp_y[cnt_y - 1][j])
                {
                    if (j + t[i] < MAXN * 2)
                        dp_y[cnt_y][j + t[i]] = true;
                    if (j - t[i] >= 0)
                        dp_y[cnt_y][j - t[i]] = true;
                }
            }
        }

        if (!flag)
            flag = true;
    }

    cout << ((dp_x[cnt_x][x + 8000] && dp_y[cnt_y][y + 8000]) ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 251648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())

int main()
{
    int64_t a,b,c,k;
    cin >> a >> b >> c >> k;
    
    int64_t result = 0;
    result = min(a,k);
    k-=a;

    if(k>0) k-=b;
    if(k>0){
      result -= min(c,k);
    }

    cout << result << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, A, res;

int gcd(int x, int y) {
	if (x < y)swap(x, y);
	while (x%y) {
		x = x%y;
		swap(x, y);
	}
	return y;
}


int main() {
	cin >> N >> res;
	for (int i = 0; i != N - 1; ++i) {
		cin >> A;
		res = gcd(A, res);
	}
	cout << res << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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 ll MOD = 1e9+7;

vector<tuple<ll, ll, ll>> T;

int main(){
    ll N, Q;
    cin >> N >> Q;
    REP(i,N){
        ll s, t, x;
        scanf("%lld %lld %lld", &s, &t, &x);
        ll left, right;
        //[left, right)
        left = s - x;
        right = t - x;
        T.emplace_back(x, left, right);
    }

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

    set<ll> D;
    map<ll, ll> I;
    vector<ll> A(Q, -1);
    REP(i,Q){
        ll d;
        scanf("%lld", &d);
        D.insert(d);
        I[d] = i;
    }

    for(auto&& t : T){
        ll x, left, right;
        x = get<0>(t);
        left = get<1>(t);
        right = get<2>(t);
        auto iter0 = D.lower_bound(left);
        auto iter1 = D.lower_bound(right);
        for(auto iter = iter0; iter != iter1; iter++){
            ll val = *iter;
            A[I[val]] = x;
        }

        D.erase(iter0, iter1);
    }

    REP(i,Q){
        ll ans = A[i];
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 31340
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N, K;
  cin >> N >> K;
  vector<ll> X(N), Y(N), X0(N), Y0(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> X.at(i) >> Y.at(i);
    X0.at(i) = X.at(i), Y0.at(i) = Y.at(i);
  }
  sort(X0.begin(), X0.end());
  sort(Y0.begin(), Y0.end());

  ll ans = 5 * 1e18;
  for (ll i0 = 0; i0 < N; i0++)
  {
    for (ll i1 = i0 + 1; i1 < N; i1++)
    {
      for (ll j0 = 0; j0 < N; j0++)
      {
        for (ll j1 = j0 + 1; j1 < N; j1++)
        {
          ll x0 = X0.at(i0), x1 = X0.at(i1);
          ll y0 = Y0.at(j0), y1 = Y0.at(j1);

          ll tmp = (x1 - x0) * (y1 - y0);

          ll cnt = 0;
          for (ll k = 0; k < N; k++)
          {
            ll x = X.at(k), y = Y.at(k);
            if (x0 <= x && x <= x1 && y0 <= y && y <= y1)
              cnt++;
          }
          if (cnt >= K)
            chmin(ans, tmp);
        }
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    ld a, b; cin >> a >> b;
    ll res = (a*(b*1000))/1000;
    cout << res << endl;
}


Measured memory_bytes: 3696
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<assert.h>

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;
const int mod=1e9+7;

int qpow(int x,int y) {
	int ans=1;
	while (y) {
		if (y&1) ans=1LL*ans*x%mod;
		x=1LL*x*x%mod;y>>=1;
	}
	return ans;
}

int main()
{
	LL a,b,c,k;
	cin>>a>>b>>c>>k;
	cout<<(k&1?b-a:a-b)<<endl;
	return 0;
}


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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

const int INF = 2e9;

int n, res = INF;
string s;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> s;
    int ar = 0, bw = 0;
    for(auto i : s){
        ar += i == 'R';
    }
    ckmin(res, ar);
    ckmin(res, n - ar);
    // i is last white
    for(int i = 0; i < n; ++i){
        if(s[i] == 'R') ar--;
        else bw++;
        ckmin(res, max(ar, bw));
    }
    cout << res;
    return 0;
}

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

int main(){
  int n,maxi=0;
  int a[2][100];
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>a[0][i];
  }
  for(int i=0; i<n; i++){
    cin>>a[1][i];
  }

  for(int i=0; i<n; i++){
    int cnt=0;
    for(int j=0; j<=i; j++){
      cnt += a[0][j];
      //cout<<a[0][j];
    }
    for(int j=i; j<n; j++){
      cnt += a[1][j];
      //cout<<a[1][j];
    }
    //cout<<cnt<<endl;
    maxi = max(cnt,maxi);
  }
  cout<<maxi<<endl;
}

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

int main(){
  int sum = 0;
  string s;
  
  cin >> s;
  for(int i = 0; i < s.length(); i++){
    if(s[i] == '1'){
      sum += 1;
    }
  }
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

struct Data{
    long long A;
    long long B;
    
    bool operator<( const Data& right ) const {
        return A < right.A;
    }
};

int Func(){
    int x = 0;
    return x;
}

int main(){
    long long A, B;
    
    cin >> A >> B;
    
    long long C[40];
    
    long long temp1 = B-A+1;
    temp1 = temp1%4;
    long long tempA = A%4;
    if (tempA%2==0) {
        if (temp1==2 or temp1==3) C[0] = 1;
        else C[0] = 0;
    }
    else {
        if (temp1==1 or temp1==2) C[0] = 1;
        else C[0] = 0;
    }
    
    for (int i=1;i<=39;i++) {
        long long temp = B-A+1;
        long long a = 2*pow(2,i);
        long long b = pow(2,i);
        temp = temp%a;
        
        long long nextA = A%a;

        if (nextA<=b-1) {
            if (nextA+temp-1>=b and nextA+temp-1<=a-1) {
                C[i] = (nextA+temp-1-(b-1))%2;
            }
            else C[i] = 0;
        }
        else {
            if (nextA+temp-1>=b and nextA+temp-1<=a-1) {
                C[i] = temp%2;
            }
            else if (nextA+temp-1 >= a and nextA+temp-1 <= a+b-1) {
                C[i] = (a-1 - nextA + 1)%2;
            }
            else {
                C[i] = temp%2;
            }
        }
    }
    
    //for (int i=0;i<=39;i++) cout << C[i] << endl;
    
    long long result = 0;
    for (int i=0;i<=39;i++) {
        long long tempaa = pow(2,i);
        result += tempaa*C[i];
    }
    
    cout << result << endl;

    
    return 0;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		int count = Integer.parseInt(br.readLine());
		String[] line = br.readLine().split(" ");

		for (int i  = count-1; i >= 0; i--) {
			if(i != count -1){
				sb.append(" ");
			}
			sb.append(line[i]);
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 24492
def main():
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())
    ans = 0
    for i in range(a + 1):
        for j in range(b + 1):
            for k in range(c + 1):
                now_mony = 500 * i + 100 * j + 50 * k
                if now_mony > x:
                    break
                if now_mony == x:
                    ans += 1
    print(ans)




if __name__ == '__main__':
    main()


Measured memory_bytes: 39408
#include<bits/stdc++.h>
#define N (2505)
#define ll long long
#define itn int
#define scafn scanf
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define CM cerr<<(&MOP2-&MOP1)/1024.0/1024.0<<endl
using namespace std;
template <class T> inline T Min(T x, T y){
    return x<y?x:y;
}
template <class T> inline T Max(T x, T y){
    return x>y?x:y;
}
bool MOP1;
int n,m,p;
struct side{
	int to,val;
};
vector<side>G[N];
vector<int>E[N];
int dis[N];
bool mark[N],can[N];
int cnt[N];
int ans;
void spfa(){
	queue<int>q;
	q.push(1);
	for(int i=1;i<=n;i++)dis[i]=-1e9;
	dis[1]=0;
	mark[1]=1;
	cnt[1]=1;
	while(q.size()){
		int x=q.front();q.pop();
		mark[x]=0;
		for(int i=0;i<G[x].size();i++){
			int y=G[x][i].to,v=G[x][i].val;
			if(!can[y])continue;
			if(dis[x]+v>dis[y]){
				dis[y]=dis[x]+v;
				if(!mark[y]){
					mark[y]=1;
					cnt[y]++;
					if(cnt[y]==n){
						ans=-1;
						return ;
					}
					q.push(y);
				}
			}
		}
	}
	ans=Max(0,dis[n]);
	return ;
}
void dfs(int x){
	if(can[x])return;
	can[x]=1;
	for(int i=0;i<E[x].size();i++){
		int y=E[x][i];
		dfs(y);
	}
}
bool MOP2;
int main(){
	scanf("%d%d%d",&n,&m,&p);
	for(int i=1;i<=m;i++){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		G[x].push_back((side)<%y,z-p%>);
		E[y].push_back(x);
	}
	dfs(n);
	spfa();
//	for(int i=1;i<=n;i++)printf("%d ",cnt[i]);
	printf("%d\n",ans);
	return 0;
}






Measured memory_bytes: 640
#include<iostream>

using namespace::std;
#define int long long int
#define MOD 1000000007
int ar[22][22],dp[22][(1<<21)];

main(){
	ios_base::sync_with_stdio(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>ar[i][j];
	for(int i=n-1;i>-1;i--)
		for(int j=0;j<(1<<n);j++)
			if(__builtin_popcountll(j)==i)
				for(int k=0;k<n;k++)
					if(ar[i][k] && !(j&(1<<k)))
						dp[i][j]=(dp[i][j]+(i==n-1?1:dp[i+1][j|(1<<k)]))%MOD;

	cout<<dp[0][0]<<'\n';
}


Measured memory_bytes: 309504
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

#ネットワークフロー
#最大流,最小カット
import queue
class Dinic():
    #Dinic法,O(|E||V|**2) ※但し、実際にはもっと高速な動作

    def __init__(self, v, inf = 10**10):
        # v:頂点数
        # G:辺情報.各頂点に対し、[行き先,重み,(この辺を含めず)既に存在する行き先の辺数]
        # level:startからの距離(これはcapacityを考慮しない) bfsで毎回リセットされる
        # iter:各頂点について、どこまで調べ終わったかを記録する
        self.V = v
        self.inf = inf
        self.G = [[] for _ in range(v)]
        self.level = [0 for _ in range(v)]
        self.iter = [0 for _ in range(v)]

    def add_edge(self, from_, to, cap):
        # to: 行き先, cap: 容量, rev: 反対側の辺

        # 無向グラフの場合、G[to]の方のcapを0→capにする必要があるので注意.('rev'はそのままで良い)

        self.G[from_].append({'to':to, 'cap':cap, 'rev':len(self.G[to])})
        self.G[to].append({'to':from_, 'cap':0, 'rev':len(self.G[from_])-1})

        

    # sからの最短距離をbfsで計算
    def bfs(self, s):
        self.level = [-1 for _ in range(self.V)]
        self.level[s] = 0
        que = queue.Queue()
        que.put(s)
        while not que.empty():
            v = que.get()
            for i in range(len(self.G[v])):
                e = self.G[v][i]
                if e['cap'] > 0 and self.level[e['to']] < 0:
                    self.level[e['to']] = self.level[v] + 1
                    que.put(e['to'])

    # 増加パスをdfsで探す
    def dfs(self, v, t, f):
        if v == t: return f
        for i in range(self.iter[v], len(self.G[v])):
            self.iter[v] = i
            e = self.G[v][i]
            if e['cap'] > 0 and self.level[v] < self.level[e['to']]:
                d = self.dfs(e['to'], t, min(f, e['cap'])) # d:流量
                if d > 0:
                    e['cap'] -= d #使用済みの分だけcapから引く
                    self.G[e['to']][e['rev']]['cap'] += d
                    return d

        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s) #levelの更新
            # bfsでtに到達不可なら終了
            if self.level[t] < 0 : return flow
            #イテレータの初期化(イテレータ：各頂点に対し、どこまで調べ終わったか)
            self.iter = [0 for _ in range(self.V)]
            f = self.dfs(s, t, self.inf) #f:そのパスの流量
            while f > 0:
                flow += f
                f = self.dfs(s,t, self.inf)

v,e = map(int,readline().split())
V = v
network = Dinic(V)
for i in range(e):
    u,v,c = map(int,readline().split())
    network.add_edge(u,v,c)

print(network.max_flow(0,V-1))


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

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};

#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int n;

long long s;

vector <long long> wek[2];

int czy_pier(vector <long long> w)
{
	sort(w.begin(), w.end());
	if (w.back()==1)
		return 0;
	s=0;
	wek[0].clear();
	wek[1].clear();
	for (int i=0; i<w.size(); i++)
	{
		s+=(w[i]-1);
	}
	if (s&1)
		return 1;
	for (int i=1; i<=n; i++)
		wek[w[i]&1].push_back(w[i]);
	if (wek[1].size()>1)
		return 0;
	s=w[0];
	for (int i=0; i<w.size(); i++)
	{
		if (w[i]&1)
			w[i]--;
		s=__gcd(w[i], s);
	}
	for (int i=0; i<w.size(); i++)
		w[i]/=s;
	return (czy_pier(w)^1);
}

int main()
{
	scanf("%d", &n);
	vector <long long> start;
	for (int i=1; i<=n; i++)
	{
		long long p;
		scanf("%lld", &p);
		start.push_back(p);
	}
	if (czy_pier(start))
		printf("First\n");
	else
		printf("Second\n");
	return 0;
}


Measured memory_bytes: 20724
from collections import deque

n, m = map(int, input().split())
road = [[] for _ in range(n)]
flag = [-1 for _ in range(n)]

for i in range(m):
  a, b = map(int, input().split())
  road[a-1].append(b-1)
  road[b-1].append(a-1)

count = 0

for k in range(n):
  if(flag[k] != -1):
    continue
  
  count += 1
  queue = deque([k])
  while queue:
    now = queue.popleft()
    flag[now] = count
    for i in road[now]:
      if(flag[i] == -1):
        queue.append(i)
  
print(count-1)
  

Measured memory_bytes: 27244
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n = int(input())
    s = []
    for _ in range(n):
        a = input()
        s.append(a)
    s.sort()
    cnt = 1
    for i in range(n-1):
        if s[i] != s[i+1]:
            cnt += 1
    print(cnt)
if __name__ == '__main__':
    main()


Measured memory_bytes: 23992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(100001);
	int x,ans=0;
	rep(i,n){
		cin >> x;
		if(x>100000) ans++;
		else a[x]++;
	}
	rep(i,100001){
		if(a[i]!=0){
			if(a[i]>i) ans+=a[i]-i;
			else if(a[i]<i) ans+=a[i];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
implicit none

integer :: n, y
integer :: i, j, k

read *, n, y

y = y / 1000

do i = 0, n
   do j = 0, n-i
      k = n - i - j
      if (i*10 + j*5 + k == y) then
         write(6,'(i0,1x,i0,1x,i0)') i,j,k
         stop
      endif
   enddo
enddo

write(6,'(a)') '-1 -1 -1'
end

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

//BIT
struct BIT{
	int N;
	int data[300010];
	void init(int n){
		N = n;
		fill(data,data+N+1,0);
	}
void add(int a,int w){
	for(int x = a;x <= N;x += x & -x) data[x] +=w;
}
//bit[1] + ... + bit[a]
int sum(int a){
	int ret = 0;
	for(int x = a; x > 0; x -= x & -x) ret+= data[x];
	return ret;
}
};

/*BIT 0~n-1ver
void add(int a,int w){
	for(int x = a;x < N; x |= x + 1) bit[x] += w;
	}
}
int sum(int a){
	int ret = 0;
	for(int x = a-1;x >= 0; x = (x & (x+1)) - 1)ret += bit[x];
	return ret;
	}*/

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	BIT bit;
	int n,q;
	cin >> n >> q;
	bit.init(n);
	REP(i,q){
		int com,x,y;
		cin >> com >> x >> y;
		if(com) cout << bit.sum(y)-bit.sum(x-1) << endl;
		else bit.add(x,y);
	}
	
  return 0;
}

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

namespace _0015
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                BigInteger num1 = BigInteger.Parse(Console.ReadLine());
                BigInteger num2 = BigInteger.Parse(Console.ReadLine());
                BigInteger ans = num1 + num2;

                if (ans.ToString().Length <= 80 && num1.ToString().Length <= 80 && num2.ToString().Length <= 80)
                {
                    Console.WriteLine(ans);
                }
                else
                {
                    Console.WriteLine("overflow");
                }
            }

        }
    }
}



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

const int INF = 1001001001;
const int mod = 1000000007;

ll pow(ll base, ll order) {
	ll ans = 1;
	rep(i,order - 1) ans *= base;
	return ans;
}

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

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

	string ans = "hon";
	if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) {
		ans = "pon";
	}
	else if (n % 10 == 3) {
		ans = "bon";
	}
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 3596
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Debug.Trace
-- trace _ = id

black :: Int
black = 0
white :: Int
white = 1

solve :: Int -> [(Int,Int)] -> Int
solve bN xys = theFunc (black,1) `mAdd` theFunc (white,1)
  where

  children = vCreate (bN+1) [] act

  act vec = do
    forM_ xys $ \(x,y) -> do
      VM.modify vec (x:) y
      VM.modify vec (y:) x
    mkRt 1 (-1)
    return vec
      
      where
      mkRt j parent = do
        cs <- VM.read vec j
        let newCs = filter (/= parent) cs
        VM.write vec j newCs
        forM_ newCs $ \c -> mkRt c j

  enc (color, i) = color * (bN+1) + i

  theFunc = func_memo enc (memovec enc (2*(bN+1)) mf [(black,1), (white,1)])

  mf rc (color,i)
    | color == black = mProdM [rc (white, j) | j <- cldrn]
    | color == white = mProdM [mAdd <$> rc (white, j) <*> rc (black, j)
                              | j <- cldrn]
    where cldrn = children V.! i
                     
vCreate :: Int -> a ->
           (forall s. VM.MVector s a -> ST s (VM.MVector s a)) ->
           V.Vector a
vCreate n init act = V.create $ do
  vec <- VM.replicate n init
  act vec
  return vec

mPrime = 10^9 + 7

mAdd :: Int -> Int -> Int
mAdd x y = let w = x + y in if w < mPrime then w else w - mPrime

mMul :: Int -> Int -> Int
mMul x y = (x * y) `mod` mPrime

mProdM :: Monad m => [m Int] -> m Int
mProdM mxs = sub 1 mxs where
  sub !acc [] = return acc
  sub !acc (mx:mxs) = do
    x <- mx
    sub (acc `mMul` x) mxs

memovec :: forall a d. (VU.Unbox a, Show a, Show d) =>
           (d -> Int) -> Int -> 
           (forall m. Monad m => (d -> m a) -> d -> m a) ->
           [d] -> VU.Vector a
memovec encode size mf ds = VU.create $ do
  vec <- VUM.new size
  flags <- VUM.replicate size False
  mapM_ (calc vec flags) ds
  return vec
  where
    calc vec flags d = do
      fv <- VUM.read flags (encode d)
      if fv then VUM.read vec (encode d)
        else do
        val <- mf (calc vec flags) d
        VUM.write vec   (encode d) val
        VUM.write flags (encode d) True
        return val

func_memo :: VU.Unbox a => (d->Int) -> VU.Vector a -> d -> a
func_memo encode vecV d = vecV VU.! (encode d)

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_bN]:remLines1 = remLines0
      bN = readBInt bs_bN
      xys = map (\[x1,x2] -> (readBInt x1,readBInt x2)) remLines1
  in solve bN xys

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 45180
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct L
{
	set<int> sset;
	int p;
	L(int p) :p(p) {}
	L() :L(0) {}
};

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

	int N, M, K, S;
	L Ls[11];

	cin >> N >> M;
	rep(i, 0, M)
	{
		cin >> K;
		rep(j, 0, K)
		{
			cin >> S;
			Ls[i].sset.insert(S);
		}
	}

	rep(i, 0, M)
	{
		cin >> Ls[i].p;
	}

	int num[11] = { 0 };
	int ans = 0;
	rep(i, 0, 1LL << N)
	{
		fill(num, num + M, 0);
		rep(j, 0, N)
		{
			if (i&(1LL << j))
			{
				rep(k, 0, M)
				{
					if (Ls[k].sset.count(j + 1) > 0)
					{
						num[k]++;
					}
				}
			}
		}
		bool ok = true;
		rep(j, 0, M)
		{
			if (num[j] % 2 != Ls[j].p)
			{
				ok = false;
				break;
			}
		}
		if (ok)
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a[100000];
pair<int,int>c[100000];
int now=0,top=0;

void NP(){
	int i=top-2;
	while(true){
		if(c[i].first<c[i+1].first)break;
		int tmp=c[i].first;
		c[i].first=c[i+1].first;
		c[i+1].first=tmp;
		tmp=c[i].second;
		c[i].second=c[i+1].second;
		c[i+1].second=tmp;
		if(i==now)break;
		i--;
	}
}
int main(){
    int n,l;
    cin>>n>>l;
    for(int i=0;i<n;i++){
        cin>>a[i];
	}
    if(a[0]>a[1]){
        c[top].first=l-a[0];
        c[top].second=0;
        top++;
		NP();
    }
    for(int i=1;i<n-1;i++){
        if(a[i-1]<a[i]&&a[i]>a[i+1]){
            c[top].first=l-a[i];
            c[top].second=i;
            top++;
			NP();
        }
    }
    if(a[n-1]>a[n-2]){
        c[top].first=l-a[n-1];
        c[top].second=n-1;
        top++;
		NP();
    }
    sort(c,c+top);
    while(now<top){
        //cout<<"#"<<c[now].first<<" "<<c[now].second<<endl;
        int clear=c[now].second;
        a[clear]=0;
        if(clear==0){
            if(a[1]>0){
                c[top].first=l-a[1]+c[now].first;
                c[top].second=1;
                top++;
				NP();
            }
        }
        if(clear>0&&clear<n-1){
            if(clear==1){
                if(a[0]>0){
                c[top].first=l-a[0]+c[now].first;
                c[top].second=0;
                top++;
				NP();
                }
                if(a[2]>a[3]){
                c[top].first=l-a[2]+c[now].first;
                c[top].second=2;
                top++;
				NP();
                }
            }
            else if(clear==n-2){
                if(a[n-1]>0){
                c[top].first=l-a[n-1]+c[now].first;
                c[top].second=n-1;
                top++;
				NP();
                }
                if(a[n-3]>a[n-4]){
                c[top].first=l-a[n-3]+c[now].first;
                c[top].second=n-3;
                top++;
				NP();
                }
            }
            else{
                if(a[clear-1]>a[clear-2]){
                c[top].first=l-a[clear-1]+c[now].first;
                c[top].second=clear-1;
                top++;
				NP();
                }
                if(a[clear+1]>a[clear+2]){
                c[top].first=l-a[clear+1]+c[now].first;
                c[top].second=clear+1;
                top++;
				NP();
                }
            }
        }
        if(clear==n-1){
            if(a[n-2]>0){
                c[top].first=l-a[n-2]+c[now].first;
                c[top].second=n-2;
                top++;
				NP();
            }
        }

        //sort(c+now,c+top);
        now++;
    }
    cout<<c[top-1].first<<endl;
    return 0;
}

Measured memory_bytes: 2336
#include <cstdio>


int main()
{
	int n,m;
	scanf("%d %d", &n, &m);

	int a[n][m] = {0};
	int b[m] = {0};
	int c[n] = {0};

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

	for (int i = 0; i < m; i++)
		scanf("%d", &b[i]);

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			c[i] += a[i][j] * b[j];
		}
	}

	for (int i = 0; i < n; i++)
		printf("%d\n", c[i]);

	return 0;
}


Measured memory_bytes: 2732