akhauriyash/Code-Regression huggingface dataset:
import           Control.Exception           (assert)
import           Control.Monad
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [n, m] <- getIntList
  as <- getIntList
  let s = sum as
      ans = n - s
  if ans < 0 then print (-1) else print ans

Measured memory_bytes: 4964
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
const LL N=200005;
LL ff[N],v[N];
LL n;
LL cnt0[N],cnt1[N];
struct qq
{
	LL x;
	qq () {}
	qq (LL _x)	{x=_x;}
};
bool operator < (qq x,qq y)	
{
	LL t=cnt1[x.x]*cnt0[y.x],t1=cnt0[x.x]*cnt1[y.x];
	return t==t1?x.x<y.x:t<t1;
}
set<qq> s;
LL fa[N];
LL find_fa (LL x)	{return fa[x]==x?x:fa[x]=find_fa(fa[x]);}
int main()
{
	scanf("%lld",&n);
	for (LL u=2;u<=n;u++) scanf("%lld",&ff[u]);
	for (LL u=1;u<=n;u++)
	{
		LL x;
		scanf("%lld",&x);
		if (x==0) cnt0[u]=1;
		else cnt1[u]=1;
		if (u!=1) 
		{
			//printf("YES:%lld\n",u);
			s.insert(qq(u));
		}
		fa[u]=u;
	}
	//printf("%lld\n",s.size());
	LL ans=0;
	while (!s.empty())
	{
		LL x=(*s.begin()).x;
		LL xx=find_fa(ff[x]);
	//	printf("%lld %lld\n",x,xx);
		ans=ans+cnt1[xx]*cnt0[x];
		s.erase(qq(x));
		if (xx!=1) s.erase(qq(xx));
		cnt1[xx]+=cnt1[x];
		cnt0[xx]+=cnt0[x];
		fa[x]=xx;
		if (xx!=1) s.insert(qq(xx));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 17280
#include <stdio.h>
#include <math.h>

#define sqr(x)  ((x) * (x))

int main(void)
{
  int n;
  int s[1001] = {0};
  int i;
  int sum = 0;
  double ave = 0;
  double sig = 0;

  while(1){

  scanf("%d", &n);

  if(n == 0)
    break;
  
  for(i = 0; i < n; i++){
    scanf("%d", &s[i]);

    sum += s[i];
  }

  ave = (double)(sum) / n;

  for(i = 0; i < n; i++)
    sig += sqr(s[i] - ave);

  sig /= n;

  printf("%.9f\n", sqrt(sig));

  sum = 0;
  sig = 0;
  
  }
  
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int h, w;
	cin >> h >> w;
	string t;
	char tag = '#';
	rep(i, w+2) {
		t += '#';
	}
	cout << t << endl;
	rep(i, h) {
		string s;
		cin >> s;
		cout << tag << "" << s << "" << tag << endl;
	}
	cout << t << endl;
	return 0;
}


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

using namespace std;

const int mod =1e9+7;

const int nax=2e5+5;

long long int dp[nax];
long long int suma[nax];

int main()
{
    int n; cin>>n;
    vector<int> xxx;
    for(int i=0;i<n;i++)
    {
        int x; cin>>x;
        xxx.push_back(x);
    }
    vector<int> a;
    a.push_back(xxx[0]);
    for(int i=1;i<n;i++)
    {
        if(xxx[i]!=a[a.size()-1]) a.push_back(xxx[i]);
    }
    n=a.size();
    dp[0]=1;
    suma[a[0]]=1;
    for(int i=1;i<n;i++)
    {
        long long int res=suma[a[i]];
        dp[i]=dp[i-1];
        dp[i]+=res;
        dp[i]%=mod;
        suma[a[i]]+=dp[i-1];
        suma[a[i]]%=mod;
    }
    cout<<dp[n-1];
    return 0;
}


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

int N, M;

int main() {
  vector<int> out;

  cin >> N;
  for (int i=0; i<N; i++) {
    int h, m;
    cin >> h >> m;
    out.push_back(h*60 + m);
  }
  cin >> M;
  for (int i=0; i<M; i++) {
    int h, m;
    cin >> h >> m;
    out.push_back(h*60 + m);
  }
  sort(out.begin(), out.end());
  out.erase( unique( out.begin(), out.end() ), out.end() );

  bool first = true;
  for (auto x : out) {
    if (!first) cout << " ";
    first = false;
    cout << x/60 << ":" << setfill('0') << setw(2) << x%60;
  }
  cout << "\n";
  return 0;
}

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

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

int lenght(char*str){ 
 int a=strlen(str);
 return a;
}

int main(void){
    char s[110];
    cin >> s;
    int flag=1;
    int n=lenght(s);
    int i;
    for(i=0;i<n;i++){
        //奇数
        //cout << s[i] << i << endl;
        if(i%2==0){
            if(s[i]=='R'||s[i]=='U'||s[i]=='D') continue;
            else flag=0;
        }
        else{
            if(s[i]=='L'||s[i]=='U'||s[i]=='D') continue;
            else flag=0;
        }
        //cout << flag << endl;
    }
    if(flag==1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

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

ll calc(ll a, ll b, ll c, ll d) {
  if (a < b) {
    return a;
  }
  ll ra = a % b;
  ll rc = c % b;
  if (ra > rc) {
    return c - rc + ra;
  }
  ra += b;
  return c - rc + ra;
}


bool judge(ll a, ll b, ll c, ll d) {
  if (a < b) {
    return false;
  }
  if (b > d) {
    return false;
  }
  if (b <= c+1) {
    return true;
  }
  // exist in [c+1, b-1] ?
  ll bo= c+1;
  ll to= b-1;


  ll g = gcd(b, d);
  a = calc(a, b, c, d);
  if (a >= b) {
    a -= b;
  }

  ll rbo = bo % g;
  ll rto = rbo - bo + to;
  ll ra = a % g;
  if (ra < rbo) {
    ra += g;
  }
  if (ra <= rto) {
    return false;
  }

  return true;
}

int main() {
  int t;
  scanf("%d", &t);
  rep (i, t) {
    ll a, b, c, d;
    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
    if (judge(a, b, c, d)) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }
  return 0;
}


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

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

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

int main(){
string S;
cin >> S;
if(S.at(5)=='1'||S.at(6)=='5'||S.at(6)=='6'||S.at(6)=='7'||S.at(6)=='8'||S.at(6)=='9'||S.at(6)=='0'){
    cout << "TBD" <<endl;
}
else{
    cout << "Heisei" <<endl;
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main() {
	int a, b, h; cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
}

Measured memory_bytes: 256
// ========================================================================================================
// Library
// ========================================================================================================
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>
using namespace std;

// competitive macro
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i ,n) for (int i = (n) - 1; i >= 0; i--)
#define LL long long
#define ULL unsigned long long

void fastIOS()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}
// ========================================================================================================
// ========================================================================================================

int main()
{
	fastIOS();

	int n; cin >> n;
    
    cout << 3*n*n << endl;
    
    return 0;
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	
	vector<VI> cs(3, VI(3));
	rep(i,3) rep(j,3) cin >>cs[i][j];
	
	rep(i,101) rep(j,101) rep(k,101){
		int ok =1;
		int b0 = cs[0][0] - i;
		int b1 = cs[0][1] - i;
		int b2 = cs[0][2] - i;
	
		if(j+b0 != cs[1][0] || j+b1 != cs[1][1] || j+b2 != cs[1][2]) ok=0;
		if(k+b0 != cs[2][0] || k+b1 != cs[2][1] || k+b2 != cs[2][2]) ok=0;
		
		if(ok){
			puts("Yes"); return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <climits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>
#include <array>
#include <unordered_map>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf 0x3f3f3f3f
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define VS vector<string>
#define VI vector<ll>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define pii pair<ll,ll>
#define pcc pair<char,char>
#define pic pair<ll,char>
#define pci pair<char,ll>
#define eps 1e-14
#define FST first
#define SEC second
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15)

namespace {
	struct input_returnner {
		ll N; input_returnner(ll N_ = 0) :N(N_) {}
		template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); }
		template<typename T> operator T() const { T res; cin >> res; return res; }
		template<typename T> T operator - (T right) { return T(input_returnner()) - right; }
		template<typename T> T operator + (T right) { return T(input_returnner()) + right; }
		template<typename T> T operator * (T right) { return T(input_returnner()) * right; }
		template<typename T> T operator / (T right) { return T(input_returnner()) / right; }
		template<typename T> T operator << (T right) { return T(input_returnner()) << right; }
		template<typename T> T operator >> (T right) { return T(input_returnner()) >> right; }
	};
	template<typename T> input_returnner in() { return in<T>(); }
	input_returnner in() { return input_returnner(); }
	input_returnner in(ll N) { return std::move(input_returnner(N)); }
}

ll MOD = 1e9 + 7;

void solve();

signed main() {
	SETUP;
	solve();
#ifdef _DEBUG
	system("pause");
#endif
	return 0;
}

#define int ll

void solve() {
	string s; cin >> s;
	cout << ((s.size() % 2 == 0) ^ (s.front() == s.back()) ? "Second": "First") << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>

using namespace std;

int main() {

	string x= "keyence";
	string s; cin >> s;

	for (int i = 0; i <6; i++) {
		if (s.find(x.substr(0, i+1)) == 0 && s.rfind(x.substr(i+1,6-i)) == s.size()-(6-i)) {
			cout << "YES" << endl; return 0;
		}
	}

	cout << "NO" << endl;
	
	return 0;
}

Measured memory_bytes: 256
S = input()
S = S[::-1]
s1 = 'maerd'
s2 = 'esare'
s3 = 'remaerd'
s4 = 'resare'

while(1):
	if S[:5] == s1:
		S = S[5:]
	elif S[:5] == s2:
		S = S[5:]
	elif S[:7] == s3:
		S = S[7:]
	elif S[:6] == s4:
		S = S[6:]
	else:
		break

if len(S)==0:
	print("YES")
else :
	print("NO")

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = a + b;
  if (b+c < ans) {
    ans = b + c;
  }
  if (c+a < ans) {
    ans = c + a;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
routes = []
for _ in range(n):
	time,x,y = map(int,input().split())
	routes.append((time,x,y))

now_x = 0
now_y = 0
time_now = 0
res = "Yes"
for time,x,y in routes :
	dist = abs(now_x - x) + (abs(now_y - y))
	t = time - time_now
	if t-dist < 0 or (t-dist)%2 != 0:
		res = "No"
		break
	now_x = x
	now_y = y
	time_now = time
print(res)

Measured memory_bytes: 17392
var input: string = require('fs').readFileSync('/dev/stdin', 'utf8');
var inputLines: string[] = input.trim().split("\n");
var parts = inputLines[0].split(" ");

var A = parseInt(parts[0]);
var op = parts[1];
var B = parseInt(parts[2]);
console.log(op == "+" ? A + B : A - B);

Measured memory_bytes: 7372
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>

using namespace std;

int main(void)
{
	double v, y, t, h, n;
	
	while(cin >> v){
		t = v / 9.8;
		y = 4.9 * t * t;
		n = (y + 5) / 5;
		n = (int) (ceil (n) );
		cout << n << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
const int maxn = 234566;
int u[maxn];
int find(int x){
	if(x == u[x]) return x;
	return u[x] = find(u[x]);
}
int x[maxn], y[maxn];
set<int> xx[maxn], yy[maxn];
int main(){
	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
	iota(u, u + maxn, 0);
	for(int i = 0; i < n; i++) u[find(x[i])] = find(y[i] + maxn / 2);
	for(int i = 0; i < n; i++){
		int nd = find(x[i]);
		xx[nd].insert(x[i]);
		yy[nd].insert(y[i]);
	}
	long long ans = 0;
	for(int i = 0; i < maxn; i++){
		ans += 1ll * xx[i].size() * yy[i].size();
	}
	cout << ans - n << endl;
	return 0;
}


Measured memory_bytes: 29696
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

#define INF 1e+9 //初期化注意
#define MAX_V 100000 //頂点数の最大値

struct edge {
	int to;
	int cost;
	//edge e ={to, cost}
};

// <最短距離, 頂点の番号>
using P = pair<int, int>;

int N;// 頂点の数
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
	//sからiへの最短距離をd[i]に保存 i=e.to
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + N, INF);
	d[s] = 0;//初期位置へのコストは0

	que.push(P(0, s));
	//queはmake_pair(cost,to)?

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;//v=e.to	from s to v
		//すでにこの経路よりいい経路が見つかっているなら無視
		if (d[v] < p.first) continue;
		

		for (int i = 0; i < G[v].size(); ++i) {
			edge e = G[v][i];
			// i 番目の v と v'を結ぶ辺　G=<e.to, e.cost>
			//e.to=v'
	                //e.cost means v to v' cost e.cost
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				//from s to v'> from s to v + from v to v'
				//vを経由したほうがコストが低いなら経由する
				que.push(P(d[e.to], e.to));
			}
		}
	}
}


	//dijkstra(int s); nからの最短距離を計算
	//d[i]はsからiまでの最短距離が保存される the path from s to i cost d[i]



void solve()
{
	cin >> N;
	int M;//辺の数
	cin>>M;
	vector<vector<int>>twin(N);
	for (int i = 0; i < M; ++i) {
		int a, b, c;
		cin >> a >> b;
		c=1;
		a--; b--;
		//the route a to b cost c
		edge e = { b, c };
		G[a].push_back(e);
		e={a,c};
		G[b].push_back(e);
		twin[a].push_back(b);
		twin[b].push_back(a);
		//有向グラフの場合であり、無向グラフなら e{a,c}も必要
	}
	dijkstra(0);
	
	map<int,int>to;
	
	bool ans=true;
	rep(i,N){
		
		if(i){
			if(d[i]==1){
				to[i]=0;
			}else{
				bool ok=false;
				rep(j,twin[i].size()){
					if(d[twin[i][j]]==d[i]-1){
						to[i]=twin[i][j];
						ok=true;
						j=1e6;
					}
				}
				if(!ok){
					//cout<<i+1<<" "<<d[i]<<endl;
					ans=false;
				}
			}
		}
	}
	if(ans){
		cout<<"Yes"<<endl;
		FOR(i,1,N){
			cout<<to[i]+1<<endl;
		}
	}else{
		cout<<"No"<<endl;
	}



}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MOD  1000000007
#define mod1 1000000009
#define var    int i,j,c=0,t,l,r,mid,z=0,k,x,y
#define aloc(n,t) ((t*)malloc((n)*sizeof(t)))

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

ll n,m;
int main()
{
    ll a,b;
    sfl(a);
    sfl(n);sfl(m);
    for(ll i=n;i<=m;i++)
    {
        if(i%a==0)
        {
            pf("OK\n");
            return 0;
        }
    }
    pf("NG\n");
}


Measured memory_bytes: 3652
let _ = read_int ()
let f t s = Str.(let rec f a i r = String.(if i >= length s then a else try f (a + 1) (search_forward r s i + length t) r with _ -> a) in f 0 0 (regexp t))
let _ = f "ABC" (read_line ()) |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;

signed main() {
    ll t;
    cin >> t;

    if(t == 0) {
        cout << 0 << endl;
        return 0;
    }

    ll speed = 1, sum = 1, ans = 1;
    while(sum<t) {
        // speedを上げるか？
        {
            ll need = (speed*9-1)/2;
            if(sum+need <= t+1) speed *= 3;
        }
        // speedを維持できるか？
        {
            ll need = (speed*3-1)/2;
            if(sum+need > t+1) speed /= 3;
        }

        sum += speed;
        ans++;
        // cerr << speed << " " << sum << " " << ans << endl;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3168
//============================================================================
// Name        : HelloWorld.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
typedef long long ll;
using namespace std;
int N,D;
int R=0;
int X[11][11];
int main() {
	cin>>N>>D;

	for(int i=0;i<N;i++){
		for(int j=0;j<D;j++){
			cin>>X[i][j];
		}
	}
	int S=0;
	for(int i=0;i<N-1;i++){
		for(int j=i+1;j<N;j++){
			S=0;
			for(int k=0;k<D;k++){
				S+=abs((X[i][k]-X[j][k])*(X[i][k]-X[j][k]));
			}
			for(int b=0;b<127;b++){
				if(S==b*b){
					R++;
				}
			}
		}
	}

	cout<<R<<endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
efforts = [list(map(int, input().split())) for _ in range(n)]

dp = [[float('inf')] * 3] * n

dp[0][0] = efforts[0][0]
dp[0][1] = efforts[0][1]
dp[0][2] = efforts[0][2]

for i in range(1, n):
    eab = dp[i-1][0] + efforts[i][1]
    eac = dp[i-1][0] + efforts[i][2]
    eba = dp[i-1][1] + efforts[i][0]
    ebc = dp[i-1][1] + efforts[i][2]
    eca = dp[i-1][2] + efforts[i][0]
    ecb = dp[i-1][2] + efforts[i][1]

    dp[i][0] = max(eba, eca)
    dp[i][1] = max(eab, ecb)
    dp[i][2] = max(eac, ebc)

print(max(dp[n-1]))

Measured memory_bytes: 64600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,a; cin >> n;
	int sum =0;
	if(n==1) cout << "Hello World" << endl;
	if(n==2){
		while(n--){
			cin >> a;
			sum += a;
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 256
def main():
    A, B, K = map(int, input().split())
    if B - A + 1 > K * 2:
        for i in range(A, A + K):
            print(i)
        for i in range(B - K + 1, B + 1):
            print(i)
    else:
        for i in range(A, B + 1):
            print(i)


main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  vector<int> a(3);
  for(int i = 0; i < 3; i++) cin>>a[i];
  sort(a.begin(), a.end());
  for(int i = 2; i >= 0; i--) {
    a[i] -= a[0];
  }
  int ans = 0;
  if(a[2] % 2 == 0) {
    ans += (a[2]-a[0])/2;
    if(a[1] % 2 == 0) {
      ans += (a[2]-a[1])/2;
    } else {
      ans += (a[2]+1-a[1])/2;
      ans++;
    }
  } else {
    if(a[1] % 2 == 0) {
      ans += (a[2]-1-a[0])/2;
      ans += (a[2]-1-a[1])/2;
      ans++;
    } else {
      ans += (a[2]+1-a[0])/2;
      ans += (a[2]-a[1])/2;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
$i = 1;
do {
 $x = $i;
 if ($x % 3 === 0) {
    echo " $i";
  } else {
    do {
      if ( $x % 10 === 3) {
        echo " $i";
        break;
      } else {
        $x /= 10;
      }
    } while ( $x );
  }
} while (++$i <= $n);
echo PHP_EOL;

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

using namespace std;

int main() {
 int n;
 cin>>n;
 vector <int> vec;
 for(int i=0;i<n;i++)
{
int x;
cin>>x;
vec.push_back(x);
}
 vector <int> gcd1,gcd2;
 gcd1.push_back(vec[0]);
 int l=vec[0];
 for(int i=1;i<n;i++)
 {
     gcd1.push_back(__gcd(vec[i],l));
     l=__gcd(vec[i],l);

 }
 l=vec[n-1];
 gcd2.push_back(vec[n-1]);
 for(int i=n-1-1;i>=0;i--)
 {

     gcd2.push_back(__gcd(vec[i],l));
   l= __gcd(vec[i],l);
 }
 reverse(gcd2.begin(),gcd2.end());


 vector <int> st;
 for(int i=1;i<n-1;i++)
 {

     st.push_back(__gcd(gcd1[i-1],gcd2[i+1]));
 }
 st.push_back(gcd1[n-2]);
 st.push_back(gcd2[1]);


 sort(st.begin(),st.end(),greater<int>());
 cout<<*st.begin();

}

Measured memory_bytes: 2168
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define quickIO()	{cin.tie(0);	cout.sync_with_stdio(false);}
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<(int)n;i++)
#define REP(i,n)	for(int i=0;i<=(int)n;i++)
#define srep(i,a,n)	for(int i=a;i<(int)n;i++)
#define SREP(i,a,n)	for(int i=a;i<=(int)n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll sqrt(ll x) {
	ll left = 0, right = x;
	rep(i, 100) {
		ll mid = (left + right) >> 1;
		if (mid*mid <= x)	left = mid;
		else	right = mid;
	}
	return left;
}
ll gcd(ll a, ll b) {
	return a%b == 0 ? b : gcd(b, a%b);
}
#define debug(x)	printf("Case #%d: ", x)
#define DEBUG 0
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ld eps = 1e-15;
const int dx[] = { 1,0,-1,0,0 };
const int dy[] = { 0,1,0,-1,0 };

// めんどくさいので、色ごとにまとめて塗りたいですよね。
// これが上手くいく方法を考えると、以下の方法で上手くいきます。
/*
→→→→→↓
↓←←←←←
→→→→→↓
…
*/
// これなら色毎に全部連結になりますよね？（他別解は多数存在すると思います）
// 処理はyの偶奇で上手く分けます。コード読めばわかるかと。

int main() {
	// データの入手
	int h, w;	cin >> h >> w;
	int n;	cin >> n;
	vint a(n);
	rep(i, n)	cin >> a[i];

	// 答えは2次元配列に取り敢えず入れます。
	vector<vint> ret(h, vint(w, 0));
	// 色ごとにループを回して、座標はループの外側に用意しておいて、制御します。
	int x = 0, y = 0;
	rep(i, n) {
		rep(j, a[i]) {
			ret[y][x] = i + 1;
			// yが奇数の時（左へ動かしていきます）
			if (y & 1) {
				// x==0ならyを進め、そうでないなら左へ。
				if (!x)	y++;
				else	x--;
			}
			// yが偶数の時（右へ）
			else {
				// 同様に。
				if (x == w - 1)	y++;
				else	x++;
			}
		}
	}

	// 答えの出力。
	rep(i, h) {
		// j==0の時だけ半角スペースの出力を省略してます
		rep(j, w)	cout << (j ? " " : "") << ret[i][j];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main()
{

 int i,j,n;
 int a[100];
 scanf("%d",&n);

 for(i=0;i<n;i++){
                  scanf("%d",&a[i]);
                 }
 for(i=n-1;i>=1;i--){
                  printf("%d ",a[i]);          
                 }

 printf("%d\n",a[0]);
 return 0;
}


Measured memory_bytes: 2044
#include <stdio.h>

using namespace std;

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



Measured memory_bytes: 2760
n = int(input())
max_count = 0
ans = 1
for i in range(1, n + 1):
    x = i
    for j in range(1, n):
        if x % 2 == 0:
            x //= 2
        else:
            if j > max_count:
                max_count = j
                ans = i
            break
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  map<int,int> mp;
  for(int i=0; i<N; i++){
    if(mp.count(vec.at(i))){
      mp[vec.at(i)]++;
    }
    else{
      mp[vec.at(i)] = 1;
    }
  }
  int cnt = 0;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    int x = itr->second;
    if(x %2 == 0){
      cnt++;
    }
  }
  if(cnt %2 == 0){
    cout << mp.size() << endl;
  }
  else{
    cout << mp.size()-1 << endl;
  }
}

Measured memory_bytes: 5376
s = input()
k = int(input())
t = sorted(s)[min(k-1,len(s)-1)]
data = []
for i in range(len(s)):
    if s[i] <= t:
        data.append(s[i:])
data.sort()
if len(data) > k:
    data = data[:k]

ndata = []
for ss in data:
    for i in range(len(ss)):
        ndata.append(ss[:i+1])
ndata = list(set(ndata))
ndata.sort()
print(ndata[k-1])


Measured memory_bytes: 41840
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    ll n, a, b;
    cin >> n >> a >> b;
    if (a % 2 == b % 2)
        cout << (b - a) / 2;
    else
        cout << min((a + b - 1) / 2, (2 * n - b - a + 1) / 2);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define inf 1e9
#define mod 1000000007
#define ff first
#define ss second

void solve()
{
	int x;
	cin>>x;
	if(x>=30)
		cout<<"Yes"<<"\n";
	else
		cout<<"No"<<"\n";
}

signed main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main {

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

        int N = sc.nextInt();
        List<Point> red = new ArrayList<>();
        List<Point> blue = new ArrayList<>();

        for (int i=0; i<N; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();

            red.add(new Point(a, b));
        }
        for (int i=0; i<N; i++) {
            int c = sc.nextInt();
            int d = sc.nextInt();

            blue.add(new Point(c, d));
        }

        System.out.println(solve(N, red, blue));

    }

    static class Point {
        public int x, y;

        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    private static int solve(int N, List<Point> red, List<Point> blue) {
        int ans = 0;

        Collections.sort(red, new Comparator<Point>() {
            public int compare(Point p1, Point p2) {
                return p1.x - p2.x;
            }
        });
        Collections.sort(blue, new Comparator<Point>() {
            public int compare(Point p1, Point p2) {
                return p1.x - p2.x;
            }
        });

        for (int i=0; i<blue.size(); i++) {
            Iterator it = red.iterator();
            Point max = null;
            while (it.hasNext()) {
                Point p = (Point)it.next();
                if (p.x < blue.get(i).x && p.y < blue.get(i).y) {
//                    System.err.println(p.x + ", " + p.y + " < " + blue.get(i).x + ", " + blue.get(i).y);
                    if (max == null || max.y < p.y) {
                        max = p;
                    }

                }
            }
            if (max != null) {
                ans++;
                red.remove(max);
            }
        }

        return ans;
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <map>
#define fr first
#define sc second
using namespace std;

typedef pair<int, int> iP;

int main(){
    
    int n, m;
    while(cin >> n, n){
        map <iP, int> flag;
        vector <iP> pos(n), mas;
        
        for(int i = 0; i < n; i++){
            int x, y; cin >> x >> y;
            if(!i) pos[i].fr = x, pos[i].sc = y;
            else pos[i].fr = x - pos[0].fr, pos[i].sc = y - pos[0].sc;
        }
        cin >> m;
        mas.resize(m);
        for(int i = 0; i < m; i++){
            cin >> mas[i].fr >> mas[i].sc;
            flag[iP(mas[i].fr, mas[i].sc)]++;
        }
        
        int ax, ay;
        for(int i = 0; i < m; i++){
            bool judge = true;
            for(int j = 1; j < n; j++){
                if(!flag[iP(mas[i].fr + pos[j].fr, mas[i].sc + pos[j].sc)]) {
                    judge = false; break;
                }
            }
            if(judge){
                ax = -(pos[0].fr - mas[i].fr), ay = -(pos[0].sc - mas[i].sc);
                break;
            }
        }
        cout << ax <<  " " << ay << endl;
    }
}

Measured memory_bytes: 1308
#include <stdio.h>
#include <stdlib.h>


typedef struct link_t{
	int id;
	struct link_t *next;
}LINK_T;


typedef struct{
	int color;
	struct link_t *next;
}USER_T;


void Bfs(USER_T *user, int id, int color)
{
	LINK_T *p;


	if(user[id].color != -1)
		return;

	user[id].color = color;

	for(p = user[id].next; p != NULL; p = p->next)
		Bfs(user, p->id, color);
}

LINK_T *my_alloc()
{
	LINK_T *p;

	if( (p = (LINK_T *)malloc(sizeof(LINK_T))) == NULL){
		printf("malloc error\n");
		exit(1);
	}

	return p;
}

int main()
{
	int users, relation_n;
	int q_n;
	USER_T *user;
	LINK_T *p;
	int id, sub_id, r_id;	// relation_id
	int i, j;


	scanf("%d %d", &users, &relation_n);

	user = (USER_T *)malloc(sizeof(USER_T) * users);

	for(i = 0; i < users; i++){
		user[i].color = -1;
		user[i].next = NULL;
	}

	for(i = 0; i < relation_n; i++){
		scanf("%d %d", &id, &r_id);
		p = my_alloc();
		p->id = r_id;
		p->next = user[id].next;
		user[id].next = p;

		p = my_alloc();
		p->id = id;
		p->next = user[r_id].next;
		user[r_id].next = p;
	}
/*
	for(i = 0; i < users; i++){
		printf("<%d>\n", i);
		for(p = user[i].next; p != NULL; p = p->next){
			printf(" %d", p->id);
		}
		printf("\n");
	}
*/
	// BFS(グループ分け)
	for(i = 0; i < users; i++)
		Bfs(user, i, i + 1);

	scanf("%d", &q_n);
	for(i = 0; i < q_n; i++){
		scanf("%d %d", &id, &sub_id);
		if(user[id].color == user[sub_id].color)
			printf("yes\n");
		else
			printf("no\n");
	}


	return 0;
}


Measured memory_bytes: 12576
import java.util.*;
public class Main{

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

        int n = Integer.parseInt(sc.next());
        List<Integer> list = new ArrayList<>(n);
        for(int i=0; i<n; i++){
            list.add(Integer.parseInt(sc.next()));
        }
        
        int q = Integer.parseInt(sc.next());
        int start,end,search,count;
        
        for(int i=0; i<q; i++){
            start = Integer.parseInt(sc.next());
            end = Integer.parseInt(sc.next());
            search = Integer.parseInt(sc.next());
            count=0;
            for(int j=start; j<end; j++){
                if(list.get(j) == search) count++;
            }
            System.out.println(count);
        }
    }
}




Measured memory_bytes: 38544
#include <iostream>
#include <algorithm>
#include <bitset>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

const long int MAX_N = 100,  MAX_P = 10000000;

int main(int argc, char const *argv[]) {
  long long int n, p[MAX_N][11];
  cin >> n;
  vector<bitset<10>> fvec;

  for (size_t i = 0; i < n; i++) {
    bitset<10> bs(0);
    for (size_t j = 0; j < 10; j++) {
      int temp;
      cin >> temp;
      if (temp) bs.set(j);
    }
    fvec.push_back(bs);
  }

  for (size_t i = 0; i < n; i++) {
    for (size_t j = 0; j <= 10; j++) cin >> p[i][j];
  }

  long long int ans = -(1<<30);

  for (size_t i = 1; i < pow(2,10); i++) {
    bitset<10> joisino(i);
    int c;
    long long int sum = 0;
    for (size_t j = 0; j < n; j++) {
      bitset<10> andbits = joisino & fvec[j];
      c = andbits.count();
      sum += p[j][c];
    }
    if (sum > ans) ans = sum;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a,b,c;
int main()
{
	cin >> a >> b >> c;
	if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0)
		cout << 0 << endl;
	else
		cout << min(min(a*b,a*c),b*c) << endl;
	return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

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

  vector<int> x(n);
  vector<int> y(m);
  rep(i, n) {
    cin >> x.at(i);
  }
  rep(i, m) {
    cin >> y.at(i);
  }

  n--;
  m--;
  ll sumx = 0;
  ll sumy = 0;
  for(ll i=0; i<n; i++) {
    ll mul = ((n-i)*(i+1))%mod;
    sumx += ((ll)x.at(i+1)-x.at(i))*mul%mod;
    sumx %= mod;
  }
  for(ll i=0; i<m; i++) {
    ll mul = ((m-i)*(i+1))%mod;
    sumy += ((ll)y.at(i+1)-y.at(i))*mul%mod;
    sumy %= mod;
  }
  cout << (sumx*sumy)%mod << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) (1e9 + 7);
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);
    int r;
    cin >> r;
    cout << 3 * r * r << endl;


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
 
 
int main() {
    int k,n;
    cin >> k >> n;
    vector<int> A(n);
    int m=-1;
    rep(i,n){
        cin >> A[i];
    }
    rep(i,n-1){
        m = max(m,abs(A[i]-A[i+1]));
    }
    m = max(m,abs(A[0]+(k-A[n-1])));
    cout << k-m << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    int r = count(ALL(s), 'R');
    int b = N - r;
    if (r > b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return (0^_^0);
}



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

int main () {
  int N, K;
  cin >> N >> K;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    int a = A.at(i);
    B.at(a-1)++;
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (B.at(i) != 0) count++;
  }
  sort(B.begin(), B.end());
  int ans = 0;
  while (count > K) {
    ans += B.at(N-count);
    count--;
  }
  cout << ans << endl;
}

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

int main(){

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

    return 0;
}

Measured memory_bytes: 1156
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l


a=nCast(input().split())
def func(a):
    return a[0]/a[1]
    
print(func(a)) 







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

/** defines and macros */
#define ll long long
#define ull unsigned long long
#define loop(n) for(int i = 0; i < n; i++)
#define loop1(n) for(int i = 1; i <= n; i++)
#define all(v) (v.begin(), v.end())
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vvi vector<vi>
#define vvpii vector<vii>
#define PB push_back

#define fw(fileName) freopen(fileName, "w", stdout)
#define fr(fileName) freopen(fileName, "r", stdin)
#define fc(stream) fclose(stream);

#define faster_IO_stream ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

/*To compile and run

	g++ -o main main.cpp && ./main

*/

/*
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣀⣤⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣤⣀⡀⠄⠄⠄⠄⠄⣰⣷⡀⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⣀⣀⣀⠄⠄⠄⠄⠄⣠⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣄⠄⠄⢠⣿⣿⣷⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠤⠒⠛⠛⠛⠛⠻⠷⣦⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⣿⣿⣿⠟⠁⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⢀⣤⣤⣶⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣡⡤⠐⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⢀⣶⣿⣿⠿⢛⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠁⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⢠⣿⠟⠉⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠘⠁⠄⢀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠻⣿⣿⣿⣿⣿⣿⣿⡛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⣾⣿⡿⣽⡿⢹⣿⣿⣟⣿⢻⠇⢀⢹⣿⢿⣿⣿⣿⣿⣿⣦⣙⢿⣿⢷⣈⠻⢿⣟⢿⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⢿⡿⠁⡿⠁⢸⣿⣿⢹⡇⢸⠄⠈⠄⠻⣏⠻⣿⡿⣿⣿⣿⣌⠛⢿⡌⠙⢧⣀⠙⢳⡹⢻⣿⣿⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠘⡇⠄⡇⢠⣼⣿⣿⠈⡇⠘⠤⠤⠤⠤⢜⣢⣘⡻⢮⡛⢿⣿⣷⣬⡤⠤⠤⠤⠥⠤⠥⢬⣿⣧⡄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠁⠄⠄⠘⢿⡏⠛⠄⠄⠄⠄⠄⠄⠄⠄⠄⠙⣿⣿⣿⡿⠋⠉⠛⠉⠄⠄⠄⠄⠄⠄⠄⢹⡿⠃⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠘⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⡟⠁⠈⢳⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢸⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠱⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⡜⠁⠄⠄⠈⢇⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠑⠦⢄⣀⣀⣀⣀⣀⠴⠊⠄⠄⠄⠄⠄⠄⠑⠤⢀⣀⣀⣀⡀⠠⠔⠋⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣶⣦⣄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣤⣶⣆⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢸⣿⣿⣿⣿⣶⣄⣀⣀⣀⣀⣤⣾⣿⣿⣿⣿⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢸⣿⣿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣿⣿⣿⣿⣿⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠘⣿⣿⣿⣿⠟⠁⠄⠄⠄⠄⠙⢿⣿⣿⣿⡟⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠘⠟⠋⠁⠄⠄⠄⠄⠄⠄⠄⠄⠉⠛⠿⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
 */

int modulo = 1e9 + 7;

int main() {
	faster_IO_stream

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

	int slen = s.length(), tlen = t.length();
	vi n(slen - tlen + 1, 1e7);

	loop(slen - tlen + 1) {
		int res = 0;
		for(int j = i; j < i + tlen; j++)
			if(s[j] != t[j - i]) res++;
		n[i] = res;
	}

	int r = 1e7;
	loop(slen - tlen + 1) if(n[i] < r) r = n[i];

	cout << r << endl;

	return 0;
}



Measured memory_bytes: 3644
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  unused_macros,
  dead_code
)]
use proconio::fastout;
use proconio::input;
use proconio::marker::*;
use std::cmp::*;
use std::collections::*;
//use std::collections::VecDeque;
macro_rules! debug {
  ($($a:expr),* $(,)*) => {
      #[cfg(debug_assertions)]
      eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
  };
}
#[fastout]
fn main() {
  input! {
    N:usize,
    XY:[(i64,i64);N]
  }
  // 傾き-1の線分の距離が最大になるケースと傾き1の線分のケースで考える。
  let mut v1 = 0;
  let mut v2 = 0;
  // 傾き1のケース
  let mut minV1 = 2000000000;
  let mut maxV1 = -2000000000;
  let mut minV2 = 2000000000;
  let mut maxV2 = -2000000000;
  for i in 0..N {
    v1 = XY[i].0 + XY[i].1;
    v2 = XY[i].0 - XY[i].1;
    minV1 = min(minV1, v1);
    minV2 = min(minV2, v2);
    maxV1 = max(maxV1, v1);
    maxV2 = max(maxV2, v2);
  }
  let mut ans = max(maxV1 - minV1, maxV2 - minV2);
  println!("{}", ans);
}


Measured memory_bytes: 8912