akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
int main() {
	int H, W, N;
	cin >> H >> W >> N;
	vector<int> a(N);
	for (auto& i : a) cin >> i;
	vector<vector<int>> c(H, vector<int>(W));
	for (int i = 0, h = 0, w = 0, x = 1; i < H * W; i++) {
		c[h][w] = x;
		a[x - 1]--;
		if (a[x - 1] == 0) x++;
		if (w % 2 == 0) {
			if (h == H - 1) w++;
			else h++;
		}
		else {
			if (h == 0) w++;
			else h--;
		}
	}
	for (const auto& v : c) {
		for (const auto& i : v) cout << i << " ";
		cout << endl;
	}
}


Measured memory_bytes: 384
package main

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

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

	nRoutes := scanInt(sc)
	maxTime := scanInt(sc)
	minCost := 9999

	for i := 0; i < nRoutes; i++ {
		cost := scanInt(sc)
		time := scanInt(sc)
		if time <= maxTime && cost < minCost {
			minCost = cost
		}
	}

	if minCost == 9999 {
		fmt.Println("TLE")
	} else {
		fmt.Println(minCost)
	}
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

Measured memory_bytes: 640
MOD = 10**9+7
s = input()
sl = list(s)
n=len(s)
dsl={i:sl[i] for i in range(n)}

dp={i:[0]*13 for i in range(n+1)}

dp[0][0]=1
for i in range(n):
    for k in range(10):
        if dsl[i] != "?" and dsl[i] != str(k):
            continue
        for j in range(13):
            dp[i+1][(j*10+k)%13] += dp[i][j]%MOD

print(dp[n][5]%MOD)


Measured memory_bytes: 83204
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
const int INF = int(1e9)+5;
int H,W;

bool onBoard(int y,int x){
    if(y>=0 && y<H && x>=0 && x<W){
        return true;
    }else{
        return false;
    }
}

int main() {
    cin >> H >>W;
    int d[H][W];
    for(int i=0;i<H;i++)for(int j=0;j<W;j++){
        d[i][j] = INF;
    }

    int Cy,Cx,Dy,Dx;
    cin >> Cy >> Cx >> Dy >>Dx;
    --Cx;--Cy;--Dx;--Dy;
    vector<string> S(H);
    for(int i=0;i<H;i++){
        cin >> S[i];
    }
    priority_queue<P,vector<P>,greater<P>> pq;
    pq.push(P(0,Cy*W+Cx));
    d[Cy][Cx] == 0;

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


    while(!pq.empty()){
        P p = pq.top();
        pq.pop();
        int y = p.second/W;
        int x = p.second%W;
        // cerr <<"y=" << y <<"x=" << x << "val=" << p.first << endl;
        if(d[y][x] < p.first){
            continue;
        }
        for(int i=0;i<4;i++){
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(onBoard(ny,nx) && S[ny][nx] == '.'){
                if(d[ny][nx] > p.first){
                    d[ny][nx] = p.first;
                    pq.push(P(p.first,ny*W+nx));
                }
            
            }
        }
            for(int j=-2;j<3;j++)for(int k=-2;k<3;k++){
                int ny = y + j;
                int nx = x + k;
                if(onBoard(ny,nx) && S[ny][nx] == '.'){
                    if(d[ny][nx] > p.first+1){
                        d[ny][nx] = p.first+1;
                        pq.push(P(p.first+1,ny*W+nx));
                    }
                }

            }
        
    }
    if(d[Dy][Dx] < INF){
        cout << d[Dy][Dx] << endl;
        return 0;
    }
    cout << -1 <<endl;
    return 0;
}

Measured memory_bytes: 9436
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  
char in[105];
auto solve(){
	scanf("%s", in);
 
	int t1 = (in[0] - '0') * 10 + (in[1] - '0');
	int t2 = (in[2] - '0') * 10 + (in[3] - '0');
 
	if (t1 >= 1 && t1 <= 12 && t2 >= 1 && t2 <= 12) return !printf("AMBIGUOUS\n");
	if (t1 >= 1 && t1 <= 12) return !printf("MMYY\n");
	if (t2 >= 1 && t2 <= 12) return !printf("YYMM\n");
	return !printf("NA\n");
}
signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();












#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


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


int arr[100005];
int main(){
    int n,m;
    cin>>n>>m;


    int a;
    string s;

    int x=0,y=0;

    while(m--){
        cin>>a;
        getchar();

        cin>>s;

        if(s=="AC"){
            if(arr[a]==-1)
                continue;



             if(arr[a]>0)
                y=y+(arr[a]-0);

             arr[a]=-1;
             x++;
        }

        else{
            if(arr[a]==-1)
                continue;

            else
                arr[a]++;
        }




    }

             cout<<x<<" "<<y<<endl;

             return 0;


}


Measured memory_bytes: 640
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace contest_Csharp
{

    class Program
    {
        public static (long m, long s)[,] dp;
        public static long mod;
        static void Main(string[] args)
        {
            checked
            {
                var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
                Console.SetOut(sw);

                var vals = Console.ReadLine().Split(' ').
                    Select(x => int.Parse(x)).ToList();


                var N = vals[0];
                //var T = vals[1];
                //var S = vals[2];
                var A= Console.ReadLine().Split(' ').
                    Select(x => long.Parse(x)).ToList();
                mod = (long)1e9 + 7;

                long ans = 0;

                var sumA = new long[N + 1];
                for (int i = 0; i < N; i++)
                {
                    sumA[i + 1] = (A[i] + sumA[i]) % mod;
                }
                for (int i = 0; i < N; i++)
                {
                    ans = (ans + (A[i] * ((sumA[N] - sumA[i + 1])%mod)) % mod) % mod;
                }
                
                Console.WriteLine((ans+mod)%mod);

                Console.Out.Flush();
            }




        }
    }

}




Measured memory_bytes: 49328
i=1
while True:
    x=int(input())
    if x==0:
        break
    x=1000-x
    a=x//500
    b=(x%500)//100
    c=(x%100)//50
    d=(x%50)//10
    e=(x%10)//5
    f=x%5
    print(a+b+c+d+e+f)
    i+=1
    


Measured memory_bytes: 5584
// Solution to https://atcoder.jp/contests/dp/tasks/dp_v
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

int N, MOD;
vector<vector<int>> adj;

// up[node] = number of ways to color the subtree of node that its parent is responsible for, empty coloring included.
// down[node] = number of ways to paint node's subtree where node must be painted black.
vector<int> up, down;

void solve_down(int node, int parent) {
    down[node] = 1;

    if (parent >= 0)
        adj[node].erase(find(adj[node].begin(), adj[node].end(), parent));

    for (int child : adj[node]) {
        solve_down(child, node);
        down[node] = (long long) down[node] * (down[child] + 1) % MOD;
    }
}

void solve_up(int node) {
    int n = adj[node].size();
    vector<int> prefix(n, 1), suffix(n, 1);

    for (int i = 0; i + 1 < n; i++)
        prefix[i + 1] = (long long) prefix[i] * (down[adj[node][i]] + 1) % MOD;

    for (int i = n - 1; i > 0; i--)
        suffix[i - 1] = (long long) suffix[i] * (down[adj[node][i]] + 1) % MOD;

    // Note that both prefix[i] and suffix[i] exclude i.
    for (int i = 0; i < n; i++)
        up[adj[node][i]] = (1 + (long long) prefix[i] * suffix[i] % MOD * up[node]) % MOD;

    for (int child : adj[node])
        solve_up(child);
}

int main() {
    scanf("%d %d", &N, &MOD);
    adj.assign(N, {});

    for (int i = 0; i < N - 1; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    up.assign(N, 1);
    down.assign(N, 1);
    solve_down(0, -1);
    solve_up(0);

    for (int i = 0; i < N; i++)
        printf("%lld\n", (long long) up[i] * down[i] % MOD);
}


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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int n;
    cin>>n;
    n=n*n;
    cout<<n;


    return 0;
}


Measured memory_bytes: 3640
import sys
input = sys.stdin.readline

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0]*n
        self.size = [1]*n

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x != y:
            if self.rank[x] < self.rank[y]:
                self.par[x] = y
                self.size[y] += self.size[x]
            else:
                self.par[y] = x
                self.size[x] += self.size[y]

            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def tree_size(self, x):
        return self.size[self.find(x)]


N = int(input())
a = [-1] + [int(_) for _ in input().split()] + [-1]
uf = UnionFind(N+1)
place = [-1]*(N+1)
ans = 0

for i in range(1, N+1):
    place[a[i]] = i

for i in range(N, 0, -1):
    left = right = 0
    if a[place[i]] < a[place[i]-1]:
        left = uf.tree_size(uf.find(a[place[i]-1]))
        uf.unite(a[place[i]], a[place[i]-1])
    
    if a[place[i]] < a[place[i]+1]:
        right = uf.tree_size(uf.find(a[place[i]+1]))
        uf.unite(a[place[i]], a[place[i]+1])
    
    ans += (left+1)*(right+1)*a[place[i]]

print(ans)

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;
const ll MOD = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(false);
	int N;
	set<pii> st;

	cin >> N;
	rep(i,N){
		int a;
		cin >> a;
		st.emplace(a, 1);
	}
	rep(i,N){
		int b;
		cin >> b;
		st.emplace(b, -1);
	}

	ll ans = 1;
	int cur = 0;
	for(auto p: st){
		auto a = p.X;
		auto d = p.Y;
		if(cur != 0 && cur * d < 0){
			ans = (ans * abs(cur)) % MOD;
		}
		cur += d;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <functional>
#include <math.h>
#include <map>
#include <set>
#include <string>
using namespace std;
#define fio ios::sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;

const int INT_INF = 1e9;
const ll LL_INF = 1e18;
const int MAXN = 500003;

typedef struct GE{
    int to;
    ll w;
    GE(){};
}GE;

int n;
int L[202];
int main() {
    scanf("%d", &n);
    for(int i=0;i<2*n;i++){
        scanf("%d", &L[i]);
    }
    sort(L, L+2*n);

    int ans=0;
    for(int i=0;i<2*n;i+=2){
        ans += L[i];
        // printf("%d ", L[i]);
    }
    // puts("");
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 256
from sys import stdin

if __name__ == '__main__':
    n = int(stdin.readline().rstrip())
    p = list(map(int, stdin.readline().rstrip().split()))

    def get_nexts(p):
        d, e = [n for i in range(n)], [n for i in range(n)]
        stack1, stack2 = [], []
        for i in range(n):
            while stack2 and p[stack2[-1]] < p[i]:
                idx = stack2.pop()
                e[idx] = i

            to_append = []
            while stack1 and p[stack1[-1]] < p[i]:
                idx = stack1.pop()
                d[idx] = i
                to_append.append(idx)

            while to_append:
                stack2.append(to_append.pop())
            stack1.append(i)

        dist1, dist2 = [], []
        for i in range(n):
            dist1.append(d[i] - i)
            dist2.append(e[i] - d[i])
        return dist1, dist2

    dist1, dist2 = get_nexts(p)
    dist3, dist4 = get_nexts(p[::-1])
    dist3, dist4 = dist3[::-1], dist4[::-1]

    ans = 0
    for i in range(n):
        ans += (dist1[i] * dist4[i] + dist2[i] * dist3[i]) * p[i]
    print(ans)


Measured memory_bytes: 76236
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

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

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


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


int main() {

	ll N;
	cin >> N;

	ll f = 0;

	for (ll i = N; i > 0; i /= 10) {
		f += i % 10;
	}

	if (N%f == 0) { cout << "Yes"; }
	else { cout << "No"; }

	system("PAUSE");

	

}


Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
int main(void) {
  long long x;
  int ans=0;
  cin >> x;
  long long i=100;
  while(true) {
    i = i + (i * 0.01);
    ++ans;
    if(i>=x) break;
  }
  cout << ans << endl;
}

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

class Node:
    def __init__(self, sigma, depth):
        self.end = False
        self.child = [None] * sigma
        self.depth = depth
    def __setitem__(self, i, x):
        self.child[i] = x
    def __getitem__(self, i):
        return self.child[i]

sigma = 2
root = Node(sigma, 0)
def add_trie(S):
    vn = root
    for cs in S:
        if vn[cs] is None:
            vn[cs] = Node(sigma, vn.depth + 1)
        vn = vn[cs]
    vn.end = True

ans = 0

N, L = map(int, readline().split())

for _ in range(N):
    S = list(map(int, readline().strip()))
    add_trie(S)

cnt = 0
stack = [root]
while stack:
    vn = stack.pop()
    for i in range(2):
        if vn[i] is None:
            r = L - vn.depth
            cnt ^= -r&r
        else:
            stack.append(vn[i])

print('Alice' if cnt else 'Bob')

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

vector<int> tree;

int gcd(int a,int b){
  if(a==0||b==0){
    return max(a,b);
  }
  int c;
  c=a%b;
  while(c!=0){
    a=b;
    b=c;
    c=a%b;
  }
  return b;
}

int solve(int a,int b,int i,int l,int r){
  if(r<=a||b<=l){
    return 0;
  }
  if(a<=l&&r<=b){
    return tree.at(i);
  }
  int x=solve(a,b,2*i+1,l,(l+r)/2);
  int y=solve(a,b,2*i+2,(l+r)/2,r);
  return gcd(x,y);
}

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  
  int n=1;
  while(n<N){
    n<<=1;
  }
  tree.resize(2*n-1,0);
  for(int i=0;i<N;i++){
    tree.at(i+n-1)=A.at(i);
  }
  for(int i=n-2;i>=0;i--){
    tree.at(i)=gcd(tree.at(2*i+1),tree.at(2*i+2));
  }
  
  int ans=1;
  for(int i=0;i<N;i++){
    int x1=solve(0,i,0,0,n);
    int x2=solve(i+1,n,0,0,n);
    ans=max(ans,gcd(x1,x2));
  }
  cout<<ans<<endl;
}
  
  
  
  

Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}
const int MAX=100002;
const int MOD=1000000007;
ll fac[MAX],finv[MAX],inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main(void) {
    COMinit();
    ll n, m; cin >> n >> m;
    if(n < m) swap(n, m);
    if(n - m > 1) {
        print(0);
        return 0;
    }
    ll ans = fac[m] * fac[n] % MOD;
    if(n == m) {
        ans = ans * 2 % MOD;
    }

    print(ans);


    return 0;
}


Measured memory_bytes: 2560
a, b = map(int, input().split())
an = 1
bn = 1

if a - b >= 2 or b - a >= 2 :
    print (0)
elif a == b :
    for i in range(a) :
        an = (an * (i + 1)) % 1000000007
        bn = (bn * (i + 1)) % 1000000007
    print ((2 * an * bn)% 1000000007)
else :
    if b > a :
      a, b = b, a 
    for i in range(a) :
        an = (an * (i + 1)) % 1000000007
    for i in range(b) :
        bn = (bn * (i + 1)) % 1000000007
    print ((an * bn)% 1000000007)

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

long gcd(long a,long b){
    //swap
    if(a>b){
        long temp = a;
        a = b;
        b = temp;
    }

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

int main()
{
    long N,X;
    std::cin >> N >> X;
    std::vector<long> x;
    for(long i=0; i<N; i++){
        long temp;
        std::cin >> temp;
        temp = temp -X;
        if(temp<0){
            temp = (-1)*temp;
        }
        x.push_back(temp);
    }
    std::sort(x.begin(),x.end());
    long gcdtemp = x[0];
    for(long i=1; i<N; i++){
        gcdtemp = gcd(x[i],gcdtemp);
    }
    std::cout << gcdtemp << std::endl;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, q, c, e, d[111111]; long long t, x[111111], y[111111];
int main() {
	scanf("%d%lld%d", &n, &t, &q);
	for (int i = 0; i < n; i++) scanf("%lld%d", x + i, d + i);
	for (int i = 1; i < n; i++) if (d[i] - d[i - 1] == 1) y[c++] = (x[i - 1] + x[i]) / 2;
	for (int i = 0; i < q; i++) {
		scanf("%d", &e); e--;
		int ptr = lower_bound(y, y + c, x[e]) - y;
		long long ret = x[e] + t * (d[e] * -2 + 3);
		if (d[e] == 1) { if (ptr != c) ret = min(ret, y[ptr]); }
		else if (--ptr != -1) ret = max(ret, y[ptr]);
		printf("%lld\n", ret);
	}
	return 0;
}

Measured memory_bytes: 4568
x,y,z,k = gets.split(' ')
x = x.to_i
y = y.to_i
z = z.to_i
k = k.to_i
a = gets.split(' ').map{|i|i.to_i}[0..3001]
b = gets.split(' ').map{|i|i.to_i}[0..3001]
c = gets.split(' ').map{|i|i.to_i}[0..3001]

ab = Array.new
a.each do |a_i|
  b.each do |b_i|
    ab << a_i + b_i
  end
end
ab = ab.sort.reverse
abc = Array.new
ab.each_with_index do |ab_i, i|
  if i > 3001
    break
  end
  c.each_with_index do |c_i, i|
    abc << ab_i + c_i
  end
end

abc = abc.sort.reverse

k.times do |k_i|
  puts abc[k_i]
end



Measured memory_bytes: 92764
#include <iostream>

 

using namespace std;

 

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


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

int main()
{
	int A,B,X,Entrou= 0;
	cin>>A>>B>>X;
	
	for(int i = 0; i <= B; i++)
	{
		if(A+i == X){
			cout<<"YES"<<endl;
			Entrou = 1;
		}
	}
	if(Entrou == 0)
	{
		cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
macro_rules! bind_from_vec {
    ( $($variable:ident),+ = $vector:expr ) => {
        let mut v = $vector.clone().into_iter();
        $(let $variable = v.next().unwrap();)+
    };
}

macro_rules! read_line {
    () => {{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        input
    }};
}

pub fn read_to_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line!().split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn pow_mod(base: usize, exp: usize, modulo: usize) -> usize {
    (0..std::mem::size_of::<usize>() * 8).rev()
        .fold(1, |acc, i|
            (acc.pow(2).rem_euclid(modulo) * base.pow((exp >> i & 1) as u32)).rem_euclid(modulo)
        )
}

fn main() {
    const MOD: usize = 1_000_000_000 + 7;

    bind_from_vec!(n, k = read_to_vec());

    let mut mem = Vec::with_capacity(k);
    mem.resize(k, 0);

    for x in (1..=k).rev() {
        mem[x - 1] = pow_mod(k/x, n, MOD);
        for i in 2..=k/x {
            mem[x - 1] = (MOD + mem[x - 1] - mem[(i * x) - 1] % MOD) % MOD;
            mem[x - 1] %= MOD;
        }
    }

    let mut ans = 0;

    for i in 1..=k {
        ans += i * mem[i - 1] % MOD;
        ans %= MOD;
    }

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


Measured memory_bytes: 2844
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//


int main() {

    int N, Q; cin >> N >> Q;
    vector<vector<int>> child(N+1);
    for (int i = 1; i <= N - 1; ++i) {
        int a, b; cin >> a >> b;
        child[a].push_back(b);
        child[b].push_back(a);
    }

    int cnt[N+1]; rep(i,N+1) cnt[i] = 0;
    rep(i,Q) {
        int p, x; cin >> p >> x;
        cnt[p] += x;
    }

    bool seen[N+1]; rep(i,N+1) seen[i] = false;
    queue<int> st;
    st.push(1);
    while(!st.empty()) {
        int a = st.front();
        st.pop();
        seen[a] = true;
        rep(i,child[a].size()) {
            int b = child[a][i];
            if (!seen[b]) {
                st.push(b);
                cnt[b] += cnt[a];
            }
        }
    }

    for (int i = 1; i <= N; ++i) {
        out(cnt[i]);
    }


    return 0;
}









Measured memory_bytes: 15732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> Pii;
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1e17
#define rep(i,a,b) for(int i =(a);i<(b);i++)
#define fs first
#define ss second
inline int Scan() {
    int x=0;int f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

template<typename T, typename U>
static inline void amin(T &x, U y)
{
    if (y < x)
        x = y;
}

// call by reference is used in x
template<typename T, typename U>
static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
//////////////////////////////////////end of template//////////////////////////////////////

ll a[100000],b[100000],c[100000];
   
ll mat[305][305];
ll dist[305][305];

ll s[105000],t[105000];

int main(){
	
   ios::sync_with_stdio(false);
   cin.tie(NULL); 
  
   ll n,m,l;
   cin >> n >> m >> l;
   
   
   
   for(int i =1;i<=m;i++) cin >> a[i] >> b[i] >> c[i];
   
   ll q;
   cin >> q;
  
   
   for(int i =1;i<=q;i++) cin >> s[i] >> t[i];
   
   for(int i = 1;i<=n;i++){
	   for(int j =1;j<=n;j++){       
	           mat[i][j] = INF;
	           dist[i][j] = INF;
	   }
	   mat[i][i] =  0;
	   dist[i][i] = 0;
   }
   
   
   for(int i =1;i<=m;i++){
	   for(int j =1;j<=m;j++){
            mat[a[i]][b[i]] = c[i];
            mat[b[i]][a[i]] = c[i];
       }
   }
   
   
   
   //cout <<"INPUT"<<endl;
   
   for(int i =1;i<=n;i++){
	   for(int j =1;j<=n;j++){
		 for(int k =1;k<=n;k++){
			  amin(mat[j][k],mat[j][i]+mat[i][k]);
		 }   
	   }
   }
   
   for(int i =1;i<=n;i++){
	   for(int j =1;j<=n;j++){
        if( i == j) continue;
        if( mat[i][j] <= l) amin(dist[i][j],1ll);
        }
   }
   
   
   for(int i = 1;i<=n;i++){
	   for(int j =1;j<=n;j++){
		 for(int k =1;k<=n;k++){   
	          amin(dist[j][k],dist[j][i] + dist[i][k]);
	      }
	   }
   }
   
   for(int i =1;i<=q;i++){
     if( dist[s[i]][t[i]] < INF)  cout << dist[s[i]][t[i]] -1 <<endl;
     else cout << -1 <<endl; 
   }
   
    

}




Measured memory_bytes: 4736
import heapq

n = int(input())
# n = 3

arr = [0]*n

pq = []
for i in range(n):
	arr[i] = int(input())
	heapq.heappush(pq, (-arr[i], i))
heapq.heapify(pq)
lg = heapq.heappop(pq)
slg = heapq.heappop(pq)
lg, slg = lg[1], slg[1]

for i in range(n):
	if i==lg:
		print(arr[slg])
	else:
		print(arr[lg])

Measured memory_bytes: 93016
from collections import deque
N = int(input())

G = {k: [] for k in range(N)}
for _ in range(N-1):
    a, b = map(int, input().split())
    # 無向グラフ
    G[a-1].append(b-1)
    G[b-1].append(a-1)


def bfs(i):
    visited = [-1 for _ in range(N)]
    visited[i] = 0
    que = deque([(i, 0)])

    while que:
        ci, d = que.popleft()

        for ni in G[ci]:
            if visited[ni] == -1:
                visited[ni] = d+1
                que.append((ni, d+1))

    return visited


F = bfs(0)
S = bfs(N-1)


ans = 0
for i in range(N):
    if F[i] <= S[i]:
        ans += 1
    else:
        ans -= 1
if ans > 0:
    print('Fennec')
else:
    print('Snuke')


Measured memory_bytes: 72036
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};



int main(){
  I n;
  cin >> n;
  UnionFind<I> uf(n+1);
  REP(i,n-1){
    I u,v,w;
    cin >> u >> v >> w;
    uf.merge(u,v,w);
  }
  REP(i,n+1){
    if (i==0) continue;
    if (uf.weight(i) % 2 == 0){
      cout << 0 << endl;
    }else{
      cout << 1 << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 2048
#include<iostream>
#include <vector>
#include <string>

using namespace std;

vector<string> split(const string &str, char delim){
  vector<string> res;
  size_t current = 0, found;
  while((found = str.find_first_of(delim, current)) != string::npos){
    res.push_back(string(str, current, found - current));
    current = found + 1;
  }
  res.push_back(string(str, current, str.size() - current));
  return res;
}


int  main()
{
	string str;
	
	getline(cin, str);
	int N = stoi(str);
	
	getline(cin, str);
	vector<string> str_v;
	str_v = split(str, ' ');
	
	int count_o = 0;
	for(int n = 0; n<N; n++){
		if(stoi(str_v[n])%2 == 1)	count_o++;
	}
	
	
	if(count_o%2 == 1){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}
	
	return 0 ;
}

Measured memory_bytes: 6656
<?php
$w = strtolower(trim(fgets(STDIN)));
$t='';
$cnt = 0;
$array=array();
while ($line = fgets(STDIN)) {
   $t .= strtolower(trim($line)." ");
}

$array = explode(" ", $t);

foreach($array as $hoge){
    if ($hoge === $w) {
        $cnt++;
    }
}
echo $cnt.PHP_EOL;
?>


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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO  = "No";

int func(long long N, std::vector<long long> H) {
    rep(i, N - 1) {
        if (H[i] <= H[i + 1]) {
            continue;
        } else {
            if (H[i + 1] - H[i] == -1) {
                H[i + 1]++;
            } else {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld", &N);
    // cin >> N;
    std::vector<long long> H(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &H[i]);
        // cin >> H[i];
    }
    func(N, std::move(H));
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long x, k, d;
    cin >> x >> k >> d;
    if(x < 0){
        x = -x;
    }
    
    if(x / d > k){
        cout << x - d * k;
    }
    else{
        //最小が正側
        if(x % d < abs(x % d - d)){
            if((k - x / d) % 2 == 0){
                cout << x % d;
            }
            else{
                cout << abs(x % d - d);
            }
        }
        //最小が負側
        else{
            if((k - x / d + 1) % 2 == 0){
                cout << abs(x % d - d);
            }
            else{
                cout << x % d;
            }
        }
        //cout << x / d << '\n';
        
    }
    
    return 0;
}


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

int keta(int x){
    if(x==0) return 0;
    return keta(x/10) +(x%10);
}

int main(){
    int n;cin>>n;
    int ans=10000000;
    for(int i=1;i<n;i++){
        int b=n-i;
        ans=min(ans,keta(i)+keta(b));
        
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from math import sqrt
x = int(input())

ps = []
for i in range(1, int(sqrt(x)) + 1):
  if x % i == 0:
    ps.append(i)
    ps.append(x // i)

for p_ in ps:
  for p in (-p_, p_):
    for r in (-1, 1):
      for s in (-1, 1):
        try:
            a = (p + r * sqrt(-5 * p**2 + s * (2 * sqrt(5) *
                                              sqrt(p ** 6 + 4 * p * x)) / p) / sqrt(5)) / 2
            if abs(a - round(a)) < 1e-6:
              a = round(a)
              print(a, a - p)
              exit()
        except ValueError:
          pass


Measured memory_bytes: 9248
INF, NVINF = float("inf"), 10**5
N, W = map(int,input().split())
dp = [0] + [INF] * NVINF
for _ in [None]*N:
  w, v = map(int,input().split())
  for j in range(NVINF, v-1, -1):
    dp[j] = min(dp[j], dp[j - v] + w)
for v, w in list(enumerate(dp))[::-1]:
    if w <= W:
      exit(print(v))

Measured memory_bytes: 87776
//https://atcoder.jp/contests/abc140/tasks/abc140_c
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
//    cin.tie(0);
//    ios::sync_with_stdio(false);
    ll N; cin>>N;
    vector<ll> bn(N-1);
    vector<ll> an(N);
    for(auto&& b:bn){
        cin>>b;
    }

    an[0]=bn[0];
    FOR(i,1,N){
        an[i]=bn[i-1];
        an[i-1]=min(an[i-1],bn[i-1]);
    }
    ll ans = 0;
    for(const auto& a:an){
        ans+=a;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
int main(){
	int a,b;
	char op;
	while(true){
		std::cin >> a >>op >> b;
		if(op == '?'){
			break;
    }else if(op == '+'){
		std::cout <<a + b<<std::endl;
	}else if(op == '-'){
		std::cout <<a - b<<std::endl; 
	}else if(op == '*'){
		std::cout <<a * b<<std::endl;
	}else if(op == '/'){
		std::cout <<a / b<<std::endl;
	}}}

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

using namespace std;

int main(){
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  int set = min(A+B,C+C);
  int manyp = max(X,Y);
  int minp  = min(X,Y);
  int summin= minp*set;
  if(minp==X){
    summin+=(Y-minp)*B;
  }else{
    summin+=(X-minp)*A;
  }
  int summax= manyp*set;
  cout << min(summax,summin) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>

using namespace std;

struct Node {
    int key;
    Node *next, *prev;
};

Node *nil;

void init() {
    nil = (Node*)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void Insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

void deleteNode(Node *cur) {
    if(cur == nil)return;

    cur->prev->next = cur->next;
    cur->next->prev = cur->prev;
    free(cur);
}
void Delete(int key) {
    Node *cur = nil->next;
    while(cur!=nil && cur->key!=key) {
        cur = cur->next;
    }
    deleteNode(cur);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void printList() {
    Node *cur = nil->next;
    int isf = 0;
    while(true) {
        if(cur == nil)break;
        if(isf++ > 0)printf(" ");
        printf("%d",cur->key);
        cur = cur->next;
    }
    printf("\n");
}

int main() {
    int n, key, Size = 0;
    char com[20];
    int np = 0, nd = 0;
    cin>>n;
    init();
    for(int i=0; i<n; i++) {
        scanf("%s", com);
        if(!strcmp(com,"insert")) {
            scanf("%d", &key);
            Insert(key);
        } else if(!strcmp(com, "delete")) {
            scanf("%d",&key);
            Delete(key);
        } else if(!strcmp(com, "deleteFirst")) {
            deleteFirst();
        } else if(!strcmp(com, "deleteLast"))deleteLast();
    }
    printList();
    return 0;
}



Measured memory_bytes: 34436
#include <iostream>
#include <stdio.h>
#include <string>
#define llint long long
#define inf 1e18

using namespace std;

llint n, k;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	
	llint ub = k+1, lb = 0, mid;
	while(ub-lb>1){
		mid = (ub+lb)/2;
		llint sum = mid, x = mid;
		for(int i = 2; i <= n; i++){
			x /= 2;
			if(x == 0) break;
			sum += x;
		}
		if(sum <= k) lb = mid;
		else ub = mid;
	}
	cout << lb << endl;
	
	return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = long long;
int main(){
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i,N) cin >> p[i];

    int ans = 0;
    for(int i=1;i<N-1;i++){
        if(p[i-1] < p[i] && p[i] < p[i+1]) ans++;
        else if(p[i+1] < p[i] && p[i] < p[i-1]) ans++;
    }

    cout << ans << endl;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define MOD 1000000007
typedef long long ll;

int main(){

	int n,m;cin >> n >> m;
	ll x = 0,y = 0;
	REP(i,n){
		ll tmp;cin >> tmp;
		x += i * tmp % MOD;x %= MOD;
		x += (n - i - 1) * ((MOD - tmp) % MOD) % MOD;x %= MOD;
	}

	REP(i,m){
		ll tmp;cin >> tmp;
		y += i * tmp % MOD;y %= MOD;
		y += (m - i - 1) * ((MOD - tmp) % MOD) % MOD;y %= MOD;
	}

	cout << x * y % MOD << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	
	int a,b,c,i,count;
	
	count=0;
	
	scanf("%d %d %d",&a,&b,&c);
	
	for(i=a;i<=b;i++){
		if(c%i==0){
			count++;
		}
	}
	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		string p,q;
      	cin>>p>>q;
      int cnt=0;
      if(p[0]==q[0])
        cnt++;
      if(p[1]==q[1])
        cnt++;
      if(p[2]==q[2])
        cnt++;
      cout<<cnt;
	}
	return 0;
}

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

int cnt[200001],n,k;
int main() {
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++) {
        int v;
        scanf("%d",&v);
        cnt[v]++;
    }
    vector<int> arr;
    for(int i=1;i<=n;i++) arr.push_back(cnt[i]);
    sort(arr.begin(),arr.end());

    int ans=0;
    for(int i=0;i<n-k;i++) ans+=arr[i];
    printf("%d\n",ans);
    
    return 0;
}


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

int a, b, m, ans;
int cost[100001][2];

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> a >> b >> m;
    int n1 = INT_MAX, n2 = INT_MAX;
    for (int i = 1; i <= a; i++) {
        cin >> cost[i][0];
        n1 = min(n1, cost[i][0]);
    }
    for (int i = 1; i <= b; i++) {
        cin >> cost[i][1];
        n2 = min(n2, cost[i][1]);
    }
    ans = n1 + n2;
    for (int i = 1; i <= m; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        ans = min(ans, cost[x][0] + cost[y][1] - c);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
/**
 * A × B を求めてください。
 */

export function Main(input: string) {
  // 問題文解体エリア
  const inputs = input.split(" ");
  const num1 = new Number(inputs[0]).valueOf();
  const num2 = new Number(inputs[1]).valueOf();

  // 問題解決エリア
  const answer = fuck(num1, num2);

  //出力エリア
  console.log(answer);
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
// 提出する時にコメントアウト解除せよ
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

export function fuck(num1: number, num2: number): number {
  return num1 * num2;
}



Measured memory_bytes: 29580
n = int(input())
card = list(map(int, input().split()))

card.sort()
card.reverse()

a = 0
b = 0
for i in range (n) :
  if i % 2 == 0 :
    a = a + card[i]
  else :
    b = b + card[i]

print (a-b)

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

int hashad(int x) {
    int sum = 0;
    while(x != 0) {
        sum += x % 10;
        x /= 10;
    }
    return sum;
} 
int main() {
    int n;
    cin >> n;
    if (n % hashad(n) == 0) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll winpoint(char aite, ll R, ll S, ll P){
    if(aite=='r') return P;
    else if(aite=='s') return R;
    return S;
}
char winte(char aite){
    if(aite=='r') return 'p';
    else if(aite=='s') return 'r';
    return 's';
}
int main(){
  ll N,K; cin >> N >> K;
  ll R, S, P; cin >> R >> S >> P;
  string T; cin >> T;

  char forbidden[N];
  ll ans = 0;
  string t[K];
  for(ll i=0; i<N; i++){
    t[i%K]+=T[i];
  }
  for(ll i=0; i<K; i++){
    char prev=' ';
    for(ll j=0; j<t[i].length(); j++){
      char aite=t[i][j];
      char jibunte=winte(aite);
      if(prev!=jibunte){
        ans+=winpoint(aite, R, S, P);
        prev=jibunte;
        continue;
      }
      prev=' ';
      
    }
  }
  cout << ans;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1e+9;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w",stdout);
    #endif
    int n;
    cin>>n;
    vector<int> h(n);
    for(int& i: h){
        cin>>i;
    }
    vector<int> dp(n, INF);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i=2; i<n; i++){
        dp[i] = min (  (dp[i-1] + abs(h[i] - h[i-1])) , (dp[i-2] + abs(h[i] - h[i-2]))   );
    }

    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 3920