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

using namespace std;

int n,m;
vector<vector<int>> g;
vector<int> ans;
vector<bool> used;


void bfs(int start){
	queue<int> q;
	q.push(start);
	used[start] = true;
	while(!q.empty()){
		int node = q.front();
		q.pop();
		for(int u : g[node]){
			if(!used[u]){
				ans[u] = node;
				q.push(u);
				used[u] = true;
			}
		}
	}
	
}

void read(){
	cin >> n >> m;
	g.resize(n);
	ans.resize(n,-1);
	used.resize(n);
	for(int i = 0; i < m; i++){
		int u,v; cin >> u >> v;
		--u,--v;
		g[u].push_back(v);
		g[v].push_back(u);	
	}
}


int main(){
	read();
	bfs(0);
	for(int i = 1; i < n; i++){
		if(ans[i]==-1){
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	for(int i = 1; i < n; i++){
		cout << ans[i] + 1 << "\n";
	}
	return 0;
}


Measured memory_bytes: 10176
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


ll dp[101][100001];

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

    ll n, W, tmpw, tmpv;
    vector<ll> w, v;
    cin >> n >> W;
    rep(i, n){
        cin >> tmpw >> tmpv;
        w.push_back(tmpw);
        v.push_back(tmpv);
    }

    dp[0][0] = 0;

    rep(i, n){
        rep(ww, W+1){
            if(ww + w[i] <= W) dp[i+1][ww+w[i]] = max(dp[i+1][ww+w[i]], dp[i][ww] + v[i]);
            dp[i+1][ww] = max(dp[i+1][ww], dp[i][ww]);
        }
    }

    ll res = 0;
    rep(i, W+1){
        res = max(res, dp[n][i]);
    }

    cout << res << endl;

    return 0;
}

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

int main() {
    long int n,a,b,sum=0;
    int flag =0;
    cin>>n;
    vector< pair <int,int> > vect;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        cin>>b;
        vect.push_back(make_pair(b,a));
    }
    sort(vect.begin(), vect.end());
    for(int i=0;i<n;i++)
    {
        if(sum+vect[i].second<=vect[i].first)
            sum += vect[i].second;
        else
        {
            flag =1;
            break;
        }
    }
    if(flag==1)
    cout<<"No";
    else
    cout<<"Yes";
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main(void){
    int n,i,j;
    double dt=0.5;
    cin>>n;
    vector<int> timetable = {0};
    vector<int> v_max;
    vector<double> v_table;
    for(i=0;i<n;i++){
        int tmp;
        cin>>tmp;
        timetable.push_back(tmp+timetable[i]);
    }
    for(i=0;i<n;i++){
        int tmp;
        cin>>tmp;
        v_max.push_back(tmp);
    }
    for(i=0;i<timetable.back()*2;i++){
        v_table.push_back((i<timetable.back())?i*0.5:(timetable.back()*2-i)*0.5);
    }
    for(i=0;i<n;i++){
        double t_s=timetable[i], t_e=timetable[i+1], v;
        for(j=0;j<v_table.size();j++){
            if(j*dt<t_s) v=v_max[i]+(t_s-j*dt);
            else if(t_s<=j*dt && j*dt<=t_e) v=v_max[i];
            else v=v_max[i]+(j*dt-t_e);
            v_table[j]=min(v_table[j],v);
        }
    }
    printf("%.4lf\n",accumulate(v_table.begin(), v_table.end(), 0.000000)*dt);
    //cout<<accumulate(v_table.begin(), v_table.end(), 0.000000)*dt<<endl;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
    
    int n;
    cin >> n;
    V<int> c(n-1), s(n-1), f(n-1);
    rep(i,n-1) cin >> c[i] >> s[i] >> f[i];

    rep(i,n) {
        int t = 0;
        for(int j = i; j < n-1; j++) {
            if(t <= s[j]) t = s[j] + c[j];
            else {
                int roop = ceil(t-s[j], f[j]);
                t = s[j] + roop*f[j] + c[j];
            }
        }
        cout << t << endl;
    }
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a) {if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(int a) {if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int n,ans=1,check=0;
    cin>>n;
    Vi a(n);
    REP(i,0,n) cin>>a[i];
    
    REP(i,0,n-1){
        if(check==0){
            if(a[i+1]>a[i]) check=1;
            if(a[i+1]<a[i]) check=2;
        }else if(check==1){
            if(a[i+1]<a[i]){
                ans++;
                check=0;
            }
        }else if(check==2){
            if(a[i+1]>a[i]){
                ans++;
                check=0;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
#include<set>
#include<vector>
using namespace std;
#define INF 1<<21


int main(){
    int N;
    int a;
    int sum;
    int ans=0;
    int A[100005];
    memset(A,0,sizeof(A));
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>a;
        A[a]++;
    }
    for(int i=0;i<100003;i++){
        sum=0;
        sum+=A[i]+A[i+1]+A[i+2];
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
}


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

int main() {
    int N; cin >> N;
    int res = 0;
    for(int i=1; i<=N; ++i) {
        int a; cin >> a;
        if((i & 1) && (a & 1)) ++res;
    }
    cout << res << '\n';
}

Measured memory_bytes: 3592
n, m = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
_sum = sum(A)
th = _sum / (4*m)
cnt = 0

for a in A:
    if a >= th:
        cnt += 1
if cnt >= m:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    int n,m;
    cin>>n;
    map<string,int> a;
    REP(i,n){
        string st;
        cin>>st;
        a[st]++;
    }
    cin>>m;
    map<string,int> b;
    REP(i,m){
        string st;
        cin>>st;
        b[st]++;
    }
    int ans=0;
    for(auto itr:a){
        ans=max(ans,max(0,itr.se-b[itr.fi]));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, T;
  cin >> N >> T;
  vector<ll> t(N);
  for (int i = 0; i < N; i++) {
    cin >> t[i];
  }
  ll ans = T;
  ll cur = 0;
  for (int i = 1; i < N; i++) {
    if (t[i] < cur + T) {
      ans += t[i] - cur;
    } else {
      ans += T;
    }
    cur = t[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4740
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main(){
ll n;
cin>>n;
if(n==1||n%2==1){
cout<<0<<endl;}
else{
	ll ans=0;
 for(ll i=10;i<=n;i*=5){
        ans+=n/i;
    }
    cout<<ans<<endl;
}

}


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

long int number[(int)1e5 + 1] = {0};

int main() {
    long int N, K;
    cin >> N >> K;
    long int a, b;
    for (int i = 0; i < N; ++i) {
        cin >> a >> b;
        number[a] += b;
    }
    for (int i = 0; i < 1e5 + 1; ++i) {
        K -= number[i];
        if(K <= 0) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define L long long
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define aa first
#define bb second
#define xx aa.aa
#define yy aa.bb
#define zz bb
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
using namespace std;
int n,w[100010],p;
vi a[100010],b[100010],x[100010];
inline int dfs(int i,vi a[])
{
	int k=0;
	for(auto j:a[i])
	  {
	   int l=dfs(j,a);
	   if(!k)
	     k=l;
	   else
	     {
		  x[k].pb(l);
		  x[l].pb(k);
		  k=0;
		 }
	  }
	if(k)
	  {
	   if(w[i]==3)
	     p=1;
	   else
	     w[i]=2;
	   return k;
	  }
	else
	  {
	   if(w[i]==2)
	     p=1;
	   else
	     w[i]=3;
	   return i;
	  }
}
inline void dfs(int i)
{
	for(auto j:x[i])
	  if(w[j]==3)
	    w[j]=-w[i],dfs(j);
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	  {
	   scanf("%d",&j);
	   if(j==-1)
	     j=0;
	   a[j].pb(i);
	  }
	for(i=1;i<=n;i++)
	  {
	   scanf("%d",&j);
	   if(j==-1)
	     j=0;
	   b[j].pb(i);
	  }
	dfs(0,a);
	dfs(0,b);
	if(p)
	  {
	   printf("IMPOSSIBLE");
	   return 0;
	  }
	for(i=1;i<=n;i++)
	  if(w[i]==2)
	    w[i]=0;
	  else if(w[i]==3)
	    {
		 w[i]=1;
		 dfs(i);
		}
	printf("POSSIBLE\n");
	for(i=1;i<=n;i++)
	  printf("%d ",w[i]);
	return 0;
}


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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef long long ll;

const int MOD = 1000000007;

ll extgcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll d = extgcd(b, a % b, y, x);
  y -= a / b * x;
  return d;
}

void cmb_init(int n, vll &fac, vll &finv) {
  vll inv(n + 1, 1);
  for (int i = 2; i <= n; 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;
  }
}

ll cmb(int n, int k, vll &fac, vll &finv) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void solve() {
  int N, K;
  cin >> N >> K;
  vi A(N, 0);
  vll fac(N + 1, 1), finv(N + 1, 1);
  cmb_init(N, fac, finv);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(all(A));
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    sum -= (ll)A[i] * cmb(N - i - 1, K - 1, fac, finv) % MOD;
    sum += (ll)A[i] * cmb(i, K - 1, fac, finv) % MOD;
    sum %= MOD;
  }
  cout << sum << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 2944
// AOJ 2618: Trip to Kyoto
// 2018.1.25 bal4u@uu

#include <stdio.h>

#define ABS(a)    ((a)>=0?(a):-(a))
#define MIN(a,b)  ((a)<=(b)?(a):(b))

int x1[10002], y1[10002], x2[10002], y2[10002];
char *msg[2] = { "%d.0\n", "%d.5\n" };

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	if (c == '-') {
		c = getchar_unlocked();
		do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
		while (c >= '0');
		return -n;
	}
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int calc(int x1, int y1, int x2, int y2)
{
	x1 += 200000000, y1 += 200000000;
	x2 += 200000000, y2 += 200000000;
	if (x1%20 == 0 && x2%20 == 0) {
		if      (x1 == x2) return ABS(y1-y2);
		else if (y1/20 == y2/20) return ABS(x1-x2) + MIN(y1%20+y2%20, 40-y1%20-y2%20);
	} else if (y1%20 == 0 && y2%20 == 0) {
		if      (y1 == y2) return ABS(x1-x2);
		else if (x1/20 == x2/20) return ABS(y1-y2) + MIN(x1%20+x2%20, 40-x1%20-x2%20);
	}
	return ABS(x1-x2) + ABS(y1-y2);
}

int main()
{
	int n, x, y, i, j, k, s, t, ans;
	int xmin, xmax, ymin, ymax;
	int x0, y0;

	n = in();
	xmin = ymin = 1000000000, xmax = ymax = -1000000000; 
	for (i = 0; i < n; i++) {
		x = in(), y = in();
		x <<= 1, y <<= 1;
		x1[i] = x,   y1[i] = y;
		x2[i] = x+y, y2[i] = x-y;
		if (x2[i] < xmin) xmin = x2[i];
		if (x2[i] > xmax) xmax = x2[i];
		if (y2[i] < ymin) ymin = y2[i];
		if (y2[i] > ymax) ymax = y2[i];
	}
 
	x = (xmin + xmax) >> 1, y = (ymin + ymax) >> 1;
	x0 = (x + y) >> 1, y0 = (x - y) >> 1;

	ans = 0x7fffffff;
	for (i = x0-50; i <= x0+50; i++) {
		for (j = y0-50; j <= y0+50; j++) {
			if (i%20 && j% 20) continue;
			t = 0; for (k = 0; k < n; k++) if (t < (s = calc(i, j, x1[k], y1[k]))) t = s;
			if (ans > t) ans = t;
		}
	}
	printf(msg[ans & 1], ans >> 1);
	return 0;
}


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

int main() {
	string S; cin >> S;
	vector<int> A, B;
	A.push_back(0);
	B.push_back(1);
	for(char c : S) {
		int d = c - '0';
		int a = min(A[A.size() - 1] + d, B[B.size() - 1] + 10 - d);
		d++;
		int b = min(A[A.size() - 1] + d, B[B.size() - 1] + 10 - d);
		A.push_back(a);
		B.push_back(b);
	}
//	for(int i: A) cout << i << " "; cout << endl;
//	for(int i: B) cout << i << " "; cout << endl;
	cout << A[A.size() - 1];;
}


Measured memory_bytes: 12148
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007
#define MAX 100100
//#define NIL -1

int main() {
    int n;
    int m;
    int ans=0;

    cin >> n >> m;

    if(n>=2){
        ans+=n*(n-1)/2;
    }
    if(m>=2){
        ans+=m*(m-1)/2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n, k;
    cin >> n >> k;
    int h[n];
    rep(i, n) { cin >> h[i]; }
    int count = 0;
    rep(i, n) {
        if (h[i] >= k) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<queue>
using namespace std;

int main() {
    int N;
    cin>>N;
    vector<char> chararr;
    chararr.push_back('a');
    chararr.push_back('b');
    chararr.push_back('c');
    chararr.push_back('d');
    chararr.push_back('e');
    chararr.push_back('f');
    chararr.push_back('g');
    chararr.push_back('h');
    chararr.push_back('i');
    chararr.push_back('j');
    chararr.push_back('k');
    chararr.push_back('l');


    queue<string>que;
    queue<int>tmpque;
    que.push("a");
    tmpque.push(1);
    string state;
    int tmpstate;
    while(!que.empty()){
        state = que.front();
        tmpstate = tmpque.front();
        que.pop();
        tmpque.pop();
        if(state.size()==N){
            cout<<state<<endl;
            continue;
        }
        for(int i=0;i<tmpstate+1;++i){
            que.push(state+chararr[i]);
            if(i==tmpstate){
                tmpque.push(tmpstate+1);
            }
            else {
                tmpque.push(tmpstate);
            }
        }
    }
}


Measured memory_bytes: 8320
#include <iostream>

using namespace std;

const int INF = 10e+7;

int hash_[200001];
int hash_min[1<<26];
int dp[200001];

int main(){
    string s;
    cin >> s;
    int N = s.size();
    int cur = 0;
    for(int i = 0; i < (1<<26); i++){
        hash_min[i] = INF;
    }
    hash_[0] = 0;
    for(int i = 0; i < N; i++){
        cur ^= (1<<(s[i]-'a'));
        hash_[i+1] = cur;
        dp[i+1] = INF;
    }
    
    dp[0] = 0;
    hash_min[0] = 0;
    for(int i = 0; i <= N; i++){
        int h = hash_[i];
        dp[i] = min(INF, hash_min[h]+1);
        for(int j = 0; j < 26; j++){
            int n = (1<<j);
            h = (hash_[i]^n);
            dp[i] = min(hash_min[h]+1, dp[i]);
            hash_min[hash_[i]] = min(hash_min[hash_[i]], dp[i]);
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 264316
import math
MOD = 1000000000+7
X, Y = map(int, input().split())

if ((2*Y-X)%3 != 0) or ((2*X-Y)%3 != 0) or (2*Y-X) < 0 or (2*X-Y) < 0:
    print(0)
elif 2 *Y == X or 2 * X == Y:
    print(1)
else:
    x = (2*Y-X) // 3
    y = (2*X-Y) // 3
    fac_list = [None for _ in range(x+y+2)]
    inv_fac_list = [None for _ in range(x+y+2)]

    fac_list[0] = 1
    for i in range(1, x+y+2):
        fac_list[i] = i * fac_list[i-1] % MOD

    inv_fac_list[x+y+1] = pow(fac_list[x+y+1],(MOD - 2), MOD)
    for i in range(x+y, 0, -1):
        inv_fac_list[i] = inv_fac_list[i+1] * (i+1) % MOD

    print((fac_list[x+y] * inv_fac_list[x] * inv_fac_list[y]) % MOD)

Measured memory_bytes: 91912
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
c = gets.chomp.split.map(&:to_i)

ans = 0
n.times do |i|
  ans += b[a[i] - 1]
  if i != 0 && a[i] - a[i - 1] == 1
    ans += c[a[i - 1] - 1]
  end
end
p ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <math.h>
typedef long long int ll;
#define pb         push_back
#define mp         make_pair
#define F          first
#define S          second
#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define pll        pair<ll,ll>
#define pii        pair<int,int>
#define all(v)     v.begin(),v.end()
#define M          1000000007
#define M2         1000000009
#define M3         1000000000000007

using namespace std;
bool isPrime(ll n)
{
    if(n<=1)
        return false;
    if(n<=3)
        return true;
    if(n%2==0 || n%3==0)
        return false;

    for(ll i=5;i*i<=n;i=i+6)
        if(n%i==0|| n%(i+2)==0)
            return false;

    return true;
}

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

}

bool sortbydesc(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    if(a.S < b.S)
        return true;
    else
        return false;
}


int main()
{
 ios::sync_with_stdio(0);
 cin.tie(0);
 cout.tie(0);
 ll n;
 cin>>n;
 vector<ll> v;
 v.pb(0);
 ll a;
 fl(i,0,n)
 {
    cin>>a;
    v.pb(a);
 }
 ll dp[n+1][n+1][2];
 fl(i,1,n+1)
 {
    dp[i][i][0]=v[i];
    dp[i][i][1]=-v[i];
 }
 for(ll i=n-1;i>0;i--)
 {
    for(ll j=i+1;j<=n;j++)
    {
        dp[i][j][0]=max(v[i]+dp[i+1][j][1],v[j]+dp[i][j-1][1]);
        dp[i][j][1]=min(dp[i+1][j][0]-v[i],dp[i][j-1][0]-v[j]);
    }
 }
 cout << dp[1][n][0];
}






Measured memory_bytes: 140544
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
LL n,A,B;
LL a[1000005];
bool judge(LL x){
    LL temp=x*B;
    LL sub=A-B;
    LL sum=0;
    for(LL i=n;i>=1;i--){
        if(a[i]>temp){
            if((a[i]-temp)%sub)
                sum+=(a[i]-temp)/sub+1;
            else
                sum+=(a[i]-temp)/sub;
        }
    }
    if(sum<=x)
        return true;
    return false;
}
int main() {
    scanf("%lld%lld%lld",&n,&A,&B);
    LL right=0;
    for(LL i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        right+=a[i]/B+1;
    }
    sort(a+1,a+1+n);
    LL left=1;
    while(left<right){
        LL mid=(left+right)>>1;
        if(judge(mid))
            right=mid;
        else
            left=mid+1;
    }
    printf("%lld\n",left);
    return 0;
}


Measured memory_bytes: 896
package main

import (
  "bufio"
  "fmt"
  "strings"
  "os"
)

func main()  {
  sc := bufio.NewScanner(os.Stdin)
  sc.Scan()
  tArr := strings.Split(sc.Text(), " ")
  for i := 0; i < 3; i++ {
    fmt.Print(string(strings.ToUpper(tArr[i])[0]))
  }
  fmt.Println()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int H, W, h, w; cin >> H >> W >> h >> w;
    h = H - h; w = W - w;
    cout << h * w << endl;
}

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

int main()
{
	int N,x,ox;
	int a[110];
	int sum=0;
	int ans=0;
	
	cin >> N >> x;
	ox=x;
	for(int i=0;i<N;i++)
	{
		cin >> a[i];
		sum+=a[i];
	}
	
	sort(a,a+N);
	
	for(int i=0;i<N;i++)
	{
		if(x>=a[i])
		{
			x-=a[i];
			ans++;
		}
		else{
			x-=a[i];
			break;
		}
	}
	if(x>0){ans--;}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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


int main(){

    int n;
    cin>>n;
    int maxnum=-1,num,index;

    FOR(i,1,n+1){
        num=0;
        for(int div=2;div<=i;div*=2){
            if(i%div==0){
                num++;
            }
        }

        if(num>maxnum){
            maxnum=num;
            index=i;
        }
    }
    cout<<index<<endl;

}

Measured memory_bytes: 384
N,K=map(int,input().split())
S=input()

H=0
cnt=0
for i in range(N):
    if i>0 and S[i]==S[i-1]=="L":
        H+=1
    elif i<N-1 and S[i]==S[i+1]=="R":
        H+=1
    if i<N-1 and S[i]!=S[i+1]:
        cnt+=1
print(H+min(cnt,K*2))

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

class Program
{
    private int N;
    private int K;
    private int[]X;
    private void Scan()
    {
        N=int.Parse(Console.ReadLine());
        K=int.Parse(Console.ReadLine());
        X=Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
    
    
    public void Solve()
    {
        Scan();
        int ans=0;
        foreach(int i in X)
        {
            ans+=Math.Min(i,K-i)*2;
        }
        Console.WriteLine(ans);
    } 
    
    static void Main()
    {
        new Program().Solve();
    }
}

Measured memory_bytes: 13268
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    auto B = readln.split.map!(to!long).array;

    if (N.iota.map!(i => A[i] > B[i]).any) {
        writeln(-1);
        return;
    }

    auto pq = new BinaryHeap!(Array!(Tuple!(long, int)), "a[0] < b[0]");
    foreach (i; 0..N) pq.insert(tuple(B[i], i));
    long ans = 0;

    long prevv = -1;
    int previdx = -1;

    while (!pq.empty) {
        auto v = pq.front[0];
        auto idx = pq.front[1];
        pq.removeFront;

        if (v == prevv && idx == previdx) {
            writeln(-1);
            return;
        }

        prevv = v;
        previdx = idx;

        if (v < A[idx]) {
            writeln(-1);
            return;
        } else if (v == A[idx]) {
            continue;
        }

        auto left = (idx - 1+ N) % N;
        auto right = (idx + 1) % N;
        auto x = B[left] + B[right];

        if (v % x == A[idx] % x) {
            ans += (v - A[idx]) / x;
            B[idx] = A[idx];
            continue;
        }

        ans += B[idx] / x;
        B[idx] %= x;
        pq.insert(tuple(B[idx], idx));
    }

    ans.writeln;
}


Measured memory_bytes: 22748
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

using ll = long long;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

#define mp make_pair
#define mt make_tuple

/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
inline T sq(T a) { return a * a; }

template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

ll pcnt(ll b) {
    return __builtin_popcountll(b);
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

const string num = "753";

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

    int ans = 0;
    for (int d = 3; d < 10; ++d) {
        // dは桁数
        for (int b = 0; b < mypow(3, d); ++b) {
            string S;
            int cb = b;
            for (int i = 0; i < d; ++i) {
                S.push_back(num[cb % 3]);
                cb /= 3;
            }

            int cnt[3];
            fill(cnt, cnt + 3, 0);
            for (char c : S) {
                cnt[(c - '3') / 2]++;
            }

            bool judge = true;
            for (int i = 0; i < 3; ++i) {
                if (cnt[i] == 0) judge = false;
            }
            if (!judge) continue;

            if (stoi(S) <= N) ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

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

int gcd(int m, int n) {
    return n == 0 ? m : gcd(n, m % n);
}
int lcm(int m, int n) {
    return (m / gcd(m, n)) * n;
}

int intceil(int a, int b) {
    return (a + (b - 1)) / b;
}

signed main() {
    cin >> N >> M;
    vi a(N);
    cin >> a;
    for (int i = 0; i < N; i++)
        a[i] /= 2;
    int l = a[0];
    for (int i = 1; i < N; i++) {
        l = lcm(a[i], l);
    }
    bool flag = 1;
    for (int i = 0; i < N; i++) {
        int tmp = l / a[i];
        if (!(tmp & 1)) {
            flag = 0;
        }
    }
    if (!flag) {
        cout << 0 << endl;
    } else {
        int tmp = M / l;
        dump(tmp);
        cout << intceil(tmp, 2) << endl;
    }
}

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

#define loop(i, n) for(int i = 0; i < n; i++)
#define sloop(i, s, n) for (int i = s; i < n; i++)
#define rloop(i, n) for (int i = n - 1; i >= 0; i--)

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, mn, mx, temp, count = 0;
    cin >> n;
    vector<int>def(8, 0);
    loop(i, n) {
        cin >> temp;
        if(temp >= 1 && temp <= 399) def[0] = 1;
        else if(temp >= 400 && temp <= 799) def[1] = 1;
        else if(temp >= 800 && temp <= 1199) def[2] = 1;
        else if(temp >= 1200 && temp <= 1599) def[3] = 1;
        else if(temp >= 1600 && temp <= 1999) def[4] = 1;
        else if(temp >= 2000 && temp <= 2399) def[5] = 1;
        else if(temp >= 2400 && temp <= 2799) def[6] = 1;
        else if(temp >= 2800 && temp <= 3199) def[7] = 1;
        else count++;
    }
    mn = 0;
    loop(i, 8) mn += def[i];
    mx = mn + count;
    if(!mn && count) mn++;
    cout << mn << " "<<  mx << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}


signed main() {

    ll a, b, x;

    cin >> a >> b >> x;

    cout << b/x+1 - (a?(a-1)/x+1:0) << endl;

  
    return 0;
}


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

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> ds(n);
    std::map<int, std::vector<std::pair<int, int>>> xby, yby;

    for (int i = 0; i < n; ++i) {
        int x, y;
        char c;
        std::cin >> x >> y >> c;

        int d;
        for (d = 0; d < 4; ++d) {
            if (c == "><v^"[d]) break;
        }

        ds[i] = d;
        xby[x].emplace_back(y, i);
        yby[y].emplace_back(x, i);
    }

    std::vector<std::vector<int>> oto(n, std::vector<int>(4, -1));
    for (auto& p : xby) {
        auto& ys = p.second;
        std::sort(ys.begin(), ys.end());

        for (int i = 0; i + 1 < (int)ys.size(); ++i) {
            int u = ys[i].second, v = ys[i + 1].second;
            oto[u][2] = v;
            oto[v][3] = u;
        }
    }

    for (auto& p : yby) {
        auto& xs = p.second;
        std::sort(xs.begin(), xs.end());

        for (int i = 0; i + 1 < (int)xs.size(); ++i) {
            int u = xs[i].second, v = xs[i + 1].second;
            oto[u][0] = v;
            oto[v][1] = u;
        }
    }

    int ans = 0;
    for (int s = 0; s < n; ++s) {
        auto to = oto;
        int cnt = 0;

        int v = s;
        while (v != -1) {
            int p = to[v][0], q = to[v][1];
            if (p != -1) to[p][1] = q;
            if (q != -1) to[q][0] = p;

            p = to[v][2], q = to[v][3];
            if (p != -1) to[p][3] = q;
            if (q != -1) to[q][2] = p;

            v = to[v][ds[v]];
            ++cnt;
        }

        ans = std::max(ans, cnt);
    }

    std::cout << ans << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}



Measured memory_bytes: 3716
#ダブリング
import copy
n,k=map(int,input().split())
d=60
#d=k.bit_length()
to=[[0 for _ in range(n)] for _ in range(d)]
to[0]=[i-1 for i in map(int,input().split())]
for i in range(1,d):
  for j in range(n):
    #print(i,j,to[i])
    to[i][j]=to[i-1][to[i-1][j]]
v=0
for i in reversed(range(d)):
  l=2**i
  if l<=k:
    v=to[i][v]
    k-=l

print(v+1)


Measured memory_bytes: 216520
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int n;
	cin >> n;
	int x[n],y[n],h[n];
	for(int i=0; i<n; i++){
		cin >> x[i] >> y[i] >> h[i];
	}

	int tmph;
	int k;
	for(int i=0; i<=100; i++){
		for(int j=0; j<=100; j++){
			for(k=0; k<n; k++){
				if(h[k]==0){
					continue;
				}
				tmph=h[k]+abs(x[k]-i)+abs(y[k]-j);
				if(tmph>=1){
					break;
				}
			}

			for(k=0; k<n; k++){
				if(h[k]!=max(tmph-abs(x[k]-i)-abs(y[k]-j), 0)){
					break;
				}
			}
			if(k==n){
				cout << i << " " << j << " " << tmph << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, k, m = M;
    cin >> n >> k;
    vector<ll> h(n);
    for (ll &e : h)
        cin >> e;
    sort(h.begin(), h.end());
    for (ll i = 0; i + k <= n; i++)
        m = min(m, h[i + k - 1] - h[i]);
    cout << m;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
const string yes = "Yes";
const string no = "No";

int main()
{
  string s;
  cin >> s;
  if(s[0]==s[1]&&s[1]==s[2]) cout << no << endl;
  else cout << yes << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
//#define scanf scanf_s
#define fir first
#define sec second
#define mp make_pair
#define mt make_tuple
#define pub push_back
using namespace std;
typedef long long int llint;
const llint one = 1;
const llint big = (one<<30);
const llint mod=1000000007;
int main(void){
	llint n,m,i,j,gen,ans,a,sota=0,soyo=0;
	vector<llint> ta;
	vector<llint> yo;
	
	scanf("%lld %lld",&n,&m);
	for(i=0;i<n;i++){
		scanf("%lld",&a);
		ta.pub(a);
	}for(i=0;i<m;i++){
		scanf("%lld",&a);
		yo.pub(a);
	}
	for(i=1;i<n;i++){
		sota+=(ta[i]-ta[i-1])*((i*(n-i))%mod);
		sota=sota%mod;
	}
	for(i=1;i<m;i++){
		soyo+=(yo[i]-yo[i-1])*((i*(m-i))%mod);
		soyo=soyo%mod;
	}
	printf("%lld\n",(sota*soyo)%mod);
	return 0;
}


Measured memory_bytes: 2548
#include <iostream>
typedef long long ll;
const ll mod = 1e9+7;
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

ll C[2020][2020] = {};

// パスカルの三角形 DP
// 各値 %mod
void Cnr() {
  for(int i = 0; i < 2020; ++i) C[i][0] = C[i][i] = 1;
  for(int i = 2; i < 2020; ++i) {
    for(int j = 1; j < i; ++j) {
      C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod;
    }
  }
}

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

  int n, k; cin >> n >> k;
  Cnr();

  for(int i = 1; i <= k; ++i) cout << (C[n-k+1][i] * C[k-1][i-1])%mod << '\n';
  return 0;
}


Measured memory_bytes: 30720
using System;
using System.IO;

namespace ABC126B
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var S = Console.ReadLine();
            var n1 = int.Parse(S.Substring(0, 2));
            var n2 = int.Parse(S.Substring(2, 2));

            var f1m = 1 <= n1 && n1 <= 12;
            var f2m = 1 <= n2 && n2 <= 12;

            if (f1m && f2m)
            {
                Console.WriteLine("AMBIGUOUS");
            }
            else if (f1m)
            {
                Console.WriteLine("MMYY");
            }
            else if (f2m)
            {
                Console.WriteLine("YYMM");
            }
            else
            {
                Console.WriteLine("NA");
            }
        }
    }
}


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

string A,B;
int DP[4000][4000];

int LCS(int n, int m)
{
    for(int i = 0; i <= n; i++)
        for(int j = 0; j <= m; j++)
            if(i == 0 || j == 0)
                DP[i][j] = 0;
            else if(A[i-1] == B[j-1])
                DP[i][j] = DP[i-1][j-1] + 1;
            else
                DP[i][j] = max(DP[i-1][j],DP[i][j-1]);
    return DP[n][m];
}

void printLCS(int n, int m)
{
    int index = LCS(n,m); ///ekhane LCS function call koresi
    char ANS[index];      ///etatei baby er naam rakha hobe :p
    ANS[index--] = '\0'; ///hudai disi...na dileo hobe :p

    while(n > 0 && m > 0)
    {
       if(A[n-1] == B[m-1])
       {
           ANS[index--] = A[n-1];
           n--;
           m--;
       }
       else if(DP[n-1][m] > DP[n][m-1])
          n--;
       else
          m--;
    }
    cout<<ANS<<endl;
}

int main()
{
    int x, y;
    cin>>A>>B;
    x = A.length();
    y = B.length();

    //cout<<"LCS : "<<LCS(x,y)<<endl;
    printLCS(x, y);
    return 0;
}


Measured memory_bytes: 47360
#include <stdio.h>

int main(){
	int n;
  	int a[3]={0,0,0};
  	scanf("%d",&n);
  	
     a[0]=n/100;
     a[1]=(n-a[0]*100)/10;
     a[2]=n%10;

 	for(int i=0;i<3;i++){
      if(a[i]==7){
      printf("Yes\n");
        break;
      }
      if(i==2)printf("No\n");
    }

}

Measured memory_bytes: 1664
#include<iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>
#include<cstring>
#include<iomanip>
#include <string>
#include <vector>	
#include<unordered_map>
#include<unordered_set>
using namespace std;


typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const int mod = 1000000007;
const ll inf = 1000000000009;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdoutn

int main()
{
	IO;
	int n{};
	cin>>n;
	int res{},cnt{},ans{};
	For(i,1,n+1)
	{
		int j=i;
		while((!(j%2)) && j>0){res++;j/=2;}
		if(res>cnt)cnt=res,ans=i;
		res=0;		
	}
	(!ans)?cout<<"1\n":cout<<ans<<'\n';

//	system("pause");
	return 0;
}

Measured memory_bytes: 3616
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

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

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

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

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

  int x;
  cin >> x;
  int tmp = x % 100;

  if (x < 100) {
    cout << 0 << endl;
    return 0;
  }

  int cnt = 0;
  for (int i = 5; 0 < i; i--) {
    cnt += tmp / i;
    tmp %= i;
  }

  int ans = 100 * cnt;
  if (ans <= x) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
N = int(input())

def check(n):
 s = str(n)
 return n <= N and s.count('3') * s.count('5') * s.count('7') >= 1

ans = 0
for i1 in [3,5,7]:
 if check(i1):
  ans += 1
 for i2 in [3,5,7]:
  if check(i2*10 + i1):
   ans += 1
  for i3 in [3,5,7]:
   if check(i3*100 + i2*10 + i1):
    ans += 1
   for i4 in [3,5,7]:
    if check(i4*1000 + i3*100 + i2*10 + i1):
     ans += 1
    for i5 in [3,5,7]:
     if check(i5*10000 + i4*1000 + i3*100 + i2*10 + i1):
      ans += 1
     for i6 in [3,5,7]:
      if check(i6*100000 + i5*10000 + i4*1000 + i3*100 + i2*10 + i1):
       ans += 1
      for i7 in [3,5,7]:
       if check(i7*1000000 + i6*100000 + i5*10000 + i4*1000 + i3*100 + i2*10 + i1):
        ans += 1
       for i8 in [3,5,7]:
        if check(i8*10000000 + i7*1000000 + i6*100000 + i5*10000 + i4*1000 + i3*100 + i2*10 + i1):
         ans += 1
        for i9 in [3,5,7]:
         if check(i9*100000000 + i8*10000000 + i7*1000000 + i6*100000 + i5*10000 + i4*1000 + i3*100 + i2*10 + i1):
          ans += 1
print(ans)

Measured memory_bytes: 3064
n = int(input())
a = list(map(int,input().split()))

b = []
for i,e in enumerate(a):
  b.append((e,i+1))
  
b.sort()

for i,t in enumerate(b):
  if i == n-1:
    print(t[1])
  else:
    print(t[1],end=' ')

Measured memory_bytes: 18496
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll x;
    cin >> x;
    ll c = 0;
    ll res = 0;
    ll tres = 0;
    while(res == 0){
        tres++;
        c += x;
        c %= 360;
        if(c==0) res = tres;
    }
    cout << res << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int x1,y1,x2,y2,x3,y3,x4,y4;
    cin >> x1 >> y1 >> x2 >> y2;
    x3 = x2 - (y2-y1);
    y3 = y2 + (x2-x1);
    x4 = x1 - (y2-y1);
    y4 = y1 + (x2-x1);
    cout << x3 <<" "<<y3 <<" "<<x4<<" "<<y4 <<endl;
}


Measured memory_bytes: 3644