akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcount
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int n, k;
int arr[101];
int dp[101][100001];
int sumdp[101][100001];
signed main(){
    cin >> n >> k;
    for(int i=0;n>i;i++){
        cin >> arr[i];
    }
    for(int i=0;k>=i;i++){
        dp[0][i] = (i <= arr[0]) ? 1 : 0;
        sumdp[0][i] = (sumdp[0][max((int)0, i-1)]%MOD + dp[0][i]%MOD)%MOD;
    }
    for(int i=1; n>i; i++){
        for(int j=0;k>=j;j++){
            if(j-arr[i] <= 0){
                dp[i][j] += sumdp[i-1][j];
            }else{
                dp[i][j] += (sumdp[i-1][j]%MOD - sumdp[i-1][j-arr[i]-1] + MOD)%MOD;
            }
            dp[i][j] %= MOD;
            sumdp[i][j] = sumdp[i][max((int)0, j-1)]%MOD + dp[i][j]%MOD;
            sumdp[i][j] %= MOD;
        }
    }
    cout << dp[n-1][k]%MOD << endl;
}










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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

ll calc(ll x){
    if(x<=0)return  0;
    x++;
    ll ans=0;
    for (int i = 0; i < 50; ++i) {
        ll loop=(1LL<<(i+1));//周期
        ll co=(x/loop)*(loop/2);//ループした回数＊１の数
        co+=max(0LL,(x%loop)-(loop/2));//00001111 -に注意
        if(co%2==1){
            ans+=(1LL<<i);
        }
    }
    return ans;
}

int main(){
    ll a,b;cin >>a>>b;
    ll ans=calc(b)^calc(a-1LL);
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

void solve() {
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    int ff = (c + b - 1) / b;
    int ss = (a + d - 1) / d;
    if(ff <= ss) cout<<"Yes";
    else cout<<"No";

}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int t = 1;
    //cin>>t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

map<ll,ll> mp;
ll n,a,b,c,d;
vpl v(3);

ll rec(ll x){
    if(x == 1) return d;
    if(x == 0) return 0;
    if(mp.find(x) != mp.end()) return mp[x];
    ll res;
    if(1e15/d >= x) res = x * d;
    else res = linf;
    rep(i,3){
        chmin(res, rec(x / v[i].first) + d * (x % v[i].first) + v[i].second);
        if(x % v[i].first){
            chmin(res, rec(x / v[i].first + 1) + d * (v[i].first - x % v[i].first) + v[i].second);
        }
    }
    return mp[x] = res;
}

int main(){
    ll t; cin >> t;
    while(t--){
        cin >> n >> a >> b >> c >> d;
        v[0] = {2,a}; v[1] = {3,b}; v[2] = {5,c};
        cout << rec(n) << endl;
        mp.clear();
    }
}

Measured memory_bytes: 4388
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< string, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789


///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////


int N;
int M;
int K;
int bdp[5000];
int A[1123];
int B[1123];
int C[1123][15];

int main(){
    
    cin>>N>>M;
    K = 1<<N;
    REP( i, M ){
        cin>>A[i]>>B[i];
        REP( j, B[i] ) cin>>C[i][j];
    }
    fill( bdp, bdp+K, -1 );
    
    bdp[0] = 0;
    
    REP( i, M ){
        REP( j, K ){
            if( bdp[j] != -1 ){
                int idx = j;
                REP( k, B[i] ){
                    idx |= (1<<(C[i][k]-1));
                }
                if( bdp[idx] == -1 ) bdp[idx] = bdp[j]+A[i];
                else{
                    bdp[idx] = min( bdp[idx], bdp[j]+A[i] );
                }
            }
        }
    }
    
    cout<<bdp[K-1]<<endl;
    
    return 0;
}



Measured memory_bytes: 384
def slove():
    import sys
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    if a >= 13:
        print(b)
    elif 6 <= a <= 12:
        print(b // 2)
    else:
        print(0)


if __name__ == '__main__':
    slove()


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

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

    int N, T;
    cin >> N >> T;
    vector<int> imos(T + 1);
    for (int i = 0; i < N; i++) {
        int l, r;
        cin >> l >> r;
        imos[l]++;
        imos[r]--;
    }
    for (int i = 0; i < T - 1; i++) imos[i+1] += imos[i];
    cout << *max_element(imos.begin(), imos.end()) << endl;
}


Measured memory_bytes: 3360
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int N;

/*==================================================*/
/*function*/
vector<int> hurui_v(int n) {
    vector<int> v;
    bool *isPrime_v;
    isPrime_v = new bool[n + 1];
    isPrime_v[0] = isPrime_v[1] = false;
    for (int i = 2; i < n + 1; i++) isPrime_v[i] = true;
    for (int i = 2; i*i <= n; i++) {
        for (int j = i * 2; j < n + 1; j += i) {
            isPrime_v[j] = false;
        }
    }
    for (int i = 0; i < n + 1; i++) {
        if (isPrime_v[i]) v.push_back(i);
    }
    delete[] isPrime_v;
    return v;
}
/*==================================================*/

int main() {
    cin>>N;

    vector<int> v = hurui_v(55555);
    vector<int> ans;
    REP(i,0,v.size()){
        if(v[i] % 5 == 1){
            ans.push_back(v[i]);
        }
        if(ans.size() == N){
            break;
        }
    }

    REP(i,0,N){
        cout<<ans[i]<<" ";
    }
    cout<<endl;


    return 0;
}


Measured memory_bytes: 384
// https://atcoder.jp/contests/abc152/tasks/abc152_d
// 
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(),(x).end()
#define outl(x) cout<<x<<endl
#define outsp(x) cout<<x<<" "
typedef long long ll;
typedef pair<int,int> P;


#define MAX_N 1000000005

int log10(int v){
	int ret=0;
	while(v>0){
		v/=10;
		ret++;
	}
	return ret;
}
int main() {
	int n;
	cin >> n;
	ll ans = 0;
	int n_kn = log10(n);
	int n_l = n/(int)pow(10,n_kn-1);
	int n_r = n%10;
	int n_c = (n - n_l*(int)pow(10,n_kn-1))/10;
	for(int a=1;a<=n;a++){
		int kn = log10(a);
		int l = a/(int)pow(10,kn-1);
		int r = a%10;
		if(r==0)continue;
		if(l==r){
			if(l<=n)ans++; // b=l (1桁)の場合
		}
		rep(j,n_kn-2){
			ans += (ll)pow(10,j);
		}
		if(n_kn>1){
			if(r<n_l){
				ans += (ll)pow(10,n_kn-2);
				// outsp(a);outl(ans);
			}else if(r==n_l){
				if(n_kn==1){
					ans ++;
				}else{
					if(l<=n_r){
						ans += n_c + 1;
					}else{
						ans += n_c;
					}

				}
				
			}
		}
	}
	outl(ans);
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    const long long inf=2000000000000000000;
    long long n,k;
    cin>>n>>k;
    int a[n];
    vector<int>sei;
    vector<int>fu;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>0)sei.push_back(a[i]);
        if(a[i]<0)fu.push_back(-a[i]);
    }
    sort(sei.begin(),sei.end());
    sort(fu.begin(),fu.end());
    long long minus,zero,plus;
    minus=sei.size()*fu.size();
    plus=(sei.size()*(sei.size()-1)+fu.size()*(fu.size()-1))/2;
    zero=n*(n-1)/2-minus-plus;
    if(k>minus && k<=minus+zero){
        cout<<"0"<<endl;
        return 0;
    }
    if(k<=minus){//解が負
        long long l=-inf,r=0;
        while(r-l>1){
            long long mid=-(l+r)/2,x=0;
            for(int i=0;i<fu.size();i++)x+=int(sei.size())-int(upper_bound(sei.begin(),sei.end(),mid/fu[i])-sei.begin());
            if(x<k)l=-mid;
            else r=-mid;
        }
        cout<<l<<endl;
    }
    else{//解が正
        k-=minus+zero;
        long long l=1,r=inf;
        while(r-l>1){
            long long mid=(l+r)/2,x=0;
            for(int i=0;i<fu.size();i++)x+=max(0,int(upper_bound(fu.begin(),fu.end(),(mid-1)/fu[i])-fu.begin()-i-1));
            for(int i=0;i<sei.size();i++)x+=max(0,int(upper_bound(sei.begin(),sei.end(),(mid-1)/sei[i])-sei.begin()-i-1));
            if(x<k)l=mid;
            else r=mid;
        }
        cout<<l<<endl;
    }
    return 0;
}


Measured memory_bytes: 5052
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b;
    cin>>a>>b;
    cout<<6 - (a + b)<<endl;
}

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

string w[110];
int main() {
  int N; cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> w[i];
  }
  bool ans = true;
  for (int i = 0; i < N - 1; i++) {
    if(w[i][w[i].size() - 1] != w[i + 1][0]) {
      ans = false;
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      if (w[i] == w[j]) {
        ans = false;
      }
    }
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]) = {
    val sc = new Scanner(System.in)
    val antennas = List.fill(5)(sc.nextInt)
    val k = sc.nextInt()

    val isAccess = antennas.combinations(2).map{
      case List(a, b) => b - a
    }.forall(_ <= k)
    if (isAccess) println("Yay!") else println(":(")
  }
}


Measured memory_bytes: 25820
import core.stdc.stdio;
import std.typecons;
import std.stdio;
import std.algorithm;
import std.math;

void main(){
	int v,e;
	scanf("%d%d",&v,&e);
	int[][] graph = new int[][v];
	foreach(i;0..e){
		int a,b;
		scanf("%d%d",&a,&b);
		graph[--a]~=--b;
		graph[b]~=a;
	}
	int[] d=new int[v];
	int[] s=new int[v];
	int[] t=new int[v];
	void dfs(int i,int b,ref int e,ref int f){
		if(d[i])
			return;
		d[i]=b;
		e++;
		foreach(c;graph[i])
			dfs(c,3-b,f,e);
	}
	foreach(i;0..v)
		dfs(i,1,s[i],t[i]);
	foreach(i;0..v)
		foreach(c;graph[i])
			if(d[i]==d[c]){
				printf("-1\n");
				return;
			}
	int g;
	int[int] h;
	foreach(i;0..v)
		if(s[i]||t[i]){
			g+=min(s[i],t[i]);
			int w=abs(s[i]-t[i]);
			if(w in h)
				h[w]++;
			else
				h[w]=1;
		}
	int[] dp=new int[v+1];
	static immutable int inf=1145141919;
	dp[]=inf;
	dp[0]=0;
	foreach(q;h.byKeyValue){
		foreach(ref x;dp)
			if(x<inf)x=0;
		foreach(i;q.key..v+1)
			if(dp[i-q.key]<q.value)
				dp[i]=min(dp[i],dp[i-q.key]+1);
	}
//	writeln(g," ",dp);
	long ans=0;
	foreach(i,x;dp)
		if(x<inf)
			ans=max(ans,cast(long)(g+i)*(v-g-i));
	printf("%lld\n",ans-e);
}

Measured memory_bytes: 8112
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1,i,j;
    //cin>>t;
    while(t--)
    {
        int n,count=0,sum=0,flag=0,maxi=-1,mini=1e18;
        cin>>n;
    
        for(i=1;i<=n;i++)
        {
            if(i%3==0 || i%5==0)
            {
                
            }
            else
            {
                sum+=i;
            }
        }
        cout<<sum;
    }
}

Measured memory_bytes: 3688
#include <stdio.h>

int main(void)
{
    int i;
    long long int N, min, a[5];
    scanf("%lld", &N);
    for (i = 0; i < 5; i ++)
        scanf("%lld", &a[i]);

    min = 1000000000000000;
    for (i = 0; i < 5; i++)
    {
        if (a[i] < min){
            min = a[i];
        }
    }

    printf("%lld\n", min >= N ? 5 : 5 + (N - 1) / min);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node { int parent,left,right;};

Node Tree[MAX];
int n, Depth[MAX];

void print (int u){
    int i , c;
    cout << "node " << u << ": ";
    cout << "parent = " << Tree[u].parent << ", ";
    cout << "depth = " <<  Depth[u] << ", ";

    if(Tree[u].parent == NIL) cout << "root, ";
    //左下にノードがなかった場合そいつがleaf(葉)である。
    else if (Tree[u].left ==NIL ) cout << "leaf, "; 
    else cout << "internal node, ";

    cout << "[";

    for(i=0,c=Tree[u].left;c != NIL; i++, c = Tree[c].right){
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

//深さを求める(高速な方法)
int rec(int u, int p){
    Depth[u] = p;
    if(Tree[u].right != NIL) rec(Tree[u].right,p); // 右の兄弟にも同じ深さを設定
    if(Tree[u].left != NIL) rec(Tree[u].left, p+1); //最も左の子に自分の深さ＋1を設定
}
int main(){
    int i,j,d,v,c,l,r;
    cin>> n;
    for(i=0;i<n;i++) Tree[i].parent = Tree[i].left = Tree[i].right = NIL;

    for(i=0;i<n;i++){
        cin >> v >> d;
        for(j=0;j<d;j++){
            cin >> c;
            if( j == 0) Tree[v].left = c;
            else Tree[l].right =c;
            l=c;
            Tree[c].parent =v;
        }
    }
    for(i=0;i<n;i++){
        if(Tree[i].parent == NIL) r =i;
    }
    rec(r,0);

    for(i=0;i<n;i++)print(i);

    return 0;
}


Measured memory_bytes: 7784
n,m=map(int, input().split())
h=list(map(int, input().split()))
near=[[0] for i in h]
for i in range(m):
    a,b=map(int, input().split())
    near[a-1].append(h[b-1])
    near[b-1].append(h[a-1])
cnt=0
for i in range(n):
    if max(near[i])<h[i]:
        cnt+=1
print(cnt)

Measured memory_bytes: 26120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;



int main(){
    ll n,k,s;
    cin >> n >> k >> s;
    vector<ll> res;
    for(ll i=0;i<k;i++){
        res.push_back(s);
    }
    if(s!=1e9){
        for(ll i=0;i<n-k;i++){
            res.push_back(1e9);
        }
    }
    else{
        for(ll i=0;i<n-k;i++){
            res.push_back(1e9-1);
        }
    }
    for(ll i=0;i<n;i++){
        cout << res[i];
        if(i!=n-1) cout << " ";
    }
    cout << endl;
    return 0;
}  


Measured memory_bytes: 4320
#include <stdio.h>

int main(void)
{
	int S, h, m, s;
	scanf("%d", &S);
	h = S / (60 * 60);
	m = S / 60 % 60; 
	s = S % 60;
	printf("%d:%d:%d\n", h, m, s);
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 1e6+5;
const int mod = 1e9+7;
int k[maxn];
int v[maxn];
ll ksm(ll a, ll b, ll c)    //快速幂取模 a^b%c
{
    ll ans=1;
    while(b){
        if(b&1)
            ans=(ans*a)%c;
        a=(a*a)%c;
        b>>=1;
    }
    return ans;
}
int main()
{
    int n; cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> k[i];
        int x = k[i];
        for(int j = 2; j*j <= x; j++) {
            if(x % j == 0) {
                int cnt = 0;
                while(x % j == 0) {
                    cnt++;
                    x /= j;
                }
                v[j] = max(v[j], cnt);
            }
        }
        if(x > 1) v[x] = max(v[x], 1);
    }
    ll s = 1;
    ll ans = 0;
    for(int i = 1; i <= 1000000; i++) {
        while(v[i]--) s = (ll)s*i%mod;
    }
    for(int i = 1; i <= n; i++) {
        ans = (ans + (ll)s * ksm(k[i], mod-2, mod))%mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

const int INF = 100000;

typedef long long ll;

int main(){
  int n, m; cin >> n >> m;
  int c[m+1];
  for(int i=1;i<=m;i++) cin >> c[i];
  int dp[m+1][n+1];
  //dp[i][j] means the minimum to make j yen from c_1 to c_i
  for(int i=0;i<=n;i++) dp[0][i]=INF;
  for(int i=0;i<=m;i++) dp[i][0]=0;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(j-c[i] >= 0) dp[i][j] = min(dp[i-1][j], dp[i][j-c[i]]+1);
      else dp[i][j] = dp[i-1][j];
    }
  }
  /*for(int i=0;i<=m;i++){
    for(int j=0;j<=n;j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }*/
  cout << dp[m][n] << endl;
}

Measured memory_bytes: 7188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int[] answer = new int[26];
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNextLine()) {
			String S = scanner.nextLine();
			S = S.toLowerCase();
			for(int i=0;i<S.length();i++) {
				if ('a'<=S.charAt(i)&&S.charAt(i)<='z') {
					answer[S.charAt(i)-'a']++;
				}
			}
		}
		scanner.close();
		for(int i=0;i<26;i++) {
			System.out.println((char)(i+'a') + " : " + answer[i]);
		}
	}
}


Measured memory_bytes: 26080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<ll> arr;
    for(int i=0; i<n; i++)
    {
        ll x;
        cin>>x;
        arr.push_back(x);
    }
    sort(arr.begin(),arr.end());
    ll sum=arr[0]+arr[1];
    ll cnt=((ll)n*(ll)(n-1)*(ll)(n-2))/6LL;
    //map<pair<ll,ll>,ll> mp;

    for(int i=0; i<n; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            sum=arr[i]+arr[j];
            /*for(int k=j+1;k<n;k++)
            {
                if(arr[i]<(arr[j]+arr[k]) && arr[j]<(arr[k]+arr[i]) && arr[k]<(arr[j]+arr[i]))
                {
                    cout<<arr[i]<<" "<<arr[j]<<" "<<arr[k]<<endl;
                    cnt++;
                }
            }*/
            cnt -= (ll)(upper_bound(arr.begin(),arr.end(),1e5)-lower_bound(arr.begin(),arr.end(),sum));
        }
    }

    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,sum;
    cin>>a>>b>>c;
    for(int i=0;i<=1000;i++)
    {
        sum=a*i;
        if(sum%b==c)
        {
            cout<<"YES";
            return 0;
        }
    }
    cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
from collections import deque
S = input()
Q = int(input())
ans = deque(S)
rev_flag = False
for i in range(Q):
    query = input()
    if query == "1":
        rev_flag = not rev_flag
    elif not rev_flag:
        if query[2] == "1":
            ans.appendleft(query[4])
        else:
            ans.append(query[4])
    else:
        if query[2] == "2":
            ans.appendleft(query[4])
        else:
            ans.append(query[4])

if rev_flag:
    ans.reverse()

print("".join(ans))


Measured memory_bytes: 8820
s = input()
a,c,x,q,m1,m2,n1,n2 = [],[],len(s),s.count("?"),0,0,0,0
for i in range(x-2):
	if s[i]=="A": m1+=1
	elif s[i]=="?": m2+=1
	if s[x-1-i]=="C": n1+=1
	elif s[x-1-i]=="?": n2+=1
	a.append([m1,m2])
	c.append([n1,n2])
c,z0,z1,z2,z3,mod,num = c[::-1],0,0,0,0,10**9+7,1
for i in range(x-2):
	if s[i+1]=="B":
		z0,z2 = (z0+a[i][0]*c[i][0])%mod,(z2+a[i][1]*c[i][1])%mod
		z1 = (z1+a[i][0]*c[i][1]+a[i][1]*c[i][0])%mod
	elif s[i+1]=="?":
		z1,z3 = (z1+a[i][0]*c[i][0])%mod,(z3+a[i][1]*c[i][1])%mod
		z2 = (z2+a[i][0]*c[i][1]+a[i][1]*c[i][0])%mod
for i in range(q-3): num = (num*3)%mod
if q>=3: print((num*z3+num*3*z2+num*9*z1+num*27*z0)%mod)
elif q==2: print((z0*9+z1*3+z2)%mod)
elif q==1: print((z0*3+z1)%mod)
elif q==0: print(z0)

Measured memory_bytes: 30680
N=int(input())
A=list(map(int,input().split()))

if 0 in A:
	print(sum(abs(a) for a in A))
else:
	cnt=sum([1 for a in A if a<0])
	
	if cnt%2==0:
		print(sum(abs(a) for a in A))
	else:
		A=[abs(a) for a in A]
		print(sum(A) -2*min(A))

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


int main(){

  int l,r,d;
  cin >> l>>r>>d;
  int ans =0;
  for(int i =l;i<=r;i++)
  {
    if(i%d == 0)ans++;
  }
  cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>

int main(){
    int n,h,m,flag;

    scanf("%d",&n);
    while(n--){
        scanf("%d:%d",&h,&m);
        switch(h){
            case 0:
                if(m<6)flag=3;
                else if(m<17)flag=2;
                else if(m<50)flag=1;
                else flag=2;
                break;
            case 1:
                if(m<1)flag=2;
                else if(m<11)flag=3;
                else if(m<22)flag=2;
                else if(m<55)flag=1;
                else flag=2;
                break;
            case 2:
                if(m<6)flag=2;
                else if(m<17)flag=3;
                else if(m<28)flag=2;
                else flag=1;
                break;
            case 3:
                if(m<1)flag=1;
                else if(m<11)flag=2;
                else if(m<22)flag=3;
                else if(m<33)flag=2;
                else flag=1;
                break;
            case 4:
                if(m<6)flag=1;
                else if(m<17)flag=2;
                else if(m<28)flag=3;
                else if(m<39)flag=2;
                else flag=1;
                break;
            case 5:
                if(m<11)flag=1;
                else if(m<22)flag=2;
                else if(m<33)flag=3;
                else if(m<44)flag=2;
                else flag=1;
                break;
            case 6:
                if(m<17)flag=1;
                else if(m<28)flag=2;
                else if(m<39)flag=3;
                else if(m<50)flag=2;
                else flag=1;
                break;
            case 7:
                if(m<22)flag=1;
                else if(m<33)flag=2;
                else if(m<44)flag=3;
                else if(m<55)flag=2;
                else flag=1;
                break;
            case 8:
                if(m<28)flag=1;
                else if(m<39)flag=2;
                else if(m<50)flag=3;
                else flag=2;
                break;
            case 9:
                if(m<33)flag=1;
                else if(m<44)flag=2;
                else if(m<55)flag=3;
                else flag=2;
                break;
            case 10:
                if(m<6)flag=2;
                else if(m<39)flag=1;
                else if(m<50)flag=2;
                else flag=3;
                break;
            case 11:
                if(m<11)flag=2;
                else if(m<44)flag=1;
                else if(m<55)flag=2;
                else flag=3;
                break;
        }
        switch(flag){
            case 1:
                puts("safe");
                break;
            case 2:
                puts("warning");
                break;
            case 3:
                puts("alert");
                break;
        }
    }
    return 0;
}

Measured memory_bytes: 580
from collections import Counter
from operator import mul
from functools import reduce
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
    N = int(input())
    factors = [1]
    for i in range(1, N+1):
        factors += prime_factorize(i)
    cnt = Counter(factors)
    cntlst = list(cnt.values())
    
    count74 = sum([1 for val in cntlst if val>=74])
    count24 = sum([1 for val in cntlst if val>=24])
    count14 = sum([1 for val in cntlst if val>=14])
    count4  = sum([1 for val in cntlst if val>=4])
    count2  = sum([1 for val in cntlst if val>=2])
    
    ans = count74 + count24*(count2-1) + count14*(count4-1) \
                + (count4*(count4-1)*(count2-2))//2
    print(ans)

main()

Measured memory_bytes: 3692
package main

import (
	"fmt"
	"strings"
)

func another(s string) string {
	if s == "0" {
		return "1"
	} else {
		return "0"
	}
}

func main() {
	var s []string

	var tmp string
	fmt.Scan(&tmp)
	s = strings.Split(tmp, "")

	var res int
	for i, v := range s {
		if i == 0 {
			continue
		}
		if v == s[i-1] {
			s[i] = another(v)
			res++
		}
	}

	fmt.Println(res)
}


Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int A, B, C, D,a;
	cin >> A >> B >> C >> D;
	a = 0;
	while (A > 0 && B > 0) {
		C = C - B;
		if (C <= 0) {
			a++;
			break;
		}
		A = A - D;
	}
	if (a == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

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

int main(){
  int x, y;
  while(1) {
    cin >> x >> y;
    if ((x == 0) && (y == 0)) {
      break;
    }
    for (int i = 0; i < x; i++) {
      for (int j = 0; j < y; j++) {
        if ((i == 0) || (j == 0) || (i == x - 1) || (j == y - 1)) {
          cout << '#';
        } else {
          cout << '.';
        }
      }
      cout << endl;
    }
    cout <<endl;
  }
}

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

int main(void){
  long long A=0;
  double B=0;

  cin >> A >> B;
  
  long long ib = 100*B+0.5;

  A*=ib;
  A/=100;
  
  cout << A << endl;
  return 0;
}



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

int main(){
    char c;
    const string s = "aeiou";
    cin >> c;
    if(s.find(c)!=string :: npos) cout << "vowel" << endl;
    else cout << "consonant" << endl;
    //cout << s.find(c) == string::npos ? "vowel" : "consonant" <<endl;

    return 0;
}


Measured memory_bytes: 3600
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	count := 0
	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())

		if a != i+1 {
			count++
		}
	}

	if count == 0 || count == 2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#define maxn 105

using namespace std;
typedef long long ll;
const double EPS = 1e-10;

int n;
double W,H;
vector <double> ys;
inline void enter(double y){
  if(y >= 0.0 && y <= H) ys.push_back(y);
}
double x[maxn << 1],y[maxn << 1];
double calc(double ly){
  vector <double> rys;
  for(int i = 1;i <= (n << 1);i++){
    if(x[i] > 0.0){
      rys.push_back(ly + (y[i] - ly) * W / x[i]);
    }else{
      if(y[i] >= ly) rys.push_back(H + 1);
      else rys.push_back(-1);
    }
  }
  sort(rys.begin(),rys.end());
  return max(0.0,min(H,rys[n]) - max(0.0,rys[n - 1]));
}
int main(){
  while(~scanf("%lf%lf%d",&W,&H,&n) && W){
    ys.clear();
    for(int i = 1;i <= (n << 1);i++) scanf("%lf%lf",&x[i],&y[i]);
    ys.push_back(0);
    ys.push_back(H);
    for(int i = 1;i <= (n << 1);i++){
      if(x[i] < W){
        enter(y[i] * W / (W - x[i]));
        enter(H - (H - y[i]) * W / (W - x[i]));
      }
    }
    for(int i = 1;i <= (n << 1);i++){
      for(int j = i + 1;j <= (n << 1);j++){
        if(x[i] != x[j])
          enter(y[i] + (y[j] - y[i]) * x[i] / (x[i] - x[j]));
      }
    }
    sort(ys.begin(),ys.end());
    double ans = 0;
    for(int i = 0;i + 1 < (int)ys.size();i++){
      ans += (ys[i + 1] - ys[i]) * (calc(ys[i] + EPS) + calc(ys[i + 1] - EPS)) / 2.0;
    }
    printf("%.10f\n",ans / H / H);
  }
  return 0;
}


Measured memory_bytes: 3312
n = int(input())
w = []
for i in range(n):
    w.append(input())
ok = True
for i in range(n-1):
    sz = len(w[i])
    if w[i][sz-1] != w[i+1][0]: ok = False
for i in range(n):
    for j in range(n):
        if i != j and w[i] == w[j]:
            ok = False
if ok: print('Yes')
else: print('No')


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>

using namespace std;

int N, K;
map<int, int> A;
int ans;
set<int> kind;
vector<int> v;

int main(void) {
	
	cin >> N >> K;

	for (int n = 0; n < N; ++n) {
		int a; cin >> a;
		kind.insert(a);
		++A[a];
	}

	for (auto m : A) {
		v.push_back(m.second);
	}

	sort(v.begin(), v.end());

	int count = kind.size() - K;

	for (int i = 0; i < count; ++i) {
		ans += v[i];
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 20092
H, W = list(map(int, input().split()))
A = [list(input()) for _ in range(H)]
delh, delw = [], []
for i in range(H):
    if all([True if i == '.' else False for i in A[i]]):
        delh.append(i)
B = [list(x) for x in zip(*A)]
for i in range(W):
    if all([True if i == '.' else False for i in B[i]]):
        delw.append(i)
B = [b for i, b in enumerate(B) if i not in delw]
A = [list(x) for x in zip(*B)]
A = [a for i, a in enumerate(A) if i not in delh]
[print(''.join(a)) for a in A]

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

//関数

int main() {
    //入力
    long S;
    cin>>S;
    
    //計算
    long X=S/100, Y=S%100;
    
    //出力
    if(0<X && X<13){
        if(0<Y && Y<13){
            cout<<"AMBIGUOUS"<<endl;
        }else{
            cout<<"MMYY"<<endl;
        }
    }else{
        if(0<Y && Y<13){
            cout<<"YYMM"<<endl;
        }else{
            cout<<"NA"<<endl;
        }
    }
    
    
}

Measured memory_bytes: 256
(defn count2devide [a i] (if (= 0 (mod a 2)) (count2devide (.intValue (/ a 2)) (+ 1 i)) i))
(let [s (java.util.Scanner. System/in)]
  (let [trash (.nextLine s)])
  (println 
    (reduce
      +
      (map 
        (fn [a] (count2devide (Integer/parseInt a) 0))
        (.split (.nextLine s) " ")))))

Measured memory_bytes: 71984
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <random>
#include <deque>

#define INF_LL 1e18
#define INF 1e9

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()

using namespace std;

using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

const ll MOD = 1e9+7;

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

template<typename T>
void chmax(T &a, T &b){
	a = max(a, b);
}

template<typename T>
void chmin(T &a, T &b){
	a = min(a, b);
}

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

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

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

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

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

class RMQ{
	int n;
	vector<int> dat;
public:
	RMQ(int n_){
		n = 1;
		while(n < n_) n *= 2;
		REP(i, n*2-1){
			dat.push_back(INF);
		}
	}

	void update(int x, int i){
		i += n-1;
		dat[i] = x;
		while(i > 0){
			i = (i-1)/2;
			dat[i] = min(dat[i*2+1], dat[i*2+2]);
		}
	}

	int query(int a, int b, int l, int r, int x){
		if(a <= l && r <= b) return dat[x];
		if(r <= a || b <= l) return INF;

		int res = INF;
		res = min(query(a, b, l, (l+r)/2, x*2+1), query(a, b, (l+r)/2, r, x*2+2));
		return res;
	}
	int query(int a, int b){
		return query(a, b, 0, n, 0);
	}
};

const ll mod = 1e9+7;

int main(void){
	ll H, W, N;
	map<PII, ll> num;
	cin >> H >> W >> N;
	REP(i, N){
		int a, b;
		cin >> a >> b; a--; b--;
		REP(j, 9){
			int tx = b+dx[j], ty = a+dy[j];
			if(1 <= tx && tx < W-1 && 1 <= ty && ty < H-1){
				num[{tx, ty}]++;
			}
		}
	}
	ll res[10] = {};
	ll sum = 0;
	for(auto x : num){
		res[x.second]++;
		if(x.second != 0) sum++;
	}
	cout << (H-2)*(W-2)-sum << endl;
	FOR(i, 1, 10){
		cout << res[i] << endl;
	}
}


Measured memory_bytes: 56448
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    ll n, d;
    cin >> n >> d;

    ll ans = 0; 
    rep(i, n) {
        ll x, y;
        cin >> x >> y;
        if(x*x + y*y <= d*d) {
            ans++;
        }
    }
    
    out(ans);
    re0;
}

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

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

using namespace std;

using ll = long long;

ll gcd(ll x, ll y) {
    while (y != 0) {
        ll r = x % y;
        x = y;
        y = r;
    }
    return x;
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

int main() {
    int N;
    cin >> N;
    ll LCM = 1;
    REP(_, N) {
        ll T;
        cin >> T;
        LCM = lcm(LCM, T);
    }
    cout << LCM << endl;
    return 0;
}

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

int n;
vector<pair<int,int>> task;
int main(){
  cin >> n;
  for(int i = 0; i< n; i++){
    int a, b;
    cin >> a >> b;
    task.emplace_back(b,a);
  }
  sort(task.begin(), task.end());
  int sum = 0;
  bool answer = true;
  for(auto v: task){
    sum += v.second;
    if(v.first < sum){
      answer = false;
      break;
    }
  }
  cout << (answer ? "Yes" : "No") << endl;
  return 0;
}  


Measured memory_bytes: 2420
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto a = readNums!int;
  max(a[0]+a[1], a[0]-a[1], a[0]*a[1]).writeln;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

#define MAX_V 222222
struct edge{int to;long long cap,rev;};

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from,int to,long long cap){
	G[from].push_back((edge){to,cap,G[to].size()});
	G[to].push_back((edge){from,0,G[from].size()-1});
}

void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while(!que.empty())	{
		int v = que.front();que.pop();
		for(int i = 0;i < G[v].size();++i){
			edge &e = G[v][i];
			if(e.cap > 0 && level[e.to] < 0){
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

int dfs(int v ,int t,long long f){
	if(v == t)return f;
	for(int &i = iter[v];i < G[v].size() ;++i){
		edge &e = G[v][i];
		if(e.cap > 0 && level[v] < level[e.to]){
			long long d = dfs(e.to,t,min(f,e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

long long Dinic(int s,int t){
	long long flow = 0;
	while(1){
		bfs(s);
		if(level[t] < 0)return flow;
		memset(iter,0,sizeof(iter));
		long long f;while((f = dfs(s,t,INF)) > 0)flow += f;
	}
}

int E = MAX_V / 2;
int s = MAX_V - 2;
int g = MAX_V - 1;
int mp[MAX_V/2];
int rmp[MAX_V/2];
bool used[MAX_V/2];
bool visited[MAX_V/2];

vector<vector<int>> v(MAX_V / 2);
vector<vector<int>> nv(MAX_V / 2);
vector<pair<int,pair<int,int>>> ans;

void dfs(int num){
	visited[num] = true;
	REP(i,nv[num].size()){
		if(!visited[nv[num][i]]){
			ans.PB(MP(rmp[nv[num][i]], MP(num, nv[num][i])));
			dfs(nv[num][i]);
		}
	}
}

int main(){
	
	int n;cin >> n;
	REP(i,n) {
		if(i != n -1)add_edge(s,i,1);
		add_edge(E+i,g,1);
	}
		
	REP(i,n-1){
		
		int e;cin >> e;
		REP(j,e){
			int tmp;cin >> tmp;tmp--;
			v[i].EB(tmp);
			add_edge(i, E+tmp, 1);
		}
	}
	
	int seica = Dinic(s, g);
	if(seica != n-1){
		cout << -1 << endl;
		return 0;
	}
	
	REP(i,n-1) {
		REP(j,G[i].size()){
			if(G[i][j].cap == 0){
				mp[i] = G[i][j].to - E;
				rmp[mp[i]] = i;
				used[mp[i]] = true;
				break;
			}
		}
	}
	
	REP(i,n-1){
		REP(j,v[i].size()){
			if(v[i][j] != mp[i])nv[v[i][j]].EB(mp[i]);
		}
	}
	
	REP(i,n){
		if(!used[i])dfs(i);
	}
	
	if(ans.size() == n-1){
		sort(ALL(ans));
		REP(i,ans.size()){
			cout << ans[i].SE.FI + 1 << " " << ans[i].SE.SE + 1 << endl;
		}
	}
	else {
		cout << -1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 55520
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    if b - a == c - b:
        print("YES")
    else:
        print("NO")
    return

#B
def B():
    o = S()
    e = S()
    for i in range(len(e)):
        print(o[i] + e[i], end="")
    if len(e) != len(o):
        print(o[-1], end="")
    print()
    return

#C
def C():
    l = [inf] * 27
    n = II()
    for _ in range(n):
        b = [0] * 27
        for si in S():
            b[ord(si) - 97] += 1
        for i in range(27):
            l[i] = min(l[i], b[i])
    ans = []
    for i in range(27):
        ans.append(chr(97 + i) * l[i])
    print("".join(ans))
    return

# D
# 解説AC
# 数式をいじくりまわす必要

def D():
    n, m = LI()
    x = LI()
    y = LI()
    ansx = 0
    ansy = 0
    for num, xi in enumerate(x, start=1):
        ansx += (num - 1) * xi - (n - num) * xi % mod
    for num, yi in enumerate(y, start=1):
        ansy += (num - 1) * yi - (m - num) * yi % mod
    print(ansx * ansy % mod)
    return

#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 74852
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define Liny "Yes\n"
#define Linn "No\n"

int main(){
  string s;cin>>s;
  int r=1,N=s.size();
  if(N%2){r=0;}
  else{
    REP(i,N/2){
      if(s[i*2]!='h'||s[i*2+1]!='i'){r=0;break;}
    }
  }
  cout<<(r?Liny:Linn);
}

Measured memory_bytes: 256
#include <iostream> 
#include <string> 
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 

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

int main(){
    int r;
    cin >> r;
     cout << 2 * r * 3.14 << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  string s,t;
  cin>>s>>t;

  ll n=s.size();
  if(s+t[n]==t)
    yes;
  else
    no;
}



Measured memory_bytes: 3644
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct Node{
  int key;
  struct Node *right,*left,*parent;
};

struct Node *root,*NIL;

void insert(int k){
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;
  z=malloc(sizeof(struct Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key){x=x->left;}
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL) root=z;
  else {
    if(z->key < y->key) y->left=z;
    else y->right=z;
  }
}

void inorder(struct Node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(struct Node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  char *str1="insert";
  char *str2="print";
  char tmp[1000];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",tmp);
    if(strcmp(tmp,str1)==0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(tmp,str2)==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 25132
#include<bits/stdc++.h>
using namespace std;
long long t,n,a[3],d,ans,x,aa[3]={2,3,5};
map<long long,long long>dp;
long long dfs(long long x)
{
	if(dp.count(x))
	{
		return dp[x];
	}
	long long nw=1e18+1e9;
	for(int i=0;i<3;i++)
	{
		if(x%aa[i]==0)
		{
			nw=min(nw,a[i]+dfs(x/aa[i]));
			continue;
		}
		long long jia=aa[i]-x%aa[i],jian=x%aa[i];
		nw=min(nw,jia*d+a[i]+dfs((x+jia)/aa[i]));
		nw=min(nw,jian*d+a[i]+dfs((x-jian)/aa[i]));
	}
	if((long double)x*d<nw)
	{
		nw=x*d;
	}
	dp[x]=nw;
	return nw;
}
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n>>a[0]>>a[1]>>a[2]>>d;
		dp.clear();
		dp[0]=0;
		dp[1]=d;
		cout<<dfs(n)<<endl;
	}
	return 0;
}

Measured memory_bytes: 4460