akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
//DEFINE and TYPEDEF--------------------------------------------------------------
 
#define timeKyaHorhaH 1.0 * clock() / CLOCKS_PER_SEC

#define FORG(i,a,n) for(lld i=a;i<n;i++) //for - general
#define FORZ(i,n) for(lld i=0;i<n;i++) //for - zero
#define FORGI(i,a,n,inc) for(lld i=a;i<n;i+=inc) //for - general incremental
#define FORZI(i,n,inc) for(lld i=0;i<n;i+=inc) //for - zero incremental
#define SPEEDUP ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define MEM(a,val) memset(a,val,sizeof(a));
 
#define SORTall(m) sort(m.begin(),m.end());
 
#define st first
#define nd second
#define pb push_back
 
typedef long long int lld;
typedef unsigned long long int ulld;

lld power(lld b, lld e)
{
    if(e==0)
        return 1;
    if(e%2==1)
        return b*power(b*b,(e-1)/2);
    else
        return power(b*b,e/2);
}
 
lld power(lld b, lld e, lld m)
{
	if(e==0)
		return 1;
	if(e%2==1)
		return b*power(((b%m)*(b%m))%m,(e-1)/2,m)%m;
	else
		return power(((b%m)*(b%m))%m,e/2,m)%m;
}
 
int nDig(lld n)
{
	if(n<0) 
		n*=-1;
	if(n==0)
		return 1;

    return floor(log10(n) + 1);
}

#define endl '\n'
#define mod 1000000007

//endl : changed to '\n', to flush comment that definition
//--------------------------------------------------------------------------------

void swagWaalaFunction()
{
	lld n,x;
	cin>>n;

	map<lld,lld> m;
	FORZ(i,n)
		m[i+1]=0;

	FORZ(i,n-1)
	{
		cin>>x;
		m[x]++;
	}

	for(auto i:m)
		cout<<i.nd<<endl;

	return;
}

int main()
{
    SPEEDUP;
 	lld t=1;
 	//cin>>t;

 	while(t--)
 		swagWaalaFunction();
	
	// cerr<<"\n"<<timeKyaHorhaH; 	
 	return 0;
}

Measured memory_bytes: 16136
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string k; cin >> k;
    int d; cin >> d;
    vector<vector<vector<int>>> dp(k.size(), vector<vector<int>>(2, vector<int>(d, -1)));
    function<int(int, int, int)> solve = [&] (int p, int lim, int rem) {
        if (p >= k.size()) return int(!rem);
        if (dp[p][lim][rem] != -1) return dp[p][lim][rem];
        int cnt = 0;
        for (int i = 0; i <= (lim ? k[p] - '0': 9); ++i)
            (cnt += solve(p + 1, lim ? k[p] - '0' == i : 0, (rem + i) % d)) %= MOD;
        return dp[p][lim][rem] = cnt;
    };
    cout << (solve(0, 1, 0) + MOD - 1) % MOD << '\n';
}

Measured memory_bytes: 10496
n = int(input())
s = []
for i in range(n):
  a , b  = input().split()
  s.append((a,int(b),i+1))

s1 = sorted(s,key = lambda S:S[1],reverse=True)
s2 = sorted(s1,key = lambda S:S[0])
for i in range(n):
  print(s2[i][2])

Measured memory_bytes: 9100
#include <iostream>
using namespace std;
typedef long long ll;

int main(){
	int k,s;
	cin >> k >> s;

	int ans = 0;
	for(int x = 0;x <= k;x++){
		for(int y = 0;y <= k;y++){
			if(s - x - y <= k && s - x - y >= 0){
				ans++;
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3592
import sys
sys.setrecursionlimit(10**9)

n, m = map(int, input().split())

root = [-1]*n

def r(x):
    if root[x] < 0 :
        return x
    else:
        root[x] = r(root[x])
        return root[x]

def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x

def size(x):
    x = r(x)
    return - root[x]

for i in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    unite(x,y)

max_size = max(map(size,range(n)))

print(max_size)

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

#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int amt = min(n, m/2);
    m -= amt*2;
    n -= amt;
    int res = amt + m/4;
    cout << res << '\n';
}
/*

 */

Measured memory_bytes: 3628
#include <stdio.h>
#include <math.h>
#include <complex>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef complex<double> P;

inline double cross(const P& a, const P& b) { return imag(conj(a)*b); }

int n;
P ps[32];

int main() {
    double x, y;
    while (scanf("%lf,%lf", &x, &y) != EOF) ps[n++] = P(x, y);
    double s = 0;
    rep (i, n-1) s += cross(ps[i]-ps[0], ps[i+1]-ps[0]);
    printf("%.9f\n", fabs(s)/2);
    return 0;
}

Measured memory_bytes: 0
import numpy as np
import collections

n = int(input())
moji = [list(map(str,input())) for index in range(n)]
count = 0

for index in range(n):
  moji[index].sort()
  moji[index] = "".join(moji[index])

moji.sort()

for index in collections.Counter(moji).values():
  n = index - 1
  count += n*(1+n)/2

print(int(count))

Measured memory_bytes: 36124
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b)	for(i=a;i<b;i++)
#define mem(a,b) memset(a , b , sizeof a ) ; 
#define M 1000000007                          
int main()                                  
{                                             
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    if(n==m) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){

	int a;
	cin >> a;
	int h, m, s;
	h = a / 3600;
	s = a % 3600;
	m = s / 60;
	s = s % 60;
	cout << h << ":" << m << ":" << s << endl;

	return 0;
}


Measured memory_bytes: 3096
// 解説前
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

// 向きを持たない辺
struct Edge {
  Edge() = default;

  Edge(size_t a, size_t b) {
    if (a > b) std::swap(a, b);
    this->a = a;
    this->b = b;
  }

  bool operator<(const Edge& other) const noexcept {
    if (a < other.a) return true;
    if (a > other.a) return false;
    return b < other.b;
  }

  size_t a = 0;
  size_t b = 0;
};

// 入力されるグラフは木構造なので、各頂点は親を1つだけ持つ
// => 幅優先探索を用いて親との辺以外の色を子との辺に割り当てれば良い
// => 必要な色数は頂点に接続される辺の最大数になる
int solve_D() {
  size_t N;
  std::cin >> N;

  // グラフを読み取る
  std::vector<std::vector<size_t>> graph(N + 1);
  std::vector<Edge> edges(N - 1);  // 入力順の辺情報
  for (size_t i = 0; i < N - 1; ++i) {
    std::cin >> edges[i].a >> edges[i].b;
    graph[edges[i].a].push_back(edges[i].b);
  }

  // 色を塗る
  // 親頂点が処理済みの状態で子供を処理すればいいので、FIFOでもFILOでも問題なく行える
  std::vector<size_t> indices;  // 頂点番号を格納するのスタック
  std::vector<size_t> parent_colors;  // 親との辺の色を格納するスタック
  indices.reserve(N);
  parent_colors.reserve(N);
  std::map<Edge, size_t> color_map;  // 辺に割り当てた色を格納するマップ
  size_t num_colors = 0;  // 必要となる色数

  // ルート頂点の子供にそれぞれ異なる色を割り当てる
  size_t color = 1;
  for (const auto child : graph[1]) {
    // 辺に割り当てた色を記録する
    const auto child_color = color++;
    color_map.emplace(Edge{1, child}, child_color);

    // 子供の子供を処理するために子頂点をスタックに積む
    indices.push_back(child);
    parent_colors.push_back(child_color);
  }

  // 親を持たない場合の色数を数える
  num_colors = std::max(num_colors, graph[1].size());

  // 各頂点の子供にそれぞれ異なる色を割り当てる
  while (!indices.empty()) {
    // 親頂点の情報をスタックから取り出す
    const auto parent = indices.back();
    const auto parent_color = parent_colors.back();
    indices.pop_back();
    parent_colors.pop_back();
    
    // 子との辺に色を割り当てる
    size_t color = 1;
    const auto& children = graph[parent];
    for (const auto child : children) {
      // 親との辺と同じ色をスキップする
      if (color == parent_color) color++;

      // 辺に割り当てた色を記録する
      const auto child_color = color++;
      color_map.emplace(Edge{parent, child}, child_color);

      // 子供の子供を処理するために子頂点をスタックに積む
      indices.push_back(child);
      parent_colors.push_back(child_color);
    }

    // 親を持つ場合の色数を数える
    num_colors = std::max(num_colors, children.size() + 1);
  }

  // 結果発表
  std::cout << num_colors << '\n';
  for (const auto& edge : edges) {
    std::cout << color_map[edge] << '\n';
  }

  return 0;
}

int main() {
  return solve_D();
}


Measured memory_bytes: 12416
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

typedef pair<string, string> P;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string S; cin >> S;
    ll ans = 0;
    map<P, int> mp;
    rep(bit, (1 << n)) {
        string K, T;
        rep(j, n) {
            if (bit & (1 << j)) K += S[j];
            else T = S[j] + T;
        }
        mp[{K, T}]++;
    }
    rep(bit, (1 << n)) {
        string K, T;
        rep(j, n) {
            if (bit & (1 << j)) K += S[n + j];
            else T = S[n + j] + T;
        }
        ans += mp[{T, K}];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 87040
from collections import Counter
n = int(input())
d = list(input() for _ in range(n))
D = Counter(d)
m = max(D.values())
l = []
for i,j in D.most_common():
  if m != j:
    break
  l.append(i)
l.sort()
for i in l:
  print(i)

Measured memory_bytes: 49564
#include <iostream>
#include <algorithm>

using namespace std;

const int NMAX = 1e5 + 5;
const long long INF = (1LL << 60);
struct Edge
{
	int left, right, cost;
};

int N, M;
Edge edges[NMAX];
long long aint[4 * NMAX], dist[NMAX];

int LeftSon(int node)
{
	return 2 * node;
}

int RightSon(int node)
{
	return 2 * node + 1;
}

void Build(int node, int left, int right)
{
	if (left == right)
	{
		aint[node] = INF;
		return;
	}
	int mid = (left + right) / 2;
	Build(LeftSon(node), left, mid);
	Build(RightSon(node), mid + 1, right);
	aint[node] = INF;
}

void Update(int node, int left, int right, int pos, long long val)
{
	if (left == right)
	{
		dist[pos] = val;
		aint[node] = val;
		return;
	}
	int mid = (left + right) / 2;
	if (pos <= mid)
		Update(LeftSon(node), left, mid, pos, val);
	else
		Update(RightSon(node), mid + 1, right, pos, val);
	aint[node] = min(aint[LeftSon(node)], aint[RightSon(node)]);
}

long long Query(int node, int left, int right, int LeftQuery, int RightQuery)
{
	if (LeftQuery <= left && right <= RightQuery)
		return aint[node];
	int mid = (left + right) / 2;
	long long ans = INF;
	if (LeftQuery <= mid)
		ans = min(ans, Query(LeftSon(node), left, mid, LeftQuery, RightQuery));
	if (RightQuery >= mid + 1)
		ans = min(ans, Query(RightSon(node), mid + 1, right, LeftQuery, RightQuery));
	return ans;
}

int main()
{
	cin >> N >> M;
	for (int i = 1;i <= N;++i)
		dist[i] = INF;
	Build(1, 1, N);
	dist[1] = 0;
	Update(1, 1, N, 1, 0);
	for (int i = 1;i <= M;++i)
		cin >> edges[i].left >> edges[i].right >> edges[i].cost;
	sort(edges + 1, edges + M + 1, [&](Edge x, Edge y)
	{
		if (x.right == y.right)
			return x.left < y.left;
		return x.right < y.right;
	});
	for (int i = 1;i <= M;++i)
	{
		dist[edges[i].right] = min(dist[edges[i].right], min(Query(1, 1, N, edges[i].left, edges[i].right) + edges[i].cost, INF));
		Update(1, 1, N, edges[i].right, dist[edges[i].right]);
	}
	long long answer = dist[N];
	if (dist[N] == INF)
		answer = -1;
	cout << answer << "\n";
	return 0;
}

Measured memory_bytes: 5120
def divisor(i):
    cnt = 0
    y = i ** (1 / 2)
    for j in range(1, int(y) + 1):
        if i % j == 0:
            cnt += (x[j] + x[i // j])
    if y % 1 == 0:
        cnt -= x[int(y)]
    return cnt

n, k = map(int, input().split())
mod = pow(10, 9) + 7
ans = 0
x = [0] * (k + 1)
for i in range(1, k + 1):
    x[i] = i - divisor(i)
    ans += (x[i] * (pow(k // i, n, mod)) % mod)
    ans %= mod
print(ans)

Measured memory_bytes: 75336
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <deque>
// #include <chrono>
#include <numeric>

using namespace std;
// using namespace std::chrono;

typedef long long int lo;
#define fast ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0);
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define inf (lo)1e9
#define N (lo)1e5 * 5
#define all(x) (x).begin(), (x).end()
#define ii pair<lo,lo>
#define iii pair<lo, pair<lo,lo> >
#define si pair<string,lo>
#define vi vector <lo> 
#define vii vector <ii> 

lo gcd(lo a, lo b){
    if(b == 0){
        return a;
    }
    return gcd(b, a % b);
}

void solve(){
    lo n;
    cin >> n;
    lo sum = 0;
    for(lo i = 1 ; i <= n ; i++){
        for(lo j = 1 ; j <= n ; j++){
            for(lo k = 1 ; k <= n ; k++){
                sum += gcd(i, gcd(j,k));
            }
        }
    }
    cout << sum << endl;
}
    
int main() {

    #ifndef ONLINE_JUDGE
        // freopen("soru.gir", "r", stdin);
        // freopen("soru.cik", "w", stdout);
    #endif
    
    fast
    
    // auto start = high_resolution_clock::now();

    lo p = 0;

    if(p){
        lo t;
        cin >> t;
        while(t--)
            solve();
    }
    else{
        solve();
    }

    // auto stop = high_resolution_clock::now();
    // auto duration = duration_cast<microseconds>(stop - start);
    
    // #ifndef ONLINE_JUDGE
    //     cout << "Elapsed time is " << duration.count() << " microseconds." << endl;
    // #endif
    
    return 0;
}

Measured memory_bytes: 3652
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll a[200005];
ll b[200005];
int main(void) {
    ll n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll sum = 0;
    for (int i = 0; i < m; i++) {
        cin >> b[i];
        sum += b[i];
    }
    ll ma = -inf;
    ll j = m;
    for (ll i = 0; i < n + 1; i++) {
        
            while (j > 0 && sum > k) {
                j--;
                sum -= b[j];
            }
            if (sum > k) {
                break;
            }
            ma = max(ma, i + j);
            if (i == n) {
                break;
            }
        
            sum += a[i];
        
    }
    cout << ma << endl;
    return 0;
}


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

public class Main {
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	int N = Integer.parseInt(scanner.next());
    	int K = Integer.parseInt(scanner.next());
    	int[] fruits = new int[N];
    	for(int i=0;i<N;i++) {
    		fruits[i] = Integer.parseInt(scanner.next());
    	}
    	int sum = 0;
    	Arrays.sort(fruits);
    	for(int i=0;i<K;i++) {
    		sum += fruits[i];
    	}
    	System.out.println(sum);
    	scanner.close();
    }
}

Measured memory_bytes: 29520
#include <algorithm>
#include <iostream>
using namespace std;
const int MOD = 2019;
int main() {
  int L, R, m{MOD};
  cin >> L >> R;
  R = min(R - L, MOD);
  L %= MOD;
  if (L+R>=MOD) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < R; ++i)
    for (int j = i; j < R; ++j) m = min(m, (L + i) * (L + j + 1) % MOD);
  cout << m << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    int n;
    cin>>n;
    vector<int> a(3,0);
    for(int i=0;i<n;i++){
	int tmp;
	cin>>tmp;
	tmp--;
	a[tmp]++;
    }
    vector<vector<vector<double> > > dp(n+1,vector<vector<double> >(n+1,vector<double>(n+1,0) ) );

    for(int i=0;i<=n;i++){
	for(int j=0;j<=n;j++){
	    for(int k=0;k<=n;k++){
		double sum = 0;
		if(i+j+k==0)continue;
		if( k>0 ) sum += dp[i][j][k-1]*k/(i+j+k);
		if( j>0 && k< n ) sum += dp[i][j-1][k+1]*j/(i+j+k);
		if( i>0 && j< n ) sum += dp[i-1][j+1][k]*i/(i+j+k);
		dp[i][j][k] = sum + (double) n /(i+j+k);
	    }
	}
    }
    printf("%0.10lf\n",dp[a[2]][a[1]][a[0]] );

    return 0;
}


Measured memory_bytes: 216832
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int n, m;

  cin >> n >> m;

  cout << (n - 1) * (m - 1) << endl;
}


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

typedef long long int ll;
#define ent cout << "\n"
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define pair < ll, ll > pp
#define f(a, b) for(auto i = a;i < b;i++)
#define rev_f(a, b) for(auto i = b;i >= a;i--)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define st(x) sort(x.begin(), x.end()) 
#define rv(x) reverse(x.begin(), x.end()) 
#define cintc() ll tc;while(tc--) 
#define deb(x) cout << x << "\n";
#define cin(a) ll a; cin >> a;
#define cin2() ll a, b; cin >> a >> b
#define cin3() ll a, b, c; cin >> a >> b >> c
#define cinn(vect, n) def_v vect(n); f(0, n) cin >> vect[i]
#define coutn(vect, n)  f(0, n) {cout << vect[i] << "";} cout << " ";

typedef vector < ll > def_v;
typedef tuple< ll, ll, ll> def_tuple;
ll mod = 1e9 + 7,cnt = 0;

vector < ll > bfs(vector < ll > graph[], vector < ll > vect, ll start, ll flag, ll n)
{

    ll vis[n + 1] = {0};
    vis[start] = 1;
    queue < ll > q;
    q.push(start);
    while(!q.empty())
    {

        ll start = q.front();
        q.pop();
        auto size = ll(graph[start].size());
        for(ll j = 0;j < size;j++)
        {
            ll x = graph[start][j];
            if(!vis[x])
            {
                vis[x] = 1;
                if(x == 1 && flag == 2)
                {
                    flag = 2;
                }
                else
                    q.push(x);
                vect[x] = flag;
            }
        }
    }

    return vect;
}

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    while(1)
    {
        if(c - b <= 0)
        {
            cout << "Yes\n";
            break;
        }
        c -= b;

        if(a - d <= 0)
        {
            cout << "No\n";
            break;
        }

        a -=d;
    } 
    return 0;
}

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

int main(){
    int i, n, h;
    char com[14],str[12];
    set<string> dictionary;
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	string str_ = str;

        if ( com[0] == 'i' ){
            dictionary.insert(str_);
        } else {
            if(dictionary.find(str_) != dictionary.end()) printf("yes\n");
            else printf("no\n");
        }
    }

    return 0;
}


Measured memory_bytes: 29084
#include <cstdio>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int INF = 1e18;
const int M = 1e9 + 7;
//__int128
const int maxn = 5e5;
int dp[maxn][20];
int x[maxn];
signed main()
{
  // freopen("in.txt", "r", stdin);
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> x[i];
  }
  int l;
  cin >> l;
  for(int i = 0; i < n; ++i) {
    dp[i][0] = upper_bound(x, x + n, x[i] + l) - x - 1;
  }
  int m = 0;
  for(int j = 1; (1 << j) < n; ++j, ++m) {
    for(int i = 0; i < n; ++i) {
      if(i + (1 << j) >= n) dp[i][j] = n - 1;
      dp[i][j] = dp[dp[i][j - 1]][j - 1];
    }
  }  
  int q;
  cin >> q;
  while(q--) {
    int l, r;
    cin >> l >> r;
    --l, --r;
    if(l > r) swap(l, r);
    int res = 0;
    while(1) {
      int time = lower_bound(dp[l], dp[l] + m, r) - dp[l];
      if(time == 0) {
        ++res;
        break;
      } else {
        time--;
        res += 1 << time;
        l = dp[l][time];
      }
    }
    cout << res << endl;
  }
  return 0;
}

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

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

  int cnt = 0, x = 1;
  while (x < K) x *= 2, cnt++;

  long ans = 0;
  for (int i = 1; i <= N; i++) {
    int j = i, tmp = 0;
    while (j < K) j *= 2, tmp++;
    ans += pow(2, cnt - tmp);
  }

  while (cnt--) N *= 2;
  cout << fixed << setprecision(9) << (double) ans / N << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a[101][101], b[101], c[101];
    int i, j;
    int n, m;
 
    scanf("%d%d", &n, &m);
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) scanf("%d", &a[i][j]);
    }
    for (j = 0; j < m; j++) scanf("%d", &b[j]);
 
    for (i = 0; i < n; i++) {
        c[i] = 0;
        for (j = 0; j < m; j++) c[i] += a[i][j] * b[j];
    }
 
    for (i = 0; i < n; i++) {
        printf("%d\n", c[i]);
    }
    return 0;
}


Measured memory_bytes: 2108
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])

for i in range(2):
	for j in range(2):
		for k in range(2):
			x = a + b*(-1)**i + c*(-1)**j + d*(-1)**k
			if x == 7:
				print(a, end='')
				print('-' if i else '+', end='')
				print(b, end='')
				print('-' if j else '+', end='')
				print(c, end='')
				print('-' if k else '+', end='')
				print(d, end='')
				print("=7")
				exit()

Measured memory_bytes: 38384
import numpy as np

def main():
    s = input()
    t = input()
    #n,m = map(int, input().split())
    #a = list(map(int,input().split()))
    l = len(s)
    bool = False
    for i in range(l):
        s = s[l-1]+s[:l-1]
        if s == t:
            bool = True
            break
    if bool == True:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 27148
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
  int a, b;
  cin >> a >> b;

  if (b < 10) {
    a = a * 10 + b;
  } else if (b < 100) {
    a = a * 100 + b;
  } else {
    a = a * 1000 + b;
  }

  bool ok = false;
  for (int i = 1; i * i <= a; i++) {
    if (i * i == a) {
      ok = true;
      break;
    }
  }
  cout << (ok ? "Yes" : "No");

  return 0;
}


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

signed main() {
	int n;
	cin >> n;
	ll sum = 0;
	vector<int> a(n);
	rep(i,n) cin>>a[i];
	for(int i = 1; i < n; i++){
		if(a[i] < a[i-1]) {
			sum += a[i-1]-a[i];
			a[i] = a[i-1];
		}
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 4028
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const double INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const ll MAX_N = 1e5 + 10;
ll dp[3][MAX_N];

void init() {
	for (ll i = 0; i <= MAX_N; i++) {
		dp[0][i] = 0;
		dp[1][i] = 0;
		dp[2][i] = 0;
	}
}

int main() {
	init();
	ll N;
	cin >> N;
	ll i, j;
	vll A, B, C;
	for (i = 0; i < N; i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		A.push_back(a);
		B.push_back(b);
		C.push_back(c);
	}
	dp[0][0] = A[0];
	dp[1][0] = B[0];
	dp[2][0] = C[0];
	for (i = 1; i < N; i++) {
		dp[0][i] = max(dp[1][i - 1] + A[i], dp[2][i - 1] + A[i]);
		dp[1][i] = max(dp[0][i - 1] + B[i], dp[2][i - 1] + B[i]);
		dp[2][i] = max(dp[0][i - 1] + C[i], dp[1][i - 1] + C[i]);
	}
	cout << max(max(dp[0][N - 1], dp[1][N - 1]), dp[2][N - 1]) << endl;
	return 0;
}


Measured memory_bytes: 5216
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var str=input.trim();
if(str=="1 0 0")console.log("Close");
if(str=="0 1 0")console.log("Close");
if(str=="1 1 0")console.log("Open");
if(str=="0 0 1")console.log("Open");
if(str=="0 0 0")console.log("Close");

Measured memory_bytes: 7384
def main():
    N, M, X = map(int, input().split())
    A = list(map(int, input().split()))
    under_x, upper_x = 0, 0
    for a in A:
        if a < X:
            under_x += 1
        else:
            upper_x += 1
    print(min(under_x, upper_x))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

a = INT()
s = input()

if a >= 3200:
    print(s)
else:
    print('red')


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

struct Acc {
  vector<int> sum;
  Acc(vector<int> v) {
    sum.push_back(0);
    each (i, v) {
      sum.push_back(sum.back() + i);
    }
  }
  int query(int begin, int end) {
    return sum[end] - sum[begin];
  }
};

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  string s;
  while (cin >> n >> s) {
    vector<int> ve;
    vector<int> vw;
    each (c, s) {
      ve.push_back(c == 'E');
      vw.push_back(c == 'W');
    }
    
    Acc e(ve);
    Acc w(vw);

    int mn = 1 << 29;
    for (int i = 0; i < s.size(); ++i) {
      mn = min(mn, w.query(0, i) + e.query(i + 1, s.size()));
    }
    cout << mn << endl;
  }
  
  return 0;
}


Measured memory_bytes: 8436
#![allow(unused_imports, unused_macros, dead_code)]
use std::f64::*;
use std::cmp::*;
use std::collections::*;

macro_rules! dump{
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const INF: i64 = 0x3f3f3f3f3f3f3f3f;
const MOD: i64 = 1000000007;
const NOTHING: usize = std::usize::MAX;
const DX: [usize; 4] = [1, 0, std::usize::MAX, 0];
const DY: [usize; 4] = [0, 1, 0, std::usize::MAX];

fn main() {
    let s: Vec<char> = readln();
    let l = s.len();
    let mut res = s.len();
    let mut flip = false;
    let mut prev = s[0];
    for i in 1..l {
        if prev != s[i] && !flip || prev == s[i] && flip {

            if i - 1 < l - 1 {
                flip = !flip;
            }
            prev = if flip {
                if s[i] == '0' { '1' } else { '0' }
            } else {
                s[i]
            };
            res = min(res, max(i, l - i));
        }
    }
    println!("{}", res);
}

trait Read {
    fn read(s: &str) -> Self;
}

fn readln<T: Read>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    T::read(buf.trim_right())
}

macro_rules! read_impl{
    ($($t:ty)*) => ($(
        impl Read for $t {
            fn read(s: &str) -> $t{
                s.parse().unwrap()
            }
        }
    )*)
}
read_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }

impl Read for String {
    fn read(s: &str) -> Self {
        s.to_string()
    }
}

impl Read for Vec<char> {
    fn read(s: &str) -> Self {
        s.chars().collect()
    }
}

impl<T: Read> Read for Vec<T> {
    fn read(s: &str) -> Self {
        s.split_whitespace().map(T::read).collect()
    }
}

impl<A: Read, B: Read> Read for (A, B) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]))
    }
}

impl<A: Read, B: Read, C: Read> Read for (A, B, C) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]))
    }
}

impl<A: Read, B: Read, C: Read, D: Read> Read for (A, B, C, D) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]), D::read(tokens[3]))
    }
}


Measured memory_bytes: 4352
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

struct P{
  double x;
  double y;

  P(){
	x=0; y=0;
  }

  P(const double &s , const double &e)
  { x=s; y=e;}

  P operator - (const P &t) const
  { return P(x-t.x , y-t.y); }

  P operator + (const P &t) const
  { return P(x+t.x , y+t.y); }

  P operator * (const double &d) const
  { return P(x*d , y*d); }

};

double dot(P& p, P& q){
  return p.x*q.x + p.y * q.y;
}

double cross(P& p, P& q){
  return p.x * q.y - p.y * q.x;
}

double norm(const P& p){
  return sqrt(p.x*p.x+p.y*p.y);
}

double cos(P& p, P& q){
  return dot(p,q) / norm(p) / norm(q);
}

int N;
int idx(int i, int j){
  return i*N+j;
}

VI to[20*20];
vector<double> cost[20*20];
double dp[20*20][10010];

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

  cin >> N;
  double R, theta; cin >> R >> theta;
  double lim_sin = theta * PI / 180.;
  vector<P> ps(N);
  REP(i,N) cin >> ps[i].x >> ps[i].y;

  REP(i,N) REP(j,N){
	if(i == j) continue;
	P d = ps[j] - ps[i];
	REP(k,N){
	  if(k == i || k == j) continue;
	  P f = ps[k] - ps[j];
	  if(acos(cos(d,f)) <= lim_sin){
		to[idx(i,j)].PB(idx(j,k));
		cost[idx(i,j)].PB(norm(ps[k]-ps[j]));
	  }
	}
  }

  fill((double*)dp, (double*)dp+20*20*10010, R+100);
  dp[0][0] = 0;
  FOR(i,1,N)
	dp[idx(0,i)][1] = norm(ps[i] - ps[0]);

  int ans = 0;
  for(int r=1;r<=R;++r){
	for(int i=0;i<N*N;++i){
	  if(dp[i][r] <= R) ans = r;
	  else continue;
	  for(int j=0;j<SZ(to[i]);++j){
		int v = to[i][j];
		dp[v][r+1] = min(dp[v][r+1],
						 dp[i][r]+cost[i][j]);
	  }
	}
  }

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

Measured memory_bytes: 32776
#include<stdio.h>
#include<ctype.h>
int main(){
    char moji[500],mojia[500];
    int i,j;
    scanf("%[^\n]",moji);
    for(i=0;i<500;i++){
        mojia[i]=toupper(moji[i]);
    }
    if(mojia[i]!='\0')printf("%s\n",mojia);
    return 0;
}

Measured memory_bytes: 524
import java.util.*;

class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int N = S.length();
		int cnt=0;
		for (int i=0;i<N;i++) {
			if (S.charAt(i)=='o') {
				cnt++;
			}
		}
		if (15-N+cnt>=8) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

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

int Z, Y, M, D;

void solve(void);

inline bool is_leap(int y) { return y % 3 == 0; }
inline bool is_big(int m) { return m % 2 == 1; }

int main() {
  cin >> Z;
  for (int zi = 1; zi <= Z; ++zi) {
    cin >> Y >> M >> D;
    solve();
  }

  return 0;
}

void solve(void) {
  int res = 0;

  while (Y != 1000) {
    ++D;
    if (is_leap(Y)) {
      if (D > 20)
        D = 1, ++M;
    }
    else {
      if (is_big(M)) {
        if (D > 20)
          D = 1, ++M;
      }
      else {
        if (D > 19)
          D = 1, ++M;
      }
    }

    if (M > 10)
      M = 1, ++Y;

    ++res;
  }

  cout << res << "\n";
}

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

int main()
{
    int N;
    cin >> N;
    int Pi[N][10];
    rep(i, N) {
        rep(j, 10) {
            cin >> Pi[i][j];
        }
    }
    int Ci[N][11];
    rep(i, N) {
        rep(j, 11) {
            cin >> Ci[i][j];
        }
    }
    int maxValue = -(1 << 30);
    for (int i = 1; i < 1024; i++) {
        int value = 0;
        rep(k, N) {
            int openCount = 0;
            rep(h, 10) {
                if ((i & (1 << h)) > 0 && Pi[k][h] > 0) {
                    openCount++;
                }
            }
            value += Ci[k][openCount];
        }
        maxValue = max(maxValue, value);
    }
    cout << maxValue << endl;
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int check(int x,int y, vvi ch) {
  int flg = 1;
  REP(i,8) {
    if(ch[x][i]==1) {
      flg=0;
      break;
    }
    if(ch[i][y]==1)  {
      flg=0;
      break;
    }
    if(x+i<8&&y+i<8) {
      if(ch[x+i][y+i]==1)  {
      flg=0;
      break;
    }
    }
    if(x-i>=0&&y+i<8) {
      if(ch[x-i][y+i]==1)  {
      flg=0;
      break;
    }
    }
    if(x+i<8&&y-i>=0) {
      if(ch[x+i][y-i]==1)  {
      flg=0;
      break;
    }
    }
    if(x-i>=0&&y-i>=0) {
      if(ch[x-i][y-i]==1)  {
      flg=0;
      break;
    }
    }
  }
  return flg;
}

int main() {
  int n,q;
  cin >> n;
  vi s(n);
  REP(i,n) cin >> s[i];
  cin >> q;
  vi t(q);
  REP(i,q) cin >> t[i];
  sort(ALL(s));
  sort(ALL(t));
  int ans=0;
  REP(i,q) {
    if(binary_search(ALL(s),t[i])) ans++;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3392
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    ll x = n;
    ll sum = 0;

    while(x>0){
        sum += x%10;
        x /= 10;
    }

    (n%sum == 0) ? Yes() : No();


}

Measured memory_bytes: 256
from collections import deque
 
n = int(input())
a = list(map(int,input().split()))
d = deque(a)
 
tmp = []
cnt = 0
while d:
  v = d.popleft()
  if len(tmp)>=2:
    if not (v >= tmp[-1] >= tmp[0] or v <= tmp[-1] <= tmp[0]):
      tmp = []
      cnt += 1
  tmp.append(v)

print(cnt+1 if tmp else cnt)

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

class myvector {
	vector<vector<int>> m_data;

public:
	explicit myvector( int N ):
		m_data( N )
	{}

	void pushBack( int t, int x ) {
		m_data[t].push_back( x );
	}

	void dump( int t ) const {
		for( size_t i = 0; i < m_data[t].size(); ++i ) {
			cout << m_data[t][i];

			if( i < m_data[t].size()-1 ) {
				cout << ' ';
			}
		}

		cout << '\n';
	}

	void clear( int t ) {
		m_data[t].clear();
	}
};

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

	int n, q;
	cin >> n >> q;

	myvector a( n );
	for( int i = 0; i < q; ++i ) {
		int cmd, t, x;
		cin >> cmd >> t;

		if( cmd == 0 ) {
			cin >> x;
			a.pushBack( t, x );
		}
		else if( cmd == 1 ) {
			a.dump( t );
		}
		else if( cmd == 2 ) {
			a.clear( t );
		}
	}

	return 0;
}



Measured memory_bytes: 5780
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    const ll mod = 1e9+7;
    ll N; cin >> N;
    vl T(N), A(N);
    REP(i, N) cin >> T[i];
    REP(i, N) cin >> A[i];
    ll mxidx = 0, mxval = -1;
    REP(i, N){
        if(mxval < T[i]){
            mxval = T[i]; mxidx = i;
        }
    }
    if(A[0] != mxval || A[mxidx] != T[mxidx]){
        cout << 0 << endl; return 0;
    }
    
    ll ans = 1; ll mxv_tmp = -1;
    REP(i, mxidx){
        if(T[i] == mxv_tmp){
            ans *= T[i]; ans %= mod;
        }
        else mxv_tmp = T[i];
    }
    mxv_tmp = -1;
    for (ll i = N-1; i > mxidx; i--) {
        if(A[i] == mxv_tmp){
            ans *= A[i]; ans %= mod;
        }
        else mxv_tmp = A[i];
    }
    cout << ans % mod << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vec vector
#define vi vec<int>
#define vvi vec<vec<int>>
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define SORT(a) stable_sort(ALL(a))
#define RSORT(a) stable_sort(RALL(a))
#define REV(a) reverse(ALL(a))
#define UNIQUE(a) a.erase(unique(ALL(a)), end(a))
#define lambda(i) [=](auto i)
#define compare(i, j) [=](auto i, auto j)
#define min_of(a) *min_element(ALL(a))
#define max_of(a) *max_element(ALL(a))
#define sum(a) accumulate(ALL(a), 0)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(a) (int)(a).size()
#define REP(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define RREP(i, n) for (auto i = n - 1; i != static_cast<decltype(i)>(-1); i--)
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (auto i = b - 1; i != a; i--)
#define EACH(i, a) for (auto&& i: (a))
using namespace std;

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

int ceil_div(int X, int Y) {
  return (X - 1) / Y + 1;
}

struct union_find {
  vi data;
  union_find(int size) : data(size, -1) { }
  bool union_set(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool find_set(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

vi cum(vi V) {
  vi U(SZ(V));
  partial_sum(ALL(V), begin(U));
  return U;
}

void solve() {
  int n;
  int ans = 0;

  cin >> n;
  // vi v(n);
  FOR(i, 1, n + 1) {
    if ((i % 3) * (i % 5) > 0) {
      ans += i;
    }
  }

  cout << ans << endl;
  // REP(i, n) {
  //   cout << v[i];
  // }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  solve();
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

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

    vector<pair< pair<string, int> ,int > > v;

    string a;
    int b;
    
    for(int i=0;i<num;i++){
        cin >> a >> b;
        v.push_back(make_pair(make_pair(a,100-b),i+1));
    }

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

    for(int i=0;i<num;i++){
        cout << v[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <numeric>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <deque>
#include <bitset>
#include <cstring>
#include <sstream>
#include <complex>

#define f first
#define s second
#define ll long long
#define ld double
#define pb push_back
#define all(x) x.begin(),x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment
 
using namespace std;
 
double start_moment = 0;
double get_runtime() { return 1.0*clock()/CLOCKS_PER_SEC; }
void reset_timer() { start_moment = get_runtime(); }
double timer_time() { return get_runtime() - start_moment; }
void runtime(){cout<<fixed<<setprecision(5)<<get_runtime()<<'\n';}
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
template <class T>void read(vector<T> &a,ll n){T x; a.clear();for(ll i=0;i<n;i++){cin>>x;a.pb(x);}}
template <class T>void write(vector<T> &a){for(T x : a) cout<<x<<' ';cout<<'\n';}

string s;

int main()
{
    ios_base::sync_with_stdio(0);
//    freopen("INPUT.txt","r",stdin);
//    freopen("OUTPUT.txt", "w", stdout);
    
    cin>>s;
    int res=0;
    int cnt=(s[0]=='R');
    for(int i=1;i<s.size();i++)
        if(s[i]==s[i-1])
            cnt++;
        else
        {
            if(s[i-1]=='R')
                res=max(res,cnt);
            cnt=1;
        }
    if(s[2]=='R')
        res=max(res,cnt);
    cout<<res;
    
    
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i< (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
//long long ccw(const Point& A, const Point& B, const Point& C) {
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}

int main() { // E,F , virtual
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n, k; cin >> n >> k;
	for (int i = 0; i < n; i++) {
		char x; cin >> x;
		if (i == k - 1) {
			cout << (char)(x - 'A' + 'a');
		}
		else
			cout << x;
	}




}


Measured memory_bytes: 256
l = input().rstrip()
n = len(l)

mod = 10**9 + 7
c = 1
d = 0
for i in range(n):
    d *= 3
    if l[i] == '1':
        d += c
        c <<= 1
    d %= mod
    c %= mod

print((c+d)%mod)

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

int main(){
    string s;
    cin>>s;
    int x,y;
    cin>>x>>y;
    vector<int> xm;
    vector<int> ym;
    int sum=0;
    int cnt=0;
    int p=0;
    for(int i=0;i<=s.size();i++){
        if(i==s.size() || s[i]=='T'){
            if(p!=0){
                if(p%2==0){
                    xm.push_back(cnt);
                }
                else{
                    ym.push_back(cnt);
                }
            }
            cnt=0;
            p++;
        }
        else{
            sum++;
            if(p==0){
                x--;
            }
            cnt++;
        }
    }
    sum+=5;
    
    const int OFF=sum+2;
    vector<vector<int>> xdp(xm.size()+1,vector<int>(2*(sum+2),0));
    xdp[0][OFF]=true;
    for(int i=0;i<xm.size();i++){
        for(int j=0;j<xdp[i].size();j++){
            if(j-xm[i]>=0) xdp[i+1][j]|=xdp[i][j-xm[i]];
            if(j+xm[i]<xdp[i].size()) xdp[i+1][j]|=xdp[i][j+xm[i]];
        }
    }
    
    vector<vector<int>> ydp(ym.size()+1,vector<int>(2*(sum+2),0));
    ydp[0][OFF]=true;
    for(int i=0;i<ym.size();i++){
        for(int j=0;j<ydp[i].size();j++){
            if(j-ym[i]>=0) ydp[i+1][j]|=ydp[i][j-ym[i]];
            if(j+ym[i]<ydp[i].size()) ydp[i+1][j]|=ydp[i][j+ym[i]];
        }
    }
    if(0<=OFF+x && OFF+x<xdp[0].size() && 0<=OFF+y && OFF+y<ydp[0].size()){
        cout<<(xdp[xm.size()][OFF+x] && ydp[ym.size()][OFF+y] ? "Yes" : "No")<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 125696
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
#define rep(i,n) for (int i = 0; i < (n); ++i)

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;}
int h,w;
char s[22][22];
int d[22][22];

vector<int>ans(200003,0);
vector<int> g[200005];
void dfs(int v,int p=-1){
  for(int u: g[v]){
    if(u==p)continue;
    ans[u] += ans[v];
    dfs(u,v);
  }
}

int main(){
  int n,q;cin>>n>>q;
  rep(i,n-1){
    int a,b;cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ans.resize(n);
  rep(i,q){
    int p,x;
    cin>>p>>x;p--;
    ans[p] += x;
  }
  dfs(0);
  rep(i,n){
    cout<<ans[i]<<" ";
  }

  return 0;
}

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

using namespace std;
using LLONG = long long;

int main()
{
    string O, E;
    cin >> O >> E;
    int size = min(O.size(), E.size());
    for (int i = 0; i < size; ++i)
        cout << O[i] << E[i];
    if (O.size() > E.size()) cout << O.back();
    cout << endl;

    return 0;
}

Measured memory_bytes: 256