akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	if ((a <= 0 && b >= 0) || (a >= 0 && b <= 0))
	{
		cout << "Zero" << endl;
	}
	else if (a > 0 && b > 0)
	{
		cout << "Positive" << endl;
	}
	else
	{
		int j = a - b;
		if (j % 2 == 0)
			cout << "Negative" << endl;
		else
			cout << "Positive" << endl;
	}
	return 0;
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)
#define Rep(i, n) for(i = 1; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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; }

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

int main()
{
	int n;
	cin >> n;
	cout << n / 3 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair

using namespace std;

int main()
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10);
	#ifdef PIYUSH_AASHIRWAAD
		I_O;
	#else
	#define print(...) 0
	#endif
	std::vector<int> v(100001);
	v[0] = 0;
	v[1] = 1;
	std::vector<int> op;
	op.pb(1);
	op.pb(6);
	op.pb(36);
	op.pb(216);
	op.pb(1296);
	op.pb(7776);
	op.pb(46656);
	op.pb(9);
	op.pb(81);
	op.pb(729);
	op.pb(6561);
	op.pb(59049);
	for (int i = 2; i <= (100000); ++i)
	{
		int m = 100000000;
		for (int j = 0; j < 12; ++j)
		{
			if(i-op[j] >= 0){
				if((v[i-op[j]]+1)<m)
					m = v[i-op[j]]+1;
			}
		}
		v[i] = m;
	}
	int n;
	cin>>n;
	cout<<v[n];
}

Measured memory_bytes: 640
MOD = 998244353
N, S = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
dpR = Array.new(N + 1, 0) # dp[i] : Aをi番目まで使って、総和がSになる組合せの数(両端の区切り違いの重複含む)
dpL = Array.new(S + 1, 0) # dp[s] : (更新用)Aをi番目まで使って、総和がsになる組合せの数(左端の区切り違いの重複含む)

A.each.with_index(1) do |a,i|
  dpL[0] = i
  S.downto(0) do |j|
    dpL[j + a] = (dpL[j + a] + dpL[j]) % MOD if j + a <= S
  end
  dpR[i] = (dpR[i - 1] + dpL[S]) % MOD
end
puts dpR[N]


Measured memory_bytes: 3964
import sys 
input = sys.stdin.readline
MOD = 10**9 +7
INF = 10**9

def main():
    a,b,c = map(int,input().split())
    
    if c-a-b <= 0:
        print('No')
        exit()
    if (c-a-b)**2 > 4*a*b:
        print('Yes')
        exit()
    print('No')
if __name__=='__main__':
    main()

Measured memory_bytes: 3060
//Be Name Khoda
//no comment...
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1007;
const int infint = (int)1e9;
const ll inf = (ll)1e18;
int a[2][MAXN], dp[2][MAXN];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < 2; i++)
		for (int j = 0; j < n; j++)
			cin >> a[i][j];
	for (int i = 0; i < 2; i++)
		for (int j = 0; j < n; j++)
		{
			dp[i][j] = a[i][j];
			int mx = 0;
			if(i != 0)
				mx = dp[i - 1][j];
			if(j != 0)
				mx = max(mx, dp[i][j - 1]);
			dp[i][j] += mx;
		}
	cout << dp[1][n - 1];
}

Measured memory_bytes: 256
from itertools import permutations
from math import sqrt
n = int(input())
positions = [tuple(map(int, input().split())) for _ in range(n)]


def calc_distance(i, j):
    return sqrt(pow((positions[i][0] - positions[j][0]), 2) + pow((positions[i][1] - positions[j][1]), 2))


ans = 0
count = 0
for tmp in permutations(range(n)):
    for i in range(len(tmp) - 1):
        ans += calc_distance(tmp[i], tmp[i + 1])
    count += 1

print(ans / count)


Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int a[100005];
void solve(){
    string s;
    cin>>s;
    if(s[2]==s[3] and s[4]==s[5])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
//	cin>> t;
	while(t--)solve();
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <set>
using namespace std;
#define maxn 100000+5
typedef long long int ll;
const double INF = 1e20;
const double pi = acos (-1.0);
int via[maxn];
int main () {
    string s;
    while(cin>>s){
        int c0=0,c1=0;
        for(int i=0;i<s.size();i++){
            if(s[i]=='0')c0++;
            else c1++;
        }
        printf("%d\n",min(c0,c1)*2);
    }
    return 0;
}


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

int main()
{
    int n, ans = 0;
    string s;
    cin >> n >> s;

    for (int i = 0; i < n - 2; i++)
    {
        if (s.substr(i, 3) == "ABC") ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3616
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 10005
#define MAXD 105
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,d;
int dp[MAXN][MAXD][2];
string str;
void add(int &a,int b){a+=b; if(a>=MOD) a-=MOD;}
int solve(int now,int sum,int smaller)
{
    if(now==n) return sum==0?1:0;
    if(dp[now][sum][smaller]!=-1) return dp[now][sum][smaller];
    int limit=smaller?9:str[now]-'0';
    int ans=0;
    for(int i=0;i<=limit;i++) add(ans,solve(now+1,(sum+i)%d,smaller|(i<limit)));
    return dp[now][sum][smaller]=ans;
}
int main()
{
    cin>>str;n=str.size();
    scanf("%d",&d);
    memset(dp,-1,sizeof(dp));
    printf("%d\n",(solve(0,0,0)-1+MOD)%MOD);
    return 0;
}



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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

 int main() {
   string S, ans = "YES";
   cin >> S;

   if (S.length() > 9) ans = "NO";

   else if (S.length() == 9) {
     if (S != "AKIHABARA") ans = "NO";
   }

   else if (S.length() == 8) {
     if (S != "KIHABARA" && S != "AKIHBARA" && S != "AKIHABRA" && S != "AKIHABAR") ans = "NO";
   }

   else if (S.length() == 7) {
     if (S != "KIHBARA" && S != "KIHABRA" && S != "KIHABAR" && S != "AKIHBRA" && S != "AKIHBAR" && S != "AKIHABR") ans = "NO";
   }

   else if (S.length() == 6) {
     if (S != "AKIHBR" && S != "KIHABR" && S != "KIHBAR" && S != "KIHBRA") ans = "NO";
   }

   else if (S.length() == 5) {
     if (S != "KIHBR") ans = "NO";
   }
   else ans = "NO";

   cout << ans << endl;
 }


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
// #include <map>
#include <iomanip>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
const int maxn = 1e5 + 10;
std::vector<int> G[maxn];
int d[maxn];

int dfs(int u){
	if(d[u] != -1) return d[u];
	d[u] = 0;
	for(int i : G[u]){
		d[u] = max(dfs(i) + 1, d[u]);
	}
	return d[u];
}

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	memset(d, -1, sizeof(d));
	for(int i = 0; i < m; ++i){
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
	}
	for(int i = 1; i <= n; ++i){
		if(d[i] == -1)
			dfs(i);
	}
	cout << *max_element(d + 1, d + n + 1) << endl;
	return 0;
}

Measured memory_bytes: 7424
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

int main(){
    int N;
    cin >> N;
    string S[N];
    map<string,int>mp;
    int ans=0;
    for(int i=0;i<N;++i){
        cin >> S[i];
        mp[S[i]]++;
        if(mp[S[i]]==1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 25408
#include <bits/stdc++.h>
using namespace std;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
//pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };
const ll mod = 1e9 + 7;
const ll N = 2e5 + 7;


int main() {
	fastIO;
	int n;
	cin >> n;
	int A[n], B[n], C[n];
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		A[i]--;
	}
	for (int i = 0; i < n; i++) {
		cin >> B[i];
	}
	for (int i = 0; i < n-1; i++) {
		cin >> C[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += B[A[i]];
		if (i) {
			if (A[i-1] == A[i]-1)
				ans += C[A[i-1]];
		}
	}
	cout << ans;

}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
  int a,b;
    
  cin >>a>>b;
  if(a<b)
    cout <<"a < b"<<endl;
  else if(a>b)
    cout <<"a > b"<<endl;
  else
    cout <<"a == b"<<endl;
    
    return 0;
    
 }




Measured memory_bytes: 3080
#include <iostream>
#include <vector>

int main()
{
  int n;
  std::cin >> n;
  std::vector<int> value(n);
  for (int i = 0; i < n; i++) {
    std::cin >> value.at(i);
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    int cost;
    std::cin >> cost;
    int v = value.at(i) - cost;
    if (v > 0) {
      res += v;
    }
  }
  std::cout << res << '\n';
}


Measured memory_bytes: 256
def main():
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())
    k = int(input())
    A = [a,b,c,d,e]
    for i in range(len(A)):
        for j in range(i,len(A)):
            if A[j] - A[i] > k:
                print(':(')
                exit()

    print('Yay!')

main()

Measured memory_bytes: 38384
n = int(input())
ppp = list(map(int,input().split()))
cnt = 0
mini = 0
maxx = 0
p = [0]*3

for i in range(n-2):
    p[0] = ppp[i]
    p[1] = ppp[i+1]
    p[2] = ppp[i+2]
    
    mini = min(p)
    maxx = max(p)
    
    if mini != p[1]:
        if maxx != p[1]:
            cnt += 1
        
print(cnt)

Measured memory_bytes: 3064
N = int(input())#.split()
A = input().split()
den = False
for i in range(N):
    if int(A[i]) % 2 == 0:
        if int(A[i]) % 3 != 0 and int(A[i]) % 5 != 0:
            print("DENIED")
            exit(0)
            den = True
if not den:
    print("APPROVED")


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

using namespace std;

constexpr int MAXN = 1e5 + 5;

int n, sum, cnt;
array<int, MAXN> a, f;

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i], sum ^= a[i], a[i] ^= a[i] - 1;
        for (int j = 30; ~j; j--) {
            if ((a[i] >> j) & 1) {
                f[j] = 1;
                break;
            }
        }
    }
    for (int j = 30; ~j; j--)
        if (((sum >> j) & 1) && f[j])
            sum ^= (1 << (j + 1)) - 1, cnt++;
    cout << (sum ? -1 : cnt) << endl;
    return 0;
}

Measured memory_bytes: 4024
#include <stdio.h>

//N解の操作後の，電光掲示板に書かれている整数として考えられる最小の値を返す関数
int func(int N, int K);

int main(){
  int N, K;
  scanf("%d %d", &N, &K);
  printf("%d\n", func(N, K));
  return 0;
}

int func(int N, int K){
  if(N == 0){
    return 1;
  }
  if(N >= 1){
    if(func(N-1, K)*2 <= func(N-1, K)+K){
      return func(N-1, K)*2;
    }else{
      return func(N-1, K)+K;
    }
  }
  return -1;
}


Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 100005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int dp1[N],dp2[N];
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   string s;
   cin>>s;
   int n=s.length();
   s='#'+s;
   dp1[0]=0,dp2[0]=1;
   for(int k=1;k<s.length();k++)
   {
       if(s[k]=='0')
       {
           (dp1[k]=3*dp1[k-1])%=M;
           (dp2[k]=dp2[k-1])%=M;
       }
       else
       {
           (dp1[k]=3*dp1[k-1] + dp2[k-1])%=M;
           (dp2[k]=2*dp2[k-1])%=M;
       }
   }
   cout<<(dp1[n] + dp2[n])%M<<endl;

}



Measured memory_bytes: 1900
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(a%b,b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}


int main(){
    init();
	ll A,B,C,D;cin>>A>>B>>C>>D;
	A--;
	cout<<B-A-((B/C-A/C)+(B/D-A/D)-(B/lcm(C,D)-A/lcm(C,D)))<<endl;	
}

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

int main() {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> mu(C);
    vector<pair<int, int>> co(A + B);
    rep(i, A + B) {
        cin >> co[i].first;
        co[i].second = (i >= A);
    }

    rep(i, C) cin >> mu[i];

    sort(co.rbegin(), co.rend());
    sort(mu.rbegin(), mu.rend());

    vector<int> li;
    ll ans = 0;
    rep(i, A + B) {
        if (co[i].second == 0) {
            if (X == 0)
                continue;
            li.push_back(co[i].first);
            X--;
        } else {
            if (Y == 0)
                continue;
            li.push_back(co[i].first);
            Y--;
        }

        if (X == 0 && Y == 0)
            break;
    }

    int r = 0, l = 0;
    for (int i = li.size() - 1; i >= 0; --i) {
        if (li[l] <= mu[r]) {
            ans += mu[r];
            r++;
        } else {
            ans += li[l];
            l++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int n, m, a[1010], b[1010];
vector<int> v;

int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        if (a[i] < n)
            v.push_back(n - a[i]);
        else
            v.push_back(0);
    }
    int ans = 0;
    sort(v.begin(), v.end());
    for (int i = 0; i < m - 1; i++)
        ans += v[i];
    cout << ans << endl;
}


Measured memory_bytes: 3136
#!/usr/bin/env python3
import string
s = input()
result = float('inf')
for last in string.ascii_lowercase:
    t = list(s)
    while not all(c == last for c in t):
        for i in range(len(t)):
            if last in t[i : i + 2]:
                t[i] = last
        t.pop()
    result = min(result, len(s) - len(t))
print(result)


Measured memory_bytes: 3896
template<class Tp>
Tp floor_sum (Tp n, Tp m, Tp a, Tp b) {
	Tp value = 0;
	if (a >= m) {
		value += n * (n - 1) * (a / m) / 2;
		a %= m;
	}
	if (b >= m) {
		value += n * (b / m);
		b %= m;
	}
	const Tp y = (a * n + b) / m;
	const Tp x = y * m - b;
	if (y == 0) return value;
	value += (n - (x + a - 1) / a) * y;
	value += floor_sum(y, a, m, (a - x % a) % a);
	return value;
}

#include <iostream>
#include <cstdint>

using i64 = std::int_fast64_t;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int test_case;
	std::cin >> test_case;
	while (test_case--) {
		i64 n, m, a, b;
		std::cin >> n >> m >> a >> b;
		std::cout << floor_sum(n, m, a, b) << '\n';
	}
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

int main(){
 	int n = 0;
  	std::vector<int> vect;
  	std::cin >> n;

  	for(int i = 0; i < n; ++i )
    {
      int tmp = 0;
      std::cin >> tmp;
      vect.push_back(tmp);
    }

  	auto sorted = vect;

  	std::sort(sorted.begin(), sorted.end());

  	for(auto const i: vect ){
      if(i== sorted.back()){
        std::cout << sorted[sorted.size() - 2] << std::endl;
      }
      else
      {
     	  std::cout << sorted.back() << std::endl;
      }
    }

  	return 0;
}


Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int ret = 0;
    for (int i = 0; i < n; i++) {
        int h;
        cin >> h;
        if (h >= k)ret++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  ll ans=0;
  ll N;
  cin>>N;
  ll a[N];
  ll b[100001]={};

  FOR(i,0,N-1){
    cin>>a[i];
    if(a[i]>100000){
      ans=ans+1;
    }else{
      b[a[i]]++;
    }

  }
  FOR(i,0,100000){
    if(i>b[i]){
      ans=ans+b[i];
    }
    if(i<b[i]){
      ans=ans+b[i]-i;
    }
  //cout<<b[i]<<endl;
  }



cout<<ans<<endl;
return 0;

}
 


Measured memory_bytes: 1792
import itertools
def sgs(k):
    return 3**k-3*(2**k-2)-3

n = int(input())
l = len(str(n))
if l <= 2:
    print(0)
    exit()
origin_list = ["3","5","7"]
lst=list(itertools.product(origin_list,repeat=l))
lst_753 = [i for i in lst if "3" in i and "5" in i and "7" in i]
lst_new = [int(''.join(i)) for i in lst_753]
sum_sgs = sum([sgs(i) for i in range(3,l)])

n_k = sum(i <= n for i in lst_new)

ans = sum_sgs+n_k
print(ans)

Measured memory_bytes: 6516
a,b,c,d = map(int,input().split(" "))
ans = 0
from fractions import gcd
def lcm(x, y):
  return (x * y) // gcd(x, y)
a -= 1
f = lcm(c,d)
ans = (b - a) - ((b//c - a//c) + (b//d - a//d) - (b//f - a//f))

print(ans)    


Measured memory_bytes: 5244
N = int(input())
ls = []
flag = True
bChar = ""
for n in range(0, N):
  ch = input()
  if n == 0:
    ls.append(ch)
  else:
    if (ch in ls) or (bChar[-1:] != ch[0:1]):
      flag = False
  ls.append(ch)
  bChar = ch
if flag == True:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3060
<?php
$n = trim(fgets(STDIN));
$aArray = array_map("intval", explode(" ", trim(fgets(STDIN))));
$sum = 0;
$dp[] = 0;
foreach($aArray as $a){
    $sum += $a;
    $dp[] = $sum;
}
foreach($dp as $sum){
    @$c[$sum]++;
}
$total = 0;
foreach($c as $d){
    $total+=$d*($d-1)/2;
}
echo $total;

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

using namespace std;

int main() {
    int alice = 0;
    int bob = 0;
    int a, n;
    cin >> n;
    vector<int> vec(n);
    for (int i = 0; i < n; ++i) {
        cin >> a;
        vec.at(i) = a;
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());

    for (int j = 0; j < n; ++j) {
        if (j % 2 == 0) {
            alice += vec.at(j);
        } else {
            bob += vec.at(j);
        }
    }
    cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <math.h>

#include <iostream>

int compare_int(const void* a, const void* b) {
    return * (int*) a - * (int*) b;
}

int ni(int tg) {
	return pow((double) tg, 2);
}

int main() {
	int n;
	std::cin >> n;

	for (int i = 1; i <= n; i++) {
		const int size = 3;
		int in[size];
		std::cin >> in[0] >> in[1] >> in[2];

		qsort(in, size, sizeof(int), compare_int);

		if (ni(in[0]) + ni(in[1]) == ni(in[2]))
			std::cout << "YES" << std::endl;
		else
			std::cout << "NO" << std::endl;
	}
}

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

int main() {
   int N;
   cin >> N;
   int A[N];
   int count=0;
   for (int i=0; i<N; i++) {
       cin >> A[i];
       if (i%2==0 && A[i]%2==1) {
           count++;
       }
   }
   cout << count << endl;
}

Measured memory_bytes: 3620
import java.io.*;

class Main {
    public static void main(String[] args) {
        try {
        	BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        	int n = Integer.parseInt( kb.readLine( ) );
			String[] str = kb.readLine( ).split( " " );
			int[] S = new int[ n ];
			for( int i=0; i<n; i++ ) {
				S[i] = Integer.parseInt( str[i] );
			}

        	int q = Integer.parseInt( kb.readLine( ) );
			str = kb.readLine( ).split( " " );
			int[] T = new int[ q ];
			for( int i=0; i<q; i++ ) {
				T[i] = Integer.parseInt( str[i] );
			}

			int cnt = 0;
			int low, high, middle;
			for( int i=0; i<q; i++ ) {
				low = 0;
				high = n-1;
				middle = n/2;
				while( low <= high ) {
					if( T[i] == S[middle] ) {
						cnt++;
						break;
					} else if( T[i] < S[middle] ) {
						high = middle - 1;
						middle = ( low+high )/2;
					} else {
						low = middle + 1;
						middle = ( low+high )/2;
					}
				}				
			}
			System.out.println( cnt );

        } catch( IOException e ) {
            System.err.println( e );
        }
    }
}

Measured memory_bytes: 42428
n, m = gets.split(" ").map(&:to_i)
matrix = []
n.times do
  matrix << gets.split(" ").map(&:to_i)
end
vector = []
m.times do
  vector << gets.to_i
end
result = []
n.times do |i|
  item = matrix[i]
  temp = 0
  m.times do |j|
    temp += item[j] * vector[j]
  end
  result << temp
end
puts result


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

int main() {
	int n;
	int a[100];
	cin >> n;
	cin >> a[0];
  	int ans = 0;
  	ans += a[0];
	for(int i=1; i!=n-1; i++){
		cin >> a[i];
		if(a[i] > a[i-1]){
			ans += a[i-1];
		}else{
			ans += a[i];
		}
	}
  	ans += a[n-2];
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<ll> A(n);
  for(int i=0;i<n;i++){
    cin >> A.at(i);
  }
  ll mm = 1e9;
  for(int i=0;i<n;i++){
    ll m = A.at(i);
    ll count = 0;
    while(m%2==0){
      m /= 2;
      count ++;
    }
    mm = min(mm,count);
  }
  cout << mm << endl;
}
      




Measured memory_bytes: 256
import numpy as np

n = int(input())
a = list(map(int,input().split(" ")))
while True:
    a = list(set(a))
    if 0 in a:
        a.remove(0)
    a.sort()
    #print(a)
    mini = a[0]
    #print(mini)
    for i in range(1,len(a)):
        a[i] %= mini
    if len(a) == 1:
        #print("ngo")
        print(mini)
        exit()

Measured memory_bytes: 23304
import numpy as np

N = int(input())
E = [[] for i in range(N)]
for i in range(N-1):
	a, b = map(int, input().split())
	E[a - 1].append(b - 1)
	E[b - 1].append(a - 1)

C = np.fromiter(map(int, input().split()), np.int)
C = np.sort(C)[::-1]

Z = [-1] * N

stack = [0]
index = 0
while stack:
	v = stack.pop()
	if Z[v] >= 0:
		continue
	Z[v] = C[index]
	index += 1
	stack.extend(E[v])

print(np.sum(C[1:]))
print(' '.join(map(str, Z)))


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

const ll INF = 1e18;

main() {
  int H, W; cin >> H >> W;
  ll S[3]{}, Smax, Smin;
  ll ans = INF;
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < H - 1; j++) {
      S[0] = 1LL * (j + 1) * W;

      Smax = Smin = S[0];
      S[1] = 1LL * (H - j - 1) * (W / 2);
      S[2] = 1LL * (H - j - 1) * (W - W / 2);
      for (int k = 1; k < 3; k++) {
        Smax = max(Smax, S[k]);
        Smin = min(Smin, S[k]);
      }
      ans = min(ans, Smax - Smin);

      Smax = Smin = S[0];
      S[1] = 1LL * ((H - j - 1) / 2) * W;
      S[2] = 1LL * ((H - j - 1) - (H - j - 1) / 2) * W;
      for (int k = 1; k < 3; k++) {
        Smax = max(Smax, S[k]);
        Smin = min(Smin, S[k]);
      }
      ans = min(ans, Smax - Smin);
    }
    swap(H, W);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		
		for(int i = 2; i < S.length(); i += 2) {
			String a = S.substring(0, (S.length() - i) / 2);
			String b = S.substring((S.length() - i) / 2, S.length() - i);
			if(a.equals(b)) {
				System.out.println(S.length() - i);
				break;
			}
		}
		
	}
}


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

struct Z{
  ll y;
  ll x;
  ll depth;
};

ll H,W,K,y,x,depth,oo=1e12,xs,ys,xg,yg;
vector<ll> y_vec={1,0,-1,0};
vector<ll> x_vec={0,1,0,-1};
vector<vector<ll>> A;
queue<Z> q;

ll bfs(){
  while(!q.empty()){
    Z now=q.front(); q.pop();
    y=now.y, x=now.x, depth=now.depth;
    if(y==yg && x==xg) return depth;
    for(ll i=0; i<4; i++){
      for(ll k=1; k<=K; k++){
        Z next={y+y_vec[i]*k, x+x_vec[i]*k, depth+1};
//cout<<"ny:"<<next.y<<" nx:"<<next.x<<endl;        
        if(A[next.y][next.x]==-1) break;
        if(A[next.y][next.x]<next.depth) break;
        if(A[next.y][next.x]==next.depth) continue;
        A[next.y][next.x]=next.depth;
        q.push(next);
//cout<<" d:"<<next.depth<<endl;          
      }
    }
  }
  return oo;
}

//A[y][x], A(x,y)として管理
int main(){
  cin>>H>>W>>K;
  cin>>ys>>xs>>yg>>xg;
  A.assign(H+2, vector<ll>(W+2,-1));
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      char a; cin>>a;
      if(a=='@') continue;
      A[i][j]=oo;
    }
  }
  A[ys][xs]=0;
  Z start={ys,xs,0};
  q.emplace(start);
  ll ans=bfs();
  if(ans==oo) ans=-1;
  cout<<ans<<endl;
}


Measured memory_bytes: 34416
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	long long n,ans,tmp;
	ans =0;
	vector<long long> v;
	cin >> n;
	for(int i=0;i<3*n;i++){
		cin >> tmp;
		v.push_back(tmp);
	}	
	sort(v.begin(),v.end());
	for(int i=n;i<3*n;i+=2){
		ans +=v[i];
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 5872
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<vin> vvin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
const int MOD=1e9+7;

int main(){
  ll u;cin>>u;
  rep(k,0,u){

  string x,y;cin>>x>>y;
  ll n=x.size(),m=y.size();
  vvll dp(n+1,vll(m+1,0));
  
  rep(i,0,n){
    rep(j,0,m){
      if(x[i]==y[j])dp[i+1][j+1]=max(dp[i][j]+1,max(dp[i][j+1],dp[i+1][j]));
      else{dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);}
    }
  }
  
  cout<<dp[n][m]<<endl;
  }
}



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

using namespace std;

int N, l[100009], r[100009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d %d", &l[i], &r[i]);
sort (l, l + N + 1);
sort (r, r + N + 1);
long long ans = 0, curr = 0;
for (int i=1; i<=N; i++)
    curr += l[N - i + 1] - r[i - 1],
    ans = max (ans, curr);
printf ("%lld\n", 2LL * ans);

return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
  int n,i,j,c = 0,tmp;
  scanf("%d",&n);
  int r[n];
  for(i = 0; i < n; i++){
    scanf("%d",&r[i]);
  }
  for(i = 0; i < n; i++){
    for(j = n - 1; j > i; j--){
      if(r[j] < r[j - 1]){
        tmp = r[j];
        r[j] = r[j - 1];
        r[j - 1] = tmp;
        c++;
      }
    }
  }
  for(i = 0; i < n; i++){
    printf("%d",r[i]);
    if(i == n - 1){
      printf("\n");
      break;
    }
    printf(" ");
  }
  printf("%d\n",c);
  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=998244353;
const ll MAX_N=500010;
const ll INF=4999999996000000001;
const int SEG_LEN=1<<20;
ll seg[2*SEG_LEN];


void update(int ind, ll v){
    ind+=SEG_LEN;
    seg[ind]=v;
    while(true){
        ind/=2;
        if(ind==0) break;
        seg[ind]=max(seg[ind*2],seg[ind*2+1]);
    }
}

ll get(int l, int r){
    ll res=0;
    l+=SEG_LEN; 
    r+=SEG_LEN;
    while(r-l>0){
        if(l%2==1){
            res=max(res,seg[l]);
            l++;
        }
        l/=2;
        if(r%2==1){
            r--;
            res=max(res,seg[r]);
        }
        r/=2;
    }
    return res;
}


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

    for(int i=0;i<n;i++){
        ll M=get(0, h[i]+1);
        update(h[i],M+a[i]);
    }

    cout<<get(0,n+1)<<endl;

}

Measured memory_bytes: 9164
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
string s;
string f;
string mn="~";
int cnt=0;
int j;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>s>>f;
	for(int i=0;i<s.size()-f.size()+1;i++)
	{
		string q;
		bool flag=true;
		for(j=i;j<i+f.size();j++)
		{
			if(s[j]=='?')
			continue;
			else
			{
				if(s[j]!=f[j-i])
					flag=false;
			}
		}
		if(flag==true)
		{
			q=s;
			for(int j=i;j<i+f.size();j++)
			q[j]=f[j-i];
			for(int j=0;j<i;j++)
			{
				if(q[j]=='?')q[j]='a';
			}
			for(int j=i+f.size();j<q.size();j++)
			{
				if(q[j]=='?')
				q[j]='a';
			}
			mn=min(mn,q);
		}
		else cnt++;
	}
	if(cnt==s.size()-f.size()+1)
		cout<<"UNRESTORABLE";
	else
	cout<<mn;
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>

using namespace std;

int N;
int digits = 0;

int count(int x) {
  int n = 0;
  while (x) {
    x /= 10;
    ++n;
  }
  return n;
}

bool valid(const string& s) {
  return s.find('3') != string::npos && s.find('5') != string::npos &&
         s.find('7') != string::npos;
}

int dfs(int x, int base, int depth) {
  int ans = 0;
  if (x <= N && valid(to_string(x))) {
    ans += 1;
  }
  if (depth == digits) {
    return ans;
  }

  for (int y : {3, 5, 7}) {
    ans += dfs(x + y * base, base * 10, depth + 1);
  }
  return ans;
}

int main() {
  cin >> N;
  digits = count(N);

  int ans = dfs(0, 1, 0);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N, T = map(int, input().split())
As = list(map(int, input().split()))
if N == 1:
  print(1)
  exit()
Ms = []
m = 0
for i in range(N):
  m = max(m, As[-i-1])
  Ms.append(m)
Ms = list(reversed(Ms))
Ds = []
for i in range(N-1):
  d = Ms[i+1]-As[i]
  Ds.append(d)
dmax = max(Ds)
r = Ds.count(dmax)
print(r)


Measured memory_bytes: 15020
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<vector>
#include<string>
using namespace std;

int main(){
    int a[5]; 
    int k;
    bool tf = true;
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
    for(int i = 0; i < 4; i++){
        for(int j = i; j < 5; j++)
        if((a[j] - a[i]) > k){
            tf = false;
        }
    }
    if(tf){
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
int main(void) {
	int n;
	cin >> n;
	int t[n];
	for(int i=0;i<n;i++) cin >> t[i];
	int m;
	cin >> m;
	int p[m], x[m];
	for(int i=0;i<m;i++) cin >> p[i] >> x[i];

	int sum=0;
	for(int i=0;i<n;i++) sum += t[i];

	for(int i=0;i<m;i++) {
		cout << sum + x[i] - t[p[i]-1] << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main() {
  string a, b;
  cin>>a>>b;
  int n = a.length();
  int m = b.length();
  vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
  
  for(int i=0;i<=n;i++) {
    for(int j=0;j<=m;j++) {
      if (i == 0 || j == 0)
        dp[i][j] = 0;
      else if (a[i-1] == b[j-1])
        dp[i][j] = dp[i-1][j-1] + 1;
      else
        dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
    }
  }
  string s = "";
  int i = n,j = m;
  while (i > 0 && j > 0) {
    if (a[i-1] == b[j-1]) {
      s = a[i-1] + s;
      i--;
      j--;
    }
    else if (dp[i-1][j] > dp[i][j-1])
      i--;
    else
      j--;
  }
  cout<<s<<endl;
}

Measured memory_bytes: 35584
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

const int MOD = 1e9+7;
const int MAXN = 100100;
ll X[MAXN], Y[MAXN];
ll dX[MAXN];

int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}
	for (int i = 0; i < N-1; i++) {
		dX[i] = X[i+1] - X[i];
		(dX[i] *= (i+1)) %= MOD;
		(dX[i] *= (N-1-i)) %= MOD;
	}
	ll sum = 0;
	for (int i = 0; i < N-1; i++)
		(sum += dX[i]) %= MOD;
	for (int i = 0; i < M; i++) {
		cin >> Y[i];
	}
	ll ans = 0;
	for (int i = 0; i < M-1; i++) {
		ll tmp = Y[i+1]-Y[i];
		(tmp *= (i+1)) %= MOD;
		(tmp *= (M-1-i)) %= MOD;
		(ans += tmp) %= MOD;
	}
	(ans *= sum) %= MOD;
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main(void) {
    long n;
    cin >> n;
    bitset<100001> s, t;
    for(long a=1; a <= 100000; a*=6)
        s[a] = 1;
    for(long a=1; a <= 100000; a*=9)
        s[a] = 1;

    long r = 1;
    while(!s[n]) {
        t = s;
        for(long a=1; a <= 100000; a*=6)
            t |= s << a;
        for(long a=1; a <= 100000; a*=9)
            t |= s << a;
        s = t;
        r++;
    }
    cout << r << endl;
}


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

int main() {
  int N , D ; 
  cin >> N >> D ; 
  if( N % (2*D+1) != 0 ){
  cout <<( N / (2*D+1) +  1) << endl ; 
  }
  else {
  cout <<( N / (2*D+1) ) << endl ;     
  }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    REP(i,H) cin >> S[i];
    vector<vector<int>> cum(H+1, vector<int>(W+1));
    REP(i,H) REP(j,W){
        cum[i+1][j+1] = cum[i][j+1] + cum[i+1][j] - cum[i][j] + (S[i][j] == '1');
    }
    int ans = INF;
    REP(i, 1<<(H-1)){
        vector<int> h;
        REP(j,H-1) if((i >> j) & 1) h.push_back(j+1);
        h.push_back(H);
        int cnt = (int)h.size() - 1;
        int preW = 0;
        bool ok = true;
        for(int j=1;j<=W;j++){
            int preH = 0;
            int tmp = 0;
            for(auto x : h){
                chmax(tmp, cum[x][j] - cum[preH][j] - cum[x][preW] + cum[preH][preW]);
                preH = x;
            }
            if(tmp > K){
                if(j == 1){
                    ok = false;
                    break;
                }
                if(preW == W-1 && j == W){
                    ok = false;
                    break;
                }
                preW = j - 1;
                j--;
                cnt++;
            }
        }
        int tmp = 0;
        int preH = 0;
        for(auto x : h){
            chmax(tmp, cum[x][W] - cum[preH][W] - cum[x][preW] + cum[preH][preW]);
            preH = x;
        }
        if(tmp > K) ok = false;

        if(ok){
            chmin(ans, cnt);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  ll a;
  cin >> a;

  if (a < 27) {
    a--;
    cout << char(a+97) << endl;
    return 0;
  }

  vector<int> ans;

  while (a > 26) {
    ll b = a % 26;
    if (b == 0) {
      ans.push_back(26);
      a--;
    } else {
      ans.push_back(b);
    }
    a /= 26;
    if (a == 27 && b == 0) break;
  }

  if (a == 27) {
    cout << "z";
  } else {
    cout << char(a+96);
  }

  for (ll i = ans.size()-1; i >= 0; i--) {
    cout << char(ans[i] + 96);
  }

  cout << endl;


  return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 500010;
 
struct Mo{
  int sz;
  vector<int> left,right,order;
  vector<bool> check;
  Mo(int n,int q):sz((int)sqrt(n)),order(q),check(n){}
  void insert(int l, int r){
    left.emplace_back(l);
    right.emplace_back(r);
  }
  template<typename ADD,typename DEL,typename REM>
  void build(const ADD &add,const DEL &del,const REM &rem){
    iota(order.begin(),order.end(),0);
    sort(order.begin(),order.end(),[&](int a,int b){
      return (left[a]/sz!=left[b]/sz?left[a]<left[b]:right[a]<right[b]);
    });
    int l=0,r=0;
    auto push=[&](int idx){
      check[idx].flip();
      if (check[idx]) add(idx);
      else del(idx);
    };
    for (int idx:order){
      while(l>left[idx]) push(--l);
      while(r<right[idx]) push(r++);
      while(l<left[idx]) push(l++);
      while(r>right[idx]) push(--r);
      rem(idx);
    }
  }
};
 
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int arr[n+1];
  for (int i = 0; i < n; ++i) cin >> arr[i];
  Mo mo(n, m);
  for (int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;
    mo.insert(l - 1, r);
  }
  int cnt[n+1]={0}, ans[m];
  int sum = 0;
  auto add=[&](int idx){if (cnt[arr[idx]]++==0) ++sum;};
  auto del=[&](int idx){if (--cnt[arr[idx]]==0) --sum;};
  auto rem=[&](int idx){ans[idx]=sum;};
  mo.build(add,del,rem);
  for (int i = 0; i < m; ++i) cout << ans[i] << '\n';
}

Measured memory_bytes: 15664
#include "bits/stdc++.h"
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

ll powMod(ll n, ll k, ll m) {
	if (k == 0) {
		return 1;
	} else if (k % 2 == 1) {
		return powMod(n, k - 1, m) * n % m;
	} else {
		ll t = powMod(n, k / 2, m);
		return t * t % m;
	}
}

int main() {
	set<ll> s;
	
	rep(i, 3) {
		int n;
		cin >> n;
		s.insert(n);
	}

	if (s.size() == 2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

map<ll, ll> factor(ll x) {
    map<ll, ll> res;
    for (ll i = 2; i * i <= x; i++) {
        while (x % i == 0) {
            res[i]++;
            x /= i;
        }
    }
    if (x != 1) res[x] = 1;
    return res;
}

int main() {
    ll N; cin >> N;
    ll ans = 0;
    for (auto i: factor(N)) {
        // cout << "for " << i.first << ":" << i.second << endl;
        ll count = 0;
        while (count * (count + 1) / 2 <= i.second) count++;
        ans += count - 1;
        // cout << count - 1 << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <cstdio>

int
main(void)
{
  int m, f, r, sum;
  char jg;
  
  while (std::scanf("%d %d %d", &m, &f, &r) != EOF) {
    if (m == -1 && f == -1 && r == -1) {
      break;
    }
    if (m == -1 || f == -1) {
      jg = 'F';
    } else {
      sum = m + f;
      if (sum >= 80) {
        jg = 'A';
      } else if (sum >= 65) {
        jg = 'B';
      } else if (sum >= 50 || r >= 50) {
        jg = 'C';
      } else if (sum >= 30) {
        jg = 'D';
      } else {
        jg = 'F';
      }
    }
    std::printf("%c\n", jg);
  }

  return 0;
}



Measured memory_bytes: 2716
#include<stdio.h>

int main(void){
    int n, c[51], v[51], i;

    scanf("%d",&n);
    for(i=1; i<=n; i++){
        scanf("%d",&v[i]);
    }
    for(i=1; i<=n; i++){
        scanf("%d",&c[i]);
    }

    int x=0, y=0;
    for(i=1; i<=n; i++){
        if(v[i] > c[i]){
            x += v[i];
            y += c[i];
        }
    }

    printf("%d\n",x-y);
    return 0;
}

Measured memory_bytes: 128
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()

zero = s.count("0")
one = s.count("1")

print(min(zero,one)*2)

Measured memory_bytes: 21760
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int x1 = sc.nextInt();
		int x2 = sc.nextInt();
		int x3 = sc.nextInt();
		int x4 = sc.nextInt();
		int x5 = sc.nextInt();
		int x[] = {x1, x2, x3, x4, x5};
		for(int i=0; i < x.length; i++) {
			if(x[i] == 0) {
				System.out.println(i + 1);
			}
		}
	}

}

Measured memory_bytes: 27076
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
#define pi 3.14159265359
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    string s;
    cin >> s;
    l = s.length();
    for(i = 0; i < l; i++){
        sum += s[i] - '0';
        sum %= 9;
    }
    if(sum == 0){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 3784