akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        var b = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        int ans = 0;
        var under = new List<long>();
        var over = new List<long>();
        if (a.Sum() <= b.Sum()) Console.WriteLine(-1);
        else
        {
            for (int i = 0; i < n; i++)
            {
                if (a[i] > b[i]) over.Add(a[i] - b[i]);
                else if (a[i] < b[i]) under.Add(b[i] - a[i]);
            }
            under = under.OrderBy(f => f).ToList();
            over = over.OrderByDescending(f => f).ToList();
            ans += under.Count();
            long x = under.Sum();
            for (int i = 0; i < over.Count(); i++)
            {
                if (x <= 0) break;
                else
                {
                    x -= over[i];
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}

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

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

    // lambda

    string s;
    cin >> s;
    int loop;
    cin >> loop;

    int is_reverse = false;
    string head = "";
    string tail = "";

    // O(n)
    while (loop--) {
        int t;
        cin >> t;

        // reverse
        if (t == 1) {
            is_reverse = !is_reverse;
        } else {
            // adding
            int f;
            cin >> f;
            string c;
            cin >> c;

            // normal
            if (!is_reverse) {
                if (f == 1)
                    head = c + head;
                else
                    tail += c;
            } else {
                if (f == 1)
                    tail += c;
                else
                    head = c + head;
            }
        }
    }

    string ans = head + s + tail;
    if (is_reverse) {
        reverse(ans.begin(), ans.end());
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1416
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
a3=list(map(int,input().split()))
n=int(input())
b=[int(input()) for i in range(n)]
for i in range(3):
    for j in range(n):
        if a1[i] == b[j]:
            a1[i] = 1
        elif a2[i] == b[j]:
            a2[i] = 1
        elif a3[i] == b[j]:
            a3[i] = 1
 
if a1[0] == a1[1] == a1[2]:
    print("Yes")
elif a2[0] == a2[1] == a2[2]:
    print("Yes")
elif a3[0] == a3[1] == a3[2]:
    print("Yes")
elif a1[0] == a2[0] == a3[0]:
    print("Yes")
elif a1[1] == a2[1] == a3[1]:
    print("Yes")
elif a1[2] == a2[2] == a3[2]:
    print("Yes")
elif a1[0] == a2[1] == a3[2]:
    print("Yes")
elif a1[2] == a2[1] == a3[0]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, l;
	cin >> n >> l;
	int r = n + l - 1;
	int ans = 0;
	if(l <= 0 && 0 <= r){
		rep(i, n){
			ans += l + i;
		}
	}else if(0 < l){
		rep2(i, 1, n){
			ans += l + i;
		}
	}else{
		rep(i, n-1){
			ans += l + i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String args[]) throws Exception{
		Scanner cin= new Scanner(System.in);
		final int n= cin.nextInt();
		int[] A    =new int[n];
		int[] DPlen=new int[n+1]; //DPlen[i]:長さi+1の増加部分列のうちの、[0]最小要素/[1]そのindex。
		int intMAX= (int)Math.pow(10d,9d)+1;
		
		A[0]= cin.nextInt();
		DPlen[0]= A[0];
		
		int k;
		for(k=1;k<n+1;k++){
			DPlen[k]= intMAX;
		}
		
		int i;
		for(i=1;i<n;i++){
			A[i]= cin.nextInt();
			int index = Arrays.binarySearch(DPlen, A[i]);
			if( index<0 ){
				index= ~index;
				DPlen[index]= A[i];
			}
		}
		
		i=0;
		while( DPlen[i]!=intMAX ){
			i++;
		}
		System.out.println(i);
	}
}

Measured memory_bytes: 66388
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
const int N = 1e5+7;
vi G[N];
ll dp[N][2];


// 1 implies black



int dfs(int s, int col , int p){

    if(dp[s][col] != 0)
        return dp[s][col];
    
    ll ans = 1 ;
    
    if(col){
        for(auto it : G[s]){
            if(it != p){
                ans *= dfs(it , !col , s);
                if(ans >= Mod)
                    ans %= Mod;
            }
        }
    }
    else
    {
        for(auto it : G[s]){
            if(it != p){
                ans *= dfs(it , col , s) + dfs(it , !col , s);
                if(ans >= Mod)
                    ans %= Mod;
            }
        }
    }
    dp[s][col] = ans;
    return ans;
}


int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    int n , u , v; cin >> n;
    for(int i = 0 ;i < n-1 ; i++){
        cin >> u >> v;
        G[u].pb(v);
        G[v].pb(u);
    }
    
    ll ans = 0;
    ans += dfs(1 , 0 , -1);
    ans += dfs(1 , 1 , -1);
    if(ans >= Mod)
        ans -= Mod;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14208
#include <stdio.h>
 
int main(){
	int i, N, max, min, a[1001];
	


	scanf("%d", &N);

	for(i = 1; i <= N; i++) {
		scanf("%d", &a[i]);
	}

	max = a[1];
 	for (i = 1; i <= N; i++) {
  		if (max < a[i]) {
   			max = a[i];
  		}	
   	}

	min = a[1];
 	for (i = 1; i <= N; i++) {
  		if (min > a[i]) {
   			min = a[i];
  		}	
   	}

	printf("%d", max - min);
 
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b;
    scanf("%d %d",&a,&b);
    
    int ketab;
    int bb=b;
    while(bb){
        bb/=10;
        ketab++;
    }
    
    int s=a*pow(10,ketab)+b;
    
    if( pow( (int)sqrt((double)s) ,2)==(double)s   ){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    
}

Measured memory_bytes: 2496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

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

    int a,b;
    cin >> a >> b;


   

    int m = min(a,b),M = max(a,b);

    rep(i,M)cout << m;



}

Measured memory_bytes: 256
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")
 
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
 
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;
 
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
 
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(0, 1); \
                 auto rnd = bind(__dis, __gen);
 
const int INF = 1E18;
const int mod = 1E9 + 7;
const int maxn = 1E5 + 5;

int dp[maxn][2];
vector<int> adj[maxn];

void dfs(int now, int lst) {
    dp[now][0] = dp[now][1] = 1;
    for (auto x : adj[now]) {
        if (x == lst) continue;
        dfs(x, now);
        dp[now][0] *= dp[x][0] + dp[x][1];
        dp[now][0] %= mod;
        dp[now][1] *= dp[x][0];
        dp[now][1] %= mod;
    }
}

int32_t main() {
    fastIO();
    
    int n, u, v;
    cin >> n;
    
    for (int i = 0; i < n-1; ++i) cin >> u >> v, adj[u].eb(v), adj[v].eb(u);
    
    dfs(1, -1);
    
    cout << (dp[1][0] + dp[1][1]) % mod << "\n";
    
    return 0;
}

Measured memory_bytes: 10880
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
    int a = ri();
    int b = ri();
    int c = ri();
    int x = ri();
    int res = 0;
    FROMTO(i,0,a) {
        FROMTO(j,0,b) {
            FROMTO(k,0,c) {
                if (i*500+j*100+k*50 == x) res++;
            }
        }
    }
    cout << res << endl;
 return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; ++i) cin >> d[i];
    sort(d.begin(), d.end());
    cout << unique(d.begin(), d.end()) - d.begin() << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n,a[202020];
ll b[202020];
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	fo(i,0,n){
		cin>>a[i];
		b[a[i]]++;
	}
	ll s=0;
	fo(i,1,n+1)s+=b[i]*(b[i]-1)/2;
	fo(i,0,n)cout<<s-(b[a[i]]-1)<<endl;
	return 0;
}


Measured memory_bytes: 3968
input_line = input().split(" ")
N, K = list(map(int, input_line))
A_i = []
for i in range(K):
	d_i = int(input())
	A_i = A_i + list(map(int, input().split(" ")))

A_i = set(A_i)
print(N - len(A_i))

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

struct process{
  string name;
  long int time;
};

int main(){
  long long int n,q;
  process queue[100000];
  long long int first, last, point;
  long long int now_time;
  bool flag_first_last = true;
  cin >>n >> q;
  first = 0;
  last = n-1;
  for(int i=0; i<n; i++){
    cin >> queue[i].name >> queue[i].time;
  }
  point = first;
  now_time = 0;
  while(flag_first_last&&(first <= last) || !flag_first_last&&(first >= last) ){
    if(queue[point].time > q){
      now_time+=q;
      queue[point].time -= q;
      last++;
      if(last >= 100000){
        last = 0;
        flag_first_last = !flag_first_last;
      }
      queue[last].name = queue[point].name;
      queue[last].time = queue[point].time;
    }else{
      now_time+=queue[point].time;
      cout << queue[point].name << " " << now_time << endl;
    }
    first++;
    if(first >= 100000){
      first = 0;
      flag_first_last = !flag_first_last;
    }
    point++;
    if(point >= 100000){
      point = 0;
    }
  }
  return 0;
}


Measured memory_bytes: 6908
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		a := getNextInt(scanner) - 1
		aa[a] = i
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, aa[i]+1)
	}

	writer.Flush()
}


Measured memory_bytes: 3840
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int x, y;
	cin >> x >> y;
	int g[13] = { 0,1,3,1,2,1,2,1,1,2,1,2,1 };
	cout << (g[x] == g[y] ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han Elmuzaffer Daima
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid (start+end)/2
#define ort (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 100005; 
const lo mod = 1000000007; 

int n,m,cev,b,a[li],k,mpp[505],x;
string s;
vector<int> v;

int main(void){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d",&x);
		mpp[x]++;
		scanf("%d",&x);
		mpp[x]++;
	}
	FOR{
		printf("%d\n",mpp[i]);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define MAX 500005
 #include<iomanip>
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define x first
 #define y second
using namespace std;
int gcd(int a, int b);
  
int power(int x, unsigned int y, unsigned int m)
{
    if (y == 0)
        return 1;
    int p = power(x, y/2, m) % m;
    p = (p * p) % m;
  
    return (y%2 == 0)? p : (x * p) % m;
}
ll modInverse(int a, int m)
{
    int g = gcd(a, m);
   
    {
        // If a and m are relatively prime, then modulo inverse
        // is a^(m-2) mode m
      
             return power(a, m-2, m);
    }
}
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
//void spf(ll num)
//{
//    fore(i,0,num+1)arr[i]=i;
//    for(ll i=2;i<=num;i+=2)
//    {
//        arr[i]=2;
//    }
//    for(ll i=3;i<=num;i+=2)
//    {
//        if(arr[i]==i)
//        for(ll j=i;j<=num;j+=i)
//        {
//           if(arr[j]==j) arr[j]=i;
//        }
//    }
//}
ll a[100006];
set<ll>d;
void sieve()
{
    for(ll i=2;i<=100005;i++)
    {
        if(a[i]==1)continue;
        else
        {
            d.insert(i);
            for(ll j=i;j<=100005;j+=i)
            {
                a[j]=1;
            }
        }
    }
}
 int32_t main()
{
    Need_for_speed(activated);
//    satisfy
//    {}
    ll x;cin>>x;
    sieve();
    auto it = d.lower_bound(x);
    {
        cout<<*it;
    }
    return 0;
    }


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

string s;
bool used[0x100];
bool ok[0x100];

int main(){
  cin>>s;
  if(s.size()<26){
    rep(i,s.size())used[s[i]]=true;
    repl(c,'a','z'+1){
      if(used[c])continue;
      s+=c;
      break;
    }
    cout<<s<<endl;
  }else{
    for(ll i=25;i>=0;i--){
      if(s[i]=='z')continue;
      repl(j,'a','z'+1)ok[j]=true;
      rep(j,i){
        ok[s[j]]=false;
      }
      {
        string res=s.substr(0,i);
        repl(k,s[i]+1,'z'+1)if(ok[k]){
          res+=k;
          break;
        }
        if(res<=s)continue;
        cout<<res<<endl;
        return 0;
      }
    }
    cout<<-1<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;

public class Main {
	static class Path {
		int x, y;
		int w;
		public Path(int y, int x, int w) {
			this.x = x;
			this.y = y;
			this.w = w;
		}
		
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int H = sc.nextInt();
		int W = sc.nextInt();
		int sy = sc.nextInt()-1;
		int sx = sc.nextInt()-1;
		int gy = sc.nextInt()-1;
		int gx = sc.nextInt()-1;
		boolean[][] map = new boolean[H][W];
		for(int i=0; i<H; i++) {
			char[] c = sc.next().toCharArray();
			for(int j=0; j<W; j++)
				map[i][j] = c[j]=='#';
		}
		
		int[][] warp = new int[H][W];
		for(int i=0; i<H; i++)
			Arrays.fill(warp[i], Integer.MAX_VALUE);
		
		LinkedList<Path> list = new LinkedList<>();
		list.add(new Path(sy, sx, 0));
		
		while(!list.isEmpty()) {
			Path cur = list.poll();
			if(warp[cur.y][cur.x] <= cur.w)
				continue;
			for(int dy=-2; dy<=2; dy++) {
				int ny = cur.y+dy;
				if(ny<0 || H<=ny)
					continue;
				for(int dx=-2; dx<=2; dx++) {
					int nx = cur.x+dx;
					if(nx<0 || W<=nx)
						continue;
					if(map[ny][nx])
						continue;
					int d = Math.abs(dy)+Math.abs(dx);
					if(d==0) {
						continue;
					} else if(d==1) {
						list.addFirst(new Path(ny, nx, cur.w));
					} else {
						list.addLast(new Path(ny, nx, cur.w+1));
					}
				}
			}
			warp[cur.y][cur.x] = cur.w;
		}
		
		System.out.println(warp[gy][gx]<Integer.MAX_VALUE ? warp[gy][gx] : -1);
		sc.close();
	}
}


Measured memory_bytes: 75456
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  int N;
  cin >> N;
  vi x(N), y(N), h(N);
  for(int i = 0; i < N; i++){
    cin >> x.at(i) >> y.at(i) >> h.at(i);
  }
  
  for(int i = 0; i <= 100; i++){
    for(int j = 0; j <= 100; j++){
      bool flag = true;
      int H = -1;
      for(int k = 0; k < N; k++){
        if(h.at(k) == 0) continue;
        if(H == -1){
          H = h.at(k) + abs(i - x.at(k)) + abs(j - y.at(k));
          break;
        }
      }
      for(int k = 0; k < N; k++){
        if(h.at(k) == 0){
          if(H > abs(i - x.at(k)) + abs(j - y.at(k))){
            flag = false;
            break;
          }
        }
        else{
          if(H != h.at(k) + abs(i - x.at(k)) + abs(j - y.at(k))){
            flag = false;
            break;
          } 
        }
      }
      if(flag){
        cout << i << ' ' << j << ' ' << H << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("avx,avx2,fma,sse,sse2")
#pragma GCC optimization ("unroll-loops")

#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;

typedef tree<int, null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> new_data;


int main()
{
   int n,m;
   cin>>n>>m;
   int sum=0;
   for(int i=0;i<m;i++)
   {
       int x;
       cin>>x;
       sum+=x;
   }
   if(sum>=n)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    double l;
    cin >> l;
    l /= 3;
    double ans = l * l * l;
    co(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define COUT(x) cout << #x << " = " << (x) << ", "
typedef long long ll;
using namespace std;
static const ll MOD = 1000000007;

int main(){
  double L;
  cin >> L;
  double res = L * L * L / 27.0;
  printf("%.7f\n", res);

}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll a,b,c,d;
    cin>>a>>b>>c>>d;

    if(a==c){
        cout<<0<<endl;
    }else{
        cout<<1<<endl;
    }
    return  0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import os
import math
import itertools

d = {}
d['A'] = 0
d['B'] = 0
d['AB'] = 0
d['O'] = 0

for s in sys.stdin:
    s = s.strip()
    type = s.split(',')[-1]
    d[type] += 1

print(d['A'])
print(d['B'])
print(d['AB'])
print(d['O'])

Measured memory_bytes: 7480
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define PB push_back
#define MP make_pair
#define all(x) x.begin(),x.end()

int N,b[100];
int main(){
	cin >> N;
	for(int i=0; i<N; i++) cin >> b[i];
	
	vector<int> now;
	for(int i=0; i<N; i++) now.PB(b[i]);
	vector<int> ans;
	for(int i=0; i<N; i++){
		for(int j=now.size()-1; j>=0; j--){
			if(now[j] == j+1){
				ans.PB(now[j]);
				now.erase(now.begin()+j);
				break;
			}
			if(j == 0){
				cout << -1 << endl;
				return 0;
			}
		}
	}
	
	reverse(ans.begin(), ans.end());
	for(int i=0; i<N; i++) cout << ans[i] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 1e6 + 5 ; 
char s[N] ; 
int f[N][2] ;
signed main()
{
	scanf("%s", s + 1 ) ;
	int n = strlen( s + 1 ), Ans = 0 ; s[0] = '0' ;
	f[n + 1][0] = 0, f[n + 1][1] = 100 ;
	for( re int i = n; i >= 0; -- i ) {
		int u = s[i] - '0' ; 
		f[i][1] = min( f[i + 1][1] - u - 1, f[i + 1][0] - u ) + 10 ;
		f[i][0] = min( f[i + 1][1] + u + 1, f[i + 1][0] + u ) ;
	}
	cout << f[0][0] << endl ;
	return 0 ;
}


Measured memory_bytes: 16896
for e in iter(input,'0'):
 n=int(e);m,f=[[0]*n for _ in[0]*n],'{:4}'*n
 j=n//2;i=j+1
 m[i][j]=1
 for k in range(2,n*n+1):
  i,j,t=-~i%n,-~j%n,j
  if m[i][j]:i,j=-~i%n,t
  m[i][j]=k
 for r in m:print(f.format(*r))


Measured memory_bytes: 5612
#include <deque>
#include <cstdio>
using namespace std;
typedef long long ll;

int m,num;
deque<int> s1,s2;
deque<int>::iterator it;

ll read() {
	ll x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return x*f;
}

int main() {
	ll n=read()+1;
	for(ll i=1;i<=n;i<<=1)m++;
	for(int i=m-2;~i;i--) {
		s1.push_back(++num),s2.push_back(num);
		if((n>>i)&1)s1.push_front(++num),s2.push_back(num);
	}
	printf("%d\n",(int)(s1.size()+s2.size()));
	for(it=s1.begin();it!=s1.end();it++)
		printf("%d ",(*it));
	for(it=s2.begin();it!=s2.end();it++)
		printf("%d ",(*it));
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      k: usize,
    }
    if n%k == 0 {
        println!("{}", 0);
    } else {
        println!("{}", n%k);
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

/**
 * Created by whiled on 16/10/29.
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        String t = sc.next();

        int count = n;
        for (int i = 0; i < n; i++){
            String tmp = t.substring(0,count);
            if (s.endsWith(tmp)){
                break;
            }else {
                count--;
            }
        }
        System.out.println(s.length() + t.length() - count);
    }
}

Measured memory_bytes: 9808
h,w=gets.split.map(&:to_i)

p [[h,w],[w,h]].map{|t,u|
  ((t/3)..(t/3+2)).map{|i|
    tt=t-i
    [[u*i,u*(tt/2),u*((tt+1)/2)],
     [u*i,(u/2)*tt,((u+1)/2)*tt]].map{|a|
     a.max-a.min
    }.min
  }.min
}.min

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N;
double p[3010];
double dp[3010][3010];


signed main(){
    cin >> N;
    rep(i, 0, N) cin >> p[i];

    dp[0][0] = 1;
    rep(i, 0, N) repe(j, 0, i){
        dp[i+1][j] += (1-p[i])*dp[i][j];
        dp[i+1][j+1] += p[i]*dp[i][j];
    }

    double ans = 0;
    repe(i, N/2+1, N) ans += dp[N][i];

    fcout(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 139904
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <sstream>
using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long

int main()
{
	int c[6] = { 500, 100, 50, 10, 5, 1 };
	while (1)
	{
		int n;
		cin >> n; if (n == 0) return 0;
		n = 1000 - n;
		int cnt = 0;
		for (int i = 0; i < 6; i++)
		{
			while (1)
			{
				if (n >= c[i])
				{
					n -= c[i];
					cnt++;
				}
				else break;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
const int N=1e5+10,M=1e9+7;
int a[N],n,m;
long long b[N];
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int x;
		cin>>x;
		a[x]=1;
	}
	b[0]=1;
	for(int i=1;i<=n;i++){
		if(!a[i-1])	b[i]=(b[i]+b[i-1])%M;
		if(i>=2&&!a[i-2]) b[i]=(b[i]+b[i-2])%M;
	}
	cout<<b[n];
	return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
#include <math.h>
#include <time.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
	int c[100001] = { 0 }, i, n, a, ans = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &a);
		c[a - 1]++;
		c[a]++;
		c[a + 1]++;
	}

	for (i = 0; i < 100000; i++) {
		if (ans < c[i]) {
			ans = c[i];
		}
	}
	printf("%d", ans);
}

Measured memory_bytes: 2120
import numpy as np

N=int(input())
A=np.array(input().split(),dtype=np.int32)

out=A[A%2==0]

flag=False
for i in range(len(out)):
    if(out[i]%3==0 or out[i]%5==0):
        pass
    else:
        flag=True

if(flag):
    print("DENIED")
else:
    print("APPROVED")

Measured memory_bytes: 21408
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
using ll = long long; 
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int n,m,x;
	cin >> n >> m >> x;
	vector<int>c(n);
	vector<vector<int>>a(n,vector<int>(m));
	rep(i,n) {
		cin >> c[i];
		rep(j,m) {
			cin >> a[i][j];
		}
	}
	
	
	int ans = 1000000000;
	for(int bit = 0;bit<(1<<n);bit++) {
		bool exist = true;
		int sum = 0;
		vector<int>b(m);
		for(int i = 0;i<n;i++) {
			
			if(bit & (1<<i)) {
				sum += c[i];
				for(int j = 0;j<m;j++) {
					b[j] += a[i][j];
				}
			}
		}
		rep(k,m) {
			
			if(b[k] < x) {
				exist = false;
				break;
			}	
		}
		
		
		if(!exist) continue;
		ans = min(ans,sum);
	}
	if(ans != 1000000000) cout << ans << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 3636
N,M = map(int,input().split())
inf = float('inf')
D = [[inf]*N for _ in range(N)]
for i in range(N):
    D[i][i] = 0

edges = []
for _ in range(M):
    a,b,c = list(map(int,input().split()))
    a -= 1
    b -= 1
    D[a][b] = c
    D[b][a] = c
    edges.append([a,b,c])

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])
# for i in range(N):
#     print(D[i])
ans = 0
for e in edges:
    used = False
    for s in range(N):
        if D[s][e[0]] + e[2] == D[s][e[1]]:
            used = True
    if not used:
        ans += 1
print(ans)

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

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

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

	int N;
	int cnt = 0;
	char c;
	cin >> N;

	for (int i = 0;i < N;i++){
		cin >> c;
		if(c == 'R') cnt++;
		else cnt--;
	}

	if(cnt > 0) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;

}


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

const int MAX_N = 103;
int N;
int h[MAX_N];

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> h[i];

  int ans = h[N - 1];

  for (int i = 0; i < N - 1; i++) {
    if (h[i] > h[i + 1]) {
      ans += h[i];
      ans -= h[i + 1];
    }
  }
  cout << ans << endl;
}


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<string>s(n);
  vector<ll>t(n);
  rep(i,0,n){
    cin>>s[i]>>t[i];
    buf+=t[i];
  }
  string x;cin>>x;
  rep(i,0,n){
    if(x==s[i]){
      cout<<buf-(res+t[i])<<endl;
      break;
    }
    res+=t[i];
  }
  return 0;
}

Measured memory_bytes: 256
import itertools
a = int(input())
b = list(map(int, input().split()))
c = list(map(int, input().split()))
r = list(itertools.permutations(range(1,a+1)))
k = []
for rr in r:
  k.append(list(rr))
#print(k)
p = k.index(b)
q = k.index(c)
print(max(p-q,q-p))

Measured memory_bytes: 15092
# 入力
N=int(input())

l=[]
for i in range(N):
  l.append(int(input()))

# 押してない：0
# 押した：1
l2=[0]*N

# 1番目は「押した：1」にしておく
l2[0]=1

# 回数カウント
c=0

i=1
while True:
  # 回数をインクリメント
  c+=1

  # 次のボタン番号を取得
  i=l[i-1]

  # 2番目のライトが光る場合は回数を出力して終了
  if i==2:
    print(c)
    exit()

  if l2[i-1]==1:
    # 無限ループ確定で終了
    print(-1)
    exit()
  else:
    # 押した／押してない を更新
    l2[i-1]=1

Measured memory_bytes: 7852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    int n, p;
    cin >> n >> p;
    bool odd = false;
    rep(i, 0, n) {
        int a;
        cin >> a;
        if (a % 2 == 1) {
            odd = true;
            break;
        }
    }
    ll ans = 0;
    if (!odd) {
        if (p == 0) ans = pow(2, n);
        else ans = 0;
    } else ans = pow(2, n - 1);

    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数 __builtin_popcount bitの個数

int main() {
  st S;
  ci(S);
  int a = 0;
  rep(i, 4){
    if(S.at(i) == '+'){
      a++;
    }
    else{
      a--;
    }
  }
  co(a);
}

Measured memory_bytes: 256
//前置き
#pragma region

#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>

using namespace std;

typedef  long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

#define FOR(i, a, n) for(ll i = (ll)(a); i < (ll)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

#pragma endregion

//関数定義
#pragma region 
//偶数 ->　true :: 奇数　-> false
bool EVEN(ll a){
    return a%2-1;
}

//最大公約数
ll gcd(ll a, ll b) {  
    if (!b)  
        return a;  
    return gcd(b, a%b);  
}  

//最小公倍数
ll lcm(ll a, ll b) {  
    return a*b/gcd(a,b);  
} 

#pragma endregion

int main(){
    int a[4], b;
    cin >> b;
    REP(i , 4){
        a[3-i] = b % 10;
        b /= 10;
    }

    int ans;
    REP(i, 8){
        ans = a[0];
        REP(j, 3){
            if(i & (1 << j)) ans -= a[j+1];
            else ans += a[j+1];
        }
        if(ans == 7){
            REP(j ,4){
                cout << a[j];
                if(j < 3){
                    if(i & (1 << j)) cout << "-";
                    else cout << "+";
                }
            }
            cout << "=7" << endl;
            return 0;
        }
    }
 }




Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(void){
	int a,b,c;
	int i = 0,x = 0 ;
	cin >> a >> b >> c;

		for ( i= a;i <= b; i++){
		if( c%i == 0 ){
				
		x++;
		}
	}
	cout << x << endl;
	
	return 0;
} 

Measured memory_bytes: 1160
#include <string>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n; double x[35], y[35], z[35];
double solve(double px, double py, double pz) {
	double ret = 0.0;
	for (int i = 0; i < n; i++) ret = max(ret, (x[i] - px) * (x[i] - px) + (y[i] - py) * (y[i] - py) + (z[i] - pz) * (z[i] - pz));
	return sqrt(ret);
}
double solve1(double px, double py) {
	double l = -1.0e+3, r = 1.0e+3;
	for (int i = 0; i < 70; i++) {
		double m1 = (l * 2.0 + r) / 3.0;
		double m2 = (l + r * 2.0) / 3.0;
		if (solve(px, py, m1) < solve(px, py, m2)) r = m2;
		else l = m1;
	}
	return solve(px, py, l);
}
double solve2(double px) {
	double l = -1.0e+3, r = 1.0e+3;
	for (int i = 0; i < 70; i++) {
		double m1 = (l * 2.0 + r) / 3.0;
		double m2 = (l + r * 2.0) / 3.0;
		if (solve1(px, m1) < solve1(px, m2)) r = m2;
		else l = m1;
	}
	return solve1(px, l);
}
double solve3() {
	double l = -1.0e+3, r = 1.0e+3;
	for (int i = 0; i < 70; i++) {
		double m1 = (l * 2.0 + r) / 3.0;
		double m2 = (l + r * 2.0) / 3.0;
		if (solve2(m1) < solve2(m2)) r = m2;
		else l = m1;
	}
	return solve2(l);
}
int main() {
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i];
		double ret = solve3();
		cout << fixed << setprecision(10) << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 3268