akhauriyash/Code-Regression huggingface dataset:
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var n int
    fmt.Scan(&n)
    a := make([]int, n)
    for i:=0;i<n;i++{
        fmt.Scan(&a[i])
    }
    ma := 0
    mi := 10000
    for i:=0;i<n;i++{
        ma = max32(ma,a[i])
        mi = min32(mi,a[i])
    }
    fmt.Println(ma-mi)
}





// Pairsort
type Pair struct {
    first,second int64
}

type By func(p1, p2 *Pair) bool

func (by By) Sort(pairs []Pair) {
    ps := &pairSorter{
            pairs : pairs,
            by: by,
    }
    sort.Sort(ps)
}

type pairSorter struct {
    pairs []Pair
    by func(p1, p2 *Pair) bool
}

func (s *pairSorter) Len() int {
    return len(s.pairs)
}

func (s *pairSorter) Swap(i, j int) {
    s.pairs[i], s.pairs[j] = s.pairs[j], s.pairs[i]
}

func (s *pairSorter) Less(i, j int) bool {
    return s.by(&s.pairs[i], &s.pairs[j])
}

func first (p1, p2 *Pair) bool {
        return p1.first < p2.first
}

func second (p1, p2 *Pair) bool {
        return p1.second < p2.second
}
// end



func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func makeTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func sortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}

func reverseString(s string) string{
    t := []rune(s)
    for i,j := 0, len(s)-1 ; i < j ; i, j = i+1, j-1 {
        t[i], t[j] = t[j], t[i]
    }
    return string(t)
}

func inside(h,w,H,W int) bool{
    if h>=0 && h<H && w>=0 && w<W{
        return true
    }
    return false
}


Measured memory_bytes: 640
a,z,x,i,j;main(t){for(scanf("%d",&t);t--;printf("%d %d\n",-z,a)){for(a=z=0,scanf("%d%d",&x,&i);--x;)scanf("%d",&j),i-=j,a=i>a?i:a,z=i<z?i:z,i=j;}exit(0);}

Measured memory_bytes: 0
#include<cstdio>

int abs(int x,int y){
	if(x>y) return x-y;
	else return y-x;
}

int main(){
	int n;
	int a[100002];
	scanf("%d",&n);
	a[0] = a[n+1] = 0;
	for(int i=0;i<n;i++) scanf("%d",a+i+1);
	int sum = 0;
	for(int i=0;i<=n;i++) sum += abs(a[i],a[i+1]);
	for(int i=1;i<=n;i++) printf("%d\n",sum-abs(a[i-1],a[i])-abs(a[i],a[i+1])+abs(a[i-1],a[i+1]));
}


Measured memory_bytes: 1536
import java.util.*;
import java.text.*;
import java.math.*;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		
		while(true){
			int m = in.nextInt();
			int d = in.nextInt();
			if((m|d) == 0) break;
			int day = d;
			switch(m){
			case 12:
				day += 335;
				break;
			case 11:
				day += 305;
				break;
			case 10:
				day += 274;
				break;
			case 9:
				day += 244;
				break;
			case 8:
				day += 213;
				break;
			case 7:
				day += 182;
				break;
			case 6:
				day += 152;
				break;
			case 5:
				day += 121;
				break;
			case 4:
				day += 91;
				break;
			case 3:
				day += 60;
				break;
			case 2:
				day += 31;
				break;
			default:
			}
			switch(day%7){
			case 1:
				System.out.println("Thursday");
				break;
			case 2:
				System.out.println("Friday");
				break;
			case 3:
				System.out.println("Saturday");
				break;
			case 4:
				System.out.println("Sunday");
				break;
			case 5:
				System.out.println("Monday");
				break;
			case 6:
				System.out.println("Tuesday");
				break;
			case 0:
				System.out.println("Wednesday");
				break;
			}
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
//失敗
int main()
{
    int H,W,i,j=0;
    scanf("%d %d",&H,&W);
    char P[H][W+1];
    for(i=0;i<H;i++) scanf("%s",P[i]);
    for(i=0;i<(H+2)*(W+2);i++){
        if(i<W+2||i%(W+2)==0||i%(W+2)==W+1||i>=(H+1)*(W+2)) printf("#");
        else if(i%(W+2)==1) printf("%s",P[j++]);
        if(i%(W+2)==W+1) puts("");
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=500010;
vector<int>G[N];
int d[N],n;char s[N];
void Add(int u,int v){G[u].push_back(v);d[v]++;}
int a[N];ll ans;
queue<int>Q;
int main()
{
	scanf("%s",s+1);n=strlen(s+1)+1;
	for(int i=1;i<n;i++)
	{
		if(s[i]=='<')Add(i,i+1);
		else Add(i+1,i);
	}
	for(int i=1;i<=n;i++)
		if(!d[i])Q.push(i);
	while(!Q.empty())
	{
		int u=Q.front();Q.pop();
		for(int v:G[u])
		{
			a[v]=max(a[v],a[u]+1);
			if(!--d[v])Q.push(v);
		}
	}
	for(int i=1;i<=n;i++)ans+=a[i];
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 32000
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define REV(i,a,n) for(int i=a;i>=n;i--)
#define all(a) a.begin(),a.end()
#define UB upper_bound
#define LB lower_bound
const int NUM = 2e5 + 5;
int dp[3001][3001][2];

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int num_tests=1; 
    //cin >> num_tests;
    while(num_tests-->0){
        int n; cin >> n;
        vector<int> a(n);
        for(auto &x:a) cin >> x;
        FOR(i,0,n)
            dp[i][i][0] = a[i], dp[i][i][1] = 0;
        for(int R_L = 1; R_L < n; R_L++){
            for(int L = 0; L + R_L < n; L++){
                int R = L + R_L;
                dp[L][R][0] = max(a[L] + dp[L+1][R][1],a[R] + dp[L][R-1][1]);
                dp[L][R][1] = min(dp[L+1][R][0],dp[L][R-1][0]);
            }
        }
        int sm = 0;
        for(auto x:a)
            sm += x;
        cout << 2*dp[0][n-1][0] - sm;
    }   
}

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin>>s;
    for(int i = 0; i<s.length(); i+=2){
        cout<<s[i];
    }

    return 0;
}

Measured memory_bytes: 592
// D - String Equivalence
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	vector<string> s(1,"a");
	while(--N){
		vector<string>t; swap(s,t);
		for(int i=0; i<t.size(); ++i){
			char mx='a'; for(auto c:t[i]) mx = max(mx, c); mx++;
			for(char c='a'; c<=mx; ++c) s.push_back(t[i] + string(1,c));
		}
	}
	for(auto x:s) cout<< x <<endl;
}

Measured memory_bytes: 8780
#include<bits/stdc++.h>
using namespace std;
int main ()
{
long long  n,t,a,d;
cin>>n>>t>>a;
long long  l =0;
long long  c =48594839489;
for(long long  i =1;i<=n;i++)
{
cin>>d;
long long s=(( t*1000-d*6)-(a *1000));
if (s <0) 
s =(-1)* s ;
if (c>s )
{
c=s;
l=i;
}
}
cout<<l<<endl;
return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	string s;
	cin >> s;

	cout << s.substr(0, s.length() - 8) << endl;

	return 0;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define MODNUM (INT(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
void chmax(T& m, T x) {
	m = max(m, x);
}

template <typename T>
void chmin(T& m, T x) {
	m = min(m, x);
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int n;
	scanf("%d", &n);
	VI p(n);
	REP(i, n) { scanf("%d", &p[i]); }
	VI min_list(n);
	int min_num = INF;
	REP(i, n) {
		chmin(min_num, p[i]);
		min_list[i] = min_num;
	}
	int result = 0;
	REP(i, n) {
		if(min_list[i] >= p[i]) {
			result++;
		}
	}
	printf("%d\n", result);
	return 0;
}

Measured memory_bytes: 1792
n = input()
K = int(input())


dp = [[[0] * (K + 2) for _ in range(2)] for _ in range(len(n) + 1)]
# positon, is_less, k-nums
dp[0][0][0] = 1

for i in range(len(n)):
    for j in range(2):
        digit = 9 if j else int(n[i])
        for k in range(K + 1):
            for d in range(digit + 1):
                if d != 0:
                    dp[i + 1][j or d < digit][k + 1] += dp[i][j][k]
                else:
                    dp[i + 1][j or d < digit][k] += dp[i][j][k]

ans = 0
for j in range(2):
    ans += dp[-1][j][K]
print(ans)

Measured memory_bytes: 40816
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

struct edge { int from, to, cost; };

int n, m, a[2000], b[2000], c[2000];
edge e[2000];
int d[1000];
bool bo[1000];

void BF() {
	fill(d, d + n, INF);
	d[0] = 0;
	int cnt = 0;
	while (1) {
		for (int i = 0; i < m; i++) {
			edge x = e[i];
			if (d[x.from] == INF)continue;
			if (d[x.to] > d[x.from] + x.cost) {
				d[x.to] = d[x.from] + x.cost;
			}
		}
		cnt++;
		if (cnt == n - 1)return;
	}

}

void LO() {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			edge x = e[j];
			if (d[x.from] == INF)continue;
			if (d[x.to] > d[x.from] + x.cost) {
				d[x.to] = d[x.from] + x.cost;
				bo[x.to] = true;
			}
			if (bo[x.from])bo[x.to] = true;
		}
	}
}

signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;
		b[i]--;
		e[i] = { a[i],b[i], - c[i] };
	}
	BF();
	LO();
	if (bo[n - 1])cout << "inf" << endl;
	else cout << -d[n - 1] << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{
	int i=0,x[3000],y[3000],k;
	while(1)
	{
    	scanf("%d %d",&x[i],&y[i]);
    	if ( x[i] == 0 && y[i] == 0 )
    	{
    		break;  
		}
		i++;
	}
	for(k=0;k<i;k++)
	{
		if(x[k]<y[k] )
 		{
 			printf("%d %d\n",x[k],y[k]);
 		}
		else 
		{
    		printf("%d %d\n",y[k],x[k]);
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
    int result = 0;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++)
        if (s[i] != t[i])
            result++;
    cout << result;
    return 0;
}

Measured memory_bytes: 3800
import copy

def main():
	N, M = [int(n) for n in input().split(" ")]
	edges = [[] for i in range(N)]
	# edges[i] : edges from vertex i 
	r = []
	for i in range(M):
		a, b = [int(x) for x in input().split(" ")]
		edges[a - 1].append(b - 1)
		edges[b - 1].append(a - 1)
		r.append([a - 1, b - 1])
	cnt = 0
	for i in range(len(r)):
		if not isConnected(edges, r[i]):
			cnt += 1
	print(cnt)

def isConnected(edges, remove_edge):
	n_v = len(edges)
	checked = [0] * n_v
	to_check = [0]
	e = copy.deepcopy(edges)
	e[remove_edge[0]].remove(remove_edge[1])
	e[remove_edge[1]].remove(remove_edge[0])
	while len(to_check) > 0:
		checking = to_check.pop(0)
		checked[checking] = 1
		for i in e[checking]:
			if checked[i] == 1:
				continue
			else:
				to_check.append(i)
	if n_v == sum(checked):
		return True
	else:
		return False


main()

Measured memory_bytes: 9372
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
    int n,q,t,c,S[10000] = {},T[500] = {};
    c = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        scanf("%d",&S[i]);
    }
    cin >> q;
    for(int i=0;i<q;i++){
        scanf("%d",&T[i]);
    }
    
    for(int i=0;i<q;i++){
        t = T[i];
        for(int j=0;j<n;j++){
            if(S[j] == T[i]){
                c++;
                break;
            }
        }
    }
    cout << c << endl;
}



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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x, y) CPP_CAT_I(x, y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x, y) x##y

#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define M5 100007
#define M9 1000000000

// util {{{
#define FOR(i, start, end) for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); i < CPP_CAT(i, xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f, c, ...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); })(c))
#define ll long long int
#define VI vector<int>
template <typename C>
i64 SIZE(const C &c)
{
    return static_cast<i64>(c.size());
}

template <typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {})
{
    if (comp(xmax, x))
    {
        xmax = x;
        return true;
    }
    return false;
}

template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {})
{
    if (comp(x, xmin))
    {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit
{
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit()
    {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

bool isOK(int mid, double key)
{
}

int binary_search(double key)
{
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = 2000000000;
    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1)
    {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key))
            right = mid;
        else
            left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}

bool isKaibun(string st)
{
    bool ans = true;
    int n = st.length();
    REP(i, n / 2)
    {
        if (st[i] != st[n - i - 1])
        {
            return false;
        }
    }
    return true;
}

int toInt(char a)
{
    return a - '0';
}

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

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

void solve()
{
    int S, W;
    cin >> S >> W;

    if (S <= W)
    {
        cout << "unsafe";
    }
    else
    {
        cout << "safe";
    }
}

signed main()
{

    solve();

    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
  string c;
  int sta,end;
  cin >> c;
  sta =0;
  end =0;
  for(int i=0;i<=(int)c.size();i++){
    if('A' ==c[i]){sta =i;
      break;}
  }
  for(int i=(int)c.size();i>=0;i--){
    if('Z'==c[i]){end =i;
      break;}
  }
  cout << end - sta +1 << endl;

}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	a, b, c := scanInt(), scanInt(), scanInt()
	x, y := scanInt(), scanInt()

	total := 0
	if a+b > 2*c {
		var z, d int
		if x > y {
			total += y * c * 2
			z = x - y
			d = a
		} else {
			total += x * c * 2
			z = y - x
			d = b
		}

		if d > c*2 {
			total += z * c * 2
		} else {
			total += z * d
		}
	} else {
		if a > c*2 {
			total += x * c * 2
		} else {
			total += x * a
		}

		if b > c*2 {
			total += y * c * 2
		} else {
			total += y * b
		}
	}
	fmt.Println(total)
}


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

#define int long long 

struct UnionFind{
    vector<int> par;
    vector<int> sizes;

    UnionFind(int size) : par(size), sizes(size,1){
        for(int i=0;i<size;i++) par[i] = i;
    }

    bool unite(int x,int y){
        x = find(x);
        y = find(y);

        if(x == y) return false;
        if(sizes[x] < sizes[y]) swap(x,y);

        par[y] = x;
        sizes[x] += sizes[y];
        sizes[y] = 0;

        return true;
    }

    int find(int x){
        if(par[x] == x) return x; 
        return par[x] = find(par[x]);
    }

    bool isSame(int x,int y){
        return find(x) == find(y);
    }

    int getSize(int x){
        return sizes[find(x)];
    }
};

signed main(){
    int N,M;
    cin >> N >> M;
    UnionFind forest(N);

    vector<int> A(M),B(M);
    for(int i=0;i<M;i++){
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
    }

    vector<int> ans(M);
    ans[M-1] = N*(N-1)/2;

    for(int i=M-1;i>0;i--){
        int sizeA = forest.getSize(A[i]);
        int sizeB = forest.getSize(B[i]);
        ans[i-1] = ans[i];
        if(forest.unite(A[i],B[i])) ans[i-1] -= (sizeA*sizeB);
    }

    for(int i=0;i<M;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 5248
/**********************************************************************
   File hoge.cpp
   Author  harunaya
   Date   2020-05-17(Sun)
   note   
**********************************************************************/

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int a, b;
  cin >> a >> b;
  cout << a*b << endl;
  return 0; 
}

Measured memory_bytes: 3624
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    a, b, c, d = [int(sys.stdin.readline().rstrip()) for _ in range(4)]
    print(min(a, b) + min(c, d))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  cout << ceil(N / 111.0) * 111 << endl;
  return 0;
}


Measured memory_bytes: 256
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  
  int n; rd(n);
  auto a=readln.split.to!(int[]);

  foreach(ref e; a) e-=1;
  int c=0;
  foreach(i; 0..n-1){
    if(i==a[i]){
      swap(a[i], a[i+1]);
      c+=1;
    }
  }
  if(a[n-1]==n-1) c+=1;

  writeln(c);

}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Measured memory_bytes: 4284
n,s=map(int,input().split())
x=list(map(int,input().split()))

import fractions as frc

x.append(s)
al=sorted(x)

ds=[0]*n
for i in range(n):
	ds[i]=al[i+1]-al[i]

if n>1:
	gc=[0]*(n-1)
	for i in range(n-1):
		gc[i]=frc.gcd(ds[i],ds[i+1]) 
    
if n==1:
	res=ds[0]
else:
	res=min(gc)

print(res)

Measured memory_bytes: 16656
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.StringJoiner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        Map<Long, Long> valToKey = new HashMap<>();
        Map<Long, Long> keyToVal = new HashMap<>();
        for (long i = 0; i <= 6_000; i++) {
            keyToVal.put(i, i * i * i * i * i);
            valToKey.put(i * i * i * i * i, i);
        }
        StringJoiner sj = new StringJoiner(" ");
        for (long i = 0; i <= 6_000; i++) {
            // A +, B +
            if (valToKey.containsKey(keyToVal.get(i) - x)) {
                sj.add(String.valueOf(i));
                sj.add(String.valueOf(valToKey.get(keyToVal.get(i) - x)));
                System.out.println(sj);
                return;
            }
            // A +, B -
            if (valToKey.containsKey(x - keyToVal.get(i))) {
                sj.add(String.valueOf(i));
                sj.add(String.valueOf(valToKey.get(x - keyToVal.get(i)) * -1));
                System.out.println(sj);
                return;
            }
            // A -, B -
            if (valToKey.containsKey(x + keyToVal.get(i))) {
                sj.add(String.valueOf(i * -1));
                sj.add(String.valueOf(valToKey.get(x + keyToVal.get(i)) * -1));
                System.out.println(sj);
                return;
            }
        }
    }

}


Measured memory_bytes: 37904
N, K = map(int, input().split())
R, S, P = map(int, input().split())
point = {"r": P, "s": R, "p": S}
T = input()


res = [0 for _ in range(N)]
for i, t in enumerate(T):
    if i - K < 0 or (i - K >= 0 and (res[i - K] == 0 or T[i - K] != T[i])):
        res[i] = point[t]

print(sum(res))


Measured memory_bytes: 4212
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

void solve(){  
	int n,k;
	cin>>n>>k;
	int ans=0;
	rep(i,0,n){
		int x;
		cin>>x;
		ans+=(x>=k);
	}  
	cout<<ans<<endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

int main() {
  int a,b,c;cin>>a>>b>>c;
  cout <<max(c-(a-b),0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}

const ll MOD = 1000000007;
const int INF = 1<<29;

int main(){
  string S; cin >> S;
  if (S == "SUN") cout << 7 << endl;
  else if (S == "MON") cout << 6 << endl;
  else if (S == "TUE") cout << 5 << endl;
  else if (S == "WED") cout << 4 << endl;
  else if (S == "THU") cout << 3 << endl;
  else if (S == "FRI") cout << 2 << endl;
  else cout << 1 << endl;
}


Measured memory_bytes: 256
fn main() {
    let s: String = read();
    let t: String = read();

    println!("{}{}", t, s);
}

use std::io::stdin;
use std::io::Read;
use std::str::FromStr;

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


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef vector<double> vec;
typedef vector<vec> mat;
const double EPS=1E-8;


vec gauss_jordan(const mat& A,const vec& b){
  int n=A.size();
  mat B(n,vec(n+1));

  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)B[i][j]=A[i][j];

  for(int i=0;i<n;i++)B[i][n]=b[i];

  for(int i=0;i<n;i++){
    int pivot=i;
    for(int j=i;j<n;j++)
      if(abs(B[j][i])>abs(B[pivot][i]))pivot=j;
    swap(B[i],B[pivot]);

    if(abs(B[i][i])<EPS)return vec(); 

    for(int j=i+1;j<=n;j++)B[i][j]/=B[i][i];

    for(int j=0;j<n;j++)
      if(i!=j)
	for(int k=i+1;k<=n;k++)B[j][k]-=B[j][i]*B[i][k];
    
  }

  vec x(n);
  for(int i=0;i<n;i++)x[i]=B[i][n];
  return x;
}
#define N 101
#define INF 1e9

int main(){

  while(1){
    int n,s,t;
    cin>>n>>s>>t;
    if(!n&&!s&&!t)break;
    s--,t--;
    int G[N][N],g[N][N],q[N];
    for(int i=0;i<n;i++)cin>>q[i];

    for(int i=0;i<n;i++)
      for(int j=0,c;j<n;j++)cin>>c,G[i][j] = g[i][j] =c>0? c:INF;
    

    for(int i=0;i<n;i++) G[i][i] = 0;
    for(int k=0;k<n;k++)
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)G[i][j] = min(G[i][j],G[i][k]+G[k][j]);


    mat A(n,vec(n,0));
    vec B(n,0);
    for(int i=0;i<n;i++){
      if(G[i][t]==INF||i==t) {A[i][i] = 1; continue;}

      int cnt=0,sum=0;
      G[t][t]=0;
      for(int j=0;j<n;j++){
	if(g[i][j] >= INF||
	   (q[i]&&G[i][t]<g[i][j]+G[j][t]))continue;
	A[i][j] = -1;
	sum+=g[i][j];
	cnt++;
      }
      B[i] = sum;
      A[i][i] = cnt;
    }
  
    vec ans=gauss_jordan(A,B);
    if(ans.empty()) cout<<"impossible"<<endl;
    else printf("%.10f\n",(double)ans[s]);
  }
  return 0;
}

Measured memory_bytes: 3484
#include <iostream>
#include <vector>
#include <utility>

using namespace std;
typedef pair<int, int> P;

int n;
vector<P> ans;

int main(void)
{
	cin >> n;
	
	int x = n/2*2;
	for(int i = 1; i <= x; i++){
		for(int j = 1; j <= x; j++){
			if(i >= j) continue;
			if(i+j != x+1) ans.push_back(make_pair(i, j));
		}
	}
	if(n%2){
		for(int i = 1; i <= x; i++) ans.push_back(make_pair(n, i));
	}
	
	cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++) cout << ans[i].first << " " << ans[i].second << endl;
	
	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    vector<vector<int>> g(3*n);
    int s,t;
    for(int i = 0; i < m; i++) {
        cin >> s >> t;
        s--;
        t--;
        g[s*3].emplace_back(t*3+1);
        g[s*3+1].emplace_back(t*3+2);
        g[s*3+2].emplace_back(t*3);
    }
    cin >> s >> t;
    s=(s-1)*3;
    t=(t-1)*3;

    vector<int> dist(n*3,-1);
    dist[s]=0;
    queue<int> q;
    q.push(s);
    while(!q.empty()) {
        int v=q.front();
        int d=dist[v];
        q.pop();
        for(auto &nv : g[v]) {
            if(dist[nv]!=-1) continue;
            dist[nv]=d+1;
            q.push(nv);
        }
    }
    if(dist[t]==-1) cout << "-1" << "\n";
    else cout << dist[t]/3 << "\n";

    return 0;
}

Measured memory_bytes: 20836
N = int(input())
S1 = input()
S2 = input()
pro = 1
i = 0
if S1[0] != S2[0]:
    pro = 6
    i = 2
    two = True
else:
    pro = 3
    i = 1
    two = False
while i < N:
    if S1[i] != S2[i]:
        i += 2
        if two:
            pro *= 3
        else:
            pro *= 2
        two = True
    else:
        i += 1
        if not two:
            pro *= 2
        two = False
print(pro%(10**9+7))



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++){
    cin >> H[i];
  }
  int M = 0;
  int C = 0;
  for (int i = 1; i < N; i++){
    if (H[i] <= H[i - 1]){
      C++;
      M = max(M, C);
    } else {
      C = 0;
    }
  }
  cout << M << endl;
}

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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0, w = 0;
    rep(i,n) if(s[i]=='R') r++;
    int ans = max(r, w);
    rep(i,n) {
        if(s[i]=='R') --r;
        else w++;
        int temp = max(r, w);
        ans = min(ans, temp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3736
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}



int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;

      bool flag=false;

      string str;
      cin>>a>>b;

      cout<<a*b<<endl;



}



Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args)throws Exception {
		BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
		br.readLine();
		long result = 0;
		int card1 = Integer.parseInt(br.readLine());
		while(br.ready()) {
			int card2 = Integer.parseInt(br.readLine());
			if(card1>0 && card2>0 && card1%2 !=0) {
				card2 -= 1;
				result += 1;
			}
			result += card1/2;
			card1 = card2;
		}
		result += card1/2;
		System.out.println(result);
	}
}

Measured memory_bytes: 32684
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		int h, w;

		Scanner stdIn = new Scanner(System.in);

		while (true) {
			h = stdIn.nextInt();
			w = stdIn.nextInt();

			if ((h + w) == 0) {
				System.exit(0);
			}

			for (int i = 0; i < h; i++) {
				if ((i % 2) == 0) {
					for (int j = 0; j < w; j++) {
						if ((j % 2) == 0) {
							System.out.print('#');
						} else {
							System.out.print('.');
						}
					}
				} else {
					for (int j = 0; j < w; j++) {
						if ((j % 2) == 1) {
							System.out.print('#');
						} else {
							System.out.print('.');
						}
					}
				}
				System.out.println();
			}
System.out.println();
		}

	}

}

Measured memory_bytes: 37068
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const double PI=3.14159265358979323846;
int main(){
    int a,b,x;
    cin >> a >> b >> x;
    if(a*a*b >= 2*x){    
        double y = atan((double)(b*b*a) / (double)(2*x)) / (PI) * 180;
        cout << fixed << setprecision(10) << y << endl;
    } else {
        double z = atan((double)(2*b)/a - (double)(2*x)/(double)(a*a*a)) / (PI) * 180;
        cout << fixed << setprecision(10) << z << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e14+4;
const int Nmax=2e5+1;
const int Nd=61;

int main(){
  int d,t,s;
  cin>>d>>t>>s;

  if(d<=t*s){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }



}


Measured memory_bytes: 3628
X = int(input())

#x^5-y^5=(x-y)(x^4+x^3y+x^2y^2+xy^3+y^4)

#for x in range(1, 121):
#  if ((x**5) - ((x-1)**5)) >= 1000000000:
#    print(x)

for a in range(0, 121):
  for b in reversed(range(-122, 120)):
    if b**5 == a**5-X:
      print(a, b)
      exit()



Measured memory_bytes: 64560
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    int N; cin >> N;
    vector<vector<int>> G(N);
    for (int i = 0; i < N - 1; i++) {
        int p, q; cin >> p >> q; p--, q--;
        G[p].push_back(q);
        G[q].push_back(p);
    }
    int nleaf = 0;
    vector<int> value(N);
    for (int i = 0; i < N; i++) {
        if (G[i].size() == 1) nleaf++;
        if (G[i].size() == 2) value[i] = 1;
    }
    auto far = [&](int node) {
        vector<int> score(N);
        stack<tuple<int, int, int>> S;
        S.emplace(value[node], node, node);
        while (!S.empty()) {
            auto [s, n, p] = S.top(); S.pop();
            score[n] = s;
            for (int next : G[n]) if (next != p) {
                S.emplace(s + value[next], next, n);
            }
        }
        auto it = max_element(begin(score), end(score));
        return make_pair(it - begin(score), *it);
    };
    auto p = far(0);
    auto q = far(p.first);
    cout << nleaf + q.second << '\n';
    return 0;
}


Measured memory_bytes: 9564
#include<stdio.h>

int quotient(int x, int y);

int remainder(int x, int y);

double float_quotient(int x, int y);

int main(void){
  int a, b;
  int d, r;
  double f;
  scanf("%d", &a);
  scanf("%d", &b);
  d = quotient(a, b);
  r = remainder(a, b);
  f = float_quotient(a, b);
  printf("%d %d %f\n", d, r, f);

  return 0;
}

int quotient(int x, int y){
  int d;
  d = (x - x%y)/y;
  return d;
}

int remainder(int x, int y){
  int r;
  r = x%y;
  return r;
}

double float_quotient(int x, int y){
  double f;
  f = (double)x/(double)y;
  return f;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int gen_time, gen_num, total_time;
  int ans = 0;
  
  cin >> gen_time >> gen_num >> total_time;
  int time = gen_time;
  
  while(time <= total_time){
    ans += gen_num;
    time += gen_time;
  }
  
  cout << ans << endl;
}

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

uint64_t ceil(uint64_t a, uint64_t b) {
    return a/b + (a % b == 0 ? 0 : 1);
}

int main() {
    uint64_t N, T, A, t_num = 1, a_num = 1, n;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> T >> A;
        n = max(ceil(t_num, T), ceil(a_num, A));
        t_num = T * n;
        a_num = A * n;
    }
    cout << t_num + a_num << endl;
    return 0;
}


Measured memory_bytes: 256
object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val pw = new java.io.PrintWriter(System.out)
	
	@scala.annotation.tailrec
	def f(n: Int, k: Int, r: Int): Int =
		if (n < k) r + n.toString.size else f(n / k, k, r+1)

	pw.println(f(sc.nextInt, sc.nextInt, 0))
	pw.flush()
}

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

int main() {
    int r;
    cin >> r;
    cout << 3*r*r << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<map>
#include<iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(n,x) for(ll i=0;i<n;i++) cin>>x[i];


int main()
{
	ll n;
	cin >> n;
	vector<string> k;
	string s;
	for (ll i = 0; i < n; i++)
	{
		cin >> s;
		sort(s.begin(), s.end());
		k.push_back(s);
	}
	sort(k.begin(), k.end());
	vector<ll> p(n, 1);
	string x = k[0];
	ll q = 0;
	for (ll i = 1; i < n; i++)
	{
		if (k[i - 1] == k[i]) p[q]++;
		else q++;
	}
	ll ans = 0;
	for (ll i = 0; i < n; i++)
	{
		if (p[i] != 0)
		{
			ans += p[i] * (p[i] - 1) / 2;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 7448
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=50+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("C.in","r",stdin);
	freopen("C.out","w",stdout);
#endif
}
int n,a[N],b[N];
void input()
{
	n=read<int>();
	For(i,1,n)a[i]=read<int>();
	For(i,1,n)b[i]=read<int>();
}
int f[N][N],g[N][N];
ll ans;
void get(int x,int (*E)[N])
{
	For(i,0,50)E[i][i%x]=1;
}
bool check(int d)
{
	memcpy(g,f,sizeof g);
	For(i,1,d)get(i,g);
	For(k,0,50)For(i,0,50)For(j,0,50)g[i][j]|=(g[i][k]&g[k][j]);
	For(i,1,n)if(!g[a[i]][b[i]])return 0;
	return 1;
}
void dfs(int d)
{
	ans+=1ll<<(d+1);
	if(!d)return;
	Fordown(i,d,0)
	{
		if(!check(i))
		{
			get(i+1,f);
			dfs(i);break;
		}
	}
}
void work()
{
	For(i,0,50)f[i][i]=1;
	Fordown(i,50,0)
	{
		if(!check(i))
		{
			if(i==50){puts("-1");return;}
			get(i+1,f);dfs(i);
			break;
		}
	}
	write(ans,'\n');
}
int main()
{
	
	input();
	work();
	return 0;
}



Measured memory_bytes: 256
li = []
for l in range(6):
    li.append(input())

t = 0
s = li.pop()
for i in li:
    for k in li:
        if int(k) - int(i) > int(s):
            t = 1
        elif int(i) - int(k) > int(s):
            t = 1

if t == 0:
    print("Yay!")
else:
    print(":(")

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

unsigned gcd(unsigned a, unsigned b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

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

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

	a[n]=x;
	sort(a,a+n+1);

	for (int i = 0; i < n; ++i){
		b[i]=a[i+1]-a[i];
	}

	int ans=b[0];
	for (int i = 1; i < n; ++i){
		ans=gcd(ans,b[i]);
	}

	cout << ans << endl;



}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cstdlib>
#include <queue>
#include <map>
#include <stack>
#define ll long long
using namespace std;



int main(){
  //cout<<123<<endl;
  int N;
  string A,B,C;cin>>N; cin>>A>>B>>C;
  int ans=0;
 
  for(int i=0;i<N;i++){
    if(A[i]==B[i] and B[i]==C[i]) continue;
    if(A[i]==B[i]) {ans++;continue;}
    if(B[i]==C[i]) {ans++;continue;}
    if(C[i]==A[i]) {ans++;continue;}
    ans++;ans++;continue;
    
  }
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 384
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define PB pop_back 
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll; 
typedef map<int , int> mii;
typedef pair<int , int> pii; 
typedef map<string , int> msi;
typedef pair<int , string> pis; 
typedef pair<int , pair<int , int> > piii;
int n , d[50 + 10] , sum;
int32_t main()
{
		cin >> n;
		for(int i = 0 ; i < n ; i ++)
				cin >> d[i];
		for(int i = 0 ; i < n ; i ++)
				for(int j = i ; j < n ; j ++)
						if(i != j)
								sum += d[i] * d[j];
		return cout << sum << endl , 0;
}


Measured memory_bytes: 256
/* created   : 2019-09-04 00:19:31
 * accepted  : 2019-09-04 00:44:25
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int a, b; cin >> a >> b;
  int ans = (b - 1 + a - 2) / (a - 1);
  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h> //I - Grid 1
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int maxn = 3010;
const int mod = 1e9 + 7;
typedef long long int ll;


ll dp[maxn][maxn],v[maxn];
ll sum[maxn];
int n,m,ans;


ll solve(int i,int j)
{
	if(i == j) return dp[i][j] = v[i];
	if(dp[i][j] != -1) return dp[i][j];

	return dp[i][j] = sum[j] - sum[i-1] - min(solve(i+1,j),solve(i,j-1));
}

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

	for(int i=0;i<maxn;++i)
		for(int j=0;j<maxn;++j)
			dp[i][j] = -1;

	for(int i=1;i<=n;++i)
	{		
		cin>>v[i];
		sum[i] = sum[i-1] + v[i];
	}

	ll X = solve(1,n);
	ll Y = sum[n] - X;

	cout<<X - Y<<"\n";
}

Measured memory_bytes: 74608
#include<stdio.h>
int main(void){
    int a,b,c,k,max,t1,t2,sum,i;
    scanf("%d %d %d",&a,&b,&c);
    scanf("%d",&k);
    if(b<a && c<a){
        max=a;
        t1=b;
        t2=c;
    }else if(a<b && c<b){
        max=b;
        t1=a;
        t2=c;
    }else{
        max=c;
        t1=a;
        t2=b;
    }
    for(i=0;i<k;i++){
        max=max*2;
    }
    printf("%d\n",max+t1+t2);
    return 0;
}


Measured memory_bytes: 128
k, l = map(int, input().split())
a = list(map(int, input().split()))
e = []
for i in range(len(a)-1):
    e.append(a[i + 1] - a[i])
e.append(a[0] + (k - a[-1]))
ans = sum(e) - max(e)
print(ans)

Measured memory_bytes: 26436
'use strict'

const main = input => {
	const args = input.split(' ')
	const a = parseInt(args[0], 10)
	const b = parseInt(args[1], 10)
	if (a * b % 2 === 0) console.log('Even')
	else console.log('Odd')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

int main(int argc, char *argv[])
{
    bool seats[100000] = {};
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        int l, r;
        cin >> l >> r;
        l -= 1;
        r -= 1;
        for(int j = l; j <= r; ++j) seats[j] = true;
    }

    cout << accumulate(begin(seats), end(seats), 0) << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int maxn = 1e5 + 50;
const ll mod = 1e9+7;
ll a[150];
int n, k;
ll dp[maxn];
ll sum[maxn];
int main(){
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    dp[0] = 1;
    for(int i = 1; i <= n; i++){
        sum[0] = dp[0];
        for(int j = 1; j <= k; j++) sum[j] = (sum[j-1] + dp[j]) % mod;
        for(int j = 0; j <= k; j++){
            if(j - a[i] <= 0) dp[j] = sum[j];
            else dp[j] = (sum[j] - sum[j-a[i]-1] + mod) % mod;
        }
    }
    printf("%lld\n", dp[k]);
    return 0;
}





Measured memory_bytes: 1920
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	string S;

	cin >> N >> S;

	int count = 0;

	for(int i = 0; i < N; i++) {
		if(S[i] == 'A') {
			if(S[i + 1] == 'B') {
				if(S[i + 2] == 'C') {
					count++;
				}
			}
		}
	}

	cout << count << endl;

}


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

int main() {
	long long A, B, M;
	cin >> A >> B >> M;
	vector<int> a(A), b(B), x(M), y(M), c(M);
	for (int i = 0; i < A; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < B; i++) {
		cin >> b[i];
	}
	int mina = a[0], minb = b[0];
	for (int i = 0; i < A; i++) {
		if (mina > a[i]) {
			mina = a[i];
		}
	}
	for (int i = 0; i < B; i++) {
		if (minb>b[i]) {
			minb = b[i];
		}
	}
	int ans = mina + minb;
	//cout << ans << endl;

	for (int i = 0; i < M; i++) {
		cin >> x[i] >> y[i] >> c[i];
		if (a[x[i]-1] + b[y[i]-1] - c[i] < ans) {
			ans = a[x[i]-1] + b[y[i]-1] - c[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2176