akhauriyash/Code-Regression huggingface dataset:
MOD = 10 ** 9 + 7
N = gets.to_i
S = 2.times.map{ '_' + gets.chomp }
def S.vertical?(i); self[0][i] == self[1][i]; end

s0 = S.vertical?(1) ? [:X, 3] : [:Y1, 6]
ans = (2 .. N).inject(s0) do |s,i|
  t, c = *s
  next [:Y2, c] if t == :Y1
  if S.vertical?(i)
    next [:X , c * 2 % MOD] if t == :X
    next [:X , c          ] if t == :Y2
  else
    next [:Y1, c * 2 % MOD] if t == :X
    next [:Y1, c * 3 % MOD] if t == :Y2
  end
end
puts ans[1]

Measured memory_bytes: 14304
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr int mo2 = 998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin>>n;
    vector<int> l(n);
    for(auto &a : l) cin>>a;
    sort(l.begin(),l.end());
    int ans = 0;
    for(int i=n-1;i>0;--i){
        for(int j=i-1;j>=0;--j){
            auto it = lower_bound(l.begin(),l.end(),l[i]+l[j]);
            int no = distance(it,l.end());
            ans += n-1 - i - no;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
int main()
{
	string s,t;
	cin>>s>>t;
	ll ans=t.length();
	ll a=s.length(),b=t.length();
	for(ll i=0;i<=a-b;i++){
		string p=s.substr(i,b);
		ll u=0;
		for(ll j=0;j<b;j++){
			if(t[j]!=p[j]) u++;
		}
		ans=min(ans,u);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3604
import math
import statistics
N = int(input())
L = [i for i in map(int,input().split())]
Q = []
for i in range(len(L)):
  Q.append(L[i] - (i+1))
b = statistics.median(Q)
a = b - 1
c = b + 1
res = 0
res2 = 0
res3 = 0
for i in range(N):
  res += abs(L[i] - (i+1) - b)
  res2 += abs(L[i] - (i+1) - a)
  res3 += abs(L[i] - (i+1) - c)
print(int(min(res,res2,res3)))

Measured memory_bytes: 27232
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n;
    cin >> n;
    vector<int> x;
    rep(i, n){ int tmp; cin >> tmp; x.push_back(tmp);}

    ll sum_x = 0;
    ll sum_xx = 0;
    rep(i, n){
        sum_x += x[i];
        sum_xx += x[i] * x[i];
    }

    ll ans = MOD;
    
    rep(p, 100){
        ll cal = sum_xx + (p+1)*(p+1)*n -2*(p+1)*sum_x;  
        ans = min(ans, cal);
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
li = list(map(int,input().split()))
s=list(input())
cnt = 0
b = 0
for i in s:
    if i == "a":
        if cnt < li[1] + li[2]:
            cnt += 1
            print("Yes")
        else:
            print("No")
    elif i == "b":
        b += 1
        if cnt < li[1] + li[2]:
            if b <= li[2]:
                cnt += 1
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    else:
        #cnt -= 1
        print("No")
#print(a)

Measured memory_bytes: 4712
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
    /*int d, t, s; cin >> d >> t >> s;
    if (d <= t * s) cout << "Yes" << endl;
    else cout << "No" << endl;
    */

    string s, t; cin >> s >> t;
    int mx = 0;
    rep(i, s.size()) {
        int tmp = 0;
        if (s.size() < i + t.size()) continue;
        rep(j, t.size()) {
            if (s[i + j] == t[j]) tmp++;
        }
        mx = max(mx, tmp);
    }
    cout << t.size() - mx << endl;


    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

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

		int r = sc.nextInt();
		int c = sc.nextInt();

		int[] rsum = new int[r];
		int[] csum = new int[c];
		int fsum = 0;

		for (int k = 0; k < r; k++) {
			for (int i = 0; i < c; i++) {
				int now_cell = sc.nextInt();
				rsum[k] = rsum[k] + now_cell;
				System.out.print(now_cell + " ");
				csum[i] = csum[i] + now_cell;
			}
			System.out.println(rsum[k]);
			fsum = fsum + rsum[k];

		}
		for (int j = 0; j < c; j++) {
			System.out.print(csum[j] + " ");
		}
		System.out.println(fsum);

	}

}



Measured memory_bytes: 40664
def calculate_num(m, n):
  integer = m
  base = n
  result = ''
  digit = 0
  while integer > 0:
    result += str(integer%base)
    integer = integer//base
    digit = len(result)
  return digit

def main():
  num = input()
  num_list = num.split()
  number = int(num_list[0])
  base = int(num_list[1])
  result = calculate_num(number, base)
  print(result)
main()

Measured memory_bytes: 3060
#include <cstdio>

int main() {
    //入力
    int a,b;
    std::scanf("%d %d",&a,&b);

    if(a < b) {
        std::printf("a < b");
    }
    else if(a > b) {
        std::printf("a > b");
    }
    else if(a == b){
        std::printf("a == b");
    }
    
    std::printf("\n");

    return 0;
}


Measured memory_bytes: 2680
import java.util.*;

public class Main {
	
	int INF = 1 << 24;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
			for(int i=0; i < n; i++){
				list.add(new ArrayList<Integer>());
				int m = sc.nextInt();
				for(int j=0; j < m;j++){
					list.get(i).add(sc.nextInt());
				}
				
			}
			int k = sc.nextInt();
			ArrayList<Integer> klist = new ArrayList<Integer>();
			for(int i=0; i < k; i++){
				klist.add(sc.nextInt());
			}
			
			int ind = -1;
			for(int i = 0; i < n; i++){
				boolean flg = false;
				for(int j = 0; j < k; j++){
					int num = klist.get(j);
					if(! list.get(i).contains(num)){
						flg = true;
						break;
					}
				}
				if(! flg){
					if(ind != -1){
						ind = -1;
						break;
					}
					else{
						ind = i + 1;
					}
				}
			}
			System.out.println(ind);
		}
		
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int A, B, C; cin >> A >> B >> C;
        cout << (A + B + C >= 22 ? "bust" : "win") << endl;
        return 0;
    }
};

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


Measured memory_bytes: 256
S = input()

left = -1

for i,s in enumerate(S):
    if s == 'A':
        left = i
        break

right = len(S)+1
for i in range(len(S)-1, -1, -1):
    if S[i] == 'Z':
        right = i
        break

if left < right:
    print(right-left+1)

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

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

    ll N;
    cin >> N;
    vll a(N-1), b(N-1), c(N);
    rep(i, N){
        cin >> c[i];
        --c[i];
    }
    rep(i, N-1) cin >> a[i] >> b[i];
    vector<unordered_set<ll>> e(N);
    rep(i, N-1){
        e[a[i]-1].insert(b[i]-1);
        e[b[i]-1].insert(a[i]-1);
    }

    vll t(N, 0), cnt(N, 0);

    function<ll(ll, ll)> dfs = [&](ll cur, ll prev){
        ll count = 1;
        ll color = c[cur];
        ll tmp = cnt[color];
        for(ll next : e[cur]){
            if(next==prev) continue;
            ll bfr = cnt[color];
            ll num = dfs(next, cur);
            count += num;
            ll aftr = cnt[color];
            ll sub = aftr - bfr;
            ll diff = num - sub;
            t[color] += diff*(diff+1)/2;
        }
        cnt[color] = tmp + count;
        return count;
    };
    dfs(0, -1);

    ll w = N*(N+1)/2;
    rep(i, N){
        ll r = N - cnt[i];
        ll a = t[i] + r*(r+1)/2;
        cout << (w-a) << endl;
    }
}


Measured memory_bytes: 65748
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

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

int main() {
  int N;
  long K;
  std::cin >> N >> K;
  /*std::vector<int> a(N), b(N);
  for (long i=0; i<N; i++) {
    std::cin >> a.at(i) >> b.at(i);
  }*/
  map<int,long> m;
  for (int i=0; i<N; i++) {
    int ai, ki;
    cin >> ai >> ki;
    m[ai] += ki;
  }
  
  /*for (auto it=m.begin(); it!=m.end(); it++) {
    cerr << it->first << ' ' << it->second << endl;
  }*/
  
  long count = 0;  
  for (auto it=m.begin(); it!=m.end(); it++) {
    count += it->second;
    //cerr << it->first << endl;
    if (count>=K) {
      cout << it->first << endl;
      break;
    }
  }
  return 0;
}

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

int main(){
  int N,x;
  cin >> N;
  vector<int> A(N,0);
  for(int i=0;i<N;i++){
    cin >> x;
    A.at(x-1) = i+1;
  }
  for(int i=0;i<N;i++){
    cout << A.at(i) << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
    template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
    template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
    template<typename T> void chadd(T& a, T b) { a = a + b; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
    };

    // 2次元用の標準入出力
    template<typename T>
    struct inpn {
        std::size_t szi, szj;
        inpn(std::size_t _szi, std::size_t _szj) : szi(_szi), szj(_szj) {}
        operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i)
                for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j];
            return a;
        }
    };

    inp inp1; // input one

    ll powll(ll a, ll n) {
        ll result = 1;
        ll base = a;
        ll mask = 1;
        while (mask <= n) {
            if (n & mask) result *= base;
            mask <<= 1;
            base *= base;
        }
        return result;
    }
}

int main() {

    ll a, b;
    cin >> a >> b;

    // nが偶数の場合， n ^ (n + 1) = 1となる
    // これを利用する

    ll ans = 0LL;

    if (a % 2 == 1) {
        if (b % 2 == 1) {
            ans = (((b - a) / 2) % 2) ^ a;
        }
        else {
            ans = ((b - a - 1) / 2 % 2) ^ a ^ b;
        }
    }
    else {
        if (b % 2 == 1) {
            ans = ((b - a + 1) / 2) % 2;
        }
        else {
            ans = (((b - a) / 2) % 2) ^ b;
        }
    }

    Cout(ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int, int> pii;
 
void solve() {
	int n;
	cin >> n;
	int mult = ceil(n / 111.0);
	int ans = mult * 111;
	cout << ans;
}
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifdef LOCAL
		ifstream in("in");
		cin.rdbuf(in.rdbuf());
	#endif
	solve();
}

Measured memory_bytes: 256
m=998244353
def c(n,r):return (g[n]*h[r]*h[n-r])%m
g=[1,1]
h=g[:]
v=[0,1]
for i in range(2,999999):
  g.append((g[-1]*i)%m)
  v.append((-v[m%i]*(m//i))%m)
  h.append((h[-1]*v[i])%m)
N,K=map(int,input().split())
P=0
for k in range(N-1,K):P+=c(K-1,k)
print(P%m)

Measured memory_bytes: 212788
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	
bool pairComparesecond(const p& firstElof, const p& secondElof)
{
    return firstElof.second > secondElof.second;
}
 
int main(){
	double a,b;
	cin>>a>>b;
	cout<<a/b<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <deque>
#include <vector>
using namespace std;


int main(){
  int n, m, a, b;
  string str;
  int c[10][10];
  cin >> n >> a >> b;
  int i, j, k;
  int ans;


  cout << min(n*a,b) << endl;
  // cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const int MaxN = 1e5;
typedef long long LL;

int n;
LL a[3 * MaxN + 5];
LL ans;
int cmp(LL x, LL y){return x > y;}
int main()
{
	while(scanf("%d", &n) != EOF)
	{
		ans = 0;
		for(int i = 1; i <= 3 * n; i++) scanf("%lld", &a[i]);
		sort(a + 1, a + 3 * n + 1, cmp);
		for(int i = 2; i <= 2 * n; i += 2)
			ans += a[i];
		printf("%lld\n", ans);
		memset(a, 0, sizeof(a));
	}
}

Measured memory_bytes: 2560
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int[] x = new int[3];
			for (int i = 0; i < 3; i++) {
				x[i] = sc.nextInt();
			}
			Arrays.sort(x);

			System.out.println(x[0] + x[1]);
		}
	}
}

Measured memory_bytes: 24276
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try(Scanner scn = new Scanner(System.in)) {
            while(scn.hasNextInt()) {
                int a = scn.nextInt(), b = scn.nextInt();
                System.out.println(euclid(Math.max(a, b), Math.min(a, b)));
            }
        }
    }

    private static int euclid(int a, int b) {
        return a % b == 0 ? b : euclid(b, a % b);
    }
}

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

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N, L;
    cin >> N >> L;

    vector<int> a;
    REP(i,N){
        a.emplace_back(L+i);
    }

    int acm = accumulate(ALL(a),0);

    int tmp = 10000;

    REP(i,N){
        if (abs(a[i]) < abs(tmp)) {
            // cout << tmp << " " << abs(a[i]) << " " << a[i] << endl;
            tmp = a[i];
        }
    }

    cout << acm - tmp << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        String S = scanner.next();
        ArrayList<Integer> r = new ArrayList<>();
        ArrayList<Integer> g = new ArrayList<>();
        HashSet<Integer> b = new HashSet<>();
        
        for(int i=0; i<N; i++){
            if(S.charAt(i) == 'R'){
                r.add(i+1);
            }else if(S.charAt(i)=='G'){
                g.add(i+1);
            }else{
                b.add(i+1);
            }
        }
        long sum = 0;
        int sizeb = b.size();
        for(Integer i :r){
            for(Integer j:g){
                sum += sizeb;
                if(b.contains(2*j-i)){
                    sum -= 1;
                }
                if(b.contains(2*i-j)){
                    sum -= 1;
                }
                if((i+j)%2==0){
                    if(b.contains((i+j)/2)){
                        sum -=1;
                    }
                }
            }
        }
        System.out.println(sum);
    }

}

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

         
                    
using namespace std;
                     
#define rep(i,a,b); for(long int i=a;i<b;i++)
#define mk make_pair        
#define LIMIT 100007
#define MOD 1000000007
#define ll long long int
#define endl '\n'
#define min3(a,b,c) ((a>b)?((b>c?c:b):(a>c?c:a)))
#define max3(a,b,c) ((a<b)?((b<c?c:b):(a<c?c:a)))
#define min(a,b) (a>b?b:a)
// #define x.first x.f
// #define x.second x.s
#define max(a,b) (a<b?b:a)
#define pb push_back
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int main() 
{ 
    FAST
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	ll n;
	cin>>n;
	ll a[n][3];
	vector<pair<ll,int>> v;
	rep(i,0,n) cin>>a[i][0]>>a[i][1]>>a[i][2];
	v.pb({a[0][0],0});
	v.pb({a[0][1],1});
	v.pb({a[0][2],2});

	rep(i,1,n)
	{
		sort(v.begin(),v.end());
		ll x=v[2].first, j=v[2].second;
		ll y=v[1].first;
		v.clear();
		rep(t,0,3)
		{
			if(t!=j) v.pb({x+a[i][t],t});
			else v.pb({y+a[i][t],t});
		}

	}

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

	cout<<v[2].first;


    return 0; 
}  


Measured memory_bytes: 2560
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	m := getNextInt(scanner)
	xx := make([]int64, n)
	yy := make([]int64, m)
	for i := 0; i < n; i++ {
		xx[i] = getNextInt64(scanner)
	}

	for i := 0; i < m; i++ {
		yy[i] = getNextInt64(scanner)
	}

	var ans, unitx, mod int64
	mod = int64(1e9 + 7)

	for i := 0; i < n-1; i++ {
		unitx += int64(i+1) * int64(n-(i+1)) * (xx[i+1] - xx[i])
		unitx %= mod
	}

	for i := 0; i < m-1; i++ {
		ans += (int64(i+1) * int64(m-(i+1)) * (yy[i+1] - yy[i]) % mod) * unitx
		ans %= mod
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 6144
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}

int main(){
  int N;
  string S;
  cin>>N>>S;

  int ans = 0;
  for(int i=1; i<N; ++i){
  int cnt=0;
    for(char c='a';c<='z'; c++){
    bool left = false, right =false;

    for(int j=0;j<i;j++)
    if(S[j]==c)left = true;
    for(int j=i;j<N;j++)
    if(S[j]==c)right = true;

    if(left&&right)
    cnt++;
}
  if(ans<cnt)
  ans=cnt;
  }
  cout<<ans<<endl;
}









Measured memory_bytes: 256
import java.util.*;

class Main {

    static Scanner input = new Scanner(System.in);
    public static void main(String[] args) {
        int n = 10;
        PriorityQueue<Integer> pq = new PriorityQueue<>((a,b) -> (b - a));

        for (int i = 0; i < n; i ++) {
            int x = input.nextInt();
            pq.add(x);
        }

        input.close();
        for (int i = n-1; i > 6; i--) {
            System.out.println(pq.poll());
        }
    }
}


Measured memory_bytes: 31556
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long x;
  cin >> x;
  long long s = x / 11;
  long long t = x % 11;
  if (t > 6) {
	cout << 2 *s + 2 << endl;
	return 0;
  }
  if (t > 0) {
	cout << 2*s + 1 << endl;
	return 0;
  }
  cout << 2*s << endl;
  return 0;
}



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

using namespace std;

int main(void) {
     int a, b;
     cin >> a >> b;
     string s;
     cin >> s;

     if(a+b+1 != s.size()) {
        cout << "No" << endl;
        return 0;
     }

     int i = 0;
     for(; i < a; i++) {
        if(! isdigit(s[i])) {
            cout << "No" << endl;
            return 0;
        }
     }

     if(s[i] != '-') {
        cout << "No" << endl;
        return 0;
     }

     for(i++; i < a+b+1; i++) {
        if(! isdigit(s[i])) {
            cout << "No" << endl;
            return 0;
        }
     }

     cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2*10**5+100)
from bisect import *

def dfs(v, pv):
    j = bisect_left(dp, a[v])
    prev = dp[j]
    dp[j] = a[v]
    ans[v] = bisect_left(dp, 10**18)-1
    
    for nv in G[v]:
        if nv==pv:
            continue
        
        dfs(nv, v)
    
    dp[j] = prev

N = int(input())
a = list(map(int, input().split()))
G = [[] for _ in range(N)]

for _ in range(N-1):
    u, v = map(int, input().split())
    G[u-1].append(v-1)
    G[v-1].append(u-1)

dp = [10**18]*(N+1)
dp[0] = -10**18
ans = [-1]*N
dfs(0, -1)

for ans_i in ans:
    print(ans_i)

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define pb push_back

int main()
{
    ll N;
    cin >> N;
    vec A(N);
    map<ll,ll> C;
    REP(i,0,N) {
        cin >> A[i];
        ++C[A[i]];
    }

    ll sum = 0, cnt;
    FORR(c,C) sum += c.second * (c.second - 1) / 2;
    REP(i,0,N) {
        cnt = sum - (C[A[i]] - 1);
        PR(cnt);
    }

    return 0;
}

/*

nC2 - (n-1)C2 = n(n-1)/2 - (n-1)(n-2)/2 = n-1

*/

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

int main(){
	int n,k;
	cin >> n >> k;
	
	int ans = 1;
	rep(i,n){
		ans = min(ans*2,ans+k);
	}
	
	cout << ans << endl;
}



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

int main()
{
  long N;
  cin >> N;

  if (N / 10 % 111 == 0 || N % 1000 % 111 == 0)
  {
    cout << "Yes" << endl;
  }

  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;

long long int gcd(long long int x, long long int y)
{
    long long int a = x;
    long long int b = y;
    long long int r = a%b;
    while(r!=0)
    {
        a = b;
        b = r;
        r = a%b;
    }
    return b;
}

long long int lcm(long long int x, long long int y)
{
    return x*y/gcd(x, y);
}

int main()
{
    long long int A, B;
    long long int C, D;
    cin >> A >> B >> C >> D;
    long long int E = max(C, D);
    long long int F = min(C, D);
    long long int l = lcm(E, F);
    long long int ans = (B - B/C - B/D + B/l) - ((A-1) - (A-1)/C - (A-1)/D + (A-1)/l);

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define     __        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define     pi        acos(-1)
#define     ll        long long int
#define     fopen     freopen("in.txt","r",stdin)
#define     fwrite    freopen("o.txt","w",stdout)
#define     f0(n)     for(int i=0;i<n;i++)
#define     mem(a)    memset(a,0,sizeof(a))
#define     mems(a)   memset(a,-1,sizeof(a))

int main()
{
    __
    //fopen;
    //fwrite;
        int n,m,p,y;
    cin>>n>>m;
    vector<int>v[n+1];
    int a[m],b[m];
    set<int>sset;
    f0(m){
        cin>>p>>y;
        a[i]=p,b[i]=y;
        v[p].push_back(y);
        sset.insert(p);
    }
    for(set<int>:: iterator i=sset.begin();i!=sset.end();i++)
    {
        int p=*i;
        sort(v[p].begin(),v[p].end());
    }
   for(int i=0;i<m;i++)
   {
       stringstream ss;
       ss<<a[i];
       string s=ss.str();
       for(int j=0;j<(6-s.size());j++) cout<<0;
       cout<<s;
       int l=lower_bound(v[a[i]].begin(),v[a[i]].end(),b[i])-v[a[i]].begin();
       l+=1;
       stringstream sd;
       sd<<l;
       string s1=sd.str();
       for(int j=0;j<(6-s1.size());j++) cout<<0;
       cout<<s1<<endl;
   }
    return 0;
}



Measured memory_bytes: 13952
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] A = Array.ConvertAll(Console.ReadLine().Trim().Split(' '), int.Parse);
            int q = int.Parse(Console.ReadLine());
            int[] m = Array.ConvertAll(Console.ReadLine().Trim().Split(' '), int.Parse);

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < q; i++)
            {
                sb.AppendLine(SearchSum(A, n, m[i]) ? "yes" : "no");
            }
            Console.Write(sb);
        }

        static bool SearchSum(int[] A, int n, int m)
        {
            if (m == 0) return true;
            if (n == 0) return false;

            return SearchSum(A, n - 1, m) || SearchSum(A, n - 1, m - A[n - 1]);
        }
    }
}

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

int main(){
  int L,A,B,C,D;
 
  cin>>L>>A>>B>>C>>D;
  
  int day=1;
  while(1){
    if(A<=C*day&&B<=D*day)break;
    day++;
  }

  cout<<L-day<<endl;
 return 0;
}

Measured memory_bytes: 1160
import itertools
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

l = [a,b,c,d,e]

ok = True
for s,t in itertools.combinations(l,2):
	if abs(s-t) > k:
		ok = False

if ok:
	print('Yay!')
else:
	print(":(")




Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int i = 0;
		int[] res = new int[30];
		Scanner sc = new Scanner(System.in);

		while (true) {
			String line = sc.next();
			int a = Integer.parseInt(line);
			line = sc.next();
			String ope = line;
			line = sc.next();
			int b = Integer.parseInt(line);

			if (ope.contentEquals("?")) {
				break;
			} else {
				switch (ope) {
				case "+":
					res[i] = a + b;
					break;
				case "-":
					res[i] = a - b;
					break;
				case "*":
					res[i] = a * b;
					break;
				case "/":
					res[i] = a / b;
					break;
				}
				i++;
			}
		}

		for (int j = 0; j < i; j++) {
			System.out.println(res[j]);
		}
	}

}


Measured memory_bytes: 26092
X, K, D = map(int, input().split())
if X < 0:
  X = -X
a = X // D
b = X % D
#回数が足りない場合
if a > K:
  print(X - (K * D))
#回数が足りる場合
else:
  if (K - a) % 2 == 1:
    print(abs(b - D))
  else:
    print(b)
  
  

Measured memory_bytes: 61816
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()

val = [1]
temp = 1
while 1:
    temp *= 6
    if temp<=10**5:
        val.append(temp)
    else:
        break

temp = 1
while 1:
    temp *= 9
    if temp<=10**5:
        val.append(temp)
    else:
        break

val.sort(reverse=True)

def rec(price,i):
    if i==len(val)-1:
        return price
    else:
        q,m = divmod(price,val[i])
        if m==0:
            return q
        else:
            if q>=9:
                return float('inf')
            else:
                x = []
                for j in range(q+1):
                    x.append(rec(price-j*val[i],i+1) + j)
                return min(x)

print(rec(N,0))

Measured memory_bytes: 50012
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int main()
{
	int r, g, b;
	cin >> r >> g >> b;

	if ( (100 * r + 10 * g + b) % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
n = int(input())
sp = [input().split() for _ in range(n)]

for i in range(n):
    sp[i][1] = int(sp[i][1])
    sp[i] = sp[i]+[i+1]
    
sp_s0 = sorted(sp, key=lambda x:(x[0], -x[1]), reverse=False)

for i in range(n):
    print(sp_s0[i][2])

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

int main() {
    int n; cin >> n;
    vector<long long> a;
    vector<long long> pairA;
    for(int i = 0; i < n; i++) {
        long long inp; cin >> inp;
        a.push_back(inp);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    for(int i = 0; i < n; i++) {
        if(a[i] == a[i+1]) {
            pairA.push_back(a[i]);
            i++;
        }
    }

    if(pairA.size() < 2) {
        cout << 0 << endl;
    } else {
        cout << pairA[0] * pairA[1] << endl;
    }
}


Measured memory_bytes: 2032
//#include    <bits/stdc++.h>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <cassert>
#include <iterator>
#include <complex>
#define N  10
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f
template<typename T> inline T max(T a,T b,T c){
    return max(a,max(b,c));
}
template<typename T> inline T min(T a,T b,T c){
    return min(a,min(b,c));
}
template<typename T> inline T max(T a,T b,T c,T d){
    return max(a,max(b,c,d));
}
template<typename T> inline T min(T a,T b,T c,T d){
    return min(a,min(b,c,d));
}
const int  dx[]={0,1,0,-1,0,1,-1,1,-1};
const int  dy[]={0,0,1,0,-1,1,-1,-1,1};
const int MOD=1000000007;
typedef long long ll;
using namespace std;
char a[N][N];
int main(){
    IOS;
   for (int i=0;i<3;i++)
      for (int j=0;j<3;j++)
         cin>>a[i][j];
   for (int i=0;i<3;i++)
      for (int j=0;j<3;j++)
         if (i==j)
            cout << a[i][j];
            cout << endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long ans = 0;
    string s;
    cin >> s;
    vector <char> v;
    
    for(int i = 0; i < (int)s.size(); i++){
        if(s[i] == 'B' && s[i+1] == 'C' && i + 1 < (int)s.size()){
            v.push_back('D');
            i++;
            continue;
        }
        v.push_back(s[i]);
        
    }
    
    int size = (int)v.size();
    for(int i = 0; i < size; i++){
        if(v[i]=='B' || v[i] == 'C'){
            int last = i-1;
            int j = i-1;
            while(v[j]!='C' && v[j] != 'B' && j >= 0){
                if(v[j]=='A'){
                    ans += last-j;
                    last--;
                }
                j--;
            }
        }
        
        if(i==size-1 && (v[i]!='B' && v[i] != 'C')){
            int last = i;
            int j = i;
            while(v[j]!='C' && v[j] != 'B' && j >= 0){
                if(v[j]=='A'){
                    ans += last-j;
                    //cout << last << " " << j << '\n';
                    last--;
                }
                j--;
            }
        }
    }
    // int cnt = 0;
    // for(int i = (int)v.size(); i >= 0; i--){
    //     if(v[i]=='A'){
    //         ans+=cnt;
    //     }
    //     else if(v[i]=='D'){
    //         cnt++;
    //     }
    //     else{
    //         cnt=0;
    //     }
    // }
    cout << ans << '\n';
}

Measured memory_bytes: 772
#include <stdio.h>
#include <algorithm>
#include <utility>
using namespace std;

int main(void) {
  int i, n, t;
  scanf("%d%d", &n, &t);
  pair<int, int> p[n];
  for(i = 0; i < n; ++i) scanf("%d%d", &p[i].first, &p[i].second);
  sort(p, p + n);
  for(i = 0; i < n; ++i) if(p[i].second <= t) {
    printf("%d", p[i].first);
    return 0;
  }
  printf("TLE");
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <functional>
#include <math.h>
#include <map>
#include <set>
#include <string>
using namespace std;
#define fio ios::sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;

const int INT_INF = 1e9;
const ll LL_INF = 1e18;
const int MAXN = 500003;

typedef struct GE{
	int to;
	ll w;
	GE(){};
}GE;

int n, m;
int A[MAXN];
int main() {
	scanf("%d", &n);

	ll cnt2=0;
	for(int i=0;i<n;i++){
		scanf("%d", &A[i]);
		int x = A[i];
		while(x%2==0){
			x/=2;
			cnt2++;
		}
	}

	printf("%lld", cnt2);
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
t = 0

flag = 1
while(flag):
    flag = 0
    for i in range(n - 1, 0, -1):
        if a[i] < a[i - 1]:
            a[i], a[i - 1] = a[i - 1], a[i]
            flag = 1
            t += 1

print(' '.join(map(str, a)))
print(t)


Measured memory_bytes: 5600
#include <stdio.h>

int main(){
  int a,x;
  int n;
  int l[100];
  int i;
  scanf("%d %d",&x,&a);
  //for(i=0;i<n;i++)scanf("%d", &l[i]);

  if(x<a)printf("0\n");
  else printf("10\n");


  return 0;
}


Measured memory_bytes: 128
from decimal import *
getcontext().prec = 20      # デフォルト28桁のところを20桁にする
def sq(n):
    m = Decimal(n).sqrt()
    return m

import math
a, b, c = list(map(int, input().split()))
# def sq(a):
#     aa = math.sqrt(a)
#     return aa
if (sq(a) + sq(b)) < sq(c):
    print("Yes")
else:
    print("No")

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

int main(void){
    int n, a, count = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a;
        if(a == 2) count++;
        if((a < 2) || !(a & 1)) continue;
        bool isprime = true;
        for(int j = 3; j <= sqrt(a); j += 2){
            if((a % j) == 0) isprime = false;
        }
        if(isprime) count++;
    }
    cout << count << endl;
    return 0;
}


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

const int N = 500005;
string w, wRev;
long long int forwardPeriod[N];
long long int reversePeriod[N];

vector<int> buildZFunction(string s) {
	int n = s.length();
	vector<int> z(n);
	z[0] = n;
	for(int i = 1, l = 0, r = 0; i < n; i++) {
		z[i] = (i < r)? min(z[i-l], r-i):0;
		while(i + z[i] < n && s[z[i]] == s[i+z[i]]) z[i]++;
		if(i+z[i]>r) l = i, r = i+z[i];
	}
	return z;
}

int main() {
	cin >> w;
	wRev = "";
	for(int i = w.length()-1; i >= 0; i--) wRev += w[i];
	vector<int> z = buildZFunction(w);
	vector<int> zRev = buildZFunction(wRev);
	
	int period = 0;
	for(int i = 1; i < w.length(); i++) {
		if(i + z[i] == w.length()) {
			period = i; break;
		}
	}
	if(period == 0) period = w.length();
	
	if(period == 1) {
		cout << w.length() << endl << 1 << endl;
	} else if(w.length() == period || w.length() % period) {
		cout << 1 << endl << 1 << endl;
	} else {
		forwardPeriod[1] = 1;
		for(int i = 2; i < w.length(); i++) {
			for(int j = forwardPeriod[i-1]; j <= i; j++) {
				if(j + z[j] >= i) {
					forwardPeriod[i] = j; break;
				}
			}
		}
		
		reversePeriod[1] = 1;
		for(int i = 2; i < w.length(); i++) {
			for(int j = reversePeriod[i-1]; j <= i; j++) {
				if(j + zRev[j] >= i) {
					reversePeriod[i] = j; break;
				}
			}
		}
		
		int ans = 0;
		for(int i = 1; i < w.length(); i++) {
			if((i % forwardPeriod[i] != 0 || i == forwardPeriod[i]) && ((w.length()-i) % reversePeriod[w.length()-i] != 0 || w.length()-i == reversePeriod[w.length()-i])) ans++;
		}
		cout << 2 << endl << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 13468
n = gets.chomp.to_i
count = 0
words = {}
max = 1
while(true)
    s = gets.chomp
    if words.has_key?(s)
        words[s] += 1
        if max < words[s]
            max = words[s]
        end
    else
        words[s] = 1
    end
    count += 1
    if count == n
        break
    end
end
words.select! {|k,v| v == max}
words2 = words.sort
words2.each do |v|
    print v[0] + "\n"
end

Measured memory_bytes: 58276
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[114514];
signed main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++){
		if(a[i]%2==1){
			puts("first");
			return 0;
		}
	}
	puts("second");
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return [LIST() for _ in range(n)]

def main():
    H, W, K = MAP()
    HH = max(H, W) + 2
    x1, y1, x2, y2 = LIST()
    c = [[-1] + [0 if c == "." else -1 for c in input()] + [-1]
         for i in range(H)]
    c = [[-1] * (W + 2)] + c + [[-1] * (W + 2)]

    # 0123: 上下左右
    stack = deque([(x1, y1, 0), (x1, y1, 1),
                   (x1, y1, 2), (x1, y1, 3)])
    append, popleft = stack.append, stack.popleft
    DX = (1, 0, -1, 0)
    DY = (0, 1, 0, -1)
    while stack:
        x, y, d = popleft()
        flag = True
        a = c[x][y] + 1
        for k in range(1, K + 1):
            xx, yy = x + k * DX[d], y + k * DY[d]
            if c[xx][yy] == 0:
                b = c[xx + DX[(d - 1) % 4]][yy + DY[(d - 1) % 4]]
                if b == 0 or b == a + 1:
                    append((xx, yy, (d - 1) % 4))
                b = c[xx + DX[(d + 1) % 4]][yy + DY[(d + 1) % 4]]
                if b == 0 or b == a + 1:
                    append((xx, yy, (d + 1) % 4))
                c[xx][yy] = a
            elif c[xx][yy] != a:
                flag = False
                break
        if flag:
            append((xx, yy, d))
        if c[x2][y2] > 0:
            print(c[x2][y2])
            return

    print(-1)
    return


if __name__ == '__main__':
    main()


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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  arr(a,n);

  vecb ok(n, false);
  rep(i,n){
    if(a[i]==i+1) ok[i]=true;
  }

  ll ans=0;
  rep(i,n){
    if(ok[i]){
      ans++;
      if(i!=n-1){
        ok[i]=false;
        ok[i+1]=false;
      }
    }
  }

  prt(ans);
}


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

#define MAX 1000000007

char nodetype[1000];	//?????????i???????????? E:?????? R:or A:alt
bool option[1000];	//?????????i??????????????§?????????true
int childN[1000];
int child[1000][10];

long long tansaku(int x){	//?????????x??\??????????????????????????????????????°?????????
	long long ans=0;
	if(option[x]) ans++;

	long long tmp;
	if(nodetype[x]=='A'){	//alt??????????????????
		tmp = 0;
		for(int i=0;i<childN[x];i++){
			tmp = (tmp + tansaku(child[x][i])) % MAX;
		}
	}else if(nodetype[x]=='R'){	//or??????????????????
		tmp=1;
		for(int i=0;i<childN[x];i++){
			tmp = (tmp * (tansaku(child[x][i])+1)) % MAX;
		}
		tmp--;
	}else if(nodetype[x]=='E'){	//???????????????
		tmp = 1;
		for(int i=0;i<childN[x];i++){
			tmp = (tmp * tansaku(child[x][i])) % MAX;
		}
	}

	ans = (ans + tmp + MAX) % MAX;
	return ans;
}

int main(){
	int n,i;
	char node[3];
	int s,t;

	cin>>n;
	for(i=0;i<n;i++){
		cin>>node;
		nodetype[i] = node[0];
		option[i] = (node[1]=='?');
		childN[i] = 0;
	}
	for(i=0;i<n-1;i++){
		cin>>s>>t;
		s--;t--;
		child[s][childN[s]++] = t;
	}

	cout<<tansaku(0)<<endl;

	return 0;
}

Measured memory_bytes: 1264
n=int(input())
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
clist = list(map(int, input().split()))

mzoku=0
before=999

for al in alist:
    mzoku+=blist[al-1]
    if before==al-1:
        mzoku+=clist[before-1]
    before=al

print(mzoku)

Measured memory_bytes: 3060
#include <stdio.h>
typedef long long int lld;
typedef long long int llu;

llu m[10000];

llu f(llu n) {
  if (m[n]) {
    return m[n];
  }
  llu r = n <= 1 ? 1 : f(n - 1) + f(n - 2);
  m[n] = r;
  return r;
}

int main(void) {
  llu n;
  scanf("%llu", &n);
  printf("%llu\n", f(n));
}


Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

int div_up(int a, int b)
{
    return (a + b - 1) / b;
}

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

    int n, q, a[112345], x[112345];
    ll sum[112345], sum1[112345];

    cin >> n >> q;
    REP(i, n)
    cin >> a[i];
    REP(i, q)
    cin >> x[i];

    sum[0] = 0;
    REP(i, n)
    sum[i + 1] = sum[i] + a[i];

    sum1[0] = 0;

    bool b = n % 2;
    REP(i, n)
    {
        sum1[i + 1] = sum1[i] + b * a[i];
        b = !b;
    }

    REP(i, q)
    {

        //x[i]より大きい数の最小値のindex
        int qi = upper_bound(a, a + n, x[i]) - lower_bound(a, a + n, 0);

        int l = n / 2 - 1;
        int r = div_up(n - 1 + qi, 2);

        while (r - l > 1)
        {
            int mid = (r + l) / 2;

            int Tnum = n - mid;

            int dr = abs(a[mid] - x[i]);
            int dl = abs(a[mid - (n - mid) + 1] - x[i]);

            if (dr >= dl)
                r = mid;
            else
                l = mid;
        }

        ll res = 0;

        res += sum[n] - sum[r];

        res += sum1[(r - (n - r))];

        cout << res << endl;
        // " " << x[i] << " " << r << endl;
    }

    return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include <vector>
using namespace std;
bool Nsided(int n, vector<int> side)
{
	int i = side.size();
	int sum = 0, maxside = 0;
	for (int j = 0; j < i; j++)
	{
		if (side[j] > maxside)
		{
			sum += maxside;
			maxside = side[j];
		}
		else
			sum += side[j];
	}
	return maxside < sum;
}
int main()
{
	int N;
	int x;
	vector <int> LI;
	cin >> N;
	while (cin >> x)
		LI.push_back(x);
	if (N >= 3 && N <= 10 && x >= 1 && x <= 100)
	{
		if (Nsided(N, LI))
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	else
		cout << "please enter N between three and ten,Li between one and hundred" << endl;
	return 0;
}


Measured memory_bytes: 3068