akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <queue>
#include <iostream>
#include <cassert>

using namespace std;

int main() {
    string word,wordk;
    int num;
    queue<int> S;
    queue<string> M;
    int n,q,k;
    int timeS = 0 ;
    int timeN = 0 ;
    cin >> n >> q ;
    for(int i=0; i<n; ++i){
        // S???time???M???name?????\???
        cin >> word;
        M.push(word);
        cin >> num;
        // time???????¨???????????????????
        timeS += num;
        S.push(num);
    }
    while(S.front() > 0 && ! S.empty()) {
        if(S.front() > q){
            k = S.front();
            S.pop();
            S.push(k-q);
            wordk = M.front();
            M.pop();
            M.push(wordk);
            timeN += q;
        }
        else{
            timeN += S.front();
            cout << M.front() << " " << timeN << endl;
            
            S.pop();
            M.pop();
        }
    }
}

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

int main(){
	int n,ans;
	double xa,ya,ra;
	double xb,yb,rb;
	double ab;
	
	cin>>n;
	while(n--){
		cin>>xa>>ya>>ra>>xb>>yb>>rb;
		ab=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
		ans=1;
		if(ab>(ra+rb))ans=0;
		else if(ra>(ab+rb))ans=2;
		else if(rb>(ab+ra))ans=-2;
		cout<<ans<<endl;
		

	}

}

Measured memory_bytes: 1232
/*
ID: wangjun30
TASK:
LANG: C++
*/
#include<iostream>
using namespace std;
int main(){
	bool a;
	bool b;
	string s;
	cin>>s;
	int A=(s[0]-48)*10+(s[1]-48);
	int B=(s[2]-48)*10+(s[3]-48);
	a=(A>=1 && A<=12);
	b=(B>=1 && B<=12);
	if(a && b)
		cout<<"AMBIGUOUS";
	else
		if(a)
			cout<<"MMYY";
		else
			if(b)
				cout<<"YYMM";
			else
				cout<<"NA";
	return 0;
}

Measured memory_bytes: 256
input = STDIN.read.split("\n")
conflicts = input.slice(1..-1).map{|c| c.split(' ').map{|v| v.to_i}}

conflicts.sort_by!{|v| v[1]}

breaks = 0
prev_break = nil

conflicts.each do |c|
  breaking_bridge = c[1] - 1

  if prev_break == nil || prev_break < c[0]
    prev_break = breaking_bridge
    breaks = breaks + 1
  end
end

print breaks


Measured memory_bytes: 20344
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

 
int n;
char s[1000][1001];
int t[1001][1001];

int solve(){
	memset(t,0,sizeof(t));
	for(int i =0 ; i < n; i++){
		char s[1001]; cin>>s;
		for (int j = 0; j < n; j++){
			t[i+1][j+1] = (s[j] == '.') + t[i][j+1] + t[i+1][j] - t[i][j];
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			int a = 0;
			for (int k = 1; k <= min(n - i,n - j); k++){
				int s = t[i+k][j+k] - (t[i][j+k] + t[i+k][j] - t[i][j]);
				if(s != k * k) break;
				a = k;
			}
			ans = max(ans,a);
		}
	}
	return ans;
}

int main(){
    while(cin>>n,n){
        cout << solve() << endl;
    }
    return 0;
}

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

const int MAX_NODE = 100;

int main() {
	int nodes[MAX_NODE + 1];
	int last = 0, from, to;
	memset(nodes, 0, sizeof(nodes));
	while (cin >> from >> to) {
	  
	  if (from == 0 && to == 0) {
	    bool check=true;
	    if(nodes[1]%2==0 || nodes[2]%2==0)
	      check=false;
	    for(int i=3;i<=last;i++)
	      {
		if(nodes[i]%2!=0)
		  check=false;
	      }
	    /* output the answerer */
	    if(check)
	      cout<<"OK"<<endl;
	    else
	      cout<<"NG"<<endl;
	    memset(nodes, 0, sizeof(nodes));
	    last=0;
	  }
	  else {
	    /* update the `nodes` */
	    nodes[from]++;
	    nodes[to]++;
	    last = max(max(from,to),last);
	  }
	}
	return 0;
}

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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)




int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N; cin >> N;
  vector<int> A(3*N);
  for (int i = 0; i < 3*N; i++) cin >> A.at(i);

  priority_queue<int, vector<int>, greater<int>> front;
  priority_queue<int> back;
  vector<ll> fv(N+1);
  vector<ll> bv(N+1);

  ll sum = 0;
  for (int i = 0; i < N; i++) {
    sum += A.at(i);
    front.push(A.at(i));
  }
  fv.at(0) = sum;
  for (int i = 0; i < N; i++) {
    int a = A.at(N + i);
    sum += a;
    front.push(a);
    int b = front.top(); front.pop();
    sum -= b;
    fv.at(i+1) = sum;
  }
  sum = 0;
  for (int i = N - 1; i >= 0; i--) {
    int a = A.at(2*N + i);
    sum += a;
    back.push(a);
  }
  bv.at(N) = sum;
  for (int i = N - 1; i >= 0; i--) {
    int a = A.at(N + i);
    sum += a;
    back.push(a);
    int b = back.top(); back.pop();
    sum -= b;
    bv.at(i) = sum;
  }
  ll ans = LLONG_MIN;
  for (int i = 0; i <= N; i++) {
    ans = max(ans, fv.at(i) - bv.at(i));
  }
  cout << ans << endl;


  return 0;
}



Measured memory_bytes: 4216
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define F first
#define S second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
int main()
{
  int n; cin >> n;
  vector<ll> a(n);
  rep(i,n) {
    cin >> a[i];
  }
  
  ll x = 0;
  ll res = 0;
  rep(i,n) {
    if(a[i] >= x) {
      x = a[i];
    }
    else {
      res += x - a[i];
    }
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 4844
#include <iostream>

char board[300][300];

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

	for (int y = 0; y < n; ++y)
		for (int x = 0; x < n; ++x)
			std::cin >> board[y][x];

	auto check = [n](int k) -> bool {
		for (int y = 0; y < n; ++y)
			for (int x = 0; x < n; ++x)
				if (board[(k + y) % n][x] != board[(k + x) % n][y])
					return false;

		return true;
	};

	int ans = 0;
	for (int i = 0; i < n; ++i)
		if (check(i))
			ans += n;

	std::cout << ans << std::endl;
}

Measured memory_bytes: 384
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func NextFloat() float64 {
  n, _ := strconv.ParseFloat(NextLine(), 64)
  return n
}
func NextFloatVec() []float64 {
  L := strings.Split(NextLine(), " ")
  N := make([]float64, len(L))
  for i := range N {
    N[i], _ = strconv.ParseFloat(L[i], 64)
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int32) int32 {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}

func Solve() {
  S := NextLine()
  N := len(S)
  K := NextInt()
  M := make([][]int, 26)
  for i := range M {
    M[i] = make([]int, N)
  }
  for i, s := range S {
    m := int(s) - int('a')
    M[m][i] = i + 1
  }
  for i := range M {
    for j := N - 1; 0 < j; j-- {
      if 0 < M[i][j - 1] { continue }
      M[i][j - 1] = M[i][j]
    }
  }
  DP := make([][][]int32, K + 1)
  for i := range DP {
    DP[i] = make([][]int32, N)
    for j := range DP[i] {
      DP[i][j] = make([]int32, N)
      for k := 0; k < i + 1; k++ {
        if N <= j + k { continue }
        DP[i][j][j + k] = int32(k + 1)
      }
    }
  }
  for i := range DP {
    for j := N - 1; 0 <= j; j-- {
      for k := j + 1; k < N; k++ {
        DP[i][j][k] = MaxInt(DP[i][j][k - 1], DP[i][j][k])
        l := M[int(S[k]) - int('a')][j]
        if l <= k {
          DP[i][j][k] = MaxInt(DP[i][l][k - 1] + 2, DP[i][j][k])
        }
        if j < N - 1 {
          DP[i][j][k] = MaxInt(DP[i][j + 1][k], DP[i][j][k])
        }
        if 0 < i {
          DP[i][j][k] = MaxInt(DP[i - 1][j][k], DP[i][j][k])
          DP[i][j][k] = MaxInt(DP[i - 1][j + 1][k - 1] + 2, DP[i][j][k])
        }
      }
    }
  }
  Write(DP[K][0][N - 1])
  return
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 129480
main :: IO ()
main = do
  s <- getLine
  putStrLn $ show $ length $solve [] s 


solve :: String -> String -> String
solve stack [] = stack
solve [] (x:xs) = solve [x] xs
solve (s:st) (x:xs)
    | s == 'S' && x == 'T' = solve st xs
    | otherwise            = solve (x:s:st) xs

Measured memory_bytes: 13948
N=int(input())
a = list(map(int,input().split()))

up = 0
down = sum(a)
result = abs(a[0]-(sum(a)-a[0]))

for i in a[:-1]:
    up += i
    down -= i
    if result > abs(up-down):
        result = abs(up-down)

print(result)

Measured memory_bytes: 24832
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

const int maxn = 1e5 + 1;
const int MOD = 1e9 + 7;

vector<long long> fact(maxn + 1, 1);
vector<long long> inv(maxn + 1, 1);

long long mod_pow(long long a, long long b, long long p = MOD) { // = (a^b) % p //((a^-1) % p) = (a^(p-2)) % p;
	long long res = 1;
	a %= p;

	while (b > 0) {
		if ((b & 1) == 1) res = ((res % p) * (a % p)) % p;
		a = ((a % p) * (a % p)) % p;
		b >>= 1;
	}
	return res;
}

void preC() {
	for (long long i = 1; i <= maxn; i++) {
		fact[i] = (i * fact[i - 1]) % MOD;
		inv[i] = (mod_pow(i, MOD - 2) * inv[i - 1]) % MOD;
	}
}

long long C(long long n, long long r) { // nCr % MOD
	if (n < r) return 0;
	return (fact[n] * ((inv[r] * inv[n - r]) % MOD)) % MOD;
}


int main() {

	preC();
	long long  n, k; cin >> n >> k;

	vector<long long > a(n + 1, 0); for (long long  i = 1; i <= n; i++) cin >> a[i];
	sort(a.begin() + 1, a.end());

	long long  ans = 0;
	for (long long  i = 1; i <= n; i++) {
		ans = ((ans % MOD) + ((a[i] % MOD ) * ((C(i - 1, k - 1) - C(n - i, k - 1) + MOD) % MOD)) % MOD) % MOD;
	}

	cout << (ans + MOD) % MOD;

	return 0;
}

Measured memory_bytes: 5236
#include<bits/stdc++.h>
using namespace std;
const int Maxn=1e5+10;
int N,K;
int H[Maxn],Dp[Maxn];
int main()
{
	cin>>N>>K;
	memset(Dp,0x3f,sizeof(Dp));
	Dp[1]=0;
	for(int i=1;i<=N;i++)
	{
		cin>>H[i]; 
		for(int j=i-1;j>=max(i-K,1);j--) Dp[i]=min(Dp[i],Dp[j]+abs(H[i]-H[j]));
	}
	cout<<Dp[N]<<endl;
	return 0;
}

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

int main(){
    int x, n;
    cin >> x >> n;
    int p[101] = {0};
    int a;
    for(int i = 0; i < n; i++){
        cin >> a;
        p[a] = 1;
    }

    if(n == 0){
        cout << x << endl;
        return 0;
    }
    int min_x = 100000000;
    int index = 0;
    for(int i = 203; i >= -103; i--){
        if(i <= 0 || i >= 101){
            if(min_x >= abs(x-i)){
                min_x = abs(x-i);
                index = i;
            }
        }else{
            if(p[i] == 0){
                if(min_x >= abs(x-i)){
                    min_x = abs(x-i);
                    index = i;
                }
            }
        }
    }

    cout << index << endl;
    return 0;
}

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

#define FOR(s, i, n) for(ll i = s; i n; i++)
typedef long long ll;
const int INF = 1e9;
const int S = 200;
inline ll f(ll a){
	return a*a*a*a*a;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll x;
	cin>>x;
	FOR(-S, a, <S){
		FOR(-S, b, <S){
			if(f(a)-f(b) == x){
				cout<<a<<' '<<b<<'\n';
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
string str;
int main()
{
	cin>>str;
	for(int i=0;i<str.size();i++)
	{
		if(str[i]=='A' && str[i+1]=='C'){cout<<"Yes"<<endl;return 0;}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000000
using namespace std;
using ll = long long;
int main()
{
    string s;
    cin >> s;
    if((s[0]==s[1]||s[3]==s[2])&&(s[1]==s[2])){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int l,r,d;
	cin>>l>>r>>d;
	long long int x=(l/d)*d;
	long long int y=(r/d)*d;
	if(x<l){
		x+=d;
	}
	cout<<(y/d)-(x/d)+1;
	return 0;
}

Measured memory_bytes: 3608
# coding: utf-8
# Your code here!

def F(n, m):
  return max(len(str(n)), len(str(m)))

n = int(input())
ans = len(str(n))
for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
        ans = min(ans, F(i, n//i))
print(ans)        


Measured memory_bytes: 9300
a,b = map(int, input().split())

if a % 2 == 0:
  mod = (b-a) % 4
  
  xor = b - mod
  for i in range(b-mod+1, b+1):
    xor ^= i
    
else:
  tmp = a+1
  mod = (b-tmp) % 4
  
  xor = a
  for i in range(b-mod, b+1):
    xor ^= i
    
print(xor)

Measured memory_bytes: 3060
//#pragma GCC optimize(3)
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set> 
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define db double
#define inf 200001
#define INF (int)2e9 
#define mod (ll)(1e9+7)
#define pi acos(-1)
#define mxbit 30
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;
int n;

struct data{
	int x,id;
	data(){}
	data(int xx,int ii){
		x=xx,id=ii;
	}
}a[inf];
int id[inf];

bool operator<(data _1,data _2){
	return _1.x<_2.x;
}

struct edge{
	int y,nxt;
	edge(){}
	edge(int yy,int nn){
		y=yy,nxt=nn;
	}
}e[inf*4*4];
int head[inf*8],ecnt;

void addedge(int x,int y){
	ecnt++;
	e[ecnt]=edge(y,head[x]);
	head[x]=ecnt;
	return;
}

int scc[inf*8],dfn[inf*8],low[inf*8];
int sta[inf*8],top,T,pcnt;

void dfs(int u){
	dfn[u]=low[u]=++T;
	sta[++top]=u;
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].y;
		if (!dfn[v]){
			dfs(v);
			low[u]=min(low[u],low[v]);
		}
		else if (!scc[v]){
			low[u]=min(low[u],dfn[v]);
		}
	}
	if (dfn[u]==low[u]){
		++pcnt;
		while (top){
			scc[sta[top]]=pcnt;
			if (sta[top]==u){
				top--;
				break;
			}
			top--;
		}
	}
	return;
}

bool two_sat(void){
	for (int i=0;i<2*n;i++){
		if (!dfn[i]){
			dfs(i);
		}
	}/*
	for (int i=0;i<2*n;i++){
		for (int j=head[i];j;j=e[j].nxt){
			printf("%d ",e[j].y);
		}
		puts("");
	}
	system("pause");*/
	for (int i=0;i<2*n;i++){
		if (scc[i]==scc[id[a[i].id^1]]){
			return 0;
		}
	}
	return 1;
}

void ST_build(int u,int l,int r){
	if (l==r){
		addedge(u+2*n-1,id[a[l].id^1]);
		return;
	}
	int mid=(l+r)/2;
	ST_build(u*2,l,mid);
	ST_build(u*2+1,mid+1,r);
	addedge(u+2*n-1,u*2+2*n-1);
	addedge(u+2*n-1,u*2+1+2*n-1);
	return;
}

void ST_link(int u,int l,int r,int L,int R,int p){
	if (R<L){
		return;
	}
	if (L<=l && r<=R){
		addedge(p,u+n*2-1);
		return;
	}
	int mid=(l+r)/2;
	if (L<=mid){
		ST_link(u*2,l,mid,L,R,p);
	}
	if (R>mid){
		ST_link(u*2+1,mid+1,r,L,R,p);
	}
	return;
}

void clear(void){
	memset(head,0,sizeof(head));
	memset(dfn,0,sizeof(dfn));
	memset(low,0,sizeof(low));
	memset(scc,0,sizeof(scc));
	memset(sta,0,sizeof(sta));
	top=T=ecnt=pcnt=0;
	return;
}

bool check(int k){
	clear();
	ST_build(1,0,2*n-1);
	for (int i=0;i<n*2;i++){
		int fr=lower_bound(a,a+n*2,data(a[i].x-k+1,0))-a;
		int bk=upper_bound(a,a+n*2,data(a[i].x+k-1,0))-a-1;
		ST_link(1,0,2*n-1,max(fr,0),i-1,i);
		ST_link(1,0,2*n-1,i+1,min(bk,n*2-1),i);
	}
	return two_sat();
}

int main(){
	rd(n)
	int maxp=0;
	for (int i=0;i<n*2;i++){
		rd(a[i].x)
		a[i].id=i;
		maxp=max(maxp,a[i].x);
	}
	sort(a,a+n*2);
	for (int i=0;i<n*2;i++){
		id[a[i].id]=i;
	}
	int l=0,r=maxp,ans=0;
	while (l<=r){
		int mid=(l+r)/2;
		if (check(mid)){
			ans=mid;
			l=mid+1;
		}
		else{
			r=mid-1;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 43264
#include <iostream>
#include "bits/stdc++.h"

using namespace std;

int main()
{
	string S;
	cin >> S;
	long long ans, t = 0;
	for(auto s : S){
		if (s == 'A' || s == 'C' || s == 'G' || s == 'T') {
			t++;
		}
		else {
			t = 0;
		}
		ans = max(t, ans);
	}
	cout << ans;
	cout << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	W, H, x, y := nextInt(), nextInt(), nextInt(), nextInt()
	area := float64(W * H) / 2.0

	hasMany := 0
	if float64(x) == float64(W)/2.0 && float64(y) == float64(H)/2.0 {
		hasMany = 1
	}

	fmt.Printf("%f %d\n", area, hasMany)
}

Measured memory_bytes: 640
from itertools import product

n, m = list(map(int, input().split()))
s = []
for _ in range(m):
    _, *si = list(map(int, input().split()))
    s.append(si)
p = list(map(int, input().split()))

ans = 0
for l in product([False, True], repeat=n):
    sat = 0
    for si, pi in zip(s, p):
        cnt = 0
        for ssi in si:
            if l[ssi - 1]:
                cnt += 1

        if cnt % 2 != pi:
            break
        else:
            sat += 1
    if sat == m:
        ans += 1

print(ans)


Measured memory_bytes: 40816
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
int S(int n) {
	int ret = 0;
	while (n > 0) {
		ret += n % 10;
		n /= 10;
	}
	return ret;
}
void check(vector< int > &ans, int n) {
	while (ans.size() > 0 && n * S(ans[ans.size() - 1]) < ans[ans.size() - 1] * S(n)) {
		ans.pop_back();
	}
	ans.push_back(n);
}
signed main() {
	cin >> K;
	vector< int > ans;
	for (int i = 1; i < 100; i++)
		check(ans, i);
	int nine = 0, ue = 1;
	while (1) {
		for (int a = ue * 100; a < ue * 1000; a += ue) {
			check(ans, a + nine);
		}
		nine = nine * 10 + 9;
		ue *= 10;
		if (ue * 100 + nine > 1e15)
			break;
	}
	rep(i, K) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[100000];
int main (){
	cin >> n;
	for (int i=0;i<n;++i){
		cin >> a[i];
	}
	sort (a,a+n);
	cout << a[n-1]-a[0];
	return 0;
}


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


int main()
{
	int n,a,count=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		if(a!=i) count++;
	}
	if(count<=2) printf("YES");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define pii pair<ll,ll>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
# define ll long long int
int n;
ll w[101],v[101];
ll dp[101][100001];
ll solve(int i,int w1)
{
	if( w1==0 || i==n)
		return dp[i][w1]=0;

	if(dp[i][w1]!=-1)
		return dp[i][w1];
	ll b=solve(i+1,w1);
	if(w1 < w[i])
		return dp[i][w1]=b;
	ll a;
	if(w1 >= w[i])
	a=(ll)v[i]+solve(i+1,w1-w[i]);
	
	return dp[i][w1]=max(a,b);
}
int main() 
{
	int w1;
	cin>>n>>w1;
	
	int i,j;
	for(i=0;i<n;i++)
		cin>>w[i]>>v[i];
	for(i=0;i<101;i++)
	for(j=0;j<100001;j++)
	dp[i][j]=-1;
	cout<<solve(0,w1)<<endl;







}


Measured memory_bytes: 79104
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import random
#####################################
n,d=INPUT()
ans=0
for _ in range(n):
    x,y=INPUT()
    if M.sqrt(x**2+y**2)<=d:
        ans+=1
print(ans)


Measured memory_bytes: 78332
def grid_bfs():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    from collections import deque
    dire = ((0, -1), (-1, 0), (1, 0), (0, 1))
    def bfs(sx, sy):
        dist = [[-1]*W for _ in range(H)] # 未訪問は-1,訪問済みは距離
        dist[sx][sy] = 0
        que = deque([(sx, sy)]) # (sx, sy)からスタート
        while que:
            x, y = que.popleft()
            d = dist[x][y]
            for dx, dy in dire:
                nx,ny = x+dx,y+dy
                # 内部で、通行可能('.')で、未訪問なら距離を更新し、dequeに入れる
                if 0<=nx<H and 0<=ny<W and S[nx][ny] == '.' and dist[nx][ny] == -1:
                    dist[nx][ny] = d+1
                    que.append((nx, ny))
        return max(map(lambda x: max(x), dist)) # これは(sx,sy)からの最長距離



    ans = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                ans = max(ans, bfs(i, j))
    print(ans)

grid_bfs()

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

int main() {
    string s;

    cin >> s;

    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector <long long int> A(100003);

  long long int sum=0;

  for (int i=1; i<N+1; i++){
    long int j=0;
    cin >> j;
    A.at(j)++;
    sum+=j;
  }

  long long int Q;
  cin >> Q;

  vector <long long int> B(Q),C(Q);
  for(long long int i=0; i<Q; i++){
    cin >> B.at(i) >> C.at(i);
  }

  for(long long int i=0; i<Q; i++){
    sum+=(C.at(i)-B.at(i))*A.at(B.at(i));
    A.at(C.at(i))+=A.at(B.at(i));
    A.at(B.at(i))=0;

    cout << sum<<endl;
  }
}


Measured memory_bytes: 5632
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<vector<char>> grid(h+2, vector<char>(w+2, '#'));
    rep(i,h)rep(j,w) cin >> grid[i+1][j+1];
    rep(i,h+2){
        rep(j,w+2) cout << grid[i][j];
        cout << endl;
    }
    return 0;
}

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

int main(){
  int a;
  int b;
  int i;
  
  cin >> a;
  cin >> b;
  
  for(i=1;i<1251;i++){
    int i_a = i * 2 / 25;
    int i_b = i / 10 ;
   // cout << i << ":" << i_b << endl;
    if (i_a == a && i_b == b){
      cout << i << endl;
      break;
    }

  }
  
  if(i==1251){
    cout << "-1" << endl;
  }
}

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

int A,B,C,X,Y;

int main(){
    cin>>A>>B>>C>>X>>Y;

    long long ans = 0;;

    if(A+B>=2*C){
        int ab = 2 * min(X,Y);
        int a = X - ab/2;
        int b = Y - ab/2;

        if(A>=2*C){
            ab += a*2;
            a=0;
        }

        if(B>=2*C){
            ab += b*2;
            b=0;
        }
        ans = a*A + b*B + ab*C;
        
    } else {
        ans = X*A + Y*B;
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    
    if (m1 != m2) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
        
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
//#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PI;
typedef pair< PI, int> PII;
#define pb push_back
#define Key_value ch[ch[root][1]][0]
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define MS(x,y) memset(x,y,sizeof(x))
const double eps = 1e-6;
const double pi = acos (-1.0);
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int M = 300005;

int s[1050][1050];

int main()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    if(n % x == 0 && m % y == 0) return 0 * puts("No");
    cout << "Yes" << endl;
    for(int i = 0; i < n; i += x)
        for(int j = 0; j < m; j += y) s[i][j] = 1e6;
    for(int i = x - 1; i < n; i += x)
        for(int j = y - 1; j < m; j += y) s[i][j] = -1e6 -1;
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < m; ++j)
        {
            if(j != m - 1) cout << s[i][j] << " ";
            else cout << s[i][j] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
signed main(){
  int h,w;
  cin>>h>>w;
  int a[h]={},b[w]={};
  string s[h];
  r(i,h)cin>>s[i];
  r(i,h){
    int S=0;
    r(j,w)if(s[i][j]=='#')S++;
    if(!S)a[i]=1;
  }
  r(i,w){
    int S=0;
    r(j,h)if(s[j][i]=='#')S++;
    if(!S)b[i]=1;
  }
  r(i,h){
    if(a[i]==1)continue;
    r(j,w)if(b[j]==0)cout<<s[i][j];
    cout<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s, t, ans;
int dp[3010][3010];
int main()
{
    cin >> s >> t;
    int m, n;
    m = s.length(); n = t.length();
    for (int i = 1; i <= m; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            if (s[i - 1] == t[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
        }
    }
    int x = m;
    int y = n;
    while (x && y)
    {
        if (s[x - 1] == t[y - 1])
        {
            ans = s[x - 1] + ans;
            x--;
            y--;
        }
        else
        {
            if (dp[x][y] == dp[x - 1][y])
                x--;
            else
                y--;
        }
    }
    cout << ans;
    return 0;
}

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

int main(){
	int A,B,K;
	cin >> A >> B >> K;
	for (int i=1 ; i<=K ; i++){
		if (i%2==1){
			B += A/2;
			A/=2;
		}
		else {
			A += B/2;
			B /= 2;
		}
	}
	cout << A << " " << B;
	return 0;
}

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

int main(){
    int r,c,mat[101][101]={0};
    cin>>r>>c;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cin>>mat[i][j];
            mat[i][c]+=mat[i][j];
            mat[r][j]+=mat[i][j];
            mat[r][c]+=mat[i][j];
        }
    }
    for(int k=0;k<r+1;k++){
        for(int l=0;l<c+1;l++){
            cout<<mat[k][l];
            if(l==c)cout<<"\n";
            else cout<<" ";
        }    
    }

    return 0;
}


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

#define int           long long 
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (int)(1e9)
// #define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v){
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}

void solve(int &test) {
    char c; cin >> c;
    if(c >= 'A' && c <= 'Z'){
        cout << 'A' << endl;
    } else cout << 'a' << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;

    start = clock(); 

    cout << fixed << setprecision(20);
    
   
    // cin >> t;
     
    for(int i = 1; i <= t; ++i){
        solve(i);
    }
    //cerr << time(start);
    return 0;
}

Measured memory_bytes: 3652
import heapq

x, y, z, k =  map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

hq = [[-a[0]-b[0]-c[0], 0, 0, 0]]
heapq.heapify(hq)
visited = {(0,0,0)}

for i in range(k):
    ii, ia, ib, ic = heapq.heappop(hq)
    print(-ii)
    na = min(ia+1, x-1)
    nb = min(ib+1, y-1)
    nc = min(ic+1, z-1)
    if not (na, ib, ic) in visited:
        heapq.heappush(hq, [-a[na] -b[ib] -c[ic], na, ib, ic])
        visited.add((na, ib, ic))
    if not (ia, nb, ic) in visited:
        heapq.heappush(hq, [-a[ia] -b[nb] -c[ic], ia, nb, ic])
        visited.add((ia, nb, ic))
    if not (ia, ib, nc) in visited:
        heapq.heappush(hq, [-a[ia] -b[ib] -c[nc], ia, ib, nc])
        visited.add((ia, ib, nc))


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

const int N = 2000000;
int prime[N];

void Eratos(){
	for(int i=0; i<N; i++){
		prime[i] = 1;
	}

	prime[0] = prime[1] = 0;
	for(int i=2; i*i<=N; i++){
		if(prime[i] == 1){
			for(int j=i*2; j<N; j+=i){
				prime[j] = 0;
			}
		}
	}
}

int main(void){
	Eratos();
	while(1){
		int a, d, n;
		cin >> a >> d >> n;

		if(a == 0 && d == 0 && n == 0) break;

		int s = a;
		int cnt = 0;
		for(int i = 0; ; i++){
			if(prime[s] == 1){
				cnt++;
				if(cnt == n) {
					cout << s << endl;
					break;
				}
			}
			s += d;
		}
	}


	return 0;
}

Measured memory_bytes: 8972
#include <cstdio>

int main() {
    int a, b, c;
    long long k;
    scanf("%d%d%d%lld", &a, &b, &c, &k);

    int ans = a - b;
    if (k % 2)
        ans = -ans;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		String st = sc.next();
		ArrayList<String> arr = new ArrayList<>();
		int K = sc.nextInt();

		for(int t=1;t<=K;t++){
			for(int s=0;s<st.length()-t+1;s++){
				arr.add(st.substring(s,s+t));
			}
		}

		Set<String> set = new HashSet<>(arr);
		List<String> list = new ArrayList<>(set);

		Collections.sort(list);

		System.out.println(list.get(K-1));

	}
}

Measured memory_bytes: 25812
#include<stdio.h>
int a,b,c;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	printf("%d %d %d\n",a,b,3*c-a-b);
	printf("%d %d %d\n",(c<<2)-(a<<1)-b,c,(a<<1)+b-(c<<1));
	printf("%d %d %d\n",a+b-c,(c<<1)-b,(c<<1)-a);
	return 0 ;
}

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

int main(void){
  int n;
  bool ans=1;
  cin >> n;
  int a[n];
  for (size_t i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (size_t i = 0; i < n; i++) {
    if(a[i]%2==0){
      if(!(a[i]%3==0 || a[i]%5==0)){
        ans=0;
      }
    }
  }
  if(ans){
    cout << "APPROVED" << endl;
  }else{
    cout << "DENIED" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := range a {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}
	ans := 0
	for i := 0; i < n; i++ {
		for i+1 < n && a[i] == a[i+1] {
			i++
		}
		if i+1 < n && a[i] < a[i+1] {
			for i+1 < n && a[i] <= a[i+1] {
				i++
			}
		} else if i+1 < n && a[i] > a[i+1] {
			for i+1 < n && a[i] >= a[i+1] {
				i++
			}
		}
		ans++
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3072
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();

    int R = sc.nextInt();
    double ans = 2 * R * Math.PI;

    System.out.println(ans);

  }
}

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

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

  private int readByte() {
    if (hasNextByte()) {
      return buffer[ptr++];
    } else {
      return -1;
    }
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  private void skipUnprintable() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
      ptr++;
    }
  }

  public boolean hasNext() {
    skipUnprintable();
    return hasNextByte();
  }

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

  public int nextInt() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    int n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public long nextLong() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }
}

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

int main(){
    int N,A,B;
    cin >> N >> A >> B;
    cout << min(N * A, B) << endl;
}

Measured memory_bytes: 256
a = input()
b = input()
c = input()
card = a[0]
a = a[1:]
while True:
    if card == "a":
        if a == "":
            print('A')
            break
        card = a[0]
        a = a[1:]
    elif card == "b":
        if b == "":
            print('B')
            break
        card = b[0]
        b = b[1:]
    else:
        if c == "":
            print('C')
            break
        card = c[0]
        c = c[1:]


Measured memory_bytes: 3064
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve()
{
	string a, b, c;
	int x, y;
	cin >> a >> b >> x >> y >> c;
	if(c == a) x--;
	else y--;
	cout << x << " " << y << endl;
}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <map>
using namespace std;


int main(int argc, char const *argv[])
{
    string s, t;
    cin >> s >> t;

    map<char, char> m1;
    map<char, char> m2;
    bool ok = true;
    for (int i=0; i<s.size(); i++) {
        if (m1.count(s[i]) == 0) {
            m1[s[i]] = t[i];
        } else {
            if (m1[s[i]] != t[i]) {
                ok = false; break;
            }
        }
        if (m2.count(t[i]) == 0) {
            m2[t[i]] = s[i];
        } else {
            if (m2[t[i]] != s[i]) {
                ok = false; break;
            }
        }
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

const long double pi = 3.14159265358979323846;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout<<setprecision(25);
    //good luck kittu!
    int a, b, h, m;
    cin>>a>>b>>h>>m;

    long double h1 = 30*h, m1 = 6*m;
    h1 += m*0.5;
    long double hx = 1.0*a*sin(h1*pi/180.0), hy = 1.0*a*cos(h1*pi/180.0);
    long double mx = 1.0*b*sin(m1*pi/180.0), my = 1.0*b*cos(m1*pi/180.0);

    long double d = (hx-mx)*(hx-mx);
    d += (hy-my)*(hy-my);

    d = sqrt(d);
    cout<<d<<"\n";
}

Measured memory_bytes: 4160
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int H, W, c, A, ans = 0;
	cin >> H >> W;
	vector<vector<pair<int, int>>> a(10);
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> c;
			a[i].emplace_back(c, j);
		}
	}
	for (int i = 0; i < H * W; i++) {
		cin >> A;
		if (A == -1) continue;
		priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> b;
		b.emplace(0, A);
		vector<bool> d(10);
		vector<int> e(10, INT_MAX);
		e[A] = 0;
		while (!b.empty()) {
			pair<int, int> f = b.top();
			b.pop();
			d[f.second] = true;
			for (pair<int, int>& i : a[f.second]) {
				if (d[i.second]) continue;
				if (e[f.second] + i.first < e[i.second]) {
					e[i.second] = e[f.second] + i.first;
					b.emplace(e[i.second], i.second);
				}
			}
		}
		ans += e[1];
	}
	cout << ans;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
		int max = 0;
		int count = 0;
		for(int i=0; i<s.length(); i++){
			if(s.charAt(i) == 'A' || s.charAt(i) == 'C' || s.charAt(i) == 'G' || s.charAt(i) == 'T'){
				count++;
				if(count > max){
					max = count;
				}
			}else{
				count = 0;
			}
		}
		System.out.println(max);
	}
}

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

typedef pair<int,int> PII;
const int M=3e5+5;
int cntx[M],cnty[M];

set<PII> se;

int main()
{
	int h,w,m; scanf("%d%d%d",&h,&w,&m);
	int x,y;
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",&x,&y);
		cntx[x]++;
		cnty[y]++;
		se.emplace(x,y);
	}
	int mx=0,my=0;
	for(int i=1;i<=h;i++)
		mx=max(mx,cntx[i]);
	for(int i=1;i<=w;i++)
		my=max(my,cnty[i]);
	vector<int> vx,vy;
	for(int i=1;i<=h;i++)
		if(cntx[i]==mx) vx.push_back(i);
	for(int i=1;i<=w;i++)
		if(cnty[i]==my) vy.push_back(i);
	int f=0;
	int ans=mx+my-1;
	for(int i:vx)
	{
		for(int j:vy)
		{
			if(!se.count({i,j}))
			{
				ans=mx+my;
				f=1;
				break;
			}
		}
		if(f) break;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 23868
#include<stdio.h>
#define MAX 200000
int max(int a,int b){return a>b ? a: b;}
int min(int a,int b){return a<b ? a: b;}
int main(void){
    int R[MAX],i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&R[i]);
    int maxv=-2000000000;
    int minv=R[0];
    for(int i=1; i<n; i++){
        maxv=max(maxv,R[i]-minv);
        minv=min(minv,R[i]);
    }
    printf("%d\n",maxv);
    return 0;
}


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

int main(){
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  double Max=0;
  int all=0, sato=0;
  for(int i=0; i<100; i++){
    for(int j=0; j<100; j++){
    if(i+j==0) continue;
     for(int k=0; k<200; k++){
      for(int l=0; l<200; l++){
        double x = (c*k+d*l)*1000000/(a*i+b*j);
        if(a*i*100+b*j*100+c*k+d*l<=f && x/1000000 <=e&& x>=Max){
          Max=x;
          all=a*i*100+b*j*100+c*k+d*l;
          sato=c*k+d*l;
        }
     } 
    }
   } 
  }
  
  cout << all << " " << sato << endl;
  
}


Measured memory_bytes: 384
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>



using ll = long long;
const int M = 1000005;

int a[12][12];

using namespace std;
int main()
{
	int n;
	cin >> n;
	string s;
	map<string, int> mp;
	for (int i = 0;i < n;i++) {
		cin >> s;
		mp[s]++;
	}//文字入れて頻度もだす
	int ma = 0;
	
		for (auto a : mp) {
			ma = max(ma, a.second);
		}//最大頻度の奴求める
		for (auto a : mp) {
			if (a.second != ma)
				continue;
			cout << a.first<<endl;
		}
}

Measured memory_bytes: 17664
from collections import deque
import math
import copy
H,W = map(int,input().split())
maze = [list(input()) for _ in range(H)]
def bfs(maze,h,w,sx,sy):
    for y in range(h):
        for x in range(w):
            if maze[y][x]=='.':
                maze[y][x]=float('inf')

    maze[sy][sx]=0
    que=deque([[sy,sx]])
    while que:
        y,x=que.popleft()
        for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
            if 0 <= y+i < H and 0<=x+j<W:
                nexty,nextx=y+i,x+j
                dist=maze[nexty][nextx]
                if dist!='#':
                    if dist>maze[y][x]+1:
                        maze[nexty][nextx]=maze[y][x]+1
                        que.append([nexty,nextx])
    m = 0                   
    for l in maze:
      li = [i for i in l if i != '#' and i < 1000000]
      if len(li) > 0:
        m = max(m,max(li))
    return m
max_dist = -1  
for si in range(H):
  for sj in range(W):
    if maze[si][sj] == '#':
      continue
    copymaze = copy.deepcopy(maze)
    res = bfs(copymaze,H,W,sj,si)
    max_dist = max(max_dist,res)
print(max_dist)

Measured memory_bytes: 3444