akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
char f[60][51];

int vis[60][50]={};
int dp[60][50][1<<12][4];

int main()
{
    int H,W,K;
    cin >>H >>W >>K;

    rep(i,6)
    {
        f[i][0]='.';
        for(int j=1; j<W; ++j) f[i][j]='#';
    }
    rep(i,H) scanf("%s", f[i+6]);
    H+=6;

    #define IN(y,x) (0<=y && y<H && 0<=x && x<W)
    memset(dp,-1,sizeof(dp));
    dp[6][0][0][0]=0;
    rep(b,K+1)rep(y,H)rep(x,W)if(f[y][x]!='#')
    {
        rep(mask,1<<12)if(dp[y][x][mask][b]>=0)
        {
            int d[6];
            rep(i,6) d[i] = (mask>>(2*i))&3;

            int px[7],py[7];
            px[0] = x;
            py[0] = y;
            rep(i,6)
            {
                px[i+1] = px[i] - dx[d[i]];
                py[i+1] = py[i] - dy[d[i]];
            }

            rep(i,7) vis[py[i]][px[i]]=1;

            rep(i,4)
            {
                int nx = x+dx[i], ny = y+dy[i], nb = b+(i>=2);
                if(nb<=K && IN(ny,nx) && f[ny][nx]!='#')
                {
                    int add=max(0,f[ny][nx]-'0');
                    if(vis[ny][nx]) add=0;

                    int nmask = ((mask<<2)&((1<<12)-1)) + i;

                    dp[ny][nx][nmask][nb] = max(dp[ny][nx][nmask][nb], dp[y][x][mask][b] + add);
                }
            }

            rep(i,7) vis[py[i]][px[i]]=0;
        }
    }

    int ans=0;
    rep(M,1<<12)rep(B,K+1) ans=max(ans,dp[H-1][W-1][M][B]);
    printf("%d\n", ans);
    return 0;
}

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

int main() {
  int a,b,h,m;cin>>a>>b>>h>>m;
  double pai=acos(-1);
  double hh=(double)(m+h*60)/720*2*pai;
  double mm=(double)m/60*2*pai;
  double xh=a*cos(hh),yh=a*sin(hh);
  double xm=b*cos(mm),ym=b*sin(mm);
  double dx=xh-xm,dy=yh-ym;
  double ans=sqrt(dx*dx+dy*dy);
  cout<<fixed<<setprecision(10)<<ans<<endl;
}

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

int main(){
    int N;
    cin >> N;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }   
    cout << "No" << endl;
}

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

void push(int A);
int pop(void);

int S[1000];
int Top = 0;

int main(void) {

	string str;
	int a, b;
	Top = 0;
	while (cin >> str) {

		if (str[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (str[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (str[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		}
		else {
			push(atoi(str.c_str()));
		}
	}
	printf("%d\n", pop());

	return 0;
}

void push(int A) {
	S[++Top] = A;
}

int pop(void) {
	Top--;
	return S[Top + 1];
}


Measured memory_bytes: 3260
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
int fa[maxn];
int sz[maxn];
int find(int x){
	return fa[x]==x ? fa[x]:fa[x]=find(fa[x]);
}
int ans;
int N,M;
void un(int x,int y){
	int fx = find(x);
	int fy = find(y);
	if(fx==fy){
		return ;
	}
	fa[fx]=fy;
	sz[fy]+=sz[fx];
	ans = max(ans,sz[fy]);
}
int main(){
	scanf("%d%d",&N,&M);
	for(int i=1;i<=N;i++){
		fa[i]=i;
		sz[i]=1;
		ans =1;
	}
	for(int i=1;i<=M;i++){
		int X,Y;
		scanf("%d%d",&X,&Y);
		un(X,Y);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5368
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

bool contains(const string& s, const string& p) {
  for (size_t i = 0; i < s.size(); ++i) {
    bool m = true;
    for (size_t j = 0; j < p.size(); ++j) {
      int k = j + i;
      if (j + i >= s.size()) {
        k = j + i - s.size();
      }
      if (s[k] != p[j]) {
        m = false;
        break;
      }
    }
    if (m) {
      return true;
    }
  }
  return false;
}

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

  if (contains(s, p)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int solve(const auto& word, auto slate) {
  auto s = lower_bound(begin(word), end(word), slate);
  if(s == end(word)) return 0;
  else               return (*s == slate) ? 1 : 0;
}

int star(const auto& word, auto slate) {
  slate.pop_back();
  auto b = lower_bound(begin(word), end(word), slate);
  auto e = upper_bound(begin(word), end(word), slate + "~");
  return e - b;
}

int main() {
  int N, M;
  cin >> N >> M;

  vector<string> word(N);
  for(auto& i: word) cin >> i;
  sort(begin(word), end(word));

  auto rev = word;
  for(auto& i: rev) reverse(begin(i), end(i));
  sort(begin(rev), end(rev));

  for(auto i = 0; i < M; ++i) {
    string slate;
    cin >> slate;

    const auto* w = &word;
    if(slate.front() == '*') {
      reverse(begin(slate), end(slate));
      w = &rev;
    }

    int q;
    for(q = 0; q < slate.size(); ++q) if(slate[q] == '?') break;

    auto res = 0;

    if(q == slate.size()) {
      if(slate.back() == '*') res = star(*w, slate);
      else                    res = solve(*w, slate);
    } else {
      for(auto c = 'a'; c <= 'z'; ++c) {
        slate[q] = c;
        if(slate.back() == '*') res += star(*w, slate);
        else                    res += solve(*w, slate);
      }
    }

    cout << res << endl;
  }
}

Measured memory_bytes: 11720
<?php
$S=trim(fgets(STDIN));
$P=trim(fgets(STDIN));

$Sl=strlen($S);
$Pl=strlen($P);
$p=$P[0];
for($i=0;$i<$Sl;$i++){
  if($S[$i]!=$p) continue;
  $l=1;
  for($j=1;$j<$Pl;$j++){
    $ij=$i+$j;
    if($Sl<=$ij) $ij-=$Sl;
    if($S[$ij]!=$P[$j]) break;
    ++$l;
  }
  if($l==$Pl) exit("Yes\n");
}
echo "No\n";

Measured memory_bytes: 15440
#include <bits/stdc++.h>
using namespace std;
const int MAXN=2010;
int n,a[MAXN],cnt[MAXN],sum[MAXN];
long long ans;
int main () {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++) {
		for (int j=i+1;j<=n;j++) {
			if (2*a[i]<=a[j]) {continue;}
			ans+=max(0,sum[a[i]]-sum[a[j]-a[i]]);
		}
		cnt[a[i]]++;
		for (int i=1;i<=1000;i++) {sum[i]=sum[i-1]+cnt[i];}
	}
//	for (int i=1;i<=n;i++) {
//		for (int j=i;j<=n;j++) {
//			if (a[j]!=a[i]&&j-i>=3) {
//				ans-=
//			}
//		}
//	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer return cout << "NO", 0;
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 4e5 + 200;
const long long MNN = 3e3 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e13;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int n, k, a[MXN];
llong dp[MNN][MNN][2];

llong get(llong action, llong l, llong r){
    if(dp[l][r][action] != -INF) return dp[l][r][action];
    if(l == r) {
        if(action == 1) return a[l];
        else return -a[l];
    }
    if(action == 1){
        llong choice1 = get(0, l + 1, r) + a[l];
        llong choice2 = get(0, l, r - 1) + a[r];
        return dp[l][r][1] = max(choice1, choice2);
    }else{
        llong choice1 = get(1, l + 1, r) - a[l];
        llong choice2 = get(1, l, r - 1) - a[r];
        return dp[l][r][0] = min(choice1, choice2);
    }
}

int main () {
    ios;
    cin >> n;
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n; j++){
            dp[i][j][0] = dp[i][j][1] = -INF;
        }
    }
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    cout << get(1, 1, n);
}


Measured memory_bytes: 151936
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
using namespace std;
int A[10000];
int main() {
	int a,b;
	cin >> a >> b;
	if(a % 2 == 1 && b % 2 == 1)
		cout << "Odd" << endl;
	else
		cout << "Even" << endl;
}

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

int main(){
    int n;
    while (1){
	cin >> n;
	if (n == 0) break;
	char b, t;
	map<char, char> m;
	vector<char> his;
	for (int i = 0; i < n; i++){
	    cin >> b >> t;
	    m.insert(map<char, char>::value_type(b, t));
	    his.push_back(b);
	}
	cin >> n;
	char c;
	for (int i = 0; i < n; i++){
	    cin >> c;
	    vector<char>::iterator f = find(his.begin(), his.end(), c);
	    if (f != his.end()) cout << m[c];
	    else cout << c;
	}
	cout << endl;
    }
}

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

static const int MAX = 2e+5;
ll cnt[10][10];

int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        string s = to_string(i);
        cnt[s[0] - '0'][s[s.size() - 1] - '0']++;
    }
    ll ans = 0;
    for(int i = 0; i <= 9; i++){
        for(int j = 0; j <= 9; j++){
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3720
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

int n;
char s[11];

void dfs(int k, char mx) {
  if (n == k) {
    rep(i, 0, n) printf("%c", s[i]);
    printf("\n");
    return;
  }
  for ( char c = 'a'; c <= mx; c++ ) {
    s[k] = c;
    if ( mx == c ) 
      dfs(k+1, (char)(mx + 1));
    else 
      dfs(k+1, mx);
  }
}

int main(void) {
  scanf("%d", &n);
  dfs(0, 'a');
  return 0;
}


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

int main() {
    string s;
    cin >> s;
    int counter = 0;
    if (s[0] == '1') counter++;
    if (s[1] == '1') counter++;
    if (s[2] == '1') counter++;
    cout << counter << endl;
}

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

#define fi first
#define se second
#define pb push_back
#define dbg(x) cout << #x << " = " << x << endl
#define all(x) x.begin(), x.end()

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

const int MAX = 1e5;
const int INF = 1e9;
vi stone(MAX + 5);
vi dp(MAX + 5, -1);
int n, k;

int sol(int i){
    if(i == 0) return 0;
    if(dp[i] != -1) return dp[i];
    int cost = INF;
    for(int j = 1; j <= k && j <= i; ++j){
       cost = min(cost, sol(i - j) + abs(stone[i] - stone[i - j]));
    }
    return dp[i] = cost;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #else
        #define endl '\n'
    #endif
    cin >> n >> k;
    for(int i = 0; i < n; ++i)
        cin >> stone[i];
    cout << sol(n - 1) << endl;
    return 0;
}


Measured memory_bytes: 10292
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var kazu = input.split(' ');

for(i=0; i<kazu.length; i++)
kazu[i]=parseInt(kazu[i], 10);

if(kazu[0] < kazu[1])
console.log("a < b");
else if(kazu[0] > kazu[1])
console.log("a > b");
else
console.log("a == b");

Measured memory_bytes: 7380
def calculate(cx1, cy1, cx2, cy2):

    Up = 'U'
    Right = 'R'
    Left = 'L'
    Down = 'D'

    h = abs(cy2 - cy1)
    w = abs(cx2 - cx1)

    if cx2 > cx1:
        if cy2 < cy1:
            Down = 'U'
            Up = 'D'
    else:
        if cy2 > cy1:
            Left = 'R'
            Right = 'L'
        else:
            Left = 'R'
            Right = 'L'
            Down = 'U'
            Up = 'D'

    return h * Up + w * Right + h * Down + (w + 1) * Left + (h + 1) * Up + (w + 1) * Right + Down + Right + (
            h + 1) * Down + (w + 1) * Left + Up


cx1, cy1, cx2, cy2 = -2, -2, 1, 1
cx1, cy1, cx2, cy2 = map(int,input().split())

print(calculate(cx1, cy1, cx2, cy2))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
#define sortup(V) sort(V.begin(), V.end())


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

    // solution comes here
    ll N;
    cin >> N;
    vl L(N);
    rep(i, N) cin >> L[i];

    sortup(L);

    ll ans=0;
    rep(i, N-2) {
        for(ll j=i+1; j<N-1; j++) {
            ll key = L[i] + L[j];
            ll r = lower_bound(L.begin(),L.end(), key) - L.begin();
            ans += r-j-1;
        }
    }

    cout << ans << nl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i,N;
  cin>>N;
  vector<int> v(N);
  for(i=0;i<N;i++)cin>>v[i];
  if(*max_element(v.begin(),v.end())*2<accumulate(v.begin(),v.end(),0)){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
from bisect import bisect_left
import sys
input = sys.stdin.readline

class Compress:

    def __init__(self, vs):
        self.xs = list(set(vs))
        self.xs.sort()

    def compress(self, x):
        return bisect_left(self.xs, x)

    def decompress(self, i):
        return self.xs[i]

def suffix_array(s):
    n = len(s)
    comp = Compress(s)
    t = [comp.compress(s[i]) for i in range(n)]
    cnt = [0] * n
    for i in range(n):
        cnt[t[i]] += 1
    for i in range(1, n):
        cnt[i] += cnt[i-1]
    p = [0] * n
    for i in range(n):
        cnt[t[i]] -= 1
        p[cnt[t[i]]] = i
    c = [0] * n
    cl = 0
    for i in range(1, n):
        if s[p[i]] != s[p[i-1]]:
            cl += 1
        c[p[i]] = cl

    pn = [0] * n
    cn = [0] * n
    h = 0
    while (1 << h) < n:
        for i in range(n):
            pn[i] = p[i] - (1 << h)
            if pn[i] < 0:
                pn[i] += n
        cnt = [0] * n
        for i in range(n):
            cnt[c[pn[i]]] += 1
        for i in range(1, n):
            cnt[i] += cnt[i-1]
        for i in range(n)[::-1]:
            cnt[c[pn[i]]] -= 1
            p[cnt[c[pn[i]]]] = pn[i]
        cn[p[0]] = 0
        cl = 0
        for i in range(1, n):
            cur = (c[p[i]], c[(p[i] + (1 << h)) % n])
            prev = (c[p[i-1]], c[(p[i-1] + (1 << h)) % n])
            if cur != prev:
                cl += 1
            cn[p[i]] = cl
        c, cn = cn, c
        h += 1
    return p


def bin_search(a, b, sa, lower):
    lb, ub = -1, N
    while ub - lb > 1:
        m = (lb + ub) // 2
        for i in range(N):
            j = (sa[m] + i) % N
            if a[i] < b[j]:
                ub = m
                break
            if a[i] > b[j]:
                lb = m
                break
        else:
            if lower:
                ub = m
            else:
                lb = m
    return ub

N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [a[i] ^ a[(i+1)%N] for i in range(N)]
d = [b[i] ^ b[(i+1)%N] for i in range(N)]
sa = suffix_array(d)
lb = bin_search(c, d, sa, True)
ub = bin_search(c, d, sa, False)
ans = []
for j in range(lb, ub):
    k = (N - sa[j]) % N
    x = a[k] ^ b[0]
    ans.append((k, x))
ans.sort()
for k, x in ans:
    print(k, x)

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

int main() {
  string S;
  cin >> S;
  if(S=="hi" || S=="hihi" || S=="hihihi" || S=="hihihihi" || S=="hihihihihi"){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int N = sc.nextInt();
        int groups = 0;
        while (N > 2){
            if (N-3 < 3){
                groups += 1;
                N = 0;
            }else{
                groups += 1;
                N -= 3;
            }
        }

        System.out.println(groups);
    }
}

Measured memory_bytes: 21332
"use strict";
var S = parseInt(require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')[0])
var sum_ret = S
for(var i=1 ; i < parseInt(S/2)+1 ; i++){
    var rev_i = S-i
    var tmp = Sum_Arr(i.toString().split(""))+Sum_Arr(rev_i.toString().split(""))
    if(sum_ret >tmp ){
      sum_ret = tmp
    }
}
console.log(sum_ret)
function Sum_Arr(str_arr){
  let ans = 0
  str_arr.forEach(function(elem){
    ans+=parseInt(elem)
  })
  return ans
}


Measured memory_bytes: 13728
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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 mini=2e9,ans=-2e9-1,N;

int main(){
    cin>>N;
    int R[N];
    rep(i,N){
        cin>>R[i];
        ans=max(ans,R[i]-mini);
        mini=min(mini,R[i]);
    }
    out(ans);
}



Measured memory_bytes: 3884
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    h: usize,
    n: usize,
    m: [(usize, i64); n],
  }
  let mut mp = vec![1i64 << 60; h + 1];
  mp[h] = 0;
  for i in (0 .. h).rev() {
    for &(a, b) in &m {
      mp[i] = cmp::min(mp[i], mp[cmp::min(i + a, h)] + b);
    }
  }

  puts!("{}\n", mp[0]);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
string s;
int a[5000];
int main(){
    cin>>s;
    for(int i=0;i<s.length();i++){
        a[s[i]]=1;
    }
    for(int i='a';i<='z';i++){
        if(a[i]==0){
            cout<<(char)i<<endl;
            return 0;
        }
    }
    cout<<"None"<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
const int MAX_N = 100000;
struct UnionFind{
    int par[MAX_N];
    void init(int n){
        for(int i = 0;i < n;i++)par[i] = i;
    }
    int root(int x){
        if(par[x] == x)return x;
        else return par[x] = root(par[x]);
    }
    bool same(int x,int y){
        return root(x) == root(y);
    }
    void unite(int x,int y){
        x = root(x);
        y = root(y);
        if(x == y)return;
        par[y] = x;
    }
};
main(){
    int N;
    cin >> N;
    vector< P > X(N),Y(N);
    vector< pair<int , pair<int,int> > >V;
    rep(i,0,N){
        int x,y;
        cin >> x >> y;
        X[i] = P(x,i);
        Y[i] = P(y,i);
    }
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    rep(i,0,N-1)V.push_back(make_pair( (X[i+1].first - X[i].first) , P(X[i+1].second , X[i].second)));
    rep(i,0,N-1)V.push_back(make_pair( (Y[i+1].first - Y[i].first) , P(Y[i+1].second , Y[i].second)));
    sort(V.begin(), V.end());
    UnionFind uf;
    uf.init(N);
    ll ans = 0;
    for(auto p:V){
        int x = p.second.first,y = p.second.second;

        if(!uf.same(x,y)){
            ans += p.first;
            uf.unite(x,y);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6516
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<vector<long double>> dp(n+1, vector<long double>(n+1, 0.0));
    vector<long double> v(n, 0.0);
    for(int i=0; i<n; i++)
        cin>>v[i];
    
    dp[0][0] = 1.0;
    for(int i=1; i<=n; i++)
    {
        for(int j=0; j<=i; j++)
        {
            if(j==0)
                dp[i][j] = dp[i-1][j]*(1-v[i-1]);
            else
                dp[i][j] = dp[i-1][j-1]*v[i-1] + dp[i-1][j]*(1-v[i-1]);
        }
    }
    // for(int i=0; i<=n; i++)
    // {
    //     for(int j=0; j<=n; j++)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    long double ans = 0.0;
    for(int j=(n+1)/2; j<=n; j++)
        ans += dp[n][j];
    cout<<setprecision(10)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 141056
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll com[55][55];
ll rcom[55][55];
int zzz[55];
int main()
{
	int num, gen, lb, ub;
	scanf("%d%d%d%d", &num, &gen, &lb, &ub);
	vector<int>kets;
	for (int i = 0; i < 18; i++)if ((lb&(1 << i)) == 0 && (ub&(1 << i)) != 0)kets.push_back(i);
	vector<int>v;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		if ((z&lb) != lb)continue;
		if ((z&ub) != z)continue;
		int x = 0;
		for (int j = 0; j < kets.size(); j++)
		{
			if (z&(1 << kets[j]))x += (1 << j);
		}
		v.push_back(x);
		//printf("%d %d\n",i, x);
	}
	int len = kets.size();
	num = v.size();
	for (int i = 0; i < 52; i++)
	{
		com[i][0] = 1;
		for (int j = 1; j <= i; j++)com[i][j] = com[i - 1][j - 1] + com[i - 1][j];
		for (int j = 1; j <= 52; j++)rcom[i][j] = rcom[i][j - 1] + com[i][j];
	}
	ll ans = 0;
	for (int p = 0; p < (1 << len); p++)
	{
		for (int i = 0; i < num; i++)zzz[i] = (p&v[i]);
		sort(zzz, zzz+num);
		zzz[num] = -1;
		ll t = 0;
		int c = 0, now = -1;
		for (int i = 0; i <= num; i++)
		{
			if (now != zzz[i])
			{
				t += rcom[c][min(c, gen)];
				now = zzz[i], c = 1;
			}
			else c++;
		}
		bool f = false;
		for (int i = 0; i < len; i++)if (p&(1 << i))f ^= 1;
		if (!f)ans += t;
		else ans -= t;
		//printf("  %d %lld\n", p, t);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 3272
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  ll K, A, B;
  cin >> K >> A >> B;
  if (A + 2 >= B) {
    cout << 1 + K << endl;
    return;
  }
  if (1 + K - 2 < A) {
    cout << 1 + K << endl;
    return;
  }
  K -= A - 1;
  ll cur = A;
  if (K % 2 == 1) {
    cur++;
    K--;
  }
  cout << cur + (K / 2) * (B - A) << endl;
  return;
}

signed main() {
  fastio();
  solve();
  //   int t;
  //   cin >> t;
  //   while (t--) solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


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

int dp[100001][4];

int main()
{
	int maxans;
	int i,j,k,n;
	cin >> n;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=3;j++)
		{
			cin >> dp[i][j];
		}
	}
	
	for(i=2;i<=n;i++)
	{
		for(j=1;j<=3;j++)
		{
			if(j==1)
			{
				dp[i][j]+=max(dp[i-1][j+1],dp[i-1][j+2]);
			}
			if(j==2)
			{
				dp[i][j]+=max(dp[i-1][j+1],dp[i-1][j-1]);
			}
			if(j==3)
			{
				dp[i][j]+=max(dp[i-1][j-1],dp[i-1][j-2]);
			}
		}
	}
	maxans = max(dp[n][1],max(dp[n][2],dp[n][3]));
	cout << maxans << endl;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, N, M, Q);
  vector<int> l(N + 2), r(N + 2);
  vector<vector<int>> train(N + 1);
  while (M--) {
    in(int, L, R);
    ++l[L];
    ++r[R];
    train[L].push_back(R);
  }
  vector<int> ls(N + 2), rs(N + 2);
  rep(i, N) {
    ls[i + 1] = ls[i] + l[i + 1];
    rs[i + 1] = rs[i] + r[i + 1];
    // rs[N - i] = rs[N - i + 1] + r[N - i];
  }

  vector outside(N + 1, vector(N + 1, 0));
  priority_queue<int> que;
  for (int i = 1; i <= N; ++i) {
    for (int t : train[i - 1]) {
      que.push(-t);
    }
    while (!que.empty() && -que.top() <= i) {
      que.pop();
    }
    priority_queue<int> que2 = que;
    for (int j = i; j <= N; ++j) {
      while (!que2.empty() && -que2.top() <= j) {
        que2.pop();
      }
      outside[i][j] = que2.size();
    }
  }
  while (Q--) {
    in(int, p, q);
    out(rs[q] - ls[p - 1] + outside[p][q]);
    // out(M - (ls[p - 1] + rs[q + 1]));
  }
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    bool ok = false;
    if(a == b && a != c)ok = true;
    if(a == c && a != b)ok = true;
    if(b == c && a != b)ok = true;
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

int n;
int a[200010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    REP(i, n) cin >> a[i+1];

    for(int i=n; i>1; i-=2) {
        cout << a[i] << " ";
    }
    cout << a[1];
    int s = (n&1) ? 2 : 3;
    for(; s<=n; s+=2) {
        cout << " " << a[s];
    }
    cout << endl;
}


Measured memory_bytes: 2944
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++) a[i] = sc.nextInt();
		int ans=0;
		for(int i=0; i<n; i++) {
			ans+=a[i]-1;
		}
		System.out.println(ans);
 	}
	
	static void printArray(int[] a) {
		int n=a.length;
		for(int i=0; i<n; i++) {
			if(i==0) System.out.print(a[i]);
			else System.out.print(" "+a[i]);
		}
		System.out.println();
	}

	static class MyScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public MyScanner(InputStream s) 
		{
			br=new BufferedReader(new InputStreamReader(s));
		}
		public String nextLine() throws IOException
		{
			return br.readLine();
		}
		public String next() throws IOException
		{
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
			
		}
		public double nextDouble() throws IOException
		{
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException
		{
			return br.ready();
		}
		public long nextLong() throws IOException
		{
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 22740
from collections import deque

S = deque(input())
Q = int(input())
reverse_index = -1

for i in range(Q):
    query = input()
    if query[0] == '1':
        reverse_index *= -1
    elif query[0] == '2':
        if query[2] == '1':
            if reverse_index == -1:
                S.appendleft(query[4])
            else:
                S.append(query[4])
        else:
            if reverse_index == -1:
                S.append(query[4])
            else:
                S.appendleft(query[4])

if reverse_index == 1:
    S.reverse()
    print(*S, sep='')
else:
    print(*S, sep='')


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

using namespace std;

int n, a, b;
int p[100010], d[100010], dp[100010];
vector<int> adj[100010];

void rootTree(int u, int par = -1){
    dp[u] = d[u];

    for(auto v : adj[u]){
        if(v == par) continue;

        p[v] = u;
        d[v] = d[u] + 1;
        rootTree(v, u);

        dp[u] = max(dp[u], dp[v]);
    }
}

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

    for(int i = 1; i < n; i++){
        int u, v;
        scanf("%d%d", &u, &v);

        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }

    memset(p, -1, sizeof(p));

    rootTree(b);

    int ans = 0, dep = 0;

    while(d[a] > dep){
        //Test for a
        ans = max(ans, dp[a] - 1);

        a = p[a];
        dep++;
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,total=0;
  cin>>n;
  long long a[n],b[n],c[n-1];
  for(int i=0;i<n;i++)
    cin>>a[i];
  for(int i=0;i<n;i++)
    cin>>b[i];
  for(int i=0;i<n-1;i++)
    cin>>c[i];
  for(int i=0;i<n;i++)
    total+=b[i];
  for(int i=1;i<n;i++)
  {
    if(a[i]==a[i-1]+1)
      total+=c[a[i-1]-1];
  }
  cout<<total<<endl;
  return 0;
}
    
  

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

bool isPalindrome(int x){
  string s = to_string(x);
  int n=s.length();
  bool ret=true;
  repeat(i,(n+1)/2){
    ret &= s[i]==s[n-1-i];
  }
  return ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A,B;cin>>A>>B;
  int ans = 0;
  for(int i=A;i<=B;i++){
    ans += isPalindrome(i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
mod = 10**9+7
fun = [1]*(n+1)
for i in range(1,n+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n+1)
rev[n] = pow(fun[n],mod-2,mod)
for i in range(n-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod

def cc(n,r):
    if n < 0 or r < 0 or r > n:
        return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod

def h(n,r):
    return(cc(n+r-1,r-1))

for i in range(1,k+1):
    bl = k-i
    rd = n-k-i+1
    print(h(bl,i)*h(rd,i+1)%mod)

Measured memory_bytes: 3444
s = gets.chomp.split("")
t = gets.chomp.split("")

max = 0

s.size.times do |i|
  count = 0
  t.size.times do |j|
    if s[i+j].nil?
      count = 0
      break
    end
    if s[i+j]==t[j]
      count += 1
    end
  end
  if max < count
    max = count
  end
end

puts("#{t.size-max}")

Measured memory_bytes: 14292
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
#define MOD 1000000007

int main(void) {
    i64 n, m;
    cin >> n >> m;
    vector<bool> a(n, false);
    vector<i64> dp(n + 1, 0);
    for (i64 i = 0; i < m; i++) {
        i64 x;
        cin >> x;
        a[x] = true;
    }
    dp[0] = 1;
    for (i64 i = 1; i <= n; i++) {
        if (!a[i - 1]) {
            dp[i] += dp[i - 1];
            dp[i] %= MOD;
        }
        if (i != 1 && !a[i - 2]) {
            dp[i] += dp[i - 2];
            dp[i] %= MOD;
        }
    }
    cout << dp[n] << endl;
}

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

int main() {
	int h1, m1;
	scanf("%d %d", &h1, &m1);
	int h2, m2;
	scanf("%d %d", &h2, &m2);
	int k;
	scanf("%d", &k);
	m1 += h1 * 60;
	m2 += h2 * 60;
	printf("%d\n", m2 - m1 - k);
	return 0;
}


Measured memory_bytes: 3828
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

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

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

func main() {
	n := nextInt()

	res := 0
	for i := 0; i < n; i++ {
		a := nextInt()

		for a%2 == 0 && a != 0 {
			a /= 2
			res++
		}
	}

	fmt.Println(res)
}


Measured memory_bytes: 896
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    string O, E; cin >> O >> E;
    rep(i, 0, O.size()+E.size()) {
      if (i%2 == 0) cout << O[i/2];
      else cout << E[(i-1)/2];
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		const long MOD = 1000000007;
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			long a = cin.Long();
			long b = cin.Long();
			long c = cin.Long();
			if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
				Console.WriteLine(0);
				return;
			} else {
				Console.WriteLine(Math.Min(Math.Min(a * b, b * c), a * c));
			}
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;
		
		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


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

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

class Mod{
  public:
    ll mod;
    // mod must be a prime number
    Mod(ll m){
        mod = m;
    }
    //a^p
    ll modpow(ll a, ll p){
        if(p == 0) return 1;
        if(p%2 == 0){
            ll half = modpow(a, p/2);
            return half * half % mod;
        }
        else return a * modpow(a,p-1) % mod;
    }

    //nCr
    ll comb(ll n, ll r){
        if(r > n-r) return comb(n,n-r);
        ll mul = 1;
        ll div = 1;
        for (int i = 0;i < r;i++){
            mul *= n-i;
            mul %= mod;
            div *= i+1;
            div %= mod;
        }
        return mul * modpow(div,mod-2) % mod;
    }
};

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

    ll N,M,K; cin >> N >> M >> K;

    ll mod = 1e9+7;

    Mod m(1e9+7);

    ll t = m.comb(N*M-2,K-2);
    ll ans = 0;

    for (int i = 0;i <= N;i++){
        ans += i*(N-i)*((M*M)%mod)*t;
        ans %= mod;
    }

    for (int i = 0;i <= M;i++){
        ans += i*(M-i)*((N*N)%mod)*t;
        ans %= mod;
    }

    cout << ans << endl;
    
    return 0;

}

Measured memory_bytes: 256
package main

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

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

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

func main() {
	S := getString()

	strMap := make(map[byte]int)
	for i := 0; i < 4; i++ {
		v, ok := strMap[S[i]]
		if ok {
			strMap[S[i]] = v + 1
		} else {
			strMap[S[i]] = 1
		}
	}

	if len(strMap) == 2 {
		for _, v := range strMap {
			if v != 2 {
			} else {
				fmt.Println("Yes")
			}
			return
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 640
import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val Array(h, n) = in.readLine().split("\\s+").map(_.toInt)
    val as = in.readLine().split("\\s+").map(_.toInt)

    System.out.println(
      if (h <= as.sum) {
        "Yes"
      } else {
        "No"
      }
    )
  }
}


Measured memory_bytes: 42376
#include <iostream>
#include <string>
#include <set>
#include <cctype>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <limits>
#include <cmath>
#include <typeinfo>
 
 
using namespace std; 
 
 
// ||    



int firstDigit(int n) 
{ 
    // Remove last digit from number 
    // till only one digit is left 
    while (n >= 10)  
        n /= 10; 
      
    // return the first digit 
    return n; 
} 

int lastDigit(int n) 
{ 
    // return the last digit 
    return (n % 10); 
} 


void sortString(string &str) 
{ 
   sort(str.begin(), str.end()); 
}
 
void reverseStr(string& str) 
{ 
    int n = str.length(); 
  
    // Swap character starting from two 
    // corners 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
} 

void bubbleSort(int arr[], int n)  
{  
    for(int i = 1; i <= n; i++) {
    	for(int j = 0; j < n; j++)  {
       		if (arr[j] > arr[j+1]) {
       			swap(arr[j], arr[j+1]); 

       		}  
    	}
    }      
 
} 

bool allCharactersSame(string s) 
{ 
	int n = s.length();
    for (int i = 1; i < n; i++) 
        if (s[i] != s[0]) 
            return false; 
  
    return true; 
}

int main() { 
	int n = 0;
	string s, p;
	int cnt = 0;
	cin >> n;
	cin >> s;
	if(n % 2 != 0) {
		cout << "No" << endl;
		return 0;	
	}
	int e = n / 2;
	int m = e;
	for(int i = 0; i < e; i++) {
		if(s[i] == s[m]) {
			cnt++;
		}
		m++;
	}
	if(cnt == n/2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
   
    return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop
import math
 
N,M = [int(i) for i in input().split(' ')]
inputList = [int(i) for i in input().split(' ')]
list = []
 
for i in inputList:
    heappush(list, -i)
 
for _ in range(M):
    heappush(list, math.ceil(heappop(list)/2))
    
print(-sum(list))

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

using namespace std;
typedef long long ll;
//#define int ll
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define FOR(i, a, b) for (int i = a; i < b; ++i)

typedef pair<int, int> pii;
typedef pair<double, int> pdi;

const int INF = 1000 * 1000 * 1000 + 10;
const int M = 1000 * 1000 * 1000 + 9;
const ll INFLL = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000;

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

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int n;
    cin >> n;

    vector<int> a(n), b(n);

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

    ll ans = 0;

    set<int> set1;
    set<int, greater<>> set2;

    set1.insert(b[n - 1]);
    set2.insert(b[n - 1]);

    for (int i = n - 2; i >= 0; --i) {
        auto it1 = set1.upper_bound(b[i]);
        auto it2 = set1.end();
        if (it1 != set1.end())
            it2 = set1.upper_bound(*it1);

        auto it3 = set2.upper_bound(b[i]);
        auto it4 = set2.end();
        if (it3 != set2.end())
            it4 = set2.upper_bound(*it3);

        int v1 = (it1 == set1.end() ? n : *it1);
        int v2 = (it2 == set1.end() ? n : *it2);
        int v3 = (it3 == set2.end() ? -1 : *it3);
        int v4 = (it4 == set2.end() ? -1 : *it4);

        set1.insert(b[i]);
        set2.insert(b[i]);

        ll val = i + 1;

        ll p1 =  (v1 != n ? ((v2 - v1) * (b[i] - v3)) : 0);
        ll p2 =  (v3 != -1 ? ((v3 - v4) * (v1 - b[i])) : 0);

        ans += (p1 + p2) * val;
    }

    cout << ans;
}

Measured memory_bytes: 10368
#include<stdio.h>
int main (){
  int a,b,tmp,r;
  scanf("%d%d",&a,&b);
if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 

 r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }


 printf("%d\n", b);


  
  return 0;

}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <functional>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
typedef long long ll;
using namespace std;
int main() {
    // input
    int n, m; cin >> n >> m;
    vector<unordered_map<int,vector<int> > > g(n);
    repeat (i,m) {
        int p, q, c; cin >> p >> q >> c; -- p; -- q;
        g[p][c].push_back(q);
        g[q][c].push_back(p);
    }
    // compute
    vector<int> dist(n, -1);
    queue<int> que;
    dist[0] = 0;
    que.push(0);
    vector<unordered_set<int> > used(n);
    function<void (int, int, int)> dfs = [&](int i, int c, int d) {
        used[i].insert(c);
        if (dist[i] == -1) {
            dist[i] = d;
            que.push(i);
        }
        for (int j : g[i][c]) {
            if (used[j].count(c)) continue;
            if (dist[j] != -1 and dist[j] < d) continue;
            dfs(j, c, d);
        }
    };
    while (not que.empty()) {
        int i = que.front(); que.pop();
        for (auto it : g[i]) {
            int c = it.first;
            if (not used[i].count(c)) {
                dfs(i, c, dist[i]+1);
            }
        }
    }
    // output
    cout << dist[n-1] << endl;
    return 0;
}


Measured memory_bytes: 67840
#include <cstdio>

int main()
{
    char a,b;
    scanf("%c %c",&a,&b);
    
    if(a == 'H' && b == 'H')
    {
        printf("H");
    }
    else if(a == 'H' && b == 'D')
    {
        printf("D");
    }
    else if(a == 'D' && b == 'H')
    {
        printf("D");
    }
    else
    {
        printf("H");
    }
}

Measured memory_bytes: 1644
import java.util.*;
import java.io.*;

class Edge{
    int a,b;
    public Edge(int a, int b){
        this.a=a;
        this.b=b;
    }
    public String toString(){
        return a+" "+b;
    }

}
public class Main {
    static void impossible(){
        System.out.println("-1");
        System.exit(0);
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        if(K > N*(N-1)/2 - N + 1) impossible();

        List<Edge> edges = new LinkedList<>();
        for(int n=1; n<N; n++){
            edges.add(new Edge(n,N));
        }
        int pairs = N*(N-1)/2 - N + 1;
        for(int i=1; i<N; i++) for(int j=i+1; j<N; j++){
            if(pairs>K){
                pairs--;
                edges.add(new Edge(i,j));
            }
        }

        System.out.println(edges.size());
        for(Edge e:edges) System.out.println(e);

    }
}

Measured memory_bytes: 24276