akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int n = 0;
            n = sc.nextInt();
            int b, f, r, v;
            int[][][] a = new int[4][3][10];
            for (int i = 0; i < n; i++) {
                b = sc.nextInt();
                f = sc.nextInt();
                r = sc.nextInt();
                v = sc.nextInt();
                a[b-1][f-1][r-1] += v;
            }
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 3; j++) {
                    for (int k = 0; k < 10; k++) {
                        System.out.printf(" %d",a[i][j][k]);
                    }
                    System.out.printf("\n");
                }
                if(i!=3)System.out.println("####################");
            }
        }
    }
}


Measured memory_bytes: 30348
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int n; cin >> n;
  set<int> s;
  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    s.insert(a);
  }

  cout << s.size() << endl;
  return 0;
}



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

int main()
{
  string S,T,ans="Yes";
  int s,t;
  cin >> S >> T;
  int A[26], B[26], L;
  for (int i = 0; i < 26; ++i) {
    A[i] = -1;
    B[i] = -1;
  }

  L = S.length();
  for (int i = 0; i < L; ++i) {
    s = static_cast<int>(S[i]-'a');
    t = static_cast<int>(T[i]-'a');
    if (A[s] == -1 && B[t] == -1) {
      A[s] = t;
      B[t] = s;
    }else if (A[s] == t && B[t] == s) {
      continue;
    }else {
      ans = "No";
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <cstring>
#include <string.h>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	long long a = 2, b = 1;
  	int n;
  	cin >> n;
  
  	while (n--) {
      long long c = a + b;
      a = b;
      b = c;
    }
  	cout << a;

	return 0;
}

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

using namespace std;

int main() {
    int m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;

    if (m2 == m1 + 1) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <functional>
#include <queue>

#define ll long long

ll dp[3001][3001];

const ll mod = 998244353;

signed main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        std::ios_base::sync_with_stdio(false);
        std::cin.tie(NULL);
        std::cout.tie(NULL);
    }
    
    int n, s;
    std::cin >> n >> s;
    std::vector<ll> a(n);
    for (int i = 0; i != n; ++i)
        std::cin >> a[i];
    dp[0][0] = 2;
    dp[0][a[0]] = 1;
    for (int i = 1; i != n; ++i)
        for (int j = 0; j <= s; ++j)
            if (j - a[i] >= 0LL)
                dp[i][j] = (dp[i - 1][j] * 2 % mod + dp[i - 1][j - a[i]]) % mod;
            else
                dp[i][j] = dp[i - 1][j] * 2 % mod;
    std::cout << dp[n-1][s];
    return 0;
}

Measured memory_bytes: 73996
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

public class Main {
    public static void main(String args[]){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            String line;
            
            while((line=br.readLine())!=null){
                if(line.equals(""))break;
                String[] splited = line.split(" ");
                int n = Integer.parseInt(splited[0]);
                s = Integer.parseInt(splited[1]);
                if(n==0&&s==0)break;if(n>=10)System.out.println("0");
                    combis(1,n);
                    System.out.println(count);
                count=0;
            }         
        }catch(Exception e){e.printStackTrace();}
        
    }
    static int[] com = new int[10];
    static int count = 0,s=0;
    static void combis(int st,int r){
        if(st<=r){
            for(int i=(st==1)? 0:com[st-1]+1;i<=9-r+st;i++){
                com[st]=i;
                combis(st+1,r);
            }
        }else{
            //System.out.println(Arrays.toString(com));
            int sum=0; for(int i=1;i<=r;i++) sum+=com[i];
            if(sum==s)count++;
        }
        
        }
    static int _10Cn(int n){
            int _n=1,d=1;
            for(int i=1; i<=n;i++){
                _n*=11-i; d*=i;
            }
            return _n/d;
        }
}

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

int main(){
    int n,q;
    cin>>n>>q;
    vector<stack<int> > s(n);
    while(q--){
        int y;
        cin>>y;
        if(y==0){
            int t,x;
            cin>>t>>x;
            s[t].push(x);
        }
        else if(y==1){
            int t;
            cin>>t;
            if(!s[t].empty()){
                cout<<s[t].top()<<endl;
            }
        }
        else{
            int t;
            cin>>t;
            if(!s[t].empty()){
                s[t].pop();
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4352
import std.stdio, std.conv, std.string, std.algorithm,
       std.math, std.array, std.container, std.typecons;

void main() {
  auto s = readln.chomp;
  auto t = readln.chomp[0..$-1];
  if(s==t) writeln("Yes");
  else writeln("No");
}


Measured memory_bytes: 2600
from heapq import heapify, heappush, heappop

maxA = 10**5

N, M = map(int, input().split())
works = [[] for _ in range(maxA)]
for _ in range(N):
    A, B = map(int, input().split())
    works[A-1].append(-B)

PQ = []
ans = 0
for dayRest in range(1, M+1):
    for B in works[dayRest-1]:
        heappush(PQ, B)
    if not PQ: continue
    B = heappop(PQ)
    ans += -B

print(ans)


Measured memory_bytes: 17856
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
int main(){
    vvi v(3,vi(3));
    rep(i,3)rep(j,3)cin>>v[i][j];
    vector<vector<bool>> b(3,vector<bool>(3,false));
    ll n;cin>>n;
    rep(i,n){
        ll a;cin>>a;
        rep(j,3)rep(k,3)if(v[j][k]==a)b[j][k]=true;
    }
    bool ok=false;
    rep(i,3){
        bool o=true;
        rep(j,3)if(!b[i][j])o=false;
        if(o)ok=true;
    }
    rep(i,3){
        bool o=true;
        rep(j,3)if(!b[j][i])o=false;
        if(o)ok=true;
    }
    if(b[0][0]&&b[1][1]&&b[2][2])ok=true;
    if(b[0][2]&&b[1][1]&&b[2][0])ok=true;
    if(ok)out("Yes");
    else out("No");
}

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

const ll INF = 1e17;
const ll MOD = 1e9+7;

int main() {
    // input, ready
    int N;
    string S;
    cin >> N >> S;

    // resolve
    int ans=0;
    int pos = S.find("ABC");
    while (pos != std::string::npos) {
        ans++;
        pos = S.find("ABC", pos + 3);
    }

    // output
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
dp = [[0]*(n+1) for _ in range(n+1)]
for k in range(1,n+1):
    for i in range(n+1-k):
        if (n-k)%2==0:
            dp[i][i+k] = max(dp[i+1][i+k] + A[i], dp[i][i+k-1] + A[i+k-1])
        else:
            dp[i][i+k] = min(dp[i+1][i+k] - A[i], dp[i][i+k-1] - A[i+k-1])
print(dp[0][n])

Measured memory_bytes: 144680
#include<stdio.h>
int main(void)
{
	int a,b,n;
	char op;
	scanf("%d %c %d",&a,&op,&b);
	if(op=='+'){
		n=a+b;
	}
	else{
		n=a-b;
	}
	printf("%d\n",n);
	return 0;
}

Measured memory_bytes: 128
n, k = [int(i) for i in input().split()]
if n >= k:
	remain = n % k
	if remain > (k//2): 
		result = abs(remain-k)
	else:
		result = remain
else:
	if n > (k//2): 
		result = abs(n-k)
	else:
		result = n

print(result)

Measured memory_bytes: 3060
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n; 
int a[100005], b[100005], p[100005];
map< pi, int > mp;
pi x[100005], y[100005];

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
	
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		x[i].fs = a[i];
		x[i].sc = i;
	}  
	for(int i=1;i<=n;i++){
		cin >> b[i];
		y[i].fs = b[i];
		y[i].sc = i;
	}
	for(int i=1;i<=n;i++){
		mp[{a[i],b[i]}]++;
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	sort(x+1, x+n+1);
	sort(y+1, y+n+1);
	bool counter = true;
	bool flag = false;
	for(int i=1;i<=n;i++){
		if(a[i]>b[i]){
			counter = false;
		}
		if(mp[{ a[i],b[i] }])flag = true;
		if(a[i+1]<=b[i] && i+1<=n )flag = true;
	}
	for(int i=1;i<=n;i++){
		p[x[i].sc] = y[i].sc;
	}
	int cur = 1;
	int len = 0;
	do{
		cur = p[cur];
		len++;
	}while(cur!=1);
	if(len!=n)flag = true;
	if(!counter || !flag ){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;

return 0;
}
///....


Measured memory_bytes: 18176
import java.util.*;
import java.io.*;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String line = br.readLine();
		String[] str = line.split(" ");
		int n = Integer.parseInt(str[0]);
		UnionFind uf = new UnionFind(n);
		int q = Integer.parseInt(str[1]);

		for (int query=0; query<q; query++) {
			line = br.readLine();
			str = line.split(" ");
			int x = Integer.parseInt(str[1]);
			int y = Integer.parseInt(str[2]);

			if (line.startsWith("0")) {
				uf.unite(x,y);
			}else {
				System.out.println(uf.same(x,y)?"1":"0");
			}
		}

		br.close();
	}
}

class UnionFind {

	int[] node;

	UnionFind(int n){
		node = new int[n];
		for (int i=0; i<n; i++)
			node[i] = i;
	}

	int find(int x){
		if(node[x] == x)
			return x;
		return node[x] = find(node[x]);
	}

	boolean same(int x,int y){
		return find(x) == find(y);
	}

	void unite(int x,int y){
		if (find(x) == find(y))
			return;
		node[find(x)] = find(y);
	}
}

Measured memory_bytes: 65092
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (size_t i = 0; i < (n); i++)
#define nvec(T, v, n) vector<T> v(n); REP(i, n) {cin>>(v)[i];}
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(i, n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(i, n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}
#define vec2d(T, v, m, n) vector<vector<T>> (v)(m, vector<T>(n))
#define nvec2d(T, v, m, n) vec2d(T, v, m, n); REP(j, m){REP(i, n) {cin>>(v[j])[i];}}

#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))

#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))

#define pos position<int>
#define at_(p) at(p.x).at(p.y)

#define GCD(v) gcd(ALL(v), 0l)

template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}

template <typename T>
using vec =vector<T>;

template <typename T>
using vvec =vector<vector<T>>;



int main(){
  int n;
  cin>>n;
  vec<pair<int,bool>> v;
  v.reserve(2*n);
  int l;
  for (int i = 0; i < n; i++) {
    cin>>l;
    v.push_back(make_pair(i+l,1));
    v.push_back(make_pair(i-l,0));
  }
  SORT(v);

  long long g=1,h=v[0].second;
  long long co=0;
  for (int i = 1; i < n*2; i++) {
    if(v[i].first!=v[i-1].first){
      co+=h*(g-h);
      g=0;h=0;
    }
    g++;
    h+=v[i].second;
//   cout<<endl<<g<<" "<<h;
  }
  co+=h*(g-h);
  cout<<co;
}



/* きょむ〜 */


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

int w, h;
vector < vector <int> > block_map;

int xs, ys;
int xg, yg;

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

bool dfs( int x, int y )
{
	if ( block_map[y][x] == 0 || block_map[y][x] != block_map[yg][xg] )
		return false;
	if ( x == xg && y == yg )
		return true;

	block_map[y][x] = -1;
	for ( int i = 0; i < 4; i++ )
	{
		int nx = x + dx[i];
		int ny = y + dy[i];
		if ( nx < 0 || nx >= w || ny < 0 || ny >= h )
			continue;

		if ( block_map[ny][nx] != -1 && block_map[ny][nx] == block_map[yg][xg] )
		{
			if ( dfs( nx, ny ) )
			{
				return true;
			}
		}
	}

	return false;
}

int main( void )
{
	while ( 1 )
	{
		cin >> w >> h;
		if ( w == 0 && h == 0 )
			break;

		block_map = vector < vector <int> >( h, vector <int>(w,0) );
		
		cin >> xs >> ys >> xg >> yg;

		xs--;
		ys--;
		xg--;
		yg--;

		int n;
		cin >> n;
		for ( int i = 0; i < n; i++ )
		{
			int c, d, x, y;
			cin >> c >> d >> x >> y;
			x--;
			y--;

			if ( d == 0 )
			{
				for ( int by = 0; by < 2; by++ )
				{
					for ( int bx = 0; bx < 4; bx++ )
					{
						block_map[y+by][x+bx] = c;
					}
				}
			}
			else
			{
				for ( int by = 0; by < 4; by++ )
				{
					for ( int bx = 0; bx < 2; bx++ )
					{
						block_map[y+by][x+bx] = c;
					}
				}
			}
		}

		if ( dfs( xs, ys ) )
			cout << "OK" << endl;
		else
			cout << "NG" << endl;

	}
	return 0;
}

Measured memory_bytes: 0
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::vec::Vec;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        d: usize,
        g: usize,
        pc: [(usize, usize); d],
    };
    let mut min = usize::max_value();
    for complete_flag in 0..(1 << d) {
        let mut score = 0;
        let mut count = 0;
        for i in 0..d {
            if complete_flag & 1 << i != 0 {
                score += (i + 1) * 100 * pc[i].0 + pc[i].1;
                count += pc[i].0;
            }
        }
        if score < g {
            continue;
        }
        min = cmp::min(min, count);
        for i in 0..d {
            if complete_flag & 1 << i == 0 {
                continue;
            }
            let mut remain = pc[i].0;
            score -= pc[i].1;
            while score >= g && remain > 0 {
                score -= (i + 1) * 100;
                count -= 1;
                remain -= 1;
            }
            score += (i + 1) * 100;
            count += 1;
            if score >= g {
                min = cmp::min(min, count);
            }
        }
    }
    println!("{}", min);
}


Measured memory_bytes: 4352
INF = 10**18

H,W = map(int,input().split())
S = [input() for _ in range(H)]
N = H*W
cost = [[INF]*N for _ in range(N)]
for k in range(N):
    cost[k][k] = 0

dx = [1,0,-1,0]
dy = [0,1,0,-1]

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        k = i*W+j
        for d in range(4):
            if not(0<=i+dx[d]<H and 0<=j+dy[d]<W):
                continue
            if S[i+dx[d]][j+dy[d]] == '.':
                cost[k][(i+dx[d])*W+(j+dy[d])] = 1

for k in range(N):
    for i in range(N):
        for j in range(N):
            if cost[i][k]!=INF and cost[k][j]!=INF:
                cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j])

ans = 0

for i in range(N):
    for j in range(N):
        if cost[i][j]!=INF:
            ans = max(ans,cost[i][j])

print(ans)

Measured memory_bytes: 44764
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(void)
{
    int a, b;

    scanf("%d %*d %d %*d", &a, &b);
    printf("%d\n", a + 1 == b);

    return 0;
}


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

long long saisyou(long long a[],long long size){
  long long minv = INT_MAX;
  
  for (int i = 0;i<size;i++){
    if(a[i] < minv)
      minv = a[i];
  }

  return minv;

}


int main (){
  long long n;
  int i;
  cin >> n;

  long long a[n];
  long long ab[n];
  long long count = 0,sum = 0;

  for (i=0;i<n;i++){
    cin >> a[i];
    ab[i] = abs(a[i]);
    sum += ab[i];
    if (a[i] < 0)
      count += 1;
  }

  
  if (count%2 == 1)
    sum = sum - saisyou(ab,n)*2;

  cout << sum << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include "cstdio"
#include <string>
#include <vector>
 
#define NMAX 100
using namespace std;
 
int main(){
	int N,K,ans,D[10] = {};
	cin >> N >> K;
	for (int i = 0; i < K; ++i)
	{
		int a;
		cin >> a;
		D[a]++;
	}
	ans = N;
	while(true){
		int s = 1,ss = ans;
		while(ss){
			if(D[ss%10] == 1){
				s = 0;
				break;
			}
			ss /= 10;
		}
		if(s == 1){
			cout << ans <<"\n";
			break;
		}
		ans++;
	}
	return 0;
}

Measured memory_bytes: 256
a,b,n=map(int,input().split())
ans=0
if a<b:ans=(a*(min(b-1,n)))//b-a*(min(b-1,n)//b)
for i in range(1,min(a+10,n+1)):ans=max(ans,(a*i)//b-a*(i//b))
print(ans)

Measured memory_bytes: 9192
h, w = gets.strip.split.map(&:to_i)
s = readlines.map {|line| line.strip.split('') }

white_count = s.flatten.count {|e| e=='.' }

start = [0,0]
goal=[h-1, w-1]
queue = [ [ start, [start] ] ]
checked = {}

shortest = 10**12
until queue.empty?
  current, passed = queue.shift

  next if passed.length > shortest || checked[ current.to_s ]

  if current == goal
    shortest = passed.length if passed.length < shortest

#p [passed.length, passed]

    next
  end

  checked[ current.to_s ]=true

  y, x = current

  queue.push( [[y-1, x], passed.dup.push([y-1, x])] )  if (0...h)===(y-1) && (0...w)===(x) && !passed.include?( [y-1, x] ) && s[y-1][x]=='.'

  queue.push( [[y+1, x], passed.dup.push([y+1, x])] ) if (0...h)===(y+1) && (0...w)===(x) && !passed.include?( [y+1, x] ) && s[y+1][x]=='.'

  queue.push( [[y, x-1], passed.dup.push([y, x-1])] ) if (0...h)===(y) && (0...w)===(x-1) && !passed.include?( [y, x-1] ) && s[y][x-1]=='.'

  queue.push( [[y, x+1], passed.dup.push([y, x+1])] ) if (0...h)===(y) && (0...w)===(x+1) && !passed.include?( [y, x+1] ) && s[y][x+1]=='.'

end

if shortest > 10**10
  p -1
  exit
end

#p [white_count, shortest]
p white_count - shortest



Measured memory_bytes: 4732
import sys
input = sys.stdin.readline

N, Q = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]

class Tree:
  C = {}
  N, D = None, None
  def __init__(s, num):
    s.N = num
  def setC(s, a, b):
    if a in s.C: s.C[a].append(b)
    else: s.C[a] = [b]
    if b in s.C: s.C[b].append(a)
    else: s.C[b] = [a]
  def exe(s):
    L = [-1] * N
    A = [0] * N
    for p, x in px:
      p -= 1
      A[p] += x
    S = [0]
    while S != []:
      t = S.pop()
      L[t] = 1
      for i in s.C[t]:
        if L[i] == -1:
          A[i] += A[t]
          S.append(i)
    for i in range(N):
      print(A[i], end = " ")

T = Tree(N)
for a, b in ab:
  a -= 1
  b -= 1
  T.setC(a, b)

T.exe()



Measured memory_bytes: 136532
#include <stdio.h>

int main(void){
	int score_sum=0;
	int max,min;
	int i,j;
	int n;
	int score[5];

while((scanf("%d",&n))!=0){
	max=0;
	min=501;
	for(i=0;i<n;i++){
			scanf("%d %d %d %d %d",&score[0],&score[1],&score[2],&score[3],&score[4]);
			for(j=0;j<5;j++){
				score_sum=score_sum+score[j];
			}
			if(max<score_sum){
				max=score_sum;
			}
			if(min>score_sum){
				min=score_sum;
			}
			score_sum=0;
	}

	if(n==0){return 0;}
	printf("%d %d\n",max,min);
	
}
	return 0;
}

Measured memory_bytes: 1028
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    struct State
    {
        internal int x, y, cnt;

        public State(int x, int y, int cnt)
        {
            this.x = x;
            this.y = y;
            this.cnt = cnt;
        }
    }

    class Problem
    {
        readonly int[] moveX = new int[] { -1, 0, 1, 0 };
        readonly int[] moveY = new int[] { 0, -1, 0, 1 };
        readonly int INF = 1 << 20;
        readonly int w, h;

        int[,] map, counts;
        int sx, sy, minCnt;

        public Problem(int w, int h)
        {
            this.w = w;
            this.h = h;
            map = new int[h, w];
            counts = new int[h, w];
        }

        public int Solve()
        {
            MakeMap();
            minCnt = INF;

            Stack<State> stk = new Stack<State>();
            stk.Push(new State(sx, sy, 0));

            while (stk.Count > 0)
            {
                State cur = stk.Pop();
                counts[cur.y, cur.x] = cur.cnt;

                for (int i = 0; i < 4; i++)
                {
                    int nextX = cur.x + moveX[i];
                    int nextY = cur.y + moveY[i];

                    if (IsValid(nextX, nextY))
                    {
                        if (counts[nextY, nextX] <= cur.cnt) continue;

                        int tempCnt = cur.cnt + (map[cur.y, cur.x] == 1 ? 0 : map[nextY, nextX]);

                        if (tempCnt < minCnt) stk.Push(new State(nextX, nextY, tempCnt));
                    }
                    else minCnt = Math.Min(minCnt, cur.cnt);
                }
            }
            return minCnt;
        }

        private bool IsValid(int x, int y)
        {
            if (x < 0 || x >= w) return false;
            if (y < 0 || y >= h) return false;
            return true;
        }

        private void MakeMap()
        {
            for (int i = 0; i < h; i++)
            {
                string input = Console.ReadLine();

                for (int j = 0; j < w; j++)
                {
                    switch (input[j])
                    {
                        case '#':
                            map[i, j] = 1;
                            break;
                        case '&':
                            sx = j;
                            sy = i;
                            break;
                    }
                    counts[i, j] = INF;
                }
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');
                int w = int.Parse(input[0]);
                int h = int.Parse(input[1]);

                if (w == 0 && h == 0) break;

                Problem pb = new Problem(w, h);
                sb.AppendLine(pb.Solve().ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 10544
#include<stdlib.h>
#include<stdio.h>

long long cnt = 0;
int count = 0;
int a[1000000];
int g[100];

void insertSort(int a[], int n, int g)
{
    for (int i = g; i < n; i++)
    {
        int v = a[i];
        int j = i - g;

        while (j >= 0 && a[j] > v)
        {
            a[j + g] = a[j];
            j = j - g;
            cnt++;
        }
        a[j + g] = v;
    }
}

void shellSort(int a[], int n)
{
    int h = 1;
    g[count] = 1;

    while ((3 * h + 1) <= n)
    {
        h = 3 * h + 1;
        count++;
        g[count] = h;
    }

    for (int i = count; i >= 0; i--)
    {
        insertSort(a, n, g[i]);
    }       
}

int main()
{
    int n;

    
    scanf("%d", &n);

    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    
    shellSort(a, n);

    printf("%d\n", count + 1);
    for (int i = count; i >= 0; i--)
    {
        printf("%d", g[i]);
        if (i > 0)
        {
            printf(" ");
        }
    }
    printf("\n");

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

    for (int i = 0; i < n; i++)
    {
        printf("%d\n", a[i]);
    }
    
    return 0;
}


Measured memory_bytes: 5640
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(void) {}
  Edge(int src, int dst) : src(src), dst(dst) {}
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void edges_to_graph(Graph &graph, const Edges &edges, const int vertices, const bool directed = true) {
  graph.clear(), graph.resize(vertices);
  for (const auto &e : edges) graph[e.src].emplace_back(e);
  if (!directed) for (const auto &e : edges) graph[e.dst].emplace_back(Edge(e.dst, e.src, e.weight));
}

void dfs(Graph &g, int v, int p, int prev_col, map<pair<int, int>, int> &cmap) {
  int col = 0;
  for (const auto &e : g[v]) {
    if (e.dst == p) continue;
    ++col;
    if (col == prev_col) ++col;
    cmap[{ v, e.dst }] = col;
    dfs(g, e.dst, v, col, cmap);
  }
}

void bfs(Graph &g, map<pair<int, int>, int> &cmap) {
  queue<tuple<int, int, int>> que;
  que.push(make_tuple(0, -1, 0));
  while (!que.empty()) {
    int v = get<0>(que.front()), p = get<1>(que.front()), pc = get<2>(que.front());
    que.pop();
    int col = 1;
    for (const auto &e : g[v]) {
      if (e.dst == p) continue;
      if (col == pc) ++col;
      cmap[{ v, e.dst }] = cmap[{ e.dst, v }] = col;
      que.push(make_tuple(e.dst, v, col));
      ++col;
    }
  }
}

Graph graph;
int main(void) {
  int n;
  cin >> n;
  Edges edges(n - 1);
  rep (i, n - 1) {
    int a, b;
    cin >> a >> b;
    edges[i] = {--a, --b, 0};
  }
  edges_to_graph(graph, edges, n, false);
  int maxi = 0;
  rep (i, n) maxi = max(maxi, (int)graph[i].size());
  // cv.assign(n, vector<int>(n));
  map<pair<int, int>, int> cmap;
  dfs(graph, 0, -1, 0, cmap);
  // bfs(graph, cmap);
  cout << maxi << "\n";
  rep (i, n - 1) cout << cmap[{ edges[i].src, edges[i].dst }] << "\n";
  return 0;
}

Measured memory_bytes: 15232
#include<iostream>
#include<vector>
#include<cstring>
#include<list>
#include<algorithm>
#define endl "\n"
#define eb emplace_back
#define FOR(i, a, b) for(long long i = a; i < b; ++i)
#define FORR(n) for(long long i = n - 1; i >= 0; --i)
#define FORE(n) for(const auto &i : n)
typedef long long ll;
using namespace std;

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    ll ans = 0;
    FOR(i, 1, n + 1)
    {
        ll j = n / i;
        ans += (j * (j + 1) * i / 2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3520
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
int main()
{
	int n=read(),S=0;
	for(int i=1;;i++)
	{
		S+=i;
		if(S>=n)return pr2(i),0;
	}return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 300010

ll power(ll k, ll n, int M){
  ll res = 1;
  while(n > 0) {
    if (n & 1) res = res * k % M;
    k = k * k % M;
    n /= 2;
  }
  return res;
}

int counter[61];

int main() {
  int N;
  ll A[SIZE];

  scanf("%d", &N);

  for (int i=0; i<N; i++) {
    scanf("%lld", A+i);

    for (int j=0; j<60; j++) {
      counter[j] += !!(A[i] & (1LL << j));
    }
  }

  ll ans = 0;

  for (int i=0; i<N; i++) {
    for (int j=0; j<60; j++) {
      if (A[i] & (1LL << j)) {
        ans += (N - counter[j]) * ((1LL << j) % mod);
      } else {
        ans += counter[j] * ((1LL << j) % mod);
      }
      ans %= mod;
    }
  }

  ans = ans * power(2, mod-2, mod) % mod;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
vector<pair<ll, ll>> vt;
ll check[100010];
int main()
{
	ll n;
	scanf("%lld", &n);
	ll cnt = 0, cnt1 = 0;
	for (int i = 1; i <= n; i++) {
		ll q, w;
		scanf("%lld %lld", &q, &w);
		vt.push_back({ q,i });
		vt.push_back({ w,i });
		cnt += q;
		cnt1 += w;
	}
	sort(vt.begin(), vt.end());
	ll dap = min(cnt, cnt1);
	ll ch = 0;
	int update = 0;
	for (int i = 0; i < n; i++) {
		ch += vt[i].first;
		if (check[vt[i].second])update = 1;
		else check[vt[i].second] = 1;
	}
	if (!update) {
		if (vt[n - 1].second == vt[n].second) {
			ll xx = -vt[n - 1].first + vt[n + 1].first;
			ll yy = vt[n].first - vt[n - 2].first;
			ch += min(xx, yy);
		}
		else {
			ch += (vt[n].first - vt[n - 1].first);
		}
	}
	dap = min(dap, ch);
	printf("%lld\n", dap);
}

Measured memory_bytes: 6384
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


N = z()
A = zz()
lis = list(range(-1, 3200, 400))
ok = 0
set_ = []
for i in range(N):
    if (A[i] >= 3200):
        ok += 1
    else:
        idx = bisect.bisect_left(lis, A[i])
        set_.append(idx)
set_ = set(set_)
min_ = max(len(set_), 1)
max_ = len(set_) + ok

print(min_, max_)


Measured memory_bytes: 42120
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int k;
  string s;
  cin >> k >> s;

  if(s.size() <= k){
    cout << s << endl;
  }
  else{
    for(int i = 0; i < k; ++i){
      cout << s[i];
    }
    cout << "..." << endl;
  }
  return 0;
}

Measured memory_bytes: 3652
//A 居合を終え、青い絵を覆う
#include<bits/stdc++.h>
using namespace std;

int main()
{
  char s;
  cin>>s;
  if(s=='a'||s=='i'||s=='u'||s=='e'||s=='o')
  {
    cout<<"vowel"<<endl;
  }
  else
  {
    cout<<"consonant"<<endl;
  }
}


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

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

  double sum = 0.0;
  for (int i = 0; i < N; i++) {
    double A = 0.0;
    cin >> A;
    sum += 1.0 / A;
  }

  double ans = 1.0 / sum;
  // 以下の出力方法もある
  // cout << setprecision(16) << ans << endl;
  printf("%.16f", ans);
  return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;

void main()
{
	auto tokens = split(chomp(readln()));
	int a = to!int(tokens[0]);
	int b = to!int(tokens[1]);

	if ((a * b) % 2 == 0)
		writeln("No");
	else
		writeln("Yes");

	stdout.flush();
}

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

int main() {
  int N;
  cin >> N;
  vector<double> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  for(int i=0;i<N-1;i++){
    vec.at(i+1) = (vec.at(i)+vec.at(i+1))/2;
  }
  cout << vec.at(N-1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
using namespace std;

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



int main() {
	int k, a, b;
	cin >> k >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}

	cout << "NG" << endl;

}

Measured memory_bytes: 3064
<?php
class MyTest {

    private function main() {
        fscanf(STDIN, "%d %d", $n, $k);
        $ret = 0;
        for($i = $n; $i > 0; $i--){
            if ($i >= $k) {
                $ret += 1/$n;
            } else {
                $tmp = 1/$n;
                $j = $i;
                while($j < $k) {
                    $j *= 2;
                    $tmp*=0.5;
                }
                $ret += $tmp;
            }
        } 
        echo $ret."\n";
    }

    public function run() {
        self::main();
    }
    
}

MyTest::run();

Measured memory_bytes: 4728
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

bool dfs(int in, int N) {
	if (in < N) return dfs(in + 4, N) | dfs(in + 7, N);
	else if (in == N) return true;
	else return false;
}

int main() {

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

	int N;
	cin >> N;

	if (dfs(0, N)) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

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

int main () {
  int a1,a2,a3;
  cin >> a1 >> a2 >> a3;

  cout << min(abs(a1-a2) + abs(a2-a3), min(abs(a1-a3) + abs(a3-a2), abs(a1-a2) + abs(a1-a3))) << endl;
  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<set>
#include<map>
#include<stack>
#define i64 long long
#define vi32 vector<int>
#define vi64 vector<long long>
#define  ii pair<int,int>
const long long mod = 1000000007LL, inf = 1e9, linf = 1e18;
using namespace std;
#define pb push_back
#define mp make_pair
#define N 100005	
using namespace std;
int n, m;
int p[12];
int f[12][12];
int k[12];
int l[12];
int ans;
void check()
{
	for (int i = 1; i <= m; i++)
	{
		int len = k[i];
		int d = 0;
		for (int j = 1; j <= k[i]; j++)
		{
			if (l[f[i][j]])d++;
		}
		if (d % 2 != p[i])return;
	}
	ans++;

}
int main()
{

	ans = 0;
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
	{
		cin >> k[i];
		for (int j = 1; j <= k[i]; j++)cin >> f[i][j];
	}
	for (int i = 1; i <= m; i++)cin >> p[i];
	i64 res = (1 << n) - 1;
	for (i64 i = 0; i <= res; i++)
	{
		for (int j = 0; j < n; j++)
		{
			l[j+1] = 0;
			if (i & (1 << j))
			{
				l[j+1] = 1;
			}

		}
		check();
	}
	cout << ans;
}



Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
  public static void main(String args[]) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int A[] = new int[2*N];
    int x[] = new int[N];
    for(int a = 0; a < N; a++){
      A[a] = scanner.nextInt();
    }
    for(int a = N; a < 2*N; a++){
      A[a] = A[a-N];
    }
    int temp = 0;
    for(int i = 0; i < N; i++){
      if(i%2 == 0){
        temp += A[i];
      }else{
        temp -= A[i];
      }
    }
    x[0] = temp;
    for(int i = 1; i < N; i++){
      x[i] = 2*A[i-1]-x[i-1];
    }    
    for(int i = 0; i < N; i++){
      System.out.print(x[i]+" ");
    }    
    
  }
}

Measured memory_bytes: 65584
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x[8]={-1,0,1,-1,1,-1,0,1};
  int y[8]={1,1,1,0,0,-1,-1,-1};
  int h,w;cin>>h>>w;
  string s[h+2];for(int i=0;i<w+2;i++){
    s[0][i]='a';s[h+1][i]='a';
  }
  for(int i=1;i<=h;i++){
    cin>>s[i];
    s[i]="a"+s[i];s[i]=s[i]+"a";
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(s[i][j]=='.'){
        int cnt=0;
        for(int k=0;k<8;k++){
          if(s[i+x[k]][j+y[k]]=='#')cnt++;
        }
        s[i][j]=cnt+'a'-49;
      }
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<w;j++)cout<<s[i][j];
    cout<<s[i][w]<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n,i,j,k,u,v,c,mincost;

  scanf("%d",&n);

  int color[n],M[n][n],d[n],p[n];

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=-1;
    }
  }

  for(i=0;i<n;i++){
    color[i]=0;
    p[i]=-1;
    d[i]=1000001;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      M[u][v]=c;
    }
  }

  d[0]=0;

  while(1){
    
    mincost=1000001;
    u=-1;
    
    for(i=0;i<n;i++){
      if(color[i]!=2 && d[i]<mincost){
	u=i;
	mincost=d[i];
      }
    }

    if(mincost==1000001) break;

    color[u]=2;

    for(i=0;i<n;i++){
      if(M[u][i]!=-1 && color[i]!=2){
	if ((M[u][i]+d[u])<d[i]){
	  p[i]=u;
	  d[i]=M[u][i]+d[u];
	  color[i]=1;
	}
      }
    }
  }
  
  for(i=0;i<n;i++)printf("%d %d\n",i,d[i]);

  return 0;

}



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

signed main () {
	int n, k;
	int r, p, s;
	string t;
	cin >> n >> k;
	cin >> r >> s >> p;
	cin >> t;
	vector < bool > won(n, false);
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (i < k || t[i - k] != t[i] || !won[i - k]) {
			if (t[i] == 'r')
				ans += p;
			else if (t[i] == 'p')
				ans += s;
			else
				ans += r;
			won[i] = true;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){
  int n;cin>>n;
  int a[n];
  vector<int> v;
  int ma;
  bool count = false;
  REP(i,n){
    cin>>a[i];
    v.pb(a[i]);
  }


  VSORT(v);

  ma = v[n-1];
  if(v[n-2] == ma){
    count = true;
  }

  REP(i,n){
    if(a[i]==ma&&count==false){
      cout<<v[n-2]<<endl;
    }else{
      cout<<ma<<endl;
    }
  }

 

  return 0;
}

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long x,k,d,c,e,f,g;
    cin>>x>>k>>d;
    x=abs(x);

    c=x/d;
    if(c>=k)
    {
        cout<<x-(k*d);
    }
    else
    {
        e=x-(c*d);
        f=e-d;
       g=k-c;
       if(g%2!=0)
       {
           cout<<abs(f);
       }
       else
       {
           cout<<e;
       }

    }


}


Measured memory_bytes: 3512