akhauriyash/Code-Regression huggingface dataset:
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

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

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

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

	N, A, B := getInt(), getInt(), getInt()
	vmax := 0
	h := make([]int, N)
	for i := 0; i < N; i++ {
		h[i] = getInt()
		if vmax < h[i] {
			vmax = h[i]
		}
	}

	r := 0x7FFFFFFF
	l := 0
	diff := A - B
	for l+1 < r {
		mid := (l + r) / 2
		dmg := B * mid
		ex := 0
		f := true
		for i := 0; i < N; i++ {
			if h[i] > dmg {
				d := h[i] - dmg
				ex += (d + diff - 1) / diff
			}
			if ex > mid {
				f = false
				break
			}
		}
		if f {
			r = mid
		} else {
			l = mid
		}
	}

	out(r)
}


Measured memory_bytes: 3072
N, A, B = input().strip().split()

N, A, B = int(N), int(A), int(B)

S = input().strip()

passed = 0
foreign = 0
for s in S:
    if s == "c":
        print("No")
    elif s == "a":
        if passed < A+B:
            print("Yes")
            passed += 1
        else:
            print("No")
    elif s == "b":
        if passed < A+B and foreign < B:
            passed += 1
            foreign += 1
            print("Yes")
        else:
            print("No")

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if((a<= c && c <= b) || (b <= c && c <= a)){
    cout << "Yes" << endl;
  }else cout << "No" << endl;
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

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

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

const int SIZE = 2000+10;
ll h, w;
string s[SIZE];
ll mem[SIZE][SIZE];


int main(){
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        cin >> s[i];
    }

    ll st, cou = 0;
    for(int i = 0; i < h; i++){
        cou = 0;
        for(int j = 0; j < w; j++){
            if(s[i][j] == '#'){
                if(cou != 0){
                    for(int k = st; k < j; k++){
                        mem[i][k] += cou;
                    }
                }
                cou = 0;
                continue;
            }
            else{
                if(cou == 0)    st = j;
                ++cou;
            }
        }
        if(cou != 0){
            for(int k = st; k < w; k++){
                mem[i][k] += cou;
            }
        }
    }

    for(int i = 0; i < w; i++){
        cou = 0;
        for(int j = 0; j < h; j++){
            if(s[j][i] == '#'){
                if(cou != 0){
                    for(int k = st; k < j; k++){
                        mem[k][i] += cou;
                    //    cout << k << ' ' << i << ' ' << cou << endl;
                    }
                }
                cou = 0;
                continue;
            }
            else{
                if(cou == 0)    st = j;
                ++cou;
            }
        }
        if(cou != 0){
            for(int k = st; k < h; k++){
                mem[k][i] += cou;
                //cout << k << ' ' << i << ' ' << cou << endl;
            }
        }
        cou = 0;
    }

    ll ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            --mem[i][j];
           // cout << mem[i][j] << ' ';
            if(ans < mem[i][j])    ans = mem[i][j];
        }
       // cout << endl;
    }

    cout << ans << endl;
}

Measured memory_bytes: 35712
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define L(i,n) for(int i=0;i<n;i++)
#define ll   long long 
#define endl '\n'   
using namespace std;
const int N = 1e5 + 5;
int  t; 
int  a[N], b[N], c[N];
int main()
{
	IO
	   	cin >> t;
	    for (int i = 0; i < t; i++)
		cin >> a[i];
		for (int i = 0; i < t; i++)
		cin >> b[i];
		for (int i = 0; i < t; i++)
		cin >> c[i];
		sort(a, a + t);
		sort(c,c + t);
		ll sum = 0; 
		for (int i = 0; i < t; i++)
		{
			auto it = upper_bound(a, a + t, b[i]-1) - a;
			auto ij = upper_bound(c, c + t, b[i]) - c;
			ij = t - ij; 
			
			sum += (ll)it*ij;
		}
		cout << sum << "\n"; 

}

Measured memory_bytes: 4368
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		int l = 0;
		for(int i = 0; i < S.length(); i++) {
			if(S.charAt(i) == 'A') {
				l = i;
				break;
			}
		}
		int r = 0;
		for(int i = S.length() - 1; i >= 0; i--) {
			if(S.charAt(i) == 'Z') {
				r = i;
				break;
			}
		}
		System.out.println(r- l + 1);
	}
}

Measured memory_bytes: 26040
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
const int N = 100005;
using namespace std;

int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n,k,ans = -1;
  cin >> n >> k;
  vector<int>v(n);
  for (int i = 0; i < n; ++i)
  {
    cin >> v[i];
  }
  sort(all(v));
  for (int i = 0; i < n; ++i)
  {
    if(v[i] >= k)
    {
      ans = i;
      break;
    }

  }
  if (ans != -1)
    cout << n-ans;
  else
    cout << 0;  
  return 0;
}


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

typedef long long ll;

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

	s += t[t.size() - 1];

	if (s == t)
	{
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
}

Measured memory_bytes: 3572
N = int(input())

task = []

for n in range(N):
    a,b = map(int,input().split())
    task.append((b,a))

task.sort()

T = 0

for i in range(N):
    b = task[i][0]
    a = task[i][1]

    T+= a
    if T>b:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 29456
import sys
sys.setrecursionlimit(2 ** 20)

class Node():
    def __init__(self, parent=None, left=None, right=None):
        self.parent = parent
        self.left = left
        self.right = right

    def __repr__(self):
        return '<Node object: parent={}, left={}, right={}>' .format(self.parent, self.left, self.right)


def set_depth(u, p):
    D[u] = p
    if not T[u].right is None:
        set_depth(T[u].right, p)
    if not T[u].left is None:
        set_depth(T[u].left, p+1)


def get_children(u):
    res = []
    c = T[u].left
    while c is not None:
        res.append(c)
        c = T[c].right
    return res


def get_type(node):
    if node.parent is None:
        return 'root'
    elif node.left is None:
        return 'leaf'
    else:
        return 'internal node'


def get_parent(node):
    return -1 if node.parent is None else node.parent


n = int(input())
T = [Node() for i in range(n)]
for _ in range(n):
    line = list(map(int, input().split()))
    i, k = line[:2]
    if k:
        T[i].left = line[2]
        prev = None
        for c in line[2:]:
            T[c].parent = i
            if prev:
                T[prev].right = c
            prev = c

D = [0] * n
for i in range(n):
    if T[i].parent is None:
        set_depth(i, 0)
        break

for i in range(n):
    print('node {}: parent = {}, depth = {}, {}, {}'.format(
        i, get_parent(T[i]), D[i], get_type(T[i]), get_children(i)))


Measured memory_bytes: 125952
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

using Edge = int; //頂点
using Graph = vector<vector<Edge>>;
Graph G;
void rec(const Graph &G, int current, int parent, long long sum,
         vector<long long> &dist) {
    dist[current] = sum;
    //木なので親では無かったら子供でしかない
    for(auto child : G[current]) {
        // cout << current << parent << endl;
        if(child == parent) {
            continue;
        } else {
            rec(G, child, current, sum + 1, dist);
        }
    }
}

int main() {
    long long N;
    cin >> N;
    G.resize(N);
    vector<long long> a(N - 1), b(N - 1);
    REP(i, N - 1) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    vector<long long> adist(N, 0);

    rec(G, 0, -1, 0, adist);

    vector<long long> Ndist(N, 0);
    rec(G, N - 1, N, 0, Ndist);

    long long cnt = 0;
    REP(i, N) {
        if(adist[i] <= Ndist[i]) {
            cnt++;
        }
    }
    if(cnt > N - cnt) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }
    return 0;
}

Measured memory_bytes: 16640
#include <iostream>
#include <vector>
using namespace std;
#define ll long long

ll dp[3005];

int main()
{
	ll n;
	cin >> n;
	vector<ll> num(n);
	for (int i = 0; i < n; ++i) {
		cin >> num[i];
	}
	for (int i = 0; i < n; ++i) {
		for (int j = i; j >= 0; --j) {
		    if (j == i) {
		    	dp[j] = num[i];
		    } else {
		    	dp[j] = max(num[i] - dp[j], num[j] - dp[j + 1]);
		    }
		}
	}
	cout << dp[0] << endl;
	return 0;
}


Measured memory_bytes: 3648
# ARC064c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 6)

    n, x = map(int, input().split())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(n - 1):
        ooi = a[i] + a[i + 1] - x
        #print(i, ooi)
        if ooi > 0:
            before = a[i + 1]
            #print(i, 'before', a[i + 1])
            a[i + 1] = max(0, a[i + 1] - ooi)
            #print(i, 'after', a[i + 1])
            ans += before - a[i + 1]
            #print(i, 'ans', ans)

            ooi = a[i] + a[i + 1] - x
            if ooi > 0:
                before = a[i]
                a[i] = max(0, a[i] - ooi)
                ans += before - a[i]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 59632
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cassert>
#include <string>
#define SIZE 400005
#define BT 62

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int A[SIZE];
ll nxt[SIZE][BT];
bool use[SIZE];
int last[SIZE];
int st[SIZE];

int main()
{
	int n;
	ll K;
	scanf("%d %lld",&n,&K);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
		A[i]--;
	}
	for(int i=2*n-1;i>=0;i--)
	{
		int a=A[i%n];
		if(i<n) nxt[i][0]=last[a]-i+1;
		last[a]=i;
	}
	//for(int i=0;i<n;i++) printf("%lld ",nxt[i][0]);puts("");
	ll all=(ll) n*(ll) K;
	for(int i=0;i+1<BT;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(nxt[j][i]>all)
			{
				nxt[j][i+1]=all+1;
			}
			else
			{
				ll to=(ll) j+nxt[j][i];
				to%=n;
				nxt[j][i+1]=nxt[to][i]+nxt[j][i];
				nxt[j][i+1]=min(nxt[j][i+1],all+1);
			}
		}
	}
	ll now=0;
	for(int i=BT-1;i>=0;i--)
	{
		ll vl=nxt[now%n][i];
		//if(i<=3) printf("%lld : %lld %lld\n",all,now,vl);
		if(now+vl<all) now+=vl;
	}
	//printf("%lld\n",now);
	int sz=0;
	memset(use,false,sizeof(use));
	while(now<all)
	{
		int v=(int) (now%n);
		if(!use[A[v]])
		{
			use[A[v]]=true;
			st[sz++]=A[v];
		}
		else
		{
			while(1)
			{
				sz--;
				int x=st[sz];
				use[x]=false;
				if(x==A[v]) break;
			}
		}
		now++;
	//for(int i=0;i<sz;i++) printf("%d ",st[i]+1);puts("");
	}
	for(int i=0;i<sz;i++) printf("%d ",st[i]+1);puts("");
	return 0;
}


Measured memory_bytes: 105088
#include <iostream>
#include <algorithm>
using namespace std;

const int MAX = 100000;

class BIT {
public:
	BIT(int n) {
		size = n + 1;
		bit = new int[size];

		for (int i = 0; i < size; i++)bit[i] = 0;
	}
	~BIT() {
		delete[] bit;
	}

	void add(int i, int n) {
		i += 1;
		while (i < size) {
			bit[i] += n;
			i += i & -i;
		}
	}

	int sum(int i) {
		i += 1;
		int ret = 0;
		while (i) {
			ret += bit[i];
			i -= i & -i;
		}
		return ret;
	}
	int size;
	int* bit;
};

int N;
int a[MAX];

bool solve(int x) {
	long long cnt = 0;
	int sum = 0;
	BIT bit(N * 2);

	for (int i = 0; i < N; i++) {
		sum += a[i] >= x ? 1 : -1;
		cnt += bit.sum(N + sum) + (sum >= 0 ? 1 : 0);
		bit.add(N + sum, 1);
	}

	if (cnt >= ((long long)N * (N + 1) / 2) / 2)return true;
	return false;
}

int main() {
	cin >> N;
	int begin = 0;
	int end = 0;
	int ans = 0;

	for (int i = 0; i < N; i++) {
		cin >> a[i];
		end = max(end, a[i] + 1);
	}

	if (N == 1)ans = a[0];
	else {
		while (begin < end) {
			int mid = (begin + end) / 2;

			if (solve(mid)) {
				ans = mid;
				begin = mid + 1;
			}
			else {
				end = mid;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1420
#include <stdio.h>

int main(void)
{
    int W, H, x, y, r;
    
    scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
    
    if (r <= x && x <= (W - r) && r <= y && y <= (H - r)){
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    
    return (0);
}



Measured memory_bytes: 2104
using System;
using System.Collections.Generic;
// using System.Globalization;
// using System.IO;
using System.Linq;
// using System.Text;
// using System.Text.RegularExpressions

class Program
{
    static void Main()
    {
        string S = Console.ReadLine();
        HashSet<char> hs = new HashSet<char>(S);
        if (hs.Count() != 2) Console.WriteLine("No");
        else
        {
            int cnt = 0;
            foreach (char c in hs) if (S.Count(x => x == c) == 2) cnt++;
            if (cnt == 2) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
        return;
    }
}

Measured memory_bytes: 26628
macro_rules! input {
  ($($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 main() {
  let stack_size = 104_857_600;
  let thd = std::thread::Builder::new().stack_size(stack_size);
  thd.spawn(|| work()).unwrap().join().unwrap();
}

fn work() {
  input! {
    n: usize,
    a: [f64; n],
  }
  let mut t = 0f64;
  for x in a {
    t += 1.0 / x;
  }
  print!("{}\n", 1.0 / t);
}


Measured memory_bytes: 8572
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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(){
    ll n;cin >>n;
    map<ll,ll> mp;
    rep(i,n){
        ll a;cin >> a;
        mp[a]++;
    }
    if(mp.size()>2)cout <<"No" <<endl,exit(0);
    if(mp.size()==1){
        ll t;
        for(auto p:mp)t=p.fi;
        if(t==n-1||t<=n/2)cout <<"Yes" <<endl;
        else cout <<"No" <<endl;
    }
    else{
        vpl v;
        for(auto x:mp){
            v.pb(x);
        }
        if(v[0].fi+1!=v[1].fi)cout <<"No" <<endl,exit(0);
        ll a=v[1].fi,x=v[0].se;
        if(a-x>=1&&x+2*(a-x)<=n)cout <<"Yes" <<endl;
        else cout <<"No" <<endl;
    }
}

Measured memory_bytes: 6528
import sys
from collections import deque
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
K = I()
a = IL()

ans = 0
for i in range(N):
  ans += min(a[i], K-a[i])*2
print(ans)

Measured memory_bytes: 38304
#include<bits/stdc++.h>
using namespace std;
#define INS(x) (x).begin(),(x).end()
#define gcd(x,y) __gcd((x),(y))



int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    long long x;
    cin>>x;

    for (int i=0;i<=1000;i++)
        for (int j=0;j<=1000;j++)
        {
            long long res1=pow(i,5)+pow(j,5),res2=pow(i,5)-pow(j,5);
            if (res1==x) {cout<<i<<' '<<-j<<'\n'; return 0;}
            if (res2==x) {cout<<i<<' '<<j<<'\n'; return 0;}
        }
    
    return 0;
}

Measured memory_bytes: 4120
# import numpy as np

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

S = [None] * H
# ans = np.zeros((H, W))
ans = [[0 for j in range(W)] for i in range(H)]

for i in range(H):
    s_tmp = [-1] * W
    s = input()
    for j, c in enumerate(s):
        if c == "#":
            s_tmp[j] = 1
        else:
            s_tmp[j] = 0
    S[i] = s_tmp

max_tmp = 0
coord = (-1, -1)
for i in range(H):
    # 左から右
    tmp = 0
    for j in range(W):
        if S[i][j] == 1:
            tmp = 0
        else:
            tmp += 1
        # ans[i, j] += tmp
        ans[i][j] += tmp
    # 右から左
    tmp = 0
    for j in reversed(range(W)):
        if S[i][j] == 1:
            tmp = 0
        else:
            tmp += 1
        # ans[i, j] += tmp
        ans[i][j] += tmp

# 右から左
for i in range(W):
    # 上から下
    tmp = 0
    for j in range(H):
        if S[j][i] == 1:
            tmp = 0
        else:
            tmp += 1
        # ans[j, i] += tmp
        ans[j][i] += tmp
    # 下から上
    tmp = 0
    for j in reversed(range(H)):
        if S[j][i] == 1:
            tmp = 0
        else:
            tmp += 1
        # ans[j, i] += tmp
        ans[j][i] += tmp
        # if ans[j, i] > max_tmp:
        if ans[j][i] > max_tmp:
            # max_tmp = ans[j, i]
            max_tmp = ans[j][i]
            coord = (j, i)

score = 1

tmp_x = coord[1]
while True:
    tmp_x -= 1
    if tmp_x < 0:
        break
    if S[coord[0]][tmp_x] == 0:
        score += 1
    else:
        break
tmp_x = coord[1]
while True:
    tmp_x += 1
    if tmp_x >= W:
        break
    if S[coord[0]][tmp_x] == 0:
        score += 1
    else:
        break
tmp_y = coord[0]
while True:
    tmp_y -= 1
    if tmp_y < 0:
        break
    if S[tmp_y][coord[1]] == 0:
        score += 1
    else:
        break
tmp_y = coord[0]
while True:
    tmp_y += 1
    if tmp_y >= H:
        break
    if S[tmp_y][coord[1]] == 0:
        score += 1
    else:
        break

print(score)


Measured memory_bytes: 115036
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N, an = 1,b=1;
	cin >> N;
	rep(i, N) {
		ll A;
		
		cin >> A; 
		ll k = (an % 10000) * (A % 10000);
		an *= A;
		if (an%10000!=k%10000||an < 0|| an > 1000000000000000000) {
			b = -1;
		}
		if (A == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	if (b==-1) {
		cout << -1 << endl;
		return 0;
	}
	cout << an << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
const int N=8005,M=205,mod=998244353,G=3,Gi=(mod+1)/3;
inline int read(){
    int s=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
    while(isdigit(ch)) s=s*10+ch-'0',ch=getchar();
    return s*f;
}
inline int pls(int a,int b){a+=b;return a>=mod?a-mod:a;}
inline int dec(int a,int b){a-=b;return a<0?a+mod:a;}
inline int mul(int a,int b){return 1ll*a*b%mod;}
inline int qpow(int a,int b){
	int res=1;
	for(;b;b>>=1,a=mul(a,a)) if(b&1) res=mul(res,a);
	return res;
}
int n,m,bit=2,rev[N<<2];
int a[N<<2],b[N<<2];
int inv[N],fac[N],f[N];

inline void init(){
	fac[0]=1;
	for(int i=1;i<=n+2;i++) fac[i]=mul(fac[i-1],i);
	inv[n+2]=qpow(fac[n+2],mod-2);
	for(int i=n+1;i>=0;i--) inv[i]=mul(inv[i+1],i+1);
}
inline int C(int n,int m){
	if(n<0||m<0||n<m) return 0;
	return mul(fac[n],mul(inv[m],inv[n-m]));
}
inline void get_rev(){
	for(int i=0;i<bit;i++) rev[i]=(rev[i>>1]>>1)|(bit>>1)*(i&1);
}
inline void ntt(int *a,int dft){
	for(int i=0;i<bit;i++) if(i<rev[i]) swap(a[i],a[rev[i]]);
	for(int i=1;i<bit;i<<=1){
		int W=qpow(dft==1?G:Gi,(mod-1)/(i<<1));
		for(int j=0;j<bit;j+=(i<<1))
			for(int k=j,w=1;k<i+j;k++,w=mul(w,W)){
				int x=a[k],y=mul(w,a[k+i]);
				a[k]=pls(x,y),a[k+i]=dec(x,y);
			}
	}
	if(dft==-1) for(int i=0,inv=qpow(bit,mod-2);i<bit;i++) a[i]=mul(a[i],inv);
}
int main(){
	scanf("%d%d",&n,&m);
	init();
	while(bit<=2*n) bit<<=1;
	get_rev();
	for(int i=1;i<=n;i++) b[i]=inv[i+2];
	ntt(b,1);
	f[0]=1;a[0]=1;
	for(int i=1;i<=m;i++){
		ntt(a,1);
		for(int j=0;j<bit;j++) a[j]=mul(a[j],b[j]);
		ntt(a,-1);
		for(int j=0;j<=n;j++) {
			f[j]=pls(mul(a[j],fac[j+2]),mul(f[j],1+j+C(j,2)));
			a[j]=mul(f[j],inv[j]);
		}
		for(int j=n+1;j<bit;j++) a[j]=0;
	}
	int ans=0;
	for(int i=0;i<=n;i++) ans=pls(ans,mul(C(n,i),f[i]));
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 4080
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
    int a;
    int b;
    int d;
    int r;
    double f;
    cin >> a >> b;

    d = a / b;
    r = a % b;
    f = (double)a / (double)b;

    cout << d << " " << r << " " << fixed << setprecision(5) << f << "\n";
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

bool test(const vector<int> &ans, vector<ll> po, int m) {
    vector<int> test((int)ans.size()+1);
    rep(i,ans.size()) {
        test[i+1] = test[i]^ans[i];
    }
    vector<int> idx(2*po[m],INF);
    rep(i,ans.size()) {
        if (idx[ans[i]]==INF) idx[ans[i]] = i;
        else {
            int ret = test[i+1]^test[idx[ans[i]]];
            cout << ret << '\n';
        }
    }
}

void experiment() {
    int n,k; cin>>n>>k;
    int ret = 0;
    rep(i,n) {
        if (i==k) continue;
        ret ^= i;
    }
    cout << ret << '\n';
}

int main(int argc, char const *argv[]) {
    ll m,k; cin>>m>>k;
    vector<ll> po(20);
    int t = 1;
    rep(i,20) {
        po[i] = t;
        t *= 2;
    }
    auto ex = [](){
        cout << -1 << '\n';
        exit(0);
    };
    if (k>=po[m]) ex();
    if (m==0 && k!=0) ex();
    if (m==1 && k!=0) ex();
    if (k==0) {
        rep(i,po[m]) {
            cout << i << ' ' << i;
            if (i+1!=po[m]) cout<<' ';
            else cout << '\n';
        }
        return 0;
    }
    vector<int> x,y;
    vector<int> ans;
    ans.reserve(2*po[m]);
    for (int i = 0; i < po[m]; ++i) {
        if (i == k) continue;
        x.push_back(i);
        y.push_back(i);
    }
    sort(y.begin(), y.end(), greater<>());
    for (auto &&e: x) ans.push_back(e);
    ans.push_back(k);
    for (auto &&e: y) ans.push_back(e);
    ans.push_back(k);
    
    print(ans);
    return 0;
}

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

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

    int A[9] = {};
    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        if(tmp <= 399) A[0]++;
        else if(400 <= tmp and tmp <= 799) A[1]++;
        else if(800 <= tmp and tmp <= 1199) A[2]++;
        else if(1200 <= tmp and tmp <= 1599) A[3]++;
        else if(1600 <= tmp and tmp <= 1999) A[4]++;
        else if(2000 <= tmp and tmp <= 2399) A[5]++;
        else if(2400 <= tmp and tmp <= 2799) A[6]++;
        else if(2800 <= tmp and tmp <= 3199) A[7]++;
        else A[8]++;
    }
    int cnt = 0, min_value, max_value;
    for(int i = 0; i < 8; i++){
        if(A[i]) cnt++;
    }
    if(A[8]){
        if(cnt){
            min_value = cnt;
            max_value = cnt + A[8];
        }else{
            min_value = 1;
            max_value = A[8];
        }
    }else min_value = max_value = cnt;
    cout << min_value << " "  << max_value << endl;

    return 0;
}

Measured memory_bytes: 256
N, K = map(int, raw_input().split())
p = map(int, raw_input().split())

s = sum(p[:K])
m = s
for i in range(K, N):
  s += p[i]
  s -= p[i-K]
  m = max(m, s)
print "%.10f"%((m+K)*.5)


Measured memory_bytes: 19988
import java.util.Scanner;
import java.util.stream.IntStream;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt(),
                M = in.nextInt(),
                Q = in.nextInt();

        // memo
        int[][] train = new int[N + 1][N + 1];

        // input
        while (M-- > 0) ++train[in.nextInt()][in.nextInt()];

        // prefix sum
        int[][] psum = new int[N + 1][N + 1];

        // horizontal sum
        IntStream.rangeClosed(1, N).forEach(l ->
                IntStream.rangeClosed(1, N).forEach(r ->
                        psum[l][r] = psum[l][r - 1] + train[l][r]
                ));

        // 2D sum
        IntStream.rangeClosed(1, N).forEach(l ->
                IntStream.rangeClosed(1, N).forEach(r ->
                        psum[l][r] += psum[l - 1][r]
                ));

        // answering queries
        while (Q-- > 0) {
            int l = in.nextInt() - 1,
                    r = in.nextInt();
            System.out.println(
                    psum[r][r] + psum[l][l] - psum[l][r] - psum[r][l]
            );
        }

    }
}

Measured memory_bytes: 154760
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
    long mod = 1000000007;
    string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
		long n = long.Parse(input[0]);
		long k = long.Parse(input[1]);
	  if(k >= n) 
    {
      long answer = 1;
      for(long i = 2; i <= k; i++)
      {
        answer *= i;
        answer %= mod;
      }
      answer *= DivideModFactorial(k-n, mod);
      answer %= mod;
      Console.WriteLine(answer);
    }
    else Console.WriteLine(0);
	}

  static long DivideMod(long x, long a, long p)//戻り値はx^a(mod p)
  {
    long num = 2;
    long answer = 1;
    long check = a;
    long memo = x%p;
    
    while(check > 0)
    {
      if(check % num == num / 2)
      {
        check -= num / 2;
        answer *= memo;
        answer %= p;
      }
    memo *= memo;
    memo %= p;
    num *= 2;
    }
    return answer;
  }

  static long DivideModReverse(long x, long p)//戻り値はx^-1(mod p), pは素数
  {
    long answer = DivideMod(x, p-2, p);
    return answer;
  }

  static long DivideModFactorial(long x, long p)//戻り値はx!^-1(mod p), pは素数
  {
    long answer = 1;
    for(long i = x; i >= 2; i--)
    {
      answer *= DivideModReverse(i, p);
      answer %= p;
    }
    return answer;
  }

  static long Comb(long a, long b, long p)//戻り値は組み合わせC(a,b)のmod p
  {
    long answer = 1;
    for(long i = a; i > a-b; i--)
    {
      answer *= i;
      answer %= p;
    }
    answer *= DivideModFactorial(b, p);
    answer %= p;
    return answer;
  }
  
}



Measured memory_bytes: 15988
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>
#include <stack>
#include <set>
#include <map>
#

#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define ALLOF(c) c.begin(), c.end()
#define RANGEOF(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define EPS 1e-9
#define INF 1000000000
using namespace std;

typedef complex<int> POINT;
template <class T>
class vevector : public vector<vector<T>>
{
public:
	using vector<vector<T>>::operator []; 
	T& operator [](const POINT &index) { return (*this)[index.real()][index.imag()]; }
};

template <class T> T read() { T t; cin >> t; return t; }
template <> POINT read<POINT>() { int x, y; cin >> x >> y; return POINT(x, y); }
template <class T> vector<T> read(int n) { vector<T> v; REP(i,n) { v.push_back(read<T>()); } return v; }
template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i,n) v.push_back(read<T>(m)); return v; }
template <class T> void write(const T &t) { cout << t << endl; }
template <class T> void write(const T &t, const T &t2) { cout << t << ' ' << t2 << endl; }

template <class T> void write(const vector<T> &v)
{
	ostringstream ss; 
	for (auto x : v) ss << x << ' ';
	auto s = ss.str();
	cout << s.substr(0, s.length() - 1) << endl;
}

template <class T> string toString(const T &t) { stringstream ss; ss << t; return ss.str(); }

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__
#define countof(a) (sizeof(a)/sizeof(a[0]))

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

vector<unsigned char> isPrime;
vector<int> primes;
void initPrimes(int n)
{
	isPrime = vector<unsigned char>(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	FOR(i, 2, n)
	{
		if (!isPrime[i]) continue;
		primes.push_back(i);
		for (int j = i * 2; j <= n; j += i)
			isPrime[j] = false;
	}
}

/// template end ///

void solve()
{
	const int _coinTypes[] = { 10, 50, 100, 500 };
	const int C = countof(_coinTypes);
	const auto coinTypes = vector<int>(_coinTypes, _coinTypes + C);
	REP (testcase, INF)
	{
		READ(int, price);
		if (!price) { break; }
		if (testcase != 0) { cout << endl; }

		vector<int> wallet = read<int>(coinTypes.size());
		auto account = inner_product(ALLOF(wallet), coinTypes.begin(), 0);
		
		vector<int> charge(C);
		int totalCharge = account - price;
		RREP(i, C) { charge[i] = totalCharge / coinTypes[i]; totalCharge %= coinTypes[i]; }
		
		vector<int> payment(C);
		REP(i, C) { payment[i] = max(wallet[i] - charge[i], 0); }
		REP(i, C) { if (payment[i]) { write(coinTypes[i], payment[i]); } }
	}
}

Measured memory_bytes: 1212
def main():
    H = int(input())
    A = list(map(int,input().split()))
    for i in range(1, H+1, 1):
        key = A[i-1]
        if i != 1:
            parent_key = A[i//2 - 1]
        else:
            parent_key = None

        if (2*i) <= H:
            left_key = A[2*i-1]
        else:
            left_key = None

        if (2*i + 1) <= H:
            right_key = A[2*i]
        else:
            right_key = None

        if (parent_key is not None) and (left_key is not None) and (right_key is not None):
            print(f'node {i}: key = {A[i-1]}, parent key = {parent_key}, left key = {left_key}, right key = {right_key}, ')
        elif(parent_key is None) and (left_key is not None) and (right_key is not None):
            print(f'node {i}: key = {A[i-1]}, left key = {left_key}, right key = {right_key}, ')
        elif (parent_key is not None) and (left_key is not None) and (right_key is None):
            print(f'node {i}: key = {A[i-1]}, parent key = {parent_key}, left key = {left_key}, ')
        elif (parent_key is not None) and (left_key is None) and (right_key is None):
            print(f'node {i}: key = {A[i-1]}, parent key = {parent_key}, ')
        elif (parent_key is None) and (left_key is not None) and (right_key is None):
            print(f'node {i}: key = {A[i-1]}, left key = {left_key}, ')

main()



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

using P = pair<int, int>;// 人、真偽
int N;
vector<vector<P>> v;

//bitに対しての整合性を判断
bool judge(int bit){

    //i人目の証言を検証
    rep(i,N){

        if(!(bit&(1<<i))) continue;//そもそもi人目がfなら無視

        for(auto j : v[i]){
            int x = j.first;
            int y = j.second;

            // 1のはずなのに0だったらダメ
            if(y==1 && !(bit&(1<<x))) return false;

            // 0のはずなのに１だったらダメ
            if(y==0 && (bit&(1<<x))) return false;
        }
    }
    
    return true;
}

int main(){
    //人iが正直者かどうかを全ての場合に分け、人数の多い順に成り立つのか調べる。→bit全探索
    cin >> N;
    v.resize(N);

    rep(i,N){
        int a; cin >> a;
        v[i].resize(a);
        rep(j,a){
            cin >> v[i][j].first >> v[i][j].second;
            --v[i][j].first;//インデックスのために１下げた
        }
    }

    int res = 0;
    rep(bit,(1<<N)){
    //1<<NはN^2を表す。
        
        if(judge(bit)){
        //正しい場合は人数を数える
            int count = 0;
            rep(i,N){
                if(bit & (1 << i)) count++;
            }
            res = max(res,count);
        }
    }

    cout << res << endl;
    return 0;
}

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

int main(){
    int N;
    string ans = "";
    cin >> N;
    while(N != 0){
        if(N & 1 == 1){
            ans = '1' + ans;
            N--;
        }else{
            ans = '0' + ans;
        }
        N = - N / 2;
        //cout << N <<' ' <<ans<< endl;
    }
    if(ans == ""){
        ans = '0';
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
from collections import defaultdict
from sys import stdin

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    BC = [tuple(map(int, input().split())) for _ in [0] * M]

    a = defaultdict(int)
    for i in A:
        a[i] += 1
    for b, c in BC:
        a[c] += b
    a = sorted(a.items(), key=lambda x: x[0], reverse=1)

    ans = 0
    for i, j in a:
        n = min(N, j)
        ans += n * i
        N -= j
        if N <= 0:
            break
    print(ans)

input = lambda: stdin.readline()
main()


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  int N,M,X;
  cin>>N>>M>>X;
  vector<int> key(M);
  cinv(key,0,M);
  sort(key.begin(),key.end());
  int res=0;
  FOR(i,0,M){
    if(key[i]<X) res++;
  }
  if(res<=M/2){
    cout<<res<<endl;
  }
  else cout<<M-res<<endl;
}


Measured memory_bytes: 256
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

result = min(a)+min(b)
for _ in range(M):
    x, y, c =map(int, input().split())
    t = a[x-1]+ b[y-1]-c
    if t < result:
        result = t
print(result)

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

int pos(const int p) {
	return p + 8001;
}

bool now[16010], next_pos[16010];
void search(const string s) {
	int move = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'T') {
			//cout << move << " =move" << endl;
			for (int j = -8000; j < 8001; j++) {
				if (now[pos(j)]) {
					next_pos[pos(j + move)] = true;
					next_pos[pos(j - move)] = true;
				}
			}
			move = 0;
			copy(next_pos, next_pos + 16010, now);
			fill(next_pos, next_pos + 16010, false);
			//for (int ii = -3; ii< 4; ii++) {
			//	cout << now[pos(ii)] << "    " << ii << endl;
			//}
		}
		else {
			move++;
		}
	}
}

int main() {
	string s,sx="",sy="T";
	int x, y;
	cin >> s >> x >> y;
	bool x_axis = true;
	for (auto &itr : s) {
		if (x_axis) {
			sx += itr;
		}
		else {
			sy += itr;
		}
		if (itr == 'T') {
			x_axis = !x_axis;
		}
	}
	//cout << sx << endl << sy << endl;
	sx = sx + 'T';
	sy = sy + 'T';
	//deque<pair<int,int>>pos, next_pos;
	//pos.push_back(make_pair(0,1));
	//for (auto &itr : sx) {
	//	while (!pos.empty()) {
	//
	//	}
	//}
	now[pos(0)] = true;
	search(sy);
	if (now[pos(y)] == false) {
		cout << "No" << endl;
		return 0;
	}
	fill(now, now + 16010, false);
	int movex = 0;
	for (int i = 0; i < sx.size(); i++) {
		if (sx[i] == 'T') {
			now[pos(movex)] = true;
			sx = sx.substr(i + 1);
			break;
		}
		else {
			movex++;
		}
	}
	search(sx);
	if (now[pos(x)] == false) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define ld double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD =1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1LL;}return res%p;}
const int N=1e6+2,M=1e6+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	// freopen("out10.txt","w",stdout);
	#endif
	int k;
	cin>>k;
	vector<int> fac;
	for(int i=1;i*i<=k;i++)
	{
		if(k%i==0)
		{
			if(i!=1)
			fac.pb(i);
			if(k/i!=i)
			{
				if(k/i!=1)
				fac.pb(k/i);
			}
		}
	}
	set<int> ans; 
	for(int i=0;i<fac.size();i++)
	{
		// cout<<fac[i]<<" ";
		int cnt=0;
		int val=k;
		while(val%fac[i]==0)
		{
			val/=fac[i];
		}
		val-=1;
		if(val>=0&&val%fac[i]==0)
		{
			ans.insert(fac[i]);
		}
	}
	k--;
	fac.clear();
	for(int i=1;i*i<=k;i++)
	{
		if(k%i==0)
		{
			if(i!=1)
			fac.pb(i);
			if(k/i!=i)
			{
				if(k/i!=1)
				fac.pb(k/i);
			}
		}
	}
	for(auto x:fac)
	{
		if((k+1)%(x)!=0)
		{
			ans.insert(x);
		}
	}
	// for(auto x:ans)
	// {
	// 	cout<<x<<" ";
	// }
	cout<<ans.size();

}
// (1+(o)*k)*(k^m) = n
// 
// Don't be afraid to fail. Be afraid not to try.
// "Become grindian instead of greendian" - aryanc403
// When you want to succeed as bad as you want to breathe, only then you’ll Be Successful!
// No Matter,How Fast You Are Driving If You Are Driving in a Wrong Direction You Will Never Reach Your Destination
// When failures hit you, you hit the failures back with Bounce Back!
// When you face failures, Don’t change your goal, Change your strategy!

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

int main(){
string S;
  cin>>S;
  
  string ans;
  for(int i=0; i<S.size(); i++){
   if(S[i]=='0' || S[i]=='1'){ans.push_back(S[i]);}
   else if(ans.size()>=1){ans.pop_back();} 
  }
 
  cout<<ans;
 }

Measured memory_bytes: 256
/*
Where is frankenstein??
▒▒▒▒▒▒▐███████▌
▒▒▒▒▒▒▐░▀░▀░▀░▌
▒▒▒▒▒▒▐▄▄▄▄▄▄▄▌
▄▀▀▀█▒▐░▀▀▄▀▀░▌▒█▀▀▀▄
▌▌▌▌▐▒▄▌░▄▄▄░▐▄▒▌▐▐▐▐

*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <stack>
#include <sstream>
#include <cstring>
#include <numeric>
#include <ctime>
#include <cassert>
#include <random>
#include <valarray>
//#include <fstream>
#define re return
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define y0 y32479
#define y1 y95874
#define next next239
#define prev prev239
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define ba back()
#define popcount __builtin_popcountll
#define fastIO()                 \
    {                            \
        ios::sync_with_stdio(0); \
        cin.tie(0);              \
        cout.tie(0);             \
    }
#define in(x) \
    int x;    \
    cin >> x;
#define in1(x) \
    int x;     \
    cin >> x;  \
    x--;
#define inll(x) \
    ll x;       \
    cin >> x;
#define ins(x) \
    string x;  \
    cin >> x;

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef pair<double, double> pdd;
typedef long double LD;
typedef double D;

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    x--;y--;
    vector<int> v(n,0);
    rep(i, n)
    {
        for (int j = i + 1; j < n; j++)
        {
            int temp=min(   abs(i-j)    ,   (   min(    abs (abs(x-i)+1+abs(y-j)),  abs (   abs(x-j)+1+abs(y-i) )   )   )   );
            v[temp]++;
        }
    }

    for(int i=1;i<n;i++)
        cout<<v[i]<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << (a * b > c * d ? a * b : c * d) << endl;
}


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

using namespace std;

int main(){
 int a,b;
 cin>>a>>b;
  
 for(int i=0;i<10000;++i){
     int za=i*8/100;
     int zb=i*10/100;
     if(a==za&&b==zb){
       cout<<i<<endl; return 0;
       }
   }
  cout<<"-1"<<endl;
  
  return 0;
  }

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author must
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        
        for (int i=0;i<n;i++){
            A[i] = sc.nextInt();
        }
        
        Arrays.sort(A);
        
        int mm = A[n-1];
        
        double center = mm/2.0;
        
        int t=0;
        if (n == 2){
            
            System.out.println(A[1] + " " + A[0]);
            
        }else{
            for(int i=0;i<n-1;i++){
                if(center < A[i]){
                    t=i;
                    break;
                }
            }

            double disA = A[t] -  center;
            double disB = center - A[t-1];

            int nn;
            if(disA < disB){
                nn = A[t];
            }else{
                nn = A[t-1];
            }

            System.out.println(mm + " " + nn);
        }
    }    
}


Measured memory_bytes: 50700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

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

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; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    int n;
    cin >> n;
    ll mul = 1;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    for (int i = 0; i < n; ++i) {
        if(mul > 1000000000000000000LL/a[i]){
            cout << -1 << endl;
            return 0;
        }
        mul *= a[i];
    }

    cout << mul << endl;
    return 0;
}

Measured memory_bytes: 3972
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <cmath>

using namespace std;

int main()
{
    // Input
    int N;
    cin >> N;

    double ave = 0.0;
    vector<double> a(N);

    for (int i = 0; i < N; i++)
    {
        double a_i;
        cin >> a_i;

        ave += a_i;
        a[i] = a_i;
    }

    // Calculate diff from AVREAGE
    ave /= N;

    for (int i = 0; i < N; i++)
    {
        a[i] = abs((double)(a[i] - ave));
    }

    int ans = 0;
    double min_diff = INT_MAX;

    for (int i = 0; i < N; i++)
    {
        if (a[i] < min_diff)
        {
            ans = i;
            min_diff = a[i];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256