akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<bitset>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll INF = 1 << 30;


int rel[12][12];
vector<vector<int>> mp;
vector<vector<int>> vst;
int mx, my;

int adj(int x, int m) {

	if (x < 0) return 0;
	if (x >= m) return m - 1;

	return x;
}

void dfs(int x, int y) {
	int d[] = { -1,0,1 };
	int nx, ny;

	if (vst[y][x] == 1) return;

	vst[y][x] = 1;

	rep(j, 3) {
		rep(i, 3) {
			nx = adj(x + d[i], mx);
			ny = adj(y + d[j], my);
			if (mp[ny][nx] == 1 && vst[ny][nx] == 0) {
				dfs(nx, ny);
			}
		}
	}
}

int islCnt() {

	int f = 0;

	rep(i, my) {
		rep(j, mx) {

			if (mp[i][j] == 1 && vst[i][j] == 0) {
				f++;
				dfs(j, i);
			}

		}
	}

	return f;
}


int main() {


	int n, m, x, y, ans;
	ans = 0;

	while (true) {
		cin >> n >> m;

		if (n == 0 && m == 0) break;

		mp = vector<vector<int>>(m);
		vst = vector<vector<int>>(m);

		rep(i, m) {
			rep(j, n) {
				cin >> x;
				mp[i].push_back(x);
				vst[i].push_back(0);

			}
		}

		mx = mp[0].size();
		my = mp.size();

		ans = islCnt();

		cout << ans << endl;
	}

}



Measured memory_bytes: 3340
def solve(H, W, a):
    grid = []
    for i in range(H):
        grid.append([])
        for j in range(W):
            grid[i].append(0)

    r = 0
    c = 0
    for i in range(len(a)):
        r, c = paint(i+1, a[i], grid, r, c)

    print_grid(grid)


def paint(color, n, grid, r, c):
    for i in range(n):
        dc = 1 if r % 2 == 0 else -1
        dr = 1 if (dc == -1 and c == 0) or (dc == 1 and c == len(grid[0])-1) else 0
        if dr == 1: dc = 0
        grid[r][c] = color
        r += dr
        c += dc
    return r, c


def print_grid(grid):
    for i in range(len(grid)):
        print(' '.join(map(str, grid[i])))


def main():
    H, W = list(map(int, input().split(' ')))
    N = int(input())
    a = list(map(int, input().split(' ')))
    solve(H, W, a)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3568
N,Y = map(int,input().split())
f=False
for i in range(N+1):
    for j in range(N+1):
        k = N-i-j
        if k < 0:
            continue
        if 10000*i + 5000*j + 1000*k == Y:
            print(i,j,k)
            f=True
            break
    if f :
        break
if f==False: 
    print(-1,-1,-1)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define int long long
#define mod 1000000007
signed main(){
    int r,g,b,n;
    cin>>r>>g>>b>>n;
    int count=0;
    for(int i=0;i<=n/r;i++){
        for(int j=0;j<=n/g;j++){
            if((n-r*i-j*g)%b==0&&n-r*i-j*g>=0){
                count++;
            }
        }
    }
    cout<<count<<endl;
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main ()
{
    int n;
    cin >> n;
    vector <pair<int,int> > V;
    for (int i = 0; i <= n; i++) {
        V.push_back(pair<int,int>(0,i));
    }
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        V[a].first += b;
    }
    sort(V.begin(), V.end());
    int i = 1;
    while (V[i].first != V[n].first) i++;
    cout << V[i].second << " " << V[i].first << endl;

    return 0;
}

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

int n,m,q,res=0;
vi a,b,c,d,e;

void f(int I){
	if(I==n){
		int tmp=0;
		for(int i=0;i<q;i++) if(e[b[i]]-e[a[i]]==c[i]) tmp+=d[i];
		res=max(res,tmp);
		return;
	}
	for(int i=e[I];i<=m;i++){
		e.push_back(i);
		f(I+1);
		e.pop_back();
	}
}

int main(){
	cin>>n>>m>>q;
	a=b=c=d=vi(q);
	for(int i=0;i<q;i++) cin>>a[i]>>b[i]>>c[i]>>d[i];
	e.push_back(1);
	f(0);
	cout<<res<<endl;
}

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


int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> h(n,0);
    rep(i,n)cin >> h[i];
    sort(h.begin(),h.end());
    ll mini = LONG_LONG_MAX;
    rep(i,n-k+1){
        mini = min(mini,h[i+k-1] - h[i]);
    }
    cout << mini << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 1024
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s=scan.next();
        int n=s.length();
        int[]a=new int[26];
        for(char c:s.toCharArray())a[c-'a']++;
        for(int i=0;i<26;++i)
            if(a[i]>(n+2)/3){
                System.out.println("NO");
                return;
            }
        System.out.println("YES");
    }
}


Measured memory_bytes: 26704
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = Integer.parseInt(sc.next()),
        b = Integer.parseInt(sc.next()),
        c = Integer.parseInt(sc.next());
    System.out.println(
      Math.max(0, c - Math.max(0, a - b))
    );
  }
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>

char s1[100];
char s2[100];

int main()
{
	while(1)
	{
		if(NULL == fgets(s1,100,stdin))
		{
			break;
		}
		s1[strlen(s1) - 1] = '\0';
		int l = strlen(s1);
		for(int i = 0; i < 26; i++)
		{
			strcpy(s2,s1);
			for(int j = 0; j < l; j++)
			{
				if('a' <= s2[j] && s2[j] <= 'z')
				{
					int w = s2[j] + i;
					if(w > 'z')
					{
						w -= 26;
					}
					s2[j] = w;
				}
			}
			if(NULL != strstr(s2,"the") || NULL != strstr(s2,"this") || NULL != strstr(s2,"that"))
			{
				printf("%s\n",s2);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 940
import java.util.Scanner;

//解説を参考にした
class Main {
    //三角形が存在するかのチェック
    static boolean checkTriangle(int[] a, int i, int j, int k) {
        if (a[i] + a[j] > a[k] && a[j] + a[k] > a[i] && a[k] + a[i] > a[j])
            return true;
        return false;
    }

    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int N = std.nextInt();
        /*
        Set<Integer> hashSet = new HashSet<Integer>();

        for (int i = 0; i < N; i++)
            hashSet.add(std.nextInt());

        Integer[] a = hashSet.toArray(new Integer[hashSet.size()]);
        */
        int[] a = new int[N];
        for (int i = 0; i < N; i++)
            a[i] = std.nextInt();

        int count = 0;
        //組み合わせ
        for(int i = 0; i < a.length-2; i++) {
            for(int j = i + 1; j < a.length-1; j++) {
                for(int k = j + 1; k < a.length; k++) {
                    if(checkTriangle(a, i, j, k) && a[i] != a[j] && a[j] != a[k] && a[k] != a[i]) count++;
                }
            }
        }

        System.out.println(count);

    }

}


Measured memory_bytes: 36536
N, M = map(int, input().split())
p_s = [list(map(int, input().split())) for _ in range(N)]
p_f = [list(map(int, input().split())) for _ in range(M)]
length = []

for s in p_s:
    for f in p_f:
        length.append(abs(s[0]-f[0]) + abs(s[1]-f[1]))
    print(length.index(min(length))+1)
    length = []

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN (-2147483647 - 1)
#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;

class Graph {
private:
	struct node {
		bool done;
		vi to, cost;
		int id, from;
		ll d;
		bool operator<(const node & another) const {
			return !(d != another.d ? d < another.d : id < another.id);
		}
	};
	vector<node> nodes;
	int n;
public:
	vll result;
	Graph(vector<vector<P>> data) {
		n = data.size();
		result.resize(n);
		nodes.resize(n);
		Loop(i, n) {
			nodes[i] = { false,{},{}, i, -1, INFLL };
			Loop(j, data[i].size()) {
				nodes[i].to.push_back(data[i][j].first);
				nodes[i].cost.push_back(data[i][j].second);
			}
		}
	}
	void reset() {
		Loop(i, n) {
			nodes[i].done = false;
			nodes[i].from = -1;
			nodes[i].d = INFLL;
		}
	}
	//mode=>dijkstra, !mode=>prim
	void mainfunc1(int start, int mode) {
		priority_queue<node> pq;
		nodes[start].d = 0;
		pq.push(nodes[start]);
		while (pq.size()) {
			node a = pq.top(); pq.pop();
			if (nodes[a.id].done) continue;
			nodes[a.id].done = true;
			Loop(j, a.to.size()) {
				node* b = &nodes[a.to[j]];
				if ((*b).done) continue;
				ll cand = (mode ? a.d : 0) + a.cost[j];
				if (cand < (*b).d) {
					(*b).d = cand;
					(*b).from = a.id;
					pq.push(*b);
				}
			}
		}
		Loop(i, n) {
			result[i] = nodes[i].d;
		}
	}
};

int main() {
	int n, m, r; cin >> n >> m >> r;
	vector<vector<P>> data(n);
	Loop(i, m) {
		int s, t, d; cin >> s >> t >> d;
		data[s].push_back({ t,d });
	}
	Graph g(data);
	g.mainfunc1(r, 1);
	Loop(i, n) {
		if (g.result[i] == INFLL) cout << "INF" << endl;
		else cout << g.result[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 41444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,k,r,s,p;
    cin >> n >> k >> r >> s >> p;
    vector<char>t(n);
    for(ll i=0;i<n;i++){
        cin >> t[i];
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        if(t[i]=='r') ans+=p;
        if(t[i]=='s') ans+=r;
        if(t[i]=='p') ans+=s;
    }
    vector<ll>judge(n,-1);//0:r,1:s,2:p
    for(ll i=0;i<n-k;i++){
        if(t[i]=='r'&&t[i+k]=='r'&&judge[i]!=0){
            ans-=p;
            judge[i+k]=0;
        }
        if(t[i]=='s'&&t[i+k]=='s'&&judge[i]!=1){
            ans-=r;
            judge[i+k]=1;
        }
        if(t[i]=='p'&&t[i+k]=='p'&&judge[i]!=2){
            ans-=s;
            judge[i+k]=2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4028
import numpy as np

a,b,x = map(int, open(0).read().split())
if a*a*b/2 >= x:
  theta = np.rad2deg(np.arctan(a*b*b/2/x))
else:
  theta = np.rad2deg(np.arctan(2*(a*b-x/a)/a/a))
print(theta)

Measured memory_bytes: 16092
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int findIndex(vector<long> vec, long value)
{
    vector<long>::iterator iter = std::find(vec.begin(), vec.end(), value);
    size_t index = distance(vec.begin(), iter);
    if(index == vec.size())
    {
        return -1;
    }
    return index;
}

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

    vector<long> vec(n);
    for (long i = 0; i < n; i++)
    {
        long a;
        cin >> a;
        vec[i] = a;
    }

    sort(vec.begin(), vec.end(), greater<int>()); // 降順

    for (long i = 0; i < n-1; i++)
    {
        if (vec[i] == vec[i+1])
        {
            cout << "NO"<< endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
using namespace __gnu_pbds;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define uid uniform_int_distribution<lli>
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>
#define endl "\n"
#define ofk order_of_key
#define fbo find_by_order
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class my>
using indexed_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

template <class my>
inline my aabs (const my &a)   { return (a > 0)  ? a : -a;         }
inline lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
inline lli LSOne(lli k)        { return (k&(-k));                  }

inline int inv(lli o, int m = mod) {
  int b = m, u = 0, v = 1, t, a=o%m;
  while (a) {
    t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += m;
  return u;
}
inline int add(const int &a, const int &b, int m=mod) { return ( a + b ) % m;           }
inline int sub(const int &a, const int &b, int m=mod) { return ( a - b + m ) % m;       }
inline int mul(const int &a, const int &b, int m=mod) { return int ( 1LL * a * b % m ); }
inline int mpow(int a, int b, int m=mod) {
    int ans = 1;
    a=((a%m)+m)%m;
    while (b) {
        if (b & 1) ans = mul(ans, a, m);
        a = mul(a, a, m);
        b >>= 1;
    }
    return ans;
}

void tejas_919()
{
    lli n, k, m, q, u=0, v=0, temp=1, max1, max2, ans=0, a, b, val=0;
    cin>>n;
    n=n*n;
    n=3*n;
    cout<<n<<endl;

}

int main()
{
    fastio cout<<endl;
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    while(t--)
        tejas_919();
}

Measured memory_bytes: 256
<?php
  const DIRS = "RDLU";
  $h[] = "000000";
  $v[] = "0000000";
  for($i=0;$i<4;$i++) {
      $h[] = "0".trim(fgets(STDIN))."0";
      $v[] = "0".trim(fgets(STDIN))."0";
  }
  $h[] = "0".trim(fgets(STDIN))."0";
  $v[] = $v[0];
  $h[] = $h[0];

  $p = array(2,1,0);
  $path = 'R';
  $stepx =  array(1,0,-1,0);
  $stepy = array(0,1,0,-1);

  while(!($p[0]==1 && $p[1]==1)) {
    for($i=0;$i<4;$i++) {
      $d = ($p[2]+$i)%4;
      $d2 = ($d+3)%4;
      if(($d==0 && $v[$p[1]-1][$p[0]]) || ($d==1 && $h[$p[1]][$p[0]])
        || ($d==2 && $v[$p[1]][$p[0]]) || ($d==3 && $h[$p[1]][$p[0]-1])) {
        $p[0] += $stepx[$d2];
        $p[1] += $stepy[$d2];
        $p[2] = $d2;
        break;
      }
    }
    $path .= DIRS[$p[2]];
  }

  echo $path.PHP_EOL;

Measured memory_bytes: 15428
#include "bits/stdc++.h"
#define ll long long
#define inf 1000000007 //10^9+7
#define sort(vec) sort(vec.begin(),vec.end());
#define rever(vec) reverse(vec.begin(),vec.end());
#define unsort(vec) sort(vec); rever(vec);
#define gcd __gcd
using namespace std;

int main() {
  ll n,m,x,y;
  cin>>n>>m>>x>>y;
  vector<ll>vec(n);
  vector<ll>vek(m);
  ll can=false;
  for(ll i=0;i<n;i++) cin>>vec.at(i);
  for(ll i=0;i<m;i++) cin>>vek.at(i);
  unsort(vec);
  sort(vek);
  ll a=vec.at(0);
  ll b=vek.at(0);
  for(ll i=x+1;i<=y;i++) {
    if(a<i&&i<=b) {
      can=true;
      break;
    }
  }
  if(can) {
    cout<<"No War"<<endl;
  }
  else {
    cout<<"War"<<endl;
  }
}

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

int main() {
    int a[6];
    int i, num;

    for (i = 0; i < 5; i++) {
        cin >> a[i];
    }
    for (i = 0; i < 5; i++) {
        if (a[i] == 0) {
            num = i + 1;
        }
    }
    cout << num << endl;
}


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

int main(){
    int A, B; cin >> A >> B;
    int ans = 0;
    if(A > B){
        ans += A;
        A--;
    }else{
        ans += B;
        B--;
    }
    if(A > B){
        ans += A;
        A--;
    }else{
        ans += B;
        B--;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
# D - Prediction and Restriction

n, k = map(int, input().split())
r, s, p = map(int, input().split())
T = list(str(input()))
A = []
ans = 0

for t in T:
    if t=='r':
        A.append(p)
    elif t=='s':
        A.append(r)
    else:
        A.append(s)

for i in range(len(A)):
    if i<k:
        ans += A[i]
        continue

    if T[i]==T[i-k]:
        T[i] = 'o'
    else:
        ans += A[i]

print(ans)



Measured memory_bytes: 4792
# -*- coding: utf-8 -*-

H,W = map(int, input().split())

# 1マス分の必要な情報を保持する
class Cell:
    def __init__(self, h, w, val):
        self.h = h
        self.w = w
        self.val = val

# 全マスを一列にする
Cells = []
for i in range(H):
    tmp = list(map(int, input().split()))
    for j in range(W):
        Cells.append(Cell(i+1, j+1, tmp[j]))

ans = []
for i in range(len(Cells)-1):
    # 奇数マスは次のマスに順次値を移していく
    if Cells[i].val % 2 == 1:
        if Cells[i].w != W:
            Cells[i].val -= 1
            Cells[i+1].val += 1
            ans.append(str(Cells[i].h) + ' ' + str(Cells[i].w) + ' ' + str(Cells[i+1].h) + ' ' + str(Cells[i+1].w))
        # 行の最後だけは次の行に移す
        else:
            Cells[i].val -= 1
            Cells[i+W].val += 1
            ans.append(str(Cells[i].h) + ' ' + str(Cells[i].w) + ' ' + str(Cells[i+W].h) + ' ' + str(Cells[i+W].w))

# 操作回数から出力
print(len(ans))
for s in ans:
    print(s)

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

int main(){
  int n,m; cin >> n >> m;
  vector<int> k(n),c(m,0);
  for(int i=0; i<n; i++){
    cin >> k[i];
    vector<int> a(k[i]);
    for(int j=0; j<k[i]; j++){
      cin >> a[j];
      c[a[j]-1]++;
    }
  }  
  int count=0;
  for(int i=0; i<m; i++){
    if(c[i]==n) count++;
  }  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var a = new int[n];
            for(var i = 0; i < n; i++){
                a[i] = int.Parse(Console.ReadLine());
            }

            var m = a.Max();
            var s = a.Sum() - m + (m / 2);
            Console.WriteLine(s);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b){
	if(a%10==0){
		return a>b;
	}
	else if(b%10==0){
		return b>a;
	}
	else 
		return (a%10)>(b%10);
}
int main(){
	int a[5];
	for(int i=0;i<5;i++)
		cin>>a[i];
	sort(a,a+5,cmp);
	int sum = 0;
	for(int i=0;i<4;i++)
		sum+=(a[i]+9)/10*10;
	sum+=a[4];
	cout<<sum<<endl;
} 

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)
#define MAX 100
#define INF (1<<21)
int n, L[MAX][MAX],S[MAX];

int bfs( int s, int t ){
    queue<int> q; q.push(s);
    int u, v, d[MAX];
    rep(i, n) d[i] = INF;
    d[s] = 1;
    while( !q.empty() ){
	u = q.front(); q.pop();
	rep(i, S[u]){
	    v = L[u][i];
	    if ( d[v] == INF ){
		d[v] = d[u] + 1;
		q.push(v);
	    }
	}
    }
    return d[t];
}

main(){
    int s, t, tl, q, c;
    cin >> n;
    rep(i, n){
	cin >> s; s--; cin >> S[s];
	rep(j, S[s]){
	    cin >> L[s][j]; L[s][j]--;
	}
    }
    cin >> q;
    rep(i, q){
	cin >> s >> t >> tl; s--; t--;
	c = bfs(s, t);
	if ( c <= tl ) cout << c << endl;
	else cout << "NA" << endl;
    }
    
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int x=sc.nextInt();
        int t=sc.nextInt();
        int rem=n%x;
        if (rem==0){
            int div=n/x;
            System.out.println(div*t);
        }
        else{
            int div=(n/x)+1;
            System.out.println(div*t);
        }
    }
}


Measured memory_bytes: 35672
#include<stdio.h>
#include<string.h>

char *grading(int mid, int final, int makeup)
{
    int total = mid + final;
    if (-1 == mid || -1 == final)
    {
        return("F");
    }
    else if (total >= 80)
    {
        return("A");
    }
    else if (total >= 65)
    {
        return("B");
    }
    else if (total >= 50)
    {
        return("C");
    }
    else if (total >= 30)
    {
        if (makeup >= 50)
        {
            return("C");
        }
        else
        {
            return("D");
        }
    }
    else
    {
        return("F");
    }

    return(0);
}

int main(void)
{
    char buffer[25];
    char grades[50][2];
    int numStudents;
    int mid, final, makeup;
    int i;

    for (numStudents = 0;numStudents<50; numStudents++)
    {
        fgets(buffer, 25, stdin);
        sscanf(buffer, "%d %d %d", &mid, &final, &makeup);
        if ((mid == -1) &&
            (final == -1) &&
            (makeup == -1))
        {
            break;
        }
        char *grade = grading(mid, final, makeup);
        strcpy(grades[numStudents], grade);
    }

    for (i = 0; i < numStudents; i++)
    {
        printf("%s\n", grades[i]);
    }

    return(0);
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)


int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    sort(ALL(A));
    int ok = A[N-1], ng = 0;
    while (abs(ok-ng) > 1) {
        int mid = (ok+ng)/2;
        int cnt = 0;
        int tmp = N-1;
        while (cnt <= K && tmp >= 0 && A[tmp] > mid) {
            cnt += A[tmp]/mid-1;
            if(A[tmp]%mid) cnt++;
            tmp--;
        }
        if (cnt <= K) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}


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

int n,arr[1000000],arr2[1000000];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		scanf("%d",&arr[i]);
	}
	arr2[0]=arr[0];
	for(int i=0;i<n;i++){
		if(i==n-1){
			arr2[i+1]=arr[i];
		}else{
			if(arr2[i]>arr[i]){
				arr2[i]=arr[i];
			}
			arr2[i+1]=arr[i];	
		}
	}

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

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define f first
#define s second
#define pb push_back

signed main()
{
  int n,m;
  cin>>n>>m;
  int s=0;
  for(int i=0;i<m;i++)
  {
      int j;
      cin>>j;
      s+=j;
  }
  if(s<=n)
  cout<<n-s<<endl;
  else
  cout<<-1<<endl;
}


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

int main(){
	int a,b,c,m;
	cin >> a >> b >> c;
	if(a>b){
		m=a;
		a=b;
		b=m;
	}
	if(b>c){
		m=b;
		b=c;
		c=m;
	}
	if(a>b){
		m=a;
		a=b;
		b=m;
	}
	cout << a << " "<< b << " " << c << endl;
	
	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <regex>
#include <set>
#include <cmath>
#include <sstream>
#include <numeric>
#include <set>
#include <unordered_map>

int main()
{
    long long a, b;
    std::cin >> a >> b;

    std::cout << a * b;

    return EXIT_SUCCESS;
}


Measured memory_bytes: 3192
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)-1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  cin >> n;
  rep(i,n){
    cin >> a[i];
  }
  qsort(a,n,sizeof(int),downint);
  for(i=0;i<n-1;i++){
    result += (ll)a[(int)ceil(i/2.0)];
  }
  cout << result << endl;
    
  return 0;
}

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


long long hp(long long x){
  if (x == 1) return 1;
  return hp(x/2) * 2 + 1;
}

int main() {
  long long H;
  cin >> H ;
  //vector<int> p(N);
  
  cout<<hp(H)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c; 
int gcd(int a,int b){return b==0?a:gcd(b,a%b);} 
int main()
{
	cin>>a>>b>>c;
	int d=gcd(a,b);
	if(c%d) cout<<"NO";
	else cout<<"YES"; 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,a,b,c,take[8];

int rec(int i,int j,int k,int l){
  if(i>=n){
	if(!(j&&k&&l))return 1.0e+9;
	return abs(a-j)+abs(b-k)+abs(c-l);
  }
  
  int ar[4]={rec(i+1,j+take[i],k,l),rec(i+1,j,k+take[i],l),rec(i+1,j,k,l+take[i]),rec(i+1,j,k,l)};
  if(j)ar[0]+=10;
  if(k)ar[1]+=10;
  if(l)ar[2]+=10;
  sort(ar,ar+4);
  
  return ar[0];
}

int main(){
  cin>>n>>a>>b>>c;
  for(int i=0;i<n;++i)
	cin>>take[i];
  
  cout<<rec(0,0,0,0)<<endl;
  return 0;
}


Measured memory_bytes: 256
s = list(input())
import sys
def bitlist(n, a, b):
  res = []
  for i in range(2**n):
    pattern = []
    for j in range(n):
      if (i >> j) & 1:
        pattern.insert(0, a)
      else:
        pattern.insert(0, b)
    res.append(pattern)
  return res

n = len(s)
lst = bitlist(n-1, "+", "-")
for i in range(2**(n-1)):
  calc = s[0]
  for j in range(n-1):
    calc += lst[i][j] + s[j+1]
  if eval(calc) == 7:
    calc += "=7"
    print(calc)
    sys.exit()

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("a < b\n");
	}
	if(a>b){
		printf("a > b\n");
	}
	if(a==b){
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;

const ll M = (1000000000 + 7);

int max_count(string& s, int b, int d)
{
  int cnt = 0;
  int max_cnt = 0;
  int i;
  for (i = b; i <= d; i++) {
    if (s[i - 1] == '.')
      cnt++;
    else
      cnt = 0;
    max_cnt = max(max_cnt, cnt);
  }
  return max_cnt;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("file.1", "r", stdin);

  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  string ss, s;
  cin >> ss;
  s = " " + ss;

  int cnt = 0;
  int blk = 0;
  int max_cnt = 0;
  int max_blk = 0;
  int i;
  if (c < d) {
    for (i = a; i <= d; i++) {
      if (s[i] == '#')
        blk++;
      else
        blk = 0;
      max_blk = max(max_blk, blk);
    }
    cout << ((max_blk < 2) ? "Yes" : "No") << endl;
  } else {
    for (i = a; i <= c; i++) {
      if (s[i] == '#')
        blk++;
      else
        blk = 0;
      max_blk = max(max_blk, blk);
    }
    for (i = b - 1; i <= d + 1; i++) {
      if (s[i] == '.')
        cnt++;
      else
        cnt = 0;
      max_cnt = max(max_cnt, cnt);
    }
    cout << ((max_blk < 2 && 3 <= max_cnt) ? "Yes" : "No") << endl;
  }
  return 0;
}

Measured memory_bytes: 720
n,k=map(int,input().split())
ans=0
xs=[0]*k
mod=10**9+7
for i in range(k-1,-1,-1):
    a=i+1
    xs[i]=pow(k//a,n,mod)
    for j in range(2,k+1):
        if a*j>k:
            break
        xs[i]-=xs[a*j-1]
        xs[i]=(xs[i]+mod)%mod

for i in range(k):
    a=i+1
    ans+=a*xs[i]
    ans%=mod
print(ans)

Measured memory_bytes: 74792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int N,a,b,c;
int A[100010],B[100010],C[100010];
int main(){
    cin >> N;
    cin >> a >> b >> c;
    A[0] = a; B[0] = b; C[0] = c;
    for(int i = 1; i < N; i++){
        cin >> a >> b >> c;
        A[i] = max(B[i-1],C[i-1]) + a;
        B[i] = max(A[i-1],C[i-1]) + b;
        C[i] = max(A[i-1],B[i-1]) + c;
    }
    cout << max(A[N-1], max(B[N-1],C[N-1])) << endl;
}



Measured memory_bytes: 1408
#include<iostream>
#define REP(i, n) for(int i=0;i<(n);++i)
#define REPA(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define INF ((int)1e9)
#define LL long long
int N;
using namespace std;
int func(int a){
    LL lp = 1;
    LL hp = 100000;
    while(lp<hp){
        LL mid = (lp+hp)/2;
        if((2*a+mid-1)*mid==2*N){
            return mid;
        }
        if((2*a+mid-1)*mid<2*N){
            lp=mid+1;
        }else{
            hp=mid;
        }
    }
    return 0;
}
int main(){
    while(cin>>N&&N){
       int ans = 0;
       for(int i=1;i*i-i<=N;++i){
           ans = max(ans, func(i));
           if(2*N%i)continue;
           if((2*N/i-i+1)&1)continue;
           ans = max(ans, i);
       }
       cout << (2*N/ans-ans+1)/2 << " " << ans << endl;
    }
    return 0;
}

//(2a+b-1)b/2=N
//2a+b-1=2N/b
//2a=2N/b-b+1
//a=(2N/b-b+1)/2
//2ab+b^2-b=2N
//b^2+2ab-b-2N=0



Measured memory_bytes: 3100
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string s; readV(s);
  auto n = s.length;

  foreach_reverse (i; 2..n) {
    if (i%2 == 1) continue;
    if (s[0..i/2] == s[i/2..i]) {
      writeln(i);
      return;
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;
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;}
const long long INF = 1LL << 60;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	
	int a,b;
	cin>>a>>b;
	if(a*b%2==0)cout<<"Even"<<endl;
	else cout<<"Odd"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, L = map(int,input().split())
A = [0] * N
B = [0] * N
for i in range(N):
  A[i] = L + i

ans = 0
diff = 10 ** 10
for j in range(N):
  B[j] = sum(A) - A[j]
  diff = min(diff, abs(sum(A)-B[j]))

if sum(A) >= 0:
  print(sum(A)-diff)
else:
  print(sum(A)+diff)

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

int main(){
  int n;
  cin >> n;
  ll a[n];
  rep(i,0,n) cin >> a[i];
  ll mx = a[0];
  ll sum = 0;
  rep(i,1,n){
    if(mx<=a[i]) mx = a[i];
    else sum += (mx - a[i]);
  }
  cout << sum << endl;
  return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  deque<int> q;
  rep(i, n) {
    int a;
    cin >> a;
    q.push_back(a);
  }

  // m:= toridasu kaisuu
  ll ans = 0;
  for(int m = 1;m<=k;m++) {
    for(int l=0;l<=m;l++) {
      for(int r=0;r<=m-l;r++) {
        deque<int> q2;
        q2 = q;
        priority_queue<int, vi, greater<int>> pq;
        ll sum = 0;
        rep(i, l) {
          if(q2.empty())break;
          sum += q2.front();
          if (q2.front() < 0) pq.push(q2.front());
          q2.pop_front();
        }
        rep(i, r) {
          if(q2.empty())break;
          sum += q2.back();
          if (q2.back() < 0) pq.push(q2.back());
          q2.pop_back();
        }
        rep(i, k - m) {
          if(pq.empty())break;
          sum -= pq.top();
          pq.pop();
        }
        maxs(ans, sum);
      }
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;



int main()
{
    int a[100001]={0};
    int n,m,i,j;
    int tempa,tempb;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++) a[i]=100005;
    for(i=1;i<=m;i++)
    {
        scanf("%d%d",&tempa,&tempb);
        if(a[tempa]>tempb)
            {a[tempa]=tempb;

            }
    }
    for(i=1;i<=n;i++)
    {
        if(a[i]<100005)
            {
            for(j=i+1;j<a[i];j++)
            {
                if(a[j]<100005)
                {
                    if(a[j]<=a[i])
                        a[i]=100005;
                    else
                    { a[j]=a[i];
                        a[i]=100005;

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


Measured memory_bytes: 640
from collections import deque
n,d,a = map(int,input().split())
f = [list(map(int,input().split()))for i in range(n)]
queue = deque()
f.sort()
tot = 0
ans = 0
for i in range(n):
    x = f[i][0]
    h = f[i][1]
    while queue and queue[0][0] < x:
        now = queue.popleft()
        tot -= now[1]
    h -= tot
    if h > 0:
        num = (h+a-1)//a
        ans += num
        damage = num*a
        tot+=damage
        queue.append((x+2*d,damage))
print(ans)
        

Measured memory_bytes: 66368
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
  int N;cin>>N;
  vi X(N);
  int x=0;
  rep(i,N){
    cin>>X[i];
    x+=X[i];
  }
  int S1=0,S2=0;
  rep(i,N){
    S1 += abs(x/N-X[i])*abs(x/N-X[i]);
  }
  rep(i,N){
    S2+= abs((x+N-1)/N-X[i])* abs((x+N-1)/N-X[i]);
  }
  int ans=min(S1,S2);
  cout<<ans<<endl;
  
  
}


Measured memory_bytes: 384
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
p = [-1,-1,-1]
ans = 1
for i in range(N):
    a = A[i]
    ans *= p.count(a-1)
    ans %= mod
    for j in range(3):
        if p[j]==a-1:
            p[j] = a
            break
print(ans)

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

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main() {
	int H,W,K;
	int ans = 0;
	cin >> H >> W >> K;
	vector<vector<char> >masu(H,vector<char>(W));
	vector<vector<char> >masue(H,vector<char>(W));
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin >> masu.at(i).at(j);
		}
	}
	vector<int>column(H,0);
	vector<int>row(W,0);
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(masu.at(i).at(j)=='#'){
				column.at(i)++;
				row.at(j)++;
			}
		}
	}

	for(int bit =0;bit < (1 << H);bit++){
		for(int bita =0;bita < (1 << W);bita++){
			vector<int>S1 = IntegerToVector(bit, H);
			vector<int>S2 = IntegerToVector(bita, W);

			masue = masu;

		
			

			for(int i=0;i<S1.size();i++){
				for(int j=0;j<W;j++){
					int x = S1.at(i);
					masue.at(x).at(j) = '.';
				}
			}
			for(int i=0;i<S2.size();i++){
				for(int j=0;j<H;j++){
					int y = S2.at(i);
					masue.at(j).at(y) = '.';
				}
			}
			int count = 0;
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					if(masue.at(i).at(j)=='#'){
						count++;
					}
				}

			}
			if(count == K){
				ans++;


			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3616
#include<iostream>
//#include<algorithm>
#include<string>
#include<vector>
//#include <cstring>
//#include <cstdio>
int main() {
	int a, b;
	while (std::cin >> a >> b, a + b != 0) {
		std::vector<std::vector<char>> ch(a, std::vector<char>(b));
		std::vector<std::vector<char>> ch2(a, std::vector<char>(b,0));
		int x=0, y=0;
		for (int i = 0; i < a; ++i) {
			for (int j = 0; j < b; ++j) {
				std::cin >> ch[i][j];
			}
		}
		while (ch[x][y] != '.') {
			if (ch2[x][y] ==1) { std::cout << "LOOP" << std::endl; break; }
			ch2[x][y]++;
			if (ch[x][y] == '>')y++;
			else if (ch[x][y] == '<')y--;
			else if (ch[x][y] == '^')x--;
			else if (ch[x][y] == 'v')x++;
		}
		if (ch2[x][y] == 0)std::cout << y <<" "<<x<< std::endl;
	}
	return 0;
}

Measured memory_bytes: 3188
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
    #include "lib/dump.hpp"
#else
    #define dump(...) 42
    #define dump_1d(...) 42
    #define dump_2d(...) 42
    #define cerrendl 42
#endif
//}}}


struct UnionFind {
  vector<int> data;  // size defined only for root node
  int count;  // count of groups

  UnionFind(){}
  UnionFind(int size) : data(size, -1), count(size){}
  bool merge(int x, int y) {/*{{{*/
    x=root(x); y=root(y);
    if (x!=y) {
      if (data[y]<data[x]) swap(x, y);
      data[x]+=data[y]; data[y]=x;
      count--;
    }
    return x != y;
  }/*}}}*/
  int root(int x) { return (data[x]<0 ? x : data[x]=root(data[x])); }
  bool same(int x,int y){ return root(x)==root(y); }
  int size(int x) { return -data[root(x)]; }

  friend auto& operator<<(auto &os, UnionFind& uf){ //{{{
    map<int, vector<int>> group;
    rep(i, sz(uf.data)){ group[uf.root(i)].pb(i); }
    os << endl; each(g, group){ os << g << endl; }
    return os;
  } //}}}
};

signed main() {
    int n,m,k;cin>>n>>m>>k;
    UnionFind uf(n);

    vector<int> add(n);
    rep(i, m){
        int a,b;cin>>a>>b;
        a--;b--;
        uf.merge(a, b);
        add[a]++;
        add[b]++;
    }
    dump(uf);

    set<pii> block;
    vector<int> dec(n);
    rep(i, k){
        int c,d;cin>>c>>d;
        c--;d--;
        if (c>d) swap(c, d);
        block.insert(mp(c, d));
        if (uf.same(c, d)){
            dec[c]++;
            dec[d]++;
        }
    }

    vi ans;
    rep(i, n){
        ans.pb(uf.size(i)-add[i]-dec[i]-1);
    }
    rep(i, sz(ans)) cout << ans[i] << (i!=sz(ans)-1 ? " " : "\n");
    return 0;
}


Measured memory_bytes: 10360
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const int inf=1e18,M=1e9+7;
const int N=1;

int func(int n)
{
    if(n==1)
        return 1;

    return 2ll*func(n/2)+1;
}

void solve()
{
    int n;
    cin>>n;

    int ans=func(n);
    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<int> counte(N);
  vector<int> countw(N);
  int e=0,w=0;
  rep(i,N)
  {
    if(S[i]=='E') e ++;
    else w ++;
    counte[i] = e;
    countw[i] = w;
  }
  int x = counte[N-1];
  int m = P;
  rep(i,N)
  {
    int z = 0;
    if(i!=0)
    {
      z += countw[i-1];
    }
    z += x - counte[i];
    m = min(m,z);
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 6128
#include<stdio.h>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 1000000
int n,M[MAX][MAX];
void dijkstra();
int main(){
  int i,j,k,c,u,v;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
	M[i][j]=INFTY;
      }
    }
  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;
    }
  }
  dijkstra();
  return 0;
}

void dijkstra(){
  int u,minv,i,j,v,sum=0;
  int d[MAX],p[MAX],color[MAX];
  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;
  color[0]=GRAY;
  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && M[u][v]!=INFTY){
	if(d[v]>d[u]+M[u][v]){
	  d[v]=d[u]+M[u][v];
	  color[v]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
      if(d[i]==INFTY){ 
	printf("%d -1\n",i);
    }else{
      printf("%d %d\n",i,d[i]);
    }
  }
}

Measured memory_bytes: 636
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>
#include <regex>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define P pair<int, int>

using namespace std;
using ll = long long;

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

void solve(){
    int x = 0;
    char s[3];
    rep(i, 3){
        cin >> s[i];
        if(s[i] == '1'){
            x++;
        }
    }
    cout << x << endl;
}

int main(){
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const string space=" ";
int f(string s,int p[]){
	stack<int> st;
	for(int i=s.size()-1;i>=0;i--){
		if('a'<=s[i]&&s[i]<='d'){
			st.push(p[s[i]-'a']);
			continue;
		}
		if(s[i]=='['||s[i]==']')continue;
		int a=st.top();
		st.pop();
		int b=st.top();
		st.pop();
		if(s[i]=='+')
			st.push(a|b);
		if(s[i]=='*')
			st.push(a&b);
		if(s[i]=='^')
			st.push(a^b);
	}
	return st.top();
}
int main(){
	while(1){
		string s,p;
		cin>>s;
		if(s==".")break;
		cin>>p;
		int a[4];
		rep(i,4)a[i]=p[i]-'0';
		int h=f(s,a);
		int ans=0;
		rep(i,10){
			rep(j,10){
				rep(k,10){
					rep(l,10){
						a[0]=i;
						a[1]=j;
						a[2]=k;
						a[3]=l;
						int b=f(s,a);
						ans+=h==b;
					}
				}
			}
		}
		cout<<h<<space<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3180