akhauriyash/Code-Regression huggingface dataset:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X, Y, A, B, C, *PQR = map(int, read().split())
    P = PQR[:A]
    Q = PQR[A : A + B]
    R = PQR[A + B :]

    P.sort(reverse=True)
    Q.sort(reverse=True)

    vec = P[:X] + Q[:Y] + R
    vec.sort(reverse=True)
    ans = sum(vec[: X + Y])

    print(ans)
    return


if __name__ == '__main__':
    main()


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

using namespace std;

int x;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	
	cin >> x;
	for (int i = 400; i <= 1800; i += 200)
	{
		if (x >= i && x < i + 200)
		{
			printf("%d\n", 8 - (x - 400) / 200);
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3776
#include<stdio.h>
int main(){
    int x,y,tmp;
    while(1){
        scanf("%d%d",&x,&y);
        if(x==0&&y==0)break;
        if(x>y)tmp=x,x=y,y=tmp;
        printf("%d %d\n",x,y);
    }return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    int n;cin>>n;
    long double a[n];
    rep(i,n){
        cin>>a[i];
    }
    long double ans=0;
    rep(i,n){
        ans+=1/a[i];
           }
        cout<<1/ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define res register ll
#define ll long long
using namespace std;
ll n,x,ans;
inline ll read()
{
  ll X=0,w=0;
  char ch=0;
  while(!isdigit(ch))
  {
    w|=ch=='-';
    ch=getchar();
  }
  while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
  return w?-X:X;
}
inline void dfs(res l,res s)
{
  if(l%s==0)
  {
    ans+=(l<<1)-s;
    return;
  }
  ans+=l/s*s*2;
  dfs(s,l%s);
}
int main()
{
  n=read(),x=read();
  ans=n;
  if(x>=n-x)
    dfs(x,n-x);
  else
    dfs(n-x,x);
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)

sum = 0
(n-1).times {|i|
  if a[i+1] - a[i] < 0
    sum += - (a[i+1] - a[i])
    a[i+1] = a[i+1] - (a[i+1] - a[i])
  else sum += 0
  end
  }
p sum

Measured memory_bytes: 28148
import java.util.Scanner;
import java.lang.Math;
import java.util.ArrayList;
import java.util.List;
//List<String> color = new ArrayList<>();
//int[] n = new int[k];

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int t = stdIn.nextInt();
		int x = stdIn.nextInt();
		double c;
		c = (double)t / x;
		System.out.println(c);
	}
}

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

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);	cout.tie(nullptr);
    if (ifstream("test.inp"))
    {
        freopen("test.inp", "r", stdin);
        #ifdef CHECKING
            freopen(taskname".out", "w", stdout);
        #else
            freopen("test.out", "w", stdout);
        #endif //CHECKING
    }
    else if (ifstream(taskname".inp"))
    {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    int x, y;   cin >> x >> y;
    int ans = 0;
    for (; x <= y; x <<= 1) ++ans;
    cout << ans;
}



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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

ll N, K;
ll MOD = 1e9+7;
vector<vector<ll>> A(105, vector<ll>(1e5 + 5, -1));

// ll solve(ll t, ll n) { // time, number
//   if (A[t][n] != -1) return A[t][n];
//   if (t == K) return A[t][n] = 1;
//   A[t][n] = 0;
//   ll i = n;
//   while (i > 0) {
//     ll temp = N / i;
//     ll temp2 = N / (temp + 1);
//     A[t][n] = (A[t][n] + (i - temp2) * solve(t + 1, temp2 + 1)) % MOD;
//     i = temp2;
//   }
//   cout << t << SP << n << SP << A[t][n] << BR;
//   return A[t][n];
// }

ll solve(ll t, ll n) { // time, number
  if (t == K) return 1;
  ll ans = 0;
  ll i = n;
  while (i > 0) {
    ll temp = N / i;
    ll temp2 = N / (temp + 1);
  cout << t << SP << i << temp << SP << temp2 << BR;
    ans = (ans + (i - temp2) * solve(t + 1, temp2 + 1)) % MOD;
    i = temp2;
  }
  cout << t << SP << n << SP << ans << BR;
  return ans;
}

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

  vector<ll> parts;
  ll d = N;
  while (d > 0) {
    ll temp = N / d;
    ll temp2 = N / (temp + 1);
    parts.push_back(d);
    d = temp2;
  }
  // SHOW(parts);

  ll psize = parts.size();
  vector<ll> dp(psize);
  vector<ll> dp2(psize);
  vector<ll> partsdiff(psize);
  
  repR0(j, psize) {
    if (j == psize - 1) dp2[j] = 1;
    else dp2[j] = parts[j] - parts[j + 1];
  }
  partsdiff = dp2;
  // SHOW(dp2);
  rep1(i, K - 1) {
    dp = dp2;
    ll temp = 0;
    rep0(j, psize) {
      temp += dp[psize - 1 - j];
      temp %= MOD;
      dp2[j] = partsdiff[j] * temp;
      dp2[j] %= MOD;
    }
    // cout << i << SP;
    // SHOW(dp2);
  }

  ll ans = 0;
  rep0(j, psize) {
    ans += dp2[j];
    ans %= MOD;
  }

  cout << ans << BR;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N-1);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++)
  {
    cin >> B.at(i);
  }
  for (int i = 0; i < N-1; i++)
  {
    cin >> C.at(i);
  }

  int score = 0;

  for (int i = 0; i < N-1; i++)
  {
    int j = A.at(i);
    score += B.at(j-1);
    if (A.at(i+1) - j == 1)
    {
      score += C.at(j-1);
    }
  }
  
  int j = A.at(N-1);
  score += B.at(j-1);

cout << score << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d) {
    cout << "Left";
  } else if (a + b < c + d) {
    cout << "Right";
  } else {
    cout << "Balanced";
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn];
long long vis[maxn];
int main(){
	int n; cin >> n;
	int cnt;
	for(int i = 1 ; i <= n ; i++){
		cin >> a[i];
		vis[a[i]]++;
	}

	long long sum = 0;
	for(int i = 1 ; i <= n ; i++){
		sum += vis[i] * (vis[i] - 1) / 2;
	}

	for(int i = 1 ; i <= n ; i++){
		cout << (vis[a[i]] >= 1 ? sum - vis[a[i]] + 1 : 0) << endl;
	}
}

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

const int MAXN = 1010;
const int MAXM = 200010;

struct Edge {
	int u, v;

	Edge() {}
	Edge(int u, int v):u(u), v(v) {}
}E[MAXM];

vector<int>to[MAXN];

int Mark[MAXN];
bitset<MAXN>vis;
bool G1[MAXN][MAXN];
bool G2[MAXN][MAXN];

inline void dfs1(int x, int st) {
	G1[st][x] = 1, vis.set(x);
	for(auto u : to[x]) if(!vis[u]) dfs1(u, st);
}

inline void dfs2(int x, int col, int k, int st) {
	if(k) G2[st][x] = Mark[x] != col;
	else Mark[x] = col; vis.set(x);
	for(auto u : to[x]) if(!vis[u]) dfs2(u, col, k, st);
}

int main() {
	int n, m; scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++) {
		int u, v; scanf("%d%d", &u, &v);
		to[u].push_back(v);
		E[i] = Edge(u, v);
	}
	for(int i = 1; i <= n; i++) vis.reset(), dfs1(i, i);
	for(int i = 1; i <= n; i++) {
		vis.reset(), vis.set(i);
		memset(Mark, 0, sizeof(Mark));
		int d = to[i].size();
		for(int j = 0; j < d; j++) if(!vis[to[i][j]]) dfs2(to[i][j], j + 1, 0, i);
		vis.reset(), vis.set(i);
		for(int j = d - 1; ~j; --j) if(!vis[to[i][j]]) dfs2(to[i][j], j + 1, 1, i);
	}
	for(int i = 1; i <= m; i++)
		puts(G1[E[i].v][E[i].u] ^ G2[E[i].u][E[i].v] ? "diff" : "same");
	return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

void solve() {
  unsigned c[9];
  for (int i = 0; i < 9; i++) {
    cin >> hex >> c[i];
  }

  unsigned ans = 0;
  for (int i = 0; i < 32; i++) {
    unsigned sum = 0;
    for (int j = 0; j < 8; j++) {
      sum += c[j];
    }
    if (sum == c[8]) break;
    unsigned a = sum ^ c[8];
    if ((a >> i & 1) == 0) continue;
    ans |= 1 << i;
    for (int j = 0; j < 9; j++) {
      c[j] ^= (1 << i);
    }
  }
  cout << hex << ans << endl;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    solve();
  }

  return 0;
}


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

using namespace std;

typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000 //2e9
#define LLINF 2000000000000000000ll // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define dmp(x) cerr << #x << ": " << x << endl;

template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}

template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T,vector<T>,greater<T>>;
template<class T> vector<T> vect(int len,T elem){ return vector<T>(len,elem); }

template<class T,class U>
ostream& operator << (ostream& os,const pair<T,U>& p){
  os << p.fi << ',' << p.sec; return os;
}
template<class T,class U>
istream& operator >> (istream& is,pair<T,U>& p){
  is >> p.fi >> p.sec; return is;
}
template<class T>
ostream& operator << (ostream &os,const vector<T> &vec){
  for(int i=0;i<vec.size();i++){
    os << vec[i];
    if(i+1<vec.size())os << ' ';
  }
  return os;
}
template<class T>
istream& operator >> (istream &is,vector<T>& vec){
  for(int i=0;i<vec.size();i++)is >> vec[i];
  return is;
}
void fastio(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(20);
}
namespace Util{
  template<class T>
  vector<pair<T,int>> runLength(vector<T> v){
    vector<pair<T,int>> res;
    for(int i=0;i<v.size();i++){
      if(res.empty()||res.back().first!=v[i])res.push_back(make_pair(v[i],1));
      else res.back().second++;
    }
    return res;
  }
  template<class T>
  void compress(vector<T> &v){
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
  }
}

void solve(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b&&b!=c){
    cout << "Yes" << endl;
  }else if(a==c&&b!=a){
    cout << "Yes" << endl;
  }else if(b==c&&a!=b){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return ;
}
 
signed main(){
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 256
package main
import (
    "bufio"
    "fmt"
    "os"
    "strconv"
    "strings"
)

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func main() {
    N := getStdinInt()
    s := make([]int, N)
    sum := 0
    for i := 0; i < N; i++ {
        s[i] = getStdinInt()
        sum += s[i]
    }

    var ans int
    if sum%10 != 0 {
        ans = sum
    } else {
        // s の 10 の倍数で無い最小値を見つける
        minS := sum // すべて 10 の倍数なら ans = 0 となるよう初期値を sum でおく
        for i := 0; i < N; i++ {
            if s[i]%10 != 0 && s[i] < minS {
                minS = s[i]
            }
        }
        ans = sum - minS
    }

    fmt.Println(ans)
}


func getStdin() string {
    return readLine()
}
func getStdinInt() int {
    str := getStdin()
    res, _ := strconv.Atoi(str)
    return res
}
func getStdinIntArr() []int {
    str := getStdin()
    list := strings.Split(str, " ")
    res := make([]int, len(list))
    for idx, v := range list {
        res[idx], _ = strconv.Atoi(v)
    }
    return res
}
func getStdinArr() []string {
    str := getStdin()
    list := strings.Split(str, " ")
    return list
}
func getStdinIntArr64() []int64 {
    str := getStdin()
    list := strings.Split(str, " ")
    res := make([]int64, len(list))
    for idx, v := range list {
        res[idx], _ = strconv.ParseInt(v, 10, 64)
    }
    return res
}
func readLine() string {
    buf := make([]byte, 0, 0)
    for {
        l, p, e := sc.ReadLine()
        if e != nil {
            panic(e)
        }
        buf = append(buf, l...)
        if !p {
            break
        }
    }
    return string(buf)
}

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

using namespace std;

int main(){
    string s;
    cin >> s;
    int ans = 0;
    int a=10000000;
    int z=0;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'A'&&a > i){
            a = i;
        }
        else if(s[i] == 'Z'&&z<i){
            z = i;
        }
    }
    ans = z-a+1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FASTIO ios::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())

int main() {
	FASTIO;
	string s;
	cin >> s;
	int ans = 0;
	if (s == "RRR") ans = 3;
	else if (s == "SRR" || s == "RRS") ans = 2;
	else if (s == "SSR" || s == "RSR" || s == "RSS" || s == "SRS") ans = 1;
	else ans = 0;
	cout << ans << "\n";
}

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

typedef long long LL;
typedef vector<LL> VL;
typedef vector<vector<LL>> VVL;
typedef vector<string> VS;

#define REPD(i,a,b) for (LL i=(a);i<(b);i++)
#define REP(i,n) REPD(i,0,n)

LL llRead(){
  LL a;
  cin >> a;
  return a;
};

string stringRead(){
  string a;
  cin >> a;
  return a;
};

vector<LL> vlRead(LL a){
  vector<LL> rv;
  REP(i, a){
    LL input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}

vector<string> vsRead(LL a){
  vector<string> rv;
  REP(i, a){
    string input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}
vector<vector<LL>> vvlRead(LL a, LL b){
  vector<vector<LL>> rv;
  REP(i, a){
    rv.push_back(vector<LL>());
    REP(j, b) {
      LL input;
      cin >> input;
      rv.at(i).push_back(input);
    }
  }
  return rv;
}

#if 1
#define debug(d) debug1(__LINE__,#d, d)
void debug1(LL line, const char* name, VL& v) {
  cout << line << ":" << name << ":vector<LL>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, LL i) {
  cout << line << ":" << name << ":LL " << i << endl;;
}
void debug1(LL line, const char* name, VS& v) {
  cout << line << ":" << name << ":vector<string>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, VVL& v) {
  cout << line << ":" << name << ":vector<vector<LL>>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    REP(j, (LL)v.at(i).size()) {
      cout << v.at(i).at(j) << " ";
    }
    cout << ", ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, char* s) {
  cout << line << ":" << name << ":char* " << s << endl;;
}
void debug1(LL line, const char* name, vector<const char*>& v) {
  cout << line << ":" << name << ":vector<const char*>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, priority_queue<LL>& p) {
  cout << line << ":" << name << ":priority_queue<LL>(" << p.size() << ") ";
  priority_queue<LL> copy = p;
  while(!copy.empty()) {
    cout << copy.top() << " ";
    copy.pop();
  }
  cout << endl;
}
#else
#define debug(n)
#endif

int main(int argc, const char * argv[]) {
	cout.precision(16);
  // source code

  auto n = llRead();
  auto s = stringRead();
  assert(s.size() == n);

  LL c = 1;
  REPD(i, 1, n) {
    if (s[i] != s[i-1]) c++;
  }
  cout << c << endl;

  return 0;
}


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

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    int64 s;
    cin >> s;
    int64 x = 1e9;
    int64 y = 1;
    int64 yy = (s+x-1)/x;
    int64 xx = yy*x - s;

    cout << 0 << " " << 0 << " ";
    cout << x << " " << y << " ";
    cout << xx << " " << yy << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,k;
	cin>>n>>k;
	std::vector<ll> v;
	for(ll i=1;i<=n;i++)
	{
		ll x;
		cin>>x;
		v.pb(x);
	}
	sort(all(v));
	reverse(all(v));
	ll s=0;
	for(ll i=k;i<n;i++)
		s+=v[i];
	cout<<s<<"\n";
	return 0;
}

Measured memory_bytes: 2420
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var buffer = Console.ReadLine().Split();
            var list = new List<int>();
            foreach (var v in buffer)
                list.Add(int.Parse(v));

            int min = int.MaxValue;
            for (int i = 1; i < N; i++)
            {
                var s1 = list.Take(i).Sum();
                var s2 = list.Skip(i).Sum();

                if (Math.Abs(s1 - s2) < min)
                    min = Math.Abs(s1 - s2);
            }

            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 28324
#include <bits/stdc++.h>
using namespace std;
 
#define MOD (1000000007)
#define f first
#define s second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];
typedef long long int ll;
#define ld long double
const int N = 2e5+30;
//https://codeforces.com/problemset/page/2?tags=1700-1700
 
 
void solve(){
   int N,W;
   cin>>N>>W;
   int w[N+3];
   int v[N+3];
   for(int i=1;i<=N;i++) cin>>w[i]>>v[i];
   ll dp[N+3][W+6];
   memset(dp,0,sizeof(dp));
   for(int i=1;i<=N;i++){
     for(int j=1;j<=W;j++){
       if(j-w[i]>=0){
         dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
       }
       else dp[i][j] = dp[i-1][j];
     }
   }
   cout<<dp[N][W]<<'\n';
}
 
 
int main(){
 	ios_base::sync_with_stdio(false);
  cin.tie(NULL);
	int T;
  //cin >> T;
  //cout<<prs.size()<<'\n';
	 T = 1;
  //visited[1]=1;
	while(T--){
		solve();
	}
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    int n;
    cin>>n;
    int a[n+1];
    for(int i=1; i<=n; i++)
        cin>>a[i];
    int cnt=n;
    int mx=n+1;
    int b[n+2];
    for(int i=1;i<=n;i++)
    {
        mx=min(mx,a[i]);
        b[i]=mx;
    }
    for(int i=1;i<=n;i++)
    {
        if(b[i]<a[i])
            cnt--;
    }
    cout<<cnt;


}


Measured memory_bytes: 1792
def main():
    _ = int(input())
    s = input().rstrip()
    r, b = 0, 0
    for c in s:
        if c == "R":
            r += 1
        else:
            b += 1
    if r > b:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
import itertools
N, M, R = map(int, input().split())
r_list = list(map(int, input().split()))

# iからjへの距離
# 町の番号は0-indexに直す
d = [[10**9 for _ in range(N)] for _ in range(N)]

# 0から0, ..., N-1からN-1への距離
for i in range(N):
    d[i][i] = 0

# aからbへの距離、bからaへの距離を記録
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c

# ワーシャルフロイド法
for k in range(N):  # 経由地点
    for i in range(N):  # スタート
        for j in range(N):  # ゴール
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

ans = 10**9

# 訪れる町の順列, 0-index
for p in itertools.permutations(r_list):
    tmp = 0
    for i in range(R - 1):
        x = p[i] - 1
        y = p[i + 1] - 1
        tmp += d[x][y]
    ans = min(ans, tmp)

print(ans)


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

int main () {
  
  int N;
  cin >> N;
  
  vector<double> v(N);
  
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  
  sort(v.begin(), v.end());
  
  double ans = 0;
  double pow = 1;
  
  for (int i = 0; i < N - 1; i++) {
    pow *= 2;    
    ans += (v[N - i - 1] / pow);
  }
  
  ans += v[0] / pow;
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
n,Y = map(int,input().split())
x = -1
y = -1
z = -1

for i in range(n+1):
    x_man = i * 10000
    for j in range(n+1):
        y_thou = j * 5000
        z_thou = (Y - x_man - y_thou)//1000
        #print(x_man,y_thou,z_thou)
        if z_thou >= 0:
            if i + j + z_thou == n:
                x = i
                y = j
                z = z_thou
                break

print(x,y,z)


Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define LL long long
using namespace std;
LL n,sum,i;
inline LL read(){
	char ch=getchar(); LL x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	return x*f;}
int main()
{
	//freopen("Falling Stone Game.in","r",stdin);
	n=read();
	for(i=1;;i++)
	{
		sum+=i;
		if(sum>=n) break;
	}
	LL tt=sum-n;
	for(LL j=1;j<=i;j++)
	 if(j==tt) continue;
	 else printf("%lld\n",j);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<long long> vl;
typedef vector<vector<ll>> vll;
typedef vector<bool> vb;
typedef set<int> si; 
#define fori(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,b,a) for(int i = (b); i >= (a); --i)
#define all(a) (a).begin(), (a).end()
//#define __builtin_popcountll bitCountLL
//#define __builtin_popcount bitCount
//__builtin_ctz 末尾0的个数, __builtin_clz 前导0的个数
//__builtin_ffs 最后一个1的位置
#define maxn 100005
#define Mod 1000000007
const int INF = 2e9;
const ll ML = 4e18;
    
void solve() {
    int n,k;
    cin >> n >> k;
    vi a(n);
    fori(i,0,n) cin >> a[i];
    fori(i,k,n) {
        if(a[i] > a[i-k]) cout << "Yes\n";
        else cout << "No\n";
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	//cout.precision(30); cout << fixed;
//	freopen("D:\\data_in.txt", "r", stdin);
   solve();
   
    /*
    clock_t start,finish;
    start = clock();
    
    finish = clock();
    cout << "\n" << (double)(finish - start) / (double)(CLOCKS_PER_SEC) * 1000 << "ms" << endl;
    */
    return 0;
}

/***************************************************************
 question:
 idea:
 tag:
 record:
 ***************************************************************/


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

int main() {
	string sa, sb, sc;
	string now;
	now = 'a';
	cin >> sa >> sb >> sc;
	//どれかの文字列が0になるまで繰り返し
	while (1) {
		if (now == "a") {
			if (sa.size() == 0) {
				cout << "A" << endl;
				break;
			}
			now = sa.substr(0, 1);
			sa.erase(0, 1);
		} else if (now == "b") {
			if (sb.size() == 0) {
				cout << "B" << endl;
				break;
			}
			now = sb[0];
			sb.erase(0, 1);
		} else if (now == "c") {
			if (sc.size() == 0) {
				cout << "C" << endl;
				break;
			}
			now = sc[0];
			sc.erase(0, 1);			
		}
	}
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(bf.readLine());
        StringTokenizer st = new StringTokenizer(bf.readLine());
        int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        Arrays.sort(a);
        double ans = a[0];
        for(int i=1; i<n; i++) {
          ans = (ans + a[i])/2.0;
        }

        out.println(ans);
        // int n = Integer.parseInt(st.nextToken());

        out.close(); System.exit(0);
    }
}


Measured memory_bytes: 20820
using System;
using System.Linq;

class Test
{
    static void Main()
    {
        int[] dd = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int a = dd[0];
        int b = dd[1];
        int d = a / b;
        int r = a % b;
        double f = Math.Round((double)a / b,5);

        Console.WriteLine("{0} {1} {2}", d, r, f);
    }
}


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

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

  set<int> s;
  rep(i,0,N-1) {
    int p;
    cin >> p;
    s.insert(p);
  }

  int m = 1001001001, ans = X;
  rep(i,0,101) {
    if (s.count(i) != 0) continue;
    else if (abs(X - i) < m) {
      m = abs(X - i);
      ans = i;
    }
  }

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


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

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

using namespace std;

const int MOD=1000000007;

int main(){
	int fib[100002];
	fib[0]=0;
	fib[1]=1;
	rep(i,100000) fib[i+2]=(fib[i+1]+fib[i])%MOD;

	int n,m; cin>>n>>m;
	int ans=1,pre=-1;
	rep(i,m+1){
		int a;
		if(i<m) cin>>a;
		else    a=n+1;
		ans=1LL*ans*fib[a-pre-1]%MOD;
		pre=a;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int m1, m2, d1, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    cout << (d2 == 1) << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

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

  vector<ll> a(n), b(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i] >> b[i];

  vector<pair<ll, int>> c;
  ll t = 0, k = 0;
  for (int i = 0; i < n; ++i)
  {
    c.emplace_back(b[i] + a[i], i);
  }
  sort(c.begin(), c.end(), greater<pair<ll, int>>());

  for (int i = 0; i < n; ++i)
  {
    if (i % 2 == 0)
    {
      t += a[c[i].second];
    }
    else
    {
      k += b[c[i].second];
    }
  }

  cout << t - k << endl;

  return 0;
}


Measured memory_bytes: 3956
// Problem : B - Crane and Turtle
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
#define dbp(x) cout<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define dbv(v) {cout<<#v<<" : ";for (auto x:v) cout<<x<<' ';cout<<endl;}
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define rep2(i,a,b) for(int i = a; i >= b; i--)
#define die(x) return cout<<x<<'\n', 0;

using namespace std;

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

int32_t main()
{
fastio;

int testcases;
testcases=1;
//cin>>testcases;

while(testcases--)
{
	int x,y;
	cin>>x>>y;
	int b=(y-2*x);
	if(b%2==0&&b>=0)
	{
		b=b/2;
		int a=x-b;
		if(a>=0)
		{
			die("Yes");			
		}
		else
		{
			die("No");
		}
	}
			die("No");
}

return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    vector<string> v{"light fly", "fly", "bantam", "feather", "light", "light welter", "welter", "light middle", "middle", "light heavy", "heavy"};
    vector<int> a{48, 51, 54, 57, 60, 64, 69, 75, 81, 91, 999999};
    double x;
    while(cin >> x){
        for (int i = 0; i < v.size(); ++i) {
            if(x <= a[i]){
                cout << v[i] << "\n";
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    vector<pair<int,int>> q(m);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i++){
        int b,c;
        cin >> b >> c;
        q[i] = {c,b};
    }
    sort(a.begin(),a.end());
    sort(q.begin(),q.end(),greater<pair<int,int>>());
    int j = 0;
    for(int i = 0; i < n; i++){
        if(q[j].second == 0) j++;
        if(j == m) break; 
        if(a[i] < q[j].first){
            a[i] = q[j].first;
            q[j] = {q[j].first,q[j].second-1};
        }
        else break;
    }
    ll sum = 0;
    for(int i = 0; i < n; i++){
        sum += a[i];
    }
    cout << sum << endl;

}

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

#define en "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int) a.size()
#define deb(x) cerr << #x << " => " << x << en
#define deba(x) cerr << #x << en; for (auto a : x) cerr << a << " "; cerr << en;
#define debp(x) cerr << #x << en; for (auto a : x)cerr<<"("<<a.fs<<", "<<a.sc<<") "; cerr << en;
#define debm(x) cerr << #x << en; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << en;}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m = HELL) { int res = 1; a %= m;
while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2)
#define mul(a, b) ((a % HELL) * (b % HELL)) % HELL

int32_t main() { fastio;
	int n, k;
	cin >> n >> k;
	int parent[n + 1][64];
	memset(parent, 0, sizeof parent);
	for (int i = 1; i <= n; i++) {
		cin >> parent[i][0];
	}
	for (int j = 1; j <= 63; j++) {
		for (int i = 1; i <= n; i++) {
			parent[i][j] = parent[parent[i][j - 1]][j - 1];
		}
	}
	int node = 1;
	for (int i = 0; i <= 63; i++) {
		if (k & (1LL << i)) {
			node = parent[node][i];
		}
	}
	cout << node << endl;
	return 0;
}

Measured memory_bytes: 103628
#include <stdio.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)

int main(){
    int n;
    scanf("%d", &n);
    int a[101];
    a[0] = 1, a[1] = 1;
    rep(i, 50){
        a[i+2] = a[i+1] + a[i];
    }

    printf("%d\n", a[n]);
}


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

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

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;

int main() {
  string s;
  cin >> s;
  rep(i,19){
    if(i==5||i==13){
      cout << " ";
    }
    else{
      cout << s[i];
    }
  }

  
}
      

Measured memory_bytes: 3536
#include <stdio.h>

int main (void)
{
  unsigned long n,a,b,m=0,ans=0;
  
  
  scanf("%lu %lu %lu", &n, &a, &b);
  
  ans += a * (n / (a+b));
  
  m = n % (a+b);  
  
  if ((long)a-(long)m >= 0) {
    ans += m;
  } else {
    ans += a;
  }
  
  printf("%lu", ans);
  
  return 0;
}

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

int main() {

	char s[10];
	scanf("%s", s);

	int n = strlen(s), ans = 0;
	if(!(n%2))
        for(int i = 1; i <= n-1; i += 2)
            ans = ans*100 + 9;
	else {
        int a = 0, t = 1;
        for(int i = 0; i < n; i++) {
            a = a*10 + s[i]-'0';
            t *= 10;
        }
        t /= 10;
        for(int i = 1; i <= n-2; i += 2)
            ans = ans*100 + 9;
        ans += a - t + 1;
	}
	
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool isprime(long long n)
{
    long long i;
    for(i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return true;
    }
    if(n==1)
        return true;
    return false;
}
int main()
{
    long long n,k=1,p=0,q,i,l=n;
    cin>>n;
    l=n;
    for(i=2;i<=sqrt(l);i++)
    {
        n=l;
        if(l%i==0)
        {
            if(!isprime(i))
            {
            k=1;
            q=k;
            while(n%i==0)
            {
                n/=i;
                k--;
                if(k==0){
                    k=q+1;
                    q=k;
                    p++;
                }
            }
            }
            n=l;
            if(!isprime(n/i))
            {
            k=1;
            q=k;
            while(n%(l/i)==0)
            {
                n/=(l/i);
                k--;
                if(k==0){
                    k=q+1;
                    q=k;
                    p++;
                }
            }
            }
        }
    }
    if(l!=1 && p==0)
        p++;
    cout<<p<<endl;

    return 0;
}


Measured memory_bytes: 3672
#include <iostream>

int main()
{
  int total_sec = 0;
  std::cin >> total_sec;
  
  const int hour = total_sec / 3600;
  const int min = (total_sec % 3600) / 60;
  const int sec = total_sec % 60;

  std::cout << hour << ":" << min << ":" << sec << std::endl;

  return 0;
}

Measured memory_bytes: 1164
n, m = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

po = []
for mo in ks:
    poyo = [0] * n
    for i in range(1, mo[0]+1):
       poyo[mo[i]-1] = 1
    po.append(poyo)
for i in range(m):
    po[i] += [p[i]]
ans = 0
for i in range(2**n):
    s = ('{:0'+str(n)+'b}').format(i)
    for j in range(m):
        wa = 0
        for k in range(n):
            wa += int(s[k]) * po[j][k]
        if wa % 2 != po[j][-1]:
            break
    else:
        ans += 1
print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		String s = sc.next();

		s = s.replaceAll("2017", "2018");

		System.out.println(s);
	}

}

Measured memory_bytes: 22996
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;

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

int main()
{
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  int r = tx - sx;
  int u = ty - sy;

  rep (i, r) {
    cout << 'R';
  }

  rep (i, u) {
    cout << 'U';
  }

  rep (i, r) {
    cout << 'L';
  }

  rep (i, u) {
    cout << 'D';
  }

  cout << 'D';

  rep (i, r+1) {
    cout << 'R';
  }

  rep (i, u+1) {
    cout << 'U';
  }

  cout << 'L';
  cout << 'U';

  rep (i, r+1) {
    cout << 'L';
  }

  rep (i, u+1) {
    cout << 'D';
  }

  cout << 'R' << endl;
}


Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int n, t[100000], a[100000], h[100000];
int cnt[100000];

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    scn(n, t);
    scn(n, a);

    rep(i, n)h[i] = -1;
    h[0] = t[0]; h[n - 1] = a[n - 1];
    if(n == 1 && t[0] != a[0]){ pri(0); return 0; }

    if(a[n - 1] > t[n - 1]){ pri(0); return 0; }
    rep1(i, n)if(t[i] > t[i - 1])h[i] = t[i];
    per(i, n - 1){
      if(h[i] != -1 && h[i] > a[i]){ pri(0); return 0; }
      if(a[i] > a[i + 1])h[i] = a[i];
    }

    ll res = 1;
    rep(i, n){
      if(h[i] == -1){
        ll x = min(a[i], t[i]);
        //pri3(i, x, h[i]);
        res = (res * x) % mod;
      }
    }

    pri(res);




/*/

//*/ break;
  }
  return 0;
}


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

int main()
{
	int x, y, c, div = 0;
	scanf("%d %d %d",&x,&y,&c);
	for(int i = x; i <= y; i++)
	{
		if( c % i == 0)
		{
			div++;
		}
	}
	printf("%d\n", div);
	return 0;
}



Measured memory_bytes: 2760
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
using namespace std;
typedef pair<long long, long long>p;
long long mod = 1e9 + 7;
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
vector< int64_t > divisor(int64_t n) {
	vector< int64_t > ret;
	for (int64_t i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int dp[200004][2];//0siro 1 kuro
	if (s[0] == '.') {
		dp[0][0] = 0;
		dp[0][1] = 1;
	}
	else {
		dp[0][0] = 1;
		dp[0][1] = 0;
	}
	for (int i = 1; i < n; i++) {
		if (s[i] == '.') {
			dp[i][0] = dp[i - 1][0];
			dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + 1;
		}
		else {
			dp[i][0] = dp[i - 1][0]+1;
			dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]);
		}
	}
	cout << min(dp[n - 1][0], dp[n - 1][1]);
}

Measured memory_bytes: 2196
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(int i=j;i<(n);++i)
#define bk(i,j,n)   for(int i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define MOD 1000000007
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>

typedef long long  ll;

ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}


int main()
{
    run;
    ll n,m;
    cin>>n>>m;
    ll o=n*(n-1);
    ll p=m*(m-1);
    cout<<o/2+p/2;




}


Measured memory_bytes: 256
n,K=list(map(int,input().split()))
xy=sorted([list(map(int,input().split())) for _ in range(n)],key=lambda x:x[0])

dp=[[[] for _ in range(n)] for _ in range(n)]
for i in range(n):
    for j in range(i+1,n):
        for k in range(i,j+1):
            dp[i][j].append(xy[k][1])
        
        dp[i][j].sort()

ans=10**19

for x in range(K,n+1):
    for i in range(n-x+1):
        left=xy[i][0]
        right=xy[i+x-1][0]

        for j in range(len(dp[i][i+x-1])-K+1):
            down=dp[i][i+x-1][j]
            up=dp[i][i+x-1][j+K-1]

            ans=min(ans,(right-left)*(up-down))

print(ans)


Measured memory_bytes: 74516
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
char s[20];int n,cnt;
int main()
{
	scanf("%s",s+1);n=strlen(s+1);
	for(int i=1;i<=n;i++)cnt+=s[i]=='x';
	cnt<=7?puts("YES"):puts("NO");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int A = in(), B = in(),C = in();
    if(A ==B+C || B == A+C||C == A+B){
        cout << "Yes" << "\n";
    }else{
        cout << "No" << "\n";
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    String S = sc.next();
    int len = S.length();
    //01010101...とするときに変える枚数xとlen-xのうち小さいほうが答え
    int w=0;
    for(int i=0;i<len;i++){
      if(i%2==0){
        if(S.substring(i,i+1).equals("1")){
          w++;
        }
      }else{
        if(S.substring(i,i+1).equals("0")){
          w++;
        }
      }
    }
    System.out.println(Math.min(w,len-w));

  }
    


}


Measured memory_bytes: 30096
h, w = map(int, input().split())
s = [input() for i in range(h)]
yoko = [([0] * w) for i in range(h)]
tate = [([0] * w) for i in range(h)]

for i in range(h):
    f = 0
    j = 0
    m = 0
    while j < w:
        if s[i][j] == ".":
            if m == 0:
                j += 1
            else:
                f = j
                m = 0
                j += 1
        else:
            if m == 0:
                for p in range(f, j):
                    yoko[i][p] = j - f
            m = 1
            j += 1
    if m == 0:
        for p in range(f, j):
            yoko[i][p] = j - f

for i in range(w):
    f = 0
    j = 0
    m = 0
    while j < h:
        if s[j][i] == ".":
            if m == 0:
                j += 1
            else:
                f = j
                m = 0
                j += 1
        else:
            if m == 0:
                for p in range(f, j):
                    tate[p][i] = j - f
            m = 1
            j += 1
    if m == 0:
        for p in range(f, j):
            tate[p][i] = j - f
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            q = yoko[i][j] + tate[i][j] - 1
            if q > ans:
                ans = q
print(ans)

Measured memory_bytes: 123224
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 

#define DEBUG(x) do { std::cerr << x; } while (0)
//std::vector<bool> v(1e9);
using namespace std;



int main()
{
	sync;
	cin.tie(0);
	//int t=5,count=0;
	std::vector<int> v(5,0);
	for(auto &c:v)
	{
		cin>>c;
		
	}
	for(int i=0;i<v.size();i++)
		if(v[i]==0)
			cout<<i+1<<"\n";
	

}

Measured memory_bytes: 3624