akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <stack>
#include <queue>
#include <tuple>
#include <regex>
#include <cmath>
#include <map>
#include <set>
#include <functional>
#include <cstring>

using namespace std;

template<typename T> bool chmax( T &a, const T b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using ll = long long;
using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;

#define eb emplace_back
#define pb push_back
#define mp make_pair

#define F first
#define S second

#define popcnt __builtin_popcountll

#define rep( i, n ) for ( ll i = 0; i < (ll)( n ); ++i )
#define reps( i, n ) for ( ll i = 1; i <= (ll)( n ); ++i )
#define rrep( i, n ) for ( ll i = (ll)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( ll i = (ll)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

template<typename T = ll> constexpr T MAX = numeric_limits<T>::max();
template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }
template<typename T> T lcm( const T a, const T b ) { return ( a / gcd( a, b ) * b ); }


int main()
{
	ll n, m; cin >> n >> m;
	vector<vector<ll>> g( n );
	rep( i, m )
	{
		ll s, t; cin >> s >> t;
		--s; --t;
		g[s].eb( t );
	}

	vector<double> dp( n + 1 );
	rrep( i, n - 1 )
	{
		arep( it, g[i] )
			dp[i] += 1 + dp[it];
		dp[i] /= g[i].size();
	}
	double ans = dp[0];

	vector<double> dp2 = dp;
	rrep( i, n - 1 )
	{
		if ( g[i].size() >= 2 )
		{
			dp2[i] = 0;
			vector<double> tmp;
			arep( it, g[i] ) tmp.eb( dp2[it] );
			sort( ALL( tmp ) ); tmp.pop_back();
			arep( it, tmp ) dp2[i] += 1 + it;
			dp2[i] /= tmp.size();

			rrep( j, i )
			{
				dp2[j] = 0;
				arep( it, g[j] ) dp2[j] += 1 + dp2[it];
				dp2[j] /= g[j].size();
			}
			chmin( ans, dp2[0] );
			rep( i, n + 1 ) dp2[i] = dp[i];
		}
	}

	cout << setprecision( 20 ) << ans << endl;

	return ( 0 );
}


Measured memory_bytes: 5552
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
# endregion
s = sum(ri_())
print(s if s < 10 else 'error')

Measured memory_bytes: 63596
#include <bits/stdc++.h>
using namespace std;
#define fast_io {cin.sync_with_stdio(0); cout.sync_with_stdio(0);}
#define out(x,y) {cout<<x<<y;}
using ll = long long int;

ll modu = pow(10,9)+7;

int main(){
	fast_io;
	ll n,k;
	cin>>n>>k;
	ll a[n+1];
	ll b[n+1];
	a[0] = 0;
	for(ll i=1;i<=n;i++){
		a[i] = (a[i-1]+i)%modu;
	}
	b[n] = n;
	for(ll i=n-1;i>=0;i--){
		b[i] = b[i+1]+i;
	}
	ll ans = 0;
	for(ll i=k;i<=n+1;i++){
		ans = (ans+(modu+b[n-i+1]-a[i-1]+1)%modu)%modu;
	}
	cout<<ans<<endl;
}

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

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

    vector<vector<int>> graph(n);
    vector<pair<int,int>> edge;
    for(int i=0; i<n-1; i++){// dumb mistake...
        int a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        graph[a].push_back(b);
        graph[b].push_back(a);
        edge.push_back({a,b});// equiv: edge.emplace_back(a,b)
    }

    vector<int> depth(n,0);
    queue<int> q;

    depth[0] = 1;
    q.push(0);

    int min = 0;// minimum number of colors
    map<pair<int,int>,int> edgecolor;// arg: (edge, color)
    vector<int> topcolor(n,0);

    while(!q.empty()){
        int current = q.front();
        q.pop();

        int c = 1;// color candidate
        for(int adjacent : graph[current]){
            if(depth[adjacent]!=0) continue;

            if(min < graph[current].size()) min = graph[current].size();

            if(c == topcolor[current]) c += 1;// skip the color already used
            topcolor[adjacent] = c;
            edgecolor[make_pair(current,adjacent)] = c;
            edgecolor[make_pair(adjacent,current)] = c;
            c += 1;

            q.push(adjacent);
            depth[adjacent] = depth[current] + 1;
        }
    }

    cout << min << endl;
    for(auto i : edge){
        cout << edgecolor[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 20084
n,h,w=map(int, input().split())
a=[list(map(int, input().split())) for num in range(n)]
ans=0

for num in range(n):
    cut=int(a[num][0]/h)
    cutw=int(a[num][1]/w)
    if cut==0 or cutw==0:
        cut=0
        cutw=0
    if cutw<cut:
        cut=cutw
    ans+=cut
    
print(ans)

Measured memory_bytes: 9152
#include<bits/stdc++.h>
#define taskname "A"
#define pb push_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 41;
const int maxs = (1 << 17);
const int mod = 1e9 + 7;
const int logn = log2(maxn) + 1;

int n , x , y , z;
int dp[maxn][maxs];
void add(int & x , int y){
    x += y;
    if(x >= mod)x -= mod;
    if(x < 0)x += mod;
}
bool Get(ll x , int y){
    return ((x >> y) & 1);
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    cin >> n >> x >> y >> z;
    dp[0][0] = 1;
    for(int i = 0 ; i < n ; ++i){
        for(int j = 0 ; j < (1 << (x + y + z)) ; ++j){
            if(dp[i][j] == 0)continue;
            for(int c = 1 ; c <= 10 ; ++c){
                int mask = (((j << c) | (1 << (c - 1))) & ((1 << (x + y + z)) - 1));
                if(Get(mask,z-1) && Get(mask,y+z-1) && Get(mask,x+y+z-1))continue;
                add(dp[i + 1][mask] , dp[i][j]);
            }
        }
    }
    int res = 1;
    for(int i = 1 ; i <= n ; ++i)res = (ll)res * 10 % mod;
    for(int i = 0 ; i < (1 << (x + y + z)); ++i){
        add(res , -dp[n][i]);
    }
    cout << res;
}


Measured memory_bytes: 19328
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        mut x: [isize; m]
    }
    if n >= m {
        println!("0");
        return;
    }
    x.sort();
    let mut l = vec![0; m - 1];
    for i in 0..m - 1 {
        l[i] = x[i + 1] - x[i];
    }
    l.sort();
    println!(
        "{}",
        x[m - 1] - x[0] - l.iter().rev().take(n - 1).sum::<isize>()
    );
}


Measured memory_bytes: 4332
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N, A, B;
  cin >> N >> A >> B;

  int plan = N * A;


  if (plan > B)
  {
    cout << B << endl;
  }
  else if (plan < B)
  {
    cout << plan << endl;
  }
  else
  {
    cout << plan << endl;
  }
}

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

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

    if (1 <= X && X <= 3)
    {
        cout << 1 << endl;
        return 0;
    }

    int max = 4;
    for (int i = 2; pow(i, 2) <= X; i++)
    {
        for (int j = 2; pow(i, j) <= X; j++)
        {
            if (pow(i, j) > max)
            {
                max = pow(i, j);
            }
        }
    }
    cout << max << endl;

    return 0;
}

Measured memory_bytes: 384
d, n = map(int, input().split())

if n == 100:
    if d == 0:
        print(101)
    elif d == 1:
        print(10100)
    elif d == 2:
        print(1010000)
else:
    if d == 0:
        print(n)
    elif d == 1:
        print(100 * n)
    elif d == 2:
        print(100 ** 2 * n)


Measured memory_bytes: 3060
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N, K = map(int, readline().split())
    h = list(map(int, readline().split()))
    ans = 0
    for x in h:
        if x >= K:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 83336
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var last = -1;
        var result = 0;
        for (var i = 0; i < num; i++)
        {
            if (last == ar[i])
            {
                result++;
                last = 10000;
            }
            else last = ar[i];
        }
        WriteLine(result);
    }

    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 13140
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>   
#include <stdio.h>    
 
using namespace std;
     
#define F first
#define S second
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
const ll inf = (ll)3e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, a[N], pref[N], suff[N], ans;

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                    

inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> a[i], pref[i] = __gcd (pref[i - 1], a[i]);
   for (int i = n; i >= 1; i --) suff[i] = __gcd (suff[i + 1], a[i]);
   for (int i = 1; i <= n; i ++) ans = max (ans, __gcd (pref[i - 1], suff[i + 1]));
   cout << ans;
   
}                                     

int main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
// cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}


Measured memory_bytes: 1408
/* ex 7_1
   TakayukiY*/

#include<stdio.h>
#include<math.h>

typedef struct point{
    int x_elem;
    int y_elem;
} point;

int main(void){
    //各頂点
    point p1,p2,p3,p4;
    //頂点1・2間の各成分の差分
    int x,y;
    //代入
    scanf("%d%d%d%d",&p1.x_elem,&p1.y_elem,&p2.x_elem,&p2.y_elem);
    //1と2の差分を計算
    x=p1.x_elem - p2.x_elem;
    y=p1.y_elem - p2.y_elem;
    //p3,p4を復元
    p3.x_elem=p2.x_elem+y;
    p3.y_elem=p2.y_elem-x;
    p4.x_elem=p1.x_elem+y;
    p4.y_elem=p1.y_elem-x;
    //出力
    printf("%d %d %d %d",p3.x_elem,p3.y_elem,p4.x_elem,p4.y_elem);

    return 0;
}

Measured memory_bytes: 1716
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String t = sc.next();
		String[] target = t.split("");
		int ans = 0;
		for (String a : target) {
			ans += Integer.parseInt(a);
		}
		if (ans % 9 == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
	}
}


Measured memory_bytes: 65460
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        r: usize,
    }
    println!("{}", 3 * r * r);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    string s;cin>>s;
    ll n=s.size();
    if(n&1){
        ll ans=n/2+1;
        rep(i,n/2){
            if(s[n/2+i+1]!=s[n/2]||s[n/2-i-1]!=s[n/2])break;
            ans++;
        }
        out(ans);
    }
    else{
        ll ans=n/2;
        if(s[n/2]!=s[n/2-1])dame(ans);
        REP(i,1,n/2){
            if(s[n/2]!=s[n/2+i]||s[n/2]!=s[n/2-i-1])break;
            ans++;
        }
        out(ans+1);
    }
}

Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <ctime>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <climits>
#include <set>
#include <vector>
#define int long long
using namespace std;
const int MOD=1e9+7;
inline int read(){
	int k=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}
	return k*f;
}
int n,ans=1;
int a[10010];
signed main()
{
	n=read();
	for(int i=1;i<=n;i++){
		int p=i;
		for(int j=2;j*j<=p;j++)if(p%j==0){
			while(p%j==0)a[j]++,p/=j;
		}
		if(p)a[p]++;
	}
	for(int i=2;i<=n;i++)ans=(ans*(a[i]+1))%MOD;
	printf("%lld",ans);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  ll S;
  get(S);
  ll x1, x2 = 0, y1 = 0, y2;
  x1 = ceil(sqrt(S));
  y2 = x1;
  ll rest = x1 * y2 - S;
  if (rest > 0) {
    x2 = 1;
    y1 = rest;
  }
  cout << 0 << " " << 0 << " " << x1 << " " << x2 << " " << y1 << " " << y2
       << endl;
  return 0;
}

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

int main() {
  int j, k;
  for (int i = 0; i < 4; i++) {
    cin >> j >> k;
    int result;
    switch (j) {
      case 1:
        result = k * 6000;
        break;
      case 2:
        result = k * 4000;
        break;
      case 3:
        result = k * 3000;
        break;
      case 4:
        result = k * 2000;
        break;
    }
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int[] x = new int[N];
        for (int i = 0; i < x.length; ++i) {
            x[i] = sc.nextInt();
        }
        int[] y = new int[M];
        for (int i = 0; i < y.length; ++i) {
            y[i] = sc.nextInt();
        }

        System.out.println(solve(x, y, X, Y) ? "War" : "No War");

        sc.close();
    }

    static boolean solve(int[] x, int[] y, int X, int Y) {
        return IntStream.concat(IntStream.of(X), Arrays.stream(x)).max().getAsInt() >= IntStream
                .concat(IntStream.of(Y), Arrays.stream(y)).min().getAsInt();
    }
}

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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<vector<int>> c(2);
  auto dfs = [&](auto&& dfs, int i, int j, int d) -> void {
    c[d % 2].push_back(j);
    for (auto k : g[j]) {
      if (k == i) continue;
      dfs(dfs, j, k, d + 1);
    }
  };
  dfs(dfs, 0, 0, 0);
  if (c[0].size() > c[1].size()) swap(c[0], c[1]);

  vector<vector<int>> p(3);
  if (c[0].size() <= n / 3) {
    for (int i = 1; i <= n; i++) {
      if (i % 3 == 0) {
        if (!c[0].empty()) {
          p[0].push_back(c[0].back());
          c[0].pop_back();
        } else {
          // if (c[1].empty()) return 1;
          p[0].push_back(c[1].back());
          c[1].pop_back();
        }
      } else {
        p[i % 3].push_back(c[1].back());
        c[1].pop_back();
      }
    }
  } else {
    for (int i = 1; i <= n; i++) {
      if (i % 3 == 1) {
        // if (c[1].empty()) return 1;
        p[1].push_back(c[1].back());
        c[1].pop_back();
      } else if (i % 3 == 2) {
        // if (c[0].empty()) return 1;
        p[2].push_back(c[0].back());
        c[0].pop_back();
      } else {
        if (c[0].size() >= c[1].size()) {
          // if (c[0].empty()) return 1;
          p[0].push_back(c[0].back());
          c[0].pop_back();
        } else {
          // if (c[1].empty()) return 1;
          p[0].push_back(c[1].back());
          c[1].pop_back();
        }
      }
    }
  }

  vector<int> r(n);
  for (int i = 0; i < n; i++) r[p[(i + 1) % 3][i / 3]] = i + 1;

  for (auto e : r) cout << e << ' ';
  cout << endl;
}


Measured memory_bytes: 17012
#include <iostream>

using namespace std;

int main() {

	double v, t, y;
	int N, i, h[100000];

	for(i=0; i<100000; i++) {
		h[i]=5*i-5;
	}

	while(cin>>v) {
		t=v/9.8;
		y=4.9*t*t;

		N=(int)((y+5)/5);
		for(i=0; i<100000; i++) {
			if(h[i]>=y) {
				N=i;
				break;
			}
		}
		cout << N << endl;
	}

	return 0;

}

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

#define ll long long
#define pb push_back
#define mk make_pair
#define pll pair<long,long>
int main()
{
    ll a,b,ans=INT_MAX,modw=2019;
    cin>>a>>b;
    for(ll i=a;i<=b&&i<a+2020;i++)
    {
      for(ll j=i+1;j<=b&&j<a+2020;j++)
      {
        //ll k=(i+2019) % modw,m= (j + 2019) % modw;
        ll s=((i*j)+2019) % modw;
         //s%=modw;
      //  cout<<s<<endl;
        ans=min(ans,s);
      }
    }

    ans%=modw;
    cout<<ans<<endl;

}


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

using namespace std;

int MAX_N = 1000000000;

void hex(vector<int> *c, int num);

int main(int argc, char** argv)
{
	int n, d;
	vector<int> v;
	while( 1 )
	{
		v.clear();
		cin >> n;
		if(n==0) break;

		hex(&v, n);
		for(int i=0; i<v.size(); i++){
			d = v[v.size() - i - 1];
			if(d>=4) d++;
			if(d>=6) d++;
			cout << d;
		}
		cout << endl;
	}
}

void hex(vector<int> *c, int num)
{
	int count = 0;
	while(num != 0)
	{
		c->push_back(num % 8);
		num /= 8;
	}
}

Measured memory_bytes: 908
H,W = map(int,input().split())
g = [input() for i in range(H)]
dr = [-1, 1, 0, 0]
dc = [0, 0, -1, 1]
for i in range(H):
    for j in range(W):
        if g[i][j] == '#':
            ok = False
            for k in range(4):
                x = i + dr[k]
                y = j + dc[k]
                if 0 <= x < H and 0 <= y < W:
                    ok = ok or g[x][y] == '#'
            if not ok:
                print('No')
                exit(0);
print('Yes')



Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int pa=0,pb=0,pc=0;
    string SA,SB,SC; cin >> SA >> SB >> SC;
    char now='a';
    while(true){
        if(now=='a'){
            if(pa==SZ(SA)) break;
            now=SA[pa];
            pa++;
        }
        if(now=='b'){
            if(pb==SZ(SB)) break;
            now=SB[pb];
            pb++;
        }
        if(now=='c'){
            if(pc==SZ(SC)) break;
            now=SC[pc];
            pc++;
        }
    }

    cout << (char)toupper(now) << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

void
solver(int x)
{
    int primes[100004];
    int i, j;

    bzero(primes, sizeof(primes));
    for (i=2; i<100004; i++) {
        if (primes[i]==1)
            continue;
        for (j=i+i; j<100004; j+=i){
            primes[j] = 1;
        }
    }
    for (i=x; primes[i]==1 && i<2*x; i++);
    printf("%d\n", i);
}

int
main(int argc, char *argv[])
{
    int X;
    scanf("%d", &X);
    solver(X);
    return 0;
}

Measured memory_bytes: 512
lists=[]
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    lists.append(H)
    lists.append(W)

j=0
for h in range(len(lists)//2): 
    for i in range(lists[2*j]):
        if i%2==0:
            for m in range(lists[2*j+1]):
                if m%2==0:
                    print("#", end='')
                if m%2!=0:
                    print(".", end='')
            print("")
        elif i%2!=0:
            for m in range(lists[2*j+1]):
                if m%2==0:
                    print(".", end='')
                if m%2!=0:
                    print("#", end='')
            print("")
    print("")
    j=j+1
    


Measured memory_bytes: 7016
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;
#define rep(i, j) for(int i = 0; i < j; i++)
#define f(i, k, j) for(int i = k; i < j; i++)
#define P pair<int, int>
const int INF = (1 << 26);
const int MAX_XY = 15;

void solve();

int x, y, f[MAX_XY + 1][MAX_XY], dp[MAX_XY + 1][MAX_XY];

int main(){
    while(cin >>x >>y && x && y){
        rep(i, MAX_XY + 1) rep(j, MAX_XY) f[i][j] = 1;
        rep(i, y) rep(j, x) cin >>f[i][j];
        memset(dp, 0, sizeof(dp));

        solve();

        int ans = 0;
        rep(i, x) ans += dp[y][i];
        cout <<ans <<endl;
    }
    return 0;
}

void solve(){
    rep(i, x) if(f[0][i] == 0) dp[0][i] = 1;

    rep(i, y - 1){
        rep(j, x){
            if(f[i + 1][j] == 1){
                dp[i + 1][j] = 0;
                continue;
            } else if(f[i + 1][j] == 0){
                f(k, -1, 2){
                    if(j + k < x && j + k >= 0) dp[i + 1][j] += dp[i][j + k];
                }
            } else{
                dp[i + 1][j] += dp[i][j];
                if(i + 3 >= y) dp[y][j] += dp[i + 1][j];
                else dp[i + 3][j] += dp[i + 1][j];
                dp[i + 1][j] = 0;
            }
        }
    }
    rep(i, x) dp[y][i] += dp[y - 1][i];
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void){
    int n, sum = 0, max = 0;
    scanf("%d", &n);
    int l[n];
    
    for(int i=0; i<n; i++){
        scanf("%d", &l[i]);
        if(max < l[i]){
            max = l[i];
        }
        sum += l[i];
    }
    
    sum -= max;
    
    if(max < sum){
        puts("Yes");
    }else{
        puts("No");
    }
    
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>

using namespace std;
const int N=2e5+10,inf=1e9;
int dp[N][2];
char s[N];

int main(){
    int n,k,ans;
    string s;
	cin >> n >> k;
    cin >> s;
    switch (s[k-1])
    {
        case 'A':
            s[k-1] = 'a';
            break;
        case 'B':
            s[k-1] = 'b';
            break;
        case 'C':
            s[k-1] = 'c';
            break;
    }

	cout << s << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>

using namespace std;
typedef long long ll;

int main()
{
	ll N,K;
	ll A[200001];
	cin >> N >> K;
	for(int i = 1; i <= N; i++){
		cin >> A[i];
	}
	
	ll cycle = 0;
	ll now = 1;
	static bool memory[200001];
	for(int i = 0; i < 200001; i++){
		memory[i] = false;
	}
	memory[1] = true;
	ll counter = 0;
	for(int i = 0; i < N; i++){
		now = A[now];
		if(memory[now]){
			break;
		}else{
			memory[now] = true;
		}
		counter++;
	}
	
	ll start = now;
	for(int i = 0; i < N; i++){
		now = A[now];
		cycle ++;
		if(now == start){
			break;
		}
	}
	
	ll K_ = K < counter ? K : (counter + (K-counter) % cycle);
	now = 1;
	for(int i = 0; i < K_; i++){
		now = A[now];
	}
	cout << now << endl;
	
	return 0;
}

Measured memory_bytes: 5392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll ans = 9900000000000000;
    ll left = -1000000000;
    ll right = 1000000000;
    ll mid = 0;
    while(abs(right - left)>1){
        mid = (left+right)/2;
        //cout <<"l r mid "<<left <<" "<<right<<" "<<mid<<endl;
        ll tmpsuml = 0;
        ll tmpsumr = 0;
        for(int i = 0; i < n; i++){
            tmpsuml += abs(a[i]-(mid+i+1));
            tmpsumr += abs(a[i]-(mid+i+2));
        }
        //cout << "suml sumr "<<tmpsuml<<" "<<tmpsumr<<endl;
        if(tmpsuml<tmpsumr){
            right = mid;
            ans = min(tmpsuml, ans);
        }else if(tmpsuml>tmpsumr){
            left = mid;
            ans = min(tmpsumr, ans);
        }else{
            ans = min(tmpsumr, ans);
            break;
        }
    }

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 1792
import sys
import itertools


class Dice(object):
    def __init__(self, faces: list):
        self.list_sn = [faces[5], faces[4], faces[0], faces[1]]  # 6,5,1,2
        self.list_we = [faces[5], faces[2], faces[0], faces[3]]  # 6,5,1,2

    def _roll_positive(self, list_a: list, list_b: list) -> list:
        list_a = list_a[1:] + list_a[0:1]  # Roll one unit in the positive direction.
        list_b[0] = list_a[0]  # Change the bottom face.
        list_b[2] = list_a[2]  # Change the top face.
        return [list_a, list_b]

    def _roll_negative(self, list_a: list, list_b: list) -> list:
        list_a = list_a[3:] + list_a[0:3]
        list_b[0] = list_a[0]  # Change the bottom face.
        list_b[2] = list_a[2]  # Change the top face.
        return [list_a, list_b]

    def roll(self, direction: str):
        if "N" == direction:
            self.list_sn, self.list_we = self._roll_positive(self.list_sn, self.list_we)
        elif "S" == direction:
            self.list_sn, self.list_we = self._roll_negative(self.list_sn, self.list_we)
        elif "E" == direction:
            self.list_we, self.list_sn = self._roll_positive(self.list_we, self.list_sn)
        else:
            self.list_we, self.list_sn = self._roll_negative(self.list_we, self.list_sn)


if __name__ == "__main__":
    dice_num = int(input())
    dice_list = [
        Dice(list(map(lambda x: int(x), input().split()))) for _ in range(dice_num)
    ]

    for Dice_a, Dice_b in itertools.combinations(dice_list, 2):
        for command in "NNNNWNNNWNNNENNNENNNWNNN":  # Check all patterns.
            Dice_b.roll(command)
            if Dice_a.list_sn == Dice_b.list_sn and Dice_a.list_we == Dice_b.list_we:
                print("No")  # Some pair is identical.
                sys.exit()
    print("Yes")  # All dices are different.



Measured memory_bytes: 5692
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl;
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class t,class u>
ostream& operator << (ostream& os,pair<t,u> p){
	return os << p.fi << ',' << p.sec;
}
template<class T>
void dump(vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		cout << vec[i];
		if(i+1<vec.size())cout << ' ';
		else cout << endl;
	}
	return;
}
template<class T>
void input(vector<T>& vec,int n){
	vec.resize(n);
	for(int i=0;i<n;i++){
		cin >> vec[i];
	}
}
void fastio(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
}
int N,M;
int A[100100],B[100100];
struct edge{
	int to,id;
	edge(){}
	edge(int to,int id):to(to),id(id){}
};
vector<edge> g[100100];
bool used[100100];
bool tree[100100];
int depth[100100];
int cnt[100100];
void add_edge(int f,int t,int id){
	g[f].pb(edge(t,id));
	g[t].pb(edge(f,id));
	return;
}
void dfs(int v,int p,int pe,int d){
	used[v] = true;
	depth[v] = d;
	for(int i=0;i<g[v].size();i++){
		edge e = g[v][i];
		if(e.to==p)continue;
		if(!used[e.to]){
			dfs(e.to,v,e.id,d+1);
			tree[e.id]=true;
		}else{
			if(depth[e.to]>depth[v])continue;
			cnt[v]++;
			if(B[e.id]!=e.to)swap(A[e.id],B[e.id]);
		}
	}
	if(cnt[v]%2==1){
		assert(pe!=-1);
		if(A[pe]!=v)swap(A[pe],B[pe]);
	}else{
		cnt[p]++;
		if(A[pe]!=p)swap(A[pe],B[pe]);
	}
	return;
}
int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
		add_edge(A[i],B[i],i);
	}
	if(M%2==1){
		cout << -1 << endl;
		return 0;
	}
	dfs(0,-1,-1,0);
	for(int i=0;i<M;i++){
		cout << A[i]+1 << ' ' << B[i]+1 << endl;
	}
	return 0;
}


Measured memory_bytes: 16384
import java.util.*;

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

        for (;;) {
            double m, f, r;

            m = scanner.nextDouble();
            f = scanner.nextDouble();
            r = scanner.nextDouble();

            if (m + f + r == -3)
                return;

            String grade;

            if (m == -1 || f == -1)
                grade = "F";
            else if (m + f >= 80)
                grade = "A";
            else if (m + f >= 65)
                grade = "B";
            else if (m + f >= 50 || (m + f >= 30 && r >= 50))
                grade = "C";
            else if (m + f >= 30)
                grade = "D";
            else
                grade = "F";

            System.out.println(grade);
        }
    }
}


Measured memory_bytes: 28292
#include <stdio.h>

#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long llong;

void BBuffet(std::istream& in, std::ostream& out) {
  int n;
  vector<int> a, c;
  in >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    in >> x;
    a.push_back(x);
  }
  int sat = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    in >> x;
    sat += x;
  }
  for (int i = 0; i < n - 1; ++i) {
    int x;
    in >> x;
    c.push_back(x);
  }

  for (int i = 0; i < n; ++i) {
    if (i >= 1 && a[i] == a[i - 1] + 1)
      sat += c[a[i - 1] - 1];
  }
  out << sat << endl;
}

int main(int argc, char** argv) { BBuffet(cin, cout); return 0; }


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

int main(){
    ll N;
    scanf("%lld", &N);
    ll end = sqrt(N), min_val = N-1;
    for(int i = 1; i <= end; i++){
        if(N % i == 0){    
            min_val = min(min_val, (N/i)+(i)-2);
        }
    }
    printf("%lld\n", min_val);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	char x, c;
	string s;
	int cnt_a=0,cnt_b=0,cnt_o=0,cnt_ab=0;
	while(cin >> n >> x >> s){
		if(s=="A"){
			cnt_a++;
		}
		else if(s=="B"){
			cnt_b++;
		}
		else if(s=="O"){
			cnt_o++;
		}
		else if("AB"){
			cnt_ab++;
		}
	}
	cout<<cnt_a << endl << cnt_b << endl << cnt_ab << endl << cnt_o << endl;
}

Measured memory_bytes: 1204
n = int(input())
s = [input()for _ in range (n)]
dic = {}

for ss in s:
    sss = list(ss)
    
    sss.sort()
    
    ssss = ''.join(sss)


    if ssss not in dic :
        dic[ssss] = 1
    
    else:
        dic[ssss]= dic[ssss]+1

  

sum = 0

for aaa in dic.values():
    sum += aaa*(aaa-1)//2
    
print(sum)

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

int main(void){
	int W,H,x,y,r;

	cin >> W >> H >> x >> y >> r;

	if(x>(W-r)||x<r||y>(H-r)||y<r) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
    cin >> N;
    int t = N;
    int sum = 0;
    while(t){
        sum += t%10;
        t/=10;
    }
    if(N%sum==0)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import Text.Printf

main = do
    ss <- getLine
    let ns = map (\x -> read x :: Double) $ words ss
    let (x1:y1:x2:y2:_) = ns
    let ans = dist x1 y1 x2 y2
    printf "%.8f\n" ans
    
dist :: Double -> Double -> Double -> Double -> Double
dist x1 y1 x2 y2 = sqrt $ (x1 - x2)^2 + (y1 - y2)^2


Measured memory_bytes: 4048
/***********************************************
#
#      Filename: d.cpp
#
#        Author: Comsyl - ylsong15@fudan.edu.cn
#   Description: ---
#        Create: 2017-05-11 19:41:07
***********************************************/
#include <bits/stdc++.h>
using namespace std;
bool ok;

// whether cur needs to match par
int dfs(int cur, int par, const vector<vector<int>>& E) {
    int cnt = 0;
    for (int v : E[cur]) {
        if (v != par) {
            cnt += dfs(v, cur, E);
        }
    }
    if (cnt > 1) {
        ok = false;
        return 0;
    }
    if (cnt == 1) return 0;
    return 1;
}

int main()
{
    int n;
    cin >> n;
    auto E = vector<vector<int>> (n, vector<int>());
    int u, v;
    for (int i = 0; i < n-1; ++ i) {
        cin >> u >> v;
        -- u; -- v;
        E[u].push_back(v);
        E[v].push_back(u);
    }
    ok = true;
    int res = dfs(0, -1, E);
    if (ok) ok = (res == 0);
    cout << (ok ? "Second" : "First") << endl;
    return 0;
}


Measured memory_bytes: 5888
def count_char(chars):
    res = {chr(i): 0 for i in range(97, 123)}
    for c in chars.lower():
        if c in res:
            res[c] += 1
    return(res)


if __name__ == "__main__":
    
    s = ""
    while True:
        try:
            s += input()
        except:
           break

    for k, v in count_char(s).items():
        print(f"{k} : {v}")




Measured memory_bytes: 5576
#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main()
{
    int i,m,n,p;
    int t=0;
    scanf("%d",&p);
    for(m=p;;m++)
    {n=sqrt(m);
    for(i=2;i<=n;i++)
        if(m%i==0)
        break;
    if(i>n)
    {printf("%d",m);
    t++;
    if(t==1)
        break;
    }

    }

    return 0;
}

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

const int MOD = 1e9+7;
const int MAX_N = 1e5+10;
int n, m;
int x[MAX_N], y[MAX_N];
ll xpsum[MAX_N], ypsum[MAX_N];

void solve()
{
    for(int i=1;i<=n;++i) (ypsum[i] = ypsum[i-1]+y[i])%=MOD;
    ll ysum = 0;
	for(int i=2;i<=n;++i)(ysum += 1LL*(i-1)*y[i]-ypsum[i-1])%=MOD;
	for(int i=1;i<=m;++i) (xpsum[i] = xpsum[i-1]+x[i])%=MOD;
	ll xsum = 0;
	for(int i=2;i<=m;++i)(xsum += 1LL*(i-1)*x[i]-xpsum[i-1])%=MOD;
	ll ans = xsum*ysum%MOD;
	cout<<ans<<'\n';
}

int main()
{
	cin >> m >> n;
	for(int i=1;i<=m;++i) cin >> x[i];
	for(int i=1;i<=n;++i) cin >> y[i];
	solve();
	return 0;
}

Measured memory_bytes: 5932
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cctype>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<cstring>
//#include<windows.h>
//#include<time.h>
#define pb push_back
#define fi first
#define se second
#define mer make_pair
#define mme memset
using namespace std;

const double pie1=3.1415926;//π1
const double pie2=3.14159265358979;//π2
const double pie3=3.14159265358979323846;//π3
const int vbi=999999999;
const int vli=-vbi;
const long long vbl=999999999999999999;
const long long vll=-vbl;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pii,int> piii;
typedef pair<pii,pii> pi4;
typedef pair<pll,ll> plll;
typedef pair<int,pii> ipii;
typedef pair<ll,pll> lpll;
typedef pair<pll,pll> pl4;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef set<int> sti;
typedef set<ll> stl;
typedef set<pii> spi;
typedef set<pll> spl;
priority_queue<int> pqi;
priority_queue<ll> pql;
queue<int> qi;
queue<ll> ql;

/*void bin_v(){
	char bin[1000];
	gets(bin);
}*/

bool pss(int a){
	for(int i=2;i<=sqrt(a);i++)
		if(a%i==0)
			return false;
	return true;
}
/////////////////////////////////////////////////////////////////////////////////////////
vector<ll> cf;
map<ll,int> mp;

void make_cf(){
	ll sum=1;
	for(int i=1;i<=31;i++){
		sum*=2;
		cf.pb(sum);
	}
}

int main(){
	//my name is Veex
	make_cf();
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	ll a[n+10];
	for(int i=1;i<=n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	int sum=0;
	for(int i=1;i<=n;i++){
		if(mp[a[i]]<=0)
			continue;
		int x=*upper_bound(cf.begin(),cf.end(),a[i]);
		x=x-a[i];
//		cout<<a[i]<<' '<<x<<endl;
		if((x==a[i]&&mp[x]>=2)||(x!=a[i]&&mp[x]>=1)){
			mp[x]--;
			mp[a[i]]--;
			sum++;
		}
		else
			mp[a[i]]--;
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 26752
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.meta;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(int N, int[][] A) {
    int[][] standby = new int[][](N, N);
    Tuple!(int, int)[] match;

    foreach (i; 0 .. N) {
        auto lside = min(A[i].front - 1, i);
        auto rside = max(A[i].front - 1, i);
        A[i].popFront;
        if (++standby[lside][rside] == 2)
            match ~= tuple(lside, rside);
    }

    int ans;
    int done;
    Tuple!(int, int)[] nmatch = [];

    while (true) {
        ans++;
        foreach (t; match) {
            done++;
            auto x = t[0];
            auto y = t[1];

            int lside, rside;
            if (!A[x].empty) {
                lside = min(x, A[x].front - 1);
                rside = max(x, A[x].front - 1);
                A[x].popFront;
                if (++standby[lside][rside] == 2)
                    nmatch ~= tuple(lside, rside);
            }

            if (!A[y].empty) {
                lside = min(y, A[y].front - 1);
                rside = max(y, A[y].front - 1);
                A[y].popFront;
                if (++standby[lside][rside] == 2)
                    nmatch ~= tuple(lside, rside);
            }
        }

        if (nmatch.empty)
            break;
        match = nmatch;
        nmatch = [];
    }

    if (done == N * (N - 1) / 2)
        return ans;
    return -1;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    int N;
    N = input.front.to!int;
    input.popFront;

    int[][] A = new int[][](cast(size_t) (N), cast(size_t) (N-1));
    foreach (i; 0 .. cast(size_t) (N)) {
        foreach (j; 0 .. cast(size_t) (N-1)) {
            A[i][j] = input.front.to!int;
            input.popFront;
        }
    }

    static if (is(ReturnType!solve == void))
        solve(N, A);
    else
        solve(N, A).writeln;
}


Measured memory_bytes: 12668
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

const ll N_MAX=3010;
ll a[N_MAX];
ll dp[N_MAX][N_MAX][3];

ll solve(int p,int q,int r){
  if(dp[p][q][r]!=-1) return dp[p][q][r];
  if(p>q) return 0;
  if(r){
    dp[p][q][r]=max(solve(p+1,q,0)+a[p],solve(p,q-1,0)+a[q]);
  }else if(r==0){
    dp[p][q][r]=min(solve(p+1,q,1)-a[p],solve(p,q-1,1)-a[q]);
  }
  return dp[p][q][r];

}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;

  //ll k;
  for(int i=1;i<=N;i++){
    cin >> a[i];
    //a.push_back(k);
  }

  for(int i=0;i<N_MAX;i++){
    for(int j=0;j<N_MAX;j++){
      dp[i][j][0]=dp[i][j][1]=-1;
    }
  }
  //1が太郎
  cout << solve(1,N,1) << endl;
  return 0;
}

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

int main() {
  int N,A,B,a=0,b=0,c=0;
  cin >> N >> A >> B;
  for(int i=0; i<N; i++){
    int P;
    cin >> P;
    if(P<=A){
      a++;
    }
    else if(P<=B){
      b++;
    }
    else{
      c++;
    }
  }
  cout << min(a,min(b,c)) << endl;
}


Measured memory_bytes: 3512
sx,sy,tx,ty=map(int,input().split())
ans=[]

for i in range(ty-sy):
    ans.append("U")
for i in range(tx-sx):
    ans.append("R")
for i in range(abs(sy-ty)):
    ans.append("D")
for i in range(abs(sx-tx)):
    ans.append("L")

ans.append("L")
for i in range(ty-sy+1):
    ans.append("U")
for i in range(tx-sx+1):
    ans.append("R")
ans.append("D")
ans.append("R")
for i in range(abs(sy-ty)+1):
    ans.append("D")
for i in range(abs(sx-tx)+1):
    ans.append("L")
ans.append("U")

print("".join(ans))

Measured memory_bytes: 3188
n, m = gets.split.map(&:to_i)
d = []
h = []
n.times{ d << gets.to_i }
m.times{ h << gets.to_i }
dp = Array.new(2){ Array.new(n+1, 1<<31) }
dp[0][0] = dp[1][0] = 0
m.times do |i|
  (0..[i,n-1].min).each do |j|
    dp[i%2^1][j+1] = [dp[i%2][j+1], dp[i%2][j] + d[j] * h[i]].min
  end
end
p dp[m%2][-1]

Measured memory_bytes: 8836