akhauriyash/Code-Regression huggingface dataset:
/***     
 * When I wrote this
 * only God & I understood
 * what I was doing
 * Now, God only knows 
 /***/ 
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip>
#include<map>
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
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;}
//fixed<< setprecision(2)
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll a,b,c,k;
    while(cin>>a>>b>>c>>k)
    {
        while(a>=b&&k>0)
        {
            b*=2;
            k--;
        }
        while(b>=c&&k>0)
        {
            c*=2;
            k--;
        }
        if(a<b&&b<c)cout<<"Yes\n";
        else cout<<"No\n";
    }
}

Measured memory_bytes: 3132
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};

map<l_l, ll> srch;
ll cnt = 0;
vector<pair<l_l, ll> > par;
vector<l_l> g;
vector<vector<char> > p;
vector<vector<char> > aho;
vector<vector<ll> > child;
vector<l_l> side;
ll w, h;

l_l rec(char c, l_l po) {
	p[po.first][po.second] = '/';
	srch[l_l(po.first, po.second)] = cnt;
	g[cnt].first += po.second;
	if(po.first == 0 || (p[po.first - 1][po.second] != '.' && aho[po.first][po.second] != aho[po.first - 1][po.second])) {
		side[cnt].first = min(side[cnt].first, po.second);
		side[cnt].second = max(side[cnt].second, po.second);
	}
	l_l res = l_l(-1, -1);
	if(po.first - 1 >= 0 && p[po.first - 1][po.second] != '.' && aho[po.first - 1][po.second] != aho[po.first][po.second]) res = l_l(po.first - 1, po.second);
	REP(i, 4) {
		ll nh = po.first + dh[i];
		ll nw = po.second + dw[i];
		if(nh >= 0 && nh < h && nw >= 0 && nw < w && p[nh][nw] == c) {
			res = max(res, rec(c, i_i(nh, nw)));
		}
	}
	return res;
}

bool d;

void dfs(ll n) {
	REP(i, child[n].size()) {
		dfs(child[n][i]);
		g[n].first += g[child[n][i]].first;
		g[n].second += g[child[n][i]].second;
	}
	if((2 * side[n].first * g[n].second >= 2 * g[n].first + g[n].second || 2 * g[n].first + g[n].second >= 2 * (side[n].second + 1) * g[n].second)) {
		d = false;
	}
}

int main(void) {
	while(true) {
		srch.erase(srch.begin(), srch.end());
		cnt = 0;
		par.resize(0);
		g.resize(0);
		d = true;
		child.resize(0);
		side.resize(0);

		cin>>w>>h;
		if(w == 0 && h == 0) break;
		p.resize(h);
		REP(i, h) p[i].resize(w);
		REP(i, h) {
			REP(j, w) cin>>p[i][j];
		}
		aho.resize(h);
		REP(i, h) aho[i].resize(w);
		REP(i, h) {
			REP(j, w) {
				aho[i][j] = p[i][j];
			}
		}
		reverse(ALL(aho));
		reverse(ALL(p));
		REP(i, h) {
			REP(j, w) {
				if(p[i][j] != '.' && p[i][j] != '/') {
					g.pb(l_l(0, 4));
					side.pb(l_l(INF, -INF));
					par.pb(pair<l_l, ll>(rec(p[i][j], i_i(i, j)), cnt));
					if(i == 0) par[0].first = l_l(-1, -1);
					++cnt;
				}
			}
		}
		vector<l_l> parhoge(par.size());
		REP(i, par.size()) {
			if(par[i].first != l_l(-1, -1)) parhoge[i].first = srch[par[i].first];
			else parhoge[i].first = -1;
			parhoge[i].second = par[i].second;
		}
		child.resize(cnt);
		REP(i, parhoge.size()) {
			if(parhoge[i].first != -1) child[parhoge[i].first].pb(parhoge[i].second);
		}
		dfs(0);
		if(d) cout<<"STABLE"<<endl;
		else cout<<"UNSTABLE"<<endl;
	}
}

Measured memory_bytes: 3172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String... args) throws IOException {
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final StringBuilder sb = new StringBuilder();
        while (true) {
            final String[] lines = br.readLine().split(" ");
            final int x = Integer.parseInt(lines[0]);
            final int y = Integer.parseInt(lines[1]);
            if ((x | y) == 0) break;
            sb.append(x < y ? x + " " + y : y + " " + x).append("\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 25068
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main()
{
	int N, M, ans = 0;
	string s;
	map<string, int> A;

	cin >> N;
	rep(i, N) {
		cin >> s;
		A[s]++;
	}

	cin >> M;
	rep(i, M) {
		cin >> s;
		A[s]--;
	}

	for (auto itr = A.begin(); itr != A.end(); itr++) ans = max(ans, itr->second);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,ans;
  cin >> a >> b >> c;
  
  ans = c - (a-b);
  
  if(ans >= 0){    
    cout << ans << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll n; cin>>n;
    string s; cin>>s;
    vector<ll> e(n), w(n);
    rep(i,n-1){
        w[i+1]+=w[i];
        if(s[i]=='W') w[i+1]++;
    }

    for(ll i=n-1; i>0; i--){
        e[i-1]+=e[i];
        if(s[i]=='E') e[i-1]++;
    }

    ll res=1e10;
    rep(i,n) chmin(res, w[i]+e[i]);
    cout<<res<<endl;
    return 0;
}

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

int main() {
  string s;
  vector<int> v;
  cin >> s;
  int at_begin = 0;
  int at_last = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'A' || s.at(i) == 'T' || s.at(i) == 'C' || s.at(i) == 'G') {
      at_last = i+1;
    }
    else {
      if (at_last != 0) {
        v.push_back(at_last - at_begin);
      }
      at_begin = i+1;
    }
  }
  if (at_last != 0) {
    v.push_back(at_last - at_begin);
  }
  if (v.size() == 0) {
    cout << 0 << endl;
  }
  else {
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    cout << max(v.at(0), 0) << endl;
  }
}


Measured memory_bytes: 256
var fs = require("fs");
 
fs.readFile("/dev/stdin", "utf-8", function(err, data) {
  if(!err) {
    var str = data.split("\n")[0];
    var k = data.split("\n")[1] - 0;
    console.log(Array(str.length).fill().map(function (_, i) {
      return Array(k).fill().map(function (_, j) {
        return  str.substr(i, j + 1);
      });
    }).reduce(function (_, a) {
      return _.concat(a);
    }).reduce(function (n, s, arr) {
      n.indexOf(s) >= 0 ? void(0) : n.push(s);
      return n;
    }, []).sort()[k-1]);
  } else {
    throw err;
  }
});

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

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; }


// std::vector Declaration
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
   return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// std::vector Initialization
template<typename T>
void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U>
void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
   os << "[";
   bool a = 1;
   for (auto e : v ) {
      os << (a ? "" : " "); 
      os << e;
      a = 0;
   }
   os << "]";
   return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
   os << "(" << p.first << " " << p.second << ")";
   return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
   os << "{";
   bool a = 1;
   for (auto e : st) {
      os << (a ? "" : " ");
      os << e;
      a = 0;
   }
   os << "}";
   return os;
}

// std::multiset Debug
template<typename T>
ostream& operator<<(ostream& os, const multiset<T>& st) {
   os << "{";
   bool a = 1;
   for (auto e : st) {
      os << (a ? "" : " ");
      os << e;
      a = 0;
   }
   os << "}";
   return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
   os << "{";
   bool a = 1;
   for (auto e : mp) {
      os << (a ? "" : " ");
      os << e.first << ":" << e.second;
      a = 0;
   }
   os << "}";
   return os;
}

// std::tuple Debug
template<int N, class Tuple>
void out(ostream& os, const Tuple& t){}
template<int N, class Tuple, class H, class ...Ts>
void out(ostream& os, const Tuple& t) {
   if (N) os << " ";
   os << get<N>(t);
   out<N+1,Tuple,Ts...>(os, t);
}
template<class ...Ts>
ostream& operator<<(ostream& os, const tuple<Ts...>& t) {
   os << "(";
   out<0,tuple<Ts...>,Ts...>(os, t);
   os << ")";
   return os;
}

// Debug
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl


struct edge { int to, cost; };
ostream& operator<<(ostream& os, const edge& e) {
   os << "(" << e.to << ", " << e.cost << ")";
   return os;
}

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

int main()
{
   int N; cin >> N;
   vector<LL> x(N), y(N);
   for (int i = 0; i < N; ++i) {
      cin >> x[i] >> y[i];
   }

   map<pair<LL,LL>,int> cnt;
   for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
         if (i == j) continue;
         ++cnt[make_pair( x[i]-x[j], y[i]-y[j] )];
      }
   }

   int ans = N;
   for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
         if (i == j) continue;
         chmin(ans, N - cnt[make_pair( x[i]-x[j], y[i]-y[j] )]);
      }
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 384
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

#define MAX_N 1000000007
#define INF 100000000000000

long long comb[100100][50];

int main(){
  long long n,m,temp;
  cin >> n >> m;
  temp = m;
  vector<long long> p;
  long long ans = 1;
  for(int i=2;i<100000;i++){
    long long count = 0;
    while(temp%i == 0){
      temp /= i;
      count++;
    }
    p.push_back(count);
  }
  if(temp != 1) p.push_back(1);

  for(int i=0;i<100100;i++){
    comb[i][0] = 1;
    if(i < 50) comb[i][i] = 1;
  }

  for(int i=2;i<100100;i++){
    for(int j=1;j<50;j++){
      comb[i][j] = comb[i-1][j-1]+comb[i-1][j];
      comb[i][j] %= 1000000007;
    }
  }

  for(int i=0;i<p.size();i++){
    long long m;
    m = p[i];
    ans *= comb[n-1+m][m];
    ans %= 1000000007;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 40308
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int main()
{
  int z;
  string s;
  cin>>s;
  z=0;
  if(s[0]==s[1] || s[1]==s[2] ||s[2]==s[3])
  {
    z=1;
  }

  if(z==1)
  {
    cout<<"Bad\n";
  }
  else
  cout<<"Good\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int ok[1000][1000];

vector<vector<int> > color(int n, int d){
	vector<vector<int> > g(2*n);
	for(int j = 0; j < 2*n; j++){
		g[j].resize(2*n, 0);
	}
	int b = 0;
	while(d % (1<<b) == 0) b++;
	if(b % 2 == 1){
		for(int i = 0; i < 2*n; i++){
			for(int j = 0; j < 2*n; j++){
				int c = (b-1)/2;
				int num = (i>>c) + (j>>c);
				g[i][j] = num % 2;
			}
		}
	} else if(b % 2 == 0){
		for(int i = 0; i < 2*n; i++){
			for(int j = 0; j < 2*n; j++){
				int c = (b-2)/2;
				int num = (i>>c);
				g[i][j] = num % 2;
			}
		}
	}
	return g;
}
int main(){
	cin.sync_with_stdio(0); cin.tie(0);
	int n;
	int d1, d2;
	cin >> n >> d1 >> d2;
	vector<vector<int> > c1 = color(n, d1);
	vector<vector<int> > c2 = color(n, d2);
	vector<vector<int> > c3 = c1;
	vector<pair<int,int> > g[4];
	for(int i = 0; i < 2*n; i++){
		for(int j = 0; j < 2*n; j++){
			g[c1[i][j] * 2 + c2[i][j]].push_back({i,j});
		}
	}
	for(int j = 0; j < 4; j++){
		if(g[j].size() >= n*n){
			for(int i = 0; i < n*n; i++){
				cout << g[j][i].first << " " << g[j][i].second << '\n';
			}
			return 0;
		}
	}
}


Measured memory_bytes: 9744
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int t;
  cin>>t;
  while(t--){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int l=s.length();
    int ans=0;
    for(int i=0;i<=l;i++){
      string t=s;
      int p=0;
      for(int j=0;j<l;j++){
	int x=n-1+(i==j);
	(p+=x)%=(int)t.size();
	t.erase(t.begin()+p);
	//cout<<p<<endl;
	//p++;
	p%=(int)t.size();
	int g=0,b=0;
	for(int k=0;k<(int)t.size();k++){
	  g+=t[k]=='G';
	  b+=t[k]=='B';
	}
	//cout<<s<<" "<<t<<endl;
	if(g*b) continue;
	ans=max(ans,b);
	break;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3168
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		String Triangle_line = input.readLine();

		String[] Triangle_line_array = Triangle_line.split(" ");

		// ??????a
		double base_a = Double.parseDouble(Triangle_line_array[0]);

		// ???b
		double side_b = Double.parseDouble(Triangle_line_array[1]);

		// ?§????C
		int angle_C = Integer.parseInt(Triangle_line_array[2]);

		// ??¢??????????????????????§????C???????§???¢??°????±???????
		double trigonometric_function_sin = Math.sin(Math.toRadians(angle_C));

		// ????????????????????????
		double trigonometric_function_cos = Math.cos(Math.toRadians(angle_C));

		double area_S = base_a * side_b * trigonometric_function_sin / 2;

		// ????????????
		double side_c_square = base_a * base_a + side_b * side_b - 2 * base_a * side_b * trigonometric_function_cos;

		// ??????
		double side_c = Math.sqrt(side_c_square);

		// ????§???¢???????????????,??¨
		double three_sum_L = base_a + side_b + side_c;

		// ??????
		double height_h = 2 * area_S / base_a;

		System.out.printf("%.8f",area_S);

		System.out.println("");

		System.out.printf("%.8f",three_sum_L);

		System.out.println("");

		System.out.printf("%.8f",height_h);

		System.out.println("");


	}

}

Measured memory_bytes: 24560
N = gets.to_i

l = N.to_s.length

a = [3,5,7]

all = 0

(l + 1).times do |i|
  next if l == 0
  
  a.repeated_permutation(i) do |bits|
    next if bits.count(7) == 0
    next if bits.count(5) == 0
    next if bits.count(3) == 0
    
    if (i == l)
      num = ""
      bits.each do |j|
        num += j.to_s
      end
      
      next if N < num.to_i
    
    end
    
    all += 1
  end


end

puts all


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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var N = inputArray[0];
			var K = inputArray[1];
			long mod = 1000000000 + 7;
			//10^10があるので、iこ選ぶときとj個選ぶときの和が等しくなることはない
			long count = 0;
			for (long i = K; i <= N+1; i++) {
				//i個選ぶときの和のパターン数を考える。　最小と最大の間にあるすべての和は表現できる
				long max = (N + (N-i+1))*i/2;//Nから順番にK個選んだときの和
				long min = (i - 1) * i / 2;
				count += max - min + 1;
				count = count % mod;
			}

			//答えの出力
			var ans = count;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


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

#define MAX 100000

vector<int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX],parent[MAX],lowest[MAX],timer;

void dfs(int current,int prev){
	//?????????current????¨????????????´????????????
	prenum[current]=lowest[current]=timer;
	timer++;
	visited[current]=true;
	int next;
	for (int i = 0; i < G[current].size(); ++i) {
		next=G[current][i];
		if(!visited[next]){
			//?????????current???????????????next????¨????????????´????????????
			parent[next]=current;
			dfs(next,current);
			//?????????next?????¢?´¢?????????????????´????????????
			lowest[current]=min(lowest[current],lowest[next]);
		}else if(next!=prev){
			//??¨??????current-->next???Back-edge?????´????????????
			lowest[current]=min(lowest[current],prenum[next]);
		}
		}
	//?????????current?????¢?´¢?????????????????´????????????
}


void art_points(){
	for (int i = 0; i < N; ++i) {visited[i]=false;}
	timer=1;
	//lowest????¨????
	dfs(0,-1);//0 ==root
	set<int> ap;
	int np=0;
	for (int i = 1; i < N; ++i) {
		int p=parent[i];
		if(p==0)np++;
		else if(prenum[p]<=lowest[i])ap.insert(p);
	}
	if(np>1)ap.insert(0);
	for (set<int>::iterator it=ap.begin();it !=ap.end();it++) {cout<<*it<<endl;}
}


int main(){
	int m;
	cin>>N>>m;
	for (int i = 0; i < m; ++i) {
		int s,t;
		cin>>s>>t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	art_points();
	return 0;
}

Measured memory_bytes: 6840
'use strict'
function main(inp) {
  inp = inp.trim().split(' ').map(n => Number(n));
  const gcd = (x, y) => y === 0 ? x : gcd(y, x%y)
  const divisors = n => {
    let dest = []
    for (let i = 1; i < Math.floor(Math.pow(n, 0.5) + 1); i++) {
      if (n % i === 0) {
        dest.push(i)
        if (Math.floor(n / i) !== i) {
          dest.push(Math.floor(n / i))
        }
      }
    }
    return dest.sort((a, b) => a - b)
  }

  const G = gcd(...inp)
  let D = divisors(G)

  let arr = [1]
  for (let i = 1; i < D.length; i++) {
    let isSO = true
    for (let j = 1; j < arr.length; j++) {
      if (gcd(arr[j], D[i]) !== 1) {
        isSO = false
        break;
      }
    }
    if (isSO) arr.push(D[i])
  }
  console.log(arr.length);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 11468
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner in=new Scanner(System.in);
    int n=in.nextInt();
    int k=in.nextInt();
    ArrayList<Integer> arr=new ArrayList<Integer>(n);
    for(int i=0;i<n;i++)
      arr.add(in.nextInt());
    Collections.sort(arr);
    int ans=0;
    for(int i=0;i<k;i++)
      ans+=arr.get(i);
    System.out.println(ans);
  }
}

Measured memory_bytes: 30280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  int B;
  int C;
  int D;
  cin >> A >> B >> C >> D;
  if (A+B > C+D) {
    cout << "Left" << endl;
  }
  else if (A+B == C+D){
    cout << "Balanced" << endl;
  }
  else {
 	cout << "Right" << endl;
  }
  
  
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int a[3],b[3],c[3],d[3],e[3],f[3];
	for(int i=0;i<3;i++)
	{
		scanf("%d %d %d %d %d %d",&a[i],&b[i],&c[i],&d[i],&e[i],&f[i]);
		if(f[i]-c[i]<0){e[i]-=1;f[i]+=60;}
		if(e[i]-b[i]<0){d[i]-=1;e[i]+=60;}
		printf("%d %d %d\n",d[i]-a[i],e[i]-b[i],f[i]-c[i]);
	}
	return 0;
}
//8:25.081クリア


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
const int maxn=300005;

int n,q[maxn],t,ans=1<<30;
char s[maxn];

int main(){
    scanf("%d",&n),scanf("%s",s+1);
    for(int i=1;i<=n;i++) q[i]=q[i-1]+(s[i]=='E');
    t=q[n];
    for(int i=1;i<=n;i++) ans=min(ans,(i-1-q[i-1])+(t-q[i]));
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int M;
  M = max({A, B, C});
  
  int sum = 3 * M;
  bool can = true;
  int ans;
  while(can) {
  if((sum) % 2 == (A + B + C) % 2) {
    can = false;
    ans = (sum - (A + B + C)) / 2;
  }
  sum +=3;
  }
    cout << ans << endl;
}
      

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  string a;
  cin >> a;
  
  if(a[0]==a[2]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<cmath>
#include<map>
#include<string>

using namespace std;

int main()
{
    long long N, D;
    int count = 0;

    cin >> N >> D;

    for (int i = 0; i < N; i++){
        long long x, y;
        cin >> x >> y;

        if(((x * x + y * y) <= (D * D))){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3628
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let a: i8 = read();
    let b: i8 = read();
    let mut socket_num = 1;
    let mut power_stripe_num = 0;
    while socket_num < b {
        socket_num += a - 1;
        power_stripe_num += 1;
    }
    println!("{}", power_stripe_num);
}


Measured memory_bytes: 4352
function main(input) {
  input = input.trim();
  const [a,b] = input.split(" ").map(Number);
 
  if(a>b){
    if(b==1){
      console.log("Bob");
    }else{
      console.log("Alice");
    }
  }else if(a<b){
    if(a==1){
      console.log("Alice");
    }else{
      console.log("Bob");
    }
  }else{
    console.log("Draw");
  }
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef pair<ll, ll> pint;


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

class Dice
{
public:
  vint num;


  Dice(vint num);
  void roll(char d);
  ll top();
  ll front();
  ll left(){return num[3];}
  ll right(){return num[2];}
  ll right(ll top, ll front);
  void print(){
    rep(i,6){
      cout<<this->num[i]<<" ";
    }
    cout<<endl;
  }
  bool check(Dice obj){
    rep(i,6){
      if(this->num[i] != obj.num[i]) return false;
    }
    // rep(i,6)cout<<this->num[i]<<" ";
    // cout<<endl;
    // rep(i,6)cout<<obj.num[i]<<" ";
    // cout<<endl;
    // this->print();
    // obj.print();
    return true;
  }

  void rotate(){
    this->roll('E');
    this->roll('N');
    this->roll('W'); // rotate clockwise
  }

  bool operator ==(Dice obj){

    rep(i,4){
      rep(j,4){
        if(obj.check(*this)) return true;
        obj.rotate();
      }
      obj.roll('E');   
    }

    obj.roll('S');
    rep(j,4){
      if(obj.check(*this)) return true;
      obj.rotate();
    }

    obj.roll('N');
    obj.roll('N');

    rep(j,4){
      if(obj.check(*this)) return true;
      obj.rotate();
    }


    return false;
  }




};

Dice::Dice(vint num){
  this->num = num;
}

void Dice::roll(char d){
  vint tmp_num = num;
  if(d == 'E'){
    num[2] = tmp_num[0];
    num[0] = tmp_num[3];
    num[3] = tmp_num[5];
    num[5] = tmp_num[2];
  }else if(d == 'N'){
    num[0] = tmp_num[1];
    num[1] = tmp_num[5];
    num[5] = tmp_num[4];
    num[4] = tmp_num[0];
  }else if(d == 'S'){
    num[0] = tmp_num[4];
    num[4] = tmp_num[5];
    num[5] = tmp_num[1];
    num[1] = tmp_num[0];
  }else if(d == 'W'){
    num[0] = tmp_num[2];
    num[2] = tmp_num[5];
    num[5] = tmp_num[3];
    num[3] = tmp_num[0];
  }else{
    assert(false);
  }
  // cout<<d<<endl;

}

ll Dice::top(){
  return num[0];
}

ll Dice::front(){
  return num[1];
}

ll Dice::right(ll top, ll front){
  
  ll cnt = 0;
  while(this->top() != top && cnt < 4){
    this->roll('E');
    cnt++;
  }
  cnt = 0;
  while(this->top() != top && cnt < 4){
    this->roll('N');
    cnt++;
  }

  cnt = 0;
  while(this->front() != front && cnt < 4){
    this->rotate();
    cnt++;
  }

  assert(this->top() == top && this->front() == front);

  return this->right();
}


void print(const vint& v)
{
  std::for_each(v.begin(), v.end(), [](int x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}

int main() {


  cout<<fixed<<setprecision(10);

  ll n;cin>>n;
  vector< Dice > vec;
  rep(i, n){
    vint v(6);
    rep(j,6) cin>>v[j];
    vec.emplace_back(v);
    // vec.back().print();
  }

  rep(i,n){
    rep(j,n){
      // cout<<i<<" "<<j<<endl;
      if(i >= j) continue;
      if(vec[i] == vec[j]){
        // cout<<i<<" "<<j<<endl;
        cout<<"No"<<endl;
        return 0;
      }
    }
  }

  cout<<"Yes"<<endl;
  // cout<<(int)(vec[0]==vec[2])<<endl;
}





//




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

int main() {
  int n;
  cin>>n;  
  vector<long>a(n);
  long ans=0;
  rep(i,n){
    cin>>a.at(i);
    ans+=a.at(i);
  }
  if(ans%2==0){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

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

using namespace std;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	string s;
	int k;
	cin >> s >> k;

	if(k <= 100) {
		string t = "";
		for(int i = 0; i < k; i++) {
			t += s;
		}
		long long ans = 0;
		for(int i = 1; i < t.length(); i++) {
			if(t[i] == t[i-1]) {
				ans++;
				t[i] = '*';
			}
		}
		cout << ans;
	}
	else {
		string t = "";
		for(int i = 0; i < 100; i++) {
			t += s;
		}
		long long ans = 0;
		for(int i = 1; i < t.length(); i++) {
			if(t[i] == t[i-1]) {
				t[i] = '*';
			}
		}
		vector<int> v;
		long long rem = k - 100;
		int cnt = 0;
		for(int i = 0; i < t.length(); i++) {
			if(i % (s.length()) == 0 and i != 0) {
				v.push_back(cnt);
				cnt = 0;
			}
			if(t[i] == '*') cnt++;
		}
		v.push_back(cnt);
		for(auto i : v) {
			ans += i;
		}

		ans += (v[99]) * (rem/2);
		ans += (v[98]) * (rem - rem/2);
		cout << ans << '\n';
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int tate,yoko,menseki,nagasa;
	scanf("%d %d",&tate,&yoko);
	
	menseki=tate*yoko;
	nagasa=tate*2+yoko*2;
	
	printf("%d %d\n",menseki,nagasa);
	return 0;
}

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

int main()
{
    int n;
    cin>>n;
    
    char s[101];
    char t[101];
    cin>>s>>t;
    
    std::vector<char> v;
    for(int i=0;i<n;i++){
        v.push_back(s[i]);
        v.push_back(t[i]);
    }
    
    for(auto x:v)
      cout<<x;
      cout<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
int main(void){
	
	int i,j,n,c=0,m,b;
	scanf("%d",&n);
	int a[n];
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	
	for(i=0;i<n-1;i++){
		m=i;
		for(j=i+1;j<n;j++){
			if(a[m]>a[j]){
				m=j;
			}
		}
		if(a[i]>a[m]){
			c++;
			b=a[i];
			a[i]=a[m];
			a[m]=b;
		}
		
	}

	for(i=0;i<n-1;i++){
		printf("%d ",a[i]);
	}
	printf("%d\n",a[n-1]);
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 2752
#include<bits/stdc++.h>
#define re register
using namespace std;
template <typename T>inline void read(T &x)
{
	x=0;int f=1;char c=getchar();
	for(;c>'9'||c<'0';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<3)+(x<<1)+(c^48);
	x*=f;
}
const int maxn=1e5+5;
struct edge
{
	int to,nxt;
}e[maxn<<1];
int n,k,head[maxn],cnt;
int a[maxn],rem[maxn],ans;
void add(int u,int v)
{
	e[++cnt].to=v;
	e[cnt].nxt=head[u];
	head[u]=cnt;
}
void dfs(int u)
{
	for(re int i=head[u];i!=0;i=e[i].nxt)
	{
		int v=e[i].to;
		dfs(v);
		if(rem[v]==k-1&&u!=1) 
		{
			ans++;
			rem[v]=-1;
		}
		rem[u]=max(rem[u],rem[v]+1);
	}
}
int main()
{
	read(n),read(k);
	for(re int i=1;i<=n;++i)
		read(a[i]);
	if(a[1]!=1) ++ans;
	for(re int i=2;i<=n;++i)
		add(a[i],i);
	dfs(1);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 6912
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#define INF INT_MAX
using namespace std;

int s;
int list[1000010];
int ans;
int cnt;

int main(){
	cin >> s;
	while (1){
		if (s % 2 == 0){
			list[s]++;
			cnt++;
			if (list[s] > 1)break;
			
			s /= 2;
		}
		else{
			list[s]++;
			cnt++;
			if (list[s] > 1)break;
			s = 3 * s + 1;
		}
	}

	cout << cnt << endl;

	return 0;
}

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

int main(){
  int N;cin>>N;
  vector <int> v(N);
  for(int a;a<N;++a) cin >> v[a];
  sort(v.begin(),v.end(),[](int x, int y)->bool {
    return x>y;
  });
  int ans;
  for (int i;i<N;++i){
    if(i&1) ans -= v[i];
    else    ans += v[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int stack1[ 50 ], stack2[ 49 ], stack3[ 50 ];
int sp1, sp2 = 0, sp3 = 0;

int main( void ) {
	int n, r, p, c;

	for ( ; scanf( "%d %d", &n, &r ), n; printf( "%d\n", stack1[ sp1 - 1 ] ) ) {
		sp1 = 0;
		while ( n-- )
			stack1[ sp1 ] = sp1 + 1, sp1++;

		while ( r-- ) {
			scanf( "%d %d", &p, &c );

			while ( p-- - 1 )
				stack2[ sp2++ ] = stack1[ --sp1 ];

			while ( c-- )
				stack3[ sp3++ ] = stack1[ --sp1 ];

			while ( sp2 )
				stack1[ sp1++ ] = stack2[ --sp2 ];

			while ( sp3 )
				stack1[ sp1++ ] = stack3[ --sp3 ];
		}
	}

	return 0;
}

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

int main() 
{
    int n;
    
    cin >> n;
    
    string blue[n];
    
	for (int i = 0; i < n; i++) 
	{
        cin >> blue[i];
    }
    
	int m;
	
    cin >> m;
    
    string red[m];
    
	for (int i = 0; i < m; i++) 
	{
        cin >> red[i];
    }

    int ans = 0;
    
    for (int i=0; i<n; i++)
	{
		string word=blue[i];
		
		int count=0;
		
		for (int j=0; j<n; j++)
		{
			if (blue[j]==word) 
			count++;
		}
		
		for (int j=0; j<m; j++)
		{
			if (red[j]==word) 
			count--;
		}
		
		ans = max(ans, count);
	}
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	std::string S;
	std::cin >> S;

	const int length = S.length();

	int hugCount(0);
	for (int i = 0; i < length / 2; ++i) {
		if (S.at(i) != S.at(length - 1 - i)) {
			++hugCount;
		}
	}

	std::cout << hugCount;

	return 0;
}



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

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);                      \
	cin.exceptions(cin.failbit);
#define int long long int //Comment when Unnecessary
#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define pii pair<int, int>
#define vi vector<int>
#define F first
#define S second
#define endl "\n" // Remove on Interactive

const int N = 300009;
const int mod = 1000000007;

int n, q, t;
string s;
set<int> st[26];

void pre()
{
}

int32_t main()
{
	IOS;
	pre();
	cin >> n >> s >> q;
	rep(i, 0, n)
	{
		st[s[i] - 'a'].insert(i);
	}
	rep(i, 0, 26)
	{
		st[i].insert(-1);
		st[i].insert(INT_MAX);
	}
	int i, l, r;
	char x;
	while (q--)
	{
		cin >> t;
		if (t == 1)
		{
			cin >> i >> x;
			if (s[i - 1] == x)
				continue;
			st[x - 'a'].insert(i - 1);
			st[s[i - 1] - 'a'].erase(st[s[i - 1] - 'a'].find(i - 1));
			s[i - 1] = x;
			continue;
		}
		cin >> l >> r;
		l--, r--;
		int ans = 0;
		rep(i, 0, 26)
		{
			int x = *st[i].lower_bound(l);
			if (x <= r)
				ans++;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 24220
n = int(input())
f = [0 for _ in range(10**4+1)]

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            k = x * x + y * y + z * z + x * y + y * z + z * x
            if k <= 10**4:
                f[k] +=1

for i in range(1, n+1):
    print(f[i])


Measured memory_bytes: 69192
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),m=s.nextInt();
		int l=Integer.MIN_VALUE,r=Integer.MAX_VALUE;
		for(int i=0;i<m;++i) {
			l=Math.max(l,s.nextInt());
			r=Math.min(r,s.nextInt());
		}
		System.out.println(Math.max(0,r-l+1));
	}
}

Measured memory_bytes: 64540
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>

using namespace std;
#define MAX 100000

int main(){
    int N;

    cin >>N;
    int i = 0;
    for (i = N; i <= 999; i++){
        int tmp1 = i / 100;
        int tmp2 = i / 10 - tmp1 * 10;
        int tmp3 = i - tmp1 * 100 - tmp2 * 10;

        if ((tmp1 == tmp2) && (tmp2 == tmp3)){
            break;
        }
    }
    cout << i << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % moder;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), moder - 2, moder) % moder * mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

int n, a[214514], b[214514];
signed main() {
	cin >> n;
	int ans = 0;
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	rep(i, 30) {
		int a_[214514], b_[214514];
		int c = (int)1 << i, d = (int)1 << (i + 1);
		rep(j, n) {
			a_[j] = a[j] % d;
			b_[j] = b[j] % d;
		}
		sort(a_, a_ + n); sort(b_, b_ + n);
		int cnt = 0;
		rep(j, n) {
			cnt += upper_bound(b_, b_ + n, d - a_[j] - 1) - lower_bound(b_, b_ + n, c - a_[j]);
			cnt += upper_bound(b_, b_ + n, d * 2 - a_[j] - 1) - lower_bound(b_, b_ + n, d + c - a_[j]);
		}
		if (cnt % 2)ans += c;
	}
	cout << ans << endl;
}


Measured memory_bytes: 6656
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    string a[10] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    while (n--){
        string s;
        cin >> s;
        int p = -1;
        REP(i,s.length()){
            int x = s[i] - '0';
            if (x == 0 && p >= 0){
                int y = s[i-1]-'0';
                cout << a[y][p % a[y].length()];
                p = -1;
            }
            if (x > 0) p++;
        }
        cout << endl;
    }

    return 0;
}

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

int main(){
    int n;
    string x;
    cin >> n >> x;
    stack<char> a;
    int cnt = 0;
    for(int i=0;i<n;i++){
        if(x[i]=='(') a.push('(');
        else if(!a.empty()){
             cnt++;
             a.pop();
        }
    }
    for(int i=0;i<n-2*cnt-a.size();i++) cout << '(';
    cout << x;
    for(int i=0;i<a.size();i++) cout << ')';
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var X = cin.ReadInt;
            var A = cin.ReadInt;
            var B = cin.ReadInt;

            var Ss = B - A;
            if(B <= A)
            {
                WriteLine("delicious");
            }
            else
            {
                if (Ss <= X)
                {
                    WriteLine("safe");
                }
                else
                {
                    WriteLine("dangerous");
                }
            }
        }
        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

Measured memory_bytes: 11220
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

const int maxn = (int) 1e5 + 10;
int a[maxn], b[maxn];

int n;

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", b + i);
  }
  return 1;
}

void solve() {
  int res = 1;
  for (int i = 0; i < n; ++i) {
    int val = -1;
    if (!i || a[i] > a[i - 1]) {
      val = a[i];
    }
    if (i == n - 1 || b[i] > b[i + 1]) {
      if (val != -1 && val != b[i]) {
        printf("0\n");
        return;
      }
      val = b[i];
    }
    if (val > a[i] || val > b[i]) {
      printf("0\n");
      return;
    }
    if (val == -1) {
      res = (long long) res * min(a[i], b[i]) % ((int) 1e9 + 7);
    }
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define gt(n) scanf("%d", &n)
#define gtll(n) scanf("%ld", &n)
#define out(n) printf("%d", n)
#define outll(n) printf("%ld", n)
#define loop(n) for(int i=0; i<n; i++)
#define MAXX 1001
#define mem(x, y) memset(x, y, sizeof(x))
#define loop1(n) for(int i=1; i<=n; i++)
#define ll long long
#define pb push_back
#define pi acos(-1)
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//(only in c)char[33];itoa(n,buffer,base);printf("%s",buffer);
#define dec_to_bin(n) std::string binary = std::bitset<64>(n).to_string();
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int main()
{
    fast;
    int n;
    string s="",s1="",s2="";

    cin>>n;
    char p;
    for(int i=0; i<n; i++)
    {
        cin>>p;
        s1+=p;
    }
    for(int i=0; i<n; i++)
    {
        cin>>p;
        s2+=p;
    }
    for(int i=1; i<=n; i++)
    {
        s+=(i+'0');
    }
    sort(s.begin(), s.end());
   // cout<<s<<endl<<s1<<endl<<s2<<endl;
    int a,b,c=0;
    do
    {
        c++;
        if(s==s1)
            a=c;
         if(s==s2)
            b=c;
    }
    while(std::next_permutation(s.begin(), s.end()));
   //cout<<a<<endl<<b<<endl;
    cout<<abs(a-b)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main(){
 int N,M;
  cin >> N >>M;
  if(N%2==1){
   for(int i=1;i<=M;i++){
    cout << M+1-i<<" " <<M+i <<endl; 
   }
  }else{
    if(N%4==0){
      int l=N-1,h=N;
      for(int i=1;i<=M;i++){
        cout<< l<< " " <<h<<endl;
        l--;
        h++;
        if(i==N/4)
          h++;
        if(h>N)
          h%=N;
      }
    }else{
     int l=N-1,h=N;
      for(int i=1;i<=M;i++){
        cout<< l<< " " <<h<<endl;
        l--;
        h++;
        if(i==N/4)
          h++;
        if(h>N)
          h%=N;
      }
    } 
    
  }
 
  return 0;
}


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

int main() {
  string s;
  cin >> s;
  set<char> st;
  for(auto ch : s) {
      st.insert(ch);
  }
  if(st.size() > 1) {
    cout << "Yes" << "\n";
  } else {
    cout << "No" << "\n";
  }
}

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

signed main() {
	int n;
	cin >> n;
	int a[n];
	long sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	long div = n * (n + 1) / 2;
	if (sum % div) {
		cout << "NO\n";
		return 0;
	}
	long k = sum / div;
	long b[n];
	for (int i = 0; i < n; i++) {
		if (i != n - 1) b[i] = a[i + 1] - a[i] - k;
		else b[i] = a[0] - a[i] - k;
	}
	for (int i = 0; i < n; i++) {
		if (b[i] > 0 || b[i] % n) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	return 0;
}

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

template<typename C>
inline void out_vector(const C& v){
  bool isFirst = true;
  for(const auto& e : v){
    if(isFirst) { isFirst = false; }
    else { cout << " "; }
    
    cout << e;
  }
  cout << endl;
}

int main() {
  int64_t n;
  cin >> n;
  priority_queue<double, vector<double>, greater<double>> v;
  
  for(int i = 0; i < n; i++){
    double a;
    cin >> a;
    v.push(a);
  }
  
  for(int i = 0; i < n-1; i++){
    double cand1 = v.top(); v.pop();
    double cand2 = v.top(); v.pop();
    auto cand = (cand1 + cand2) / 2;
    v.push(cand);
  }
  
  cout << setprecision(10) << v.top() << endl;
}

Measured memory_bytes: 256
import math

def is_prime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    i = 3
    while i <= math.sqrt(x):
        if x % i == 0:
            return False
        i += 2
    return True

n = int(input())
ans = 0
for i in range(n):
    x = int(input())
    if is_prime(x):
        ans += 1
print(ans)


Measured memory_bytes: 5676
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n,k,r,s,p;
  string t;
  cin>>n>>k>>r>>s>>p>>t;
  int ans=0;
  vector<int> flag(n);
  rep(i,n){
    flag.at(i)=0;
  }
  for(int i=0; i<n; i++){
    if(i-k>=0 && t.at(i-k)==t.at(i) && flag.at(i-k)) continue;
    if(t.at(i)=='r') ans+=p;
    else if(t.at(i)=='s') ans+=r;
    else if(t.at(i)=='p') ans+=s;
    flag.at(i)=true;
  }
  cout<<ans<<endl;
}

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

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>

void print(T x)
{
	std::cout << x <<" " ;
}


signed main(void) {
	int r;
	cin >> r  ;
	print(3 * r*r);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<string,ll> PP;
typedef pair<string,string> P;

map<P,ll> m[1111];

void Main() {
  ll n;
  R n;
  PP p[n],q[n];
  rep(i,n) {
    cin >> p[i].F >> p[i].S;
    q[i]=p[i];
    reverse(all(q[i].F));
  }
  rep(i,n) {
    if(m[0].count(P("",p[i].F))) m[0][P("",p[i].F)]=min(m[0][P("",p[i].F)],p[i].S);
    else m[0][P("",p[i].F)]=p[i].S;
  }
  ll ans=MAXL;
  rep(j,1000) {
    tr(it,m[j]) {
      P r=it->F;
      ll d=it->S;
      string s=r.F,t=r.S;
      if(s.size()) {
        bool f=1;
        rep(i,s.size()) {
          if(s[i]!=s[s.size()-1-i]) f=0;
        }
        if(f) ans=min(ans,d);
        rep(i,n) {
          ll mm=min(s.size(),p[i].F.size());
          if(p[i].F.substr(0,mm)==s.substr(0,mm)) {
            P pp=P(s.substr(mm),p[i].F.substr(mm));
            if(pp.F==""||pp.S=="") {
              if(m[j+mm].count(pp)) m[j+mm][pp]=min(m[j+mm][pp],d+p[i].S);
              else m[j+mm][pp]=d+p[i].S;
            }
          }
        }
      } else {
        bool f=1;
        rep(i,t.size()) {
          if(t[i]!=t[t.size()-1-i]) f=0;
        }
        if(f) ans=min(ans,d);
        rep(i,n) {
          ll mm=min(t.size(),q[i].F.size());
          if(q[i].F.substr(0,mm)==t.substr(0,mm)) {
            P pp=P(q[i].F.substr(mm),t.substr(mm));
            if(pp.F==""||pp.S=="") {
              if(m[j+mm].count(pp)) m[j+mm][pp]=min(m[j+mm][pp],d+q[i].S);
              else m[j+mm][pp]=d+q[i].S;
            }
          }
        }
      }
    }
  }
  if(ans==MAXL) ans=-1;
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 75148