akhauriyash/Code-Regression huggingface dataset:
h, w = map(int, input().split())
b = [[0] * w for _ in range(h)]
q = []

for i in range(h):
    for j, m in enumerate(input()):
        if m == "#":
            q.append((i, j))
            b[i][j] = 1

cnt = -1

while q:
    nq = []
    for y, x in q:
        if y > 0:
            if not b[y-1][x]:
                b[y-1][x] = 1
                nq.append((y-1, x))
        if y < h-1:
            if not b[y+1][x]:
                b[y+1][x] = 1
                nq.append((y+1, x))
        if x > 0:
            if not b[y][x-1]: 
                b[y][x-1] = 1
                nq.append((y, x-1))
        if x < w-1:
            if not b[y][x+1]: 
                b[y][x+1] = 1
                nq.append((y, x+1))
    
    q = nq    
    cnt += 1
    
print(cnt)


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

int cnt(int n) {
    int ret = 0;
    while (n % 2 != 1) {
        ret++;
        n /= 2;
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        ans += cnt(x);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

main()
{
	int a[101];
	int n;
	int i;
	int count=0;
	
    scanf("%d",&n);
    
    for(i=1;i<=n;i++)
    {
		scanf("%d",&a[i]);
	}
	
	for(i=1;i<=n;i++)
	{
		if(i%2!=0&&a[i]%2!=0)
		{
			++count;
		}
	}
	
	printf("%d",count);
}

	

Measured memory_bytes: 1732
// AOL 1059 Mysterious Onslaught
// 2018.2.18 bal4u

#include <stdio.h>
#include <string.h>

int n;
int map[5][5][5][5];
char memo[1<<25];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int calc(int b)
{
	int r1, c1, r2, c2, k, ans;

	if (!b) return 1;
	if (memo[b] > 0) return memo[b];

	for (k = r1 = 0; ; r1++, k += 5) for (c1 = 0; c1 < n; c1++) {
		if (b & (1<<(k + c1))) goto next;
	}

next:
	ans = 25;
	for (r2 = r1; r2 < n; r2++) for (c2 = c1; c2 < n; c2++) {
		k = b ^ map[r1][c1][r2][c2];
		k = calc(k) + 1;
		if (ans > k) ans = k;
	}
	return memo[b] = ans;
}

void init()
{
	int r1, r2, c1, c2, r, c;

	for (r1 = 0; r1 < 5; r1++) for (c1 = 0; c1 < 5; c1++)
		for (r2 = r1; r2 < 5; r2++) for (c2 = c1; c2 < 5; c2++)
			for (r = r1; r <= r2; r++) for (c = c1; c <= c2; c++)
				map[r1][c1][r2][c2] |= (1<<(r*5+c));
}

int main()
{
	int r, c, b, k;

	init();
	while (n = in()) {
		b = 0;
		for (k = r = 0; r < n; r++, k += 5) for (c = 0; c < n; c++) {
			if (getchar_unlocked() & 1) b |= 1 << (k+c);
			getchar_unlocked();
		}
		k = calc(b)-1;
		while (k--) printf("myon");
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 34452
# https://atcoder.jp/contests/abc116/tasks/abc116_d

N, K = gets.split.map(&:to_i)
max_in_type = {}
values = []

N.times do
  temp = gets.split.map(&:to_i)
  max_in_type[temp[0]] = temp[1] if !(max_in_type[temp[0]]&.>(temp[1]))
  values << (temp[1] << 17) + temp[0]
end

ph = []
sum = 0
use_type_count = 0
type_flags = {}

t_mask = (1 << 17) - 1

values.sort.reverse[0...K].each do |t_v|
  t = t_v & t_mask
  v = t_v >> 17
  sum += v
  if !type_flags[t]
    type_flags[t] = true
    use_type_count += 1
  else
    ph << v
  end
end
ph.sort!
ans = sum + use_type_count**2

rph = max_in_type.select { |t, v| !type_flags[t] }.values.sort.reverse

t = 0
phsize = ph.size
rphsize = rph.size
(phsize > rphsize ? rphsize : phsize).times do |i|
  sum = sum - ph[i] + rph[i]
  t = sum + (use_type_count += 1)**2
  ans = t if t > ans
end

p ans

Measured memory_bytes: 18288
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#define rep(i,n) for (int i = 0; i < (n);i++)
typedef long long ll;
using namespace std;
/*#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;*/


void Main()
{
    int n; cin>>n;
    vector<int> a(n);
    rep(i,n){
        cin>>a.at(i);
    }

    vector<int> b(n);
    rep(i,n){
        cin>>b.at(i);
    }
    
    int sum =0;
    rep(i,n){
        sum+=b.at(i);
    }

    vector<int> c(n-1);
    rep(i,n-1){
        cin>>c.at(i);
    }
    rep(i,n-1){
        if(a.at(i)+1 == a.at(i+1))
            sum+=c.at(a.at(i)-1);
    }
    cout << sum << endl;

}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    h,w=map(int,input().split())
    s=""
    for _ in range(h):
        s+=input()
    sc=list(Counter(s).values())
    cunt_1=(h%2)*(w%2)
    cunt_2=(h%2)*(w//2)+(w%2)*(h//2)
    cunt_4=(h//2)*(w//2)
    #print(sc)
    for i,scc in enumerate(sc):
        if scc>=4:
            x=min(scc//4,cunt_4)
            sc[i]-=x*4
            cunt_4-=x
    for i,scc in enumerate(sc):
        if scc>=2:
            x=min(scc//2,cunt_2)
            sc[i]-=x*2
            cunt_2-=x
    for i,scc in enumerate(sc):
        if scc>=1:
            x=min(scc,cunt_1)
            sc[i]-=x
            cunt_1-=x
    print("Yes" if all(scc==0 for scc in sc) else "No")

        

if __name__=='__main__':
    main()

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

using namespace std;

#define ll long long

const int N=1e6+5;

int m,n,k,l,r,u,x,tc,y,q,d,a[N];


char s[N],t[N];

bool freq[26];

int len,sz,pos[N];

pair <int,ll> v[N];


ll ans;

vector<int> where[26];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    scanf("%s",s);
    sz=strlen(s);
    scanf("%s",t);
    len=strlen(t);
    for(int i=0;s[i];i++){
        freq[s[i]-'a']=true;
        where[s[i]-'a'].push_back(i);
    }
    for(int i=0;t[i];i++)
        if (!freq[t[i]-'a'])
            return !printf("-1\n");
    int i=0,last;
    while(true){
        ans+=sz;
        last=-1;
        while(i<len){
            int pos=upper_bound(where[t[i]-'a'].begin(),where[t[i]-'a'].end(),last)-where[t[i]-'a'].begin();
            if (pos>=(int)where[t[i]-'a'].size()){
                break;
            }
            last=where[t[i]-'a'][pos];
            i++;
        }
        if (i==len){
            ans-=sz-last-1;
            break;
        }
    }
    printf("%lld\n",ans);
}





Measured memory_bytes: 4992
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = input().strip()

ans = 0
x = 0
for v in S:
    if v == 'I':
        x += 1
    else:
        x -= 1
    ans = max(ans, x)
print(ans)


Measured memory_bytes: 61884
import itertools
A,B,C,D = input()
ABCD = [int(A),int(B),int(C),int(D)]
op = ["+","-"]

#デカルト積
OP = list(itertools.product(op,repeat = 3))
def can_seven(li,op):
    m = len(op)
    n = len(op[0])
    for j in range(m):
        res = li[0]
        for i in range(n):
            if op[j][i] == "+": res += li[i+1]
            else: res -= li[i+1]
        if res == 7:
            return ("{0}"+op[j][0]+"{1}"+op[j][1]+"{2}"+op[j][2]+"{3}=7").format(li[0],li[1],li[2],li[3])
    return "Fail"

print(can_seven(ABCD,OP))


    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int n;

const int N = 51;
ll s[N],p[N];

ll dfs(int lv, ll &r){
    if(r<=0) return 0;

    if(s[lv]<=r){
        r -= s[lv];
        return p[lv];
    }

    ll ret = 0;
    --r;

    ret += dfs(lv-1,r);
    if(r<=0) return ret;

    --r;
    ++ret;

    ret += dfs(lv-1,r);

    --r;
    return ret;
}

int main(){
    s[0] = 1;
    p[0] = 1;
    for(int i=1; i<N; ++i){
        s[i] = 2*s[i-1] + 3;
        p[i] = 2*p[i-1] + 1;
    }

    ll x;
    cin >>n >>x;
    cout << dfs(n,x) << endl;
    return 0;
}


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

int H, W;
int CH, CW, DH, DW;
int dh[] = {-1, 0, 0, 1}, dw[] = {0, 1, -1, 0};
string S[1005];
bool used[1005][1005];

// warp, h, w
typedef pair<int, pair<int, int>> P;

void solve() {
  priority_queue<P, vector<P>, greater<P>> q;
  q.push(make_pair(0, make_pair(CH, CW)));

  while (!q.empty()) {
    P c = q.top();
    q.pop();
    int ch = c.second.first, cw = c.second.second;
    // printf("c = (%d, %d, %d)\n", c.first, ch, cw);
    if (ch == DH && cw == DW) {
      printf("%d\n", c.first);
      return;
    }
    if (used[ch][cw]) { continue; }
    used[ch][cw] = true;

    for (int i = 0; i < 4; i++) {
      int nh = ch + dh[i], nw = cw + dw[i];
      // printf("walk: %d, %d\n", nh, nw);
      if (0 <= nh && nh < H && 0 <= nw && nw < W && S[nh][nw] == '.' && !used[nh][nw]) {
        q.push(make_pair(c.first, make_pair(nh, nw)));
      }
    }
    for (int i = -2; i <= 2; i++) {
      for (int j = -2; j <= 2; j++) {
        if (i == 0 && j == 0) { continue; }
        int nh = ch + i, nw = cw + j;
        // printf("warp: %d, %d\n", nh, nw);
        if (0 <= nh && nh <= H && 0 <= nw && nw <= W && S[nh][nw] == '.' && !used[nh][nw]) {
          q.push(make_pair(c.first+1, make_pair(nh, nw)));
        }
      }
    }
  }
  printf("-1\n");
}

int main() {
  cin >> H >> W >> CH >> CW >> DH >> DW;
  CH--; CW--; DH--; DW--;
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  solve();
}


Measured memory_bytes: 7584
import java.util.*;
import java.io.*;
class Main {
    static ArrayList<Integer>[] graph;
    static long MOD = (long)(1e9+7);
    static long[][] dp;
    static long dfs(int src, int par, boolean isBlack) {
        int x = isBlack?1:0;
        if(dp[src][x]!=-1)
            return dp[src][x];
        long count = 1;
        for(int i: graph[src]) {
            if(par==i) continue;
            long subTreeCount = 0;
            if(isBlack)
                subTreeCount = (subTreeCount + dfs(i, src, false))%MOD;
            subTreeCount = (subTreeCount + dfs(i, src, true));
            count = (count * subTreeCount)%MOD;
        }
        return dp[src][x] = count%MOD;
    }
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        graph = new ArrayList[n];
        for(int i = 0; i<n; i++)
            graph[i] = new ArrayList<>();
        dp = new long[n][2];
        for(long[] i: dp)
            Arrays.fill(i, -1);
        for(int i = 0; i<n-1; i++) {
            int u = sc.nextInt()-1;
            int v = sc.nextInt()-1;
            graph[u].add(v);
            graph[v].add(u);
        }
        System.out.println((dfs(0, -1, true)+dfs(0, -1, false))%MOD);
    }
}

Measured memory_bytes: 126564
n,k = map(int, input().split())
s = list(input())

r = 0
happy = 0

for i in range(1, len(s)):
    if s[i-1] is not s[i]:
        if k is not 0:
            if r is 0:
                r = 1
            else:
                happy += 2
                r = 0
                k -= 1
    else:
        happy += 1

if r == 1:
    happy += 1
print(happy)

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

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

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int V, E; cin >> V >> E;
    vvl dist(V, vl(V, INFL));
    rep(i,V) dist[i][i] = 0;
    rep(i,E){
        ll s,t,d;
        cin >> s >> t >> d;
        dist[s][t] = d;
    }
    rep(k,V) rep(i,V) rep(j,V){
        if(dist[i][k] == INFL || dist[k][j] == INFL) continue;
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    }
    rep(i,V){
        if(dist[i][i] < 0){
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }
    rep(i,V){
        rep(j,V){
            if(dist[i][j] == INFL)
                cout << "INF";
            else
                cout << dist[i][j];
            if(j != V-1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3300
#!/usr/bin/perl
use POSIX qw(ceil);
use Data::Dumper;

my ($d,$g) = map {$_ - 0} split(/\s+/o,<STDIN>);

my @pc = ();
for(my $i=0;$i<$d;$i++){
  my @a = map {$_ - 0} split(/\s+/o,<STDIN>);
  $a[2] = $a[0] * (100*(1+$i)) + $a[1];
  push(@pc,\@a);
}

my $min_cnt = 1000000000;
my $dd = 2 ** $d;

for(my $i=0;$i<$dd;$i++){
  my $sc1 = 0;
  my $cnt1 = 0;
  for(my $j=0;$j<$d;$j++){
    if( ( $i & ( 2 ** $j ) ) != 0 ){
      $cnt1 += $pc[$j]->[0];
      $sc1 += $pc[$j]->[2];
    }
  }
  $min_cnt = $cnt1 if $sc1 >= $g and $cnt1 < $min_cnt;
  if( $sc1 < $g ){
    my $l = $g - $sc1;
    for(my $j=0;$j<$d;$j++){
      next if ($i & ( 2 ** $j ))!=0;
      my $cnt2 = ceil( $l / (100*(1+$j)) );
      next if $cnt2 >= $pc[$j]->[0];
      $cnt2 += $cnt1;
      $min_cnt = $cnt2 if $cnt2 < $min_cnt;
    }
  }
}

print "$min_cnt\n";
exit(0);


Measured memory_bytes: 2560
import java.util.Scanner;

/**
 *
 * @author German le yo
 */
public class Main{
    
    // State contins the last action and the curent max happyness
    static int[][] state;
    static int[][] days;
    
    static int[] getOther(int j){
        switch(j){
            case 0: return new int[]{1, 2};
            case 1: return new int[]{0, 2};
            case 2: return new int[]{0, 1};
        }
        
        return null;
    }
    
    static int getMax(int i, int j){
        // Calulated
        if(state[i][j] != 0) return state[i][j];
        // Base case
        if(i == 0) return days[0][j];
        
        // Get max of others
        int[] other = getOther(j);
        int maxOther = -1, maxTmp;
        for(int otherI: other){
            maxTmp = getMax(i - 1, otherI);
            if(maxTmp > maxOther) maxOther = maxTmp; 
        }
       
       return state[i][j] = maxOther + days[i][j];
    }
    
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        
        // Input
        int N = scan.nextInt();
        state = new int[N][3];
        days = new int[N][3];
        for(int i = 0; i < N; i++){
            days[i] = new int[]{scan.nextInt(), scan.nextInt(), scan.nextInt()};
        }
        
        int max0 = getMax(N - 1, 0);
        int max1 = getMax(N - 1, 1);
        int max2 = getMax(N - 1, 2);

        System.out.println(Math.max(Math.max(max0, max1), max2));
    }
    
}

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

int main()
{
	int h,w;
	while(cin >> h >> w){
		if(!h && !w)
			break;

		for(int i = 0;i<h;++i){
			for(int j=0;j<w;++j){
				if((i+j)%2 == 0)
					cout << '#';
				else
					cout << '.';
			}
			cout << endl;
		}
		cout << endl;
	}


	return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <algorithm>
#define MAXN 55
#define ll long long
ll a[MAXN];
bool cmp(ll a, ll b) {
	return a > b;
}
ll cmn(int x, int y) {
	ll ret = 1;
	for(int i = 1; i <= y; i++) 
		ret = ret * (x-y+i) / i;
	return ret;
}
int main() {
	int n, l, r, cnt = 0, loc;
	ll ans = 0, t, sum = 0;
	double avg;
	scanf("%d%d%d", &n, &l ,&r);
	for(int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
	}
	std::sort(a+1, a+1+n, cmp);
	
	t = a[l];
	bool flag = 1;
	for(int i = 1; i <= n; i++)
		if(a[i] == t) {
			cnt++;
			if(flag) {
				loc = i;
				flag = 0;
			}
		}
	if(cnt == 1) {
		for(int i = 1; i <= l; i++) 
			sum += a[i];
		avg = sum * 1.0 / l;
		ans = 1;
	}else if(loc == 1) {
		for(int i = l; i <= cnt; i++) {
			ans += cmn(cnt, i);
			if(i >= r)	break; 
		}	
		for(int i = 1; i <= l; i++)
			sum += a[i];
		avg = sum * 1.0 / l;
	}else if(loc <= l) {
		ans += cmn(cnt, l-loc+1);
		for(int i = 1; i <= l; i++)
			sum += a[i];
		avg = sum * 1.0 / l;
	}
	printf("%.6lf\n%lld", avg, ans);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    string k;cin>>k;
    ll d;cin>>d;
    vector<mat> dp(2,mat(k.size()+1,vec(d)));
    dp[0][0][0]=1;
    rep(i,k.size()){
        ll t=k[i]-'0';
        rep(j,d){
            rep(l,t){
                dp[1][i+1][(j+l)%d]=(dp[1][i+1][(j+l)%d]+dp[0][i][j])%inf;
            }
            dp[0][i+1][(j+t)%d]=(dp[0][i+1][(j+t)%d]+dp[0][i][j])%inf;
            rep(l,10){
                dp[1][i+1][(j+l)%d]=(dp[1][i+1][(j+l)%d]+dp[1][i][j])%inf;
            }
        }
    }
    ll ans=(dp[0][k.size()][0]+dp[1][k.size()][0]-1)%inf;
    if(ans<0)ans+=inf;
    cout<<ans<<endl;
}

Measured memory_bytes: 25880
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    f = [1]*(k+1)
    p = 2
    phi = list(range(k+1))
    while p <= k:
        while p <= k and not f[p]:
            p += 1
        j = p
        x = (p-1)*pow(p,mod-2,mod)%mod
        while j <= k:
            phi[j] *= x
            phi[j] %= mod
            f[j] = 0
            j += p
        p += 1
    ans = 0
    for i in range(1,k+1):
        ans += phi[i]*pow(k//i,n,mod)
    print(ans%mod)
    return

#Solve
if __name__ == "__main__":
    solve()


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

#define int long long

using namespace std;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  int ans = 0;
  while (true) {
    bool found = false;
    for (int i = 0; i < n; i++) {
      int x = b[(i - 1 + n) % n], &y = b[i], z = b[(i + 1) % n];
      assert(x > 0 && y > 0 && z > 0);
      if (y < (x + z)) {
        continue;
      }
      int l = 0, r = 1e9;
      while (r - l > 1) {
        int mid = (l + r) >> 1;
        if (y - (x + z) * mid >= a[i]) {
          l = mid;
        } else {
          r = mid;
        }
      }
      ans += l;
      y -= l * (x + z);
      found |= (bool)l;
    }
    if (!found) {
      break;
    }
  }
  cout << (a == b ? ans : -1) << '\n';
  return 0;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,CC;
int S[101010],T[101010],C[101010],did[101010];
vector<int> st[201010];

int pre[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>CC;
	FOR(i,N) {
		cin>>S[i]>>T[i]>>C[i];
		C[i]--;
		st[S[i]].push_back(i);
	}
	
	int num=0;
	FOR(i,CC) pre[i]=202020;
	FOR(i,101000) {
		
		FORR(e,st[i]) {
			if(pre[C[e]]<=S[e]) {
				pre[C[e]]=T[e];
				did[e]++;
			}
		}
		FORR(e,st[i]) if(did[e]==0) {
			FOR(j,CC) {
				if(pre[j]<S[e]) {
					pre[j]=202020;
					pre[C[e]]=T[e];
					break;
				}
			}
			if(j==CC) {
				pre[C[e]]=T[e];
				num++;
			}
		}
	}
	
	
	
	cout<<num<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 9728
#include <iostream>

using namespace std;

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

    int ans = N;
    while (ans >= N) {
        if ((ans % 2 != 0) || (ans % N != 0)){
            ++ans;
        }else{
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

typedef long long ll;
using namespace std;
#define Mod 1000000007

ll modinv(ll a) {
    ll m=Mod;
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

    vector<vector<ll> > dp(4040,vector<ll>(4040,0));

    ll h=2020;

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

    for(i=1;i<4040;i++){
        for(j=1;j<4040;j++){
            dp[i][j]+=dp[i-1][j]+dp[i][j-1];
            dp[i][j]%=Mod;
        }
    }

    ll ans=0;
    for(i=0;i<n;i++){
        ans+=dp[h+a[i]][h+b[i]];
        ans%=Mod;
    }

    ll kaijou[8080];
    kaijou[0]=1;
    for(i=1;i<8080;i++){
        kaijou[i]=i*kaijou[i-1];
        kaijou[i]%=Mod;
    }

    ll gen=0;
    for(i=0;i<n;i++){
        ll x=kaijou[2*(a[i]+b[i])]*modinv(kaijou[2*a[i]]);
        x%=Mod;
        x*=modinv(kaijou[2*b[i]]);
        x%=Mod;
        gen+=x;
        gen%=Mod;
    }

    cout<<((ans-gen+Mod)%Mod*modinv(2))%Mod<<endl;


    return 0;
}

Measured memory_bytes: 131200
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int A = scn.nextInt();
    int B = scn.nextInt();

    int sum = A + B;
    int diff = A - B;
    int seki = A * B;

    int max = sum;
    max = Math.max(max, diff);
    max = Math.max(max, seki);

    System.out.println(max);
  }

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N, M, Q; cin >> N >> M >> Q;
	vvi abcd(Q, vi(4));
	REP(i, Q) {
		cin >> abcd[i][0] >> abcd[i][1] >> abcd[i][2] >> abcd[i][3];
	}
	int res = -1;
	FOR(i,1,M+1) FOR(j,i,M+1) FOR(k,j,M+1) FOR(l,k,M+1) FOR(m,l,M+1) FOR(n,m,M+1) FOR(o,n,M+1) FOR(p,o,M+1) FOR(q,p,M+1) FOR(r,q,M+1) {
		vi temp;
		temp.push_back(i);
		temp.push_back(j);
		temp.push_back(k);
		temp.push_back(l);
		temp.push_back(m);
		temp.push_back(n);
		temp.push_back(o);
		temp.push_back(p);
		temp.push_back(q);
		temp.push_back(r);
		int temp_res = 0;
		REP(s, Q) {
			if (temp[abcd[s][1] - 1] - temp[abcd[s][0] - 1] == abcd[s][2]) {
				temp_res += abcd[s][3];
			}
		}
		chmax(res, temp_res);
	}
	cout << res << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>

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

using namespace std;

struct Data {
  int h,p,q;
  bool operator < ( const Data &data ) const {
    return h > data.h;///
  }
};

int main() {
  int n,m,a;
  while( cin >> n >> m >> a, n|m|a ) {
    --a;
    priority_queue<Data> Q;    
    rep(i,m) {
      int h,p,q;
      cin >> h >> p >> q;
      --q, --p;
      Q.push((Data){h,p,q});
    }
    vector<int> vec(n);
    rep(i,n) vec[i] = i;
    while( !Q.empty() ) {
      Data data = Q.top(); Q.pop();
      swap(vec[data.p],vec[data.q]);
    }
    cout << vec[a]+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3000
def main():
    N = int(input())
    A = map(int, input().split())

    ctr = [0] * (10 ** 5 + 2)  # [-1,10**5]
    for x in A:
        for j in range(-1, 2):
            ctr[x + j] += 1
    print(max(ctr))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10124
N = int(input())
L = list(map(int, input().split()))

L = sorted(L)
L = L[::-1]

ans = 0

for i in range(N):
    Li = L[i]
    for j in range(i+1, N):
        Lj = L[j]
        for k in range(j+1, N):
            Lk = L[k]
            if Lj + Lk > Li:
                if Li not in [Lj, Lk]:
                    if Lj not in [Li, Lk]:
                        ans += 1


print(ans)


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
struct Mint {
	int val;
	Mint() { val = 0; }
	Mint(const ll& x) {
		val = (-MOD <= x && x < MOD) ? x : x % MOD;
		if (val < 0) val += MOD;
	}
	friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; }
	friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
	friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; }
	Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
	Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; }
	friend Mint modex(Mint a, ll p) {
		assert(p >= 0);
		Mint ans = 1;
		for (; p; p >>= 1, a *= a) if (p & 1) ans *= a;
		return ans;
	}
	Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); }
	Mint& operator++() { return *this += 1; }
	Mint& operator--() { return *this -= 1; }
	Mint operator++(int) { Mint result(*this); *this += 1; return result; }
	Mint operator--(int) { Mint result(*this); *this -= 1; return result; }
	Mint operator-() const { return Mint(-val); }
	friend Mint operator+(Mint a, const Mint& b) { return a += b; }
	friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
	friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
	friend Mint operator/(Mint a, const Mint& b) { return a /= b; }
	friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; }
};
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	vector<vector<pair<int, int>>> E(n + 3);
	for (int i = 0; i < m; ++i) {
		int l, r, x;
		scanf("%d%d%d", &l, &r, &x);
		E[r + 2].push_back({l + 2, x});
	}
	vector<vector<Mint>> dp(n + 3, vector<Mint>(n + 3));
	dp[1][0] = 1;
	for (int i = 2; i <= n + 2; ++i) {
		vector<vector<Mint>> ndp(n + 3, vector<Mint>(n + 3));
		for (int a = 0; a < i; ++a)
			for (int b = 0; b < a; ++b) {
				for (auto& e : E[i]) {
					if (e.second == 1) {
						if (e.first <= a) dp[a][b] = 0;
					} else if (e.second == 2) {
						if (e.first > a || e.first <= b) dp[a][b] = 0;
					} else {
						if (e.first > b) dp[a][b] = 0;
					}
				}
				ndp[a][b] += dp[a][b];
				ndp[i][b] += dp[a][b];
				ndp[i][a] += dp[a][b];
			}
		swap(ndp, dp);
	}
	Mint ans = 0;
	for (int a = 0; a < n + 2; ++a)
		for (int b = 0; b < a; ++b)
			ans += dp[a][b];
	printf("%d\n", ans.val);
}


Measured memory_bytes: 1064
#include<stdio.h>
int main(void)
{
	int n,i,max,min;
	long long int sum;
	int a[10001];

	scanf("%d",&n);
	max=-1000000;
	min=1000000;	
	sum=0;
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(max<a[i]){
			max=a[i];
		}
		if(min>a[i]){
			min=a[i];
		}
		sum=sum+a[i];
	}
	printf("%d %d %lld\n",min,max,sum);
	return 0;
}
	

Measured memory_bytes: 1068
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
<url:>
問題文============================================================

=================================================================

解説=============================================================

================================================================
*/
void solve(){
    ll N; cin >> N;
    vector<ll> A(N+2,0);
    for(int i = 1; i <= N;i++) cin >> A[i];
    ll cusum = 0;
    for(int i = 1; i <= N+1;i++){
        cusum += abs(A[i] - A[i-1]);
    }
   // cusum += abs(A[N] - A[0]);
    
    for(int i = 1; i <= N;i++){
        cout << cusum - abs(A[i] - A[i-1]) - abs(A[i+1] - A[i]) + abs(A[i+1] - A[i-1]) << endl;
    }
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    solve();
    return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    long long int r,c;
    cin>>r>>c;
    if(r==1 || c==1)
    cout<<1<<endl;
    else if((r*c)%2==0)
    cout<<(r*c)/2<<endl;
	else
	cout<<((r*c)/2)+1<<endl;
	return 0;
}

Measured memory_bytes: 256
a = input()
b = input()
n = len(a)
if len(a) == len(b):
    i = 0
    while i<n and a[i] == b[i]:
        i += 1
    if i == n:
        print("EQUAL")
    elif a[i] > b[i]:
        print("GREATER")
    else:
        print("LESS")
elif len(a) > len(b):
    print("GREATER")
else:
    print("LESS")

Measured memory_bytes: 3060
#include<cstdio>
using namespace std;
int main(){
  long long n,a;
  long long min,max,sum;
  scanf("%lld",&n);
  for(int i=0;i<n;i++){
    scanf("%lld",&a);
    if(i==0) max=min=sum=a;
    if(i!=0 && a<min){
      min=a;
      sum+=a;
    }else if(i!=0 && a>max){
      max=a;
      sum+=a;
    }else if(i!=0){
      sum+=a;
    }
  }
  printf("%lld %lld %lld\n",min,max,sum);
  return 0;
}



Measured memory_bytes: 2716
n = int(input())
A = list(map(int,input().split()))

rank = [0 for i in range(9)]

for a in A:
	res = min(a//400,8)
	rank[res] += 1

ans = 0
for r in rank[:-1]:
	if r == 0:
		continue
	ans+=1

min_ans = 0
max_ans = 0

if ans == 0:
	min_ans = 1
	max_ans = rank[-1]
else:
	min_ans = ans
	max_ans = ans+rank[-1]
# print(rank)
print(min_ans,max_ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define FLASH cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define FILEIO freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);
#define maxn 200000

using namespace std;

signed main()
{

 	FLASH

 	int n;
 	cin>>n;	
 	int d[n + 1];

 	fr(i, 1, n + 1) cin>>d[i];

 	sort(d + 1, d + n + 1);
 	cout<<d[n/2 + 1] - d[n/2];
 		
}

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

public class Main {

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

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

        String[] strArray = br.readLine().split(" ");
        int a = Integer.parseInt(strArray[0]);
        int b = Integer.parseInt(strArray[1]);

        System.out.println(a*b + " " + (a+b)*2);
	}
}

Measured memory_bytes: 24244
#include<bits/stdc++.h>
    using namespace std;
    signed main()
    {
        
        
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        #ifndef ONLINE_JUDGE
        if (fopen("INPUT.txt", "r")) {
            freopen ("INPUT.txt" , "r" , stdin);
            // freopen ("OUTPUT.txt" , "w" , stdout);
        }
        #endif
    //-----------------------------------------------------------------------------------------------------------
        long long a, b;
        cin>>a>>b;
        vector<long long> p1 ,p2;
        p1.push_back(1);
        p2.push_back(1);
        int ff=sqrt(a), gg=sqrt(b);
        for(int i=2;i<=ff;i++) 
        {
            if(a%i==0)
                p1.push_back(i);
            while(a%i==0)
                a/=i;
            
        }
        if(a>1)
            p1.push_back(a);

        for(int i=2;i<=ff;i++) 
        {
            if(b%i==0)
                p2.push_back(i);
            while(b%i==0)
                b/=i;
            
        }
        if(b>1)
            p2.push_back(b);
        int cnt=0;
        for(auto i:p1)
        {
            if(find(p2.begin(), p2.end(), i)!=p2.end())
                cnt++;
        }
        cout<<cnt<<endl;
    }

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = 0;
        String s = "";
        int b = 0;
        while(true){
            a = sc.nextInt();
            s = sc.next();
            b = sc.nextInt();
            if(s.equals("?"))break;

            if(s.equals("+")){
                System.out.println(a + b);
            }
            else if(s.equals("-")){
                System.out.println(a - b);
            }
            else if(s.equals("*")){
                System.out.println(a * b);
            }
            else if(s.equals("/")){
                if(b != 0)System.out.println(a / b);
                else System.out.println();
            }
            else{
                a = 0;
                s = "";
                b = 0;
            }
        }
    }
}


Measured memory_bytes: 26452
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int k; cin>>k;
    string s; cin>>s;

    int n = s.length();
    if (n <= k) {
        cout << s << '\n';
    }
    else {
        string ans = s.substr(0,k);
        ans += "...";
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<queue>
#include<vector>

using namespace std;

int main(){
    int N;
    cin >> N;
    
    vector< pair<int, int> > G[N];

    for(int i =0 ; i<N-1; i++){
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        G[u].push_back({v, w});
        G[v].push_back({u, w});
    }

    queue< int > que;
    que.push(0);

    int ans[N]; fill(ans, ans + N, -1);
    ans[0] = 0;

    while(!que.empty()){
        int v = que.front(); que.pop();
        for(auto n : G[v]){
            if(ans[n.first]==-1){                
                if(n.second % 2 == 0){
                    ans[n.first] = ans[v];
                }
                else{
                    ans[n.first] = ans[v] * (-1) + 1;
                }   
                que.push(n.first);             
            }
        }
    }

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

Measured memory_bytes: 6784
import math
a,b,x = map(int, input().split())
if x == a*a*b:
  print(0)
elif x >= a*a*b/2:
  print(math.atan((2*a*a*b-2*x)/a/a/a)*180/math.pi)
else:
  print(math.atan(a*b*b/2/x)*180/math.pi)

Measured memory_bytes: 3316
n,d = map(int,input().split())
l = []
for i in range(n):
  x,y = map(int,input().split())
  l.append([x,y])
ans = 0
for j in l:
  if j[0]**2 + j[1]**2 <= d**2:
    ans += 1
print(ans)

Measured memory_bytes: 39056
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
#define mo 1000000007
#define ull unsigned long long 

int main(){
  int a,b,c;cin>>a>>b>>c;
  if(a==b && b!=c)
    cout<<"Yes";
  else if(b==c && c!=a)
    cout<<"Yes";
  else if(a==c && b!=a)
    cout<<"Yes";
  else
    cout<<"No";
}

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

int main()
{
    long long int x,a,b;
    cin>>x;
    for(int i=-1000;i<=1000;i++)
    {
        long long prod1=1;
        for(int d=1;d<=5;d++)
        {
            prod1=1LL*prod1*i;
        }

      for(int j=i+1;j<=1000;j++)
      {long long prod2=1;
          for(int d=1;d<=5;d++)
          {
              prod2=prod2*1LL*j;
          }
          if(prod2-prod1==x) {cout<<j<<" "<<i;return 0;}
      }

    }
}


Measured memory_bytes: 3592
#include<stdio.h>
 
int main(void)
{
	int C = 0;
	int i,j,p;
	char S[26];
	scanf("%26s",S);
	for( p = 0; S[p] != '\0'; p++);
	for( i = 0; i < p; i++){
	for( j = 0; j < p; j++){
		if( S[i] == S[j] ) C++ ;
	}
	}
	if( C == p)  printf("yes");
	else printf("no");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define NMAX 1005

using namespace std;
using ll = long long;
using pll = pair<ll,ll>;

char b[NMAX][NMAX];
ll cnt[NMAX][NMAX];
ll dc[4]={0,1,0,-1},dl[4]={1,0,-1,0};
int main()
{
    ll n,m,x1,y1,x2,y2;
    cin>>n>>m>>x1>>y1>>x2>>y2;
    for(ll i=1;i<=n;i++)
        for(ll j=1;j<=m;j++)
            cin>>b[i][j];
    queue<pll> adj,square;
    adj.push({x1,y1});
    square.push({x1,y1});
    cnt[x1][y1]=1;
    while(!adj.empty () || !square.empty()){
        if(!adj.empty()){
            for(ll i=0;i<4;i++){
                ll nx=adj.front().first+dc[i],ny=adj.front().second+dl[i];
                if(b[nx][ny]=='.' && cnt[nx][ny]==0){
                    cnt[nx][ny]=cnt[adj.front().first][adj.front().second];
                    adj.push({nx,ny});
                    square.push({nx,ny});
                }
            }
            adj.pop();
        }
        else{
            for(ll i=0;i<25;i++){
                ll nx=square.front().first+i/5-2,ny=square.front().second+i%5-2;
                if(nx>0 && ny>0 && b[nx][ny]=='.' && cnt[nx][ny]==0){
                    cnt[nx][ny]=cnt[square.front().first][square.front().second]+1;
                    adj.push({nx,ny});
                    square.push({nx,ny});
                }
            }
            square.pop();
        }
    }
    cout<<cnt[x2][y2]-1;
    return 0;
}


Measured memory_bytes: 12624
/*  ex7_3
    pptenshi  */

#include<stdio.h>
#include<stdlib.h>

int main(void) {
    int height,         // H
        width,          // W
        *is_row_del,    // 取り除く行
        *is_col_del;    // 取り除く列
    char **grid;         // マス目 
    
    //--- input height, width ---//
    scanf("%d%d", &height, &width);


    //--- メモリ確保 ---//

    is_row_del = (int*)calloc(height, sizeof(int));
    if (is_row_del == NULL) exit(1);
    // 1で初期化
    for (int i = 0; i < height; i++) is_row_del[i] = 1;   
    

    is_col_del = (int*)calloc(width, sizeof(int));
    if (is_col_del == NULL) exit(1);
    // 1で初期化
    for (int i = 0; i < width; i++) is_col_del[i] = 1;

    grid = (char**)calloc(height, sizeof(char*));
    if (grid == NULL) exit(1);
    for (int i = 0; i < height; i++) {
        grid[i] = (char*)calloc(width, sizeof(char));
        if (grid[i] == NULL) exit(1);
    }


    //--- input grid ---//
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            scanf(" %c", &grid[i][j]);
        }
    }


    //--- 圧縮できる列, 行を求める ---//
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            if (grid[i][j] == '#') {
                is_row_del[i] = 0;
                is_col_del[j] = 0;
            }
        }
    }
    

    //--- output ---//
    for (int i = 0; i < height; i++) {
        if (is_row_del[i]) continue;  // 取り除く行

        for (int j = 0; j < width; j++) {
            if (is_col_del[j]) continue;  // 取り除く列

            printf("%c", grid[i][j]);
        }
        putchar('\n');   
    }


    //--- メモリ解放 ---//
    free(is_row_del);
    free(is_col_del);
    for (int i = 0; i < height; i++) {
        free(grid[i]);
    }
    free(grid);


    return 0;
}

Measured memory_bytes: 1644
#include <stdio.h>
#define N 20
#define NN 200

int n,A[N];

int main(){
  int q,Q[NN],i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&Q[i]);
    if(solve(0,Q[i]))printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}

int solve(int x,int y){
  int res;
  if(y == 0)return 1;
  if(x >= n)return 0;
  res = solve(x + 1,y) || solve(x + 1,y - A[x]);
  return res;
}



Measured memory_bytes: 2048
n=input()
a=input()
b=input()
c=input()

n = int(n)

def classify(a,b,c):
	if (a==b)and (b==c):
		return 0
	else:
		if (a==b):
			return 1
		elif (b==c):
			return 1
		elif (c==a):
			return 1
		else:
			return 2

ans_sum = 0
for i in range(n):
	ans = classify(a[i], b[i], c[i])
	ans_sum+=ans

print(ans_sum)

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

#define REP(i,n) for(int i = 0;i < n;i++)
#define REPR(i,n) for(int i = n-1;i >= 0;i--)
#define FOR(i,m,n) for(int i = m;i < n;i++)
#define INF 2e9
#define ALL(v) v.begin(),v.end()
#define ll long long
#define GREATER greater<int>()

using namespace std;

string pop_back(string s){
    string t = s.substr(0,s.size()-1);
    return t;
}

int gcd(int max,int min){
    
    if(max<min){
        int tmp=max;
        max=min;
        min=tmp;
    }

    if(max%min==0)return min;
    else return gcd(min,max%min);

}

int main(void){

    int a[3],k;
    cin>>a[0]>>a[1]>>a[2]>>k;
    sort(a,a+3);
    for(int i=0;i<k;i++)a[2]*=2;
    cout<<a[0]+a[1]+a[2]<<endl;

    return 0;
}




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

typedef long long ll;

const int N=51;
ll dp[N][N][N*N];

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

	vector<int> x(n);
	for(int i=0;i<n;i++)	cin >> x[i];

	dp[0][0][0]=1;

	for(int i=0;i<n;i++){
		for(int j=0;j<n+1;j++){
			for(int k=0;k<N*N;k++){
				dp[i+1][j][k]+=dp[i][j][k];

				if(j && k>=x[i])
					dp[i+1][j][k]+=dp[i][j-1][k-x[i]];
			}
		}
	}
	ll ans=0;

	for(int i=1;i<=n;i++)	ans+=dp[n][i][i*a];

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 52096
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define MN 200005
using namespace std;
vector <int> v[MN];
int n,sm,rin,lk,ans;
int a[MN],b[MN],c[MN],d[MN],fa[MN];

inline int read()
{
	int n=0,f=1; char c=getchar();
	while (c<'0' || c>'9') {if(c=='-')f=-1; c=getchar();}
	while (c>='0' && c<='9') {n=n*10+c-'0'; c=getchar();}
	return n*f;
}

int getf(int x) {//	puts("sb");
	return fa[x]?fa[x]=getf(fa[x]):x;}
inline bool gather(int x,int y) {if (x!=y) return fa[x]=y; else return false;}

int main()
{
	register int i,j;
	n=read();
	for (i=1;i<=n;++i) sm^=(a[i]=c[i]=read());
	for (i=1;i<=n;++i) b[i]=d[i]=read();
	c[n+1]=sm; sort(c+1,c+n+2); sort(d+1,d+n+1);
	for (i=1;i<=n;++i) if (c[i]!=d[i]) break;
	for (j=i;j<=n;++j) if (c[j+1]!=d[j]) break;
	if (j<=n) return 0*printf("-1");
	rin=unique(c+1,c+n+2)-c-1;
	for (i=1;i<=n;++i)
		a[i]=lower_bound(c+1,c+rin+1,a[i])-c,
		b[i]=lower_bound(c+1,c+rin+1,b[i])-c;
	sm=lower_bound(c+1,c+rin+1,sm)-c;
	for (i=1;i<=n;++i)
		if (a[i]!=b[i]) ++lk,++ans,
			v[a[i]].push_back(i),
			v[b[i]].push_back(i);
//	printf("%d\n",rin);
//	puts("sb");	
	for (i=1;i<=n;++i) if (a[i]!=b[i] && sm==b[i]) {--ans; break;}
	for (i=1;i<=rin;++i)
		for (j=0;j+1<v[i].size();++j)
			if (gather(getf(v[i][j]),getf(v[i][j+1]))) --lk;
//	printf("%d\n",lk);	
//		{
//			printf("%d %d\n",j,v[i].size()-1);
//			printf("lala=%d",j>=v[i].size()-1);			
//			if (j>=v[i].size()-1) break;
//		}
	ans+=lk;
	printf("%d",ans);
}

Measured memory_bytes: 12672
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	ll n, m;
	cin >> n >> m;
	if (n < 2)n=3;
	if (m < 2)m=3;
	cout << (n - 2)*(m - 2) << endl;
	char nyaa;
	cin >> nyaa;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int k,i,s,c;
  while(1){
    scanf("%d",&k);
    if(!k)
      break;
    s=0;
    for(i=0;i<k*(k-1)/2;i++){
      scanf("%d",&c);
      s+=c;
    }
    s/=(k-1);
    printf("%d\n",s);
  }
  return 0;
}

Measured memory_bytes: 600