akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 100100;

PII A[MAX];

LL RES[MAX];

int main(int argc, char* argv[])
{
	//ios::sync_with_stdio(false); cin.tie(0);

	int h, w, n;
	scanf("%d%d%d", &h, &w, &n);

	set<PII> S;

	FOR (i, 0, n)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;

		S.insert(MP(x, y));
		A[i] = MP(x, y);
	}

	FOR (it, 0, n)
	{
		int x = A[it].first;
		int y = A[it].second;

		FOR (a, 0, 3)
		{
			FOR (b, 0, 3)
			{
				if (x - a < 0) continue;
				if (y - b < 0) continue;

				if (x + 2 - a >= h) continue;
				if (y + 2 - b >= w) continue;

				int cnt = 0;

				FOR (i, 0, 3)
				{
					FOR (j, 0, 3)
					{
						int x1 = x - a + i;
						int y1 = y - b + j;

						if (S.count(MP(x1, y1))) cnt++;
					}
				}

				RES[cnt]++;
			}
		}
	}

	LL tot = 0;

	FOR (i, 1, 10)
	{
		RES[i] /= i;
		tot += RES[i];
	}

	RES[0] = (h - 2) * (LL)(w - 2) - tot;

	FOR (i, 0, 10)
	{
		cout<<RES[i]<<endl;
	}



}


Measured memory_bytes: 5760
#include<iostream>

using namespace std;

int main() {
	int x, a, b;
	cin >> x >> a >> b;

	if (a >= b)
		cout << "delicious" << endl;
	else {
		if (x + a >= b)
			cout << "safe" << endl;
		else
			cout << "dangerous" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "5", "1 3 4 5 7" ].solve == 2 );
	assert( [ "15", "13 76 46 15 50 98 93 77 31 43 84 90 6 24 14" ].solve == 3 );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	
	auto ans = 0L;
	foreach( i, a; as )
	{
		ans += ( ( i + 1 ) % 2 == 1 && a % 2 == 1 );
	}
	return ans;
}


Measured memory_bytes: 2772
import Data.List (sort)
import Data.Char (toLower)
import Text.Printf (printf)

readIntLine :: IO ([Int])
readIntLine = do
    x <- getLine
    return $ map (read :: String -> Int) $ words x

main :: IO ()
main = do
    [n,k] <- readIntLine
    putStrLn $ printf "%.10f" $ prob n k

prob :: Int -> Int -> Double
prob n k =
    let comp = sum $ map (singleprob k) [1..n]
      in comp / (fromIntegral n)

singleprob :: Int -> Int -> Double
singleprob k l =
    if l >= k then 1.0
              else 0.5 * singleprob k (2*l)


Measured memory_bytes: 508
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int main(){
	long long int n, a[10], cnt = 0;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		if (a[i] % 2 == 0){
			cnt++;
		}
	}
	cout << pow(3, n) - pow(2, cnt) << endl;
	return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
n = len(S)
m = len(T)

ans = 'UNRESTORABLE'
for i in range(n - m + 1):
    for j in range(m):
        if T[j] == S[i + j] or S[i + j] == '?':
            continue
        else:
            break
    else:
        ans = S[0 : i] + T + S[i + m :]
        ans = ans.replace('?', 'a')

print(ans)

Measured memory_bytes: 3064
import sys #sys.exit()に使う。
from collections import deque

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

p = [str(input()) for _ in range(H)]

reached = [[float("inf")]*W for _ in range(H)]
dxdy = [(1,0),(-1,0),(0,1),(0,-1)]
reached[0][0] = 1
queue = deque([[0,0]])

while queue:
  x,y = queue.popleft()
  for i in range(4):
    nx = x + dxdy[i][0]
    ny = y + dxdy[i][1]
    if 0<=nx<H and 0<=ny<W and p[nx][ny] != "#" and reached[nx][ny] > H*W:
      queue.append([nx,ny])
      reached[nx][ny] = reached[x][y] + 1
    if nx == H-1 and ny == W-1:
      break

shiro = 0
for i in range(H):
  for j in range(W):
    if p[i][j] == ".":
      shiro += 1

ans = shiro - reached[H-1][W-1]
if ans >= 0:
  print(ans)
else:
  print("-1")

Measured memory_bytes: 3444
#include <stdio.h>

int main()
{
    int number;
    int a[100];
    
    scanf("%d", &number);
    for ( int i = 0; i < number; ++i ) {
        scanf("%d",&a[i]);
    }
    
    for ( int i = number - 1; i > 0; --i ) {
        printf("%d ", a[i]);
    }
    printf("%d\n", a[0]);
    
    return 0;
}


Measured memory_bytes: 2076
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int w[] = new int[n];
		int i, nSum=0, nMax=0;
		for(i=0; i<n; i++){
			w[i] = sc.nextInt();
			nSum+=w[i];
			if(nMax<w[i]){
				nMax=w[i];
			}
		}

		int kMin, kMinIni, kMinWok, kZan=k, nSumZan=nSum, kSho=0;
		kMinIni=nSum%k==0?nSum/k:nSum/k+1;
		if(kMinIni<nMax) kMinIni=nMax;
		kMin=kMinIni;
		while(true){
			for(i=0; i<n; i++){
				if(kMin>kSho+w[i]){
					kSho+=w[i];
				} else if(kMin==kSho+w[i]){
					if(kZan==1){
						for(i++; i<n; i++){
							kMin+=w[i];
						}
						break;
					}
					kZan--;
					nSumZan-=(kSho+w[i]);
					kSho=0;
				} else {
					if(kZan==1){
						kMin=kSho+w[i];
						for(i++; i<n; i++){
							kMin+=w[i];
						}
						break;
					}
					kMinWok=(nSumZan-kSho)%(kZan-1)==0?
						(nSumZan-kSho)/(kZan-1):
						(nSumZan-kSho)/(kZan-1)+1;
					if(kMinWok>=kSho+w[i]){
						kMin=kSho+w[i];
						kZan--;
						nSumZan-=(kSho+w[i]);
						kSho=0;
					} else{
						kZan--;
						nSumZan-=kSho;
						kSho=w[i];
					}
				}
			}
			if(kMinIni==kMin) break;
			kMinIni++;
			kMin=kMinIni;
			kZan=k;
			nSumZan=nSum;
			kSho=0;
		}
		System.out.println(kMin);
	}
}

Measured memory_bytes: 65248
#include <iostream>
using namespace std;
int main(void){
    int n,k;
    string s;
    cin>>s;
    n=k=s.length();
    for(int i=0;i<n-1;i++){
        if(s[i]!=s[i+1]){
            k=min(k, max(i+1, n-i-1));
        }
    }
    cout<<k<<endl;
}


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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

// ========================================================================= //

const int N = 100179;
string S = "AKIHABARA";

int main() {
    ios::sync_with_stdio(false);

    string t;
    cin >> t;
    int i = 0;
    for (char c : t) {
        while (i < sz(S) && S[i] != c) {
            if (S[i] != 'A') {
                cout << "NO\n";
                return 0;
            }
            ++i;
        }
        if (i == sz(S)) {
            cout << "NO\n";
            return 0;
        }
        ++i;
    }
    while (i < sz(S)) {
        if (S[i] != 'A') {
            cout << "NO\n";
            return 0;
        }
        ++i;
    }
    cout << "YES\n";

    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	s := nextMega()

	rank := 0
	sum := 0
	for i := 0; i < n; i++ {
		ok := false
		if s[i] == 'a' && sum < a+b {
			sum++
			ok = true
		} else if s[i] == 'b' {
			rank++
			if sum < a+b && rank <= b {
				sum++
				ok = true
			}
		}
		if ok {
			puts("Yes")
		} else {
			puts("No")
		}
	}
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


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

int main() {
    int n;
    long long max_v, min_v, sum_v;
    cin >> n;
    vector<long long> v(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    
    min_v = *min_element(v.begin(), v.end());
    max_v = *max_element(v.begin(), v.end());
    sum_v = accumulate(v.begin(), v.end(), 0LL);
    
    cout << min_v << " " << max_v << " " << sum_v << endl;
    return 0;
}


Measured memory_bytes: 3168
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T>
// using o_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define sfind(i) find_by_order(i)
// #define ord(i) order_of_key(i)
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
using cd = complex<double>;
const double pi = acos(-1);
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define vi vector<int>
#define vl vector<ll>
#define _max(vec) (*max_element(all(vec)))
#define _min(vec) (*min_element(all(vec)))
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'  //....????
#define int ll
vector<ll> ft(1, 1LL);


/*======================================================================*/
void solve(){
    int n;
    cin >> n;
    vi v(n);
    rep(i, 0, n)cin >> v[i];
    sort(all(v));
    int ans = v[n-1];
    int c = n-2, cur = n-2;
    while(c){
        ans += v[cur], c--;
        if(c > 0)ans += v[cur], cur--, c--;
    }
    cout << ans << endl;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> primes(100);
  for (int i = 1; i <= n; i++) {
    int k = i;
    for (int j = 2; j * j <= k; j++) {
      while (k % j == 0) {
        primes.at(j)++;
        k /= j;
      }
    }
    if (k > 1) primes.at(k)++;
  }
  int ans = 0;
  for (int i = 0; i < 100; i++) {
    for (int j = i + 1; j < 100; j++) {
      for (int k = j + 1; k < 100; k++) {
        if (primes.at(i) >= 4 && primes.at(j) >= 4 && primes.at(k) >= 2) ans++;
        if (primes.at(i) >= 4 && primes.at(j) >= 2 && primes.at(k) >= 4) ans++;
        if (primes.at(i) >= 2 && primes.at(j) >= 4 && primes.at(k) >= 4) ans++;
      }
      if (primes.at(i) >= 24 && primes.at(j) >= 2) ans++;
      if (primes.at(i) >= 14 && primes.at(j) >= 4) ans++;
      if (primes.at(i) >= 4 && primes.at(j) >= 14) ans++;
      if (primes.at(i) >= 2 && primes.at(j) >= 24) ans++;
    }
    if (primes.at(i) >= 74) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cctype>
#include<vector>
using namespace std;
#define fr first
#define sc second
typedef pair<int,int> P;
int main(){
  string scan;
  vector<vector<int> > mas;
  int dp[128][128];
  while(getline(cin,scan)){
    vector< int >  v;
    for(int i = 0 , t = 0 ; i < scan.size() ; i++ ){
      if(isdigit(scan[i])) t = t * 10 + scan[i] - '0';
      if(scan[i] == ',' || i == scan.size() - 1){
        v.push_back(t);
        t = 0;
      }
    }
    mas.push_back(v);
  }
  dp[0][0] = mas[0][0];
  int center = mas.size() / 2;
  for(int i = 1 ; i < mas.size() ; i++){
    for(int j = 0 ; j < mas[i].size() ; j++){
      if( i <= center ) dp[i][j] = max(dp[i-1][j],dp[i-1][j-1]);
      else dp[i][j] = max(dp[i-1][j],dp[i-1][j+1]);
      dp[i][j] += mas[i][j];
    }
  }
  cout << dp[mas.size()-1][mas[mas.size()-1].size()-1] << endl;
}

Measured memory_bytes: 1276
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;


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

    int n, x;
    cin >> n >> x;
    int sum = 0;
    vector<int> nums(n);
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
    }

    sort(nums.begin(), nums.end());
    for (int i = 0; i < n; ++i) {
        sum += nums[i];
        if (sum > x) {
            cout << i << endl;
            return 0;
        } else if (sum == x) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << n - 1 << endl;
    return 0;
}

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

const int MAX = 1000000;
const int MOD = 1e9+7;

long mpow(long x, long n){
    long ans = 1;
    while(n != 0){
        if(n%2==1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n/2;
    }
    return ans;
}

long mfact(long n){
  long ans = 1;
  for(long i=2; i<=n; i++){
    ans = ans*i % MOD;
  }
  return ans;
}

long mcomb(long n, long m){ //aCbをmod計算
    if(n == 0 && m == 0) return 1;
    if(n < m || n < 0) return 0;
    long ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}


int main(){
    int x , y;
    cin >> x >> y;

    if((x + y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }

    int n = (2 * y - x) / 3;
    int m = y - 2 * n;

    if(n < 0 || m < 0){
        cout << 0 << endl;
        return 0;
    }


    cout << mcomb(n + m,n) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
const ll MAX = 2*(ll)pow(10, 5);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n, l;
  cin >> n >> l;
  ll sum = 0;
  rep(i, n) sum += l+i;
  ll min = INF, res;
  rep(i, n) {
    if (abs(sum-(sum-(l+i))) < min) {
      min = abs(sum-(sum-(l+i)));
      res = sum-(l+i);
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <unistd.h>
#include <sstream>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846
#define pb push_back

void solve()
{
    int x;cin>>x;
    cout<<1-x;
}

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

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ll long long int
#define forr(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
#define oo 2000000000000000000LL
using namespace std;

ll n,k;
ll p[5500] , c[5500];

ll get(ll i){
    ll next = p[i] , sum=0LL , cycle_cnt = 0;
    i = next ;
    while(1){
        sum +=c[next];
        next = p[next];
        cycle_cnt++;
        if(next==i) break;
    }
    ll ans = -oo, cnt = 0 , path=0;
    while(1){
        cnt++;
        path += c[next];
        if( cnt > k ) break;
        else{
            ans = max(ans , path);
            ll tot = ( k - cnt )/cycle_cnt;
            tot = path + max(0LL , sum)*tot;
            ans = max(ans , tot);
        }
        next = p[next];
        if(next == i) break;
    }
    return ans;
}

void _sol(){
    cin >> n >> k;
    forr(i,n) cin >> p[i] , p[i]--;
    forr(i,n) cin >> c[i];
    ll ans = -oo;
    for(ll i=0LL;i<n;i++){
        ans = max(ans , get(i));
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    _sol();
}


Measured memory_bytes: 3708
#include <iostream>
#include <algorithm>
#include <complex>

int main()
{
    int k, x;
    std::cin >> k >> x;

    for (int i = -1000000; i <= 1000000; ++i)
    {
        if (abs(x - i) < k)
            std::cout << i << " ";
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,m,h[100001],a,b,c[100001]={0},i,x=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++){
		scanf("%d",&h[i]);
	}
	for(i=1;i<=m;i++){
		scanf("%d%d",&a,&b);
		if(h[a]>h[b]) c[b]=1;
		if(h[a]<h[b]) c[a]=1;
		if(h[a]==h[b]){
			c[a]=1;
			c[b]=1;
		}
	}
	for(i=1;i<=n;i++){
		if(c[i]==0) x++;
	}
	printf("%d\n",x);
	return 0;
}


Measured memory_bytes: 2512
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  int init_hp,max_hp;
  while(cin>>init_hp>>max_hp,init_hp|max_hp){
    int r,c;
    cin>>r>>c;
    vs a(r);
    REP(i,r){
      cin>>a[i];
    }

    int t;
    cin>>t;
    map<char,int> d;
    REP(i,t){
      char c;
      int dd;
      cin>>c>>dd;
      d[c]=dd;
    }
    int s;
    cin>>s;
    int cy=0,cx=0;
    vi damages;
    REP(i,s){
      char dd;
      int n;
      cin>>dd>>n;
      int dy=0,dx=0;
      switch(dd){
        case 'U':
          dy=-1;break;
        case 'D':
          dy=1;break;
        case 'L':
          dx=-1;break;
        case 'R':
          dx=1;break;
      }
      REP(j,n){
        cy+=dy;
        cx+=dx;
        damages.push_back(d[a[cy][cx]]);
      }
    }

    int P;
    cin>>P;
    vi p(P);
    REP(i,P){
      cin>>p[i];
    }

    vi cured(1<<P);
    REP(i,1<<P){
      REP(j,P){
        if((i>>j)&1){
          cured[i]+=p[j];
        }
      }
    }

    int n=damages.size();
    vvi dp(n+1,vi(1<<P));
    dp[0][0]=init_hp;
    REP(i,n){
      REP(j,1<<P){
        if(dp[i][j]>0){
          if(dp[i][j]<=damages[i]){
            REP(k,1<<P){
              bool ok=true;
              if(j&k){
                ok=false;
              }
              if(ok){
                dp[i+1][j|k]=max(dp[i+1][j|k],min(max_hp,dp[i][j]+cured[k])-damages[i]);
              }
            }
          }else{
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]-damages[i]);
          }
        }
      }
    }
    /*
    REP(i,n+1){
      REP(j,1<<P){
        cerr<<i<<" "<<j<<" "<<dp[i][j]<<endl;
      }
    }
    */
    bool ok=false;
    REP(j,1<<P){
      if(dp[n][j]>0){
        ok=true;
      }
    }
    cout<<(ok?"YES":"NO")<<endl;
  }

}

Measured memory_bytes: 17188
#include <iostream>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
using ll=long long;
int main(){
  int n, m;
  cin >> n >> m;
  priority_queue<ll> que;
  for(int i=0; i<n; i++){
    ll l;
    cin >> l;
    que.push(l);
  }
  while(m>0){
    ll a=que.top();
    que.pop();
    if(a==0) break;
    a/=2;
    que.push(a);
    m--;
  }
  ll ans=0;
  for(int i=0; i<n; i++){
    ans+=que.top();
    que.pop();
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 1400
def d_MaximumAverageSets(N, A, B, V):
    # パスカルの三角形でコンビネーション計算
    C = [[0] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        for j in range(i + 1):
            if j == 0 or j == i:
                C[i][j] = 1
            else:
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j]

    # 平均値の最大値を計算
    import decimal
    v = sorted(V, reverse=True)
    max_ave = decimal.Decimal(sum(v[:A]) / A)

    count = 0
    if v[0] != v[A - 1]:
        X = Y = 0
        for i in range(N):
            if v[A - 1] == v[i]:
                X += 1
                if i < A:
                    Y += 1
        count = C[X][Y]
    else:
        X = 0
        for i in range(N):
            if v[0] == v[i]:
                X += 1
        for i in range(A, B + 1):
            count += C[X][i]
    ans = '{}\n{}'.format(max_ave, count)
    return ans

N,A,B = [int(i) for i in input().split()]
V = [int(i) for i in input().split()]
print(d_MaximumAverageSets(N, A, B, V))

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

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

int main(){
    int x;
    cin>>x;
    if(x==3 || x==5 || x==7) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	cout<<min(string(a,'0'+b),string(b,'0'+a))<<"\n";
	return 0;
}


Measured memory_bytes: 3624
let () = Scanf.scanf "%d\n" @@ fun n ->
  let xs = Array.make n 0 in
  let ys = Array.make n 0 in
  for i = 0 to n - 1 do
    Scanf.scanf "%d %d\n" @@ fun x y ->
      xs.(i) <- x + y;
      ys.(i) <- x - y;
  done;
  Array.sort compare xs;
  Array.sort compare ys;
  Printf.printf "%d\n" @@ max (xs.(n - 1) - xs.(0)) (ys.(n - 1) - ys.(0))

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

int main() {
  int n;
  cin >> n;
  vector<int>a;
  bool f = false;
  a.push_back(n);
  for (int i = 0; i < 1000000; i++) {
    if (n % 2 == 0) n = n / 2;
    else n = n * 3 + 1;
    a.push_back(n);
    for (int j = 0; j < (a.size() - 1); j++) {
      if (n == a[j]) {
        cout << a.size() << endl;
        f = true;
        break;
      }
    }
    if (f) break;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int m = sc.nextInt();
    boolean[][] b = new boolean[m][n];
    int[] p = new int[m];
    int ans = 0;

    for(int i = 0; i < m; i++){
      int k = sc.nextInt();
      for(int j = 0; j < k; j++){
        int s = sc.nextInt();
        b[i][s - 1] = true;
      }
    }

    for(int i = 0; i < m; i++){
      p[i] = sc.nextInt();
    }

    for(int i = 0; i < (1 << n); i++){
      int tmp2 = 0;
      for(int l = 0; l < m; l++){
        int tmp = 0;
        for(int j = 0; j < n; j++){
          if(((1 & i >> j) == 1) && (b[l][j] == true)){
            tmp += 1;
          }
        }
        if(tmp % 2 == p[l]){
          tmp2 += 1;
        }
      }
      if(tmp2 == m){
        ans += 1;
      }
    }

    System.out.println(ans);
  }
}


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

void solve(long long A, long long B)
{
    if (2 * max(A, B) <= 16)
    {
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


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

using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

int solve(int sx, string &S, string &T, int W, int dir) {

    int p = sx;
    int N = S.size();

    // left
    p = sx;
    for (int i = 0; i < N; i++) {
        if (dir == 0) {
            if (S[i] == 'L') p--;
            if (p < 0) return 0;
            if (p + 1 < W && T[i] == 'R') p++;
        } else {
            if (S[i] == 'U') p--;
            if (p < 0) return 0;
            if (p + 1 < W && T[i] == 'D') p++;
        }
    }

    // right
    p = sx;
    for (int i = 0; i < N; i++) {
        if (dir == 0) {
            if (S[i] == 'R') p++;
            if (p >= W) return 0;
            if (p - 1 >= 0 && T[i] == 'L') p--;
        } else {
            if (S[i] == 'D') p++;
            if (p >= W) return 0;
            if (p - 1 >= 0 && T[i] == 'U') p--;
        }
    }

    return 1;
}

void solve() {
    int H, W, N;
    cin >> H >> W >> N;
    int sy, sx;
    cin >> sy >> sx;
    sy--, sx--;
    string S, T;
    cin >> S >> T;
    int r1 = solve(sx, S, T, W, 0);
    int r2 = solve(sy, S, T, H, 1);

    if (r1 && r2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 920
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int a = sc.nextInt();
        int ans = h / a + (h % a == 0 ? 0 : 1);
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 0;
int l, a[20] = {2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3};
vi v[20];
vector<pair<int, pii> > ans;
void pri(int i, int j, int k){
  ans.pb(mp(i, mp(j, k)));
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> l;
  int b = 1, L = l, d = l;
  FOR(i, 1, 20){
    FOR(j, 0, L%a[i]){
      pri(i, 20, d-b);
      d -= b;
    }
    L /= a[i];
    if(L < 1) break;
    FOR(j, 0, a[i]) pri(i, i+1, j*b);
    b *= a[i];
  }
  cout << 20 << " " << sz(ans) << endl;
  FOR(i, 0, sz(ans)) cout << ans[i].fi << " " << ans[i].se.fi << " " << ans[i].se.se << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int x, y, c, max, min;
  int a, b, r1,r2;
  int result;

  while(scanf("%d%d",&x,&y)!=EOF){
    if(x>y){
      max=x;
      min=y;
    }
    else{
      max=y;
      min=x;
    }
    a=max;
    b=min;
    while(1){
      //      printf("s: a=%d b=%d r1=%d r2=%d\n",a,b,r1,r2);
      r1=a/b;
      r2=a%b;
      if(r2==0){
	result=b;
	break;
      }
      //      printf("g: a=%d b=%d r1=%d r2=%d\n",a,b,r1,r2);
      a=b;
      b=r2;
    }
    printf("%d %d\n",result,max/result*min);
  }
  return(0);
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
using namespace std;

#define MAX 100009
#define NIL -1

int main() {
	char st[52];
	cin >> st;
	for (int i = 0; i < strlen(st) - 8; i++) {
		printf("%c", st[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}



int main() {

  long n;

  cin >> n;

  vector<long> a(n);

  for(int i=0;i<n;i++){
    cin >> a[i];
    // cerr <<a[i] <<endl;
  }
  cerr << endl;


  long ans =0;

  sort(a.begin(),a.end(),greater<long>());


  vector<bool> b(n,false);


  vector<long> c(n);

  vector<long> d(n,0);

  for(int i=0;i<n;i++){
    int k=1;
    for(k=1;k<=a[i];k*=2){
      d[i]++;
    }
    c[i] = k-a[i];
    cerr << c[i]<<endl;
  }


  cerr <<endl;


  long j = n-1;
  long nowd = -1;
  for(int i=0;i<n;i++){
    cerr << endl << " a[i] : " << a[i] << "c[i]  " << c[i] << " d[i] " << d[i]<< endl;
    if (nowd != d[i]){
      nowd = d[i];
      j=n-1;
    }


    if (b[i] ==true)continue;



    for(;j>i;j--){
      cerr << " :: " << a[j] << ":";
      if (b[j]==true)continue;
      if (c[i] < a[j])break;

      // if (c[i] == a[j]){
      //   ans++;
      //   b[i] =true;
      //   b[j] =true;
      //   break;
      // }


      long pairnum = a[i] + a[j];
      if (  !(pairnum & (pairnum-1) )){//べき乗
        cerr << "  find  " << a[j] <<endl;;
        ans++;
        b[i] =true;
        b[j] =true;
        break;
      } 




    }




  }





// for(int i=0;i<n-1;i++){
//     if (b[i] ==true)continue;
//     for(int j=i+1;j<n;j++){
//       if (b[j]==true)continue;


 
//       long pairnum = a[i] + a[j];
//       if (  !(pairnum & (pairnum-1) )){//べき乗
//         ans++;
//         b[i] =true;
//         b[j] =true;
//         break;
//       } 
 
//     }
 
 
//   }



    // for(int j=n-1;j>0;j--){
    //   if (b[j]==true)continue;













  cout << ans << endl;
  // cout << "w:" << w << "  h:" << h << endl;


}




















Measured memory_bytes: 5504
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.math.BigDecimal;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            int mod = 1000000007;
            long NF = 1;
            long MF = 1;
            for(int i=1; i<=N; i++){
                NF = (NF*i)%mod;
            }
            for(int i=1; i<=M; i++){
                MF = (MF*i)%mod;
            }
            long res = 1;
            if(N==M){
                res = (NF*MF*2)%mod;
            }
            else if(N==M+1||M==N+1){
                res = (NF*MF)%mod;
            }
            else res=0;
            out.println(res);
        }
    }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 21588
#include <stdio.h>


int main(void){
  int N, i;
  scanf("%d", &N);
  int A[N];
  for(i=0 ; i<N ; i++)
    scanf("%d", &A[i]);

  int max = 0, max_n;
  for(i=0 ; i<N ; i++){
    if(max < A[i]){
      max = A[i];
      A[i] = -1;
      max_n = i;
    }
  }

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


  for(i=0 ; i<N ; i++){
    if(i != max_n)
      printf("%d\n", max);
    else
      printf("%d\n", max2);
  }

  return 0;
}


Measured memory_bytes: 2304
def prList(A):
    n = len(A)
    for i in range(n):
        if i:
            print(" ", end="")
        print(A[i], end="")
    print("")


def insertSort(A):
    n = len(A)
    for i in range(1, n):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        prList(A)


n = int(input())
A = [int(i) for i in input().split()]
prList(A)
insertSort(A)



Measured memory_bytes: 6320
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
#define ll long long int
#define pair <ll, ll> pi
#define vector <ll> vi
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define SQ(a) (a) * (a)
#define ordered_set tree<ll, null_type, greater_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> //greater_equal<ll> or less<ll>
// find_by_key()   order_of_key()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/*bool comp(string a, string b) {
if (a.size() != b.size()) return a.size() < b.size();
return a < b;
}*/

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen('input.txt', 'r', stdin);
    //freopen('output.txt', 'w', stdout);
    ll i, j, k, n, m, b, d, t, ans = 0,x,y;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++){
        cin>>k;
        a[i]=k;
        ans^=k;
    }
    for(i=0;i<n;i++){
        cout<<(ans^a[i])<<" ";
    }
    return 0;
}

Measured memory_bytes: 5076
#include<stdio.h>
int main(void){
    int i,j,input;
    int x[20000];
    for(i=0;i<20000;i++){
        x[i]=0;
    }
    x[1]=1;
    for(i=2;i<10000;i++){
        for(j=i*i;j<10000;j*=i){
            x[j]=1;
        }
    }
    scanf("%d",&input);
    for(i=input;i!=0;i--){
        if(x[i]==1){
            printf("%d\n",i);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
loop do
  a, op, b = gets.split
  a = a.to_i
  b = b.to_i

  break if op == "?"

  case op
  when "+"
    puts a+b
  when "-"
    puts a-b
  when "*"
    puts a*b
  when "/"
    puts a/b
  end
end

Measured memory_bytes: 8624
//saw
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,i;
  cin>>N;
  int X[N],sorted[N];
  for(i=0;i<N;i++){
    cin>>sorted[i];
    X[i]=sorted[i];
  }
  sort(sorted,sorted+N);
  int under=sorted[N/2-1],above=sorted[N/2];
  for(i=0;i<N;i++){
    if(X[i]<above) cout<<above<<endl;
    else cout<<under<<endl;
  }
  return 0 ;
}


Measured memory_bytes: 3840
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
    ll a,b,x;
    cin >> a >> b >> x;
    ll a_x = a/x;
    ll b_x = b/x;
    ll ans = b_x - a_x;
    if(a%x == 0){
        ans ++;

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

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

//#define int long long

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

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

    int r = 0, b = 0;
    rep(i, n) {
        if (s[i] == 'R') {
            r++;
        } else {
            b++;
        }
    }
    if (r > b) {
        printf("Yes");
    } else {
        printf("No");
    }

    /* --------------------------------- */
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = NextInt()
        Dim S As String = ReadLine()

        Dim ans As Integer

        For i As Integer = 1 To N
            Dim X As String = Mid(S, 1, i)
            Dim Y As String = Mid(S, i + 1)
            Dim cnt As Integer = 0
            For j As Integer = Asc("a") To Asc("z")
                Dim c As Char = Chr(j)
                If X.Contains(c) AndAlso Y.Contains(c) Then cnt += 1
            Next
            ans = Math.Max(ans, cnt)
        Next

        WriteLine(ans)
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


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

using namespace std;

namespace {
    int H, W, A;
    vector<string> F;
    void input() {
        cin >> H >> W >> A;
        F.clear(); F.resize(H);
        for (int i = 0; i < H; i++) {
            cin >> F[i];
        }
    }

    struct S {
        int p, q, y, x, dir;
        S(int p, int q, int y, int x, int dir) : p(p), q(q), y(y), x(x), dir(dir) {}
    };

    void find_pos(int& y, int &x, char c) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (F[i][j] == c) {
                    y = i;
                    x = j;
                    return;
                }
            }
        }
        assert(0);
    }

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

    const int INF = 1<<28;

    bool valid_pos(int y, int x) {
        if (y < 0 || y >= H) return false;
        if (x < 0 || x >= W) return false;
        if (F[y][x] == '#') return false;
        return true;
    }

    void solve() {
        int sy, sx; find_pos(sy, sx, 'S');
        static bool D[11][11][101][101][4];
        memset(D, 0, sizeof(D));
        queue<S> Q;
        Q.push(S(0, 0, sy, sx, 2));
        while (!Q.empty()) {
            S c = Q.front(); Q.pop();
            const int y = c.y;
            const int x = c.x;
            if (F[y][x] == 'S' && c.dir == 0) continue;
            for (int i = -1; i <= 1; i++) {
                int np, nq;
                if (c.dir % 2 == 0) {
                    np = c.p + (i < 0); nq = c.q + (i > 0);
                } else {
                    np = c.p + (i > 0); nq = c.q + (i < 0);
                }
                int ny = y + dy[c.dir]; 
                int nx = x + dx[c.dir];
                int ndir = (c.dir + i + 4) % 4;
                if (np > A || nq > A) continue;
                if (valid_pos(ny, nx)) {
                    bool& next = D[np][nq][ny][nx][ndir];
                    if (!next) {
                        next = true;
                        Q.push(S(np, nq, ny, nx, ndir));
                    }
                }
            }
        }

        int gy, gx;
        find_pos(gy, gx, 'G');
        int ans = INF;
        for (int i = 0; i <= A; i++) {
            for (int j = 0; j <= A; j++) {
                for (int k = 0; k < 4; k++) {
                    if (D[i][j][gy][gx][k]) {
                        ans = min(ans, i + j);
                    }
                }
            }
        }
        cout << (ans == INF ? -1: ans) << endl;
    }
}

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

Measured memory_bytes: 6196
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let Sa: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };
    let Sb: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };
    let Sc: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };

    let mut A = Sa.clone();
    A.reverse();
    let mut B = Sb.clone();
    B.reverse();
    let mut C = Sc.clone();
    C.reverse();
    let mut S = vec![A, B, C];
    let mut i = 0;
    while let Some(c) = S[i].pop() {
        i = match c {
            'a' => 0,
            'b' => 1,
            _ => 2
        };
    }

    let ans = if i == 0 { "A" } else if i == 1 { "B" } else { "C" };

    println!("{}", ans);
}

Measured memory_bytes: 4352
using System;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] temp = Console.ReadLine().Split(' ');
            int w = int.Parse(temp[0]);
            int h = int.Parse(temp[1]);
            int x = int.Parse(temp[2]);
            int y = int.Parse(temp[3]);
            int r = int.Parse(temp[4]);

            if (x + r <= w && x + r >= 0 && x - r <= w && x - r >= 0 && y + r <= h && y + r >= 0 && y - r <= h && y - r >= 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            Console.ReadKey();

        }
    }
}



Measured memory_bytes: 17928
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	
	long max = 1000_000_000_000_000_000L;

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		long[] longArr = fs.nextLongArr(n);
		
		Arrays.sort(longArr);
		if(longArr[0] == 0) {
			System.out.println(0);
			return;
		}
		
		long now = longArr[0];
		long limit;
		if(now == 1) {
			limit = max / now;
		}else {
			limit = max / now;
		}
		
		for(int i = 1; i < longArr.length; i++) {
			if(limit < longArr[i]) {
				System.out.println(-1);
				return;
			}
			now *= longArr[i];
			limit = max / now;
		}
		
		System.out.println(now);
		
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


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

#define ll long long
int main() {
  ll N, D;
  cin >> N >> D;
  
  int ans = 0;
  for (int i = 0; i < N; i++){
    ll x, y;
    cin >> x >> y;
    
    if (x * x + y * y <= D* D) ans++;
    
  }
  cout << ans << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	int n;cin>>n;
	vector<long double> A(n);
	for(int i=0;i<n;i++)
	{
	    cin>>A[i];
	}
	vector<vector<long double>> dp(n+1,vector<long double>(n+1));
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
	    for(int j=0;j<=i;j++)
	    {
	        if(j==0)
	        {
	            dp[i][j]=dp[i-1][j]*(1-A[i-1]);
	        }
	        else
	        {
	            dp[i][j]=(dp[i-1][j]*(1-A[i-1]))+(dp[i-1][j-1]*(A[i-1]));
	        }
	    }
	}
	long double sol=0;
	for(int i=(n+1)/2;i<=n;i++)
	{
	    sol+=dp[n][i];
	}
	cout<<fixed<<setprecision(10)<<sol;
}

Measured memory_bytes: 141056