akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
struct UnionFind {vector<int> par, cnt;
    UnionFind(int NV) { par.clear(); cnt.resize(NV, 1); rep(i, 0, NV) par.push_back(i); }
    void reset() { rep(i, 0, cnt.size()) cnt[i] = 1; rep(i, 0, par.size()) par[i] = i; }
    int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); }
    void operator()(int x, int y) {x = operator[](x); y = operator[](y);
        if (x != y) par[x] = y, cnt[y] += cnt[x];}};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
 
 


#define NO "NO"
#define YES "YES"
int N, H;
int L[101010], R[101010];
int in[505], ou[505];
int used[505];
UnionFind uf(505);
//---------------------------------------------------------------------------------------------------
string solve() {
    cin >> N >> H;

    // make_edge
    rep(i, 0, N) {
        int a, b, c, d; cin >> a >> b >> c >> d;

        int l;
        if (0 < c) l = -c;
        else l = a;

        int r;
        if (0 < d) r = d;
        else r = -b;

        l += 250, r += 250;

        L[i] = l, R[i] = r;
    }

    // in/out check
    rep(i, 0, N) {
        int l = L[i], r = R[i];
        ou[l]++; in[r]++;
    }
    rep(i, 0, 505) {
        int x = i - 250;
        if (0 < x) if (ou[i] < in[i]) return NO;
        if (x < 0) if (in[i] < ou[i]) return NO;
    }

    // cycle check
    rep(i, 0, 505) {
        int x = i - 250;
        if (0 < x) if (ou[i] > in[i]) uf(500, i);
        if (x < 0) if (in[i] > ou[i]) uf(500, i);
    }
    rep(i, 0, N) {
        int l = L[i], r = R[i];

        used[l] = used[r] = 1;
        uf(l, r);
    }
    rep(i, 0, 505) if (used[i]) if (uf[i] != uf[500]) return NO;

    return YES;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cout << solve() << endl;
}

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

using namespace std;

#define all(v)          v.begin(), v.end()
#define pb              push_back
#define sz(x)          (int) (x.size())
#define endl            "\n"
#define isOdd(n)       (n&1)
#define pow(n, m)      (ll)powl(n, m)
#define clr(x, val)     memset(x, val, sizeof(x))
#define EPS 1e-6

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, k; cin >> n >> k;
    int a[n];
    for(auto &i: a) cin >> i;
    int l = 0;
    for(int i = k; i < n; i++){
        cout << (a[i] > a[l++] ? "Yes" : "No") << endl;
    }
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(int i = k; i < n; i++)
#define rrep(i, n) RREP(i, 0, n)
#define RREP(i, k, n) for(int i = n-1; i > k-1; i--)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;

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

bool isSmall(char a) {
    return 'a' <= a && a <= 'z';
}

void end() {
    cout << "WA" << endl;
    exit(0);
}

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

    string S;
    cin >> S;

    string ans;
    if (S[0] != 'A') end();
    if (!isSmall(S[1])) end();

    int cnum = 0;
    REP(i, 2, S.size()-1) {
        if(S[i] == 'C') cnum++;
        else if(!isSmall(S[i])) end();
    }

    if (cnum != 1) end();
    if (!isSmall(S[S.size()-1])) end();

    cout << "AC" << endl;

    return 0;
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for(int i=0; i<1000; i++){
    vector<int> v = {i/100,i/10%10,i%10};
    int f = 0;
    for(int i=0; i<n; i++){
      if(s.at(i) - '0' == v.at(f)){
        f++;
      }
      if(f == 3){
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//package atcoder;

import java.util.Scanner;

/**
 *
 * @author HP
 */
public class Main {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int a=input.nextInt();
        int b=input.nextInt();
        int f=b-a;
        int z=0;
        int c[]=new int[999];
        int count=0;
        for(int i=1;i<=999;i++)
        {
            c[count]=(i*(i+1))/2;
            count++;
        }
        for(int i=1;i<count;i++)
        {
            if(c[i]-c[i-1]==f)
            {
                z=c[i-1]-a;
            }
        }
        System.out.println(z);
    }
}


Measured memory_bytes: 21844
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x:usize = read();
    match x {
        400..=599 => println!("8"),
        600..=799 => println!("7"),
        800..=999 => println!("6"),
        1000..=1199 => println!("5"),
        1200..=1399 => println!("4"),
        1400..=1599 => println!("3"),
        1600..=1799 => println!("2"),
        _ => println!("1")
    }
}

Measured memory_bytes: 2132
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;


int M, N, D[256];
bool G[256][256];


int main()
{
	for(; cin >> M && M; ) {
		memset(G, false, sizeof G);

		cin >> N;

		for(int i = 1; i <= N; i++) {
			cin >> D[i];
		}

		for(int i = 0; i <= N; i++) {
			for(int j = 1; j <= M; j++) {
				if(i+j >= N+1) G[i][N+1] = true;
				else G[i][max(0, min(i+j+D[i+j], N+1))] = true;
			}
		}

		for(int i = 0; i <= N+1; i++) {
			for(int j = 0; j <= N+1; j++) {
				for(int k = 0; k <= N+1; k++) {
					G[i][j] |= (G[i][k] && G[k][j]);
				}
			}
		}

		bool res = G[0][N+1];
		for(int i = 1; i <= N; i++) {
			res &= (G[0][i] ? G[i][N+1] : true);
		}
		
		cout << (res ? "OK" : "NG") << endl;
	}
}

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

int main()
{
  string a, b;
  cin >> a >> b;
  if ((a[0] == 'H' && b[0] == 'H') || (a[0] == 'D' && b[0] == 'D'))
    puts("H");
  else
    puts("D");
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
#define N 200010
#define M 30
vector<ll> v[M];
int F(int i,ll left,ll right){
    return lower_bound(v[i].begin(),v[i].end(),right)
    -lower_bound(v[i].begin(),v[i].end(),left);
}
int main(){
    ll n,a[N];
    cin>>n;
    lol(i,n)cin>>a[i];
    lol(i,n){
	ll x;cin>>x;
	lol(j,M){
	    v[j].push_back(x%((ll)2<<j));
	}
    }
    lol(i,M)sort(v[i].begin(),v[i].end());
    ll res=0;
    lol(i,M){
	ll ans=0;
	lol(j,n){
	    ll t=a[j]%((ll)2<<i);
	    ans+=F(i,((ll)1<<i)-t,((ll)2<<i)-t);
	    ans+=F(i,((ll)3<<i)-t,((ll)4<<i)-t);
	}
	res+=((ll)1<<i)*(ans%2);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 54244
#import<cstdio>
#define k 1024
#define r(a) for(i=0;i<a;i++)
#define s(a) scanf("%d",a);
#define m(a,b) a=a<b?a:b
int i,w,n,m,c[k],d[k],p[k];main(){s(&n)s(&m)r(n)s(d+i)r(m)s(c+i)r(n)p[i]=1e9;r(m*n)w=i%n,m(p[w],p[w+1]+c[i/n]*d[n-w-1]);printf("%d\n",p[0]);}

Measured memory_bytes: 1040
import sys
from collections import deque, defaultdict
import copy
import bisect
#sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions

import sys
def input():
	return sys.stdin.readline().strip()


def soinsu_bunkai(n):
	ans = []
	num = n
	i = 2
	while i <= n**0.5:
		if num % i == 0:
			if len(ans) == 0 or ans[-1][0] != i:
				ans.append([i, 1])
			else:
				ans[-1][1] += 1
			num = num//i
		else:
			i+=1
	if num != 1:
		ans.append([num, 1])

	return ans

N = int(input())

soinsu_list = defaultdict(int)
for i in range(2, N + 1):
	soinsu = soinsu_bunkai(i)
	for x in soinsu:
		soinsu_list[x[0]] += x[1]


ans = 1
for i in soinsu_list:
	ans *= soinsu_list[i] + 1
	ans = ans % 1000000007

print(ans)

Measured memory_bytes: 64748
INF = 1<<29
loop do
  n, m = gets.split.map(&:to_i)
  break if n == 0
  s = [[[0, 0]], *n.times.map { gets.split.map(&:to_i)[1..-1].each_slice(2).to_a } ]

  c = s.flatten(1).transpose[0].max

  dp = (n+1).times.map { (m+1).times.map { [INF] * (c+1) } }
  (m+1).times{ |i| dp[0][i].fill(0) }

  n.times do |i|
    (m+1).times do |j|
      s[i].each do |k, d0|
        s[i+1].each do |l, d1|
          x = i == 0 ? 0 : dp[i][j][k] + (l - k).abs * (d0 + d1)
          dp[i+1][j][l] = x if dp[i+1][j][l] > x
        end
      end
    end
    next if i == n - 1
    m.times do |j|
      s[i].each do |k, d0|
        s[i+2].each do |l, d1|
          x = i == 0 ? 0 : dp[i][j][k] + (l - k).abs * (d0 + d1)
          dp[i+2][j+1][l] = x if dp[i+2][j+1][l] > x
        end
      end
    end
  end
  min = dp[n][m].flatten.min
  m.times do |i|
    min = [dp[n-1][i].flatten.min, min].min
  end
  p min
end

Measured memory_bytes: 153092
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,T=MI()
    A=LI()
    mini = inf
    mini_cnt = 0
    max_profit = 0
    ans = 0
    for i,a in enumerate(A):
        profit = a-mini
        if max_profit==profit:
            ans += 1
        if max_profit<profit:
            max_profit = profit
            ans = 1
        if mini==a:
            mini_cnt+=1
        if mini>a:
            mini=a
            mini_cnt=1
    print(ans)

if __name__ == '__main__':
    main()

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

void fnInput(int64_t& rnNum)
{
  cin >> rnNum;
}

int fnDigitsCheck(int64_t nDivisor)
{
  int nDigitCnt = 0;
  while (nDivisor)
  {
    nDigitCnt++;
    nDivisor /= 10;
  }

  return nDigitCnt;
}

int fnMultiplCheck(int64_t nNum)
{
  int nMinDigit = fnDigitsCheck(nNum);

  for (int64_t n = 2; n * n <= nNum; n++)          // int型 n だとうまく行かない
  {
    if (nNum % n != 0)  continue;
    int64_t nOtr = nNum / n;
    nMinDigit = min(nMinDigit, fnDigitsCheck(nOtr));
  }
  return nMinDigit;
}

int main()
{
  int64_t nNum;
  
  fnInput(nNum);
  cout << fnMultiplCheck(nNum) << endl;

  return 0;
}


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

const ll INF = 1e9;
ll H,W,ans;
char F[1000][1000];
ll d[1000][1000];
typedef pair<ll,ll> P;
queue<P> que;
ll dx[4] ={1,0,-1,0},dy[4]={0,1,0,-1};

int main(void){
    cin >> H >> W;
    rep(i,H)rep(j,W){
        cin >> F[i][j];
        d[i][j] = INF;
        if(F[i][j] == '#'){
            que.push(mp(i,j));
            d[i][j] = 0;
        }
    }
    while(!que.empty()){
        P p = que.front();que.pop();
        ll x = p.first,y = p.second;
        rep(i,4){
            ll nx= x + dx[i],ny = y + dy[i];
            if(0<=nx && nx<H && 0<=ny && ny<W && F[nx][ny] == '.'){
                F[nx][ny] = '#';
                d[nx][ny] = d[x][y]+1;
                que.push(mp(nx,ny));
            }
        }
    }
    
    rep(i,H)rep(j,W){
        ans = max(d[i][j],ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 25396
import numpy as np
N,K = tuple(map(int,input().split()))
h = np.array(input().split(),dtype=np.int32)

dp = np.zeros(N,dtype=np.int32)
for i in range(1,N):
	dp[i] = np.min(np.abs(h[i]-h[max(0,i-K):i]) + dp[max(0,i-K):i])
print(dp[-1])


Measured memory_bytes: 21352
#include<bits/stdc++.h>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  double W,H,x,y;
  cin>>W>>H>>x>>y;
  double S = (double)W*H/2;
  bool flg = false;
  if(x == W/2 && y == H/2) flg =true;
  cout << setprecision(6) << S;
  if(flg) cout << " " << 1;
  else cout << " " << 0;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7,maxn=405;
int n,c;
ll sum[maxn],f[maxn][maxn];
int a[maxn],b[maxn];
int main(){
	cin>>n>>c;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		memset(sum,0,sizeof(sum));
		for(int j=a[i];j<=b[i];j++){
			ll t=1;
			for(int k=0;k<=c;k++){
				sum[k]=sum[k]+t;
				sum[k]%=mod;
				t=t*j%mod;
			}
		}
		for(int j=0;j<=c;j++)
			for(int k=0;k<=j;k++)
				f[i][j]=(f[i][j]+f[i-1][j-k]*sum[k])%mod;
	}
	printf("%d\n",f[n][c]);	
	return 0 ;
} 

Measured memory_bytes: 5012
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FOR(a,b,c) for(int a = (b); a <= (c); a++)
#define RFOR(a,b,c) for(int a = (b); a >= (c); a--)
#define all(x) (x).begin(), (x).end()
#define vi vector <int>
#define vvi vector <vi>
#define ll long long
#define vll vector <ll>
#define vvl vector <vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ep emplace
#define fs first
#define sd second
#define mod 998244353
#define EPS 1e-9
#define tc int t; cin >> t; while(t--)
using namespace std;

int main() {
    FIO;
    int n,k; cin >> n >> k;
    vi chk(n + 1);
    FOR(i,1,k){
        int x; cin >> x;
        while(x--) {
            int y; cin >> y;
            chk[y] = 1;
        }
    }
    int cnt = n;
    FOR(i,1,n) cnt -= chk[i];
    cout << cnt << '\n';
    return 0;
}


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

from collections import defaultdict
d = defaultdict(int)
cnt = 0
for i in range(N):
  s = input().replace("AB","#")
  cnt += s.count("#")
  l = 1 if s[0]  == "B" else 0
  r = 1 if s[-1] == "A" else 0
  d[(l,r)] += 1

if d[(1,0)]>0  and d[(0,1)]>1 :
  print(cnt+d[(1,1)] + min(d[(0,1)],d[(1,0)]))
elif d[(1,0)] >0 or d[(0,1)]>0:
  print(cnt+d[(1,1)] + min(d[(0,1)],d[(1,0)]))
else:
  print(cnt+max(0,d[(1,1)]-1))
  
  


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rs64() {
	int64_t n;
	scanf("%" SCNd64, &n);
	return n;
}

#define MOD 1000000007
template<int mod>
struct ModInt{
	int x;
	ModInt():x(0){}
	ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
	ModInt &operator+=(const ModInt &p){
		if((x+=p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator-=(const ModInt &p){
		if((x+=mod-p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator*=(const ModInt &p){
		x=(int)(1LL*x*p.x%mod);
		return *this;
	}
	ModInt &operator/=(const ModInt &p){
		*this*=p.inverse();
		return *this;
	}
	ModInt &operator^=(long long p){
		ModInt res = 1;
		for (; p; p >>= 1) {
			if (p & 1) res *= *this;
			*this *= *this;
		}
		return *this = res;
	}
	ModInt operator-()const{return ModInt(-x);}
	ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
	ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
	ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
	ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
	ModInt operator^(long long p)const{return ModInt(*this)^=p;}
	bool operator==(const ModInt &p)const{return x==p.x;}
	bool operator!=(const ModInt &p)const{return x!=p.x;}
	explicit operator int() const { return x; }						   // added by QCFium
	ModInt operator=(const int p) {x = p; return ModInt(*this);} // added by QCFium
	ModInt inverse()const{
		int a=x,b=mod,u=1,v=0,t;
		while(b>0){
			t=a/b;
			a-=t*b;
			std::swap(a,b);
			u-=t*v;
			std::swap(u,v);
		}
		return ModInt(u);
	}
	friend std::ostream &operator<<(std::ostream &os,const ModInt<mod> &p){
		return os<<p.x;
	}
	friend std::istream &operator>>(std::istream &is,ModInt<mod> &a){
		long long x;
		is>>x;
		a=ModInt<mod>(x);
		return (is);
	}
};
typedef ModInt<MOD> mint;

struct MComb {
	std::vector<mint> fact;
	std::vector<mint> inversed;
	MComb(int n) { // O(n+log(mod))
		fact = std::vector<mint>(n+1,1);
		for (int i = 1; i <= n; i++) fact[i] = fact[i-1]*mint(i);
		inversed = std::vector<mint>(n+1);
		inversed[n] = fact[n] ^ (MOD-2);
		for (int i = n - 1; i >= 0; i--) inversed[i]=inversed[i+1]*mint(i+1);
	}
	mint ncr(int n, int r) {
		return (fact[n] * inversed[r] * inversed[n-r]);
	}
	mint npr(int n, int r) {
		return (fact[n] * inversed[n-r]);
	}
	mint nhr(int n, int r) {
		assert(n+r-1 < (int)fact.size());
		return ncr(n+r-1, r);
	}
};



int main() {
	int n = ri();
	int x[n];
	for (auto &i : x) i = ri();
	int dist[n - 1];
	for (int i = 0; i + 1 < n; i++) dist[i] = x[i + 1] - x[i];
	mint res = 0;
	MComb com(n);
	mint sum = 0;
	for (int i = 0; i + 1 < n; i++) {
		sum += com.fact[n - 1] / com.fact[i + 1] * com.fact[i];
		res += sum * mint(dist[i]);
	}
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 1792
import sys
s=input()
k="dream"
l="erase" #5文字ペア
m="eraser" #6文字
n="dreamer" #7文字
while True:
    if s=="":
        print("YES")
        sys.exit()
    elif k in s[-5:]:
        s=s[:-5]            
    elif l in s[-5:]:
        s=s[:-5]
    elif m in s[-6:]:
        s=s[:-6]
    elif n in s[-7:]:
        s=s[:-7]
    else:
        print("NO")
        sys.exit()

Measured memory_bytes: 3188
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class AtCoder {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String n = in.next();
            int sum = 0;
            for (int i = 0; i < n.length(); i++) {
                sum += (n.charAt(i) - '0');
            }

            if (Integer.parseInt(n) % sum == 0) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }
    }
}


Measured memory_bytes: 23380
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val time = StdIn.readInt()
    val h = time / 3600
    val m = (time % 3600) / 60
    val s = (time % 3600) % 60
    println(s"$h:$m:$s")
  }
}

Measured memory_bytes: 43848
// https://atcoder.jp/contests/abc136/tasks/abc136_a
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#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))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if (c - (a - b) >= 0) {
        cout << c - (a - b) << endl;
    } else {
        cout << "0\n";
    }
    return 0;
}


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

int main(){
  int N, M, C;
  int A[20][20], B[20], r[20], res=0;
  int i,j;
  
  cin >> N >> M >> C;
  for(i=0;i<M;i++){
    cin >> B[i];
  }
  for(i=0;i<N;i++){
    for(j=0;j<M;j++){
      cin >> A[i][j];
    }
  }
  
  for(i=0;i<N;i++){
    r[i]=0;
    for(j=0;j<M;j++){
      r[i]+=A[i][j]*B[j];
    }
    r[i]+=C;
    if(r[i]>0){
      res++;
    }
  }
  
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int H,W,K;
    cin >> H >> W >> K;
    vector<string>c(H);
    for(int i = 0; i < H; i++) {
        cin >> c[i];
    }
    int ans = 0;
    for(int bit = 0; bit < (1 << (H+W)); bit++) {
        int cnt = 0;
        for(int i = 0; i < H; i++) {
            if(1 & (bit >> i)) {
                continue;
            }
            for(int j = 0; j < W; j++) {
                if(1 & (bit >> (H+j))) {
                    continue;
                }
                if(c[i][j] == '#') {
                    cnt++;
                }
            }
        }
        if(cnt == K) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3604
// -*- coding:utf-8-unix -*-

 
use proconio::input;

fn main() {
    /*     input! {
        n: usize,
        mut plan: [(i32, i32, i32); n],  // Vec<(i32, i32, i32)>
    }
 */
    input! {
        n: u32,
    }
    let tot = (n as f32 / 1.08).ceil();
    if (tot * 1.08) as u32 == n {
        println!("{}",tot);
    }else{
        println!(":(");
    }


}


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

int main(){
	while(1){
		int n,score=0;
		std::cin>>n;
		if(n==0)break;
		std::vector<int>v(n);
		for(int i=0;i<n;i++)std::cin>>v[i];
		for(int i=0;i<n;i++){
			for(int j=0;j<n-1;j++){
				if(v[j]>v[j+1]){
					v[j]^=v[j+1];
					v[j+1]^=v[j];
					v[j]^=v[j+1];
				}
			}
		}
		for(int i=1;i<n-1;i++)score+=v[i];
		std::cout<<score/(n-2)<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1196
n, k = map(int,input().split())
p = list(map(int,input().split()))

ranges = 0
temp = 0
for i in range(n - k + 1):
    if ranges == 0:
        ranges = sum(p[:k])
        temp = ranges
    else:
        temp = temp - p[i - 1] + p[i - 1 + k]
        if temp > ranges:
            ranges = temp

ans = (ranges + k) / 2
print(ans)

Measured memory_bytes: 25060
# D

import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import breadth_first_order

N, M = list(map(int, input().split()))

row = []
col = []
for i in range(M):
    r, c = list(map(int, input().split()))
    row.append(c-1)
    col.append(r-1)

data = [1] * (M)

csr = csr_matrix((data, (row, col)), shape=(N, N))
_, proc = breadth_first_order(csr, 0, directed=False)

if -9999 in proc[1:]:
  print('No')
else:
  print('Yes')
  print('\n'.join((proc[1:]+1).astype('str')))

Measured memory_bytes: 74520
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fill(x,c) memset(x,c,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int SIZE = 1e6+10;
ll a[SIZE];
int main() {
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n,t;
	cin>>n>>t;
	ll sum=0;
	rep(i,0,t){
		cin>>a[0];
		sum+=a[0];
	}
	cout<<(sum>=n?"Yes":"No");
  	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		long x = Long.parseLong(tokens[1]);
		tokens = in.nextLine().split(" ");
		List<Long> a = new ArrayList<>(N);
		for (int i = 0; i < N; ++i) {
			a.add(Long.parseLong(tokens[i]));
		}
		Collections.sort(a);

		long childrenNum = 0;
		boolean lack = false;
		for (int i = 0; i < N - 1; ++i) {
			if (x - a.get(i) < 0) {
				lack = true;
				break;
			}
			childrenNum++;
			x -= a.get(i);
		}
		if (!lack && x == a.get(N - 1)) {
			childrenNum++;
		}
		if (childrenNum < 0) {
			childrenNum = 0;
		}
		System.out.println(childrenNum);

		in.close();
	}
}

Measured memory_bytes: 22996
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
int main() {
	int i, j, n, p[10001] = {0};
	for (i = 2; i <= 10000; i++) if(p[i]==0) for (j = 2 ;i*j <= 10000; j++) p[i*j] = 1;
		
	while (scanf("%d", &n),n!=0) {
		for (i = n; i >= 2; --i)
			if (p[i] == 0 && p[i - 2] == 0) {
				printf("%d %d\n", i - 2, i);
				break;
			}
	}
	return 0;
}

Measured memory_bytes: 644
program double_factorization
    implicit none
    integer(kind=8) :: n
    integer(kind=8) :: ans

    read(*, *) n
    ans = min(g2(n, 2), g2(n, 5))
    print *, ans


contains
    recursive integer(kind=8) function g1(n, p) result(res)
        implicit none
        integer(kind=8), intent(in) :: n
        integer(kind=4), intent(in) :: p
        
        if(n == 0) then
            res = 0
        else
            res = n/p + g1(n/p, p)
        endif
   
    end function g1

    recursive integer(kind=8) function g2(n, p) result(res)
        implicit none
        integer(kind=8), intent(in) :: n
        integer(kind=4), intent(in) :: p

        res = 0

        if(mod(n, 2) == 1) then
            res = g1(n, p) - g2(n-1, p)
        else
            res = g1(n/2, p)

            if(p == 2) then
                res = res + n/2
            endif
        endif

    end function g2

end program double_factorization

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
using ll = long long;
int main() {
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	if (A + B < 2*C) {
		cout << A * X + B * Y << endl;
	}
	else {
		if (X < Y) {
			int ans1 = 2 * Y*C;
			int ans2 = 2 * X*C + (Y - X)*B;
			if (ans1 < ans2)
				cout << ans1 << endl;
			else
				cout << ans2 << endl;
		}
		else {
			int ans3 = 2 * X*C;
			int ans4 = 2 * Y*C + (X - Y)*A;
			if (ans3 < ans4)
				cout << ans3 << endl;
			else
				cout << ans4 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
int main() {
    long n,m;
    multimap<long,long> ml;
	cin >> n >> m;
    for(long i = 0; i < n;i++) {
        long a,b;
        cin >> a >>b;
        ml.insert(make_pair(a, b));
    }
    long bottle = m;
    long money = 0;
    for(pair<long, long> p:ml){
        if(bottle <= 0) break;
        if(p.second >= bottle) {
            money += p.first * bottle; 
            break;
        }
        else {
		money += p.first * p.second;
        bottle -= p.second;}
	}
    cout << money;
}

Measured memory_bytes: 6528
#include<iostream>
#include<stdlib.h>
using namespace std;

static const int MAX = 100;
static const int INF = (1<<21);
int color[MAX] = {0};
int M[MAX][MAX];
int d[MAX];

void prim(int n) {
    d[0] = 0;
    int minconst = INF, u, i;
    for ( i = 1; i < n; i++ ) d[i] = INF;

    while(1) {
        minconst = INF;
        for ( i = 0; i < n; i++ )
        {
            if ( color[i] != 1 && minconst > d[i] ) {
                minconst = d[i];
                u = i;
            }
        }

        if ( minconst == INF )
            break;

        color[u] = 1;

        for ( i = 0; i < n; i++ ) {
            if ( color[i] != 1 && M[u][i] != -1 ) {
                if ( M[u][i] < d[i] ) d[i] = M[u][i];
            }
        }
    }
}

int main() {
    int n, i, j;

    cin >> n;
    for ( i = 0; i < n; i++ ) {
        for ( j = 0; j < n; j++ ) {
            cin >> M[i][j];
        }
    }

    prim(n);

    int sum = 0;
    for ( i = 0; i < n; i++ ) {
        sum += d[i];
    }
    cout << sum << endl;
}



Measured memory_bytes: 3112
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef _DEBUG

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 200005
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
struct Node {
	int S, T, XX;
	Node() {}
	Node(int S, int T, int XX) :S(S), T(T), XX(XX) {}
};
struct Query {
	int id, D, block;
	Query() {}
	Query(int id, int D) :id(id), D(D) {
		block = -1;
	}
};
bool mycomp(Node& a, Node& b) {
	if (a.XX != b.XX) return a.XX < b.XX;
	return a.S < b.S;
}
struct querycomp {
	bool operator() (const Query&lhs, const Query& rhs) const {
		return lhs.D < rhs.D;
	}
};
bool querycomp2(Query&lhs, Query& rhs) {
	return lhs.id < rhs.id;
}
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");

	int N, Q;
	scanf("%d %d", &N, &Q);
	vector <Node> ns(N);
	for (int i = 0; i < N; i++) {
		int S, T, XX;
		scanf("%d %d %d", &S, &T, &XX);
		ns[i] = Node(max(S - XX, 0), max(T - XX, 0), XX);
	}
	sort(ALL(ns), mycomp);
	set <Query, querycomp> ss;
	for (int j = 0; j < Q; j++) {
		int D;
		scanf("%d", &D);
		ss.insert(Query(j, D));
	}
	vector <Query> res;
	for (int i = 0; i < N; i++) {
		auto itr = ss.lower_bound(Query(0, ns[i].S));
		while (itr != ss.end() and itr->D >= ns[i].S and itr->D < ns[i].T) {
			res.push_back(*itr);
			res.back().block = ns[i].XX;
			auto next_itr = itr;
			next_itr++;
			ss.erase(itr);
			itr = next_itr;
		}
	}
	while (!ss.empty()) {
		res.push_back(*ss.begin());
		ss.erase(*ss.begin());
	}
	sort(ALL(res), querycomp2);
	for (int j = 0; j < Q; j++) printf("%d\n", res[j].block);
	return 0;
}

Measured memory_bytes: 19568
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;

bool check(string cur) {
	set<char> ss;
	for (char x : cur)ss.insert(x);
	return (ss.size() != cur.size());
}

void solve() {
	string s; cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (i + 1 < s.length() && check(s.substr(i, 2))) {
			cout << i + 1 << ' ' << i + 2 << endl;
			return ;
		}
		if (i + 2 < s.length() && check(s.substr(i, 3))) {
			cout << i + 1 << ' ' << i + 3 << endl;
			return ;
		}
	}
	cout << -1 << ' ' << -1;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// int t; cin >> t;
	// while (t--)
	solve();

}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define ll long long
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define rep2(i,a,b) for(ll i=a;i>=b;i--)

int main(int argc, char** argv) {
	ll n,a,b;
	cin>>n>>a>>b;
	if(a==0&&b==0)
	{
		printf("0");
		return 0;
	}
	ll bf=n/(a+b)*(a);
	if(n%(a+b)<a)
	{
		bf+=n%(a+b);
	}
	else bf+=a;
	cout<<bf;
	return 0;
}

Measured memory_bytes: 256
line = input()
a, b, c, x, y = map(int, line.split(' '))

if x < y:
    pizza = [(x, a), (y, b)]
else:
    pizza = [(y, b), (x, a)]

values = list()
values.append(c * 2 * pizza[0][0] + pizza[1][1] * (pizza[1][0] - pizza[0][0]))
values.append(c * 2 * pizza[1][0])
values.append(a * x + b * y)

print(min(values))


Measured memory_bytes: 3064
<?php
$tower = [
  [
    [0,0,0,0,0,0,0,0,0,0,],
    [0,0,0,0,0,0,0,0,0,0,],
    [0,0,0,0,0,0,0,0,0,0,],
  ],
  [
    [0,0,0,0,0,0,0,0,0,0,],
    [0,0,0,0,0,0,0,0,0,0,],
    [0,0,0,0,0,0,0,0,0,0,],
  ],
  [
    [0,0,0,0,0,0,0,0,0,0,],
    [0,0,0,0,0,0,0,0,0,0,],
    [0,0,0,0,0,0,0,0,0,0,],
  ],
  [
    [0,0,0,0,0,0,0,0,0,0,],
    [0,0,0,0,0,0,0,0,0,0,],
    [0,0,0,0,0,0,0,0,0,0,],
  ],
];
$info = trim(fgets(STDIN));
for ($k = 0; $k < $info; $k++){
  $input_num = explode(" ", trim(fgets(STDIN)));
  $tower[$input_num[0] -1][$input_num[1] -1][$input_num[2] -1] = $tower[$input_num[0] -1][$input_num[1] -1][$input_num[2] -1] + $input_num[3];
}
foreach ($tower as $key => $value) {
  if ($key != 0)
    echo '####################'. PHP_EOL;
  foreach ($value as $k => $v) {
    echo ' ';
    echo implode(' ',$v);
    echo PHP_EOL;
  }
}

Measured memory_bytes: 9336
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node{
    int key;
    Node *prev;
    Node *next;
};

Node *nil;

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int key){
    Node *x = (Node*)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

Node* listSearch(int key){
    Node *cur = nil->next;
    while(cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *t){
    if( t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(cur != nil){
        if(isf++ > 0)printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

int main(){
    int n;
    scanf("%d", &n);
    int i, key;
    char command[100];
    init();
    for(i = 0; i < n; i++){
        scanf("%s%d", command, &key);
        if(command[0] == 'i'){
            insert(key);
        }else if(command[0] == 'd'){
            if(strlen(command) > 6){
                if(command[6] == 'F'){
                    deleteFirst();
                }else if(command[6] == 'L'){
                    deleteLast();
                }
            }else{
                deleteKey(key);
            }
        }
    }
    printList();

    return 0;
}


Measured memory_bytes: 33944
def main():
    S = list(input())
    num_stone = 0
    num_paper = 0
    ans = 0
    for c in S:
        if c == 'g':
            if num_paper < num_stone:
                num_paper += 1
                ans += 1
            else:
                num_stone += 1
        else:
            if num_paper < num_stone:
                num_paper += 1
            else:
                num_stone += 1
                ans -= 1
    print(ans)
main()


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

#define PI 4*atan(1)
#define INF 1e8

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  int n;
  for(int i = 1; i <= N*M; i++){
    if(i % N == 0 && i % M == 0){
      n = i;
      break;
    }
  }

  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  int now = 0, ans = 0;
  for(int i = 0; i < n / M; i++){
    int _max = 0;
    int _min = INF;
    for(int j = 0; j < M; j++){
      _max = max(_max, A[now]);
      _min = min(_min, A[now]);
      now++;
      if(now >= N)now = 0;
    }
    ans += (_max - _min);
  }
  cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

ll dp[100003];

int main() {
  ll n, ans = 0, k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  rep(i, 100003) dp[i] = INF;
  dp[0] = 0;
  dp[1] = abs(h[0] - h[1]);
  for (int i = 2; i < n; ++i)
    for (int j = 1; i - j >= 0 && j <= k; ++j)
      dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));

  cout << dp[n - 1] << endl;
  return 0;
}


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

int main() {
	int x, y;
	while(1){
	 cin >> x >> y;
	 if(x == 0 && y == 0)break;
	 if(x <= y)cout << x << " " << y << endl;
	 else cout <<y << " " << x << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
	int array[30];
	int w, n;

	cin >> w;
	cin >> n;
	for(int i = 0; i < w; i++) {
		array[i] = i + 1;
	}
	for(int i = 0; i < n; i++) {
		int a, b, c;
		scanf("%d,%d", &a, &b);
		c = array[a - 1];
		array[a - 1] = array[b - 1];
		array[b - 1] = c;
	}

	for(int i = 0; i < w; i++) {
		cout << array[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1240
import sys
import numpy as np


def solve(field):
    idx = np.arange(field.size).reshape(field.shape)
    field_idx = field * idx
    li = np.maximum.accumulate(field_idx, axis=1)
    ui = np.maximum.accumulate(field_idx, axis=0)

    field_idx += (field ^ 1) * field.size
    ri = np.fliplr(np.minimum.accumulate(np.fliplr(field_idx), axis=1))
    di = np.flipud(np.minimum.accumulate(np.flipud(field_idx), axis=0))
    return (ri - li + (di - ui) // field.shape[1]).max() - 3


h, w = list(map(int, input().split()))
h2, w2 = h + 2, w + 2
field = np.ones((h2, w2), dtype=np.int32)
field[1:h + 1, 1:w + 1] = [[c == '#' for c in line.rstrip()] for line in sys.stdin]
print(solve(field))


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

int		main(void)
{
	int n;
	cin >> n;
	vector<int> t(n);
	for (int i = 0; i < n; i++)
		cin >> t[i];
	int m;
	cin >> m;
	vector<int> p(m);
	vector<int> x(m);
	for (int i = 0; i < m; i++)
	{
		cin >> p[i];
		cin >> x[i];
	}
	for (int i = 0; i < m; i++)
	{
		int index = p[i] - 1;
		int tmp = t[index];
		t[index] = x[i];
		int total = accumulate(t.begin(), t.end(), 0);
		cout << total << endl;
		t[index] = tmp;
	}
}


Measured memory_bytes: 256
n = gets.to_i
as = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)

cnt =0
for i in 0...bs.size
  cnt+=[bs[i],as[i]+as[i+1]].min
  as[i+1]=[as[i+1]-(bs[i]-as[i]),0].max if as[i]<bs[i]
end
puts cnt


Measured memory_bytes: 19596
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

void out(vector<ll> &ans) {
    rep(i, 3) { cout << ans[0] << " "; }
    cout << endl;
}

int main() {
    // source
    ll n, y;
    cin >> n >> y;
    rep(i, (y / 10000) + 1) {
        rep(j, (y / 5000) + 1) {
            ll k = n - i - j;
            if (k < 0) {
                continue;
            }
            ll num = i * 10000 + j * 5000 + k * 1000;
            if (num == y) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

#define N 10000000

int prinum[N];

void prime(){
    for(int i=2;i*i<N;i++){
        if(prinum[i]==1)continue;
        for(int j=i*2;j<N;j+=i){
            prinum[j]=1;
        }
    }
}

int main(){
    int n,cou;
    prinum[0]=prinum[1]=1;
    prime();
    while(cin >> n,n){
        cou=0;
        for(int i=n+1;i<=2*n;i++){
            if(prinum[i]==0)cou++;
        }
        cout << cou << endl;
    }
}



Measured memory_bytes: 42112
n = int(input())
A = [list(map(int, list('{:020b}'.format(a))))
     for a in map(int, input().split())]

ans = 0
R = -1
X = [0]*20
for L in range(n):
    while R+1 < n and all(x+y != 2 for x, y in zip(X, A[R+1])):
        for i in range(20):
            X[i] += A[R+1][i]
        R += 1
    ans += R-L+1
    for i in range(20):
        X[i] -= A[L][i]
print(ans)

Measured memory_bytes: 125020
#include <vector>
#include <iomanip>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<int> adj[n];
    while (m--) {
        int s, t; cin >> s >> t;
        adj[s-1].push_back(t-1);
    }
    for (int i = 0; i < n; i++) sort(adj[i].begin(), adj[i].end());
    double dp1[n];
    dp1[n-1] = 0;
    for (int k = n-2; k >= 0; k--) {
        double tmp = 0;
        for (int x : adj[k]) tmp += dp1[x];
        tmp /= adj[k].size();
        dp1[k] = tmp + 1;
    }
    double ans = dp1[0];
    for (int i = 0; i < n; i++) {
        if (adj[i].size() <= 1) continue;
        int j = adj[i][0];
        for (int k : adj[i]) if (dp1[k] > dp1[j]) j = k;
        double dp[n];
        dp[n-1] = 0;
        for (int k = n-2; k >= 0; k--) {
            double tmp = 0;
            for (int x : adj[k])
                if (k != i || x != j) tmp += dp[x];
            tmp /= adj[k].size() - (k == i);
            dp[k] = tmp + 1;
        }
        ans = min(dp[0], ans);
    }
    cout << setprecision(16) << ans << endl;
}


Measured memory_bytes: 1408
#define ll long long
#define MOD 1000000007
#define MOD2 998244353
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set2d(array, val, m, n) memset(array, val, sizeof(array[0][0]) * m * n);
#include <bits/stdc++.h>
using namespace std;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x %= p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll po(ll base, ll powerRaised)
{
    if (powerRaised != 0)
        return (base * po(base, powerRaised - 1));
    else
        return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, m;
    cin >> n >> m;
    ll sum = 0, cnt = 0;
    vector<ll> v;
    for (int i = 0; i < n; i++)
    {
        ll x;
        cin >> x;
        v.pb(x);
        sum += x;
    }
    ll tp = (sum / (4 * m));
    if (sum % (4 * m) != 0)
        tp++;
    for (int i = 0; i < n; i++)
    {
        if (v[i] >= tp)
            cnt++;
    }
    if (cnt >= m)
        cout << "Yes";
    else
        cout << "No";
}

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

typedef long long ll;
const int MOD = 2019;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    vector<int> cnt(2020);
    cnt[0] = 1; // remainder 0 already exists once
    ll ans = 0;
    // subtract suffixes
    ll num = 0;
    ll pot = 1;
    for (int i = s.length() - 1; i >= 0; --i) {
        ll cur = s[i] - '0';
        num += (cur * pot) % MOD;
        ans += cnt[num % MOD];
        cnt[num % MOD]++;
        pot = pot * 10 % MOD;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N,M,Q;
vector<int> A,B,C,D,V;

vector<int> g[100010];
int color[100010];
int visited[100010];

int main(){
  cin>>N>>M;
  A.resize(M);
  B.resize(M);
  rep(i,M) cin>>A[i]>>B[i];
  cin>>Q;
  C.resize(Q);
  D.resize(Q);
  V.resize(Q);
  rep(i,Q) cin>>V[i]>>D[i]>>C[i];

  rep(i,M){
    A[i]--;B[i]--;
    g[A[i]].push_back(B[i]);
    g[B[i]].push_back(A[i]);
  }
  rep(i,N) visited[i]=-1;

  for(int i=Q-1;i>=0;i--){
    V[i]--;
    if(visited[V[i]]>=D[i]) continue;

    queue<int> Q;
    Q.push(V[i]);
    visited[V[i]]=D[i];
    while(!Q.empty()){
      int now=Q.front();
      Q.pop();

      if(color[now]==0) color[now]=C[i];
      if(visited[now]==0) continue;

      for(auto nex:g[now]){
        if(visited[nex]>=visited[now]-1) continue;
        visited[nex]=visited[now]-1;
        Q.push(nex);
      }
    }
  }

  for(int i=0;i<N;i++) cout<<color[i]<<endl;


  return 0;
}


Measured memory_bytes: 9592