akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(){
    int x, y; cin >> x >> y;
    int g1[]={1,3,5,7,8,10,12};
    int g2[]={4,6,9,11};
    int flag=0;

    for(int i=0; i<7; i++){
        if (x==g1[i] || y==g1[i]) flag++;
    }
    if (flag==0){
        for (int j=0; j<4; j++){
            if (x==g2[j] || y==g2[j]) flag++;
        }
    }
    cout << (flag==2 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import sys

YES = "yes"
NO = "no"

class Node:
    def __init__(self, value, p = None, l = None, r = None):
        self.key = value
        self.p = p
        self.left = l
        self.right = r

def chgchild(parent, old, new = None):
    if parent == None:
        return
    else:
#        print("\tparent:{}".format(parent.key))
        if parent.left == old:
            parent.left = new
        else:
            parent.right = new
        if new != None:
            new.p = parent

def delete(node):
    if node == None:
        return
#    print("\tdel key:{}".format(node.key))
    if node.left == None:
        chgchild(node.p, node, node.right)
    elif node.right == None:
        chgchild(node.p, node, node.left)
    else:
        ino = []
        inorder(node,ino)
        next = 0
        for i in range(len(ino)):
            if ino[i].key == node.key:
                next = i + 1
                break
        node.key = ino[next].key
        delete(ino[next])

def getroot(x):
    if x.p != None:
        return getroot(x.p)
    return x

def keylist(A):
    B = []
    for i in A:
        B.append(i.key)
    return B

def preorder(x, A):
    if x == None:
        return
    A.append(x)
    preorder(x.left, A)
    preorder(x.right, A)

def inorder(x, A):
    if x == None:
        return
    inorder(x.left, A)
    A.append(x)
    inorder(x.right, A)

def postorder(x, A):
    if x == None:
        return
    postorder(x.left, A)
    postorder(x.right, A)
    A.append(x)

def ptree(root):
    pre = []
    ino = []
    preorder(root, pre)
    inorder(root, ino)
    ap = keylist(pre)
    ip = keylist(ino)
    print(" {}".format(" ".join(map(str,ip))))
    print(" {}".format(" ".join(map(str,ap))))

def find(value, root):
    if root == None:
        return None
    elif value < root.key:
        return find(value,root.left)
    elif value > root.key:
        return find(value,root.right)
    return root

def insert(root, z):
    y = None # x ??????
    x = root  # 'T ??????'
    while x != None:
        y = x # ???????¨????
        if z.key < x.key:
            x = x.left # ?????????????§????
        else:
            x = x.right # ?????????????§????
    z.p = y

    if y == None: # T ???????????´???
        return z
    elif z.key < y.key:
        y.left = z # z ??? y ?????????????????????
    else:
        y.right = z # z ??? y ?????????????????????
    return root

def main():

    """ ????????? """
    num = int(input().strip())
    istr = sys.stdin.read()
    cmds = list(istr.splitlines())
    root = None
    for i in range(num):
        cmd = cmds[i][0]
        if cmd == "i":
            n = Node(int(cmds[i][7:]))
            root = insert(root, n)
        elif cmd == "f":
            if find(int(cmds[i][5:]),root) == None:
                print(NO)
            else:
                print(YES)
        elif cmd == "p":
            ptree(root)
        elif cmd == "d":
            node = find(int(cmds[i][7:]),root)
            delete(node)

 

if __name__ == '__main__':
    main()

Measured memory_bytes: 213244
#include <stdio.h>

void call(int n);

int main(void)
{
	int n;
	
	scanf("%d", &n);
	
	call(n);
	
	return 0;
}

void call(int n)
{
	int i, x;
	
	for (i = 1; i <= n; i++) {
		x = i;
		if (x % 3 == 0) {
			printf(" %d", i);
		} else {
			while (1) {
				if (x % 10 == 3) {
					printf(" %d", i);
					break;
				}
				x /= 10;
				if (!x) {
					break;
				}
			}
		}
	}
	printf("\n");
	
}

Measured memory_bytes: 600
n = int(input())
w = [input() for i in range(n)]
for j in range(len(w)):
    if w.count(w[j]) > 1:
        print("No")
        exit()
for k in range(len(w)-1):
    if w[k][-1] != w[k+1][0]:
        print("No")
        exit()
print("Yes")

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

using namespace std;

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

    int n;
    cin >> n;

    int sum = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 2 == 1) {
            sum++;
        }
    }

    double x = float(sum) / n;
    printf("%0.10f", x);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
 int n;
 cin >> n;
 double i;
  if (n % 2 == 0)  {
    i = n / 2;
    cout << i / n << endl;
  }
   else {
    i = (n - 1) / 2;
    cout << (i + 1) / n << endl;
   }
  }
     

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

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (n, m): (usize, usize) = {
      let v: Vec<i64> = read_vec();
      (v[0] as usize, v[1] as usize)
    };

    let mut v: Vec<(i64, i64)> = Vec::new();
    for _ in 0..n {
      let touple: (i64, i64) = {
        let v: Vec<i64> = read_vec();
        (v[0], v[1])
      };
      v.push(touple);
    }

    v.sort();
    let mut res: i64 = 0;
    let mut count: i64 = 0;

    for i in 0..n {
        if count + v[i].1 > m as i64{
          res += v[i].0 * (m as i64 - count);
          count = m as i64;
        } else {
          res += v[i].0 * v[i].1;
          count += v[i].1;
        }

        if count == m as i64 {
          break;
        }
    }


    println!("{}", res);
}


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

int nd[] = {-1,2,5,5,4,5,6,3,7,6};

bool comp(const string& a, const string& b){
	return a.size() == b.size() ? a < b : a.size() < b.size();
}

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> d(M);
	for(int i = 0;i < M;i++){
		cin >> d[i];
	}
	vector<string> dp(N + 1);
	for(int i = 0;i < N;i++) if(i == 0 || !dp[i].empty()) {
		for(int j = 0;j < M;j++) {
			int to = i + nd[d[j]];
			if(to > N) continue;
			string s = dp[i];
			s += (char)('0' + d[j]);
			if(comp(dp[to], s)){
				dp[to] = move(s);
			}
		}
	}
	cout << dp[N] << endl;
	return 0;
}


Measured memory_bytes: 43648
#include<stdio.h>
int main()
{
  int A,B,C,D,v,w,y;
  scanf("%d%d%d%d",&A,&B,&C,&D);
  if(A<B)
  {
    v=A;
  }
  else if(A>B)
  {
    v=B;
  }
  if(C<D)
  {
    y=C;
  }
  else if(C>D)
  {
    y=D;
  }
  w=v+y;
  printf("%d",w);
  return 0;
}

Measured memory_bytes: 256
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N = II()
res = 0
for i in range(1, N+1):
    n = N//i
    res += i*n*(n+1) >> 1

print(res)


Measured memory_bytes: 64272
import java.util.*;


class Node{
	int id, cost, to, bad;

	public Node(int id, int cost, int to, int bad) {
		super();
		this.id = id;
		this.cost = cost;
		this.to = to;
		this.bad = bad;
	}
	
}

public class Main {
	public static void main(String[] args)  {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt();
		String s = sc.next();
		sc.close();
		
		Node dp[] = new Node[n+1];
		int INF = Integer.MAX_VALUE/2;
		for(int i=0;i<n+1;i++) {
			int bad = s.charAt(i) - '0'; 
			dp[i] = new Node(i, INF,-1, bad);
		}
		dp[n].cost = 0;
		
		Queue<Node> q = new PriorityQueue<>((p1,p2)->{
			if(p1.cost!=p2.cost) return p1.cost - p2.cost;
			return p1.id - p2.id;
		});
		
		
		q.offer(dp[n]);
		
		for(int i=n-1;i>=0;i--) {
			while(!q.isEmpty()&&(q.peek().bad == 1 || q.peek().id - i > m)) {
				q.poll();
			};
			if(q.isEmpty()) {
				System.out.println(-1);
				return;
			}
			if(dp[i].bad==1)continue;
			dp[i].cost = q.peek().cost+1;
			dp[i].to = q.peek().id;
			q.offer(dp[i]);
		}
		
		StringBuilder sb = new StringBuilder();
		int now = 0;
		while(dp[now].to != -1) {
			int to = dp[now].to;
			int dist = to - now;
			sb.append(dist + " ");
			now = to;
		}
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 43760
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int x;
void input()
{
    cin>>x;
}

void solve()
{
    int ans=0;
    ans+=(x/500)*1000;
    x%=500;
    ans+=(x/5)*5;
    cout<<ans<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

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

int graph[10][10];

//vは現在地
int dfs(int v, int n, int visited[10]){
    //すべて訪れたかどうか
    int res = 1;
    for(int i = 0; i < n; i++)
    {
        if(visited[i]==0){
            res = 0;
        }
    }
    //すべて訪れていたら1を返す
    if(res==1) return 1;

    //最終的な返り値
    int cnt = 0;
    for(int i = 0; i < n; i++)
    {
        if(graph[v][i]==1 && visited[i]==0){
            //次の目的地をiにする
            visited[i] = 1;
            cnt += dfs(i, n, visited);
            //i+1の場合も確かめるため、元に戻す
            visited[i] = 0;
        }
    }
    
    return cnt;
}

int main(){
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        graph[a-1][b-1] = 1;
        graph[b-1][a-1] = 1;
    }
    int visited[10];
    for(int i = 0; i < n; i++)
    {
        visited[i] = 0;
    }
    visited[0] = 1;
    cout << dfs(0, n, visited) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define ll long long
#define mset(s, _) memset(s, _, sizeof s)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main(void) {
  int n;
  cin >> n;
  vector<int> X;
  int sum_X = 0;
  rep(i, 0, n - 1) {
    int x;
    cin >> x;
    sum_X += x;
    X.push_back(x);
  }

  double true_ave = (sum_X) / (1.0 * n);

  int upper_ave = true_ave + 1;
  int ave = true_ave;
  int lower_ave = true_ave - 1;
  // cout << upper_ave << endl;
  // cout << ave << endl;
  // cout << lower_ave << endl;

  int upper_ave_sum_X = 0;
  rep(i, 0, n - 1) {
    upper_ave_sum_X += (X[i] - upper_ave) * (X[i] - upper_ave);
  }

  int ave_sum_X = 0;
  rep(i, 0, n - 1) { ave_sum_X += (X[i] - ave) * (X[i] - ave); }

  int lower_ave_sum_X = 0;
  rep(i, 0, n - 1) {
    lower_ave_sum_X += (X[i] - lower_ave) * (X[i] - lower_ave);
  }

  // cout << upper_ave_sum_X << endl;
  // cout << ave_sum_X << endl;
  // cout << lower_ave_sum_X << endl;

  cout << min(upper_ave_sum_X, min(ave_sum_X, lower_ave_sum_X));
  cout << endl;
  return 0;
}


Measured memory_bytes: 3612
#!/usr/bin/env python3

N = int(input())
# S = input()
# N, K = map(int, input().split())
A = list(map(int, input().split()))

def main():
    cnt_4 = 0
    cnt_2 = 0
    cnt = 0
    for a in A:
        if a % 4 == 0:
            cnt_4 += 1
        elif a % 2 == 0:
            cnt_2 += 1
        else:
            cnt += 1
    if cnt_4 - cnt >= 0:
        print("Yes")
    elif cnt_4 - cnt == -1:
        if cnt_2 >= 1:
            print("No")
        else:
            print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 15020
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    int a[13] = {0};
    a[1] = 1;
    a[3] = 1;
    a[5] = 1;
    a[7] = 1;
    a[8] = 1;
    a[10] = 1;
    a[12] = 1;
    a[4] = 2;
    a[6] = 2;
    a[9] = 2;
    a[11] = 2;
    int x, y; cin >> x >> y;
    if (x == 2 || y == 2) {
        cout << "No" << endl;
        return 0;
    }
    if (a[x] == a[y]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define sz size
#define sc(a) scanf("%d",&a)
#define scll(a) scanf("%lld",&a)
#define scc(a) scanf(" %c",&a)
#define scs(a) scanf(" %s",a)
#define me(a,b) memset(a,b,sizeof a)
#define all(a) a.begin(),a.end()
#define allr(a,n) a,a+n
#define loop(s,e,st) for(int i=s;i<=e;i+=st)
#define read_arr(a,s,n) for(int i=s;i<n+s;i++){sc(a[i]);}
#define read_arr_ll(a,s,n) for(int i=s;i<n+s;i++){scll(a[i]);}
#define err(a,s) cerr<<a<<s;
#define err_arr(a,s,n) for(int i=s;i<n+s;i++){cerr<<a[i]<<" ";}cerr<<endl;
using namespace std;
const int  N =100010;
ll n;
char s[N];

int main() {
	scanf("%s", s);
		n = strlen(s);
		int pos = true;
		if(s[n-1]=='1' || s[0]=='0'){
			pos = false;
		}
		int q = 0;
		for(int i=0; i<n/2; i++){
			if(s[i]!=s[n-2-i]){
				pos = false;
			}
			if(s[i]=='1'){
				q++;
			}
		}
		if(pos==false){
			printf("-1\n");
			return 0;
		}
		vector<pair<int, int> > v;
		int edg = n-1;
		for(int i=0; i<q; i++){
			v.push_back({i, i+1});
			edg--;
		}
		int vert = q + 1, last = 0;
		for(int i=0; i<n/2; i++){
			if(s[i]=='0'){
				v.push_back({last, vert++});
				edg--;
			}
			else{
				last++;
			}
		}
		for(int i=0; i<edg; i++){
			v.push_back({q, vert++});
		}
		for(int i=0; i<n-1; i++){
			printf("%d %d\n", v[i].first+1, v[i].second+1);
		}
	return 0;
}


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

queue<pair<pair<int,int>, int> > Q; // grid id, dist
int dist[1005][1005];
char grid[1005][1005];

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

int main() {
    cin >> H >> W;
    for (int i=0; i<H; i++) {
        cin >> grid[i];
    }
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            if (grid[i][j]=='#') {
                Q.push(make_pair(make_pair(i, j), 0)); // the sources
            }
        }
    }
    int maxD = 0;
    memset(dist, -1, sizeof dist);
    while (!Q.empty()) {
        int x = Q.front().first.first, y = Q.front().first.second, d = Q.front().second; 
        Q.pop();
        if (dist[x][y] != -1) continue;
        dist[x][y] = d;
        maxD = max(maxD, d);
        for (int i=0; i<4; i++) {
            int nx = x + dx[i], ny = y + dy[i], nd = d + 1;
            if (nx >= 0 && nx < H && ny >= 0 && ny < W) {
                Q.push(make_pair(make_pair(nx, ny), nd));
            }
        }
    }
    cout << maxD << '\n';
    return 0;
}

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

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

    int n;
    cin >> n;

    char s[16];
    int p[256] = {};
    for (int i = 0; i < n; i++) {
        cin >> s;
        p[s[0]]++;
    }

    char *c = "MARCH";
    int64_t q[5];
    for (int i = 0; i < 5; i++) {
        q[i] = p[c[i]];
    }

    int64_t r = q[0] * q[1] * q[2] + q[0] * q[1] * q[3] + q[0] * q[1] * q[4] + q[0] * q[2] * q[3] + q[0] * q[2] * q[4] + q[0] * q[3] * q[4] + q[1] * q[2] * q[3] + q[1] * q[2] * q[4] + q[1] * q[3] * q[4] + q[2] * q[3] * q[4];

    cout << r << endl;

    return 0;
}

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

int main(){
    int N,T;
    cin >> N >> T;
    int c[N],t[N];
    int ans=1e5;
    for(int i=0;i<N;i++){
        cin >> c[i] >> t[i];
        if(t[i]<=T){
            ans=min(ans,c[i]);
        }
    }
    if(ans==1e5) cout << "TLE" << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   double sum = 0;
   double pay = 0;
   String p ="";
   for(int i = 0;i<N;i++)
   {
     pay = sc.nextDouble();
     p = sc.next();
     if(p.equals("JPY")) sum += pay;
     else sum += pay*380000.0;
   }
   System.out.println(sum);
 }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);


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

ll modinv(ll a) {
    ll b = mod, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod; 
    if (u < 0) u += mod;
    return u;
}

class UnionFind{
    public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> parent;

    UnionFind(int N){
        parent = vector<int>(N,-1);
    }

    int root(int A){
        if(parent[A] < 0) return A;
        return parent[A]=root(parent[A]);
    }

    int size(int A){
        return -parent[root(A)];
    }

    bool unite(int A, int B) {
        A = root(A), B = root(B);
        if(A == B) return false; 

        if(size(A) < size(B)) swap(A,B);
        parent[A] += parent[B];
        parent[B] = A;
        return true;
    }

    bool same(int A, int B){
        return root(A)==root(B);
    } 
};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    ll k=0;
    ll a[n];
    UnionFind uni(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i] == -1) k++;
        else{
            a[i]--;
            uni.unite(i,a[i]);
        }
    }
    ll t = n;
    vector<ll> v;
    ll mi = 0;
    for(int i=0;i<n;i++){
        if(a[i] == -1){
            v.push_back(uni.size(i));
            t -= uni.size(i);
        }
        if(i == uni.root(i)) mi += uni.size(i) -1;
    }
    ll ans = (mi + k);
    ll m = v.size();
    ll dp[m+1][m+1]={};
    dp[0][0]=1;
    ll inv = modinv(n-1);
    for(int i=0;i<m;i++){
        for(int j=0;j<=i;j++){
            dp[i+1][j] += dp[i][j];
            dp[i+1][j] %= mod;

            ll ret = dp[i][j]*v[i]%mod;
            ret = (ret*inv)%mod;
            dp[i+1][j+1] += ret;
            dp[i+1][j+1] %= mod;
        }
    }
    ll now = 1;
    for(int i=2;i<=m;i++){
        dp[m][i] = (dp[m][i]*now)%mod;
        ans += mod - dp[m][i];
        ans %= mod;
        now *= i;
        now %= mod;
    }
    for(int i=0;i<m;i++){
        ans += mod - ((v[i]-1)*inv)%mod;
        ans %= mod;
    }
    ans *= modpow(n-1,k);
    ans %= mod;
    cout << ans << endl;
}

Measured memory_bytes: 199140
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, A;
    cin >> H >> A;
    cout << (H - 1) / A + 1 << endl;
    return 0;
}


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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}

const int maxn=200000;
int N,ct[maxn];
vi al[maxn];
int X,Y;

int a,b,g;
void gcd(int m,int n) {
    if (n==0) {a=1;b=0;g=m;return;}
    gcd(n,m%n);
    int t=a-b*(m/n);
    a=b;b=t;
}

int inv(int a,int mod) {
	gcd(mod,a);
	return g>0?b:-b;
}

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

	cin >> N >> X >> Y;
	for (int i=0;i<N;i++) {
		int c,w;
		cin >> c >> w;
		c--;
		al[c].push_back(w);
	}
	for (int i=0;i<N;i++) {
		sort(al[i].begin(),al[i].end());
	}

	sort(al,al+N,[](const vi& a,const vi& b) -> bool {
			if (a.size()==0) return 0;
			if (b.size()==0) return 1;
			return a[0]<b[0];
			});

	for (int i=0;i<N;i++) if (al[i].size()==0)
		N=i;

	for (int i=0;i<N;i++) if (al[i][0]+al[0][0]>Y) N=i;
	if (N<2) {
		cout << 1 << endl;
		return 0;
	}

	ll ans=1;
	ll tot=0;
	for (int i=0;i<N;i++) {
		for (;ct[i]<al[i].size() && (al[i][ct[i]]+al[i][0]<=X || al[i][ct[i]]+al[!i][0]<=Y);) {
			ans=ans*++tot%mod*inv(++ct[i],mod)%mod;
		}
	}

	if (ans<0) ans+=mod;
	cout << ans << endl;

}

Measured memory_bytes: 9728
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


// #define INT_MAX 2147483647
// #define LL_MAX 9223372036854775807

using namespace std;
#define i64  long long

void solve(void)
{
  int a,b;
  cin>>a>>b;

  if(a>b)
    cout<<"a > b"<<endl;
  else if ( a == b)
  cout<<"a == b"<<endl;
  else
  cout<<"a < b"<<endl;
  
  return;
}
int main(int argc, const char *argv[])
{

  solve();

  return 0;
}



Measured memory_bytes: 3084
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		TreeMap<String,Integer> map=new TreeMap<>();
		int q=Integer.parseInt(in.next());
		for(int i=0;i<q;i++) {
			int odr=Integer.parseInt(in.next());
			
			switch(odr) {
			case 0:
				String key0=in.next();
				int x0=Integer.parseInt(in.next());
				map.put(key0,x0);
				break;
				
			case 1:
				String key1=in.next();
				out.println(map.get(key1));
				break;
			}
		}
		out.flush();
	}

}



Measured memory_bytes: 125844
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b;
    scanf ("%d %d",&a,&b);
    if (a < b) {
        printf("a < b\n");
    }
    if (a > b) {
        printf("a > b\n");
    }
    if (a == b) {
        printf("a == b\n");
    }
    return 0;
}



Measured memory_bytes: 2104
import math
from sys import stdin
A, B, H, M = [int(_) for _ in stdin.readline().rstrip().split()]
theta = ((H*60+M)/720 - M/60)*(math.pi*2)
ans = A ** 2 + B ** 2 - 2 * A * B * math.cos(theta)
ans = math.sqrt(ans)
print(ans)

Measured memory_bytes: 9312
#include <cstdio>
#include <cstdlib>
#include <cstring>

class ListNode
{
  private:
    ListNode *next;
    ListNode *prev;
    int key;

  public:
    ListNode(ListNode *next = NULL, ListNode *prev = NULL, int key = NULL)
        : next(next),
          prev(prev),
          key(key)
    {
    }

    ~ListNode() {}

    void setNext(ListNode *new_next)
    {
        next = new_next;
    }

    void setPrev(ListNode *new_prev)
    {
        prev = new_prev;
    }

    ListNode *getNext()
    {
        return next;
    }

    ListNode *getPrev()
    {
        return prev;
    }

    int getKey()
    {
        return key;
    }

    void setKey(int new_key)
    {
        key = new_key;
    }
};

class LinkedList
{

  private:
    ListNode *nil;

  public:
    LinkedList()
    {
        nil = (ListNode *)malloc(sizeof(ListNode));
        nil->setNext(nil);
        nil->setPrev(nil);
    }

    ~LinkedList()
    {
        while (nil->getNext() != nil)
        {
            deleteFirst();
        }

        free(nil);
    }

    void insert(int new_key)
    {
        ListNode *new_node = (ListNode *)malloc(sizeof(ListNode));
        new_node->setNext(nil->getNext());
        nil->getNext()->setPrev(new_node);
        nil->setNext(new_node);
        new_node->setPrev(nil);

        new_node->setKey(new_key);
    }

    void deleteNode(ListNode *target)
    {
        if (target != nil)
        {
            target->getPrev()->setNext(target->getNext());
            target->getNext()->setPrev(target->getPrev());
            free(target);
        }
    }

    void deleteFirst()
    {
        deleteNode(nil->getNext());
    }

    void deleteLast()
    {
        deleteNode(nil->getPrev());
    }

    ListNode *listSearch(int key)
    {
        ListNode *cur = nil->getNext();
        while (cur != nil && cur->getKey() != key)
        {
            cur = cur->getNext();
        }
        return cur;
    }

    void deleteKey(int key)
    {
        deleteNode(listSearch(key));
    }

    void printList()
    {
        ListNode *cur = nil->getNext();
        while (cur != nil)
        {
            printf("%d", cur->getKey());
            cur = cur->getNext();
            if (cur != nil)
            {
                printf(" ");
            }
            else
            {
                printf("\n");
                break;
            }
        }
    }
};

int main()
{
    LinkedList l;

    char com[20];
    int n, key;

    scanf("%d", &n);

    for (int i = 0; i < n; i++)
    {
        scanf("%s%d", com, &key);

        if (com[0] == 'i')
        {
            l.insert(key);
        }
        else if (com[0] == 'd')
        {
            if (strlen(com) > 6)
            {
                if (com[6] == 'F')
                {
                    l.deleteFirst();
                }
                else
                {
                    l.deleteLast();
                }
            }
            else
            {
                l.deleteKey(key);
            }
        }
    }

    l.printList();
}


Measured memory_bytes: 33960
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ft first
#define sd second
#define pb push_back
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e9+7;
 
ll power(ll a, ll b, ll m = mod) {
    ll x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
 
const int N = 4e5+9;
// ll a[N];
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);    
    int n, k, s; cin >> n >> k >> s;
    if(s == 1000*1000*1000) {
        for(int i = 1; i <= k; i++) {
            cout << s << " ";
        }
        for(int i = k+1; i <= n; i++) {
            cout << "1 ";
        }
        cout << "\n";
        return 0;
    }
    for(int i = 1; i <= k; i++) {
        cout << s << " ";
    }
    for(int i = k+1; i <= n; i++) {
        cout << s+1 << " ";
    }
    cout << "\n";





 
    return 0;
    
}

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

int main() {
  ll x, y; cin >> x >> y;
  int ans = 0;
  while(y >= x) {y /= 2; ans++;}
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, a, b);
  if (a + b == 15)
    puts("+");
  else if (a * b == 15)
    puts("*");
  else
    puts("x");

  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, m;
	cin>>n>>m;
	cout<<n*(n - 1)/2 + m*(m - 1)/2<<endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-
k = int(input())
a, b = map(int, input().split())
flag = 0
for i in range(a, b + 1):
    if i % k == 0:
        flag = 1
        break

if flag == 1:
    print("OK")
else:
    print("NG")

Measured memory_bytes: 9168
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define fd(i,j,k) for(int i=j;i>=k;i--)
#define fr(i,j) for(int i=beg[j];i;i=nex[i])
using namespace std;
int const mn=15+3,ms=(1<<15)+3,mo=1e9+7;
int n,m,f[ms],g[mn][ms],pw2[mn*mn];
int main(){
	scanf("%d%d",&n,&m);
	fo(i,1,m){
		int u,v;
		scanf("%d%d",&u,&v);
		g[u][1<<(v-1)]=1;
	}
	pw2[0]=1;
	fo(i,1,n*(n-1)/2)pw2[i]=2ll*pw2[i-1]%mo;
	int lim=(1<<n)-1;
	fo(i,1,n)fo(s,1,lim)for(int ss=(s-1)&s;ss;ss=(ss-1)&s)
		g[i][s]=g[i][ss]+g[i][s-ss];
	fo(s,0,lim)if((!(s&3))||((s&3)==3))f[s]=1;
	fo(s,1,lim)for(int ss=(s-1)&s;ss;ss=(ss-1)&s)
		if((!(s&3))||(((s&3)==3)&&((!(ss&3))||((ss&3)==3)))){
			LL tmp=1;
			fo(i,1,n)if(ss&(1<<(i-1)))tmp=tmp*pw2[g[i][s-ss]]%mo;
				else if(s&(1<<(i-1)))tmp=tmp*(pw2[g[i][ss]]-1)%mo;
			f[s]=(f[s]+f[s-ss]*tmp)%mo;
		}
	printf("%d",((pw2[m]-f[lim])%mo+mo)%mo);
	return 0;
}


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

int main() {
  string atcoder;
  string contest;
  string str;
  cin >> atcoder >> str >> contest;
  
  string AxC = "AxC";
  AxC.at(1) = str.at(0);
  
  cout << AxC << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		long n = sc.nextLong();
		int sqrtN = (int) Math.sqrt((double) n);
		long step = 0;

		for (int i = sqrtN; i >= 1; i--) {
			if (n % i == 0) {
				step = (i - 1) + (n / i - 1);
				break;
			}
		}
		System.out.println(step);
		sc.close();
	}
}


Measured memory_bytes: 23892
import java.util.*;
import java.lang.*;


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

        TreeMap<Long, Integer> tm = new TreeMap<Long, Integer>();
        for (int i = 0; i < n; i++) {
            long tmp = sc.nextLong();
            if (tm.containsKey(tmp)) {
                tm.put(tmp, tm.get(tmp) + 1);
            } else {
                tm.put(tmp, 1);
            }
        }

        int count = 0;
        while (!tm.isEmpty()) {
            long req = 0;
            for (int j = 0; j < 33; j++) {
                if (Math.pow(2, j) > tm.lastKey()) {
                    req = (long)Math.pow(2, j) - tm.lastKey();
                    break;
                }
            }
            if (tm.get(tm.lastKey()) == 1) {
                tm.remove(tm.lastKey());
            } else {
                tm.put(tm.lastKey(), tm.get(tm.lastKey()) - 1);
            }
            if (tm.containsKey(req)) {
                if (tm.get(req) == 1) {
                    tm.remove(req);
                } else {
                    tm.put(req, tm.get(req) - 1);
                }
                count++;
            }
        }
        System.out.println(count);
    }
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;
#define rep(i,s,e) for(int i = (int)(s); i < (int)(e); ++i)
#define per(i,s,e) for(int i = (int)(s)-1; i >= (int)(e); --i)

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  vector<int> v(n); cin >> v;
  ll ans = 0;
  rep(i,0,n){
    if(i&&v[i-1]>0&&v[i]>0){
      v[i]--;
      v[i-1]--;
      ans++;
    }
    ans += v[i]/2;v[i] = v[i]%2;
  }
  rep(i,0,n-1){
    if(v[i]&&v[i-1]){
      ans++;
      i++;
    }
  }
    
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
int cmp3(T lhs, T rhs) { return (lhs == rhs) ? 0 : (lhs > rhs) ? 1 : -1; }

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

void solve(string const &S, string const &T) {
  vector<vector<int>> dp(S.size()+1, vector<int>(T.size()+1, 0));
  REP(i, S.size()) {
    REP(j, T.size()) {
      dp[i+1][j+1] = max({dp[i][j+1], dp[i+1][j], dp[i][j]+(S[i]==T[j])});
    }
  }
  string str;
  for (int i = S.size(), j = T.size(), val = dp[i][j]; val > 0; --val) {
    while (dp[i][j-1] == dp[i][j]) { --j; }
    while (dp[i-1][j] == dp[i][j]) { --i; }
    str.push_back(S[i-1]);
    --i, --j;
  }
  reverse(begin(str), end(str));
  cout << str << endl;
}

int main() {
  string S, T;
  cin >> S >> T;
  solve(S, T);
  return 0;
}


Measured memory_bytes: 35584
N,M,X = map(int,input().split())
books = []
for _ in range(N):
    line = list(map(int,input().split()))
    books.append(line)

values = []
for i in range(2**N):
    bags = []
    for j in range(N):
        if ((i >> j) & 1):
            bags.append(j)
    
    value = 0
    algs = [0] * M
    for k in bags:
        value += books[k][0]
        for l in range(M):
            algs[l] += books[k][l+1]
    
    for r in algs:
        if r < X:
            break
    else:
        values.append(value)
    
if len(values) == 0:
    print(-1)
else:
    print(min(values))

Measured memory_bytes: 73988
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*power((a*a)%mod,n/2))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int md = 998244353;
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}


signed main()
{
    showoff;
    int l,r;
    cin >> l >> r;
    vector<int>v;
    FOR(i,l,min(r+1,l+2020)){
        v.pb(i%2019);
    }
    int ans = inf;
    FOR(i,0,sz(v)){
        FOR(j,i+1,sz(v)){
            ans = min(ans,(v[i]*v[j])%2019);
        }
    }
    cout << ans;
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int ans=1000;
  string s,t;
  cin>>s>>t;
  int n = s.size();
  int m = t.size();
  rep(i,n){
    if(i+m>n) continue;
    int notsame=0;
    rep(j,m){
      if(s.at(i+j)!=t.at(j))
        notsame++;
    }
    ans=min(ans,notsame);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int count=0;
		
		for(int i=a; i<=b; i++) {
			if(c%i==0) {
				count++;
			}
		}
		System.out.println(count);
		
	}
}



Measured memory_bytes: 26420
import heapq

N = int(input())

arr = [int(x) for x in input().split()]
arr = sorted(arr,reverse = True)

ans = 0
q = []

heapq.heappush(q,-arr[0])

#print(q)

for i in range(1,N):
    tmp = heapq.heappop(q)
    #print(tmp)
    tmp *= -1
    ans += tmp
    #print(ans)
    heapq.heappush(q,-arr[i])
    heapq.heappush(q,-arr[i])
    #print(q)
print(ans)

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); 
	
	int n;
	cin >> n;
	int even = n / 2;
	int odd = n - n / 2;
	cout << even * odd << endl;
	return 0;
}



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

def factorization(n):
    arr = []
    if n == 1:
        return arr
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

f_list = factorization(n)
ans = 0

for i in range(len(f_list)):
    _tmp = f_list[i][1]
    j = 1
    while _tmp >= 0:
        _tmp -= j
        j += 1
    ans += j-2

print(ans)

Measured memory_bytes: 9476
use std::io::*;
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let mut sc = Scanner::new(cin.lock());

    let n: usize = sc.next();
    let v = sc.vec::<i64>(n);
    println!(
        "{} {} {}",
        v.iter().min().unwrap(),
        v.iter().max().unwrap(),
        v.iter().sum::<i64>()
    );
}

/* ========== Scanner ========== */

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.next::<String>().chars().collect()
    }
}



Measured memory_bytes: 5052
import sys
n=input()
ls=[]
for _ in xrange(n):
    ls.append(input())
m1= max(ls)
i=ls.index(m1)
del ls[ls.index(m1)]
m2= max(ls)
ls.insert(i,m1)
for i in xrange(n):
    if ls[i]==m1:
        print m2
    else:
        print m1

Measured memory_bytes: 12164
def gcd(a,b)
  if b == 0
    a
  else
    gcd(b,a%b)
  end
end

def lcm(a,b)
  a*b/gcd(a,b)
end

def main()
  while a = gets 
    c = a.split(' ').map(&:to_i)
    print gcd(c[0],c[1])
    print ' '
    puts lcm(c[0],c[1])
  end
end

3
main()

Measured memory_bytes: 8580
n,m = map(int,input().split())
s = []
k = []
for i in range(m):
    inp = list(map(int,input().split()))
    k.append(inp[0])
    s.append(inp[1:len(inp)])
p = list(map(int,input().split()))

count = 0
for i in range(2**n):
    allon = True
    for j in range(m):
        on = 0
        for l in range(k[j]):
            on = on +  (i >> (s[j][l]-1))&1
        if on%2 != p[j]:
            allon = False
            break
    if allon:
        count+=1
print(count)

Measured memory_bytes: 40304
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    vector<vector<int> > a(3, vector<int>(n));
    for(int i=0; i<n; ++i){
        for(int j=0; j<3; ++j){
            cin >> a[j][i];
        }
    }

    vector<int> ret(n, 0);
    for(int i=0; i<3; ++i){
        vector<int> x(101, 0);
        for(int j=0; j<n; ++j)
            ++ x[a[i][j]];

        for(int j=0; j<n; ++j){
            if(x[a[i][j]] == 1)
                ret[j] += a[i][j];
        }
    }

    for(int i=0; i<n; ++i)
        cout << ret[i] << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rep3(i, m, n) for(ll i=m;i<=(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1000000000000000000

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

void solve_abc_d() {
	ll n, k;
	ll l_ans = -LLINF;

	cin >> n >> k;
	V p(n), c(n);
	rep(i, n) {
		cin >> p[i];
		p[i]--;
	}
	rep(i, n) cin >> c[i];

	rep(i, n) {
		ll cnt = 0;
		ll tot = 0;
		ll now = i;
		while (true) {
			cnt++;
			tot += c[now];
			now = p[now];
			if (now == i) {
				break;
			}
		}

		ll cnt2 = 0;
		ll tot2 = 0;
		now = i;
		while (true) {
			cnt2++;
			tot2 += c[now];

			if (cnt2 > k) break;

			ll num = (k - cnt2) / cnt;
			chmax(l_ans, tot2 + max(0LL, tot * num));

			now = p[now];
			if (now == i) {
				break;
			}
		}
	}

	cout << l_ans << "\n";
}

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

	solve_abc_d();

	return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    
    int ans = -1;
    for (int i = 0; i < 100000; i++) {
        //cout << (8 * i) / 100 << endl;
        if ((8 * i) / 100 == a && (10 * i) / 100 == b) {
            ans = i;
            break;
        }
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    int n,q;
    cin>>n>>q;
    vec A(n),B,C;
    rep(i,n) cin>>A[i];
    reverse(all(A));
    rep(i,(n-1)/2) B.push_back((A[i+1]+A[2*(i+1)])/2);
    reverse(all(B));
    ll sum=0;
    rep(i,(n+1)/2) sum+=A[2*i],C.push_back(sum);
    rep(i,(n-1)/2) sum=sum-A[2*(i+1)]+A[i+1],C.push_back(sum);
    reverse(all(C));
    rep(i,q){
        ll x;
        cin>>x;
        cout<<C[lower_bound(all(B),x)-B.begin()]<<"\n";
    }
}

Measured memory_bytes: 3828
#137c
N = int(input())
s_dict = {}
ans = 0

#文字を読み込みつつ、出現回数を辞書化して、辞書に追加
for i in range(N): #2<N<10^5
  # https://www.lifewithpython.com/2015/05/python-count-characters-in-string.html
  string = list(input())
  string.sort(reverse=False)
  
  #print(tuple(string))
    
  if tuple(string) in s_dict:
    s_dict[tuple(string)] += 1
  else:
    s_dict[tuple(string)] = 1

for i in s_dict.values():
  if i != 1:
    ans += sum([i for i in range(1,i)])

print(ans)

Measured memory_bytes: 23652
n=int(input())
li=[list(map(int,input().split())) for _ in range(n)]
c=[0 for i in range(n)]
ans=0
j=0
for i in li:
    c[j]=sum(i)
    ans-=i[1]
    j+=1
c.sort(reverse=True)
ans+=sum(c[::2])
print(ans)

Measured memory_bytes: 31872
N, K = gets.split(' ').map(&:to_i)

def add(a, b)
  a1, a2 = a
  b1, b2 = b

  c = a2.lcm(b2)
  [a1*c/a2 + b1*c/b2, c]
end

a,b = 1.upto(N).map {|i|
  try = Math.log2(1.0 * K / i).ceil
  try > 0 ? [1, 2**try] : [1,1]
}.inject([0,1]) {|acc,i| add(acc,i) }
puts 1.0 * a / b / N


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 h,w;
  cin >> h >> w;
  vector<string> a(h);
  REP(i,h)cin >> a[i];
  REP(i,h){
    REP(j,w){
      if(i == 0 || (j == w-1 && i != h-1)){
        cout << "#";
      }else if(i != 0 && i != h-1 && j != 0 && j != w-1 && (i+j)%4 < 2){
        cout << "#";
      }else if(a[i][j] == '#'){
        cout << "#";
      }else{
        cout << ".";
      }
    }
    cout << endl;
  }
  cout << endl;
  REP(i,h){
    REP(j,w){
      if(i == h-1 || (j == 0 && i != 0)){
        cout << "#";
      }else if(i != 0 && i != h-1 && j != 0 && j != w-1 && (i+j)%4 >= 2){
        cout << "#";
      }else if(a[i][j] == '#'){
        cout << "#";
      }else{
        cout << ".";
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
import math
from itertools import accumulate


def is_prime(n):
    if n == 1:
        return 0

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return 0

    return 1


Q = int(input())
L = [0]*Q
R = [0]*Q

for i in range(Q):
    L[i], R[i] = list(map(int, input().split()))

min_L = min(L)
max_R = max(R)

check = []
for i in range(min_L, max_R+1):
    if (i % 2 == 1):
        flg = (is_prime(i) and is_prime((i+1)/2))
    else:
        flg = 0
    check.append(flg)

# 累積和
check = [0] + check
check = list(accumulate(check))

for i in range(Q):
    print(check[R[i] - min_L + 1] - check[L[i] - min_L])

Measured memory_bytes: 14772