akhauriyash/Code-Regression huggingface dataset:
import scala.io.StdIn

object Main {
  case class Path(x: Int, y: Int, length: Int)
  case class Edge(to: Int, length: Int)

  def main(args: Array[String]): Unit = {
    while(true) {
      val n :: m :: p :: a :: b :: _res = StdIn.readLine().split(" ").map(_.toInt).toList
      if(n == 0) { return; }

      val ts = StdIn.readLine().split(" ").map(_.toInt).toList
      val paths:List[Path] = (0 until p).toList.map{ _ =>
        val x :: y :: z :: _res = StdIn.readLine().split(" ").map(_.toInt).toList
        Path(x, y, z)
      }

      println(solve(ts, paths, m, a, b).map(x => "%.3f".format(x)).getOrElse("Impossible"))
    }
  }

  def solve(ts: List[Int], paths: List[Path], numCity: Int, start: Int, end: Int): Option[Double] = {
    val cities:List[Int] = (1 to numCity).toList

    val edges = paths.flatMap{ case p@Path(x, y, l) => List(p, Path(y, x, l)) }

    val tickets = ts.toArray
    val ticketIndex = (0 until ts.size).toArray
    val n = ts.size
    val dp = Array.fill(numCity+1, 1 << n)(Double.MaxValue)

    dp(start)(0) = 0

    for {
      ticketUsed <- 0 until (1 << n)
      edge <- edges
      ticketUsing <- 0 until n
    } {
      if((ticketUsed & 1 << ticketUsing) > 0) {
  
        val current = dp(edge.y)(ticketUsed)
        val updating = dp(edge.x)(ticketUsed & ~(1 << ticketUsing)) + edge.length.toDouble / tickets(ticketUsing)
        if(current > updating) {
          dp(edge.y)(ticketUsed) = updating
        }
      }  
    }

    val ret = dp(end).min
    if(ret == Double.MaxValue) { None } else { Some(ret) }
  }
}



Measured memory_bytes: 60240
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  
  if (a < 0 || a > 100)
  {
    cout << "Invalid age" << endl;
    return 1;
  }
  else if (b % 2 != 0)
  {
    cout << "Invalid fare" << endl;
    return 1;
  }
  
  if (a >= 13)
  {
    cout << b << endl;
    return 0;
  }
  else if (a >= 6 && a <= 12)
  {
    cout << b / 2 << endl;
    return 0;
  }
  else
  {
    cout << 0 << endl;
    return 0;
  }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))
#define _max(x, y)(max(0, max((x), (y))))
#define _min(x, y)(max(0, min((x), (y))))

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;

typedef struct Node {
    int id;
    map<int, char> connects;
} Node;

bool canReach(Node *nodes, const int &n, const int &u, const int &v) {
    queue<int> q;
    map<int, char> table;
    int id;

    table[u] = 1;

    int i;

    for (i = 0; i < n; i++) {
        if (nodes[u].connects[i] == 1) {
            q.push(i);
            table[i] = 1;
        }
    }

    while (!q.empty()) {
        id = q.front();

        q.pop();

        if (id == v) return true;

        table[id] = 1;

        for (i = 0; i < n; i++) {
            if (nodes[id].connects[i] == 0) continue;

            if (table.find(i) == table.end()) {
                table[i] = 1;
                q.push(i);
            }
        }
    }

    return false;
}

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;

    cin >> n >> m;

    Node nodes[n];
    int a, b;
    int ans = 0;
    map<pair<int, int>, char> table;
    pair<int, int> p;
    int u, v;

    int i, j;

    for (i = 0; i < n; i++) {
        nodes[i].id = i;

        for (j = 0; j < n; j++) nodes[i].connects[j] = 0;
    }

    for (i = 0; i < m; i++) {
        cin >> a >> b;

        a--;
        b--;

        nodes[a].connects[b] = 1;
        nodes[b].connects[a] = 1;
    }

    for (i = 0; i < n; i++) {
        u = nodes[i].id;

        for (j = 0; j < n; j++) {
            if (nodes[i].connects[j] == 0) continue;

            v = j;

            nodes[u].connects[v] = 0;
            nodes[v].connects[u] = 0;

            if (!canReach(nodes, n, u, v)) {
                p.first = min(u, v);
                p.second = max(u, v);

                if (table.find(p) == table.end()) {
                    ans++;

                    table[p] = 1;
                }
            }

            nodes[u].connects[v] = 1;
            nodes[v].connects[u] = 1;
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 384
while num = gets
  num = num.split().map(&:to_i).sort
  buf = num[0] * num[1]

  while num[1] % num[0] != 0
    temp = num[0]
    num[0] = num[1] % num[0]
    num[1] = temp
  end

  num[1] = buf / num[0]

  puts "#{num[0]} #{num[1]}"
end

Measured memory_bytes: 6096
import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0:
  if zero >= 1 and k%2 == 1:
    ans = 0
  else:
    if k%2 == 1:
      minus.reverse()
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((len(plus)-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(len(minus)//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)

Measured memory_bytes: 31932
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);


    int h1, m1, h2, m2, K;
    cin >> h1 >> m1 >> h2 >> m2 >> K;

    auto count = [&](int h, int m) {
        return h * 60 + m;
    };

    int L = count(h1, m1);
    int R = count(h2, m2);

    R -= K + 1;
    int res = max(0, R - L + 1);

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 3556
# 与えられた数値の桁数と桁値の総和を計算する.
def calc_digit_sum(num):
    digits = sums = 0
    while num > 0:
        digits += 1
        sums += num % 10
        num //= 10
    return digits, sums


a, b = map(int, input().split())
if 1 <= a <= 9 and 1 <= b <= 9:
    print(a * b)
    exit()
print(-1)

Measured memory_bytes: 61408
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end() 
#define x first
#define y second

using namespace std;

typedef long long ll;
template <typename T> using V = vector <T>;

int main() {fio;
	int N;
	cin >> N;
	V <ll> A(N), cum(N);
	
	for(int i = 0; i < N; i++) {
		cin >> A[i];
		cum[i] = A[i];
		if(i) {
			cum[i] += cum[i - 1];
		}
	}
	V <V <ll>> DP(N, V <ll> (N + 1, 1e18));

	for(int sz = 1; sz <= N; sz++) {
		for(int i = 0; i + sz - 1 < N; i++) {
			if(sz == 1) {
				DP[i][sz] = 0;
				continue;
			}
			for(int sz0 = 1; sz0 < sz; sz0++) {
				int sz1 = sz - sz0;
				ll cost = cum[i + sz - 1];
				if(i) {
					cost -= cum[i - 1];
				}
				DP[i][sz] = min(DP[i][sz0] + DP[i + sz0][sz1] + cost, DP[i][sz]);
			}
		}
	}
	cout << DP[0][N];
	
    return 0;
}

Measured memory_bytes: 1536
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

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

		LinkedList<Process> processQueue = new LinkedList<Process>();

		int n = sc.nextInt();
		int quantum = sc.nextInt();
		for (int i = 0; i < n; i++) {
			processQueue.add(new Process(sc.next(), sc.nextInt()));
		}
		
		for (int spendTime = 0; !processQueue.isEmpty(); ) {
			Process run = processQueue.remove();
			if (run.pRemain > quantum) {
				run.pRemain -= quantum;
				processQueue.add(run);
				spendTime += quantum;
			} else if (run.pRemain == quantum) {
				run.pRemain -= quantum;
				spendTime += quantum;
				printProcess(run, spendTime);
			} else {
				spendTime += run.pRemain;
				run.pRemain = 0;
				printProcess(run, spendTime);
			}
		}
    	
        sc.close();
	}

	private static void printProcess(Process run, int eTime) {
		StringBuffer str = new StringBuffer();

		str.append(run.pName);
		str.append(" ");
		str.append(eTime);

		System.out.println(str);
	}
}

class Process {
	String pName;
	int pRemain;
	int eTime;
	
	Process(String name, int time) {
		pName = name;
		pRemain = time;
		eTime = 0;
	}
}

Measured memory_bytes: 65684
#include <iostream>
  #include <string>
  #include <vector>
  #include <algorithm>
  #include <utility>
  #include <map> 
  using namespace std;
  typedef long long ll;
  #define rep(i,n) for (int i=0;i < (int)(n);i++)
  
  
  int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    map<int,int> mp;
    rep(i,n) {
      cin >> v[i];
      mp[v[i]]++;
    }
    int ans = 0;
    rep(i,n){
      int num = v[i];
      vector<int> div;
      for (int h = 2; h*h <= num; h++){
        if (num%h == 0){
          div.push_back(h);
          div.push_back(num/h);
        }
      }
      div.push_back(num);
      div.push_back(1);
      bool can = true;
      rep(j,div.size()){
        if (mp.count(div[j])){
          can = false;
          if (div[j] == num && mp[num] == 1) {
            can = true;
            continue;
          }
          break;
        }
      }
      if (can) ans++;
    }
    cout << ans << endl;

    
      

    
    return 0;
  }


Measured memory_bytes: 13492
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>


using namespace std;

int main(){

	int A[3];

	cin >> A[0] >> A[1] >> A[2];

	sort(A, A+3);

	cout << A[0]*A[1]/2 << endl;

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef ONLINE_JUDGE
#define trace(...)
#endif

using LL = long long;

const int N = 1e5 + 10, MOD = 1e9 + 7;
int a[N], b[N];
LL dp[N][13];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	string s; cin >> s;
	int n = s.size();
	dp[0][0] = 1;
	int p = 1;
	for (int i = 1; i <= n; i++) {
		int x = s[n - i] == '?' ? -1 : s[n - i] - '0';
		for (int s = 0; s < 13; s++) {
			for (int d = 0; d <= 9; d++) {
				if (x != d && x != -1) continue; 
				dp[i][(s + d * p) % 13] += dp[i - 1][s];
			}
		}
		for (int s = 0; s < 13; s++) {
			dp[i][s] %= MOD;
		}
		p = (p * 10) % 13;
	}
	cout << dp[n][5] << endl;

	return 0;
}


Measured memory_bytes: 10704
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

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

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}


int main(){

    ll N;
    
    cin >> N;
    ll n=N;
    ll i=2;
    map<ll,ll> map{};
    ll maxv = 0;
    while(true) {
        if(N%i==0) {
            ll tmp = i;
            while(N%i==0) {
                if(map[i]==0)map[i]=1;
                else map[i]++;
                N /= i;
            }
        }
        i++;
        if(i*i > N){
            if(N != 1 && N != 0)map[N]++;
            break;
        }
    }
    ll ans = 0;

    for(auto itr = map.begin(); itr!= map.end(); ++itr) {
        ll tmp = itr->second;
        ll j=0;
        while(true) {
            j++;
            if(tmp<j)break;
            tmp -= j;
            ans++;
        }
    }

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

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,a,b;
  cin>> n >>a>>b;
  long long int ans = n/(a+b)*a;
  long long int rem = n%(a+b);
  ans+= min(rem,a);
    
    cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

const int Nmax = 40, ABmax = 10;

int a[Nmax], b[Nmax], c[Nmax];
int dp[Nmax + 1][Nmax * ABmax + 1][Nmax * ABmax + 1];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;
	rep(i, 0, N) cin >> a[i] >> b[i] >> c[i];


	rep(i, 0, Nmax + 1) rep(j, 0, Nmax * ABmax + 1) rep(k, 0, Nmax * ABmax + 1) dp[i][j][k] = 1e9;

	
	dp[0][0][0] = 0;

	rep(i, 0, N) {
		rep(j, 0, N * 10 + 1) {
			rep(k, 0, N * 10 + 1) {
				dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
				if(j - a[i] >= 0 && k - b[i] >= 0) {
					dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
				}
			}
		}
	}
	
	int ans = 1e9;
	rep(i, 1, N * 10 + 1) rep(j, 1, N * 10 + 1) if(i * Mb == j * Ma) ans = min(ans, dp[N][i][j]);

	if(ans == 1e9) cout << -1 << endl;
	else cout << ans << endl;

}


Measured memory_bytes: 25984
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0), cout.precision(15);
    int A, B, T; // 1 20
    cin >> A >> B >> T;
    cout << B * (T / A) << endl;
    return 0;
}


Measured memory_bytes: 256
a, b, c, x = [int(input()) for _ in range(4)]

# print(a, b, c, x)
ans = 0

for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if x == 500 * i + 100 * j + 50 * k:
                ans += 1
        # if 0 <= 50 * c <= x - (500 * i + 100 * j):
        #     ans += 1
print(ans)


Measured memory_bytes: 2940
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,m=parseMap(split(readline()))
    city=[0 for i in 1:n]
    for i in 1:m
        a,b=parseMap(split(readline()))
        city[a]+=1
        city[b]+=1
    end
    for i in city
        println(i)
    end
end
main()

Measured memory_bytes: 172508
#include <stdio.h>

int main(void)
{
	int a,b,t;
	
	int i;
	
	scanf("%d %d %d",&a,&b,&t);
	
	double time = t + 0.5;
	
	int sum = 0;
	
	for(i = 1; time > a * i; i++){
		sum = sum + b;
	}
	
	printf("%d\n",sum);
	
	return 0;
	
}	

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

using namespace std;

int yoko[1010][110][110];

int main(void) {
    int n, m, a;
    while (cin >> n >> m >> a, n) {
        memset(yoko, 0, sizeof yoko);
        int h, p, q;
        for (int i = 0; i < m; i++) {
            cin >> h >> p >> q;
            yoko[h][p][q] = 1;
            yoko[h][q][p] = 1;
        }

        for (int i = 1000; i >= 1; i--) {
            for (int j = 1; j <= n; j++) {
                if (yoko[i][a][j]) {
                    a = j;
                    break;
                }
            }
        }
        cout << a << endl;
    }
    return 0;
}

Measured memory_bytes: 50772
#include <iostream>
#include <queue>
#include <cstring>

using namespace std;

// →　↓　←　↑
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int h, w;
bool maze[32][32][4];
bool past[32][32];


class state {
public:
    int x, y, d;
    state(int a, int b, int c) { x = a; y = b; d = c; }
};


void solve()
{
    bool flag = false;
        
    state s(0, 0, 1);
    queue<state> q;
    q.push(s);
        
    while (!q.empty()) {
        state now = q.front();
        q.pop();
        past[now.y][now.x] = true;
            
        if (now.x == w - 1 && now.y == h - 1) {
            cout << now.d << endl;
            flag = true;
            break;
        }

        for (int i = 0; i < 4; i++) {
            if (maze[now.y][now.x][i])
                continue;
            int nx = now.x + dx[i];
            int ny = now.y + dy[i];

            if (nx < 0 || ny < 0 || nx >= w || ny >= h)
                continue;

            if (past[ny][nx] == false) {
                past[ny][nx] = true;
                q.push(state(nx, ny, now.d + 1));
            }
        }
    }

    if (!flag)
        cout << 0 << endl;
}

int main()
{
    while (cin >> w >> h, w || h) {
        int inp;

        memset(maze, 0, sizeof(maze));
        memset(past, 0, sizeof(past));
        // Input
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w - 1; x++) {
                cin >> inp;
                if (inp == 0)
                    maze[y][x + 1][2] = maze[y][x][0] = false;
                else
                    maze[y][x + 1][2] = maze[y][x][0] = true;
            }

            if (y < h - 1) 
                for (int x = 0; x < w; x++) {
                    cin >> inp;
                    if (inp == 0)
                        maze[y + 1][x][3] = maze[y][x][1] = false;
                    else
                        maze[y + 1][x][3] = maze[y][x][1] = true;                        
                }
        }

        solve();
    }

    return 0;
}

Measured memory_bytes: 1220
s = input()

a = -1
c = -1
lower = 0
for i in range(len(s)):
  if s[i] == 'A':
    a = i
  if s[i] == 'C':
    c = i
  if 'a' <= s[i] <= 'z':
    lower += 1

if a == 0 and 2 <= c <= len(s) - 2 and lower == len(s) - 2:
  print('AC')
else:
  print('WA')


Measured memory_bytes: 9056
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
  ll n;
  cin >> n;
  vll a(n);
  rep(i,0,n) cin >> a[i];
  
 ll ans=0;
 rep(i,1,n){
  ll x=max(0ll,a[i-1]-a[i]);
  ans+=x;
  a[i]+=x; 
 }
  
 cout << ans << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}


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

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

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

	int max = a[0], min = a[0];
	for (int i = 0; i < N; ++i) {
		if (a[i] > max)
			max = a[i];
		if (a[i] < min)
			min = a[i];
	}

	cout << max - min << endl;
}


Measured memory_bytes: 256
from math import floor, ceil

H,W = map(int,input().split())
ans = float('inf')

if H%3==0 or W%3==0:
  print(0)
  exit()

for x in range(1,H):
  S = [W*x, (H-x)*floor(W/2), (H-x)*ceil(W/2)]
  ans = min(ans, max(S)-min(S))

for x in range(1,W):
  S = [H*x, (W-x)*floor(H/2), (W-x)*ceil(H/2)]
  ans = min(ans, max(S)-min(S))

print(min(ans,H,W))

Measured memory_bytes: 42332
#include<stdio.h>
int main(void){
    int card[4][13]={0},b,c,n,i;
    char a;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf(" %c",&a);
        scanf("%d",&b);
        if(a=='S')
            card[0][b-1]=1;
        else if(a=='H')
            card[1][b-1]=1;
        else if(a=='C')
            card[2][b-1]=1;
        else if(a=='D')
            card[3][b-1]=1;
            //printf("%c:%d\n",a,b);
    }

    /*for(int u=0;u<4;u++){
        for(int g=0;g<13;g++){
            printf("%d ",card[u][g]);
        }printf("\n");
    }*/


    for(i=0;i<13;i++){
            if(card[0][i]==0)
                printf("S %d\n",i+1);
    }
    for(i=0;i<13;i++){
            if(card[1][i]==0)
                printf("H %d\n",i+1);
    }
    for(i=0;i<13;i++){
            if(card[2][i]==0)
                printf("C %d\n",i+1);
    }
    for(i=0;i<13;i++){
            if(card[3][i]==0)
                printf("D %d\n",i+1);
    }
    return 0;
}

Measured memory_bytes: 2720
s = input()
def check(s):
    ans = 0
    for i in range(len(s)):
        if i % 2 == 0 and s[i] != '0':
            ans += 1
        if i % 2 == 1 and s[i] != '1':
            ans += 1
    ans2 = 0
    for i in range(len(s)):
        if i % 2 == 0 and s[i] != '1':
            ans2 += 1
        if i % 2 == 1 and s[i] != '0':
            ans2 += 1
    return min(ans,ans2)
print(check(s))


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

struct BIT
{
  i64 n;
  vector<i64> bit;

  BIT(i64 _n)
  {
    n = _n;
    bit.resize(n);
    fill(bit.begin(), bit.end(), 0);
  }

  void add(i64 idx, i64 x)
  {
    for (i64 i = idx; i <= n; i += i & -i)
      bit[i] += x;
  }

  i64 sum(i64 end)
  {
    i64 ret = 0;
    for (i64 i = end; i >= 1; i -= i & -i)
      ret += bit[i];
    return ret;
  }
};

int main()
{
  i64 n, k;
  cin >> n >> k;
  vector<i64> a(n + 1);
  for (i64 i = 1; i <= n; i++)
  {
    cin >> a[i];
    a[i] += (i ? a[i - 1] : 0LL) - k;
  }
  vector<i64> sorted_a = a;
  sort(sorted_a.begin(), sorted_a.end());
  i64 ans = 0;
  BIT bit(n + 2);
  for (i64 i = n; i >= 0; --i)
  {
    i64 idx = lower_bound(sorted_a.begin(), sorted_a.end(), a[i]) - sorted_a.begin() + 1;
    if (i != n)
      ans += n - i - bit.sum(idx - 1);
    bit.add(idx, 1);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 5260
H, N = map(int, input().split())
AB = []
for _ in range(N):
    AB.append(tuple(map(int, input().split())))
max_a = max(ab[0] for ab in AB)
table = [0] + [float('inf')] * (H + max_a)

for i in range(N):
    for j in range(AB[i][0], H + max_a):
        table[j] = min(table[j], table[j - AB[i][0]] + AB[i][1])
print(min(table[H:]))


Measured memory_bytes: 50396
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
 int N,A,B;
  cin>>N>>A>>B;
  if(N*A<B){
    cout<<N*A<<endl;
  }
  else{
    cout<<B<<endl;
  }
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  I a,b,k;
  cin >> a >> b >> k;
  if (k >= a){
    I tmp = 0;
    cout << 0 << " " << max(b-(k-a),tmp) << endl;
  }else{
    cout << a-k << " " << b << endl;
  }
  return 0;
}



Measured memory_bytes: 256
n = int(input())
ans = 0
c = len(str(n))
if n <= 10:
    print(min(n, 9))
else:
    for i in range(1, 10):
        for j in range(1, 10):
            pa = 0
            pa2 = 0
            if i == j:
                pa += 1
                pa2 += 1
            temp = n - (i * 10**(c-1) + j)
            temp2 = n - (j * 10**(c-1) + i)
            if c > 2:
                if temp >= 0:
                    pa += min(10**(c-2), temp//10 + 1)
                if temp2 >= 0:
                    pa2 += min(10**(c-2), temp2//10 + 1)
            else:
                if temp >= 0:
                    pa += 1
                if temp2 >= 0:
                    pa2 += 1
            for k in range(0, c-2):
                pa += 10**k
                pa2 += 10**k
            ans += pa*pa2
            #print(i, j, pa*pa2)
    print(ans)
    

Measured memory_bytes: 3064
//---------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//                                                        NEVER  GIVE  UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define testcases() ll t; cin>>t; while(t--)
#define debug cout<<"Hello\n";
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
//------------------------------------------------------------------------------------------------------------------------------
#define mod 998244353
int main()
{
	
	#ifndef ONLINE_JUDGE
	freopen("C:/Users/DELL/Desktop/input.txt", "r", stdin);
	#endif

	fast;
	ll n,k;
	cin>>n>>k;
	vector<pair<ll,ll>> vp(k);
	vector<ll> dp(n+1,0);
	for(ll i=0;i<k;i++)
		cin>>vp[i].fi>>vp[i].se;
	vector<ll> prefix(n+1,0);
	dp[0] = prefix[0] = 0;
	dp[1] = prefix[1] = 1;
	for(ll i=2;i<=n;i++)
	{
		for(ll j=0;j<k;j++)
		{
			ll r = min(n,max(i-vp[j].fi,0ll));
			ll l = max(i-vp[j].se-1,0ll);
			dp[i] = (dp[i] + prefix[r] - prefix[l] + mod) % mod; 
		}
		prefix[i] = (prefix[i-1] + dp[i]) % mod;
	}
	cout<<dp[n];
	return 0;
}


Measured memory_bytes: 6356
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> a(N, vector<int>(N-1));
    rep(i, N)
    {
        rep(j, N - 1)
        {
            cin >> a[i][j];
            --a[i][j];
        }
        reverse(a[i].begin(), a[i].end());
    }
    
    vector<P> q;
    
    auto check = [&](int i)
    {
        if (a[i].size() == 0) return;
        int j = a[i].back();
        if (a[j].back() == i)
        {
            P p(i, j);
            if (p.first > p.second) swap(p.first, p.second);
            q.push_back(p);
        }
    };
    
    rep(i, N) check(i);
    
    int day = 0;
    while(q.size() > 0)
    {
        ++day;
        
        sort(q.begin(), q.end());
        q.erase(unique(q.begin(), q.end()), q.end());
        
        vector<P> prevQ;
        swap(prevQ, q);
        for (P p : prevQ)
        {
            a[p.first].pop_back();
            a[p.second].pop_back();
            check(p.first);
            check(p.second);
        }
    }
    
    rep (i, N)
    {
        if (a[i].size() != 0)
        {
            cout << -1 << endl;
            return 0;
        }
    }
    
    cout << day << endl;
    return 0;
}

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

/*
code credits : ਜ਼ੈਲਦਾਰ
dashan jot singh
*/
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define inf LLONG_MAX
#define p pair<ll,ll>
ll n,w;
ll arr[110][2];
ll dp[110][100010];
ll solve(){
	for(ll i=0;i<=n;i++){
		for(ll j=0;j<=w;j++){
			if(i==0||j==0){
				dp[i][j]=0;
			}
			else if(arr[i-1][0]<=j){
				dp[i][j]=max(arr[i-1][1]+dp[i-1][j-arr[i-1][0]],dp[i-1][j]);
			}
			else{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	return dp[n][w];
}
int main(){
	fast;
	cin>>n>>w;
	for(ll i=0;i<n;i++){
		cin>>arr[i][0]>>arr[i][1];
	}
	// memset(dp,-1,sizeof(dp));
	cout<<solve()<<endl;
	return 0;
}

Measured memory_bytes: 80128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    string s;
    string t;
    int i = 0;
    string res = "No";
    cin >> s >> t;
    int size = s.size();

    for(i = 0; i < size; i++){
        rotate(s.begin(), s.begin() + 1, s.end());
        if(s == t){
            res = "Yes";
            break;
        }
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

struct date{
    int y;
    int m;
    int d;
};
int main(){
    int n;
    std::cin>>n;
    struct date data[n];
    for(int i=0;i<n;i++){
        std::cin>>data[i].y>>data[i].m>>data[i].d;
    }
    
    int cnt[n]={0};
    for(int i=0;i<n;i++){
        int start=data[i].y;
        if(start%3==0){
            int tmp=20-data[i].d+1;
            cnt[i]=cnt[i]+tmp;
            int month=data[i].m;
            tmp=10-month;
            cnt[i]=cnt[i]+tmp*20;
            for(int s=start+1;s<1000;s++){
                if(s%3==0){
                    cnt[i]=cnt[i]+200;
                }else{
                    cnt[i]=cnt[i]+195;
                }
            }
        }else{
            if(data[i].m%2==0){
                int tmp=19-data[i].d+1;
                cnt[i]=cnt[i]+tmp;
                int month=data[i].m;
                for(int m=month+1;m<=10;m++){
                    if(m%2==0){
                        cnt[i]=cnt[i]+19;
                    }else{
                        cnt[i]=cnt[i]+20;
                    }   
                }
                for(int s=start+1;s<1000;s++){
                    if(s%3==0){
                        cnt[i]=cnt[i]+200;
                    }else{
                        cnt[i]=cnt[i]+195;
                    }
               }
            }else{
                int tmp=20-data[i].d+1;
                cnt[i]=cnt[i]+tmp;
                int month=data[i].m;
                for(int m=month+1;m<=10;m++){
                    if(m%2==0){
                        cnt[i]=cnt[i]+19;
                    }else{
                        cnt[i]=cnt[i]+20;
                    }   
                }
                for(int s=start+1;s<1000;s++){
                    if(s%3==0){
                        cnt[i]=cnt[i]+200;
                    }else{
                        cnt[i]=cnt[i]+195;
                    }
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        std::cout<<cnt[i]<<"\n";
    }
    return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        string s = sc.NextString();
        int x = sc.NextInt();
        int y = sc.NextInt();
        int d = 0;
        var list = new List<int>();
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == 'T')
            {
                list.Add(d);
                d = 0;
            }
            else d++;
        }
        if (d > 0) list.Add(d);
        var h = list.Where((p, i) => i % 2 == 0).ToArray();
        var v = list.Where((p, i) => i % 2 != 0).ToArray();
        if (list.Count < 2)
        {
            Console.WriteLine(list[0] == x ? "Yes" : "No");
            return;
        }
        Console.WriteLine(DP(h, x, new int[] { list[0] }) && DP(v, y, new int[] { -list[1], list[1] }) ? "Yes" : "No");
    }

    static bool DP(int[] a, int dest, int[] init)
    {
        int MAX = 16001;
        int MID = 8000;
        bool[,] dp = new bool[a.Length, MAX];
        for (int i = 0; i < init.Length; i++) dp[0, init[i] + MID] = true;
        for (int i = 1; i < a.Length; i++)
        {
            for (int j = 0; j < MAX; j++)
            {
                if (!dp[i - 1, j]) continue;
                if (j + a[i] < MAX) dp[i, j + a[i]] = true;
                if (j - a[i] >= 0) dp[i, j - a[i]] = true;
            }
        }
        return dp[a.Length - 1, dest + MID];
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 130648
n = int(input())
leaves = list(map(int, input().split()))

ans = 0
nodes_min = [0] * (n + 1)
nodes_max = [0] * (n + 1)
nodes_min[n] = leaves[n]
nodes_max[n] = leaves[n]

for depth in range(n, 0, -1):
    root_min = nodes_min[depth] // 2 + nodes_min[depth] % 2
    nodes_min[depth - 1] = leaves[depth - 1] + root_min
    root_max = nodes_max[depth]
    nodes_max[depth - 1] = leaves[depth - 1] + root_max
nodes = [0] * (n + 1)
nodes[0] = 1
if nodes[0] < nodes_min[0]:
    print(-1)
else:
    for depth in range(n):
        roots = nodes[depth]-leaves[depth]
        nodes[depth + 1] = min(roots * 2, nodes_max[depth + 1])
        if nodes[depth+1] < nodes_min[depth+1]:
            print(-1)
            break
    else:
        print(sum(nodes))


Measured memory_bytes: 26380
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include<bits/stdc++.h>
#include<iostream>
#include<iterator>

#define max(a,b) ((a>b)?a:b)                        //finding max
#define min(a,b) ((a<b)?a:b)                        //finding min
#define Max(a,b,c) max(a,max(b,c))                  //finding max between 3 numbers
#define Min(a,b,c) min(a,min(b,c))                  //finding min between 3 numbers
#define Pi acos(-1.0)                               //defining Pi for mathematical uses
#define Clear(a) memset(a,0,sizeof(a))              //clearing memory of an array
#define setfalse(a) memset(a,false,sizeof(a))       //setting the array into false
#define settrue(a) memset(a,true,sizeof(a))         //setting the array into true
#define clrstr(a) memset(a,'\0',sizeof(a))          //setting string array to null
#define open freopen("input.txt","r",stdin)         //opening input file
#define close freopen ("output.txt","w",stdout)     //opening output file
#define Case(a) printf("Case %d: ",a)               //printing case number
#define caseh(a) printf("Case #%d: ",a)             //printing case number having '#'
#define getcase(a) scanf("%d",&a)                   //scanning case number
#define caseloop(a,b) for(a=1;a<=b;a++)             //making case loop
#define EPS 1e-9                                    //small value for avoiding preccesion error
#define LL long long                                //long long short form

using namespace std;

int main()
{
    LL n,l;
    string s;
    vector<string> vs;
    cin>>n>>l;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        vs.push_back(s);
    }
    sort(vs.begin(),vs.end());
    for(vector<string>::iterator it =vs.begin();it!=vs.end();it++)
    {
        cout<<*it;
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

vi g[10000];
vector<string> s(10000);
void dfs(int now, int h){
  int i;
  rep(i,h)cout<<'.';
  cout<<s[now]<<endl;
  rep(i,g[now].size())
    dfs(g[now][i],h+1);
}


int main(void) {
  int i,j;
  int n;
  cin>>n;
  rep(i,n){
    int a;
    cin>>a;
    if(a)g[a-1].push_back(i);
    cin>>s[i];
  }
  dfs(0,0);
}

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

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


int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H)
    {
        cin >> S.at(i);
    }

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

    rep(i, H)
    {
        rep(j, W)
        {
            char c_tmp = S.at(i)[j];
            if(c_tmp == '#')
            {
                continue;
            }
            int sum = 0;
            rep(k, 8)
            {
                if((i + dx[k]) < 0 || (j + dy[k]) < 0 || (i + dx[k]) >= H || (j + dy[k] >= W))
                {
                    continue;
                }
                char bomb = S.at(i + dx[k])[j + dy[k]];
                if(bomb == '#')
                {
                    sum++;
                }
            }
            S.at(i)[j] = sum + '0';
        }
    }

    rep(i, H)
    {
        cout << S.at(i) << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < A.length; i++) {
                A[i] = in.nextInt();
            }

            long min = (long) 1e18;
            long l = -(int) 1e18, r = (int) 1e18;
            for (; l + 1 < r;) {
                long c = (l + r) / 2;
                // long snukeL = snuke(A, l);
                // long snukeR = snuke(A, r);
                long snuke = snuke(A, c);
                long snukeP = snuke(A, c + 1);
                long snukeM = snuke(A, c - 1);
                if (snukeP < snuke) {
                    l = c;
                } else if (snukeM < snuke) {
                    r = c;
                } else {
                    min = Math.min(min, snuke);
                    break;
                }
            }
            long snukeL = snuke(A, l);
            long snukeR = snuke(A, r);
            min = Math.min(min, snukeL);
            min = Math.min(min, snukeR);
            System.out.println(min);
        }
    }

    private static long snuke(int[] a, long c) {
        long value = 0;
        for (int i = 0; i < a.length; i++) {
            value += Math.abs(a[i] - (c + i + 1));
        }
        return value;
    }
}


Measured memory_bytes: 66836
// Coloring Colorfully

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

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

    int len = (int)s.length();

    bool is_black;
    if (s[0] == '0') {
        is_black = true;
    } else {
        is_black = false;
    }
    
    int cost = 0;
    for (int i = 1; i < len; i++) {
        if (is_black) {
            if (s[i] == '0') {
                cost++;
            }
            is_black = false;
        } else {
            if (s[i] == '1') {
                cost++;
            }
            is_black = true;
        }
    }

    cout << cost << endl;

    return 0;
}


Measured memory_bytes: 512
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;


int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if ((c - b) * (c - a) < 0) cout << "Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let _ = Array.fold_left (fun (c, p) a -> if a = p then c + 1, 0 else c, a) (0, 0) a_s |> fst |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
typedef long long ll;
using namespace std;

int main() {
	int a,b;
	cin>>a>>b;
	cout << a+b/2<<endl;
	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
int n, m;

bool ok(map<int, VI> &mp, VI &p, VI &k, int order)
{
    vector<int> on(n);
    rep(i, n) on[i] = ((order >> i) & 1);
    bool ret = true;
    rep(i, m)
    {
        int cnt = 0;
        rep(j, k[i])
        {
            cnt += on[mp[i][j]];
        }
        ret &= (cnt % 2 == p[i]);
    }
    return ret;
}

int main()
{
    cin >> n >> m;
    map<int, VI> mp;
    vector<int> k(m);
    rep(i, m)
    {
        cin >> k[i];
        rep(j, k[i])
        {
            int t;
            cin >> t;
            t--;
            mp[i].push_back(t);
        }
    }
    VI p(m);
    rep(i, m) cin >> p[i];
    int ans = 0;
    rep(i, 1 << n)
    {
        if (ok(mp, p, k, i))
            ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/*
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
*/

#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    string s;
    cin >> s;
    deque <char> c;
    for (auto d : s)
    {
        c.push_back(d);
    }
    int ans = 0;
    while (c.size() > 1)
    {
        if (c.front() == c.back())
        {
            c.pop_front();
            c.pop_back();
        }
        else if (c.front() != 'x' && c.back() != 'x')
        {
            puts("-1");
            return 0;
        }
        else
        {
            ans++;
            if (c.front() == 'x')
            {
                c.pop_front();
            }
            else
            {
                c.pop_back();
            }
        }
    }
    cout << ans << '\n';
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int a,b;
    cin >> a >> b;
    if(b<a)swap(a,b);
    REP(i,b)cout << a;

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;

int main(){
	cin>>n;
	int t=0;
	for(int i=0;i<n;i++){
		char c;
		cin>>c;
		if(c=='R') t++;
	}
	cout<<(t>n-t?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=100010;
int a,b,c,d,e;
int s[10];
ll ans;
inline int read(){
    int f=1,x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
int main(){
    cin>>a>>b>>c>>d>>e;
    ans+=a;ans+=b;ans+=c;ans+=d;ans+=e;
    int a1=10-(a%10),b1=10-(b%10),c1=10-(c%10),d1=10-(d%10),e1=10-(e%10);
    a1%=10;b1%=10;c1%=10;d1%=10;e1%=10;
    s[1]=a1,s[2]=b1,s[3]=c1,s[4]=d1,s[5]=e1;
    sort(s+1,s+6);
    //for(int i=1;i<=5;i++) cout<<s[i]<<" ";
    //cout<<endl;
    for(int i=1;i<=4;i++) ans+=s[i];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import java.util.*
fun main(args: Array<String>) {
    val N = nextInt()
    val P = listOfInt(-1).joinToString(separator = "")
    val Q = listOfInt(-1).joinToString(separator = "")
    val A = IntArray(N)
    val R = mutableListOf<String>()
    fun Permutation(n: Int) {
        if (n == N) {
            R.add(A.joinToString(separator = ""))
        } else {
            for (m in 0 until N) {
                if (A.slice(0 until n).all { it != m }) {
                    A[n] = m
                    Permutation(n + 1)
                }
            }
        }
    }
    Permutation(0)
    val p = R.binarySearch(P, Comparator { o1, o2 -> o1.compareTo(o2) })
    val q = R.binarySearch(Q, Comparator { o1, o2 -> o1.compareTo(o2) })
    println(Math.abs(p - q))
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }


Measured memory_bytes: 70516
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<set>
#include<algorithm>
#include<map>
#include<ctime>
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps = 1e-8;
const int maxn = 200009;
const int inf = 100000009;
int main()
{
	ll a;
	cin >> a;
	if (a & 1) cout << 0;
	else {
		ll p2 = 0, p5 = 0;
		ll b = a/2;
		while (a>=2) {
			p2 += a / 2;
			a /= 2;
		}
		while (b >= 5) {
			p5 += b / 5;
			b /= 5;
		}
		cout << min(p5,p2);
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 256