akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

ll N,M,P[1010],a[1100000];

int main2(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	if(cin>>N>>M,!N)return 1;
	rep(i,N)cin>>P[i];
	P[N++]=0;
	rep(i,N)rep(j,N)a[i*N+j]=-(P[i]+P[j]);
	sort(a,a+N*N);
	ll ans=0;
	rep(i,N*N){
		ll b=-a[i];
		int id=lower_bound(a,a+N*N,-(M-b))-a;
		if(id==N*N)continue;
		ans=max(ans,b-a[id]);
	}
	cout<<ans<<endl;
	return 0;
}

int main(){
	while(!main2());
}

Measured memory_bytes: 9400
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
    for (T &x : vec)
        is >> x;
    return is;
}

ll gcd( ll m, ll n )
{
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}

ll lcm( ll m, ll n )
{
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	return ((m / gcd(m, n)) * n);
}

int main(){
    int a,b;
    cin >> a >> b;
    if(a+b==15){
        cout << "+" << endl;
    }else if(a*b==15){
        cout << "*" << endl;
    }else{
        cout << "x" << endl;
    }

    return 0;
}

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

long long p = 1e9+7;

//繰り返し２乗法
int Pow(long long a, long long n){
  if (n == 1) return a%p;
  if (n % 2 == 1) return (a*Pow(a,n-1))%p;
  long long t = Pow(a,n/2)%p;
  return (t*t)%p;
}

//フェルマーの小定理より1/Y = Y ^{(1e9+7)-2}
int inv(long long a){
  return Pow(a, p-2);
}

//nCr
int comb(long long n,long long r){
  long long denominator=1,numerator=1;
  for(int i=0; i<r; i++){
    denominator = denominator * (r-i) % p;
    numerator = numerator * (n-i) % p;
  }
  return (inv(denominator) * numerator) % p;
}


int main(){
  long long a,b,n;
  cin >> n >> a >> b;

  long long ans = Pow(2,n) - comb(n,a) - comb(n,b) - 1;
  while(ans < 0) ans += p;
  cout << ans << endl;
}


Measured memory_bytes: 256
/* ex3_3
   offNaria */
#include <stdio.h>
#include <math.h> //対数計算をするので数学関数のヘッダーファイルを読み込み

int main(void){
  int input_N, input_K; //整数input_N,input_Kを定義
  scanf("%d %d", &input_N, &input_K); //入力を変数に代入
  int output = log(input_N) / log(input_K) + 1; //桁数はKを底とするNの対数に1を加えたもの
  printf("%d\n", output);
  return 0;
}


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

int main(){
  vector<int> numbers{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  
  int N;
  cin >> N;
  N = N - 1;
  
  cout << numbers.at(N) << endl;
}

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

public class Main {
	final static int MOD = 1000000007;
	final static int intMax = 1000000000;
	final static int intMin = -1000000000;
	final static int[] dx = { 0, 0, -1, 1 };
	final static int[] dy = { -1, 1, 0, 0 };

	static int add(int a, int b) {
		return (a + b) % MOD;
	}
	
	static int sub(int a, int b) {
		return (a - b + MOD) % MOD;
	}
	
	static int mult(int a, int b) {
		return (int)((((long)(a)) * b) % MOD);
	}
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//		BufferedReader br = new BufferedReader(new FileReader(".in"));
		PrintWriter out = new PrintWriter(new File(".out"));
		String s = br.readLine();
		String t = br.readLine();
		int N = s.length();
		int M = t.length();
		String[][] dp = new String[N + 1][M + 1];
		for(int i = 0; i <= N; ++i) {
			for(int j = 0; j <= M; ++j) {
				dp[i][j] = "";
			}
		}
		for(int i = 1; i <= N; ++i) {
			for(int j = 1; j <= M; ++j) {
				int mxlen = dp[i - 1][j].length();
				String mxstr = dp[i - 1][j];
				if(dp[i][j - 1].length() > mxlen) {
					mxlen = dp[i][j - 1].length();
					mxstr = dp[i][j - 1];
				}
				if(dp[i - 1][j - 1].length() > mxlen) {
					mxlen = dp[i - 1][j - 1].length();
					mxstr = dp[i - 1][j - 1];
				}
				if(s.charAt(i - 1) == t.charAt(j - 1)) {
					if(dp[i - 1][j - 1].length() + 1> mxlen) {
						mxlen = dp[i - 1][j - 1].length() + 1;
						mxstr = dp[i - 1][j - 1] + s.charAt(i - 1);
					}
				}
				dp[i][j] = mxstr;
			}
		}
		System.out.println(dp[N][M]);
		br.close();
		out.close();
	}
}

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

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

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

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};


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

string s;

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

	cin>>s;
	REP(i,s.size()) if(i%2==0) cout<<s[i];
	cout<<endl;

	return 0;
}


Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <time.h>
#include <bits/stdc++.h>

#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
int main() {
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    IO;
    int n ,k;
    cin>>n >>k;
    ll arr[n+2];
    ll dp[n+2];
    for(int i =0 ;i < n ; i++){
        cin>>arr[i];
        dp[i]=INT_MAX;
    }
    dp[0]=0;
    for(int i = 1;i < n ; i++)
    {
        ll ans=INT_MAX;
        for(int j = 1 ; j<=k&&i-j>=0 ; j++){
            ans=min(ans,dp[(i-j)]+abs(arr[i]-arr[i-j]));
        }
        dp[i]=ans;
    }
    cout<<dp[n-1]<<endl;

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
 
int main(void){
    int i,j;            //  ループ文に使用
    int x,y,z;
    int count1,count2,count;   //  カウント用に使用
    int box[256] = {};
    char s[200001] = {};        //  文字列
    char s2[200001] = {};        //  文字列
    int a,b,c;
    a = b = c = i = 0;
    int mode = 0;
    count = count1 = count2 = 0;
 
    //  入力処理
    
    scanf("%s",s);
 
    //  計算処理
    if (s[1] != '\0'){
        i = 1;
        while(s[i] != '\0'){
           if (s[i] == s[i - 1]){
               if (s[i + 1] == '\0'){
                   count = count + 1;
                   break;
               }else if (s[i + 2] == '\0'){
                   count = count + 2;
                   break;
               }else if(s[i + 3] == '\0'){
                    i = i + 1;
                    count = count + 3;
                    break;
               }else{
                i = i + 3;
                count = count + 2;
               }
           }else{
               if (s[i + 1] == '\0'){
                   count = count + 2;
                   break;
               }
               i = i + 1;
               count++;
           }
          // count++;
          
        }
    }else{
        count = 1;
    }
    //  出力処理
 
    printf("%d",count);
 
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int mod(int x)
{
	if(x>0)
	return x;
	else return -1*x;
}
int main()
{
	ll x,n,t;
	cin>>n>>x>>t;
	if(n%x==0)
	cout<<(n/x)*t<<"\n";
	else cout<<((n+x)/x)*t<<"\n";
	
}

Measured memory_bytes: 3588
class Solution:
    def solve(self, n, arr):
        count = 1
        minElement = arr[0]

        for i in range(1, n):
            if arr[i] <= minElement:
                count += 1
                minElement = arr[i]

        return count


sol = Solution()

n = int(input().strip())
arr = list(map(int, input().strip().split(" ")))

print(sol.solve(n, arr))


Measured memory_bytes: 25716
#include<stdio.h>
#include<math.h>
int main(void)
{
	double a,b,c,d;
	//d=3.14159265;
	scanf("%lf",&a);
	b=a*a*M_PI;
	c=(a+a)*M_PI;
	printf("%lf %lf\n",b,c);
	return 0;
}

Measured memory_bytes: 1076
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	i64 n, k; scanf("%lld%lld", &n, &k); std::vector<i64> a(n);
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
	
	i64 sum = 0;
	for(auto v: a) sum += v;
	
	std::vector<i64> divisor;
	for(i64 M = 1; M * M <= sum; M++) {
		if(sum % M) continue;
		divisor.push_back(M);
		divisor.push_back(sum / M);
	}
	sort(begin(divisor), end(divisor));
	
	i64 ans = 1;
	for(auto M: divisor) {
		i64 A = 0;
		std::vector<std::pair<i64, i64>> vec;
		for(int i = 0; i < n; i++) {
			vec.push_back({a[i] % M, M - a[i] % M});
			A += M - a[i] % M;
		}
		sort(begin(vec), end(vec));
		
		i64 cost = A, tmp = 0;
		for(auto v: vec) {
			tmp += v.first;
			A -= v.second;
			
			cost = std::min(cost, tmp + std::abs(A - tmp));
		}
		
		if(cost <= k) ans = M;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int main(){
int n,k,a[100001]={0};
long long ans=0;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++){
	scanf("%d",&a[i]);
	ans+=min(a[i],abs(k-a[i]));
}
cout<<ans*2<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int a,b,i,cnt=0,n,m,c;
	cin>>a>>b;
	for(i=a;i<=b;i++)
	{
		m=i;
		n=i;
		c=0;
		while(n>0)
		{
			c=(c*10)+(n%10);
			n=n/10;
		}
		if(m-c==0)
		cnt++;
	//	cout<<i<<" "<<m<<" "<<n<<endl;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3556
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double EPS = 1e-8;

const int tx[] = {0,1,0,-1};
const int ty[] = {-1,0,1,0};

int students[100][100];

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		for(int y=0;y<n;y++){
			for(int x=0;x<n;x++){
				scanf("%d",&students[y][x]);
			}
		}

		map<P,int> table;
		vector<int>* row_low = new vector<int>[n];
		for(int y=0;y<n;y++){
			int minv = numeric_limits<int>::max();

			for(int x=0;x<n;x++){
				if(minv > students[y][x]){
					minv = students[y][x];
					row_low[y].clear();
					row_low[y].push_back(x);
				}
				else if(minv == students[y][x]){
					row_low[y].push_back(x);
				}
			}

			for(int i=0;i<row_low[y].size();i++){
				table[P(row_low[y][i],y)]++;
			}
		}

		vector<int>* col_high = new vector<int>[n];
		for(int x=0;x<n;x++){
			int maxv = numeric_limits<int>::min();

			for(int y=0;y<n;y++){
				if(maxv < students[y][x]){
					maxv = students[y][x];
					col_high[x].clear();
					col_high[x].push_back(y);
				}
				else if(maxv == students[y][x]){
					col_high[x].push_back(y);
				}
			}

			for(int i=0;i<col_high[x].size();i++){
				table[P(x,col_high[x][i])]++;
			}
		}

		int maxv = 0;
		for(int x=0;x<n;x++){
			for(int y=0;y<n;y++){
				if(table[P(x,y)]==2){
					maxv = max(students[y][x],maxv);
				}
			}
		}

		printf("%d\n",maxv);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n,m; cin>>n>>m;
    map<int,int> mp;
    rep(i,m){
        int a,b; cin>>a>>b;
        if(a>b) swap(a,b);
        if(mp[a]==0) mp[a]=b;
        else mp[a]=min(mp[a],b);
    }
    int ans=0, a=0;
    while(a!=n){
        if(mp[a]==0) a++;
        else{
            ans++;
            int b=mp[a]-1;
            vector<int> p;
            for(int i=a; i<=b; ++i){
                if(mp[i]!=0) p.push_back(mp[i]);
            }
            sort(btoe(p));
            a=p[0];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7304
#ABC062

x,y = map(int,input().split())
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
if x == 2 and y == 2:
    print("Yes")
elif x in a and y in a:
    print("Yes")
elif x in b and y in b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int sen[1001][101];
int main(void){
  int n,m,a,h,p,q;
  while(cin>>n>>m>>a){
    if(n==0) break;
    memset(sen,0,sizeof(sen));
    REP(i,m){
      cin>>h>>p>>q;
      sen[h][p] = q;
      sen[h][q] = p;
    }
    REP(i,1001){
      if(sen[1000-i][a]){
        a = sen[1000-i][a];
      }
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const long double INF = (1e10);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}


int n;
long double memo[666][666];
bool done[666][666],g[666][666];

long double solve(int v, int s){
	int i,c=0;
	long double m=-INF;
	if(done[v][s]){
		return memo[v][s];
	}
	done[v][s] = true;
	if(v==(n-1)){
		return memo[v][s] = 0.0;
	}
	memo[v][s] = 0.0;
	for(i=0; i<n; ++i){
		if(!g[v][i]){
			continue;
		}
		memo[v][s] += solve(i,s);
		++c;
	}
	if(v!=s || c<2){
		memo[v][s] /= c;
		memo[v][s] += 1.0;
		return memo[v][s];
	}
	for(i=0; i<n; ++i){
		if(!g[v][i]){
			continue;
		}
		m = max(m,solve(i,s));
	}
	memo[v][s] -= m;
	memo[v][s] /= (c-1);
	memo[v][s] += 1.0;
	return memo[v][s];
}

int main(void){
	int s,t,i,m;
	long double ans = INF;
	cin >> n >> m;
	for(i=0; i<m; ++i){
		cin >> s >> t;
		--s; --t;
		g[s][t] = true;
	}
	for(i=0; i<n; ++i){
		ans = min(ans,solve(0,i));
	}
	cout << fixed << setprecision(50) << ans << endl;
	return 0;
}


Measured memory_bytes: 7296
number = 4
fare = [int(input()) for a in range(number)]
 
fare_0_0 = fare[0] + fare[2] #A + C
fare_0_1 = fare[0] + fare[3] #A + D
fare_1_0 = fare[1] + fare[2] #B + C
fare_1_1 = fare[1] + fare[3] #B + D
 
fare_min = fare_0_0
if fare_min > fare_0_1:
    fare_min = fare_0_1
if fare_min > fare_1_0:
    fare_min = fare_1_0
if fare_min > fare_1_1:
    fare_min = fare_1_1
    
print(fare_min)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string>
using namespace std;
const int maxn=3e4+10;
int n;
char s[maxn];
bool z[11],a[101],b[1001];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>s[i];
		int x=s[i]-'0';
		for(int j=0;j<100;j++){
			if(a[j]) b[10*j+x]++;
		}
		for(int j=0;j<10;j++){
			if(z[j]) a[10*j+x]++;
		}
		z[x]++;
//		cout<<x;
	}
	int ans=0;
	for(int i=0;i<1000;i++){
		if(b[i]) ans++;
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 256
n,a,b=gets.chomp.split(" ").map(&:to_i)

def to_sum(i)
    i%10 + i/10%10 + i/100%10 + i/1000%10 + i/10000%10
end

ans = 0
(1..n).each do |m|
    sum = to_sum(m)
    if a <= sum && sum <= b 
        ans = ans + m
    end
end
puts ans


Measured memory_bytes: 1788
#include <stdio.h>

int main(void) {
    int a[3];
    scanf("%d %d %d", &a[0], &a[1], &a[2]);
    int sum[3];
    sum[0] = a[0] + a[1];
    sum[1] = a[0] + a[2];
    sum[2] = a[1] + a[2];
    int min = 300;
    for(int i = 0;i < 3;i++){
        if(sum[i] < min){
            min = sum[i];
        }
    }
    printf("%d\n", min);
}


Measured memory_bytes: 128
open System

let s = Console.ReadLine()

let ans =
    let bCompCnt, wCompCnt =
        let head =
            if s.[0] = 'B' then
                1, 0, 'B'
            else
                0, 1, 'W'

        [1 .. s.Length - 1]
        |> List.map (fun i -> s.[i])
        |> List.fold
            (fun (b, w, prevColor) c ->
                if prevColor = c then
                    b, w, c
                else
                    match c with
                    | 'B' -> (b + 1), w, 'B'
                    | _ -> b, (w + 1), 'W'
            ) head
        |> (fun (b, w, _) -> b, w)

    if bCompCnt = wCompCnt then
        2 * bCompCnt - 1
    else
        min bCompCnt wCompCnt
        |> fun n -> 2 * n

ans |> Console.WriteLine

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int ans=0;
	for(int i=1;i<=n;++i){
		string t=to_string(i);
		if(t.size()%2==1)++ans;
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 3688
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim(){
  int u, minv;
  int d[MAX],p[MAX],color[MAX];

  for(int i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;

  while (1)
  {
    minv=INFTY;
    u=-1;
    for(int i=0;i<n;i++){
      if(minv> d[i] && color[i] != BLACK){
        u=i;
        minv=d[i];
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(int v=0;v<n;v++){
      if(color[v]!=BLACK && M[u][v]!=INFTY){
        if(d[v]>M[u][v]){
          d[v]=M[u][v];
          p[v]=u;
          color[v]=GRAY;
        }
      }
    }
  }
  int sum =0;
  for(int i=0;i<n;i++){
    if(p[i]!=-1)sum+=M[i][p[i]];
  }
  return sum;
}

int main(){
  cin >> n;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int e;
      cin >> e;
      M[i][j]=(e==-1) ? INFTY:e;
    }
  }
  cout << prim() << endl;
  return 0;
}


Measured memory_bytes: 3144
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	"""
	DP: 動的計画法を用いる
	"""
	n = int(input())
	src = [list(map(int, input().split())) for i in range(2)]
	#print(src)
	ans = [[0 for i in range(n)] for j in range(2)]
	ans[0][0] = src[0][0]
	for y in range(2):
		for x in range(n):
			# 片方ずつ処理して、合計値を比較しながら代入していく
			if x: ans[y][x] = max(ans[y][x], ans[y][x - 1] + src[y][x])
			if y: ans[y][x] = max(ans[y][x], ans[y - 1][x] + src[y][x])
	print(ans[1][n - 1])

if __name__ == '__main__':
	main()

Measured memory_bytes: 20588
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;constexpr ll INF=1LL<<60,MOD=1e9+7;//998244353;
void solve();int main(){cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();return 0;}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d>0?i<n:i>n;i+=d)
#define endl "\n"
#ifdef __LOCAL
#include "ostreams.h"
#endif
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> vector<T> make_vector(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_vector(size_t a,Ts... ts){return vector<decltype(make_vector(ts...))>(a,make_vector(ts...));}
void print(){cerr<<endl;} template<class T,class... Ts> void print(const T& a,const Ts&... ts){cerr<<a<<' ';print(ts...);}

void solve(){
    ll n, q; cin >> n >> q;
    vector<vector<ll>> E(n);
    rep(_, n - 1){
        ll u, v; cin >> u >> v;
        u --; v --;
        E[u].push_back(v);
        E[v].push_back(u);
    }

    vector<ll> ans(n);
    rep(_, q){
        ll p, x; cin >> p >> x;
        p -- ;
        ans[p] += x;
    }

    vector<pll> stack{{0, -1}};
    while(!stack.empty()){
        ll v, p; tie(v, p) = stack.back(); stack.pop_back();
        for(auto nv : E[v]){
            if(nv == p){
                continue;
            }
            ans[nv] += ans[v];
            stack.emplace_back(nv, v);
        }
    }

    for(auto a : ans){
        cout << a << endl;
    }
}

Measured memory_bytes: 19696
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
using namespace std;

const int mod = 1000000007;

struct modint{
    //member variable

    long long x;

    //constructor

    modint(long long x = 0):x((x%mod+mod)%mod){}

    //operator

    modint& operator+=(const modint ob){
        if((x += ob.x) >= mod) x -= mod;
        return *this;
    }

    modint& operator-=(const modint ob){
        if((x += mod - ob.x) >= mod) x -= mod;
        return *this;
    }

    modint& operator*=(const modint ob){
        (x *= ob.x) %= mod;
        return *this;
    }

    modint operator+(const modint ob) const {
        modint res(*this);
        return res+=ob;
    }

    modint operator-(const modint ob) const {
        modint res(*this);
        return res-=ob;
    }

    modint operator*(const modint ob) const {
        modint res(*this);
        return res*=ob;
    }

    modint pow(long long index) const {
        if(!index){
            modint ob(1);
            return ob;
        }
        modint ob = pow(index>>1);
        ob *= ob;
        if(index&1) ob *= *this;
        return ob;
    }

    //for prime mod
    modint inverse() const {
        return pow(mod-2);
    }

    modint& operator/=(const modint ob){
        return (*this) *= ob.inverse();
    }

    modint operator/(const modint ob) const {
        modint res(*this);
        return res/=ob;
    }
};

struct combination{
    //member variable
    vector<modint> fact, invfact;

    //constructor
    combination(int n):fact(n+1),invfact(n+1){
        fact[0] = 1;
        for(int i=1; i<=n; i++){
            fact[i] = fact[i-1]*i;
        }
        invfact[n] = fact[n].inverse();
        for(int i=n; i>=1; i--){
            invfact[i-1] = invfact[i]*i;
        }
    }

    modint operator()(int n, int k){
        if(k < 0 || k > n) return 0;
        return fact[n]*invfact[k]*invfact[n-k];
    }
};

int main(){
    int n, k;
    cin >> n >> k;
    modint ans(1);
    if(k>=n-1){
        for(int i = n+1; i <= 2*n-1; i++){
            ans *= i;
        }
        for(int i = 1; i <= n-1; i++){
            ans /= i;
        }
        cout << ans.x << endl;
        return 0;
    }
    modint ans2(0);
    combination c(n);
    for(int i = 1; i <= k; i++){
        ans2 += c(n,i) * c(n-1, i);
    }
    cout << (ans2.x + 1) % mod << endl;
    return 0;
}

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

int main()
{
int D;
int N;

	
	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> D;
	cin >> N;

	if( N == 100 )
		cout << N + 1;
	else
		cout << N;

	if( D >= 1 ) cout << "00";
	if( D == 2 ) cout << "00";

	cout << endl;

	return 0;
}






Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int X,Y,A,B,C;
int p[1<<17],q[1<<17],r[1<<17];
main()
{
	cin>>X>>Y>>A>>B>>C;
	for(int i=0;i<A;i++)cin>>p[i];
	for(int i=0;i<B;i++)cin>>q[i];
	for(int i=0;i<C;i++)cin>>r[i];
	sort(p,p+A);
	sort(q,q+B);
	sort(r,r+C);
	vector<int>T(X+Y);
	long now=0;
	for(int i=0;i<X;i++)now+=T[i]=p[A-i-1];
	for(int i=0;i<Y;i++)now+=T[X+i]=q[B-i-1];
	long ans=now;
	sort(T.begin(),T.end());
	for(int i=0;i<min(X+Y,C);i++)
	{
		now+=r[C-i-1]-T[i];
		ans=max(ans,now);
	}
	cout<<ans<<endl;
}


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

using namespace std;

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    X--;
    Y--;

    map<int, int> mp;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            mp[min(j - i, abs(X - i) + 1 + abs(Y - j))]++;
        }
    }

    for (int i = 1; i < N; ++i) {
        cout << mp[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 384
# coding: utf-8
# Your code here!
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i * 500 + j * 100 + k * 50 == X:
                ans += 1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

constexpr auto INF = INT_MAX/2;
constexpr auto MOD = 1000000007;

int main() {

	int s,w;
	cin >> s>>w;
	
	cout << (s - w <= 0 ? "unsafe" : "safe") << endl;

}


Measured memory_bytes: 3624
#define REP(i, n) for(long long int i = 0; i < (long long int)(n); i++)
#define lint long long int

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

int main() {
	lint N, M;
	cin >> N >> M;
	priority_queue<lint> q;

	REP(i, N) {
		lint A;
		cin >> A;
		q.push(A);
	}

	REP(m, M) {
		lint new_A = q.top() / 2;
		q.pop();
		q.push(new_A);
	}

	lint shiharai = 0;
	while(!q.empty()) {
		shiharai += q.top();
		q.pop();
	}

	cout << shiharai << endl;

	return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

string s;

int main(){
	cin>>s;
	int A=0,B=0;
	for(auto i:s){
		if(i=='0') A++;
		else B++;
	}
	cout<<min(A,B)*2<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <iomanip>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
    int mon,x,y,n,k;          	
    cin>>n>>k>>x>>y;
    if(n>k)
    {
    	mon=k*x+(n-k)*y;
    }
    else mon=n*x;
    cout<<mon;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int h, w;
	cin >> h >> w;
    vector<vector<bool>> s(h,vector<bool>(w));
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            char tmp; cin >> tmp;
            s[i][j]=(tmp=='.' ? 1 : 0);
        }
    }

    int ans=0;
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            if(!s[i][j]) continue;
            
            vector<vector<bool>> v=s;
            v[i][j]=0;
            queue<pair<pair<int,int>,int>> q;
            q.push(make_pair(make_pair(i,j),0));
            while(!q.empty()){
                auto tmp=q.front();
                int x=tmp.first.first, y=tmp.first.second, z=tmp.second;
                q.pop();
                ans = max(ans,z);

                if(x>0 && v[x-1][y]){
                    q.push(make_pair(make_pair(x-1,y),z+1));
                    v[x-1][y]=0;
                }
                if(x<h-1 && v[x+1][y]){
                    q.push(make_pair(make_pair(x+1,y),z+1));
                    v[x+1][y]=0;
                }
                if(y>0 && v[x][y-1]){
                    q.push(make_pair(make_pair(x,y-1),z+1));
                    v[x][y-1]=0;
                }
                if(y<w-1 && v[x][y+1]){
                    q.push(make_pair(make_pair(x,y+1),z+1));
                    v[x][y+1]=0;
                }

            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<double> dp(n+1);
    dp[0]=1;
    for(int coins=0;coins<n;coins++)
    {
        double p_heads;
        cin>>p_heads;
        for(int i=coins+1;i>=0;i--)
        {
            dp[i]=( i==0 ? 0: dp[i-1]*p_heads)+dp[i]*(1-p_heads);
        }
        
    }
    double ans=0;
    for(int i=0;i<=n;i++)
    {
        int tails=n-i;
        if(tails<i)
        {
            ans+=dp[i];
        }
    }
    printf("%.10lf\n",ans);
}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e3 + 100;
int T;
char str[N][N];
int ans[N][N], vis[N][N], n, m, sx, sy, ex, ey;
int dis[4][2] = {{1, 0},
                 {-1, 0},
                 {0, -1},
                 {0, 1}};
struct node {
    int x, y, step;
};
deque<node> q;

int main() {
    scanf("%d%d%d%d%d%d", &n, &m, &sx, &sy, &ex, &ey);
    for (int i = 1; i <= n; i++)scanf("%s", str[i] + 1);
    for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)ans[i][j] = -1;
//    node a;
//    a.x = sx, a.y = sy, a.step = 0;
    q.push_back(node{sx, sy, 0});
    while (!q.empty()) {
        node now = q.front();
        q.pop_front();
        int x = now.x, y = now.y, st = now.step;
        if (vis[x][y])continue;
        vis[x][y] = 1;
        ans[x][y] = st;
        for (int i = 0; i < 4; i++) {
            int xx = x + dis[i][0], yy = y + dis[i][1];
            if (xx > 0 && xx <= n && yy > 0 && yy <= m && !vis[xx][yy] && str[xx][yy] == '.') {
                q.push_front(node{xx, yy, st});
            }

        }
        for (int xx = max(1, x - 2); xx <= min(x + 2, n); xx++) {
            for (int yy = max(1, y - 2); yy <= min(y + 2, m); yy++) {
                if (!vis[xx][yy] && str[xx][yy] == '.') {
                    q.push_back(node{xx, yy, st + 1});
                }
            }
        }
    }
    if (ans[ex][ey] < 0)puts("-1");
    else printf("%d\n", ans[ex][ey]);
    return 0;
}


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

int main() {
    int N;
    string S;
    cin >> N >> S;

    int res = 0;
    for (int i = 0; i < 1000; i++) {
        int c[3] = {i / 100, (i / 10) % 10, i % 10};
        int cnt = 0;
        for (int j = 0; j < N; j++) {
            if (S[j] - '0' == c[cnt]) {
                cnt++;
                if (cnt == 3) break;
            }
        }
        if (cnt == 3) res++;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    bool flag=false;
    int N;cin>>N;
    for(int i=0;i<=25;i++)for(int j=0;j<=15;j++)if(N==4*i+7*j)flag=true;
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
/*
[abc117] D - XXOR
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;
const int MAX_D = 40;

int N;
ll K;
ll A[MAX_N];
int cnt[MAX_D];
ll dp[MAX_D + 1][2];

ll solve() {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < MAX_D; j++) {
            if ((A[i] >> j) & 1LL) {
                cnt[j]++;
            }
        }
    }

    memset(dp, -1, sizeof(dp));
    dp[MAX_D][0] = 0;
    for (int j = MAX_D - 1; j >= 0; j--) {
        for (int smaller = 0; smaller < 2; smaller++) {
            if (dp[j + 1][smaller] == -1) {
                continue;
            }
            for (int i = 0; i <= (smaller ? 1 : ((K >> j) & 1LL)); i++) {
                dp[j][smaller || i < ((K >> j) & 1LL)] =
                    max(dp[j][smaller || i < ((K >> j) & 1LL)],
                        dp[j + 1][smaller] +
                            (1LL << j) * (i ? (N - cnt[j]) : cnt[j]));
            }
        }
    }
    ll ans = max(dp[0][0], dp[0][1]);

    return ans;
}

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    cout << solve() << endl;

    return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  ll H, W; cin >> H >> W;
  if (H % 3 == 0 || W % 3 == 0){
    cout << 0 << endl;
    return 0;
  }

  ll ans = min(H, W);
  for (ll j = 0; j <= W; j++){
    ll now1 = H * j;
    ll now2 = (H/2) * (W - j);
    ll now3 = (H-(H/2)) * (W - j);

    ll now = max(now1,max(now2,now3)) - min(now1,min(now2,now3));
    ans = min(ans, now);
  }

  for (ll i = 0; i <= H; i++){
    ll now1 = W * i;
    ll now2 = (H-i) * (W/2);
    ll now3 = (H-i) * (W-(W/2));
    ll now = max(now1,max(now2,now3)) - min(now1,min(now2,now3));
    ans = min(ans, now);
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3584
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto abc = readints;
    int a = abc[0], b = abc[1], c = abc[2];

    if (a + b >= c)
        writeln("Yes");
    else
        writeln("No");
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
char s[100005];
int n,num[26];
ll ans,sum,inv[100005];
ll quick_pow(ll x,ll a)
{
	ll ans=1;
	while(a)
	{
		if(a&1)ans=ans*x%MOD;
		x=x*x%MOD;
		a>>=1;
	}
	return ans;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)inv[i]=quick_pow(i,MOD-2);
	inv[0]=1;
	scanf("%s",s+1);
	sum=1;
	for(int i=1;i<=n;i++)
	{
		num[s[i]-'a']++;
		ans+=sum*inv[num[s[i]-'a']]%MOD;
		sum=sum*inv[num[s[i]-'a']]%MOD*(num[s[i]-'a']+1)%MOD;
	}
	printf("%lld\n",ans%MOD);
	return 0;
}

Measured memory_bytes: 1024
#pragma region
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 1e9
using namespace std;
template <class T = int>
T in() {
  T x;
  cin >> x;
  return (x);
}

typedef long long ll;
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;
}

#pragma endregion

int main() {
  ll h = in(), w = in();
  if (h != 1 && w != 1) {
    ll ans = ((w + 1) / 2) * ((h + 1) / 2) + (w / 2) * (h / 2);
    cout << ans << endl;
  } else {
    cout << 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//
// Created by 26019 on 2020/6/6/006.
//

#include <iostream>

using namespace std;

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



Measured memory_bytes: 3184
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>

constexpr long long int Mod = 1000000007L;
long long int power3(const int exp) {
	if (exp == 0) {
		return 1;
	}
	else if (exp == 1) {
		return 3;
	}
	else {
		auto r = power3(exp / 2);
		return (((r * r) % Mod) * power3(exp % 2)) % Mod;
	}
}
long long int count(const int current, const std::string &state, std::vector<long long int>& memo) {
	if (current == state.size()) {
		return 1;
	}
	else if (memo[current] != -1) {
		return memo[current];
	}
	else {
		if (state[current] == '1') {
			return memo[current] = (count(current + 1, state, memo) * 2 + power3(state.size() - current - 1)) % Mod;
		}
		else {
			return memo[current] = count(current + 1, state, memo);
		}
	}
}
int main() {
	std::string l; std::cin >> l;
	std::vector<long long int> memo(l.size(), -1);
	for (auto i = l.size(); i > 1000; i -= 500) count(i, l, memo);
	std::cout << count(0, l, memo) << std::endl;
};

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>A>>B;
    cout<<(A-1)*(B-1)<<endl;
}

Measured memory_bytes: 256
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han Elmuzaffer Daima
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid (start+end)/2
#define ort (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 300005; 
const lo mod = 1000000007; 

lo n,m,cev,b[li],a[li],k,cev1;
string s;
vector<lo> v;

inline lo add(lo x,lo y){
	if(x+y>=mod) return x+y-mod;
	return x+y;
}
inline lo mul(lo x,lo y){
	return (x%mod)*(y%mod)%mod;
}

inline lo solve(){
	scanf("%lld %lld",&n,&m);
	FOR{
		scanf("%lld",&a[i]);
		//~ a[i]=add(a[i],mod);
		//~ if(i>1){
			cev=add(cev,mul((i-1),a[i]));
			//~ cev-=
			//~ cout<<cev<<endl;
		//~ }
	}
	cev=cev%mod;
	FOR{
		cev-=mul((n-i),a[i]);
		cev=cev%mod;
	}
	for(lo i=1;i<=m;i++){
		scanf("%lld",&b[i]);
		//~ b[i]=add(b[i],mod);
		if(i>1){
			cev1=add(cev1,mul((i-1),b[i]));
		}
	}
	cev1=cev1%mod;
	for(lo i=1;i<=m;i++){
		cev1-=mul((m-i),b[i]);
		cev1=cev1%mod;
	}
	//~ printf("%lld %lld\n",cev,cev1);
	printf("%lld\n",mul(cev,cev1));
	return 0;
}

int main(void){
	solve();
	
	return 0;
}


Measured memory_bytes: 3072
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=2000 +117;
const int MM=2000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.cpp.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
int fa[NN][NN]={};
vector<int> p[NN]={};
void dfs(int x,int f,int rt){
	fa[rt][x]=f;
	for(int i=0;i<p[x].size();++i){
		int cur=p[x][i];
		if(cur!=f)dfs(cur,x,rt);
	}
}
int bel[NN][NN]={};
#define pii pair<int,int>
#define mp make_pair
queue<pii> q;
int rt,st;
void col(int x){
	if(bel[rt][x]){
		q.push(mp(st,x));
		return ;
	}
	bel[rt][x]=st;
	for(int i=0;i<p[x].size();++i){
		int cur=p[x][i];
		if(cur!=fa[rt][x]){
			col(cur);
		}
	}
}
void add(int x,int y){
	if(x==y)return ;
	if(bel[x][y]){
		add(bel[x][y],y);
		return ;
	}
	if(bel[y][x]){
		add(bel[y][x],x);
		return ;
	}
	rt=x,st=y;
	col(y);
	rt=y,st=x;
	col(x);
	while(!q.empty()){
		pii now=q.front();
		q.pop();
		add(now.first,now.second);
	}
}
int ans=0;
void calc(int x,int fa,int pre){
	if(bel[pre][x]==x)++ans,pre=x;
	for(int i=0;i<p[x].size();++i){
		int cur=p[x][i];
		if(cur!=fa){
			calc(cur,x,pre);
		}
	}
}
int main(){
	//open();
	n=read();
	m=read();
	for(int i=1;i<n;++i){
		int x=read(),y=read();
		p[x].push_back(y);
		p[y].push_back(x);
	}
	for(int i=1;i<=n;++i){
		dfs(i,0,i);
	}
	for(int i=1;i<=m;++i){
		add(read(),read());
	}
	for(int i=1;i<=n;++i){
		calc(i,0,i);
	}
	ans/=2;
	printf("%d\n",ans);
	close();
	return 0;
}

Measured memory_bytes: 35200
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int a[200010], n, k;

bool check(int mid) {
    int cnt = 0;
    for (int i=0;i<n;i++) cnt += (a[i]+mid-1)/mid-1;
    return (cnt<=k);
}

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

    int l = 0, r = 1e9;
    while (l+1<r) {
        int mid = (l+r)/2;
        if (check(mid)) r = mid; else l = mid;
    }

    cout << r << endl;
}


Measured memory_bytes: 4396
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int h,a;
  cin >> h >> a;
  if(h%a==0){
    cout << h/a << endl;
  }
  else cout << h/a+1 << endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

# きれいさ、おいしさ、人気度、でそれぞれ正負のどちらを目指すかを決める
# たとえば、人気度だけ負を目指す場合
# i個目のケーキを食べることで「きれいさの正の値 + おいしさの正の値 + 人気度 * -1」が
# 大きくなるときだけ更新するDPを考える
# dp[i] = [値, (きれいさ,おいしさ,人気度)]

N,M = map(int,readline().split())
cakes = [None] * N
for i in range(N):
  cakes[i] = list(map(int,readline().split()))

INF = -(10 ** 15)
ans = INF
for i in range(2 ** 3):
  base = [-1,-1,-1]
  for j in range(3):
    if (i >> j) & 1:
      base[j] = 1
  dp = [None] * (M + 1)
  for j in range(M + 1):
    dp[j] = [INF,[INF,INF,INF]]
  dp[0] = [0,[0,0,0]]
  for j in range(N):
    x,y,z = cakes[j]
    for k in range(M-1,-1,-1):
      if dp[k][0] == INF:
        continue
      newx = dp[k][1][0] + x * base[0]
      newy = dp[k][1][1] + y * base[1]
      newz = dp[k][1][2] + z * base[2]
      if dp[k + 1][0] < newx + newy + newz:
        dp[k + 1][0] = newx + newy + newz
        dp[k + 1][1][0] = newx
        dp[k + 1][1][1] = newy
        dp[k + 1][1][2] = newz
  if ans < dp[M][0]:
    ans = dp[M][0]
    
print(ans)  


Measured memory_bytes: 74700
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path; vl A, T;
//***********//
int main() {
	cin >> N >> M;
	if (N == M) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

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

   reverse(s.begin(), s.end());
   for (int i = 0; i < s.size(); ) {
      if (s.substr(i, 5) == "maerd") {
         i += 5;
      } else if (s.substr(i, 5) == "esare") {
         i += 5;
      } else if (s.substr(i, 6) == "resare") {
         i += 6;
      } else if (s.substr(i, 7) == "remaerd") {
         i += 7;
      } else {
         break;
      }
      
      if (i == s.size()) {
         puts("YES");
         return 0;
      }
   }

   puts("NO");

   return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<int,int>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i,n) for (ll i=(ll)n-1;i>=0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<60
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}//最大公約数
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}//最小公倍数
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
const int MOD = 998244353;

inline ll mod_add(ll a,ll b){return (a+b)%MOD;}
inline ll mod_sub(ll a,ll b){return (a+MOD-b)%MOD;}
inline ll mod_mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){
if(n&1)res=res*x%mod;
x=x*x%mod;n>>=1;}return res;}
inline ll mod_inv(ll x){return mod_pow(x,MOD-2);}
inline ll mod_div(ll a, ll b){return mod_mul(a,mod_inv(b));}
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back
ll n;
int main(){
   cin>>n;
   VI a(n);rep(i,n)cin>>a[i];

   ll res=0;
   int right=0;
   int sum=0;
   for(int left=0;left<n;left++){
      while(right<n && (sum^a[right])==(sum+a[right])){
         sum+=a[right];
         right++;
      }
      res+=right-left;
      if(left==right)right++;
      else{
         sum-=a[left];
      }
   }
   cout<<res<<endl;
}

Measured memory_bytes: 4764