akhauriyash/Code-Regression huggingface dataset:
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        a: usize,
        b: f64
    }
    let mut int_b = b as usize;
    let mut ans = a * int_b;
    let mut min_b = ((b - int_b as f64) * 100.0).round() as usize;
    ans += (a * min_b) / 100;

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

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2716
#include<iostream>
#include<vector>
//#include<algorithm>
#include<numeric>
#include<cstdio>
using namespace std;
int main(){
  int n;
  vector<double> a;
  cin >> n;
  double tmp;
  for(int i=0 ; i<n;++i){
    cin >> tmp;
    a.push_back(1.0f/tmp);
  }
  double lenom = 0.f;
  //for(int i=0 ; i<n;++i){
  //  lenom += a[i];
  //}
  lenom = std::accumulate(a.begin(), a.end(), 0.0f);
  double result = 1/lenom;
  
  cout << result;
  //printf("%lf\n", result);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a < b)
		if (b < c)
			printf("%d %d %d\n", a, b, c);
		else if (c < a)
			printf("%d %d %d\n", c, a, b);
		else
			printf("%d %d %d\n", a, c, b);
	else
		if (a < c)
			printf("%d %d %d\n", b, a, c);
		else if (c < b)
			printf("%d %d %d\n", c, b, a);
		else
			printf("%d %d %d\n", b, c, a);
		return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    int h=s.size();
    int w=t.size();
    vector<vector<int> > dp(h+1,vector<int>(w+1));
    REP(i,1,h+1){
	REP(j,1,w+1){
	    if(s[i-1]==t[j-1]){
		dp[i][j]=dp[i-1][j-1]+1;
	    }
	    else{
		dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	    }
	}
    }
    string ans;
    while(dp[h][w]!=0){
	if(dp[h][w]==dp[h-1][w]){
	    h--;
	}
	else if(dp[h][w]==dp[h][w-1]){
	    w--;
	}
	else{
	    ans+=s[h-1];
	    h--;
	    w--;
	}
    }
    reverse(all(ans));
    cout<<ans<<'\n';
    return(0);
}


Measured memory_bytes: 35584
/*
 _    _    _______   _    _
| |  / /  |  _____| | |  / /
| | / /   | |       | | / /
| |/ /    | |_____  | |/ /
| |\ \    |  _____| | |\ \
| | \ \   | |       | | \ \
| |  \ \  | |_____  | |  \ \
|_|   \_\ |_______| |_|   \_\

*/
#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define right(x) x << 1 | 1
#define left(x) x << 1
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
#define mkp make_pair
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekekek

const ll ool = 1e18 + 9;
const int oo = 1e9 + 9, base = 1e9 + 7;
const ld eps = 1e-7;
const int N = 2e6 + 6;

int n, cnt0, cnt1;

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

	cin >> n;
	forn(i, 1, n) {
        int x;
        cin >> x;
        if (x & 1) cnt1++;
        if (x % 4 == 0) cnt0++;
    }

    if (cnt1 - (cnt1 + cnt0 == n) > cnt0) cout << "No\n";
    else cout << "Yes\n";

	return 0;
}


Measured memory_bytes: 256
// AOJ 1350 There is No Alternative
// 2018.3.2 bal4u
 
#include <stdio.h>
//#include <stdlib.h>
#include <string.h>
 
/* UNION-FIND library */
#define MAX 502
int id[MAX], size[MAX];
void init(int n) { int i; for (i = 0; i < n; i++) id[i] = i, size[i] = 1; }
int root(int i) { while (i != id[i]) id[i] = id[id[i]], i = id[i]; return i; }
int connected(int p, int q) { return root(p) == root(q); }
void unite(int p, int q)
{
    int i = root(p), j = root(q); if (i == j) return;
    if (size[i] < size[j]) id[i] = j, size[j] += size[i]; else id[j] = i, size[i] += size[j];
}

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

typedef struct { int s, d, c; } T;
T e[50002], e0[50002];
T ee[50002]; int sz;
int f[10002];


int main()
{
	int N, M, i, j, t, MST, ansf, anss;

	N = in(), M = in();
	for (i = 0; i < M; i++) {
		e0[i].s = in()-1, e0[i].d = in()-1, e0[i].c = t = in();
		f[t]++;
	}
	for (i = 1; i <= 10000; i++) f[i] += f[i-1];
	for (i = M-1; i >= 0; i--) t = e0[i].c, e[--f[t]] = e0[i];

	MST = 0, sz = 0, init(N);
	for (i = 0; i < M; i++) {
		if (!connected(e[i].s, e[i].d)) {
			unite(e[i].s, e[i].d);
			ee[sz++] = e[i], MST += e[i].c;
		}
	}

	ansf = anss = 0;
	for (i = 0; i < sz; i++) {
		int ss = ee[i].s, dd = ee[i].d;
		init(N);
		t = 0;
		for (j = 0; j < M; j++) {
			if (!connected(e[j].s, e[j].d) && (e[j].s != ss || e[j].d != dd)) {
				unite(e[j].s, e[j].d);
				t += e[j].c;
			}
		}
		if (t != MST) ansf++, anss += ee[i].c;
	}
	printf("%d %d\n", ansf, anss);
	return 0;
}


Measured memory_bytes: 3060
#ifndef _WIN32
#include<iostream>
#endif 

#include<cmath>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

#define FOR(i,bg,ed) for(int i = (bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
struct cww {
	cww() {
		ios::sync_with_stdio(false);
		cin.tie(0);
	}
}star;
template<typename T>
istream & operator>> (istream &is, vector<T>&v) {
	for (auto &it : v)is >> it;
	return is;
}
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
typedef pair<int, int> P;
const int INF = 1e7;
int main() {
	int n;
	while (cin >> n, n) {
		vector<P> rw(n);
		REP(i, n)cin >> rw[i].fi >> rw[i].se;
		sort(ALL(rw));
		reverse(ALL(rw));
		int rsum = 0;
		int wsum = 0;
		REP(i, n) {
			rsum += rw[i].fi;
			wsum += rw[i].se;
		}
		if (rw.front().first * 2 <= rsum) {
			cout << rsum + wsum << endl;
		}
		else {
			int rest = rw.front().first * 2 - rsum;
			vector<int> dp(rest + 1, 0);
			dp[0] = 1;
			FOR(i, 1, n) {
				for (int j = rest; j >= rw[i].se; j--) {
					dp[j] |= dp[j - rw[i].se];
				}
			}
			int ans = 0;
			REP(i, rest + 1)if (dp[i])ans = i;
			cout << rest - ans + rsum + wsum << endl;
		}


	}


	return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){
      lint n;
      string s;
      cin>>n>>s;
      lint count=0,count1=0;
      rep(i,n){
          if(s[i]=='.')count++;
      }
      lint ans=INF;
      rep(i,n){
        ans=min(ans,count1+count);
        if(s[i]=='#')count1++;
        else count--;

      }
      ans=min(ans,count1+count);
      cout<<ans<<endl;
      
  }
      

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    int N;
    cin >> N;
    vector<string> S(N);
    vector<int> P(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i] >> P[i];
    }

    vector<int> ans(N);
    for (int i = 0; i < N; i++) {
        int t = 0;
        for (int j = 0; j < N; j++) {
            if (i == j) continue;
            t += (S[j] < S[i] ? true : S[j] > S[i] ? false : P[j] > P[i]);
        }
        ans[t] = i;
    }

    for (int x : ans) {
        cout << x + 1 << endl;
    }
}


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

i = 0
a = []
a.append(s)
b = [0] * 10000

while True:
    if a[i] % 2 == 0:
        a.append(a[i] // 2)
    else:
        a.append(a[i] * 3 + 1)
    b[a[i]] += 1
    if b[a[i]] == 2:
        break
    i += 1

print(i + 1)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
    int N;
    cin >> N;
    string S;
    cin >> S;
    string ans = S;
    bool a = false;
    int continuing = 0;
    for(int i=0;i<N;i++){
        if(S[i]=='('){
            a=true;
            continuing++;
        }else if(S[i]==')'){
            if(a){
                continuing--;
                a = continuing!=0;
            }else{
                ans = '(' + ans;
            }
        }
    }
    for(int i=0;i<continuing;i++) ans=ans+')';
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
//#include "atcoder/all"
//using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;

signed main(){
	string s;
	cin >> s;
	if(s.back() == 's') {
		s += "es";
	} else {
		s += 's';
	}
	out(s);
}

Measured memory_bytes: 3636
from decimal import Decimal as D
import sys

def naiseki(A,B):
    return A[0]*B[0]+A[1]*B[1]
def scaler(k,A):
    return[k*A[0],k*A[1]]
def size(A):
    return A[0]**2+A[1]**2
def plus(A,B):
    return [A[0]+B[0],A[1]+B[1]]

while True:
    try:
        x1,y1,x2,y2,xq,yq=[D(i) for i in input().split(",")]
        P1P2=[x2-x1,y2-y1]
        P1Q=[xq-x1,yq-y1]
        P1H=scaler(naiseki(P1P2,P1Q)/size(P1P2),P1P2)
        QH=plus(P1H,scaler(-1,P1Q))
        QR=scaler(2,QH)
        OP1=[x1,y1]
        OR=plus(OP1,plus(P1Q,QR))
        print(OR[0],OR[1])
    except EOFError:
        sys.exit()

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

#define ten(n) ((int)1e##n)
// dump macro{{{
// http://www.creativ.xyz/dump-cpp-652
#define DUMPOUT cerr // 変数ダンプ先。coutかcerr

#ifdef PCM
// 引数はいくつでもどんな型でも可（ストリーム出力演算子があればOK）
#define dump(...) DUMPOUT<<"  "; \
  DUMPOUT<<#__VA_ARGS__; \
  DUMPOUT<<":=> "; \
  dump_func(__VA_ARGS__); DUMPOUT<<"in ["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl;
#define dump_1d(x,n) DUMPOUT <<"  " \
  <<#x<<"["<<#n<<"]"<<":=> {"; \
  rep(i,n){ DUMPOUT << x[i] << (((i)==(n-1))?"}":", "); } DUMPOUT <<" in [" << __LINE__ << "]" << endl;

#define dump_2d(x,n,m) DUMPOUT <<"  " \
    <<#x<<"["<<#n<<"]"<<"["<<#m<<"]"<<":=> \n"; \
    rep(i,n)rep(j,m){ DUMPOUT << ((j==0)?"     |":" ") << x[i][j] << (((j)==(m-1))?"|\n":" "); } \
    DUMPOUT <<"  in [" << __LINE__ << "]" << endl;
#else
#define dump(...) 42
#define dump_1d(...) 42
#define dump_2d(...) 42
#endif

// デバッグ用変数ダンプ関数
void dump_func() {
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail)
{
    DUMPOUT << head;
    if (sizeof...(Tail) == 0) {
        DUMPOUT << " ";
    }
    else {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
    os << "{";
    for (int i = 0; i<vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}/*}}}*/

#define rep(i, x) for(int i = 0; i < (int)(x); i++)/*{{{*/
#define reps(i,x) for(int i = 1; i <= (int)(x); i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define foreach(x,a) for(auto& (x) : (a) )
#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define INF 2147483647
#define INFLL 1000000000000000000LL
#define MOD 1000000007/*}}}*/

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;/*{{{*/
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<pii,vii,greater<pii> > spq;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*}}}*/

// global variables

int main() {
  ll n;cin>>n;
  ll a[n];
  rep(i,n)cin>>a[i];

  vi b;
  rep(i,n){
    if (i%2==0) b.pb(a[i]);
    else {
      b.insert(b.begin(), a[i]);
    }
  }

  if (n%2==1) reverse(all(b));

  rep(i,n){
    cout << b[i] << (i==n-1?"\n":" ");
  }

  return 0;
}


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

using namespace std;

int parent(int i){
    return i/2;
}

int left(int i){
    return 2*i;
}

int right(int i){
    return 2*i+1;
}

int main(void){
    int h;
    cin >> h;
    int a[h+1];
    for(int i = 1; i <= h; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= h; i++){
        cout << "node " << i <<": ";
        cout << "key = " << a[i] << ", ";
        if(parent(i) >= 1)cout << "parent key = " << a[parent(i)] << ", ";
        if(left(i) <= h)cout << "left key = " << a[left(i)] << ", ";
        if(right(i) <= h)cout << "right key = " << a[right(i)] << ", ";
        cout << endl;
    }
    return 0;
}


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

int cntA[200001],cntB[200001];
vector<int> e[200001];
bool vis[200001];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	string s;
	cin>>n>>m>>s;
	s.insert(0," ");
	for(int i=1,u,v;i<=m;i++){
		cin>>u>>v;
		e[u].emplace_back(v);
		e[v].emplace_back(u);
		if(s[v]=='A')
			cntA[u]++;
		else
			cntB[u]++;
		if(s[u]=='A')
			cntA[v]++;
		else
			cntB[v]++;
	}
	queue<int> q;
	int cnt = 0;
	for(int i=1;i<=n;i++)
		if(cntA[i]==0||cntB[i]==0)
			q.emplace(i),vis[i]=true;
	while(!q.empty()){
		int x = q.front();q.pop();
		cnt++;
		for(int it:e[x]){
			if(s[x]=='A')
				cntA[it]--;
			else
				cntB[it]--;
			if(!vis[it])
				if(cntA[it]==0||cntB[it]==0)
					q.emplace(it),vis[it]=true;
		}
	}
	if(cnt==n)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
}


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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,n) for(int i=(int)(n-1);i>=0;--i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int W = 5;
int H;

bool disappear(int x, int y, int c, int& n, vvi& field) {
    int sx = x+1;
    while (sx < W) {
        if (field[y][sx] == c) {
            n++;
            if (disappear(sx, y, c, n, field)) {
                field[y][sx] = 0;
            }
        } else {
            break;
        }
        sx++;
    }
    return n >= 3;
}

void fall(vvi& field) {
    RREP(x, 5) {
        RREP(y, H) {
            if (field[y][x] == 0) {
                for (int sy = y-1; sy >= 0; sy--) {
                    if (field[sy][x] != 0) {
                        swap(field[y][x], field[sy][x]);
                        break;
                    }
                }
            }
        }
    }
}

int main() {
    while (cin >> H, H) {
        vvi field(H, vi(5));
        REP(y, H) REP(x, W) cin >> field[y][x];

        int score = 0;
        bool redo;
        do {
            redo = false;
            REP(y, H) {
                REP(x, W) {
                    if (field[y][x] != 0) {
                        int n = 1;
                        if (disappear(x, y, field[y][x], n, field)) {
                            score += field[y][x] * n;
                            field[y][x] = 0;
                            redo = true;
                        }
                    }
                }
            }
            fall(field);
        } while (redo);
        cout << score << endl;
    }
}

Measured memory_bytes: 3008
#include <iostream>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <vector>
#define ll long long int
using namespace std;

int main(){
	int n, m;
	int t[100], p[100], x[100];
	int sum = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> t[i];
	}
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> p[i] >> x[i];
	}
	for (int i = 1; i <= n; i++) {
		sum += t[i];
	}
	for (int i = 1; i <= m; i++) {
		cout << sum - t[p[i]] + x[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n; cin >> n;
    vl s(n);
    rep(i,n) cin >> s[i];
    ll mx = 0;
    for(ll c=1; c<=n-1; c++){
        ll l=0, r=n-1;
        ll sum = 0;
        if((n-1) % c == 0){
            ll tmp = 0;
            while(l < r){
                sum += s[l] + s[r];
                tmp = max(tmp, sum);
                l += c; r -= c;
            }
            mx = max(mx, tmp);
        }else{
            ll tmp = 0;
            while(r > c){
                sum += s[l] + s[r];
                tmp = max(tmp, sum);
                l += c; r -= c;
            }
            mx = max(mx, tmp);
        }
    }
    cout << mx << endl;
}


Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {
	
	public static int searchLinear(int[] nums, int[] queries) {
		
		int answer = 0;
		
		for (int i = 0; i < queries.length; i++) {
			int query = queries[i];
			for (int j = 0; j < nums.length; j++) {
				if (query == nums[j]) {
					answer++;
					break;
				}
			}
		}
		
		return answer;
	}
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int arrLen = scan.nextInt();
		scan.nextLine();
		int[] a = new int[arrLen];
		
		for (int i = 0; i < arrLen; i++) {
			a[i] = scan.nextInt();
		}
		scan.nextLine();
		
		int querLen = scan.nextInt();
		scan.nextLine();
		int[] b = new int[querLen];
		
		for (int i = 0; i < querLen; i++) {
			b[i] = scan.nextInt();
		}
		
		scan.close();

		int answer = searchLinear(a, b);
		
		System.out.println(answer);
	}
}


Measured memory_bytes: 40772
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <iostream>

using namespace std;
typedef long long ll;

int mo[5]={0,1,0,-1,0};
int ans,n,X1[1000],X2[1000],Y1[1000],Y2[1000],mm[4010][4010]={0};

void calc(int w,int h){
    
    for(int i=0;i<4010;i++)
        for(int j=0;j<4010;j++)
            mm[i][j]=0;
    
    ans=0;
    
    vector<int> x,y;
    map<int,int> mx,my;
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        scanf("%d%d%d%d",&X1[i],&Y1[i],&X2[i],&Y2[i]);
        
        x.push_back(X1[i]);
        x.push_back(X2[i]);
        x.push_back(X1[i]+1);
        y.push_back(Y1[i]);
        y.push_back(Y2[i]);
        y.push_back(Y1[i]+1);
    }
    
    x.push_back(0);
    x.push_back(w);
    y.push_back(0);
    y.push_back(h);
    
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    x.erase(unique(x.begin(),x.end()),x.end());
    y.erase(unique(y.begin(),y.end()),y.end());
    
    for(int i=0;i<x.size();i++){
        mx[x[i]]=i;
    }
    for(int i=0;i<y.size();i++){
        my[y[i]]=i;
    }
    
    for(int i=0;i<n;i++){
        mm[my[Y1[i]]][mx[X1[i]]]++;
        mm[my[Y1[i]]][mx[X2[i]]]--;
        mm[my[Y2[i]]][mx[X1[i]]]--;
        mm[my[Y2[i]]][mx[X2[i]]]++;
    }
    
    for(int i=0;i<y.size();i++){
        for(int j=0;j<x.size();j++){
            mm[i][j+1]+=mm[i][j];
        }
    }
    
    for(int i=0;i<x.size();i++){
        for(int j=0;j<y.size();j++){
            mm[j+1][i]+=mm[j][i];
        }
    }
    
    
    for(int i=0;i<y.size()-1;i++){
        for(int j=0;j<x.size()-1;j++){
            if(mm[i][j]>0) continue;
            
            queue<pair<int,int> > q;
            q.push(make_pair(i,j));
            mm[i][j]=1;
            ans++;
            
            while(!q.empty()){
                pair<int,int> p = q.front();
                q.pop();
                
                for(int k=0;k<4;k++){
                    if(0<=p.first+mo[k] && p.first+mo[k]<y.size()-1 && 0<=p.second+mo[k+1] && p.second+mo[k+1]<x.size()-1){
                        if(mm[p.first+mo[k]][p.second+mo[k+1]]==0){
                            q.push(make_pair(p.first+mo[k],p.second+mo[k+1]));
                            mm[p.first+mo[k]][p.second+mo[k+1]]=1;
                        }
                    }
                }
            }
        }
    }
    
    printf("%d\n",ans);
    
    return;
}

int main(){
    int w,h;
    
    while(1){
        scanf("%d%d",&w,&h);
        if(w==0) break;
        calc(w,h);
    }
    
    return 0;
}

Measured memory_bytes: 64128
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define ull unsigned ll
#define pll pair<ll, ll>
#define itr(a) begin(a), end(a)
#define pb push_back
#define x first
#define y second
#define endl '\n'
#define FAST cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define FILES(namein, nameout) freopen(namein, "r", stdin); freopen(nameout, "w", stdout);
#define M 1000000007
#define N 200000
#define INF 101111111111111
using namespace std;
main(){
    FAST;
    ll k, x;
    cin >> k >> x;
    for(ll i = x-k+1;i<=x+k-1;i++) cout << i << " ";
}

Measured memory_bytes: 256
/******************************************************************************
 
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
 
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define vi vector <int>
#define vp vector <pair<int,int>>
#define pb push_back
#define pob pop_back
#define mp make_pair
#define f(x,y,z) for(x=y;x<z;x++)
#define si size()
#define ee endl
#define re return 
//Author Rahul Sannigrahi
 
 
int solve()
{
 int x1,x2,x3,x4,x5;
 cin>>x1>>x2>>x3>>x4>>x5;
 if(x1==0)
 cout<<1<<ee;
 else
 if(x2==0)
 cout<<2<<ee;
 else
 if(x3==0)
 cout<<3<<ee;
 else
 if(x4==0)
 cout<<4<<ee;
 else
 if(x5==0)
 cout<<5<<ee;
 return 0;
}
 
int32_t main()
{
    IOS
    int t=1;
    //cin>>t;
    while(t--)
    solve();
    return 0;
}
 


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int L[105];

int main()
{
    int N;
    cin >> N;
    REP(i, N)
    {
        cin >> L[i];
    }

    REP(i, N)
    {
        ll sum = 0;
        REP(j, N)
        {
            if (i == j)
                continue;
            sum += L[j];
        }
        if (sum <= L[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cmath>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(int i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(int i = 0; i <=(ll)(n); i++)

int main(){
    string s1;
    cin >> s1;
    if(s1[0] >= 'a' && s1[0] <= 'z'){
    cout << "a" << endl;

    //文字が英大文字かどうか判定
    }else if(s1[0] >= 'A' && s1[0] <= 'Z'){
    cout << "A" << endl;
    }
    return 0;
}

Measured memory_bytes: 3120
s = raw_input()
K = int(raw_input())
s_list = list(s)
for i in range(len(s_list)):
    # how long does it take to force a
    lag = ord('z') - ord(s_list[i]) + 1
    if s_list[i] != 'a' and K >= lag and i < len(s_list) - 1:
        # not a and can conv
        s_list[i] = 'a'
        K -= lag
    elif i == len(s_list) - 1:
        s_list[i] = chr(ord('a') + ((ord(s_list[i]) - ord('a') + K) % 26))
print "".join(s_list)



Measured memory_bytes: 6660
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

int main() {
    int N;
    scanf("%d", &N);
    vector<pii> X;
    for (int i = 0; i < N; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        X.push_back(make_pair(a + b, a - b));
    }
    sort(X.begin(), X.end());
    int ans = 1, r = X[0].first;
    for (int i = 1; i < N; i++) {
        int curl = X[i].second, curr = X[i].first;
        if (curl < r) continue;
        ans++;
        r = curr;
    }
    printf("%d\n", ans);
    return 0;
}


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

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

  if (n == 0)
    cout << 2 << endl;
  else if (n == 1)
    cout << 1 << endl;
  else {
        n -= 1;

  long long tmp1 = 2;
  long long tmp2 = 1;
  long long tmp;
    for (int i = 0; i < n; i++) {
      tmp = tmp2;
      tmp2 += tmp1;
      tmp1 = tmp;
    }
  
  cout << tmp2 << endl;
  }

}

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

int n;
int a[5][105];
int sum, ans = 0;

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

    cin >> n;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < n; j++) cin >> a[i][j];
    }

    for (int i = 0; i < n; i++) {
        sum = 0;
        for (int j = 0; j < i + 1; j++) sum += a[0][j];
        for (int k = i; k < n; k++) sum += a[1][k];

        ans = max(ans, sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

	int n = scan.nextInt();
	if(n % 2 == 0){
	    System.out.println(n);
	}else{
	    System.out.println(n*2);
	}
    }
}


Measured memory_bytes: 23764
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
h = sorted(list(map(int, readline().split())))
if n <= k:
    print(0)
else:
    print(sum(h[:n - k]))


Measured memory_bytes: 21988
#include <stdio.h>
int main()
{
  int d;
  scanf("%d", &d);
  if (d == 25)
    printf("Christmas");
  else if(d == 24)
    printf("Christmas Eve");
  else if (d == 23)
  printf("Christmas Eve Eve");
  else if(d == 22)
    printf("Christmas Eve Eve Eve");
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#ifdef ONLINE_JUDGE
#define trace(...)
#endif

using LL = long long;
const int N = 12, M = 1e3, INF = 1e9;

int best[1 << N];

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

	fill(best, best + (1 << N), INF);
	best[0] = 0;

	int n, m; cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		int mask = 0;
		while (b--) {
			int j; cin >> j; j--;
			mask |= (1 << j);
		}

		for (int sm = 0; sm < (1 << n); sm++) {
			if ((sm & mask) == sm) {
				best[sm] = min(best[sm], a);
			}
		}
	}

	for (int mask = 1; mask < (1 << n); mask++) {
		for (int sm = 0; sm < (1 << n); sm++) {
			if ((sm & mask) == sm) {
				best[mask] = min(best[mask], best[sm] + best[mask ^ sm]);
			}
		}
	}

	int ans = best[(1 << n) - 1];
	if (ans == INF) ans = -1;
	cout << ans << endl;

	return 0;
}


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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

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

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  int n = in();

  int T = 0, X = 0, Y = 0;
  for (int i = 0; i < n; ++i) {
    int t = in(), x = in(), y = in();
    if (abs(X - x) + abs(Y - y) > t - T || ((abs(X - x) + abs(Y - y)) & 1) != ((t - T) & 1)) {
      cout << "No" << endl;
      return 0;
    }
    T = t;
    X = x;
    Y = y;
  }

  cout << "Yes" << endl;
}


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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const ll MAX { 2510 }, oo { 1LL << 62 };

vector<ii> adj[MAX];
bitset<MAX> found;

void dfs(ll u)
{
    if (found[u])
        return;

    found[u] = true;

    for (auto p : adj[u])
        dfs(p.first);
}

bool can_reach(ll s, ll u)
{
    found.reset();

    dfs(u);

    return found[s];
}
    
ll solve(int N)
{
    vector<ll> dist(N + 1, oo);

    dist[1] = 0;

    for (int k = 0; k < N - 1; ++k)
        for (int u = 1; u <= N; ++u)
            for (auto p : adj[u])
            {
                auto v = p.first, w = p.second;

                dist[v] = min(dist[v], dist[u] + w);
            }

    auto ans = max(0LL, -dist[N]);

    for (int u = 1; u <= N; ++u)
        for (auto p : adj[u])
        {
            auto v = p.first, w = p.second;

            if (dist[v] > dist[u] + w and can_reach(v, 1) and can_reach(N, v))
                return -1;
        }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, M, P;
    cin >> N >> M >> P;

    while (M--)
    {
        ll a, b, c;
        cin >> a >> b >> c;

        adj[a].push_back(ii(b, P - c));
    }

    auto ans = solve(N);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3876
/*
    Author: isaf27 (Ivan Safonov)
*/

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define fastIO ios_base::sync_with_stdio(0)
#define nul point(0, 0)
#define str_to_int(stroka) atoi(stroka.c_str())
#define str_to_ll(stroka) atoll(stroka.c_str())
#define str_to_double(stroka) atof(stroka.c_str())
#define what_is(x) cerr << #x << " is " << x << endl
#define solve_system int number; cin >> number; for (int i = 0; i < number; i++) solve()
#define solve_system_scanf int number; scanf("%d", &number); for (int i = 0; i < number; i++) solve()

//permanent constants
const ld pi = 3.141592653589793238462643383279;
const ld log23 = 1.58496250072115618145373894394781;
const ld eps = 1e-8;
const ll INF = 1e18 + 239;
const ll prost = 239;
const int two = 2;
const int th = 3;
const ll MOD = 1e9 + 7;
const ll MOD2 = MOD * MOD;
const int BIG = 1e9 + 239;
const int alf = 26;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int dig = 10;
const string str_alf = "abcdefghijklmnopqrstuvwxyz";
const string str_alf_big = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int bt = 31;
const int fr = 4;

//easy functions
template< typename T >
inline T gcd(T a, T b) { return a ? gcd(b % a, a) : b; }
template< typename T >
inline T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
inline bool is_down(char x) { return ('a' <= x && x <= 'z'); }
inline bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
inline bool is_digit(char x) { return ('0' <= x && x <= '9'); }
ll power(ll a, int k)
{
    if (k == 0) return 1;
    ll t = power(a, k >> 1);
    t = (t * t) % MOD;
    if (k & 1) t = (t * a) % MOD;
    return t;
}

//random
mt19937 rnd(239);

//constants
const int M = 2 * 1e5 + 239;
const int N = 2 * 1e3 + 239;
const int L = 20;
const int T = (1 << 20);
const int B = trunc(sqrt(M)) + 1;
const int X = 2010;

int kol[M], n, m;
bool can[M];

int main()
{
    #ifdef ONPC
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastIO;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        kol[i] = 1;
        can[i] = false;
    }
    can[0] = true;
    for (int i = 0; i < m; i++)
    {
        int s, f;
        cin >> s >> f;
        s--, f--;
        kol[s]--;
        kol[f]++;
        if (!can[s]) continue;
        can[f] = true;
        if (kol[s] == 0) can[s] = false;
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
        ans += (can[i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 768
#include <iostream>

using namespace std;

typedef long long LL;

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define dump(x)  cerr << #x << " = " << (x) << endl;

LL p = 1000*1000*1000 + 7;

LL a(LL n, LL i) {
  return (i+1 + (i+1)*(n-i-2)%p)%p;
}

int main() {
  LL n, m;
  LL *x, *y;
  cin >> n >> m;
  x = new LL[n];
  y = new LL[m];

  REP(i, n) {
    cin >> x[i];
  }
  REP(i, m) {
    cin >> y[i];
  }

  LL sum_x = 0, sum = 0;

  REP(i, n-1) {
    sum_x = (sum_x + a(n, i)*(x[i+1] - x[i])%p)%p;
  }
  REP(j, m-1) {
    sum = (sum + sum_x*a(m, j)%p*(y[j+1] - y[j])%p)%p;
  }

  cout << sum%p << endl;
  
  return 0;
}

Measured memory_bytes: 1792
N = int(input())
LR = [[0, 0] for i in range(N)]
p = q = -1
Lp = 0
Rq = 10**9 + 1
w_max = 0
for i in range(N):
  L, R = map(int, input().split())
  if L > Lp:
    Lp = L
    p = i
  if R < Rq:
    Rq = R
    q = i
  w_max = max(w_max, R-L+1)
  LR[i] = [L, R]


# 問題pと問題qを同じコンテストで実施する場合
ans = w_max + max(Rq-Lp+1, 0)
if p == q:
  print(ans)
  quit()

# 問題pと問題qを別々のコンテストで実施する場合
ab = []
wp = LR[p][1] - Lp + 1
wq = Rq - LR[q][0] + 1
for i in range(N):
  if i==p or i==q:
    continue
  ab.append([
    min(wp, max(LR[i][1]-Lp+1, 0)), -min(wq, max(Rq-LR[i][0]+1, 0))
  ])

# aの昇順(タイブレークはbの降順)に並べる
ab.sort()
ab.append([wp, 0])
b_min = wq
for a, b in ab:
  ans = max(ans, a+b_min)
  b_min = min(b_min, -b)

print(ans)

Measured memory_bytes: 36688
x=int(input())
li=[]

for i in range(-1000,1000):
    li.append([i,i**5])

step=len(li)

for j in range(step):
    for k in range(step):
        if li[j][1]-li[k][1]==x:
            print(li[j][0],li[k][0])
            exit()

Measured memory_bytes: 9344
var
  c,t,m,i,j,minc,mint,n:longint;
begin
  readln(n,m);
  minc:=10000;
  for i:=1 to n do
    begin
      readln(c,t);
      if t<=m then
        if c<minc then minc:=c;
    end;
  if minc=10000 then write('TLE') else write(minc);
end.

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

using namespace std;

using ll = long long;

int main(){
    ll a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if(a == 0)cout << 1;
    else if(b == 0)cout << 2;
    else if (c == 0)cout << 3;
    else if(d == 0)cout << 4;
    else cout << 5;
    return 0;

}


Measured memory_bytes: 3592
#include "bits/stdc++.h"

using namespace std;

int main()
{
	int A[3][3];
	int N, bingo[8] = {0};
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A[i][j];
		}
	}
	cin >> N;
	vector<int> b(N);
	for (int i = 0; i < N; i++) cin >> b[i];

	for (int bn = 0; bn < N; bn++) {
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (A[i][j] == b[bn]) A[i][j] = 0;
			}
		}
	}

	bool flg = false;
	for (int i = 0; i < 3; i++) 
		if (A[i][0] + A[i][1] + A[i][2] == 0) {
			flg = true; 
			break;
		}
	for (int j = 0; j < 3; j++) 
		if (A[0][j] + A[1][j] + A[2][j] == 0) {
			flg = true;
			break;
		}
	if (A[0][0] + A[1][1] + A[2][2] == 0) flg = true;
	if (A[2][0] + A[1][1] + A[0][2] == 0) flg = true;
	
	flg ? cout << "Yes" : cout << "No";

	return 0;
}

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

using namespace std;
#define int long long
const int N = 6666 , mod = 1e9+7; 
//dp[i]:代表以3,...,i组成的和为i的方案数
int dp[N];
signed main(){
	dp[1]=0,dp[2]=0,dp[3]=1,dp[4]=1;
	for(int i=5;i<=2001;i++) dp[i]=(dp[i-2]+dp[i-3]+dp[i-4])%mod;
	int n;
	cin>>n;
	cout<<dp[n];
	return 0;
}
/*

*/

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  ll n;cin >> n;
  if(n%2==1) {
    cout << 0 << endl;
    return 0;
  }
  n /= 2;

  ll ans = 0;
  ll five = 5;
  rep(i,25) {
    ans+=n/five;
    n/=5;
  }
  cout << ans << endl;

  return 0;
}


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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    int x,a,b;
    cin >> x >> a >> b;
    if(abs(a-x) <= abs(b-x)){
        cout << "A" << endl;
    }else{
        cout << "B" << endl;
    }
	return 0;
}



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

//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long

using namespace std;

const int NN = 1e6 + 7;
const int N = 1e6 + 7;
const int M = 20;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const double long rf = 1e-14;

void solve1()
{
    double long a,b,c;
    cin >> a >> b >> c;
    cout << ( sqrt(a) + sqrt(b) + rf < sqrt(c) ? "Yes" : "No" );
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 384
#デフォルト
import itertools
from collections import defaultdict
import collections
import math
import sys
sys.setrecursionlimit(200000)
mod = 1000000007

x = list(map(int,input().split()))

for i in range(5):
    if x[i] != i + 1:
        print(i+1)
        break


Measured memory_bytes: 9396
#include<iostream>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)


bool check(string s){
    int q[]={6,5,4,3,2,7,6,5,4,3,2};
    int sum=0;
    rep(i,11){
        sum+=(s[i]-'0')*q[i];
    }
    sum%=11;
    if(sum<=1)sum=0;
    else sum = 11-sum;
    if(sum == s[11]-'0')return true;
    else return false;
}

int main(){
    string s;
    int a;
    cin>>s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '?'){
            a = i;
        }
    }
    
    int sum=0;
    int num = -1;
    
    for(int i = 0; i <= 9; i++){
        s[a] = '0'+i;
        if(check(s) == true){
            sum++;
            num = i;
        }
    }
    
    if(sum >= 2){
        cout << "MULTIPLE" << endl;
    }else{
        cout << num << endl;
    }
}

Measured memory_bytes: 1184
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	ll N; cin >> N;
	ll ans = 0;
	for (ll i = 1; i <= 1000000; i++) {
		if (N%i == 0 && i < (N / i) - 1) ans += (N / i) - 1;
	}
	cout << ans << endl;

	return 0;
}

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

#define int long long

main()
{
  int n;
  int a[100005];
  int maxv = 0, minv = 114514;
 
  cin >> n;

  for(int i = 0; i < n; i++) {
    cin >> a[i];
    maxv = max(a[i], maxv), minv = min(a[i], minv);
  }

  if(maxv - minv >= 2) {
    cout << "No" << endl;
  } else if(maxv == minv) {
    if(maxv == n - 1 || n / 2 >= maxv) cout << "Yes" << endl;
    else cout << "No" << endl;
  } else {
    int cnt = 0;
    for(int i = 0; i < n; i++) {
      if(minv == a[i]) cnt++;
    }
    //aloneがmaxv人以上いちゃだめ
    //
    if(cnt < maxv && (n - cnt) / 2 >= maxv - cnt) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  return (0);
}
  

Measured memory_bytes: 1024