akhauriyash/Code-Regression huggingface dataset:
Num = int(input())

Str = input().split(" ")

NumList = [int(s) for s in Str]

Count = 0
Break = 1
for i in range(len(NumList)):
  if Break == NumList[i]:
    Break += 1
  else:
    Count += 1

if Count == Num:
  print("-1")
else:
  print(Count)

Measured memory_bytes: 26268
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=1000005;
char ch1[MAXN],ch2[MAXN];int n,m,K;
struct node
{
	int mask,pos;
	node(){}node(int _mask,int _pos){mask=_mask;pos=_pos;}
}sta[2*MAXN];int tp;
vector<node> add;
vector<int> ans1,ans2;
int main()
{
	n=read();m=read();K=read();
	scanf("%s",ch1+1);scanf("%s",ch2+1);
	reverse(ch1+1,ch1+1+n);reverse(ch2+1,ch2+1+m);int N=max(n,m);
	for(int i=N;i>=1;i--)
	{
		if(ch1[i]=='1'&&ch2[i]=='1')
		{
			int nowmask=3,cnt=K,pos=i;add.clear();
			while(tp)
			{
				if(nowmask==3)
				{
					if(cnt>=sta[tp].pos-pos)
					{
						cnt-=sta[tp].pos-pos;pos=sta[tp].pos;
						add.emplace_back(node(sta[tp].mask^nowmask,sta[tp].pos));
						nowmask&=sta[tp].mask;--tp;
					}else break;
				}
				else if(nowmask)
				{
					if(sta[tp].pos==pos+1)
					{
						pos=sta[tp].pos;
						if(nowmask^sta[tp].mask)nowmask=3;
						else nowmask&=sta[tp].mask;--tp;
					}else break;
				}
				else break;
			}
			if(nowmask!=0&&nowmask!=3)++pos,add.emplace_back(node(nowmask,pos));
			else if(nowmask==3)pos+=cnt,add.emplace_back(node(nowmask,pos));
			reverse(add.begin(),add.end());
			for(auto p:add)sta[++tp]=p;
		}
		else if(ch1[i]=='1'||ch2[i]=='1')sta[++tp]=node((ch1[i]=='1')+(ch2[i]=='1')*2,i);
	}
	for(int i=tp,pre=0;i>=1;i--)
	{
		if(sta[i].mask&1)
		{
			for(int j=pre+1;j<sta[i].pos;j++)ans1.emplace_back(0);
			ans1.emplace_back(1);pre=sta[i].pos;
		}
	}
	for(int i=tp,pre=0;i>=1;i--)
	{
		if(sta[i].mask&2)
		{
			for(int j=pre+1;j<sta[i].pos;j++)ans2.emplace_back(0);
			ans2.emplace_back(1);pre=sta[i].pos;
		}
	}reverse(ans1.begin(),ans1.end());reverse(ans2.begin(),ans2.end());
	for(auto p:ans1)putchar(p+'0');puts("");
	for(auto p:ans2)putchar(p+'0');puts("");
	return 0;
}


Measured memory_bytes: 32104
#include<bits/stdc++.h>
int main(){
    int h,w,k;std::cin>>h>>w>>k;
    for(int i=0;i<=h;i++){
        for(int j=0;j<=w;j++){
            if(i*j+(h-i)*(w-j)==k){
                std::cout<<"Yes"<<'\n';
                return 0;
            }
        }
    }
    std::cout<<"No"<<'\n';
}



Measured memory_bytes: 256
def solve():
    import sys
    input = sys.stdin.readline
    N,M,S = map(int,input().split())
    UVAB = [tuple(map(int,input().split())) for i in range(M)]
    CD = [tuple(map(int,input().split())) for i in range(N)]

    es = [[] for _ in range(N)]
    for u,v,a,b in UVAB:
        u,v = u-1,v-1
        es[u].append((v,a,b))
        es[v].append((u,a,b))

    INF = float('inf')
    times = [INF] * (2501 * N)
    start = min(2500,S)*N
    times[start] = 0
    hq = [start]
    ans = [-1] * N
    ans[0] = 0
    reached = 0
    import heapq
    heapq.heapify(hq)
    while hq:
        x = heapq.heappop(hq)
        t,v = divmod(x,N*2501)
        s,i = divmod(v,N)
        if ans[i] < 0:
            ans[i] = t
            reached += 1
            if reached == N-1: break
        for to,a,b in es[i]:
            if a > s: continue
            nv = (s-a)*N + to
            if times[nv] <= t + b: continue
            times[nv] = t + b
            heapq.heappush(hq, (t+b)*N*2501 + nv)
        ns = s
        nt = times[v]
        while ns <= 2500:
            ns += CD[i][0]
            nt += CD[i][1]
            nv = min(2500,ns)*N + i
            if times[nv] <= nt: break
            times[nv] = nt
            heapq.heappush(hq, nt*N*2501 + nv)
    print(*ans[1:], sep='\n')
solve()

Measured memory_bytes: 89872
import sys
from itertools import accumulate

input = sys.stdin.readline


def solve(H, W, D, A, Q, LR):
    position = [None] * (H * W + 1)
    for h in range(H):
        for w in range(W):
            position[A[h][w]] = (h, w)

    mp = [0] * (H * W + 1)

    for i in range(1, H * W + 1 - D):
        h, w = position[i]
        y, x = position[i + D]
        mp[i + D] = abs(x - w) + abs(y - h)

    for d in range(1, D + 1):
        mp[d::D] = list(accumulate(mp[d::D]))

    ans = [str(mp[r] - mp[l]) for l, r in LR]
    ans = "\n".join(ans)
    return ans


def main():
    H, W, D = map(int, input().split())
    A = [tuple(map(int, input().split())) for _ in range(H)]
    Q = int(input())
    LR = [tuple(map(int, input().split())) for _ in range(Q)]

    ans = solve(H, W, D, A, Q, LR)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 44184
/*
 _____ ____ _____   ___   ___  __  ___  
|_   _/ __ \_   _| |__ \ / _ \/_ |/ _ \ 
  | || |  | || |      ) | | | || | (_) |
  | || |  | || |     / /| | | || |\__, |
 _| || |__| || |_   / /_| |_| || |  / / 
|_____\____/_____| |____|\___/ |_| /_/   
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb push_back
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
const double goldie = 1.61803398875;
int main(){
    map<string,int>m;
    int n;
    cin >> n;
    ll sum = 0;
    rep(i,0,n){
        string zg;
        cin >> zg;
        sort a(zg);
        sum+=m[zg]++;
    }
    cout << sum;
}

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

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

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    string S1, S2;
    cin >> N >> S1 >> S2;
    REV(S1);
    REV(S2);

    ll cnt, k;
    bool f;
    if(S1[0] == S2[0]) {
        cnt = 3;
        k = 1;
        f = true;
    }
    else {
        cnt = 6;
        k = 2;
        f = false;
    }

    while(k < N) {
        if(S1[k] == S2[k]) {
            if(f) cnt = (cnt * 2) % MOD;
            f = true;
            ++k;
        } 
        else {
            if(f) cnt = (cnt * 2) % MOD;
            else cnt = (cnt * 3) % MOD;
            f = false;
            k += 2;
        }
    }
    PR(cnt);

    return 0;
}

/*



*/

Measured memory_bytes: 3628
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        long[] h = new long[n];
        for(int i=0; i<n; i++) {
            h[i] = in.nextLong();
        }
        
        Set<Integer>[] roads = new Set[n];
        for(int i=0; i<n; i++) {
            roads[i] = new HashSet<>();
        }
        
        for(int i=0; i<m; i++) {
            int a = in.nextInt()-1;
            int b = in.nextInt()-1;
            roads[a].add(b);
            roads[b].add(a);
        }
        
        int ans = 0;
        for(int i=0; i<n; i++) {
            Set<Integer> road = roads[i];
            Iterator<Integer> it = road.iterator();
            boolean isGood = true;
            while(it.hasNext()) {
                int dest = it.next();
                if(h[i] <= h[dest]) {
                    isGood = false;
                    break;
                }
            }
            if(isGood) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 83960
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector> 
using namespace std;
int main(){
  int n, r, p, c;
  

  while(1){
    
    cin >> n >> r;
    if(n == 0 && r == 0) break;
    int i;
    int a[n], temp[n];
    for(i = 1;i < n+1;i++){
      a[n-i] = i;
    }

    for(int j = 0;j < r;j++){
      cin >> p >> c;
      
      
      
      for(i = 0;i < c;i++){
        temp[i] = a[p-1+i];
        //cout << "temp[n-p-c+i] = " << temp[n-p-c+i] << "a[n-p-1+i] = " << a[n-p-1+i] << endl;
      }
      for(i = 0;i < p-1;i++){
        temp[c+i] = a[i];
      } 
      for(i = 0;i < n-p-c+1;i++){
        temp[c+p-1+i] = a[c+p-1+i];
      }
      for(i = 0;i < n;i++){
        a[i] = temp[i];
      }
      
    }
    
    cout << temp[0] << endl;

  }

  return 0;
}

Measured memory_bytes: 1160
/*input
8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310
*/
/**
    Author: Kristopher Paul
    Date Created: 16-11-2019
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
//#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int n;
    cin >> n;
    vector<pii> vec;
    FOR(i,0,n){
        int x,y;
        cin >> x >> y;
        vec.pb({x,y});
    }
    sort(vec.begin(),vec.end());
    double sum = 0;
    do{
        FOR(i,1,n){
            sum += sqrt(ceil(pow((vec[i].first-vec[i-1].first),2)) + ceil(pow((vec[i].second-vec[i-1].second),2)));
        }
    }while(next_permutation(vec.begin(),vec.end()));
    double f = 1;
    FOR(i,1,n+1){
        f *= i;
    }
    sum /= f;
    cout << fixed << setprecision(10) << sum << endl;
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}


Measured memory_bytes: 256
a,b,c,d = input().split()
A = int(a)
B = int(b)
C = int(c)
D = int(d)

left = A+B
right = C+D

if(left>right):
	print("Left")
elif(left<right):
	print("Right")
elif(left==right):
	print("Balanced")

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

int main() {
  string s,t;
  cin >> s >> t;
  for(int i=0 ;i<s.size() ;i++){
    if(s == t){
      cout << "Yes" << endl;
      return 0;
    }
    s = s.back() + s.substr(0,s.size()-1);
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int S;
    cin>>S;
    int h,m,s;
    s = S%60;
    S -= s;
    S /= 60;
    m = S%60;
    S -= m;
    S /= 60;
    h = S;
    printf("%d:%d:%d\n",h,m,s);
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int n; cin >> n;
    for(int i=0; i<n; i++){
        char c; cin >> c;
        if(c == 'Y'){
            cout << "Four" << endl;
            return 0;
        }
    }

    cout << "Three" << endl;
    return 0;
}

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

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"

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

int main(void) {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;

  int i=0, j=0, ans=0;
  while(j<n){
    while(j<n && s[j]=='1'){
      j++;
    }
    ans = max(ans, j-i);
    while(j<n && s[j]=='0'){
      j++;
    }
    k--;
    if(k<0){
      while(i<n && s[i]=='1'){
        i++;
      }
      while(i<n && s[i]=='0'){
        i++;
      }
    }
    ans = max(ans, j-i);
  }

  prt(ans);

}


Measured memory_bytes: 512
#include <bits/stdc++.h>                        
#define pb push_back                            
#define mp make_pair                            
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define endl "\n"
#define jonathan ios_base::sync_with_stdio(0)
#define livingston cin.tie(0)                   
using namespace std;                            
                                                
void yes() {cout << "YES" << endl;}                                               
void no() {cout << "NO" << endl;}                                                        
                                                
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};         
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; 

const long long INF = 8e18 + 8;
const double EPS = 1e-9;
const long long MOD = 998244353;

void solve() {
	long long n, x; cin >> n >> x;
	vector<long long> a(n), b(n);
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	long long ans = sum;
	for (int j = 1; j < n; j++) {
		sum = j * x;
		for (int i = 0; i < n; i++) {
			b[i] = min(a[i], a[(i - 1 + n) % n]);
			sum += b[i];
		}
		for (int i = 0; i < n; i++) {
			a[i] = b[i];
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
}

int main() {
    jonathan; 
    livingston;
    bool tests = 0;
    int t = 1;
    if (tests) cin >> t;
    for (int i = 1; i <= t; i++) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    string s;
    int x;
    cin >> s >> x;
    REP(i,s.length()){
        if (i % x == 0) cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;

int main(void){
  int n;
  string s;
  cin >> n >> s;
  int count = 0;
  for(int i=0;i<n-2;i++){
  	 if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C' ){
     	count ++;
     }
  }
  cout << count;
return 0;
}

Measured memory_bytes: 256
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  sort(h.begin(), h.end());
  ll cnt = 0;
  for (ll i = 0; i < n - k; i++) cnt += h[i];
  cout << cnt;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <list>
using namespace std;
	
int main(){
	int N[4];
	cin >> N[0] >> N[1] >> N[2] >> N[3];
	int check[4] = {0,0,0,0};
	for (int i=0;i<4;i++){
		if (N[i] == 1)
			check[0] = 1;
		if (N[i] == 4)
			check[1] = 1;
		if (N[i] == 7)
			check[2] = 1;
		if (N[i] == 9)
			check[3] = 1;
	}
	if (check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1){
		cout << "YES" << endl;
	}
	else
		cout << "NO" << endl;
}

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

#define mod 1000000007

int main() {
    int N, M;
    cin >> N >> M;
    vector<int>S(N);
    for (int i = 0; i < N; ++i) {
      cin >> S[i];
    }
    vector<int>T(M);
    for (int i = 0; i < M; ++i) {
      cin >> T[i];
    }

    // Sのi番目までとTのj番目までの結果がdp[i][j]
    vector<vector<ll>> dp(N+1, vector<ll>(M+1, 1));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            if(S[i] == T[j]){
                dp[i+1][j+1] = dp[i][j+1] + dp[i+1][j];
            } else{
                dp[i+1][j+1] = dp[i][j+1] + dp[i+1][j] + mod - dp[i][j];
            }
            dp[i+1][j+1] %= mod;
        }
    }

    cout << dp[N][M];
    return 0;
}

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

int main() {
  int K;
  string S;
  cin >> K>>S;
  if (S.size()>K){
    for (int i=0;i<K;i++)
      cout << S.at(i);
    cout<<"..."<<endl;
  }
  else
    cout<<S<<endl;
  
}

Measured memory_bytes: 3632
import std.stdio;
import std.algorithm;
void main(){
	int[] arr;
	arr.length = 5;
	readf("%d %d %d %d %d\n", &arr[0], &arr[1], &arr[2], &arr[3], &arr[4]);
	auto sortedarr = sort!((int a, int b){return a > b;})(arr);
	while(1){
		int i = sortedarr.front;
		sortedarr.popFront();
		if(sortedarr.empty()){
			writeln(i);
			break;
		}
		writef("%d ", i);
	}
}

Measured memory_bytes: 1008
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

bool isN(double k)
{
    for(int i = 1; i <= k; i++){
        if(i*i == k){
            return true;
        }
    }
    return false;
}


int main()
{
   int n, k, ans = 0;
   cin >> n >> k;
   vector<vector<int> > v(n, vector<int>(k, 0));
   rep(i, n){
       rep(j, k){
           cin >> v[i][j];
       }
   }
   for(int i = 0; i < n; i++){
       for(int j = i+1; j < n; j++){
           int t = 0;
           rep(l, k){
               t += (abs((v[i][l]-v[j][l]))* abs(v[i][l]-v[j][l]));
           }
           if(isN(t)){
               ans++;
           }
       }
   }
   cout << ans << endl;
   return 0;
}

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

bool Compare(pair<ll,ll> p1, pair<ll,ll> p2){
  	if(p1.first < p2.first) return true;
  	if(p1.first == p2.first) return (p1.second <= p2.second);
  	return false;
}

int main(){
    ll n;
    cin >> n;
    
    ll x, l;
    vector<pair<ll,ll>> v(n);
    for(ll i=0; i<n; i++){
        cin >> x >> l;
        v[i].first = x-l; v[i].second = x+l;
    }

    sort(v.begin(), v.end(), Compare);
    ll cnt = 0, i=0, j=1;
    while(i<n && j<n){
        if(v[i].second > v[j].first){
            cnt++;
            if(v[i].second >= v[j].second) i=j;
            j++;
        }
        else {i=j; j++;}
    }

    cout << n-cnt << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

//秒から時間を割り出すプログラム
public class Main {
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
		int inputInt = Integer.parseInt(input);
		
		int hour = inputInt / 3600;
		inputInt -= hour * 3600;
		int minute = inputInt / 60;
		inputInt -= minute * 60;
		int second = inputInt;
		
		System.out.println(hour + ":" + minute + ":" + second);
		sc.close();
	}
}



Measured memory_bytes: 26216
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<string> S(N);
    for (auto& x : S) cin >> x;
    map<string, int> cnt;
    for (auto& x : S) ++cnt[x];
    int mx = 0;
    for (auto& entry : cnt) {
      chmax(mx, entry.snd);
    }
    for (auto& entry : cnt) {
      if (entry.snd == mx) {
        cout << entry.fst << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 26752
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto N = RD;
	auto M = RD;
	auto A = RDA;
	A.sort!"a > b"();
	auto s = A.sum;

	auto x = M * 4;
	bool ans = true;
	foreach (i; 0..M)
	{
		if (A[i] * x < s)
		{
			ans = false;
		}
	}

	writeln(ans ? "Yes" : "No");
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 256
N = int(input())

A = list(map(int, input().split()))

#0の数がN-1になった時点で終了
#Aの中のminを割り出しそれのmodをA内でとるを繰り返す

mina = 0
while(1):
    if(len(A)==1):break
    mina = min(A)
    minaind = A.index(mina)
    delind =[]
    for i in range(0,len(A)):
        # print(A,minaind)
        if i == minaind:continue
        # print(i)
        A[i]%=mina
        # if A[i] <= 0: delind.append(i)
    B=[]
    for i in range(0,len(A)):
        if(A[i]>0):
            B.append(A[i])
            
    A = B

print(A[0])

Measured memory_bytes: 14252
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;

int compare_ll(const void *a, const void *b)
{
	ll *A = (ll *)a;
	ll *B = (ll *)b;
	if (*A < *B) return 1;
	if (*A > *B) return -1;//昇順と降順あってる？
	return 0;
}

int main(void)
{
	//変数の宣言
	int x,y,z,m;
	static ll int a[1010];
	static ll int b[1010];
	static ll int c[1010];
	static ll int d[3010];
	static ll int v[3000010];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	ll int ans=0;
	int count=0;
	ll int temp=0;
	int temp1=0;
	int temp2=0;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	int dummy;



	//データの読み込み


	scanf("%d %d %d %d",&x,&y,&z,&m);
//	scanf_s("%d %d %d %d",&x,&y,&z,&m);

	for(i=0;i<x;i++){
		scanf("%lld",&a[i]);
//		scanf_s("%lld",&a[i]);
	}

	for(i=0;i<y;i++){
		scanf("%lld",&b[i]);
//		scanf_s("%lld",&b[i]);
	}

	for(i=0;i<z;i++){
		scanf("%lld",&c[i]);
//		scanf_s("%lld",&c[i]);
	}
	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	temp=0;
	for(i=0;i<x;i++){
		for(j=0;j<y;j++){
			v[temp]=a[i]+b[j];
			temp++;
		}
	}

	qsort(v,x*y,sizeof(ll),compare_ll);

	for(i=0;i<m;i++){
		d[i]=v[i];
	}


	temp=0;
	for(i=0;i<z;i++){
		for(j=0;j<m;j++){
			v[temp]=c[i]+d[j];
			temp++;
		}
	}

	qsort(v,z*m,sizeof(ll),compare_ll);

	//	printf("計算部分終了\n");

	//出力
	for(i=0;i<m;i++){
		printf("%lld\n",v[i]);
	}


/*	for(i=0;i<b+w;i++){
		printf("%lld %lld\n",black[i],white[i]);
	}*/


	//	printf("結果の出力終了\n");

	return 0;
}



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

#define long long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(x) (int)x.size()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,v) memset(a,v,sizeof(a))
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define INF 0x3f3f3f3f//infinity for integers
#define JJ ios_base::sync_with_stdio(0); cin.tie(0)//input fast
#define MOD 1000000007
#define hash(n) unordered_map<int,int>mp(n)

 
int main() 
{ 
	JJ;
	int x,y; cin>>x>>y;
	if(y%2!=0 || y>(x*4) || y<(x*2))
	cout<<"No"<<endl;
else
	cout<<"Yes"<<endl;



    
} 

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int ans=MOD;
  int N; cin>>N;
  rep(i,1,N){
    int K=N-i;
    string X=to_string(i),Y=to_string(K);
    int count=0;
    rep(j,0,X.size())
      count+=X[j]-'0';
    rep(j,0,Y.size())
      count+=Y[j]-'0';
    ans=min(ans,count);
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {
    int n;
    cin >> n;
    
    string s;
    cin >> s;
    s = s + '0';
    int tmp = 0;
    bool mode = false;
    int start, end;
    for(int i = 1;i < n; i++){
        for(int j = 0; j < n - i + 1; j++){
            if (s[j]==s[i+j]){
                if (!mode){
                    mode = true;
                    start = j;
                }
            }else{
                if (mode){
                    mode = false;
                    end = j - 1;
                    if (end >= start + i){
                        tmp = max(tmp, end - start + 1 - (end - start - i + 1));
                    }else{
                        tmp = max(tmp, end - start + 1);
                    }
                }
            }
        }
    }
    cout << tmp << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
#define intt long long

int main(){
	intt N; std::cin >> N;
	std::vector<intt> A(N);
	for (int i = 0; i < N; ++i)
		std::cin >> A[i];

	intt i = 0;
	intt ans = 0;
	while (true) {
		if (i == N)
			break;
		intt incre = i;
		intt decre = i;
		while (incre < N - 1 && A[incre] <= A[incre + 1])
			++incre;
		while (decre < N - 1 && A[decre] >= A[decre + 1])
			++decre;
		i = std::max(incre, decre) + 1;
		++ans;
	}
	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 3932
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef long long int ll;
void hack(ll n)
{
    if(n==124)
    cout<<"hacked";   
}
ll gcd(ll a,ll b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
ll mod=998244353;
ll mod1=1e9+6;
#define int ll
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0) return power(a*a%mod,b/2);
    else return a*power(a*a%mod,b/2)%mod;
}
ll power1(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0) return power(a*a%mod1,b/2);
    else return a*power(a*a%mod1,b/2)%mod1;
}
void show(vector <pair<int,int>> v)
{
    for(int i=0;i<v.size();++i) cout<<v[i].first<<" "<<v[i].second<<" ";
        cout<<endl;
}
#define endl '\n'
bool comp(pair<int,int> p,pair<int,int> p1)
{
    if(p.first!=p1.first)
        return p.first<p1.first;
    else
        return p.second>p1.second;
}

int32_t main()
{
    IOS
 
    int n,m;
    cin>>n>>m;
    int a[n],b[n];
    vector<pair<int,int>>v;
    for(int i=0;i<n;++i)
        {
            cin>>a[i]>>b[i];
            if(a[i]<=m)
            {
                v.push_back({b[i],a[i]});
            }
        }
        sort(v.begin(),v.end(),comp);
        reverse(v.begin(),v.end());
        int ans=0;
        bool visited[m+1];
        memset(visited,false,sizeof(visited));
        int count[m+1];
        set<int> s;
        memset(count,0,sizeof(count));
        for(int i=1;i<=m;++i)
            s.insert(i);
        int count1=0;
        for(int i=0;i<v.size();++i)
        {
           // cout<<v[i].first<<" "<<v[i].second<<endl;
            int index=-1;
            auto it=s.lower_bound(m-v[i].second+2);
           // cout<<*it<<endl;
            if(it==s.begin())
                continue;
            else
            {
                it--;
                s.erase(it);
                ans+=v[i].first;
            }
            
        }
        cout<<ans;


}


Measured memory_bytes: 8944
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	long n;cin>>n;
	long x = sqrt(n);
	long a = 1;
	rep(i,1,x){
	    long b = i;
	    if(n%b==0)a=b;
	}
	cout<<(a-1)+(n/a-1)<<endl;
}


Measured memory_bytes: 256
def maxHeapify i
  l = i*2
  r = l+1
  max = l<=$H && $a[l-1] > $a[i-1] ? l : i
  max = r if r <= $H && $a[r-1] > $a[max-1]
  unless max == i
    $a[i-1],$a[max-1] = $a[max-1],$a[i-1]
    maxHeapify max
  end
end
$H=gets.to_i
$a=gets.split.map &:to_i
($H/2).downto(1) {|i| maxHeapify i}
print ' ',$a.join(' ')
puts

Measured memory_bytes: 99752
import sys
import math
from collections import deque
from collections import defaultdict

class UnionFind():
    def __init__(self, n):
        #初期化[-1]*nのリストを作る
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        #要素x,yのグループを統合する
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        #要素xが所属するグループの人数を返す
        return -self.parents[self.find(x)]

    def same(self, x, y):
        #要素xとyが同じグループかどうか(同じならTrue)
        return self.find(x) == self.find(y)

    def members(self, x):
        #要素xと同じグループのメンバー全員を返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        #Find-Treeの頂点
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        #グループ数を返す
        return len(self.roots())

    def all_group_members(self):
        #頂点:[グループリスト]を返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    """
    #遷移を確認したいときはこちらに書き換えて実行する(for以降の経路圧縮が行われていない)
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)))
    """

def main():
    n, m, k = list(map(int,sys.stdin.readline().split()))
    uf = UnionFind(n)
    num_of_friends = [-1] * n

    for _ in range(m):
        a, b = list(map(int,sys.stdin.readline().split()))
        a -= 1
        b -= 1
        uf.union(a,b)
        num_of_friends[a] -= 1
        num_of_friends[b] -= 1
        #print(num_of_friends)
    #print(uf)
    """
    for i2 in range(n):
        roots[find(i2)] += 1
        print(roots)"""
    for i3 in range(n):
        num_of_friends[i3] += uf.size(i3)
        #print(num_of_friends)

    for _ in range(k):
        c, d = list(map(int,sys.stdin.readline().split()))
        c -= 1
        d -= 1
        """
        if find(c) == find(d):
            num_of_friends[c] -= 1
            num_of_friends[d] -= 1
        """
        if uf.same(c,d):
            num_of_friends[c] -= 1
            num_of_friends[d] -= 1    
    #print(num_of_friends)
    print(' '.join([str(number) for number in num_of_friends]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 18388
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

bool f[3];
int main(void) {
    REP(i, 2) {
        int a;
        cin >> a;
        a--;
        f[a] = true;
    }
    REP(i, 3) if (!f[i]) {
        cout << i + 1 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll fac[500];
	rep(i, 0, 300){
		fac[i] = i*i*i*i*i;
	}
	
	ll x; cin >> x;
	
	ll a, b;
	rep(i, 0, 300){
		rep(j, 0, 300){
			if(fac[i]-fac[j] == x){
				a = i;
				b = j;
			}
			
			if(fac[i]+fac[j] == x){
				a = i;
				b = -j;
			}
		}
	}
	cout << a << " " << b << endl;
	return 0;
}

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

 using namespace std;
  int Arr[4][1001];
  int ColPart[1000001]={},RowPart[1000001]={};
  bool Area[2010][2010]={};
  int Row=0,Col=0;
  int W,H;
  int n;

  typedef struct{
   int x,y;
  }NODE;
  queue<NODE> q;
  NODE mknd(int x,int y){
   NODE T;
   T.x = x;
   T.y = y;
   return T;
  }
   void Floodfill(int x,int y){
   q.push(mknd(x,y));
   while(!q.empty()){
        int X = q.front().x;
        int Y = q.front().y;
        q.pop();
    if(X+1<Row&&Area[X+1][Y]==0){
        Area[X+1][Y]=1;
        q.push(mknd(X+1,Y));
    }
    if(X-1>=0&&Area[X-1][Y]==0){
        Area[X-1][Y]=1;
        q.push(mknd(X-1,Y));
    }
    if(Y+1<Col&&Area[X][Y+1]==0){
        Area[X][Y+1]=1;
        q.push(mknd(X,Y+1));
    }
    if(Y-1>=0&&Area[X][Y-1]==0){
        Area[X][Y-1]=1;
        q.push(mknd(X,Y-1));
    }
   }
   return;
  }
  int main(){
    do{
    Row = Col = 0;
   for(int i=0;i<1000001;i++){
    RowPart[i] = -1;
    ColPart[i] = -1;
   }
   for(int i=0;i<2010;i++){
    for(int j=0;j<2010;j++){
        Area[i][j] =false;
    }
   }
   for(int i=0;i<1001;i++){
    Arr[0][i] = 0;
    Arr[1][i] = 0;
    Arr[2][i] = 0;
    Arr[3][i] = 0;
   }
   scanf("%d%d",&W,&H);
   if(W==0&&H==0)break;
   scanf("%d",&n);
   for(int i=1;i<=n;i++){
    scanf("%d%d%d%d",&Arr[0][i],&Arr[1][i],&Arr[2][i],&Arr[3][i]);
    ColPart[Arr[0][i]] = 0;
    ColPart[Arr[2][i]] = 0;
    RowPart[Arr[1][i]] = 0;
    RowPart[Arr[3][i]] = 0;
   }
   Arr[0][0] = 0;
   Arr[1][0] = 0;
   Arr[2][0] = W;
   Arr[3][0] = H;
    ColPart[Arr[0][0]] = 0;
    ColPart[Arr[2][0]] = 0;
    RowPart[Arr[1][0]] = 0;
    RowPart[Arr[3][0]] = 0;
    int RS= 0 ,CS= 0 ;
   for(int i=0;i<1000001;i++){
    if(!RowPart[i]){
        RowPart[i]=Row;
        Row++;
    }
    if(!ColPart[i]){
        ColPart[i]=Col;
        Col++;
    }
   }
   for(int i=1;i<=n;i++){
    int x1 = Arr[0][i];
    int y1 = Arr[1][i];
    int x2 = Arr[2][i];
    int y2 = Arr[3][i];
    for(int j=RowPart[y1];j<RowPart[y2];j++){
        for(int k=ColPart[x1];k<ColPart[x2];k++){
            Area[j][k] = 1;
        }
    }
   }
   int Count = 0;
  Row = Row-1;
  Col = Col-1;
   for(int i=0;i<Row;i++){
    for(int j=0;j<Col;j++){
        if(Area[i][j]==0){
        Floodfill(i,j);
        Count++;
        }
    }
   }
   printf("%d\n",Count);
   }while(true);
  }

Measured memory_bytes: 14984
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int x[N],n,l,i,z,p,q;
long long ans,s[N];
int main(){
	scanf("%d%d",&l,&n);
	for(i=1;i<=n;++i)scanf("%d",x+i),s[i]=s[i-1]+x[i];
	for(i=1;i<=n;++i){
		p=min(i-1,n-i);q=min(i,n-i);
		ans=max(ans,x[i]+2*(s[i-1]-s[i-p-1]+1ll*l*q-(s[i+q]-s[i])));
		p=min(i-1,n-i+1);q=min(i-1,n-i);
		ans=max(ans,l-x[i]+2*(s[i-1]-s[i-p-1]+1ll*l*q-(s[i+q]-s[i])));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#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,string>;

int main() {
    int n;
    cin >> n;
    map<string, int> mp;
    int maxi = 0;
    rep(i,n) {
        string s;
        cin >> s;
        if(mp.count(s)) {
            mp.at(s)++;
        }
        else {
            mp[s] = 1;
        }
        maxi = max(maxi, mp.at(s));
    }
    
    for(auto a : mp) {
        if(a.second == maxi) cout << a.first << endl;
    }
    
    return 0;
}

Measured memory_bytes: 19200
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define LL long long

using namespace std;

int a[100005];
int dp[100005];

int solve(int x) {
    if (x<1) return 10000000;
    if (x==1) return 0;
    if (dp[x]!=-1) return dp[x];
    return dp[x]=min(solve(x-1)+abs(a[x]-a[x-1]),solve(x-2)+abs(a[x]-a[x-2]));
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    for (int i=1;i<=n;i++) cin >> a[i];    
    memset (dp,-1,sizeof(dp));
    cout << solve(n) << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Data
{
public:
    int z, y, x, s;
    Data(int z0, int y0, int x0, int s0){
        z = z0;
        y = y0;
        x = x0;
        s = s0;
    }
    int toInt(){
        return ((z * 50 + y) * 50 + x) * 1024 + s;
    }
};

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

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

    vector<string> m(h, string(w, ' '));
    int sy, sx;
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            cin >> m[i][j];
            if(m[i][j] == '%'){
                sy = i;
                sx = j;
            }
        }
    }

    int sn;
    cin >> sn;
    vector<vector<string> > ms(10, vector<string>(h, string(w, ' ')));
    for(int i=0; i<sn; ++i){
        for(int j=0; j<h; ++j){
            cin >> ms[i][j];
        }
    }

    vector<bool> dp(2*50*50*1024, false);
    dp[Data(0, sy, sx, 0).toInt()] = true;
    queue<Data> q;
    q.push(Data(0, sy, sx, 0));

    int ret = 0;
    while(!q.empty()){
        int n = q.size();
        while(--n >= 0){
            int z = q.front().z;
            int y = q.front().y;
            int x = q.front().x;
            int s = q.front().s;
            q.pop();

            if(m[y][x] == '&'){
                cout << ret << endl;
                return 0;
            }if(m[y][x] == '|'){
                Data d(z^1, y, x, s);
                if(!dp[d.toInt()]){
                    dp[d.toInt()] = true;
                    q.push(d);
                }
            }else if(isalpha(m[y][x])){
                int s2 = s;
                s2 ^= 1 << (tolower(m[y][x]) - 'a');
                int z2 = z;
                if(ms[tolower(m[y][x]) - 'a'][y][x] == '*')
                    z2 ^= 1;
                Data d(z2, y, x, s2);
                if(!dp[d.toInt()]){
                    dp[d.toInt()] = true;
                    q.push(d);
                }
            }

            for(int i=0; i<4; ++i){
                int y2 = y + dy[i];
                int x2 = x + dx[i];
                if(m[y2][x2] == '#')
                    continue;

                int z2 = z;
                if(m[y2][x2] != '|'){
                    z2 = 0;
                    if(m[y2][x2] == '^' || isupper(m[y2][x2]))
                        z2 = 1;

                    bitset<10> bs(s);
                    for(int j=0; j<10; ++j){
                        if(bs[j] && ms[j][y2][x2] == '*')
                            z2 ^= 1;
                    }

                    if(z != z2)
                        continue;
                }

                Data d(z2, y2, x2, s);
                if(!dp[d.toInt()]){
                    dp[d.toInt()] = true;
                    q.push(d);
                }
            }
        }
        ++ ret;
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 2620