akhauriyash/Code-Regression huggingface dataset:
/*
ID: thanhvq1
LANG: C++14
PROB: namenum
*/

#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;

// defines
#define int long long
typedef long long ll;
#define double long double
#define vec vector
#define vi vector<int>
#define vvi vector<vector<int>>
#define FZ(n) memset((n),0,sizeof())
#define FMO(n) memset((n),-1,sizeof(n))
#define unset unordered_set
#define ii pair<int, int>
#define vii vector<ii>
#define F first
#define S second
#define mp make_pair
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)(x).size())
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define debug(x) cout << #x << " = " << (x) << endl
#define debug2(x, y) cout<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<< endl
#define debug3(x, y, z) cout<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<<", "<<#z<<" = "<<(z)<<endl
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c) min(a, b) < min(b, c) ? min(a, b) : min(b, c)

//permanent constants
const long long INF64 = 1e18; const int INF32 = 1e9; const int BIG = (int)(1e9 + 239);
const int MOD = 998244353; //1e9 + 7;  const ll MOD2 = (ll)MOD * (ll)MOD;
const double PI = 2.0*acos(0.0); //acos(-1.0L);
const double EPS = static_cast<double>(1e-10);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0};
//const ll INF = (ll)(1e18 + 239);

//random
mt19937 rnd(239); //(chrono::high_resolution_clock::now().time_since_epoch().count());

void FILEIO() {  freopen("in.txt", "r", stdin);  freopen("out.txt", "w", stdout); }
//void FILEIO()   {freopen("in.txt", "w", stdout);}
//void FILEIO() {  freopen("namenum.in", "r", stdin);  freopen("namenum.out", "w", stdout); }
void input() {   }

void solve() {
	int n; cin >> n;
	vi a(n); FOR(i, 0, n) cin >> a[i];
	if(n==1) {cout << "Yes" << endl; return;}
	int minV = INT_MAX, maxV=INT_MIN;
	vi sufMin, preMax;
	FORD(i, n-1, 1) {
		minV = min(minV, a[i]); sufMin.PB(minV);
	
		
//		debug3(i, a[i], minV);
		

	}
	FOR(i, 0, n-1) {maxV = max(maxV, a[i]); preMax.PB(maxV);
	
//	debug3(i, a[i], maxV);
	
	}
	
//	FOR(i, 0, n-1) cout << sufMin[i] << ", "; cout << endl;
//	FOR(i, 0, n-1) cout << preMax[i] << ", " ; cout << endl;	
	
	FOR(i, 0, n-1) if(preMax[i]-sufMin[n-2-i]>=2) {cout << "No" << endl; return;}
	cout << "Yes" << endl;
}

signed main() {
  ios_base::sync_with_stdio(false); cin.tie();
//  FILEIO();
//auto beginProgram = chrono::steady_clock::now();

//  int test = 0;
//  int t; cin >> t;
//  while(t--)
  {
//	  cout << "Case " << ++test << ": ";
	  solve();
  }

//  auto endProgram = chrono::steady_clock::now();
//  cout << chrono::duration_cast<chrono::milliseconds>(endProgram - beginProgram).count() << " ms" << endl;

  return 0;
}



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

using namespace std;
#define ll long long int
#define rep(i,n) for(i=0;i<(n);i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
typedef pair< ll, ll > lpair;

bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    if(a.ff == b.ff)
        return (a.ss < b.ss);
    return (a.ff < b.ff);
}

vector< ll > prime(1000005,1);
void p()
{
    ll i,j;
    for(i=2;i<=1000000;i++)
    {
        if(prime[i] == 1)
        {
            for(j = 2*i;j<=1000000;j+=i) prime[j] = 0;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll row,col,i,j;

    cin>>row>>col;

    ll dp[row+1][col+1];
    string temp;
    vector< string > a;
    rep(i,row)
    {
        cin>>temp;
        a.pb(temp);
    }
    rep(i,row+1) dp[i][0] = 0;
    rep(i,col+1) dp[0][i] = 0;
    dp[1][1] = 1;

    for(i = 1;i<=row;i++)
    {
        for(j = 1 ;j<=col;j++)
        {
            if(i == 1 && j == 1)
                continue;
            if(a[i-1][j-1] == '#')
                dp[i][j] = 0;
            else
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%(1000000000+7);
        }
    }
    // for(i = 1;i<=row;i++)
    // {
    //     for(j = 1;j<=col;j++)
    //         cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    cout<<dp[row][col]<<endl;

    return 0;
}

Measured memory_bytes: 17024
#include <stdio.h>
#include <stdlib.h>
#define MAX 10001
int main() {
int i,j;
int n,m,a[MAX],b[MAX],key,count=0;
scanf("%d",&n);
for(i=0;i<n;i++){
    scanf("%d",&a[i]);
}
scanf("%d",&m);
for(i=0;i<m;i++){
    scanf("%d",&b[i]);
}
i=0;
for (j = 0; j < m; j++) {
  key=b[j];
  while (a[i]!=key) {
    i++;
    if(i==n) {break;}
  }
  if(i!=n) {count++;}
  i=0;
}
printf("%d\n",count);

return 0;
}


Measured memory_bytes: 2104
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
using namespace std;
#define ll long long int
#define inf 0x3fffff
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define print(a) cout<<a
#define prints(a) cout<<a<<" "
#define println(a) cout<<a<<endl
#define fori(n) for(i=0;i<n;i++)
#define forj(n) for(j=0;j<n;j++)
#define fork(n) for(k=0;k<n;k++)


int main()
{
    int i,s[3],odd=0,even=0,neg=0,pos=0;
    cin>>s[0]>>s[1]>>s[2];
    sort(s,s+2);
    if(s[0]==s[1]) cout<<s[2]<<endl;
    else if(s[2]==s[1]) cout<<s[0]<<endl;
    else if(s[2]==s[0]) cout<<s[1]<<endl;
    else
    {
        for(i=0; i<3; i++)
        {
            if(s[i]<0)neg++;
            else pos++;
            if(s[i]%2==0) even++;
            else odd++;
        }
        if(neg==1) cout<<s[0]<<endl;
        else if(pos==1) cout<<s[2]<<endl;
        else
        {
            for(i=0; i<3; i++)
            {
                if(s[i]%2==0 && even==1)
                {
                    cout<<s[i]<<endl;
                    return 0;
                }
                if((s[i]%2==1||s[i]%2==-1) && odd==1)
                {
                    cout<<s[i]<<endl;
                    return 0;
                }
            }
        }
    }
}


Measured memory_bytes: 256
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    X = int(input())
    print(X * 360 // math.gcd(360, X) // X)    


if __name__ == "__main__":
    main()


Measured memory_bytes: 75012
import sys
import bisect

MOD = pow(10, 9)+7
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    init = []
    for i in range(N):
        cnt = 0
        for j in range(0, i):
            if A[j] < A[i]:
                cnt += 1
        init.append(cnt)
    
    Atmp = A.copy()
    Atmp.sort()
    large = []
    for i in range(N):
        large.append(bisect.bisect_left(Atmp, A[i]))

    ans = 0
    for i in range(N):
        a0 = large[i]*K-init[i]
        b = large[i]
        ans += K*a0 - ((K*(K-1))//2)*large[i]
        ans %= MOD
    print(ans%MOD)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main(void){
    long long n,c,k;
    long long bus=0,board=0,T=0;
    cin >> n >> c >> k;
    vector<long long> t(n);
    for(int i=0; i<n; i++)cin >> t[i];
    sort(t.begin(),t.end());
    for(int i=0; i<n; i++){
        if(board==0){
            T=t[i]+k;
            bus++;
            board++;
        }else if(T>=t[i]){
            board++;
        }else {
            bus++;board=1;
            T=t[i]+k;
        }
        if(board==c)board=0;
    }
    cout << bus << endl;
    return 0;
}

Measured memory_bytes: 1024
import itertools
n,m,q = map(int,input().split())
ch = list(itertools.combinations_with_replacement(range(1,m+1),n))
lch = len(ch)
rel = [0]*lch
l = [list(map(int,input().split())) for _ in range(q)]
for k in range(lch):
    for i in range(q):
        if ch[k][l[i][1]-1]-ch[k][l[i][0]-1]==l[i][2]:
            rel[k]+=l[i][3]
print(max(rel))

Measured memory_bytes: 25252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;


int main() {
    int n, l;
    cin >> n >> l;
    vector<string> v;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        v.push_back(s);
    }
    sort(v.begin(), v.end());
    string ans = "";
    for (int i = 0; i < n; i++) {
        ans += v[i];
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
  int N,K,X,Y;
  scanf("%d%d%d%d",&N,&K,&X,&Y);
  int t = min(N,K);
  printf("%d\n",min(N,K)*X+max(N-K,0)*Y);
}


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

using namespace std;

void solve(void)
{
	string s;
	cin >> s;
	int ans = 0, k = s.size();
	for (char c : s)
	{
		if (c == 'o')
			ans++;
	}
	cout << (15-k+ans >= 8 ? "YES" : "NO") << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 100005;
struct Card
{
	char suit;
	int value;
	friend bool operator<(const Card& a, const Card& b)
	{
		return a.value < b.value;
	}
} card[N], t[N];
int partition(Card arr[], int p, int r)	//[p, r)????????????,????????????pivot??????
{
	int pivot = arr[r - 1].value;
	int i = p;
	for (int j = p; j < r - 1; ++j)
	{
		if (arr[j].value <= pivot)
		{
			swap(arr[i++], arr[j]);
		}
	}
	swap(arr[i], arr[r - 1]);
	return i;
}

void q_sort(Card arr[], int l, int r)
{
	if (l + 1 < r)
	{
		int t = partition(arr, l, r);
		q_sort(arr, l, t);
		q_sort(arr, t, r);
	}
}

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> card[i].suit >> card[i].value;
		t[i] = card[i];
	}
	q_sort(card, 0, n);
	stable_sort(t, t + n);
	bool flag = true;
	for (int i = 0; i < n; ++i)
	{
		if (card[i].suit != t[i].suit)
		{
			flag = false;
			break;
		}
	}
	if (flag)
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;

	for (int i = 0; i < n; ++i)
		cout << card[i].suit << ' ' << card[i].value << endl;

	return 0;
}

Measured memory_bytes: 4712
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::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;
}

template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

long long gcd(ll x, ll y){
	if(x < y) swap(x,y);
	while(x%y){
		long long tmp = y;
		y = x%y; x = tmp;
	}
	return y;
}

int main(){
	int n; cin >> n;
	string s; cin >> s;
	ll r = 0, g = 0, b = 0;
	rip(i,n,0){
		if(s[i] == 'B') b++;
		else if(s[i] == 'G') g++;
		else r++;
	}
	ll ans = r*g*b;
	rip(i,n,0){
		rip(j,i,0){
			int k = 2*i - j;
			if(k >= n) continue;
			if(s[i] != s[k] && s[i] != s[j] && s[k] != s[j]){
				ans--;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3608
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

bool IsAcgt(const char ch) {
  return (ch == 'A' || ch == 'C' || ch == 'G' || ch == 'T');
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int32_t N, M, X;
  cin >> N >> M >> X;
  vector<int32_t> A(M);
  for (int32_t i = 0; i < M; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  int32_t count_left = 0, count_right = 0;
  for (int32_t i = 0; i < M; ++i) {
    if (A[i] < X && (i == M - 1 || X < A[i + 1])) {
      count_left = i + 1;
      count_right = M - count_left;
      break;
    }
  }
  cout << min(count_left, count_right) << endl;

  return 0;
}


Measured memory_bytes: 256
Imports System

Public Class Program

    Public Shared Sub Main(args As String())

        Dim N As Integer = Integer.Parse(Console.ReadLine)

        Dim Man(N - 1, N - 1) As Integer



        For i As Integer = 0 To N - 1
            Dim Ai As Integer = Integer.Parse(Console.ReadLine)

            For j As Integer = 0 To Ai - 1

                Dim Input() As String = Console.ReadLine.Split(" ")
                Man(i, Integer.Parse(Input(0) - 1)) = Integer.Parse(Input(1)) + 1
            Next

        Next

        Dim status(N - 1) As Boolean
        Dim maxcnt As Integer = 0


        For s As UInt16 = 0 To 2 ^ N - 1
            Try
                Dim cnt As Integer = 0

                For d As Integer = 0 To N - 1
                    status(d) = (s >> d) And 1

                    If status(d) Then
                        cnt += 1
                    End If

                Next

                If maxcnt > cnt Then
                    Throw New ieieie
                End If

                For d As Integer = 0 To N - 1
                    If status(d) Then

                        For dd As Integer = 0 To N - 1

                            If (Man(d, dd) = 2) AndAlso (status(dd) = False) Then
                                Throw New ieieie
                            End If

                            If (Man(d, dd) = 1) AndAlso (status(dd) = True) Then
                                Throw New ieieie
                            End If

                        Next

                    End If
                Next

                maxcnt = cnt
            Catch ex As ieieie

            End Try



        Next


        Console.WriteLine(maxcnt)




    End Sub
End Class

Public Class ieieie : Inherits Exception

End Class

Measured memory_bytes: 17360
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
    int H,N;
    cin >> H >> N;
    vector<int> waza(N);
    
    for (int i = 0;i < N;i++) {
        cin >> waza.at(i);
    }

    int health = 0;

    for (int i = 0;i < N;i++) {
        H -= waza.at(i);
    }

    if (H <= 0) { 
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
int main(void){
	int n;
	long long int *a;
	long long int *b;
	scanf("%d",&n);
	a=(long long int *)calloc(n,sizeof(long long int));
	b=(long long int *)calloc(n,sizeof(long long int));
	
	for(int i=0; i<n; i++){
		scanf("%d%d",&a[i],&b[i]);
	}
	long long int cnt=0;
	for(int i=n-1; i>-1; i--){
		long long int tmpa=a[i]+cnt;
		long long int tmpb=b[i];
		if(tmpa%tmpb!=0)cnt+=(long long int)(tmpa/tmpb+1)*tmpb-tmpa;
	}
	printf("%lld\n",cnt);
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<assert.h>
#include<vector>
#include<string.h>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<string>
#include<iostream>
#include<set>
#include<unordered_set>
#include<map>
#include<queue>
#include<functional>
#include<list>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 500005;
const int MM = 1000000007;

int mn[MX], mx[MX];

int main()
{
	ll N, M;
	scanf("%lld%lld", &N, &M);
	ll s = 0, e = 1e12, m;
	while(s <= e){
		m = (s+e) / 2;
		if(2*m <= M && m*4 <= 2*N+M ) s = m+1;
		else e = m-1;
	}swap(s, e);
	printf("%lld\n", s);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 13
#define pi M_PI

struct dice{
    int d[6], tmp[6];
};
struct dice dice1;
struct dice dice2;
void init1(int n[6]){
    int i;
    for (i=0;i<6;i++){
        dice1.d[i]=n[i];
    }
}
void init2(int n[6]){
    int i;
    for (i=0;i<6;i++){
        dice2.d[i]=n[i];
    }
}
void throwdice(char c){
    int i;
    for(i=0;i<6;i++){
        dice1.tmp[i]=dice1.d[i];
    }
    if(c=='N'){
        dice1.d[0]=dice1.tmp[1];
        dice1.d[1]=dice1.tmp[5];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[0];
        dice1.d[5]=dice1.tmp[4];
    }
    else if(c=='E'){
        dice1.d[0]=dice1.tmp[3];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[0];
        dice1.d[3]=dice1.tmp[5];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[2];
    }
    else if(c=='W'){
        dice1.d[0]=dice1.tmp[2];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[5];
        dice1.d[3]=dice1.tmp[0];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[3];
    }
    else if(c=='S'){
        dice1.d[0]=dice1.tmp[4];
        dice1.d[1]=dice1.tmp[0];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[5];
        dice1.d[5]=dice1.tmp[1];
    }
    else if(c=='R'){
        dice1.d[0]=dice1.tmp[0];
        dice1.d[1]=dice1.tmp[3];
        dice1.d[2]=dice1.tmp[1];
        dice1.d[3]=dice1.tmp[4];
        dice1.d[4]=dice1.tmp[2];
        dice1.d[5]=dice1.tmp[5];
    }
}
int compare(){
    int i;
    for(i=0;i<6;i++){
        if(dice1.d[i]!=dice2.d[i]){
            return 0;
        }
    }
    return 1;
}

int main(){
   int n[6];
   int check=0;
int i,j;
   for(int i=0;i<6;i++){
	   scanf("%d",&n[i]);
   }
   init1(n);
   for(int i=0;i<6;i++){
	   scanf("%d",&n[i]);
   }
   init2(n);
   for(i=0;i<4;i++){
        for(j=0;j<4;j++){
            throwdice('N');
            throwdice('E');
            throwdice('S');
            if(compare()) check=1;
        }
        throwdice('N');    
    }
    throwdice('E');
    for(i=0;i<2;i++){
        for(j=0;j<4;j++){
            throwdice('N');
            throwdice('E');
            throwdice('S');
            if(compare()) check=1;
        }
        throwdice('W');    
        throwdice('W');    
    }
	if(check)printf("Yes\n");
	else printf("No\n");
   return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	vi a(n);
	trav(x, a) cin >> x;

	ll ans = 0;

	if(a[0] != 0){
		cout << -1 << endl;
		return 0;
	}

	rep(i,1,n){
		int dif = a[i]-a[i-1];
		if(dif > 1){
			cout << -1 << endl;
			return 0;
		}
		if(dif == 1) ans++;
		if(dif < 1) ans += a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#define rep(i,j,k) for (i=j;i<=k;i++)
using namespace std;
const int N=505;
int n,m,i,j;
char s[N][N],a[N][N],b[N][N];
int main()
{
//	freopen("color.in","r",stdin);
//	freopen("color.out","w",stdout);
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%s",s[i]+1);
	rep(i,1,n)
		rep(j,1,m) a[i][j]=b[i][j]='.';
	rep(i,1,m) a[1][i]=b[n][i]='#';
	rep(i,2,n-1)
		rep(j,2,m-1)
			if (s[i][j]=='#') a[i][j]=b[i][j]='#';
	for (j=2;j<=m-1;j+=2)
		rep(i,2,n-1) a[i][j]='#';
	for (j=3;j<=m-1;j+=2)
		rep(i,2,n-1) b[i][j]='#';
	rep(i,1,n) {
		rep(j,1,m) printf("%c",a[i][j]);
		printf("\n");
	}
	printf("\n");
	rep(i,1,n) {
		rep(j,1,m) printf("%c",b[i][j]);
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  int n, d;
  cin >> n >> d;
  
  int ans = n / (d*2+1) + 1;
  if (n % (d*2+1) == 0)
    ans--;
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

typedef struct {
	double x;
	double y;
} Point;

void Koch(int n, Point a, Point b) {
	Point s,t,u;
	double rad = 60 * M_PI /180;
	if (n == 0) return;
	s.x = (2.0 * a.x + 1.0 * b.x)/3.0;
	s.y = (2.0 * a.y + 1.0 * b.y)/3.0;
	t.x = (1.0 * a.x + 2.0 * b.x)/3.0;
	t.y = (1.0 * a.y + 2.0 * b.y)/3.0;
	u.x = (t.x - s.x) * cos(rad) - (t.y - s.y) * sin(rad) + s.x;
	u.y = (t.x - s.x) * sin(rad) + (t.y - s.y) * cos(rad) + s.y;

	Koch(n-1, a, s);
	printf("%f %f\n",s.x,s.y);
	Koch(n-1, s, u);
	printf("%f %f\n",u.x,u.y);
	Koch(n-1, u, t);
	printf("%f %f\n",t.x,t.y);
	Koch(n-1, t, b);
}

int main () {
	Point a,b;
	int n;

	scanf("%d", &n);

	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;

	printf("%f %f\n", a.x, a.y);
	Koch(n, a, b);
	printf("%f %f\n", b.x, b.y);

	return 0;
}

Measured memory_bytes: 636
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {0,1,0,-1};
const static int ty[] = {-1,0,1,0};

const static double EPS = 1e-8;

int main(){
  int num_of_players;
  map<string,int> dict;
  dict["Rock"] = 0;
  dict["Fire"] = 1;
  dict["Scissors"] = 2;
  dict["Snake"] = 3;
  dict["Human"] = 4;
  dict["Tree"] = 5;
  dict["Wolf"] = 6;
  dict["Sponge"] = 7;
  dict["Paper"] = 8;
  dict["Air"] = 9;
  dict["Water"] = 10;
  dict["Dragon"] = 11;
  dict["Devil"] = 12;
  dict["Lightning"] = 13;
  dict["Gun"] = 14;

  map<int,bool> canWin;
  for(int hand_i = 0; hand_i < 15; hand_i++){
    for(int hand_j = 0; hand_j < 15; hand_j++){
      canWin[hand_i * 15 + hand_j] = false;
      for(int offset = 1; offset <= 7; offset++){
        if(hand_j == (hand_i + offset) % 15){
          canWin[hand_i * 15 + hand_j] = true;
        }
      }
    }
  }

  while(~scanf("%d",&num_of_players)){
    if(num_of_players == 0){
      break;
    }
    vector<string> players;
    for(int player_i = 0; player_i < num_of_players; player_i++){
      string hand;
      cin >> hand;
      players.push_back(hand);
    }

    bool lose[1001] = {};
    bool win[1001] = {};
    for(int player_i = 0; player_i < num_of_players; player_i++){
      for(int player_j = player_i + 1; player_j < num_of_players; player_j++){
        if(canWin[dict[players[player_i]] * 15 + dict[players[player_j]]]){
          lose[player_j] = true;
          win[player_i] = true;
        }
        if(canWin[dict[players[player_j]] * 15 + dict[players[player_i]]]){
          lose[player_i] = true;
          win[player_j] = true;
        }
      }
    }

    string res = "Draw";
    for(int player_i = 0; player_i < num_of_players; player_i++){
      if(!lose[player_i] && win[player_i]){
        res = players[player_i];
        break;
      }
    }
    printf("%s\n",res.c_str());
  }
}

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

const long long INF = 10000000000LL;
long long G[100][100];

int main() {
  int V, E; cin >> V >> E;
  for(int i = 0; i < V; i++)
    for(int j = 0; j < V; j++)
      G[i][j] = INF;
  for(int v = 0; v < V; v++)
    G[v][v] = 0;
  for(int i = 0; i < E; i++) {
    long long from, to, d;
    cin >> from >> to >> d;
    G[from][to] = min(G[from][to], d);
  }
  for(int k = 0; k < V; k++)
    for(int i = 0; i < V; i++)
      for(int j = 0; j < V; j++)
        if(G[i][k] != INF && G[k][j] != INF)
          G[i][j] = min(G[i][j], G[i][k] + G[k][j]);

  bool negative_loop = false;
  for(int v = 0; v < V; v++)
    if(G[v][v] < 0) negative_loop = true;
  if(negative_loop) {
    cout << "NEGATIVE CYCLE" << endl;
  }
  else {
    for(int i = 0; i < V; i++) {
      for(int j = 0; j < V; j++) {
        if(G[i][j] == INF) cout << "INF";
        else cout << G[i][j];

        if(j + 1 != V) cout << " ";
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 1240
import java.util.Scanner;
import java.util.Stack;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {
		for(;;){
			String buf = sc.nextLine();
			if(".".equals(buf)){
				break;
			}
			System.out.println(solve2(buf)?"yes":"no");
		}
	}
	
	
	boolean solve(String s){
		String left = "[(";
		String right = "])";
		
		Stack<Integer> open = new Stack<Integer>(); 
		for(char ch: s.toCharArray()){
			int l = left.indexOf(ch);
			int r = right.indexOf(ch);

			if(l >= 0) open.push(l);
			if(r >= 0 && open.isEmpty()) return false;
			if(r >= 0 && open.pop() != r) return false;
		}
		return open.isEmpty();
	}	
	
	boolean solve2(String s){
		s = s.replaceAll("[a-zA-Z\\.]", "").replace(" ","");
		int length = s.length();
		for(;;){
			s = s.replaceAll("\\(\\)", "").replace(" ","");
			s = s.replaceAll("\\[\\]", "").replace(" ","");
			if(s.length() == 0){
				return true;
			}
			
			if(s.length() < length){
				length = s.length();
			}else{
				return false;
			}
		}
	}
}



Measured memory_bytes: 67080
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}

int main()
{
    int n;
    cin >> n;
    ll ans1=1;
    ll ans2=1;
    ll tmp=1;
    REP(i,n){
        tmp*=10;
        ans1*=9;
        ans2*=8;
        ans1%=MOD;
        ans2%=MOD;
        tmp%=MOD;
    }
    ans1*=2;
    ans1%=MOD;
    ans1=(tmp+MOD-(ans1+MOD-ans2)%MOD)%MOD;
    cout << ans1 << endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <numeric>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>


using namespace std;
using ll = long long;
const ll INF = 1e9;


int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> x(n+1), y(m+1);
    for (int i = 1; i <= n; i++) {
        cin >> x[i];
    }
    for (int i = 1; i <= m; i++) {
        cin >> y[i];
    }

    ll v = 0;
    for (int i = 1; i <= n; i++) {
        v += (i + i - n - 1) * x[i];
        v %= (ll)1e9 + 7;
    }

    ll d = 0;
    for (int i = 1; i <= m; i++) {
        d += (i + i - m - 1) * y[i];
        d %= (ll)1e9 + 7;
    }

    cout << (v * d) % ((ll)1e9 + 7) << endl;

    return 0;
}

Measured memory_bytes: 1792
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let s = read::<String>().chars().collect::<Vec<char>>();
    let ans = solve(&s);
    println!("{}", ans);
}

fn solve(s: &Vec<char>) -> usize {
    let n = s.len();
    let mut pos = 0;
    let mut ans = 0;
    let mut acnt = 0;
    while pos < n {
        if s[pos] == 'A' {
            acnt += 1;
            pos += 1;
        } else if pos < n - 1 && s[pos] == 'B' && s[pos + 1] == 'C' {
            ans += acnt;
            pos += 2;
        } else {
            acnt = 0;
            pos += 1;
        }
    }
    return ans;
}

Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
	
	char tmp[64];
	string S;
	int max = 0;
	int t = 0;
	
	cin >> S;
	
	for(int i=0; i<S.length(); i++){
		t = 0;
		for(int j=i; j<S.length(); j++){
			if(S[j] == 'A' || S[j] == 'T' || S[j] == 'C' || S[j] == 'G'){
				t++;
			}else{
				break;
			}
		}
		max = (t > max) ? t : max;
	}
	
	printf("%d\n", max);
	
	return 0;
	
}


Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=200000;
const int MAXLEN=200000;

int h,w,n;
int sx,sy;
char a[MAXN+1];
char b[MAXN+1];

int len;
char c[MAXN+1];
char d[MAXN+1];

bool solveonedim(int start) {
	//printf("solveonedim(%d,%d,%s,%s)\n",len,start,c,d);
	int l=1,r=len;
	for(int i=n-1;i>=0;--i) {
		if(d[i]=='-') r=min(r+1,len);
		if(d[i]=='+') l=max(l-1,1);
		if(c[i]=='-') ++l;
		if(c[i]=='+') --r;
		if(l>r) return false;
		//printf("\tat start of %d: %d..%d\n",i,l,r);
	}
	return l<=start&&start<=r;
}

bool solve() {
	len=h;
	REP(i,n) if(a[i]=='U') c[i]='-'; else if(a[i]=='D') c[i]='+'; else c[i]='.'; c[n]='\0';
	REP(i,n) if(b[i]=='U') d[i]='-'; else if(b[i]=='D') d[i]='+'; else d[i]='.'; d[n]='\0';
	if(!solveonedim(sx)) return false;
	len=w;
	REP(i,n) if(a[i]=='L') c[i]='-'; else if(a[i]=='R') c[i]='+'; else c[i]='.'; c[n]='\0';
	REP(i,n) if(b[i]=='L') d[i]='-'; else if(b[i]=='R') d[i]='+'; else d[i]='.'; d[n]='\0';
	if(!solveonedim(sy)) return false;
	return true;
}

void run() {
	scanf("%d%d%d",&h,&w,&n);
	scanf("%d%d",&sx,&sy);
	scanf("%s",a);
	scanf("%s",b);
	printf("%s\n",solve()?"YES":"NO");
}

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


Measured memory_bytes: 1024
#include <cstdio>

int main(void){
	
	char c[4];
	char d[4];
	
	scanf("%s",c);
	scanf("%s",d);
	
	char s[3];
	
	s[0]=d[2];
	s[1]=d[1];
	s[2]=d[0];
	
	if(c[0]==s[0] && c[1]==s[1] && c[2]==s[2]){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

char a='a',b='a',c='a';
string s;
set<string> S;

int main(){
	while(1){
		printf("?%c%c%ca\n",a,b,c);fflush(stdout);
		string t="";
		t+=a,t+=b,t+=c,t+='a';
		S.insert(t);
		cin>>s;
		if(s[0]!='a'||S.count(s)){
			printf("!OUT\n");fflush(stdout);
			return 0;
		}
		S.insert(s);
		a=s[s.sz-1];
		c++;
		if(c=='{')b++,c='a';
	}
}

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

        int all = 0;
        for(int i=0; i<N.length(); i++){
            all += n[i]-'0';
}
        int M = Integer.valueOf(N);

        if(M%all==0){
            System.out.println("Yes");
        }else{
            System.out.println("No");    
    }         
}
}

Measured memory_bytes: 35656
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() 
{
   cin>>n>>s;
   if(n%2==1)
   {
      cout<<"No";
      return 0;
  }
   string a=s.substr(0,n/2),b=s.substr(n/2,n/2);
   if(a==b) 
   {
      cout<<"Yes";
      return 0;
   }
    cout<<"No";
}

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

int main(){
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  int sumA = 0;
  for(int i = 0; i < N; i++){
    sumA += A.at(i);
  }
  if(H <= sumA) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3792
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] sArr = sc.next().toCharArray();
        boolean[] abc = new boolean[26];

        for (int i = 0; i < sArr.length; i++) {
            abc[sArr[i]-'a'] = true;
        }

        String ans = "None";
        for (int i = 0; i < abc.length; i++) {
            if (abc[i] == true) {
                continue;
            } else {
                char ansChar = (char)(i+'a');
                ans = String.valueOf(ansChar);
                break;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 26232
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,command,x;
    string key,l,r;
    map<string,int> myMap;
    cin >> n;
    
    for(int i = 0;i < n;++i){
        cin >> command;
        // insert
        if(command == 0){
            cin >> key >> x;
            myMap[key] = x;
        // find
        }else if(command == 1){
            cin >> key;
            if(myMap.count(key)){
                cout << myMap[key] << endl;
            }else{
                cout << 0 << endl;
            }
        }
        // delete
        else if(command == 2){
            cin >> key;
            myMap.erase(key);
        }
        // dump
        else if(command == 3){
            cin >> l >> r;
            map<string,int>::iterator begin,end;
            begin = myMap.lower_bound(l);
            end = myMap.upper_bound(r);
            for(;begin != end;++begin){
                cout << begin->first << " " << begin->second << endl;
            }
        }
    }
}


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

using namespace std;

const int DIM = 1e5 + 7;

vector <pair <int, int> > v[DIM];
int col[DIM];
int dp[DIM];

int nr = 0;

void dfs(int nod, int prev = 0)
{
	int k = 1;
	
	for(auto i : v[nod])
		if(i.first != prev)
		{
			if(k == dp[nod])
				k++;
			
			dp[i.first] = k;
			col[i.second] = k;
			k++;
			
			dfs(i.first, nod);
		}
}

main()
{
	int n;
	cin >> n;
	
	for(int i = 1; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		
		v[x].push_back({y, i});
		v[y].push_back({x, i});
	}
	
	dfs(1);
	
	for(int i = 1; i < n; i++)
		nr = max(nr, col[i]);
	
	cout << nr << '\n';
	
	for(int i = 1; i < n; i++)
		cout << col[i] << '\n';
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int a, b, c;
    cin >> a>>b>>c;

    string ans = "No";
    if(a<=c && c<=b) ans="Yes";

    cout << ans<< endl;

   return 0;
}

Measured memory_bytes: 256
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;



int main() {
	int N;
	cin >> N;
	map<string, int>mp;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	int m = 0;
	for (auto it = mp.begin(); it != mp.end();  ++it) {
		chmax(m, it->second);
	}
	for (auto it = mp.begin(); it != mp.end(); it++) {
		if (it->second == m) {
			cout << it->first << endl;
		}
	}
}


Measured memory_bytes: 25216
N = int(input())
A = input().split()
A = [int(n) for n in A]
S = sum(A)
X1 = S
result = []
for i in range(1,N-1,2):
    X1 -= 2*A[i]

result.append(X1)
text = str(X1)

for i in range(N-1):
    result.append(2*A[i]-result[i])
    text += " " + str(result[i+1])

print(text)

Measured memory_bytes: 14528
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e9;
const long long LINF = 1LL << 50;
#define int long long


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, p; cin >> n >> p;
	int ans = 1;
	// mapで素因数分解を実装する
	map<int, int>mp;
	for (int i = 2; i <= sqrt(p); i++) {
		// iが素数かどうか判定(無駄な処理を減らす)
		if (!prime(i))continue;
		while (p%i == 0) {
			// iで何回割り切れるか求める
			mp[i]++; p /= i;
		}
		ans *= pow(i, mp[i] / n);
	}
	if (p != 1) {
		mp[p] = 1;
	}
	ans *= pow(p, mp[p] / n);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <climits>

using namespace std;


int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);

	int a, b, c, d, e, f;

	cin >> a >> b >> c >> d >> e >> f;

	set<int> sugars;

	for (int i = 0; i <= f; ++i) {
		for (int j = 0; j <= f; ++j) {
			if (a * i + b * j <= f)
				sugars.insert(c * i + d * j);
		}
	}

	set<int> water;
	for (int i = 0; i <= f; ++i) {
		for (int j = 0; j <= f; ++j) {
			if (i == 0 && j == 0)
				continue;
			if (a * i * 100 + b * j * 100 <= f) {
				water.insert(a * i * 100 + b * j * 100);
			}
		}
	}

	double max_density = 0;
	int sugarAns = 0;
	int waterAns = a * 100;
	for (auto s : sugars) {
		for (auto w : water) {
			if (s + w == 0)
				continue;
			double density = 100.0 * s / (s + w);
			if (density > max_density && (100.0 * s / w) <= e && w + s <= f) {
				sugarAns = s;
				waterAns = w;
				max_density = density;
			}
		}
	}

	cout << waterAns + sugarAns << " " << sugarAns << endl;

	return 0;
}

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

int main() {
    int n; cin>>n;
    vector<int> a(n);
    rep(i, n) cin>>a[i];

    int cnt=0;
    rep(i, n) {
        cnt++;
        while (i<n-1&&a[i]==a[i+1]) i++;
        if (i==n-1) break;
        if (a[i]<a[i+1]) {
            while (i<n-1&&a[i]<=a[i+1]) i++;
        }
        else {
            while (i<n-1&&a[i]>=a[i+1]) i++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

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

#define pb         push_back

const int INF = 100000000;

int main(void) {
	while(1){
		int x, y, s;
		int ma = 0;
		cin >> x >> y >> s;
		if(x == 0 && y == 0 && s == 0) break;

		for(int i=1; i<s; i++){
			for(int j=1; j<s; j++){
				int p1 = i;
				int p2 = j;
				int p1x = p1*(100 + x)/100;
				int p2x = p2*(100 + x)/100;
				//printf("p1,p2:%d %d\n", p1, p2);

				//cout << p1x + p2x << endl;
				//cout << 13*105/100 + 88*105/100 << endl;
				if(p1x + p2x == s){
					int p1y = p1*(100 + y)/100;
					int p2y = p2*(100 + y)/100;

					if(p1y + p2y > ma){
						ma = p1y + p2y;
					}
				}

			}
		}

		cout << ma << endl;

	}
	
	return 0;
}

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

const int maxn = 20;
int N, S[1<<maxn];
map<int,int> cnt;
int gen[maxn];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N;
    multiset<int> ms;
    int mx = 0;
    for (int i = 0; i < (1<<N); i++) {
        cin >> S[i];
        cnt[S[i]]++;
        mx = max(mx,S[i]);
        ms.insert(S[i]);
    }
    priority_queue<pair<int,int>> pq;        
    pq.push({N,mx});
    auto it = ms.find(mx);
    ms.erase(it);
    while (!pq.empty()) {
        auto p = pq.top(); pq.pop();
        //cout << p.first << ' ' << p.second << '\n';
        if (p.first == 0) continue;
        pq.push({p.first-1,p.second});
        assert(p.first >= 1);
        auto it = ms.lower_bound(p.second);
        if (it != ms.begin()) {
            --it;
            assert(*it < p.second);
            pq.push({p.first-1,*it});
            ms.erase(it);
        }
        else {
            cout << "No\n";
            return 0;
        }
    }
    assert(ms.empty());
    cout << "Yes\n";
}



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

using namespace std;

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    long long n;

    cin >> n;

    long long num = ceil(n/1000.0)*1000;

    cout << num-n << '\n';

    return 0;

}



Measured memory_bytes: 3552
// 入力マクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize, m: usize,
        a: [usize; n],
    }

    let mut a = a;
    a.sort_by(|c, b| b.cmp(c));

    let ans = if (a[m - 1] as f64) < a.iter().sum::<usize>() as f64 / (4 * m) as f64 {
        "No"
    } else {
        "Yes"
    };

    println!("{}", ans);
}


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

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

  int P[1000];
  int i=0;
  if(N == 0)
  {
    printf("0\n");
    return 0;
  }

  while(N != 0)
  {
    if(N < 0)
    {
      if(N%(-2) == -1)
      {
        P[i] = 1;
        N = N/(-2) + 1;
      }
      else
      {
        P[i] = 0;
        N = N/(-2);
      }
    }
    else if(N > 0)
    {
      if(N%(-2) == 1)
      {
        P[i] = 1;
        N = N/(-2);
      }
      else
      {
        P[i] = 0;
        N = N/(-2);
      }
    }
    i++;
  }
  for(int j=i-1;j>=0;j--)
  {
    printf("%d",P[j]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 256