akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
	char c[101],m[7]={'I','V','X','L','C','D','M'};
	int s,i,j,h,n[7]={1,5,10,50,100,500,1000};
  while(gets(c)!=NULL) {
    s=0; h=10;
	for (i=0;i<strlen(c);i++) {
     for (j=0;j<7;j++) if (c[i]==m[j]) break;
	 s+=n[j];
	 if (h<j) s-=n[h]*2;
	 h=j;
	}
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 1124
def read_ints():
    return [int(c) for c in input().split()]


def main():
    n = int(input())
    xs = read_ints()
    accs = []
    prev = -1
    cur = 0
    for x in xs:
        if x != prev:
            accs.append(cur)
            cur = 0
        cur += 1
        prev = x
    accs.append(cur)

    ans = sum(acc // 2 for acc in accs)
    print(ans)
    return


if __name__ == '__main__':
    main()

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

using namespace std;
vector<int > vec,bol;

int main() {
    int n;
    cin>>n;
    vec.resize(n);
    bol.resize(n);
    for(int i=0;i<n;i++){
        cin>>vec[i];
        if(i&&vec[i]<=vec[i-1])bol[i-1]=1;
    }
    int an=0;
    for(int i=0;i<n;i++){
        int j=i,tr=0;
        while(j<n&&bol[j])j++,tr++;
        an=max(an,tr);
        i=j;
    }
    cout<<an<<endl;
    return 0;
}

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

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

  if (s.size() % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }

  for (int i = 0; i < s.size(); i += 2) {
    if (s[i] != 'h' || s[i + 1] != 'i') {
      cout << "No" << endl;
      return 0;
    }
  }

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


Measured memory_bytes: 256
import java.util.*;

public class  Main{
    static Scanner s = new Scanner(System.in);

    public static void main(String[] args){
        int n = s.nextInt(), x = s.nextInt(), t = s.nextInt();
        int count = 0;
        count = n / x * t;
        if (n % x > 0)
            count += t;

        System.out.println(count);
    }
}


Measured memory_bytes: 35680
// AOJ 2137 Time Trial
// 2019.4.4 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned char uchar;
typedef struct { uchar pos[7]; int step; } Q;
Q que[1200000]; int top, end;
char encode[128];

char map[18][18]; int H, W;
int mv[4][2] = { {-1,0}, {0,1}, {1,0}, {0,-1} };

// 数値のハッシュ関数
#define HASHSIZ 2000081
unsigned hash[HASHSIZ + 5], *hashend = hash + HASHSIZ;

int insert(uchar *pos)
{
	int i;
	unsigned x, *p;

	x = 0; for (i = 0; i < 4; i++) x = (x << 8) | pos[i];
	p = hash + (int)(x % HASHSIZ);
	while (*p) {
		if (*p == x) return 0;
		if (++p == hashend) p = hash;
	}
	*p = x;
	return 1;
}

void sort(uchar *p)
{
	uchar t;
	if (p[0] > p[1]) t = p[0], p[0] = p[1], p[1] = t;
	if (p[1] > p[2]) {
		t = p[1], p[1] = p[2], p[2] = t;
		if (p[0] > p[1]) t = p[0], p[0] = p[1], p[1] = t;
	}
}

int bfs(uchar *goal, uchar *init)
{
	int i, r, c, nr, nc, ic, step;
	uchar pos[4], npos[4], np;

	sort(goal), sort(init + 1);
	top = 0, end = 1;
	memcpy(que[0].pos, init, 4), que[0].step = 0;
	while (top != end) {
		memcpy(pos, que[top].pos, 4), step = que[top].step, top++;

		if (goal[0] == pos[1] && goal[1] == pos[2] && goal[2] == pos[3]) return step;

		if (!insert(pos)) continue;   // 同一状態がすでにあった

		r = pos[0] >> 4, c = pos[0] & 0xf;
		for (i = 0; i < 4; i++) {
			memcpy(npos, pos, 4);
			nr = r + mv[i][0], nc = c + mv[i][1], np = (nr << 4) | nc;
			if (map[nr][nc] == '#') continue;
			for (ic = 1; ic < 4; ic++) if (pos[ic] == np) break;
			if (ic < 4) {  // 移動先がRock
				uchar cr = nr + mv[i][0], cc = nc + mv[i][1], cp = (cr << 4) | cc;
				if (map[cr][cc] == '#') continue;    // コンテナの先が壁か別のコンテナ？
				if (pos[1] == cp || pos[2] == cp || pos[3] == cp) continue;
				npos[ic] = cp;
			}
			npos[0] = np, que[end].step = step + 1;
			sort(npos + 1);
			memcpy(que[end++].pos, npos, 4);
		}
	}
	return -1;
}

int main()
{
	int k, r, c, nc, np;
	uchar goal[3], pos[4], p;

	memset(encode, -1, sizeof(encode));
	encode['@'] = 0, encode['*'] = 1, encode['_'] = 4;
	while (scanf("%d%d", &W, &H) && W) {
		memset(hash, 0, sizeof(hash));
		np = nc = 0;
		for (r = 0; r < H; r++) {
			scanf("%s", map[r]);
			for (c = 0; c < W; c++) {
				if ((k = encode[map[r][c]]) < 0) continue;
				p = (r << 4) | c;
				if (k == 0) pos[k] = p;              // Hero 
				else if (k < 4) pos[k + np++] = p;   // Rock
				else goal[nc++] = p;                 // Marked Square
				map[r][c] = '.';
			}
		}
		printf("%d\n", bfs(goal, pos));
	}
	return 0;
}


Measured memory_bytes: 22468
from fractions import gcd

N = int(input())
a_list = [int(x) for x in input().split()]
L = [0]
R = [0]

for i in range(1, N):
    L.append(gcd(L[i-1], a_list[i-1]))
    R.append(gcd(R[i-1], a_list[N-i]))
R.reverse()
ans = 0
for i in range(N):
    ans = max(gcd(L[i], R[i]), ans)
print(ans)

Measured memory_bytes: 16120
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int h, w;
char board[120][120];
int cluster[120][120];

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

void dps(int x, int y, int b, int n){
  if(x < 0  || y < 0 ) return;
  if(x >= w || y >= h) return;
  if(cluster[y][x] == 0 && board[y][x] == b){
    cluster[y][x] = n;
    REP(i,4) dps(x+dx[i], y+dy[i], b, n);
  }
}

int main(){
  while(scanf("%d%d ",&h,&w), h+w){
    int cnt = 0;
    REP(i,h) fgets(board[i], sizeof(board[i]), stdin);
    memset(cluster,0,sizeof(cluster));
    REP(i,h) REP(j,w)
      if(cluster[i][j] == 0)
        dps(j, i, board[i][j], ++cnt);
    cout << cnt << endl;
  }
  return 0;
}

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

typedef vector<int> vi;

vi dp1,dp2;

int sum1(int l, int r) { return r<l? 0 : dp1[r+1]-dp1[l]; }
int sum2(int l, int r) { return r<l? 0 : dp2[r+1]-dp2[l]; }

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    string s;
    while(cin >> n)
    {
        cin >> s;
        dp1 = vi(n+1,0); dp2 = vi(n+1,0);
        for(int i = 0; i < n; i++)
        {
            dp1[i+1] = dp1[i] + (s[i] == 'E');
            dp2[i+1] = dp2[i] + (s[i] == 'W');
        }

        int ans = n;
        for(int i = 0; i < n; i++)
            ans = min(ans, sum2(0,i-1) + sum1(i+1,n-1));
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 2964
use std::io;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main(){
    let num:String = read();
    let list = num.chars().collect::<Vec<char>>();
    
    match &list[&list.len() - 1]{
        '2'| '4'| '5'|  '7'| '9' => println!("hon"),
        '0'| '1'| '6'| '8' => println!("pon"),
        '3' => println!("bon"),
        _=> println!("Error"),
    }
}

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

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> grid(h+2,vector<char>(w+2,'.'));

    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cin >> grid[i][j];
        }
    }
    bool check = true;
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            if(
                grid[i][j] == '#' &&
                (
                    grid[i-1][j] == '.' &&
                    grid[i][j-1] == '.' &&
                    grid[i+1][j] == '.' &&
                    grid[i][j+1] == '.'
                )
            ){
                check = false;
            }
        }
    }

    if(check){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
c = True
for i in range(n):
  t, x, y = map(int, input().split())
  if x + y == t:
    c = True
  elif x + y < t and (t - x - y) % 2 == 0:
    c = True
  else:
    c = False
    break
if c == True:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
import math
from decimal import Decimal
import itertools

N = int(input())
x, y = [0] * N, [0] * N
per = list(itertools.permutations(range(1, N+1)))
for i in range(N):
  x[i], y[i] = map(int, input().split())
dis = 0
for lis in per:
  for j in range(1, len(lis)):
    k = lis[j]
    l = lis[j-1]
    dis += math.sqrt((x[l-1] - x[k-1])**2 + (y[l-1] - y[k-1])**2)
fac = math.factorial(N)
print(dis/fac)

Measured memory_bytes: 14752
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

//#####################
//Union-Find
//#####################

int n, uf_par[112345], uf_rnk[112345];

void uf_init(int size)
{
    REP(i, size)
    {
        uf_par[i] = i;
        uf_rnk[i] = 0;
    }
}

int uf_find(int x)
{
    if (uf_par[x] == x)
        return x;
    else
        return uf_par[x] = uf_find(uf_par[x]);
}

void uf_unite(int x, int y)
{
    x = uf_find(x);
    y = uf_find(y);
    if (x == y)
        return;

    if (uf_rnk[x] < uf_rnk[y])
    {
        uf_par[x] = y;
    }
    else
    {
        uf_par[y] = x;
        if (uf_rnk[x] == uf_rnk[y])
            uf_rnk[x]++;
    }
}

bool uf_same(int x, int y)
{
    return uf_find(x) == uf_find(y);
}

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

    int m, a[112345], b[112345];

    ll size[112345];

    cin >> n >> m;

    REP(i, n + 1)
    size[i] = 1;

    uf_init(n + 1);

    REP(i, m)
    {
        cin >> a[m - 1 - i] >> b[m - 1 - i];
    }

    vector<ll> res;

    ll h = (ll)n * (ll)(n - 1) / 2;

    REP(i, m)
    {
        res.push_back(h);

        if (uf_same(a[i], b[i]))
            continue;

        ll ta = size[uf_find(a[i])];
        ll tb = size[uf_find(b[i])];

        ll tmp = ta * tb;

        h -= tmp;

        uf_unite(a[i], b[i]);

        size[uf_find(a[i])] = ta + tb;
    }

    reverse(res.begin(), res.end());

    for (ll i : res)
        cout << i << endl;

    return 0;
}

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

using namespace std;

typedef long long llint;

int main() {
  int t, d, l;
  while (cin >> t >> d >> l, t) {
    vector<int> x(t);
    for (int i = 0; i < t; i++) {
      cin >> x[i];
    }
    int ans = 0, cnt = 0;
    for (int i = 0; i < t; i++) {
      if (cnt > 0) ans++, cnt--;
      if (x[i] >= l) cnt = d;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG

 // 深さ優先探索
vector<bool> seen;
int dfs(const Graph &G, ll v) {
    seen[v] = true; // v を訪問済にする
    int score = 0; 

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー

        // 負荷さ優先探索中の処理



        dfs(G, next_v); // 再帰的に探索, 毎回mat渡してええの？
    }
    return score;
} 

/*
//桁数の計算
ll keta(ll num){
  ll ans= 0 ;
  ll rem;

  for (ll i = 4; i >= 0 ; i--){
    rem = pow(10,i);
    ans += (num / rem); 
    num = num % rem;
  }
  return ans;
}
*/


int main() {
  ll K;
  string S, ans;
  cin >> K >> S;

  if(S.size() <= K) cout << S << endl;
  else{
    for(ll i=0 ; i < K ; i++){
      //if(i < S.size()){
        cout << S.at(i);
      //}
    }
    cout << "..." << endl;
  }

  return 0;
}

Measured memory_bytes: 3632
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

//最大公約数
	long long GCD(long long a, long long b) {
		if (a < b)
			swap(a, b);
		if (b == 0) return a;
		else return GCD(b, a % b);
	}
	//素数判定
	bool sosuu_check(int num) {
		int i;
		for (i = 2; i <= sqrt(num); ++i) {
			if (num%i == 0)
				return false;
		}
		return (num < 2) ? false : true;
	}
	
	int check(int N, int a, int b) {
		int A,B,i;
		if (a > b) {
			A = a;
			B = b;
		}
		else {
			A = b;
			B = a;
		}
		for (i = N / b; i > 0; i--) {
			if ((N - b * i) % a == 0) {
				return i;
			}
		}
		return 0;
	}
	//コンビネーション(n,r)
	ull combination(int n, int r) {
		if (r * 2 > n) r = n - r;
		ull dividend = 1;
		ull divisor = 1;
		for (int i = 1; i <= r; ++i) {
			dividend *= (n - i + 1);
			divisor *= i;
		}
		return dividend / divisor;
	}

	void Swap(int* left, int* right)
	{
		int temp = *left;
		*left = *right;
		*right = temp;
	}

int main() {
	ll N, Q, i;
	string S;
	cin >> N >> Q>>S;
	vector<ll> vec(100001,0);
	for (i = 1; i < N; i++) {
		if (S[i] == 'C'&&S[i - 1] == 'A')
			vec[i] = vec[i - 1] + 1;
		else
			vec[i] = vec[i - 1];
	}
	int l, r;
	REP(i, Q) {
		cin >> l >> r;
		cout << vec[r-1] - vec[l-1] << endl;
	}
	return 0;
}

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

int main() {
    char x;
    cin >> x;
    if ((x >= 'a') && (x <= 'z'))
    {
        cout << "a" << endl;
    } else
    {
        cout << "A" << endl;
    }
    
    
  return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int k, x;
    cin >> k >> x;
    if (500 * k >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}



Measured memory_bytes: 384
import java.awt.List;
import java.util.*;
public class Main {
	static int modNum = 1000000007;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String a = sc.next();
		
		
//		ArrayList<Integer> list = new ArrayList<Integer>();
//		
//		for(int i=1;i<=a*2;i++){
//			int b = sc.nextInt();
//			list.add(b);
//		}


		
		System.out.println(a.lastIndexOf('Z')-a.indexOf('A')+1);
		sc.close();
	}
}

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

int child_count, candy;
vector<int> child;

int main(int argc, char const* argv[])
{
    cin >> child_count;
    cin >> candy;

    int input;
    for (int i = 0; i < child_count; i++) {
        cin >> input;
        child.push_back(input);
    }

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

    int child_sat = 0;
    for (auto& i : child) {
        candy -= i;
        if (candy >= 0) {
            child_sat++;
        } else {
            break;
        }
    }
    if (candy > 0) {
        child_sat--;
    }

    cout << child_sat;

    return 0;
}


Measured memory_bytes: 256
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;
const int MOD = 998244353;

int main() {
	int N;
	cin>>N;
	int ans = 0;
	for (int i = 1;i < N;++i) 
		for (int j = 1;i * j < N;++j) 
			ans++;

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


Measured memory_bytes: 3592
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            #i & -iでLSB(least significant bit/最下位 bit)が求まる
            #区間和はLSBだけ引いていく
            i -= i & -i
        return s

    #a_i(1<=i<=n)にxを加算
    #点に対する更新
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

def invnumber(n, S):
    bit = Bit(2*n+1)
    invs = 0
    for i in range(n):
        s = S[i]+n #BITで扱うため
        invs += bit.sum(s) # #i<j
        bit.add(s, 1)
    return invs

n = int(input())
a = list(map(int, input().split()))
r = max(a)+1
l = 0
c = (n*(n+1)//2+1)//2
while r-l > 1:
    m = (l+r)//2
    S = [0]*(n+1)
    for i in range(1, n+1):
        if a[i-1] >= m:
            S[i] = S[i-1] + 1
        else:
            S[i] = S[i-1] - 1
    if invnumber(n+1, S) >= c:
        l = m
    else:
        r = m
print(l)


Measured memory_bytes: 118884
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
  
  long long N,X,M;
  cin >> N >> X >> M;

  vector<int> num(M,0);
  
  int cnt = 1;
  int st = 0,en = 0;
  long long x = X;
  for(int i = 0;i < N;i++) {
    if(num[x] != 0) {
      st = num[x];
      en = cnt;
      break;
    }
    num[x] = cnt;
    cnt++;
    x = x*x % M;
  }
  

  int n = en-st;
  
  
  long long ans = 0;

  if(n == 0) {
    for(int i = 0;i < N;i++) {
      ans += X;
      X = X*X%M;
    }
    cout << ans << endl;
    return 0;
  }

  for(int i = 0;i < st-1;i++) {
    ans += X;
    X = X*X%M;
  }

  long long loop_sum = 0;
  long long rest = N-st+1;
  long long loop_num = rest / n;
  int r = rest % n;
  for(int i = 0;i < n;i++) {
    if(i < r) ans += x;
    loop_sum += x;
    x = x*x%M;
  }

  ans += loop_num*loop_sum;
  cout << ans << endl;
 

}


Measured memory_bytes: 3780
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define loop(i,s,e) for(ll i=s; i<e; i++)
#define endl '\n'
#define vll vector<ll>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define N 100001
#define pb push_back
#define INF LLONG_MAX
#define inf INT_MAX
#define minusinf INT_MIN

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

ll arr[101];
ll n;

ll dp[100001][3];

bool second_wins(ll k, ll player){
	if(k<0 and player==2) return true;
	if(k<0 and player==1) return false;

	if(k==0 and player==2) return false;
	if(k==0 and player==1) return true;

	if(dp[k][player]!=-1) return dp[k][player];

	if(player==2){

		loop(i,0,n) {
			if(second_wins(k-arr[i],3-player)==true) {
				dp[k][player]=1;
				return true;
			}
		}
		dp[k][player] = 0;
		return false;
	}

	loop(i,0,n) {
		if(second_wins(k-arr[i],3-player)==false) {
			dp[k][player] = 0;
			return false;
		}
	}
	dp[k][player] = 1;
	return true;
}

void alpha(){

	memset(dp, -1, sizeof(dp));

	ll k;
	cin>>n>>k;

	loop(i,0,n) cin>>arr[i];

	if(second_wins(k,1)) cout<<"Second"<<endl;
	else cout<<"First"<<endl;

	
	return;

}

int main(){

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



    ll t=1;
	//cin>>t;

  	while(t--) alpha();

	return 0;

}

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   //最大値を求める
#define MIN(x) *min_element(ALL(x))   //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007      //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

#define ifr(i, n) for (int i = (n)-1; i >= 0; --i)

signed main()
{
    
    while(true){
        int a, b;
        cin >> a >> b;
        if(a == 0 && b == 0)
            break;
        int counter = 0;
        FOR(i, 1, a){
            FOR(j, i+1, a){
                FOR(k, j+1, a){
                    if(i+j+k == b)
                        ++counter;
                }
            }
        }

        
        cout << counter << endl;

    }

}


Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)

int N,M;
char A[1010][1010];
bool F[1010][1010];
int dist[1010][1010];

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

signed main(){
	cin>>N>>M;
	queue<P> que;
	REP(i,N){
		cin>>A[i];
	}
	REP(i,N)REP(j,M){
		if(A[i][j]=='#'){
			que.push(make_pair(i,j));
			F[i][j]=true;
		}
	}
	while(!que.empty()){
		P p=que.front();
		que.pop();
		REP(i,4){
			int nx=p.first+dx[i];
			int ny=p.second+dy[i];
			if(nx<0||ny<0||nx>=N||ny>=M||F[nx][ny]==true)continue;
			dist[nx][ny]=dist[p.first][p.second]+1;
			que.push(make_pair(nx,ny));
			F[nx][ny]=true;
		}
	}
	int ans=0;
	REP(i,N)REP(j,M){
		ans=max(ans,dist[i][j]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 20404
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;
ll M = 1e6;

int main(){
 ll x;
 cin>>x;
 for(ll i=-M;i<M;i++){
  ll tmp = (pow(i,5)+0.5)+ x;
  ll a = pow(tmp,0.2) + 0.5;
  if( a*a*a*a*a == i*i*i*i*i + x ){
   cout<<a<<' '<<i<<endl;
   return 0;
  }
 }
    return 0;
}


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

vector<vector<vector<int>>> edge;
vector<bool> used;
void add_edge(int u, int v, int c) {
    edge[u].push_back({v, c, (int)edge[v].size()});
    edge[v].push_back({u, 0, (int)edge[u].size()-1});
}

int dfs(int v, int t, int f) {
    if (v==t) return f;
    used[v] = true;
    for (int i = 0; i < (int)edge[v].size(); i++) {
        auto e = edge[v][i];
        if (used[e[0]] || e[1]==0) continue;
        int d = dfs(e[0], t, min(f, e[1]));
        if (d > 0) {
            edge[v][i][1] -= d;
            edge[e[0]][e[2]][1] += d;
            return d;
        }
    }
    return 0;
}

int max_flow(int s, int t) {
    int res = 0;
    int M = (int)edge.size();
    while (true) {
        used = vector<bool>(M, false);
        int f = dfs(s, t, 99999999);
        if (f == 0) break;
        else res += f;
    }
    return res;
}

int main() {
    int INF = 999;
    int H,W;
    cin >> H >> W;
    vector<string> grid(H);
    for (int i = 0; i < H; i++) cin >> grid[i];
    edge.resize(H+W+2);
    int start, goal;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j] == '.') continue;
            if (grid[i][j] == 'S') {
                start = i*W+j;
                add_edge(H+W, i, INF);
                add_edge(H+W, H+j, INF);
            }
            else if (grid[i][j] == 'T') {
                goal = i*W+j;
                add_edge(i, H+W+1, INF);
                add_edge(H+j, H+W+1, INF);
            }
            else if (grid[i][j] == 'o') {
                add_edge(i, H+j, 1);
                add_edge(H+j, i, 1);
            }
        }
    }
    if (start / W == goal / W || (goal-start) % W == 0) cout << -1 << endl;
    else cout << max_flow(H+W, H+W+1) << endl;
    return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl0

ll modpow(ll x, ll y, ll m){
    if(y==0) return 1;
    ll res = modpow(x,y/2,m);
    return res * res % m * (y&1 ? x : 1) % m;
}

int h,w,n,k;

int ask(int a, int b, int c, int d){
    printf("? %d %d %d %d\n", a, b, c-1, d-1);
    fflush(stdout);
    int p;
    cin >> p;
    return p;
}

int ans[50][50];

void solve(int i1, int j1, int i2, int j2, int n){
    int h = i2 - i1;
    int w = j2 - j1;
    if(n == 0 || n == h*w){
        for(int i = i1; i < i2; ++i){
            for(int j = j1; j < j2; ++j){
                ans[i][j] = n == 0 ? 0 : 1;
            }
        }
    } else {
        if(h > w){
            int x = ask(i1, j1, i1 + h/2, j2);
            solve(i1, j1, i1 + h/2, j2, x);
            solve(i1 + h/2, j1, i2, j2, n - x);
        } else {
            int x = ask(i1, j1, i2, j1 + w/2);
            solve(i1, j1, i2, j1 + w/2, x);
            solve(i1, j1 + w/2, i2, j2, n - x);
        }
    }
}

int main(){
    cin >> h >> w >> n >> k;
    memset(ans, -1, sizeof ans);
    solve(0, 0, h, w, n);

    rep(i,h/5){
        solve(i*5, 0, i*5+5, w, ask(i*5, 0, i*5+5, w));
    }

    // rep(i,h){
    //     rep(j,w){
    //         cerr << ans[i][j];
    //     }
    //     cerr << endl;
    // }

    ll sigma = 0;
    rep(i,h)rep(j,w){
        sigma += ans[i][j] * modpow(2, i*w + j, k);
        sigma %= k;
    }
    cout << "! " << sigma << endl;
}


Measured memory_bytes: 724
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int n,a[200010];
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	
	if(n==1){
		cout<<a[0]<<endl;
		return 0;
	}
	
	int cnt=n-1;
	if(cnt%2==(n%2))cnt--;
	for(int i=0;i<n;i++){
		cout<<a[cnt];
		if(i!=n-1)cout<<" ";
		
		if(cnt%2!=(n%2))cnt-=2;
		else cnt+=2;
		
		if(cnt<0)cnt=(n%2);
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 2944
nm = gets.split.map(&:to_i)
n = nm[0]
m = nm[1]
distance =Hash.new
x = gets.split.map(&:to_i).sort!
positioned = Array.new(m,0)

for i in (0..m-2)
distance[i] = x[i+1]-x[i]
end
distance = distance.sort_by{|k,v| v}



if n >= m
answer = 0


else
  answer = x[m-1] - x[0]
positioned[0] = 1
n -= 1
  while n > 0
    array = distance.pop
    positioned[array[0]+1] =1
    answer -= array[1]
    n -=1
  end

end

p answer


Measured memory_bytes: 22776
# coding: utf-8
N=int(input())

l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(l[N-1])

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(100000)
fin = sys.stdin.readline

N, M = [int(elem) for elem in fin().split()]
adj = [[] for _ in range(N)]
for _ in range(M):
    a, b = [int(elem) - 1 for elem in fin().split()]
    adj[a].append(b)
    adj[b].append(a)


def judge_bipartite(adj, v, color, colors):
    colors[v] = color
    for neighbor in adj[v]:
        if colors[neighbor] is None:
            if not judge_bipartite(adj, neighbor, 1 - color, colors):
                return False
        else:
            if colors[neighbor] == color:
                return False
    else:
        return True

colors = [None] * N
bipartite = judge_bipartite(adj, 0, 0, colors)

if not bipartite:
    print(N * (N - 1) // 2 - M)
else:
    num_b = sum([v == 0 for v in colors])
    num_w = N - num_b
    print(num_b * num_w - M)



Measured memory_bytes: 31152
#include<iostream>
#include<string>
using namespace std;
int o,S1,S2;
int main(){
string S;
while(o<5){
cin>>S;
S1=0;
S2=0;
for(int i=0;i<S.size()-2;i++){
if(S.substr(i,3)=="JOI"){S1++;}
if(S.substr(i,3)=="IOI"){S2++;}
}
cout<<S1<<endl;
cout<<S2<<endl;
o++;
}
}

Measured memory_bytes: 1216
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;

using namespace std;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        int j = i;
        int sum = 0;
        while(j)
        {
            sum += j%10;
            j /= 10;
        }
        if(sum >= a && sum <= b)ans += i;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {
    string S, T;
    cin >> S;
    cin >> T;

    if (S.length() + 1 == T.length()) {
        for (int i = 0; i < S.length(); ++i) {
            if (S.at(i) != T.at(i)) {
                cout << "No" << endl;
                return 0;
            }
        }

        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7, INF = 1e9, larg = 1e5;
int A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
int max_value = 0, max_index = 0;
int min_value = INF, min_index = 0;

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

int main() {
	cin >> N;
	if(N < 105) cout << 0;
	else if(N < 135) cout << 1;
	else if(N < 165) cout << 2;
	else if(N < 189) cout << 3;
	else if(N < 195) cout << 4;
	else cout << 5;
}


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

using namespace std;

const int MX = 307;

int a[MX][MX];
bool on[MX][MX];
bool banned[MX];
int cnt[MX];
pair<int, int> calc(int n, int m) {
    for (int i = 1; i <= m; i++) {
        cnt[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
        int j = 1;
        while (banned[a[i][j]]) j++;
        cnt[a[i][j]]++;
    }
    pair<int, int> ans(-1, -1);
    for (int i = 1; i <= m; i++) {
        ans = max(ans, make_pair(cnt[i], i));
    }
    return ans;
}

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }

    int ans = n + m;

    for (int i = 1; i <= m; i++) {
        auto cur = calc(n, m);
        ans = min(ans, cur.first);
        banned[cur.second] = true;
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define print(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
ll MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}
ll modpow(ll x, ll y, ll m) {
    if (y == 0) return 1;
    ll res = modpow(x, y / 2, m);
    return res * res % m * (y & 1 ? x : 1) % m;
}
ll modinv(ll x) { return modpow(x, MOD - 2, MOD); }

int main(){
    ll N, H; cin >> H >> N;
    vector<P> I(N);
    rep(i,N){ ll a,b; cin >> a >> b; I[i] = {a,b}; };
    
    ll dp[N+5][H+10];
    rep(i,N+5) rep(j,H+10){
        if(!i || !j) dp[i][j] = 0;
        else dp[i][j] = 1e18;
    }
    
    rep1(i,N) rep(j,H+1){
        dp[i][j] = min(dp[i][j], dp[i][max(j-I[i-1].first,0LL)] + I[i-1].second);
        dp[i+1][j] = dp[i][j];
    }
    
    print(dp[N][H]);
    
    return 0;
}

Measured memory_bytes: 78848
k = gets.chomp.to_i
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
k.times do |i|
  break if arr.length > k
  if arr[i] % 10 == 0
    arr << arr[i] * 10 + (arr[i] % 10)
    arr << arr[i] * 10 + (arr[i] % 10 + 1)
  elsif arr[i] % 10 == 9
    arr << arr[i] * 10 + (arr[i] % 10 - 1)
    arr << arr[i] * 10 + (arr[i])
  else
    arr << arr[i] * 10 + (arr[i] % 10 - 1)
    arr << arr[i] * 10 + (arr[i] % 10)
    arr << arr[i] * 10 + (arr[i] % 10 + 1)
  end
end
print arr[k - 1]

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// abc 142e // DAME:
int main(){
    int n, m;
    cin >> n >> m;
    int a[m+1];
    vector<int> c[m+1];
    vector<int> dp(5000, inf);
    dp[0] = 0;
    rep(i, m){
        int aa, bb;
        cin >> aa >> bb;
        a[i] = aa;
        // s: 集合
        int s = 0;
        rep(j, bb){
            int tmp;
            cin >> tmp;
            tmp--;
            c[i].push_back(tmp);
            s |= 1<<tmp;
        }
        dp[s] = a[i];
    }

    for(int bit=0; bit<(1<<n); bit++){
        rep(i, m){
            int tmp = bit;
            rep(j, c[i].size()){
                int cc = c[i][j];
                tmp |= 1<<cc;
            }
            chmin(dp[tmp], dp[bit] + a[i]);
        }
    }
    if (dp[(1<<n)-1]==inf) cout << -1 << endl;
    else cout << dp[(1<<n) - 1] << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int k;
    vector<int> antenna(5);
    rep(i,antenna.size())
    {
        cin>>antenna[i];
    }
    cin>>k;
    rep(i,antenna.size()-1)
    {
        if(abs(antenna[i]-antenna[antenna.size()-1])>k)
        {
            cout<<":("<<endl;
            return 0;
        }
    }
    cout<<"Yay!"<<endl;

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=1;i<=(n);i++)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
template<class T> inline bool chmin(T& a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a,T b){
if(a<b){
a=b;
return true;
}
return false;
}
int main(){
    int n;cin>>n;
    vl a(n),b(n),c(n);rep(i,n)cin>>a[i]>>b[i]>>c[i];
    vector<vl> dp(n+1,vl(4,0));
    rep(i,n){
        dp[i+1][1]=max(dp[i][2]+a[i],dp[i][3]+a[i]);
        dp[i+1][2]=max(dp[i][1]+b[i],dp[i][3]+b[i]);
        dp[i+1][3]=max(dp[i][1]+c[i],dp[i][2]+c[i]);
    }
    ll ans=max(dp[n][1],max(dp[n][2],dp[n][3]));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9600
N = int(input())
A = [int(a) for a in input().split()]

A.sort(reverse=True)
a = 0
b = 0
i = 1
while i < N:
    if A[i] == A[i-1] and a == 0:
        a = A[i]
        i += 2
    elif A[i] == A[i-1] and b == 0:
        b = A[i]
        i += 2
    else:
        i += 1

print(a*b)

Measured memory_bytes: 14252
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  int x;
  cin >> x;
  if(x < 1200) {
    cout << "ABC" << endl;
  }else {
    cout << "ARC" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int a,b;
    cin>>a>>b;
    
    if(a<=8 && b<=8){
        cout<<"Yay!"<<endl;
    }else{
        cout<<":("<<endl;
    }
        
        
    
    
    return 0;
}






Measured memory_bytes: 256
#include <vector>
#include <cstdio>
using namespace std;
typedef pair<int,int> pii;

typedef struct{
	int x;
	int y;
}dir;
const dir D[]={
	{0,-1},{0,1},{-1,0},{1,0}
};
const int max_depth=10;

int dfs2(int x,int y,const dir &d,vector<vector<int> >&m){
	if(x<0||m[0].size()<=x || y<0||m.size()<=y)return -1;
	if(m[y][x]==1||m[y][x]==3)return 0;
	int r=dfs2(x+d.x,y+d.y,d,m);
	if(r<0)return -1;
	return r+1;
}
int dfs(int depth,int x,int y,vector<vector<int> >&m,pii &goal){
	if(depth>max_depth-1)return -1;
	int ret=-1;
	for(auto &d:D){
		int dist=dfs2(x+d.x,y+d.y,d,m);
		if(dist>=0){
			pii p={x+d.x*(dist+1),y+d.y*(dist+1)};
			if(p==goal)return depth+1;
			if(dist>0){
				m[p.second][p.first]=0;
				int r=dfs(depth+1,p.first-d.x,p.second-d.y,m,goal);
				m[p.second][p.first]=1;
				if(r>=0 && (ret<0||ret>r))ret=r;
			}
		}
	}
	return ret;
}

int main(){
	int W,H;
	for(;scanf("%d%d",&W,&H),H;){
		pii start,goal;
		vector<vector<int> >v(H);
		for(int y=0;y<H;y++){
			v[y].resize(W);
			for(int x=0;x<W;x++){
				scanf("%d",&v[y][x]);
				if(v[y][x]==2)start={x,y};
				if(v[y][x]==3)goal={x,y};
			}
		}
		printf("%d\n",dfs(0,start.first,start.second,v,goal));
	}
}

Measured memory_bytes: 1016
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  int64_t X;
  std::cin >> X;
  for (int64_t A: range(-1000, 1001)) {
    for (int64_t B: range(-1000, 1001)) {
      if (A * A * A * A * A - B * B * B * B * B == X) {
        std::cout << A << ' ' << B << '\n';
        return 0;
      } 
    }
  }
  return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> X(n), Y(m);
  for(int &u : X) cin >> u;
  for(int &u : Y) cin >> u;
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  reverse(X.begin(), X.end());
  for(int z = x + 1; z <= y; z++){
    if(X[0] < z && z <= Y[0]){
      cout << "No ";
      break;
    }
  }
  cout << "War\n";
  return 0;
}

Measured memory_bytes: 256
import * as fs from "fs";

// inputで受け取り配列化する
const [X, K, D] = fs.readFileSync("/dev/stdin", "utf8").split(" ").map(Number);

const temp = K * D;

if (temp > Math.abs(X)) {
  const x = Math.abs(X);
  const num = Math.floor(x / D);
  const diff = K - num;
  const ans = Math.min(Math.abs(X - num * D), Math.abs(X + num * D));
  if (diff % 2 === 0) {
    console.log(ans);
  } else {
    console.log(Math.min(Math.abs(ans + D), Math.abs(ans - D)));
  }
} else {
  const ans = Math.abs(X) - temp;
  console.log(ans);
}


Measured memory_bytes: 29684
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,ans;
bool compare(vector<ll> &a,vector<ll> &b)
{
    for(ll i=0;i<26;i++)
    {
        if(a[i]<b[i])
            return 1;
    }
    return 0;
}
void solve()
{
    cin>>n;vector<vector<ll>> vc(n,vector<ll>(26,0));
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        for(auto it:s)
            vc[i][it-'a']++;
    }
    //sort(vc.begin(),vc.end(),compare);
    map<vector<ll>,ll>mp;
    for(int i=0;i<n;i++)
        mp[vc[i]]++;
    for(auto it:mp)
    {
        ans+=it.second*(it.second-1)/2;
    }
    cout<<ans<<endl;
    
}   

int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
   // int t;cin>>t;while(t--)
   {
        solve();
    }
    return 0;
}


Measured memory_bytes: 54144
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int h,w;
string G[51];
bool checked[51][51];
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

bool isRect(int x,int y)
{
  int x1,x2,y1,y2;
  x1 = x2 = x;
  y1 = y2 = y;

  rep(i,h)
    rep(j,w)
    {
      if(G[i][j] == G[y][x])
	{
	  if(j < x1)x1 = j;
	  if(j > x2)x2 = j;
	  if(i < y1)y1 = i;
	  if(i > y2)y2 = i;
	}
    }

  REP(i,y1,y2+1)
    REP(j,x1,x2+1)
    if(G[i][j] != G[y][x] && !checked[i][j])return false;
  return true;

}

void draw(int x,int y,char c)
{
  if(checked[y][x])return;
  checked[y][x] = true;
  rep(i,4)
    {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
      if(G[ny][nx] != c)continue;
      draw(nx,ny,c);
    }
}

bool isSafe()
{
  rep(i,h)
    rep(j,w)
    if(G[i][j] != '.' && !checked[i][j])return false;
  return true;
}

int main()
{
  int T;
  cin >> T;
  while(T-- > 0)
    {
      cin >> h >> w;
      rep(i,h)
	cin >> G[i];
      rep(i,51)rep(j,51)checked[i][j] = false;

      while(true)
	{
	  bool Fin = true;
	  bool update = false;
       
	  rep(i,h)
	    {	
	      rep(j,w)
		{
		  if(G[i][j] == '.')continue;
		  if(checked[i][j])continue;
		  Fin = false;
		  if(isRect(j,i))
		    {
		      update = true;
		      draw(j,i,G[i][j]);
		    }
		}
	    }
	  if(Fin || !update)break;
	}
   
      isSafe()?cout << "SAFE" << endl:cout << "SUSPICIOUS" << endl;
    }
  return 0;
}

Measured memory_bytes: 1332
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define int ll
using pint = pair<int,int>;
using Graph = vector<vector<int>>;
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 1e10; //10^10
const double PI = acos(-1.0L);
const int dx[4] = {1, 0, -1, 0} , dy[4] = {0, 1, 0, -1};
/*mod逆元*/long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template< typename T >T mod_pow(T x, T n, T p=MOD) {T ret = 1;while(n > 0) {if(n & 1) (ret *= x) %= p;(x *= x) %= p;n >>= 1;}return ret;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    int ans = -INF;
    FOR(i,1,n+1)FOR(j,2,1919)if(POW(i,j)<=n) chmax(ans,POW(i,j));
    out(ans);

    return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if(a+b==15){
        puts("+");
    }
    else if(a*b == 15){
        puts("*");
    }
    else{
        puts("x");
    }
}

Measured memory_bytes: 3548
def solve(a):
    nodd = 0
    for x in a:
        nodd += (x&1)
    return (nodd%2==0)


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    if solve(A):
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()

Measured memory_bytes: 14108
# 解説参照
# require 'pry'
N = gets.to_i
arr = []
brr = []
N.times do |i|
  arr << gets.split.map(&:to_i)
end
# p arr
N.times do |i|
  brr << gets.split.map(&:to_i)
end
# p brr
res = -(1 << 30)

# binding.pry
1.upto((1 << 10) - 1) do |b|
  cc = 0 # 利益の合計値
  N.times do |i|
    c = 0 # 店毎の営業時間一致の個数
    10.times do |j|
      c += 1 if (b >> j & 1) == 1 && arr[i][j] == 1
    end
    cc += brr[i][c]
  end
  res = cc if res < cc
end
puts res

Measured memory_bytes: 3836