akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i --)

template <std::size_t N>
struct Era {
	int prime_array[ N + 1 ];

	constexpr Era() : prime_array() {
		prime_array[ 0 ] = 0;
		prime_array[ 1 ] = 0;
		rep( i, 2, N + 1 ){
			prime_array[ i ] = 1;
		}
		int lim = N;
		rep( i, 2, lim ){
			if (prime_array[ i ] == 0)
				continue;
			lim = N / i;
			for(int j = i * 2; j < N + 1; j += i){
				prime_array[ j ] = 0;
			}
		};
		rep_d( i, N, 0 ){
			if (prime_array[ i ] == 1 && prime_array[ ( i + 1 ) / 2 ] == 1)
				prime_array[ i ] = 1;
			else
				prime_array[ i ] = 0;
		}
		rep( i, 1, N ){
			prime_array[ i ] += prime_array[ i - 1 ];
		}
	}
};

const int MaxN = 1e5 + 5;
int main( void ){
	constexpr auto era = Era <MaxN>();
	cin.tie( 0 );
	ios::sync_with_stdio( false );
	int Q; cin >> Q;
	rep( i, 0, Q ){
		int l, r;
		cin >> l >> r;
		cout << era.prime_array[ r ] - era.prime_array[ l - 1 ] << endl;
	}
}


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

int main() {
	string a, b;
	cin >> a;
	cin >> b;
	int ans = INT_MAX;
	for(int i = 0; i <= a.length() - b.length(); i++) {
		int temp = 0;
		for(int j = 0; j < b.length(); j++) {
			if(a[i + j] != b[j]) temp++;
		}
		ans = min(ans, temp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

int r, c, p;

int main() {
  while((c = getchar_unlocked()) > 13) {
    if (c == p) {
      p = 1;
    }
    else {
      r += 1;
      p = p == 1 ? 0 : c;
    }
  }
  printf("%d\n", r);
}


Measured memory_bytes: 128
h,w = map(int,input().split())

dp = [-1] * 10
for i in range(10):
    dp[i] = list(map(int,input().split()))

for k in range(10):
    for i in range(10):
        for j in range(10):

            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

ans = 0
for _ in range(h):
    a = list(map(int,input().split()))
    for i in range(w):
        if a[i] == 1 or a[i] == -1:
            pass

        else:
            ans += dp[a[i]][1]

print(ans)

Measured memory_bytes: 3064
#include <iostream>
int main()
{
    int n,p=0;
    std::cin>>n;
    for(int i=0;i<=n;i++)
    {
        int m=n-i*4;
        if(m%7==0&&m>=0)p=1;
    }
    if(p)std::cout<<"Yes\n";
    else std::cout<<"No\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
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;}
//自作関数
template<class T> ll llpow(T x,T n){ll ans=1;while(n--){ans*=x;}return ans;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int n;
int main(){
    int W;
    cin>>n>>W;
    int w[n],v[n];
    rep(i,n){
       cin>>w[i]>>v[i];
    }
    ll dp[W+1];
    rep(i,W+1)dp[i]=0;
    for(int i=0;i<n;i++){
        for(int j=W;j>=0;j--){
            if((j-w[i])>=0)chmax(dp[j],dp[j-w[i]]+v[i]);
        }
    }
    cout<<dp[W]<<endl;
    return 0;
}




Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define all(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };

int main()
{
	int d, n;
	cin >> d >> n;
	if (d == 0) {
		if (n == 100) {
			cout << 101 << endl;
		}
		else {
			cout << n << endl;
		}
	}
	else if (d == 1) {
		if (n == 100) {
			cout << 10100 << endl;
		}
		else {
			cout << n * 100 << endl;
		}
	}
	else {
		if (n == 100) {
			cout << 1010000 << endl;
		}
		else {
			cout << n * 10000 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-

def solve():
    N, M = list(map(int, input().split()))
    start = []
    for i in range(N):
        a, b = list(map(int, input().split()))
        start.append((a, b))
    
    checkpoints = []
    for i in range(M):
        c, d = list(map(int, input().split()))
        checkpoints.append((c, d))
    
    # 1 <= N,M <= 50 なので、全探索しても高々 N*M = 2500

    for i in range(N):
        min_d = float("inf")
        for j in range(M):
            d = abs(start[i][0]-checkpoints[j][0]) + abs(start[i][1]-checkpoints[j][1])
            if d < min_d:
                min_d = d
                ans = j + 1
        print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

// えびちゃんの make_vector (ここから)
template <typename Tp, size_t N>
std::vector<Tp> make_vector_detail(std::vector<size_t>& sizes, typename std::enable_if<(N == 1), const Tp&>::type x) {
  return std::vector<Tp>(sizes[0], x);
}
template <typename Tp, size_t N>
auto make_vector_detail(std::vector<size_t>& sizes, typename std::enable_if<(N > 1), const Tp&>::type x) {
  size_t size = sizes[N-1];
  sizes.pop_back();
  return std::vector<decltype(make_vector_detail<Tp, N-1>(sizes, x))>(size, make_vector_detail<Tp, N-1>(sizes, x));
}

template <typename Tp, size_t N>
auto make_vector(const size_t(&sizes)[N], const Tp& x) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return make_vector_detail<Tp, N>(s, x);
}
// えびちゃんの make_vector (ここまで)

signed main(){
    
    int n, m; cin >> n >> m;
    vector<vector<int> > s(m, vector<int> (n, 0));
    for(int i = 0; i < m; i++){
        int k; cin >> k;
        for(int j = 0; j < k; j++){
            int val; cin >> val;
            val--;
            s[i][val] = 1;
        }
    }

    vector<int> p(m);
    for(int i = 0; i < m; i++) cin >> p[i];
    
    int ans = 0;
    for(int bit = 0; bit < (1 << n); bit++){
        bool flag = true;

        for(int j = 0; j < m; j++){
            int cnt = 0;
            int hoge = bit;
            for(int k = 0; k < n; k++){
                if(s[j][k] && ((1 << k) & bit)) cnt++; 
            }
            if(cnt % 2 != p[j]) flag = false;
        }

        if(flag) ans++;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def calc(x):
    result = 0
    y = x
    while y % 100 == 0:
        y = int(y / 100)
        result += 1
    return result

def main():
    D, N = map(int, input().split())

    cnt = 0
    val = 0

    while cnt != N:
        val += 1
        if calc(val) == D:
            cnt += 1

    print(val)

main()

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int P, Q, R;
    cin >> P >> Q >> R;
    cout << P+Q+R - max({P, Q, R}) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define LL long long
using namespace std;
string s[300];
int zsuv = 300;
int field[1205][1205];
int prefR[605][605];
int prefH[605][605];
int sumR(int idx , int l , int r)
{
    if(idx < 0)
        return 0;
    if(idx > 600)
        return 0;
    return prefR[idx][r] - (l > 1 ? prefR[idx][l - 2] : 0);
}
int sumH(int idx , int l , int r)
{
    if(idx < 0)
        return 0;
    if(idx > 600)
        return 0;
    return prefH[idx][r] - (l > 1 ? prefH[idx][l - 2] : 0);
}
int main() 
{
    int h , w;
    cin >> h >> w;
    for(int i = 0; i < h; i++)
        cin >> s[i];
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
            if(s[i][j] == '#')
            {
                field[i + j][i - j + zsuv] = 1;
            }
    }
    for(int i = 0; i <= 600; i++)
    {
        for(int j = 0; j <= 600; j++)
        {
            prefR[i][j] = field[i][j] + (j > 1 ? prefR[i][j - 2] : 0);
            prefH[j][i] = field[i][j] + (i > 1 ? prefH[j][i - 2] : 0);
        }
    }
    LL ans = 0;
    for(int i = 0; i <= 600; i++)
    {
        for(int j = 0; j <= 600; j++)
        {
            for(int k = j + 2; k <= 600; k += 2)
            {
                if(field[i][j] && field[i][k])
                {
                    //cout << i << " " << j << " " << k << endl;
                    int diff = k - j;
                    
                    ans -= field[i + diff][j + diff];
                    ans -= field[i + diff][j];
                    ans += sumR(i - diff , j , k) + sumR(i + diff , j , k);
                }
                if(field[j][i] && field[k][i])
                {
                    //cout << i << " " << j << " " << k << endl;
                    int diff = k - j;
                    if(i - diff >= 0)
                    ans -= field[k][i - diff];
                    ans -= field[k][i + diff];
                    ans += sumH(i - diff , j , k) + sumH(i + diff , j , k);
                }
            }
        }
    }
    cout << ans;
    return 0;
}

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

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

using ll = long long;

const int MAXN = 105;
int N;
ll Wmax;
ll W[MAXN];
int V[MAXN];

int dp[MAXN][MAXN][3 * MAXN];

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

	cin >> N >> Wmax;
	for (int i = 0; i < N; i++) {
		cin >> W[i] >> V[i];
	}

	dp[0][0][0] = 0;
	for (int i = 0; i < N; i++) {
		for (int n = 0; n <= i; n++) {
			for (int a = 0; a <= 3 * n; a++) {
				ll curW = n * W[0] + a;
				if (curW > Wmax) continue;
				setmax(dp[i+1][n][a], dp[i][n][a]);
				ll nxtW = (n+1) * W[0] + a + (W[i] - W[0]);
				if (nxtW <= Wmax) {
					setmax(dp[i+1][n+1][a + (W[i] - W[0])], dp[i][n][a] + V[i]);
				}
			}
		}
	}

	int ans = 0;
	for (int n = 0; n <= N; n++) {
		for (int a = 0; a <= 3 * n; a++) {
			setmax(ans, dp[N][n][a]);
		}
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 11392
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	string s; cin >> s;
	ll ans = 0;
	REP(i, 16) {
		if (s[i] != "CODEFESTIVAL2016"[i]) {
			++ans;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[100000];
	for(int i=0;i<n;i++) cin>>a[i];
	int c[100000];
	for (int i = 0; i<n; i++) c[a[i] - 1] = i + 1;
	for (int i = 0; i<n; i++) cout << c[i] << endl;
	return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int A=stdIn.nextInt();
		int B=stdIn.nextInt();
		if(A*N<=B)
			System.out.println(A*N);
		else
			System.out.println(B);
	}
}

Measured memory_bytes: 22228
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;




int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================

	int N;
	cin >> N;
	vector<int> X(N + 1), Y(N + 1), T(N + 1);
	X[0] = 0;
	Y[0] = 0;
	T[0] = 0;
	for (int i = 0; i < N; i++) {
		cin >> T[i + 1] >> X[i + 1] >> Y[i + 1];
	}

	for (int i = 0; i < N; i++) {
		int amari = (T[i + 1] - T[i]) - (X[i + 1] - X[i] + Y[i + 1] - Y[i]);
		if (amari < 0 || amari % 2 != 0) {
			cout << "No";
			return 0;
		}


	}

	cout << "Yes";




}	




Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

const int N=2e5+5;
const int M=5e5+5;
const int T=1e6+5;
const int mod=924844033;
const int sqr=5;
const int sqrinv=554906420;

int n,u,v,siz[N],limit,lg;
int E,ot[M],ne[M],g[N];
int fac[N],inv[N],infac[N];
int a[T],b[T],r[T];

int F_p(int x,int y)
{
	int bas=x,ret=1;
	while(y)
	{
		if(y&1) ret=1LL*ret*bas%mod;
		bas=1LL*bas*bas%mod;
		y>>=1;
	}
	return ret;
}

void add(int u,int v)
{
	ot[++E]=v;
	ne[E]=g[u];
	g[u]=E;
}

void init()
{
	int i;
	scanf("%d",&n);
	for(i=1;i<n;++i)
	{
		scanf("%d%d",&u,&v);
		add(u,v),add(v,u);
	}
}

void dfs(int x,int fath)
{
	siz[x]=1;
	int p,to;
	for(p=g[x];p;p=ne[p])
	{
		to=ot[p];
		if(to==fath) continue;
		dfs(to,x);
		siz[x]+=siz[to];
		++a[siz[to]];
	}
	++a[n-siz[x]];
}

int solve_complex(int x,int tp)
{
	if(~tp) return F_p(sqr,x);
	else return F_p(sqrinv,x);
}

void DFT(int *A,int tp)
{
	int i;
	for(i=0;i<limit;++i)
		if(i<r[i])
			swap(A[i],A[r[i]]);
	
	int len,j,k;
	for(len=1;len<limit;len<<=1)
	{
		int wn=solve_complex((mod-1)/(2*len),tp);
		for(j=0;j<limit;j+=len<<1)
		{
			int w=1;
			for(k=0;k<len;++k,w=1LL*w*wn%mod)
			{
				int x=A[j+k];
				int y=1LL*w*A[j+k+len]%mod;
				A[j+k]=x+y,A[j+k+len]=x-y;
				if(A[j+k]>=mod) A[j+k]-=mod;
				if(A[j+k+len]<0) A[j+k+len]+=mod;
			}
		}
	}
}

void prework()
{
	int i;dfs(1,0);
	fac[0]=1;for(i=1;i<=n;++i) fac[i]=1LL*fac[i-1]*i%mod;
	inv[1]=1;for(i=2;i<=n;++i) inv[i]=1LL*inv[mod%i]*(mod-mod/i)%mod;
	infac[0]=1;for(i=1;i<=n;++i) infac[i]=1LL*infac[i-1]*inv[i]%mod;
}

void work()
{
	int i;a[0]=0;
	for(i=0;i<=n;++i) a[i]=1LL*a[i]*fac[i]%mod;
	for(i=0;i<=n;++i) b[i]=infac[n-i];
	
	limit=1;
	while(limit<=2*n) limit<<=1,++lg;
	for(i=1;i<limit;++i) r[i]=(r[i>>1]>>1)|((i&1)<<(lg-1));
	
	DFT(a,1),DFT(b,1);
	for(i=0;i<limit;++i) a[i]=1LL*a[i]*b[i]%mod;
	DFT(a,-1);
	
	int INV=F_p(limit,mod-2);
	for(i=1;i<=n;++i) a[i+n]=1LL*a[i+n]*INV%mod*infac[i]%mod;
	for(i=1;i<=n;++i) a[i]=1LL*fac[n]*infac[i]%mod*infac[n-i]%mod*n%mod;
	for(i=1;i<=n;++i)
	{
		a[i]-=a[i+n];
		if(a[i]<0) a[i]+=mod;
	}
	for(i=1;i<=n;++i) printf("%d\n",a[i]);
}

int main()
{
	init();prework();work();
	return 0;
}

Measured memory_bytes: 29312
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var abx = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();
            Console.WriteLine(abx[2] / abx[0] * abx[1]);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 
typedef long long ll;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define DBGV(v,n) forn(i,n) cout << v[i] << " "; cout << endl
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
 
ll solve(vector <int> &v, int n, int k)
{
	ll MAXN = 10000000000000000;
	vector <ll> dp(n,MAXN);
	dp[0]=0;
	forr(i,1,n)
	{
		for(int j=1; j<=k; j++)
		{
			if(i-j < 0) break;
			dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
		}
		//DBG(dp[i]);
	}
	return dp[n-1];
}
 
int main()
{ 
	FIN;
	
	#ifdef input
		freopen("test1.txt", "r", stdin);
	#endif
	
	int n;
	cin >> n;
	vector <int> v(n);
	forn(i,n) cin >> v[i];
	cout << solve(v,n,2) << endl;
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()

typedef long long ll;

int N;
vector<int> A,B;
vector<pair<int, int>> A_sorted,B_sorted;

struct UnionFind{
    vector<int> Parent;
    vector<int> sizes;
    UnionFind(int n):Parent(n),sizes(n,1){ rep(i,n)Parent[i]=i; }
    //find the root of x
    int root(int x){
        if(x!=Parent[x]){
        Parent[x] = root(Parent[x]);
        }
        return Parent[x];
    }
    //merge x and y
    void unite(int x,int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(sizes[x] < sizes[y]) swap(x, y);
        Parent[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(int x,int y){ return root(x) == root(y); }
    int size(int x){ return sizes[root(x)]; }
};

void INPUT(){
    cin>>N;
    A.resize(N);B.resize(N);
    rep(i,N){
        cin>>A[i];
        A_sorted.push_back({A[i],i});
    }
    rep(i,N){
        cin>>B[i];
        B_sorted.push_back({B[i],i});
    }
    sort(all(A_sorted));sort(all(B_sorted));
}

int main() {
    INPUT();
    //sortしてA[i]<=B[i]を満たないならいかなる置換でも達成できない
    rep(i,N){
        if(A_sorted[i].first>B_sorted[i].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    //sortして達成可能な場合
    //sortしたときの対応関係から、互いに素な巡回置換の数を数える
    UnionFind uni(N);
    rep(i,N){
        uni.unite(A_sorted[i].second,B_sorted[i].second);
    }
    //互いに素な巡回置換の個数（つまり、UnionFindのグループの数）
    int cnt = 0;
    rep(i,N){
        if(uni.Parent[i] == i)cnt++;
    }
    /*
    互いに素な巡回置換が1つのとき、N-1回の互換（swap）で表現でき、
    そこから互いに素な循環が1つ増えるたびに、必要な互換の数は1ずつ減るので、
    cnt > 1のときはN-2回以内のswapで達成可能
    */
    if(cnt > 1){
        cout<<"Yes"<<endl;
        return 0;
    }
    /*
    互いに素な巡回置換が1つのとき
    Bの隣り合う要素をswapすれば、1つの巡回置換を2つに分解できる
    */
    rep(i,N-1){
        if(A_sorted[i+1].first <= B_sorted[i].first){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3316
package main

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

type graph struct {
	setuzoku []int
	value int
	me int
}
func main() {
	scan_init()
	n:= scanInt()
	X := scanInt()
	Y := scanInt()
	// vertexs := make([]int,n)
	graphs := make([]graph,n)
	// cnts := make([]int,n)

	graphs[0].setuzoku = []int{}
	graphs[0].setuzoku = append(graphs[0].setuzoku,1)
	graphs[0].me = 0
	for i:= 1; i<n-1; i++ {
		graphs[i].setuzoku = []int{}
		graphs[i].setuzoku = append(graphs[i].setuzoku, i+1)
		graphs[i].setuzoku = append(graphs[i].setuzoku, i-1)
		graphs[i].me = i
	}
	graphs[n-1].setuzoku = append(graphs[n-1].setuzoku, n-2)
	graphs[n-1].me = n-1

	graphs[X-1].setuzoku = append(graphs[X-1].setuzoku, Y-1)
	graphs[Y-1].setuzoku = append(graphs[Y-1].setuzoku, X-1)
	// ここまでgraph完成
	results := make ([][]int,n) //これはある頂点を基準にした時にどの頂点がどの距離か
	mapresults := make([]map[int]int,n)
	// fmt.Println(graphs)
	for i:=0; i<n; i++{
		results[i] = make([]int,n)
		mapresults[i] = make(map[int]int)
		meboshi := map[int]int{} //どの頂点に訪れたかチェック
		que := []graph{} //que
		meboshi[i] = i
		graphs[i].value = 0
		que = append(que,graphs[i])
		cost := 0
		results[i][i] = graphs[i].value
		cost += 1
		for len(que) > 0{
			var gra graph
			gra,que = pop(que)
			indent := gra.me
			// fmt.Println(indent, gra)
			for _,val := range gra.setuzoku {
				if i == 4 {
					// fmt.Println(gra,val,meboshi,results[i],indent,que)
				}
				if _,ok := meboshi[val]; !ok {
					meboshi[val] = val
					results[i][val] = graphs[indent].value +1
					graphs[val].value = graphs[indent].value + 1
					que = append(que,graphs[val])
				}
			}
			cost += 1
		}
	}
	counter := make([]int,n)
	for i:= 0;i<n; i++ {
		counter[i] = 0
	}
	for i:= 0; i<n; i++ { //編の数
		for j:= 0; j<n; j++ {
			counter[results[j][i]]++
		}
	}
	for i:=1; i<n; i++ {
		fmt.Println(counter[i]/2)
	}
}
func pop(slice []graph) (graph, []graph) {
	ans := slice[0]
	slice = slice[1:len(slice)]
	return ans, slice
}
var sc = bufio.NewScanner(os.Stdin)
func scan_init () {
	sc.Split(bufio.ScanWords)
}
func scanInt () int{
sc.Scan()
	i,_ := strconv.Atoi(sc.Text())
	return i
}
func scan () string{
 sc.Scan()
	return sc.Text()
}

Measured memory_bytes: 66764
(let ((A (read))
      (B (read))
      (C (read))
      (X (read)))
  (format t "~A~%"
          (loop for k upto A with totalA = 0
             do
               (setf totalA (* k 500))
             when (> totalA X) return ans1
             sum (loop for m upto B with totalB
                    do
                      (setf totalB (+ totalA (* 100 m)))
                    when (> totalB X) return ans2
                    sum (loop for n upto C with totalC
                           do
                             (setf totalC (+ totalB (* 50 n)))
                           when (> totalC X) return ans3
                           count (= totalC X) into ans3
                           finally (return ans3))
                    into ans2
                    finally (return ans2))
             into ans1
             finally (return ans1))))


Measured memory_bytes: 15460
#include <algorithm>
#include <iostream>
#define N_MAX 1001
#define INF (1e9)
using namespace std;
int n,c[N_MAX],cost[N_MAX][N_MAX];
bool visited[N_MAX];

int func(int u){
  int sum=0;
  visited[u]=true;
  for(int i=0;i<n;i++){
    if(cost[u][i]==INF||visited[i]) continue;
    if(c[i]) sum+=cost[u][i];
    else sum+=min(cost[u][i],func(i));
  }
  return sum;
}

int main(){
  int u,v,p;
  cin>>n;
  for(int i=1;i<n;i++) cin>>c[i];
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++) cost[i][j]=INF;
  for(int i=1;i<n;i++) cin>>u>>v>>p,cost[u][v]=cost[v][u]=p;
  cout<<func(0)<<endl;
  return 0;
}

Measured memory_bytes: 5064
#include <bits/stdc++.h>
#include <string>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/

ll dp[3333][3333];
ll rdp[3333][3333];

int main(void) {
  ll i, j, k, l;
  
  ll N, T;
  cin >> N >> T;
  ll a[3333], b[3333];
  ll ra[3333], rb[3333];
  
  for(i=0; i<N; i++) {
    cin >> a[i] >> b[i];
    ra[N-1-i]=a[i]; rb[N-1-i]=b[i];
  }
  
  for(i=0; i<N; i++) {
    for(j=0; j<=T; j++) {
      chmax(dp[i+1][j], dp[i][j]);
      if(j+a[i]<=T)
        chmax(dp[i+1][j+a[i]], dp[i][j]+b[i]);
    }
  }
  
  
  for(i=0; i<N; i++) {
    for(j=0; j<=T; j++) {
      chmax(rdp[i+1][j], rdp[i][j]);
      if(j+ra[i]<=T)
        chmax(rdp[i+1][j+ra[i]], rdp[i][j]+rb[i]);
    }
  }
  
  ll ans=0;
  for(i=1; i<=N; i++) {
    for(j=0; j<=T-1; j++) {
      chmax(ans, dp[i-1][j]+rdp[N-i][T-1-j]+b[i-1]);
    }
  }
  
  pt(ans);
}



Measured memory_bytes: 160000
import java.util.Scanner;
import java.util.stream.LongStream;

class Solver {

    private final long A;
    private final long B;

    Solver(Scanner in) {
        A = in.nextLong();
        B = in.nextLong();
    }

    void solve() {
        System.out.println(factorize(gcd(A, B)).length + 1);
    }

    long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    long[] factorize(long x) {
        LongStream.Builder builder = LongStream.builder();
        long i = 2;
        for (; i * i <= x; i++) {
            int c = 0;
            while (x % i == 0) {
                x /= i;
                c++;
            }
            if (c > 0) builder.accept(x);
        }
        if (x != 1) builder.accept(i);
        return builder.build().toArray();
    }
}

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        new Solver(in).solve();

        in.close();
    }
}

Measured memory_bytes: 28628
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long // for codeforces

double cake[11][11];

bool solve(int w, vector<int> &vec){
  int n = vec.size();
  vector<vector<double>> dp(1<<n, vector<double>(n, INF));
  // dp[mask][n] mask ????????£????????????vec[i]???????°????
  rep(i,n) dp[1<<i][i] = 2*vec[i];
  repl(mask,1,1<<n) rep(i,n) if(dp[mask][i]<INF){
    rep(j,n) if((mask&(1<<j))==0){
      int nmask = mask | (1<<j);
      dp[nmask][j] = min(dp[nmask][j], dp[mask][i] + cake[vec[i]][vec[j]] + vec[j] - vec[i]);
    }
  }
  rep(i,n) if(dp[(1<<n)-1][i]<=w) return true;
  return false;
}


int main(){
  repl(i,3,11) repl(j,3,11){
    double c = i+j;
    double a = i-j;
    cake[i][j] = sqrt(c*c - a*a);
  }
  string str;
  while(getline(cin, str)){
    stringstream ss;
    ss<<str;
    int w;
    ss>>w;
    vector<int> vec;
    int r;
    while(ss>>r) vec.pb(r);
    if(solve(w,vec)) cout<<"OK"<<endl;
    else cout<<"NA"<<endl;
  }

  return 0;
}

Measured memory_bytes: 3432
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define ll long long
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

int bs(ll*a,ll n,ll x){
	//aのうちx以上のものの個数を求める
	if(a[0]<x)return 0;
	int l=0,r=n;
	while(r-l>1){
		int m=(l+r)/2;
		if(a[m]>=x)l=m;
		else r=m;
	}
	return r;
}

ll ceilsqrt(ll x){
	ll r=sqrt(x);
	while(r*r<x)r++;
	return r;
}

ll m[200010],p[200010];
ll mc,pc,zc;
int main(){
	ll n,k;
	scanf("%lld%lld",&n,&k);
	for(int i=0;i<n;i++){
		int t;
		scanf("%d",&t);
		if(t>0)p[pc++]=t;
		else if(t<0)m[mc++]=-t;
		else zc++;
	}
	
	ll ppp=pc*(pc-1)/2+mc*(mc-1)/2;
	ll mmm=pc*mc;
	sortdown(p,pc);
	sortdown(m,mc);

	if(k+ppp>n*(n-1)/2){
		//答えは正
		k=n*(n-1)/2+1-k;//大きい方からk番目
		ll l=0,r=1e18;//x以上のものがk個以上あるか？ l:ok,r:ng
		while(r-l>1){
			ll mid=(l+r)/2;
			ll cnt=0;
			for(int i=0;i<pc;i++)cnt+=bs(p,pc,(mid+p[i]-1)/p[i]);
			for(int i=0;i<mc;i++)cnt+=bs(m,mc,(mid+m[i]-1)/m[i]);
			cnt-=bs(p,pc,ceilsqrt(mid));
			cnt-=bs(m,mc,ceilsqrt(mid));
			cnt/=2;
			//printf("%lld %lld\n",mid,cnt);
			if(cnt>=k)l=mid;
			else r=mid;
		}
		printf("%lld",l);
	}else if(k<=mmm){
		//答えは負
		ll l=0,r=1e18;//-x以下のものがk個以上あるか？ l:ok,r:ng
		while(r-l>1){
			ll mid=(l+r)/2;
			ll cnt=0;
			for(int i=0;i<pc;i++)cnt+=bs(m,mc,(mid+p[i]-1)/p[i]);
			//printf("%lld %lld\n",mid,cnt);
			if(cnt>=k)l=mid;
			else r=mid;
		}
		printf("%lld",-l);
	}else{
		puts("0");
	}
}

Measured memory_bytes: 4496
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF=10000000;
const int mod=1e9+7;
int a,b,x,y;
int extgcd(int a,int b,int& x,int& y)
{
    int d=a;
    if(b!=0)
    {
        d=extgcd(b,a%b,y,x);
        y-=(a/b)*x;
    }
    else
    {
        x=1;
        y=0;
    }
    return d;
}
int main()
{
    scanf("%d %d",&a,&b);
    int d=extgcd(a,b,x,y);
    printf("%d %d\n",x,y);
    return 0;
}



Measured memory_bytes: 3228
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strArray = br.readLine().split(" ");
		int a = Integer.parseInt(strArray[0]);
		int b = Integer.parseInt(strArray[1]);
		System.out.println(getGCD(a, b));

	}

	public static int getGCD(int a, int b) {
		if (a == b) return a;
		else if (a < b) {
			return getGCD(a, b - a);
		}
		else return getGCD(a - b, a);
	}
}

Measured memory_bytes: 24428
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

void run (void) {
  const i32 n = read_int();
  const i32 l = read_int();
  i32 *a = (i32 *) calloc (n, sizeof (i32));
  for (i32 i = 0; i < n; ++i) {
    a[i] = read_int();
  }
  i32 *deq = (i32 *) calloc (n, sizeof (i32));
  i32 front = 0;
  i32 last = 0;
  for (i32 i = 0; i < l; ++i) {
    while (front < last && a[i] < deq[last - 1]) last--;
    deq[last++] = a[i];
  }
  print_int (deq[front]);
  for (i32 i = l; i < n; ++i) {
    if (a[i - l] == deq[front]) front++;
    while (front < last && a[i] < deq[last - 1]) last--;
    deq[last++] = a[i];
    putchar (' ');
    print_int (deq[front]);
  }
  putchar('\n');
}

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



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

using namespace std ;


set<int> s;
int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        s.insert(x);
    }
    cout << s.size() << endl;
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<tuple<string,int,int>>P; 
	for (int n = 0; n < N; ++n) {
		string S;
		int p;
		cin >> S >> p;
		P.emplace_back(S,-p,n + 1);
	}	
	sort(P.begin(),P.end());
	for (int n = 0; n < N; ++n) {
		cout << get<2>(P[n]) <<endl;

	}
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

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

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


mint mpow(int x, int n){
  if(n==0)return 1;

  mint y = mpow(x, n/2);
  y *= y;

  if(n%2==1) y *=x;
  return y;
}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};



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

  mint ans=1;
  REP(i,n)ans*=10;

  mint t=1;
  REP(i,n)t*=9;
  ans -= t*2;

  t=1;
  REP(i,n)t*=8;
  ans+=t;

  cout << ans.x << endl;
}



Measured memory_bytes: 3632
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int A[][][];
        A=new int[4][3][10];
        for(int i=0;i<N;i++){
            int a[];
            a=new int[4];
            for(int j=0;j<4;j++) a[j]=sc.nextInt();
            A[a[0]-1][a[1]-1][a[2]-1]+=a[3];
        }
        for(int i=0;i<4;i++){
            for(int j=0;j<3;j++){
                System.out.print(" ");
                for(int k=0;k<10;k++){
                    System.out.print(A[i][j][k]);
                    if(k!=9) System.out.print(" ");
                    else System.out.println();
                }
            }
            if(i!=3) System.out.println("####################");
        }
    }
}


Measured memory_bytes: 29488
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

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

int n, k;
int a[110];
int dp[100100];

int main()
{
  cin >> n >> k;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  fill(dp, dp + n, 0);
  for (int i = 1; i <= k; i++)
  {
    for (int j = 0; j < n; j++)
    {
      if (i >= a[j] && dp[i - a[j]] == 0)
      {
        dp[i] = 1;
      }
    }
  }
  cout << (dp[k] ? "First" : "Second") << "\n";
}

Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<vector>
#include<stdbool.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<string.h>
#include<ctype.h>
using namespace std;
int main()
{
	int a1=0, a2=0, a4=0;
	int n;
	cin >> n;
	for (int i = 0;i < n;i++)
	{
		int t;
		cin >> t;
		if (t % 4 == 0) a4++;
		else if (t % 2 == 0) a2++;
		else a1++;
	}
	if (a2 > 0 && a1 <= a4) cout << "Yes" << endl;
	else if(a2==0 && a1<=a4+1)cout << "Yes" << endl;
	else cout << "No" << endl;
	getchar();getchar();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;

//ここから

void solve(){
  int h,w;
  cin>>h>>w;
  vector<string>a(h);
  rep(i,h)cin>>a[i];
  bool ok=false;
  vector<int>c(26);
  rep(i,h){
    rep(j,w){
      c[a[i][j]-'a']++;
    }
  }
  int sum=0;
  rep(i,26){
    sum+=c[i]/4;
    c[i]%=4;
  }
  if(h%2==1&&w%2==1){
    int two=(h+w-2)/2;
    int one=1;
    rep(i,26){
      if(c[i]==2)two-=c[i]/2;
      else if(c[i]==1)one-=c[i];
    }
    if(two>=0&&one==0)ok=true;
  }
  else if(h%2==1){
    int two=w/2;
    bool ng=false;
    rep(i,26){
      if(c[i]==2)two-=c[i]/2;
      if(c[i]%2)ng=true;
    }
    if(!ng&&two>=0)ok=true;
  }
  else if(w%2==1){
    int two=h/2;
    bool ng=false;
    rep(i,26){
      if(c[i]==2)two-=c[i]/2;
      if(c[i]%2)ng=true;
    }
    if(!ng&&two>=0)ok=true;
  }
  else {
    bool ng=false;
    rep(i,26){
      if(c[i]!=0)ng=true;
    }
    if(!ng)ok=true;
  }
  if(ok)cout<<"Yes";
  else cout<<"No";
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}

Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

const mod = 10^^9+7;
alias mint = FactorRing!mod;

void main()
{
  int n, m; readV(n, m);
  int[] x; readA(n, x);
  int[] y; readA(m, y);

  auto xc = new mint[](n), yc = new mint[](m);
  xc[0] = x[0];
  foreach (i; 1..n) xc[i] = xc[i-1]+x[i];
  yc[0] = y[0];
  foreach (i; 1..m) yc[i] = yc[i-1]+y[i];

  auto s1 = new mint[](n);
  foreach (i; 1..n)
    s1[i] = s1[i-1] + mint(i)*x[i] - xc[i-1];
  auto s2 = new mint[](m);
  foreach (i; 1..m)
    s2[i] = s2[i-1] + mint(i)*y[i] - yc[i-1];

  writeln(s1[$-1]*s2[$-1]);
}

struct FactorRing(int m, bool pos = false)
{
  version(BigEndian) union { long vl; struct { int vi2; int vi; } } else union { long vl; int vi; }
  alias FR = FactorRing!(m, pos);
  @property static init() { return FR(0); }
  @property int value() { return vi; }
  @property void value(int v) { vi = mod(v); }
  alias value this;

  this(int v) { vi = v; }
  this(int v, bool runMod) { vi = runMod ? mod(v) : v; }
  this(long v) { vi = mod(v); }

  ref auto opAssign(int v) { vi = v; return this; }

  pure auto mod(int v) const { static if (pos) return v%m; else return (v%m+m)%m; }
  pure auto mod(long v) const { static if (pos) return cast(int)(v%m); else return cast(int)((v%m+m)%m); }

  static if (!pos) pure ref auto opUnary(string op: "-")() { return FR(mod(-vi)); }

  static if (m < int.max / 2) {
    pure ref auto opBinary(string op)(int r) if (op == "+" || op == "-") { return FR(mod(mixin("vi"~op~"r"))); }
    ref auto opOpAssign(string op)(int r) if (op == "+" || op == "-") { vi = mod(mixin("vi"~op~"r")); return this; }
  } else {
    pure ref auto opBinary(string op)(int r) if (op == "+" || op == "-") { return FR(mod(mixin("vl"~op~"r"))); }
    ref auto opOpAssign(string op)(int r) if (op == "+" || op == "-") { vi = mod(mixin("vl"~op~"r")); return this; }
  }
  pure ref auto opBinary(string op: "*")(int r) { return FR(mod(vl*r)); }
  ref auto opOpAssign(string op: "*")(int r) { vi = mod(vl*r); return this; }

  pure ref auto opBinary(string op)(ref FR r) if (op == "+" || op == "-" || op == "*") { return opBinary!op(r.vi); }
  ref auto opOpAssign(string op)(ref FR r) if (op == "+" || op == "-" || op == "*") { return opOpAssign!op(r.vi); }
}


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

int main(){
    int n;
    cin >> n;
    bool flag=false;
    for(int i=1; i<10; i++){
        for(int j=1; j<10;j++){
            if(i*j==n) flag=true;
        }
    }
    if(flag==true) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
const int INF = 2100100100;
const int MOD = 1e9 + 7;

int dp[110000][13];
 
int main() {
    string S;
    cin >> S;
    int len = S.size();
    reverse(S.begin(), S.end());
 
    if (S[0] == '?') {
        for (int i = 0; i < 10; i++) {
            dp[0][i] = 1;
        }
    } else {
        int index = S[0] - '0';
        dp[0][index] = 1;
    }
 
    int num = 1;
    for (int i = 1; i < len; i++) {
        num *= 10;
        num %= 13;
 
        if (S[i] == '?') {
            for (int j = 0; j < 10; j++) {
                for (int k = 0; k < 13; k++) {
                    int index = (k + j * num) % 13;
                    dp[i][index] += dp[i - 1][k];
                    dp[i][index] %= MOD;
                }
            }
        } else {
            for (int k = 0; k < 13; k++) {
                int j = (S[i] - '0');
                int index = (k + j * num) % 13;
                dp[i][index] += dp[i - 1][k];
                dp[i][index] %= MOD;
            }
        }
    }
 
    cout << dp[len - 1][5] << endl;
 
    return 0;
}

Measured memory_bytes: 5504
n = gets.to_i
a, d = gets.chomp.split.map(&:to_i)
h = Hash.new{|h, k| h[k] = k}
gets.to_i.times{
    x, y, z = gets.chomp.split.map(&:to_i)
    case x
    when 0
        temp = h[y]
        h[y] = h[z]
        h[z] = temp
    when 1
        h[y] = h[z]
    end
}
puts a + d * (h[gets.to_i] - 1)


Measured memory_bytes: 8872
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	#ifndef ONLINE_JUDGE
		// freopen("input.txt", "r", stdin);
		// freopen("output.txt", "w", stdout);
	#endif

	int n;
	cin >> n;
	string s[n];
	int t[n];
	for(int i = 0; i < n; i++) {
		cin >> s[i] >> t[i];
	}
	string x;
	cin >> x;
	int ans = 0;
	bool flag = 0;
	for(int i = 0; i < n; i++) {
		if(flag) {
			ans += t[i];
		}
		else if(x == s[i]) {
			flag = 1;
		}
	}
	cout << ans;

	return 0;
}

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

int main(){

    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    for(ll b = 1; b <= N; b++){
        ans += max(0LL, (N / b) * (b - K));
        if(N % b)ans += max(0LL, (N % b) - max(0LL, K - 1LL));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int a[1010];
int main()
{
	int n,k;cin>>n>>k;rep(i,n) cin>>a[i];sort(a,a+n);
	int out=0;rep(i,k) out+=a[i];
	cout<<out<<endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll a[220000],d[220000];
int main(){
    ll n,ans=220000;
    cin>>n;
    string s;
    cin>>s;
    if(s[0]=='#')a[0]=1;
    if(s[n-1]=='.')d[n-1]=1;
    rep(i,1,n){
        if(s[i]=='#')a[i]=a[i-1]+1;
        else a[i]=a[i-1];
        }
    irep(i,n-1,1){
        if(s[i-1]=='.')d[i-1]=d[i]+1;
        else d[i-1]=d[i];
        }
    rep(i,0,n-1)ans=min(a[i]+d[i+1],ans);
    ans=min(ans,d[0]);
    ans=min(ans,a[n-1]);
    cout<<ans<<endl;
}

Measured memory_bytes: 3716
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define MN 50
using namespace std;
inline int read()
{
    int x=0,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;
}
bool f[MN+5];
int n,a[MN+5],b[MN+5];long long ans=(1LL<<50)-1;
bool Solve(long long S,int s,int t)
{
    memset(f,0,sizeof(f));f[s]=1;
    for(int j=s;j;--j) if(f[j]) for(int k=1;k<=j;++k) if(S&(1LL<<k-1)) f[j%k]=1;
    return f[t];
}
int main()
{
    n=read();
    for(int i=1;i<=n;++i) a[i]=read();
    for(int j=1;j<=n;++j) b[j]=read();
    for(int i=1;i<=n;++i) if(!Solve(ans,a[i],b[i])) return 0*puts("-1");
    for(int i=50;i;--i)
    {
        ans^=1LL<<i-1;int flag=1;
        for(int j=1;j<=n;++j) if(!Solve(ans,a[j],b[j])) flag=0;
        if(!flag) ans|=1LL<<i-1;
    }
    cout<<(ans<<1);
    return 0;
}


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

using namespace std;

double odleglosc(pair<int,int> a,pair<int,int> b)
{
    int x=a.first-b.first;
    int y=a.second-b.second;
    x*=x;y*=y;
    return sqrt((double)(x+y));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<pair<int,int> > a;
    for(int i = 0;i<n;i++)
    {
        int pom,pom2;
        cin>>pom>>pom2;
        a.push_back(make_pair(pom,pom2));
    }
    vector<int> k;
    for(int i = 0;i<n;i++)k.push_back(i);
    double srednia=0;
    int ile=0;
    do
    {
        for(int i = 1;i<n;i++)srednia+=odleglosc(a[k[i]],a[k[i-1]]  );
        ile++;
    }while(next_permutation(k.begin(),k.end()));
    srednia=srednia/(double)ile;
    cout<<setprecision(9)<<srednia;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main (String[] args){
        Scanner scn = new Scanner(System.in);
        String s = scn.nextLine();
        String[] s2 = s.split("");
        String t = scn.nextLine();
        String[] t2 = t.split("");
        int cnt = 0;
        for(int i=0;i<3;i++){
            if(s2[i].equals(t2[i])){
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 21844