akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#define LL long long

std::map<int,char> str;
char s[100010],t[100010];
using namespace std;
LL n,m;
int main() {
    scanf("%lld%lld", &n, &m);
    scanf("%s%s", s, t);
    if(s[0]!=t[0]) return puts("-1"),0;
    LL a = n*m/__gcd(n,m);
    str[1] = s[0];
    for(int i=1;i<n;++i) str[i*a/n] = s[i];
    for(int i=1;i<m;++i) if(str[i*a/m]) if(str[i*a/m]!=t[i]) return puts("-1"),0;
    printf("%lld\n",a);
    return 0;
}

Measured memory_bytes: 8192
import numpy as np
a,b = map(int, input().split())

x=np.array([['.']*100]*100,dtype=str)

x[:,:50]='#'

v1=(a-1)//20
v2=(a-1)-v1*20
w1=(b-1)//20
w2=(b-1)-w1*20

for i in range(v1):
    x[2*i+1,1:40:2]='.'

x[-1,1:2*v2:2]='.'

for i in range(w1):
    x[2*i+1,51:90:2]='#'
x[-1,51:50+w2*2:2]='#'
print(100,100)
for i in range(100):
    print(''.join(x[i]))

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

int main() {
  ll n, y;
  cin >> n >> y;
  for (ll i = 0; i <= n; i++) {
    for (ll j = 0; i + j <= n; j++) {
      ll k = n - (i + j);
      if (i * 10000 + j * 5000 + k * 1000 == y) {
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	x*=f;
	return;
}
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
const long double eps=1e-25;
const long double delta=0.999;
long double ansx=0,ansy=0,ans;
int n;
struct node{
	long double x,y;
}a[55];
inline long double dis(node p,node q)
{
	return sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y));
}
long double cal(long double x,long double y)
{
	long double ret=0;
	for(int i=1;i<=n;i++) ret=max(ret,dis({x,y},a[i]));
	return ret;
}
void SA()
{
	long double t=3500;
	while(t>eps)
	{
		long double x=ansx+(rand()*2-RAND_MAX)*t;
		long double y=ansy+(rand()*2-RAND_MAX)*t;
		long double r=cal(x,y);
		long double de=r-ans;
		if(de<0) ansx=x,ansy=y,ans=r;
		else if(exp(-de/t)*RAND_MAX>rand()) ansx=x,ansy=y;
		t*=delta;
	}
}
int main()
{
	srand(time(0)); 
	read(n);
	for(int i=1;i<=n;i++)
	read(a[i].x),read(a[i].y),ansx+=a[i].x,ansy+=a[i].y;
	ansx/=n,ansy/=n;
	ans=cal(ansx,ansy);
	for(int i=1;i<=5;i++) SA();
	printf("%.10Lf\n",ans);
	return 0;
}

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

using namespace std;

int reg(map<string, int>& tbl, string& name) {
	if (tbl.count(name) == 0) {
		int id = tbl.size();
		tbl[name] = id;
	}
	return tbl[name];
}

int N;
vector< vector<int> > G;
vector<int> power;
vector<int> ps;
vector<int> conv;
vector<int> adjacent;

int ans = 0, p = 0;
bool merge(int n) {
	if (adjacent[n] > 0) return false;
	for (int i = 0; i < G[n].size(); ++i) {
		adjacent[G[n][i]]++;
	}
	return true;
}
bool remove(int n) {
	for (int i = 0; i < G[n].size(); ++i) {
		adjacent[G[n][i]]--;
	}
}
void dfs(int n) {
	if (n == N) {
		ans = max(ans, p);
	}
	else if (p + ps[n] > ans) {
		if ( merge(conv[n]) ) {
			p += power[n];
			dfs(n+1);
			remove(conv[n]);
			p -= power[n];
		}
		if ( G[conv[n]].size() > 0 ) dfs(n+1);
	}
}

int main() {
	while ( cin >> N, N ) {
		map<string, int> tbl;
		power.clear(); power.resize(N);
		G.clear(); G.resize(N);
		conv.clear(); conv.resize(N);
		for (int i = 0; i < N; ++i) {
			string A; cin >> A; int a = reg(tbl, A);
			int B, C; cin >> B >> C;
			for (int j = 0; j < C; ++j) {
				string D; cin >> D;
				int d = reg(tbl, D);
				G[a].push_back(d);
			}
			power[i] = B;
			conv[i] = a;
		}
		ps.resize(N+1);
		for (int i = 0; i < N; ++i) {
			ps[i] = power[i];
		}
		for (int i = N-1; i >= 0; --i) {
			ps[i] += ps[i+1];
		}
		adjacent = vector<int>(N, 0);
		ans = 0; p = power[0]; merge(conv[0]);
		dfs(1);
		cout << ans << endl;
	}
}

Measured memory_bytes: 1260
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

const int NMAX = 100000;
const int MMAX = 100000;

vector<int> table[NMAX]; 

int color[NMAX];

void search(int s, int id, int n) {
	queue<int> q;
	q.push(s);
	color[s] = id;

	while(true) {
		if (q.empty()) {
			return;
		}
		int current = q.front(); q.pop();
		for (int i = 0; i < table[current].size(); i++) {
			int v = table[current][i];
			if (color[v] == -1) {
				q.push(v);
				color[v] = id;
			}
		}
	}
}

void assignColor(int n) {
	int id = 0;
	for (int i = 0; i < n; i++) {
		color[i] = -1;
	}	
	
	for (int i = 0; i < n; i++) {
		if (color[i] == -1) {
			id++;
			search(i, id, n);
		}
	}
}

int main() {
	int n, m;
	scanf("%d %d", &n, &m);

	for (int i = 0; i < m; i++) {
		int s, t;
		scanf("%d %d", &s, &t);
		table[s].push_back(t);
		table[t].push_back(s);
	}

	assignColor(n);

	int q;
	scanf("%d", &q);

	for (int i = 0; i < q; i++) {
		int s, t;
		scanf("%d %d", &s, &t);

		bool result = color[s] == color[t];
		if (result) {
			printf("yes\n");
		} else {
			printf("no\n");
		}
	}

	return 0;
}



Measured memory_bytes: 8976
#!/usr/bin/env python
#pyrival orz
import os
import sys
from io import BytesIO, IOBase

"""
    for _ in range(int(input())):
    n,m=map(int,input().split())
    n=int(input())
    a = [int(x) for x in input().split()]
"""

def main():
    m,n=map(int,input().split())
    a = [int(x) for x in input().split()]
    ans=-(1<<30)
    for i in range(m-200,m+200):
        if i in a:
            continue
        if abs(i-m)>=abs(ans-m):
            continue
        ans=i
    print(ans)

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 62704
#include<iostream>
using namespace std;
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#define int long long int
int function2(int memo[],int turn[],int n,map<int,int> &sticks)
{
	if(n<0)
	{
		return -1000000000;
	}
	if(n==0)
	{
		return 0;
	}
	if(memo[n]!=-1)
	{
		return memo[n];
	}
	else
	{
		map<int,set<int>> mp;
		int here=-1000000000;
		mp[here].insert(-1);
		for(auto &p:sticks)
		{
			int val=1+function2(memo,turn,n-p.second,sticks);
			mp[val].insert(p.first);
		}
		auto it=mp.end();
		it--;
		int answer=*it->second.rbegin();
		turn[n]=answer;
		memo[n]=it->first;
		return it->first;
	}
}
int32_t main()
{
	int a,b;
	cin>>a>>b;
	if(b%a==0)
	{
		cout<<a+b<<endl;
	}
	else
	   cout<<b-a<<endl;
}


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

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	int N;
	int A[];
	public void run() {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		A = new int[N];
		for(int i=0; i<N; i++) A[i] = sc.nextInt();
		Arrays.sort(A);

		int a = 0;
		int b = 0;
		for(int i=0; i<N; i++) {
			if(i%2==0) a += A[N-i-1];
			else b += A[N-i-1];
		}
		System.out.println(a-b);
		sc.close();
	}
}

Measured memory_bytes: 22356
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  string s; cin >> s;
  cout << s.rfind('Z')-s.find('A')+1 << endl;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int N; cin >> N;
  vector<int> H(N);
  int ans = 0;
  for(int i = 0; i < N; ++i) {
    cin >> H[i];
  }
  reverse(H.begin(), H.end());
  for(int i = 0; i < N; ++i) {
    bool matched=true;
    int h = H[i];
    for(int j = i+1; j < N; ++j) {
      if(h < H[j]) matched = false;
    }
    if(matched) ans++;
  }
  cout << ans << endl;

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double EPS = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int main() {
	int m; cin >> m;
	while (m--) {
		string str; cin >> str;
		set<string> ans;
		REP(i, 1, str.size()) {
			string sub1[2], sub2[2];
			sub1[0] = sub1[1] = str.substr(0, i);
			sub2[0] = sub2[1] = str.substr(i);
			reverse(all(sub1[1]));
			reverse(all(sub2[1]));

			rep(j, 2) rep(k, 2) {
				ans.insert(sub1[j] + sub2[k]);
				ans.insert(sub2[j] + sub1[k]);
			}
		}
		cout << ans.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1292
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

min_diff = 10 ** 10
ret = -1

for i, h in enumerate(H):
    d = abs(A - (T - h * 0.006))
    if min_diff > d:
        min_diff = d
        ret = i + 1

print(ret)


Measured memory_bytes: 3060
n,a=int(input()),list(map(int,input().split()))
g=0
from math import gcd
for i in a:g=gcd(i,g)
if g!=1:print("not coprime")
else:

    primes=list(range(10**6+1))
    primes[0]=primes[1]=0
    for i in range(2,10**6+1):
        if primes[i]==i:
            for j in range(2*i,10**6,i):primes[j]=i
    ps=set()
    for x in a:
        while x !=1:
            t=primes[x]
            if t in ps:print("setwise coprime");exit()
            ps.add(t)
            while x%t==0:x//=t
    print("pairwise coprime")

Measured memory_bytes: 189072
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] tmpStr=scanner.nextLine().split(" ");
        int ans=0;
        int N = Integer.parseInt(tmpStr[0]);
        int K = Integer.parseInt(tmpStr[1]);
        List<Integer> list = new ArrayList<>();
        String[] tmpStr2=scanner.nextLine().split(" ");
        for (int i = 0; i < N; i++) {
            list.add(Integer.parseInt(tmpStr2[i]));
        }
        Collections.sort(list);
        Set<Integer> set = new HashSet<>();
        set.addAll(list);
        int baketuNum = set.size();
        int sabun=set.size()-K;
        if(sabun>0){
            int count[] = new int[baketuNum];
            List<Integer> list2 = new ArrayList<>();
            int tmpNum=0;
            int baketuIndex=-1;
            for (int i = 0; i < list.size(); i++) {
                if(tmpNum!=list.get(i)){
                    tmpNum=list.get(i);
                    baketuIndex++;
                }
                count[baketuIndex]++;
            }
            for (int v:count){
                list2.add(v);
            }
            Collections.sort(list2);
            for (int i = 0; i < sabun; i++) {
                ans+=list2.get(i);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 59152
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(void){
    int N; cin >> N;
    string S; cin >> S;
    
    ll r=0, g=0, b=0;
    for (auto c : S){
        if (c=='R') r++;
        if (c=='G') g++;
        if (c=='B') b++;
    }
    
    ll ans = r * g * b;
    for (int d = 1; d <= N; d++){
        for (int m = 0; m < N; m++){
            if (m-d<0||m+d>N-1) continue;
            if (S[m-d]!=S[m+d] && S[m-d]!=S[m] && S[m]!=S[m+d]) ans--;
        }
    }
    cout << ans << endl;
}


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

typedef long long ll;
#define mod 1000000007

int main()
{
    ll n;
    cin >> n;
    ll ans = 1;
    
    ll p1 = 1, p2 = 1, p3 = 1;

    for(int i = 0; i < n; i++){
        p1 = (p1 * 10) % mod;
        p2 = (p2 * 9) % mod;
        p3 = (p3 * 8) % mod;
    }

    p2 = (2 * p2) % mod;

    ans = (p1 - p2 + p3 + mod) % mod;

    cout << ans << "\n";
}

Measured memory_bytes: 3612
<?php
// Your code here!
fscanf(STDIN,"%d %d",$a,$b);

$sum = 0;

for($i=0;$i<2;$i++){
    if($a > $b){
        $sum += $a;
        $a -= 1;
    }elseif($a < $b){
        $sum += $b;
        $b -= 1;
    }else{
        $sum += $a;
        $a -= 1;
    }
}

echo $sum;
?>

Measured memory_bytes: 4728
//057
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(void){
    int n, m, x, y,ans;
    long tmp;
    cin >> n >> m;
    vector<tuple<int, int>>stu;
    vector<tuple<int, int>>cp;
    rep(i, n){
        cin >> x >> y;
        stu.push_back(make_tuple(x,y));
    }
    rep(i, m){
        cin >> x >> y;
        cp.push_back(make_tuple(x, y));
    }
    
    rep(i, n){
        x = get<0>(stu[i]);
        y = get<1>(stu[i]);
        long d = 10000000000;
        rep(j, m){
            tmp = abs(x - get<0>(cp[j])) + abs(y-get<1>(cp[j]));
            //cout << tmp << endl;
            if (d > tmp){
                d = tmp;
                ans =j+1;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
def dense(w, s):
	if s + w == 0:
		return 0
	return s / (w + s) * 100

def resolve():
	A, B, C, D, E, F = map(int, input().split())
	waters = set()
	sugars = set()

	for i in range(31):
		for j in range(31):
			v = A*i*100 + B*j*100
			if v > F:
				continue
			waters.add(v)
	for i in range(3001):
		for j in range(3001):
			v = i*C + j*D
			if v > F:
				continue
			sugars.add(v)
	ans_w, ans_s = 0, 0
	for w in waters:
		for s in sugars:
			if w + s > F or s > w//100*E or s + w == 0:
				continue
			if dense(w, s) >= dense(ans_w, ans_s):
				ans_w, ans_s = w, s
	print(ans_w + ans_s, ans_s)
resolve()

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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define vi vector<int>

using namespace std;

int get(int pos, set<int> s) {
  for (int x : s) {
    if (!pos) return x;
    pos--;
  }
  return -1;
}

void solve() {
  int n;
  cin >> n;
  vi h(n), dp(n, 1e9);
  for (int i = 0; i < n; i++) {
      cin >> h[i];
  }
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
      for (int j : {i + 1, i + 2}) {
          if (j < n) {
              dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
          }
      }
  }
  cout << dp[n - 1] << "\n";
}

int main() {
  ios::sync_with_stdio(false);
  srand (time(NULL));
  int t = 1;
  // cin >> t;
  while (t--) solve();
  return 0;
}

Measured memory_bytes: 1024
S = input()

S_mae = int(S[:2])
S_ushiro = int(S[2:])

flg_MMYY = 0
flg_YYMM = 0
if 1 <= S_mae and S_mae <= 12:
    flg_MMYY = 1
    if 1 <= S_ushiro and S_ushiro <= 12:
        flg_YYMM = 1
        print('AMBIGUOUS')
    else:
        print('MMYY')
elif 1 <= S_ushiro and S_ushiro <= 12:
    flg_YYMM = 1
    print('YYMM')

else:
    print('NA')


Measured memory_bytes: 3060
import itertools

n = int(input())
s = [0] * n
for _ in range(n):
    s[_] = input()
cnt = [0] * 5
for i in range(n):
    if s[i][0] == 'M':
        cnt[0] += 1
    elif s[i][0] == 'A':
        cnt[1] += 1
    elif s[i][0] == 'R':
        cnt[2] += 1
    elif s[i][0] == 'C':
        cnt[3] += 1
    elif s[i][0] == 'H':
        cnt[4] += 1
    else:
        pass

num = 0
newCnt = []
for i in range(5):
    if cnt[i] > 0:
        num += 1
        newCnt.append(cnt[i])

ans = 0
val = 1
if len(newCnt) < 3:
    ans = 0
elif len(newCnt) < 4:
    for i in range(len(newCnt)):
        val *= newCnt[i]
    ans = val
else:
    com = itertools.combinations(newCnt, 3)
    for i in com:
        val = 1
        for j in i:
            val *= j
        ans += val

print(ans)

Measured memory_bytes: 9716
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 110000
ll MOD=1e9+7;

template< typename T >
vector< T > slide_min(const vector< T > &v, int k)
{
  deque< int > deq;
  vector< T > ret;
  for(int i = 0; i < v.size(); i++) {
    while(!deq.empty() && v[deq.back()] >= v[i]) {
      deq.pop_back();
    }
    deq.push_back(i);
    if(i - k + 1 >= 0) {
      ret.emplace_back(v[deq.front()]);
      if(deq.front() == i - k + 1) deq.pop_front();
    }
  }
  return ret;
}
template< typename T >
vector< T > slide_max(const vector< T > &v, int k)
{
  deque< int > deq;
  vector< T > ret;
  for(int i = 0; i < v.size(); i++) {
    while(!deq.empty() && v[deq.back()] <= v[i]) {
      deq.pop_back();
    }
    deq.push_back(i);
    if(i - k + 1 >= 0) {
      ret.emplace_back(v[deq.front()]);
      if(deq.front() == i - k + 1) deq.pop_front();
    }
  }
  return ret;
}

main(){
  int h,w;cin>>h>>w;
  int a=in(),b=in();
  vector<int> s(h);
  rep(i,h){
    rep(j,w){
    if((j>=a)^(i>=b))cout<<1;
    else cout<<0;
    }
    cout<<endl;
  }
}

Measured memory_bytes: 1280
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
using namespace std;

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

	if (s <= w) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}
}

Measured memory_bytes: 3636
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        String s;
        Scanner reader = new Scanner(System.in);
        s = reader.nextLine();

        String[] str;
        str = s.split(" ");
        BigInteger a = new BigInteger(str[0]);
        BigInteger b = new BigInteger(str[1]);

        BigInteger c = a.multiply(b);

        System.out.println(c);
    }
}



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

using namespace std;

const int MOD = 1e9 + 21;

void solve()
{

}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);

    int c[5] = {};

    for(int i = 1; i <= 3; ++i)
    {
        int x, y;
        cin >> x >> y;
        ++c[x], ++c[y];
    }

    sort(c + 1, c + 5);

    if(c[1] == c[2] && c[3] == c[4] && c[1] == 1 && c[3] == 2)
        cout << "YES\n";
    else
        cout << "NO\n";

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

vector<int> vals[8];
vector<int> sums[900001];

map<int, pair<int, int>> m;
int A[305][305];

signed main() {
	int H, W, D;
	cin >> H >> W >> D;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int inp;
			cin >> inp;
			A[i][j] = inp;
			//m[番号] == (y,x)
			m[inp] = make_pair(i+1, j+1);
		}
	}

	for (int mod = 0; mod < D; mod++) {
		//Dで割ったあまりで場合分け
		sums[mod].push_back(0);
		int start = mod == 0 ? D : mod;
		for (int i = start; i+D <= H * W; i += D) {
			//今
			pair<int, int> before = m[i];
			//後
			pair<int, int> after = m[i + D];
			//マンハッタン距離を計算
			int man = abs(before.first - after.first) + abs(before.second - after.second);
			//累積和にする
			sums[mod].push_back(sums[mod].back() + man);
		}
	}

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int l, r;
		cin >> l >> r;


		int left, right;
		int ans;
		if (l % D == 0) {
			left = sums[l%D][l / D - 1];
			right = sums[l%D][r / D - 1];
			ans = right - left;
		}
		else {
			left = sums[l%D][l / D ];
			right = sums[l%D][r / D];
			ans = right - left;
		}

		cout << ans << "\n";
	}






	return 0;
}

Measured memory_bytes: 30720
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    vector<int> arr;
    int input,ans(0);
    for (int i = 0; i < n; i++)
    {
        cin>>input;
        arr.push_back(input);
    }
    sort(arr.begin(),arr.end());
    for (int i = 0; i < k; i++)
    {
        ans+=arr[i];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3604
/*
       Hi there <3 
──────▄▀▄─────▄▀▄
─────▄█░░▀▀▀▀▀░░█▄
─▄▄──█░░░░░░░░░░░█──▄▄
█▄▄█─█░░▀░░┬░░▀░░█─█▄▄█

*/
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <stack>
#include <sstream>
#include <cstring>
#include <numeric>
#include <ctime>
#include <cassert>
#include <unordered_set>
#include<unordered_map>
#include <random>
#include <valarray>
//#include <fstream>
#define MOD 1000000007
#define re return
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define y0 y32479
#define y1 y95874
#define next next239
#define prev prev239
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define ba back()
#define popcount __builtin_popcountll
#define fastIO()                 \
    {                            \
        ios::sync_with_stdio(0); \
        cin.tie(0);              \
        cout.tie(0);             \
    }
#define in(x) \
    int x;    \
    cin >> x;
#define in1(x) \
    int x;     \
    cin >> x;  \
    x--;
#define inll(x) \
    ll x;       \
    cin >> x;
#define ins(x) \
    string x;  \
    cin >> x;

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef pair<double, double> pdd;
typedef long double LD;
typedef double D;

void Solve()
{
    int n;
    cin>>n;
    int arr[n];
    rep(i,n)
        cin>>arr[i];
    int dp[n+1];
    for(int i=0;i<=n;i++)
    {
        dp[i]=INT_MAX;
    }
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min((dp[i-1]+abs(arr[i-1]-arr[i])),(dp[i-2]+abs(arr[i-2]-arr[i])));
    }
    cout<<dp[n-1]<<"\n";
}

int main()
{
    fastIO();
    int t;
    t=1;
    while (t--)
    {
        Solve();
    }
    return 0;
}

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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0);

signed main () {
  cin.tie(0);
  cout << setprecision(10);
  int n, m; cin >> n >> m;
  if(n == 1) {
    cout << m << endl;
    return 0;
  }
  RFOR(i, m/n, 1) {
    if(m % i == 0) {
      cout << i << endl;
      break;
    }
  }
  
}


Measured memory_bytes: 256
#include <iostream>

typedef long long LL;
typedef unsigned long long ULL;
//typedef pair<int,int> PII;
//typedef vector<int> VI;

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define FILL(A,value) memset(A,value,sizeof(A))
#define f first
#define s second

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << (a - 1) * (b - 1);

    return 0;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	priority_queue<int> pq;
	rep(i, n){
		int a; cin >>a; pq.emplace(a);
	}
	rep(i, m){
		int c = pq.top(); pq.pop();
		pq.emplace(c /2 );
	}
	ll ans =0;
	while(sz(pq)){
		ans += pq.top(); pq.pop();
	}
	cout <<ans <<"\n";
	return 0;
	
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_H = 10005;
const int MAX_N = 1005;

int H, N;
int A[MAX_N], B[MAX_N];
int dp[MAX_H];

signed main()
{
  cin >> H >> N;
  REP(n,N) {
    cin >> A[n] >> B[n];
  }

  REP(h,MAX_H) {
    dp[h] = INF_LL;
  }

  dp[H] = 0;
  for(int h = H; 0 < h; h--) {
    REP(n,N) {
      dp[max((LL)0, h-A[n])] = min(dp[max((LL)0, h-A[n])], dp[h] + B[n]);
    }
  }

  cout << dp[0] << endl;

  return 0;
}


Measured memory_bytes: 384
if __name__ == '__main__':
    n = int(input())
    v = list(map(int,input().split()))
    v.sort()
    for i in range(n-1):
        a = v.pop(0)
        b = v.pop(0)
        v.insert(0, (a+b)/2)
    print(v[0])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main(){
	int m,f,r;
  char grade;
  while(true){
    scanf("%d %d %d",&m,&f,&r);
    if (m == -1 && f == -1 && r == -1) break;
    if (m == -1 || f == -1){
      grade = 'F'; 
    } else if (m+f >= 80){
      grade = 'A';
    } else if (m+f >= 65){
      grade = 'B';
    } else if (m+f >= 50){
      grade = 'C';
    } else if (m+f >= 30){
      grade = (r >= 50)? 'C':'D';
    } else {
      grade = 'F';
    }
    printf("%c\n",grade);
  }
  
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm. fill_n(&an[0][0],n*m,0); typedef long long ll;*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define FO(i,a,b) for(int i = (int)a;i < (int)b;++i)
#define FE(i,a,b) for(int i = (int)a;i <= (int)b;++i)
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
#define print(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
bool cmp(PI p1,PI p2){
	if(p1.ff < p2.ff)return true;	// You should not be writing p1.ss <= p2.ss !!!
	else if(p1.ff == p2.ff){ if(p1.ss < p2.ss)return true; return false; }
	return false;
}

void solve(){
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	int ans = 0;
	if(k >= a){
		ans += a;
		k -= a;
	}else{
		ans += k;
		k = 0;
	}
	if(k >= b){
		k -= b;
	}else{
		k = 0;
	}
	if(k >= c){
		ans -= c;
		k -= c;
	}else{
		ans -= k;
		k = 0;
	}
	cout << ans << endl;
}
/* When you have to multiply many things , do it in different (multiple) lines, not in a single line .*/
int32_t main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(15); std::cout << std::fixed;
	int nT = 1;
	//cin >> nT;
	FE(i,1,nT)
		solve();
	return 0;
}


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

int main(void)
{
    int N, X, m[101];
    cin >> N >> X;

    // sum : m1, m2, m3, …, mn の総和;
    // M   : m1, m2, m3, …, mn の内最も小さい値
    int sum=0, M=1001001001;    
    for(int i=0; i<N; i++){
        cin >> m[i];
        sum += m[i];
        
        // 最小値を更新
        if(m[i] < M){
            M = m[i];
        }
    }

    int ans = N+(X-sum)/M;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

int color[100005][15];
vector<int> G[100005];

class BSplatterPainting {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    unordered_map<int, int> res;
    int N, M;

    void f(int from, int d, int c) {
        queue<P> q;
        q.push({from, d});

        while (!q.empty()) {
            int i, dist;
            tie(i, dist) = q.front();
            q.pop();
            if (color[i][dist] != -1) continue;
            color[i][dist] = c;
            if (res.count(i) == 0) {
                res[i] = c;
            }

            if (dist == 0) continue;
            REP(j, G[i].size()) {
                int to = G[i][j];
                if (color[to][dist - 1] != -1) continue;
                q.push({to, dist - 1});
            }
        }
    }

    void solve(std::istream& cin, std::ostream& cout) {
        cin >> N >> M;

        CLR(color, 0);
        REP(i, N) G[i].clear();

        REP(i, M) {
            int a, b;
            cin >> a >> b;
            a--, b--;
            G[a].push_back(b);
            G[b].push_back(a);
        }

        int Q;
        cin >> Q;
        struct query {
            int v, d, c;
        };
        vector<query> vq(Q);
        REP(i, Q) {
            cin >> vq[i].v >> vq[i].d >> vq[i].c;
            vq[i].v--;
        }
        reverse(vq.begin(), vq.end());

        REP(i, N) REP(j, 11) color[i][j] = -1;

        REP(i, Q) {
            f(vq[i].v, vq[i].d, vq[i].c);
        }

        REP(i, N) {
            cout << res[i] << endl;
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    BSplatterPainting solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 28072
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    ll a,b,n;
    cin >> a >>b >> n;
    ll x = min(b-1,n);
    ll ans = floor((a*x)/b);
    ans = ans - a*floor(x/b);
    cout << ans << endl;
}
    



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define forn(i,n) for(int i = 0; i < (int) n; ++i)
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

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

  int ans = 0;
  forn(i,n){
    int x;
    cin >> x;
    ans += (i%2 == 0 && (x&1));
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3600
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int  A,B,C,D;
int main() {
	cin>>A>>B>>C>>D;

	if((A+B)>(C+D))cout<<"Left"<<endl;
	if((A+B)==(C+D))cout<<"Balanced"<<endl;
	if((A+B)<(C+D))cout<<"Right"<<endl;

    return 0;
    }


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

int a[100050], b[100050];
int ans[100050];
bool vis[100050];
int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &b[i]);
    int maxVal = -1;
    for(int i = 1; i <= n; ++i)
    {
        ans[i] = a[i];
        if(a[i] > maxVal)
        {
            maxVal = a[i];
            vis[i] = true;
        }
    }
    maxVal = -1;
    for(int i = n; i >= 1; --i)
    {
        if(vis[i] && b[i] < ans[i])
        {
            puts("0");
            return 0;
        }
        if(b[i] > maxVal)
        {
            if(vis[i] && ans[i] != b[i])
            {
                puts("0");
                return 0;
            }
            maxVal = b[i];
            vis[i] = true;
        }
        else
            ans[i] = min(ans[i], b[i]);
    }
    long long ret = 1;
    for(int i = 1; i <= n; ++i)
        if(!vis[i])
            ret = ret * ans[i] % 1000000007ll;
    printf("%lld", ret);
    return 0;
}


Measured memory_bytes: 1536
// Problem : A - +-x
// Contest : AtCoder Beginner Contest 137
// URL : https://atcoder.jp/contests/abc137/tasks/abc137_a
// Memory Limit : 1024,000000 MB 
// Time Limit : 2000,000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

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

  cout.precision(16);
  cout << fixed;
  
  int a;
  int b;
  cin >> a >> b;
  
  vector<int> c = {a + b, a - b, a * b};
  
  cout << *max_element(c.cbegin(), c.cend());
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int main(){

ios::sync_with_stdio(false);
cin.tie(0);

string s;
cin>>s;

if(s[2]==s[3] && s[4]==s[5]){
cout << "Yes"<<endl;
}else{
cout << "No"<<endl;

}


}


Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
const int INF = 1e9;

int main(){
   int n, m;
   cin >> n >> m;
   vector<P> v;
   for (int i = 0; i < m; ++i){
      int a, b;
      cin >> a >> b;
      v.push_back(P(b, a));
   }
   /*
   for (int i = 0; i < m-1; ++i){
      for (int j = m-1; j > i; --j){
         if (p[j-1] > p[j]){
            P tmp = p[j];
            p[j] = p[j-1];
            p[j-1] = tmp;
         }
      }
   }
   */
   sort(v.begin(), v.end());

   int ans = 0;
   int cut = 0;
   int j = 0;
   while (max(cut, j) < v.size()){
      ++ans;
      int cp = v[cut].first;
      while (j < v.size()){
         if (v[j].second <= cp-1 && cp <= v[j].first){
            ++j;
         }
         else {
            cut = j;
            break;
         }
      }
   }

   cout << ans << endl;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    scanf("%d",&n);
    vector<string> N(n);
    for(int i=0;i<n;i++) cin>>N[i];
    scanf("%d",&m);
    vector<string> M(m);
    for(int i=0;i<m;i++) cin>>M[i];

    int ans=0;
    for(int i=0;i<n;i++){
        int sum=0;
        for(int j=0;j<n;j++){
            if(N[i]==N[j])
                sum++;      
        }                   
        for(int j=0;j<m;j++){
            if(N[i]==M[j])
                sum--;      
        }                   
        if(ans<sum)
            ans=sum;      
    }
    
    printf("%d\n",ans);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var hw = Array.ConvertAll(ReadLine().Split(' '), long.Parse);
        var res = long.MaxValue;
        for (var j = 0; j < 2; j++)
            for (var i = 1; i < hw[j]; i++)
            {
                var ar = new[] { i * hw[(j + 1) % 2], (hw[j] - i) * (hw[(j + 1) % 2] / 2), (hw[j] - i) * ((hw[(j + 1) % 2] + 1) / 2) };
                var ar2 = new[] { i * hw[(j + 1) % 2], hw[(j + 1) % 2] * ((hw[j] - i + 1) / 2), hw[(j + 1) % 2] * ((hw[j] - i) / 2) };
                res = Min(res, ar.Max() - ar.Min());
                res = Min(res, ar2.Max() - ar2.Min());
            }
        WriteLine(res);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 17476
import sys
def main():
  n,q,*c=map(int,sys.stdin.buffer.read().split())
  a=[0]*q
  j,*b=t=[0]*9**6
  for i in sorted(range(q),key=lambda x:c[x+x-~n]):
    l,r=c[i+i+n],c[i+i-~n]
    while j<r:
      k=c[j]
      j+=1
      x,y,b[k]=b[k]+1,j+1,j
      while x<=n:
        t[x]+=1
        x=x+(x&-x)
      while y<=n:
        t[y]-=1
        y=y+(y&-y)
    s=0
    while l:
      s=s+t[l]
      l=l-(l&-l)
    a[i]=s
  print(' '.join(map(str,a)))
main()

Measured memory_bytes: 326552
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 
 
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll n; cin >> n;
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        if (i % 3 != 0 && i % 5 != 0) {
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[21];
	int i,mojisu;
	
	scanf("%s",&str);
	mojisu=strlen(str);
	
	for(i=0;i<mojisu;i++)
		printf("%c",str[mojisu-i-1]);
	printf("\n");
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int H, W;
	cin >> H >> W;
	
	REP(i, 0, H){
		string s="";
		cin >> s;
		cout << s << endl << s << endl;
	}

}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    REP(i, 1, n + 1)
    {
        if (n % i == 0)
        {
            ans += n / i - 1;
        }
        else
        {
            ans += n / i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;
import java.lang.Math;

class Main {
  static double distance(int x1, int x2, int y1, int y2) {
    int dx = (x1 - x2) * (x1 - x2);
    int dy = (y1 - y2) * (y1 - y2);
    return Math.pow((dx + dy), 0.5);
  }

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

    double ave = 0.0;

    int n = Integer.parseInt(stdIn.next());
    int x[] = new int[n];
    int y[] = new int[n];
    for (int i = 0; i < n; i++) {
      x[i] = Integer.parseInt(stdIn.next());
      y[i] = Integer.parseInt(stdIn.next());
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        ave += distance(x[i], x[j], y[i], y[j]);
      }
    }

    ave /= n;

    System.out.println(ave);
  }
}


Measured memory_bytes: 23252