akhauriyash/Code-Regression huggingface dataset:
import scala.io.StdIn.{readLine, readInt}

sealed trait Order
case class Print(a: Int, b: Int)              extends Order
case class Reverse(a: Int, b: Int)            extends Order
case class Replace(a: Int, b: Int, p: String) extends Order

object Main extends App {
  val str    = readLine()
  val n      = readInt()
  val lines  = Iterator.fill(n)(readLine())
  val orders = lines.map { _.split(" ") }.map {
    case Array("print", a, b)      => Print(a.toInt, b.toInt)
    case Array("reverse", a, b)    => Reverse(a.toInt, b.toInt)
    case Array("replace", a, b, p) => Replace(a.toInt, b.toInt, p)
  }

  val printStrings = {
    val (_, printStrings) = orders.foldLeft((str, Nil: List[String])) { (accum, order) =>
      val (s, printStrings) = accum
      order match {
        case Print(a, b)      =>
          val ps = s.slice(a, b + 1)
          (s, ps :: printStrings)
        case Reverse(a, b)    =>
          val rev = s.slice(a, b + 1).reverse
          (s.patch(a, rev, b - a + 1), printStrings)
        case Replace(a, b, p) =>
          (s.patch(a, p, b - a + 1), printStrings)
      }
    }
    printStrings.reverse
  }

  printStrings.foreach(println)
}



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

int main(){
  string S;
  cin >> S;
  int Y=0;
  int M=0;
  if((S.at(2)=='0' && S.at(3)!='0') || (S.at(2)=='1' && S.at(3)>='0' && S.at(3)<='2')){
    Y=1;
  }
  if((S.at(0)=='0' && S.at(1)!='0') || (S.at(0)=='1' && S.at(1)>='0' && S.at(1)<='2')){
    M=1;
  }
  if(Y==1 && M==1){
    cout << "AMBIGUOUS" << endl;
  }
  else if(Y==1 && M==0){
    cout << "YYMM" << endl;
  }
  else if(Y==0 && M==1){
    cout << "MMYY" << endl;
  }
  else{
    cout << "NA" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 100000;
		for (int i = 1; i < N / 2 + 1; i++) {
			String I = String.valueOf(i);
			String J = String.valueOf(N - i);
			int temp = 0;
			int jj = 0;
			for (int j = 0; j < J.length(); j++) {
				temp += Integer.parseInt(J.substring(j, j + 1));
			}
			for (int k = 0; k < I.length(); k++) {
				temp += Integer.parseInt(I.substring(k, k + 1));
			}
			if(ans>temp) {
				ans = temp;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 39564
#include<iostream>
#include<string>
using namespace std;
int main(){
	int price = 700;
	string s;
	cin >> s;
	for (int i = 0; i < 3; i++){
		if (s.at(i) == 'o'){
			price += 100;
		}
	}
	cout << price << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <climits>

using namespace std;

#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

//???
class Point {
public:
    double x, y;
    
    Point (double x = 0, double y = 0):x(x), y(y){}
    Point operator + (Point p){return Point(x + p.x, y + p.y);}
    Point operator - (Point p){return Point(x - p.x, y - p.y);}
    Point operator * (double a){return Point(a * x, a * y);}
    Point operator / (double a){return Point(x / a, y / a);}
    
    double norm(){return x*x + y*y;};
    double absolute(){return sqrt(norm());};
    
    bool operator < (const Point &p) const{
        return x != p.x ? x < p.x : y < p.y;
    }
    
    bool operator == (const Point &p) const{
        return equals(x, p.x) && equals(y, p.y);
    }
    
};
typedef Point Vector;                               //????????????
//????????????a,b?????????
double cross(Vector a, Vector b){
    return a.x * b.y - a.y * b.x;
}


//??????????????????http://imagingsolution.net/math/calc_n_point_area/
int main(){
    
    int n;
    double ans = 0.0;
    double area = 0.0, s = 0.0, t = 0.0;
    
    cin >> n;
    
    Vector *q = new Vector[n];
    
    for (int i = 0; i < n; i++) {
        cin >> q[i].x;
        cin >> q[i].y;
    }
    
    for (int i = 0; i < n; i++) {
        if ( ( area = cross(q[i], q[(i+1)%n]) ) > EPS) {
            s += fabs(area) / 2.0;
        }
        else{
            t += fabs(area) / 2.0;
        }
    }
    ans = fabs(s-t);
    
    printf("%.1lf\n", ans);

    return 0;
}

Measured memory_bytes: 1244
class Route
  def initialize
    @grid = {}
  end

  def matatabi_set x1, y1, x2, y2
    m1 = make_key(x1, y1, x2, y2)
    m2 = make_key(x2, y2, x1, y1)
    @grid[m1] = true
    @grid[m2] = true
  end

  def ng? x1, y1, x2, y2
    @grid[make_key(x1, y1, x2, y2)]
  end

  def make_key x1, y1, x2, y2
    "#{x1.to_s(16)}#{y1.to_s(16)}#{x2.to_s(16)}#{y2.to_s(16)}"
  end
end

def main
  gets.chomp.to_i.times do
    gx,gy = gets.chomp.split.map(&:to_i)
    dp = Array.new(gy+1).map{Array.new(gx+1)}

    route = Route.new
    gets.chomp.to_i.times do
      x1, y1, x2, y2 = gets.chomp.split.map(&:to_i)
      route.matatabi_set(x1, y1, x2, y2)
    end

    dp[0][0] = 1
    (1..dp[0].size-1).each do |x|
      dp[0][x] = (route.ng?(x-1, 0, x, 0) ? 0 : dp[0][x-1])
    end
    (1..dp.size-1).each do |y|
      dp[y][0] = (route.ng?(0, y-1, 0, y) ? 0 : dp[y-1][0])
    end

    (1..dp[0].size-1).each do |x|
      (1..dp.size-1).each do |y|
        up = (route.ng?(x, y-1, x, y) ? 0 : dp[y-1][x])
        left = (route.ng?(x-1, y, x, y) ? 0 : dp[y][x-1])
        dp[y][x] = up + left
      end
    end

    puts (dp[gy][gx] == 0 ? 'Miserable Hokusai!' : dp[gy][gx])
  end
end

main

Measured memory_bytes: 6128
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;
constexpr ll inf = 2e18;

inline auto is_kaibun (const string & s)
{
  rep (i, s.length () / 2)
  {
    if (s [i] != s [s.length () - 1 - i])
    {
      return false;
    }
  }
  return true;
}

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  string s;
  cin >> s;

  auto rs = s;
  reverse (ALL (rs));

  auto ans = 0;
  auto n = s.length () / 2;
  rep (i, n)
  {
    if (s [i] != rs [i])
    {
      ++ ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      List<string> s = ReadLine().ToList().ConvertAll(x=>x.ToString());
      s.Sort();
      List<string> ans = new List<string>();
      ans.Add("a");
      ans.Add("b");
      ans.Add("c");
      if (string.Join("",s)==string.Join("",ans))
      {
        WriteLine("Yes");
        
      }
      else
      {
        WriteLine("No");
      }
    }
}

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

int main(){
  int N; cin >> N;
  int p_max = 0;
  int r = 0;
  for(int i=0;i<N;i++){
    int p; cin >> p;
    r += p;
    p_max = max(p,p_max);
  }
  r -= p_max/2;
  cout << r << endl;
  
}

Measured memory_bytes: 256
import copy

S = input()
strs = list(S)
strs.reverse()
targets = [list("maerd"), list("remaerd"), list("esare"), list("resare")]

cnt = -1
_targets = copy.copy(targets)
for i in range(len(strs)):
    s = strs[i]
    cnt += 1
    is_match = False
    __targets = copy.copy(_targets)
    for target in __targets:
        if len(target) <= cnt:
            continue
        if target[cnt] == s:
            is_match = True
            if len(target) - 1 == cnt:
                _targets = copy.copy(targets)
                cnt = -1
            break
        else:
            _targets.remove(target)
    if not(is_match):
        print("NO")
        exit()

print("YES")


Measured memory_bytes: 4468
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define mod 1000000007
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
	
//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
	
	int n,i;
	cin>>n;
	vector<int> a(n),b(n,0);
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		b[i+1]=b[i]+a[i];
	}
	int ans=0,k=0;
	for(i=0;i<n;i++)
	{
		k=a[i]*((b[n]-b[i+1])%mod);
		ans+=k;
		ans=ans%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6376
parseInt(x) = parse(Int,x)

function main()
	n,m = map(parseInt, split(readline()))
	a = map(parseInt, split(readline()))
	b = Array{Int}(n)
	b[1] = a[1]
	for i in 2:n
		b[i] = b[i-1]+a[i]
	end
	d = Dict{Int,Int}()
	for i in 1:n
		k = b[i]%m
		if haskey(d,k)
			d[k] += 1
		else
			d[k] = 1
		end
	end
	s = 0
	if haskey(d,0)
		s += d[0]
	end
	for i in keys(d)
		s += div(d[i]*(d[i]-1),2)
	end
	print(s)
end
main()

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

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

int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;

    mat res(h, vec(w, 1));

    rep(i, h) rep(j, w) {
        if (j < a && i < b) res[i][j] = 0;
        else if (j >= a && i >= b) res[i][j] = 0;
    }

    rep(i, h) {
        rep(j, w) {
            cout << res[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 5120
//158 A - Station and Bus 2020/3/7

#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    string s; cin >> s;
    bool ans = true;
    if (s[0]==s[1] && s[1]==s[2]) ans = false;
    cout << (ans ? "Yes" : "No" ) << endl;
}

Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_C
# Koch Curve
# Result:
import sys
import math

# 60 degree
degree = math.pi / 3

def print_point(point):
    print '%f %f' % (point[0], point[1])

def koch(depth, p1, p2):
    if depth == 0:
        return
    s = ((2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1]) / 3)
    t = ((p1[0] + 2 * p2[0]) / 3, (p1[1] + 2 * p2[1]) / 3)
    u = ((t[0] - s[0]) * math.cos(degree) - (t[1] - s[1]) * math.sin(degree) + s[0],
         (t[0] - s[0]) * math.sin(degree) + (t[1] - s[1]) * math.cos(degree) + s[1])
    depth -= 1
    koch(depth, p1, s)
    print_point(s)
    koch(depth, s, u)
    print_point(u)
    koch(depth, u, t)
    print_point(t)
    koch(depth, t, p2)

n_itr = int(sys.stdin.readline())
start = (0.0, 0.0)
end = (100.0, 0.0)
print_point(start)
koch(n_itr, start, end)
print_point(end)

Measured memory_bytes: 4472
import fractions
import math
from collections import Counter
A, B = map(int, input().split())
C = fractions.gcd(A, B)

prime_count = Counter()
for i in range(2, math.ceil(math.sqrt(C))+1):
  while C % i == 0:
    C /= i
    prime_count[i] += 1
if C > 1:
  prime_count[int(C)] += 1

print(len(prime_count)+1)

Measured memory_bytes: 5428
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int yon[200] = {};
    rep(i,0,200){
        yon[i] = i*(i+1)*(i+2)/6;
    }
//    vector<vector<int> > dp1(1000001,vector<int>()),dp2(1000001,vector<int>());
    vector<int> dp1(1000001,INF),dp2(1000001,INF);
    dp1[0] = dp2[0] = 0;
    for(int i = 0; i < 1000001; i++){
        rep(j,0,200){
            if(i + yon[j] < 1000001){
                dp1[i + yon[j]] = min(dp1[i] + 1,dp1[i + yon[j]]);
                if(yon[j] % 2){
                    dp2[i + yon[j]] = min(dp2[i] + 1,dp2[i + yon[j]]);
                }
            }
        }
    }

    while(true){
        int tmp;
        cin >> tmp;
        if(tmp == 0) break;
        cout << dp1[tmp] << " " << dp2[tmp] << endl;
    }
    return 0;
}



Measured memory_bytes: 10604
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class Main {
	int N,M;
	ArrayList<Integer>[] list;
	@SuppressWarnings("unchecked")
	public void solve() {
		while(true){

			N = nextInt();
			if(N == 0)break;

			list = new ArrayList[30];
			for(int i = 0;i < 30;i++){
				list[i] = new ArrayList<Integer>();
			}

			for(int i = 0;i < N;i++){
				M = nextInt();
				for(int j = 0;j < M;j++){
					int day = nextInt() - 1;
					list[day].add(i);
				}
			}

			long[][] max = new long[30 + 1][N];
			for(int i = 0;i < N;i++){
				max[0][i] = (1L << i);
			}

			boolean find = false;

			for(int i = 0;i < 30;i++){
				long sum = 0L;
				for(int n : list[i]){
					sum |= max[i][n];
				}
				for(int n : list[i]){
					max[i][n] |= sum;
				}

				long ans = 0L;

				for(int j = 0;j < N;j++){
					max[i + 1][j] = max[i][j];
				}

				for(int n : list[i]){
					ans |= max[i + 1][n];
				}

				if(ans == (1L << N) - 1){
					find = true;
					out.println(i + 1);
					break;
				}
			}
			if(!find){
				out.println(-1);
			}

		}
	}

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

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

int main(){
  int N; cin >> N;
  vector<int> l(N);
  for(int i=0;i<N;i++){
    cin >> l[i];
  }
  sort(l.rbegin(),l.rend());
  int ans=0;
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      if(l[i]>l[j]*2){
        break;
      }
      for(int m=j+1;m<N;m++){
        if(l[i]<l[j]+l[m]){
          ans++;
        }
        else break;
      }
    }
  }
  cout << ans << endl;
}
      
      
  

Measured memory_bytes: 256
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=2e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=(xx<<3)+(xx<<1)+ch-'0';ch=getchar();}
    return xx*ff;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using mint = modint998244353;

int main(){
	fastio;
	// mint::set_mod(MOD);

	int n, m; 
	cin>>n>>m;
	vector<mint> a(n), b(m);
	forn(i,n){
		int x; cin>>x;
		a[i] = x;
	}
	forn(i,m){
		int x; cin>>x;
		b[i] = x;
	}

	auto c = convolution(a, b);
	forn(i,c.size()) cout<<c[i].val()<<" ";
	cout<<ln;

	return 0;
}

Measured memory_bytes: 19060
s = gets.chomp.split("").map { |e| e.to_s }
ans = 0
t = ["C","O","D","E","F","E","S","T","I","V","A","L","2","0","1","6"]
s.size.times do |i|
	if s[i] != t[i]
		ans += 1
	end
end

puts ans

Measured memory_bytes: 1916
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	lli n;
	cin >> n;

	vector<int> perm(n);
	vector<int> p(n);
	vector<int> q(n);

	for (int i = 0; i < n; i++) {
		perm[i] = i + 1;
		cin >> p[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> q[i];
	}

	lli count = 0;

	lli a, b;

	do {

		bool same_p = true;
		bool same_q = true;

		for (int i = 0; i < n; i++) {
			if (perm[i] != p[i]) {
				same_p = false;
			}if (perm[i] != q[i]) {
				same_q = false;
			}
		}

		if (same_p) {
			a = count;
		}
		if (same_q) {
			b = count;
		}
		count++;
	} while (next_permutation(perm.begin(),perm.end()));

	cout << abs(a - b) << endl;

	return 0;
}

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

int main() {
 int N;
 cin >> N;
  int a, b, c, d;
  
  a = N / 1000;
  b = (N  - a * 1000) / 100;
  c = (N - a * 1000 - b * 100) / 10;
  d = (N - a * 1000 - b * 100 - c * 10);
   
  
    if(a == b && b == c  ||  b == c && c == d ){
      cout << "Yes" << endl;
    }
  else{
    cout << "No" << endl;
  }


}

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

ll N,x;
ll factor[100];

int main(void){
    cin >> N;
    
    for(ll i=2;i<=N;i++){
        x = i;
        for(ll j=2;j*j<=N;j++){
            while(x%j==0){
                x/=j;
                factor[j]++;
            }
        }
        if(x!=1)factor[x]++;
    }
    ll ans=0;
    ll cntp=0,cntq=0;
    //for(ll i =2 ;i<=N;i++)if(factor[i]>0)cout << i <<" "<<factor[i] << endl;
    for(ll i =2 ;i<=N;i++)if(factor[i]>=74)cntp++;
    ans +=cntp;
    cntp=0;
    for(ll i=2;i<=N;i++){
        if(factor[i]>=24)cntp++;
        if(factor[i]>=2)cntq++;
    }
    ans +=cntp*(cntq-1);
    cntp = cntq=0;
    for(ll i=2;i<=N;i++){
        if(factor[i]>=14)cntp++;
        if(factor[i]>=4)cntq++;
    }
     ans +=cntp*(cntq-1);
    cntp = cntq=0;
    for(ll i=2;i<=N;i++){
        if(factor[i]>=4)cntp++;
        if(factor[i]>=2)cntq++;
    }
    ans +=cntp*(cntp-1)/2*(cntq-2);
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
#include<utility>
#include<cmath>
#include<queue>
#include<unordered_map>
#include<unordered_set>

using namespace std;
#define ll long long
#define mk make_pair
#define out freopen("out.txt", "w", stdout)
const int N = 1e5 + 10;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;



int main()
{
	string s, t;
	int a, b;
	cin >> a >> b;
	for (int i = 0; i < b; i++)
	{
		s += to_string(a);
	}
	for (int i = 0; i < a; i++)
	{
		t += to_string(b);
	}
	cout << min(s, t) << endl;
}

Measured memory_bytes: 256
N = int(input())
INF = 10 ** 6
six = [[6 ** i * j for j in range(1, 6)] for i in range(1, 7)]
nin = [[9 ** i * j for j in range(1, 9)] for i in range(1, 6)]
dp = [INF] * (100010)
dp[0] = 0
for p in [6, 9]:
    for n in range(1, 10 ** 5 + 1):
        power = 1
        while power <= n:
            dp[n] = min(dp[n], dp[n - power] + 1)
            power *= p
print(dp[N])

Measured memory_bytes: 3828
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

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

#define io ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
#define mod  1000000007
#define pii pair<int, int>
#define PI 2*acos(0.0)
#define forn(i, n) for(int i = 0; i < n; i++)

int dp[1005][1005];

int main()
{
    io;
    int r, c;
    cin>>r>>c;
    char inp[r+1][c+1];
    for(int i = 1; i<= r; i++)
        for(int j = 1;j <= c; j++)
            cin>>inp[i][j];

    dp[1][1] = 1;
    for(int i = 1; i<= r;i++)
    {
        for(int j=1; j<= c;j++)
        {
            if(i == 1 && j == 1)
                continue;
            if(inp[i][j] == '#')
                dp[i][j] = 0;
            else
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
        }
    }
    cout<<dp[r][c];
    return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    vector<ll> a(n, 0);
    
    for(ll i=0; i<n; i++)
        cin >> a[i];
    
    ll ans = 0;
    for(ll i=0; i<n; i++){
        if(i%2 == 0)
            ans += a[i];
        else
            ans -= a[i];
    }
    
    for(ll i=0; i<n; i++){
        cout << ans << endl;
        ans = - ans + 2 * a[i];
    }
    
    return 0;
}


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

int main() {
	int W,H,x,y,r;
	cin >> W >> H >> x >> y >> r;
	if(W < 2*r || H < 2*r){
	cout << "No" << endl;
	}
	else if(x + r <= W && x - r >= 0 && y + r <= H && y - r >= 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main(){
    int h, w;
    cin >> h >> w;
    int c[10][10];
    for(int i = 0; i < 100; i++) cin >> c[i/10][i%10];
    for(int k = 0; k < 10; k++){
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
            }
        }
    }
    int cnt[10] = {};
    int x;
    for(int i = 0; i < h*w; i++){
        cin >> x;
        if(x != -1) cnt[x]++;
    }
    int ans = 0;
    for(int i = 0; i < 10; i++) ans += c[i][1]*cnt[i];
    cout << ans << endl;
    return 0;
}

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

#define pb push_back
#define mk make_pair
#define all(v) v.begin(),v.end()
#define sz(v) int(v.size())
#define ll long long
#define fi first
#define se second
#define FOR(i,a,b) for(ll int i = a;i<b;i++)
#define FORR(i,a,b) for(ll int i = a;i>=b;i--)

using namespace std;

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


bool compare(int a, int b){
    return(a>b);
}

int main(){
    #ifdef LOCAL_DEFINE
        freopen("input.txt","rt", stdin);
    #endif
        int n;
        cin>>n;
        vi v;
        v.resize(n);
        for(auto& i : v) cin>>i;
        int maxi = 0, m=0;
        if(v.size()>1)     
        for(int i=v.size()-2;i>=0; i--){ 
            if(v[i]>=v[i+1]) m++;
            else m=0;
            maxi = max(m,maxi);
        }
        cout<<maxi;
    #ifdef LOCAL_DEFINE
        cerr<<"Time elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"s";
    #endif

    return 0;
}





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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    vector<vector<int>> c(3, vector<int>(3));
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> c[i][j];
        }
    }
    for(int i = 0; i <= 100; i++){
        if(i > c[0][0] || i > c[0][1] || i > c[0][2]) break;
        for(int j = 0; j <= 100; j++){
            if(j > c[1][0] || j > c[1][1] || j > c[1][2]) break;
            for(int k = 0; k <= 100; k++){
                if(k > c[2][0] || k > c[2][1] || k > c[2][2]) break;
                if(c[0][0] - i == c[1][0] - j && c[0][0] - i == c[2][0] - k){
                    if(c[0][1] - i == c[1][1] - j && c[0][1] - i == c[2][1] - k){
                        if(c[0][2] - i == c[1][2] - j && c[0][2] - i == c[2][2] - k){
                            cout << "Yes" << endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
(defun 2-num (x)
  (cond
	((= x 1) 1)
	((= x 9) 2)
	((= x 7) 4)
	((= x 4) 8)
	(t 0)))

(princ (if (= (+ (2-num (read)) (2-num (read)) (2-num (read)) (2-num (read))) 15) "YES" "NO"))


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

using pii = pair<int, int>;
#define fst first
#define snd second

struct UnionFind {
    vector<int> data;
    vector<int> diff_w;
    UnionFind(int size) : data(size, -1), diff_w(size) { }

    bool unionSet(int x, int y, int w) {
        pii xx = _root(x), yy = _root(y);
        x = xx.fst, y = yy.fst;
        if (x != y) {
            if (data[y] < data[x]) swap(x, y), swap(xx, yy), w *= -1;
            data[x] += data[y]; data[y] = x;
            diff_w[y] = xx.snd - yy.snd + w;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x){
        return _root(x).fst;
    }
    int diff(int x, int y){
        root(x);
        root(y);

        return diff_w[y] - diff_w[x];
    }
    pii _root(int x) {
        pii ret;

        if(data[x] < 0){
            ret = pii(x, diff_w[x]);
        }
        else {
            ret = _root(data[x]);
            ret.snd += diff_w[x];

            data[x]    = ret.fst;
            diff_w[x]  = ret.snd;
        }

        return ret;
    }
    int size(int x) {
        return -data[root(x)];
    }
};

int main(void){
    for(int n, m; cin >> n >> m, n;){
        UnionFind uf(n);

        rep(_, m){
            char op; cin >> op;

            if(op == '!'){
                int a, b, w; cin >> a >> b >> w;
                a--, b--;
                uf.unionSet(a, b, w);
            }
            else {
                int a, b; cin >> a >> b;
                a--, b--;
                if(not uf.findSet(a, b)) cout << "UNKNOWN" << endl;
                else cout << uf.diff(a, b) << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3612
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(a: int, b: int):
    ans=10**10
    tmpa,tmpb=a,b
    for i in range(4):
        tmpa,tmpb=a,b
        cnt=0
        now=bin(i)[2:].zfill(2)
        if now[0]=="1":
            tmpa=-a
            cnt+=1
        if now[1]=="1":
            tmpb=-b
            cnt+=1
        if tmpa<=tmpb:
            ans=min(ans,cnt+tmpb-tmpa)
    print(ans)
    return


# Generated by 1.1.4 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
    y = int(next(tokens))  # type: int
    solve(x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5076
#include <bits/stdc++.h>
#define sanyes ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long int
#define pb push_back
#define bpc __builtin_popcount
#define f first
#define s second

const llong mxn = 1e5 + 7;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

llong n, q, h, s, d;

int main(){
    cin >> q >> h >> s >> d;
    cin >> n;
    cout << (n / 2) * min(8 * q, min(4 * h, min(2 * s, d))) + (n % 2) * min(4 * q, min(2 * h, s));
    return 0;
}


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

using namespace std;

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

struct St {
    deque<int> q;
    bool flip{false};

    void add(int x) {
        if (flip)
            q.push_front(x);
        else
            q.push_back(x);
    }

    void print() {
        if (flip)
            reverse(q.begin(), q.end());
        for (int x : q)
            cout << x << " ";
        cout << '\n';
    }
};

int main() {
#ifdef LOCAL
    // freopen("input", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(12);
    int n;
    cin >> n;
    St st;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        st.add(x);
        st.flip = !st.flip;
    }
    st.print();
}

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

int main(){
   int n; cin>>n;
   int bucket[101] = {0};
   for(int i=0; i < n; i++) {
      int tmp;cin>>tmp;
      bucket[tmp] = 1;
   }

   int ans = 0;
   for(int j=100; j > 0; j--) {
      if(bucket[j] == 1) ans++;
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200002)
N, M = map(int, input().split())
xrd = [[] for i in range(N)]
x = [None]*N


def check(s):
    global xrd,x
    for t, d in xrd[s]:
        if x[t] is None:
            x[t] = x[s] + d
            check(t)
        else:
            if x[t] != x[s] + d:
                print("No")
                exit()


for i in range(M):
    L, R, D = map(int, input().split())
    xrd[L-1].append([R-1, D])
    xrd[R-1].append([L-1, -D])

for i in range(N):
    if x[i] is None:
        x[i] = 0
        check(i)


print("Yes")


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

using namespace std;

#define MOD 1000000007

int main()
{
	int n;
	string s;
	cin >> n >> s;
	int count[26]={};
	for(int i=0;i<n;i++)
		count[s[i]-'a']++;
	
	long long ans=1;
	for(int i=0;i<26;i++)
	{
		if(count[i]>0)ans*=(count[i]+1);
		ans%=MOD;
	}
	
	cout << ans-1 << endl;
}


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

int main() {
  // input
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for(int i=0; i<N; i++) cin >> vec.at(i);
  
  // sort in ascending order
  sort(vec.begin(),vec.end());
  
  // calc.
  int cnt= 0;
  int d_bottom= -1;
  for(int i=0; i<N; i++){
  	if( d_bottom < vec.at(i) ){
      d_bottom = vec.at(i);
      cnt++;
    }
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
# coding: UTF-8
n = int(input())
Ans =[ [0 for i in range(n)] for j in range(n)]
for l in range(n):
  raw = list(map(int,input().split()))
  i = raw[0]
  d = raw[1]
  for m in range(2,d+2):
    Ans[i-1][raw[m]-1] = 1

for i in range(n):
  print(" ".join(map(str,Ans[i])))


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

int main(){
    int m, f, r;
    while(cin >> m >> f >> r, m + f + r != -3){
        if(m == -1 | f == -1)
            cout << "F" << endl;
        else if(m + f >= 80)
            cout << "A" << endl;
        else if(m+f >= 65 && m+f < 80)
            cout << "B" << endl;
        else if((m+f >= 50 && m+f < 65) ||
                (m+f >= 30 && m+f < 50 && r >= 50))
            cout << "C" << endl;
        else if(m+f >= 30 && m+f < 50)
            cout << "D" << endl;
        else if(m+f < 30)
            cout << "F" << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

bool isLeap(int y);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/



int main()
{
	int vec[] = {1, -1, 4, -4};
	queue<string> que;
	map<string, int> d;
	
	que.push("01234567");
	while (!que.empty())
	{
		string str = que.front(); que.pop();
		int zero = str.find("0");
		string str2;
		rep(i, 4)
		{
			int next_z;
			next_z = zero + vec[i];
			if (next_z>=0 && next_z<=7 && !((zero==3 && next_z==4) || (zero==4 && next_z==3)))
			{
				str2 = str;
				swap(str2[zero], str2[next_z]);
				if (d.find(str2) == d.end())
				{
					que.push(str2);
					d[str2] = d[str] + 1;
				}
			}
		}
	}
	
	string num;
	while (getline(cin, num))
	{
		string::iterator end_it = remove(num.begin(), num.end(), ' ');
		num.erase(end_it, num.end());
		cout << d[num] << endl;
	}
	
	return 0;
}


bool isLeap(int y)
{
	return y % 400 == 0
						? true : y % 100 == 0
						? false : y % 4 == 0
						? true : false;
}

ll gcd(ll a, ll b)
{
	return (b > 0) ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}

void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

Measured memory_bytes: 3428
input_data = gets.chomp.split(" ")
n = input_data[0].to_i
pStock = input_data[1].to_i

while n != 0 do 
    points = pStock
    
    nStones = []
    n.times do 
        nStones.push(0)
    end
    
    index = 0
    i = 0
    while true do
        if points > 0
            points -= 1
            nStones[i] += 1
        else
            flug = false
            n.times do |j|
                if nStones[j] == pStock
                    flug = true
                    index = j
                    break
                end
            end
            if flug == true
                break
            end
            points = nStones[i] 
            nStones[i] = 0
        end
        i += 1
        if i >= n 
            i = 0
        end
    end
    
    puts index

    input_data = gets.chomp.split(" ")
    n = input_data[0].to_i
    pStock = input_data[1].to_i
end


Measured memory_bytes: 6872
def dfs(s):
    if not visited[s]:
        visited[s] = True
        stack[s] = True
        for t in adj[s]:
            if stack[t]:
                print(1)
                exit()
            else:
                dfs(t)
    stack[s] = False

nv, ne = map(int, input().split(' '))
adj = [[] for _ in range(nv)]
visited = [False] * nv
stack = [False] * nv

for _ in range(ne):
    s, t = map(int, input().split(' '))
    adj[s].append(t)

for i in range(nv):
    dfs(i)

print(0)

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

int main() {
  int n;
  string s,t,ans;
  cin >> n >> s >> t;
  
  ans="";
  for(int i; i<n; i++){
    ans+=s.at(i);
    ans+=t.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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


    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, a[i] + b[i]);
    }
    cout << ans << endl;
    return 0;
}

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


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

    int n;
    cin >> n;
    for(int i=0; i<n; i++) {
        int a;
        cin >> a;
        if(a%2==0) {
            if(a%3==0 || a%5==0) {
                ;
            }
            else {
                cout << "DENIED";
                return 0;
            }

        }
    }
    cout << "APPROVED";

    return 0;
}

Measured memory_bytes: 256
x,y=[int(x) for x in input().split()]
def check(s):
    for i in s:
        if x in i and y in i:
            return True
    return False
if check([[1,3,5,7,8,10,12],[2],[4,6,9,11]]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
using namespace std;

int ctoi(char c) {
	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

int main(){
  string s;
  cin>>s;
  int n=s.length();
  int mod=2019;
  int rui10[200020];
  rui10[0]=1;
  for(int i=1;i<200020;i++){
    rui10[i]=(10*rui10[i-1])%mod;
  }
  int x[n+1];
  x[0]=0; x[1]=ctoi(s[n-1]);
  for(int i=2;i<=n;i++){
    x[i]=(x[i-1]+ctoi(s[n-i])*rui10[i-1])%mod;
  }
  map<int,ll> mp;
  ll ans=0;
  rep(i,n+1){
    mp[x[i]]++;
  }
  for(auto p:mp){
    ans+=p.second*(p.second-1)/2;
  }
  cout<<ans;
}

Measured memory_bytes: 5192
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pdd pair<double, double>
#define V vector<int>
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define db(x) cout << #x << "=" << (x) << endl
#define db2(x, y) cout << #x << "=" << (x) << " " << #y << "=" << (y) << endl
#define db3(x, y, z) cout << #x << "=" << (x) << " " << #y << "=" << (y) << " " << #z << "=" << (z) << endl

using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1007;
const double eps = 1e-9;

int w[maxn], v[maxn];
int dp[1 << 12];

int main()
{
#ifdef AFei
    freopen("in.txt", "r", stdin);
#endif

    int N, M;
    cin >> N >> M;
    memset(dp, 0x3f, sizeof dp);
    dp[0] = 0;
    int sum = 0;
    for (int n, i = 0; i < M; ++i)
    {
        cin >> w[i] >> n;
        for (int x, j = 0; j < n; ++j)
        {
            cin >> x;
            v[i] |= 1 << (x - 1);
        }
        sum |= v[i];
    }
    int ans = -1;
    if (sum == (1 << N) - 1)
    {
        for (int i = 0; i < M; ++i)
            for(int j = 0; j < (1<<N); ++ j)
                dp[j | v[i]] = min(dp[j | v[i]], dp[j] + w[i]);
        ans = dp[(1<<N)-1];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct TEMP_OMAZINAI_ { TEMP_OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } TEMP__omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void TEMP_INPUT_IMPL_() {};
template <class T, class... Args> void TEMP_INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; TEMP_INPUT_IMPL_(args...); }
void TEMP_OUTPUT_IMPL_() {};
template <class T, class... Args> void TEMP_OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); TEMP_OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; TEMP_INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define rsort_v(v) std::sort(v.rbegin(), v.rend())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (TEMP_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //

int main() {
	in_v(ll, N, 4);
	sort_v(N);
	YESNO(N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
ll sum(ll left, ll right, vl &a)
{
    ll s=0;
    for(ll i=left; i<=right; i++)
    {
        s+=a[i];
    }
    return s;
}
void solve()
{
    ll n;
    cin>>n;
    vl a(n);
    
    forr(i, n)  cin>>a[i];
    
    vector<vl> dp(n, vl(n, 1e18+5));
    forr(i, n)
    forr(j, n)
    {
        if(i>=j)
        dp[i][j]=0;
    }
    for(ll left=n-2; left>=0; left--)
    {
        for(ll right=left+1; right<n; right++)
        {
            
            ll s=sum(left, right, a);
            for(ll ind=left; ind<=right-1; ind++)
            {
                dp[left][right]=min(dp[left][right], dp[left][ind]+dp[ind+1][right]+s);
            }
            
        }
    }
    cout<<dp[0][n-1];
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}



Measured memory_bytes: 1536
#include<iostream>

using namespace std;

int main()
{
	int a, b;
	char op;

	while (true)
	{
		cin >> a >> op >> b;

		if (op == '?')
			break;

		switch (op)
		{
		case '+' :
			cout << a + b << endl;
			break;
		case '-' :
			cout << a - b << endl;
			break;
		case '*':
			cout << a * b << endl;
			break;
		case '/':
			cout << a / b << endl;
			break;
		default:
			break;
		}
	}
}

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

#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define endl        "\n"
#define sz(x)       (int)x.size()
#define mod         1000000007

using namespace std;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,m;
string s,t;

signed main()
{
    showoff;
    cin >> n >> m >> s >> t;
    int fo =1;
    int cnt = (n*m)/__gcd(n,m);
    FOR(i,0,n){
    if((i*m)%n == 0){
    int b = (i*m)/n;
    if(s[i] == t[b]){continue;}
    fo = 0;
    break;
    }
    }
    if(fo) cout << cnt;
    else cout << -1;
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
     	long ans = 0;
		int N = scan.nextInt();
		int A[] = new int[100000];
		for(int i=0;i<N;i++) {
            int input = scan.nextInt();
            A[input-1] += 1;
            ans += input;
		}
		
		int Q = scan.nextInt();
		for(int i=0;i<Q;i++) {
            int B = scan.nextInt();
            int C = scan.nextInt();
          
            ans += A[B-1] * (C-B);
            System.out.println(ans);
          
			A[C-1] += A[B-1];
            A[B-1] = 0;
		}
	}
}

Measured memory_bytes: 60304
using System;

class Program
{
	static void Main()
    {
		string[] num = Console.ReadLine().Split(' ');
      	if( ((int.Parse(num[0]) * int.Parse(num[1])) % 2) == 0)
        {
          Console.WriteLine("Even");
        }
      	else
        {
          Console.WriteLine("Odd");
        }
    }
}


Measured memory_bytes: 11092
def partition as, p, r
  j = p - 1
  p.upto(r) do |i|
    if as[i][1].to_i <= as[r][1].to_i
      j += 1
      as[j], as[i] = as[i], as[j]
    end
  end
  return j
end

def quick_sort as, p, r
  if p < r
    q = partition as, p, r
    quick_sort as, p, q - 1
    quick_sort as, q + 1, r
  end
end

n = gets.chomp.to_i
as = []
while l = gets
  as << l.chomp.split(' ')
end
orig_orders = {}
as.each do |a|
  orig_orders[a[1].to_i] = a[0]
end
quick_sort as, 0, n - 1
new_orders = {}
as.each do |a|
  new_orders[a[1].to_i] = a[0]
end

puts orig_orders == new_orders ? 'Stable' : 'Not stable'
as.each do |a|
  puts a.join(' ')
end


Measured memory_bytes: 38524