akhauriyash/Code-Regression huggingface dataset:
alist = []
blist = []
for i in range(4):
    a = int(input())
    alist.append(a)
for i in range(2):
    b = int(input())
    blist.append(b)
alist.sort()
blist.sort()
print(alist[1]+alist[2]+alist[3]+blist[1])


Measured memory_bytes: 5600
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





















int main(){
    ll n, m, x;
    cin >> n >> m >> x;
    vector<ll> c(n);
    vector<vector<ll>> a(n, vector<ll>(m));
    REP(i, n){
        cin >> c[i];
        REP(j, m){
            cin >> a[i][j];
        }
    }
    ll ans = INF;
    REP(bit, (1 << n)){
        vector<ll> s(m);
        ll sum = 0;
        REP(i, n){
            if(bit & (1LL << i)){
                sum += c[i];
                REP(j, m){
                    s[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        REP(i, m){
            if(s[i] < x){
                ok = false;
                break;
            }
        }
        if(ok) ans = min(ans, sum);
    }
    cout << ((ans != INF)? ans : -1) << endl;
}


Measured memory_bytes: 3632
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;

class E
{
	static long F()
	{
		return long.Parse(Console.ReadLine());
	}
	static long[] G()
	{
		return Console.ReadLine().Split().Select(long.Parse).ToArray();
	}
	static long[] F(long[] v)
	{
		var w = new long[v.Length];
		for (var i = 0; i < v.Length; i++) w[i] = -v[i];
		return w;
	}
	static long[,] c;
	static long Comb(int a, int b)
	{
		if (c == null)
		{
			var M = 50;
			c = new long[M + 1, M + 1];
			for (var i = 0; i <= M; i++) c[i, 0] = c[i, i] = 1;
			for (var i = 2; i <= M; i++) for (var k = 1; k < i; k++) c[i, k] = c[i - 1, k - 1] + c[i - 1, k];
		}
		return c[a, b];
	}
	public static void Main()
	{
		var v = G();
		int N = (int)v[0], A = (int)v[1], B = (int)v[2];
		Array.Sort(v = G());
		var k = new List<long>(N);
		var d = new Dictionary<long, int>(N);
		foreach (var x in v)
		{
			if (!d.ContainsKey(x))
			{
				d[x] = 1;
				k.Add(x);
			}
			else d[x]++;
		}
		k.Reverse();
		var s = 0L;
		var sc = 0;
		var last = 0L;
		foreach (var x in k)
		{
			if (sc + d[x] >= A)
			{
				sc = A - sc;
				s += sc * x;
				last = x;
				break;
			}
			else
			{
				s += d[x] * x;
				sc += d[x];
			}
		}
		Console.WriteLine(s / (double)A);
		if (sc == A)
		{
			var s2 = Math.Min(d[last], B);
			var ans = 0L;
			for (var i = sc; i <= s2; i++) ans += Comb(d[last], i);
			Console.WriteLine(ans);
		}
		else Console.WriteLine(Comb(d[last], sc));
	}
}


Measured memory_bytes: 13536
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
l3=list(map(int,input().split()))

s=0
for i in range(0,min(l1[0],l1[1],l1[2],l2[0],l3[0])+1):
  j=l1[0]-i
  m=l1[1]-i
  n=l1[2]-i
  if l2[0]-j==l2[1]-m==l2[2]-n and l3[0]-j==l3[1]-m==l3[2]-n:
    s=1
    break

print("Yes" if s==1 else "No")

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

int main(){
    string S, T;
    cin >> S >> T;
    int n = S.length();
    bool ans = true;
    for(int i = 0; i < n; i++){
        if(S[i] != T[i]) ans = false;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

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

    int ans = 0;
    for(int sec = 0; sec < 1000; sec++) {
      int count = 0, tmp = sec;
      for(int i = 0; i < N; i++) {
        if(S.charAt(N - 1 - i) - '0' == tmp % 10) {
          tmp = tmp / 10;
          count++;
        }
        if(count == 3) {
          ans += 1;
          break;
        }
      }
    }
    System.out.println(ans);
  }
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	vector<ll> S(N+1,0);
	REP(i,N){
		ll V=in();
		S[i+1] += S[i]+V;
	}
	map<ll,ll> C;
	REP(i,N+1){
		C[S[i]]++;
	}

	ll sum = 0;
	for(auto& x:C){
		sum += max(0LL,x.second*(x.second-1LL)/2LL);
	}
	out(sum);
	return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }

LL MOD = 1000000007;

int main(){
    LL n;
    cin >> n;
    vector<LL> a(n);
    for(LL i = 0; i < n; ++i){
        cin >> a[i];
    }
    vector<LL> bit_cnt(61);
    for(LL i = 0; i < n; ++i){
        for(LL j = 0; j < 61; ++j){
            if(a[i] & (1LL<<j)) bit_cnt[j]++;
        }
    }
    LL ans = 0;
    for(LL j = 0; j < 61; ++j){
        ans = (ans + (1LL<<j) % MOD * bit_cnt[j] % MOD * (n - bit_cnt[j]) % MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2560
# 初期入力
import sys
input = sys.stdin.readline  #文字列では使わない
K = int(input())

count =1
x=7 %K

if K %2 ==0 or K %5 ==0:
    count = -1
else:

    while x %K !=0:
        count +=1
        x = (x*10 +7)%K
        #print(x,end =" ")
print(count)

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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1)
  {
    sz = 1;
    while (sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x)
  {
    seg[k + sz] = x;
  }

  void build()
  {
    for (int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x)
  {
    k += sz;
    seg[k] = x;
    while (k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b)
  {
    Monoid L = M1, R = M1;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1) L = f(L, seg[a++]);
      if (b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const
  {
    return seg[k + sz];
  }
};

void solve() {
  int N, Q; cin >> N >> Q;
  SegmentTree<int> seg(N, [](int a, int b){ return a + b; }, 0);
  string s;
  cin >> s;
  rep(i, N - 1) {
    if (s.substr(i, 2) == "AC") seg.update(i, 1);
  }
  rep(_, Q) {
    int l, r; cin >> l >> r;
    l--, r--;
    cout << seg.query(l, r) << '\n';
  }
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define x first
#define y second
#define sz(a) ((int)(a.size()))
const int mod = 1812447359;
const int mod2 = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const int MAX = 200005;
const int ZSUV = 10 * 1000 * 1000;
int main() {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for(auto &x : a)
		cin >> x;
	vector<ll> b(n + 1);
	b[n] = a[n];
	for(int i = n - 1; i >= 0; i--)
		b[i] = a[i] + b[i + 1];
	ll ans = 0;
	ll now = 1;
	for(int i = 0; i <= n; i++)
	{
		if(a[i] > now)
		{
			cout << -1;
			return 0;
		}
		ans += now;
		now -= a[i];
		now *= 2;
		if(i != n)
			now = min(now , b[i + 1]);
	}
	cout << ans;
}


Measured memory_bytes: 4496
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int[] c = new int[N];
		int[] t = new int[N];
		int p = 1100;
		for(int i = 0; i < N; i++){
			c[i] = sc.nextInt();
			t[i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++){
			if((t[i] <= T) && (c[i] < p)){
					p = c[i];
				}
			}
		if(p == 1100){
			System.out.println("TLE");
		}else{
			System.out.println(p);
		}
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

ll dp[22][1 << 22];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> a[i][j];
        }
    }
    dp[0][0] = 1;
    for (int i = 0; i < n; i++)
    {
        for (int S = 0; S < (1 << n); S++)
        {
            if (dp[i][S] == 0)
            {
                continue;
            }
            for (int j = 0; j < n; j++)
            {
                if (S & (1 << j))
                {
                    continue;
                }
                if (a[i][j] == 1)
                {
                    (dp[i + 1][S + (1 << j)] += dp[i][S]) %= MOD;
                }
            }
        }
    }
    cout << dp[n][(1 << n) - 1] << endl;
}

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

using ll=long long;
#define int ll

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

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}
int h[1500+1],w[1500+1];
signed main(){
	bool flag=false;
	while(true){
	int N=read(),M=read();
	if(N==0&&M==0) break;
	int maxh=0,maxw=0;
	REP(i,N){
		h[i]=read();
		maxh+=h[i];
	}
	REP(i,M){
		w[i]=read();
		maxw+=w[i];
	}
	
	int MIN=min(maxh,maxw);
	
	int cntH[maxh+1],cntW[maxw+1];
	
	REP(i,MIN+1){
		cntH[i]=0;
		cntW[i]=0;
	}
	
	int length;
	REP(i,N){
		length=0;
		FOR(j,i,N){
			length+=h[j];
			cntH[length]++;
		}
	}
	
	REP(i,M){
		length=0;
		FOR(j,i,M){
			length+=w[j];
			cntW[length]++;
		}
	}
	int ans=0;
	FOR(i,1,MIN+1) ans += cntH[i]*cntW[i];
	
	cout << ans << endl;
	}
}

Measured memory_bytes: 11100
#include <stdio.h>
#define MAX_N 100
#define INF 2001
 
struct vertex
{
  int dis;
  int Edge[MAX_N];
  int visit;
} typedef vertex;
 
int n;
vertex V[MAX_N]; 
 
int Sum();
 
int main()
{
  int i, j;
 
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      for(j = 0; j < n; j++)
    {
      scanf("%d", &V[i].Edge[j]);
    }
    }
 
  printf("%d\n", Sum());
 
  return 0;
}
 
int Sum()
{
  int i, j;
  int join = 0;
  int d, mini_d;
  int sum = 0;
 

  for(i = 0; i < n; i++)
    {
      V[i].dis = INF;
      V[i].visit = 0;
    }
 
  for(i = 0; i < n; i++)
    {
      V[join].visit = 1;
 
   
      for(j = 0; j < n; j++)
    {
      d = V[join].Edge[j];
 
      if(V[j].visit == 0 && d < V[j].dis && d != -1)
        V[j].dis = d;
    }

      mini_d = INF;
      for(j = 0; j < n; j++)
    {
      if(mini_d > V[j].dis && V[j].visit == 0) 
        {
          mini_d = V[j].dis;
          join = j;
        }
    }
      if(mini_d != INF)
    sum += mini_d;
    }
 
  return sum;
}

Measured memory_bytes: 640
n = int(input())

s = set()
for _ in range(n):
    c, k = [int(x) for x in input().split()]
    if c == 0:
        s.add(k)
        print(len(s))
        continue
    if c == 1:
        if k in s:
            print(1)
        else:
            print(0)
        continue
    if c==2:
        s.discard(k)




Measured memory_bytes: 23368
d,g = map(int,input().split())
    
arr = []
    
for i in range(d):
    arr.append(list(map(int,input().split())))
    
from itertools import product
from math import ceil
    
ans = 1e09
#各問題を選択するしないを01表記
for c in product([0,1],repeat=d):
    #print(c)
    #スコア
    score = 0
    #解く問題数
    num = 0
    
    ind = 0
    #まず01表記を全て
    for i in range(d):
        #もし01表記で1の場合，完答した場合の点数，問題数を加算
        if c[i] == 1:
            score += arr[i][0]*100*(i+1) + arr[i][1]
            num += arr[i][0]
        #0だった場合，
        else:
            ind = max(i,ind)
    #目標よりも点数が大きかった場合，小さい方を答えにする
    if g - score <= 0:
        ans = min(ans,num)
        #print(0,ans,num,score,ind)
    #もし目標が，点数とind番目の問題を完答してない場合との和より小さい時
    elif g - score <= (arr[ind][0]-1)*100*(ind+1):
        num += ceil((g-score)/(100*(ind+1)))
        ans = min(ans,num)
        #print(1,ans,num,score,ind)
    else:
        pass
#print(2,num,score,ind)
print(ans)

Measured memory_bytes: 40560
#include <bits/stdc++.h>
using namespace std;
 
const int INF = 1145141919;
const long long INFL = 1LL<<60;
 
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
 
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
 
int main()
{
	int N, W;
	cin >> N >> W;
	int w[110], v[110];
	for (int i = 0; i < N; ++i)
	{
		cin >> w[i] >> v[i];
	}
	int dp[110001];
	for (int i = 0; i <= 110000; ++i)
	{
		dp[i] = INF;
	}
	dp[0] = 0;
	for (int i = 0; i < N; ++i)
	{
		for (int j = 110000; j >= 0; --j)
		{
			if(dp[j] != INF && j+v[i] <= 110000)
			{
				dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
			}
		}
	}
	int ans = INF;
	for (int i = 110000; i >= 0; --i)
	{
		if(dp[i] <= W)
		{
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 640
N, K = map(int, input().split())
H = list(map(int, input().split())) # N匹のモンスターの体力
ans = 0
tot = 0

if N <= K:
    tot = 0
else:
    H.sort(reverse = False)
    for i in range(N - K):
        tot += H[i]
        
print(tot)

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

template<class E, class T> struct Rerooting {
    using F = function<T(T, T)>;
    using H = function<T(T, E)>;
private : 
    struct Edge {
        int to;
        E dat;
        T dp, sum;
        Edge (int to, const E &dat, const T &dp, const T &sum) : 
            to(to), dat(dat), dp(dp), sum(sum) { }
    };
    vector<vector<Edge>> g;
    vector<T> subdp, dp;
    const T id;
    const F f;
    const H h;
    int edges;

public : 
    Rerooting (int n, const F &f, const H &h, const T &id) : 
        g(n), f(f), h(h), id(id), subdp(n, id), dp(n, id) { edges = 0; }

    void add_edge (int v, int u, const E &val) {
        assert(++edges < (int)g.size());
        g[v].emplace_back(u, val, id, id);
        g[u].emplace_back(v, val, id, id);
    }

    void add_edge2 (int v, int u, const E &val1, const E &val2) {
        assert(++edges < (int)g.size());
        g[v].emplace_back(u, val1, id, id);
        g[u].emplace_back(v, val2, id, id);
    }

    void dfs1 (int v, int p) {
        for (const auto &e : g[v]) {
            if (e.to == p) continue;
            dfs1(e.to, v);
            subdp[v] = f(subdp[v], h(subdp[e.to], e.dat));
        }
    }

    void dfs2 (int v, int p, const T &top) {
        T buff = id;
        for (int i = 0; i < (int)g[v].size(); i++) {
            Edge &e = g[v][i];
            e.sum = buff;
            e.dp = h(e.to == p ? top : subdp[e.to], e.dat);
            buff = f(buff, e.dp);
        }
        dp[v] = buff;
        buff = id;
        for (int i = (int)g[v].size() - 1; i >= 0; i--) {
            Edge &e = g[v][i];
            if (e.to != p) dfs2(e.to, v, f(buff, e.sum));
            e.sum = f(e.sum, buff);
            buff = f(buff, e.dp);
        }
    }

    vector<T> build(int s = 0) {
        dfs1(s, -1);
        dfs2(s, -1, id);
        return dp;
    }

};

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

    auto f = [](int a, int b) { return max(a, b); };
    auto h = [](int a, int b) { return (a + b); };
    Rerooting<int, int> g(n, f, h, 0);

    for (int i = 0; i < n - 1; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        g.add_edge(a, b, c);
    }

    for (auto ans : g.build()) cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 4716
#include <bits/stdc++.h>
using namespace std;
#define FORN(i, a, b)                   for(int i=a; i<=b; ++i)
#define pb                              push_back
const int N = 2e5 + 10;
int h, w, n;
typedef pair< int, int > pr;
map < pr, bool > block;
vector < int > col[N];
int main() {
    ios::sync_with_stdio(0);
    cin >> h >> w >> n;
    FORN(i, 1, n) {
        int x, y;
        cin >> x >> y;
        block[{x, y}] = true;
        col[y].pb(x);
    }
    FORN(i, 1, w) { col[i].pb(h+1); block[{h+1, i}] = true; }
    FORN(i, 1, h) sort(col[i].begin(), col[i].end());
    int ans = 1e6;
    for(int x = 1, y = 1, steps = 0; x <= h && y <= w;) {
        if (block[{x+1, y}]) { steps ++; ans = min(ans, steps); break; }
        auto nxt = *lower_bound(col[y].begin(), col[y].end(), x);
        ans = min(ans, steps + nxt - x);
        x ++; steps ++;
        while (x < nxt && y < w && block[{x, y+1}]) { steps ++; x++; }
        if (x < nxt) y++;
    }
    cout << ans;
}

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

int main(){
    int N;
    cin >> N;
    long long x[N], y[N], h[N];
    long long X, Y, H;
    rep(i, N){
        scanf("%lld%lld%lld", &x[i],& y[i], &h[i]);
    }
    for(int i = 0; i <= 100; i++){
        for(int j = 0; j <= 100; j++){
            for(int k = 0; k < N; k++){
                if(h[k] != 0){
                    H = h[k] + abs(i - x[k]) + abs(j - y[k]);
                    break;
                }
            }
            for(int k = 0; k < N; k++){
                if(h[k] != 0){
                    if(H != h[k] + abs(i - x[k]) + abs(j - y[k]) )break;
                }else{
                    if(H > abs(i - x[k]) + abs(j - y[k]) )  break;
                }
                if(k == N - 1) cout << i << " " << j << " " << H << endl;
            }
        }
    }
    return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  cout << (h2 * 60 + m2) - (h1 * 60 + m1) - k;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3600
def bfs(u):
  if used.count(True) == N:
    res[0] += 1
    return
  for v in adj[u]:
    if used[v]:
      continue
    used[v] = True
    bfs(v)
    used[v] = False

N, M = map(int, input().split())
adj = [[] for i in range(N)]
for i in range(M):
  u, v = map(lambda x: int(x)-1, input().split())
  adj[u].append(v)
  adj[v].append(u)

used = [False for i in range(N)]
used[0] = True
res = [0]
bfs(0)

print(res[0])


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#define MAX 20000001
#define VMAX 10000

int main(void) {
    unsigned short *A, *B;

    int C[VMAX+ 1];
    int n, i, j;
    scanf("%d", &n);

    A = malloc(sizeof(short) * n + 1);
    B = malloc(sizeof(short) * n + 1);

    // for i = 0 to k
    for ( i = 0; i <= VMAX; i++ ) C[i] = 0;

    // C[i]にiの出現数を記録する
    for ( i = 0; i < n; i++ ) {
        scanf("%hu", &A[i + 1]);
        C[A[i + 1]]++;    
    }

    // C[i]にi以下の数の出現数を記録する  for i = 1 to k
    for ( i = 1; i <= VMAX; i++ ) C[i] = C[i] + C[i - 1];

    // for j = n downto 1
    for ( j = 1; j <= n; j++ ) {
        B[C[A[j]]] = A[j];
        C[A[j]]--;
    }

    for ( i = 1; i <= n; i++ ) {
        if ( i > 1 ) printf(" ");
        printf("%d", B[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 9596
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////

struct db {
	ll f;
	ll s;
};

bool cmp(db x, db y) {
	return x.s > y.s;
}



ll n;

ll v[MAX];

int main() {

	ll n;
	cin >> n;

	while (n % 111 != 0) { n++; }

	cout << n;

	

	system("PAUSE");
}

Measured memory_bytes: 504
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String a = br.readLine();
		String b = br.readLine();
		String c = br.readLine();
		String turn = a;
		a = a.substring(1,a.length());
		while(true){
			char ch = turn.charAt(0);
			if(ch=='a'){
				turn = a;
				if(turn.length()==0){
					sb.append('A');
					break;
				}
				a = a.substring(1,a.length());
			}else if(ch=='b'){
				turn = b;
				if(turn.length()==0){
					sb.append('B');
					break;
				}
				b = b.substring(1,b.length());
			}else if(ch=='c'){
				turn = c;
				if(turn.length()==0){
					sb.append('C');
					break;
				}
				c = c.substring(1,c.length());
			}
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 8148
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100005;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vector<int> cnt(60,0),x(60,0);
    for(auto it:a){
        for(int i=0;i<50;i++){
            if(it&(1ll<<i))cnt[i]++;
        }
    }
    for(int i=0;i<60;i++){
        if((2*cnt[i]<n)&&((1ll<<i)<=k))x[i]=1;
    }
    int X=0;
    for(int i=0;i<60;i++)if(x[i])X|=(1ll<<i);
    int res=0;
    if(X<=k)for(auto it:a)res+=(it^X);
    for(int i=60;i>=0;i--){
        if(x[i]){
            X-=(1ll<<i);
            if(X<=k){
                int tmp=0;
                for(auto it:a)tmp+=(it^X);
                res=max(res,tmp);
                X+=(1ll<<i);
            }
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int N, H;
int a[MAX_N], b[MAX_N];

typedef tuple<int, int, int> T;
struct CustomCompare {
  bool operator()(const T &t1, const T &t2) { return get<2>(t2) > get<2>(t1); }
};

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> H;
  REP(i, N) cin >> a[i] >> b[i];

  int idx = 0;
  int ma = 0;
  for (int i = 0; i < N; i++) {
    if (ma < a[i]) {
      ma = max(ma, a[i]);
      idx = i;
    }
  }

  priority_queue<T, vector<T>, CustomCompare> q;
  REP(i, N) if (i != idx) q.push({i, a[i], b[i]});

  int ans = 0;
  int h = H;
  while (!q.empty()) {
    T t = q.top();
    q.pop();
    int ii = get<0>(t), aa = get<1>(t), bb = get<2>(t);
    // 倒せるなら振るための刀でも使ってよい
    if (b[idx] >= h) {
      h -= b[idx];
      ans++;
      break;
    }
    // そうでなければ基本的には上から順番に投げる
    // が、ただし a[idx] の方がつよければそちらを使う
    if (bb < a[idx]) {
      h -= a[idx];
      ans++;
      break;
    }
    else {
      h -= bb;
      ans++;
    }
    if (h <= 0) {
      break;
    }
  }

  if (h > 0) {
    h -= b[idx];
    ans++;
    ans += ceil((double)h / a[idx]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2680
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prd(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
const int inf = 1e9+10;
const ll INF = 2e18+10;
const int Mod = 1e9+7;
const int MAXN = 1000010;
const int N=2e5+10;
const int M=210;
const int M1=1e9+7;
const int M2=1e9+9;
const int base=131;
int main()
{
  ios::sync_with_stdio(0), cin.tie(0); cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int x;
  cin>>x;
  if(x>=30) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	int arr[n][3];
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			// arr[i].push_back()	
			cin >> arr[i][j];
		}
		
	}
	int dp[n+1][3];
	
	memset(dp, 0, sizeof(dp));
	
	dp[0][0] = arr[0][0];
	dp[0][1] = arr[0][1];
	dp[0][2] = arr[0][2];

	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++){

			dp[i][j] = arr[i][j] + max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]);
		}
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;
	return 0;
}

Measured memory_bytes: 5940
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i,a) for(ll i=a-1;i>=0;i--)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define printall(n,array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

int main(){
    ll s;
    ll cnt = 2;
    cin >> s;
    ll now = s;
    VE v;
    v.push_back(now);
    while(true){
        if(now%2==0){
            now = now / 2;
        }else{
            now = now * 3 + 1;
        }
        auto result = find(v.begin(), v.end(), now);
        if(result != v.end()){
            break;
        }else{
            v.push_back(now);
            cnt++;
        }
    }
    print(cnt);
}

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

using namespace std;

int k,n;
int a[200010];
int ans;

int main()
{
    scanf("%d%d",&k,&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
    {
        ans=max(ans,a[i]-a[i-1]);
        if(i==n)
        {
            ans=max(ans,k-a[n]+a[1]);
        }
    }
    if(n==2)
        printf("%d",min(a[2]-a[1],k-a[2]+a[1]));
    else
        printf("%d",k-ans);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

vector<int> sub_count;

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

	int N;
	cin >> N;

	sub_count.assign(N, 0);

	for (int i = 0; i < N - 1; i++)
	{
		int a;
		cin >> a;

		sub_count[a - 1]++;
	}

	for (int i = 0; i < N; i++)
	{
		cout << sub_count[i] << "\n";
	}

	return 0;
}


Measured memory_bytes: 3912
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long H, W;

string S[505];
string B[505];
string R[505];

int main(){
	cin >> H >> W;
	for(int i = 0; i < H; i++){
		cin >> S[i];
	}

	for(int i = 0; i < H; i++){
		string tmp = "";
		for(int j = 0; j < W; j++){
			if(i % 2 == 0){
				if(j == 0){
					tmp += "#";
				}else if(j == W - 1){
					tmp += ".";
				}else{
					tmp += ".";
				}
			}else{
				if(j == 0){
					tmp += "#";
				}else if(j == W - 1){
					tmp += ".";
				}else{
					tmp += "#";
				}
			}
		}
		B[i] = tmp;
	}

	for(int i = 0; i < H; i++){
		string tmp = "";
		for(int j = 0; j < W; j++){
			if(i % 2 == 0){
				if(j == 0){
					tmp += ".";
				}else if(j == W - 1){
					tmp += "#";
				}else{
					tmp += "#";
				}
			}else{
				if(j == 0){
					tmp += ".";
				}else if(j == W - 1){
					tmp += "#";
				}else{
					tmp += ".";
				}
			}
		}
		R[i] = tmp;
	}

	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(S[i][j] == '#'){
				R[i][j] = '#';
				B[i][j] = '#';
			}
		}
	}

	for(int i = 0; i < H; i++){
		cout << R[i] << endl;
	}

	cout << endl;

	for(int i = 0; i < H; i++){
		cout << B[i] << endl;
	}

}



Measured memory_bytes: 1536
H, W = gets.split(" ").map(&:to_i)

G = Array(H){Array(W, nil)}
H.times do |i|
  G[i] = gets.chomp.split("")
end

def paintable?(i, j)
  if i > 0 && j > 0 && i < H - 1 && j < W - 1 then
    if G[i+1][j] == "." && G[i-1][j] == "." && G[i][j-1] == "." && G[i][j+1] == "." then
      return false
    else
      return true
    end
  elsif i == 0 && j > 0 && i < H - 1 && j < W - 1 then
    if G[i+1][j] == "." && G[i][j-1] == "." && G[i][j+1] == "." then
      return false
    else
      return true
    end
  elsif i > 0 && j == 0 && i < H - 1 && j < W - 1 then
    if G[i][j+1] == "." && G[i+1][j] == "." && G[i-1][j] == "." then
      return false
    else
      return true
    end
  elsif i > 0 && j > 0 && i == H - 1 && j < W - 1 then
    if G[i-1][j] == "." && G[i][j+1] == "." && G[i][j-1] == "." then
      return false
    else
      return true
    end
  elsif i > 0 && j > 0 && i < H - 1 && j == W - 1 then
    if G[i-1][j] == "." && G[i+1][j] == "." && G[i][j-1] == "." then
      return false
    else
      return true
    end
  elsif i == 0 && j == 0 then
    if G[i+1][j] == "." && G[i][j+1] == "." then
      return false
    else
      return true
    end
  elsif i == H - 1 && j == W - 1 then
    if G[i-1][j] == "." && G[i][j-1] == "." then
      return false
    else
      return true
    end
  elsif i == 0 && j == W - 1 then
    if G[i+1][j] == "." && G[i][j-1] == "." then
      return false
    else
      return true
    end
  elsif j == 0 && i == H - 1 then
    if G[i-1][j] == "." && G[i][j+1] == "." then
      return false
    else
      return true
    end
  end
end

check = true

H.times do |i|
  W.times do |j|
    if G[i][j] == "#" then
      unless paintable?(i, j)
        puts "No"
        check = false
        exit
      end
    end
  end
  unless check
    exit
  end
end


if check then
  puts "Yes"
end

Measured memory_bytes: 2044
dic = {}

for i in range(int(input())):
    order = list(input().split())

    if order[0] == "0":
        if order[1] in dic:
            dic[order[1]] = int(order[2])
        else:
            dic[order[1]] = int(order[2])
    else:
        print(dic[order[1]])


Measured memory_bytes: 37504
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int n;
    string s,t;

    cin >> n;
    cin >> s >> t;

    rep(i,n){
        cout << s[i];
        cout << t[i ];
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
"""
 // Author : snape_here - Susanta Mukherjee

"""
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()

    
#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
from math import ceil,floor,log,sqrt,factorial,pow,pi
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *,threading



def ii(): return int(input())
def fi(): return float(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())

import math
 
def find_gcd(x, y): 
      
    while(y): 
        x, y = y, x % y 
      
    return x
 
def main():
 
    n=ii()
    l=li()
    a=0
    for i in range(n):
        a+=1/l[i]
    a=1/a 
    print(a)
    
# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        if self.buffer.tell():
            return self.buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 29548
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// to container
template <class C>
void input(C &c)
{
    for_each(c.begin(), c.end(), [](auto &i) { cin >> i; });
}

// to number, string
template <class T>
T input()
{
    T data;
    cin >> data;
    return data;
}

int main()
{
    const ll MAX_N = 200001;
    ll N = input<ll>(), K = input<ll>();
    vector<ll> v(MAX_N, 0);
    set<ll> s;

    for (ll i = 0; i < N; i++)
    {
        ll a = input<ll>();
        s.insert(a);
        v[a]++;
    }

    sort(v.begin(), v.end());

    ll idx = 0;
    while (v[idx] == 0)
    {
        idx++;
    }

    ll res = 0;
    ll kind = s.size();

    while (true)
    {
        if (kind <= K)
        {
            break;
        }

        res += v[idx++];
        kind--;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 11136
// B - Picture Frame
#include <bits/stdc++.h>
using namespace std;

int N, M;
vector<string> s(100), t(100);
int solve();


int main() {
  //青
  cin >> N;
  for(int i =0; i< N; i++){
    cin >>s.at(i);
  }
  //赤
  cin >> M;
  for(int i =0; i< M; i++){
    cin >>t.at(i);
  }

  cout << solve() << endl;

}

int solve(){
  int max = 0;
  for(int i =0; i< N; i++){
    int point = 0;
    for(int j=0; j<N; j++){
      if(s.at(i) == s.at(j)){
        point++;
      }
    }
    for(int k = 0; k<M; k++){
      if(s.at(i) == t.at(k)){
        point--;
      }
    }
    if (max <point){
      max = point;
    }
  }
  return max;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 200000 + 10;
LL n, m;
int main() {
	cin >> n >> m;
	LL ans = n * m / 2;
	if (n%2==1 && m%2==1) ans ++;
	if (n == 1 || m == 1) ans = 1;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,x[100010],y[100010],a[100010],b[100010],Ysum=0,Xsum=0;
    ll X[100010],Y[100010],ans=0;
    cin>>n>>m;
    rep(i,n) cin>>x[i];
    rep(i,m) cin>>y[i];
    rep(i,n-1){
        a[i]=(i+1)*(n-1-i)%MOD;
        // cout<<a[i]<<endl;
    }
    rep(i,m-1){
        b[i]=(i+1)*(m-1-i)%MOD;
        // cout<<b[i]<<endl;
    }
    rep(i,n-1){
        X[i]=(x[i+1]-x[i])*a[i];
        X[i]%=MOD;
        Xsum+=X[i];
        // cout<<X[i]<<endl;
    }
    Xsum%=MOD;
    rep(i,m-1){
        Y[i]=(y[i+1]-y[i])*b[i];
        Y[i]%=MOD;
        Ysum+=Y[i];
        // cout<<Y[i]<<endl;
    }
    Ysum%=MOD;
    // cout<<endl;
    ans=Xsum*Ysum;
    ans%=MOD;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lb long double
#define pb push_back
#define qwerty1 first
#define qwerty2 second
#define qwerty3 -> first
#define qwerty4 -> second
#define umap unordered_map
#define uset unordered_set
#define pii pair < int , int >

using namespace std;

const int N = 100005;
const ll M = 1000000007;
const lb PI = acos(-1);

ll n;
ll dp[N][5][5][5][5];

bool inline ok(ll a , ll b , ll c , ll d)
{
    if(a == 1 && b == 3 && c == 2)
        return 0;

    if(a == 3 && b == 1 && c == 2)
        return 0;

    if(a == 1 && b == 2 && c == 3)
        return 0;


    if(b == 1 && c == 3 && d == 2)
        return 0;

    if(b == 3 && c == 1 && d == 2)
        return 0;

    if(b == 1 && c == 2 && d == 3)
        return 0;

    if(a == 1 && b == 4 && c == 3 && d == 2)
        return 0;

    if(a == 1 && b == 3 && c == 3 && d == 2)
        return 0;

    if(a == 1 && b == 2 && c == 3 && d == 2)
        return 0;

    if(a == 1 && b == 3 && c == 1 && d == 2)
        return 0;

    if(a == 1 && b == 3 && c == 4 && d == 2)
        return 0;
        
    return 1;
}

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

    ll i , a , b , c , d , j , ans = 0;

    cin >> n;

    if(n == 3)
    {
        cout << 61;
        return 0;
    }

      for(a = 1 ; a <= 4 ; a++)
        for(b = 1 ; b <= 4 ; b++)
            for(c = 1 ; c <= 4 ; c++)
                for(d = 1 ; d <= 4 ; d++)
                    if(ok(a , b , c , d))
                        dp[4][a][b][c][d] = 1;


    for(i = 5 ; i <= n ; i++)
        for(a = 1 ; a <= 4 ; a++)
            for(b = 1 ; b <= 4 ; b++)
                for(c = 1 ; c <= 4 ; c++)
                    for(d = 1 ; d <= 4 ; d++)
                        if(ok(a , b , c , d))
                            for(j = 1 ; j <= 4 ; j++)
                                if(ok(j , a , b , c))
                                    dp[i][a][b][c][d] = (dp[i][a][b][c][d] + dp[i - 1][j][a][b][c]) % M;

    for(a = 1 ; a <= 4 ; a++)
        for(b = 1 ; b <= 4 ; b++)
            for(c = 1 ; c <= 4 ; c++)
                for(d = 1 ; d <= 4 ; d++)
                    if(ok(a , b , c , d))
                        ans = (ans + dp[n][a][b][c][d]) % M;

    cout << ans;

    return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<string>

using namespace std;
using std::string;

int main() {
	string a, b;
	int count = 0;
	cin >> a >> b;

	
		if (a[0] == b[0]) {
			count++;
		}
		if (a[1] == b[1]) {
			count++;
		}
		if (a[2] == b[2]) {
			count++;
		}
	

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,b;
int keyn(int p){
	int sum=0,c=0;
	for(int i=2;i*i<=p;i++){
		if(p%i==0){
			sum+=i;c=i;
			while(p%i==0)p/=i;
		}
	}
	if(p>=2){
		sum+=p;c=p;
	}
	return c*2-sum;
}
int main(){
	int a,b;
	while(true){
		cin>>a>>b;
		if(a==0 && b==0)break;
		int v=keyn(a);
		int w=keyn(b);
		if(v>w)cout<<'a'<<endl;
		else cout<<'b'<<endl;
	}
}

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

#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FORD(i, b, a) for (int i = b; i >= a; --i)
#define FORE(i, v) for (__typeof (v.begin()) i = v.begin(); i != v.end(); ++i)
#define FORR(i, v) for (__typpeof (v.rbegin()) i = v.rbegin(); i != v.rend(); ++i)
#define sz(v) (int) v.size()
#define all(v) v.begin(), v.end()
#define sqr(x) 1ll * (x) * (x)
#define EPS 1e-9

template <class T> int getBit(T x, int k) { return x >> k & 1; }
template <class T> T onBit(T x, int k) { return x  (T(1) << k); }
template <class T> T offBit(T x, int k) { return x & (~(T(1) << k)); }

const int N = 1e5 + 10;

int n, answer;
int a[N];

void load() {
  scanf("%d", &n);
  FOR(i, 1, n) scanf("%d", a + i);
}

void process() {
  for (int i = 1; i <= n;) {
    if (a[i] == i) {
      answer++;
      if (a[i + 1] == i + 1) {
        i++;
      }
    }
    i++;
  }
  printf("%d\n", answer);
}

int main() {
 // freopen("input.in", "r", stdin);
//  freopen("output.out", "w", stdout);

  load();
  process();

  return 0;
}


Measured memory_bytes: 640
import java.util.*

fun main(args: Array<String>) = yorukatsu15b()

fun yorukatsu15b() {
    val s = readLine()!!

    val deque = ArrayDeque<Char>()

    var answer = 0

    for (c in s) {
        if (deque.isNotEmpty() && deque.peek() != c) {
            deque.poll()
            answer++
        } else {
            deque.addLast(c)
        }
    }

    answer *= 2

    println(answer)
}


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

namespace AtCoder.Abc
{
    class A_166_A_C
    {
        // https://atcoder.jp/contests/abc166/tasks/abc166_a
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();
            if (s == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("ABC");
            }

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 25664