akhauriyash/Code-Regression huggingface dataset:
// RAM RAM

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define mp make_pair
#define arrayin(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define N 55

using namespace std;
 


int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
    string a;cin>>a;
    if(a=="a" || a=="e" || a=="i" || a=="o" || a=="u"){
    	cout<<"vowel"<<endl;
    }else{
    	cout<<"consonant"<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = -float('inf')
for i in range(n):
    s = []
    j = p[i]-1 
    s.append(c[j])
    while j != i:
        j = p[j]-1
        s.append(s[-1]+c[j])
    l = len(s)
    if k <= l:
        a = max(s[:k])
    elif s[-1] <= 0:
        a = max(s)
    else:
        w, r = divmod(k, l)
        a1 = s[-1]*(w-1) + max(s)
        a2 = s[-1]*w
        if r != 0:
            a2 += max(0, max(s[:r]))
        a = max(a1, a2)
    ans = max(ans, a)
print(ans)

'''

n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = -float('inf')
for i in range(n):
    j = p[i] - 1
    s = [c[j]]
    while j != i:
        j = p[j] - 1
        s.append(s[-1] + c[j])
    l = len(s)
    if k <= l:
        score = max(s[:k])
    elif s[-1] <= 0:
        score = max(s)
    else:
        w, r = divmod(k, l)
        score1 = s[-1] * (w - 1)
        score1 += max(s)
        score2 = s[-1] * w
        if r != 0:
            score2 += max(0, max(s[:r]))
        score = max(score1, score2)

    ans = max(ans, score)

print(ans)
'''

Measured memory_bytes: 80564
#include <bits/stdc++.h>
    #include<cmath> 
     
    #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
    #define SUBL freopen("/home/ajinkya/Desktop/input.txt","r",stdin); freopen("/home/ajinkya/Desktop/output.txt","w",stdout); 
    #define ll long long
    #define ull unsigned long long
    #define FI(i,a,n) for(int i=a; i<=n; i++)
    #define RFI(i,n,a) for(int i=n; i>=a; i--)
    #define FLL(i,a,n) for(ll i=a; i<=n; i++)
    #define RFLL(i,n,a) for(ll i=n; i>=a; i--)
    #define vi vector<int>
    #define vll vector<ll>
    #define all(v) v.begin(),v.end()
    #define pll pair<ll,ll>
    #define pi pair<int, int>
    #define GCD(a,b) __gcd(a,b)
    #define MP make_pair
    #define PB push_back
    #define PF push_front
    #define LB lower_bound
    #define UB upper_bound
    #define debug(x) cout << x << endl
    #define MOD 1000000007
    #define INF LLONG_MAX
    #define PI 3.14159265359
    using namespace std;
     
    vector<int> adj[200005];
    vector<int> counter(200005, 0); 
    
    void dfs(int u, int p, int pre )
    {
    	counter[u] += pre;
    	for(auto &i:adj[u])
    	{
    		if(i==p) continue;
    		dfs(i, u, counter[u]);
    	}
    }

    int main()
    {
        fastio 
        // SUBL
      	int n, q;
      	cin >> n >> q;
      	
      	for(int i=1; i<n; i++)
      	{
      		int x, y;
      		cin >> x >> y;
      		adj[x].PB(y);
      		adj[y].PB(x);
      	}
      	for(int i=1; i<=q; i++)
      	{
      		int p, x;
      		cin >> p >> x;
      		counter[p]+=x;
      	}
      	dfs(1,-1,0);
      	for(int i=1; i<=n; i++) cout << counter[i] << " ";
        return 0;
    }         	

Measured memory_bytes: 23552
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <iomanip>

using namespace std;
typedef long long ll;
const int maxn=1e5+1111;

int arr[maxn];
int dp[maxn];
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    dp[0]=dp[1]=0;
    for(int i=1;i<=n;++i){
        scanf("%d",arr+i);
        if(i>1) dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);
        for(int j=2;j<=k&&i-j>0;++j){
            dp[i]=min(dp[i-j]+abs(arr[i]-arr[i-j]),dp[i]);
        }
    }
    printf("%d\n",dp[n]);
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int,input().split()))

ans1 = c = 0
for i,a in enumerate(A):
    c += a
    if i%2:
        if c < 1:
            ans1 += 1-c
            c = 1
    else:
        if c > -1:
            ans1 += c+1
            c = -1

ans2 = c = 0
for i,a in enumerate(A):
    c += a
    if i%2==0:
        if c < 1:
            ans2 += 1-c
            c = 1
    else:
        if c > -1:
            ans2 += c+1
            c = -1

print(min(ans1,ans2))

Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N,M,X,Y;
    cin >> N >> M >> X >> Y;
    int x[N],y[M];
    rep(i,N){
        cin >> x[i];
    }
    rep(i,M){
        cin >> y[i];
    }
    sort(x,x+N);
    sort(y,y+M);
    if(min(Y,y[0])-max(X,x[N-1])>=1) cout << "No War" << endl;
    else cout << "War" << endl;





}


Measured memory_bytes: 256
s=list(input())
t=list(input())
ans=[0 for _ in range(len(s))]
for i in range(len(s)-len(t)+1):
    cnt=0
    for j in range(len(t)):
        if s[i+j]=='?' or s[i+j]==t[j]:
            cnt+=1
    if cnt==len(t):
        ans[i]=i+1
mark=ans.index(max(ans))
if sum(ans)!=0:
    for j in range(len(s)):
        if mark<=j and j<mark+len(t):
            s[j]=t[j-mark]
        elif s[j]=='?':
            s[j]='a'
    print(''.join(s))
else:print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

//#define _USE_MATH_DEFINES
//#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 1000000007; // 10000000000000007ll;

const double eps = 1e-8;

const i64 MAXN = 2'000'000 + 6;

i64 n, m;

i64 a[MAXN];


int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> m;

    i64 R = n * (n - 1) / 2 + m * (m - 1) / 2;
    cout << R << endl;



    return 0;
}

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

const int X = 101;
const int Y = 101;

int main(void)
{
    int N;
    cin >> N;
    vector<tuple<int, int, int>> pyramid;
    for (size_t i = 0; i < N; i++)
    {
        int x, y, h;
        scanf("%d %d %d", &x, &y, &h);
        pyramid.push_back(make_tuple(x, y, h));
    }

    for (int Cx = 0; Cx < X; Cx++)
    {
        for (int Cy = 0; Cy < Y; Cy++)
        {
            int H = 0;
            for(size_t i = 0; i < pyramid.size(); i++)
            {
                if (get<2>(pyramid[i]) >= 1)
                {
                    H = get<2>(pyramid[i]) + abs(get<0>(pyramid[i]) - Cx) + abs(get<1>(pyramid[i]) - Cy);
                    break;
                }
            }
            for(size_t i = 0; i < pyramid.size(); i++)
            {
                if (get<2>(pyramid[i]) != max(H - abs(get<0>(pyramid[i]) - Cx) - abs(get<1>(pyramid[i]) - Cy), 0))
                {
                    break;
                }
                if (i == pyramid.size()-1){
                    cout << Cx << " " << Cy << " " << H << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int w,h,x,y,r;
	cin>>w>>h>>x>>y>>r;
	if(x+r<=w&&y+r<=h&&x-r>=0&&y-r>=0){
		cout<<"Yes"<<endl;
}
    else{
		cout<<"No"<<endl;
}
}



Measured memory_bytes: 3088
#include <stdio.h>

int main(void){

    int S,h,m,s;
    scanf("%d", &S);
    h = S / 3600;
    m = (S - h*3600)/60;
    s = S - h*3600 - m*60;



    printf("%d:%d:%d\n", h, m, s);
    return 0;
}

Measured memory_bytes: 592
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        Set<Long> set = new HashSet<Long>();
        for (int i = 0; i < n; ++i) {
            String op = input.next();
            String st = input.next();
            long enc = 0;
            for (int k = 0; k < st.length(); ++k) {
                switch (st.charAt(k)) {
                    case 'A': enc = enc * 10 + 1;
                        break;
                    case 'C': enc = enc * 10 + 2;
                        break;
                    case 'G': enc = enc * 10 + 3;
                        break;
                    case 'T': enc = enc * 10 + 4;
                        break;
                }
            }
            if (op.equals("insert")) set.add(enc);
            else if (op.equals("find")) {
                if (set.contains(enc)) System.out.println("yes");
                else System.out.println("no");
            }
        }
    }                
}

Measured memory_bytes: 222940
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn main() {
    let v = read_vec::<usize>();
    println!("{}",if v[0]+v[1] == 15 {'+'} else if v[0]*v[1] == 15 {'*'} else {'x'});
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define pb push_back
#define mp make_pair
#define fi(i,start,end) for(int i=start; i < end ; ++i)
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mod 10000000


int main()
{
	string n;
	cin>>n;
	long long unsigned int ans =0;
	for(auto i:n)
    {
        ans=(ans+(i-'0'));
    }
    if(ans%9==0){cout<<"Yes";}
    else
        cout<<"No";
}


Measured memory_bytes: 3684
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO ツ篠ゥツ督ョツ青カツ青ャツつウツづェツつスツδソツッツドツ・ツスツタツブ
for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			System.out.println(i+"x"+j+"="+i*j);
		}
}
	}

}

Measured memory_bytes: 9104
#include <bits/stdc++.h>
#define nmax 100005

using namespace std;

vector <pair <int,int>> g[nmax];
int color[nmax];

void solve(int u, int par, int dist){
    color[u]=dist;
    for(auto v:g[u]){
        if(v.first!=par){
            solve(v.first,u,(dist+v.second)&1);
        }
    }
}

int main(){
    int n;
    cin >> n;
    for(int i=0,u,v,w;i<n-1;i++){
        cin >> u >> v >> w;
        u--,v--;
        g[u].emplace_back(v,w);
        g[v].emplace_back(u,w);
    }
    solve(0,-1,0);
    for(int i=0;i<n;i++){
        cout << color[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 8448
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#define N 100010
#define M 55
#define ls i << 1
#define rs i << 1 | 1
#define inf 1000000001
#define inc(i) (++ (i))
#define dec(i) (-- (i))
#define mid ((l + r) >> 1)
#define int long long
#define XRZ 1000000007
#define debug() puts("XRZ TXDY");
#define n_ ((n >> 1) + 1)
#define mem(i, x) memset(i, x, sizeof(i));
#define Next(i, u) for(register int i = head[u]; i ; i = e[i].nxt)
// #define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout);
#define Rep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i <= i##Limit ; inc(i))
#define Dep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i >= i##Limit ; dec(i))
// const int dx[10] = {1, -1, 0, 0};
// const int dy[10] = {0, 0, 1, -1};
using namespace std;
inline int read() {
    register int x = 0, f = 1; register char c = getchar();
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
int a, b, c;
signed main() {
    a = read(), b = read(), c = read();
    if(a == b) {
      if(c != a) puts("Yes");
      else puts("No"); return 0;
    }
    else if(a == c) {
      if(b != a) puts("Yes");
      else puts("No"); return 0;
    }
    else if(b == c) {
      if(a != b) puts("Yes");
      else puts("No"); return 0;
    } puts("No");
    return 0;int zmy666 = 232313092, zzz = 389898087, xjj = 83989342;
}


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

rlt = 0
dic = {}

for _ in range(N):
  a = input()
  if a not in dic:
    dic[a] = 1
  else:
    dic[a] += 1
    
for k in dic:
  if dic[k] % 2 == 1:
    rlt += 1
    
print(rlt)

Measured memory_bytes: 59864
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum[501][501], k, q;

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

  cin >> n >> m >> q;
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    sum[a][b]++;
  }
  rep(i, n) {
    rrep(j, 1, n) { sum[i][j] += sum[i][j - 1]; }
  }
  rep(i, q) {
    cin >> a >> b;
    a--;
    b--;
    ans = 0;
    rrep(j, a, b + 1) { ans += sum[j][b]; }
    Cout(ans);
  }
  return 0;
}

Measured memory_bytes: 2944
//T2
#include<iostream>
#include<string>
using namespace std;
const int N=102;
string mat[N];
int flag[N][N];
int main(){
	ios::sync_with_stdio(false);
	int n,m; cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>mat[i]; bool ok=1;
		for(int j=0;j<m;j++){
			if(mat[i][j]=='#'){ok=0; break;}
		}
		if(ok){
			for(int j=0;j<m;j++) flag[i][j]=1;
		}
	}
	for(int j=0;j<m;j++){
		bool ok=1;
		for(int i=0;i<n;i++){
			if(mat[i][j]=='#'){ok=0; break;}
		}
		if(ok){
			for(int i=0;i<n;i++) flag[i][j]=1;
		}
	}
	for(int i=0;i<n;i++){
		bool ok=1;
		for(int j=0;j<m;j++){
			if(!flag[i][j]){ok=0; cout<<mat[i][j];}
		}
		if(!ok) cout<<endl;
	}
return 0;
}

Measured memory_bytes: 384
n = int(input())

for i in range(1,n+1):
    x = i
    if i % 3 == 0:
        print(" ",end="")
        print(i,end="")
    else:
        while True:
            if x == 0:
                break
            if x % 10 == 3:
                print(" ",end="")
                print(i,end="")
                break
            x = int(x/10)

print("")
            


Measured memory_bytes: 6160
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


H, W = map(int, input().split())

fld = [""] * H
for i in range(H):
    fld[i] = input()

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

d = [[float("inf") for i in range(H * W)] for i in range(H * W)]
for i in range(H):
    for j in range(W):
        if fld[i][j] == '#':
            continue
        for k in range(4):
            x = i + dx[k]
            y = j + dy[k]
            if x < 0 or x >= H or y < 0 or y >= W:
                continue
            if fld[x][y] == ".":
                d[i*W+j][x*W+y] = 1


for i in range(H*W):
    d[i][i] = 0

warshall = warshall_floyd(d, H*W)
ans = 0
for val in warshall:
    for v in val:
        if v != float("inf"):
            ans = max(ans, v)

print(ans)


Measured memory_bytes: 136388
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    int k,i,j;
    bool yay=true;
    int values[5];
    for(i=0;i<5;i++)
    {
        cin>>values[i];
    }
    cin>>k;

    for(i=0; i<5;i++)
    {
        for(j=(i+1); j<5;j++)
        {
            if(abs(values[i]-values[j]) > k)
            {
                yay = false;
            }
        }
    }
    if(yay == true)
        cout << "Yay!" << endl;
    else
        cout<< ":("<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(n)     for (int i = 0; i <  n; i++)
#define rrep(n)    for (int i = n; i >= 0; i--)
#define Rep(a, b)  for (int i = a; i <  b; i++)
#define Rrep(a, b) for (int i = a; i >= b; i--)
#define gcd(x,y) __gcd(x,y)
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
const ll MOD = (1e9)+7;
const ll mod = 998244353;
const ll inf=(1LL<<62);
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline A abs(A &a) { return (a < 0 ? -a : a); }
using namespace std;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  ll h[1000000], dp[1000000];
  cin >> n;
  rep(n) {
    cin >> h[i];
    dp[i] = inf;
  }

  dp[0] = 0;

  rep(n) {
    chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
  }

  cout << dp[n - 1] << "\n";

  return (0);
}


Measured memory_bytes: 5160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, A[24], B[24], C[24];
  scanf("%d", &n);
  for(int i=0; i<n; i++) scanf("%d", &A[i]);
  for(int i=0; i<n; i++) scanf("%d", &B[i]);
  for(int i=0; i<n-1; i++) scanf("%d", &C[i]);
  int ans = 0;
  for(int i=0; i<n; i++) {
   ans += B[A[i]-1];
    if(i>0 && A[i]==A[i-1]+1) ans += C[A[i-1]-1];
  }
  printf("%d\n", ans);   
 return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#define int long long

signed main()
{
    int N, A, B;
    std::cin >> A >> B >> N;
    std::cout << (int)(std::floor((A * std::min((B-1), N)) / B)) - (int)((A * std::floor(std::min((B-1), N) / B)));
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
using namespace std;

int main() {
    nl // Lofi songs
    
    int s, w;
    cin >> s >> w;
    cout << (w >= s ? "unsafe":"safe");
}

Measured memory_bytes: 3596
#include <cstdio>
#include <cstdint>
#include <vector>
#include <map>

int inf = 1e9;

std::map<intmax_t, int> memo;

int dfs(intmax_t n, const std::vector<intmax_t>& div) {
  if (n == 1) return 0;
  if (memo.find(n) != memo.end()) return memo.at(n);
  int res = 0;
  for (auto x: div) {
    if (x > n) break;
    if (n % x != 0) continue;
    int cur = dfs(n / x, div) + 1;
    res = std::max(cur, res);
  }
  if (res == 0) res = -1;
  memo[n] = res;
  return res;
}

int main() {
  intmax_t n;
  scanf("%jd", &n);

  if (n == 1)
    return puts("-1"), 0;

  std::vector<intmax_t> div{2, 8};
  auto tmp = div;
  intmax_t bound = 1e18;
  while (true) {
    bool updated = false;
    std::vector<intmax_t> tmp0;
    for (auto x: tmp) {
      if (10*x > bound) continue;
      tmp0.push_back(10*x+2);
      tmp0.push_back(10*x+8);
      div.push_back(10*x+2);
      div.push_back(10*x+8);
      updated = true;
    }
    tmp = std::move(tmp0);
    if (!updated) break;
  }

  int res = dfs(n, div);
  if (!res) res = -1;
  printf("%d\n", res);
}



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

int a, b, c;
int solve() {
    int s = 0, t = 0;

    std::vector<bool> waked(61, false);
    while(true) {
        if(waked[s]) {
            return -1;
        }
        waked[s] = true;

        if(s <= c && c <= s+a) {
            break;
        }

        t += (a + b);
        s = (a+b+s)%60;
    }
    return t + c - s;
}

int main() {
    std::cin >> a >> b >> c;
    std::cout << solve() << std::endl;
}


Measured memory_bytes: 3092
def main():
    from collections import deque, defaultdict
    n, m = map(int, input().split())
    g = [[] for _ in range(n + 1)]
    ref = defaultdict(list)
    q = deque([])
    visited = set()
    inf = 10 ** 10
    dist = [-inf] * (n + 1)

    for i in range(m):
        a, b, k = map(int, input().split())
        g[a].append(b)
        g[b].append(a)
        ref[(a, b)] = k


    def dfs(u):
        q.append(u)
        while q:
            v = q.pop()
            visited.add(v)
            for x in g[v]:
                if x not in visited:
                    if ref[(v, x)] != []:
                        y = ref.get((v, x))
                        if dist[x] == -inf:
                            dist[x] = dist[v] + y
                        elif dist[x] != dist[v] + y:
                            print("No")
                            exit()
                    else:
                        y = ref.get((x, v))
                        if dist[x] == -inf:
                            dist[x] = dist[v] - y
                        elif dist[v] != dist[x] + y:
                            print("No")
                            exit()
                    q.append(x)


    for i in range(1, n + 1):
        if i not in visited:
            dist[i] = 1
            dfs(i)
    print("Yes")
if __name__ == '__main__':
    main()

Measured memory_bytes: 79468
package main
import "fmt"

func main() {
	var s,t string
	fmt.Scan(&s, &t)
	ans := false

	for index := range s {
		if s[index:] + s[0:index] == t {
			ans = true
		}
	}

	if ans{
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int n,k;
    cin>>n>>k;
    int ans=0;
    while(n>0){
        n/=k;
        ans++;
    }
    cout<<ans<<endl;
}


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

int main(){
  int N;
  int A[102];
  int i,j,t,cnt=0;
  
  cin >> N;
  for (i=0;i<N;i++)cin >> A[i];

  for (i=0;i<N;i++){
    for (j=N-1;j>i;j--){
      if (A[j]<A[j-1]){
	t=A[j];
	A[j]=A[j-1];
	A[j-1]=t;
	cnt++;
      }
    }
  }

  for (i=0;i<N-1;i++)
    cout << A[i] << " ";

  cout << A[i] << endl;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int N;
string s[2];

int main(){
    cin >> N;
    cin >> s[0] >> s[1];

    ll cnt = 1;
    for(int i=0;i<N;i++){
        if(i==0){
            if(s[0][i] == s[1][i]){
                cnt *= 3;
            }else{
                cnt *= 6;
                i++;
            }
        }else{
            if(s[0][i] == s[1][i]){
                if(s[0][i-1]==s[1][i-1]){   // p1
                    cnt = cnt * 2 % mod;
                }else{
                    cnt = cnt % mod;
                }
            }else{
                if(s[0][i-1] == s[1][i-1]){ // p3
                    cnt = cnt * 2 % mod;
                }else{
                    cnt = cnt * 3 % mod;
                }
                i++;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    int num;
    num = N;
    int keta = 0;
    while(num!=0){
        num /= 10;
        keta++;
    }
    int res = 0;
    if (keta==1){
        res = N;
    }else if(keta==2){
        res = 9;
    }else if (keta==3){
        res = 9 + (N-99);
    }else if (keta==4){
        res = 9 + 900;
    }else if (keta==5){
        res = 9 + 900 + (N-9999);
    }else if (keta==6){
        res = 9 + 900 + 90000;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

# argsは数を文字列で表したリスト
# 一番大きい数を文字列として出力
def maxnum(*args):
    maxn = args[0]
    for i in range(1, len(args)):
        if len(maxn) != len(args[i]):
            if len(args[i]) > len(maxn):
                maxn = args[i]
        else:
            maxn = max(maxn, args[i])
    return maxn


# 数字0〜9を作るのに必要なマッチ棒の数
nmatch = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = [""] + [None] * N
for i in range(1, N + 1):
    maxn = ""
    for a in A:
        if i - nmatch[a] >= 0 and dp[i - nmatch[a]] != None:
            maxn = maxnum(maxn, dp[i - nmatch[a]] + str(a), str(a) + dp[i - nmatch[a]])
            dp[i] = maxn

print(dp[N])


Measured memory_bytes: 28080
#include<bits/stdc++.h>
#define ll long long 
ll dp[110000];
int wt[110],val[110];
using namespace std;
int main()
{
	int n,w;
	cin>>n>>w;
	for(int i=0 ; i<n ; i++)
		cin>>wt[i]>>val[i];
	for(int i=0 ; i<n ; i++)
	{
		for(int j=w ; j>=0 ; j--)
		{
			if(j+wt[i]<=w)
				dp[j+wt[i]]=max(dp[j+wt[i]],val[i]+dp[j]);
		}
	}
	
	ll ret=0;
	for(int i=0 ; i<=w ; i++)
	{
		//cout<<dp[i]<<" ";
		ret=max(ret,dp[i]);
	}
	cout<<ret;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdlib>

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) std::cout << (j ? s1 : s2) << endl;
# define YES(j) std::cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)

int main()
{
    int w,a,b;cin >> w >> a >> b ;

    if(a <= b && b <= a+w) p(0)
    else if(a <= b+w && b+w <= a+w) p(0)
    else if(b+w<a) p(a-(b+w))
    else if(a+w<b) p(b-(a+w))
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

ll odp = 0;

int IleDo1(int a, int b)
{
    if (a + b <= 9)
        return 1;
    return 2;
}

int CyfDo1(int a, int b)
{
    int s = a + b;
    if (s <= 9)
        return s;
    return s % 10 + 1;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int m;
    cin >> m;
    vector<int> a;
    ll odp = 0;
    for (int i = 0; i < m; ++i)
    {
        ll cyf, il;
        cin >> cyf >> il;
        vector<int> r;
        while (il >= 2)
        {
            ll ilN = il / 2;
            odp += ilN * IleDo1(cyf, cyf);
            if (il % 2 == 1)
                r.push_back(cyf);
            il = ilN;
            cyf = CyfDo1(cyf, cyf);
        }
        if (il == 1)
            r.push_back(cyf);
        while (r.size() != 0)
        {
            a.push_back(r.back());
            r.pop_back();
        }
    }
    while (a.size() >= 2)
    {
        int cyf2 = a.back();
        a.pop_back();
        int cyf1 = a.back();
        a.pop_back();
        odp += IleDo1(cyf1, cyf2);
        a.push_back(CyfDo1(cyf1, cyf2));
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 18152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_158
{
    class C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] ab = ReadInts();
            int a = ab[0];
            int b = ab[1];
            for(int i = 1; i <= 1000; i++)
            {
                if (i * 8 / 100 == a && i * 10 / 100 == b)
                {
                    WriteLine(i);
                    return;
                }
            }
            WriteLine(-1);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b, bool usemod = true) {ll c = 1LL; while (b > 0) {if (b & 1LL) {if(!usemod)c*=a;else c = a * c%mod;}if (!usemod) a*=a;else a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}

double dis(pair<int,int> x, pair<int,int> y) {
	return sqrt((double)((x.F - y.F) * (x.F - y.F) + (x.S - y.S) * (x.S - y.S)));
}

bool solve() {
	pair<int,int> pos[3];
	REP (i,3) cin >> pos[i].F >> pos[i].S;
	double A[3];
	REP (i,3) {
		A[i] = dis(pos[i],pos[(i+1)%3]);
	}
	sort(A,A+3);
	double ab1 = A[2];
	double ab2 = A[1]*A[1]-A[0]*A[0];
	ab2 /= ab1;
	double a = (ab1-ab2)/2, b = (ab1+ab2)/2, c = sqrt(A[0]*A[0]-a*a);
	double ans = A[2] / ((A[1]+A[0]+a+b)/c+2);
	cout << fixed << setprecision(10) << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;

/**
 * Created by Taichi1 on 10/22/16.
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		HashSet<Integer> set = new HashSet<>();
		while (sc.hasNext()) {
			set.add(sc.nextInt());
		}
		System.out.println(set.size());
	}
}

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

#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define vec vector<int>
#define dead not_bad
#define bad gooood

#define left not_right
#define y1 what

using namespace std;

const int N = (int) 150;
const int M = (int) 20;
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const int ALPHA = 26;
const int mod = INF + 2;
const double PI = 3.14159265359;
const ld EPS = (ld) 1e-12;

const int nx[4] = {0, 0, -1, 1};
const int ny[4] = {1, -1, 0, 0};

int A, B;
int d[N][N];
int f[N][N];

int main() {
  #define fn "saddle"
  #ifdef witch
      freopen("input.txt", "r", stdin);
  //    freopen("output.txt", "w", stdout);
  #else
      //freopen(fn".in", "r", stdin);
      //freopen(fn".out", "w", stdout);
  #endif
  cin >> A >> B;
  for (int i = 1; i <= A; i++) {
    for (int j = 1; j <= B; j++) {
      cin >> d[i][j];
    }
  }
  for (int a = 0; a < N; a++) {
    for (int b = 0; b < N; b++) {
      for (int i = 1; i <= A; i++) {
        for (int j = 1; j <= B; j++) {
          f[a][b] = max(f[a][b], d[i][j] - i * a - j * b);
        }
      }
    }
  }
  for (int i = 1; i <= A; i++) {
    for (int j = 1; j <= B; j++) {
      int mn = INF;
      for (int a = 0; a < N; a++) {
        for (int b = 0; b < N; b++) {
          mn = min(mn, f[a][b] + a * i + b * j);
        }
      }
      if (mn != d[i][j]) {
        cout << "Impossible";
        return 0;
      }
    }
  }
  cout << "Possible\n";
  cout << 200 << ' ' << 100 * 100 + 99 * 2 << endl;
  for (int a = 0; a + 1 < 100; a++) {
    cout << a + 1 << ' ' << a + 2 << " X\n";
  }
  for (int b = 0; b + 1 < 100; b++) {
    cout << 100 + b + 1 << ' ' << 100 + b + 2 << " Y\n";
  }
  for (int a = 0; a < 100; a++) {
    for (int b = 0; b < 100; b++) {
      cout << a + 1 << ' ' << 100 + 100 - b << ' ' << f[a][b] << "\n";
    }
  }
  cout << 1 << ' ' << 200;
  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			int[] a=new int[n];
			for(int i=0;i<n;i++) a[i]=sc.nextInt();
			int min=Integer.MAX_VALUE;
			for(int i=-100;i<=100;i++){
				int sum=0;
				for(int j=0;j<n;j++) sum+=(i-a[j])*(i-a[j]);
				min=Math.min(sum,min);
			}
			System.out.println(min);
		}
	}
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

ll INF = (1ll << 32);

int main() {
  ll N, M; cin >> N >> M;
  vi a(M), b(M), c(M);
  for (ll i = 0; i < M; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i] -= 1;
    b[i] -= 1;
  }


  vvi m(N, vi(N, INF));
  for (ll i = 0; i < N; i++) m[i][i] = 0;
  for (ll i = 0; i < M; i++) {
    m[a[i]][b[i]] = c[i];
    m[b[i]][a[i]] = c[i];
  }

  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < N; j++) {
      for (ll k = 0; k < N; k++) {
        if (m[j][k] > m[j][i] + m[i][k]) {
          m[j][k] = m[j][i] + m[i][k];
        }
      }
    }
  }

  ll cnt = 0;
  for (ll i = 0; i < M; i++) {
    if (min(m[a[i]][b[i]], m[b[i]][a[i]]) < c[i]) {
      cnt += 1;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

int main() {

	ll N;
	cin >> N;

	ll v = 0;

	for (ll i = N; i > 0; i /= 2) {
	v++;
	}

	ll ans = 1;

	repn(i, v - 1) { ans *= 2; }

	cout << ans;
	system("PAUSE");
}


Measured memory_bytes: 504
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

    auto calc=[](string T) {
        int N = T.size();
        int cnt = 0;
        vector<int> A;
        rep(i,N) {
            if (T[i]=='1') cnt++;
            else {
                A.emplace_back(cnt);
                cnt = 0;
            }
        }
        A.emplace_back(cnt);
        //for (auto i : A) cout << i << " ";
        //cout << endl << endl;
        int M = A.size();
        // j == 0:動かしていない,j == 1:左,j == 2:右, j == 3 右すんどめ
        vector<vector<int>> dp(M, vector<int>(4));
        rep(i,M-1) {
            chmax(dp[i+1][0],dp[i][0]);
            chmax(dp[i+1][1],dp[i][0]+A[i]);
            chmax(dp[i+1][2],dp[i][0]+A[i+1]);
            chmax(dp[i+1][3],dp[i][0]+A[i+1]-1);

            chmax(dp[i+1][0],dp[i][1]);
            chmax(dp[i+1][1],dp[i][1]+A[i]-1);
            if (A[i] > 1) {
                chmax(dp[i+1][2],dp[i][1]+A[i+1]);
                chmax(dp[i+1][3],dp[i][1]+A[i+1]-1);
            }

            chmax(dp[i+1][0],dp[i][2]);

            chmax(dp[i+1][0],dp[i][3]);
            if (A[i] > 1) chmax(dp[i+1][1],dp[i][3]+1);
            chmax(dp[i+1][2],dp[i][3]+A[i+1]);
            chmax(dp[i+1][3],dp[i][3]+A[i+1]-1);
        }
        int ret = 0;
        rep(k,4) chmax(ret,dp[M-1][k]);
        return ret;
    };
    int N; cin >> N;
    string S; cin >> S;
    int ans = 0;
    string T;
    rep(i,N) {
        if (S[i]=='1') T += S[i];
        else {
            if (i and S[i-1]=='1') T += S[i];
            else {
                if (!T.empty()) {
                    while (T.back()=='0') T.pop_back();
                    ans += calc(T);
                    T = "";
                }
            }
        }
    }
    if (!T.empty()) {
        while (T.back()=='0') T.pop_back();
        ans += calc(T);
        T = "";
    }

    cout << ans << ln;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    long long A, B ,K;
    cin >> A >> B >> K;

    if(K <= A){
        cout << A-K << endl;
        cout << B << endl;
    }
    else if(K <= A+B){
        cout << 0 << endl;
        cout << A+B-K << endl;
    }
    else{
        cout << 0 << endl;
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a) (a).begin(), (a).end()

const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T &r, T &l)
{
    T tmp = r;
    r = l;
    l = tmp;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
    for (T &x : vec)
        is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
    return is;
}

int main()
{
    ll N;
    cin >> N;
    vector<vector<ll>> x(N, vector<ll>()); //
    vector<vector<ll>> y(N, vector<ll>()); //
    vector<ll> a(N);                       // power
    

    for (ll i = 0; i < N; i++)
    {
        cin >> a[i];
        // cerr <<a[i] <<endl;
        for (ll j = 0; j < a[i]; j++)
        {
            ll xx, yy;
            cin >> xx >> yy;
            x[i].push_back(xx-1);
            y[i].push_back(yy);
        }
    }

    ll ans = 0;

    // N=15なのでbitやる

    // // {0, 1, ..., n-1} の部分集合の全探索
    for (ll bit = 0; bit < (1 << N); ++bit){ // bitで 1が立っている場合は　N人が真
        bool isTrue = true;
        ll count = 0;

        for (ll j = 0; j < N; j++)
        {
            if (bit & (1 << j))
            {
                count++;
            }
        }

        // cerr << bit <<endl;
        // cerr <<count <<endl;

        // 検証
        for (ll j = 0; j < N; j++) // hito j nituite
        {
            for (ll k = 0; k < a[j]; k++){
                if (bit & (1 << j)){ //正直な場合
                    if (  !( ((bit & (1 << (x[j][k]) ))>0 ) == y[j][k]  ) ){
                        // cerr << (1 << j) <<"の人が : "<<(1 << (x[j][k])) << " == " << y[j][k] <<endl;
                        isTrue = false;
                    }
                }
            }
        }
        
        cerr << bit <<  " " << isTrue <<endl;
        cerr << endl;

        if (isTrue){
            if (ans < count){
                ans = count;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fast                          \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);
#define FOR(n) for(int i(0);i<n;++i)
#define ASC(i,a,b) for(int i(a); i <=b; ++i)
#define DESC(i,a,b) for(int i(a);i>=b;i--)
#define WL(t) while(t--)
#define SZ(a) int((a).size())
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define BB begin()
#define EE end()*
#define all(c) c.BB, c.EE
#define present(container, element) (container.find(element) != container.end())
// ^^for set,map etc
#define cpresent(container, element) (find(all(container), element) != container.end())
// for vector,array etc
#define tr(container, it) for (auto it = container.begin(); it != container.end(); it++)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef map<char,int> mci;
typedef pair<int, int> pii;
typedef map<int,pii> ipii;
const float INF = numeric_limits<float>::infinity();
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846264338;
const LL big=998244353;

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

int mini(int a,int b,int c){
	int d= min(a,b);
	return min(d,c);
}

int main(){
	int n,k;
	cin >> n >> k;
	vector<int> ht;
	FOR(n){
		int x; cin >> x;
		ht.PB(x);
	}
	int dp[n];
	dp[0]=0; dp[1]=abs(ht[1]-ht[0]);
	for(int i(2);i<n;++i){
		int tof=INT_MAX;
		for(int j(i-k);j<=(i-1);++j){
			if(j>=0 && j<n){
			int temp=dp[j]+abs(ht[j]-ht[i]);
			tof=min(tof,temp);
		}
		}
		dp[i]=tof;
	}
	cout << dp[n-1];

}


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

int main() {
    string s;

    cin >> s;

    bool flag = true;

    if( s.at(0) == 'A' && s.at(1) == 'A' && s.at(2) == 'A') flag = false;
    if( s.at(0) == 'B' && s.at(1) == 'B' && s.at(2) == 'B') flag = false;


    if(flag) cout << "Yes" << endl;
    else     cout << "No"  << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
int arr[n];
for(int i=0;i<n;i++)
    cin>>arr[i];
sort(arr,arr+n);
int ans=0;
for(int i=0;i<n-k;i++)
{
    ans+=arr[i];
}
cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
from sys import exit

def no():
  print("NO"); exit()

S = input()

n = len(S)

while n >= 5:
  # print(n)
  pf = S[n-3:n]
  if pf == "eam":
    if S[n-5:n] == "dream":
      n -= 5
    else:
      no()
  elif pf == "mer":
    if n >= 7 and S[n-7:n] == "dreamer":
      n -= 7
    else:
      no()
  elif pf == "ase":
    if S[n-5:n] == "erase":
      n -= 5
    else:
      no()
  elif pf == "ser":
    if n >= 6 and S[n-6:n] == "eraser":
      n -= 6
    else:
      no()
  else:
    no()

if n > 0:
  no()
else:
  print("YES"); exit()


Measured memory_bytes: 3316
import java.util.*;

public class Main{
    Main(){
	Scanner sc = new Scanner(System.in);
	TreeMap<String, Vector<Integer>> map = new TreeMap<String, Vector<Integer>>(); 

	while(sc.hasNext()){
	    String str = sc.next();
	    Integer tmp = Integer.valueOf(sc.next());
	    Vector<Integer> vec;
	    if(map.containsKey(str)){
		vec = map.get(str);
		map.remove(str);
	    } else {
		vec = new Vector<Integer>();
	    }
	    vec.add(tmp);
	    map.put(str, vec);
	}

	for(Iterator it = map.keySet().iterator(); it.hasNext();){
	    String str = (String)it.next();
	    Vector<Integer> vec = map.get(str);
	    Collections.sort(vec);
	    System.out.println(str);
	    System.out.print((vec.get(0)).toString());
	    for(int i = 1; i < vec.size(); i++)
		System.out.print(" " + (vec.get(i)).toString());
	    System.out.println();
	}
    }

    public static void main(String[] args){
	new Main();
    }
}

Measured memory_bytes: 12000
<?php
$input = explode(" ", trim(fgets(STDIN)));
$a = (int)$input[0];
$b = (int)$input[1];

if ($a > $b) {
    echo "a > b".PHP_EOL;
} elseif ($a === $b) {
    echo "a == b".PHP_EOL;
} else {
    echo "a < b".PHP_EOL;
}
?>


Measured memory_bytes: 9192