akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long 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 = 1LL << 60;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    for (int i = 1; i < n; i++) {
        int cnt = 0;
        for (char c = 'a'; c <= 'z'; c++) {
            bool left = false; bool right = false;
            for (int j = 0; j < i; j++) {
                if (s[j] == c) left = true;
            }
            for (int j = i; j < n; j++) {
                if (s[j] == c) right = true;
            }
            if (left && right) cnt++;
        }
        chmax(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

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

int m, d;
int M, D;

int main() {
  cin >> m >> d;
  cin >> M >> D;
  if (m==4 || m==6 || m==9 || m==11) {
    if (d==30) cout << 1 << endl;
    else cout << 0 << endl;
  }
  else if (m==2) {
    if (d==28) cout << 1 << endl; 
    else cout << 0 << endl; 
  }
  else {
    if (d==31) cout << 1 << endl;
    else cout << 0 << endl;    
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int m,f,b;
	scanf("%d %d %d",&m,&f,&b);
	if(m>b)
		puts("0");
	else{
		if((m+f)>=b)
			printf("%d\n",b-m);
		else
			puts("NA");	
		}
	return 0;
}


Measured memory_bytes: 2112
import Control.Applicative

main :: IO ()
main = do
    [a, b] <- map read . words <$> getLine
    putStrLn $ solve a b 
    
solve :: Int -> Int -> String
solve a b = if a == b then "Draw" 
            else if a == 1 then "Alice" 
            else if b == 1 then "Bob"
            else if a > b then "Alice" 
            else "Bob"

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INFL=1LL << 60;
const long long INF=1<<29;

int main() {
    ll N;
    cin >>N;
    vector<ll> A(5);
    ll count=0;
    ll Amin=INFL;
    for(int i=0;i<5;i++){
        cin >>A.at(i);
        Amin=min(A.at(i),Amin);
    }
    count=N/Amin+4;
    if(N%Amin!=0) count++;
    cout <<count<<endl;

    return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <unordered_map>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

int const MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-12;
int INF = INT_MAX / 10;

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

int main() {
	int H, W, K; cin >> H >> W >> K;
	vector<vector<bool> > a(H, vector<bool>(W));
	int y0, x0;
	rep(y, H) {
		string s; cin >> s;
		rep(x, W) a[y][x] = (s[x] == '#');
		rep(x, W) if (s[x] == 'S') y0 = y, x0 = x;
	}
	vector<vector<int> > d(H, vector<int>(W, INF));
	d[y0][x0] = 0;
	queue<i_i> q;
	q.push(i_i(y0, x0));
	while (!q.empty()) {
		int y = q.front().first, x = q.front().second;
		q.pop();
		if (d[y][x] == K) continue;
		rep(k, 4) {
			int _y = y + dy[k], _x = x + dx[k];
			if (0<=_y && _y<H && 0<=_x && _x<W && !a[_y][_x] && d[y][x] + 1 < d[_y][_x]) {
				d[_y][_x] = d[y][x] + 1;
				q.push(i_i(_y, _x));
			}
		}
	}
	int ans = INF;
	rep(y, H) rep(x, W) if (d[y][x] <= K) {
		int mi = INF;
		mi = min(mi, y);
		mi = min(mi, H - y - 1);
		mi = min(mi, x);
		mi = min(mi, W - x - 1);
		ans = min(ans, (mi + K - 1) / K);
	}
	cout << ans + 1 << endl;
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int s, w;
  cin >> s >> w;

  bool res = w >= s;

  cout << (res ? "unsafe" : "safe") << endl;

  return 0;
}


Measured memory_bytes: 3632
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8').split(' ');
let h = +input[0];

let count = 0;

while (h > 0) {
  // console.log(`h: ${h}`);
  count++;
  h = Math.floor(h / 2);
}

console.log((2 ** count) - 1);


Measured memory_bytes: 7372
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import *

setrecursionlimit(10**7)

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

MOD = 10**9 + 7

N, M = reads()
A = reads()
B = reads() 

setA = set(A)
setB = set(B)

if len(setA) < len(A) or len(setB) < len(B):
  print(0); exit()

P = N * M
A.sort()
B.sort()

ans = 1
for i in range(P, 0, -1):
  inA = i in setA
  inB = i in setB
  w = N - bisect(A, i)
  h = M - bisect(B, i)
  if inA and inB:
    p = 1
  elif inA:
    p = h
  elif inB:
    p = w
  else:
    p = w * h - (P - i)
  if p <= 0:
    print(0); exit()
  ans = ans * p % MOD

print(ans)


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

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

int main(){
  int a,b;
  char op;
  cin >> a >> op >> b;
  if(op=='-')cout << a-b << endl;
  else cout << a+b << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

vector<int> v[26];

int main(){
  string s;
  cin >> s;
  int n=s.size();
  if(n%2){
    if(s[0]==s[n-1])cout << "Second" << endl;
    else cout << "First" << endl;
    return 0;
  }else{
    if(s[0]==s[n-1])cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
  }
  cout << "Second" << endl;
return 0;}

Measured memory_bytes: 512
def identification(x,y,arr)
    if(arr[y][x]==1)
        arr[y][x]=0
        identification(x-1,y,arr) if x-1>=0 && arr[y][x-1]==1
        identification(x+1,y,arr) if x+1<12 && arr[y][x+1]==1
        identification(x,y-1,arr) if y-1>=0 && arr[y-1][x]==1
        identification(x,y+1,arr) if y+1<12 && arr[y+1][x]==1
        return true
    end
    return false
end
while !STDIN.eof?
    arr=[]
    count=0
    12.times do
        arr<<gets.split(//).map(&:to_i)
    end
    gets
    12.times do |y|
        12.times do |x|
            count+=1 if identification(x,y,arr)
        end
    end
    p count
    break if $_==nil
end

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

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

struct edge { int to,cost; };
const int MOD=1e9+7;

int main() {
  int N;cin>>N;
  string S;cin>>S;
  string res="";
  REP(i,S.size()){
    int tmp = S[i]-0-64+N;
    if (tmp>26) tmp -= 26;
    tmp += 64;
    res.push_back((char)tmp);
  }
  OUT(res);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  string s;
  int w;
  cin >> s >> w;
  string ans = "";
  int idx = 0;
  while (idx < s.size()) {
    ans += s[idx];
    idx += w;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  double A,B,H,M;
  cin >> A>>B>>H>>M;
  M=M+ 60*H;
  
  double kakudo;
  kakudo= M*(5.5);
  while(kakudo>=360){
   kakudo=kakudo-360; 
  }
  if(kakudo<0){
    kakudo=(-1)*kakudo;
  }
  if(kakudo>=180){
    kakudo=360-kakudo;
  }

  
  kakudo=kakudo*(3.14159265358979323846)/180;

  double KK;
  KK=sqrt( A*A + B*B - 2*A*B*cos(kakudo));
  cout <<std::setprecision(15)<< KK << endl;
  return 0;
}



Measured memory_bytes: 4192
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> a(N),b(N),c(N);
  rep(i,N) {
    cin >> a.at(i);
  }
  rep(i,N) {
    cin >> b.at(i);
  }
  rep(i,N) {
    cin >> c.at(i);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  long ans=0;
  rep(i,N) {
    int d=b.at(i);
    int A=lower_bound(a.begin(),a.end(),d)-a.begin();
    int C=N-(upper_bound(c.begin(),c.end(),d)-c.begin());
    
    ans = ans+(long)(A)*C;
    
  }
 
  

    cout<<ans<<endl;
  
}
  

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>

using namespace std;


typedef long long ll;
 
bool prime(long a){
    int ans=0;
    for (long i=2;i<sqrt(a);i++) if(a%i==0) ans=1;
    if(ans) return false;
    else return true;
}

int main(void){
    long x;
  cin >> x;
    for(long i=x;;i++){
        if(prime(i)) {
            cout << i << endl;
            break;
        }
    }
}



Measured memory_bytes: 256
from collections import defaultdict, Counter

H, W, N = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]

d = defaultdict(int)
for a, b in ab:
  for da in range(3):
    aa = a - da
    if aa < 1 or H < aa + 2:
      continue
    for db in range(3):
      bb = b - db
      if bb < 1 or W < bb + 2:
        continue
      
      d[(aa, bb)] += 1

num = [0] * 10
num[0] = (H - 2) * (W - 2)
count_n = Counter(list(d.values()))
for i in range(1, 10):
  n = count_n[i]
  num[i] += n
  num[0] -= n

print(*num, sep='\n')

Measured memory_bytes: 180056
#include <iostream>
#include <bitset>
#include <string>

using namespace std;

int main() {
  string n; cin >> n;
  int num[4] = {};
  char op[4] = {};
  for (int i = 0; i < 4; ++i) {
    num[i] = n[i] - '0';
  }
  for (int i = 0; i < 8; ++i) {
    int ans = num[0];
    bitset<3> x = static_cast<bitset<3> >(i);
    for (int j = 0; j < 3; ++j) {
      if (x[j]) ans += num[j + 1];
      else ans -= num[j + 1];
    }
    if (ans == 7) {
      cout << num[0];
      for (int j = 0; j < 3; ++j) {
        if (x[j]) cout << '+';
        else cout << '-';
        cout << num[j + 1];
      }
      cout << "=7" << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define all(a) a.begin(),a.end()
typedef pair<int,int> P;
const long long mod=998244353;
const long long inf=1ll<<61;

signed main(){
	int k;cin>>k;
	int now=0;
	rep(i,3e6){
		now=now*10+7;
		now%=k;
		if(now==0){
			cout<<i+1<<endl;return 0;
		}
	}
	cout<<-1<<endl;
}

Measured memory_bytes: 3612
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
		
		int k=sc.nextInt();
		
		//最初はk通り。
		//次は隣とかぶらないようにk-1通り。
		
		long result=(int) (k*Math.pow((k-1),n-1));
		
		System.out.println(result);
		
		sc.close();


	}



}



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

const int maxn = int(4e4) + 10, mod = int(1e9) + 7;
typedef long long ll;
ll fac[maxn], inv[maxn]; //inv阶乘逆元 
int n, a[2000007], b[2000007], dp[4007][4007];

ll power_mod(ll p, ll q) 
{
    ll ret = 1;
    while (q) 
	{
        if (q & 1) ret = ret * p % mod;
        p = p * p % mod;
        q >>= 1;
    }
    return ret;
}

void init() 
{
    fac[0] = 1;
    for (int i = 1; i <= maxn - 10; i++) fac[i] = fac[i - 1] * i % mod;
    inv[maxn - 10] = power_mod(fac[maxn - 10], mod - 2);
    for (int i = maxn - 10; i > 0; i--) inv[i-1] = inv[i] * i % mod;
}

ll C(int n, int m) 
{
    return fac[n] * inv[m] % mod * inv[n - m] % mod;
}

int main() 
{
    init();
    cin >> n;
    for (int i = 1; i <= n; i++) 
	{
        cin >> a[i] >> b[i];
        dp[2001 - a[i]][2001 - b[i]]++;  //将整个坐标系向右上方偏移2000个单位 
    }
    
    for (int i = 1; i <= 4001; i++)
        for (int j = 1; j <= 4001; j++) 
		{
            dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
            dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
        }
        
    ll ans = 0;
    for (int i = 1; i <= n; i++) ans = (ans + dp[2001 + a[i]][2001 + b[i]]) % mod;
    for (int i = 1; i <= n; i++) ans = (ans - C(a[i] + a[i] + b[i] + b[i], a[i] + a[i]) + mod) % mod;
    cout << ans * power_mod(2, mod - 2) % mod << endl;
    
    return 0;
}

Measured memory_bytes: 68480
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
//const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int K;
    string S;
    cin>>K>>S;
    int L=S.size();
    if(L<=K){
        cout<<S<<endl;
    }else{
        for(int i=0;i<K;i++){
            cout<<S[i];
        }
        cout<<"..."<<endl;
    }
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)

bool pal(string s)
{
	string t=s;
	reverse(t.begin(),t.end());
	if(s==t)	return true;
	else return false;
}
int main() 
{		
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	string s;
	cin>>s;
	if(s.size()%2==0)	cout<<"NO";
	else
	{
		int flag=0;
		if(pal(s))	flag=1;
		if(flag==0)	{cout<<"No"; return 0;}
		long long int a=(s.size()-1)/2,b=(s.size()+3)/2;
		string t=string(s,a+1);
		if(!pal(t))	{cout<<"No"; return 0;}
		cout<<"Yes";
	}	
	return 0;	
}

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

struct Button{
	int x1,x2,y1,y2;
	string link;
};


void click(int x, int y, string& now, map< string , vector<struct Button> >& page, int& p, vector<string>& buff){
	vector<Button> B = page[now];
	string to;
	for(int i=0 ; i < B.size() ; i++ ){
		if( B[i].x1 <= x && x <= B[i].x2 && B[i].y1 <= y && y <= B[i].y2 ){
			to = B[i].link;
		}
	}
	if( !to.empty() ){
		now = to;
		while( p != buff.size()-1 ){
			buff.pop_back();
		}
		buff.push_back( to );
		p++;
	}
}

void back(string& now, int& p, vector<string>& buff){
	if( p != 0 && !buff.empty() ){
		p--;
		now = buff[p];
	}
}

void forward(string& now, int& p, vector<string>& buff){
	if( p+1 < buff.size() ){
		p++;
		now = buff[p];
	}
}

void show(string& now){
	cout << now << endl;
}

int main(){
	int n;
	while( cin >> n , n ){
		int w,h;
		map< string , vector<struct Button> > page;
		vector<string> buff;
		string now;
		int p=0;
		
		cin >> w >> h;
		for(int i=0 ; i < n ; i++ ){
			int b;
			string title;
			cin >> title >> b;
			
			if( i == 0 ){
				now = title;
				buff.push_back( now );
			}
			for(int j=0 ; j < b ; j++ ){
				int x1, y1, x2, y2;
				string link;
				
				cin >> x1 >> y1 >> x2 >> y2 >> link;
				struct Button button;
				button.x1 = x1;
				button.y1 = y1;
				button.x2 = x2;
				button.y2 = y2;
				button.link = link;
				page[title].push_back( button );
			}
		}
		int m;
		cin >> m;
		for(int i=0 ; i < m ; i++ ){
			string s;
			cin >> s;
			if( s == "click" ){
				int x, y;
				cin >> x >> y;
				click( x , y , now , page , p , buff );
			}else if( s == "back" ){
				back( now , p , buff );
			}else if( s == "forward" ){
				forward( now , p , buff );
			}else if( s == "show" ){
				show( now );
			}
		}	
	}
}

Measured memory_bytes: 0
def main():
    n, w = map(int, input().split())
    wv = [list(map(int, input().split())) for _ in range(n)]
    dp = [[None]*(w+1) for _ in range(n+1)]
    dp[0] = [0]*(w+1)
    for i in range(1, n+1):
        wi, vi = wv[i-1]
        di = dp[i]
        dio = dp[i-1]
        for j in range(wi):
            di[j] = dio[j]
        for j in range(wi, w+1):
            dion = dio[j-wi]+vi
            if dion > dio[j]:
                di[j] = dion
            else:
                di[j] = dio[j]
    print(dp[-1][-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 420328
x,k,d=map(int,input('').split(' '))
if x<0:
    x=x*(-1)

if x>=k*d:
    print(x-k*d)
else:
    e=x//d
    f=x%d
    g=f-d
    if g<0:
        g=g*(-1)
    
    if (k-e)%2==0:
        print(f)
    else:
        print(g)

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

#define len(x)  (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b)    for (int a = 0; a < int(b); ++a)
#define kk(n)    ff(k, n)
#define xx(n)    ff(x, n)
#define yy(n)    ff(y, n)
#define ii(n)    ff(i, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define kkk(a, b) fff(k, a, b)
#define xxx(a, b) fff(x, a, b)
#define yyy(a, b) fff(y, a, b)
#define iii(a, b) fff(i, a, b)
#define bb begin()
#define ee end()
#define uu first
#define vv second
#define all(x)  (x).bb, (x).ee
#define ite(v)   decltype((v).bb)
#define fe(i, v) for(ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)    { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#define zz(array, byte)   memset(array, byte, sizeof(array));

using LL = long long;
using DD = long double;
using pii = pair<int, int>;



const LL  INFLL  = 0x7f7f7f7f7f7f7f7fLL;
const int INFint = 0x7f7f7f7f;  //Works with memset(..).
 
     

int N;
vector<string> lines;


int minForPair(int a, int b) {
    vector<vector<int> > friction(N, vector<int>(N, 0));
    ii (N) {
        kk (N) {
            if (lines[i][a] == lines[k][b]) {
                friction[i][k] = 1;
            }
        }
    }
    ii (N) {
        int carrying = 0;
        int diagonal = N - i;
        kk (diagonal) {
            carrying += friction[i+k][k];
            friction[i+k][k] = carrying;
        }
    }
    iii (1, N) {
        int carrying = 0;
        int diagonal = N - i;
        kk (diagonal) {
            carrying += friction[k][i+k];
            friction[k][i+k] = carrying;
        }

    }

    vector<vector<int> > dp(N+1, vector<int>(N+1, 0));
    for (int i = N-1; i >= 0; --i) {
        for (int k = N-1; k >= 0; --k) {
            dp[i][k] = friction[N-1-i][N-1-k] + min(dp[i+1][k], dp[i][k+1]);
        }
    }

    return dp[0][0];
}


int main() {
    //ios_base::sync_with_stdio(false);     cin.tie(NULL);
    //cout << '\n';
    cout.precision(16);
    

    int H, W;
    cin >> H >> W;
    N = H;
    lines.resize(H);
    ii (H)
        cin >> lines[i];

    int rr = 0;
    ii (W-1) {
        rr += minForPair(i, i+1);
    }

    cout << rr << '\n';
    

    return 0;
}



Measured memory_bytes: 1312
#define M 300001
a[M],i;main(n,q,x){
	for(scanf("%d%d",&n,&q);i<n;i++)scanf("%d",&x),a[x]=x;
	for(i=1;i<M;i++)if(!a[i])a[i]=a[i-1];
	for(;q--;printf("%d\n",n))for(n=0,scanf("%d",&x),i=x;i<M;i+=x)if(n<a[i-1]%x)n=a[i-1]%x;
	exit(0);
}

Measured memory_bytes: 1768
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int vis[N];
vector<int> g[N];
int dp[N];
int dfs(int u){
	if(vis[u]) return dp[u];
	vis[u] = 1;
	int ans = 0;
	for(auto j:g[u]){
		ans = max(ans, 1+dfs(j));
	}
	dp[u] = ans;
	return dp[u];
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int n,m;
		cin >> n >> m;
		string s[n+1];
		rep(i,0,n) cin >> s[i+1];
		int dp[n+1][m+1];
		rep(i,0,n+1){
			rep(j,0,m+1) dp[i][j] = 0;
		}
		rep(i,1,n+1){
			rep(j,1,m+1){
				if(i==1 && j==1) dp[i][j] = 1;
				else if(s[i][j-1]=='.') dp[i][j] = (dp[i-1][j]+dp[i][j-1])%M;
				else dp[i][j] = 0;
			}
		}
		cout<<dp[n][m];
	}
}

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

int main()
{
  int n;
  cin>>n;
  long long int ans=1;
  for(int i=1;i<=n;i++)
    {
      ans*=1ll*i;
      ans%=1000000007;
    }
  cout<<ans<<"\n";  


  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
        int[] a = Read.ints();
        if (a[2] <= a[1]) { Console.WriteLine("delicious");return; }
        Console.WriteLine(a[2]-a[1]<=a[0]?"safe":"dangerous");
    }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b)
    {
        return a * b / gcd(a, b);
    }
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        if (n == 2) return true;

        for (long i = 2; i < n; i++)
        {
            if (n % i == 0) return false;
        }
        return true;
    }

}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] longs()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
    public static int Int()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] ints()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

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

using namespace std;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int N, Q; cin >> N >> Q;
   vector<int64_t> st({N});
   for (int i = 1; i <= Q; ++i) {
      int64_t x; cin >> x;
      while (st.size() && st.back() >= x) st.pop_back();
      st.emplace_back(x);
   }
   Q = st.size();
   vector<int64_t> dp(Q);
   dp[Q-1] = 1;
   vector<int64_t> ans(N+1);
   for (int i = Q - 1; i >= 0; --i) {
      if (i == 0) {
         ans[st[i]] += dp[i];
         continue;
      }
      int64_t z = st[i];
      st[i] = 2e18;
      while (z > st[0]) {
         int j = upper_bound(st.begin(), st.end(), z) - st.begin() - 1;
         dp[j] += dp[i] * (z / st[j]);
         z %= st[j];
      }
      ans[z] += dp[i];
   }
   for (int i = N - 1; i >= 0; --i) ans[i] += ans[i+1];
   for (int i = 1; i <= N; ++i) cout << ans[i] << '\n';
   return 0;
}


Measured memory_bytes: 5740
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int A[3][3], N, b[15];
	int B[3][3];

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A[i][j];
			B[i][j] = 0;
		}
	}

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

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (A[j][k] == b[i]) {
					B[j][k] = 1;
				}
			}
		}
	}

	string ans = "No";
	if (B[0][0] == 1 && B[0][1] == 1 && B[0][2] == 1) {
		ans = "Yes";
	}
	if (B[1][0] == 1 && B[1][1] == 1 && B[1][2] == 1) {
		ans = "Yes";
	}
	if (B[2][0] == 1 && B[2][1] == 1 && B[2][2] == 1) {
		ans = "Yes";
	}
	if (B[0][0] == 1 && B[1][0] == 1 && B[2][0] == 1) {
		ans = "Yes";
	}
	if (B[0][1] == 1 && B[1][1] == 1 && B[2][1] == 1) {
		ans = "Yes";
	}
	if (B[0][2] == 1 && B[1][2] == 1 && B[2][2] == 1) {
		ans = "Yes";
	}
	if (B[0][0] == 1 && B[1][1] == 1 && B[2][2] == 1) {
		ans = "Yes";
	}
	if (B[0][2] == 1 && B[1][1] == 1 && B[2][0] == 1) {
		ans = "Yes";
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
 
#define ll long long
#define sz 200005
 
using namespace std;
 
vector<ll>graph[sz];
 
ll visited[sz],level[sz];
 
int main()
{
    ll n,m,u,v;
 
    scanf("%lld %lld",&n,&m);
 
    for(ll i=1; i<=m; i++)
    {
        scanf("%lld %lld",&u,&v);
 
        graph[u].push_back(v);
        graph[u].push_back(v);
    }
 
    queue<ll>q;
 
    memset(visited,0,sizeof(visited));
 
    visited[1]=1;
    level[1]=0;
 
    q.push(1);
 
    ll flag=0,kk=0;
 
    while(!q.empty())
    {
        u=q.front();
        q.pop();
 
        for(ll i=0; i<graph[u].size(); i++)
        {
            v=graph[u][i];
 
            if(!visited[v])
            {
                visited[v]=1;
                level[v]=level[u]+1;
                q.push(v);
            }
 
            if(v==n)
            {
                if(level[v]==2)
                {
                    flag=1;
 
                    break;
                }
 
                else
                {
                    kk=1;
                    break;
                }
            }
        }
 
        if(kk==1||flag==1)
            break;
    }
 
    if(flag==1)
        printf("POSSIBLE\n");
 
    else
        printf("IMPOSSIBLE\n");
 
    return (0);
}

Measured memory_bytes: 13552
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	An := make([]int, N)
	for i := 0; i < N-1; i++ {
		An[nextInt()-1]++
	}
	for _, Ai := range An {
		fmt.Println(Ai)
	}
}

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

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


Measured memory_bytes: 6168
import itertools
def main():
    N = int(input())
    P = list(map(int, input().split()))
    S = list(map(int, input().split()))
    count = 1
    if P == S:
        print(0)
    else:
        for i in itertools.permutations(list(range(1,N + 1))):
            if P == list(i):
                a = count
            elif S == list(i):
                b = count
            count += 1
        print(abs(a - b))
main()

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

#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
const int MOD=1e9+7;
int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
int invmod(int a, int md){return powmod(a,md-2,md);}
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
typedef vector<int> vi; typedef pair<int, int> ii; typedef vector< ii > vii;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return (((a%md)*(b%md))%md+md)%md;}
int addmod(int a, int b, int md) {return ((a%md+b%md)%md+md)%md;}
int submod(int a, int b, int md) {return (((a%md-b%md)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);



signed main(void) {
	IOS;
	int n; cin>>n;
	int ans=(n/500)*1000;
	n%=500;
	ans += (n/5)*5;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn
#define per(i,a,n) for (int i=a-1;i>=n;i--)//iをnからa
#define db(x) cout << #x << " = " << x << endl
#define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法


//sort(all(a)); ソート
//sort(all(a),greater<int>()); 逆順ソート

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

    int sizesa=s.size()-t.size()+1;
    int tsize=t.size();
    //db(sizesa);
    int ans=10001;
    int sa;
rep(i,0,sizesa){
    sa=0;
    rep(j,0,tsize){
        if(t.at(j)!=s.at(i+j)){
            sa++;
        }
    }
    ans=min(sa,ans);
}

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

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
using namespace std;
int fa[100005],dis[100005];

int find(int x)
{
	if (fa[x]==x) return x;
	int fx=find(fa[x]);
	dis[x]+=dis[fa[x]];
	fa[x]=fx;
	return fx;
}
int main()
{
	int n,m;
	bool f=true;
	int l,r,d;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	{
		fa[i]=i;dis[i]=0;
	}
	for (int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&l,&r,&d);
		if (!f) continue;
		int fl=find(l),fr=find(r);
		if (fl==fr)
		{
			if (dis[l]-dis[r]!=d) f=false;
	    }
	    else 
	    {
	    	fa[fl]=fr;
	    	dis[fl]=dis[r]-dis[l]+d;
	   }
   }
   if (f) printf("Yes\n");
   else printf("No\n");
   return 0;
}

Measured memory_bytes: 1152
N,C = map(int,input().split())
X=[]
V=[]
for i in range(N):
    x,v=map(int,input().split())
    X.append(x)
    V.append(v)
#時計回りで見る
R=[0]*(N+1)#0番目は１に格納する
Rans=[0]*(N+1)
for i in range(N):
    R[i+1]=R[i]+V[i]
    Rans[i+1]=max(Rans[i],R[i+1]-X[i])
L=[0]*(N+1)
Lans=[0]*(N+1)
for i in range(N,0,-1):
    L[i-1]=L[i]+V[i-1]#N-1にN-1を格納
    Lans[i-1]=max(Lans[i],L[i-1]-C+X[i-1])
ans_1=max(Rans[N],Lans[0])
ans_2=max(Lans[i+1]+R[i+1]-2*X[i] for i in range(N))
ans_3=max(Rans[i-1]+L[i-1]-2*C+2*X[i-1] for i in range(N,0,-1))
print(max(ans_1,ans_2,ans_3))

Measured memory_bytes: 28464
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define y0 yy
#define y1 Yy
#define yn YY
#include <assert.h>
#include <algorithm>
#include <vector>
using namespace std;

int n, res;
char s[100005];

int main() {
	scanf("%s", &s);
	n = strlen(s);
	for (int i = 0; i < n - 1; i++) res += s[i + 1] != s[i];
	printf("%d\n", res);
#ifdef LOCAL_MSVC_DEBUG
	system("pause");
#endif
	return 0;
}


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

using namespace std;

int main(){
        string s1,s2;
	cin >> s1 >> s2;
	int c=0;
	for(int i=0;i<3;i++)
		if(s1[i]==s2[i]) c++;
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
//2018-1-17
//miaomiao
//
#include <bits/stdc++.h>
using namespace std;

#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)

#define N 16
const int P = 1e9 + 7;

inline int Mod(int a){
	if(a < 0) a += P;
	return a >= P? a-P: a;
}
inline int Mul(int a, int b){return 1ll * a * b % P;}

inline int Calc(int a){
	return __builtin_popcount(a);
}

int f[1<<N], reach[N];

bool Check(int a){
	int u = a & 1, v = (a & 2) >> 1;
	return u == v;
}

int main(){
	int n, m, u, v, t, tf;

	scanf("%d%d", &n, &m);
	For(i, 1, m){
		scanf("%d%d", &u, &v);
		reach[u] |= 1 << (v-1);
	}

	f[0] = 1;
	For(i, 1, (1<<n)-1) if(Check(i)) for(u = i; u; u = (u-1)&i){
		if(!Check(u)) continue;

		t = i ^ u; tf = f[t];
		For(j, 0, n-1){
			if(u&(1<<j)) tf = Mul(tf, 1<<Calc(reach[j+1]&t));
			if(t&(1<<j)) tf = Mul(tf, (1<<Calc(reach[j+1]&u))-1);
		}
		
		f[i] = Mod(f[i] + tf);
	}

	int ans = 1;
	while(m--) ans = Mul(ans, 2);
	ans = Mod(ans - f[(1<<n)-1]);

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
#pragma gcc optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, m; cin >> n >> m;
    vector<int> f(n + 1, -1);
    int ans = 1;
    function<int(int)> find = [&] (int x) {
        return f[x] < 0 ? x : f[x] = find(f[x]);
    };
    auto merge = [&] (int x, int y) {
        if ((x = find(x)) == (y = find(y))) return;
        if (x > y) swap(x, y);
        f[x] += f[y];
        f[y] = x;
        ans = max(ans, -f[x]);
    };
    while (m--) {
        int u, v; cin >> u >> v;
        merge(u, v);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 4000
wmax,hmax,n = map(int,input().split())
wmin = hmin = 0
for i in range(n):
  x,y,a = map(int,input().split())
  if a == 1:
    if wmin < x:
      wmin = x
  elif a == 2:
    if wmax > x:
      wmax = x
  elif a == 3:
    if hmin < y:
      hmin = y
  else:
    if hmax > y:
      hmax = y

if wmax-wmin < 0 or hmax-hmin < 0:
  print(0)
else:
  print((wmax-wmin) * (hmax-hmin))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

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

int main() {
	int k, x;
	cin >> k >> x;

	vector<int> vi;

	for (int i = 1; i <= k*2-1; i++) {
		int num = x - k + i;
		vi.push_back(num);
	}

	for (int i = 0; i < vi.size(); i++) {
		if (vi.size() == i - 1) {
			cout << vi[i] << endl;
		} else {
			cout << vi[i] << " ";
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define sec second
#define fir first
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}



int main(){
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll c = 0;
	rep(i,0,n){
		if(s[i]=='1') ++c;
	}
	
	if(c==0){
		rep(i,0,n){
			cout<<1<<endl;
		}
		return 0;
	}
	if(c==1){ 
		rep(i,0,n-1){
		if(s[i]=='0'){
			if(s[n-1]!='1') cout<<1<<endl;
			else cout<<2<<endl;
		}
		
		else{
			cout<<0<<endl;
		}
		}
		if(s[n-1]=='0') cout<<2<<endl;
		else cout<<0<<endl;
		return 0;
		
	}
	vector<ll> cnt(n+1,0);
	cnt[1] = 1;
	cnt[2] = 1;
	rep(i,3,n+1){
		ll x = __builtin_popcount(i);
		cnt[i] = cnt[i%x] + 1;
	}
	vector<ll> r1(n+1),r2(n+1);
	r1[0] = 1%(c-1);
	r2[0] = 1%(c+1);
	rep(i,1,n){
		r1[i] = (r1[i-1]*2)%(c-1);
		r2[i] = (r2[i-1]*2)%(c+1);
	}
	vector<ll> pr1(n+1,0),pr2(n+1,0);
	vector<ll> sr1(n+2,0),sr2(n+2,0);
	
	if(s[0]=='1') pr1[0] = r1[n-1],pr2[0] = r2[n-1];
	
	rep(i,1,n){
		if(s[i]=='1'){
			pr1[i] = (pr1[i-1] + r1[n-i-1])%(c-1);
			pr2[i] = (pr2[i-1] + r2[n-i-1])%(c+1);
		}
		else{
			pr1[i] = pr1[i-1];
			pr2[i] = pr2[i-1];
		}
		//cout<<i<<" "<<pr1[i]<<" "<<pr2[i]<<endl;
	}
	if(s[n-1]=='1') sr1[n-1] = r1[0],sr2[n-1] = r2[0];
	rrep(i,n-2,0){
		if(s[i]=='1'){
			sr1[i] = (sr1[i+1] + r1[n-i-1])%(c-1);
			sr2[i] = (sr2[i+1] + r2[n-i-1])%(c+1);
		}
		else{
			sr1[i] = sr1[i+1];
			sr2[i] = sr2[i+1];
		}
		//cout<<i<<" "<<sr1[i]<<" "<<sr2[i]<<endl;
	}
	
	rep(i,0,n){
		if(i==0){
			if(s[i]=='1'){
				cout<<cnt[sr1[i+1]] + 1<<endl;
			}
			else{
				ll r = (r2[n-i-1] + sr2[i+1])%(c+1);
				cout<<cnt[r]+1<<endl;
			}
		}
		else if(i==n-1){
			if(s[i]=='1'){
				cout<<cnt[pr1[i-1]] + 1<<endl;
			}
			else{
				ll r = (r2[n-i-1] + pr2[i-1])%(c+1);
				cout<<cnt[r] + 1<<endl;
			}			
		}
		else{
			if(s[i]=='1'){
				ll r = (pr1[i-1] + sr1[i+1])%(c-1); 
				cout<<cnt[r] + 1<<endl;
			}
			else{
				ll r = (pr2[i-1] + sr2[i+1] + r2[n-1-i])%(c+1); 
				cout<<cnt[r] + 1<<endl;
			}
		}
	}
	
	
	
}
		 

Measured memory_bytes: 14384
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define ld long double
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL); clock_t beg = clock()
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 3e5+7 ;
const int INF = 1e18 ;
const int MOD = 1e9 + 7 ;
string s ;

void solve(){
	int n , m ;
	cin >> n >> m ;
	vi a(n) ;
	for(auto& x : a) cin >> x ;
	int sm = 0 ;
	for(int i = 0 ; i < n ; i++){
		sm += a[i] ;
	}
	int cnt = 0 ;
	for(int i = 0 ; i < n ; i++){
		if(a[i]*4*m >= sm) cnt++ ;
	}
	cout << (cnt >= m ? "Yes\n" : "No\n") ;
}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
}


Measured memory_bytes: 256
import datetime

data = input().split(' ')
data = map(lambda x: int(x), data)

h1, m1, h2, m2, k = list(data)

wakeup = datetime.datetime(2000, 1, 1, hour=h1, minute=m1)
gotobed = datetime.datetime(2000, 1, 1, hour=h2, minute=m2)

study = datetime.timedelta(minutes=k)

result = gotobed  - wakeup - study
result = result.total_seconds() / 60
result = int(result)

print(result)

Measured memory_bytes: 9380
#include <array>
#include <cmath>
#include <iostream>

int main()
{
    int n, k;
    std::cin >> n >> k;
    const long long int mod                 = 1000000007;
    std::array<long long int, 100001> array = {0};

    auto modpow = [](long long int a, long long int n, const long long int& mod) {
        long long int res = 1;
        while (n > 0)
        {
            if (n & 1) res = res * a % mod;
            a = a * a % mod;
            n >>= 1;
        }
        return res;
    };

    for (int i = k; i > k / 2; --i)
    {
        array[i] = 1;
    }

    for (int i = k / 2; i > 0; --i)
    {
        array[i] = modpow(k / i, n, mod);

        for (int j = 2 * i; j <= k; j += i)
        {
            array[i] -= array[j];
            if (array[i] < 0) array[i] += mod;
        }
    }

    long long int result = 0;
    for (int i = k; i > 0; --i)
    {
        result += (i * array[i] % mod);
        result %= mod;
    }

    std::cout << result << std::endl;
}


Measured memory_bytes: 3980
import sys
def input():
    return sys.stdin.readline()[:-1]
n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
l = -1
r = 10**12

a.sort(reverse=True)
f.sort()

while l+1<r:
    #print()
    now = (l+r)//2
    s=0
    for i in range(n):
        s += max(0,a[i]-now//f[i])
    if s<=k:
        r=now
    else:
        l=now

print(r)


Measured memory_bytes: 113280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(int a, int b){
   return b ? GCD(b, a%b) : a;
}

int LCM(int a, int b){
   return (a * b)/(GCD(a, b));
}

int main(){
   int H, W, h, w;
   cin >> H >> W >> h >> w;

   cout << (H-h)*(W-w)<< endl;

   return 0;
}

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

using namespace std;
using ll = long long;
constexpr int mod = 1e9+7;
constexpr int md = mod;
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
double bitToen(double b){
    return b * 380000.0;
}
int main(){
    int n;
    cin>>n;
    vector<pair<double,string>> otosi(n);
    double ret = 0;
    for(auto & a : otosi){
        cin>>a.first >> a.second;
        if(a.second == "BTC"){
            ret += bitToen(a.first);
        }else{
            ret += a.first;
        }
    }
    cout << std::fixed;
    cout << std::setprecision(5) <<  ret <<endl;
    return 0;
}



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

int main(){
	int H, W;
	while(1){
		cin>>H>>W;
		if(H==0 && W==0) break;

		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				cout<<"#";
			}
			cout<<endl;
		}
		cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
//#include<string.h>
//char a[10000],b[10000],c[10000];


int main(){
int i,j,n;
scanf("%d",&n);

   if(n<105)
   printf("0\n");
   else if(n>=105&&n<135)
   printf("1\n");
   else if(n>=135&&n<165)
   printf("2\n");
   else if(n>=165&&n<189)
   printf("3\n");
   else if(n>=189&&n<195)
   printf("4\n");
   else if(n>=195)
   printf("5\n");

    return 0;


}




Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{

	public static void main(String[] args) throws Exception{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int num = Integer.parseInt(br.readLine());

		System.out.println((int)Math.pow(num, 3));

	}
}

Measured memory_bytes: 24300
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

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

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

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

void solve()
{
    int n;
    seika s;
    cin >> n >> s;
    for (char c : s)
    {
        cout << char((c - 'A' + n) % 26 + 'A');
    }
    cout << endl;
}

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


Measured memory_bytes: 256
#include <stdio.h>

int
main(void)
{
	for (;;) {
		int n, x;
		int i, j, k;
		int s = 0;

		scanf("%d%d", &n, &x);

		if (n == 0 && x == 0)
			break;

		for (i = 1; i <= n - 2; i++)
			for (j = i + 1; j <= n - 1; j++)
				for (k = j + 1; k <= n; k++)
					if (i + j + k == x)
						s++;

		printf("%d\n", s);
	}

	return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int MAXN = 1e5 + 10;
int a[MAXN];
int n , l;
int main(){
	ios::sync_with_stdio(0);
	cin >> n >> l;
	for(int i = 1 ; i <= n ; ++ i)
		cin >> a[i];
	for(int i = 1 ; i < n ; ++ i)
		if(a[i] + a[i + 1] >= l){
			cout << "Possible" << endl;
			for(int j = 1 ; j < i ; ++ j)
				cout << j << endl;
			for(int j = n - 1 ; j >= i + 1 ; -- j)
				cout << j << endl;
			cout << i << endl;
			return 0;
		}
	cout << "Impossible" << endl;
	return 0;
}

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

using namespace std;
int main()
{
	int i,j,n,s=10000000,m=10000000;
	string a,b;
	cin>>a>>b;
	for(i=0;i<a.size()-b.size()+1;i++)
	{
		s=0;
		for(j=0;j<b.size();j++)
			if(a[i+j]!=b[j]) s++;
		m=min(s,m);
	}
	cout<<m;
}

Measured memory_bytes: 3620
n, l = map(int, input().split())

list1 = []
for i in range(1, n+1):
    list1.append(l + i - 1)
if min(list1) > 0:
    print(sum(list1) - list1[0]) 
elif max(list1) < 0:
    print(sum(list1) - list1[n-1])
else:
    print(sum(list1) - list1[list1.index(0)]) 

Measured memory_bytes: 3060
#include <bits/stdc++.h>  
 
using namespace std;
 
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int main() {
	string s;
	while(getline(cin, s)) {
		rep(i, 26) {
			rep(j, s.size()) {
				if('a' <= s[j] && s[j] < 'z') s[j] += 1;
				else if(s[j] == 'z') s[j] = 'a';
			}
			if(s.find("the") != string::npos || s.find("this") != string::npos || s.find("that") != string::npos) {
				cout << s << endl;				
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3044
#include<stdio.h>
#include<vector>
using namespace std;
int main()
{
    long long k,x;
    vector<long long>v;
    scanf("%lld %lld",&k,&x);
        for(long long i=x-(k-1);i<x;i++){
            v.push_back(i);
        }
        for(long long i=x;i<=x+(k-1);i++){
            v.push_back(i);
        }
        long long a=v.size();
        for(long long j=0;j<a;j++){
            printf("%lld ",v[j]);
        }
        printf("\n");
}


Measured memory_bytes: 256
#配列arrに値xを最適に挿入(もしくは置換)する。配列arrは重複あり・降順
def insert(arr,x)
  len = arr.length
  if x > arr[-1]
    d = (len-1) / 2
    i = d
    #2分探索ここから
    while len > 1
      if arr[i] < x
        i -= d
        len = len - d - ((len-1)%2)
        d = (len-1) / 2
        i += d
      else
        len = len - d - 1
        d = (len-1) / 2
        i += d + 1
      end
    end
    #2分探索ここまで
    arr[i] = x
  else
    arr.push(x)
  end
end

n = gets.to_i
a = []
n.times do |i|
  a[i] = gets.to_i
end
arr = [a[0]]
(n-1).times do |i|
  insert(arr,a[i+1])
end
puts arr.length

Measured memory_bytes: 16196