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


#define ALL(a) 		(a.begin() , a.end())
#define ll 			long long int
#define ff          first
#define ss          second
#define pb          push_back
#define ar 			array
#define mp 			make_pair
#define f(i,a,b)   	for(ll i =a;i<=b;i++)
#define inf 		INT_MAX
#define pll 		pair<ll,ll>
#define mat 		vector<vector<ll>>


#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 //debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }


 

const ll INF = 1e18;
void init(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE 
		freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#endif
}
 
bool checkp2(ll n){
	return n && !(n & (n-1));
}

ll numsetbit(ll n){
	ll count = 0;
	for(;n;count++){
		n = n & (n-1);
	}
	return count;
}
 
ll powe(ll x , ll n ,const ll mod){
    x = x % mod;
	ll po = 1;
	while(n){
		if(n & 1){
			po = (po*x) % mod;
		}
		n = n>>1;
		x = ((x % mod) * (x % mod)) % mod;
	}
	return po;
}

ll powm(ll x , ll n){
	ll po = 1;
	while(n){
		if(n & 1){
			po = (po*x);
		}
		n = n>>1;
		x = (x*x);
	}
	return po;
} 



bool isPrime(ll x){
	if(x < 2)
		return 0;
	for(ll y = 2; y * y <= x; y++){
		if(x % y == 0){
			return 0;
		}
	}
	return true;
}
const ll  mod = 1e9 + 7;
void solve(){


	ll s;
	cin>>s;

	vector<ll> dp(s+10 , 0);
	dp[0] = 1;
		
	for(ll i = 1;i<=s;i++){
		for(ll j = 3;j <= i;j++){
			dp[i] += dp[i-j];
			dp[i] %= mod;
		}
	}

	cout<<dp[s]<<endl;



		
}

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

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

#define int long long 

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 
#define pb push_back

const int maxn = 1e5+10;
const int inf = 1e9;
const lf eps = 1e-8;

int n;

vector<int > s,t;

signed main() {
    read(n);int p=101;n++;
    while(n>1) {if(n&1) t.pb(--p),n--;else s.pb(--p),n>>=1;}
    int m=s.size()+t.size();printf("%lld\n",m<<1);
    for(int i=0;i<(int)t.size();i++) printf("%lld ",t[i]);
    for(int i=s.size()-1;~i;i--) printf("%lld ",s[i]);
    for(int i=100-m+1;i<=100;i++) printf("%lld ",i);
    return 0;
}


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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll a, b, r;
	cin >> a >> b;
	r = (a + b) >> 1;
	bool s = (abs(a-r) == abs(b-r));
	if (s) cout << r << "\n";
	else cout << "IMPOSSIBLE\n";
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define IREP(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define IMAX INT_MAX
#define IMIN INT_MIN
#define LMAX LLONG_MAX
#define LMIN LLONG_MIN
template<typename T> inline void chmin(T &a, T b){ if(a > b) a = b; }
template<typename T> inline void chmax(T &a, T b){ if(a < b) a = b; }
template<typename T> inline void xch(T &a, T &b){ T w = a; a = b; b = w; }


int main() {
    int K;
    cin >> K;
    string S;
    cin >> S;
    if(S.length() <= K){
        cout << S << endl;
    }
    else{
        REP(i, K){
            cout << S[i];
        }
        cout << "..." << endl;
    }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int r,c,n,x,y,ans[200][200];
int main(void)
{
    scanf("%d%d%d",&r,&c,&n);
    x=1,y=1;
    for(int i=1,cnt;i<=n;i++)
    {
        scanf("%d",&cnt);
        while(cnt--)
        {
            ans[x][y]=i;
            if(y==c&&x%2==1)
                y=c,x++;
            else if(y==1&&x%2==0)
                y=1,x++;
            else if(x&1)
                y++;
            else
                y--;
        }
    }
    for(int i=1;i<=r;i++)
    for(int j=1;j<=c;j++)
        printf("%d%c",ans[i][j],j==c?'\n':' ');
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


int n, k, x[101010];

int main(){
	cin >> n >> k;
	int mainas = 0, zero = 0;
	for(int i = 0; i < n; i++){
		cin >> x[i];
		if(x[i] < 0) mainas++;
		if(x[i] == 0) zero = 1;
	}
	
	int cnt = INF;
	for(int i = 0; i < n; i++){
		if(i < mainas && k > mainas-i + n-mainas) continue;
		if(i >= mainas && k > i+1) continue;
		cnt = min(cnt, abs(x[i]) + (mainas <= i ? (i-mainas+1 >= k ? 0 : abs(x[i]) + abs(x[i-k+1])) :(mainas - i >= k ? 0 : abs(x[i]) + x[i+k-1])));
	}
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll A,B;
ll gcd(ll a,ll b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int main(){
    cin >> A >> B;
    ll u = gcd(A,B);
    vector<ll> V(1000);
    ll j = 0;
    for(ll i=2;i*i<=u;i++){
        if(u%i==0){
            V[j]= i;
            j++;
            while(u%i==0){
                u/=i;
            }
        }
    }
    if(u!=1){
        V[j] = u;
        j++;
    }
    cout << j+1 << endl;

    return 0;

}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
a = []
b = [int(s) for s in input().split()]
for i in range(n):
    a.append([int(s) for s in input().split()])

count = 0
for i in range(n):
    score = 0
    for j in range(m):
        score += a[i][j] * b[j]
    if score + c > 0:
        count += 1
print(count)

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

int main() {
	int a, b, c;
	cin >> a >> b >>c;
	if (a!=b and b!=c and c!=a) cout << 3 << endl;
	else{
		if (a==b and b==c and c==a)	cout << 1 << endl;
		else cout << 2 << endl;
	} 
	
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#define FORi(N) for(int i=0;i<N;++i)
using namespace std;
using ll = long long;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
int main(){
  ll N,K;
  cin>>N>>K;
  ll ans;
  if((N-1)%(K-1)==0){
    ans=(N-1)/(K-1);
  }else{
    ans =(N-1)/(K-1)+1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
a,b=gets,gets
c,d=a.size,b.size
dp=Array.new(c){Array.new(d,0)}
c.times{|i|dp[i][0]=i}
d.times{|i|dp[0][i]=i}
(c-1).times {|i|
	(d-1).times{|j|
		dp[i+1][j+1]=(a[i]==b[j]?dp[i][j]:[dp[i][j],dp[i+1][j],dp[i][j+1]].min+1)
	}
}
puts dp[c-1][d-1]

Measured memory_bytes: 16656
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef unsigned __int128 ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

ll a[26];
ll hs[2][4444];

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	random_device rd;
	mt19937_64 eng(rd());
	uniform_int_distribution<unsigned long long> distr;
	REP(i, 26) 
    {
        a[i] = ll(distr(eng) * distr(eng));
    }
	string s, t; cin >> s >> t;
	int n = s.size(), m = t.size();

	hs[0][0] = hs[1][0] = 0;
	REP(i, n)
	{
		hs[0][i + 1] = hs[0][i] + a[s[i] - 'a'];
	}
	REP(i, m)
	{
		hs[1][i + 1] = hs[1][i] + a[t[i] - 'a'];
	}

	for (int i = min(n, m); i >= 0; i--)
	{
		set<ll> st;
		REP(j, n - i + 1)
		{
			ll t = hs[0][j + i] - hs[0][j];
			st.insert(t);
		}
		REP(j, m - i + 1)
		{
			ll t = hs[1][j + i] - hs[1][j];
			if (st.count(t))
			{
				cout << i << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
const int maxn=110000;
long long a[maxn];
const int INF=1<<30;
int n;
long long l;
long long q;
int f[maxn][35]={};
inline void init()
{
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
    scanf("%d",a+i);
  scanf("%d%d",&l,&q);
  for(int i=1;i<=n;i++)
  {
    int x=(int)(upper_bound(a+1,a+n+1,a[i]+l)-a-1);
    f[i][0]=x;
  }
  for(int j=1;j<=30;j++)
  {
    for(int i=1;i<=n;i++)
      f[i][j]=f[f[i][j-1]][j-1];
  }
}
inline void work_()
{
  while(q--)
  {
    long long a,b;
    scanf("%lld %lld",&a,&b);
    if(a>b)
      swap(a,b);
    int ans=0;
    int cur=a;
    for(int i=30;i>=0;i--)
    {
	  if(f[cur][i]<b)
	  {
	    ans+=1<<i;
	    cur=f[cur][i];
	  }
	}
	printf("%d\n",ans+1);
  }
}
int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	init();
	work_();
	return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
char num[2][200005];string c;string ans;
int main(){
//	for(int i=1;i<=200004;i++){
//	num[0][i]=0;num[1][i]=0;
//}
	int p=0,q=0,s=0,m=0,n=0;
	int head=0;
	int x,y;
	char tmp;
	cin>>c;
	scanf("%d",&x);
	for(int i=1;i<=x;i++){
		scanf("%d",&m);
		if(m==1){
			head=1-head;//y=p;p=q;q=y;
		}else{
			scanf("%d",&n);
			if(n==1){
				cin>>tmp;
				if(head==0){p++;num[0][p]=tmp;}else{ q++;num[1][q]=tmp;}
			}else{
				cin>>tmp;
				if(head==0){q++;num[1][q]=tmp;}else{ p++;num[0][p]=tmp;}
			}
		}
	}
	if(head==0){for(int i=1;i<=p;i++)ans=ans+num[0][p+1-i];}else{for(int i=1;i<=q;i++)ans=ans+num[1][q+1-i];}
	if(head==1){
		for(int j=0;j<c.length()/2;j++)swap(c[j],c[c.length()-j-1]);
	}
	ans=ans+c;
	if(head==0){for(int i=1;i<=q;i++)ans=ans+num[1][i];}else{for(int i=1;i<=p;i++)ans=ans+num[0][i];}
	cout<<ans;
}


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

int main(){
    int N;
    cin >> N;
    vector<float> vec(N);
    for(int i = 0; i < N; i++) cin >> vec.at(i);
    sort(vec.begin(),vec.end());

    float sum = 0;

    for (int i = 0; i < N; i++){
        if (i == 0){
            sum += (vec.at(0) + vec.at(1)) / 2;
            continue;
        }
        if (i == 1){
            continue;
        }
        sum = (sum + vec.at(i)) / 2;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define ull unsigned long long

using namespace std;

inline ll in()
{
	ll Req = 0, wX = 0; char ch;
	while (!isdigit(ch)) {wX |= (ch == '-'); ch = getchar();}
	while (isdigit(ch)) {Req = (Req << 3) + (Req << 1) + (ch ^ 48); ch = getchar();}
	return wX ? -Req : Req;
}

inline void out(ll x)
{
	register short Pxn[20], Ry = 0;
	if (x == 0) putchar('0');
	if (x < 0) putchar('-'), x = -x;
	while (x != 0) Pxn[Ry] = x % 10, x /= 10, Ry++;
	for (int i = Ry - 1; i >= 0; i--) putchar(Pxn[i] + '0');
}

int main()
{

	int a = in(), b = in();
	if (a + b == 15) puts("+");
	else if (a * b == 15) puts("*");
	else puts("x");

  return 0;

}



Measured memory_bytes: 256
N,Q = gets.chomp.split.map(&:to_i)

ne = Array.new(N+1) { Array.new }

(N-1).times do
  a,b = gets.chomp.split.map(&:to_i)
  ne[a].push(b)
  ne[b].push(a)
end

ans = Array.new(N+1, 0)
Q.times do
  p,x = gets.chomp.split.map(&:to_i)
  ans[p] += x
end

stack = [[1,-1]]
while !stack.empty?
  t,f = stack.pop
  ne[t].each do |tt|
    next if tt==f
    ans[tt] += ans[t]
    stack.push([tt,t])
  end
end

ans.shift
puts ans.join(' ')


Measured memory_bytes: 45036
from heapq import heappush,heappop
import queue
import re
import math
import functools


def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

def make1d_arr(n,val=INF):
    return [val for i in range(n)]

def make2d_arr(h,w,val =INF):
    return [[val for i in range(w)]for i in range(h)]

def gcd (a,b):
    if(b==0):
        return a
    return gcd(b,a%b)


N = int_raw()
As =[]
for _ in range(N):
    As.append(int_raw())
SUM = sum(As)

DIV = 998244353

ALL = 1
for _ in range(N):
    ALL = (ALL*3)%DIV

def main():
    dp1 = [0]*(SUM+1)
    dp3 = [0]*(SUM+1)
    dp1[0]=1
    dp3[0]=1
    
    for n in range(N):
        a = As[n]
        dp1 = [(dp1[s]+(dp1[s-a] if s>=a else 0))%DIV for s in range(SUM+1)]
        dp3 = [(dp3[s]*2 + (dp3[s-a] if s>=a else 0))%DIV for s in range(SUM+1)]

    S3 = (sum(dp3[(SUM+1)//2:])*3)%DIV
    S1 = (dp1[(SUM)//2]*3)%DIV if SUM%2==0 else 0
    return (ALL - S3 + S1 + DIV) % DIV

print(main())


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

int main(){
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    vector<int> water, sugar;
    for(int i=0; i<=(f/(100 * a)); i++){// type A
        for(int j=0; j<=((f - 100 * a * i)/(100 * b)); j++){// type B
            water.push_back(a * i + b * j);
        }
    }
    int max_sugar = f * e / (100 + e);
    for(int i=0; i<=(max_sugar / c); i++){// type C
        for(int j=0; j<=((max_sugar - c * i) / d); j++){// type D
            sugar.push_back(c * i + d * j);
        }
    }
    sort(water.begin(),water.end());
    sort(sugar.begin(),sugar.end());

    //cout << "sugar : ";
    //for(auto s : sugar) cout << s << " ";
    //cout << endl;

    vector<int> ans = {1, 0};// (water, sugar)
    for(int i=1; i<water.size();i++){
        if(water[i] == water[i-1]) continue;
        //cout << water[i] * 100 << endl;

        int s = sugar[upper_bound(sugar.begin(),sugar.end(),min(e * water[i], f - 100 * water[i])) - sugar.begin() - 1];
        //cout << s << endl;
        if((100 * ans[0]   + ans[1]) * s 
         > (100 * water[i] + s     ) * ans[1]){
            ans[0] = water[i];
            ans[1] = s;
        }
        else if(s == 0 && ans[1] == 0) ans[0] = water[i];
        
        if(ans[0] * e == ans[1]) break;
    }
    cout << ans[0] * 100 + ans[1] << " " << ans[1] << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long a, b = 0, e = 0;
	string s;
	cin >> s;
	for (int h = 0; h < s.size() - 1; h++) {
		if (s[h] != s[h + 1]){
			b++;
		}
	}
	cout << b << endl;
	cin >> e;
}

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

int main(void){
  int A, B, C, D;
  int cnt = 0;
  cin >> A >> B;
  cin >> C >> D;
  for(int i = 0; i < 110; i++){
    if(A <= i && i < B && C <= i && i < D){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

using namespace std;

int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    else
    {
        return gcd(b,a%b);
    }
}

int gcd2(int a,int b,int c)
    {
        int num=gcd(a,b);

        return gcd(num,c);
    }


int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("inputf.in", "r", stdin);
    // freopen("outputf.in", "w", stdout);
    // #endif

    int t;
    cin>>t;
    int i,j,k;
    int arr[t][t][t];
       for(i=0;i<t;i++)
    {
        for(j=0;j<t;j++)
        {
            for(k=0;k<t;k++)
            {
                
                arr[i][j][k]=-1;
                
            }
        }   
    }
    
    long long sum=0; 
    for(i=0;i<t;i++)
    {
        for(j=0;j<t;j++)
        {
            for(k=0;k<t;k++)
            {
                if(arr[i][j][k]<0)
                {
                    arr[i][j][k]=gcd2(i+1,j+1,k+1);
                }
            }
        }   
    }

    for(i=0;i<t;i++)
    {
        for(j=0;j<t;j++)
        {
            for(k=0;k<t;k++)
            {
                
               // cout<<  arr[i][j][k]<<" ";
                sum=sum+(long long)arr[i][j][k];
                
            }
        }   
    }
    cout<<sum;
   // cout<<gcd(2,2);




}

Measured memory_bytes: 34884
#include <iostream>
#include <cstdio>

using namespace std;

int main(){
	int min=1000000;
	int max=-1000000;
	long long sum=0;
	int n;
	int a;
	int i;
	
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a;
		sum +=a;
		if (a<min)
			min = a;
		if(a>max)
			max = a;
	}
	cout<<min<<" "<<max<<" "<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1168
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

ll H, W;

int main() {
    fastio();
    cin >> W >> H;
    vector<ll> P(W), Q(H);
    REP(i, W) cin >> P[i];
    REP(i, H) cin >> Q[i];
    if(W > H) {
        swap(P, Q);
        swap(W, H);
    }
    sort(ALL(P)); sort(ALL(Q));
    vector<ll> S(W+1), T(H+1);
    S[0] = T[0] = 0;
    FOR(i, 1, W) S[i] = S[i-1] + P[i-1];
    FOR(i, 1, H) T[i] = T[i-1] + Q[i-1];
    // priv(P); priv(Q);
    ll ans = S[W] + T[H];
    // cerr << ans << endl;
    REP(i, W) {
        size_t b = upper_bound(ALL(Q), P[i]) - Q.begin();
        ans += (H - b) * P[i] + T[b];
        // cerr << b << " " << (H - b) * P[i] << " " <<  T[b] << endl;
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
#include "bits/stdc++.h"
using namespace std;
typedef unsigned long long ll;
vector<ll > vec;
vector<vector<ll > > vec2;

ll sum(ll a, ll b){
    ll ans = 0;

    for(ll i = a; i <= b; i++){
        ans+=i;
    }

    return ans;
}

int main(){

    string s;
    cin >> s;
    
    for(ll i = 0; i < s.length();){
        ll j = i;
        //一緒の間ループを回し続けて，切れ目を探す
        while(j < s.length() && s[j] == s[i]){
            ++j;
        }
        vec.push_back(j - i);
        //次の始点へすっ飛ばす
        i = j;
    }

    ll ans = 0;

    if(s[0] == '<'){
        if(vec.size() % 2 != 0){
            vec.push_back(1);
        }
        for(ll i = 1; i < vec.size(); i+=2){
            //cout << vec[i] << " " << vec[i-1]  << endl;
            if(vec[i] >= vec[i-1]){
                ll e1 = vec[i];
                ans += sum(0, vec[i-1]-1);            
                ans += sum(0 , e1);
                //cout << sum(s1, e1) <<endl;
                //cout << sum(0, vec[i] - 1) << endl;
            }else{
                ans += sum(0, vec[i-1]);
                ll e2 = vec[i] - 1;
                ans += sum(0, e2);
                //cout << sum(0, vec[i-1]) + sum(0, e1) <<endl;
            }
            //cout << ans << endl;
        }
    }else{
        ans += sum(0, vec[0]);
        if((vec.size()-1) % 2 != 0){
            vec.push_back(1);
        }
        for(ll i = 2; i < vec.size(); i+=2){
            if(vec[i] >= vec[i-1]){
                ll e1 = vec[i];
                //cout << s1 << " " << e1 << endl;
                ans += sum(0, vec[i-1]-1);            
                ans += sum(0 , e1);
                //cout << sum(s1, e1) + sum(0, vec[i] - 1) <<endl;
            }else{
                ans += sum(0, vec[i-1]);
                ll e2 = vec[i] - 1;
                ans += sum(0, e2);
                //cout << sum(0, vec[i-1]) + sum(0, e1) <<endl;
            }
            //cout << ans << endl;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3068
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
S = input()
Q = INT()
q = deque(S)
flg = 1
for _ in range(Q):
	Que = input().split()
	if Que[0] == "1":
		flg *= -1
	else:
		_, F, C = Que
		if any(int(F)*flg == x for x in [2, -1]):
			q.append(C)
		else:
			q.appendleft(C)
if flg == 1:
	print(*q, sep = "")
else:
	print(*list(q)[::-1], sep = "")

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

long long X,Y;long long base=1000000007LL;

long long kaijo(long long a) {
  if (a==0) return 1LL;
  else {
    return a*kaijo(a-1)%base;
  }
}

long long ruijo(long long a,long long b) {
  if (b==0LL) return 1LL;
  else {
    if (b%2==0) return (ruijo(a,b/2)*ruijo(a,b/2))%base;
    else return (a*ruijo(a,b-1))%base;
  }
}

int main() {
  cin >> X >> Y;
  if ((X+Y)%3LL!=0LL || Y>2*X || X>2*Y) cout << 0 << endl;
  else {
    long long k=(X+Y)/3LL;
    long long x=(2*Y-X)/3LL;
    long long y=(2*X-Y)/3LL;
    long long a=(kaijo(x)*kaijo(y))%base;
    cout << (kaijo(k)*ruijo(a,base-2LL))%base << endl;
  }
}

Measured memory_bytes: 10624
using System;

namespace ITP1_7_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string data = Console.ReadLine();
            int r = int.Parse(data.Split(' ')[0]);
            int c = int.Parse(data.Split(' ')[1]);
            int[,] table = new int[r+1, c+1];

            for (int i = 0; i < r; i++)
            {
                string number = Console.ReadLine();
                for (int j = 0; j < c; j++)
                {
                    table[i, j] = int.Parse(number.Split(' ')[j]);  //用意した配列に振り分け
                }
            }
            for (int i = 0; i < r; i++) 
            {
                for (int j = 0; j < c; j++) //横の和
                {
                    table[i, c] += table[i, j];
                }
            }
            for (int j = 0; j < c; j++) 
            {
                for (int i = 0; i < r; i++)  //縦の和
                {
                    table[r, j] += table[i, j];
                }
            }

            for (int i = 0; i < r; i++)
            {
                table[r, c] += table[i, c];
            }

            for (int i = 0; i < r + 1; i++)
            {
                for (int j = 0; j < c + 1; j++)
                {
                    Console.Write("{0}",table[i, j]);
                    if (j != c)
                        Console.Write(" ");
                }
                Console.Write("\n");
            }
        }
    }
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int ans = 0;
    for (int i = 1; i < n - 1; i++)
    {
        if ((p[i - 1] <= p[i] && p[i] <= p[i + 1]) || (p[i - 1] >= p[i] && p[i] >= p[i + 1]))
            ans++;
    }
    cout << ans << endl;
    return 0;
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void anss(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n;cin>>n;
  for(i=0;i<n;i++){
    cin>>buf;
    if(buf%4==0)buf4++;
    else if(buf%2==0)buf2++;
    else buf1++;
  }
  if(buf2==0)
  ans1(buf4+1>=buf1);
  else
  {
    ans1(buf4>=buf1);
  }
  

  return 0;
}

Measured memory_bytes: 256
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();


		long ans=1l;
		for (int i = 0; i < N; i++) {
			long time=sc.nextLong();

			ans=lcm(ans, time);
		}

		System.out.println(ans);

	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}


	public static long gcd(long a, long b) {

		if (b == 0) {
			return a;
		}

		if (a < b) {
			long t = a;
			a = b;
			b = t;
		}

		return gcd(b, a%b);

	}

	public static long lcm(long a, long b) {

		long gcd=gcd(a,b);
		return a /gcd*b;
	}


	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define int long long
const int MOD = 1e9 + 7;
using pii=std::pair<int,int>;
using namespace std;

const int maxs = 2005;

int s, dp[maxs][maxs];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> s;
    dp[0][0] = 1;
    for(int i = 0; i < s; i++)
    {
        int cursum = 0;
        for(int j = 0; j < s; j++)
        {
            cursum += dp[i][j];
            cursum %= MOD;
            if(j + 3 <= s)
            {
                dp[i + 1][j + 3] += cursum;
                dp[i + 1][j + 3] %= MOD;
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < s; i++)
    {
        ans += dp[i][s];
        ans %= MOD;
    }
    cout << ans << "\n";
    return 0;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> ans(N,0);
  for(int i=0;i<M;i++){
    int a, b;
    cin >> a >> b;
    for(int j=0;j<N;j++){
      if(j==a-1||j==b-1) ans.at(j)++;
    }
  }
  for(int i=0;i<N;i++) cout << ans.at(i) << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int X = Integer.parseInt(sc.next());
		int Y = Integer.parseInt(sc.next());
		int Z = Integer.parseInt(sc.next());
		System.out.println(Z + " "+ X + " "+Y);
	}
}

Measured memory_bytes: 27004
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  ll tmp1 = (c - a - b)*(c - a - b);
  ll tmp2 = 4*a*b;
  if(tmp2 < tmp1 && c-a-b > 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n,i,j,s;
  int A[110][115];
  int B[110][115];

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    for(j=1;j<=n+1;j++){
      A[i][j]=0;
      B[i][j]=0;
    }
  }

  for(i=1;i<=n;i++){
    for(j=1;j<=n+1;j++){
      scanf("%d",&A[i][j]);
      if(j == 2)s=A[i][j];
      if(s+2 == j)break;
    }
  }

  for(i=1;i<=n;i++){
    for(j=3;j<=n+1;j++){
      if(A[i][j]!=0){
	B[i][A[i][j]]=1;
      }
    }
  }

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j!=1)printf(" ");
      printf("%d",B[i][j]);
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, x, n) for(int i = x; i < (int)(n); i++)
#define ALL(n) begin(n), end(n)
//struct cww{cww(){ios::sync_with_stdio(false);cin.tie(nullptr);}}star;
const long long INF = numeric_limits<long long>::max();

int main() {
  int n;
  scanf("%d", &n);
  int m;
  scanf("%d", &m);
  vector<int> s(m);
  vector<int> c(m);
  REP(i, m) {
    scanf("%d", &(s.at(i)));
    scanf("%d", &(c.at(i)));
  }

  // 0番目が一番左
  vector<int> numbers(n);
  REP(i, n) {
    numbers.at(i) = -1;
  }
  bool impossible = false;
  REP(i, m) {
    if (numbers.at(s.at(i) - 1) == -1) {
      numbers.at(s.at(i) - 1) = c.at(i);
    } else {
      if (numbers.at(s.at(i) - 1) != c.at(i)) {
        impossible = true;
        break;
      }
    }
  }

  if (numbers.at(0) == -1) {
    if (n == 1) {
      numbers.at(0) = 0;
    } else {
      numbers.at(0) = 1;
    }
  }
  REP2(i, 1, n) {
    if (numbers.at(i) == -1) {
      numbers.at(i) = 0;
    }
  }

  if (n > 1 && numbers.at(0) == 0) {
    impossible = true;
  }

  int value = 0;
  if (!impossible) {
    value = 0;
    REP(i, n) {
      value = numbers.at(i) + value * 10;
    }
  } else {
    value = -1;
  }


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

  return 0;
}


Measured memory_bytes: 256
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

/* see https://github.com/pllk/cphb/ */
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
    tree_order_statistics_node_update> indexed_set;

typedef unsigned int uint;
typedef long long ll;
//typedef __int128 lll;

#define fori(n) for(ll i=0; i<(n); i++)

typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    int n, d;
    cin>>n>>d;
    vvi x(n, vi(d));
    fori(n)
        for(int j=0; j<d; j++)
            cin>>x[i][j];

    int ans=0;
    for(int i=0; i<n; i++)  {
        for(int j=i+1; j<n; j++) {
            ll a=0;
            for(int k=0; k<d; k++) {
                int t=x[i][k]-x[j][k];
                a+=t*t;
            }
            ll sq=(ll)sqrt(a);
            if(sq*sq==a)
                ans++;
        }
    }

    cout<<ans<<endl;

}



Measured memory_bytes: 256
def main():
    n, w = map(int, input().split(" "))
    items = []
    for _ in range(n):
        items.append(list(map(int, input().split(" "))))

    memo = [[0] * (w + 1) for _ in range(n)]

    for i in range(n):
        val = items[i][0]
        wei = items[i][1]
        for j in range(w + 1):
            if i == 0:
                if j >= wei:
                    memo[i][j] = val
            else:
                if j >= wei:
                    memo[i][j] = max(
                        memo[i - 1][j],
                        memo[i - 1][j - wei] + val,
                    )
                else:
                    memo[i][j] = memo[i - 1][j]
    return memo[n - 1][w]


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


Measured memory_bytes: 25148
import java.util.Scanner;


public class Main{
    public static void swap(int c, int d){
        int a, b;
        a = c;
        b = d;
    }

    public static void main(String[] args) {
        int a, b;
        Scanner sc = new Scanner(System.in);
        while(true){
            a = sc.nextInt();
            b = sc.nextInt();
            if(a ==0 && b == 0){
            break;
            }
            else if(a > b){
            int temp = a;
            a = b;
            b = temp;
        }
        System.out.println( a+" "+b);
        }

    }
    
}


Measured memory_bytes: 35964
import java.util.ArrayList;
import java.util.Scanner;

class Main{
	static final long MOD = 1000000007;

	static int H, W, K;
	static long[][] dp = new long[110][10];
	static int ans = 0;
	static long n = 0;





	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		n = sc.nextLong();

		ArrayList<Integer> list = new ArrayList<Integer>();

		for(int i= 2; i <= n;i++){					//素数調べ
			boolean flag = true;
			for(int j = 2;j*j < i;j++){
				if(i%j == 0){
					flag = false;
					break;
				}
			}
			if(flag){
				list.add(i);
			}
		}

		int[] data = new int[list.size()];

		int p =0;
		while(true){						//各素数ごとの数をカウント
			if(n == 0){
				break;
			}
			long x = n;
			p =0;
			while(true){
								if(x == 1){
					break;
				}
				if(x % list.get(p) == 0){
					data[p]++;
					x /= list.get(p);
				}else{
					p++;
				}
			}
			n--;
		}
		
//		for(int i = 0;i < data.length;i++){					//確認
//			System.out.print(list.get(i) + " ");
//			System.out.println(data[i]);
//
//		}
		
		int c75 = 0;
		int c25 = 0;
		int c15 = 0;
		int c5 = 0;
		int c3 = 0;

		for(int i = 0;i < list.size();i++){

			if(data[i] >= 2){
				c3++;
			}
			if(data[i] >= 4){
				c5++;
			}
			if(data[i] >= 14){
				c15++;
			}
			if(data[i] >= 24){
				c25++;
			}
			if(data[i] >= 74){
				c75++;
			}
		}

		long ans = 0;
		ans += c75 + c25*(c3-1) + c15 * (c5-1) + (c5*(c5-1)/2)*(c3-2);
		System.out.println(ans);







	}
}







class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



Measured memory_bytes: 23636
N,M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
minX = X[0]
maxX = X[-1]
ans = maxX-minX
Y = [X[i+1] -X[i] for i in range(M-1)]
Y.sort()

if M == 1:
	print(0)
	exit()
if N >= M:
	print(0)
	exit()
else:
	ans = sum(Y[:M-N])
	print(ans)

Measured memory_bytes: 13968
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
  typedef long long int lli;
  string A;
  lli alpha[26];
  memset(alpha,0,sizeof(alpha));
  cin >> A;
  for (int i=0; i<A.length(); i++) {
    alpha[A[i]-'a']++;
  }
  lli n=A.length();
  lli ans=n*(n-1)/2;
  for (int i=0; i<26; i++) {
    ans-=alpha[i]*(alpha[i]-1)/2;
  }
  printf("%lld\n",ans+1);
  return 0;
}


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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

namespace IO {
    #define gc getchar()
    template <typename T>
    inline void read(T& x) {
        x = 0; bool f = 1; char ch;
        for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1;
        for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48);
        x = f ? x : -x;
    }
    #undef gc
}

const int MAXN = 1e6 + 10;
const int MAXVAL = 3e5;

int n, arr[MAXN], K, f[MAXN], ans;

struct Segment_Tree {
    #define mid ((l + r) >> 1)
    #define ls k << 1, l, mid
    #define rs k << 1 | 1, mid + 1, r
    struct Node { int val; } t[MAXN << 2];
    void pushup(int k) { t[k].val = max(t[k << 1 | 1].val, t[k << 1].val); }
    void modify(int k, int l, int r, int pos, int val) {
        if (l == r) return t[k].val = val, void();
        if (pos <= mid) modify(ls, pos, val);
        else modify(rs, pos, val);
        pushup(k);
    }
    int query(int k, int l, int r, int ql, int qr) {
        if (ql <= l && r <= qr) return t[k].val;
        int res = 0;
        if (ql <= mid) res = max(res, query(ls, ql, qr));
        if (qr > mid) res = max(res, query(rs, ql, qr));
        return res;
    }
} sgt;

int main() {
    IO::read(n), IO::read(K);
    rep(i, 1, n) IO::read(arr[i]);
    rep(i, 1, n) {
        f[i] = sgt.query(1, 1, MAXVAL, max(0, arr[i] - K) + 2, min(MAXVAL, arr[i] + K) + 2) + 1;
        sgt.modify(1, 1, MAXVAL, arr[i] + 2, f[i]);
        ans = max(ans, f[i]);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 10100
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[List[int]]"):
    import numpy as np
    from scipy.sparse.csgraph import floyd_warshall
    A = np.array(A, dtype=np.float64)
    B = floyd_warshall(A, directed=True)
    if not np.array_equal(A, B):
        return -1
    delta = 1e-7
    _, pre = floyd_warshall(A-delta+np.identity(N)*delta, return_predecessors=True)
    return int(A[pre == [[i]*N for i in range(N)]].sum()) // 2

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [[int(next(tokens)) for _ in range(N)] for _ in range(N)]  # type: "List[List[int]]"
    print(solve(N, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n, k, q;
  cin >> n >> k >> q;
  vi a(n, k);
  map<int, int> mp;
  rep(i, q) {
    int w;
    cin >> w;
    w--;
    mp[w]++;
  }
  dump(a);
  dump(mp);
  rep(i, n) {
    a[i] -= (q - mp[i]);
  }
  dump(a);
  rep(i, n) {
    if (a[i] > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 5760
input1 = list(map(int, input().split()))
input2 = list(map(int, input().split()))
T = int(input())
A = input1[0]
V = input1[1]
B = input2[0]
W = input2[1]

# print(A, V, B, W, T)



if W >= V:
    catch = False
else:
    if abs(B-A)/(V-W) <= T:
        catch = True
    else:
        catch = False

print("YES" if catch == True else "NO")

Measured memory_bytes: 9204
<?php
  fscanf(STDIN,"%d",$n);
  $a=explode(' ', trim(fgets(STDIN)));
  $sum=0;

  for($i=1;$i<$n;$i++){
    if($a[$i-1]>$a[$i]){
      $sa=$a[$i-1]-$a[$i];
      $sum+=$sa;
      $a[$i]+=$sa;
    }
  }

  echo $sum."\n";
  

Measured memory_bytes: 31908
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  _l=sorted(l)

  if n%2==0:
    a=_l[n//2-1]
    b=_l[n//2]

    for x in l:
      if x<=a:
        print(b)
      else:
        print(a)

main()


Measured memory_bytes: 29172
def main():
    K, N = map(int, input().split(' '))
    A = list(map(int, input().split()))
    A.sort()
    A.append(A[0] + K)
    max_diff = A[0] + K - A[-1]
    for a, b in zip(A, A[1:]):
        if (b - a) > max_diff:
            max_diff = b - a
    print(K - max_diff)


if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
ll fac[N], inv[N], ans;
int h, w, a, b;

ll power(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
void init() {
    fac[0] = 1;
    for (int i = 1; i < N; ++i) {
        fac[i] = fac[i - 1] * i % mod;
    }
    inv[N - 1] = power(fac[N - 1], mod - 2);
    for (int i = N - 2; i >= 0; --i) {
        inv[i] = inv[i + 1] * (i + 1) % mod;
    }
}

inline ll C(int x, int y) {
    return fac[x] * inv[y] % mod * inv[x - y] % mod;
}
inline ll cal(int x1, int y1, int x2, int y2) {
    int x = x2 - x1;
    int y = y2 - y1;
    return C(x + y, x);
}

int main() {
    init();
    cin >> h >> w >> a >> b;
    // first p = {h - a - 1, b}
    // then x--,y++
    int x = h - a - 1;
    int y = b;
    while (x >= 0 && y < w) {
        ll d1 = cal(0,0,x,y);
        ll d2 = cal(x,y,h-1,w-1);
        ans = (ans + d1 * d2 % mod) % mod;
        --x;
        ++y;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6780
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<int> x(N), y(N), h(N);
  int n;
  rep(i, N) {
    cin >> x[i] >> y[i] >> h[i];
    if(h[i]) n = i;
  }
  int CX, CY, H;
  int ans[3];
  for(CX=0; CX<=100; ++CX) {
    for(CY=0; CY<=100; ++CY) {
      H = h[n] + (abs(CX-x[n]) + abs(CY-y[n]));
      bool flg = true;
      rep(i, N) {
        if(h[i] > 0 && H-h[i] != abs(CX-x[i])+abs(CY-y[i]))
          flg = false;
        if(h[i]==0 && H > abs(CX-x[i])+abs(CY-y[i]))
          flg = false;
      }
      if(flg) {
        ans[0]=CX;
        ans[1]=CY;
        ans[2]=H;
      }
    }
  }
  printf("%d %d %d\n", ans[0], ans[1], ans[2]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;
ll N;

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
int n,m;
int ans=0;

vector<vector<int>> grid;
vector<ll> H, S;
vector<bool> seen;
vector<ll>sum;
vector<int> pl;

int main(int argc, char **argv){
	int num[3];
	cin>>num[0]>>num[1]>>num[2];
	
	int cnt=0;
	sort(num,num+3);
	int M=num[2];

	int odd[3];
	rep(i,0,3) odd[i]=num[i]%2;

	if(odd[0]==odd[1] && odd[1]==odd[2]){
		//cout<<"oppai"<<endl;
		cnt+=(num[1]-num[0])/2;
		cnt+=(num[2]-num[1]);
		cout<<cnt<<endl;
	}else{
		if(odd[0]==odd[1]){
			cnt+=(num[1]-num[0])/2;
			cnt+=(num[2]-num[1]);
			cout<<cnt<<endl;
		}else if(odd[0]==odd[2]){
			cnt+=(num[2]+1-num[1])/2;
			//cout<<cnt<<endl;
			cnt+=(num[2]-num[0])/2;
			//cout<<cnt<<endl;
			cnt++;
			cout<<cnt<<endl;
		}else if(odd[1]==odd[2]){
			cnt+=(num[2]+1-num[0])/2;
			cnt+=(num[2]-num[1])/2;
			cnt++;
			cout<<cnt<<endl;
		}
	}
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int N; cin >> N;
    VI x(N), y(N), h(N); REP(i,N) cin >> x[i] >> y[i] >> h[i];
    int t = 0; while(h[t] == 0) t++;
    REP(cx,101)REP(cy,101){
        int H = h[t] + abs(cx-x[t]) + abs(cy-y[t]);
        bool flag = true;
        REP(i,N){
            if(h[i] != max(H-abs(cx-x[i])-abs(cy-y[i]), 0)){
                flag = false;
                break;
            }
        }
        if(flag){
            cout << cx << " " << cy << " " << H << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256