akhauriyash/Code-Regression huggingface dataset:
n, l = map(int, input().split())

aaa = [l + x for x in range(n)]
sum_aaa = sum(aaa)
tmp = float("inf")
for a in aaa:
    if abs(sum_aaa - (sum_aaa - a)) < tmp:
        tmp = abs(sum_aaa - (sum_aaa - a))
        res = sum_aaa - a
print(res)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;

int main()
{
    int n;
    bool ans=false;
    cin >>n;
    for(int i=0;i*4<=100;i++)
        for(int j=0;j*7<=100;j++) if(i*4+j*7==n) ans=true;
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, K; cin >> N >> K;
  vector<bool> dislike(10);
  for (ll i = 0; i < K; i++) {
    ll d; cin >> d;
    dislike[d] = true;
  }
  for (ll x = N; true; x++) {
    string s = to_string(x);
    bool success = true;
    for (char c : s) {
      if (dislike[c - '0']) {
	success = false;
	break;
      }
    }
    if (success) {
      cout << x << endl;
      return 0;
    }
  }

  return 0;
}



Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

int main() {
	int N; cin >> N;
	uint64_t ans = 0;
	rep(i, N) {
		ans += i;
	}
	cout << ans << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define _GLIBCXX_DEBUG
int main()	{
  int n;
  int count=1,ans=0;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  rep(i,n){
    if(a[i]==count){
      count++;
    }
    else{
      ans++;
    }
  }
  if(ans==n){
    cout<<-1<<endl;
  }
  else{
    cout<<ans<<endl;
  }
}

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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	int a,b,c,x,y;
	cin >> a >> b >> c >> x >> y;
	int mi = std::min(x, y);

	ll s1 = a * mi + b * mi;
	ll s2 = c * 2 * mi;

	ll ans = std::min(s1, s2);

	if (y-mi>0) {
		ll ss1 = b * (y-mi);
		ll ss2 = c * 2 * (y-mi);
		ans += std::min(ss1, ss2);
	} else if (x-mi>0) {
		ll ss1 = a * (x-mi);
		ll ss2 = c * 2 * (x-mi);
		ans += std::min(ss1, ss2);
	}
	cout << ans << endl;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, el;
    cin >> n;
    vector<int> happiness[n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 3; j++) {
            cin >> el;
            happiness[i].push_back(el);
        }

    for (int i = 1; i < n; i++)
        for (int j = 0; j < 3; j++) {
            int maxx = 0;
            for (int k = 0; k < 3; k++)
                if (k != j && happiness[i - 1][k] > maxx)
                    maxx = happiness[i - 1][k];
            happiness[i][j] += maxx;
        }
    cout << max(max(happiness[n - 1][0], happiness[n - 1][1]), happiness[n - 1][2]);

    return 0;
}

Measured memory_bytes: 8608
# coding: utf-8
# Your code here!

n = open(0)
n = n.read()
l1 = "abcdefghijklmnopqrstuvwxyz"
l2 = [0]*26

for i in n:
   for j in range(len(l1)):
      if i == l1[j] or i == l1[j].upper():
         l2[j] += 1

for i in range(len(l1)):
   print(l1[i], ":", l2[i])


Measured memory_bytes: 5576
n = int(input())
a = list(map(int, input().split()))
b = a[n:2*n]

import heapq

q = a[:n]
heapq.heapify(q)

res = [0]*(n+1)
res[0] = sum(q)
for i, x in enumerate(b):
    heapq.heappush(q, x)
    y = heapq.heappop(q)
    res[i+1] = res[i]+x-y

b.reverse()
q = [-x for x in a[2*n:]]
heapq.heapify(q)
s = -sum(q)
res[-1] -= s

for i, x in enumerate(b):
    heapq.heappush(q, -x)
    y = heapq.heappop(q)
    s += x+y
    res[-2-i] -= s

print(max(res))

Measured memory_bytes: 39124
N=int(input())
S=[input() for i in range(N)]
kekka=[0]*4
for i in range(N):
    if S[i]=="AC":
        kekka[0]+=1
    elif S[i]=="WA":
        kekka[1]+=1
    elif S[i]=="TLE":
        kekka[2]+=1
    elif S[i]=="RE":
        kekka[3]+=1
aaa=["AC","WA","TLE","RE"]
for i in range(4):
    print("{} x {}".format(aaa[i],kekka[i]))

Measured memory_bytes: 16192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {

    string S;
    cin >>S;
    ll N = S.size();
    ll ans = 0;
    rep(bit,1<<N){
        vector<string> B;
        ll cnt = 0;
        rep(i,N){
            if((bit>>i)&1){
                B.pb(S.substr(i-cnt,cnt+1));
                cnt = 0;

            }else{
                
                if(i==N-1){
                    B.pb(S.substr(i-cnt,cnt+1));
                }
                cnt++;
            }
            
            
        }

        rep(i,B.size()){
            string s = B[i];
            //cout <<s<<endl;
            ans+= stol(s);
        }

    }



    cout<<ans/2<<endl;


    return 0;
    

}

Measured memory_bytes: 3612
/*

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

*/

#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define pb push_back
#define np next_permutation
#define bs binary_search
#define mp make_pair
#define all(x) x.begin(), x.end()
#define bp __builtin_popcountll
#define sqr(x) ((llong)sqrt (x))
#define b_ctz __builtin_ctzll
#define b_clz __builtin_clzll

#define y1 road_to_respa_top_6
#define prev road_to_respa_top_6
#define Abdrakhman abcdefghijklmnopqrstuvwxyzRakhman
#define left kotoriy_levee_chem_right
#define right kotoriy_pravee_chem_left

#define android ios_base::sync_with_stdio(0), cin.tie (0), cout.tie (0)
#define fn ""

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

typedef vector <llong> vl;
typedef vector <string> vs;
typedef vector <vector <llong>> matrix;

typedef pair <llong, llong> pll;

typedef map <llong, llong> mll;

typedef set <llong> sl;

const llong MXN = 1e6 + 1;
const llong MNN = 1e3 + 1;
const llong MOD = 1e9 + 7;
const llong INF = 1e18;
const llong MAGIC = 1000;
const ldouble EPS = 1e-9;
const ldouble PI = 3.1415926536;
const string TIME = "rovno_ushten_push_ketti";

inline llong log2 (llong x) {return 64 - b_clz (x) - 1;};
inline llong __lcm (llong a, llong b) {return a / __gcd (a, b) * b;};

llong n;
llong a[MXN];

llong get (llong x) {
    for (llong i = 1; i <= n; ++ i) {
        x -= x % a[i];
    }
    return x;
}

int main () {
    android;
    random_device rand;
    #ifdef I_LOVE_DILYA
        freopen ("input.txt", "r", stdin);
    #endif
    cin >> n;
    for (llong i = 1; i <= n; ++ i) cin >> a[i];
    llong x, y;
    llong l = 0, r = INF;
    while (r - l > 1) {
        llong mid = (l + r) / 2;
        if (get (mid) <= 2) l = mid;
        else r = mid;
    }
    if (get (r) <= 2) x = r;
    else x = l;
    l = 0, r = INF;
    while (r - l > 1) {
        llong mid = (l + r) / 2;
        if (2 <= get (mid)) r = mid;
        else l = mid;
    }
    if (2 <= get (l)) y = l;
    else y = r;
    if (x < y) return cout << "-1", 0;
    cout << y << ' ' << x;
    return 0;
}

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

namespace ABC073A
{
    class Program
    {
        static void Main(string[] args)
        {
            string n;
            n = Console.ReadLine();
            if (n[0] == '9' || n[1] == '9')
                Console.WriteLine("Yes");

            else
                Console.WriteLine("No");

            Console.ReadKey();


        }
    }
}

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

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

  int fst= -1;
  int snd= -1;
  // bitset<200000> bits;
  int fst_id; // 最大値をとるindexは1つ持っておけば十分
  int buf;
  for(int i=0; i<N; i++){
    cin >> buf;
    if( buf > fst ){
      snd= fst;
      fst= buf;
      fst_id= i;
    }
    else if( buf>=snd ){
      snd= buf;
    }
  }

  for(int i=0; i<N; i++){
    if( i==fst_id ){
      cout << snd << endl;
    }
    else{
      cout << fst << endl;
    }
  }
}

Measured memory_bytes: 1664
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int N;
int A[100005],neg[100005];

int main(void) {
    cin>>N;

    for(int i = 1;i <= N;i++) {
        cin>>A[i];
    }

    sort(A+1,A+N+1);
    for(int i = 2;i <= N-1;i++) {
        if(A[i] < 0)
            neg[i] = -1;
        else
            neg[i] = 1;
    }

    neg[1] = -1;
    neg[N] = 1;

    int ans = 0;
    for(int i = 1;i <= N;i++) {
        ans += neg[i]*A[i];
    }
    cout<<ans<<endl;

    for(int i = 2;i <= N-1;i++) {
        if(neg[i] == 1) {
            cout<<A[1]<<" "<<A[i]<<endl;
            A[1] -= A[i];
        }
    }

    for(int i = 1;i < N;i++) {
        if(neg[i] == -1) {
            cout<<A[N]<<" "<<A[i]<<endl;
            A[N] -= A[i];
        } 
    }

    return 0;
}


Measured memory_bytes: 2688
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApplication76
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int answer=0;
            for(int b =0;b<a;b++)
            {
               int[] c = new int[2];
               c=Console.ReadLine().Split().Select(int.Parse).ToArray();
               answer+=c[1]-c[0]+1;
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define st first
#define nd second
#define turbo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define qi queue<int>
#define ld long double

using namespace std;

/*---------------------------------------------------------///CODE///---------------------------------------------------------*/

bool dp[100005];

int main()
{
    turbo

    dp[0] = false;

    int n, k; cin >> n >> k;

    vi T(n);

    for(int i = 0; i < n; i++)
        cin >> T[i];

    for(int i = 1; i <= k; i++)
        for(int j = 0; j < n; j++)
            if(T[j] <= i)
                if(!dp[i - T[j]])
                    dp[i] = true;

    cout << (dp[k] ? "First" : "Second");
    return 0;
}

Measured memory_bytes: 384
def min(a,b); a < b ? a : b; end

l,r = gets.split.map(&:to_i)
r = min(l + 2019, r)
ans = 2019
(l .. r).to_a.combination(2) do |i,j|
  ans = min(ans, (i * j) % 2019)
  break if ans.zero?
end
puts ans


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

int main(){

  double x1, y1, x2, y2, x3, y3, x, y;

  while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x >> y){

    double a = x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2);
    double b = x*(y1 - y2) + x1*(y2 - y) + x2*(y - y1);
    double c = x*(y2 - y3) + x2*(y3 - y) + x3*(y - y2);
    double d = x*(y3 - y1) + x3*(y1 - y) + x1*(y - y3);

    if((a<0 && b<0 && c<0 && d<0) || (a>0 && b>0 && c>0 && d>0))
      puts("YES");
    else puts("NO");

  }
}
      

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

ll n;
ll h1;
vector<ll> h;
ll dp[101010];
int main(){
	cin >> n;
	for(ll i = 0; i < n; i++){
		cin >> h1;
		h.push_back(h1);
	}
	dp[1] = 0;
//	dp[1] = abs(h[0]-h[1]);
	if(n == 2){
		cout << abs(h[0]-h[1]) << "\n";
		return 0;
	}
	dp[2] = min(abs(h[0]-h[1]), abs(h[0]-h[2]));
	for(ll i = 3; i <= n; i++){
		dp[i] = min(dp[i-1] + abs(h[i-1]-h[i-2]), dp[i-2] + abs(h[i-1]-h[i-3]));
	}
	for(ll i = 1; i <=n ; i++){
//		cout << i << ": " << dp[i] << "\n";
	}	
		cout << dp[n] << "\n";
}


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

#define ll long long int
#define ull unsigned long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


using namespace std;

const int INF = 1e9 + 7;
const int N = 1e5+5;

int main() {

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


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

typedef pair<int, int> P;

int main()
{
    int N, M;
    scanf("%d %d", &N, &M);
    vector<vector<int>> mp(N);
    for(int i = 0; i < M; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        --a, --b;
        mp[a].push_back(b);
        mp[b].push_back(a);
    }

    queue<P> task;
    vector<bool> vis(N, false);
    task.push(make_pair(0,0));
    vis[0] = true;
    while(!task.empty()){
        int from = task.front().first;
        int cost = task.front().second;
        if(from == N-1) {
            if(cost <= 2) cout << "POSSIBLE" << endl;
            else cout << "IMPOSSIBLE" << endl;
            return 0;
        }
        task.pop();
        for(int i = 0; i < mp[from].size(); ++i) {
            int to = mp[from][i];
            if(vis[to]) continue;
            vis[to] = true;
            task.push(make_pair(to, cost + 1));
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 12784
main = readLn >>= print.solve

solve n = length ( filter (\s -> (read s::Int) <= n && all (`elem` s) "357" ) semi )
  where
  semi = go ["3","5","7"]
  go [] = []
  go (s:ss)
    | length s == 9 = s : go ss
    | otherwise = (:) s $ go $ ('3':s):('5':s):('7':s):ss

Measured memory_bytes: 1020
import sys
N, M = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]

for i in range(0, 1000):
    ok = True
    for si, ci in sc:
        if (i//10**(N-si)) % 10 != ci:
            ok = False
    if ok and len(str(i)) == N:
        print(i)
        sys.exit()
else:
    print(-1)


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

using namespace std;

int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    
    int cnt = 0;
    
    for(int i = 0; i <= A; i++){
        for(int j = 0; j <= B; j++){
            for(int k = 0; k <= C; k++){
                int sum;
                sum = 500 * i + 100 * j + 50 * k;
                if(sum == X)    cnt++;
            }
        }
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,(e))
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define irpz(i,s) irp(i,(s),-1)
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(b<a){a=b;return 1;}return 0;}

ll MOD = 1000000007,N,K;

#define MAX 200001 //[n+1]
ll fac[MAX]; // 階乗 n!
ll inv[MAX]; // 逆元 1/n
ll finv[MAX]; // 逆元の階乗 (n^-1)! = (1/n)!

// n 個の配列に、mod p で前処理する
void init(int n, int p){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	rp(i,2,n+1){
		fac[i] = fac[i-1] * i % p;
		inv[i] = p - inv[p%i] * (p/i) % p;
		finv[i] = finv[i-1] * inv[i] % p;
	}
}

// 二項係数計算 nCr(mod m)
ll nCr(int n, int r, int m){
	if(n<r || n<0 || r<0) return 0;
	return fac[n] * (finv[n-r] * finv[r] % m) % m;
}

ll solve(){
	init(N, MOD);
	K = min(K, N-1);
	ll ans = 0;
	rp(k,0,K+1){
		ll x = nCr(N, k, MOD) * nCr(N-1, k, MOD) % MOD;
		ans = (ans + x) % MOD;
	}
	return ans;
}

int main(){
	cin>>N>>K;
	cout<< solve() <<endl;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
const double PI=acos(-1);
//fixed<<setprecision(11)<<

int main(){
  int r,d,x;
  cin>>r>>d>>x;
  for(int i=1;i<=10;i++){
  x=r*x-d;
  cout<<x<<endl;
  }
return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define PUTS(x) cout << (x) << endl;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define PB push_back

using Point = pair<int, int>;

int main() {
    Int h, w;
    cin >> h >> w;
    auto grid = vector<vector<int>>(h, vector<int>(w, -1));
    rep(i, h) {
        rep(j, w) {
            char c;
            cin >> c;
            if (c == '.') grid[i][j] = 0;
        }
    }

    auto ans = 0;
    rep(sy, h) {
        rep(sx, w) {
            rep(gy, h) {
                rep(gx, w) {
                    auto start = Point(sy, sx);
                    auto x = grid;
                    auto q = queue<Point>();

                    auto setValue = [&](int i, int j, int value) {
                        if (!(0 <= i && i < h && 0 <= j && j < w)) return;
                        if (Point(i, j) != start && x[i][j] == 0) {
                            x[i][j] = value;
                            q.push(Point(i, j));
                        }
                    };

                    q.push(start);
                    while (q.size() > 0) {
                        auto p = q.front();
                        q.pop();
                        auto v = x[p.first][p.second];
                        auto y = p.first;
                        auto x = p.second;
                        setValue(y + 1, x, v + 1);
                        setValue(y - 1, x, v + 1);
                        setValue(y, x - 1, v + 1);
                        setValue(y, x + 1, v + 1);
                    }
                    ans = max(ans, x[gy][gx]);
                }
            }
        }
    }
    PUTS(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;
using ull = unsigned long long;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ull a, b; cin >> a >> b;
	if (a == b) {
		cout << 1 << endl;
		return 0;
	}

	vl x(64), y(64);
	REP(i, 64) {
		x[i] = (a >> i) & 1;
		y[i] = (b >> i) & 1;
	}

	ull ma_idx; // ビットが変わった点
	for (ll i = 63; i >= 0; --i) if (x[i] != y[i]) {
		ma_idx = i;
		break;
	}

	ll y_ma1 = -1;
	REP(i, ma_idx) if (y[i] == 1) {
		y_ma1 = i;
	}

	ull x_res0 = 0;
	REP(i, ma_idx) if (x[i] == 1) {
		x_res0 = i + 1;
	}

	ull ans = 0;

	ull y_freelen = y_ma1 + 1;
	ull x_freelen = ma_idx - x_res0;
	ull under = a & ((1ull << x_res0) - 1);
	ull diff = x_res0 == 0 ? 0 : (1ull << x_res0) - under;
	if (y_freelen + x_freelen >= ma_idx) {
		ans += 1ull << ma_idx;
	} else {
		ans += 1ull << ma_idx;
		ans -= 1ull << x_res0;
		ans += diff;
		ans += 1ull << y_freelen;
	}

	ans += 1ull << ma_idx;
	ans -= under;

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

string s;

signed main() {
	cin >> s;
	int n = s.length();
	
	int i;
	vector<int> lens;
	vector<char> chars;
	int len = 1;
	
	for (i = 1; i < n; i++) {
		if (s[i - 1] != s[i]) {
			lens.push_back(len);
			chars.push_back(s[i - 1]);
			len = 1;
		}
		else {
			len++;
		}
	}
	lens.push_back(len);
	chars.push_back(s[n - 1]);
	
	int ans = 0;
	for (i = 0; i < lens.size(); i++) {
		ans += lens[i] * (lens[i] - 1) / 2;
	}
	
	for (i = 0; i + 1 < lens.size(); i++) {
		if (chars[i] == '<' && chars[i + 1] == '>') {
			ans += max(lens[i], lens[i + 1]);
		}
	}
	
	if (chars[0] == '>') ans += lens[0];
	if (chars[chars.size() - 1] == '<') ans += lens[chars.size() - 1];
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

const int INF = 987654321;
int dy[2] = {1, 0};
int dx[2] = {0, 1};

int h, w;
int a[100][100];
int b[100][100];
int c[100][100];

bool inRange(int y, int x) {
	return y >= 0 && y < h && x >= 0 && x < w;
}

int cache[100][100][12800];
int solve(int y, int x, int pre) {
	if(y == h-1 && x == w-1) 
		return abs(pre-c[y][x]);

	//cout << y << ", " << x << ", " << pre << endl;
	int& ret = cache[y][x][pre];
	if(ret != -1) return ret;
	ret = INF;

	rep(dir,0,2) {
		int ny = y + dy[dir];
		int nx = x + dx[dir];
		if(inRange(ny,nx)) {
			ret = min(ret, solve(ny,nx,abs(c[y][x]+pre)));
			ret = min(ret, solve(ny,nx,abs(c[y][x]-pre)));
		}
	}

	return ret;
}

int main(void) {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    cin >> h >> w;
    rep(i,0,h) rep(j,0,w) {
    	cin >> a[i][j];
    }
    rep(i,0,h) rep(j,0,w) {
    	cin >> b[i][j];
    }
    rep(i,0,h) rep(j,0,w) {
    	c[i][j] = abs(a[i][j]-b[i][j]);
    }

    memset(cache, -1, sizeof(cache));
    int ret = solve(0,0,0);
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 500352
while True:
    n = int(input())
    if n == 0:
        break;
    x = {}
    for i in range(n):
        k,v = input().split()
        x[k] = v
    y = []
    for i in range(int(input())):
        a = input().rstrip()
        if a in x:
            y.append(x[a])
        else:
            y.append(a)
    print(''.join(y))

Measured memory_bytes: 8536
import collections
n = int(raw_input())
cities,q = collections.deque(map(int, raw_input().split(' '))), collections.deque(map(int, raw_input().split(' ')))
res = 0
while(q):
	u = q.pop()
	for _ in range(2):
		c = cities.pop()
		m = min(u, c)
		c -=m
		u -= m
		res += m
	cities.append(c)
print res

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

using namespace std;
#define taskname "A"
#define pb	push_back
#define mp 	make_pair

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2e5 + 5;
ll l , r;
vector<int> s , t;

const int mod = 1e9 + 7;

int dp[65][2][2][2][2][2];
const int maxbit = 60;

int cal(int pos , bool a , bool b , bool c , bool d , bool e){
    //cout << pos << " " << a << " " << b << " " << c << " " << d << endl;
    if(pos == maxbit + 1)return 1;
    if(dp[pos][a][b][c][d][e] != -1)return dp[pos][a][b][c][d][e];
    int & res = dp[pos][a][b][c][d][e];
    res = 0;
    for(int i = (a ? 0 : s[pos]) ; i <= (b ? 1 : t[pos]) ; ++i){
        for(int j = max(i , (c ? 0 : s[pos])) ; j <= (d ? 1 : t[pos]) ; ++j){
            if(j == 1 && (e | i) == 0)continue;
            res += cal(pos + 1 , a | (i > s[pos]) , b | (i < t[pos]) ,
                       c | (j > s[pos]) , d | (j < t[pos]) , e | i);
            if(res >= mod)res -= mod;
        }
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    memset(dp,-1,sizeof dp);
    cin >> l >> r;
    for(int i = maxbit ; i >= 0 ; --i){
        if((1ll << i) & l)s.pb(1);else s.pb(0);
        if((1ll << i) & r)t.pb(1);else t.pb(0);
    }
//    for(int i = l ; i <= r ; ++i){
//        for(int j = l ; j <= r ; ++j){
//            if((i ^ j) == j % i)cout << bitset<7>(i) << " " << i << " " << j << endl;
//        }
//    }
    cout << cal(0 , 0 , 0 , 0 , 0 , 0);
}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

int main() {
  cout << fixed << setprecision(15);
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector<ll> B(M);
  vector<ll> C(M);
  for (ll i = 0; i < M; i++) {
    cin >> B[i] >> C[i];
  }

  // Aを小さい順にソートする
  sort(A.begin(), A.end());

  // Cの大きい順に並びかえる
  vector<ll> id(M);
  iota(id.begin(), id.end(), 0);
  sort(id.begin(), id.end(), [&](ll i, ll j) { return C[i] > C[j]; });

  ll ans = 0;
  ll a = 0;
  for (auto i : id) {
    for (ll j = 0; j < B[i]; j++) {
      if (a >= N) break;
      ans += max(A[a], C[i]);
      a++;
    }
  }

  for (ll i = a; i < N; i++) {
    ans += A[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3328
w[100000],n,k,g;
f(int p)
{
    int c=1;g=0;
    for(int i=0;i<n;)
    {
        if(g+w[i]<=p)
        {
            g+=w[i++];
        }
        else
        {
            if(g>0)c++;
            else return k+1; 
            g=0;
        }
    }
    return c;
}
main()
{
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;scanf("%d",w+i++));
    int l=0,r=1e9,m;
    while(l<r)
    {
        m=(l+r)/2;
        if(f(m)>k)l=m+1;
        else r=m;
    }
    for(m--;;m++)
    {
        if(f(m)<=k)break;
    }
    printf("%d\n",m);
    return 0;
}

Measured memory_bytes: 2216
fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    var dict:MutableMap<Long,Int> = mutableMapOf()
    (1..n).map{
        var a = readLine()!!.toLong()
        if(dict[a] == null) dict[a] = 0
        dict[a] = dict[a]!! + 1
    }
    println(dict.values.filter{y-> y%2 == 1}.size)
     
}


Measured memory_bytes: 48000
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
//ノート　isupperで大文字の判定　islowerで小文字の判定
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    std::vector<int> a(4);
    rep(i,6){
        int n;
        std::cin >> n;
        a[n-1]++;
    }
    sort(all(a));
    if(a[0]==1&&a[1]==1&&a[2]==2&&a[3]==2)std::cout << "YES" << std::endl;
    else std::cout << "NO" << std::endl;
   
}

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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    ll ans = 0;
    rep(i, n) {
        ll c_num = n - distance(c.begin(), upper_bound(c.begin(), c.end(), b[i]));
        ll a_num = distance(a.begin(), lower_bound(a.begin(), a.end(), b[i]));
        ans += ( a_num * c_num );
    }
    cout << ans << endl;
    return 0;
}


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

int N,A,B,C;

void swap(int array[],int j){
  int st;
  st=array[j];
  array[j]=array[j+1];
  array[j+1]=st;
}

int key(int array[],int cur,int a,int b,int c){
  int ret[4];
  int i,j;
  if(cur==N){
    if(a>0&&b>0&&c>0){
      return abs(a-A)+abs(b-B)+abs(c-C)-30;
    }else{
      return 1000000000;
    }
  }
  ret[0]=key(array,cur+1,a,b,c);
  ret[1]=key(array,cur+1,a+array[cur],b,c)+10;
  ret[2]=key(array,cur+1,a,b+array[cur],c)+10;
  ret[3]=key(array,cur+1,a,b,c+array[cur])+10;
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(ret[j+1]<ret[j])swap(ret,j);
    }
  }
  return ret[0];
}

int main(void){
  int i,ans;
  scanf("%d%d%d%d",&N,&A,&B,&C);
  int array[N];
  for(i=0;i<N;i++){
    while(scanf("%d",&array[i])!=1);
  }
  ans=key(array,0,0,0,0);
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
l=[list(map(int, input().split())) for i in range(3)]
r=[0,0,0,0]
for i in range(3):
    r[l[i][0]-1]+=1
    r[l[i][1]-1]+=1
r.sort()
if r==[1,1,2,2]:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
//by Top1
#include <bits/stdc++.h>
     
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
 
const int inf = INT_MAX;
const int mod = 1e9 + 7;
const int maxn = 6e5 + 111;
     
using namespace std;

int q, n, m, dist[maxn], dp[maxn], ans;
vector <int> g[maxn];
bool was[maxn];

int dfs(int v){
	if (was[v])
		return dp[v];
	was[v] = true;
	dp[v] = 0;
	for (auto to : g[v]){
		dp[v] = max(dp[v], dfs(to) + 1);
	}
	return dp[v];
}

void solve(){    
	cin >> n >> m;
		
	for (int i = 1; i <= m; i++){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
	}

	for (int i = 1; i <= n; i++){
		ans = max(ans, dfs(i));
		/*for (int j = 1; j <= n; j++)
			cout << dist[j] << " ";

		cout << endl;*/
	}

	cout << ans;
}

main(){
    boost;
	    
	q = 1;

	while (q--){
		solve();
	}
}

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

int main(){
    int n; cin >> n;
    map<long long,long long> mp;
    vector<long long> a(n);
    for(int i=0;i<n;++i) cin >> a[i];
    for(int i=0;i<n;++i){
        mp[a[i]]++;
    }
    long long sum = 0;
    for (auto itr=mp.begin(); itr!=mp.end();++itr){
        sum += ((itr->second)*(itr->second-1)/2);
    }
    for(int i=0;i<n;++i){
        cout << sum - (mp[a[i]]-1) <<endl;
        
    }
    return 0;
}

Measured memory_bytes: 11008
plan=gets.to_i
t,x,y=[],[],[]
x_n,y_n,t_n=0,0,0
plan.times do |i|
  t[i],x[i],y[i]=gets.split.map(&:to_i)
  if (t[i]-t_n)>=(x[i]-x_n).abs+(y[i]-y_n).abs && (t[i].even? == (x[i]+y[i]).even?)
    @result="Yes"
    x_n=x[i]
    y_n=y[i]
    t_n=t[i]
  else
    @result="No"
    break
  end
end
puts @result

Measured memory_bytes: 4300
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



string replace(string src, string from, string to)
{
    string::size_type Pos(src.find(from));
    while (Pos != string::npos)
    {
        src.replace(Pos, from.length(), to);
        Pos = src.find(from, Pos + to.length());
    }
    return src;
}
bool rec(string s) {
    if (s.length() < 3) return false;
    if (s == "ABC") return true;

    string ss;
    string t = replace(s, "ABC", "#");
    if (s.substr(0, 3) == "ABC") {
        if (t.find("A") != string::npos) return false;
        ss = replace(s, "ABC", "A");
    } else if (s.substr(s.length() - 3, 3) == "ABC") {
        if (t.find("C") != string::npos) return false;
        ss = replace(s, "ABC", "C");
    } else {
        if (t.find("B") != string::npos) return false;
        ss = replace(s, "ABC", "B");
    }

    if (ss.length() == s.length()) return false;

    return rec(ss);
}
//-----------------------------------------------------------------------------------
int main() {
    string s; cin >> s;

    if (rec(s)) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 16324
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    n = input()
    if n == "A":
        print("T")
    elif n == "C":
        print("G")
    elif n == "G":
        print("C")
    else:
        print("A")
    return

#B
def B():
    s = S()
    ans = 0
    n = len(s)
    for i in range(n):
        for j in range(i,n):
            f = 1
            for k in range(i,j+1):
                if s[k] not in list("AGCT"):f = 0
            if f:
                ans = max(ans,j+1-i)
    print(ans)
#C
def C():
    n,q = LI()
    s = S()
    f = [0 for i in range(n)]
    for i in range(n-1):
        if s[i:i+2] == ["A","C"]:
            f[i+1] += 1
    for i in range(n-1):
        f[i+1] += f[i]
    f.insert(0,0)
    for i in range(q):
        l,r = LI()
        print(f[r]-f[l])
    return

#D
def D():
    n = I()
    dp = [[0]*64 for i in range(n+1)]
    dp[3] = [1]*64
    dp[3][6] = 0
    dp[3][9] = 0
    dp[3][18] = 0
    ng = [[0,1,2],[0,2,1],[1,0,2]]
    for i in range(3,n):
        for j in range(64):
            k = [0,0,0]
            m = j
            for o in range(3):
                k[2-o] = m%4
                m //= 4
            if k not in ng:
                for d in range(4):
                    l = k[1:]+[d]
                    m = k[:2]+[d]
                    o = [k[2]]+[k[1]]+[d]
                    o2 = [k[1]]+[d]+[k[2]]
                    o3 = [k[0]]+[k[2]]+[d]
                    if l not in ng and m != [0,1,2] and o != [0,1,2] and o2 != [0,1,2] and o3 != [0,1,2]:
                        q = 0
                        for o in range(3):
                            q += (4**o)*l[2-o]
                        dp[i+1][q] += dp[i][j]
                        dp[i+1][q] %= mod
    print(sum(dp[n])%mod)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int a, b, t;
    cin >> a >> b >> t;
    cout << t/a*b << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 100005
using namespace std;
int n,k;
int a[maxn];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int ans=0;
	for(int i=1;i<=k;i++)
	ans+=a[i];
	printf("%d\n",ans);
}

Measured memory_bytes: 3796
#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 int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n;
int t[100005];
int a[100005];
int d[100005];

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> t[i];
	}

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

	if (t[n - 1] != a[0]) {
		cout << 0 << endl;
		return 0;
	}

	d[0] = 1;

	for (int i = 1; i < n; i++) {
		if (t[i - 1] == t[i]) {
			d[i] = t[i];
		}
		else {
			d[i] = 1;
		}
	}

	d[n - 1] = 1;

	for (int i = n - 2; i >= 0; i--) {
		if (a[i] == a[i + 1]) {
			if (d[i] == 1 && t[i] > a[i]) {
				cout << 0 << endl;
				return 0;
			}
			d[i] = std::min(d[i], a[i]);
		}
		else {
			if (d[i]==1 && t[i] != a[i]) {
				cout << 0 << endl;
				return 0;
			}
			d[i] = 1;
		}
	}

	ll ans = 1;
	for (int i = 0; i < n; i++) {
		ans = (ans * (ll)d[i]) % mod;
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
  string w;
  cin >> w;
  vector<int> count(26, 0);

  for (int i = 0; i < w.size(); i++) {
    count[w[i] - 'a'] += 1;
  }
  bool beautiful = 1;
  for (int i = 0; i < 26; i++) {
    if (count[i] % 2 != 0) {
      beautiful = 0;
      break;
    }
  }
  if (beautiful)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define mod 1000000007
typedef long long ll;

int main(void) {
  ll i, j, k, n;
  char s[100100];
  scanf("%s", s);
  n = strlen(s);
  ll dp[n][13];
  for(i = 0; i < n; ++i) for(j = 0; j < 13; ++j) dp[i][j] = 0;
  if(s[0] == '?') for(i = 0; i < 10; ++i) dp[0][i] = 1;
  else dp[0][s[0] - '0'] = 1;
  for(i = 1; i < n; ++i) {
    if(s[i] == '?') 
      for(j = 0; j < 13; ++j) for(k = 0; k < 10; ++k) dp[i][(j * 10 + k) % 13] += dp[i - 1][j];
    else for(j = 0; j < 13; ++j) dp[i][(j * 10 + s[i] - '0') % 13] += dp[i - 1][j];
    for(j = 0; j < 13; ++j) dp[i][j] %= mod;
  }
  printf("%lld", dp[n - 1][5]);
  return 0;
}

Measured memory_bytes: 10368
/**
 *      ABC 53 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-05 02:39:40
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int x; cin >> x;
    x < 1200 ? cout << "ABC" : cout << "ARC";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
char s1[105];
char s2[105];
char s3[105];
char pre;
int flag;
int main()
{
	cin>>s1>>s2>>s3;
	if(s1[strlen(s1)-1]==s2[0]&&s2[strlen(s2)-1]==s3[0])
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}



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

int main()
{
	long long aa,bb,cc,dd;
	scanf("%lld%lld%lld",&aa,&bb,&cc);
	dd=cc-(aa+bb);
	if (aa+bb>cc) printf("No");
	else 
	{
		if (4*aa*bb-dd*dd<0) printf("Yes");
		else printf("No");
	}
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define REP(i,x) for(ll i=0;i<(ll)(x);i++)

int main()
{
	cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> p_i(N, 0);
    REP(i, N)
    {
        cin >> p_i.at(i);
    }

    // p_iの和が最大になるとこ
    vector<ull> dp(N-K+1, 0);

    REP(i, K)
    {
        dp.at(0) = dp.at(0) + (1 + p_i.at(i));
    }

    for(int i=0; i<N-K; i++)
    {
        // double s_i = ((double)p_i.at(i) + 1) / 2;
        // double s_iK = ((double)p_i.at(i+K) + 1) / 2;
        // dp.at(i+1) = dp.at(i) - s_i + s_iK;
        dp.at(i+1) = dp.at(i) + p_i.at(i+K) - p_i.at(i);
    }
    sort(dp.begin(), dp.end(), greater<ull>());

    double ans = (double)*dp.begin() / 2;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	long long k;
	cin >> n >> k;
	vector<long long> a(n);
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<n;i++) a[i]--;
	
	long long res=0;
	map<long long,long long> mp;
	mp[0LL]=1LL;
	long long prev=0;
	vector<long long> b(n+1);
	b[0]=0;
	for(int i=0;i<n;i++){
		prev+=a[i];
		prev%=k;
		prev=(prev+k)%k;
		b[i+1]=prev;
		if((i+1)>=k){
			mp[b[i-k+1]]--;
		}
		if(mp.find(prev)!=mp.end()){
			res+=mp[prev];
			mp[prev]=mp[prev]+1;
		}else{
			mp[prev]=1;
		}
		//cout << res << " ";
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 15872
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 3);
  (v[0], v[1], v[2])
}

fn main() {
   let (n, x, y) = read_touple::<usize>();
   let mut g = vec![vec![]; n];
   for i in 0..n-1 {
     g[i].push(i+1);
     g[i+1].push(i);
   }

   g[x-1].push(y-1);
   g[y-1].push(x-1);

   let mut ans = vec![0; n-1];
   for i in 0..n {
     let dist = bfs_dist(n, &g, i);
     //println!("{:?}", dist);
     for d in dist {
       if d == std::usize::MAX {
         continue
       }
        ans[d] += 1;
     }
   }
   
   for a in ans {
     println!("{}", a/2);
   }
}

use ::std::collections::VecDeque;
use std::cmp::*;

//単一視点から目的のノードまでの最短距離、ただし全ての辺の重みが等しいグラフに限る
fn bfs_dist(n: usize, g: &Vec<Vec<usize>>, start: usize) -> Vec<usize> {
  let mut visit = vec![false; n];
  let mut q = VecDeque::new();
  let mut dist = vec![std::usize::MAX; n];

  //init
  visit[start] = true;
  q.push_back(start);

  while let Some(now) = q.pop_front() {

    for &e in &g[now] {
      if !visit[e] {
        visit[e] = true;
        dist[e] = min(dist[e], dist[now] + 1);
        q.push_back(e);
      }
    }
  }
  return dist;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;

#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define pi pair<int,int>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define mod 1000000007
#define pai acos(-1)
#define N 100005


int main ()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n;cin>>n;
   ll ans=0;
   ll ar;cin>>ar;
   for(int i=1;i<n;i++){
      ll br;cin>>br;
      ans+=max(0ll,ar-br);
      ar=max(ar,br);
   }
   cout<<ans<<endl;
   return 0;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
        #define ll long long
        #define rep(i,a,b) for(i=a;i<b;i++)
        #define pb push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define hell 1000000007
        using namespace std;

        void solve()
        {
          ll n,m,i,j,k,c=0,y=0,ams=0,a,b;
          string s;
         cin>>n;
         vector < ll > v(n);
         map < ll , ll > M;
         rep(i,0,n)
         {
             cin>>v[i];
             M[v[i]]++;
             y+=v[i];
         }
         cin>>k;
         rep(i,0,k)
         {
             cin>>a>>b;
             y-=M[a]*a;
             y+=M[a]*b;
             cout<<y<<endl;
            // M[a]=0;
             M[b]+=M[a];
             M[a]=0;
         }



    }

        int main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
            solve();
        }


Measured memory_bytes: 10052