akhauriyash/Code-Regression huggingface dataset:
//https://atcoder.jp/contests/abc149/tasks/abc149_e
//E - Handshake
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
struct Info {
    ll sum=0;
    ll id0,id1;
};
#if 01
int main(){
#if LOCAL&0
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N,M; cin>>N>>M;
    vector<ll> an(N);
    for(auto&& a:an){
        cin>>a;
    }
    sort(an.begin(),an.end());
    dump(an);

    //M回の閾値
    auto check_func = [&](ll v)->bool{
        ll cnt=0;
        FOR(i,0,N){
            ll tmp = v-an.at(i);
            auto it = lower_bound(an.begin(), an.end(), tmp);
            cnt += distance(it, an.end()); 
        }
        return (cnt>=M);
    };

    ll lb=0,ub= INT64_MAX;
    while(ub-lb>1){
        ll mid=(ub+lb)/2;
        auto ck = check_func(mid);
        if (ck){
            lb=mid;
        }else{
            ub=mid;
        }
        //dump(mid,ck,lb,ub);
    }
    dump(lb);

    //累積和
    vector<ll> sums(N+1);
    FOR(i,0,N){
        sums[i+1] = sums[i] + an.at(i);
    }
    ll ans=0;
    ll m=M;
    FOR(i,0,N){
        auto r = an.end() - lower_bound(an.begin(), an.end(), lb-an.at(i));
        m -= r;
        auto ad=sums[N] - sums[N-r] + an.at(i)*r;
        dump(i, r,ad);
        ans += ad;
    }
    dump(m,ans);
    ans += lb * m;
    cout<<ans<<endl;
    return 0;
}
#else
int main() {
    ll N,M; cin>>N>>M;
    vector<ll> an(N);
    for(auto&& a:an){
        cin>>a;
    }
    sort(an.begin(),an.end(),greater<ll>());
    dump(an);      

    vector<Info> tbl;
    tbl.reserve(N*N);
    REP(i,N){
        REP(j,N){
            Info info;
            info.sum=an[i]+an[j];
            info.id0=i;
            info.id1=j;
            tbl.push_back(move(info));
        }
    }
    sort(tbl.begin(),tbl.end(),[](const auto& a,const auto& b){ return a.sum>b.sum;});
    ll ans=0;
    REP(i,M){
        const auto& d=tbl[i];
        ans += d.sum;
        dump(d.id0,d.id1,d.sum);
    }
    cout<<ans<<endl;

    return 0;
}
#endif

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN=100100;
const ll MAXK=17;
const ll INF=2e18;
const ll MOD=998244353;

string S;
ll A[MAXN][2];

int main(){
    cin>>S;
    for (auto &i:S)if(i=='?')i='D';
    cout<<S;
}   

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    int n;
    cin >> n;
    int prev;
    int max_count = 0;
    int current_count = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (i == 0) {
            prev = x;
            continue;
        }
        if (prev >= x) {
            current_count++;
        }
        else if (prev < x) {
            max_count = max(max_count, current_count);
            current_count = 0;
        }
        prev = x;
    }
    max_count = max(max_count, current_count);
    cout << max_count << "\n";
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

const ll MOD = 1e9+7;


signed main(){
    ll n,m;
    cin >> n >> m;
    if(n == 1 && m == 1) cout << 1 << endl;
    else if(n == 1 || m == 1) cout << ((ll)max(n,m)-2) << endl;
    else cout << (n-2)*(m-2) << endl;
    
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

//vector< vector<int> > v (size1, vector<int>(size2) );



int h,w,sx,sy,gx,gy,nx,ny,x,y;
queue<P> que;
P xy;
int cost[50][50];
char field[50][50];


int dfs(){
    FOR(i,0,h){
        FOR(j,0,w){
            cost[i][j]=INF;
        }
    }

    cost[sy][sx]=0;
    que.push(P(sy,sx));


    while(que.size()){
        xy=que.front();
        que.pop();
        y=xy.first;
        x=xy.second;
        FOR(i,0,4){
            ny=y+dy[i], nx=x+dx[i];
            //cout<<ny<<' '<<nx<<endl;
            if(0<=nx && nx<w && 0<=ny && ny<h && field[ny][nx]=='.' && cost[ny][nx]==INF){
                cost[ny][nx]=cost[y][x]+1;
                que.push(P(ny,nx));
            }
        }

    }  

    return 0; 

}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>h>>w;
    sx=0;
    sy=0;
    gx=w-1;
    gy=h-1;
    
    FOR(i,0,h){
        cin>>field[i];
    }
    
    dfs();
    int cnt=0;
    FOR(i,0,h){
        FOR(j,0,w){
            if(field[i][j]=='#')
            cnt++;
        }
    }
    //cout<<cnt<<endl;
    
    if (cost[h-1][w-1]==INF){
        cout<<-1<<endl;
    }else cout<<h*w-cost[gy][gx]-cnt-1<<endl;
    
    /*FOR(i,0,r){
        FOR(j,0,c){
            if(cost[i][j]!=INF) cout<<cost[i][j]<<' ';
            else cout<<'N'<<' ';
            if(j==c-1) cout<<endl;
        }
    }*/
    
}
//r


Measured memory_bytes: 256
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

def distance(i1, i2):
    p1 = xy[i1]
    p2 = xy[i2]
    return ((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) ** 0.5

dp = [None] * (1 << n)
def dfs(state=0):
    if dp[state] is not None:
        return dp[state]

    ans = []
    s = 0
    for i in range(n):
        target = 1 << i
        if not state & target:
            res = dfs(state | target)
            ans.append(i)
            for v in res[0]:
                s += distance(i, v)
    dp[state] = ans, s
    return dp[state]

print(dfs()[1] / n)


Measured memory_bytes: 3188
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let a = scan!(usize);
    let b = scan!(usize);
    let h = scan!(usize);
    println!("{}", (a + b) * h / 2);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	ll a, b, c;
	cin >> a >> b >> c;
	ll k;
	cin >> k;

	rep(i, k){
		if (a >= b) b *= 2;
		else
			c *= 2;
	}

	if (a < b && b < c) puts("Yes");
	else
		puts("No");

	return 0;
}


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

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

    int ans = 0;
    for(i = 0; i < n; i++) {
        if ((i+1) % 2 == 1 && a[i] % 2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>

using namespace std;

const int INF = 100000000;
struct Vec{
	int ind;
	int val;
};

bool valDesc( const Vec& left, const Vec& right ) {
    return left.val == right.val  ? left.val> right.val: left.val > right.val;
}

bool valAsc( const Vec& left, const Vec& right ) {
    return left.val == right.val  ? left.val <  right.val: left.val < right.val;
}
int main(void){
	long N,K,x,ans=(long)0;

	cin >> N >> K;
	long s1,s2,s;
	if(K%2 == 0){
		s2 = floor(N/K);
		s1 = floor((long)2*N/K) -s2;
		ans = s1*(s1-(long)1)*(s1-(long)2)+(long)3*s1*(s1-(long)1) + s1;
		ans += s2*(s2-(long)1)*(s2-(long)2)+(long)3*s2*(s2-(long)1) + s2;
	}
	else{
		s = floor(N/K);
		ans = s*(s-(long)1)*(s-(long)2)+(long)3*s*(s-(long)1) + s;
	}

	printf("%ld\n",ans);
	fflush(stdout);

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
        return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
        var tmp = ReadIntArray();
        int n = tmp[0], x = tmp[1];

        int[] ls =  ReadIntArray();

        int i = 1;
        int pos = 0;

        while (i <= n && pos + ls[i-1] <= x)
        {
            pos += ls[i-1];
            i++;
        }

        WriteLine(i);
    }
}


Measured memory_bytes: 13268
#include<stdio.h>

int main(void)
{
 int a,b,c;
 scanf("%d %d %d" ,&a,&b,&c);
 if(a<b&&b<c){
 	printf("Yes\n");
	 }
 else{
 	printf("No\n");
 	}
 return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> hi(n+2);
  hi[0]=0;hi[n+1]=0;
  for(int i=1;i<n+1;i++)
    cin >> hi[i];
  vector<int> va(50,101),pe(50,101);
  int i=1,v=0,p=0;
  while(i<n+1){
    if(hi[i]>hi[i-1]){
      while(hi[i]<=hi[i+1])
        i++;
      pe[p]=hi[i];
      p++;
    }
    else if(hi[i]<hi[i-1]){
      while(hi[i]>=hi[i+1]&&i<n+1)
        i++;
      if(i!=n+1)
       va[v]=hi[i];
      v++;
    }
    i++;
  }
  if(va[0]==101&&pe[0]==101){
    cout << '0' << endl;
    return 0;
  }
  sort(va.begin(),va.end());
  sort(pe.begin(),pe.end());
  int ans=0,num=1,V=0,P=0;
  for (int j=0;j<100;j++){
    if(va[V]==j){
      while(va[V]==j){
        V++;
        num++;
      }
    }
    if(pe[P]==j){
      while(pe[P]==j){
        P++;
        num--;
      }
    }
    ans+=num;
  }
  cout << ans << endl;
 // for(int j=0;j<v;j++)
   // cout << va[j] << " ";
}

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

main(){
  int a,ans=1;
  cin >>a;
  for(int i=1;i<100;i++){
    for(int j= 2;j<100;j++){
      if(a<pow(i,j))break;
      else if( ans<pow(i,j))ans = pow(i,j);
    }
  }
  cout<<(ans)<<endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int N=3e7+10;

int qpow(int a,int b) {
	int ret=1;
	while(b) {
		if(b&1) ret=1ll*ret*a%mod;
		a=1ll*a*a%mod,b>>=1;
	}
	return ret;
}

int S,f[N],ans=0;

int main() {
	cin>>S;
	for(int i=1;i<N;i++) f[i]=f[i/10]+1;
	for(int i=1,j=1,sum=0;i<1e7;i++) {
		while(sum<S) sum+=f[j++];
		if(sum==S) ++ans;
		sum-=f[i];
	}
	for(int i=8;i<=S;i++) {
		if(S%i==0) {
			int cnt=(qpow(10,i)-qpow(10,i-1)+mod)%mod;
			ans=(1ll*ans+cnt-S/i+1+mod)%mod;
		}
		if(i>8) {
			int lo=S/i+1,up=(S-1)/(i-1);
			if(lo<=up) ans=(1ll*ans+up-lo+1+mod)%mod;
		}
	}
	cout<<ans;
	return 0;
}


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

int main() {
    int x, n, ans = INT_MAX, diff = 0;
    cin >> x >> n;
    set<int> st;
    rep(i, n) {
        int temp;
        cin >> temp;
        st.insert(temp);
    }
    while(true) {
        if(st.find(x - diff) == st.end()) {
            ans = x - diff;
            break;
        }
        if(st.find(x + diff) == st.end()) {
            ans = x + diff;
            break;
        }
        diff++;
    }
    cout << ans << endl;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;

int main() {
    ll n, w;
    cin >> n >> w;
    vector<vector<ll>> v(4, vector<ll>());
    ll b, va;
    cin >> b >> va;
    v[0].push_back(va);
    ll we;
    REP(i, n - 1) {
        cin >> we >> va;
        v[we - b].push_back(va);
    }
    vector<vector<ll>> u(4, vector<ll>(101, 0));
    REP(i, 4) {
        sort(ALL(v[i]), greater<ll>());
        REP(j, v[i].size()) {
            u[i][j + 1] = u[i][j] + v[i][j];
        }
    }

    ll s = v[3].size();
    ll mx = 0;
    REP(i, v[0].size() + 1) {
        REP(j, v[1].size() + 1) {
            REP(k, v[2].size() + 1) {
                //if (b * i + (b + 1) * j + (b + 2) * k > w) break;
                //ll num = (w - (b * i + (b + 1) * j + (b + 2) * k)) / (b + 3);
                //chmax(mx, u[0][i] + u[1][j] + u[2][k] + u[3][min(num, s)]);
                REP(l, s + 1) {
                    if (b * i + (b + 1) * j + (b + 2) * k + (b + 3) * l > w) break;
                    chmax(mx, u[0][i] + u[1][j] + u[2][k] + u[3][l]);
                }
            }
        }
    }

    cout << mx << endl;
}


Measured memory_bytes: 256
from heapq import heappush,heappop
import sys
input=sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
lst=[]
for i in range(N):
    heappush(lst,(-B[i],i))

count=0
while lst:
    h,i=heappop(lst)
    h=-h
    x,z=B[i-1],B[(i+1)%N]
    kkk=x+z
    if (h-A[i])%kkk==0:
        count+=(h-A[i])//kkk
        B[i]=A[i]
        continue
    elif kkk>=h:
        print(-1)
        sys.exit()
    else:
        count+=h//kkk
        h=h%kkk
        B[i]=h    
        if A[i]>h:
            print(-1)
            sys.exit()
        heappush(lst,(-h,i))

if A==B:
    print(count)
else:
    print(-1)

Measured memory_bytes: 122828
h,w,n = map(int, input().split())
sr,sc = map(int, input().split())
s = input()
t = input()
now = [sc,sc,sr,sr]
ans = "YES"
for i,j in zip(s,t):
  if i == "L":
    now[0] -= 1
    if now[0] <= 0:
      ans = "NO"
      break
  elif i == "R":
    now[1] += 1
    if now[1] > w:
      ans = "NO"
      break
  elif i == "U":
    now[2] -= 1
    if now[2] <= 0:
      ans = "NO"
      break
  else:
    now[3] += 1
    if now[3] > h:
      ans = "NO"
      break
  if j == "L":
    now[1] = max(1,now[1]-1)
  elif j == "R":
    now[0] = min(w,now[0]+1)
  elif j == "U":
    now[3] = max(1,now[3]-1)
  else:
    now[2] = min(h,now[2]+1)
print(ans)
   


Measured memory_bytes: 48460
(defun splitat (c line)
  (labels ((rec (line acc)
				(let ((pos (position-if (lambda(cc) (char= c cc)) line)))
				  (if pos
					  (rec (subseq line (1+ pos)) (cons (subseq line 0 pos) acc))
					(nreverse (cons line acc))))))
	(rec line nil)))
(defun f(a b)
  (if (and (< a 10)
           (> a 0)
           (< b 10)
           (> b 0))
    (* a b)
    -1))
(let* ((line (read-line nil nil))
       (splited (mapcar #'parse-integer (splitat #\space line))))
  (format t "~A" (f (car splited) (cadr splited))))


Measured memory_bytes: 13032
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int A, B, M;
    scanf("%d%d%d", &A, &B, &M);
    int a[A], b[B], x[M], y[M], c[M];
    rep(i, A) scanf("%d", &a[i]);
    rep(i, B) scanf("%d", &b[i]);
    rep(i, M) scanf("%d%d%d", &x[i], &y[i], &c[i]);
    int ans = *min_element(a, a+A) + *min_element(b, b+B);
    rep(i, M){
        chmin(ans, a[x[i]-1] + b[y[i]-1] - c[i]);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define rof(i,a,b) for(int (i)=(a);(i) > (b); --(i))
#define pb push_back
#define pr pair<int,int>
#define mp make_pair
#define ll long long int
const int mod=1e9+7;
int main(){
  int n,m;
  cin>>n>>m;
  int a[m];
  int sum=0;
  for(int i=0;i<m;i++){cin>>a[i];sum+=a[i];}
  if(sum<=n)cout<<n-sum<<endl;
  else cout<<"-1"<<endl;
}


Measured memory_bytes: 3628
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let n = read::<usize>();

    let mut vs = vec![0f64; n];
    for _ in 0..n {
        let v = read_vec::<String>();
        if v[1] == "JPY" {
            vs.push(v[0].parse::<f64>().unwrap());
        } else {
            vs.push(v[0].parse::<f64>().unwrap() * 380000.0);
        }
    }
    let ans = vs.iter().sum::<f64>();
    println!("{}", ans);
}


Measured memory_bytes: 4352
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    h,n=parseMap(split(readline()))
    a=parseMap(split(readline()))
    if sum(a)>=h
        println("Yes")
    else
        println("No")
    end
end
main()

Measured memory_bytes: 115076
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define debug(x)  cerr << #x << " = " << x << endl
#define pb push_back
#define F first
#define S second
#define OK order_of_key
#define FO find_by_order
#define PI 3.14159265
#define nmax 100100
const ll inf = std::numeric_limits<ll>::max();
const int infint = std::numeric_limits<int>::max();
const ll mod = 1e9+7;
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(a,b) << ' ' << -min(0,n-a-b);

    return 0;
}



Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
#define rep0(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)

#define shosu setprecision(10)

typedef long long ll;
ll longinf=1ll<<60;
int inf=1<<29;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};



int N,M;
int ans;
bool c[9][9];


int main(){
    cin>>N>>M;
    rep0(i,M){
        int a,b;
        cin>>a>>b;
        c[a-1][b-1]=c[b-1][a-1]=true;
    }
    vector<int> v;
    rep1(i,N-1){
        v.push_back(i);
    }
    do{
        bool ok=true;
        if(!c[0][v[0]])ok=false;
        rep0(i,N-2){
            if(!c[v[i]][v[i+1]]) ok=false;
        }
        if(ok) ans++;

    }while(next_permutation(v.begin(),v.end()));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int n;
long long MIN;
int a[200005];
long long sum[200005];
int main()
{
	MIN = (long long)1 << 60;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]), sum[i] = sum[i - 1] + a[i];
	for(int i = 1; i <= n - 1; i++)
	{
		long long t = sum[n] - sum[i];
		MIN = min(MIN, abs(t - sum[i]));
	}
	printf("%d\n", MIN);
	return 0;
}

Measured memory_bytes: 2560
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;



int main() {
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    ll mi = min({a, b, c, d, e});
    cout << 4+(n+mi-1)/mi << endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())

xs = []
for n in range(N):
    A,B=map(int,input().split())
    xs.append( (A,B))

m = 0
c = 0
for a,b in sorted(xs,key=lambda x:x[0]):
    if m+b <= M:
        m+=b
        c+=a*b
    else:
        #print('b', M-m)
        c+=a*(M-m)
        m+=M-m
        break
print(c)



Measured memory_bytes: 18932
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define forr(i, n) for(int i = 0;i < (int)n; i++)
#define deb(x) cout<<#x<<" " <<x<<"\n";
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define mp make_pair
#define test int tests;cin >> tests;while(tests--)
#define endl "\n"
const int INF = 2e9;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int arr[5];
	int ans = -1;
	forr(i,5) {
		cin>>arr[i];
		if(arr[i]==0) ans = i+1;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3648
local mmi, mma = math.min, math.max
local n = io.read("*n", "*l")
local s = io.read()
local sa = {}
for i = 1, n do
  table.insert(sa, {i, s:sub(i, n)})
end
table.sort(sa, function(x, y) return x[2] < y[2] end)
local lcpa = {}
for i = 1, n do
  lcpa[i] = {}
  for j = 1, n do
    lcpa[i][j] = 0
  end
end
for i = 1, n - 1 do
  local len = mmi(#sa[i][2], #sa[i + 1][2])
  local c = 0
  for j = 1, len do
    if sa[i][2]:sub(j, j) == sa[i + 1][2]:sub(j, j) then
      c = c + 1
    else break end
  end
  local i1, i2 = sa[i][1], sa[i + 1][1]
  lcpa[i1][i2], lcpa[i2][i1] = c, c
end
for i = 1, n - 2 do
  local prv = lcpa[sa[i][1]][sa[i + 1][1]]
  if 0 < prv then
    for j = i + 1, n - 1 do
      local nxt = lcpa[sa[j][1]][sa[j + 1][1]]
      if nxt == 0 then
        break
      else
        prv = mmi(prv, nxt)
        lcpa[sa[i][1]][sa[j + 1][1]], lcpa[sa[j + 1][1]][sa[i][1]] = prv, prv
      end
    end
  end
end
local ret = 0
for i = 1, n - 1 do
  for j = i + 1, n do
    ret = mma(ret, mmi(lcpa[i][j], j - i))
  end
end
print(ret)


Measured memory_bytes: 337024
t = input()
cnt = 0
ans = []
for i in range(len(t)-1):

    a,b,c = t[i],t[i-1],t[i+1]
    if a == "?" and c == "P":
        ans.append("D")
    elif a == "?" and b == "D":
        ans.append("P")
    elif a == "?":
        ans.append("D")
    else: ans.append(a)
if (t[-1] == "?") :ans.append("D")
else: ans.append(t[-1])

print(*ans,sep="")

Measured memory_bytes: 13884
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	map<char, ll>map;

	string m = "MARCH";
	int n;
	cin >> n;
	

	cout << n/3 << endl;
	
	return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define rep(i,N) for(int i=0;i<N;i++)

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

  int H,N;
  cin>>H>>N;
  int a=0;
  rep(i,N){
    int A;
    cin>>A;
    a+=A;
  }
  if(a<H)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = pow(10, 7);
const ll LINF = (ll)pow(10, 19);
struct edge{int from, to, cost;};
int main(){
  int n, m;cin>>n>>m;
  vector<edge> es(m);
  for(int i=0;i<m;i++){
    int a, b, c;cin>>a>>b>>c;a--;b--;
    es[i].from=a;
    es[i].to=b;
    es[i].cost=c;
  }
  vector<ll> d(n, -(ll)LINF);
  d[0]=(ll)0;
  for(int t=0;t<n;t++){
    for(int i=0;i<m;i++){
      edge tmp = es[i];
      if(d[tmp.from]!=-(ll)LINF && d[tmp.to] < d[tmp.from] + (ll)tmp.cost){
        // printf("%d %lld->%lld\n", tmp.to, d[tmp.to], d[tmp.from] + (ll)tmp.cost);
        d[tmp.to] = d[tmp.from] + (ll)tmp.cost;
      }
    }
  }
  vector<bool> negative(n, false);
  for(int t=0;t<=n;t++){
    for(int i=0;i<m;i++){
      edge tmp = es[i];
      if(d[tmp.from]!=-(ll)LINF && d[tmp.to] < d[tmp.from] + (ll)tmp.cost){
        // printf("%d %lld->%lld\n", tmp.to, d[tmp.to], d[tmp.from] + (ll)tmp.cost);
        d[tmp.to] = d[tmp.from] + (ll)tmp.cost;
        negative[tmp.to]=true;
      }
      if(negative[tmp.from])negative[tmp.to]=true;
    }
  }
  if(negative[n-1])cout<<"inf"<<endl;
  else cout<<d[n-1]<<endl;
}


Measured memory_bytes: 256
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let a: Vec<isize> = (0..n)
        .map(|_| iterator.next().unwrap().parse().unwrap())
        .collect();

    let mut b: Vec<isize> = vec![0; n];
    b[0] = a[0];
    for i in 1..n {
        b[i] = b[i - 1] + a[i];
    }

    let mut c: Vec<isize> = vec![0; n];
    c[n - 1] = a[n - 1];
    for i in (0..(n - 1)).rev() {
        c[i] = c[i + 1] + a[i];
    }

    let mut ans: isize = std::isize::MAX;
    for i in 0..(n - 1) {
        let x = b[i];
        let y = c[i + 1];
        let d = if x > y { x - y } else { y - x };
        ans = min(ans, d);
    }
    return ans.to_string();
}


Measured memory_bytes: 12540
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define modd               1e9+7
#define ff                 first
#define ss                 second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define rep(i,l,r)         for(int i=l;i<r;i++)
#define rer(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
using namespace std;
int32_t main(){

	
    int a,b,c;
    cin >> a >> b >> c;
	if(a+b+c>=22){
		cout << "bust\n";
	}    
	else
		cout << "win\n";
    return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <cstring>
typedef long long ll;
template <class T>
void r(T &x)
{
    #define gc getchar()
    x = 0;
    char c = gc;
    int f = 1;
    while (!isdigit(c)) {if (c == '-') f = -1;c = gc;}
    while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = gc;
    x *= f;
    #undef gc
}
template <class T>
void p(T x)
{
    if (x < 0)
        putchar ('-'), x = (~x) + 1;
    if (x > 9)
        p(x / 10);
    putchar ((x % 10) ^ 48);
}
template <class T>
T Max(T a, T b)
{
    return a > b ? a : b;
}
template <class T>
T Min(T a, T b)
{
    return a < b ? a : b;
}
char a[305];
int k;
int main() 
{
    scanf ("%s %d", a, &k);
    int len = strlen(a);
    ll ans = 0;
    int h, t;
    for (int i = 0, j;i < len; i = j)
    {
        for (j = i;j < len; j++)
            if (a[j] != a[i])
                break;
        ans += (j - i) >> 1;
        if (!i)
            h = j - i;
        if (j == len)
            t = j - i;
    }
    if (t == len && t == len)
        ans = 1ll * k * len >> 1;
    else
    {
        ans = ans * k;
        if (a[0] == a[len - 1] && h / 2 + t / 2 < (h + t) / 2)
            ans += k - 1;
    }
    p(ans);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
	char a[40],b[10];
	int c,d;
	gets(a);
	scanf("%d %d",&c,&d);
	getchar();
	gets(b);
	if(b[0]==a[0]){
		printf("%d %d",c-1,d);
	}
	else {
		printf("%d %d",c,d-1);
	}
	
	return 0;
} 

Measured memory_bytes: 128
#include<stdio.h>
#define rep(i,n) for(i=0;i<n;i++)
#define For(i,a,n) for(i=a;i<n;i++)
int i;

int main(){
  int  n;
  scanf("%d",&n);
  double  a[n];
  rep(i,n){
    scanf("%lf",&a[i]);
  }
  double s;
  s=0;
  rep(i,n){
    s=s+(1/a[i]);
  }
  s=1/s;
  printf("%f\n",s);
  return 0;
}



Measured memory_bytes: 128
s = input()

n = int(s.split()[0])
m = int(s.split()[1])

inp = [input().split() for _ in range(n)]

count = 0
for i in range(1,m+1):
    flg = True
    for like in inp:
        if str(i) not in like[1:]:
            flg = False
            break
    if flg:
        count += 1

print(count)


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;


int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, m;
	cin >> n >> m;
	priority_queue<int> q;
	for (int i = 0; i < n; i++)
	{
		int cur;
		cin >> cur;
		q.push(cur);
	}
	for (int i = 0; i < m; i++)
	{
		int cur = q.top();
		q.pop();
		cur /= 2;
		q.push(cur);
	}
	long long res = 0;
	while (!q.empty())
	{
		res += q.top();
		q.pop();
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
typedef long long LL;
int main() {
	int n = 0, m = 0,ans = 0;
	int problems[100] = {}, drinks[100][2] = {};
	int memory_problems[100] = {};
	std::cin >> n;
	for (int i = 0; i < n; i++) { std::cin >> problems[i]; memory_problems[i] = problems[i]; }
	std::cin >> m;
	for (int i = 0; i < m; i++) { std::cin >> drinks[i][0]; std::cin >> drinks[i][1]; }
	for (int i = 0; i < m; i++) {
		problems[drinks[i][0]-1] = drinks[i][1];
		for (int j = 0; j < n; j++) {
			ans += problems[j];
		}
		std::cout << ans;
		std::cout << std::endl;
		ans = 0;
		problems[drinks[i][0]-1] = memory_problems[drinks[i][0]-1];
	}
}

Measured memory_bytes: 256
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    A,B,M = map(int, input().split())
    v1 =list(map(int, input().split())) 
    v2 =list(map(int, input().split())) 
    res = INF
    for i in range(M):
        X,Y,C = map(int, input().split())
        res = min(res,v1[X-1] + v2[Y-1] - C)

    res = min(res,min(v1) + min(v2))
    res = max(0,res)
    print(res)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 19508
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int main()
{
    int N;
    cin >> N;
    vector<int> h(N);
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }
    int cnt = 0, ans = 0;;
    rep(i, N-1){
        if(h[i] >= h[i+1]){
            cnt++;
        }
        else{
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  //2, 5
  ll len = 100;
  vector<vector<ll>> dp(len, vector<ll>(len, 0));
  vector<pll> pos;
  for (ll i = 0; i < N; ++i) {
    string a;
    cin >> a;
    bool f = false;
    string temp;
    ll cnt = 0;
    for (ll j = 0; j < a.size(); ++j) {
      if (a.at(j) == '.') {
        f = true;
        cnt = a.size() - j - 1;
        break;
      }
    }
    for (ll i = 0; i < 9 - cnt; ++i) {
      a += '0';
    }
    string temp_a;
    for (ll i = 0; i < a.size(); ++i) {
      if (a.at(i) != '.') {
        temp_a += a.at(i);
      }
    }
    a = temp_a;
    ll num_a = (stoll)(a);
    ll two = 0, five = 0;
    while (num_a % 2 == 0) {
      two += 1;
      num_a /= 2;
    }
    while (num_a % 5 == 0) {
      five += 1;
      num_a /= 5;
    }
    dp.at(two).at(five) += 1;
    pos.push_back({two, five});
  }
  for (ll i = len - 1; i >= 0; --i) {
    for (ll j = len - 1; j >= 0; --j) {
      if (i != 0) {
        dp.at(i - 1).at(j) += dp.at(i).at(j);
      }
    }
  }
  for (ll i = len - 1; i >= 0; --i) {
    for (ll j = len - 1; j >= 0; --j) {
      if (j != 0) {
        dp.at(i).at(j - 1) += dp.at(i).at(j);
      }
    }
  }
  // for (ll i = 0; i < len; ++i) {
  //   for (ll j = 0; j < len; ++j) {
  //     cout << dp.at(i).at(j) << " ";
  //   }
  //   cout << "\n";
  // }
  ll ans = 0;
  for (ll i = 0; i < pos.size(); ++i) {
    ll t = pos.at(i).first, f = pos.at(i).second;
    ll nt = max(0ll, 18 - t);
    ll nf = max(0ll, 18 - f);
    // cout << t << ' ' << f << "\n";
    if (t >= nt && f >= nf) {
      ans -= 1;
    }
    ans += dp.at(nt).at(nf);
    // cout << dp.at(nt).at(nf) << "\n";
  }
  ans /= 2;
  cout << ans << "\n";
}


Measured memory_bytes: 7440
//
#include"bits/stdc++.h"

// NOTE TO SELF // try to simplyfy the problem

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

#define ll long long int

//const int mod=1000000007;

using namespace std;


//const ll INF= 1e18L+5 ;

int main()
{

    string s,t;
    cin>>s>>t;
    
    int n=(int)s.size();
    int m=(int)t.size();
    
    
    int dp[n+1][m+1];
    
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(i==0||j==0)
                dp[i][j]=0;
            
            else if(s[i-1]==t[j-1])
            {
                dp[i][j]= 1+dp[i-1][j-1];
            }
            
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            
            
            
        }
        
        
    }

    string ans="";
    
    
        // Start from the right-most-bottom-most corner and
        // one by one store characters in lcs[]
        int i = n, j = m;
        while (i > 0 && j > 0)
        {
           // If current character in X[] and Y are same, then
           // current character is part of LCS
           if (s[i-1] == t[j-1])
           {
                ans+=s[i-1]; // Put current character in result
               i--; j--; // reduce values of i, j and index
           }
       
           // If not same, then find the larger of two and
           // go in the direction of larger value
           else if (dp[i-1][j] > dp[i][j-1])
              i--;
           else
              j--;
        }
    
    
    reverse(ans.begin(), ans.end());
    
    cout<<ans<<endl;
    
    
       return 0;

}


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

int main(){
   long long int N;
   cin >> N;
   double sqrtN;
   sqrtN = sqrt(N);
   long long int min = N-1;
   for (int i=1; i<ceil(sqrtN)+1; i++){
      if (N % i == 0){
         long long int m = N/i;
         long long int temp = m + i - 2;
         if (temp < min){
            min = temp;
         }
      } else{
         continue;
      }
   }
   cout << min << endl;

}



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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > Matrix;



int main() {
	int n, i, j, k;
	vi d, x;

	cin >> n;
	SIZE(d, n);
	j = 0;
	rep(i, n) {
		cin >> d[i];
		j = max(j, d[i]);
	}
	SIZE(x, j + 1);
	rep(i, n) {
		x[d[i]]++;
	}
	repj(i, 1, j+1) {
		x[i] += x[i - 1];
	}
	k = 0;
	rep(i, j) {
		if (x[j] / 2 == x[i])k++;
		if (x[j] / 2 < x[i])break;
	}

	cout << k;

	return 0;
}


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

using namespace std;

typedef long long ll;
const int maxn = 5005;
const ll mul1 = 1e9 + 7;
const ll mul2 = 1e9 + 9;
const ll mod = 19260817;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}
char s[maxn];
ll Hash1[maxn], Hash2[maxn];
ll power1[maxn], power2[maxn];
int n;

inline bool check(reg int len, reg int x, reg int y) {
    reg ll tmp1 = ((Hash1[x + len - 1] - Hash1[x - 1] * power1[len] % mod + mod) % mod) % mod;
    reg ll tmp2 = (Hash1[y + len - 1] - Hash1[y - 1] * power1[len] % mod + mod) % mod;
    reg ll tmp3 = ((Hash2[x + len - 1] - Hash2[x - 1] * power2[len] % mod + mod) % mod) % mod;
    reg ll tmp4 = (Hash2[y + len - 1] - Hash2[y - 1] * power2[len] % mod + mod) % mod;
    if (tmp1 == tmp2 && tmp3 == tmp4) return true;
    return false;
}

int main() {
    power1[0] = 1; for (reg int i = 1; i <= 5000; i++) power1[i] = power1[i - 1] * mul1 % mod;
    power2[0] = 1; for (reg int i = 1; i <= 5000; i++) power2[i] = power2[i - 1] * mul2 % mod;
    n = read();
    scanf("%s", s + 1);
    for (reg int i = 1; i <= n; i++) {
        Hash1[i] = (Hash1[i - 1] * mul1 % mod + s[i]) % mod;
        Hash2[i] = (Hash2[i - 1] * mul2 % mod + s[i]) % mod;
    }
    reg int Ans = 0;
    for (reg int i = 1; i <= n; i++) {
        for (reg int j = i + 1; j <= n; j++) {
            reg int len = j - i;
            reg int l = 1, r = len;
            reg int res = 0;
            while (l <= r) {
                reg int mid = (l + r) >> 1;
                if (j + mid - 1 > n) { r = mid - 1; continue; }
                if (check(mid, i, j)) l = mid + 1, res = mid;
                else r = mid - 1;
            }
            Ans = max(Ans, res);
        }
    }
    printf("%d\n", Ans);
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200005;
const ll p=998244353ll;
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
struct qwq{
	int a,b;
	qwq(){}
	qwq(int a,int b):a(a),b(b){}
	inline bool operator<(const qwq &a)const{return b>a.b;}
}a[N];
int main(){
	int n,i,t=1000000000;
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d%d",&a[i].a,&a[i].b);
	sort(a+1,a+n+1);
	for(i=1;i<=n;++i)t=min(a[i].b,t)-a[i].a;
	if(t<0)puts("No");else puts("Yes");
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); 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; }

string S;
char now;
int cnt;

int main(){
    cin>>S;
    now=S[0];
    repi(i,1,S.length()){
        if(S[i]!=now){
            cnt++;
            now=S[i];
        } 
    }
    out(cnt);
}


Measured memory_bytes: 512
package main

import "fmt"

var s string

func main() {
	fmt.Scan(&s)
	n := len(s)
	rs := []rune(s)
	if ispar(rs) && ispar(rs[:(n-1)/2]) && ispar(rs[(n+3)/2-1:]) {
		fmt.Println("Yes")
	} else {

		fmt.Println("No")
	}
}

func ispar(rs []rune) bool {
	n := len(rs)
	for i := 0; i < n; i++ {
		if rs[i] != rs[n-i-1] {
			return false
		}
	}
	return true
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0;
  string s;
  std::cin >> x>>s;
  rep(i,x){
    if(s[i]=='R')y++;
  }
  std::cout << (((x)/2<y)?"Yes":"No") << '\n';
}


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

#define rep(i,n) for(ll i=0;i<(ll)n;++i)
#define rep1(i,n) for(ll i=1;i<=(ll)n;++i)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  string s, t;
  cin >> s >> t;
  
  
  cout << t << s << endl;
}



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


int main()
{
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i, n)
    cin >> a[i];
  sort(a.begin(), a.end());
  int ans = k - *(a.end() - 1) + a[0];
  for (int i=1; i<n; i++)
    ans = max(ans, a[i] - a[i-1]);
  cout << k - ans << endl;
}

Measured memory_bytes: 1152