akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

d, n = map(int, input().split())

if d == 0 and n == 100:
    print(101)
elif d == 0:
    print(n)

if d == 1 and n == 100:
    print(10100)
elif d == 1:
    print(100 * n)

if d == 2 and n == 100:
    print(1010000)
elif d == 2:
    print(10000 * n)    

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

using namespace std;

int P;
int Reciprocal[46000];
string ExpInfo;


int getReciprocal(int a) {
	int x, n;

	n = P - 2;
	x = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			x = (x*a) % P;
		}
		a = (a*a) % P;
		n >>= 1;
	}

	return x;
}

int getNumber(unsigned int *pIndex) {
	int num;
	string tmp;
	stringstream ss;

	tmp += ExpInfo[(*pIndex)++];
	while (isdigit(ExpInfo[*pIndex])) {
		tmp += ExpInfo[*pIndex];
		++(*pIndex);
	}
	ss << tmp;
	ss >> num;
	--(*pIndex);

	//cout << num << " ";
	return num;
}

int priorityOfOperation(char c) {

	switch (c) {
	case'(':
		return 3;
	case '*':
	case '/':
		return 2;
	case '+':
	case '-':
		return 1;
	default:
		return 0;
	}
}

bool calculation(stack<int>& digitList, stack<char>& opList) {
	int num2, result;
	char ch;

	ch = opList.top();
	opList.pop();
	num2 = digitList.top();
	digitList.pop();
	result = digitList.top();
	digitList.pop();
	//cout << result << " " << ch << " " << num2 << " = ";

	if (ch == '+' || ch == '-') {
		if (ch == '-') {
			num2 = P - num2;
			//cout << "m=" << num2 << endl;
		}
		result = (result + num2) % P;
	}
	else if (ch == '*' || ch == '/') {
		if (ch == '/') {
			if (num2 == 0) {
				return false;
			}
			num2 = Reciprocal[num2];
		}
		result = (result * num2) % P;
	}
	//cout << result << endl;
	digitList.push(result);
	return true;
}

bool calculationProcess(stack<int>& digitList, stack<char>& opList) {
	int num, nowPriority;
	char cTmp;

	//size = ExpInfo.size();
	for (unsigned int i = 0; i < ExpInfo.size(); ++i) {
		cTmp = ExpInfo[i];

		if (cTmp == ' ') {
			ExpInfo = ExpInfo.erase(i, 1);
			--i;
			continue;
		}
		
		if (isdigit(cTmp)) {
			num = getNumber(&i);
			//cout << num << " ";
			digitList.push(num);
			continue;
		}
		if (opList.empty() || cTmp == '(' || opList.top() == '(') {
			opList.push(cTmp);
			continue;
		}

		nowPriority = priorityOfOperation(cTmp);
		if (nowPriority > priorityOfOperation(opList.top())) {
			opList.push(cTmp);
		}
		else {
			do {
				if (!calculation(digitList, opList)) {
					return false;
				}
			} while (!opList.empty() && opList.top() != '(' && nowPriority <= priorityOfOperation(opList.top()));

			if (cTmp == ')') {
				opList.pop();
			}
			else {
				opList.push(cTmp);
			}
		}
	}

	while (!opList.empty()) {
		if (!calculation(digitList, opList)) {
			return false;
		}
	}

	return true;
}

void solve() {
	stack<int> digitList;
	stack<char> opList;

	if (!calculationProcess(digitList, opList)) {
		cout << "NG" << endl;
		//cout << "numSize:" << digitList.size() << "  opSize:" << opList.size() << endl;
		return;
	}
	cout << ExpInfo << " = ";
	cout << digitList.top() << " (mod " << P << ")" << endl;
	digitList.pop();
	//cout << "numSize:" << digitList.size() << "  opSize:" << opList.size() << endl;
}

int main() {
	char ch;

	while (cin >> P >> ch, P) {
		for (int i = 1; i < P; ++i) {
			Reciprocal[i] = getReciprocal(i);
		}
		getline(cin, ExpInfo);
		solve();
	}

	return 0;
}



Measured memory_bytes: 3424
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

k = inp()
b = (k-1)//50+50
r = k%50
l = 50-r
a = b-r-1
if r == 0: a = b
print(50)
res = [-1] * 50
for i in range(50):
    if i < l:
        res[i] = a
    else:
        res[i] = b
print(*res)

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

int gcd(int n1, int n2) {
	return (n2 == 0) ? n1 : gcd(n2, n1 % n2);
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	vector<int> g(n);
	g[0] = a[0];
	for (int i = 1; i < n; i++)
		g[i] = gcd(g[i - 1], a[i]);
	cout << g[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
long long int minx(long long int a,long long int b)
{
	if (a>b)
	 	return b;
	return a;
}
long long int maxx(long long int a,long long int b)
{
	if (a>b)
	 	return a;
	return b;
}
int main()
{
	long long int a,b;
	cin>>a>>b;
	if (a>0 && b>0)
		cout<<"Positive\n";
	else
	{
		int num=0;
		for (int i=minx(a,b);i<=maxx(a,b);i++)
		{
			if (i==0)
			{
				cout<<"Zero\n";
				return 0;
			}
			else if (minx(i,0)==i)
				num++;
		}
		if (num%2==0)
			cout<<"Positive\n";
		else
			cout<<"Negative\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

void correct(){
    int X;
    std::cin>>X;
    for(int A=-118;A<120;++A){
        for(int B=-119;B<118;++B){
            if(A*A*A*A*A-B*B*B*B*B==X){
                std::cout<<A<<" "<<B<<std::endl;
                return;
            }
        }
    }
}
int main(){
    correct();
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#include <math.h>
#include <iomanip>
#include <fstream>
#include <random>
using namespace std;

inline void InitRand()
{
    srand((unsigned int)time(NULL));
}
int main() {
     InitRand();
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i){cin>>a[i];}
    sort(a,a+n);
    int sum1=0;
    int sum2=0;
    for(int i=0;i<n;++i){
        if(i%2==0){sum1+=a[n-i-1];}else{sum2+=a[n-i-1];}
    }
    cout<<sum1-sum2<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.lang.Math.abs
import java.math.BigInteger

fun read() = readLine()!!

operator fun BigInteger.dec(): BigInteger = this.subtract(BigInteger.ONE)

// 階乗 (n!)
tailrec fun fact(n: BigInteger, ans: BigInteger = BigInteger.ONE) : BigInteger {
    if(n.compareTo(BigInteger.ONE) < 1) return ans
    return fact(n.dec(), ans * n)
}

// 最大公約数
tailrec fun gcd(a: Int, b: Int): Int {
    if(b == 0) return a
    return gcd(b, a % b)
}

// フィボナッチ数
//
tailrec fun fib(n: BigInteger, a: BigInteger = BigInteger.ZERO, b: BigInteger = BigInteger.ONE): BigInteger {
    if(n == BigInteger.ONE) return a
    return fib(n.dec(), b, a + b)
}

// 累乗(バイナリ法)
// a^n
tailrec fun pow(a: BigInteger, n: Int, ans: BigInteger = BigInteger.ONE): BigInteger {
    if(n == 0) return ans
    return pow(a * a, n.ushr(1), if(n.and(1) == 1) ans * a else ans)
}

tailrec fun newton(
    f: (Double) -> Double,
    df: (Double) -> Double,
    x: Double,
    eps: Double = Float.MIN_VALUE.toDouble()
): Double {
    val xnew = x - f(x) / df(x)
    if(abs(xnew - x) < eps) return xnew
    return newton(f, df, xnew, eps)
}

tailrec fun iteration(
    r: (Double) -> Double,
    x: Double,
    eps: Double = Float.MIN_VALUE.toDouble()
): Double {
    val xnew = r(x)
    if(abs(xnew - x) < eps) return xnew
    return iteration(r, xnew, eps)
}

// 二分探索 (木構造使ってない)
fun binarySearch(list: List<Int>, target: Int): Int {
    if(target < list.first() || list.last() < target) return -1

    var first = 0
    var last = list.size
    while (first + 1 != last) {
        val center = first + (last - first) / 2
        val centerVal = list[center]

        if(centerVal == target) return centerVal

        if(centerVal < target) first = center
        else last = center
    }
    return -1
}

fun main(vararg args: String) {
    val a = listOf('R', 'U', 'D')
    val b = listOf('L', 'U', 'D')
    val s = read()
    var br = false
    for(i in s.indices) {
        if(i % 2 == 0) {
            if(! a.contains(s[i])) br = true
        }else{
            if(! b.contains(s[i])) br = true
        }
    }
    println(if(br) "No" else "Yes")
}

Measured memory_bytes: 37768
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


int main(){
    int H,W,h,w; cin >> H >> W >> h >> w; 
    cout << H*W - (h*W + w*H - w*h) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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; }

ll N,W,dp[101][100100],w,v;

int main(){
    cin>>N>>W;
    rep(i,100100){
        if(i)dp[0][i]=1e9+7;
        else dp[0][i]=0;
    }
    repi(i,1,N+1){
        cin>>w>>v;
        rep(j,100100){
            if(j<v)dp[i][j]=dp[i-1][j];
            else{
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-v]+w);
            }
            // if(dp[i][j]!=1e9+7)cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
        }
        // out("");
    }
    for(int i=100000;i>=0;i--){
        if(dp[N][i]<=W){
            // out(dp[N][i]);
            out(i);
            return 0;
        }
    }
    
    
}


Measured memory_bytes: 79360
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 120000;

int n;
int a[MAXN];

ll solve() {
	if (n == 1)
		return 0;
	sort(a, a + n);
	if (n % 2 == 0) {
		ll ans = 0;
		int k = n / 2;
		for (int i = 0; i < k - 1; ++i)
			ans -= 2 * a[i];
		ans -= a[k - 1];
		ans += a[k];
		for (int i = k + 1; i < n; ++i)
			ans += 2 * a[i];
		return ans;
	}
	else {
		ll ans = 0;
		int k = n / 2 + 1;
		for (int i = 0; i < k - 2; ++i)
			ans -= 2 * a[i];
		ans -= a[k - 1];
		ans -= a[k - 2];
		for (int i = k; i < n; ++i)
			ans += 2 * a[i];
		return ans;
	}
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	ll ans = solve();
	for (int i = 0; i < n; ++i)
		a[i] = -a[i];
	ans = max(ans, solve());
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 640
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int main(){
	int R, G;
	cin >> R >> G;
	cout << 2 * G - R << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	string s;
	cin>>s;
	sort(s.begin(),s.end());
	//cout<<s[0]<<s[1]<<s[2]<<s[3]<<endl;
	if(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2])	cout<<"Yes"<<endl;
	else						cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
// う　し　た　ぷ　に　き　あ　く　ん　笑
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];

    bool ans = true;

    for (int i = 1; i < n; i++) {
        if (h[i] > h[i - 1]) {
            h[i]--;
        } else if (h[i] == h[i - 1])
            ;
        else if (h[i] < h[i - 1]) {
            ans = false;
        }
    }

    cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3988
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;

void solve(){
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    char cur = 'a';
    while(true){
        if(cur == 'a'){
            if(s1.empty()) break;
            cur = s1[0];
            s1.erase(0, 1);
        }
        else if(cur == 'b'){
            if(s2.empty()) break;
            cur = s2[0];
            s2.erase(0, 1);
        }
        else{
            if(s3.empty()) break;
            cur = s3[0];
            s3.erase(0, 1);
        }
    }
    cout << (char)(cur - 32);
}

 
int main() {
    barsik;
    int q = 1;
    //cin >> q;
    while(q--) solve();
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;i++)
#define FORD(i,a,b) for (int i=a;i>=b;i--)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n,k,a[500010],x[500010],y[500010],b[500010];
LL ans;
void calc(){
	int t=0;
	FORD(i,30,0) t+=y[i]*(1<<i);
	LL s=0;
	FOR(i,1,n)
		if ((a[i]&t)==a[i]) s+=b[i];
	ans=max(ans,s);
}
int main(){
	scanf("%d%d",&n,&k);
	FOR(i,1,n) getint(a[i]),getint(b[i]);
	FOR(i,0,30) x[i]=k&1,k>>=1;
	FOR(i,0,30) y[i]=x[i];
	calc();
	FORD(i,30,0)
		if (x[i]==1){
			FOR(j,0,30) y[j]=x[j];
			y[i]--;
			FORD(j,i-1,0) y[j]=1;
			calc();
		}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4864
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int X = sc.nextInt();
    int Y = sc.nextInt();
    int ans = 0;
    if(N <= K) {
      ans = N * X; 
    } else {
      ans = K * X + (N - K) * Y;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 22740
h, w = (int(i) for i in input().split())

inp = [[i for i in list(input())] for i in range(h)]

bombs = [[0 for _ in range(w+2)] for _ in range(h+2)]

for hh in range(h):
    for ww in range(w):
        if inp[hh][ww] =="#":
            bombs[hh][ww+2] += 1
            bombs[hh][ww] += 1
            bombs[hh][ww+1] += 1
            bombs[hh+1][ww+2] += 1
            bombs[hh+1][ww] += 1
            bombs[hh+1][ww + 1] += 1
            bombs[hh+2][ww+2] += 1
            bombs[hh+2][ww] += 1
            bombs[hh+2][ww + 1] += 1

for hh in range(h):
    for ww in range(w):
        if inp[hh][ww] == "#":
            print("#", end="")
        else:
            print(bombs[hh+1][ww+1], end="")
    print()


Measured memory_bytes: 3572
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

constexpr int Mod = 1000000007;

constexpr int add(int a, int b) { return (a + b) % Mod; }
constexpr int sub(int a, int b) { return (a - b) % Mod; }
constexpr int mul(int a, int b) { return (int) ((long long) a * b % Mod); }
constexpr int fma(int a, int b, int c) { return (int) (((long long) a * b + c) % Mod); }
constexpr int pow(int a, int b) {
  auto c = 1;
  while (b) {
    if (b & 1)
      c = mul(c, a);
    a = mul(a, a);
    b >>= 1;
  }
  return c;
}

int Q[200000];
int R[200000];

struct Cell { int x, y; };

void init(int N) {
  Q[0] = 1;
  for (auto i = 1; i <= N; ++i)
    Q[i] = mul(Q[i - 1], i);
  R[N] = pow(Q[N], Mod - 2);
  for (auto i = N; i; --i)
    R[i - 1] = mul(R[i], i);
}

int calc(const Cell& a, const Cell& b) {
  auto x = b.x - a.x;
  auto y = b.y - a.y;
  return mul(Q[x + y], mul(R[x], R[y]));
}

int main() {
  int N, M, K;
  scanf("%d%d%d", &N, &M, &K);
  init(max(N, M) * 2 - 1);
  static Cell A[3001];
  for (auto i = 0; i < K; ++i)
    scanf("%d%d", &A[i].x, &A[i].y);
  sort(A, A + K, [](const Cell& a, const Cell& b) {
    return a.x != b.x ? a.x < b.x : a.y < b.y;
  });
  A[K] = {N, M};
  static int F[3001];
  for (auto i = 0; i <= K; ++i) {
    F[i] = calc(Cell{1, 1}, A[i]);
    for (auto j = 0; j < i; ++j)
      if (A[j].x <= A[i].x && A[j].y <= A[i].y)
        F[i] = fma(-F[j], calc(A[j], A[i]), F[i]);
  }
  printf("%d\n", add(F[K], Mod));
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
template <typename signature> using f = const function<signature>;
f<bool(int, int)> hori = [](int di, int dj) { return abs(di) == 0 and abs(dj) == 1; };
f<bool(int, int)> vert = [](int di, int dj) { return abs(di) == 1 and abs(dj) == 0; };
f<bool(int, int)> diag = [](int di, int dj) { return abs(di) == 1 and abs(dj) == 1; };
f<bool(int, int)> operator||(f<bool(int, int)>& f1, f<bool(int, int)>& f2) {
    return [&](int di, int dj) { return f1(di, dj) or f2(di, dj); };
}
vector<vector<int>> flood(vector<vector<int>>& a, int si, int sj,
f<bool(int, int)>& can, f<void(int, int)>& f = [](int, int) {}) {
    vector<vector<int>> d(a.size(), vector<int>(a[0].size(), -1));
    d[si][sj] = 0;
    queue<pair<int, int>> q({{si, sj}});
    while(not q.empty()) {
        auto p = q.front(); q.pop();
        int i = p.first, j = p.second;
        f(i, j);
        for(int di = -1; di <= 1; di++) {
            for(int dj = -1; dj <= 1; dj++) {
                int ni = i + di, nj = j + dj;
                if(a[ni][nj] and d[ni][nj] == -1 and can(di, dj)) {
                    d[ni][nj] = d[i][j] + 1;
                    q.push({ni, nj});
                }
            }
        }
    }
    return d;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int h, w, n;
    cin >> h >> w >> n;
    vector<vector<int>> a(h + 2, vector<int>(w + 2));
    vector<int> vi(n + 1), vj(n + 1);
    for(int i = 1; i <= h; i++) {
        string s;
        cin >> s;
        for(int j = 1; j <= w; j++) {
            a[i][j] = s[j - 1] != 'X';
            if(s[j - 1] == 'S') {
                vi[0] = i, vj[0] = j;
            } else if(isdigit(s[j - 1])) {
                vi[s[j - 1] - '0'] = i, vj[s[j - 1] - '0'] = j;
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += flood(a, vi[i - 1], vj[i - 1], hori or vert)[vi[i]][vj[i]];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 10624
N = int(input())
A = [int(x) for x in input().split()]
cnt = 0
while True:
    if len(A) == A.count(0):
        break
    if len([x for x in A if x%2 == 0]) == len(A):
        A = [x//2 for x in A]
        cnt += 1
    else:
        break
print(cnt)

Measured memory_bytes: 3060
def gcd(a, b)
  a, b = b, a if a > b
  until a == 0
    a, b = b%a, a
  end
  return b
end

def lcm(a, b)
  a*b/gcd(a, b)
end

while gets do
  a, b = $_.chomp.split(' ').map(&:to_i)
  puts "#{gcd(a, b)} #{lcm(a, b)}"
end

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

#define 	pi				3.1415926536
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(int i = a ; i < b ; i++)
#define     repn(i, a, b)   for(int i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define 	E 				end()
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define 	vi 				vector<int>
#define     vll             vector<long long int>
#define     pii             pair<int, int>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	io   			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;

//fixed<<setprecision(9);
//max_element(mp.begin(), mp.end(), compare)
// __gcd(a, b);

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }

bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }

void solve()
{
    double r; cin>>r;
    cout<<fixed<<setprecision(9)<<2*pi*r<<nl;
}

int main()
{
    //io;
    int t = 1, k = 1;
    // cin>>t; 
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}


Measured memory_bytes: 3784
//###################################################################
//###     Copyright ????? 2017- Keita Sanno. All Rights Reserved.     ###
//###         This program is written only by Keita Sanno.        ###
//###                      - Nov 28, 2017 -                       ###
//###################################################################

#include <iostream>
#include <string>
#include <queue>
using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  queue<string> str;
  queue<int> t;
  for(int i = 0; i < n; i++){
    string name;
    int remain;
    cin >> name;
    cin >> remain;
    str.push(name);
    t.push(remain);
  }
  int sum = 0;
  while(!str.empty()){
    string name = str.front();
    str.pop();
    int remain = t.front();
    t.pop();
    if(remain > q){
      str.push(name);
      t.push(remain - q);
      sum += q;
    }
    else{
      sum += remain;
      cout << name << " " << sum << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 5736
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
char str[maxn];
int ans[maxn];
int n;
void solve()
{
    for(int i=2;i<n;i++)
    {
        if(ans[i]==1)
        {
            if(str[i]=='o')
            {
                ans[i+1]=ans[i-1];
            }
            else ans[i+1]=(ans[i-1]==1?2:1);
        }
        else {
            if(str[i]=='o')
            {
                ans[i+1]=(ans[i-1]==1?2:1);
            }
            else ans[i+1]=ans[i-1];
        }
    }
}
int check()
{
    int i;
    for(int i=1;i<=n;i++)
    {
        int l=i-1,r=i+1;
        if(l==0)l=n;
        if(r==n+1)r=1;
        if(ans[i]==1)
        {
            if(str[i]=='o'&&ans[l]!=ans[r])return 0;
            if(str[i]=='x'&&ans[l]==ans[r])return 0;

        }
        else
        {
            if(str[i]=='o'&&ans[l]==ans[r])return 0;
            if(str[i]=='x'&&ans[l]!=ans[r])return 0;
        }

    }
    return 1;
}
int main()
{
    scanf("%d",&n);
    scanf("%s",str+1);
    ans[1]=ans[2]=1;
    solve();
    if(check())
    {
        for(int i=1;i<=n;i++)
            printf("%c",ans[i]==1?'S':'W');
        printf("\n");
        return 0;
    }
    ans[1]=ans[2]=2;
    solve();
    if(check())
    {
        for(int i=1;i<=n;i++)
            printf("%c",ans[i]==1?'S':'W');
        printf("\n");
        return 0;
    }
    ans[1]=1;
    ans[2]=2;
    solve();
    if(check())
    {
        for(int i=1;i<=n;i++)
            printf("%c",ans[i]==1?'S':'W');
        printf("\n");
        return 0;
    }
    ans[1]=2;
    ans[2]=1;
    solve();
    if(check())
    {
        for(int i=1;i<=n;i++)
            printf("%c",ans[i]==1?'S':'W');
        printf("\n");
        return 0;
    }
    printf("-1\n");
    return 0;

}

Measured memory_bytes: 2816
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int t=1e4;
bool f[3][3][20000];
string s[3]; 
int l[3];
bool check(char a,char b){
	RE (a=='?'||b=='?'||a==b);
}
void solve(int a,int b){
	rep(i,0,l[a])
		rep(j,0,l[b])
			if(!check(s[a][i],s[b][j]))f[a][b][t+i-j]=1;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	rep(i,0,3){
		cin>>s[i];l[i]=s[i].size();
	}
	solve(0,1);solve(0,2);solve(1,2);
	int ans=l[0]+l[1]+l[2];
	FOR(i,-4000,4000)
		FOR(j,-4000,4000)
			if(!f[0][1][i+t]&&!f[0][2][j+t]&&!f[1][2][t+j-i])
				gmin(ans,max(l[0],max(l[1]+i,j+l[2]))-min(0,min(i,j)));
	cout<<ans;
	RE 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
int main() {
    cin >> n;
    ll nxt;
    ll ans = 0;
    for(ll i = 1; i <= n; i = nxt + 1) {
        nxt = n / (n / i) ;
        ll v = n / i;
        if(n % v == 0 && i + 1 <= n / v && n / v <= nxt + 1) {
            ans += n / v - 1;
        }
    }
    cout << ans;
    return 0;
}


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

int N,cost[10000];
int dp[5010][2];
const int INF=1e9;
int main(){
    scanf("%d",&N);
    for(int i=0;i<N-1;i++)scanf("%d",&cost[i]);

    fill_n(*dp,2*5010,INF);
    dp[1][0]=dp[0][1]=0;

    for(int i=0;i<N-1;i++){
        for(int j=min(i+1,N/2);j>=0;j--){
            dp[j+1][0]=min(dp[j][0],dp[j][1]+cost[i]);
            dp[j][1]=min(dp[j][0]+cost[i],dp[j][1]);
        }
    }

    printf("%d\n",min(dp[N/2][0],dp[N/2][1]));
    return 0;
}

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    ll n, a, b;
    cin >> n >> a >> b;

    ll ans = a*(n/(a+b));
    ans += (n%(a+b) >= a ? a: (n%(a+b))%(a));

    cout << ans << "\n";
    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


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

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

    printf("%.12f\n", (double)L * L * L / 27);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  
#include <cmath>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;
using P= pair<ll,ll>;
 
int main() {
    double D,T,S;
    cin>>D>>T>>S;
    
    if(D/S>T)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 3720
#!/usr/bin/env python3
from itertools import product


try:
    from typing import List
except ImportError:
    pass


def solve(N: int, F: "List[List[int]]", P: "List[List[int]]"):
    print(max(
        sum(
            Pi[sum(ptnj * Fij for ptnj, Fij in zip(ptn, Fi))]
            for Fi, Pi in zip(F, P)
        )
        for ptn in product((0, 1), repeat=10)
        if sum(ptn) != 0
    ))


def main():
    N = int(input())
    F = [
        [int(x) for x in input().split()]
        for _ in range(N)
    ]
    P = [
        [int(x) for x in input().split()]
        for _ in range(N)
    ]
    solve(N, F, P)


if __name__ == '__main__':
    main()


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

int main(){
  int N;
  string s;
  bool f = false;
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> s;
    if (s == "Y") {
      f = true;
    }
  }
  if (f) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
p = list(map(int,input().split()))

count = 0

for i in range(N-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        count += 1

i = N-1
if p[i] == i+1:
    p[i], p[i-1] = p[i-1], p[i]
    count += 1
        
print(count)

Measured memory_bytes: 13880
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>

using namespace std;

int main() {
	
	string s;
	vector<string> t;

	cin >> s;

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') {
			t.push_back("0");
		}
		else if (s[i] == '1') {
			t.push_back("1");
		}
		else if (s[i] == 'B') {
			if (t.empty()) { 
				continue; 
			}
			else {
				t.pop_back();
			}
		}
	}

	for (int i = 0; i < t.size(); i++) {
		cout << t.at(i);
	}
}



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

int main() {
    int N, M;
    cin >> N >> M;
    int a, b;
    vector<pair<int, int>> pairs(N);
    for(int i=0; i<N; i++){
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }

    sort(pairs.begin(), pairs.end());

    int cnt=0;
    long long cost=0;
    for(int i=0; i<N; i++){
        if(pairs[i].second < M){
            cost += (long long)pairs[i].first * pairs[i].second;
            M -= pairs[i].second;
        }
        else{
            cost += (long long)pairs[i].first * M;
            M = 0;
        }

        if(M==0){
            cout << cost << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)

using namespace std;
using ii = pair<int,int>;
using ll = long long;

const double PI = acos(-1.0);

pair<double,double> rot(const pair<double,double>& p, const double& ang) {
  return {p.first*cos(ang) - p.second*sin(ang), p.first*sin(ang) + p.second*cos(ang)};
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int a,b,h,m;
  cin >> a >> b >> h >> m;
  double angm = -double(m)*(2.0*PI/60.0);
  double angh = -double(h)*(2.0*PI/12.0) - (double(m)/60.0)*(2.0*PI/12.0);
  pair<double,double> p1 = rot({0,a}, angh), p2 = rot({0,b}, angm);
  double dx = p1.first - p2.first, dy = p1.second - p2.second;
  cout << fixed << setprecision(10) << sqrt(dx*dx+dy*dy) << '\n';
  return 0;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

const int NMAX = 2005;
const int MOD = (int) 1e9 + 7;

int dp[NMAX][NMAX];
int pow2[NMAX];

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;

    pow2[0] = 1;
    for (int i = 1; i <= n; ++i) {
        pow2[i] = 2 * pow2[i - 1] % MOD;
    }

    dp[n][0] = 1;
    dp[n][1] = -1;
    int ans = 0;
    for (int i = n; i >= 0; --i) {
        for (int j = 1; j <= i; ++j) {
            dp[i][j] += dp[i][j - 1];
            dp[i][j] %= MOD;
        }
        if (n - i == k || i == 1) {
            ans = (int64_t) dp[i][i - 1] * pow2[i - 1] % MOD;
            break;
        } else {
            for (int j = 0; j < i - 1; ++j) {
                dp[i - 1][j] += dp[i][j];
                dp[i - 1][j] %= MOD;
                dp[i - 1][i] -= dp[i][j];
                dp[i - 1][i] %= MOD;
            }
            for (int j = 1; j < i; ++j) {
                dp[i - 1][j - 1] += dp[i][j];
                dp[i - 1][j - 1] %= MOD;
                dp[i - 1][j] -= dp[i][j];
                dp[i - 1][j] %= MOD;
            }
        }
    }
    ans %= MOD;
    if (ans < 0) ans += MOD;
    cout << ans << '\n';
}


Measured memory_bytes: 14080
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ACprac
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] itmp = Console.ReadLine().Split(' ');
            int[] abc = new int[3];
            abc[0] = int.Parse(itmp[0]);
            abc[1] = int.Parse(itmp[1]);
            abc[2] = int.Parse(itmp[2]);

            int k = int.Parse(Console.ReadLine());

            for(int count = 0; count < k; count++)
            {
                int mNum = 0;
                int max = 0;

                for(int i = 0; i < 3; i++)
                {
                    if(abc[i] >= max)
                    {
                        max = abc[i];
                        mNum = i;
                    }
                }
                abc[mNum] = abc[mNum] * 2;
            }
            k = abc[0] + abc[1] + abc[2];
            Console.WriteLine(k);
        }
    }
}


Measured memory_bytes: 11092
def solv(S):
    for i in range(0, len(S)):
        if S[i] != '1':
            return i
    return -1


S = input()
K = int(input())
ans = solv(S)
if ans == -1:
    print(1)
elif ans + 1 > K:
    print(1)
else:
    print(S[ans])


Measured memory_bytes: 3060
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define FOR(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

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

	string c;
	cin >> c;

	if (c == "a" || c == "i" || c == "u" || c == "e" || c == "o") {
		cout << "vowel" << endl;
	} else {
		cout << "consonant" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "sstream"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const int N=1e5+1;
map<int,bool>ac; map<int,int>wa;
int main() {
    quick
    int n,m,solved=0,pe=0,x; string s; cin>>n>>m;
    while(m--){
        cin>>x>>s;
        if(s=="WA"){
            if(!ac[x]){wa[x]++;}
        }
        else if(s=="AC"){

            if(!ac[x]){
                solved++; pe+=wa[x] ;ac[x]=1;}

        }
    }
    cout<<solved<<" "<<pe;
}

Measured memory_bytes: 9600
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
h = LI()
dp = [float('INF')]*N
dp[0] = 0
for i in range(N):
    if i-1>=0:
        dp[i] = min(dp[i],dp[i-1]+abs(h[i]-h[i-1]))
    if i-2>=0:
        dp[i] = min(dp[i],dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Measured memory_bytes: 52208
n,m = map(int,input().split())
a = set([int(input()) for i in range(m)])

mod = 1000000007
result = [0]*(n+1)
result[0] = 1
for i in range(1,n+1):
    if i in a:
        result[i] = 0
    else:
        result[i] = (result[i-1] + result[i-2])%mod

print(result[n])

Measured memory_bytes: 56664
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

void solve() {
    int n;
    cin >> n;
    vll l(n);
    cin >> l;
    ll ans = 0;
    REP(i, n) {
        REP(j,n) {
            REP(k, n){
                if (i < j && j < k) {
                    if (l[i] != l[j] && l[j] != l[k] && l[i] != l[k]) {
                       if (l[i] < l[j] + l[k] && l[j] < l[i] + l[k] && l[k] < l[i] + l[j]) {
                           ++ans;
                       }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

int main() {
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    string s;
    map<char,int>mp;
    cin>>s;
    for(int i=0;i<s.length();i++)
        mp[s[i]]++;
    auto it=mp.begin(),it1=it++;
    cout<<((mp.size()==2 && it->second==it1->second)?"Yes" : "No")<<endl;
}



Measured memory_bytes: 256
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

const int GOAL = 1;
const int WAY = 0;
const int WALL = -1;

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

struct state {
	int l_x, l_y, r_x, r_y;
	state(int l_x, int l_y, int r_x, int r_y):l_x(l_x), l_y(l_y), r_x(r_x), r_y(r_y) {}
};

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

	for(int w, h; cin >> w >> h, w;) {
		vector<vector<int> > l_map(h + 2, vector<int>(w + 2, WALL));
		vector<vector<int> > r_map(h + 2, vector<int>(w + 2, WALL));

		int l_sx, l_sy, r_sx, r_sy;
		for(int i = 1; i <= h; ++i) {
			string l, r;
			cin >> l >> r;

			for(int j = 0; j < w; ++j) {
				switch(l[j]) {
				case '%':
					l_map[i][j + 1] = GOAL;
					break;
				case '#':
					l_map[i][j + 1] = WALL;
					break;
				case 'L':
					l_sx = j + 1;
					l_sy = i;
				default:
					l_map[i][j + 1] = WAY;
				}

				switch(r[j]) {
				case '%':
					r_map[i][j + 1] = GOAL;
					break;
				case '#':
					r_map[i][j + 1] = WALL;
					break;
				case 'R':
					r_sx = j + 1;
					r_sy = i;
				default:
					r_map[i][j + 1] = WAY;
				}
			}
		}

		stack<state> sta;
		sta.push(state(l_sx, l_sy, r_sx, r_sy));
		bool reachable = false;
		bool visited[52][52][52][52] = {};

		while(!sta.empty()) {
			const state& s = sta.top();
			int l_x = s.l_x, l_y = s.l_y, r_x = s.r_x, r_y = s.r_y;
			sta.pop();

			visited[l_x][l_y][r_x][r_y] = true;

			if(l_map[l_y][l_x] == GOAL && r_map[r_y][r_x] == GOAL) {
				reachable = true;
				break;
			}

			if(l_map[l_y][l_x] == GOAL || r_map[r_y][r_x] == GOAL)
				continue;

						
			for(int i = 0; i < 4; ++i) {
				int l_nx = l_x + dx[i], l_ny = l_y + dy[i], r_nx = r_x - dx[i], r_ny = r_y + dy[i];
				if(l_map[l_ny][l_nx] == WALL) {
					l_nx = l_x;
					l_ny = l_y;
				}
				
				if(r_map[r_ny][r_nx] == WALL) {
					r_nx = r_x;
					r_ny = r_y;
				}

				if(!visited[l_nx][l_ny][r_nx][r_ny])
					sta.push(state(l_nx, l_ny, r_nx, r_ny));
			}
		}

		cout << (reachable ? "Yes" : "No") << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 51780
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include<cstdlib>
#define FOR(i,a,b) for(i=a;i<=b;i++)

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long


int A, B;
const int n = 100;

int main()
{
	cout << 100 << ' ' << 100 << endl;
	cin >> A >> B;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i < 50) {
				if (i % 2 == 0 && j % 2 == 0 && i * 25 + j / 2 < (A - 1))
					cout << '.';
				else cout << '#';
			}
			else if (i < 60) cout << '.';
			else if (i % 2 == 0 && j % 2 == 0 && (i - 60) * 25 + j / 2 < (B - 1))
				cout << '#';
			else cout << '.';

		}
		cout << endl;
	}



    return 0;
}



Measured memory_bytes: 256
// 2015/07/03 Tazoe

#include <iostream>
using namespace std;

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

	int B;
	cin >> B;

	int C;
	cin >> C;

	int D;
	cin >> D;

	int P;
	cin >> P;

	int X = A*P;

	int Y = B;
	if(P>C){
		Y += D*(P-C);
	}

	if(X<=Y){
		cout << X << endl;
	}
	else{
		cout << Y << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define null nullptr
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

using namespace std;

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
typedef unordered_map<int,int> mp;

const int mod = 1e9+7;
const int inf = 1e18;


int32_t main(){
    FAST;
    
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
 	int n;	cin >> n;
 	int a[n], b[n] , c[n-1];
 	for(int x=0;x<n;x++)	cin >> a[x];
 	for(int x=0;x<n;x++)	cin >> b[x];
    for(int x=0;x<n-1;x++)	cin >> c[x];
    
    int ans = 0;

	for(int x=0;x<n-1;x++){
		int dish = a[x];
		ans += b[dish-1];
        b[dish-1] = 0;
		if(a[x+1] == dish+1) 
		ans += c[dish-1];
	}

	ans += accumulate(b,b+n,0LL);

	cout << ans;


    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

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

func powMod(x, y, mod int) int {
	if y == 0 {
		return 1
	}

	if y%2 == 0 {
		d := powMod(x, y/2, mod)
		return (d * d) % mod
	} else {
		return (x * powMod(x, y-1, mod)) % mod
	}
}

func calcComb(n, r, mod int) int {
	result := 1
	if r > n-r {
		r = n - r
	}
	for i := n; i > n-r; i-- {
		result *= i
		result %= mod
	}
	for i := 2; i <= r; i++ {
		result *= powMod(i, mod-2, mod)
		result %= mod
	}
	return result
}

func solve(n, k int) int {
	mod := 1000000000 + 7
	red := n - k
	for i := 1; i <= k; i++ {
		if red+1 < i {
			fmt.Println(0)
			continue
		}
		blueSplit := calcComb(k-1, i-1, mod)
		ans := calcComb(red+1, i, mod) * blueSplit
		ans %= mod
		fmt.Println(ans)
	}
	return 0
}

func main() {
	n, _ := strconv.Atoi(input())
	k, _ := strconv.Atoi(input())
	solve(n, k)
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <assert.h>
#include <time.h>
//#define _Test
typedef long long LL;
const int INF = 500000001;
const double EPS = 1e-9;
const double PI = acos(-1.0);
using namespace std;
int a[15], dir[4]={1, -1, -4, 4};
char ch[15];
map<string, int> mm;
struct p
{
    char s[15];
    int flag;
}fir, en;
queue<p> qq;
bool check(int x, int y)
{
    if(x < 0 || x >= 8)
    {
        return false;
    }
    if(x == 3 && y == 4 || x == 4 && y == 3)
    {
        return false;
    }
    return true;
}

void bfs()
{
    while(!qq.empty())
    {
        en = qq.front();
        qq.pop();
        for(int i = 0; i < 4; i++)
        {
            fir.flag = en.flag + dir[i];
            if(check(fir.flag, en.flag))
            {
                strcpy(fir.s, en.s);
                swap(fir.s[en.flag], fir.s[fir.flag]);
                if(mm.find(fir.s) == mm.end())
                {
                    mm[fir.s] = mm[en.s] + 1;
                    qq.push(fir);
                }
            }
        }
    }
}
int main()
{
    #ifdef _Test
        freopen("test0.in", "r", stdin);
        freopen("test0.out", "w", stdout);
        srand(time(NULL));
    #endif
    char c[100];
    while(~scanf("%d", &a[0]))
    {
        for(int i = 1; i < 8; i++)
        {
            scanf("%d", &a[i]);
        }
        for(int i = 0; i < 8; i++)
        {
            fir.s[i] = i + '0';
            c[i] = a[i] + '0';
        }
        c[8] = '\0';
        fir.flag = 0;
        fir.s[8] = '\0';
        mm[fir.s] = 1;
        qq.push(fir);
        bfs();

        printf("%d\n", mm[c] - 1);
    }
    return 0;
}

Measured memory_bytes: 3468
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void)
{
  int n, m;
  scanf("%d %d", &n, &m);

  int k, a;
  int food[31] = {0};
  rep(i, 0, n)
  {
    scanf("%d", &k);
    rep(j, 0, k)
    {
      scanf("%d", &a);
      food[a]++;
    }
  }
  int ans = 0;
  rep(i, 1, m + 1)
  {
    if (food[i] == n)
      ans++;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128