akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
bool prime(ll n){
    for(ll i = 2; i * i <= n; i++)
        if(n % i == 0)
            return false;
    return true;
}
int main()
{
    Hello
    ll a, b;
    cin >> a >> b;
    ll n = max(a, b);
    set <ll> v;
    for(ll i = 1; i * i <= n; i++){
        if(a % i == 0 && b % i == 0 && prime(i))
                v.insert(i);
        if(a % i == 0 && (b) % (a/i) == 0 && prime(a/i))
            v.insert(a/i);
    }
    cout << v.size();
    return 0;
}


Measured memory_bytes: 384
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let k: usize = sc.read();
    let mut has_okashi: Vec<bool> = vec![false; n];
    for _ in 0..k {
        let d: i32 = sc.read();
        for _ in 0..d {
            let a: usize = sc.read();
            has_okashi[a - 1] = true;
        }
    }
    let v_okashi: Vec<bool> = has_okashi.iter().filter(|&e| !*e).cloned().collect();
    println!("{}", v_okashi.len());
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 2168
def ints():
  return list(map(int, input().split()))

H, W = ints()

A = [ints() for i in range(H)]
B = [ints() for i in range(H)]

C = 20000
dp = [[0 for j in range(W)] for i in range(H)]
dp[0][0] |= 1 << (C - A[0][0] + B[0][0]) 
dp[0][0] |= 1 << (C + A[0][0] - B[0][0])

for i in range(H):
  for j in range(W):
    if i + 1 < H:
      dp[i + 1][j] |= dp[i][j] << abs(A[i + 1][j] - B[i + 1][j])
      dp[i + 1][j] |= dp[i][j] >> abs(A[i + 1][j] - B[i + 1][j])
    if j + 1 < W:
      dp[i][j + 1] |= dp[i][j] << abs(A[i][j + 1] - B[i][j + 1])
      dp[i][j + 1] |= dp[i][j] >> abs(A[i][j + 1] - B[i][j + 1])

ans = 10**100
for k in range(2*C):
  if dp[H - 1][W - 1] >> k & 1:
    ans = min(ans, abs(k - C))
print(ans)

Measured memory_bytes: 73432
#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() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  rep(i, N) cin >> H.at(i);
  vector<set<int>> A(N);
  int x, y;
  rep(i, M){
   cin >> x >> y;
   A.at(x-1).insert(y-1);
   A.at(y-1).insert(x-1);
  }
  
  int ans = 0;
  
  rep(i, N){
   bool flg = true;
   for(auto e : A.at(i)){
    if(H.at(i) <= H.at(e)){
     flg = false; 
    }
   }
   if(flg) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 17740
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}

	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	for i := 0; i < n-1; i++ {
		a[i+1] = gcd(a[i], a[i+1])
	}

	fmt.Println(a[n-1])
}

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

int main()
{
    int N,M;cin >>N>>M;
    bool st[N+1],la[N+1];
    for(int a = 0;a < N;a++){
        st[a] = false;
        la[a] = false;
    }
    for(int a = 0;a < M;a++){
        int x,y;cin >> x >> y;
        if(x == 1)st[y] = true;
        if(y == 1)st[x] = true;
        if(x == N)la[y] = true;
        if(y == N)la[x] = true;
    }
    bool result = false;
    for(int a = 0;a < N+1;a++){
        if(st[a]){
            if(la[a]){
                result = true;
                break;
            }
        }
    }
    cout<<(result?"POSSIBLE":"IMPOSSIBLE")<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <numeric>
using namespace std;
typedef long long int ll;

char fi[850][850];
int d[850][850];

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

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int h,w,k; cin >> h >> w >> k;
	int sx,sy;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> fi[i][j];
			d[i][j]=1e9;
			if(fi[i][j]=='S'){
				d[i][j]=0;
				sx=i,sy=j;
			}
		}
	}
	queue<pair<int,int>> q;
	q.push(make_pair(sx,sy));
	while(q.size()){
		auto p=q.front(); q.pop();
		int x=p.first,y=p.second;
		for(int i=0;i<4;i++){
			int nx=x+dx[i],ny=y+dy[i];
			if(0<=nx&&nx<h&&0<=ny&&ny<w&&fi[nx][ny]=='.'&&d[nx][ny]>d[x][y]+1){
				d[nx][ny]=d[x][y]+1;
				q.push(make_pair(nx,ny));
			}
		}
	}
	int res=1e9;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(d[i][j]<=k){
				int p=min({(i+k-1)/k,(h-1-i+k-1)/k,(j+k-1)/k,(w-1-j+k-1)/k});
				res=min(res,p+1);
			}
		}
	}
	printf("%d\n",res);
}


Measured memory_bytes: 3584
#include<stdio.h>
#include<math.h>

typedef struct{double x,y;}Point;

void koch(int,Point,Point);

int main(){
  Point a,b;
  int n;

  scanf("%d",&n);
  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;
  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);

  return 0;
}

void koch(int n,Point a,Point b){
  if(n==0)return;
  Point s,t,u;
  double th = M_PI * 60.0/180.0;
  
  s.x=(2.0*a.x+1.0*b.x)/3.0;
  s.y=(2.0*a.y+1.0*b.y)/3.0;
  t.x=(1.0*a.x+2.0*b.x)/3.0;
  t.y=(1.0*a.y+2.0*b.y)/3.0;
  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;
  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);
}



Measured memory_bytes: 2048
/***************************************************************
	File name: F.cpp
	Author: huhao
	Create time: Sun 07 Jun 2020 02:34:32 PM CST
***************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=r*10+c-48;
		c=getchar();
	}
	return r*t;
}
const int N=300010;
int n,p[N];
int check(int l,int r)
{
	fr(i,l,r) if(p[i]<l||p[i]>r) return 0;
	int lst=0;
	for(int i=l;i<=r;i+=2) if(p[i]<=i)
	{
		if(p[i]<lst) return 0;
		lst=p[i];
	}
	lst=0;
	for(int i=l;i<=r;i+=2) if(p[i]>=i)
	{
		if(p[i]<lst) return 0;
		lst=p[i];
	}
	return 1;
}
int main()
{
	n=read();
	fr(i,1,n) p[i]=read();
	for(int l=1,r=1;r<=n;l=++r)
	{
		if(p[r]==r) continue;
		while(r+2<=n&&p[r+1]==r+1&&p[r+2]!=r+2) r+=2;
		if(!check(l,r)){ printf("No\n"); return 0; }
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1280
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
dp = [0] * (len(t) + 1)
dp[0] = 0

def pon(d):
 if d  == 'r':
    return p
 elif d == 's':
    return r
 else:
    return s

m = []
for i,j in enumerate(t):
    m.append(j)
    if i >= k:
        if m[i-k] == j:
            dp[i+1] = dp[i]
            m[i] = 'skip'
        else:
            dp[i+1] = dp[i]+pon(j)
    else:
        dp[i+1] = dp[i] + pon(j)
print(dp[-1])

Measured memory_bytes: 13668
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

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

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

    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    priority_queue<pair<ll, ll>> pq;
    rep(i, n) cin >> a[i];
    rep(i, n) {
        cin >> b[i];
        if(b[i] > a[i]) pq.push({b[i], i});
    }
    ll ans = 0;
    while(!pq.empty()) {
        ll i = pq.top().second;
        ll x = pq.top().first;
        pq.pop();
        ll y = b[(i + n - 1) % n] + b[(i + 1) % n];
        ll z = x % y;
        if(a[i] % y == z) {
            ans += (x - a[i]) / y;
            b[i] = a[i];
        } else if(x == z || a[i] > z) {
            cout << -1 << endl;
            return 0;
        } else {
            ans += x / y;
            b[i] = z;
            pq.push({z, i});
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9200
N , M = map(int , input().split())
A = [str(input()) for i in range(N)]
B = [str(input()) for i in range(M)]

def bina(A , B):
    for i in range((N-M)+1):
        for w in range(N):
            c = []
            for q in range(M):
                c += [A[i+q][w:w+M]]
            if c == B:
                return "Yes"
    return "No"

if __name__ == '__main__':
    ans = bina(A , B)
    print(ans)

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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end(),greater<int>());
    int Alice = 0;
    int Bob = 0;
    for(int i = 0; i < N/2; i++){
        Alice += a.at(2*i);
        Bob += a.at(2*i+1);
    }
    if(N%2 == 1){
        Alice += a.at(N-1);
    }
    cout << Alice - Bob << endl;
}

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

using namespace std;

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

    int count = 0;
    for (int i = 1; i < n; i++) {
        if (s.at(i) == 'E') {
            count++;
        }
    }

    int min = count;

    for (int i = 1; i < n; i++) {
        if (s.at(i) == 'E') count--;
        if (s.at(i-1) == 'W') count++;
        if (min > count) min = count;
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 900
import java.util.*;

public class Main {

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

        int n = scanner.nextInt();
        int max = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int a =  scanner.nextInt();
            int b = scanner.nextInt();

            if (a > max){
                max = a;
                ans = a + b;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 64772
#include <stdio.h>
int main(void) {
	long long n, a[100001], b[100000], x=0, i, j;
	scanf("%lld", &n);
	for (i = 0; i < n + 1; i++) {
		scanf("%lld", &a[i]);
	}
	for (j = 0; j < n; j++) {
		scanf("%lld", &b[j]);
	}
	for (i = 0; i < n; i++) {
		if (b[i] <= a[i]) {
			x += b[i];
			b[i] = 0;
		}
		else {
			x += a[i];
			b[i] -= a[i];
		}
		if (b[i] <= a[i + 1]) {
			x += b[i];
			a[i + 1] -= b[i];
		}
		else {
			x += a[i + 1];
			a[i + 1] = 0;
		}
	}
	printf("%lld\n", x);
	return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
struct AAA{
		int c,d;
		double e;
	}aaa;
int main(){
	int a,b;
	void exe(int a,int b);
	
	
	scanf("%d%d",&a,&b);
	
	exe(a,b);
	printf("%d %d %.8lf\n", aaa.c,aaa.d,aaa.e);
		
	
	return 0;
}
void exe(int a,int b){
	aaa.c = a/b;
	aaa.d = a%b;
	aaa.e = (double)a/b;
}
	

Measured memory_bytes: 640
n, m, q = [int(x) for x in input().split()]

t_list = [[0] * (n + 1) for i in range(n + 1)]
c_list = [[0] * (n + 1) for i in range(n + 1)]

for _ in range(m):
    l, r = [int(x) for x in input().split()]
    t_list[l][r] += 1

for i in range(1, n + 1):
    for j in range(1, n + 1):
        c_list[i][j] = t_list[i][j] + c_list[i][j - 1] + c_list[i - 1][j] - c_list[i - 1][j - 1]

for _ in range(q):
    l, r = [int(x) for x in input().split()]
    print(c_list[r][r] - c_list[l - 1][r] - c_list[r][l - 1] + c_list[l - 1][l - 1])

Measured memory_bytes: 15296
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<string> a(H);
  for (int i = 0; i < H; i++) cin >> a.at(i);
  
  vector<string> b(H+2);
  for (int i = 0; i < H+2; i++) {
    if (i == 0 || i == H+1) for (int j = 0; j < W+2; j++) b.at(i) += '#';
    else b.at(i) = '#' + a.at(i-1) + '#';
  }
  
  for (int i = 0; i < H+2; i++) cout << b.at(i) << endl;
}

Measured memory_bytes: 256
#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 IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define ll long long
#define endl "\n"
#define ar array
#define deb(x) cout << #x << " = " << x << endl
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll N = 2e5 + 1;

template <class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
inline ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
inline ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
inline ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
struct comp
{
    bool operator()(const pair<ll, ll> &x, const pair<ll, ll> &y) const
    {
        return x.first < y.first;
    }
};
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll pwr(ll x, ll n)
{
    if (n == 0)
        return 1;
    if (n & 1)
        return mul(x, pwr(mul(x, x), (n - 1) / 2));
    else
        return pwr(mul(x, x), n / 2);
}
ll modInv(ll n)
{
    return pwr(n, mod - 2);
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}
ll dp[3000];
ll solve(ll s)
{
    // cout << "s " << s << endl;
    if (s == 0)
    {
        return 1;
    }
    else if (dp[s] != -1)
        return dp[s];
    ll ans = 0;
    for (int i = 3; i <= s; i++)
    {
        if (s - i >= 0)
            ans = (ans + solve(s - i)) % mod;
    }
  //  cout << "s " << s << " ans " << ans << endl;
    dp[s] = ans;
    return ans;
}
int main()
{
    IOS;
    int t = 1;
    // cin >> t;
    while (t--)
    {
        memset(dp, -1, sizeof(dp));
        ll s;
        cin >> s;
        cout << solve(s) << endl;
    }
}

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

int main() {
  int N;
  cin >> N;
  
  if (0 < N && N < 10) {
  	cout << N << endl;
  }
  
  else if (9 < N && N < 100) {
  	cout << 9 << endl;
  }
  
  else if (99 < N && N< 1000) {
  	cout << N - 90 << endl;
  }
  
  else if (999 < N && N < 10000) {
  	cout << 909 << endl;
  }
  
  else if (9999 < N && N < 100000) {
  	cout << N - 9090 << endl;
  }
  
  else {
  	cout << 90909 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 222
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,a[N],b[N],c[N],ans;
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
	}
	for(int i=1;i<=n;i++){
		b[i]=read();
	} 
	for(int i=1;i<n;i++){
		c[i]=read();
	}
	for(int i=1;i<=n;i++){
		ans+=b[a[i]];
		if(i>1&&a[i]==a[i-1]+1){
			ans+=c[a[i-1]];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
# number of balls
N = input()
# ball values
K = list(map(int, input().split()))

# get ball counts
# ball_counts = {}
# for i in range(len(K)):
#     ball_value = K[i]
#     if ball_value in ball_counts:
#         ball_counts[ball_value] += 1
#     else:
#         ball_counts[ball_value] = 1

# for i in range(len(K)):
#     ball_value = K[i]
#     two_equal_values_count = 0
#     for value, count in ball_counts.items():
#         # check if we can even come up with a pair
#         if count > 1:
#             if value == ball_value:
#                 # if we have three balls [1, 1, 1] and the current ball is 1, we want to remove our current 1 and only look at [1, 1]
#                 two_equal_values_count += (count - 1) * (count - 2) / 2
#             else:
#                 two_equal_values_count += count * (count - 1) / 2

# get ball counts
ball_counts = {}
for i in range(len(K)):
    ball_value = K[i]
    if ball_value in ball_counts:
        ball_counts[ball_value] += 1
    else:
        ball_counts[ball_value] = 1

# get sums
total_sum = 0
for value, count in ball_counts.items():
    total_sum += (count * (count - 1)) / 2

# remove extra
for i in range(len(K)):
    ball_value = K[i]
    print(int(total_sum - (ball_counts[ball_value] - 1)))

Measured memory_bytes: 24748
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N; cin >> N;
    vector<int> x(N), y(N), h(N);
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i] >> h[i];

    vector<pair<int, pair<int, int>>> p(N);
    for (int i = 0; i < N; i++) {
        p[i] = make_pair(h[i], make_pair(x[i], y[i]));
    }

    sort(p.rbegin(), p.rend());

    if (p[0].first == 0) {
        int CX, CY;
        for (int cx = 0; cx <= 100; cx++) {
            bool flag = true;
            for (int i = 0; i < N; i++) {
                if (p[i].second.first == cx) {
                    flag = true;
                    break;
                }
            }
            if (flag) CX = cx;
        }
        for (int cy = 0; cy <= 100; cy++) {
            bool flag = true;
            for (int i = 0; i < N; i++) {
                if (p[i].second.second == cy) {
                    flag = true;
                    break;
                }
            }
            if (flag) CY = cy;
        }
        print(CX, CY, 1);
        return;
    }

    int H = 1;
    for (int cx = 0; cx <= 100; cx++) {
        for (int cy = 0; cy <= 100; cy++) {
            bool flag = true;
            H = p[0].first + abs(p[0].second.first - cx) + abs(p[0].second.second - cy);
            int cnt = 0;
            for (int i = 1; i < N; i++) {
                if (p[i].first == 0) {
                    cnt++;
                    continue;
                }
                int tmp_h = p[i].first + abs(p[i].second.first - cx) + abs(p[i].second.second - cy);
                if (tmp_h != H) flag = false; 
            }
            if (flag) {
                if (cnt == N-1) {
                    cx = p[0].second.first;
                    cy = p[0].second.second;
                    H = p[0].first;
                }
                print(cx, cy, H);
                return;
            }
        }
    }
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3636
function Main(input) {
  input = input.split(" ");
  var count = 0;
  for(var i=1;i<=input[0];i++){
    var tmp=0;
    for(var j of i.toString()){
      tmp+=Number(j);
    }
    if((input[1]<=tmp)&&(input[2]>=tmp)){
      count+=i;
    }
  }
  console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 10540
A = gets.strip.to_i + 1
B = gets.strip.to_i + 1
C = gets.strip.to_i + 1
X = gets.strip.to_i
count = 0

A.times do |i|
  B.times do |j|
    C.times do |k|
      count += 1 if 500*i + 100*j + 50*k == X
    end
  end
end

puts count

Measured memory_bytes: 1788
s = input()
ans = 0

if len(s) == 1:
    print(int(s))
    exit()

for i in range(1 << (len(s) - 1)):
    l = []
    num_sum = 0
    for j in range(len(s)-1):
        if (i >> j & 1) == 1:
            l.append(1)
        else:
            l.append(0)
    cur_num_str = s[0]
    for i in range(len(l)):
        if l[i] == 1:
            num_sum += int(cur_num_str)
            cur_num_str = s[i+1]
        else:
            cur_num_str += s[i+1]
    num_sum += int(cur_num_str)
    ans += num_sum
print(ans)





Measured memory_bytes: 3064
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
int main(void){
    int n;
    std::cin >> n;
    std::map<std::string, std::vector<std::pair<int, int>>> a;
    std::string s;
    int p;
    for(int i = 0; i < n; i++){
        std::cin >> s >> p;
        // if(a.find(s) == a.end()) a[s].resize(0);
        a[s].push_back(std::make_pair(p, i));
    }
    for(auto i = a.begin(); i != a.end(); i++){
        std::vector<std::pair<int, int>> tmp = i->second;
        std::sort(tmp.rbegin(), tmp.rend());
        for(int i = 0; i < tmp.size(); i++){
            std::cout << tmp[i].second + 1 << std::endl;
        }
    }
    return 0;
}

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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max() / 2;
const ll mod = 1e9+7;

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

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

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
  if (a < b) return a = b, true; else return false;
}


void solve(){
  int N, K;
  cin >> N >> K;

  int V[55];
  rep(i, N){
    cin >> V[i];
  }

  int ans = 0;
  rep(i, K+1){
    rep(j, K-i+1){
      rep(k, K-i-j+1){
        if(i + j > N) break;
        if(i + j <= k) break;
        vector<int> vv;
        rep(l, i){
          vv.emplace_back(V[l]);
        }
        rep(l, j){
          vv.emplace_back(V[N-l-1]);
        }
        sort(ALL(vv), greater<int>());
        // printf("%d,%d,%d\n",i,j,k);
        // rep(l, i+j-k){
        //   cout << vv[i] << " ";
        // }
        // cout << endl;
        int sum = accumulate(vv.begin(), vv.begin()+(vv.size() - k), 0);
        ans = max(ans, sum);
      }
    }
  }

  cout << ans << endl;
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
int main(){
	fast;
	ll x,y; cin>>x>>y;
	ll cnt=x*2;
	if(y<cnt){
		cout<<"No\n";
		return 0;
	} 
	for(auto i=1;i<=x;++i){
		if(cnt==y){
			cout<<"Yes\n";
			return 0;
		}
		else
			cnt+=2;
	}
	if(cnt==y)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3636
#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;


#define ll       long long int
#define fast     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define MOD      1000000007
#define pb       push_back
#define S        second
#define F        first
#define P 		 pair<ll,ll>
#define PI 3.1415926535897932384626433832795028
//#define ordered_set tree<ll, null_type,less_equal<>, rb_tree_tag,tree_order_statistics_node_update>

int mul(int a, int b) {
	return (long long)a * b % MOD;
}

int power(int a, int b) {
	int ans = 1;
	while (b > 0) {
		if (b & 1) ans = mul(ans, a);
		a = mul(a, a);
		b >>= 1;
	}
	return ans;
}
//bitset<400000010> b;

// ll n=100000;
ll p[1000100] = {0};
vector<ll> v[1000000];
void sieve(ll n) {
	for (ll i = 2; i * i <= n; i++) {
		if (!p[i])
			//primes.push_back(i);
			for (ll j = i; j <= n; j += i) {
				if (i != j)
					;
				p[j] = 1;
			}
	}
}


// ll nextPowerOf2(ll n)
// {
//     ll p = 1;
//     if (n && !(n & (n - 1)))
//         return n;

//     while (p < n)
//         p <<= 1;

//     return p;
// }
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);

}
ll factorial(ll n)
{
	if (n == 0)
		return 1;
	return n * factorial(n - 1);
}
struct segmenttree {
	vector<int> st;
	int n;
	void init(int _n) {
		n = _n;
		st.clear();
		st.resize(4 * _n, 0);
	}

	void update(int l, int r, int indup, int val, int node) {
		if (l == r) {
			st[node] += val;
			return;
		}
		else {
			int mid = (l + r) / 2;
			if (indup >= l && indup <= mid) {
				update(l, mid, indup, val, node * 2 + 1);
			}
			else {
				update(mid + 1, r, indup, val, node * 2 + 2);
			}
			st[node] = st[2 * node + 1] + st[2 * node + 2];
		}
	}

	int query(int si, int se, int l, int r, int node) {
		if (se < l || si > r || l > r) {
			return 0;
		}
		if (si >= l && se <= r) {
			return st[node];
		}
		int mid = (si + se) / 2;
		int q1 = query(si, mid, l, r, node * 2 + 1);
		int q2 = query(mid + 1, se, l, r, node * 2 + 2);
		return q1 + q2;
	}
	int query(int l, int r) {
		return query(0, n - 1, l, r, 0);
	}
	void update(int index, int val) {
		update(0, n - 1, index, val, 0);
	}
} tree;

bool chkcow(ll n, vector<ll> &a, ll k, ll mis) {
	ll sum = 0;
	for (ll i = 0; i < n; i++) {
		if (a[i] > mis)
			sum += a[i] - mis;
		if (sum >= k)
			return true;
	}


	return false;
}
struct cmp {
	bool operator() (const pair<ll, ll> &a, const pair<ll, ll> &b )const
	{
		ll lena = a.S - a.F;
		ll lenb = b.S - b.F;
		if (lena == lenb)
			return a.F < b.F;
		return lena > lenb;
	}
};
string solve(ll a[], ll k, ll n) {
	bool dp[k + 1]; memset(dp, 0, sizeof dp);
	for (ll i = 1; i <= k; i++) {
		for (int x = 0; x < n; x++) {
			if (a[x] <= i) {
				if (dp[i - a[x]] == 0)
					dp[i] = 1;
			}
		}
	}
	return dp[k] ? "First" : "Second";
}


int32_t main()
{	fast

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif

	ll n, k;
	cin >> n >> k;
	ll a[n];
	for (ll i = 0; i < n; i++)
		cin >> a[i];

	cout << solve(a, k, n)<<endl;

	return 0;

}

Measured memory_bytes: 24960
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    if ((b-a) % 2 == 0){
        cout << (b-a)/2 << endl;
    }
    else {
        ll ans = 0;
        if (b-1 < n-a){
            ans += a-1;
            ans++;
            b -= ans;
            ans += (b-1)/2;
        }else{
            ans += n-b;
            ans++;
            a += ans;
            ans += (n-a)/2;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
import static java.lang.Integer.MAX_VALUE;
import static java.lang.Integer.MIN_VALUE;
import static java.lang.Integer.parseInt;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * Sport Meet
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("0")) {

			int[][] min = { { 0, MAX_VALUE }, { 0, MAX_VALUE } };
			int[][] max = { { 0, MIN_VALUE }, { 0, MIN_VALUE } };
			int n = Integer.parseInt(line);
			for (int i = 0; i < n; ++i) {
				line = br.readLine();
				int team = parseInt(line.substring(0, line.indexOf(' ')));
				int sec = seconds(line.substring(line.indexOf(' ') + 1));

				//
				if (sec < min[0][1]) {
					min[1][0] = min[0][0];
					min[1][1] = min[0][1];
					min[0][0] = team;
					min[0][1] = sec;
				} else if (sec > min[0][1] && sec < min[1][1]) {
					min[1][0] = team;
					min[1][1] = sec;
				}
				//
				if (sec > max[0][1]) {
					max[1][0] = max[0][0];
					max[1][1] = max[0][1];
					max[0][0] = team;
					max[0][1] = sec;
				} else if (sec < max[0][1] && sec > max[1][1]) {
					max[1][0] = team;
					max[1][1] = sec;
				}
			}
			System.out.print(String.format("%d\n%d\n%d\n", min[0][0],
					min[1][0], max[1][0]));
		}

	}

	static int seconds(String info) {
		StringTokenizer st = new StringTokenizer(info);
		int min = 0, sec = 0;
		for (int i = 0; i < 8; ++i) {
			if (i % 2 == 0) {
				min += parseInt(st.nextToken());
			} else {
				sec += parseInt(st.nextToken());
			}
		}
		return min * 60 + sec;
	}

}

Measured memory_bytes: 30084
import java.util.*;
import java.util.Collections;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    StringBuilder sb = new StringBuilder(S);
    int cnt = 0;
    for (int i = 0; i < S.length(); i++) {
      sb.deleteCharAt(sb.length() - 1);
      String formar = sb.substring(0, sb.length() / 2);
      String latter = sb.substring(sb.length() / 2, sb.length());
      if (formar.equals(latter)) {
        System.out.println(sb.length());
        break;
      }
    }
  }
}


Measured memory_bytes: 22740
H, W = map(int,input().split())
N = int(input())
ans = [[0]*W for _ in range(H)]
A = [int(i) for i in input().split()]
hpos = 0
wpos = 0
apos = 0
cnt = 0
while True:
  while cnt<A[apos]:
    ans[hpos][wpos] = apos+1
    if hpos%2 == 0:
      wpos += 1
      if wpos == W:
        hpos += 1
        wpos = W-1
    else:
      wpos -= 1
      if wpos == -1:
        hpos += 1
        wpos = 0
    cnt += 1
  cnt = 0
  apos += 1
  if hpos == H:
    break
for i in range(H):
  print(*ans[i])

Measured memory_bytes: 3952
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long k = sc.nextLong()+1;
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = Math.max((k-a)/2 , 0);
        System.out.println(b-2 > a ? a + (b-a)*c + (k-a)%2 : k);
    }
}


Measured memory_bytes: 21968
N = int(input())
h = list(map(int, input().split()))
INF = 10 ** 9

dp = [INF] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N): 
    dp1 = dp[i - 1] + abs(h[i] - h[i - 1])
    dp[i] = min(dp[i], dp1)
    dp2 = dp[i - 2] + abs(h[i] - h[i - 2])
    dp[i] = min(dp[i], dp2)

print(dp[-1])

Measured memory_bytes: 13976
#include <iostream>
using namespace std;
 
int main(){
    int a,b;
    cin >> a >> b;
    while (a != 0 && b != 0){
        for(int i = 0; i < a; i++){
            for(int j = 0; j < b; j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
        cin >> a >> b;
    }
     
}


Measured memory_bytes: 3068
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

int N;
char S[200005][20];
set<string> st;
signed main(){
    scanf("%lld",&N);
    rep(i,N){
        scanf("%s",S[i]);
        string str=S[i];
        st.insert(str);
    }
    int ans=st.size();
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 22844
N=int(input())
lamps=[]
for a in range(N):
    _=int(input())
    lamps.append(_)
lamps.insert(0,"aaa")

PressedButtons=[False]*int(N+1)

a=1
count=0

if lamps.count(2)==0:
    print("-1")
    exit()

while PressedButtons[a]==False :
    PressedButtons[a]=True
    count+=1
    a=lamps[a]
    if a==2:
        print(count)
        exit()
print('-1')

Measured memory_bytes: 7960
N = int(input())
P = list(map(int, input().split()))

m = []
for i, p in enumerate(P):
    if i+1 == p:
        m.append(True)
    else:
        m.append(False)

# print(m)

double = 0
flag = False
for mi in m:
    if mi:
        if flag:
            double += 1
            flag = False
        else:
            flag = True
    else:
        flag = False

single = m.count(True) - 2 * double
# print(single, double)
print(single+double)

Measured memory_bytes: 13880
#include<iostream>
using namespace std;
string s1,s2,s3;
char c1,c2,c3;
int main(){
  cin>>s1>>s2>>s3;
  c1=toupper(s1[0]);
  c2=toupper(s2[0]);
  c3=toupper(s3[0]);
  cout<<c1<<c2<<c3<<endl;
}

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

using namespace std;

int main() {
    long S;
    cin >> S;
    long sum = 0;
    string origin = to_string(S);
    string str = to_string(S);
    int n = str.size() - 1;
    for (int bit = 0; bit < (1<<n); ++bit) {
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (bit & (1<<i)) {
                int p = i - count;
                sum += stol(str.substr(0, p + 1));
                str.erase(str.begin(), str.begin()+p+1);
                count += p + 1;
            }
        }
        if (str.size() != 0){
            sum += stol(str);
        }
        str = origin;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import numpy as np
from sys import stdin


def main() -> None:
    global N, M, A, B
    N = next_int()
    M = next_int()
    A = np.array([input() for _ in range(N)])
    B = np.array([input() for _ in range(M)])

    ans = "No"
    for Ni in range(N):
        for Nj in range(N):
            if judge(Ni, Nj):
                ans = "Yes"
                break
        if ans == "Yes":
            break
    print(ans)


def judge(ni: int, nj: int) -> bool:
    for i in range(M):
        for j in range(M):
            if ni + i >= N or nj + j >= N:
                return False
            if B[i][j] != A[ni + i][nj + j]:
                return False
    return True


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 12516
#include<iostream>
#include<math.h>
 using namespace std ;
 int main()
{
short int a,b,c,d;

cin>>a;
cin>>b;
cin>>c;
cin>>d;
if((abs(c-a))<=d) cout<< "Yes";
else
 if((abs(c-b)<=d)&& ( abs(b-a)<=d) ) cout<< "Yes";
else
cout<< "No";




}
   
    

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

using namespace std;

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

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

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

    int ans = 0;

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

    cout << ans << endl;
}

Measured memory_bytes: 256
S = input()

def palin(s):
    t = s[::-1]
    if s == t:
        return True
    else:
        return False

N = len(S)
h = (N-1)//2
S1 = S[0:h]
S2 = S[h+1:N]
if palin(S) and palin(S1) and palin(S2):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define line printf("-----------------------------\n")
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
ll n;
int   main()
{
        scanf("%lld",&n);
        ll mini=LLONG_MAX;
       for(int i=0;i<5;i++)
       {
           ll  x;
           scanf("%lld",&x);
           mini=min(mini,x);
       }
       ll ans=5;
       if(mini>=n) printf("%d",ans);
       else{

       ans+=(n-mini-1)/mini;
       ans+=1;
       printf("%lld",ans);
       }
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/15  Problem: 051_abc_d / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N,M;

LL ans = 0LL;

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

	cin >> N>>M;
	VVI d(N, VI(N, INF));
	vector<pair<PII, int>>edge;
	FOR(i, 0, M) {
		int a, b, c; cin >> a >> b >> c;
		a--, b--;
		d[a][b] = d[b][a] = c;
		edge.push_back(pair<PII, int>(PII(a, b), c));
	}
	FOR(i, 0, N)d[i][i] = 0;
	FOR(k, 0, N)FOR(i, 0, N)FOR(j, 0, N) {
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	}

	FOR(i, 0, M) {
		int s, t, c;
		auto a = edge[i];
		s = a.first.first;
		t = a.first.second;
		c = a.second;
		int nouse = 1;
		FOR(j, 0, N) {
			FOR(k, 0, N) {
				if (d[j][k] == d[j][s] + c + d[t][k])nouse = 0;
			}
		}
		ans += nouse;

	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<deque>
#include<list>
#include<queue>
#include<stack>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<complex>
#include<cmath>
#include<limits>
#include<cassert>
#include<bitset>
#include<numeric>
#include<functional>

using namespace std;

vector<int> A, memo;
int n;
const int INF = int(1e9);
int ans;
bool flag;

int dfs(int i){
  if (memo[i] != -1)
    return memo[i];

  int res = 0;
  for (int j = 0; j < n; j++){
    if (!((i >> j) & 1))
      continue;
    res += dfs(i ^ (1 << j));
    if (res < 0)
     res = -INF;
  }

  if (A[i] == 0 and res > 0) {
    res = -INF;
    flag = true;
  }

  if (A[i] == 1 and res == 0) {
    ans += 1;
    res = 1;
  }


  return memo[i] = res;
} 

int main(){
  flag = false;
  cin >> n;
  int m = 1 << n;
  A.resize(m);
  memo.resize(m, -1);
  for (auto &a: A) cin >> a;

  dfs(m - 1);
  if(flag) cout << -1 << endl; 
  else cout << ans << endl;
}



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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W;
string S[50];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	FOR(y,H) cin>>S[y];
	FOR(y,H) FOR(x,W) if(S[y][x]=='.') {
		int num=0;
		for(int y2=max(0,y-1);y2<=min(H-1,y+1);y2++) {
			for(int x2=max(0,x-1);x2<=min(W-1,x+1);x2++) {
				if(S[y2][x2]=='#') num++;
			}
		}
		S[y][x]='0'+num;
	}
	FOR(y,H) cout<<S[y]<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}

bool isprime(int n){
    if(n==2){
        return true ;
    }
    else if(n<2 || n%2==0){
        return false ;
    }
    else{
        int i = 3 ;
        while(i<=sqrt(n)){
            if(n%i==0){
                return false ;
            }
            i += 2 ;
        }
        return true ;
    }
}


//-------------------------------------------------
// メモ
/*






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


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n ;
  cin >> n ;
  if(isprime(n)){
    cout << n <<endl ;
  }
  else{
    int i = n+1 ;
    while(1){
    if(isprime(i)){
      cout << i <<endl ;
      return 0 ;
    }
    else{
      i++ ;
    }
    }
  }
  
  
  
  
  return 0 ;
}




Measured memory_bytes: 256
n,m = map(int, input().split())
ans = 0
L = 1
R = n
for i in range(m):
    l,r = map(int, input().split())
    L = max(l,L)
    R = min(r,R)
    
if L <= R:
    print(R-L+1)
else:
    print(0)

Measured memory_bytes: 3188
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

const INF = 10000000000000000

func main() {
	var s string
	fmt.Scan(&s)
	n := len(s)
	ans := INF
	for i := 0; i < n-1; i++ {
		if s[i] != s[i+1] {
			ans = min(ans, max(i+1, n-1-i))
		}
	}

	if ans == INF {
		ans = n
	}

	fmt.Println(ans)

}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    int K;
    cin >> S >> K;
    rep(i,0,S.size()){
        int cnt = ('z' - S[i] + 1) % 26;
        if(cnt <= K){
            K -= cnt;
            S[i] = 'a';
        }
    }
    S.back() += K % 26;
    if(S.back() > 'z')S.back() -= 26;
    cout << S << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

int main() {
    int H, W, N;
    
    scanf("%d", &H);
    scanf("%d", &W);
    scanf("%d", &N);
    
    if(W>=H){
    for(int i=1;i<=H;i++){
        if (W*i>=N) {
            printf("%d", i);
            return 0;
        }
    }
} else {
    for(int i=1;i<=W;i++){
        if (H*i>=N) {
            printf("%d", i);
            return 0;
        }
    }
}
    return 0;
}

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

using namespace std;

void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    if(b-a == c-b){
        cout<<"YES";
    }else
    {
        cout<<"NO";
    }
    

}

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

Measured memory_bytes: 256
//use itertools::Itertools;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        m: usize,
        edge: [(usize1,usize1);m]
    }

    let mut tree = vec![vec![]; n];
    for (e, &(from, to)) in edge.iter().enumerate() {
        tree[from].push((to, e));
        tree[to].push((from, e));
    }

    let mut shirube = vec![0; n];

    let mut q: VecDeque<usize> = VecDeque::new();
    q.push_back(0);
    while q.len() > 0 {
        let target = q.pop_front().unwrap();

        for &(v, e) in &tree[target] {
            if shirube[v] > 0 {
                continue;
            }

            shirube[v] = target + 1;
            q.push_back(v);
        }

        //println!("{:?}", q);
        //println!("{:?}", shirube);
    }

    println!("Yes");

    for i in 1..n {
        println!("{}", shirube[i]);
    }
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 17948