akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int main() {
  ll r, D, sx;
  while(input(r,D,sx)) {
    ll x = sx;
    REP(i,10) {
      x = r * x - D;
      cout << x << endl;
    }
  }
}


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

using namespace std;

int main()
{
    int n;
    while(cin >> n, n)
    {
        int a[n];
        for(int i=0; i<n; i++)
        {
            cin >> a[i];
        }
        sort(a, a+n);
        int min_dif = 10000000;
        for(int i=1; i<n; i++)
        {
            int d = a[i] - a[i-1];
            if(d<0) d = -d;
            min_dif = min(min_dif, d);
        }
        cout << min_dif << endl;
    }
}

Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
 
int main(){
    int d;
    long long g;
    cin>>d>>g;
    int ans=0;
    vector<long long> p(d),c(d);
    for (int i=0; i<d; i++){
        cin>>p[i];
        cin>>c[i];
        ans+=p[i];
    }
    for (int bit=0;bit< (1<<d) ;bit++){
        vector<bool> s(d,false);
        for (int i=0; i<d ; i++){
            if(bit & (1<<i)){
                s[i]=true;
            }
        }
        long long sum=0;
        int prob=0;
        for (int i=0; i<d; i++){
            if(s[i]){
                sum+=100*(i+1)*p[i]+c[i];
                prob+=p[i];
            }
        }
        if(sum>=g)ans=min(ans,prob);
        else{
            for (int j=d-1; j>=0; j--){
                if(s[j])continue;
                for (int k=0; k<p[j]; k++){
                    if(sum>=g)break;
                    sum+=100*(j+1);
                    prob++;
                    }
                }
                ans=min(ans,prob);
            }

    }
    cout<<ans;
    return 0;
}

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

LL inf = 1000000000000;
LL mod = 1000000007;

int main()
{
	vector<LL> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.end());

	if ((a[0] != a[2]) && (a[0] == a[1] || a[1] == a[2])) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

	
}

Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()

    # (距離, 接する頂点)の情報を持つ有向グラフのデータを生成
    graph = [[] for _ in range(N)]
    for _ in range(N):
        v1, k, *vertices = il()
        for idx in range(0, k * 2, 2):
            v2, c = vertices[idx:idx + 2]
            graph[v1].append((c, v2))

    # ダイクストラ法
    dist = [INF] * N    # 各頂点までの距離を保持する配列
    dist[0] = 0         # 開始始点の頂点は距離をゼロとする
    visited = [0] * N   # 各頂点の訪問状態を保持する配列[0: 未訪問, 1: 訪問済み]
    heap = [(0, 0)]     # 距離と始点頂点（自分自身への移動距離はゼロ）
    heapq.heapify(heap) # 距離と頂点の情報を距離で優先度付きキューとする
    while heap:
        # 頂点uとuに到達するまでの距離
        min_cost, u = heapq.heappop(heap)

        # さらに小さい距離で既に到達済みの場合はcontinue
        if dist[u] < min_cost: continue
        visited[u] = 1  # 頂点uを訪問済みにする

        # グラフの情報から接する頂点と移動距離を順に処理
        for cost, v in graph[u]:
            if visited[v] != 1:
                if dist[u] + cost < dist[v]:
                    # 未到達かつ小さい距離で移動できる場合には
                    # 距離の更新と優先度付きキューに(距離, 頂点)の情報を追加
                    dist[v] = dist[u] + cost
                    heapq.heappush(heap, (dist[v], v))
    # 回答
    for n in range(N):
        print(n, dist[n])


if __name__ == '__main__':
    main()



Measured memory_bytes: 69192
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M, Q;
  cin >> N >> M >> Q;
  vector<int> L(M), R(M);
  // グリッド
  vector<vector<int>> a(N, vector<int>(N));
  for (int i = 0; i < M; i++)
  {
    cin >> L[i] >> R[i];
    L[i]--, R[i]--;
    a[L[i]][R[i]]++;
  }

  cerr << "grid" << endl;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      cerr << a[i][j] << " ";
    }
    cerr << endl;
  }

  // 二次元累積和の構築
  vector<vector<int>> s(N + 1, vector<int>(N + 1));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      s[i + 1][j + 1] = s[i][j + 1] + s[i + 1][j] - s[i][j] + a[i][j];
    }
  }

  cerr << "sum" << endl;
  for (int i = 0; i < N + 1; i++)
  {
    for (int j = 0; j < N + 1; j++)
    {
      cerr << s[i][j] << " ";
    }
    cerr << endl;
  }

  // 各クエリの計算((x1, x2], * (y1, y2]の長方形区間の和)
  for (int i = 0; i < Q; i++)
  {
    int p, q;
    cin >> p >> q;
    p--, q--;
    cout << s[q + 1][q + 1] - s[p][q + 1] - s[q + 1][p] + s[p][p] << endl;
  }
}

Measured memory_bytes: 4480
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <list>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <numeric>
#include <cmath>
#include <memory.h>
#include <sstream>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef pair<ll, int> pli;
typedef vector<vector<int>> vvi;

#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-8

int main() {
    int n;
    cin >> n;
    unordered_map<int, int> cnt;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        ++cnt[a];
        if (cnt.size() > 2) {
            cout << "No";
            return 0;
        }
    }

    if (cnt.size() == 1) {
        int val = (*cnt.begin()).first;
        if (2 * val <= n || val == n - 1) {
            cout << "Yes";
        } else {
            cout << "No";
        }
    } else {
        int a = (*cnt.begin()).first, na = (*cnt.begin()).second;
        int b = (*(next(cnt.begin()))).first, nb = (*(next(cnt.begin()))).second;
        if (a > b) {
            swap(a, b);
            swap(na, nb);
        }
        if (b - a > 1 || b <= na) {
            cout << "No";
            return 0;
        }
        b -= na;
        if (2 * b <= nb) {
            cout << "Yes";
        } else {
            cout << "No";
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

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

	ll m = 0;;
	for (int i = 1; i*i <= N; i++) {
		if (i*i <= N) {
			m = i * i;
		}
	}
	cout << m << endl;

	return 0;
}

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

long long inf = 1e15;


int main() {

    long long n;
    cin >> n;

    long long ans = inf;
    for(long long i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            long long a = i;
            long long b = n / a;
            long long res = a + b - 2;
            if(res < ans) ans = res;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
using namespace std;

string S, T;
long long N;

int main() {
	cin >> S;
	cin >> T;
	string U = "abcdefghijklmnopqrstuvwxyz";
	int idx[28] = {};
	int idx2[28] = {};
	N = S.length();
	int n;

	bool flag = true;
	for (int i = 0; i < N; i++) {
		n = U.find(S[i])+1;
		if (idx[n] == 0) {
			idx[n] = U.find(T[i])+1;
		}
		else if (idx[n] != (U.find(T[i]) + 1)) {
			flag = false;
			break;
		}
		n = U.find(T[i]) + 1;
		if (idx2[n] == 0) {
			idx2[n] = U.find(S[i]) + 1;
		}
		else if (idx2[n] != (U.find(S[i]) + 1)) {
			flag = false;
			break;
		}
	}

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

Measured memory_bytes: 776
#include <iostream>
#include<cstdio>
#include<queue>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=1e7+5;

int main()
{int n,d;
cin>>n>>d;
int ans=n/(2*d+1);
if((n%(2*d+1))!=0) ans++;
cout<<ans<<endl;

    return 0;
}

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

Q=[]
import math
for i in range(10000):
    if H>1:
        H=H//2
        Q.append(H)
    elif H==1:
        break
Q.sort()
S=0
a=1
for i in range(len(Q)):
    a=2*a+1
print(a)

Measured memory_bytes: 9172
x,y=map(int,input().split())

ans =0

if 0<x and x<y:
    ans=abs(y) - abs(x)
elif x==-y:
    ans =1
elif x==0 and x<y:
    ans =abs(y) - abs(x)    
elif x<0 and 0<y and (abs(x) < abs(y)):
    ans = 1 + abs(y) - abs(x)
elif x<0 and 0<y and (abs(x) > abs(y)):
    ans = 1 + abs(x) - abs(y)
elif x<y and y<0:
    ans = abs(x) - abs(y)
elif x<y and y==0:
    ans = abs(x) - abs(y)
elif 0<y and y<x:
    ans = 2 + abs(x) - abs(y)
elif y==0 and y<x:
    ans = 1 + abs(x) - abs(y)
elif y<0 and 0<x and (abs(x) > abs(y)):
    ans = 1 + abs(x) - abs(y)
elif y<0 and 0<x and (abs(x) < abs(y)):
    ans = 1 + abs(y) - abs(x)
elif y<x and x<0:
    ans = 2 + abs(y) - abs(x)
elif y<x and x==0:
    ans = 1 + abs(y)
print(ans)


Measured memory_bytes: 3064
import itertools

N, M, X = map(int, input().split())
ca = []
for _ in range(N):
  ca.append(list(map(int, input().split())))
  
ns = [i for i in range(N)]
price = 1000000000000
for r in range(1,N+1):
  for v in itertools.combinations(ns, r):
    flag = True
    for j in range(M):
      s = sum([ca[i][j+1] for i in v])
      if s < X:
        flag = False
        continue
    if flag:
      p = sum([ca[i][0] for i in v])
      price = min(price, p)
      
if price == 1000000000000:
  print(-1)
else:
  print(price)

Measured memory_bytes: 9228
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int k = Integer.parseInt(sc.next());
        int t = Integer.parseInt(sc.next());

        int[] a = new int[t];
        PriorityQueue<Integer> queue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer t0, Integer t1) {
                return t1-t0;
            }
        });
        for(int i=0;i<t;i++){
            a[i] = Integer.parseInt(sc.next());
            queue.add(a[i]);
        }
        Integer big,small;
        while(queue.size() > 1){
            big = queue.poll();
            small = queue.poll();
            if(big-small > 0)queue.add(big-small);
        }
        if(queue.size() > 0){
            System.out.println(queue.poll()-1);
        }else{
            System.out.println(0);
        }
        


    }
}


Measured memory_bytes: 21844
n,m=map(int,input().split())
x=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    x[a-1].append(b-1)
    x[b-1].append(a-1)

def size0find():
    global x,n
    next=[]
    for i in range(n):
        if len(x[i])==1:
            next.append(i)
            k=x[i][0]
            x[i].remove(k)
            x[k].remove(i)
    return next

cnt=0
while True:
    y=size0find()
    l=len(y)
    if l==0:
        break
    cnt+=l
print(cnt)


Measured memory_bytes: 3064
/*{{{*/
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>

using namespace             std;
typedef long long           ll;
typedef unsigned long long  ull;
typedef pair<ll, ll>        P;
const double                PIE = 3.141592;

#define rep_n(i, a, b)  for (int i=a; i<b; i++)
#define rep(i, n)       rep_n(i, 0, n)
#define all(v)          (v).begin(), (v).end()
#define item(v)         sizeof(v)/sizeof(v[0])
#define tov(v)          v, v+item(v)
#define mp(x, y)        make_pair(x, y)
#define mset(x, y)      memset(x, y, sizeof(x))
#define chmin(x,y)      (x=min(x, y))
#define chmax(x,y)      (x=max(x, y))
#define SORTI(v)        sort(v, v+item(v))
#define SORT(v)         sort(d.begin(), d.end());
#define UNIQUE(x)       x.erase(unique(all(x)), x.end())
#define ins(x, y, z)    x.insert(x.begin()+y, z)
#define era(x, y)       x.erase(x.begin()+y)
#define era1(x, y, z)   x.erase(x.begin()+y, x.begin()+z)
#define COUNT(x, y)     count(all(x), y)
#define FIND(x, y)      find(all(x), y) - x.begin()
#define BIT(x, y)       (x>>y&1)

#define ci1(a)          cin>>a 
#define ci2(a, b)       cin>>a>>b
#define ci3(a, b, c)    cin>>a>>b>>c
#define ci4(a, b, c, d) cin>>a>>b>>c>>d
#define co1(a)          cout<<a<<endl;
#define co2(a, b)       cout<<a<<" "<<b<<endl;
#define co3(a, b, c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define co4(a, b, c, d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
/*}}}*/

ll x, y, z, ans;
vector<ll> v;

int main() {
    ci2(x, y);

    ans=(1900*y+100*(x-y)) * pow(2, y);

    co1(ans);

}

///*debug*/co1();


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep2(i,x,y) for (int i = x; i < (y); ++i)
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
int INF = 100100101;
int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  int n, k;
  cin>>n>>k;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  sort(a.begin(),a.end());
  int ans = 0;
  rep(i,k) ans += a[i];
  cout << ans << endl;
  return 0;
}

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

int main() {

  int a = 0;
  int b = 0;

  cin >> a;
  cin >> b;

  if ( a % 2 == 0 || b % 2 == 0) {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }

}



Measured memory_bytes: 3516
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define lowbit(x) (x& -x)
#define inf 0x3f3f3f3f
#define eps 1e-18
#define maxn 2000010
inline ll read(){ll tmp=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-'0'; return tmp*f;}
inline ll power(ll a,ll b){ll ans=1; for(;b;b>>=1){if(b&1)ans=ans*a%mod; a=a*a%mod;} return ans;}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void swap(int &a,int &b){int tmp=a; a=b; b=tmp;}
using namespace std;
int main()
{
	int n=read(),ans=0;
	for(int i=1;i<=n;i+=2){
		int cnt=0;
		for(int j=1;j<=i;j++)
			if(i%j==0)++cnt;
		if(cnt==8)++ans;
	}
	printf("%d\n",ans);
}

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

template <typename T>
struct ReRooting
{
  using F = function<T(T, int)>;
  using F2 = function<T(T, T)>;
  static const int MAX_V = 200010;
  int V;
  vector<int> E[MAX_V];
  vector<T> dp[MAX_V];
  //f(v) = g(merge(f(dp_c1,c1), f(dp_c2,c2), ..., f(dp_ck,ck)) , v)
  F f, g;
  F2 merge;
  T mi; //identity of merge

  ReRooting(int V_, F f_, F2 merge_, T mi_, F g_ = [](T a, T b) { return a; })
      : V(V_), f(f_), merge(merge_), mi(mi_), g(g_) {}

  void add_E(int a, int b)
  {
    E[a].push_back(b);
    E[b].push_back(a);
  }

  T dfs1(int p, int v)
  {
    T res = mi;
    for (int i = 0; i < E[v].size(); ++i)
    {
      if (E[v][i] == p)
        continue;
      dp[v][i] = dfs1(v, E[v][i]);
      res = merge(res, f(dp[v][i], E[v][i]));
    }
    return g(res, v);
  }

  void dfs2(int p, int v, T add)
  {
    for (int i = 0; i < E[v].size(); ++i)
    {
      if (E[v][i] == p)
      {
        dp[v][i] = add;
        break;
      }
    }

    vector<T> pL(E[v].size() + 1), pR(E[v].size() + 1);
    pL[0] = mi;
    for (int i = 0; i < E[v].size(); ++i)
      pL[i + 1] = merge(pL[i], f(dp[v][i], E[v][i]));
    pR[E[v].size()] = mi;
    for (int i = E[v].size(); i > 0; --i)
      pR[i - 1] = merge(pR[i], f(dp[v][i - 1], E[v][i - 1]));

    for (int i = 0; i < E[v].size(); ++i)
    {
      if (E[v][i] == p)
        continue;
      T val = merge(pL[i], pR[i + 1]);
      dfs2(v, E[v][i], g(val, v));
    }
  }

  void calc(int root = 0)
  {
    for (int i = 0; i < V; ++i)
      dp[i].resize(E[i].size());
    dfs1(-1, root);
    dfs2(-1, root, mi);
  }

  T solve(int v)
  {
    T ans = mi;
    for (int i = 0; i < E[v].size(); ++i)
    {
      ans = merge(ans, f(dp[v][i], E[v][i]));
    }
    return g(ans, v);
  }
};

int main()
{
  int n, m;
  cin >> n >> m;
  auto f = [&](long long a, int v) {
    (void)v;
    return (a + 1) % m;
  };
  auto merge = [&](long long a, long long b) {
    return a * b % m;
  };
  ReRooting<long long> re(n, f, merge, 1);
  for (int i = 0; i < n - 1; ++i)
  {
    int x, y;
    cin >> x >> y;
    x--, y--;
    re.add_E(x, y);
  }
  re.calc();
  for (int i = 0; i < n; ++i)
    cout << re.solve(i) << endl;
  return 0;
}

Measured memory_bytes: 38528
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, res, vis[200];
bool b[200][200];


int main() {
	cin >> N;
	res = -1;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			char c;
			cin >> c;
			b[i][j] = (c == '1');
		}
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			vis[j] = 0;
		}
		int c = 0;
		queue<int>q;
		q.push(i);
		bool f = false;
		while (!q.empty()) {
			queue<int>r;
			++c;
			while (!q.empty()) {
				int x = q.front();
				q.pop();
				if (vis[x] == c)continue;
				if (vis[x] != 0) {
					f = true;
					break;
				}
				else {
					vis[x] = c;
					for (int j = 0; j < N; ++j) {
						if (b[x][j] && !vis[j]) {
							r.push(j);
						}
					}
				}
			}
			if (f)break;
			q = r;
		}
		if (!f) {
			res = max(res, c);
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 500
#include <algorithm>
#include <chrono>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef long long Int;

#define KIND 26
//#define KIND 2
Int D;
Int c[KIND];
Int s[400][KIND];
Int last[KIND];

std::chrono::time_point<std::chrono::steady_clock> start;

Int range(Int l, Int r)
{
    Int len = r - l - 1;
    return -len * (len + 1) / 2;
}

void tic()
{
    start = std::chrono::steady_clock::now();
}

double toc()
{
    auto now = std::chrono::steady_clock::now();
    std::chrono::duration<double> duration = now - start;
    return duration.count();
}

struct ContestInfo {
    set<Int> held[KIND];
    vector<Int> t;
    int D;
    Int score = 0;
    ContestInfo(int D) : D(D)
    {
        t.resize(D, -1);
        for (int i = 0; i < KIND; i++) {
            held[i].insert(-1);
            held[i].insert(D);
            score += c[i] * range(-1, D);
        }
    }

    void add(int d, int q)
    {
        if (t[d] != -1) {
            cout << "Add failed" << endl;
            exit(1);
        }
        t[d] = q;
        score += s[d][q];
        held[q].insert(d);
        auto it = held[q].find(d);
        auto rit = next(it);
        auto lit = prev(it);
        score -= c[q] * range(*lit, *rit);
        score += c[q] * range(*it, *rit);
        score += c[q] * range(*lit, *it);
    }

    void erase(int d)
    {
        if (t[d] == -1) {
            cout << "erase failed" << endl;
            exit(1);
        }
        int q = t[d];
        t[d] = -1;
        score -= s[d][q];
        auto it = held[q].find(d);
        auto rit = next(it);
        auto lit = prev(it);
        score += c[q] * range(*lit, *rit);
        score -= c[q] * range(*it, *rit);
        score -= c[q] * range(*lit, *it);
        held[q].erase(it);
    }

    void change(int d, int q)
    {
        erase(d);
        add(d, q);
    }

    void output()
    {
        for (int i = 0; i < D; i++) {
            cout << t[i] + 1 << endl;
        }
    }
};

Int calc_score(vector<Int> t)
{
    Int score = 0;
    fill(last, last + 26, -1);
    for (int d = 0; d < D; d++) {
        score += s[d][t[d]];
        last[t[d]] = d;
        for (int i = 0; i < KIND; i++) {
            score -= c[i] * (d - last[i]);
        }
        // cout << score << endl;
    }
    return score;
}

int main()
{
    tic();
    cin >> D;
    for (Int i = 0; i < KIND; i++) {
        cin >> c[i];
    }
    for (Int d = 0; d < D; d++) {
        for (Int i = 0; i < KIND; i++) {
            cin >> s[d][i];
        }
    }

    ContestInfo ci(D);

    for (int d = 0; d < D; d++) {
        Int t;
        t = rand() % KIND;
        ci.add(d, t);
    }
    Int current_score = ci.score;

    while (toc() < 1.9) {
        Int d, q;
        d = rand() % D;
        q = rand() % KIND;
        int old = ci.t[d];
        ci.change(d, q);
        Int new_score = ci.score;
        if (new_score < current_score) {
            ci.change(d, old);
        }
        else {
            current_score = new_score;
        }
        current_score = new_score;
    }
    ci.output();
    return 0;
}

Measured memory_bytes: 3300
# -*- coding: utf-8 -*-
# input
# 配列のinput
n = int(input())
temp_array = []
addlist = temp_array.append
for i in range(n):
    addlist(input())
print('AC x '+str(temp_array.count('AC')))
print('WA x '+str(temp_array.count('WA')))
print('TLE x '+str(temp_array.count('TLE')))
print('RE x '+str(temp_array.count('RE')))

Measured memory_bytes: 16248
a1,a2,a3 = gets.split.map(&:to_i)
a4,a5,a6 = gets.split.map(&:to_i)
a7,a8,a9 = gets.split.map(&:to_i)
n = gets.to_i
b = []
a = n.times.map{gets.to_i}
bingo = [[a1,a2,a3],[a4,a5,a6],[a7,a8,a9],[a1,a4,a7],[a2,a5,a8],[a3,a6,a9],[a1,a5,a9],[a3,a5,a7]]
bingo.each do |array|
  b << "Yes" if (array&a).size == 3
end
if b.size == 0
  puts "No"
else
  puts "Yes"
end

Measured memory_bytes: 1788
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

     static Scanner scanner;

     public static void main(String[] args) {
         scanner = new Scanner(System.in);

         int N=gi();
         int K=gi();
         long[] v=new long[N];

         for(int i=0; i<N;i++) {
        	 v[i]=gl();
         }

         long max=0;

         for(int i=0; i<=Math.min(N, K);i++) {
        	 for (int j=0; j<=i;j++) {
        		 long tmp=0;
        	     List<Long> ml=new ArrayList<Long>();
        	     for(int k=0; k<j;k++) {
        	    	 if(v[k]>=0) {
        	    		 tmp+=v[k];
        	    	 } else {
        	    		 ml.add(v[k]);
        	    	 }
        	     }

        	     for(int k=0; k<i-j;k++) {
        	    	 if(v[N-1-k]>=0) {
        	    		 tmp+=v[N-1-k];
        	    	 } else {
        	    		 ml.add(v[N-1-k]);
        	    	 }
        	     }
        	     Collections.sort(ml);
        	     for(int k=K-i; k<ml.size();k++) {
        	    	 tmp+=ml.get(k);
        	     }
        	     max=Math.max(max, tmp);
        	 }
         }

         System.out.print(max);
     }

     public static class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> implements Comparable<Pair<K, V>> {
    		/** serialVersionUID. */
    	    private static final long serialVersionUID = 6411527075103472113L;

    	    public Pair(final K key, final V value) {
    	        super(key, value);
    	    }

    		@Override
    		public int compareTo(Pair<K, V> o) {

    			Comparable key = (Comparable)this.getKey();
    			Comparable key2 = (Comparable)o.getKey();

    			return key.compareTo(key2);
    		}

    	}

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 38812
N = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(N - 1):
    if a[i] - 1 == i:
        a[i], a[i + 1] = a[i + 1], a[i]
        cnt += 1
if a[N - 1] - 1 == N - 1:
    cnt += 1
print(cnt)

Measured memory_bytes: 14008
n, m, x, y = map(int, input().split())

li_x = list(map(int, input().split()))
li_y = list(map(int, input().split()))

max_x = max(li_x)
min_y = min(li_y)

# print([z for z in range(x + 1, y + 1)])
# print([zz for zz in range(max_x + 1, min_y + 1)])

if len(set([z for z in range(x + 1, y + 1)]).intersection(set([zz for zz in range(max_x + 1, min_y + 1)]))) > 0:
    print("No War")
else:
    print("War")



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vl a(n);
    rep(i, n) cin >> a[i];
    sort(whole(a));
   
    const int NMAX = 1000005;
    vector<bool> filled(NMAX, false);
    bool ok = true;
    rep(i, n) {
        filled[a[i]] = true;
        for (int j=2; j*j<=a[i]; j++) {
            if (a[i]%j==0) {
                int now = j;
                if (filled[now]) {
                    ok = false;
                    break;
                }
                filled[now] = true;
                if (j*j!=a[i]) {
                    now = a[i]/j;
                    if (filled[now]) {
                        ok = false;
                        break;
                    }
                    filled[now] = true;
                }
            }
            if (!ok) break;
        }
        if (!ok) break;
    }
    if (ok) {
        cout << "pairwise coprime" << endl;
        return 0;
    }
    ll tot = a[0];
    rep(i, n) {
        if (i==0) continue;
        tot = __gcd(tot, a[i]);
    }
    if (tot!=1) {
        cout << "not coprime" << endl;
        return 0;
    }
    cout << "setwise coprime" << endl;
    return 0;
}


Measured memory_bytes: 11368
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main() {
	long long n, q, s, t; cin >> n >> q >> s >> t;
	vector<long long>height(n + 1);	for (int i = 0; i <= n; i++)cin >> height[i];
	vector<long long>dis(n); for (int i = 0; i < n; i++)dis[i] = height[i + 1] - height[i];
	long long temperature = 0;
	for (int i = 0; i < n; i++) {
		if (dis[i] > 0)temperature -= s * abs(dis[i]);
		else temperature += t * abs(dis[i]);
	}
	for (int i = 0; i < q; i++) {
		int l, r, x; cin >> l >> r >> x;
		long long small = min(dis[l - 1], dis[l - 1] + x);
		long long big = max(dis[l - 1], dis[l - 1] + x);
		if (0 <= small)
			temperature -= s * x;
		else if (big <= 0)
			temperature -= t * x;
		else {
			if (0 <= x)
				temperature -= s * big + t * abs(small);
			else
				temperature += s * big + t * abs(small);
		}
		dis[l - 1] += x;
		if (r != n) {
			small = min(dis[r], dis[r] - x);
			big = max(dis[r], dis[r] - x);
			if (0 <= small)
				temperature += s * x;
			else if (big <= 0)
				temperature += t * x;
			else {
				if (0 <= x)
					temperature += s * big + t * abs(small);
				else
					temperature -= s * big + t * abs(small);
			}
			dis[r] -= x;
		}
		cout << temperature << endl;
	}
	return 0;
}


Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(string, O, E);
  int d = O.length() - E.length();
  rep(i, 0, (int)O.length() - d) {
    cout << O[i];
    cout << E[i];
  }
  if (d) {
    cout << O[O.length() - 1];
  }
}


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

using namespace std;

int main() {
	int k; cin >> k;
	int r = 0;
	for (int i = 1; i <= 20000000; i++) {
		r = (r * 10 + 7) % k;
		if (r == 0) {
			cout << i << '\n';
			return 0;
		}
	}
	cout << "-1\n";
	return 0;
}


Measured memory_bytes: 3504
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;

typedef long long              ll;
typedef long double            ld;
typedef pair<int, int>         pi;
typedef vector<int>            vi;
typedef vector<pair<int, int>> vpi;

#define pb       push_back
#define all(x)   begin(x), end(x)
#define sz(x)    (int)(x).size()
#define ff       first
#define ss       second
#define mp       make_pair
#define lb       lower_bound
#define ub       upper_bound
#define tcase()  int t; cin >> t; while(t--)

const int MOD = 1e9 + 7; // 998244353;
const int MX  = 2e5 + 5;
const ll  INF = 1e18;
const ld  PI  = acos((ld) -1);

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main(){



    int n, k;
    cin >> n >> k;
    double arr[n];

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

        arr[i] = (arr[i] + 1) / 2;
    }

    double best = 0, sum = 0;

    for(int i = 0; i < n; i++){
        sum += arr[i];
        if(i >= k) sum -= arr[i - k];
        best = max(best, sum);
    }

    printf("%.12lf", best);
}


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

int main() {
  int N, r, l, sum;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> r >> l;
    sum += (l-r+1);
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    if len(S)%2 != 0:
        print(NO)
    else:
        for i in range(len(S)):
            if i % 2 == 0 and S[i] != "h":
                print(NO)
                return
            if i % 2 == 1 and S[i] != "i":
                print(NO)
                return
        print(YES)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;

int size[100010], fa[100010];
long long dp[100010];
map <long long, int> to_i;
long long D[100010];
int n;

int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &D[i]);
		to_i[D[i]] = i;
		size[i] = 1, dp[i] = 0;
	}
	map <long long, int> :: iterator it = to_i.end();
	while ((--it) != to_i.begin()) {
		int x = it->se;
		if (2 * size[x] >= n || !to_i.count(D[x] + 2 * size[x] - n)) {
			printf("-1\n");
			return 0;
		}
		fa[x] = to_i[D[x] + 2 * size[x] - n];
		size[fa[x]] += size[x], dp[fa[x]] += dp[x] + size[x];
	}
	if (to_i.begin()->fi != dp[to_i.begin()->se]) {
		printf("-1\n");
		return 0;
	}
	for (int i = 1; i <= n; i++) {
		if (fa[i]) printf("%d %d\n", i, fa[i]);
	}
	return 0;
}


Measured memory_bytes: 9984
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#define INF 1000000
 
using namespace std;
typedef long long ll;
 



char back(char a,int bnum){
	int lest;
	if(bnum>26){
		bnum-=26;
		if('a'<=a && a<='z'){
			a=a+('A'-'a');
		}
		else if('A'<=a && a<='Z'){
			a=a+('a'-'A');
		}
	}
	if('a'<=a && a<='z'){//こもじ
		if(a-bnum>='a'){
			return a-bnum;
		}else{
			lest=(a-'a'+1)-bnum;
			return 'Z'+lest;
		}
	}else if('A'<=a && a<='Z'){//おおもじ
		if(a-bnum>='A'){
			return a-bnum;
		}else{
			lest=(a-'A'+1)-bnum;
			return 'z'+lest;
		}
	}
	return '+';
}

int main(){
	while(1){
	int n,k[101],key[101];
	cin>>n;
	if(n==0)break;

	string s;
	for(int i=0;i<n;i++){
		cin>>k[i];
	}
	cin>>s;

	int num=0;
	for(int i=0;i<101;i++){
		key[i]=k[num%(n)];
		num++;
	}
	for(int i=0;i<s.size();i++){
		s[i]=back(s[i],key[i]);
	}
	cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int n;
  cin >> n;

  int ans = 0, p = 0;
  rep(i, 0, n) {
    cin >> p;
    if (p != i + 1) ans++;
  }

  if (ans == 0 || ans == 2)
    cout << "YES" << endl;
  else 
    cout << "NO" << endl;
}


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

int main()
{
  int n,m;
  for(;cin>>n>>m;)
    {
      long long int map[n+2];
      long long int sum=0;
      map[1]=0;
      for(int i=2;i<=n;i++)
	{
	  int tmp;
	  cin>>tmp;
	  sum+=tmp;
	  map[i]=sum;
	  //	  cout<<"map["<<i<<"]="<<map[i]<<endl;
	}
      long long int ans=0;
      int now=1;
      for(int i=1;i<=m;i++)
	{
	  int tmp;
	  cin>>tmp;
	  int old=now;
	  now+=tmp;
	  ans+=abs(map[now]-map[old]);
	}
      cout<<ans%100000<<endl;
    }
}

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

typedef long long ll;
vector<int>v(5);

int solve(string st)
{

    int i,res=0;
    for(i=0; i<st.size(); i++)
    {
        int pos=st[i]-48;
        res+=v[pos];
        if(res%10!=0 && i!=4)
        {
            int a=res/10;
            a++;
            res=a*10;
        }
    }
    return res;
}


int main()
{

    ll n,i,a,j,b;
    string st="01234";
    vector<int>v1;
    cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4];
    do
    {
        a=solve(st);
        v1.push_back(a);
    }
    while (next_permutation(st.begin(), st.end()));
    sort(v1.begin(),v1.end());
    cout << v1[0] << "\n";

    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0 ,-1};
signed main() {
    int N,P;
    cin >> N >> P;
    int ans = 1;
    if(N == 1) {
        cout << P << endl;
        return 0;
    }
    while(true) {
        for(int i = 2; i*i <= P; i++) {
            if(P%i == 0) {
                int cnt = 0;
                while(P%i == 0) {
                    P/=i;
                    cnt++;
                }
                for(int j = 0; j < cnt/N; j++) {
                    ans*=i;
                }
            }
        }
        break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3604
# A - Integer Product 
n = int(input())
a = [input() for _ in range(n)]

# bi=ai*(10**9)とすると、(aiは小数第9位までの小数だからbiは整数)
# ai*ajが整数<=>bi*bj/(10**18)が整数<=>bi*bjが素因数に2を18個、5を18個持つ。
# p2[i]:biを素因数分解したときの2の数。
# p5[i]:biを素因数分解したときの5の数。
# c25[i][j]:bi...bnのうち、素因数に2をi個以上、5をj個以上持つbiの数。
# biに対して、ペアになれるのはc25[18-p2[i]][18-p5[i]]個。
# ただし、自分自身は含めないのでbiが素因数として2を9個以上、5を9個以上もつときは―1する。
# また、(bi,bj)と(bj,bi)を重複して数えてしまうので、最後に//2する。

p2 = [0 for _ in range(n)]
p5 = [0 for _ in range(n)]

for i in range(n):
  if '.' in a[i]:
    bi = int(a[i].replace('.','')+'0'*(9-(len(a[i])-a[i].index('.')-1)))
  else:
    bi = int(a[i])*(10**9)
  c = 0
  while(bi%2 == 0 and c < 18):
    c += 1
    bi //= 2
  p2[i] = c
  c = 0
  while(bi%5 == 0 and c < 18):
    c += 1
    bi //= 5
  p5[i] = c

c25 = [[0 for _ in range(20)] for _ in range(20)]
for i in range(n):
  c25[p2[i]][p5[i]] += 1
for i in range(18,-1,-1):
  for j in range(18,-1,-1):
    c25[i][j] += c25[i+1][j]+c25[i][j+1]-c25[i+1][j+1]

ans = 0
for i in range(n):
  ans += c25[18-p2[i]][18-p5[i]]
  if p2[i] >= 9 and p5[i] >= 9:
    ans -= 1
print(ans//2)


Measured memory_bytes: 121772
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

const int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, m;
    cin >> n >> m;
    vi k(m);
    vector<vi> s(m);
    rep(i, m) {
        cin >> k[i];
        s[i].resize(k[i]);
        rep(j, k[i]) {
            int st;
            cin >> st;
            st--;
            s[i][j] = st;
        }
    }
    vi p(m);
    rep(i, m) cin >> p[i];

    int res = 0;

    rep(sw, 1 << n) {
        bool f = true;
        rep(i, m) {
            int c = 0;
            rep(j, k[i]) {
                int l = (sw >> s[i][j]) & 1;
                if (l) c++;
            }
            if (c % 2 != p[i]) f = false;
        }
        if (f) res++;
    }

    cout << res << endl;
    return 0;
}


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

typedef long long ll;

int main() {
	int n;
	scanf("%d", &n);
	int streak = 0;
	int got3 = 0;
	for (int i = 0; i < n; i++)
	{
		int d1, d2;
		scanf("%d %d", &d1, &d2);
		if (d1 == d2)
		{
			streak++;
			if (streak == 3) got3 = 1;
			
		}
		else
		{
			streak = 0;
		}
		
		
	}
	if (got3)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	
	return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double PI=3.1415926535897932;
const double LIT=0.000000001;

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define MUL(a,b) a=(a*b)%mod

ll yaku(ll a, ll b){
    if(a>b) return yaku(b,a);
    return b%a ? yaku(b%a,a) : a;
}

vec Sosu;
map<ll,ll> G;

vec Eratosthenes(ll N){
    vec ret;
    vector<bool> a(N+1,true);
    a.at(0)=false;
    a.at(1)=false;
    REP(i,2,N+1){
        if(a.at(i)) for(ll k=2*i;k<=N;k+=i) a.at(k)=false;
    }
    rep(i,N+1) if(a.at(i)) ret.pb(i);
    rep(i,ret.size()) G.insert(mp(ret[i],i));
    return ret;
}

ll N;

const ll MAXA=1000001;
vec d;
vec SC;
ll PP;
void Solve(ll a){
    ll A=a;
    rep(i,PP){
        if(A==1) return;
        if(G.count(A)) {
            SC[G[A]]=max(SC[G[A]],(ll)1);
            return;
        }
        ll s=Sosu[i];
        ll Count=0;
        while(true){
            if(A%s) break;
            A/=s;
            Count++;
        }
        SC[i]=max(SC[i],Count);
    }
    return;
}

ll ruijou(ll n, ll k){
    if(!k) return 1;
    ll a=ruijou(n,k/2);
    a=(a*a)%mod;
    return k%2 ? (a*n)%mod : a;
}


int main(){
    cin>>N;
    Sosu=Eratosthenes(MAXA);
    rep(i,N){
        ll x; cin>>x;
        d.pb(x);
    }

    PP=Sosu.size();
    rep(i,PP) SC.pb(0);
    rep(i,N) Solve(d[i]);
    ll kobai=1;
    rep(i,PP) MUL(kobai,ruijou(Sosu[i],SC[i]));
    ll ans=0;
    rep(i,N) ADD(ans,(kobai*ruijou(d[i],mod-2))%mod);
    cout<<ans<<endl;
    
    


}

Measured memory_bytes: 10420
<?php

fscanf( STDIN, "%d %d %d", $a, $b, $c );

if( -100 <= $a && $a <= 100 && -100 <= $b && $b <= 100 && -100 <= $c && $c <= 100 ){
    if( $a === $b ){
        echo $c;
    }elseif( $a == $c ){
        echo $b;
    }else{
        echo $a;
    }
}

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

int main() {
    int n, l;
    int ans = 0;
    vector<int> L;
    cin >> n;

    for(int i=0; i<n; i++)
    {
        cin >> l;
        L.push_back(l);
    }
    sort(L.begin(), L.end());

    if(n < 3)
    {
        cout << ans << endl;
        return 0;
    }

    for(int i=0; i<(L.size()-2); i++)
    {
        for(int j=(i+1); j<(L.size()-1); j++)
        {
            for(int k=(j+1); k<L.size(); k++)
            {
                if((L[i]+L[j])>L[k] && L[i] < L[j] && L[j] < L[k]) 
                {
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}



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

#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<typename T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b){ if(a>b){ a=b; return 1;} return 0;}


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    //cin.tie(nullptr);
    //ios::sync_with_stdio(false);   //cin cout 高速化

    string s;

    while(true){
        cin >> s;
        if(cin.eof()) break;
        int joi_cnt = 0, ioi_cnt = 0;
        for(int  i = 0; i < s.size()-2; i++){
            if(s[i]=='J'&&s[i+1]=='O'&&s[i+2]=='I') joi_cnt++;
            else if(s[i]=='I'&&s[i+1]=='O'&&s[i+2]=='I') ioi_cnt++; 
        }
        cout << joi_cnt <<'\n'<< ioi_cnt <<'\n';
    }
}



Measured memory_bytes: 3024
/* 	* In the name of GOD 
 	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int n, m, k, ans = 0;
	cin >> n >> m >> k;
	string s[n];
	for (int i = 0; i < n; i++){
		cin >> s[i];
	}
	int po = pow(2, n);
	int po2 = pow (2, m);
	int a[n], b[m];
	for (int i = 0; i < po; i++){
		for (int j = 0; j < po2; j++){
			string t[n];
			for (int i = 0; i < n; i++)
				t[i] = s[i];
			int x = i, y = j;
			for (int k = 0; k < n; k++){
				a[k] = x % 2;
				x /= 2;
			}
			for (int k = 0; k < m; k++){
				b[k] = y % 2;
				y /= 2;
			}
			for (int k = 0; k < n; k++){
				if (a[k] == 0)
					continue;
				for (int l = 0; l < m; l++)
					t[k][l] = 'R';
			}
			for (int k = 0; k < m; k++){
				if (b[k] == 0)
					continue;
				for (int l = 0; l < n; l++)
					t[l][k] = 'R';
			}
			int an = 0;
			for (int k = 0; k < n; k++){
				for (int l = 0; l < m; l++){
					if (t[k][l] == '#')
						an ++;
				}
			}
			if (an == k)
				ans ++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 4000