akhauriyash/Code-Regression huggingface dataset:
n = gets.chomp.to_i
nodes = []
n.times do
    tmp = gets.chomp.split.map(&:to_i)
    nodes[tmp[0]] = { id: tmp[0], parent: nil, depth: nil, type: (tmp.size)  < 3 ? "leaf" : "internal node", children: tmp[2, tmp.size - 2] }
end

# rootCand = [*0..(n - 1)]
# nodes.each do |n|
#     next if n[1] == 0
#     rootCand = rootCand - n.drop(2)
# end
# root = rootCand[0]

# ans = []
# nodes.each do |node|
#     id = node[0]
#     parent = nil
#     depth = nil
#     if node.size < 3 then
#         type = "leaf"
#         children = []
#     else
#         type = "internal node"
#         children = node[2, node.size - 2]
#     end
#     if id == root then
#         parent = -1
#         type = "root"
#         depth = 0
#     end
#     ans.push({ id: id, parent: parent, depth: depth, type: type, children: children })
# end

nodes.each do |node|
    next if node[:type] == "leaf"
    node[:children].each do |c|
        nodes[c][:parent] = node[:id]
    end
end

nodes.each do |node|
    if node[:parent] == nil then
        node[:parent] = -1
        node[:type] = "root"
    end
end

nodes.each do |node|
    depth = 0
    parent = node[:parent]
    until parent == -1 do
        parent = nodes[parent][:parent]
        depth += 1
    end
    node[:depth] = depth
end

nodes.each { |node| puts "node #{node[:id]}: parent = #{node[:parent]}, depth = #{node[:depth]}, #{node[:type]}, #{node[:children]}" } 



Measured memory_bytes: 56116
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')

parent = lambda i: math.floor(i / 2)
left = lambda i: 2 * i
right = lambda i: 2 * i + 1


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    H = ii()
    heap = il()

    for i in range(H):
        string = 'node {0}: key = {1}, '.format(i + 1, heap[i])
        i += 1
        if parent(i) >= 1: string += 'parent key = {0}, '.format(heap[parent(i) - 1])
        if left(i) <= H: string += 'left key = {0}, '.format(heap[left(i) - 1])
        if right(i) <= H: string += 'right key = {0}, '.format(heap[right(i) - 1])
        print(string)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7148
H, W = map(int,input().split())
s = [list(input()) for i in range(H)]
num_of_point = 0
for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            num_of_point += 1
 
counter = 0
position = [[0,0]]
while True:
    counter += 1
    new_position =[]
    for i,j in position:
        for i_,j_ in [[-1,0],[1,0],[0,1],[0,-1]]:
            i_new = i+i_
            j_new = j+j_
            if i_new >=0 and i_new <= H-1 and j_new >= 0 and j_new <= W-1:
                if s[i_new][j_new] == '.':
                    new_position.append([i_new,j_new])
                    s[i_new][j_new] = counter
    if [H-1,W-1] in new_position:
        print(num_of_point-counter-1)
        break
    if counter >= H*W:
      	print(-1)
      	break
    position = new_position

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int S, W;
  cin >> S >> W;
  if(S > W) cout << "safe" << endl;
  else cout << "unsafe" << endl;
  return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong X;
  cin >> X;

  array<llong, 201> a = {};
  for (int i = 1; i <= 200; ++i) {
    a[i] = 1;
    for (int j = 0; j < 5; ++j) {
      a[i] *= i;
    }
  }

  for (int i = 0; i <= 200; ++i) {
    cerr << i << " " << a[i] << endl;
  }

  llong A, B;
  for (int i = 0; i <= 200; ++i) {
    for (int j = 0; j <= 200; ++j) {
      if (a[i] - a[j] == X) {
        A = i;
        B = j;
      }
      else if (a[i] + a[j] == X) {
        A = i;
        B = -j;
      }
    }
  }

  cout << A << " " << B << endl;

  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  string s; cin >> s;

  string result;
  if (s=="A") result = "T";
  else if (s=="C") result = "G";
  else if (s=="G") result = "C";
  else result = "A";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    LL n; R(n);
    W(n*n);
    return 0;
}


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

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main() {
  double a, b, l[4] = {}, r[4] = {};
  while(cin >> a >> b) {
    if(a >= 1.1) l[0]++;
    else if(a >= 0.6) l[1]++;
    else if(a >= 0.2) l[2]++;
    else l[3]++;

    if(b >= 1.1) r[0]++;
    else if(b >= 0.6) r[1]++;
    else if(b >= 0.2) r[2]++;
    else r[3]++;
  }
  rep(i, 4) cout << l[i] << ' ' << r[i] << endl;
}

Measured memory_bytes: 1280
n, m = gets.split.map(&:to_i)
s    = gets.chomp

ans = 0

if m == 2 || m == 5
  
  n.times{ |i| (s[i].ord - '0'.ord)%m == 0 && ans+=(i+1) }

else
  
  h = Hash.new(0)
  h[0] = 1
  
  cur = 0
  p10 = 1
  
  s.reverse.chars do |c|
    cur = ( cur + ( c.ord - '0'.ord) * p10 ) % m
    ans += h[cur]
    h[cur] += 1
    p10 = p10 * 10 % m
  end
end

puts ans

Measured memory_bytes: 2940
N = int(input())
H = [int(s) for s in input().split(" ")]

res = len(H) <= 1
for i in range(len(H) - 1, 0, -1):
    right = H[i]
    left = H[i - 1]

    if left - right > 1:
        break

    if left - right == 1:
        H[i - 1] = left - 1

    if i == 1:
        res = True

print("Yes") if res else print("No")

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

vector<vector<int>> g;
int dp[100010];

int rec(int v){
  if(dp[v]!=-1)return dp[v];

  int res=0;
  for(int nv:g[v])res=max(res, rec(nv)+1);
  return dp[v]=res;
}

int main(){
  int n,m;
  cin>>n>>m;
  g.assign(n, vector<int>());

  for(int i=0; i<m; ++i){
    int x,y;
    cin>>x>>y;
    g[x-1].push_back(y-1);
  }

  for(int i=0; i<n; ++i)dp[i]=-1;

  int ans=0;
  for(int v=0; v<n; ++v)ans=max(ans, rec(v));

  cout<<ans<<endl;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  int len = s.length();
  bool flag = true;
  //cout << len << endl;
  rep(i,len) {
    if(s[i] != t[i]) {
      flag = false;
      break;
    }
  }
  
  if(flag == true) printf("%s\n", "Yes");
  else printf("%s\n", "No");
  
  return 0;
}


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

long long power[22], N, x[1009], y[1009], G[2]; vector<long long>E;

string solve(long long X, long long Y) {
	int cnt = 0; string ans = ""; long long rx = 0, ry = 0;
	for (int i = 0; i < E.size(); i += 2) {
		cnt++;
		vector<long long>H; H.push_back(E[i]); if (i != E.size() - 1) H.push_back(E[i + 1]);

		for (int j = 0; j < (1 << (2 * H.size())); j++) {
			long long vx = rx, vy = ry; int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 }; char c[5] = "RULD";
			string rem = "";

			for (int k = 0; k < H.size(); k++) {
				vx += H[k] * dx[(j / (1 << (2 * k))) % 4];
				vy += H[k] * dy[(j / (1 << (2 * k))) % 4];
				rem += c[(j / (1 << (2 * k))) % 4];
			}
			
			if ((X - vx + power[20]) % power[cnt] == 0 && (Y - vy + power[20]) % power[cnt] == 0 && (i < E.size() - 2 || (vx == X && vy == Y))) {
				rx = vx; ry = vy; ans += rem;
				break;
			}
		}
	}
	return ans;
}

int main() {
	power[0] = 1; for (int i = 1; i <= 22; i++) power[i] = power[i - 1] * 3;

	cin >> N;
	for (int i = 1; i <= N; i++) { cin >> x[i] >> y[i]; G[(x[i] + y[i] + 10000000000LL) % 2]++; }

	if (G[0] >= 1 && G[1] >= 1) { cout << "-1" << endl; return 0; }
	for (int i = 0; i < 20; i++) { E.push_back(power[i]); E.push_back(power[i]); }
	if (G[1] >= 1) E.pop_back();

	cout << E.size() << endl;
	for (int i = 0; i < E.size(); i++) { if (i) cout << " "; cout << E[i]; } cout << endl;
	for (int i = 1; i <= N; i++) {
		cout << solve(x[i], y[i]) << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

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


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

	double ans = 0;

	if (n == 1) {
		cout << 1;
		return 0;
	}
	else if (n % 2 == 0) {
		cout << 0.5;
		return 0;
	}
	else if (n % 2 == 1) {
		ans = (double)(n / 2 + 1) / n;
		cout << ans;
		return 0;
	}

	



}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>

using namespace std;

int n, k;
int d[10];

bool check(int x)
{
	int t;
	while (x != 0) {
		t = x % 10;
		for (int i = 0; i < k; i++) {
			if (t == d[i])
				return false;
		}
		x /= 10;
	}
	return true;
}

int main()
{
	cin >> n >> k;
	for (int i = 0; i < k; i++)
		cin >> d[i];

	for (int i = n;; i++) {
		if (check(i)) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <string>

using namespace std;

typedef string::const_iterator state;

int p,q,r;

int expression(state &begin);
int term(state &begin);
int number(state &begin);
int factor(state &begin);

int number(state &begin){
	int ans;
	if(*begin=='0'){
		ans =0;
	}
	if(*begin=='1'){
		ans =1;
	}
	if(*begin=='2'){
		ans =2;
	}
	if(*begin=='P'){
		ans =p;
	}
	if(*begin=='Q'){
		ans =q;
	}
	if(*begin=='R'){
		ans =r;
	}
	begin++;
	return ans;
}

int factor(state &begin){
	if(*begin=='('){
		begin++;
		int ans = expression(begin);
		begin++;
		return ans;
	}else{
		return number(begin);
	}
}

int term(state &begin){
	int ans;
	int t=0;
	while(*begin=='-'){
		t+=1;
		begin++;
	}
	ans = factor(begin);
	if(t%2==0)return ans;
	return 2-ans;
}

int expression(state &begin){
	int ans = term(begin);
	while(1){
		if(*begin=='*'){
			begin++;
			int ans2 = term(begin);
			if(ans==0||ans2==0){
				ans = 0;
			}else if(ans==1||ans2==1){
				ans = 1;
			}else{
				ans = 2;
			}
		}else if(*begin=='+'){
			begin++;
			int ans2 = term(begin);
			if(ans==2||ans2==2){
				ans = 2;
			}else if(ans==1||ans2==1){
				ans = 1;
			}else{
				ans = 0;
			}
		}else{
			break;
		}
	}
	return ans;
}


int main(){
	string s;
	while(cin >> s&&s!="."){
		int ans = 0;
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				for(int k=0;k<3;k++){
					p=i;
					q=j;
					r=k;
					state begin =s.begin();
					if(expression(begin)==2){
						ans +=1;
					}
				}
			}
		}
		cout << ans << endl;
	}
}

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

int main(void) {
    int r, D, x;
	scanf("%d %d %d", &r, &D, &x);
	int ans = x;

	for ( int i = 0; i < 10; i++ ) {
		ans = ans*r-D;
		printf("%d\n", ans);
	}
    return 0;
}

Measured memory_bytes: 256
h1 , s1 , h2 , s2 = map(int,input().split())

while h1 >= 0 and h2 >= 0 :

    h2 -= s1
    if h2 <= 0 :
        break
    h1 -= s2
    if h1 <= 0 :
        break

#print(h1 , h2)

if h1 > h2 :
    print('Yes')
else:
    print('No')


Measured memory_bytes: 8972
#include <stdio.h>
#define MIN(x, y) (((x) > (y)) ? (y) : (x))
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))

int main()
{
  long long x;
  scanf("%lld", &x);
  long long sum = 100;
  long long year = 0;
  do {
    sum += sum / 100;
    year++;
  } while (sum < x);
  printf("%lld", year);
  return 0;
}

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

int main(){
	string s,t;cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),greater<>());
	if(s<t)puts("Yes");
	else puts("No");
}

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

using namespace std;

#define ll long long int
const int mod = 1e9 + 7;

vector<int> dp(1e5+1,-1);
vector<int> adj[(int)(1e5+ 1)];

int ans(int node){
    if(adj[node].size()==0){
        dp[node] = 0;
        return dp[node];
    }
    if(dp[node]!=-1)return dp[node];
    int a = -1;
    for(auto i: adj[node]){
        a = max(a,ans(i));
    }
    dp[node] = 1 + a;
    return dp[node];
}

int main() {
    //code
    int n,m;
    cin>>n>>m;
    int u,v;
    while(m--){
        cin>>u>>v;
        adj[u].push_back(v);
    }
    int an = 0;
    for(int i = 1;i <=n;i++)an = max(an,ans(i));
    cout<<an;
    return 0;
}

Measured memory_bytes: 11028
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = int64_t;

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

    vector<int> a(n, 0);
    for (int i = 1; i < n; i++) {
        int tmp;
        cin >> tmp;
        a.at(tmp - 1) += 1;
    }

    for (auto&& i : a) {
        cout << i << endl;
    }
}


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

using namespace std;
#define mod 1000000007
#define int long long
#define mxn 200002
int fact[mxn];
int inv[mxn];
int mul(int a, int b)
{
    return a*b%mod;
}
int mypower(int a, int b)
{
    int ans = 1;
    while(b)
    {
        if(b%2)
            ans = mul(ans, a);
        b=b/2;
        a=mul(a,a);
    }
    return ans;
}
void pre()
{
    fact[0] = 1;
    int i;
    for(i=1;i<mxn;i++)
        fact[i] = mul(fact[i-1], i);
    inv[mxn-1] = mypower(fact[mxn-1], mod-2);    
    for(i=mxn-2;i>=0;i--)
        inv[i] = mul(inv[i+1], i+1);
}
int nCr(int n, int r)
{
    if(n < 0 || r < 0 || n < r)
        return 0;
    return mul(fact[n], mul(inv[r], inv[n-r]));    
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    pre();
    int n;
    cin >> n;
    if(n <= 2)
        cout << 0 << '\n';
    else
    {
        int i, ans = 0;
        for(i=1;2*i+1<=n;i++)
            ans = (ans + nCr(n-2*i-1, i-1))%mod;
        ans = (ans+mod)%mod;
        cout << ans;
    }
}

Measured memory_bytes: 6776
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
//#define inf 2000000000
#define inf 8000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a)
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;

inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=200005;
//i_am_noob
int n,m,k,cnt,ans=0;
char grid[7][7],grid2[7][7];

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m >> k;
    rep(n) rep1(j,m) cin >> grid[i][j];
    rep1(mask,pow2(n+m)){
        rep(n) rep1(j,m) grid2[i][j]=grid[i][j];
        rep(n) if(mask&pow2(i)) rep1(j,m) grid2[i][j]='.';
        rep1(j,m) if(mask&pow2(n+j)) rep(n) grid2[i][j]='.';
        cnt=0;
        rep(n) rep1(j,m) if(grid2[i][j]=='#') cnt++;
        if(cnt==k) ans++;
    }
    print1(ans);
    return 0;
}


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

A, B, C = map(int, input().split())
K = int(input())

if A < B < C:
    print('Yes')
    exit()

while K > 0:
    if A >= B:
        B *= 2
    elif B >= C:
        C *= 2

    K -= 1


if A < B < C:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9172
/* C - One Quadrillion and One Dalmatians */

#include <stdio.h>
#define ALPH 26

/*
long long ExAlph(int n){
  if(n == 0) return 1;
  else return ALPH * ExAlph(n - 1);
}
*/

int main(void){
  long long N, n;
  long long exAlph[12];
  scanf("%lld", &N);
  for(int i = 0; i < 12; i++){
    if(i == 0){
      exAlph[i] = 1;
    }else{
      exAlph[i] = exAlph[i - 1] * ALPH;
    }
    // printf("%lld\n", exAlph[i]);
  }
  n = N;
  for(int i = 1; ; i++){
    if(n <= exAlph[i]){ // 出力される文字数はiで確定
      n--;
      for(int j = i; j > 0; j--){
        printf("%c", 'a' + n / exAlph[j - 1]);
        n -= n / exAlph[j - 1] * exAlph[j - 1];
      }
      break;
    }else{
      n -= exAlph[i];
    }
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep_ll(i,n) for(ll i = 0; i < (ll)(n); i++)

using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;

const long double PI = (acos(-1));
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a%b);
}
int main(){
    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;
    vector<int> ans(n, 0);
    rep(sv, n){
        vector<int> dis(n, INF);
        queue<int> q;
        auto push = [&](int v, int d){
            if(dis[v] != INF) return;
            q.push(v);
            dis[v]=d;
        };
        push(sv, 0);
        while(!q.empty()){
            int v = q.front(); q.pop();
            int d = dis[v];
            if(v+1>=0) push(v-1, d+1);
            if(v-1<n) push(v+1, d+1);
            if(v==x) push(y, d+1);
            if(v==y) push(x, d+1);
        }
        rep(i,n) ans[dis[i]]++; 
    }
    rep(i, n) ans[i] /= 2;
    for(int i = 1; i <= n-1; ++i){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
class Program {
  static void Main (string[] args) {
    int n = int.Parse(Console.ReadLine());
    float od = 0.0f;
    for (int cnt = 0; cnt < n; cnt++) {
      string[] str = Console.ReadLine().Split(' ');
      if (str[1] == "JPY") {
        od += float.Parse(str[0]);
      }
      else if (str[1] == "BTC") {
        float bt = float.Parse(str[0]);
        od += bt * 380000.0f;
      }
    }
    Console.WriteLine(od);
  }
}

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

int main(){
    string s;
    cin >> s;
    string revs = s;
    int ansCount = 0;
    for(int i = 0; i < s.size() / 2; i++){
        if(s[i] != revs[s.size()-1-i])ansCount++;
    }
    cout << ansCount << endl;
    return 0;
}

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

int main(){
    int a,b;
    char op;
    while(1){
        cin>> a >> op >> b;
        if(op == '?') break;
        else if(op=='+') cout<< a+b <<endl;
        else if(op=='-') cout<< a-b <<endl;
        else if(op=='*') cout<< a*b <<endl;
        else if(op=='/') cout<< a/b <<endl;
        
    }
    }

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
  int N, K, now;
  cin >> N >> K;
  double pr=0, prk=1;
  for(int i=1; i<=N; i++){
    now = i;
    while(now < K){
      now *= 2;
      prk /= 2;
    }
    pr += prk / N;
    prk = 1;
  }
  cout << setprecision(12) << pr;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x;
    cin>>n;
    bool f = false;
    for(int i=1;i<10;i++){
        if((n%i==0)&&(n/i<10)){
            f = true;
        }
    }
    if(f){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    

    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
int main() {
    string S;
    cin >> S;
    long long ans = 0;
    long long index = 0;
    rep(j, 0, S.size()){
        if(S[j]=='B') {
            index++;
        }
    }
    rep(i, 0, S.size()-1){
        if(S[i]=='B') {
            index--;
            ans += ((S.size()-1)-index) - i;
        }
        
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
#pragma region DEBUG
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\n"
lli dx[] = {-1,1,0,0};
lli dy[] = {0,0,-1,1};
lli d5x[] = {-2,-1,0,1,2};
lli d5y[] = {-2,-1,0,1,2};
lli h,w;
lli dist[1200][1200];
bool visited[1200][1200];
string arr[1200];
bool check(lli x,lli y){
    if(x < h && y < w && x >= 0 && y >= 0 && !visited[x][y] && arr[x][y] == '.'){
            return true;
    }
    return false;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
   // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    lli t;
    t =1 ;
    while(t--){
        cin>>h>>w;
        lli ax,ay, bx,by;
        cin>>ax>>ay>>bx>>by;
        ax--,ay--,bx--,by--;
        for(lli i = 0; i<h; i++)
            cin>>arr[i];
        for(lli i = 0; i<h; i++){
            for(lli j = 0; j<w; j++)
                dist[i][j] = INT_MAX;
        }
        set <tuple<lli,lli,lli> > s;
        s.insert({0,ax,ay});
        while(!s.empty()){
            lli d,x,y;
            tie(d,x,y) = *(s.begin());
            visited[x][y] = true;
            for(lli i = 0; i<4; i++){
                lli X = x + dx[i];
                lli Y = y + dy[i];
                if(check(X,Y)){
                    dist[X][Y] = min(d,dist[X][Y]);
                    s.insert({dist[X][Y],X,Y});
                }
            }
            for(lli i = 0; i<5; i++){
                for(lli j = 0; j<5; j++){
                    lli X = x + d5x[i];
                    lli Y = y + d5y[j];
                    //debug(X,Y);
                    if(check(X,Y)){
                        dist[X][Y] = min(d+1,dist[X][Y]);
                        s.insert({dist[X][Y],X,Y});
                    }
                }
            }
            s.erase({d,x,y});
        }
        lli ans = -1;
        if(dist[bx][by] != INT_MAX)
            ans = dist[bx][by];
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 15880
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    # N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    # h_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([]))

    for i in range(1, 6):
        if S == "hi" * i:
            print('Yes')
            return

    print('No')


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """hihi"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """hi"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """ha"""
        output = """No"""
        self.assertIO(input, output)


Measured memory_bytes: 6060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int n; cin >> n;
    map<int, ll> mp;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
        mp[a[i]]++;
    }
    ll all = 0;
    for(auto p : mp){
        all += p.second * (p.second-1) / 2;
    }
    rep(i,n){
        ll ans = all;
        ans -= mp[a[i]] * (mp[a[i]]-1) / 2;
        ans += (mp[a[i]]-1) * (mp[a[i]]-2) /2;
        cout << ans << endl;
    }
}


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

int op(int a, int b) { return max(a,b); }
int e() { return 0;}

int dp[300005];
int main() {
    int n, k;
    cin>>n>>k;
    vector<int> vec;

    for(int i=0; i<n; i++)
    {
        int x;
        cin >> x;
        vec.push_back(x);
    }

    segtree<int, op, e> dp(300005);
    for(int i=0; i<n; i++)
    {
        int x=vec[i];
        int l=x-k, r=x+k+1;
        l=max(0,l); r=min(r,300005);
        int now = dp.prod(l,r)+1;
        dp.set(x, now);
    }
    cout << dp.prod(0, 300005);

    return 0;
}


Measured memory_bytes: 9852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main(){
  string S;
  cin >> S;
  if (S.at(2)==S.at(3) && S.at(4)==S.at(5)) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a;
    cin >> n >> a;
    if (n % 500 <= a) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define all(x) x.begin(), x.end()
#define watch(x) cout<<#x<<" : "<<x<<endl
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define testCases int tt;cin>>tt; while(tt--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef vector<string> vs;

int main() {
    fastio;
    int n;
    cin >> n;
    set<int> s;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        s.insert(temp);
    }
    if (s.size() == n) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 12992
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
	int n = read.to!int;
	int m = read.to!int;
	
	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node(i);
	
	foreach(j; 0 .. m){
		int u = read.to!int - 1;
		int v = read.to!int - 1;
		nodes[u].sons ~= nodes[v];
	}
	
	int s = read.to!int - 1;
	int t = read.to!int - 1;
	Node node0 = nodes[s], node1 = nodes[t];
	
	node0.value = [0, -1, -1];
	Node[] queue = [node0];
	int ix;
	while(ix < queue.length){
		Node nd = queue[ix];
		foreach(son; nd.sons){
			bool f = 0;
			if(nd.value[0] >= 0 && son.value[1] < 0){
				son.value[1] = nd.value[0];
				f = 1;
			}
			if(nd.value[1] >= 0  && son.value[2] < 0){
				son.value[2] = nd.value[1];
				f = 1;
			}
			if(nd.value[2] >= 0  && son.value[0] < 0){
				son.value[0] = nd.value[2] + 1;
				f = 1;
			}
			if(f) queue ~= son;
		}
		log("ix:", ix, "queue:", queue, "nodes:", nodes);
		ix ++;
	}
	if(node1.value[0] >= 0) node1.value[0].writeln;
	else "-1".writeln;
}
	
class Node{ // 流用時注意
	int id;
	int[3] value = [-1, -1, -1]; // 余り0で訪れる最小の歩数 など
	Node[] sons;
	this(int id){
		this.id = id;
	}
	override string toString(){
		return (id + 1).to!string ~ "->" ~ sons.map!(x => (x.id + 1).to!string).array.join(",") ~ " " ~  value.to!string;
	}
}



Measured memory_bytes: 22012
<?php
list($n, $a, $b) = ints();
if ($a > $b) exit('0');
if ($a === $b) exit('1');
if ($n === 1) exit('0');
echo ($b - $a) * ($n - 2) + 1;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16272
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in range(1,n+1)]

d={ea:eb for (ea,eb) in zip(a,b)}

for k,v in sorted(d.items(), key=lambda x:x[0]):
  print(str(v)+" ",end="")
print()


Measured memory_bytes: 25592
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
//	 static int mod = 998244353;
	 public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();
	        int K = sc.nextInt();
	        
	        int cnt1=N/K;
	        long ans=(long)Math.pow(cnt1, 3);
	        if(K%2==0) {
	        	int cnt2=(N+K/2)/K;
	        	ans=ans+(long)Math.pow(cnt2,3);
	        }
	   	 	
	   	 System.out.println(ans);
	 }
	 

}

Measured memory_bytes: 23380
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for (int i = 0; i < (n); i++)

int main() {
  int A, B;

  cin >> A >> B;
  if (A + B >= 10) cout << "error" << endl;
  else cout << A + B << endl;
  
  return 0;
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  SCIN(w);
  map< char, int > mp;
  REP(i, w.size()) {
    mp[w[i]]++;
  }

  bool ok = true;
  EACH(i, mp) {
    ok &= (i.second % 2 == 0);
  }

  OK(ok);

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

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

    int A[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }

    sort(A, A+N);

    for(int i=N-1; i>=0; i--){
        H -= A[i];
    }

    if(H <= 0) cout << "Yes";
    else cout << "No";

    return 0;
}

Measured memory_bytes: 640
N=int(input())
S=[input() for i in range(N)]
M=int(input())
T=[input() for i in range(M)]

Set=set(S)

a=0
A=[0]
for i in Set:
    a=0
    if i in S:
        a+=S.count(i)
    if i in T:
        a-=T.count(i)
    A.append(a)

print(max(A))


Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define REP(i,n) for(i=0;i<(int)(n);++i)
#define SIZE 3010//文字列の長さの最大値
int i,j;//for文の添字

int max(int a,int b){//a,bのうち大きい方を返す
    if(a>b)return a;
    else return b;
}

int main(){
    //変数の初期化
    char s1[SIZE],s2[SIZE];
    int ls1=0,ls2=0;
    int dp[SIZE][SIZE];
    char res[SIZE];
    int lcslen;
    int ms1,ms2;
    int cnt = 0;
    //入力処理
    fgets(s1,SIZE,stdin);
    fgets(s2,SIZE,stdin);

    ls1 = strlen(s1);
    ls2 = strlen(s2);
    REP(i,ls1){//動的計画法
        REP(j,ls2){
            if(i==0||j==0){
                dp[i][j]=0;
            }else{
                if(s1[i-1]==s2[j-1]){
                    dp[i][j]=dp[i-1][j-1]+1;
                }else{
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
    }
    lcslen = dp[ls1-1][ls2-1];
    ms1=ls1-1;
    ms2=ls2-1;
    cnt = lcslen-1;
    while(dp[ms1][ms2]!=0){
        if(s1[ms1-1]==s2[ms2-1]){
            res[cnt--] = s1[ms1-1];
            ms1--;
            ms2--;
        }else if(dp[ms1-1][ms2]>=dp[ms1][ms2-1]){
            ms1--;
        }else{
            ms2--;
        }
    }
    //出力処理
    printf("%s\n",res);
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

const int MAX = 1e6+10;
const ll INF = 1e18;

const int DX[4] = {-1, 0, 1, 0};
const int DY[4] = {0, -1, 0, 1};

int H, W, K;
int X1, Y1, X2, Y2;
vector<vector<bool>> C;

ll solve() {
    vvi dist(H, vi(W, INF));
    queue<ii> que;
    que.push(ii(X1, Y1));
    dist[X1][Y1] = 0;

    while(!que.empty()) {
        ll x, y;
        tie(x, y) = que.front(); que.pop();

        REP (d, 4) {
            FOR (k, 1, K+1) {
                int nx = x + DX[d] * k, ny = y + DY[d] * k;
                if (nx < 0 || H <= nx || ny < 0 || W <= ny || !C[nx][ny] || dist[nx][ny] <= dist[x][y]) break;
                if (dist[nx][ny] == INF) {
                    dist[nx][ny] = dist[x][y] + 1;
                    que.push(ii(nx, ny));
                }
            }
        }
    }

    if (dist[X2][Y2] == INF) return -1;
    return dist[X2][Y2]; 
}

int main() {
    cout << fixed << setprecision(15);
    cin >> H >> W >> K >> X1 >> Y1 >> X2 >> Y2;
    X1--; Y1--; X2--; Y2--;
    REP (h, H) {
        string s;
        cin >> s;
        C.push_back(vector<bool>(W));
        REP (w, W) if (s[w] == '.') C[h][w] = true;
    }
    cout << solve() << endl;
}

Measured memory_bytes: 19044
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[][] x = new String[h][w];
		int[] a = new int[h];
		int[] b = new int[w];

		for (int i = 0; i < h; i++) {
			String str = sc.next();
			for (int j = 0; j < w; j++) {
				x[i][j] = str.substring(j, j + 1);
				if (x[i][j].equals("#")) {
					a[i]++;
					b[j]++;
				}
			}
		}

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (a[i] > 0 && b[j] > 0) {
					System.out.print(x[i][j]);
				}
			}
			if (a[i] > 0) {
				System.out.println();
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 24788
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll k;
    cin>>k;
    int arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    k--;
    cout<<arr[k];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 12032
function Main(input) {
  const data = input.trim();
 
  var strs = data.split("");
 
  var list = [];
 
  strs.forEach((n) => {
    if (list.indexOf(n) == -1) {
      list.push(n);
    } else {
      var idx = list.indexOf(n);
      list.splice(idx, 1);
    }
  });
 
  if (list.length > 0) {
    console.log("No");
  } else {
    console.log("Yes");
  }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
def S1(r,T,M):
  # 1+r+...+r^{T-1}
  # (r^T-1)/(r-1)
  # mod M(r-1)で計算する
  if r == 1:
    return T%M
  x = pow(r,T,M*(r-1)) - 1
  return (x//(r-1))%M

def S2(r,T,M):
  # sum ir^i
  if r == 1:
    x = T*(T-1)//2
    return x%M
  Mr = M*(r-1)
  x = (T-1) * pow(r,T,Mr)
  x -= S1(r,T,Mr)
  x += 1
  x //= (r-1)
  return x

def S(A,B,L,M):
  result = 0
  d = len(str(A)) # 桁数
  start = A
  r = 10**d
  while True:
    n1 = ((r-1)-A)//B+1
    items = min(n1,L) # その桁の項数
    last = A + (items-1)*B
    x = last * S1(r,items,M)
    x -= B * S2(r,items,M)
    result *= pow(r,items,M)
    result += x
    result %= M
    # パラメータの更新
    r *= 10
    d += 1 # 不要かも
    L -= items
    A += B*items
    if L <= 0:
      break
  return result%M

L,A,B,M = map(int,input().split())
answer = S(A,B,L,M)
print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/abc121_b.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, M, C;
  cin >> N >> M >> C;

  vector<int> b(M);
  rep(i, M) { cin >> b[i]; }
  
  vector<vector<int>> c(N, vector<int>(M, 0));
  rep(i, N) {
    rep(j, M) { cin >> c[i][j]; }
  }

  ll cnt = 0;
  rep(i, N) {
    int tmp = C;
    rep(j, M) {
      tmp += b[j] * c[i][j];
    }
    if (tmp > 0) cnt++;
  }

  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n, d, x, a, ans;
  cin >> n >> d >> x;
  d--;
  ans = x;
  rep(i,n)
  {
    cin >> a;
    ans += d / a;
    ans++;
  }

  cout << ans;
}


Measured memory_bytes: 256