akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define loop(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[i];}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }

int main(){
  int n; set<string> s; cin >> n;
  string tmp;
  vector<string>w(n);
  rep(i,n){
    cin >> tmp;
    w[i]=tmp;
  }
  
  s.insert(w[0]);
  loop(i,1,n){
    if(w[i-1].back()!=w[i].front()||s.find(w[i])!=s.end()){
      cout << "No" << endl;
      return 0;
    }
    s.insert(w[i]);
  }

  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

typedef long long ll;

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

const long long INF = 1LL << 60;

bool solve(int x, int y, int z) {
  return (x+y>z and y+z>x and z+x>y);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string n; cin>>n;
  
  int sum = 0;

  rep(i, n.length()) {
    int c = n[i] - '0';
    sum += c;
  }
  
  if(sum%9==0) cout<<"Yes";
  else cout<<"No";

  return 0;
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000,mod=1000000007,n;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n,num,sum=0;cin>>n; ll arr[n],freq[n+1]={0};
    memset(freq,0,sizeof(freq));
    for(ll i=0;i<n;i++)cin>>arr[i],freq[arr[i]]++;
    for(ll i=1;i<n+1;i++)
    {
        num=((freq[i])*(freq[i]-1))/2;
        sum+=num;
    }
    ll num1;
    for(ll i=0;i<n;i++)
    {
        num1=((freq[arr[i]])*(freq[arr[i]]-1))/2;num=num1;
        sum-=num;
        freq[arr[i]]--;
        num=((freq[arr[i]])*(freq[arr[i]]-1))/2;
        sum+=num;
        cout<<sum<<endl;
        freq[arr[i]]++;
        sum-=num;
        sum+=num1;
    }
}


Measured memory_bytes: 5760
#include<iostream>

using namespace std;

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if((a&&b&&c>=-100)&&(a&&b&&c<=100))
	{
	if (a==b)
	{
		cout<<c;
	}
	else if(a==c)
	{
		cout<<b;
	}
	else if(b==c)
	{
		cout<<a;
	}
}
return 0;
}


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

#define zton(i,n) for(int i=0;i<=n;i++)
#define oneton(i,n) for(int i=1;i<=n;i++)
#define fo(i,n) for(int i=0;i<n;i++)
#define fab(i,a,b) for(int i=a;i<b;i++)
#define loop(i,b,a) for(int i=a;i>=b;i--)
#define dsort(arr,n) sort(arr, arr + n, greater<int>())
#define vsortd(a) sort(a.begin(), a.end(), greater<double>())
#define vsort(a) sort(a.begin(), a.end())
#define ll long long int
#define test int tc;cin>>tc;while(tc--)
#define dbg(x) cout<<#x<<'='<<(x)<<endl;
#define dbg2(x,y) cout<<#x<<'='<<(x)<<endl<<#y<<'='<<(y)<<endl;
#define dbg3(x,y,z) cout<<#x<<'='<<(x)<<endl<<#y<<'='<<(y)<<endl<<#z<<"="<<(z)<<endl;
#define dbg4(x,y,z,w) cout<<#x<<'='<<(x)<<endl<<#y<<'='<<(y)<<endl<<#z<<"="<<(z)<<endl<<#w<<"="<<(w);
#define minheap priority_queue <int, vector<int>, greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define ff first
#define ss second
#define mpr make_pair
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mkv vector<int>
#define allzero(dp) memset(dp,0,sizeof(dp))
#define endl "\n"
#define print(x) cout<<x<<endl;

const int mod=998244353;
using namespace std;
bool sortcol( const vector<int>& v1,const vector<int>& v2 ) {return v1[1] < v2[1];}
typedef pair<int, int> pi;

void fastio()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

bool sortfun(const pair<ll,ll> &a,const pair<ll,ll> &b){
    return (a.ss>b.ss);
   // if(a.first==b.first)return a.second<b.second;
    //return false;
}

ll power(ll x, ll y){
    ll res = 1;x=x%mod;
    while(y>0){
        if(y&1)res=(res*x)%mod;
        y=y>>1;x=(x*x)%mod;}
    return res;
}


void solve()
{
    int n;cin>>n;
    map<string,int>mp;
    mp["AC"]=0;
    mp["WA"]=0;
    mp["TLE"]=0;
    mp["RE"]=0;
    fo(i,n)
    {
        string s;cin>>s;;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}

int main()
{
   // fastio();
  //  test
    solve();
}


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

#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)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

template<class T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*🍈( '-'  🍈*/

int main(){
	ll N,K; cin >> N >> K;
	int M;
	vector<PII> ans;
	FORq(i,2,N){
		ans.PB(MP(1,i));
	}

	ll G = (N-1) * (N-2) / 2;
	if (G < K){
		puts("-1");
		return 0;
	}
	FORq(i,2,N){
		FORq(j,2,N){
			if (i >= j) continue;
			if (G == K) break;
			G--;
			ans.PB(MP(i,j));
		}
		if (G==K) break;
	}

	M = ans.size();
	cout << M << "\n";
	REP(i,M){
	    cout << ans[i].fst << " " << ans[i].snd << "\n";
	}


	return 0;
}


Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	if n < 2 || n >50{
		return
	}

	nums := make([]int, n)
	for i:=0; i<len(nums); i++{
		fmt.Scan(&nums[i])
	}

	sum := 0
	for i:=0; i<len(nums); i++{
		for j:=i+1; j<len(nums); j++{
			sum += nums[i] * nums[j]
		}
	}

	fmt.Println(sum)
}

Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
const double PI=3.14159265358979323846;
const long long INF = 1LL << 60;

int main() {
	string N;
	cin >> N;
	if (N == "ABC")
		std::cout << "ARC" << '\n';
	else
		std::cout << "ABC" << '\n';
}


Measured memory_bytes: 3620
N = int(input())
s = list(input())
sum = [0]*(N+1)

for i in range(1,N+1):
    if s[i-1] == 'W':
        sum[i] = sum[i-1]+1
    else:
        sum[i] = sum[i-1]
    
for i in range(1,N+1):
    temp = sum[i-1] + (N-i - (sum[N]-sum[i]))
    if i == 1:
        ans = temp
    elif temp < ans:
        ans = temp
    

print(ans)

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

using namespace std;

int main() {
	int n, x,y, dist[112], cont=1;
	
	scanf("%d %d", &n, &x);
	
	dist[0] = 0;
	for (int i=1; i<=n; ++i) {
		scanf("%d", &y);
		
		dist[i] = dist[i-1] + y;
		
		if (dist[i] <= x) 
			++cont;
	}
	
	printf("%d\n", cont);
	
	return 0;
}

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

int main() {
  string c;
  cin >> c;
  // 英小文字のうち母音は a、e、i、o、u
  
  
  // cが母音であるとき、vowel
  // そうでないとき consonant と出力せよ。
  // ここにプログラムを追記
  
  string vowel = "aeiou";
  
  // vowel の中に 入力内容 c が入っていないかを確認
  bool x = false;
  
  for (int i = 0;i < vowel.size(); i++) {
    if (c.at(0) == vowel.at(i)) {
      x = true;
      break;
    }
  }

  if (x) {
    cout << "vowel" <<endl;
  } else {
    cout << "consonant" <<endl;
  }
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
 #define big 1000000007
int64_t GCD(int64_t a,int64_t b){
    return b == 0 ? a : GCD(b, a % b);
   
}
int main(){
    int64_t a,b;
    cin >> a >>b;
    cout << a*b/GCD(a,b)<<endl;;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> vec(N+1);
  vector<int> vecS(M),vecC(M);
  int f=0;
  for(int i = 0; i < M; i++){
    int s,c;
    cin >> s >> c;
    vecS.at(i) = s;
    vecC.at(i) = c;
    if(N>1 && s==1 && c==0) f++;
    vec.at(s) = c;
  }
  for(int i = 0; i < M-1; i++){
    for(int j = i+1; j < M; j++){
      if(vecS.at(i)==vecS.at(j)){
        if(vecC.at(i)!=vecC.at(j)) f++;
      }
    }
  }
  if(f>0){
    cout << "-1" << endl;
    return 0;
  }
  if(N>1 && vec.at(1)==0) vec.at(1)=1;
  for(int i = 1; i <= N; i++){
    cout << vec.at(i);
  }
}

Measured memory_bytes: 256
#D
N, K = map(int, input().split())
p= [int(x) for x in input().split()]
ap = p
ans = 0
for i in range(N):
    if i == 0:
        ap[i] = (p[i]+1)/2
    else:
        ap[i] = (p[i]+1)/2 + ap[i-1]
for i in range(N-K+1):
    now = 0
    if i == 0:
        now = ap[K-1]
    else:
        now = ap[K+i-1]-ap[i-1]
    ans = max(ans, now)

print (ans)

Measured memory_bytes: 25188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>

int main() {
	int N, K; std::cin >> N >> K;
	std::vector<int> P(N);
	for (auto& r : P) std::cin >> r;
	std::sort(P.begin(), P.end());
	int ans{ 0 };
	for (auto i{ 0 }; i < K; ++i)
		ans += P[i];
	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 3640
fun main(args: Array<String>) {
    val (n, h) = readLine()!!.split(' ').map { it.toInt() }
    val xs = IntArray(n)
    val ys = IntArray(n)
    repeat(n) {
        val (a, b) = readLine()!!.split(' ').map { it.toInt() }
        xs[it] = a
        ys[it] = b
    }

    var ans = 0
    var hp = h

    val a = xs.max()!!

    for (b in ys.filter { it > a }.sortedDescending()) {
        ans++
        hp -= b

        if (hp <= 0) {
            break
        }
    }

    if (hp > 0) {
        ans += (hp + a - 1) / a
    }

    println(ans)
}

Measured memory_bytes: 57812
#!/usr/bin/env python3
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(n - 2):
    cnt += (p[i] < p[i + 1] < p[i + 2]) or (p[i] > p[i + 1] > p[i + 2])
print(cnt)


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

int main(void){
	int num;
	std::cin >> num;

	std::string event;
	int out = 0, runner = 0, point = 0;
	for(int i = 0; i < num; ++i){
		while(out < 3){
			std:: cin >> event;

			if(event == "OUT"){
				++out;		
			}else if(event == "HIT"){
				if(runner == 3){
					++point;
				}else{
					++runner;
				}
			}else if(event == "HOMERUN"){
				point += runner + 1;
				runner = 0;
			}
		}
		std::cout << point << std::endl;
		out = 0, runner = 0, point = 0;
	}
	return 0;
}

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

using namespace std;
#define int long long
#define x first
#define y second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

mt19937 rand1(136786931);
int randlr(int l, int r) {
    return rand1() % (r - l + 1) + l;
}

string s = "";
vector<string> answ;
void gen(int i, int n) {
    if (i == n) {
        answ.push_back(s);
        return;
    }

    vector<bool> used(11);
    for (int j = 0; j < i; j ++) {
        used[s[j] - 'a'] = 1;
    }

    for (int k = 0; k <= 10; k ++) {
        s += (k + 'a');
        gen(i + 1, n);
        s.pop_back();
        if (!used[k]) break;
    }
}

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

    int n;
    cin >> n;
    gen(0, n);
    for (auto u : answ) {
        cout << u << "\n";
    }

    return 0;
}


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

using namespace std;
 
int main(){
    int n;
    string str;
    vector<string> v;
     
    cin >> n;
    for(int i = 0 ; i < n ; i++){
        cin >> str;
        v.push_back(str);
    }
    cin >> n;
    int st = 0; //0 Closed , 1 Opened
    for(int i = 0 ; i < n ; i++){
        int flg = 0;
        cin >> str;
        for(int j = 0 ; j < v.size() ; j++){
            if(str == v[j]){
                if(!st){
                    cout << "Opened by " << str << endl;
                    st = 1;
                }
                else{
                    cout << "Closed by " << str << endl;
                    st = 0;
                }
                flg = 1;
                break;
            }
        }
        if(!flg) cout << "Unknown " << str << endl;
    } 
    return 0;
}

Measured memory_bytes: 3172
from sys import stdin


def main():
    M, N = map(int, stdin.readline().rstrip().split(" "))
    xs   = list(map(int, stdin.readline().rstrip().split(" ")))
    d    = M - sum(xs)
    
    if d >= 0:
       print(d)
    else:
       print(-1)
        
if __name__ == "__main__":
  main()

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

using namespace std;

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

    int t = 1;
    // cin >> t;
    while (t--) {
        string s;
        cin >> s;
        int n = s.size() - 1;
        if (s[n] == '2' || s[n] == '4' || s[n] == '5' || s[n] == '7' || s[n] == '9') cout << "hon";
        else if (s[n] == '3') cout << "bon";
        else cout << "pon";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3668
# ABC088D - Grid Repainting
import sys
input = sys.stdin.readline

from collections import deque

def bfs() -> None:
    q = [(0, 0)]
    while q:
        x, y = q.pop(0)
        for dx, dy in dxy:
            nx, ny = x + dx, y + dy  # next x, y
            if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == "." and dist[nx][ny] == 0:
                q.append((nx, ny))
                dist[nx][ny] = dist[x][y] + 1


def main():
    global H, W, S, dist, dxy
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    dist = [[0] * W for _ in range(H)]  # distance from (0, 0) to (x, y)
    dist[0][0] = 1
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    bfs()
    white, x = sum(s.count(".") for s in S), dist[-1][-1]
    ans = white - x if x else -1
    print(ans)


if __name__ == "__main__":
    main()

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

int main() {
    int x, a, b;
    cin >> x >> a >> b;

    if (x < a && x < b) {
        if (a - x < b - x) {
            cout << "A" << endl;
        }
        else {
            cout << "B" << endl;
        }
    }
    if (x > a && x < b) {
        if (x - a < b - x) {
            cout << "A" << endl;
        }
        else {
            cout << "B" << endl;
        }
    }
    if (x < a && x > b) {
        if (a - x < x - b) {
            cout << "A" << endl;
        }
        else {
            cout << "B" << endl;
        }
    }
    if (x > a && x > b) {
        if (x - a < x - b) {
            cout << "A" << endl;
        }
        else {
            cout << "B" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <queue>
#include <limits.h>
#include <string.h>
#include <vector>
#include <map>
#include <math.h>
#define LL long long
#define INF 2100000000
#define fi first
#define se second
#define lowbit(x) (x&(-x))
#define eps 5e-7
#define getr(x,y) x*y/(x+y+2.0*sqrt(x*y))
#define getd(x,y) 2.0*sqrt(x*y)
#define judgel(r,x) r+sqrt(2*x*r+r*r)<=x
#define fuck(x1,y1,x2,y2,z) (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)<=z*z

using namespace std;
const int maxn=(int)1e5+10;
const int maxm=(int)4e6+10;
const LL MOD=(LL)1e9+7;
LL a[maxm];
struct dfs{
    int now,vis;
    LL num;
    dfs(){}
    dfs(int now,LL num,int vis):now(now),num(num),vis(vis){}
};
dfs q[maxn];
int fuc(int L){
    int t=0;
    q[0]=dfs(0,0,0);
    int h=1;
    while(h){
        dfs tmp=q[h-1];
        h--;
        if(L==tmp.now){
            a[t++]=tmp.num;
            continue;
        }
        tmp.num*=10;
        for(int i=0;i<10;i++){
            if(!((tmp.vis>>i)&1)) q[h++]=dfs(tmp.now+1,tmp.num+i,tmp.vis|(1<<i));
        }
    }
    return t;
}
#define getdif(n,snum,power) min(abs(n-snum),power-abs(n-snum));
int main(){
#ifdef shuaishuai
    freopen("C:\\Users\\hasee\\Desktop\\a.txt","r",stdin);
    //freopen("C:\\Users\\hasee\\Desktop\\b.txt","w",stdout);
#endif
    string s;
    cin>>s;
    int l=s.size();
    int sz=fuc(l);
   // for(int i=0;i<a.size();i++ )printf("%lld\n",a[i]);
 //  printf("%d\n",a.size());
    LL fuck=0;
    LL tot=1;
    for(int i=0;i<l;i++){
        fuck*=10;
        tot*=10;
        fuck+=s[i]-'0';
    }
    LL dif=0;
    LL ans=0;

    for(int i=0;i<sz;i++){
        LL tmp=getdif(a[i],fuck,tot);
        if(tmp>dif){
            dif=tmp;
            ans=a[i];
        }
        else if(tmp==dif){
            if(a[i]<ans) ans=a[i];
        }
    }
    vector<int> q;
    while(ans){
        q.push_back(ans%10);
        ans/=10;
    }
    for(int i=q.size();i<l;i++) q.push_back(0);
    for(int i=q.size()-1;i>=0;i--)printf("%d",q[i]);printf("\n");
    return 0;
}

Measured memory_bytes: 31676
#include<iostream>
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define N 2*10e5
using namespace std;
void get(ll arr[],ll n){for(ll i=0;i<n;i++) cin>>arr[i];}
int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n,m;
	cin>>n>>m;
	ll arr[m],sum=0;
	for(int i=0;i<m;i++)
	cin>>arr[i] , sum+=arr[i];
	if(sum>n)
	cout<<"-1";
	else
	cout<<n-sum;
}



Measured memory_bytes: 3676
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    cout<<setprecision(16);
    ll n,k;
    cin>>n>>k;
    vector<double> v(n,0);
    rep(i,n){
        cin>>v[i];
    }
    ll ng = 0;
    ll ok = 1e9;

    while(ok-ng>1){
        ll mid = (ng+ok)/2;
        ll sum = 0;

        rep(i,n){
            ll c = v[i];
            if(c>=mid){
                sum += (c / mid);
                if (c % mid == 0)sum--;
            }
        }

        if(sum<=k){
            ok=mid;
        }else{
            ng=mid;
        }

    }


    cout<<ok<<endl;






    return 0;
}


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

int main(void){
  int n,k;
  cin>>n>>k;
  if(n%k==0)cout<<'0'<<endl;
  else cout<<'1'<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    ll n; cin >> n;
    vector<string> S(n);
    for (ll i = 0; i < n; i++) {
        cin >> S[i];
        sort(S[i].begin(), S[i].end());
    }
    sort(S.begin(), S.end());

    ll ans = 0, cnt = 0;
    for (ll i = 0; i < n - 1; i++) {
        if (S[i] == S[i + 1]) {
            cnt++;
            ans += cnt;
        } else {
            cnt = 0;
        }
    }
    cout << ans << endl;
}

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

int main(){
    int N; cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    vector<long long> DP(N,0);
    DP[0] = 1000;
    for(int i = 1; i < N; i++){
        for(int j = 0; j < i; j++){
            //cout << (DP[j]-(DP[j]%A[j])) << endl;
            DP[i] = max(DP[i-1],(long long)(((DP[j]-(DP[j]%A[j]))/A[j])*A[i])+DP[j]%A[j]);
        }
        //cout <<DP[i]<< endl;
    }
    cout << DP[N-1] << endl;
    
}






Measured memory_bytes: 3628
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int A = sc.nextInt();
		final int B = sc.nextInt();
		final int H = sc.nextInt();
		final int M = sc.nextInt();
		sc.close();
		double omega_h = 2*Math.PI/12;
		double omega_m = 2*Math.PI/60;
		double dig_h = omega_h*H + M*Math.PI/360;
		double dig_m = omega_m*M;
		double ans = Math.sqrt(A*A + B*B - 2*A*B*Math.cos(Math.abs(dig_h - dig_m)));
		System.out.println(ans);
	}
}


Measured memory_bytes: 35872
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  int i,j,k,l;
  ll n,s;
  ll dp[10][101][1001]={{{}}};
  fill(dp[0][0],dp[9][100],0);
  for(i=0;i<101;i++) dp[0][i][i]=1;
  for(i=0;i<9;i++){
    for(j=0;j<101;j++){
      for(k=0;k<1001;k++){
	for(l=j+1;l<101;l++){
	  if(k+l>1000) break;
	  dp[i+1][l][k+l]+=dp[i][j][k];
	}
      }
    }
  }
  while(cin >> n >> s,n||s) {
    ll o=0;
    for(i=0;i<101;i++) o+=dp[n-1][i][s];
    cout << o << endl;
  }
  return 0;
}

Measured memory_bytes: 9064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DWaterBottle solver = new DWaterBottle();
        solver.solve(1, in, out);
        out.close();
    }

    static class DWaterBottle {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int a = in.scanInt();
            int b = in.scanInt();
            int x = in.scanInt();
            double half = (a * a * b) / 2;
            if (x <= half) {
                out.println((90 - (Math.toDegrees(Math.atan((2d * x) / (b * b * 1d * a))))));
            } else {
                double y = (2d * x / (a * a * 1d)) - b;
                out.println(90 - (Math.toDegrees(Math.atan((1d * a) / (b - y + 0d)))));
            }

        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}



Measured memory_bytes: 23508
n, m = map(int, input().split())
l_x = list(map(int, input().split()))

if n >= m:
    print(0)
else:
    l_x.sort()
    l_d = [l_x[i+1]-l_x[i] for i in range(m-1)]
    l_d.sort(reverse=True)

    big_ds = 0
    for j in range(n-1):
        big_ds += l_d[j]

    print(sum(l_d)-big_ds)

Measured memory_bytes: 13960
#include <stdio.h>

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

  char cha[n];
  scanf("%s",cha);

  int sum=1;
  int i;

  for(i=0;i<n-1;i++){
    if(cha[i]!=cha[i+1])  sum++;
  }

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


Measured memory_bytes: 256
def solve0(A, B, C, K):
    for i in range(K):
        A, B, C = B + C, A + C, A + B
    return A - B

def solve(A, B, C, K):
    if K % 2 == 0:
        return A - B
    else:
        return B - A

A, B, C, K = [int(_) for _ in input().split()]

print(solve(A, B, C, K))



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

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

    long long ans = 0;
    long long max = a[0];
    for (int i = 1; i < n; i++) {
        if (max <= a[i]) {
            max = a[i];
        } else {
            ans += max - a[i];
        }

    }    

    cout << ans << endl;
}


Measured memory_bytes: 4720
#include <iostream>
#include <algorithm>

using namespace std;

int main(){

	int N, i;
	cin >> N;

	for(i = 0; i < 15; i++){
		if(N - 7 * i >= 0){
			if((N - 7 * i) % 4 == 0 ){
				cout << "Yes\n";
				return 0;
			}
		} 
	}

	cout << "No\n";
	return 0;

}

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

int main() {
  int n;
  cin >> n;
  
  rep(i, n) {
    int a;
    cin >> a;
    if(a % 2 == 0 && a % 3 != 0 && a % 5 != 0) {
//      cout << a << endl;
      cout << "DENIED" << endl;
      return 0;
    }
  }
  
  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 256
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll n,i,j,ct=0,k;
            cin>>n>>k;
            while(n>0)
            {
                ++ct;
                n=n/k;
            }
            cout<<ct<<endl;
        }
        return 0;
    }


Measured memory_bytes: 256
function Main(arg) {
 
    var S = arg.split("\n")[0].split("");
    var T = arg.split("\n")[1].split("");

    var ans = 0;

    for (var i = 0; i < S.length; i++){
        if (S[i] === T[i]) ans++;
    }

    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
int main() {
  string s;
  cin >> s;
  int cnt = 0;
  char now = s[0];
  int ans = 0;
  for(int i=0; i<s.size(); i++){
    if(s[i]!=now) {
      cnt = 0;
      ans++;
    }
    else cnt++;
    if(cnt==0) now = s[i];
  }
  cout << ans << endl;
}

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

int main() {
  int x1, y1, x2, y2, x3, y3, x4, y4;
  cin >> x1 >> y1 >> x2 >> y2;
  x3 = x2 + (y2 - y1) * (-1);
  y3 = y2 + (x2 - x1);
  x4 = x3 + (y3 - y2) * (-1);
  y4 = y3 + (x3 - x2);
  cout << x3 << endl << y3 << endl << x4 << endl << y4;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    string s; cin>>s;
    
    s=' '+s;

    vint sum(N+1);
    for(int i=1;i<=N;i++){
        sum[i]=sum[i-1]+(s[i]=='E');
    }
    
    int ans=N;
    for(int i=1;i<=N;i++){
        int l=(i-1)-sum[i-1];
        int r=sum[N]-sum[i];
        ans=min(ans,l+r);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3040
N, K = map(int, input().split())
RSP = list(map(int, input().split()))
d = {'r': 0, 's': 1, 'p': 2}
T = input()

ans = 0
flags = [True] * K
for n in range(N):
    if flags[n % K]:
        ans += RSP[(d[T[n]] - 1) % 3]
        if n + K < N:
            if T[n] == T[n + K]:
                flags[n % K] = False
    else:
        flags[n % K] = True
print(ans)


Measured memory_bytes: 3956
INF = 1000000007

n, k = map(int, input().split())
a = list(map(int, input().split()))
ans_i = 0
ans_e = 0

for i in range(len(a)):
    for j in range(len(a)):
        if i == j: continue
        #print(a[i], a[j])
        if a[i] > a[j]:
            if i < j:
                ans_i += 1
            else:
                ans_e += 1
x = ans_i * k
ans = ans_i + ans_e
y = ans * ((k * (k-1) ) // 2)
print(int((x + y) % INF))


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		int count = 0;
		for(int i = 0; i <= 2; i++) {
			if(S.substring(i, i+1).equals("o")){
				count++;
			}else {
				continue;
			}
		}
		System.out.println(700 + 100 * count);
	}
}

Measured memory_bytes: 21844
import sys
input = sys.stdin.readline
from operator import itemgetter

def rotate(x, y):
	return (-y, x)

def main():
	x1, y1, x2, y2 = map(int, input().strip().split())
	v = (x2-x1, y2-y1)
	lp = (x2, y2)
	for i in range(2):
		v = rotate(v[0], v[1])
		next = lp[0]+v[0], lp[1]+v[1]
		print("{} {} ".format(next[0], next[1]), end="")
		lp = next
	print("")
	# d = max(abs(x1 - x2), abs(y1 - y2))
	# if y1 > y2:
	# 	print(" ".join(map(str, [x2+d, y2, x2+d, y1])))
	# elif y1 < y2:
	# 	print(" ".join(map(str, [x2-d, y2, x2-d, y1])))
	# elif x1 > x2:
	# 	print(" ".join(map(str, [x2, y2-d, x1, y2-d])))
	# elif x1 < x2:
	# 	print(" ".join(map(str, [x2, y2+d, x1, y2+d])))

if __name__ == '__main__':
	main()


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

int main(){
  int h,w,k;
  cin >> h >> w >> k;
  vector<vector<int>> c(h,vector<int>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      char a;
      cin >> a;
      if(a=='#') c[i][j]++;
    }
  }
  
  int l=pow(2,h+w);
  
  int ans=0;
  for(int i=0;i<l;i++){
    int s=0;
    for(int a=0;a<h;a++){
      for(int b=0;b<w;b++){
        int x=pow(2,a);
        int y=pow(2,h+b);
        if(i/x%2&&i/y%2) s+=c[a][b];
      }
    }
    if(s==k) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4108
/*
g++ -std=c++14 -o2 -Wall ABC121A.cpp -o .\out\ABC121A.out
.\out\ABC121A.out
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << (H-h)*(W-w) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;

using Graph = vector<vector<int>>;


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

	int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    multiset<int> set1;
    rep(i,N){
        auto itr = set1.lower_bound(A[i]);
        if(itr == set1.begin()){
            set1.insert(A[i]);
        }
        else{
            set1.erase(--itr);
            set1.insert(A[i]);
        }
    }
    cout << set1.size() << endl;
}

Measured memory_bytes: 5760
import java.util.*;
public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args) {
 
    while(kbd.hasNext()){
        double r = kbd.nextDouble();
     
        if(r==0){
        ;
        }
        else{
        double x = r*r*Math.PI;
        double y = 2*r*Math.PI;
        System.out.printf("%f %f\n",x,y);
        }
    }
    }
}

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

signed main(){
  int n;cin>>n;
  string s;cin>>s;
  if(n&1){cout<<"No"<<endl;return 0;}
  string t=s.substr(0,n/2);
  t+=t;
  if(t==s)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main() {
	int A,B,C;
	cin >> A >> B >> C;
	if(A+B+C >= 22){
		cout <<  "bust" << endl;
	} else {
		cout << "win" << endl;
	}
  
}

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

int main(){
 ll x; cin >> x; ll ans;
 for(int i=1;i<400;i++){
   if((x*i)%360==0){
     ans=i;
     break;
   }
 }
 cout << ans << endl;
}


Measured memory_bytes: 3620
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const S = args[0][0]
	const t1 = {
		'Sunny': 'Cloudy',
		'Cloudy': 'Rainy',
		'Rainy': 'Sunny'
	}

	console.log(t1[S])
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 22076
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

typedef long long ll;

int n,N;
ll s[4000][2],a,b;
string d;

int main(){
    while(cin>>N){
	if(N==0)return 0;
	for(int i=0;i<4000;i++){
	    for(int j=0;j<2;j++){
		s[i][j]=0;
	    }
	}
	int m=0;
	for(int i=0;i<N;i++){
	    cin>>n>>a>>b;
	    int flag=0;
	    for(int j=0;j<m;j++)if(s[j][0]==n){s[j][1]+=a*b;flag=1;}
	    if(flag==0){s[m][0]=n;s[m][1]=a*b;m++;}
	}
	int flag2=0;
	for(int i=0;i<m;i++)if(s[i][1]>999999){cout<<s[i][0]<<endl;flag2=1;}
	if(flag2==0)cout<<"NA"<<endl;
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a),q(b),r(c),al;
  rep(i,a){
    cin >> p[i];
  }
  rep(i,b){
    cin >> q[i];
  }
  rep(i,c){
    cin >> r[i];
    al.pb(r[i]);
  }
  sort(all(p));
  sort(all(q));
  reverse(all(p));
  reverse(all(q));
  rep(i, x) al.pb(p[i]);
  rep(i, y) al.pb(q[i]);
  sort(all(al));
  reverse(all(al));
  ll ans = 0;
  rep(i, x + y) ans += al[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9740
#include <iostream>
using namespace std;
int main(){
	int n;
	int a[100]={0};
	while(cin>>n){
		a[n-1]++;
	}
	int b=0;
	for(int i=0;i<100;i++){
		if(a[i]>b) b=a[i];
	}
	for(int j=0;j<100;j++){
		if(a[j]==b) cout<<j+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import sys
import io
import math
import re

import sys
import io
import math
import re

menu_num = 5
menu_sum = 0
menu_time_divided = 9
flag_a = 0
flag_b = 0

for num in range(menu_num):
    data_info = input().split()
    menu = int(data_info[0])
    menu_sum += math.ceil(menu / 10) * 10

    if menu % 10 == 0:
        flag_a = 1

    if menu_time_divided >= menu % 10 and menu % 10 != 0:
        menu_time_divided = menu % 10
        flag_b = 1

if flag_a == 0 and flag_b == 1:
    print(menu_sum+menu_time_divided-10)
elif flag_a == 1 and flag_b == 1:
    print(menu_sum+menu_time_divided-10)
else:
    print(menu_sum)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;

using P = pair<int, int>;


vector<int> to[100005];
int cost[100005];
signed main(){
    int n;
    cin >> n;

    vector<int> b(n-1);
    rep(i,n-1)cin>> b[i];
    vector<int> a(n);
    int ans = b[0];
    ans += b[n-2];
    //cout << ans << endl;
    rep(i,n-2) {
        ans += min(b[i],b[i+1]);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2560
N=int(input())
D={}
M=1
for _ in range(N):
    S=input()
    if S in D:
        D[S]+=1
        M=max(M,D[S])
    else:
        D[S]=1

K=[a for a in D if D[a]==M]
K.sort()
for a in K:
    print(a)


Measured memory_bytes: 143804
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    from collections import Counter

    n = int(input())
    a = Counter(list(map(int, input().split())))
    sorted_a = sorted(a.items(), key=lambda x: (x[0], x[1]), reverse=True)
    squares = [key for key, value in sorted_a if value >= 4]
    rectangles = [key for key, value in sorted_a if value >= 2]

    if (len(squares) >= 1) and (len(rectangles) >= 2):
        print(max(squares[0] ** 2, rectangles[0] * rectangles[1]))
    elif (len(squares) >= 1) and (len(rectangles) < 2):
        print(squares[0] ** 2)
    elif len(rectangles) >= 2:
        print(rectangles[0] * rectangles[1])
    else:
        print(0)


Measured memory_bytes: 27812
///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 304;

int h, w;
int c[N][N];

int dp[N][N], dp2[2 * N][N];
vector<int> a[2];

int f(int num) {
    for (int j = 0; j < 2; ++j) {
        a[j].clear();
        for (int t = 0; t < h; ++t) {
            a[j].push_back(c[num - j][t]);
        }
    }
    memset(dp, -1, sizeof dp);
    memset(dp2, 0, sizeof dp);

    for (int hs = 2 * h; hs >= 0; --hs) {
        for (int t = max(hs, h), id = 1; t < min(2 * h, hs + h); ++t, ++id) {
            int j1 = t - h;
            int j2 = t - hs;
            int add = (a[0][j1] == a[1][j2]);
            dp2[hs][id] = dp2[hs][id - 1] + add;
        }
    }

    for (int i = 0; i <= h; ++i) {
        for (int j = 0; j <= h; ++j) {
            int& res = dp[i][j];
            if (i == 0 || j == 0) {
                res = 0;
            } else {
                int add = dp2[h + j - i][min(i, j)];
                res = add + min(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    return dp[h][h];
}

void solve() {
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) {
            c[j][i] = s[j] - 'a' + 1;
        }
    }

    int ans = 0;
    for (int i = 1; i < w; ++i) {
        ans += f(i);
    }

    cout << ans << "\n";
}

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

    int z = 1;
    /// cin >> z;

    while (z--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 5064
import sys, math
from pprint import pprint
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

days = {'SUN':7,'MON':6,'TUE':5,'WED':4,'THU':3,'FRI':2,'SAT':1}
S = rs()
print(days[S])


Measured memory_bytes: 38512
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    string S;
    int N;

    cin >> S;

    N = S.length();

    for(int i = 0; i < (N - 1) / 2; i++){
        if(S[i] != S[(N - 1) / 2 - i - 1]){
            cout << "No" << endl;
            return 0;
        }
        if(S[i + (N + 3) / 2 -1] != S[N - i - 1]){
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i = 0; i < N; i++){
        if(S[i] != S[N - i - 1]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


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

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

    for(int i=1;i<n;i++){
        int v=a[i];
        int j=i-1;
        
        for(int k=0;k<n;k++){
            cout<<a[k];
            if(k<n-1)cout<<" ";
        }
        cout<<endl;

        while(j>=0 && a[j]>v){
            a[j+1]=a[j];
            j--;
            a[j+1]=v;
        }
    }
    
    for(int k=0;k<n;k++){
        cout<<a[k];
        if(k<n-1)cout<<" ";
    }


    cout<<endl;
    return 0;
}


Measured memory_bytes: 3084
import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    S = input().strip()
    T = input().strip()
    s_t = {}
    t_s = {}
    for s, t in zip(S, T):
        if s not in s_t and t not in t_s:
            s_t[s] = t
            t_s[t] = s
        elif s in s_t and t in t_s:
            if not (s_t[s] == t and t_s[t] == s):
                return 'No'
        else:
            return 'No'
    return 'Yes'



if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 76484
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
using namespace std;
const int INF = 1e9;
typedef long long lint;
const lint LINF = 1e18;
const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}
 
int main(){
	string s; cin >> s;
	int k; cin >> k;
	int count = 0;
	rep(i,s.size()){
		if (s[i] == '1'){
			count++;
		}
		else {
			break;
		}
	}
	if (k <= count){
		cout << 1 << endl;
	}else{
		cout << s[count] << endl;
	}
}


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

using namespace std;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;

int h, n, w, x, y, x2, y2;
long long fak[2 * MAXN], block[MAXN], from[MAXN];
pair<int,int> tocke[MAXN];

inline bool cmp(const pair<int,int>&a, const pair<int,int>&b)
{
	if(a.first != b.first)
		return a.first < b.first;
	else
		return a.second < b.second;
}

inline long long mul(long long a, long long b)
{
	return (a * b) % MOD;
}
inline long long add(long long a, long long b)
{
	long long ret = a + b;
	if(ret >= MOD)
		return ret - MOD;
	else if(ret >= 0)
		return ret;
	else
		return ret + MOD;
}

long long qp(long long a, long long pot)
{
	if(pot == 1)
		return a % MOD;
	if(pot % 2 == 0)
		return qp(mul(a, a), pot / 2) % MOD;
	return mul(qp(a, pot - 1), a);
}
long long choose(long long a, long long b)
{
	return mul(fak[a], qp(mul(fak[b], fak[a - b]), MOD - 2));
}

inline void calc()
{
	fak[0] = 1;
	fak[1] = 1;
	for(int i = 2; i < 2 * MAXN; i++)
		fak[i] = mul(fak[i - 1], i);
}

inline void rtl()
{
	for(int i = n - 1; i >= 0; i--)
	{
		x = tocke[i].first, y = tocke[i].second;
		block[i] = choose(x + y, y);
		from[i] = choose(h - x + w - y, w - y);
		for(int k = n - 1; k > i; k--)
		{
			x2 = tocke[k].first, y2 = tocke[k].second;
			if(x2 >= x && y2 >= y)
			{
				from[i] = add(from[i], -mul(from[k], choose(x2 - x + y2- y, x2 - x)));
			}
		}
	}
}

int main()
{
	calc();
	cin >> h >> w >> n;
	h--;
	w--;
	for(int i = 0; i < n; i++)
	{
		cin >> tocke[i].first >> tocke[i].second;
		tocke[i].first -= 1;
		tocke[i].second -= 1;
	}
	sort(tocke, tocke + n, cmp);
	rtl();
	long long blocked = 0;
	for(int i = 0; i < n; i++)
		blocked = add(blocked, mul(block[i], from[i]));
	cout << add(choose(h + w, w), -blocked);
	return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
const int maxn=1000;
int s[maxn+5][maxn+5];
int n,m,A,B;

int main()
{

    cin>>n>>m>>A>>B;
    for(int i=1;i<=B;++i)
        for(int j=1;j<=A;++j)
            s[i][j]=0;
    for(int i=1;i<=B;++i)
        for(int j=A+1;j<=m;++j)
            s[i][j]=1;
    for(int i=B+1;i<=n;++i)
        for(int j=1;j<=A;++j)
            s[i][j]=1;
    for(int i=B+1;i<=n;++i)
        for(int j=A+1;j<=m;++j)
            s[i][j]=0;
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j) printf("%d",s[i][j]);printf("\n");
    }
    return 0;
}


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


int64_t powpow(int64_t x, int64_t a, int64_t m){
  if(a==0){
    return 1;
  }
  else if(a%2==0){
    int64_t t=powpow(x,a/2,m);
    return t*t%m;
  }
  else{
    return x*powpow(x,a-1,m)%m;
  }
}

int64_t stair(int64_t n, int64_t a, int64_t m){
  int64_t ans=1;
  for (int i=a; i<=n; i++){
    ans=ans*i%m;
  }
  return ans;
}

int64_t comb3(int64_t n, int64_t r, int64_t m){
  int64_t ans=stair(n,n-r+1,m);
  ans*=powpow(stair(r,1,m),m-2,m);
  return ans%m;
}

int main() {
  int64_t n, a, b;
  cin >> n >> a >> b;
  int64_t m=pow(10,9)+7;
  int64_t result;
  result = powpow(2,n,m) - comb3(n,a,m) - comb3(n,b,m) - 1;
  result%=m;
  if(result<0){
    result+=m;
  }
  cout << result << endl;
}

Measured memory_bytes: 256