akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <atcoder/all>
#include <set>
using namespace std;
using namespace atcoder;

int main() {
	int N, M;
	cin >> N >> M;
	mcf_graph<int, int> graph(N * M + 2);
	vector<string> Map(N);
	set<int> Edges;
	for (int i = 0; i < N; i++) cin >> Map[i];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (Map[i][j] == '#') continue;
			if (Map[i][j] == 'o') {
				graph.add_edge(0, i * M + j + 1, 1, 0);
			}
			if (i + 1 < N && Map[i + 1][j] != '#') {
				int e = graph.add_edge(i * M + j + 1, (i + 1) * M + j + 1, 100, 0);
				Edges.insert(e);
			}
			if (j + 1 < M && Map[i][j + 1] != '#') {
				int e = graph.add_edge(i * M + j + 1, i * M + (j + 1) + 1, 100, 0);
				Edges.insert(e);
			}
			graph.add_edge(i * M + j + 1, M * N + 1, 1, N - i + M - j);
		}
	}
	auto p = graph.flow(0, N * M + 1);
	int ans = 0;
	for (int e : Edges) {
		auto E = graph.get_edge(e);
		ans += E.flow;
	}
	cout << ans << endl;
}


Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;

int n,arr[100000];

int main() {
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",arr+i);

    int ans=0;
    for(int i=0,j=0;i<n;i=j) {
        for(j=i+1;j<n && arr[j-1] >= arr[j]; j++);
        ans = max(ans, j-i-1);
    }
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 640
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var S string
	var o, e, r int
	fmt.Scan(&S)
	for i, v := range S {
		w := strconv.Itoa(i % 2)
		if string(v) != w {
			o++
		}
		if string(v) == w {
			e++
		}
	}
	if e < o {
		r = e
	} else {
		r = o
	}
	fmt.Println(r)

}

Measured memory_bytes: 1408
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=[int(_) for _ in input().split()]
    cunt=0
    for a in A:
        if a%2==0:cunt+=1
    print(3**n-2**cunt)

if __name__=='__main__':
    main()

Measured memory_bytes: 3060
#include <cstring>
#include <iostream>

using namespace std;

int main()
{
  string s;
  cin>>s;
  if(s[0]==s[1] && s[1]==s[2])
       printf("Yes");
  
  else if(s[1]==s[2] && s[2]==s[3])
        printf("Yes");
  
  else
     printf("No");
}


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

using namespace std;

long long dp[3100][3100];
bool used[3100][3100];
long long a[3100];
int N;

long long dfs(int i, int j)
{
  if (j - i == 0) return 0;
  long long &res = dp[i][j];
  if (used[i][j]) return res;
  used[i][j] = true;

  int len = j - i;
  if ((N - len) % 2 == 0) res = max(dfs(i + 1, j) + a[i], dfs(i, j - 1) + a[j - 1]);
  else res = min(dfs(i + 1, j) - a[i], dfs(i, j - 1) - a[j - 1]);
  return res;
}

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

  cout << dfs(0, N) << endl;

  return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a,b,c; cin>>a>>b>>c;
    if (a.back()==b.front() && b.back()==c.front()){
        cout<<"YES\n";
    }else{
        cout<<"NO\n";
    }
    return 0;
}


Measured memory_bytes: 256
import math
import sys
H = int(input())
#H = list(map(int,input().split()))
#H = sorted(H,reverse=True)

if H == 0:
    print(0)
    sys.exit()
elif H == 1:
    print(1)
    sys.exit()

mon_num = 1
attack_num = 0
for k in range(1000000000000):
    
    attack_num += mon_num
    
    H = math.floor(H/2)
    mon_num = mon_num*2
    
    
    if H == 1:
        attack_num += mon_num
        break
print(attack_num)
        
    

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <set>
 
using namespace std;
 
#define MAX_V 100
#define MAX_E 10000
#define INF 1e9
typedef pair<int,int> pii;
 
struct Edge{
  int u,v,cost;
  Edge(){}
  Edge(int u,int v,int cost) : u(u),v(v),cost(cost) {}
};
 
bool cmp(const Edge &e1,const Edge &e2){
  return e1.cost < e2.cost;
}
 
int V,E,par[MAX_V],rank[MAX_V],wmin;
Edge es[MAX_E];
 
void init(){
  for(int i = 0 ; i < V ; i++){
    par[i] = i;
    rank[i] = 0;
  }
}
 
int find(int x){
  if(par[x] == x){
    return x;
  }
  return par[x] = find(par[x]);
}
 
void unite(int x,int y){
  x = find(x), y = find(y);
  if(x == y){
    return;
  }
  if(rank[x] < rank[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(rank[x] == rank[y]){
      rank[x]++;
    }
  }
}
 
bool same(int x,int y){
  return find(x) == find(y);
}
 
int kruskal(){
  init();
  sort(es,es+E,cmp);
  set<pii> v;
  int max = 0, min = INF;
  for(int i = 0 ; i < E ; i++){
    Edge e = es[i];
    if(!same(e.u,e.v) && wmin <= e.cost){
      unite(e.u,e.v);
      v.insert(pii(e.u,e.v));
      max = std::max(max,e.cost);
      min = std::min(min,e.cost);
    } 
  }
  if((int)v.size() != V-1){
    return INF;
  }
  return max-min;
}
 
int main(){
  while(cin >> V >> E, (V | E)){
    int a,b,c,w[MAX_E];
    for(int i = 0 ; i < E ; i++){
      cin >> a >> b >> c;
      a--, b--;
      es[i] = Edge(a,b,c);
      w[i] = c;
    }
    sort(w,w+E);
    int res = 1e9;
    for(int i = 0 ; i < E ; i++){
      wmin = w[i];
      res = min(res,kruskal());
    }
    cout << (res == INF ? -1 : res) << endl;
  }
  return 0;
}

Measured memory_bytes: 1304
n=int(input())
a=[input() for i in range(n)]

import collections
d=collections.defaultdict(int)
maxi=0
for i in a:
    d[i]+=1
    maxi=max(d[i],maxi)
b=[]
for word,cnt in d.items():
    if cnt==maxi:
        b.append(word)
b=sorted(b)
for i in b:
    print(i)

Measured memory_bytes: 35468
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nk = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            var sum = 1L;
            var p = (long)Math.Pow(10, 9) + 7;
            var all = AggregateSum(nk[0]);
            for (var i = nk[1]; i <= nk[0]; i++)
            {
                var min = AggregateSum(i - 1);
                var max = all - AggregateSum(nk[0] - i);
                sum += (max - min + 1) % p;
            }
            Console.WriteLine(sum % p);
        }

        static long AggregateSum(long x)
        {
            return (long)(x * (x + 1) / 2);
        }
    }
}


Measured memory_bytes: 28572
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>

const int INF = 1 << 30;
const int V = 10;
struct edge { int to, cost; };
std::vector<edge>v[100];
typedef std::pair<int, int>p;

int main() {
	int n;
	std::cin >> n;
	std::vector<int>a(n);
	for (int i = 0;i < n;i++) {
		std::cin >> a[i];
	}
	std::sort(a.rbegin(), a.rend());
	long long int flag = 0, b = 0, c = 0;
	for (int i = 0;i < n;i++) {
		if (flag == 0) {
			if (a[i] == a[i + 1]) {
				b = a[i];
				i+=2;
				flag += 1;
			}
		}
		if (flag == 1) {
			if (a[i] == a[i + 1]) {
				c = a[i];
				break;
			}
		}
	}
	long long int ans = b*c;
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main() {

	long long int n, k;
	scanf("%lld", &n);
	scanf("%lld", &k);

	long long int a[200000];
	for (long long int i = 0;i < n;i++)
	{
		scanf("%lld", &a[i]);
	}
	for (long long int j = 0;j < n - k;j++)
	{
		if (a[k + j] > a[j])
		{
			printf("Yes\n");
		}
		else
			printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
using ll = long long;
typedef pair<int,int> P;
typedef pair<P,ll> PP;
using Graph = vector<vector<ll> >;
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 ll INF = 1e18;

ll h,w;
ll n;
ll ans[120][120];

int main(){
    cin >> h >> w;
    cin >> n;
    vector<ll>a(n);
    queue<ll>que;
    rep(i,n){
        cin>>a[i];
        rep(j,a[i])que.push(i+1);
    }

    for(int i=0;i<h;i++){
        if(i%2==0){
            for(int j=0;j<w;j++){
                ans[i][j]=que.front();que.pop();
            }
        }
        else{
            for(int j=w-1;j>=0;j--){
                ans[i][j]=que.front();que.pop();
            }
        }
    }
    rep(i,h){
        rep(j,w-1){
            cout<<ans[i][j]<<' ';
        }
        cout<< ans[i][w-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
#define F first
#define S second
#define PK push_back
#define POK pop_back()
#define B begin()
#define E end()
#define C clear()
#define SE size()
using namespace std;
typedef pair<int,int>P;
typedef vector<int>V;
typedef vector<P>V1;
int a[100001];
int main(void){
	int n;
	int i;
	P pp[2],pp1[2];
	V v;
	V1 v1;
	int cnt;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i+=2)	v.PK(a[i]);
	sort(v.B,v.E);
	cnt=0;
	for(i=0;i<v.SE;i++){
		cnt++;
		if(v[i]!=v[i+1]&&i!=v.SE-1){
			pp[0].S=v[i];
			pp[0].F=cnt;
			v1.PK(pp[0]);
			cnt=0;
		}
	}
	pp[0].S=v[v.SE-1];
	pp[0].F=cnt;
	v1.PK(pp[0]);
	cnt=0;
	v1.PK(make_pair(-1,-1));
//	for(i=0;i<v1.SE;i++)		cout<<v1[i].F<<" "<<v1[i].S<<endl;
	sort(v1.B,v1.E);
	pp[0].F=v1[v1.SE-1].F;
	pp[0].S=v1[v1.SE-1].S;
	v1.POK;
//	for(i=0;i<v1.SE;i++)		cout<<v1[i].F<<" "<<v1[i].S<<endl;
	pp[1].F=v1[v1.SE-1].F;
	pp[1].S=v1[v1.SE-1].S;
//	cout<<pp[0].F<<" "<<pp[0].S<<" "<<pp[1].F<<" "<<pp[1].S<<endl;
	
	v.C;
	v1.C;
	
	for(i=1;i<n;i+=2)	v.PK(a[i]);
	sort(v.B,v.E);
	cnt=0;
	for(i=0;i<v.SE;i++){
		cnt++;
		if(v[i]!=v[i+1]&&i!=v.SE-1){
			pp1[0].S=v[i];
			pp1[0].F=cnt;
			v1.PK(pp1[0]);
			cnt=0;
		}
	}
	pp1[0].S=v[v.SE-1];
	pp1[0].F=cnt;
	v1.PK(pp1[0]);
	cnt=0;
	v1.PK(make_pair(-1,-1));
//	for(i=0;i<v1.SE;i++)		cout<<v1[i].F<<" "<<v1[i].S<<endl;
	sort(v1.B,v1.E);
	pp1[0].F=v1[v1.SE-1].F;
	pp1[0].S=v1[v1.SE-1].S;
	v1.POK;
//	for(i=0;i<v1.SE;i++)		cout<<v1[i].F<<" "<<v1[i].S<<endl;
	pp1[1].F=v1[v1.SE-1].F;
	pp1[1].S=v1[v1.SE-1].S;
//	cout<<pp1[0].F<<" "<<pp1[0].S<<" "<<pp1[1].F<<" "<<pp1[1].S<<endl;
	cnt=0;
	if(pp[0].S==pp1[0].S){
		if(pp[0].F+pp1[1].F>pp[1].F+pp1[0].F){
			cnt=n-(pp[0].F+pp1[1].F);
		}
		else if(pp[0].F+pp1[1].F<pp[1].F+pp1[0].F){
			cnt=n-(pp[1].F+pp1[0].F);
		}
		else{
			cnt=n-(pp[1].F+pp1[0].F);
			if(pp[1].F==-1&&pp1[1].F==-1){
				cnt=pp[0].F;
			}
			
		}
	}
	if(pp[0].S!=pp1[0].S){
		for(i=0;i<n;i++){
			if(i%2==0){
				if(pp[0].S!=a[i])	cnt++;
			}
			else{
				if(pp1[0].S!=a[i])	cnt++;
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}
	
	
	
	

Measured memory_bytes: 1532
fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: u64 = iter.next().unwrap().parse().unwrap();
    let a: Vec<u64> = (&mut iter).take(n).map(|x| x.parse().unwrap()).collect();
    
    let mut sum: Vec<u64> = vec![0;n+1];
    for i in 0..n {
        sum[i+1] = sum[i] + a[i];
    }

    let mut hmap = std::collections::HashMap::new();
    for i in 0..n+1 {
        *hmap.entry(sum[i]%m).or_insert(0) += 1;
    }

    let mut ret = 0u64;
    for &value in hmap.values() {
        ret += value * (value - 1) / 2;
    }
    println!("{}", ret);
}

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

int main(){
  string T; cin >> T;
  long long ans = 0;
  for(int i=0;i<T.size();i++){
    if(T.at(i) == '?'){
      T.at(i) = 'D';
    }
  }
  cout << T << endl;
}


Measured memory_bytes: 3756
# -*- coding: utf-8 -*-
import itertools
N = [1, 2, 3, 4]
abn = [list(map(int, input().split())) for _ in range(3)]
map = [[0 for _ in range(4)] for _ in range(4)]

for a,b in abn:
    map[a-1][b-1] = 1
    map[b-1][a-1] = 1

for path in itertools.permutations(N, 4):
    ans = True
    for i in range(3):
        if map[path[i]-1][path[i+1]-1] == 0:
            ans = False

    if ans == True:
        print("YES")
        exit()

print("NO")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int N,K;
vector<int> a;
bool dp[5001][5001];

bool C(int n) {
    for(int i=0; i<=N; ++i) {
        for(int j=0; j<=K; ++j) dp[i][j] = 0;
    }
    dp[0][0] = 1;
    for(int i=1; i<=N; ++i) {
        for(int j=0; j<=K; ++j) {
            dp[i][j] = dp[i-1][j];
            if(i - 1 != n && j - a[i-1] >= 0) dp[i][j] |= dp[i - 1][j - a[i - 1]];
        }
    }

    for(int k=max(0, K - a[n]); k<K; ++k) {
        if(dp[N][k]) return true;
    }
    return false;
}

int main() {
    cin >> N >> K;
    a.resize(N);
    for(int i=0; i<N; ++i) cin >> a[i];
    sort(begin(a), end(a));

    int l = -1, r = N;
    while(r - l > 1) {
        int m = (l + r) / 2;
        if(C(m)) r = m;
        else l = m;
    }
    cout << l + 1 << endl;
}

Measured memory_bytes: 24832
#include <stdio.h>
int main ()
{
    int a, b, c, x, i, j, k, cnt=0;
    scanf("%d%d%d%d", &a, &b, &c, &x);
    for (i=0; i <= a && 500*i<=x; i++)
        for (j=0; j <= b && 100*j+500*i<=x; j++)
            for (k=0; k <= c && 50*k+100*j+500*i<=x; k++)
                if (500*i+100*j+50*k==x)cnt++;
    printf("%d", cnt);
}

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

using namespace std;
using ll = long long;

template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_V(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_M(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}

int main() {
    ll n;
    cin>>n;
    ll c =1;
    c *= n * n * n;
    cout<<c<<endl;

    return 0;
}

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

int n,m,ans;
int a[maxl];
char s[maxl];

inline void prework()
{
	
}

inline void mainwork()
{
	
}

inline void print()
{
	scanf("%d",&n);
	ans=n/2;
	if(n%2==0)
		ans--;
	printf("%d",ans);
}

int main()
{
	int t=1;
	//scanf("%d",&t);
	for(int i=1;i<=t;i++)
	{
		prework();
		mainwork();
		print();
	}
	return 0;
}

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

int main() {
  int x;
  cin >> x;
  
  int now;
  int l = sqrt(x);
  int ans;
  for(int i = l; i <= x; i++){
    now = (1 + i) * i / 2;
    if(now >= x){
      ans = i;
      break;
    }
  }
  
  cout << ans << endl;
}

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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  rep(i, M) cin >> B[i];
  int ans = 0;
  rep(i, N) {
    int tmp = C;
    rep(j, M) {
      int A;
      cin >> A;
      tmp += A * B[j];
    }
    if (tmp > 0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
#include<stdio.h>

#define MAX 100005
#define NIL -1

struct Node{ int p, l, r, t;};
struct Node T[MAX];

int n, H, D[MAX],h[MAX];

void Depth(int u){
  
  int d=0;
  if(T[u].r!=NIL){
    D[T[u].r]=D[u]+1;
    Depth(T[u].r);
  }
  if(T[u].l!=NIL){ 
    D[T[u].l]=D[u]+1;
    Depth(T[u].l);
  }
}

int Height(int u){

  int a,s;
  a=s=0;
  if(T[u].r==NIL && T[u].l==NIL) return 0;
  if(T[u].l!=NIL){
    a=Height(T[u].l)+1;
  }
  if(T[u].r!=NIL){
    s=Height(T[u].r)+1;
  }
  if(a>s) return a;
  else return s;
}

int main(){
  int i,d, v, c, l,r;
  
  scanf("%d", &n);
  
  for (i=0;i<n;i++){
    T[i].p=T[i].l=T[i].r=NIL;
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    if(l!=NIL){
      T[l].p=v;
    }
    if(r!=NIL){
      T[r].p=v;
    }
    T[v].l = l;
    T[v].r = r;
  }
  for (i=0;i<n;i++){
    if(T[i].l != -1){
      T[i].t++;
    }
    if(T[i].r != -1){
      T[i].t++;
    }
  }
  
  for (i=0;i<n;i++){
    if(T[i].p==NIL){
      D[i]=0;
      Depth(i);
      break;
    }
  }
  
  for (i=0;i<n;i++){
    h[i]=Height(i); 
  }
  
  for (i=0;i<n;i++){
    printf("node %d: parent = %d,",i,T[i].p);
    if(T[i].p==NIL)printf(" sibling = -1, ");
    else if(T[T[i].p].r==i)  printf(" sibling = %d, ",T[T[i].p].l);
    else   if(T[T[i].p].l==i) printf(" sibling = %d, ",T[T[i].p].r);
    printf("degree = %d, ",T[i].t);
    printf("depth = %d, height = %d, ",D[i],h[i]);
    if(T[i].p==NIL) printf("root\n");
    else if(T[i].t==0) printf("leaf\n");
    else printf("internal node\n");
  }
  return 0;
}

Measured memory_bytes: 620
s = input()
i = 0
S1 = []
S2 = []
water = []
wtot = 0
while i < len(s):
    if s[i] == "\\":
        S1.append(i)
    elif s[i] == '/' and len(S1) != 0:
        w0 = (i - S1[-1])
        wtot += w0
        if len(S2) == 0:
            S2.append((S1[-1], w0))
        else:
            while len(S2) != 0 and S2[-1][0] > S1[-1]:
                w0 += S2[-1][1]
                S2.pop()
            S2.append((S1[-1], w0))
        S1.pop()
    i += 1

ans = str(wtot) + '\n' + str(len(S2))
for p in S2:
    ans += ' ' + str(p[1])
print(ans)



Measured memory_bytes: 6240
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

typedef long long ll;

using namespace std;
using namespace boost::multiprecision;

int main(){

    ll h;
    cin >> h;

    vector<ll> v(41);

    v[0] = 1;

    rep(i,40){
        v[i + 1] = v[i] * 2 + 1;
        //cerr << v[i] << endl;
    }

    int hlog = (int)(log2((double)h));

    cerr << log2((double)h) << endl;
    cerr << (int)(log2((double)h)) << endl;

    cout << v[hlog] << endl;

    return 0;
}

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

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


Measured memory_bytes: 256
// luogu-judger-enable-o2
// luogu-judger-enable-o2
#pragma GCC optimize("-O2")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<map>
#include<bitset>
#include<ctime>
#include<cstdlib> 
#define LL long long
#define DB long double
#define pa pair<LL,int>
#define ctz __builtin_ctz
using namespace std;

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline void Out(LL x){
    if(x>9) Out(x/10);
    putchar(x%10+'0'); 
}
const int N=2e5+10;
int n;
int a[N];
int top,hed;
struct node{
	int len;
	int l,r;
	int v;
}d[N];
bool add(int x,int mid){
	if(!x) return 0;
	if(d[x].len>1){
		++top;
		--d[x].len;
		d[top].len=1;
		d[top].v=d[x].v;
		d[top].r=d[x].r;
		d[top].l=x;
		d[d[x].r].l=top;
		d[x].r=top;
		return add(top,mid);
	}
	else{
		++d[x].v;
		if(d[x].v<=mid) return 1;
		else {
			d[x].v=1;
			return add(d[x].l,mid);
		}
	}
}
bool check(int mid){
	top=hed=1;
	d[1].len=a[1];
	d[1].v=1;
	d[1].l=d[1].r=0;
	int L=a[1];
	for(int i=2;i<=n;++i){
		if(a[i]>L){
			++top;
			d[top].len=a[i]-L;
			d[top].v=1;
			L=a[i];
			d[top].l=hed;
			d[hed].r=top;
			hed=top;
			continue;
		}
		while(L>a[i]){
			if(d[hed].len<=L-a[i]){
				L-=d[hed].len;
				hed=d[hed].l;
			}
			else {
				d[hed].len-=L-a[i];
				L=a[i];
			}
		}
		if(d[hed].len>1){
			++top;
			d[top].len=1;
			d[top].v=d[hed].v;
			d[top].l=hed;
			d[hed].r=top;
			d[hed].len--;
			hed=top;
		}
		if(!add(hed,mid)) return 0;
	}
	return 1;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i) a[i]=read();
    bool flag=0;
    for(int i=2;i<=n;++i) if(a[i]<=a[i-1]) {flag=1;break;}
    if(!flag){
    	puts("1");return 0;
	}
    int l=2,r=n,mid;
    while(l!=r){
    	mid=l+r>>1;
    	if(check(mid)) r=mid;
    	else l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}
/*
10
100 8 8

*/

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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1)
  {
    sz = 1;
    while (sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x)
  {
    seg[k + sz] = x;
  }

  void build()
  {
    for (int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x)
  {
    k += sz;
    seg[k] = x;
    while (k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b)
  {
    Monoid L = M1, R = M1;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1) L = f(L, seg[a++]);
      if (b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const
  {
    return seg[k + sz];
  }
};

void solve() {
  int N, Q; cin >> N >> Q;
  SegmentTree<int> seg(N + 1, [](int a, int b){ return a + b; }, 0);
  string s;
  cin >> s;
  rep(i, N - 1) {
    if (s.substr(i, 2) == "AC") seg.update(i + 1, 1);
  }
  rep(_, Q) {
    int l, r; cin >> l >> r;
    cout << seg.query(l, r) << '\n';
  }
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables **************/
string s;
int k;
set<string> st;
vector<int> basyo[26];
/**********************************************/

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

    cin >> s >> k;
    
    REP(i, s.size()){
        basyo[s[i]-'a'].pb(i);
    }

    for(char c = 'a'; c <= 'z'; c++){
        for(auto x: basyo[c-'a']){
            for(int j = 1; j <= 5 && x+j <= s.size(); j++){
                st.insert(s.substr(x, j));
            }
        }
        if(st.size() >= k) break;
    }
    auto itr = st.begin();
    REP(i, k-1){
        ++itr;
    }
    cout << *itr << endl;
}


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

typedef long long LL;

string dp[60][60],s;

void update(string &o,string p){
	if(p.empty())	return;
	if(o.size()>p.size())	return;
	if(p.size()>o.size()){
		o=p;	return;
		}
	if(o<p)
		o=p;
	}

string dfs(int l,int r){
	if(l>r)	return "";
	if(!dp[l][r].empty())	return dp[l][r];
	string &res=dp[l][r];
	bool flag=false;
	for(int i=l;i<=r;i++){
		flag|=(s[i]=='L'||s[i]=='R'||s[i]==','||s[i]=='('||s[i]==')');
		}
	if(!flag&&(s[l]!='0'||l==r)){
		for(int i=l;i<=r;i++){
			if(s[i]=='?'){
				res+='9';
				}
			else{
				res+=s[i];
				}
			}
		return res;
		}
	if(s[l+1]!='('&&s[l+1]!='?')	return res;
	if(s[r]!=')'&&s[r]!='?')	return res;
	for(int i=l+3;i<r-1;i++){
		if(s[i]=='?'||s[i]==','){
			dfs(l+2,i-1);
			dfs(i+1,r-1);
			if(dp[l+2][i-1].empty()||dp[i+1][r-1].empty())
				continue;
			if(s[l]=='L'||s[l]=='?')
				update(res,dp[l+2][i-1]);
			if(s[l]=='R'||s[l]=='?')
				update(res,dp[i+1][r-1]);
			}
		}
	return res;
	}

int main(){
	cin>>s;
	auto len=s.size();
	dfs(0,(int)len-1);
	if(dp[0][len-1].empty()){
		printf("invalid\n");
		}
	else{
		cout<< dp[0][len-1] <<endl;
		}
	return 0;
	}

Measured memory_bytes: 3284
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int h ,a;

int main(){
	cin >> h >> a;
	
	cout << (h+a-1)/(a) << endl;
	
	return 0;
}

Measured memory_bytes: 256
def main():
  N, Q = list(map(int, input().split()))
  S = input()
  
  #ACをカウントし、累積和を求める
  C = [0]
  c = 0
  for i in range(N-1):
    if ('A' == S[i]):
      if ('C' == S[i+1]):
        c += 1
    C.append(c)
  for i in range(Q):
    l, r = list(map(int, input().split()))
    print(C[r-1] - C[l-1])
main()


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

int main()
{
	int n,k,x,y;
	cin >> n >> k >> x >> y;
	if (n <= k)
	{
		cout << x*n << endl;
	}
	else
	{
		cout << x*k+y*(n-k) << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(void){
	unsigned long int a=100;
	unsigned long int x;
	int y=0;
	
	if(scanf("%lu",&x)> 0 ) {;
	
	do{
		a=a*1.01;
		y++;
	}while(a<x);
	
	printf("%d ",y);
}
}

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

using ll = long long;

const int N = 100005;

int n;
ll a[N], r, t;

int main(){
	scanf("%d", &n);
  	for(int i=0; i<n; i++) scanf("%lld", a+i);
  	sort(a, a+n);
  	if(n&1){
      	for(int i=0; i<n/2-1; i++) r-=2*a[i];
      	r-=a[n/2-1]+a[n/2];
      	for(int i=n/2+1; i<n; i++) r+=2*a[i];
      	for(int i=0; i<n/2; i++) t-=2*a[i];
      	t+=a[n/2]+a[n/2+1];
      	for(int i=n/2+2; i<n; i++) t+=2*a[i];
      	r=max(r, t);
    }
  	else{
      	for(int i=0; i<n/2-1; i++) r-=2*a[i];
      	r+=a[n/2]-a[n/2-1];
      	for(int i=n/2+1; i<n; i++) r+=2*a[i];
    }
  	printf("%lld", r);
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Numerics;

public class Program
{
    public static void Main(string[] args)
    {
        //string[] line = Console.ReadLine().Split(' ');

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

        Console.WriteLine((x == 7 || x == 5 || x == 3) ? "YES" : "NO");
        Console.ReadLine();
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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(){
    const ll mod = 1e9 + 7;
    ll n; cin >> n;
    vector<ll> t(n), a(n), M(n, 0), m(n, 0);
    rep(i, n) cin >> t[i];
    rep(i, n) cin >> a[i];
    rep(i, n) {
        if(i==0){
            M[i]=t[i]; m[i] = t[i];
            continue;
        }
        if(t[i] > t[i-1]){
            M[i]=t[i]; m[i]=t[i];
        }else{
            M[i]=t[i]; m[i]=1;
        }
    }
    rep(i, n) {
        if(i==0){
            chmin(M[n-1-i], a[n-1-i]); chmax(m[n-1-i], a[n-1-i]);
            continue;
        }
        if(a[n-1-i] > a[n-i]){
            chmin(M[n-1-i], a[n-1-i]); chmax(m[n-1-i], a[n-1-i]);
        }else{
            chmin(M[n-1-i], a[n-1-i]); chmax(m[n-1-i], 1ll);
        }
    }
    ll res=1;
    rep(i,n){
        if(M[i]<m[i]){
            res=0;
            break;
        }
        res *= (M[i]-m[i]+1)%mod;
        res %= mod;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3456
import java.util.Scanner;

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

        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int[] dist = new int[y];

        for (int i = 0; i < y; i++) {
            dist[i] = scanner.nextInt();
        }

        scanner.close();

        int[] sa = new int[y];

        for (int i = 0; i < dist.length; i++) {
            if (i == 0) {
                sa[0] = dist[0];
            } else {
                sa[i] = dist[i] - dist[i - 1];
            }
            if (i == dist.length - 1) {
                sa[0] += x - dist[i];
            }
        }

        dist = null;

        int max = sa[0];
        int sum = 0;
        for (int i : sa) {
            if (i > max) {
                max = i;
            }
            sum += i;
        }

        System.out.println(sum - max);
    }
}

Measured memory_bytes: 79548
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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 ll INF = 1e18;




int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    set<ll>st;
    map<ll,ll>mp;
    rep(i,n){
        mp[a[i]]++;
        st.insert(a[i]);
    }
    ll ans = 0;
    for(ll i=40;i>=0;i--){
        ll now = pow(2,i);
        for(auto itr=mp.begin();itr!=mp.end();itr++){
            if(itr->second<=0)continue;
            ll f = itr->first;
            ll s = itr->second;
            if(f*2==now){
                while(s>1){//同一の数字のペア
                    ans++;
                    s-=2;
                    itr->second-=2;
                }
                continue;
            }
            ll x = now - f;
            if(!x>0)continue;
            if(st.find(x)==st.end())continue;
            if(mp[x]>0){
                ll c = min(s,mp[x]);
                ans += c;
                mp[x]-=c;
                itr->second-=c;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 25728
#include<cstdio>
#include<algorithm>
int main(){
    int k,n,l[50];
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)scanf("%d",&l[i]);
    std::sort(l,l+n);
    int ans=0;
    for(int i=0;i<k;i++){
        ans+=l[n-1-i];
    }
    printf("%d",ans);
    return 0;
}

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int a,b,c,d;

main() {
    cin >> a >> b >> c >> d;
    ct(min(a,b)+min(c,d))
}






Measured memory_bytes: 256
#include<stdio.h>
int isPrime(int x){
  int i;
  if(x < 2) return 0;
  else if (x == 2) return 1;
  if(x%2 == 0) return 0;
  for(i=3; i*i<=x; i+=2){
    if(x%i == 0) return 0;
  }
  return 1;
}

int main(){
  int n,x,i;
  int cnt = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&x);
    if(isPrime(x)) cnt++;
  }
  printf("%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2680
# include <iostream>

using namespace std;

struct Vertex
{
    int id, k, *adjcent, start, end;
    bool passed = false;
};

Vertex *vertexs;
int time_ = 0;

void DFS(int now)
{
    vertexs[now].passed = true;
    time_++;
    vertexs[now].start = time_;
    for(int i=0; i<vertexs[now].k; i++)
    {
        if(!vertexs[vertexs[now].adjcent[i]].passed) DFS(vertexs[now].adjcent[i]);
    }
    time_++;
    vertexs[now].end = time_;
}

int main()
{
    int n;
    scanf("%d", &n);
    vertexs = new Vertex[n+1];
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d", &vertexs[i].id, &vertexs[i].k);
        vertexs[i].adjcent = new int[vertexs[i].k];
        for(int j=0; j<vertexs[i].k; j++)
        {
            scanf("%d", &vertexs[i].adjcent[j]);
        }
    }
    for(int i=1; i<=n; i++)
    {
        if(!vertexs[i].passed) DFS(vertexs[i].id);
    }
    for(int i=1; i<=n; i++) printf("%d %d %d\n", vertexs[i].id, vertexs[i].start, vertexs[i].end);

    return 0;
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

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

    val = val - 1;

    int ans = 0;

    for(int i = 1; i <= val; i ++)
    {
        int temp = val / i;

        if(temp == 0)
        {
            ans ++;
        }
        else
        {
            ans += temp;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3664
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_set>
#include <queue>
#include <unordered_map>
#include <set>

#pragma GCC optimize("O3")

using namespace std;
using ll = long long;
using ull = unsigned long long;

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repd(i, n) for(ll i = (n) - 1ll; i >= 0; --i)
#define FOR(i, a, b) for(ll i = a; i < ll(b); ++i)
#define FORD(i, a, b) for(ll i = a; i > ll(b); --i)
#define asort(array, size) std::sort(array, array + size)
#define cauto const auto&
#define bit(n) (1LL << (n))

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll A = a * c;
    ll B = a * d;
    ll C = b * c;
    ll D = b * d;
    ll ans = max(A, max(B, max(C, D)));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

  int h, w;
  cin >> h >> w;
  int H = h + 2;
  int W = w + 2;
  vector<string> s(H);
  s[0] = string(W, '#');
  rep(i, h) {
    int r = i + 1;
    cin >> s[r];
    s[r] = '#' + s[r] + '#';
  }
  s[H-1] = string(W, '#');

  vvvi d(H, vvi(W, vi(4)));
  rep(r, H) {
    rep(c, W) {
      if (s[r][c] == '#') {
        d[r][c][0] = -1;
      }
      else {
        d[r][c][0] = d[r][c-1][0] + 1;
      }
    }
  }

  rep(r, H) {
    rrep(c, W) {
      if (s[r][c] == '#') {
        d[r][c][1] = -1;
      }
      else {
        d[r][c][1] = d[r][c+1][1] + 1;
      }
    }
  }

  rep(c, W) {
    rep(r, H) {
      if (s[r][c] == '#') {
        d[r][c][2] = -1;
      }
      else {
        d[r][c][2] = d[r-1][c][2] + 1;
      }
    }
  }

  rep(c, W) {
    rrep(r, H) {
      if (s[r][c] == '#') {
        d[r][c][3] = -1;
      }
      else {
        d[r][c][3] = d[r+1][c][3] + 1;
      }
    }
  }

  int ma = 0;
  rep(r, H) {
    rep(c, W) {
      if (s[r][c] == '.') {
        chmax(ma, d[r][c][0] + d[r][c][1] + d[r][c][2] + d[r][c][3] + 1);
      }
    }
  }

  cout << ma << endl;

}


Measured memory_bytes: 292224
#include<iostream>
using namespace std;
int main(){
  long long a,b;
  cin>>a>>b;
  long long x=a,y=b;
  while(y!=0){
    long long temp=y;
    y=x%y;
    x=temp;
  }
  cout<<(a*b)/x<<endl;
  return(0);
}
  
  

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

int main(){
  long long n, k, ans = 0;
  cin >> n >> k;
  long long r, s, p;
  cin >> r >> s >> p;
  string t;
  cin >> t;
  vector<char> a(n, true);
  map<char, long long> pun;
  pun['r'] = p;
  pun['p'] = s;
  pun['s'] = r;
  for(int i = 0; i < n; ++i){
      if((i < k) || (i >= k && (t[i] != t[i - k] || (t[i] == t[i - k] && a[i - k])))){
          ans += pun[t[i]];
          a[i] = false;
      }
  }
  cout << ans;
}


Measured memory_bytes: 512
S=input()
n=len(S)
a=0
b=0
for i in range(1,int(n/2)+1):
    if S[i-1]!=S[n-i]:
        a=1
        print("No")
        break;
p=[]
q=[]
if a==0:
    for i in range(1,int(n/2)+1):
        p.append(S[i-1])
        q.append(S[i+int(n/2)])
    #print(p,q)
    for i in range(1,int((len(p))/2)+1):
        #print(p[i-1],p[len(p)-i],q[i-1],q[len(p)-i])
        if p[i-1]!=p[len(p)-i] or q[i-1]!=q[len(p)-i]:
            b=1
            print("No")
            break;
if a==0 and b==0:
    print("Yes")


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define int long long int 
#define mp make_pair
#define pb push_back
#define f first
#define s second

int32_t main()
{
     IOS;
     
     int n,m,x,y;
     
     cin>>n>>m>>x>>y;
     
     int z=-1000;
     
     
     
     for(int i=1;i<=n;i++)
     {
          int a;
          
          cin>>a;
          
          z=max(z,a);
          
     }
     
     z=max(z,x);
     
     z+=1;
     
     int flag=0;
     
     if(z>y)
     flag=1;
     
     for(int i=1;i<=m;i++)
     {
          int a;
          cin>>a;
          
          if(a<z)
          {
               flag=1;
          }
          
     }
     
     if(flag==0)
     {
          cout<<"No War";
     }
     else
     {
          cout<<"War";
     }
     return 0;     
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
#define fs first
#define sc second

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;



int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> s(n + 1);
    rep(i, n){
        cin >> a[i];
        s[i + 1] = s[i] + a[i];
    }
    ll ans = LLINF;
    rep(i, n){
        ll tmp = s[i] - s[0];
        ll tmp2 = s.back() - s[i];
        chmin(ans, abs(tmp - tmp2));
    }
    print(ans);


}


Measured memory_bytes: 3456
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
long long cnt;
int l;
int A[1000000];
int n;
vector<int>G;
void insertionSort(int A[],int n,int g)
{
	for(int i=g;i<n;i++)
	{
		int v=A[i];
		int j=i-g;
		while(j>=0&&A[j]>v)
		{
			A[j+g]=A[j];
			j-=g;
			cnt++;
		}
		A[j+g]=v;
	}
}
void shellSort(int A[],int n)
{
	for(int h=1; ;)
	{
		if(h>n) break;
		G.push_back(h);
		h=3*h+1;
	}
for(int i=G.size()-1;i>=0;i--)
{

	insertionSort(A,n,G[i]);
}
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	scanf("%d",&A[i]);
	cnt=0;
	shellSort(A,n);
	cout<<G.size()<<endl;
	for(int i=G.size()-1;i>=0;i--)
	{
		printf("%d",G[i]);
		if(i) printf(" ");
		
	}
	printf("\n");
	printf("%d\n",cnt);
	for(int i=0;i<n;i++) printf("%d\n",A[i]);
	return 0;
}


Measured memory_bytes: 7192
n,m=map(int,input().split())
li = []
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    li.append(b)
  elif b==n:
    li.append(a)

if len(set(li))==len(li): print('IMPOSSIBLE')
else: print('POSSIBLE')

Measured memory_bytes: 23288
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
int main(){
  string a;
  cin >> a;
  if(a[0] == '7' || a[1] == '7' || a[2] == '7')cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3628
import java.io.*;
public class Main {
  public static void main(String args[]) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String s = null;
    try {
      s = reader.readLine();
    } catch(IOException e) {
    }
    System.out.println(s.substring(0, 4) + " " + s.substring(4));
  }
}

Measured memory_bytes: 22228
/*
 *  AUTHOR : MANAV PATEl
*/
#include<bits/stdc++.h>
#include<functional>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

namespace fastio {

	template <class T> istream &operator>>(istream &os, vector<T> & vec) {
		for (auto &u : vec)os >> u;
		return os;
	}
	template <class T> ostream &operator<<(ostream &os, const vector<T> & vec) {
		for (auto &u : vec)os << u << " ";
		return os;
	}
	template<class T1, class T2> inline istream& operator>>(istream& os, pair<T1, T2>& p) {
		return os >> p.first >> p.second;
	}
	template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
		return os << p.first << " " << p.second;
	}
	template <class T> ostream &operator<<(ostream &os, set<T> & con) {
		for (auto &u : con) os << u << " ";
		return os;
	}
	void re() {}
	template <typename T, typename... args> void re(T& x, args&... tail) {
		cin >> x;
		re(tail...);
	}
	void pr() {}
	template <typename T> void pr(const T& x) {
		cout << x;
	}
	template <typename T, typename... args> void pr(const T& x, const args&... tail) {
		cout << x << " ";
		pr(tail...);
	}
	template <typename... args> void prln(const args&... tail) {
		pr(tail...);
		cout << "\n";
	}
}
using namespace fastio;

typedef long long int ll;
typedef long double ld;

const ll mod = 1e9+7;
const ll mod1 = 998244353;

#define fill(a)  memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back

int main()
{
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	ll x, a;
  	re(x,a);
  if(x < a) prln(0);
  else prln(10);
}


Measured memory_bytes: 256
N = map(int, input())
p = [int(s) for s in input().split()]
cnt = 0

for i, vs in enumerate(zip(p, p[1:])):

    if vs[0] == i + 1:

        p[i] = vs[1]
        p[i + 1] = vs[0]
        cnt += 1

if p[-1] == len(p):
    cnt += 1

print(cnt)

Measured memory_bytes: 13880