akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define MOD (1000000007)
#define MODLL (1000000007ll)
typedef pair<ll, int> PLI;

vector<PLI> g[123456];
ll tkhs[123456],aoki[123456],stot[123456],ttos[123456];


priority_queue< PLI, vector<PLI>, greater<PLI> > pq;

int main(void){
	int n,m,s,t,u,v,i,j,now,next;
	ll d,dist,edge,ans;
	PLI tmp;
	fill(tkhs,tkhs+123456,INFLL);
	fill(aoki,aoki+123456,INFLL);
	fill(stot,stot+123456,0ll);
	fill(ttos,ttos+123456,0ll);
	cin >> n >> m;
	cin >> s >> t;
	s--;
	t--;
	tkhs[s] = 0ll;
	aoki[t] = 0ll;
	stot[s] = 1ll;
	ttos[t] = 1ll;
	for(i=0; i<m; i++){
		cin >> u >> v >> d;
		u--;
		v--;
		g[u].push_back(PLI(d,v));
		g[v].push_back(PLI(d,u));
	}
	pq.push(PLI(tkhs[s],s));
	while(!pq.empty()){
		tmp = pq.top();
		pq.pop();
		now = tmp.second;
		dist = tmp.first;
		for(i=(g[now].size()-1); i>=0; i--){
			next = g[now][i].second;
			edge = g[now][i].first;
			if(tkhs[next] >  dist + edge ){
				tkhs[next] = dist + edge;
				pq.push(PLI(tkhs[next],next));
			}
		}
	}
	for(i=0; i<n; i++){
		pq.push(PLI(tkhs[i],i));
	}
	while(!pq.empty()){
		tmp = pq.top();
		pq.pop();
		now = tmp.second;
		dist = tmp.first;
		for(i=(g[now].size()-1); i>=0; i--){
			next = g[now][i].second;
			edge = g[now][i].first;
			if(tkhs[next] == dist + edge){
				stot[next] += stot[now];
				stot[next] %= MOD;
			}
		}
	}
	pq.push(PLI(aoki[t],t));
	while(!pq.empty()){
		tmp = pq.top();
		pq.pop();
		now = tmp.second;
		dist = tmp.first;
		for(i=(g[now].size()-1); i>=0; i--){
			next = g[now][i].second;
			edge = g[now][i].first;
			if(aoki[next] >  dist + edge ){
				aoki[next] = dist + edge;
				pq.push(PLI(aoki[next],next));
			}
		}
	}
	for(i=0; i<n; i++){
		pq.push(PLI(aoki[i],i));
	}
	while(!pq.empty()){
		tmp = pq.top();
		pq.pop();
		now = tmp.second;
		dist = tmp.first;
		for(i=(g[now].size()-1); i>=0; i--){
			next = g[now][i].second;
			edge = g[now][i].first;
			if(aoki[next] == dist + edge){
				ttos[next] += ttos[now];
				ttos[next] %= MODLL;
			}
		}
	}
	ans = stot[t] * ttos[s];
	ans %= MOD;
	for(i=0; i<n; i++){
		if((tkhs[i] == aoki[i]) && ((tkhs[i] + aoki[i]) == tkhs[t])){
			dist = (stot[i] * ttos[i]) % MOD;
			dist *= dist;
			dist %= MODLL;
			ans -= dist;
			ans += MODLL;
			ans %= MODLL;
		}
		for(j=(g[i].size()-1); j>=0; j--){
			next = g[i][j].second;
			edge = g[i][j].first;
			if(tkhs[i] + edge + aoki[next] != tkhs[t]){
				continue;
			}
			if(tkhs[i]*2 < tkhs[t] && tkhs[next]*2 > tkhs[t]){
				dist = (stot[i] * ttos[next]) % MOD;
				dist *= dist;
				dist %= MODLL;
				ans -= dist;
				ans += MODLL;
				ans %= MODLL;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 19576
import math
a,b,x = map(int,input().split())
v = (a**2)*b
amari = v-x
if amari <= v/2:
    nagasa = amari/a/a*2
    ans = math.atan(nagasa/a)
    ans = ans*360/2/math.pi
    print(ans)
else:
    nagasa = x/b/a*2
    ans = math.pi/2 - math.atan(nagasa/b) 
    ans = ans*360/2/math.pi
    print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define pint pair<int,int>
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int i,n;	cin>>n;
	ll a[n],s1=0;
	for(i=0;i<n;i++){
		int t1,t2;	cin>>t1>>t2;
		a[i]=t1+t2;
		s1-=t2;
	}
	sort(a,a+n);
	for(i=n-1;i>=0;i-=2){
		s1+=a[i];
	}
	cout<<s1<<endl;
	return 0;
}

Measured memory_bytes: 1024
/* ex 9_2
   unomi */

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

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;  // 要素を代入
    new->next = *first;  // 新しいノードの指す先にfirstの値を代入
    *first = new;  // firstを新しいノードに設定
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) return 2;  
    elem = tmp->elem;  //要素を取り出し
    *first = tmp->next;  // firstを手前に
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void){
    char input[10*10*10*10*10], trash;
    int i=1, j=0, k=0, cnt=0, prev_cnt=1;

    //最初のノードの指す先を設定
    node *first = NULL;

    // 入力の取得
    scanf("%s",input);

    // 最初の箱をスタックにpush
    push(&first, input[0]);

    while(input[i] != '\0'){
        //printf("step:%d  %c\n",i,input[i]);
        if(first != NULL && first->elem != input[i]){
            trash = pop(&first);
            //puts("###");
            //printf("%c %c\n",input[i],first->elem);
            cnt+=2;
        }
        else push(&first, input[i]);
        i++;
    }

    
    printf("%d\n",cnt);

    return 0;
}



Measured memory_bytes: 4856
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long min = (long) Math.pow(10, 9);
		long max = 0;
		for(int i = 0; i < n; i++) {
			long tmp = sc.nextLong();
			min = Math.min(min, tmp);
			max = Math.max(max, tmp);
		}
		System.out.println(max - min);
	}

}


Measured memory_bytes: 21972
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int A = int.Parse(s[0]);
        int B = int.Parse(s[1]);
        int C = int.Parse(s[2]);
        bool[] remainders = new bool[B + 1];
        for(int i = 1; i <= B; i++)
        {
            int remainder = (A * i) % B;
            if(remainders[remainder])
            {
                Console.WriteLine("NO");
                break;
            }
            else if(remainder == C)
            {
                Console.WriteLine("YES");
                break;
            }
            remainders[remainder] = true;
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<queue>

typedef long long ll;
using namespace std;

#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

const int max_n = 1e5+5;
const ll mod = 1e9 + 7;


int n;
string s;
int main()
{
	IOS;
 
	cin >> n>>s;

	int cnt = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == s[i + 1])
			cnt++;
	}
	cout << n - cnt;
}


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int n,i,k,a[200000],lo,hi,m,cnt,c;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)	scanf("%d",&a[i]);
	hi=a[0];
	for(i=1;i<n;i++)	hi=max(hi,a[i]);
	lo=1;
	while(lo<=hi)	{
		m=(hi+lo)/2;
		cnt=0;
		for(i=0;i<n;i++)	{
			c=a[i]/m;
			if(a[i]%m==0)	c--;
			cnt+=c;
		}
		if(cnt<=k)	hi=m-1;
		else lo=m+1;
	}
	printf("%d\n",lo);
	return 0;
}

Measured memory_bytes: 2472
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
  tmp = input()
  if(tmp == "AC"):
    AC += 1
  if(tmp == "WA"):
    WA += 1
  if(tmp == "TLE"):
    TLE += 1
  if(tmp == "RE"):
    RE += 1
print("AC x "+str(AC))
print("WA x " +str(WA))
print("TLE x " +str(TLE))
print("RE x " +str(RE))

Measured memory_bytes: 8936
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define elif(a) else if(a)
#define INF INT_MAX
#define F first
#define S second
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int a,b;
double g;
ll c,d;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(1){
    scanf("%lf",&g);
    if(g==-1) break;
    if(a>=256){
      printf("NA\n");
      continue;
    }
    a=(int)g;
    g=g-(int)g;
    int cnt=0,p=1;
    c=d=0;

    while(cnt<4){

      g*=2;
      d*=10;
      if((int)g==1){
        d++;
        g-=1;
      }

      cnt++;
    }


    if(g!=1.0 && g!=0.0){
      printf("NA\n");
      continue;
    }

    cnt=0;

    while(a>1){
      if(a%2==1) c+=p;
      cnt++;
      p*=10;
      a/=2;
    }
    if(a==1) c+=p;
    if(cnt>=8){
      printf("NA\n");
    }else{
      printf("%08d.",c);
      printf("%04d\n",d);
    }
  }
  return 0;
}




Measured memory_bytes: 3224
n,T = map(int, raw_input().split(' '))
dishes = [map(int, raw_input().split(' ')) for _ in range(n)]

#print n,T
#print dishes
h = [0 for iii in range(T + 1)]
dishes.sort(key = lambda x:x[0])
m = dishes[0][1] if len(dishes) == 1 else 0
for u,v in dishes:
	m = max(m , h[T-1] + v)
	for tt in range(T - 1, -1, -1):
		if tt - u >= 0:
			h[tt] = max(h[tt], v + h[tt - u])
		
print m


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

signed main() {
	int N;
	cin>>N;
	vector<int> a(N);
	for(int i=0;i<N;i++)cin>>a[i];
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	int ans1=a[0];
	int tmp=ans1/2;
	int dist=100000000000;
	int ans2;
	for(int i=0;i<N;i++){
		if(llabs(a[i]-tmp)<dist){
			ans2=a[i];
			dist=llabs(a[i]-tmp);
		}
	}
	if(N==2 && a[0]==100 && a[1]==0){
		ans1=100;
		ans2=0;
	}
	
	cout<<ans1<<' '<<ans2<<endl;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			int[] as = new int[N];
			int[] bs = new int[N];
			
			for(int i = 0; i < N; i++) {
				as[i] = sc.nextInt();
				bs[i] = sc.nextInt();
			}
			
			for(int i = 0; i < N - 2; i++) {
				if(as[i + 0] == bs[i + 0] && as[i + 1] == bs[i + 1] && as[i + 2] == bs[i + 2]) {
					System.out.println("Yes");
					return;
				}
			}
			
			System.out.println("No");
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 32764
#include <stdio.h>

int main() {
  char ch[250]={0};
  char a[250] ={0};
  int h;
  int i,j,k,l,n,m;


  while(1){
    i=0;
    while(1){
      
      scanf("%c",&ch[i]);
      if(ch[i] == '\n') {    
	break;
      }
      
      i++;
    }
   
    if ( i == 1 && ch[0] == '-' ) break;

    //  printf("%d",i);
    
    scanf("%d",&m);
    
    for(j=0;j<m;j++){
      scanf("%d", &h );
      
      for(k=0;k<i-h;k++) {
	a[k] = ch[h+k];
	//    printf("a[%d] = ch[%d]の%c\n",k ,h+k,ch[h+k]);
      }
      for(k=0;k<h;k++){
	a[i-h+k] = ch[k];
	//   printf("a[%d] = ch[%d]の%c\n",i-h+k,k,ch[k]);
      }
      for(k=0; k<i; k++){
	ch[k] = a[k];
	// printf("ch[%d] = a[%d]の%c\n",k,k,a[k]);
      }
    }
    for(k=0;k<i;k++) {
      printf("%c",ch[k]);
    }
    printf("\n");
      scanf("%c",&ch[0]);
  }
  
  
  return 0;
  
}


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

using namespace std;

const int N = 1e6 + 6, mod = 1e9 + 7;

vector<int> g[N];
vector<long long> * one[N];
vector<long long> * zero[N];
int off[N];
int cnt[N];

int sz[N], n, lv[N];

long long powmod(long long b, long long p) {
  long long r = 1;
  for (; p; p >>= 1, b = b * b % mod)
    if (p & 1) r = r * b % mod;
  return r;
}

inline void getSize(int v) {
  sz[v] = 1;
  cnt[lv[v]]++;
  for (int u : g[v])
    lv[u] = lv[v] + 1, getSize(u), sz[v] += sz[u];
}

long long dua[N];

void dfs(int v) {
  int bg = -1;
  for (int u : g[v]) {
    if (bg == -1 || sz[bg] < sz[u])
      bg = u;
  }
  if (bg == -1) {
    (*one[v])[off[v]]++;
    (*one[v])[off[v]] %= mod;
    return;
  }
  for (int u : g[v]) if (u != bg) {
    off[u] = 0;
    one[u] = new vector<long long>(sz[u], 0LL);
    zero[u] = new vector<long long>(sz[u], 1LL);
    dfs(u);
  }
  one[bg] = one[v];
  zero[bg] = zero[v];
  off[bg] = off[v] + 1;
  dfs(bg);
  vector<long long> & curo = *one[v];
  vector<long long> & curz = *zero[v];
  curo[off[v]]++;
  curo[off[v]] %= mod;
  int til = 0;
  for (int u : g[v]) if (u != bg) {
    til = max(til, sz[u]);
    for (int i = 0, j = off[v] + 1; i < sz[u]; ++i, ++j) {
      long long vo = (1LL * curz[j] * (*one[u])[i] + 1LL * curo[j] * (*zero[u])[i]) % mod;
      long long vz = (1LL * (*zero[u])[i] * curz[j]) % mod;
      dua[i] = (dua[i] * ((*one[u])[i] + (*zero[u])[i]) + (*one[u])[i] * 1LL * (*one[v])[j]) % mod;
      // cerr << u << " " << v << " " << j << " " << vo << " " << vz << endl;
      curo[j] = vo;
      curz[j] = vz;
    }
  }
  for (int i = 0, j = off[v]+1; i < til; ++i, ++j) {
    curz[j] += dua[i];
    curz[j] %= mod;
    dua[i] = 0;
  }
  // cerr << v << endl;
  // for (int i = 0; i < curo.size(); i++) {
  //   cerr << curo[i] << " ";
  // }
  // cerr << endl;
  // cerr << v << endl;
  // for (int i = 0; i < curo.size(); i++) {
  //   cerr << curz[i] << " ";
  // }
  // cerr << endl;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int p;
    scanf("%d", &p);
    g[p].push_back(i);
  }
  n++;
  lv[0] = 0;
  getSize(0);
  int u = 0;
  off[u] = 0;
  one[u] = new vector<long long>(sz[u], 0LL);
  zero[u] = new vector<long long>(sz[u], 1LL);
  dfs(0);
  long long ans = 0;
  for (int i = 0; i < sz[0]; ++i) {
    ans = (ans + powmod(2, n-cnt[i]) * 1LL * (*one[0])[i]) % mod;
    // cerr << (*one[0])[i] << " " << powmod(2, n-cnt[i]) <<  endl;
  }
  if (ans < 0) ans += mod;
  cout << ans << endl;
  return 0;
}

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


int main() {
ll n,k;
cin >> n >> k;
vector<ll> vec(n+1);
for (ll i = 1;i < n+1;i++) {
  cin >> vec.at(i);
}

for (ll i = k+1;i <= n;i++) {
  if (vec.at(i) > vec.at(i-k)) {
    cout << "Yes" << endl;
  } else cout << "No" << endl;
}

return 0;
}



Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define debug(n) cout << "DEBUG1 " << n << "\n";
#define debug2(n, m) cout << "DEBUG2 " << n << ' ' << m << "\n";
#define debug3(n, m, x) cout << "DEBUG3 " << n << ' ' << m << ' ' << x << "\n";
#define ss_def stringstream ss // stringstream, do ss_def(str), then ss >> n (n is int)
#define upzero(n) if (n < 0) n = 0
#pragma GCC optimize("Ofast")
using namespace std;
int main() {
	int l, r, d;
	cin >> l >> r >> d;
	int cnt = 0;
	for (int i = l;i <= r;i++) {
		if (i % d == 0) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3628
#include<stdio.h>

int main(void)
{
	int a,n,sum=0,i=0,c=0;
	int iNumber[10000] = {0};
	char number[10000] = {0};

	while(1)
	{
		scanf("%s",&number[i]);
		if(number[i] == '0')
		{
			break;
		}
		
		for(i = c;number[i] != 0;i++)
		{
			iNumber[i] = number[i] - '0';
		}
		iNumber[i] = 10;
		i++;
		c = i;
	}
	for(a = 0;a < i;a++)
	{
		if(iNumber[a] == 10)
		{
			printf("%d\n",sum);
			sum = 0;
		}
		else
		{
			sum = sum + iNumber[a];
		}
	}
		
	return 0;
}

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

int func( int n )
{
    if ( n > 0 )
        return n + func(n-1);
    else
        return 0;
}

int main( void )
{
    int n;
    cin >> n;
    
    int ans = func(n);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
	int color[8] = {0}; // 色は8色ある

	int n;

	std::cin >> n;

	int tourist = 0;

	for (int i = 0; i < n; i++) {
		int rate;
		std::cin >> rate;

		if (rate >= 3200) {
			tourist++;
		} else {
			color[rate / 400] = 1;
		}
	}

	int ans = 0;

	for (int i = 0; i < 8; i++) {
		ans += color[i];
	}

	if (ans == 0) {
		ans = 1;
		tourist--;
	}

	std::cout << ans << " " << ans + tourist << std::endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));// ??\????????????????????????
            String line;
            String[] listA = null;
            String[] listB = null;
            int count = 0;
            while ((line = br.readLine()) != null) {
            	if(count == 0){
            		count++;
            		listA = line.split(" ", 0);
            	}else{
            		count++;
            		listB = line.split(" ", 0);
            	}
            	if(count == 2){
            		count = 0;
	                blow(listA, listB);
            	}
            } 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    private static void blow(String[] listA, String[] listB) {
    	int hit = 0;
    	int blow = 0;
    	int i = 0;
    	int j = 0;
    	for(i = 0; i < 4; i++){
    		for(j = 0; j < 4; j++){
    			int rdmA = Integer.parseInt(listA[i]);
    			int rdmB = Integer.parseInt(listB[j]);	
    			if(i == j && rdmA == rdmB){
    				hit++;
    				break;
    			}else if(rdmA == rdmB && i != j){
    				blow++;
    			}
    		}
    	}
        System.out.println(hit + " " + blow);
    }
}

Measured memory_bytes: 24148
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int amount = scanner.nextInt();
		int result = amount + (int) Math.pow(amount, 2) + (int) Math.pow(amount, 3);
		System.out.println(result);
	}
}


Measured memory_bytes: 27048
package main

import (
	"fmt"
)

func stringsWithTheSameLength(n int, s, t string) string {
	var ans string
	for i := 0; i < n; i++ {
		ans += string(s[i])
		ans += string(t[i])
	}
	return ans
}

func main() {
	var n int
	var s, t string
	fmt.Scan(&n, &s, &t)
	fmt.Println(stringsWithTheSameLength(n, s, t))
}


Measured memory_bytes: 512
s = list(input())
K = int(input())
for i in range(len(s)-1):
    if K == 0:
        break
    else:
        if s[i] == "a":
            continue
        else:
            if 123-ord(s[i]) <= K:
                K -= 123-ord(s[i])
                s[i] = "a"
K = K %26
if K > 0:
    if ord(s[-1])+K <= 122:
        s[-1] = chr(ord(s[-1])+K)
    else:
        s[-1] = chr(96+((ord(s[-1])+K-122)))

print(*s,sep="")

Measured memory_bytes: 52344
#include<stdio.h>

#define N 100
int a[N][N], b[N][N];

int main(){
    int n, i, j, k;
    
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d %d", &a[i][0], &a[i][1]);
        if(a[i][1] != 0){ 
            for(j = 0; j < a[i][1]; j++){
                scanf("%d", &a[i][2+j]);
            }
        }
    }
    
    for(i = 0; i < n; i++){
        for(j = 0; j < a[i][1]; j++){
            b[i][a[i][j+2]-1] = 1;
        }
      }
    
    
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            if (j != 0){
                printf(" ");
            }
            printf("%d", b[i][j]);
        }
        putchar('\n');
    }
    return 0;
}


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

int main() {
  long long n, i, m = 0, a = 0, r = 0, c = 0, h = 0;
  cin >> n;
  
  string s;
  for(i = 0; i < n; i++){
    cin >> s;
    if(s.at(0) == 'M') m++;
    if(s.at(0) == 'A') a++;
    if(s.at(0) == 'R') r++;
    if(s.at(0) == 'C') c++;
    if(s.at(0) == 'H') h++;
  }
  
  long long ans = 0;
  ans += m * a * r + m * a * c + m * a * h + m * r * c + m * r * h
    + m * c * h + a * r * c + a * r * h + a * c * h + r * c * h;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
//const ll MOD=1000000007;
const ll MOD=998244353;

const int MAX_N=404040;
ll inv[MAX_N+1], fact[MAX_N+1], ifact[MAX_N+1];

ll comb(int n, int k){
  if(n<k) return 0;
  return fact[n]*ifact[k]%MOD*ifact[n-k]%MOD;
}

void prepare(){
  inv[1]=fact[0]=fact[1]=ifact[0]=ifact[1]=1LL;
  for(int i=2;i<=MAX_N;i++){
    inv[i]=inv[MOD%i]*(MOD-MOD/i)%MOD;
    fact[i]=fact[i-1]*i%MOD;
    ifact[i]=ifact[i-1]*inv[i]%MOD;
  }
}

long long modpow(long long a, long long n){
  long long r = 1;
  while (n) {
    r = r * ( (n%2)?a:1 ) %MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return r;
}


int main(){
  int N,M,K; cin>>N>>M>>K;
  prepare();
  ll ans=0;
  for(int i=0;i<=K;i++){
    ans+=comb(N-1,N-1-i)*M%MOD*modpow(M-1,N-i-1)%MOD;
  }
  cout<<ans%MOD<<endl;
  return 0;
}

Measured memory_bytes: 13128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

int main(){
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    sort(a, a+n, greater<ll>());

    ll ans = 0;
    rep(i, n-1){
        ans += a[(i+1)/2];
    }

    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 5144
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <queue>
#include <vector>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
vector<long long>A;
int check(long long k1){
	long long now=1,w=-1,k2=k1;
	int s=0;
	for (int i=1;i<=17;i++){
		if (k1%10!=9&&w==-1) w=now;
		s+=k1%10; k1/=10; now*=10;
	}
	long long k3=k2+w;
	return k2*(s+1)<=k3*s;
}
int main(){
	long long pre=0;
	for (int i=0;i<=15;i++){
		for (int j=0;j<=200;j++)
			if ((i||j)&&check(j*(pre+1)+pre)) A.push_back(j*(pre+1)+pre);
		pre=pre*10+9;
	}
	sort(A.begin(),A.end());
	A.resize(unique(A.begin(),A.end())-A.begin());
	int n; scanf("%d",&n);
	for (int i=0;i<n;i++) cout<<A[i]<<endl;
}

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

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define rep(i,n) for(int (i)=0; (i)<n; ++(i))
#define rep1(i,n) for(int (i)=1; (i)<=n; ++(i))
#define repU(i,bottom,ceiling) for(int (i) = (bottom); (i) <= (ceiling); ++(i))
#define repD(i,ceiling,bottom) for(int (i) = (ceiling); (i) >= (bottom); --(i))
#define pub push_back
#define pob pop_back
#define prf printf
#define scf scanf
#define mkp make_pair
#define fir first
#define sec second
#define clr(a) memset((a),0,sizeof(a))

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;

const vector<pair<int,int>> DIR = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int INF = (int)2e9 + 1e8;
const int MOD = (int)1e9 + 7;

template<typename T,typename U>
inline pair<T,U> operator+(const pair<T,U> & l,const pair<T,U> & r) {
    return {l.fir+r.fir,l.sec+r.sec};
}

template<typename T,typename U>
inline pair<T,U> operator-(const pair<T,U> & l,const pair<T,U> & r) {
    return {l.fir-r.fir,l.sec-r.sec};
}

template<typename T,typename U>
inline pair<T,U> operator*(const pair<T,U> & l,const pair<T,U> & r) {
    return {l.fir*r.fir,l.sec*r.sec};
}

template<typename T> inline T gcd(T a,T b){ if(a % b){ return gcd(b,a % b); }else{ return b; } }

template<typename T> inline T lcm(T a,T b){ return a / gcd(a,b) * b; }

inline int Pow(const long long n,long long m,const int mod = MOD){
	long long res = 1,pow = n;
	while(m) {
		if(m & 1) res = (res * pow) % mod;
		pow = (pow * pow) % mod;
		m >>= 1;
	}
	return res;
}

inline vector<int> Frac(const int range,const int mod = MOD){
	vector<int> frac;
	frac.push_back(1);
	for(int i = 1; i <= range; ++i) frac.push_back((long long)frac.back() * i % mod);
	return frac;
}

inline int Comb(const int n,const int m,const int mod = MOD){
	if(n < m || m < 0) return 0;
	vector<int> frac(Frac(n,mod));
	long long rev = Pow((long long)frac[m] * frac[n-m] % mod,mod-2,mod);
	return rev * frac[n] % mod;
}

template<typename T> inline bool v_find(const vector<T> v,const T obj){
	auto itr = find(v.begin(), v.end(), obj);
	size_t index = distance(v.begin(),itr);
	if (index != v.size()) { return true; }
	return false;
}

template<typename T> inline bool v_erase(vector<T> &v,const T obj){
	auto itr = find(v.begin(), v.end(), obj);
	size_t index = distance(v.begin(),itr);
	if (index != v.size()) {
		v.erase(itr);
		return true;
	}
	return false;
}

template<class T,class U> inline auto LB(const T v,const U in){ return lower_bound(v.begin(),v.end(),in); }

template<class T,class U> inline auto UB(const T v,const U in){ return upper_bound(v.begin(),v.end(),in); }

int n,a[100001],c[100001]={};

inline void solve(){
  int m=0,cur=1;
  c[1]=1;
  while(cur!=2){
    cur=a[cur];
    ++m;
    if(c[cur]){
      cout<<-1;
      return;
    }
    c[cur]=1;
  }
  cout<<m;
  return;
}

inline void input(){
  cin>>n;
  rep(i,n) cin>>a[i+1];
  return;
}

int main(){
  cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	solve();
	return 0;
}


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

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main() {
    int H, W, c[10][10], A[200][200];
    cin >> H >> W;
    REP(i, 10) REP(j, 10) cin >> c[i][j];
    REP(i, H) REP(j, W) cin >> A[i][j];

    REP(k, 10) REP(i, 10) REP(j, 10)
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);

    int ans = 0;
    REP(i, H) REP(j, W) {
        if (A[i][j] != -1)
            ans += c[A[i][j]][1];
    }
    cout << ans << endl;
    return 0;
}

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

cnt = 0
while True:
    flg  = False

    for a in A:
        if (a % 2 != 0):
            flg = True
            break
    else:
        cnt += 1
        A = list(map(lambda x : x // 2, A))
    
    if (flg == True):
        break

print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
long long n, a[405], dp[405][405], sum[405];
long long solve (int l, int r){
	if (l==r) return 0;
	if (dp[l][r]) return dp[l][r];
	dp[l][r]=987654321987654321LL;
	for (int mid=l; mid<r; mid++)
		dp[l][r] = min(dp[l][r], sum[r]-sum[l-1] + solve(l, mid) + solve(mid+1, r));
	return dp[l][r];
}
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n; 
for (int i=1; i<=n; i++) cin >> a[i];
for (int i=1; i<=n; i++) sum[i] = a[i]+sum[i-1];
cout << (solve(1, n)) << endl;
return 0;
}


Measured memory_bytes: 4936
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  cin >> n;
  while(n--) {
    string x;
    cin >> x;
    vector<int> v;
    REP(i,8)
      v.push_back(x[i]-'0');
    sort(ALL(v));
    vector<int> vv;
    do {
      string s;
      REP(i,8) {
        s[i] = (char)(v[i]+'0');
      }
      vv.push_back(atoi(s.c_str()));
    }while(next_permutation(ALL(v)));
    cout << *max_element(ALL(vv))-*min_element(ALL(vv)) << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

void check(vector<ll> &k,vector<string> &pp,ll M)
{
	rep(i,M){
		ll a,b;
		cin>>a>>b;
		if(k.at(a-1)<k.at(b-1)){
			pp.at(a-1)="wrong";
		}
		if(k[a-1]>k[b-1]){
			pp.at(b-1)="wrong";
		}		
		if(k[a-1]==k[b-1]){
			pp.at(a-1)="wrong";
			pp.at(b-1)="wrong";
		}		
	}
}
			


signed main() {
	IOS;
	ll N,M;
	cin>>N>>M;
	vector<ll> K(N);
	vector<string> A(N,"good");
	rep(i,N){
		ll c;
		cin>>c;
		K.at(i)=c;
	}
	check(K,A,M);
	ll ans=0;
	rep(i,N){
		if(A.at(i)=="good"){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
		

}


Measured memory_bytes: 7120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define Rep(i, s, n) for (ll i = (ll)s; i < (ll)n; i++)
typedef long long ll;

bool isPrime(ll n) {
    Rep (i, 2, sqrt(n)+1) {
        if (n % i == 0) return 0;
    }
    return 1;
}

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

    ll n;
    cin >> n;
    ll min = n - 1;
    if (!isPrime(n)) {
        Rep (i, 2, sqrt(n)+1) {
            if (n % i == 0) {
                ll j = n / i;
                ll k = (i-1) + (j-1);
                if (min > k) min = k;
            }
        }
    }
    cout << min << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int x, y;
  cin >> x >> y;

  rep(i, 0, x + 1) {
    int j = x - i;
    if (i * 2 + j * 4 == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;

vector<pair<double, int> > vec;

int sum(ll num){
    int ans = 0;
    while (num){
        ans += num%10;
        num /= 10;
    }

    return ans;
}

double val(ll num){
    return (double)num / (double)sum(num);
}

int main(){
    /*for (int i = 9; i <= 10000000; i+=10){
        double cur = (double)i/(double)sum(i);
        while (!vec.empty() && vec.back().fi > cur)
            vec.pop_back();
        vec.push_back(mp(cur, i));
    }

    int i = 1;
    while (i < vec.size()){
        printf("dif from pre = %d\n", vec[i].se-vec[i-1].se);
        int j = i;
        while (j < vec.size() && vec[j].se-vec[j-1].se == vec[i].se-vec[i-1].se){
            printf("i = %d, val = %f\n", vec[j].se, vec[j].fi);
            j++;
        }
        i = j;
    }
    //for (int i = 0; i < vec.size(); i++)
      //  printf("i = %d, val = %f\n", vec[i].se, vec[i].fi);
    */
    int k;
    scanf("%d", &k);

    ll num = 0, add = 1;
    while (k--){
        if (val(num+add) > val(num+10*add))
            add *= 10;
        num += add;

        printf("%lld\n", num);
    }
    return 0;
}


Measured memory_bytes: 256
/*author : Yashvardhan
Thursday, April 30, 2020
3:31 PM
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}


signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);

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

	time_t t1, t2;
	t1 = clock();
	
	int n;
	cin >> n;

	vi arr(n + 1);
	for(int i = 1; i  <= n; i++){
		cin >> arr[i];
	}

	int rmin = inf;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		rmin = min(rmin, arr[i]);
		if(arr[i] <= rmin) ans++;
	}

	cout << ans << endl;
	

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 
template <class _Tv> inline string join(_Tv &v,string sep=" "){
    ostringstream s;FOREACH(it,v){if(it!=v.begin())s<<sep;s<<*it;};return s.str();
}

typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef complex<D> P;
#define X real()
#define Y imag()
#define EPS (1e-9)
#define DEQ(p1,p2) (abs((p1)-(p2)) < EPS)

#ifdef _DEBUG
template<class _Tv> inline void _prfe(const char *_n,_Tv _c,bool _p=false){
    ITER(_c) _it=_c.begin();
    if(_p){cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif

int num[6];

int main(){
    int n;
    cin >> n;
    double h;
    while(cin >> h){
        int i = (int)((h-160.0)/5.0);
        if(i < 0) i = 0;
        if(i > 5) i = 5;
        num[i]++;
    }
    REP(i,6){
        cout << i+1 << ":";
        REP(j,num[i]) cout << "*";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1232
n,l=map(int,input().split())
a=list(map(int,input().split()))

flag=0
for i in range(n-1):
    if a[i]+a[i+1]>=l:
        flag=1
        break

if flag==0:
    print("Impossible")
else:
    print("Possible")
    if i>0:
        for j in range(1,i+1):
            print(j)
    if i+2<n:
        tmp=[]
        for j in range(i+2,n):
            tmp.append(j)
        for item in tmp[::-1]:
            print(item)
    print(i+1)




Measured memory_bytes: 66892
#include <bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

using namespace std;
typedef long long ll;

int main()
{
    FAST_IO;
    int a,b,c,d,e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a > k)
        cout << ":(" << endl;
    else
        cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a == b && b == c ){
    cout << 1 << endl;
  }
  else if(a == b && b != c && c != a ){
    cout << 2 << endl;
  }
  else if (a != b && b != c && c == a){
    cout << 2 << endl;
  }
  else if(a != b && b == c && c != a){
    cout << 2 << endl;
  }
  else{
    cout << 3 << endl;
  }
}
  

Measured memory_bytes: 3528
import Foundation

func solve(n: Int, aSizes: [Int], bSizes: [Int], cSizes: [Int]) -> Int {

    var bPassed = [Int: Int]()

    return bSizes
        .map {
            if let cases = bPassed[$0] {
                return cases
            }
            let lowerCases = corneredBounds(searchValue: $0, list: aSizes, policy: .lower).left + 1
            let upperCases = n - corneredBounds(searchValue: $0, list: cSizes, policy: .upper).right
            let cases = lowerCases * upperCases
            bPassed[$0] = cases
            return cases
        }
        .reduce(0, +)
}

func corneredBounds(searchValue: Int, list: [Int], policy: Direction) -> (left: Int, right: Int) {

    var openedLeft = -1
    var openedRight = list.count

    while openedRight - openedLeft > 1 {

        let mid = (openedRight + openedLeft) / 2

        func midValueShouldBeInLeftSide() -> Bool {
            policy.midValueShouldBeInLeftSide(at: mid, on: list, with: searchValue)
        }

        if midValueShouldBeInLeftSide() {
            openedLeft = mid
        }
        else {
            openedRight = mid
        }
    }

    return (openedLeft, openedRight)
}

enum Direction {

    case lower
    case upper

    func midValueShouldBeInLeftSide(at index: Int, on list: [Int], with searchValue: Int) -> Bool {

        switch self {
            case .lower: return list[index] <  searchValue ? true : false
            case .upper: return list[index] <= searchValue ? true : false
        }
    }
}

let n = Int(readLine()!)!
var aSizes = readLine()!.split(separator: " ").compactMap{ Int($0) }.sorted()
var bSizes = readLine()!.split(separator: " ").compactMap{ Int($0) }
var cSizes = readLine()!.split(separator: " ").compactMap{ Int($0) }.sorted()

let answer = solve(n: n, aSizes: aSizes, bSizes: bSizes, cSizes: cSizes)
print(answer)


Measured memory_bytes: 27444
#include <stdio.h>
#include <string.h>

int main(void) {
	int l,r;
	char s[200001];
	
	scanf("%s",s);
	
	for (l = 0;s[l] != 'A';l++){
	}
	for (r = strlen(s)-1;s[r] != 'Z';r--){
	}
	
	printf("%d\n",r-l+1);
	
	return 0;
}


Measured memory_bytes: 384
import sys
import copy
import string
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a, b = na()
li = [i for i in range(2, 14)]
li.append(1)
if li.index(a) < li.index(b):
    print("Bob")
elif li.index(a) == li.index(b):
    print('Draw')
else:
    print("Alice")

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REPI(i, init, n) for(ll i = init; i < (ll)(n); i++)

class DP{
public:

  vector<unordered_map<ll, ll>> dp;
  vector<ll> divable;
  map<ll, ll> a;

  DP(ll N, ll K){
    //cout << "init" << endl;

    //vector<vector<ll>> dp1(K + 1, vector<ll>(N + 1));
    vector<unordered_map<ll, ll>> dp1(K + 1);
    //cout << "init" << endl;
    dp = dp1;

    std::vector<ll> v;
    divable = v;
    for (ll i = 1; i * i <= N; i++){
      divable.push_back(i);
      divable.push_back(N/i);
    }
    sort(divable.begin(), divable.end());
    divable.erase(unique(divable.begin(), divable.end()), divable.end());

    map<ll, ll> a1;
    a = a1;
    REP(i, divable.size() - 1){
      a[divable[i + 1]] = divable[i + 1] - divable[i];
    }

    REPI(i, 1, K + 1){
      for(ll j = divable.size() - 1; j >= 0; j--){
        ll dj = divable[j];
        if (i == 1) dp[1][dj] = 1;
        else if (dj == N) dp[i][dj] = dp[i - 1][1];
        else{
          ll tmp = N / dj;
          ll tmp1 = (dp[i - 1][tmp] * a[tmp]) % MOD;
          dp[i][dj] = (dp[i][divable[j + 1]] + tmp1) % MOD;
        }
      }
      //cout << i << endl;
    }

  }



};

int main() {
  ll N, K;
  cin >> N >> K;

  auto table = DP(N, K + 1);
  // REP(i, K + 2) {
  //   REP(j, N + 1) cout << table.dp[i][j] << " ";
  //   cout << endl;
  // }
  cout << table.dp[K+1][1] << endl;

  return 0;
}


Measured memory_bytes: 304532
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
inline int read()
{
    int x=0,t=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-') t=-1,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return x*t;
}
int n;
int pow(int a,int b)
{
	int res=1,t=a;
	while(b)
	{
		if(b&1) res=res*t;
		t=t*t; b>>=1;
	}
	return res;
}
int main ()
{
	n=read();
	printf("%d\n",pow(n,3));
	return 0;
}


Measured memory_bytes: 256
N, K, Q = map(int, input().split())
A = [0] * Q
B = [K-Q] * (N+1)
for i in range(Q):
  A[i] = int(input())
  B[A[i]] += 1
for i in range(1, N+1):
  if B[i] <= 0:
    print('No')
  else:
    print('Yes')

Measured memory_bytes: 10416
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };

template<typename T, typename U> istream & operator>>(istream & s, pair<T, U> & p) { return (s >> p.FI >> p.SE); }
template<typename T, typename U> ostream & operator<<(ostream & s, pair<T, U> const & p) { return (s << p.FI << " " << p.SE); }

int main() {
	IN(int, n);
	vector<vector<int>> g(n);
	vector<pair<int, int>> edge;
	inc(i, n - 1) {
		IN(int, a, b);
		a--; b--;
		g[a].PB(b);
		g[b].PB(a);
		edge.EB(a, b);
	}
	
	pair<int, LL> ans = { n + 1, 0 };
	inc(x, 2 * n - 1) {
		vector<int> c;
		if(x < n) { c.PB(x); } else {
			c.PB(edge[x - n].FI);
			c.PB(edge[x - n].SE);
		}
		
		LL leaf = SI(c);
		vector<int> c2;
		vector<bool> vis(n, false);
		RF(v, c) { vis[v] = true; }
		int d = 0;
		until(c.empty()) {
			d++;
			int ma = 1;
			RF(v, c) {
				int cnt = 0;
				RF(e, g[v]) {
					if(vis[e]) { continue; }
					vis[e] = true;
					c2.PB(e);
					cnt++;
				}
				setmax(ma, cnt);
			}
			leaf *= ma;
			c = c2;
			c2.clear();
		}
		setmin(ans, make_pair(d, leaf));
	}
	OUT(ans);
}


Measured memory_bytes: 256
import scala.util.control.Breaks

object Main{
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val y = sc.nextInt

    var flag = true
    val b = new Breaks
    b.breakable {
      for (i <- 0 to n) {
        for (j <- 0 to (n - i)) {
          if (i * 10000 + j * 5000 + (n - i - j) * 1000 == y) {
            println(s"$i $j ${n - i - j}")
            flag = false
            b.break
          }
        }
      }
    }
    if (flag)
      println("-1 -1 -1")
  }
}

Measured memory_bytes: 27308
#include <stdio.h>
 
int main(void)
{
 
  int a, b, r, num;

  scanf("%d %d", &a,&b);

 

  if(a<b){
    num = a;
    a = b;
    b = num;
  }
 

  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 

  printf("%d\n", b);
 
  return 0;
}


Measured memory_bytes: 2104
import java.util.ArrayList;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String searchWord = sc.next().toLowerCase();
        ArrayList<String> stringArray = new ArrayList<String>();
        String target = "";
        while(true){
            target = sc.next();
            if(target.equals("END_OF_TEXT")) break;
            stringArray.add(target.toLowerCase());
        }
        int count = 0;
        for(String str: stringArray){
            if(str.equals(searchWord)){
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26212
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+1, INF = 1e9+1;

int n, k, h[N], dp[N];
int main() {
  cin >> n >> k;
  for(int i = 0; i < n; i++) cin >> h[i];
  for(int i = 1; i < n; i++) {
    dp[i] = INF;
    for(int j = max(i-k, 0); j < i; j++) dp[i] = min(dp[j] + abs(h[i] - h[j]), dp[i]);
  }
  cout << dp[n-1];
}

Measured memory_bytes: 1024