akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define PAPER_SIZE 10

int paper[PAPER_SIZE][PAPER_SIZE];

void dropInk(int x, int y, int size);
void dropSInk(int x, int y);
void dropMInk(int x, int y);
void dropLInk(int x, int y);
void addInk(int x, int y);
int countWhite();
int checkMax();

int main()
{
        //Initialize Paper
        int i, j;
        for(i = 0; i < PAPER_SIZE; i++) {
                for(j = 0; j < PAPER_SIZE; j++) {
                        paper[i][j] = 0;
                }
        }
        //Read action
        int x1, y1, size;
        while(scanf("%d,%d,%d", &x1, &y1, &size) != EOF)
        {
                //Simulate
                dropInk(x1,y1,size);
        }
        //Count white area
        int white = countWhite();
        //Check Max
        int max = checkMax();
        //Print out
        printf("%d\n%d\n", white, max);
        return 0;
}

void dropInk(int x, int y, int size)
{
        switch(size) {
                case 1:
                        dropSInk(x, y);
                        break;
                case 2:
                        dropMInk(x, y);
                        break;
                case 3:
                        dropLInk(x, y);
                        break;
        }
}

void dropSInk(int x, int y)
{
        addInk(x, y);
        addInk(x-1, y);
        addInk(x+1, y);
        addInk(x, y-1);
        addInk(x, y+1);
}

void dropMInk(int x, int y)
{
        addInk(x-1, y-1);
        addInk(x-1, y);
        addInk(x-1, y+1);
        addInk(x, y-1);
        addInk(x, y);
        addInk(x, y+1);
        addInk(x+1, y-1);
        addInk(x+1, y);
        addInk(x+1, y+1);
}

void dropLInk(int x, int y)
{
        addInk(x, y);
        addInk(x, y-2);
        addInk(x-1, y-1);
        addInk(x, y-1);
        addInk(x+1, y-1);
        addInk(x-2, y);
        addInk(x-1, y);
        addInk(x+1, y);
        addInk(x+2, y);
        addInk(x-1, y+1);
        addInk(x, y+1);
        addInk(x+1, y+1);
        addInk(x, y+2);
}

void addInk(int x, int y)
{
        if(0 <= x && x < PAPER_SIZE &&
                        0 <= y && y < PAPER_SIZE) {
                paper[y][x]++;
        }
}

int countWhite()
{
        int white = 0;
        int i, j;
        for(i = 0; i < PAPER_SIZE; i++) {
                for(j = 0; j < PAPER_SIZE; j++) {
                        if(paper[i][j] == 0)
                                white++;
                }
        }
        return white;
}

int checkMax()
{
        int max = 0;
        int i, j;
        for(i = 0; i < PAPER_SIZE; i++) {
                for(j = 0; j < PAPER_SIZE; j++) {
                        if(max < paper[i][j])
                                max = paper[i][j];
                }
        }
        return max;
}

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


def solve(X: int, N: int, p: "List[int]"):
    p.sort()

    Q = []
    for q in range(-200, 200):
        if q not in p:
            Q.append(q)

    Q_diff = [abs(a - X) for a in Q]

    mn = min(Q_diff)

    ans_idx = Q_diff.index(mn)
    ans = Q[ans_idx]

    print(ans)
    return


# Generated by 1.1.7.1 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()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)

if __name__ == '__main__':
    main()


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

#define INF INT_MAX/2
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

   int A,B;
   cin>>A>>B;
   ll ans = -10000000;
   ans = max(A+B,max(A-B,A*B));
   cout<<ans<<endl;
   return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int cnt = 0;
    rep(i, n) {
        if (i%2==0 && a[i]%2) cnt++;
    }
    cout << cnt << endl;
}

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

double calc_len2(int a, int b, double theta) {
  return a*a + b*b - 2*a*b*cos(theta * M_PI/180);
}

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  
  double h_angle = (60*h + m) * 360.0/(12*60);
  double m_angle = m * 360/60;
  
  cout << fixed << setprecision(10) << sqrt(calc_len2(a, b, abs(h_angle - m_angle)));
  
  return 0;
}

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

#define SIZE(a) ((int)(a).size())
#define REP(i, n) for (int i = 0; i < (n); ++i)

const int N = 8055;
bool f[2][2*N];

int can(vector<int> a, int x) {
	if (x <= -N || x >= N) return 0;
	REP(i, 2) REP(j, 2*N) f[i][j] = 0;
	f[0][N] = 1;
	REP(i, SIZE(a)) {
		REP(j, 2*N) if (f[0][j]) {
			if (j+a[i] >= 0 && j+a[i] < 2*N) f[1][j+a[i]] = 1;
			if (j-a[i] >= 0 && j-a[i] < 2*N) f[1][j-a[i]] = 1;
		}
		REP(j, 2*N) {
			f[0][j] = f[1][j];
			f[1][j] = 0;
		} 
	}
	return f[0][x+N];
}

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

	string s;
	int x, y;
	cin >> s >> x >> y;
	int n = SIZE(s);

	int dir = 0;
	vector<int> a[2];

	int i = 0;
	while (i < n && s[i] == 'F') ++i, --x;
	for (; i < n; ++i) {
		int j = i;
		while (j < n && s[j] == 'F') ++j;
		if (j - i > 0) a[dir].push_back(j - i);
		if (j < n) dir ^= 1;
		i = j;
	}

	cout << ((can(a[0], x) && can(a[1], y)) ? "Yes" : "No") << '\n';

	return 0;
}

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

#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed

int main() {
  int a, b, ans = 0;
  //string s;
  cin >> a;
  //vector<int> v(n), c(n);
  cout << a + a * a + a * a * a << endl;
}


Measured memory_bytes: 3592
from sys import stdin
def issai():
    print("Hello World")

def nisai():
    a = int(stdin.readline().rstrip())
    b = int(stdin.readline().rstrip())
    print(a+b)

if __name__ == '__main__':
    x = int(stdin.readline().rstrip())
    if x == 1:
        issai()
    elif x == 2:
        nisai()


Measured memory_bytes: 2940
# AOJ GRL_6_A "Maximum Flow"
# Ford-Fulkerson method

import sys
input = sys.stdin.readline

INF = 10**18

H, W = map(int, input().split())
V = H+W


def make():
    state = [list(input().rstrip()) for _ in range(H)]
    graph = [{} for _ in range(V+2)]

    start = V
    finish = V+1

    for h in range(H):
        for w in range(W):
            u, v = h, w+H
            if state[h][w] == "o":
                graph[u][v] = 1
                graph[v][u] = 1
            if state[h][w] == "S":
                graph[v][start] = INF
                graph[start][v] = INF
                graph[u][start] = INF
                graph[start][u] = INF
            if state[h][w] == "T":
                graph[u][finish] = INF
                graph[finish][u] = INF
                graph[v][finish] = INF
                graph[finish][v] = INF
    
    return graph, start, finish


def dfs2(start, finish, graph):
    Flow = [INF]*len(graph)
    used = [False]*len(graph)
    Par = [-1]*len(graph)
    stack = [start]
    used[start] = True
    while stack:
        v = stack.pop()
        if v == finish:
            d = Flow[v]
            while v != start:
                nv = Par[v]
                graph[nv][v] -= d
                graph[v][nv] += d
                v = nv
            return d, graph
        for i, (nv, ncap) in enumerate(graph[v].items()):
            if not used[nv] and ncap > 0:
                used[nv] = True
                stack.append(nv)
                Par[nv] = v
                Flow[nv] = min(Flow[v], ncap)
    return 0, graph

# solve
def max_flow(start, finish, graph):
    flow = 0
    while True:
        f, graph = dfs2(start, finish, graph)
        if f == 0: return flow
        flow += f


def main():
    graph, start, finish = make()
    ans = max_flow(start, finish, graph)

    if ans > INF//2:
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 44908
#include<iostream>
#include<stdio.h>
using namespace std;

int main(void){
  int a,b,c,d,e,f;
  double x,y;
  while(  cin>>a >>b >>c >>d >>e >>f){
    x =(double) (e*c-b*f)/(a*e-b*d);
    y =(double) (a*f-d*c)/(a*e-b*d);
    if(x==0) x=0;
    if(y==0) y=0;
    printf("%.3f %.3f\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 1192
function main() {
  var
  hands, pattern,
  swap,
  i = 0, j;
  for (;;) {
    if (input[i] == 0) break;
    
    
    hands = [];
    for (j = 0; j < 5; j++) {
      hands.push(Number(input[i++]));
    }
    
    pattern = hands.reduce(function (pat, h) {
      return (pat[h] = true, pat);
    }, {});
    
    keys = Object.keys(pattern).map(Number).sort(function (x, y) { return x - y; });
    
    if (keys.length === 2) {
      if (keys[1] - keys[0] == 2) {
        swap = keys[0];
        keys[0] = keys[1];
        keys[1] = swap;
      }
      hands.forEach(function (h) {
        console.log(keys.indexOf(h) + 1);
      });
    } else {
      hands.forEach(function () {
        console.log(3);
      });
    }
  }
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 9964
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)

bool isprime(int x){
	for(int i = 2;i*i<=x;i++){
		if(x%i == 0)return false;
	}
	return x!=1;
}
int gcd(int a, int b) 
{ 
    // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 




int xor1(int x){
	if(x<=0)return 0;
	if(x%2 == 0){
		int tmp = x/2;
		if(tmp%2)return 1^x;
		else return 0^x;
	}
	else{
		int tmp = (x+1)/2;
		if(tmp%2)return 1;
		else return 0;
	}
}

int n;
int n1;

void solve(){
	in(n);
	in(n1);
	out(xor1(n1)^xor1(n-1));
}

int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
const int maxn=100006;
int a[maxn],b[maxn];
int n;
bool eq(){
  for(int i=1;i<=n;++i)if(a[i]!=b[i])return false;
  return true;
}
int c[maxn],d[maxn];
bool nosolu(){
  int pt=1;
  for(int i=1;i<=n+1;++i){
    if(pt<=n&&c[i]==d[pt])++pt;
  }
  return pt<=n;
}
int seq[maxn];
int res=0;
map<int,int> cnt1,cnt2;
void check(){
  int tot=0;
  for(int i=1;i<=n;++i){
    if(a[i]!=b[i])cnt1[a[i]]++,cnt2[b[i]]++;
  }
  int val=-1,VAL;
  for(int i=1;i<=n;++i){
    if(a[i]!=b[i]){
      if(cnt1[a[i]]>cnt2[a[i]]){
	val=a[i];
      }
      if(cnt1[b[i]]<cnt2[b[i]]){
	VAL=b[i];
      }
    }
  }
  if(val!=-1){//printf("%d %d\n",val,VAL);
    for(int i=1;i<=n;++i){
      if(b[i]==VAL){
	b[i]=val;
	if(val==a[i])res++;
	break;
      }
    }
  }
}
int ufs[maxn];
int find(int x){
  return x==ufs[x]?x:ufs[x]=find(ufs[x]);
}
bool cmp1(const int &x,const int &y){
  return a[x]<a[y];
}
bool cmp2(const int &x,const int &y){
  return b[x]<b[y];
}
void link(int a,int b){
  ufs[find(a)]=find(b);
}
int work(){
  check();
  bool flag=true;
  for(int i=1;i<=n;++i)if(a[i]!=b[i])flag=false;
  if(flag)return 1;
  int cnt=0;
  for(int i=1;i<=n;++i)if(a[i]!=b[i])seq[++cnt]=i;
  sort(seq+1,seq+cnt+1,cmp1);
  int old=-1,tot=0;
  for(int i=1;i<=cnt;++i){
    if(old!=a[seq[i]]){
      old=a[seq[i]];++tot;
    }
    a[seq[i]]=tot;
  }
  old=-1;tot=0;
  sort(seq+1,seq+cnt+1,cmp2);
  for(int i=1;i<=cnt;++i){
    if(old!=b[seq[i]]){
      old=b[seq[i]];++tot;
    }
    b[seq[i]]=tot;
  }
  for(int i=1;i<=tot;++i)ufs[i]=i;
  for(int i=1;i<=cnt;++i){
    link(a[seq[i]],b[seq[i]]);
  }
  int ans=0;
  for(int i=1;i<=tot;++i)if(ufs[i]==i)ans++;
  return ans+res;
}
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;++i)scanf("%d",a+i);
  for(int i=1;i<=n;++i)scanf("%d",b+i);
  for(int i=1;i<=n;++i)c[i]=a[i],d[i]=b[i];
  c[n+1]=0;for(int i=1;i<=n;++i)c[n+1]^=c[i];
  int tmp=c[n+1];
  sort(d+1,d+n+1);sort(c+1,c+n+2);
  if(eq())printf("0\n");
  else{
    if(nosolu())printf("-1\n");
    else{
      int cnt=0;bool flag=false;
      for(int i=1;i<=n;++i){
	if(a[i]!=b[i]){
	  cnt++;if(b[i]==tmp)flag=true;
	}
      }
      if(flag)printf("%d\n",cnt+work()-1);
      else printf("%d\n",cnt+work());
    }
  }
  return 0;
}


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

using namespace std;
typedef pair<double, int> P;
typedef pair<P, int> PP;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<double> VD;
typedef vector<VD> VVD;

int main(void) {
	int n, m, p, a, b;
	cin >> n >> m >> p >> a >> b;
	if (!(n || m || p || a || b)) {
		return 0;
	}
	vector<int> t(n);
	for (int i = 0; i < n; i++) {
		cin >> t[i];
	}
	VV r(m, V(m, -1));
	for (int i = 0; i < p; i++) {
		int x, y;
		cin >> x >> y;
		cin >> r[--x][--y];
		r[y][x] = r[x][y];
	}
	VVD d(m, VD(1 << n, INT_MAX / 6));
	priority_queue<PP, vector<PP>, greater<PP> > q;
	d[--a] = VD(1 << n, 0);
	q.push(PP(P(0, 0), a)); // コスト, 馬車券, 現在地
	double ans = INT_MAX / 6;
	while (q.size()) {
		PP top = q.top();
		q.pop();
		double cost = top.first.first;
		int use = top.first.second;
		int curr = top.second;
		if (d[curr][use] < cost) {
			continue;
		}
		if (curr == b - 1 && cost < ans) {
			ans = cost;
		}
		for (int i = 0; i < m; i++) { // 次に行く場所
			if (~r[curr][i]) { // 道路があるとき
				for (int j = 0; j < n; j++) { // 馬車券
					if (((use >> j) & 1) == 0) { // まだ残っていれば
						double ncost = cost + (double)r[curr][i] / t[j];
						int nuse = use | (1 << j);
						if (ncost < d[i][nuse]) {
							d[i][nuse] = ncost;
							q.push(PP(P(ncost, nuse), i));
						}
					}
				}
			}
		}
	}
	if (ans == INT_MAX / 6) {
		puts("Impossible");
	} else {
		printf("%.4f\n", ans);
	}
	return main();
}

Measured memory_bytes: 5044
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

lengths = list(sorted(map(int, input().split())))
print(lengths[0] * lengths[1] // 2)



Measured memory_bytes: 7624
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String[] inputs = sc.nextLine().split(" ");
		sc.close();

		Deque<Integer> dq = new ArrayDeque<>();

		for(String val : inputs) {

			if(isInt(val)) {
				int num = Integer.parseInt(val);
				dq.push(num);
			} else {
				calc(dq, val);
			}
		}

		System.out.println(dq.pop());

	}

	private static void calc(Deque<Integer> dq, String val) {

		char ope = val.charAt(0);
		int b = dq.pop();
		int a = dq.pop();

		switch (ope) {
		case '+':
			dq.push(a + b);
			break;
		case '-':
			dq.push(a - b);
			break;
		case '*':
			dq.push(a * b);
			break;
		default:
			break;
		}

	}

	private static boolean isInt(String val) {

		try {
			Integer.parseInt(val);
			return true;
		} catch (NumberFormatException e) {
			return false;
		}
	}

}

Measured memory_bytes: 26120
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=100000+10;

int n,m=0,x[N],y[N],Sx[N],Sy[N];

struct edge { int u,v,w; } e[N<<2];

int f[N*3];
int find(int x) { return x==f[x]?x:f[x]=find(f[x]); }

ll Kruskal() {
	sort(e+1,e+m+1,[](edge a,edge b) { return a.w<b.w; });
	for (int i=1;i<=n*3;++i) f[i]=i;
	ll ans=0;
	for (int i=1;i<=m;++i) {
		int u=find(e[i].u),v=find(e[i].v),w=e[i].w;
		if (u!=v) ans+=w,f[u]=v;
	}
	return ans;
}

int main() {
	n=read();
	for (int i=1;i<=n;++i) Sx[i]=x[i]=read(),Sy[i]=y[i]=read();
	sort(Sx+1,Sx+n+1); int cx=unique(Sx+1,Sx+n+1)-Sx-1;
	sort(Sy+1,Sy+n+1); int cy=unique(Sy+1,Sy+n+1)-Sy-1;
	for (int i=1;i<=n;++i) {
		x[i]=lower_bound(Sx+1,Sx+cx+1,x[i])-Sx;
		y[i]=lower_bound(Sy+1,Sy+cy+1,y[i])-Sy;
		e[++m]=(edge){i,x[i]+n,0};
		e[++m]=(edge){i,y[i]+n+cx,0};
	}
	for (int i=1;i<cx;++i) e[++m]=(edge){i+n,i+n+1,Sx[i+1]-Sx[i]};
	for (int i=1;i<cy;++i) e[++m]=(edge){i+n+cx,i+n+cx+1,Sy[i+1]-Sy[i]};
	printf("%lld\n",Kruskal());
	return 0;
}

Measured memory_bytes: 11172
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <bits/stdc++.h>
using namespace std;

int main(){
    int N; cin >> N;
    long long ans = 1;
    long long modu = 1000000007;
    
    for(int i = 1; i < N + 1; i++){
        ans *= i;
        ans = ans % modu;
    }
    
    cout << ans % modu << endl;
}




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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;
struct edge{int to, cost;};

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

int N, M;
vii adj;
vi color;

bool dfs(int v=0, int c=1){
    color[v]=c;
    for(auto nv : adj[v]){
        if(color[nv] == 0 && !dfs(nv, -c)) return false;
        if(color[nv] == c) return false;
    }
    return true;
}

int main(){
    cin >> N >> M;
    adj.resize(N);
    color.assign(N, 0);
    for(int i=0; i<M; i++){
        int a, b; cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    ll ans;
    if(dfs()){
        int c1=0, c2=0;
        for(int i=0; i<N; i++){
            if(color[i] == 1) c1++;
            else c2++;
        }
        ans=(ll)N*(N-1)/2-(ll)c1*(c1-1)/2-(ll)c2*(c2-1)/2-M;
    }
    else ans=(ll)N*(N-1)/2-M;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9516
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}




int main(void) {
  ll L, R;
  cin >> L >> R;
  
  if(R-L>=2018) {
    pt(0);
  }else {
    ll i, j;
    ll ans=INF;
    for(i=L; i<R; i++) {
      for(j=i+1; j<=R; j++) {
        chmin(ans, i*j%2019);
      }
    }
    
    pt(ans);
  }
  
}


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

int main(){
    int k;
	char ch[100];
	int i;
	
	scanf("%d",&k);
	scanf("%s",ch);

	int n = strlen(ch);

	if(n<= k){
	printf("%s",ch);
}
    else {
		for(i=0;i<=k-1;i++){
			printf("%c",ch[i]);
		}
      	    printf("...");
	}

}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;


bool can_MM(string s){
  int x = stoi(s);
  if((x >= 1) && (x <= 12)) return true;
  else return false;
}

int main(){
  string S;
  cin >> S;

  string s1 = S.substr(0, 2);
  string s2 = S.substr(2, 2);

  bool m1 = can_MM(s1);
  bool m2 = can_MM(s2);

  string ret;
  if(!m1 && !m2) {
    ret = "NA";
  }else if(m1 && m2) {
    ret = "AMBIGUOUS";
  }else if(!m1 && m2) {
    ret = "YYMM";
  }else{
    ret = "MMYY";
  }

  cout << ret << endl;

  return 0;
}



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

using namespace std;

typedef long long ll;

int main()
{
    int n;

    cin >> n;

    int counter[4] = {0};

    for(int i = 0; i < n; i++)
    {
        string verdict;

        cin >> verdict;

        if(verdict == "AC")
        {
            counter[0]++;
        }
        else if(verdict == "WA")
        {
            counter[1]++;
        }
        else if(verdict == "TLE")
        {
            counter[2]++;
        }
        else
        {
            counter[3]++;
        }
    }

    cout << "AC x " << counter[0] << endl;
    cout << "WA x " << counter[1] << endl;
    cout << "TLE x " << counter[2] << endl;
    cout << "RE x " << counter[3] << endl;

    return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}

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


    int n;
    cin >> n;
    cout << (n+1)/2 << '\n';
    
    


    
    
    return 0;
}


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

int main(){
    string str; cin >> str;
    vector<int> v(str.length());
    v.assign(str.length(), 0);
    for(int i = 0; i < str.length(); i++){
        if(str[i] == 'L'){
            int j = i;
            while(str[i] == 'L'){
                i++;
            }
            v[j - 1] += (i - j) / 2; 
            v[j] += (i - j) - (i - j) / 2;
        }else{
            int j = i;
            while(str[i] == 'R'){
                i++;
            }
            v[i] += (i - j) / 2; 
            v[i - 1] += (i - j) - (i - j) / 2;
        }
        i--;
    }

    for(auto x : v){
        cout << x << " ";
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
 
using namespace std;
long long n,p,maxx=1,dem=0;
 
void input()
{
	cin>>n>>p;
}
 
void output()
{
	cout<<maxx;
}
 
void kt(long long x)
{
	if (x<4) return;
	long long y=x;
	for (long i=2; i*i<=x; i++)
	{
		if (y==1) return;
		dem=0;
		while (y%i==0)
		{
			y=y/i;
			dem++;
		}
		if (dem/n>0) 
		for (int j=1; j<=dem/n; j++) maxx*=i;
	}
}
 
void fin()
{
	if (n==1) 
	{
		maxx=p;
		return;
	}
	kt(p);
}
 
main()
{
//	freopen("TEST.INP","r",stdin);
//	freopen("TEST.OUT","w",stdout);
	input();
	fin();
	output();
	return 0;
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	pair<long double, long double> a[3000];
	for (int i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].second = 1 - a[i].first;
	}

	vector<vector<long double>> dp(n + 1, vector<long double>(n + 1));
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		dp[i][0] = dp[i - 1][0] * a[i - 1].second;
		for (int j = 1; j <= n; j++) {
			dp[i][j] += dp[i - 1][j - 1] * a[i - 1].first;
			dp[i][j] += dp[i - 1][j] * a[i - 1].second;
		}
	}
	long double ans = 0;
	for (int i = n / 2 + 1; i <= n; i++) {
		ans += dp[n][i];
	}
	printf("%.12Lf\n", ans);

	return 0;
}

Measured memory_bytes: 144296
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    h, w = map(int, input().split())
    col = [[0, w + 1] for _ in range(h)]
    row = [[0, h + 1] for _ in range(w)]
    for i in range(h):
        s = list(input()[:-1].decode())
        for j in range(w):
            if s[j] == '#':
                col[i].append(j + 1)
                row[j].append(i + 1)

    cc = [[0] * (w + 2) for _ in range(h)]
    rc = [[0] * (h + 2) for _ in range(w)]

    for i in range(h):
        col[i].sort()
        for j in range(len(col[i]) - 1):
            cc[i][col[i][j] + 1:col[i][j + 1]] = [col[i][j + 1] - col[i][j] - 1] * (col[i][j + 1] - col[i][j] - 1)

    for i in range(w):
        row[i].sort()
        for j in range(len(row[i]) - 1):
            rc[i][row[i][j] + 1:row[i][j + 1]] = [row[i][j + 1] - row[i][j] - 1] * (row[i][j + 1] - row[i][j] - 1)

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, cc[i][j + 1] + rc[j][i + 1] - 1)

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 204936
#include<stdio.h>
int main(void)
{
  int A,B;
  int n=0;
  int result=0;
  
  
  scanf("%d %d",&A,&B);
  while(n<2){
    if(A>B){
      result+=A;
      A-=1;
    }
    else{
      result+=B;
      B-=1;
    }
    n++;
  } 
  printf("%d",result);
  return 0;
}

Measured memory_bytes: 128
Public Class Main
    Public Shared Sub Main()
        Dim arr() As Integer = sc.IntArr()
        Dim A() As Integer = sc.IntArr()
        Dim H As Integer = arr(0)
        Dim N As Integer = arr(1)
        Dim accum As Integer = 0
        For i As Integer = n - 1 To 0 Step -1
          accum += A(i)
        Next
        Console.WriteLine(If(accum < h, "No", "Yes"))
    End Sub
End Class

' FastScanner start
Public Class sc
    Public Shared Function Str() As String
        Return Console.ReadLine().Trim()
    End Function
    Public Shared Function Int() As Integer
        Return Integer.Parse(Str())
    End Function
    Public Shared Function Lng() As Long
        Return Long.Parse(Str())
    End Function
    Public Shared Function Dbl() As Double
        Return Double.Parse(Str())
    End Function
    Public Shared Function StrArr(Optional separator As String = " ") As String()
        Return Str().Split(separator)
    End Function
    Public Shared Function IntArr(Optional separator As String = " ") As Integer()
        Return Array.ConvertAll(Of String, Integer)(StrArr(separator), AddressOf Integer.Parse)
    End Function
    Public Shared Function LngArr(Optional separator As String = " ") As Long()
        Return Array.ConvertAll(Of String, Long)(StrArr(separator), AddressOf Long.Parse)
    End Function
    Public Shared Function DblArr(Optional separator As String = " ") As Double()
        Return Array.ConvertAll(Of String, Double)(StrArr(separator), AddressOf Double.Parse)
    End Function
End Class
' FastScanner end

Measured memory_bytes: 16480
n = int(input())
P =[]
s = 0
for _ in range(n):P += [[int(i) for i in input().split()]]
for j in range(n-1):s += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0]
s += P[-1][0]*P[0][1] - P[-1][1]*P[0][0]
print(s*0.5)

Measured memory_bytes: 7724
import sys

n, k = [int(i) for i in sys.stdin.readline().split()]
a_ls = []
MOD = 10**9+7
for i in range(n):
    a_ls.append([int(i) for i in sys.stdin.readline().split()])


def matmul(a, b):
    x = len(a)
    res = [[0 for i in range(x)]for j in range(x)]
    for i in range(x):
        for j in range(x):
            for k in range(x):
                res[i][j] += (a[i][k] * b[k][j])
            res[i][j] %= MOD
    return res

def power(a, n):
    x = len(a)
    res = a
    for i in range(n - 1):
        res = matmul(res, a)
    return res

def plus(a, b):
    x = len(a)
    res = [[0 for i in range(x)]for j in range(x)]
    for i in range(x):
        for j in range(x):
            res[i][j] = (a[i][j] + b[i][j]) % MOD
    return res

k_2 = bin(k)[2:][::-1]
base = a_ls
res = [[1 if i == j else 0 for i in range(n)]for j in range(n)]
for ind, _k in enumerate(k_2):
    if _k == "1":
        res = matmul(res, base)
    base = power(base, 2)
print(sum([sum(i) % MOD for i in res]) % MOD)

Measured memory_bytes: 70492
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

void Str2Year(char* str, int& year, int& month, int& day)
{
	char* tp;
	tp = strtok(str, "/");
	year = atoi( tp );

	tp = strtok(NULL, "/");
	month = atoi(tp);

	tp = strtok(NULL, "/");
	day = atoi(tp);
}



int main(void)
{
	int N = 0;
	double x;
	char u[4] = { 0 };
	double sum = 0;

	scanf("%d", &N);

	for (int cnt = 0; cnt < N; cnt++)
	{
		scanf("%lf %s", &x, u);
		if (0==strcmp(u, "JPY"))
		{
			sum += x;
		}
		else
		{
			sum += x * 380000.0;
		}
	}
	printf("%f", sum);
	printf("\n");

	return 0;
}

Measured memory_bytes: 128
from math import *
from collections import defaultdict
GLOBAL = {}
def roots(n):
	res = set()
	for i in range(1,int(sqrt(n))+1):
		if n%i == 0:
			res.add(i)
			res.add(n//i)
	return len(res)

n = int(input())
cnt = 0
for i in range(1,n+1):
	y = n//i
	cnt+=((y)*(y+1)*(i))//2
print(cnt)


Measured memory_bytes: 66728
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll N, M; cin >> N >> M;
    vll A(N); rep(i, N) cin >> A[i];
    sort(all(A));
    map<ll, ll, greater<ll>> mp;
    rep(i, M) {
        ll b, c; cin >> b >> c;
        mp[c] += b;
    }

    //for (auto elem : mp) {
    //    cout << elem.first << " " << elem.second << endl;
    //}

    auto iter = mp.begin();
    rep(i, N) {
        ll value = (*iter).first;

        if (A[i] >= value) {
            break;
        }
        A[i] = value;
        (*iter).second--;

        if ((*iter).second == 0) iter++;
        if (iter == mp.end()) break;
    }

    ll total = accumulate(all(A), 0ll);
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 8960
import java.math.BigDecimal;
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int N = Integer.parseInt(sc.next());
        BigDecimal[] A = new BigDecimal[N];
        
        for (int i = 0; i < A.length; i++)
        {
            A[i] = sc.nextBigDecimal();
        }
        
        BigDecimal ans = BigDecimal.ONE;
        BigDecimal tmp = new BigDecimal("1000000000000000000");
        
        for (int i = 0; i < A.length; i++)
        {
            if (A[i].compareTo(BigDecimal.ZERO) == 0)
            {
                System.out.println("0");
                sc.close();
                return;
            }
        }
        
        for (int i = 0; i < A.length; i++)
        {
            if (A[i].compareTo(tmp) == 1 || ans.compareTo(tmp) == 1)
            {
                System.out.println("-1");
                sc.close();
                return;
            }
            else
            {
                ans = ans.multiply(A[i]);
            }
        }
        
        if (ans.compareTo(tmp) == 1)
        {
            System.out.println("-1");
            sc.close();
            return;
        }
        else
        {
            System.out.println(ans);
            sc.close();
            return;
        }
    }
}


Measured memory_bytes: 55216
#include <stdio.h>

int main()
{
  int a, b, c, d, n;
  int i, j, k, l;
  int ans = 0;

  while(scanf("%d", &n) != EOF){
    for(i = 0; i < 10; i++){
      for(j = 0; j < 10; j++){
        for(k = 0; k < 10; k++){
          for(l = 0; l < 10; l++){
            if(i + j + k + l == n) ans++;
          }
        }
      }
    }

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

    ans = 0;
  }

  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#define ll long long
#define rep(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n, 0), vv(n, 0);
  rep(i, 0, m) {
    int a;
    cin >> a;
    a--;
    string s;
    cin >> s;
    if(vv[a] == 0) {
      if(s == "AC") vv[a] = 1;
      else v[a]++;
    }
  }
  int sump = 0, suma = 0;
  rep(i, 0, n) {
    if(vv[i] == 1) sump += v[i];
    suma += vv[i];
  }
  cout << suma << " " << sump << "\n";
}

Measured memory_bytes: 4000
def bubble_sort(A, N):
    flag = True
    exchange_count = 0
    while flag:
        flag = False
        for j in reversed(range(1,N)):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = True
                exchange_count += 1
    print(*A)
    print(exchange_count)

N = int(input())
A = list(map(int, input().split()))
bubble_sort(A,N)


Measured memory_bytes: 5604
#define _USE_MATH_DEFINES // for C++  
#include <cmath> 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <functional>
#include <bitset>
#define LL long long

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    cout << v.back() - v.front() << endl;
} 

Measured memory_bytes: 256
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize ("Ofast,unroll-loops,-ffloat-store,no-stack-protector")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

string to_string(const string& s) { return '"' + s + '"'; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
    #define debug(...) cout << "#" << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 3
#endif
 
#define cin_exception cin.exceptions(cin.failbit);
#define cout_precision cout.setf(ios::fixed); cout.precision(15);
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using ld = long double;  using ui = uint_fast32_t;
using ll = int_fast64_t; using ul = uint_fast64_t;

// -----------------------------------------------------------------------------

void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int a; cin >> a;
        n -= a;
    }
    if (n < 0) cout << -1 << '\n';
    else cout << n << '\n';
}

// -----------------------------------------------------------------------------

int main() {
    fast_io; cout_precision;
#ifdef LOCAL
    cin_exception;
#endif
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }
}

Measured memory_bytes: 3644
inversion = 1 #1 は反転していない、 -1 は反転している。
s = input()
s1 = ""
s2 = ""
n_query = int(input())
for i in range(n_query):
    q = input().split()
    
    if q[0] == '1':
        inversion *= -1
    elif q[0] == '2':
        if inversion == 1:
            if q[1] == '1':
                s1 = s1 + q[2]
            elif q[1] == '2':
                s2 = s2 + q[2]
        elif inversion == -1:
            if q[1] == '1':
                s2 = s2 + q[2]
            elif q[1] == '2':
                s1 = s1 + q[2]

if inversion == 1:
    s = s1[::-1] + s + s2
elif inversion == -1:
    s = s2[::-1] + s[::-1] + s1

print(s)

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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------

int main() {
    ll I, O, T, J, L;
    cin >> I >> O >> T >> J >> L;
    ll ans1 = O, ans2 = O; //0じゃなくてO
    ans1 += I / 2 * 2 + J / 2 * 2 + L / 2 * 2;
    if (min({I, J, L}) > 0) {
        ans2 += 3;
        I--, J--, L--;
    }
    ans2 += I / 2 * 2 + J / 2 * 2 + L / 2 * 2;
    cout << max(ans1, ans2) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int alp[26];
int main(){
  int h,w;cin>>h>>w;
  for(int i = 0; h > i; i++){
    for(int j = 0; w > j; j++){
      char z;cin>>z;
      alp[z-'a']++;
    }
  }
  int four = 0;
  int two = 0;
  int one = 0;
  for(int i = 0; 26 > i; i++){
    four += alp[i]/4;
    alp[i]%=4;
    two += alp[i]/2;
    alp[i]%=2;
    one += alp[i];
  }
  if((h/2)*(w/2) <= four){
    four -= (h/2)*(w/2);
    two += four*2;
  }else{
    cout << "No" << endl;
    return 0;
  }
  if((h%2) || (w%2)){
    if((h*w-((h/2)*(w/2))*4)/2 <= two){
      two -= (h*w-((h/2)*(w/2))*4)/2;
      one += two*2;
    }else{
      cout << "No" << endl;
      return 0;
    }
    if(h%2 && w%2){
      if(1 != one){
        cout << "No" << endl;
        return 0;
      }
    } 
  }
  cout << "Yes" << endl;
}


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

int main() {
  int N,H;
  cin >> N;
  int max=0;
  for (int i=0;i<N;i++) {
    cin >> H;
    if (H>max) max=H;
    else if (H<max-1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define forin(x,n) for(auto& (x) : n)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define inf 1000000000
#define llinf 1000000000000000
#define MAX 1000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;
typedef pair<int,pint> P;


int main(){
    int n,m;
    cin>>n>>m;
    vint k(m);
    vint p(m);
    vector<vector<int>> s(m);
    rep(i,m){
        cin>>k[i];
        rep(j,k[i]){
            int x;
            cin>>x;
            s[i].pb(x-1);
        }
    }
    rep(i,m)cin>>p[i];
    int ans=0;
    rep(i,1<<n){
        rep(j,m){
            int sum=0;
            rep(j2,k[j]){
                int num=(i>>s[j][j2])%2;
                sum+=num;
            }
            if(sum%2!=p[j])break;
            if(j==m-1)ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

int main(void) {
    string N;
    int K;
    cin >> N >> K;
    
    if(K == 1) {
        cout << 9 * (N.size()-1) + stoi(N.substr(0, 1)) << endl;
    } else if(K == 2) {
        int64_t ans = 0;
        for(int i=2; i<N.size(); i++) {
            ans += 9 * 9 * (i-1);
        }
        ans += (stoi(N.substr(0, 1)) - 1) * 9 * (N.size()-1);
        string cp = N;
        for(int i=1; i<cp.size(); i++) {
            cp[i] = '0';
        }
        for(int i=1; i<cp.size(); i++) {
            for(int j=1; j<10; j++) {
                cp[i] = '0'+j;
                if(cp <= N) {
                    ++ans;
                }
                cp[i] = '0';
            }
        }
        cout << ans << endl;
    } else {
        if(N.size() < 3) {
            cout << 0 << endl;
            return 0;
        }
        int64_t ans = 0;
        for(int i=3; i<N.size(); i++) {
            ans += 9 * 9 * 9 * (i-1) * (i-2) / 2;
        }
        ans += (stoi(N.substr(0, 1)) - 1) * 9 * 9 * (N.size()-1) * (N.size()-2) / 2;
        string cp = N;
        for(int i=1; i<cp.size(); i++) {
            cp[i] = '0';
        }
        for(int i=1; i<cp.size(); i++) {
            for(int j=i+1; j<cp.size(); j++) {
                for(int k=1; k<10; k++) {
                    for(int l=1; l<10; l++) {
                        cp[i] = '0' + k;
                        cp[j] = '0' + l;
                        if(cp < N) {
                            ++ans;
                        }
                        cp[i] = '0';
                        cp[j] = '0';
                    }
                } 
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long li;


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

    li n, m, l;
    cin >> n >> m >> l;

    const li inf = 1LL << 58;
    vector<vector<li>> g(n, vector<li>(n, inf));
    for (int i = 0; i < n; ++i) {
        g[i][i] = 0;
    }
    for (int i = 0; i < m; ++i) {
        li a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        g[a][b] = g[b][a] = c;
    }

    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }

    vector<vector<li>> gg(n, vector<li>(n, inf));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (g[i][j] <= l) {
                gg[i][j] = 1;
            }
        }
    }

    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                gg[i][j] = min(gg[i][j], gg[i][k] + gg[k][j]);
            }
        }
    }

    li q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        li s, t;
        cin >> s >> t;
        s--; t--;
        li ans = gg[s][t];
        if (ans >= inf) {
            cout << -1 << endl;
        } else {
            cout << ans - 1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2048
n,q=map(int,input().split())
s=input()
i=1
dp=[0 for i in range (n)]
while(i<n):
	if(s[i-1]=='A' and s[i]=='C'):
		dp[i]=dp[i-1]+1
	else:
		dp[i]=dp[i-1]
	i+=1
i=0
# print(dp)

while(i<q):
	l,r=map(int,input().split())
	print(dp[r-1]-dp[l-1])
	i+=1

Measured memory_bytes: 6180
#include <stdio.h>
int main(){
    int a;
    scanf("%d",&a);
    int p,h,m;
    m=a%60;
    h=(a-m)/60;
    p=h/60;
    h=h%60;
    
    printf("%d:%d:%d\n",p,h,m);
    return 0;
}


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

int main(void) {
	int N; cin >> N;
	int i, j = 1;
	if (N <= 3) {
		cout << "No" << endl;
		return 0;
	}
	else {
		for (i = 0; i <= N; i += 4) {
			for (j = 0; j <= N; j += 7) {
				if (N - (i + j) == 0) {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}

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



Measured memory_bytes: 256
n = int(input())
S = list(map(int,input().split())) #2分探索するリスト
q = int(input())
T = list(map(int,input().split()))

ans = 0

for item in T:
    low = 0
    high = len(S)-1
    while low <= high:
        mid = (low+high)//2
        guess = S[mid]
        if guess == item:
            ans += 1
            break
        elif guess > item:
            high = mid -1
        else:
            low = mid +1
print(ans)


Measured memory_bytes: 16708
from bisect import bisect_right
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

power = 1
powers = [1]
while power <= 10 ** 9:
    power *= 2
    powers.append(power)

a.sort()
c = Counter(a)

ans = 0
for e in a[::-1]:
    i = bisect_right(powers, e)
    target = powers[i]

    if target == 2 * e:
        if c[e] >= 2:
            c[e] -= 2
            ans += 1

    else:
        if c[e] and c[target-e]:
            c[e] -= 1
            c[target-e] -= 1
            ans += 1

print(ans)


Measured memory_bytes: 33296
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
const ll inf = 100100100100100;

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

vector<ll> dijkstra(int s, vector< vector<pair<int,ll>>> l, int v){
    vector<ll> dist; rep(i,0,v) dist.push_back(inf); dist[s] = 0;
    priority_queue< pair<int, ll>,vector<pair<int, ll>>,greater<pair<int, ll>>> que; que.push(make_pair(0,s));

    while(!que.empty()){
        pair<int,ll> p = que.top(); que.pop();
        int vertex = p.second;
        if(dist[vertex] < p.first) continue;
        rep(i,0,l[vertex].size()){
            pair<int,ll> to = l[vertex][i];
            if(dist[to.second] > dist[vertex] + to.first){
                dist[to.second] = dist[vertex] + to.first;
                que.push(make_pair(dist[to.second],to.second));
            }
        }
    
    }
    return dist;
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    
   int n,m,s,t;
   cin >> n >> m >> s >> t;
   s--; t--;

   vector< vector< pair<int,ll> > >yen(n);
   vector< vector< pair<int,ll> > >snuuk(n);

   rep(i,0,m){
       int frm,to,a,b;
       cin >> frm >> to >> a >> b;
        frm--; to--;
        yen[frm].push_back(make_pair(a,to));
        yen[to].push_back(make_pair(a,frm));
        snuuk[frm].push_back(make_pair(b,to));
        snuuk[to].push_back(make_pair(b,frm));
   }

   vector<ll> y_cost = dijkstra(s,yen,n);
   vector<ll> s_cost = dijkstra(t,snuuk,n);

   vector<ll> sumcost;
   rep(i,0,n) {
       sumcost.push_back(y_cost[i] + s_cost[i]);
   }
   
   int i = n-2;
   while(i > -1){
       sumcost[i] = min(sumcost[i], sumcost[i+1]);
       i--;
    }
    rep(i,0,n) cout << 1000000000000000 - sumcost[i] << endl;
   
 
}



Measured memory_bytes: 27244