akhauriyash/Code-Regression huggingface dataset:
// Contest: AtCoder Beginner Contest 173 (https://atcoder.jp/contests/abc173)
// Problem: C: H and V (https://atcoder.jp/contests/abc173/tasks/abc173_c)


// region boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion

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

    int h, w, k; cin >> h >> w >> k;
    vector<string> g(h);
    rep(i, h)
        cin >> g[i];

    int ans = 0;
    for (int rm = 0; rm < (1 << h); ++rm) {
        for (int cm = 0; cm < (1 << w); ++cm) {
            int rem = 0;
            rep(i, h) rep(j, w)
                rem += (g[i][j] == '#' && !((rm >> i) & 1) && !((cm >> j) & 1));
            ans += (rem == k);
        }
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3668
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line.trim().split_whitespace();
    let s = it.next().unwrap();

    let line = gets();
    let mut it = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<u32>().ok().unwrap());
    let (a, b) = (it.next().unwrap(), it.next().unwrap());

    let line = gets();
    let u = line.trim();

    if u == s {
        println!("{} {}", a - 1, b);
    } else {
        println!("{} {}", a, b - 1);
    }
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

ll solve(){
  ll N,A,B; cin>>N>>A>>B;
  ll b = A*(N-1) + B;
  ll t = A + B*(N-1);
  ll ans;
  if(t>=b){ ans = (t-b)+1; }
  else{ ans = 0; }
  return ans;
}

int main(){
  cout << solve()<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#define ll long long
using namespace std;

int h,w,k,x[10],y[10],ans,bl;
char c[10][10];

void dfs(int num,int opt,int sum){
    if (sum<k) return;
    if (opt==1){
        if (num==w){
            ans+=(sum==k);
            return;
        }
        dfs(num+1,opt,sum);
        int q[10];q[0]=0;

        for (int i=0;i<h;++i)
            if (c[i][num]=='#') q[++q[0]]=i,c[i][num]='.',--sum;
        dfs(num+1,opt,sum);
        for (int i=1;i<=q[0];++i)
            c[q[i]][num]='#',++sum;
    }
    else {
        if (num==h){
            dfs(0,1,sum);
            return;
        }
        dfs(num+1,opt,sum);

        int q[10];q[0]=0;
        for (int i=0;i<w;++i)
            if (c[num][i]=='#') q[++q[0]]=i,c[num][i]='.',--sum;
        dfs(num+1,opt,sum);
        for (int i=1;i<=q[0];++i)
            c[num][q[i]]='#',++sum;
    }

}

int main() {
    scanf("%d%d%d",&h,&w,&k);
    for (int i=0;i<h;++i) {
        scanf("%s", c[i]);
        for (int j=0;j<w;++j)
            if (c[i][j]=='#') ++bl;
    }
    dfs(0,0,bl);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3756
#include <iostream>
using namespace std;
typedef long long ll;

const ll mod = 1e9+7;

int main(){
  string l; cin >> l; int n = l.size();
  ll bare = 1, bare_next = 0, safe = 0;
  for(int i=0; i<n; i++) {
    if (l[i] == '1') {
      bare_next = bare * 2 % mod;
      safe = (safe * 3 + bare) % mod;
    } else {
      bare_next = bare;
      safe = safe * 3 % mod;
    }
    //cout << bare << " " << bare_next << " " << safe << endl;
    bare = bare_next;
  }
  cout << (safe + bare) % mod << endl;
}

Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemA_MoreLess solver = new ProblemA_MoreLess();
        solver.solve(1, in, out);
        out.close();
    }

    static class ProblemA_MoreLess {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            char[] s = in.next().toCharArray();
            int n = s.length;
            int[] l = new int[n];
            int[] r = new int[n];
            for (int i = 0; i < n; i++) {
                if (s[i] == '<') {
                    l[i] = 1;
                    if (i > 0) {
                        l[i] += l[i - 1];
                    }
                }
            }
            for (int i = n - 1; i >= 0; i--) {
                if (s[i] == '>') {
                    r[i] = 1;
                    if (i + 1 < n) {
                        r[i] += r[i + 1];
                    }
                }
            }
            long ans = r[0] + l[n - 1];
            for (int i = 0; i + 1 < n; i++) {
                ans += Math.max(l[i], r[i + 1]);
            }
            out.println(ans);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

    }
}



Measured memory_bytes: 33492
s=input()
n=len(s)
ans="Yes"
for i in range(n//2):
    if s[i]!=s[n-1-i]:
        ans="No"
for j in range(n//2):
    if s[i]!=s[n//2-1-i]:
        ans="No"
for j in range(n//2):
    if s[n//2+1+i]!=s[-1-i]:
        ans="No"


print(ans)

Measured memory_bytes: 3064
// Problem : B - Frog 2
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
 
#define endl "\n"
#define int long long
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define rep(n) for(int i=0;i<(n);i++)
#define rrep(n) for(int i=(n)-1;i>=0;i--)
#define mem(a,b) memset((a),(b),sizeof (a))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define INF (long long) 1e18
#define MOD 1000000007


void solve(){
      int n,k;
      cin>>n>>k;
      int arr[n],dp[n];
      rep(n) cin>>arr[i];
      for(int i=0;i<n;i++){
            if(i==0) {dp[i] = 0;continue;}
            else dp[i] = INT_MAX;
            for(int j=i-1;j>=max((int)0,i-k);j--){
                  dp[i] = min(dp[i],dp[j] + abs(arr[i]-arr[j]));
            }
      }
      cout<<dp[n-1]<<endl;
}

int32_t main(){
      FAST
      int t=1;
      //cin>>t;
      while(t--)
            solve();
      return 0;
}




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

#define MAXN 123456

int n, actv[MAXN][3], dp[MAXN][3];

int solve(int day, int atvd){
    if(dp[day][atvd]!=-1) return dp[day][atvd];
    if(day==n) return 0;
    if(atvd==0){
        return dp[day][atvd] = max(solve(day+1, 1)+actv[day][1], solve(day+1, 2)+actv[day][2]);
    }
    else if(atvd==1){
        return dp[day][atvd] = max(solve(day+1, 0)+actv[day][0], solve(day+1, 2)+actv[day][2]);
    }
    else if(atvd==2){
        return dp[day][atvd] = max(solve(day+1, 0)+actv[day][0], solve(day+1, 1)+actv[day][1]);
    }
}

int main(){
    cin >> n;

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

    memset(dp, -1, sizeof dp);

    int resp, resp1, resp2;

    resp = solve(0, 0);
    resp1 = solve(0, 1);
    resp2 = solve(0, 2);

    cout << max(resp, max(resp1, resp2)) << endl;
}


Measured memory_bytes: 7552
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

void SolveC()
{
	// グリッド情報の入力
	vector<vector<int>> c;
	c.resize(3);
	for (int i = 0; i < 3; i++)
	{
		c[i].resize(3);
	}
	for (int i = 0; i < 3; i++)
	{
		scanf("%d %d %d", &c[i][0], &c[i][1], &c[i][2]);
	}

	// 整数ai(a1, a2, a3)と整数bj(b1, b2, b3)
	// ここでは、xがa、yがbを表す
	vector<int> x;
	vector<int> y;
	x.resize(3, 0);
	y.resize(3, 0);

	// c11 = x1 + y1 -> y1 = c11 - x1
	// c12 = x1 + y2 -> y2 = c12 - x1
	// c13 = x1 + y3 -> y3 = c13 - x1
	// これらを一般化すると、yi = c1i - x1
	for (int i = 0; i < 3; i++)
	{
		y[i] = c[0][i] - x[0];
	}
	// c11 = x1 + y1 -> x1 = c11 - y1
	// c21 = x2 + y1 -> x2 = c21 - y1
	// c11 = x3 + y1 -> x3 = c31 - y1
	// これらを一般化すると、xi = ci1 - y1
	for (int i = 0; i < 3; i++)
	{
		x[i] = c[i][0] - y[0];
	}

	// 情報が正しいと仮定
	bool flag = true;
	// グリッドの情報と高橋くんがもっている情報が正しいか精査
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			if (x[i] + y[j] != c[i][j])
			{
				// そうじゃないとき、正しくない
				flag = false;
			}
		}
	}

	if (flag)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
}

int main()
{
	SolveC();
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#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<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<62;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int S,T;
string s,t;

int main(){
	cin>>s>>t;
	S=s.size();
	T=t.size();
	string res="{";
	for(int i=0;i<=S-T;i++){
		bool B=1;
		string tmp=s;
		for(int j=0;j<T;j++){
			if(tmp[i+j]!='?'&&tmp[i+j]!=t[j]) B=0;
			tmp[i+j]=t[j];
		}
		for(int j=0;j<S;j++) if(tmp[j]=='?') tmp[j]='a';
		if(B) res=min(res,tmp);
	}
	cout<<(res=="{"?"UNRESTORABLE":res)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ctype.h>
using namespace std;
 
 
int main(){
    int N;
    cin >>N;
    bool s=1;

    int b=N%7;
    for(;b<=N;b+=7){
        if(b%4==0)s=false;
    }
    if(s)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main( void )
{
	int w, q, map[100];
	while(cin >> w >> q, w | q) {
		for(int i=0; i < w; ++i) map[i] = -1;
		for(int i=0; i < q; ++i) {
			char c;
			int id, ww;
			cin >> c;
			if(c == 's') {
				cin >> id >> ww;
				int count = 0, start = 0; bool hit = false;
				for(int j=0; j < w; ++j) {
					if(map[j] == -1) ++count;
					else			count = 0;
					if(count == ww) {
						for(int k=j; k > j-ww; --k) map[k] = id;
						hit = true; start = j-ww; break;
					}
				}
				if(hit)
					cout << start+1 << endl;
				else
					cout << "impossible" << endl;
			}
			else {
				cin >> id;
				for(int j=0; j < w; ++j) if(map[j] == id) map[j] = -1;
			}
		}
		cout << "END" << endl;
	}
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int

typedef long long ll;
typedef pair<ll,ll> p;

int waterA, waterB, sugarA, sugarB, sugarLimit, beakerLimit;
long double maxv = -1;
int resA, resB;

void dfs()
{
  for (int i = 0; i < 41; i++)
  {
    for (int j = 0; j < 41; j++)
    {
      for (int k = 0; k < 41; k++)
      {
        for (int l = 0; l < 41; l++)
        {
          long double water = i * waterA * 100 + j * waterB * 100;
          long double sugar = k * sugarA + l * sugarB;
          if((water / 100) * sugarLimit < sugar) break;
          if(sugar + water > beakerLimit) break;
          long double rate = (sugar*100.0) / (sugar + water);
          if(rate > maxv)
          {
            resA = water + sugar;
            resB = sugar;
            maxv = rate;
          }
        }
      }
    }
  }

}

int main()
{
  cin >> waterA >> waterB >> sugarA >> sugarB >> sugarLimit >> beakerLimit;
  dfs();
  cout << resA << " " << resB << endl;



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

int A,B,T;

int main()
{
  cin >> A >> B >> T;

  int ans = 0;
  int t = A;
  while(t <= T + 0.5) {
    ans += B;
    t += A;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

h,w,k = (int(x) for x in input().split())
row_cnt = []
col_cnt = []
lst = []
total = 0
for i in xrange(h):
    lst.append([1 if c=='#' else 0 for c in input().strip()])
    row_cnt.append(sum(lst[-1]))
    total += row_cnt[-1]
for j in xrange(w):
    col_cnt.append(sum((lst[i][j] for i in xrange(h))))

ans = 0
for i in xrange(2**h):
    bini = bin(i)[2:]
    bini = ((h-len(bini))*'0')+bini
    curk = total
    for ii,c in enumerate(bini):
        if c == '1':
            curk -= row_cnt[ii]
    
    for j in xrange(2**w):
        binj = bin(j)[2:]
        binj = ((w-len(binj))*'0')+binj
        cur = curk
        for ii,c in enumerate(binj):
            if c == '1':
                bonus = 0
                for jj,cc in enumerate(bini):
                    if cc == '1' and lst[jj][ii] == 1:
                        bonus += 1
                cur -= col_cnt[ii] - bonus
        if cur == k:
            ans += 1
print(ans)

Measured memory_bytes: 79596
<?php
list($s) = strs();
list($w) = ints();
$a = str_split($s, $w);
$ans = '';
for ($i = 0; $i < count($a); ++$i) $ans .= $a[$i][0];
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


Measured memory_bytes: 16184
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)
	writer := bufio.NewWriter(os.Stdout)

	var a, b int
	fmt.Sscan(getNextLine(scanner), &a, &b)

	if a < 13 {
		b /= 2
	}
	if a < 6 {
		b = 0
	}

	fmt.Fprintln(writer, b)
	writer.Flush()

}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

typedef long long int lli;

void swap(int* a, int* b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void ll_swap(lli* a, lli* b)
{
    lli tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int gcd(int a, int b)
{
    if (a < b)
        swap(&a, &b);

    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}

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

long power(long x, int n) {
    long ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
		printf("res:%lld a:%lld\n", res,a);
	}
	return res;
}


lli comb(lli n, lli r)
{
    if (n == 0)
        return 0;

    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (comb(n - 1, r - 1) + comb(n - 1, r));
}

/*
#define MAX 100000
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/


int main()
{
    int N, K;
    int d;
    int A[200][200];
    int B[200] = { 0 };

    scanf("%d%d", &N, &K);

    for (int i = 0; i < K; i++)
    {
        scanf("%d", &d);
        for (int j = 0; j < d; j++)
        {
            scanf("%d", &A[i][j]);
            B[A[i][j]]++;
        }
    }

    int count = 0;

    for (int i = 1; i <= N; i++)
    {
        if (B[i] == 0)
            count++;
    }
    printf("%d", count);
}



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

int n, A[8], B[8];

bool check() {
	for(int i = 0; i < n; i++) 
		if(A[i] < B[i])
			return true;
	return false;
}

int main() {
	cin >> n;
	for(int i = 0; i < n; i++) cin >> A[i];
	for(int i = 0; i < n; i++) cin >> B[i];
	
	int s = 0;
	for(int i = 0; i < n && !s; i++) 
		if(A[i] < B[i]) s = 1;
		else if(A[i] > B[i]) s = -1;
	
	if(s == 0) return cout << 0, 0;
	if(s == -1) 
		for(int i = 0; i < n; i++) swap(A[i], B[i]);

	int r;
	while(check()) {
		next_permutation(A, A + n);
		r++;
	}

	cout << r;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
a = list(list(input())for i in range(h))
stack = []
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            stack.append((i,j))
        
vec = ((1,0),(0,1),(-1,0),(0,-1))
move = 0
while stack:
    next = []
    move +=1
    for y,x in stack:
        for ny,nx in vec:
            ty,tx = y+ny,x+nx
            if ty>h-1 or tx>w-1 or ty<0 or tx <0:continue
            if a[ty][tx] == ".":
                a[ty][tx] = move
                next.append((ty,tx))
    stack = next

print(move-1)


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

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector <ll> vec;
typedef pair <ll, ll> pr;
typedef pair <ll, pr> pr2;
typedef map <ll, vector<ll> > mv;

const int MX = 2e6+10;
const int mod = 1e9 + 7;
const ll inf = 1LL << 62;

int dx4[] = { 0, 0, -1, 1 };
int dy4[] = { 1, -1, 0, 0 };

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

// TOOLS
#define LCM(a,b)        (a / __gcd(a,b) ) *b
#define gcd(a,b)        __gcd(a,b)
#define all(x)          (x).begin(), (x).end()
#define mem(a, n)       memset(a, n, sizeof(a))
#define for1(i, n)      for(int i=1; i<=n; i++)
#define for0(i, n)      for(int i=0; i<n; i++)
#define rof0(i, n)      for(int i=n-1; i>=0; i--)
#define rof1(i, n)      for(int i=n; i>=1; i--)
#define forab(i, a, b)  for(int i=a; i<=b; i++)
#define rofab(i, a, b)  for(int i=b; i>=a; i--)
#define pb              push_back
#define pbb             pop_back

// CIN/COUT
#define sin(s)          getline(cin, s)
#define case(a)              cout << "Case "<<(a)<<": "

// SCANF/PRINTF
#define fYES            printf("YES\n")
#define fNO             printf("NO\n")
#define Scf(a)          scanf("%lld", &a)
#define Scf2(a, b)      scanf("%lld %lld", &a, &b)
#define Scf3(a, b, c)   scanf("%lld %lld %lld", &a, &b, &c)
#define Scf4(a,b,c,d)   scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define Pnf(a)          printf("%lld\n", a)
#define Pnf2(a, b)      printf("%lld %lld\n", a, b)
#define Pnf3(a, b, c)   printf("%lld %lld %lld\n", a, b, c)
#define Bug(n)          printf(">> %lld <<\n", n)

// OTHERS
#define sz(n)          n.size()
#define clr(v)          v.clear()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define in              freopen("input.txt", "r", stdin)
#define out             freopen("output.txt", "w", stdout)
#define FastIO          { ios_base::sync_with_stdio(false); cin.tie(0); }
#define F               first
#define S               second
#define mpp             make_pair
//End
int mark[100010],mark1[100010];
vector<ll > v,v1;
set<int>S;
int main()
{

    ll n, m, k, q, t, cnt = 0, sum = 0,ans=1, mx = -inf, mn = inf, a, b, c,d,e,f,g,h,i,j,x, y, z,temp, temp1;
    string s, s1, s2, s3,s4,s5,s6,s7;
    cin>>a>>b>>t;
    x=t/a;
    cout<<x*b<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define M 1000000007 
#define MM 998244353
using namespace std;
 
int main()
{
	int n, flag = 0; 

	cin >> n; 

	for (int i = 1; i < 10; i++)
	{
		if (n%i == 0)
		{
			if (n/i<10)
			{
				cout << "Yes";
				flag = 1;
				exit(0);
			}
		}
	}

	if (flag == 0)
	{
		cout << "No";
	}

  	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define MAX 25
#define NIL -1

struct node
{
	int parent;
	int left;
	int right;
	node() {
		parent = left = right = NIL;
	}
} T[MAX];

void preorder(int u)
{
	cout << " " << u;
	if (T[u].left != NIL)
		preorder(T[u].left);
	if (T[u].right != NIL)
		preorder(T[u].right);
}

void inorder(int u)
{
	if (T[u].left != NIL)
		inorder(T[u].left);
	cout << " " << u;
	if (T[u].right != NIL)
		inorder(T[u].right);
}

void postorder(int u)
{
	if (T[u].left != NIL)
		postorder(T[u].left);
	if (T[u].right != NIL)
		postorder(T[u].right);
	cout << " " << u;
}

int main(void)
{
	int n, id, l, r, i;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> id >> l >> r;
		if (l != NIL) 
		{
			T[id].left = l;
			T[l].parent = id;
		}
		if (r != NIL)
		{
			T[id].right = r;
			T[r].parent = id;
		}
	}
	for (i = 0; i < n; i++) 
	{
		if (T[i].parent == NIL)
			break;
	}
	cout << "Preorder\n";
	preorder(i);
	cout << endl << "Inorder\n";
	inorder(i);
	cout << endl << "Postorder\n";
	postorder(i);
	cout << endl;
}


Measured memory_bytes: 3104
use std::io;
fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let mut iter = s.trim().split_whitespace();
    let a: u32 = iter.next().unwrap().parse().unwrap();
    let b: u32 = iter.next().unwrap().parse().unwrap();
    let c: u32 = iter.next().unwrap().parse().unwrap();

    let mut cnt = 0;
    for i in a..b+1 {
        if c % i == 0 {
            cnt += 1;
        }
    }

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


Measured memory_bytes: 5024
#include <stdio.h>

int  t(int x, int y){
if(y == 0){
 return x;
}
else {
return t(y,x%y);
}
}


int main(){

int x,y,f;
scanf("%d %d\n",&x,&y);

if(y>x){
 f = y;
 y = x;
 x = f;
}

printf("%d\n",t(x,y));

return 0;
}

  

 


Measured memory_bytes: 2140
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
#include <cmath>
using namespace std;
#define MAXH 101
#define MAXW 101
#define INF 1000
#define MAXN 100001
#define MOD 1000000007
typedef long long ll;

ll n, s;
vector<string> S;
int cur[3];


int main(){
    string s;
    for(int i = 0;i < 3;i++){
        cin >> s;
        S.push_back(s);
    }

    int now = 0;

    while(1){
        if(cur[now] == S[now].length()){
            printf("%c\n", now + 65);
            return 0;
        }
        int nex = S[now][cur[now]] - 97;
        cur[now]++;
        now = nex;
    }

    printf("-1\n");
    return 1;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{

    char arr[1200];
    char s[]="s";
    char es[]="es" ;
    gets(arr);
    int x=strlen(arr);


    if(arr[x-1]=='s')
    {
        strcat(arr,es);
    }
    else
    {
        strcat(arr,s);
    }
    puts(arr);



    return(0);
}


Measured memory_bytes: 1488
import numpy
a, b, h, m = list(map(int, input().split()))

t_angle = (h * 30) + (m * 0.5) # 30 = 360 / 12, 0.5 = 30 / 60
b_angle = m * 6 # 6 = 360 / 60
if t_angle - b_angle == 0:
  print(abs(a - b))
  exit()
space_angle = abs(b_angle - t_angle)
c2 = (a * a + b * b) - (2 * a * b * numpy.cos(numpy.radians(space_angle)))
print(numpy.sqrt(c2))

Measured memory_bytes: 27228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
	ll l,r;
	cin >> l >> r;
	ll ans = 2019;
	for(ll i = l;i<l+2019&&i<r;i++)
	{
		for(ll j=i+1;j<=l+2019&&j<=r;j++)
		{
			ans = min(ans,i*j%2019);
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#coding: UTF-8
from collections import deque
n = int(input())
link = [[] for i in range(n+1)]
for i in range(n):
  r = list(map(int,input().split()))
  u = r.pop(0)
  k = r.pop(0)
  link[u] = r

searched=set()
queue = deque()
d = [-1 for i in range(n+1)]

v = 1
d[v] = 0
queue.append(v)
searched.add(v)
while queue:
  v = queue.popleft()
  for w in link[v]:
    if w not in searched:
      d[w] = d[v] + 1
      queue.append(w)
      searched.add(w)

for i in range(1,n+1):
  print(str(i) + " " + str(d[i]))



Measured memory_bytes: 6028
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, k;
    cin >> n >> k;
    if (2 * k - 1 <= n) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}


Measured memory_bytes: 892
import java.util.Scanner;
public class Main{
	public static void main(String[] agrs){
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int satu = 1000;
		while(true){
			if(satu - n < 0){
				satu += 1000;
			}
			else{
				System.out.print(satu - n);
				break;
			}
		}
	}
}

Measured memory_bytes: 35828
#include<iostream>
using namespace std;
int ctoi(char c){
  return c -'0';
}
int main(){
  string s; cin >> s;
  int ans=99999;
  for(int i=0;i<s.size()-2;i++){
    int a,b,c;
    a=ctoi(s[i]); b=ctoi(s[i+1]); c=ctoi(s[i+2]);
    int num = a*100+b*10+c;
    if(ans>=abs(num-753)) ans=abs(num-753);
    //cout << num << " " << ans << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int ans[] = new int[N];
        int a[] = new int[M];
        int b[] = new int[M];
        for (int i = 0; i < M; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();

            ans[a[i] - 1] += 1;
            ans[b[i] - 1] += 1;
        }

        for (int i = 0; i < N; i++) {
            System.out.println(ans[i]);
        }
    }
}

Measured memory_bytes: 21716
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = list(input())
K = int(input())


def ans():
    for i in range(K):
        if S[i] != '1':
            return S[i]

    return '1'


print(ans())


Measured memory_bytes: 9736
#include <bits/stdc++.h>
#define M 1111

using namespace std;

priority_queue <int> Q;

int A[M], B[M], tmp[M], vis[M], n;

bool cmp(int x, int y) {
	return A[x] < A[y];
}

int ans = 0;

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= 2 * n; i++) scanf("%d%d", &A[i], &B[i]), tmp[i] = i;
	sort(tmp + 1, tmp + 2 * n + 1, cmp);
	for(int i = 1; i <= 2 * n; i++) {
		int x = tmp[i];
		if(x > n) {
			for(int i = B[x] - 1; i >= 0; i--)
				if(vis[i]) {
					vis[i] = 0;
					ans++;
					break;
				}
		} else vis[B[x]] = 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h = S/3600;
        int m = (S-(h*3600))/60;
        int s = S-(h*3600)-(m*60);
        System.out.println(h+":"+m+":"+s);
    }
}


Measured memory_bytes: 26132
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;


const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main() {
  int n;
  cin >> n;
  mint ans = 1;
  rep(i,n){
    ans*=(i+1);
  }
  print(ans.x);
  return 0;
}

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

def main():
    H, W = map(int, input().split())
    a = []
    for i in range(H):
        tmp = str(input())
        if "#" in tmp:
            a.append(tmp)
    binary = [1]*W
    for i in range(len(a)):
        for j in range(W):
            if a[i][j] == "#":
                binary[j] = 0
    for i in range(len(a)):
        tmp = ""
        for j, b in enumerate(binary):
            if b == 0:
                tmp += a[i][j]
        print(tmp)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
N = gets.chomp.to_i
W = gets.chomp.split.map(&:to_i)

ans = 100 * 100 + 1
0.upto(N - 2) { |i|
  s1 = W.select.with_index { |n, ind| ind <= i }.inject(:+)
  s2 = W.select.with_index { |n, ind| ind > i }.inject(:+)
  ans = [ans, (s1 - s2).abs].min
}

puts ans


Measured memory_bytes: 3964
#include <stdio.h>
 
int main(void) {
    long N,A,B;
    long x,y;
    scanf("%ld %ld %ld", &N, &A, &B);
 
    x = N/(A+B);
    y = N%(A+B);
    y = y > A ? A : y;
    
    x = A*x+y;
    printf("%ld\n", x);
 
    return 0;
}
 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n);i++)
#define rep1(i,n) for(int i=1; i<(n); i++)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;

template< int mod >
struct ModInt
{
  int x;

  ModInt() : x(0) {}

  ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p)
  {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p)
  {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p)
  {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p)
  {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const
  {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    return ModInt(u);
  }

  friend ostream &operator<<(ostream &os, const ModInt< mod > &p)
  {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt< mod > &a)
  {
    long long x;
    is >> x;
    a = ModInt< mod >(x);
    return (is);
  }

};

const int mod = 1e9 + 7;
using modint = ModInt< mod >;

modint dp[202][101010];
int main(){
    int n, x;
    cin >> n >> x;
    vector<int> s(n);
    rep(i, n) cin >> s[i];
    sort(all(s));
    reverse(all(s));
    dp[0][x] = 1;
    rep(i, n){
        rep(j, 100001) dp[i+1][j] = dp[i][j]*(n-1-i);
        rep(j, 100001) dp[i+1][j%s[i]] += dp[i][j];
    }
    modint ans = 0;
    rep(i, 100001) ans += dp[n][i]*(i%s[0]);
    cout << ans << endl;

}




Measured memory_bytes: 80000
#include <stdio.h>
#include <stdbool.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)

int par[101010];

void UnionFind(int N){
    for(int i = 0; i < N; i++) par[i] = i;
}

int root(int x) { 
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
}

void unite(int x, int y) {
    int rx = root(x); 
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry; 
}

bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
}


int main(){
    int n, q;
    scanf("%d%d", &n, &q);
    UnionFind(n);

    rep(i, q) {
        int com, x, y;
        scanf("%d%d%d", &com, &x, &y);
        if(com == 0) unite(x, y);
        else {
            if(same(x, y)) puts("1");
            else puts("0");
        }
    }
}




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

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define sc(a, n) int a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
#define int long long
const int inf = 2e9, maxn = 200000;

void solve(int ci)
{
   int a, b, h, m;
   cin >> a >> b >> h >> m;
   long double a1 = ((h * 60 + m) * 2 * atan2(0, -1)) / (12 * 60);
   long double a2 = (m * 2 * atan2(0, -1)) / 60;
   //cout << a1 << ' ' << a2 << '\n';
   cout.precision(30);
   cout << sqrtl(a * a + b * b - 2 * a * b * cos(min(abs(a1 - a2), 2 * atan2(0, -1) - abs(a1 - a2))));
}

main()
{
    //cout << atan2(0, -1);
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    f(t) solve(i + 1);
}


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

using namespace std;

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

    for (size_t i = 0; i < S.size(); i++) {
        string S_slide;
        S_slide = S.substr(i, S.size()-i) + S.substr(0, i);
        if(S_slide == T) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int> >

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;

int printYes() {
    cout << "Yes" << endl;
    return 0;
}

int printNo() {
    cout << "No" << endl;
    return 0;
}

int ans;

int printAns() {
    cout << ans << endl;
    return 0;
}


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
    int x1, y1, x2, y2, x3, x4, y3, y4;
    cin >> x1 >> y1 >> x2 >> y2;
    int deltaX, deltaY;
    deltaX = x2 - x1;
    deltaY = y2 - x1;
    x4 = -(y2 - y1) + x1;
    y4 = (x2 - x1) + y1;
    x3 = -(y1 - y4) + x4;
    y3 = (x1 - x4) + y4;
    cout << x3 << " " << y3 << " " << x4 << " " << y4;


    return 0;
}


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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}

int main() {
  string s;
  cin>>s;
  rep(i,s.size()-1){
    if(s[i]=='A' && s[i+1]=='C'){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 998244353
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	ll n, ma, mb;

	cin>>n>>ma>>mb;

	vll a(n), b(n), c(n);

	vector<vector<vector<ll>>> dp(n+1, vvll(405, vll(405, 1e18)));

	rep(i, n) cin>>a[i]>>b[i]>>c[i];

	//薬品iまで使ったとき，aの量がj，bの量がkにできる最小のコスト
	dp[0][0][0]=0;
	repr(i, 1, n+1){
		rep(j, 405){
			rep(k, 405){
				if(j>=a[i-1]&&k>=b[i-1]){
					dp[i][j][k]=min(dp[i-1][j][k], dp[i-1][j-a[i-1]][k-b[i-1]]+c[i-1]);
				}else{
					dp[i][j][k]=dp[i-1][j][k];
				}
			}
		}
	}
	//cout<<"OK"<<endl;

	ll ans=1e18;
	repr(j, 1, 405){
		repr(k, 1, 405){
			if(j%ma==0&&k%mb==0&&j/ma==k/mb){
				if(ans>dp[n][j][k]) ans=dp[n][j][k];
			}
		}
	}

	if(ans!=1e18){
		cout<<ans<<endl;
	} else{
		cout<<-1<<endl;
	}
}


Measured memory_bytes: 54656
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define ll long long
#define int ll
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
typedef pair <int, int> pii;

int n;
int initposition[101010];
int position[101010][25];
int ct[101010];
string str;
int32_t main()
{
    cin >> str;
    n = str.length();
    for (int i = 0; i<n; i++)
    {
        initposition[i] = i;
    }
    for (int i = 0; i<n; i++)
    {
        if (str[i] == 'L')
            position[i][0] = initposition[i]-1;
        if (str[i] == 'R')
            position[i][0] = initposition[i]+1;
    }
    for (int t = 1; t<=20; t++)
    {
        for (int i = 0; i<n; i++)
        {
            position[i][t] = position[position[i][t-1]][t-1];
        }
    }
    for (int i = 0; i<n; i++)
    {
        ct[position[i][20]]++;
    }
    for (int i = 0; i<n; i++)
    {
        printf("%lld ",ct[i]);
    }
    printf("\n");
}

Measured memory_bytes: 21888
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  sort(p.begin(), p.end());
  p[n-1] = p[n-1]/2; 
  int sum = 0;
  rep(i, n) sum += p[i];
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#create date: 2020-07-03 11:44

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, k = na()
    a = na()
    visited_time = [-1] * n
    visited_time[0] = 0
    x, t = 0, 0
    while True:
        x = a[x] - 1
        t += 1
        if visited_time[x] > 0:
            b = visited_time[x]
            r = t - visited_time[x]
            break
        else:
            visited_time[x] = t
    if k <= b:
        print(visited_time.index(k) + 1)
    else:
        c = (k-b) % r
        print(visited_time.index(b+c) + 1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 31268
#include <stdio.h>
int total;
int val;
long max=-1000000;
long min=1000000;
long sum=0;
int x;

main(){

  scanf("%d",&total);
  if(total>0&&total<=10000){
  
  for (x=1;x<=total;x++){
   scanf("%d",&val);
   
   if(max<val){
   max=val;
   }
   if(min>val){
   min=val;
   }
   sum+=val;
  }
  }
  printf("%ld %ld %ld\n",min,max,sum);
  return 0;
}  
  

Measured memory_bytes: 600
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
#define INF 10000000
struct node{
	int to[2];
};
node N[6];
int main(){
	N[0].to[0]=1;
	N[0].to[1]=5;
	N[1].to[0]=INF;
	N[1].to[1]=2;
	N[2].to[0]=4;
	N[2].to[1]=3;
	N[3].to[0]=5;
	N[3].to[1]=1;
	N[4].to[0]=3;
	N[4].to[1]=5;
	N[5].to[0]=1;
	N[5].to[1]=INF;
	string str;
	while(cin >> str && str!="#"){
		int now=0;
		for(int i=0;i<str.size();i++){
			int rp=str[i]-'0';
			now=N[now].to[rp];
			if(now==INF) break;
		}
		if(now==3) puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int n,pos;
vector<int> pre,in,post;

void rec(int l,int r){ 
    if(l>=r)return;
    int root=pre[pos++];
    int m=distance(in.begin(),find(in.begin(),in.end(),root));        
    rec(l,m);
    rec(m+1,r);
    post.push_back(root);
}
void solve(){
    pos=0;
    rec(0,pre.size());
    for(int i=0;i<n;i++){
        if(i)cout<<" ";
        cout<<post[i];
    }   
    cout<<"\n";
}
int main(){
    int k;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>k;
        pre.push_back(k);
    }   
    for(int i=0;i<n;i++){
        cin>>k;
        in.push_back(k);
    }   
    solve();
    return 0;

}



Measured memory_bytes: 3140