akhauriyash/Code-Regression huggingface dataset:
while 1:
    try:
        s = input().split()
        st = []
        for v in s:
            if v == '+' or v == '-' or v == '*' or v == '/':
                a = st.pop()
                b = st.pop()
                if v == '+':
                    st.append(a + b)
                elif v == '-':
                    st.append(b - a)
                elif v == '*':
                    st.append(a * b)
                elif v == '/':
                    st.append(b / a)
            else:
                st.append(float(v))
        print(st.pop())
    except:
        break



Measured memory_bytes: 5576
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  int d, n;
  cin >> d >> n;
  vi t(d);
  cin >> t;
  vi a(n), b(n), c(n);
  rep(i, n) cin >> a[i] >> b[i] >> c[i];
  vvi dp(d, vi(n, -1));
  rep(i, n) if (a[i] <= t[0] && t[0] <= b[i]) dp[0][i] = 0;
  loop(i, 1, d) rep(j, n) rep(k, n) {
    if (t[i] < a[k] || b[k] < t[i] || dp[i - 1][j] == -1) continue;
    cmax(dp[i][k], dp[i - 1][j] + abs(c[k] - c[j]));
  }
  cout << *max_element(all(dp.back())) << endl;
}

Measured memory_bytes: 3260
import sys
import collections

input = sys.stdin.readline

def main():
    ans = 0
    n = int(input())
    s = [input().rstrip('\n') for _ in range(n)]
    m = int(input())
    t = [input().rstrip('\n') for _ in range(m)]
    cs = collections.Counter(s)
    ct = collections.Counter(t)
    for k,v in cs.items():
        ans = max(v-ct[k], ans)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9376
#include<bits/stdc++.h>
#include<iomanip>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define KETA 40

using namespace std;

typedef long long  ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n;
	int p[21];
	int total=0;

	cin>>n;
	rep(i,n){
		cin>>p[i];
	}

	for(int i=1; i<n-1; i++){
		if(p[i-1]<p[i]&&p[i]<=p[i+1])total++;
		else if(p[i-1]>=p[i]&&p[i]>p[i+1])total++;
	}
	cout<<total<<endl;

	return 0;

}


Measured memory_bytes: 256
# include "cstdio"
# include "algorithm" 
 
const int maxm=1000+10; 
 
int n,	//n个蛋糕 
	m; 	//取出m个蛋糕 
 
long long 
	dp[5][maxm], 
	ans,now1,now2; 
 
inline long long read(){
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0' || ch>'9'){
		if(ch=='-') w=-w;
		ch=getchar();
	}
	while(ch>='0' && ch<='9'){
		s=s*10+ch-'0';
		ch=getchar();
	}
	return s*w;
}

inline long long max(long long x,long long y){
	return x>y?x:y; 
} 

inline bool comp(long long x,long long y){
	return x>y?true:false; 
} 

int main(){
	long long x,y,z;
	register int i,j; 
	n=read(),m=read();
	for(i=1;i<=n;i++){
		x=read(),y=read(),z=read(); 
		dp[1][i]=x+y+z; //-x-y-z
		dp[2][i]=x+y-z;	//-x-y+z
		dp[3][i]=x-y+z;	//-x+y-z
		dp[4][i]=x-y-z;	//-x+y+z
	}
	for(i=1;i<=4;i++){
		std::sort(dp[i]+1,dp[i]+1+n,comp);
		now1=now2=0; 
		for(j=1;j<=m;j++){
			now1+=dp[i][j];
			now2+=dp[i][n-j+1]; 
		}
		ans=max(ans,max(now1>0?now1:-now1,now2>0?now2:-now2)); 
	}
	printf("%lld",ans); 
	return 0; 
} 

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

    def bfs(start):
        q = [start]
        d = [inf]*N
        d[start] = 0
        for i in range(N):
            tmp = []
            while q:
                v = q.pop()
                for to in edge[v]:
                    if d[to]==inf:
                        tmp.append(to)
                        d[to] = i+1
            q = tmp
        return d        
    
    fennec = bfs(0)
    snuke = bfs(N-1)

    f,s = 0,0
    for i in range(N):
        if fennec[i]<=snuke[i]:
            f+=1
        else:
            s+=1
    if f>s:
        print("Fennec")
    else:
        print("Snuke")

    

if __name__ == '__main__':
    main()

Measured memory_bytes: 87068
n,m,x=map(int,input().split())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
cursor=n
current=[0]*n
mincost=1000000000000000000000
breakflag=0
while True:
  thing=[0]*m
  cost=0
  for i in range(n):
    if current[i]==1:
      cost+=a[i][0]
      for j in range(m):
        thing[j]+=a[i][j+1]
  success=1
  for j in range(m):
    if thing[j]<x:
      success=0
  if success==1 and cost<mincost:
    mincost=cost
  while True:
    if current[cursor-1]<1:
      current[cursor-1]+=1
      for i in range(cursor,n):
        current[i]=0
      cursor=n
      break
    cursor-=1
    if cursor==0:
      breakflag=1
      break    
  if breakflag==1:
    break
if mincost==1000000000000000000000:
  print(-1)
else:
  print(mincost)

Measured memory_bytes: 9260
#include<stdio.h>

int main(void) {
	int x, y;
	scanf("%d %d", &x, &y);
	int i, n;
	for (i = 0; i <= x; i++) {
		n = 2 * i + 4 * (x - i);
			if (n == y) {
				printf("Yes");
				break;
			}
			else {
			}
	}
	if (n != y) {
		printf("No");
	}

	return 0;

}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
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; }
 
// 累乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
int dx[4] = {1, 0, 0, -1}, dy[4] = {0, 1, -1 ,0};
 
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
 
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }
 
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
 
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
 
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};



int main(){
    ll N;
    cin >> N;
    map<ll, ll>mp;
    vector<ll>a(N);
    REP(i, N){
        cin >> a[i];
        mp[a[i]]++;
    }
    ll sum = 0;
    for(auto x : mp){
        sum += (x.second * (x.second - 1)) / 2;
    }

    REP(i, N){
        cout << sum - (mp[a[i]] - 1) << endl;
    }
    return 0;
    }

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

int main() {
	int n;
	scanf("%d", &n);
	vector<int> data(n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &data[i]);
	}
	vector<int> longest(n+1);
	int x = -1;
	for(int i = 0; i < n; i++) {
		longest[data[i]] = longest[data[i] - 1] + 1;
		x = max(x, longest[data[i]]);
	}
	printf("%d\n", n-x);
}

Measured memory_bytes: 1792
from collections import defaultdict

N = int(input())
A = [int(input()) for i in range(N)]

d = defaultdict(int)
for Ai in A:
    d[Ai] += 1

sorted_A = sorted(d.keys(), reverse=True)
for Ai in A:
    if Ai < sorted_A[0]:
        ans = sorted_A[0]
    else:
        ans = sorted_A[0] if d[sorted_A[0]] >= 2 else sorted_A[1]
    print(ans)


Measured memory_bytes: 75860
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;
vector<int>vec;

int bs(int a){
  int l=-1,r=(int)vec.size();
  while(r-l>1){
    int mid=(l+r)/2;
    if(vec[mid]<a){
      r=mid;
    }
    else{
      l=mid;
    }
  }
  return r;
}

int main(){
  int n;
  int a[100009];
  cin>>n;
  rep(i,n){
    cin>>a[i];
  }
  vec.push_back(a[0]);
  for(int i=1;i<n;i++){
    int idx=bs(a[i]);
    if(idx==vec.size()){
      vec.push_back(a[i]);
    }
    else{
      vec[idx]=a[i];
    }
  }
  cout<<vec.size()<<endl;
  return(0);
}


Measured memory_bytes: 1276
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,6);
  var list = {
  	"K" : input.indexOf("K"),
    "I" : input.indexOf("I"),
    "H" : input.indexOf("H"),
    "B" : input.indexOf("B"),
    "R" : input.indexOf("R")
  };
  if(list["K"] == -1 || list["I"] == -1 ||list["H"] == -1 ||list["B"] == -1 ||list["R"] == -1){
     myout("NO");
    return;
     }
  if(list["K"] > list["I"] || list["I"] > list["H"] ||
     list["H"] > list["B"] || list["B"] > list["R"]){
     myout("NO");
    return;
     }
  if(input.length > 9){
     myout("NO");
    return;
  }
  if(list["K"] != list["I"]-1 || list["I"] != list["H"]-1){
     myout("NO");
    return;
  }
  if(list["B"] - list["H"] > 2){
     myout("NO");
    return;
  }
  if(list["B"] - list["H"] == 2){
     var tmp = input[list["B"]-1];
    if(tmp != "A"){
       myout("NO");
    return;
    }
  }
  if(list["R"] - list["B"] > 2){
     myout("NO");
    return;
  }
  if(list["R"] - list["B"] == 2){
     var tmp = input[list["R"]-1];
    if(tmp != "A"){
       myout("NO");
    return;
    }
  }
  var maeAcount = 0;
  for(var i = 0; i < input.length; i++){
    if(input[i] == "A"){
       maeAcount++;
    }else{
      break;
    }
  }
  if(maeAcount > 1){
     myout("NO");
    return;
  }
  var atoAcount = 0;
  for(var i = input.length-1; i >= 0; i--){
    if(input[i] == "A"){
       atoAcount++;
    }else{
      break;
    }
  }
  if(atoAcount > 1){
     myout("NO");
    return;
  }
  myout("YES");
}
Main(myin());

Measured memory_bytes: 7372
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
// MAIN IDEA   : combinatorics NCR
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define rw freopen("graphs_as_a_service.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 1e5 + 10, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
int n, a[N] = { }, cnt;
int main() {
#ifdef ONLINE_JUDGE
	FAST
#endif
	cin >> n;
	lp(i,1,n)
		cin >> a[i];
	lp(i,1,n)
	{
		if (a[i] == i && i + 1 <= n)
			swap(a[i], a[i + 1]), cnt++;
	}
	if (a[n] == n)
		cnt++;
	f(cnt);
	return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

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

int n,a,sum;

bitset<2005*2005> bit(1);

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

	cin>>n;
	REP(i,n) {
		cin>>a;
		sum+=a;
		bit|=(bit<<a);
	}
	sum=(sum+1)/2;
	while(bit[sum]==0) sum++;
	cout<<sum<<endl;

	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000000000

int n, a[100000];

int main(){
  cin >> n;
  int minv = MAX;
  for ( int i = 0; i < n; i++){
    cin >> a[i];
    minv = min(minv, a[i]);
  }

  bool flag = true;
  while(flag){
    flag = false;
    for ( int i = 0; i < n; i++){
      if (a[i] % minv == 0 ){
        a[i] = minv;
      } else {
        a[i] = a[i] % minv;
        flag = true;
      }
      minv = min(minv, a[i]);
    }
  }

  cout << minv << endl;

  return 0;
}

Measured memory_bytes: 640
@n = gets.to_i
@w_array = gets.chomp.split(' ').map(&:to_i)

def diff(k)
    former = @w_array.first(k).inject(:+)
    latter = @w_array.last(@n - k).inject(:+)
    (latter - former).abs
end

diff_array = []

1.upto(@n - 1) do |i|
    diff_array << diff(i)
end

print diff_array.min

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};

int main() {

	int n;
	cin>>n;

	int t=0;
	for(int i=1; i<n+1; i++){
		int a;
		cin>>a;
		if(a%2>0&&i%2>0)t++;
	}
	cout<<t<<endl;

	return 0;
}


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

#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define uint unsigned int
#define lli long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define forn(i, n)  for(int i=0;i<n;++i)
#define rforn(i,start) for(int i = start; i >= 0;--i)
#define forsn(i,start,end) for(int i=start;i<end;++i)
#define rforsn(i,start,end) for(int i=start;i>=end;--i)
#define debug(x) cout<<#x<<" = "<<x<<"\n";
const int CONST = 1e9 + 7;
const double pi = 3.14159265358979323846;
const int MAX = 100005;

// Declare Variables here


int32_t main()
{
    fastio;
    #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    //  freopen("output.txt","w",stdout);
    #endif
    
    int r, c, m;
    cin>>r>>c>>m;

    // vector<bool> iscom(min(r, c)+1, false);
    vector<int> row(r+1, 0), col(c+1, 0);
    int maxir=0, maxic=0;
    set<pii> targets;
    forn(i, m){
        int u, v;
        cin>>u>>v;

        // if(u==v)    iscom[u]=true;
        row[u]++;
        col[v]++;
        targets.insert({u, v});
    }
    vector<int> ridx, cidx;
    maxir= *max_element(all(row));
    maxic = *max_element(all(col));
    forn(i, r+1){
        if(row[i]==maxir){
            // maxir=row[i];
            ridx.pb(i);
        }
    }

    int ans=maxic + maxir-1;
    forn(i, c+1){
        if(col[i]==maxic){
            // maxic=col[i];
            cidx.pb(i);
            // int tmp = maxir + maxic;
            // if(targets.find({ridx, i})!= targets.end()){
            //     --tmp;
            // }
            // ans = max(ans, tmp);
        }
    }

    for(auto i: ridx){
        // bool f= false;
        for(auto j: cidx){
            if(targets.count({i, j})==0){
                ans = maxic + maxir;
                cout<<ans<<endl;
                return 0;
                // f=true;
                // break;
            }
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 23784
#include<stdio.h>
#include<algorithm>
using namespace std;
int m[110][110];
int now[110];
int n;
int dfs(int a,int b){
	if(n==a){
		if(b<2)return 0;
		int val=0;
		for(int i=0;i<b;i++){
			int t=9999999;
			for(int j=0;j<b;j++){
				if(i!=j)t=min(t,m[now[i]][now[j]]);
			}
			val+=t;
		}
		return val;
	}
	int ret=dfs(a+1,b);
	bool ok=true;
	for(int i=0;i<b;i++)if(!m[now[i]][a])ok=false;
	if(ok){
		now[b]=a;
		ret=max(ret,dfs(a+1,b+1));
	}
	return ret;
}
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	n=a;
	for(int i=0;i<b;i++){
		int p,q,r;scanf("%d%d%d",&p,&q,&r);p--;q--;
		m[p][q]=m[q][p]=r;
	}
	printf("%d\n",dfs(0,0));
}

Measured memory_bytes: 1072
(defun xylength (x y)
  (sqrt (+ (expt (- (car x) (car y)) 2) (expt (- (cdr x) (cdr y)) 2))))
(let* ((n (read))
       (lst (loop :repeat n :collect (cons (read) (read)))))
  (princ (float (/ (loop :for k :in lst :sum (loop :for j :in lst :sum (xylength k j))) n))))


Measured memory_bytes: 16352
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
using namespace std;

int main(){

  double v;
  while( cin >> v ){
    double t = v / 9.8;
    double y = 4.9 * t * t;
    // cout << y << endl;
    int n = (y + 5 + 0.0000001) / 5;
    n++;
    cout << n << endl;
  }

  return 0;
}

Measured memory_bytes: 3116
//include,using,define等
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>

// ===============================================================
//using系
#pragma region header
using namespace std;
using ll = long long;
using lint = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ui = unsigned int;
using qul = queue<ll>;
using pql = priority_queue<ll>;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#pragma region header
//#define int long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define INF (ll)10000000000000000
#define mod (ll)1000000007
#define P pair<lint,lint>
template <class T>
bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
template <class T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main(void) {
	lint n; cin >> n;
	lint a, b; cin >> a >> b;
	if ((b - a) % 2 == 0)
		printf("Alice\n");
	else
		printf("Borys\n");

    return 0;
}

Measured memory_bytes: 3568
S = list(input())
l = len(S)
S1 = S[:l//2][::-1]
S2 = S[l-l//2:]
ans = (l+1)//2
c = S[l//2]
for i in range(l//2):
    if S1[i] == c and S2[i] == c:
        ans += 1
    else:
        break
print(ans)

Measured memory_bytes: 72628
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var rc=Arr[0].split(" ").map(Number);
var c=[];
for(var i=0;i<rc[1]+1;i++)c.push(0);
 
for(var i=1;i<Arr.length;i++){
   var arr=Arr[i].split(" ").map(Number);
   var sum=arr.reduce(function(a,b){return a+b;});
   console.log(Arr[i]+" "+sum);
   arr.push(sum);
   arr.forEach(function(v,i){c[i]+=v;});
}
console.log(c.join(" "));


Measured memory_bytes: 17412
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>
#include<queue>
#include<set>


#define MOD 1000000007
#define DEBUG 0


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

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

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

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

	return true;
}



bool comp(const pair<long long int, vector<int>> a, const pair<long long int, vector<int>> b) {
	if (a.first != b.first) {
		return a.first < b.first;
	}
	else {
		return a.second < b.second;
	}

}










int main(){

	
	double L;
	cin >> L;

	double val = L / 3.0;

	val = val * val * val;

	printf("%.8lf\n", val);

	

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
#define ll long long ;

int N;
int S;

int change(int a){
	while (a > 0){
		S += a % 10;
		a = a / 10;
	}
	return S;

}

int main(){

	cin >> N;
	if (N % change(N) == 0)  cout << "Yes" << endl;
	else cout << "No" << endl;
		 

	return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

import itertools

X,N = map(int,readline().split())
p = list(map(int,readline().split()))
ans = -INF
now = INF
for i in range(-10,105):
    if i not in p:
        if now > abs(X-i):
            ans = i
            now = abs(X-i)
print(ans)


Measured memory_bytes: 9356
// #include <iostream>
// #include <string>
// #include <math.h>
// #include <map>
// #include <vector>
// #include <tuple>
// #include <algorithm>
// #include <queue>
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define pii pair<int, int>
#define plli pair <lli, lli>
#define F(i,n) for(lli (i)=0;(i)<(n);(i)++)
#define FR(i,n) for(lli (i)=(n)-1;(i)>=0;(i)--)
#define FSG(i,a,b) for(lli (i)=(a);(i)<(b);(i)++)
#define FSGR(i,a,b) for(lli (i)=(b)-1;(i)>=(a);(i)--)
#define VAL(n) cout << n << endl;
#define VALD(n) cout << #n << ": " << n << endl;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int main() {
  long long int N, M;
  cin >> N >> M;
  vector<pair<int, int> > vec;
  for(int i = 0; i < N; i++){
    int a, b;
    cin >> a >> b;
    vec.emplace_back(a, b);
  }
  sort(vec.begin(), vec.end());
  queue<pii> q;
  F(i, N){
    q.push(vec[i]);
  }
  long long int sum = 0;
  auto c = [](plli ai,plli bi){return ai.second < bi.second;};
  priority_queue<lli, vector<plli>, decltype(c)> pq(c);
  FSG(i, 1, M+1){
    while(q.size() > 0 && (q.front()).first <= i){
      pq.push(q.front());
      q.pop();
    }

    if(pq.size()>0){
      sum += (pq.top()).second;
      pq.pop();
    }
  }
  cout << sum << endl;
  return 0;
}


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

int main(){
  string s;
  cin >> s;
  
  int start, end;
  for ( int i = 0; i < s.size(); i++ ){
    if ( s[i] == 'A' ){
      start = i;
      break;
    }
  }
  
  for ( int i = s.size() - 1; i >=0; i-- ){
    if ( s[i] == 'Z' ){
      end = i;
      break;
    }
  }
  
  cout << end - start + 1 << endl;
}

Measured memory_bytes: 640
unittest
{
	assert( [ "2 2", "2 1 2", "1 2", "0 1" ].parse.expand.solve == 1 );
	assert( [ "2 3", "2 1 2", "1 1", "1 2", "0 0 1" ].parse.expand.solve == 0 );
	assert( [ "5 2", "3 1 2 5", "2 2 3", "1 0" ].parse.expand.solve == 8 );
}



import core.bitop;
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto ss = new long[][ nm[ 1 ] ];
	foreach( ref s; ss )
	{
		input.popFront;
		s = input.front.split.to!( long[] )[ 1 .. $ ];
	}
	input.popFront;
	auto ps = input.front.split.to!( long[] );
	return tuple( nm[ 0 ], ss, ps );
}

auto solve( long n, long[][] ss, long[] ps )
{
	// 電球に対応しているスイッチをビットパターンに変換
	auto pbs = new uint[]( ps.length );
	foreach( ref pb, s; lockstep( pbs, ss ) )
	{
		foreach( w; s )
		{
			pb |= 1 << ( w - 1 );
		}
	}
	
	// 各スイッチのON/OFF状態をビットパターンで列挙
	auto ans = 0L;
	auto m = 1U << n;
	for( auto b = 0U; b < m; b++ )
	{
		//  電球に対応しているスイッチと各スイッチのON/OFF状態のANDを取って電球の状態を判定
		auto on = 0L;
		foreach( pb, p; lockstep( pbs, ps ) )
		{
			on += ( ( b & pb ).popcnt % 2 == p );
		}
		
		// 全ての電球が付いていたら答えに足す
		ans += ( on == ps.length );
	}
	
	return ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
/* global variables */
/* function */
/* main */
int main(){
    string t;
    cin >> t;

    string ac = "CODEFESTIVAL2016";
    int ans = 0;
    for (int i = 0; i < t.size(); i++) {
        if (t[i] != ac[i]) {
            ans++;
        }
    }

    cout << ans << '\n';
}

Measured memory_bytes: 3592
import Control.Applicative
import Debug.Trace

calc :: [String] -> String
calc xs = loop xs $ words "_ _"
  where
    loop [] (y : _) = y
    loop (x : xs) ys@(a : b : ys')
      | x == "+" = loop xs ((calc' (+) b a) : ys')
      | x == "-" = loop xs ((calc' (-) b a) : ys')
      | x == "*" = loop xs ((calc' (*) b a) : ys')
      | otherwise = loop xs (x : ys)
      where calc' obj x y = show (obj (read x) (read y))

main :: IO ()
main = do
  ss <- words <$> getLine
  putStrLn $ calc ss



Measured memory_bytes: 3972
#include<bits/stdc++.h>
using namespace std;
string s;
long long ans=0;
bool fuhao[15];
int len;
inline void check()
{	
	long long num=0;
	for(int i=0; i<len; i++)
	{
		num*=10;
		num+=s[i]-'0';
		if(fuhao[i])
			ans+=num, num=0;
	}
	ans+=num;
}
inline void fuha(int x)
{
	if(x==len-1)
	{
		fuhao[len-1]=false;
		check();
		return;
	}
	fuhao[x]=false;
	fuha(x+1);
	fuhao[x]=true;
	fuha(x+1);
}
int main()
{
    cin>>s;
    len=s.size();
    fuha(0);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    D, T, S = map(int, input().split())

    if D / S <= T:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 72776
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
struct edge{
  int from,to,cost;
};
bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}
edge es[100001];
int E,V;
ll kruskal(){
  sort(es,es+E,comp);
  init(V);
  ll res = 0;
  for(int i=0;i<E;i++){
    edge e = es[i];
    cout << es[i].cost << endl;
    if(!same(e.to,e.from)){
      unite(e.to,e.from);
      res += e.cost;
    }
  }
  return res;
}

int main()
{
  int N,a,f;
  ll d[301][301],s[301][301],res=0;
  cin >> N; 
  REP(i,N)REP(j,N){
    cin >> a;
    d[i][j] = a;
    s[i][j] = a;
    res += s[i][j];
  }
  res /= 2;

  REP(i,N)REP(j,N)REP(k,N){
    d[j][k] = min(d[j][k] , d[j][i] + d[i][k]);
  }
  REP(j,N)REP(k,N){
    if(s[j][k] != d[j][k]){
      cout << -1 << endl;
      return 0;
    }
  }
  REP(i,N)for(int j=0;j<i+1;j++){
    REP(k,N){
    if(k == i || k ==j) continue;
    if(d[i][j] == (d[i][k] + d[k][j])){
      res -= d[i][j];
      k = N;
    }
    }
  }
  
 
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 1664
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
plus = 0
minus = 0
for i in range(n):
  if a[i] > b[i]:
    minus += a[i]-b[i]
  elif a[i] < b[i]:
    plus += (b[i] - a[i])//2
if minus <= plus:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 4600
#include <algorithm>
#include <iostream>
#include <vector>

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

int main() {
  using namespace std;
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  int ans = 0;
  long long req = 0;
  vector<int> suf;
  for (int i = 0; i < n; i++) {
    if (a[i] - b[i] < 0) {
      ans++;
      req += b[i] - a[i];
    } else if (a[i] - b[i] > 0) {
      suf.emplace_back(a[i] - b[i]);
    }
  }
  debug(req, ans);
  sort(suf.begin(), suf.end(), greater<int>());
  long long suf_sum = 0;
  for (int i = 0; i < (int)suf.size(); i++) {
    if (suf_sum >= req) break;
    suf_sum += suf[i];
    ans++;
  }
  if (suf_sum >= req) {
    cout << ans << '\n';
  } else {
    cout << -1 << '\n';
  }
  return 0;
}

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

template <typename t>
void mi(t& a, const t& b) { a = min(a, b); }

template <typename t>
void ma(t& a, const t& b) { a = max(a, b); }

constexpr int si = 1024 * 1024, si_log = 10 + 10, mod = static_cast<int>(1e9) + 7, partition_size = 400;

template <typename t, typename u>
void ad(t& a, const u& b)
{
  a += b;
  if (mod <= a) a -= mod;
}

template <typename t, typename u>
void mu(t& a, const u& b)
{
  a = (a * b) % mod;
}

inline int64_t power(int64_t bas, int64_t p)
{
  int64_t r = 1;
  while (p)
  {
    if (p & 1)
      r = (r * bas) % mod;
    bas = (bas * bas) % mod;
    p >>= 1;
  }
  return r;
}

constexpr long double eps = 1.0e-9;
//printf("%0.9f\n", p);
int n, m, k, ar[si], br[si];
char bar[si], car[si];
vector<pair<int, int64_t>> gr[si];


int64_t sol()
{
  auto r = 0 * numeric_limits<int64_t>::max();

  int q = 0;

  for (int i = 0; i <= n; i++)
  {
    if (ar[i])
    {
      br[q++] = ar[i];
    }
  }
  
  if (k < q)
  {
    sort(br, br + q);

    for (int i = 0; k < q--; i++)
    {
      r += br[i];
    }
  }

  return r;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  while (2 == scanf("%d%d", &n, &k))
  {
    for (int i = 0; i < n; i++)
    {
      int x;
      scanf("%d", &x);
      ar[x]++;
    }

    //n = static_cast<int>(strlen(car));
    auto s = sol();

    //puts(s ? "YES" : "NO");
    cout << s << '\n';
#ifndef _DEBUG
        break;
#else
    for (int i = 0; i <= n + 2; i++)
    {
      gr[i].clear();
    }
    memset(car, 0, sizeof car);
    memset(ar, 0, sizeof ar);
    memset(br, 0, sizeof br);
    memset(br, 0, sizeof br);
#endif
  }
  return 0;
}


Measured memory_bytes: 30976
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a,b,k;
    a = sc.nextInt();
    b = sc.nextInt();
    k = sc.nextInt();
    for(int i = Math.min(a,b);i>=1; i--){
      if(a%i==0&&b%i==0){
        k--;
        if(k==0){
          System.out.println(i);
        }
      }
    }
  }
}

Measured memory_bytes: 21844
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

void main(){
	uint[] arr=new uint[10];
	for(uint i;i<10;++i){
		arr[i]=readln().chomp().to!int();
	}
	arr.sort().reverse();
	for(uint i;i<3;++i){
		writeln(arr[i]);
	}
}

Measured memory_bytes: 2472
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  ll L;
  cin >> L;
  vector<ll> ones;
  ll i = 0;
  while ((L>>i) > 0) {
    if ((L>>i) & 1) {
      ones.push_back(i);
    }
    ++i;
  }
  reverse(all(ones)); // decreasing order

  // For Debug
  // for (auto x : ones) {
  //   cout << x << endl;
  // }

  ll N = ones[0]; // The length of vertices without root(1).
  vector<triple> edges;
  rep(i, N) {
    // i+2 is the target number.
    edges.emplace_back(i+1, i+2, 0);
    edges.emplace_back(i+1, i+2, 1LL << i);
  }
  // Now, N+1 is the last indice.

  ll summed = 1<<N;
  rep(i, ones.size()) {
    if (i == 0) { continue; }
    ll M = ones[i]; // The offset. e.g. 2 for 1 of 100
    edges.emplace_back(M+1, N+1, summed);
    // Do somethinbg
    summed += 1<<M;
  }

  cout << N+1 << " " << edges.size() << endl;
  for (auto x : edges) {
    int i, j, c;
    tie(i, j, c) = x;
    cout << i << " " << j << " " << c << endl;
  }
}


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

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<ll> v(n);
  for(auto &e:v) cin >> e;
  int f = 0;
  for(int i = 0; i < n; i++) if(v[i] < 0) f = i + 1;
  ll ans = 1e18;
  for(int i = 0; i <= k; i++) {
    ll res = 0;
    ll more = 1e18;
    if(i) {
      if(f-i<0) continue;
      res += -v[f-i];
      more = min(more, -v[f-i]);
    } else more = 0;
    if(k-i) {
      if(f+k-i-1>=n) continue;
      res += v[f+(k-i)-1];
      more = min(more, v[f+(k-i)-1]);
    } else more = 0;
    ans = min(ans, res + more);
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
  int i=0;
  long long ans=1,h;
  cin >> h;

  long long hh=h;

  while(hh>0){
    hh/=2;
    i++;
  }
  for(int j=1; j<i; j++){
    ans <<= 1;
    ans++;
  }
  cout << ans;
  return 0;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a) {if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(int a) {if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
void AorB(int a,string b,string c) {if(a){cout<<b<<endl;}else{cout<<c<<endl;}}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

struct UnionFind {
    vector<int> data;
    vector<int> sizes;
    
    UnionFind(int n) : data(n) ,sizes(n, 1){
        for(int i = 0; i < n; i++) data[i] = i;
    }
    
    int root(int x) {
        if (data[x] == x) return x;
        return data[x] = root(data[x]);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (y < x) swap(x, y);
        data[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int size(int x) {
        return sizes[root(x)];
    }
};

signed main(){start();
    int n;
    cin>>n;
    int m=n-1;
    Vi dist(n,0),a(m),b(m);
    VVi connect(n);
    REP(i,0,m){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        connect[a[i]].pb(b[i]);
        connect[b[i]].pb(a[i]);
    }
    queue<Tiii> q;
    q.push(mt(0,-1,0));
    while(!q.empty()){
        int now,past,dnow;
        tie(now,past,dnow)=q.front();
        q.pop();
        dist[now]=dnow;
        if(now==n-1) break;
        REP(i,0,connect[now].size()) if(connect[now][i]!=past) q.push(mt(connect[now][i],now,dnow+1));
    }
    
    int now=m;
    Vi keiro;
    keiro.pb(m);
    REP(i,0,dist[m]){
        REP(j,0,connect[now].size()){
            if(dist[connect[now][j]]==dist[m]-i-1){
                keiro.pb(connect[now][j]);
                now=connect[now][j];
            }
        }
    }
    reverse(ALL(keiro));
    Vi ng;
    ng.pb(keiro[dist[m]/2]);
    ng.pb(keiro[dist[m]/2+1]);
    int ngmax=max(ng[0],ng[1]);
    int ngmin=min(ng[0],ng[1]);

    UnionFind UF(n);
    REP(i,0,m){
        if(max(a[i],b[i])!=ngmax || min(a[i],b[i])!=ngmin) UF.unite(a[i],b[i]);
    }
    if(UF.size(0)>UF.size(m)) cout<<"Fennec"<<endl;
    else cout<<"Snuke"<<endl;
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll MOD = 1000000007;
ll INF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

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

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

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string s, t;
  cin >> s >> t;
  ll n = s.size();
  ll m = t.size();
  ll ans = INF;
  for(ll i = 0; i <= n - m; i++){
    ll tmp = 0;
    for(ll j = 0; j < m; j++){
      if(t[j] != s[i + j]) tmp++;
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;

    
    
  return 0;
}



Measured memory_bytes: 3656
#include <iostream>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
int n; 
int a[410];
ll dp[410][410];

ll rec(ll left, ll right) {
    if (dp[left][right]) return dp[left][right];
    if (left + 1 == right) return 0;

    ll sum = 0;
    ll ans = INF;
    for (ll i = left; i < right; i++) sum += a[i];
    for (ll i = left + 1; i < right; i++) {
        ans = min(ans, sum + rec(left, i) + rec(i, right));
    }
    return dp[left][right] = ans;
}

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

    cout << rec(0, n) << endl;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n;
	cin>>n;
	vd a(n);
	rep(i,n)cin>>a[i];
	double f=accumulate(all(a),0.0)/n;
	int index=0;double diff=INF;
	rep(i,n){
	    if(fabs(a[i]-f)<diff){
	        diff=fabs(a[i]-f);
	        index=i;
	    }
	}
	cout<<index<<endl;
	
	return 0;
}


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

int main(){
  ll N, K;
  cin >> N >> K;
  
  vector<ll>H(N);
  rep(i,N)cin >> H[i];
  
  sort(H.begin(),H.end());
  ll ans = 0;
  rep(i,N-K){
    ans+=H[i];
  }
  cout << ans <<endl;
}

Measured memory_bytes: 4788
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 100;

i64 n, d;
vector<i64> a[MAXN];

bool check(i64 s) {
    i64 t = (i64)sqrt(s);
    if (sqr(t) == s || sqr(t - 1) == s || sqrt(t + 1) == s || sqr(t - 2) == s || sqrt(t + 2) == s) {
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> d;

    for (i64 i = 0; i < n; i++) {
        for (i64 j = 0; j < d; j++) {
            i64 t;
            cin >> t;
            a[i].push_back(t);
        }
    }

    i64 R = 0;
    for (i64 i = 0; i < n; i++) {
        for (i64 j = i + 1; j < n; j++) {
            i64 s = 0;
            for (i64 k = 0; k < d; k++) {
                s += sqr(a[i][k] - a[j][k]);
            }
            if (check(s)) {
                R++;
            }
        }

    }
    cout << R;

    return 0;
}


Measured memory_bytes: 256