akhauriyash/Code-Regression huggingface dataset:
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////


///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
	int n;
	cin >> n;
	int B[100005];
	B[0] = INF;
	B[n] = INF;
	LL suma = 0;
	
	for(int i = 1; i <= n-1; i++){
		cin >> B[i];
	}
	
	for(int i = 1; i <= n; i++){
		suma += min(B[i], B[i-1]);
	}
	
	cout << suma << endl;
	
	
	
	

	
	
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 256
use proconio::*;
use std::cmp::max;
use std::collections::BinaryHeap;

#[fastout]
fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };

    let mut lasts = [-1; 26];
    let mut t = vec![26; d];
    let depth = 21;
    for i in 0..d {
        let mut max_score = -10000000;
        for j in 0..26 {
            let tmp = search(i, j, &c, &s, &mut lasts, depth, d, 0, 6);
            if tmp > max_score {
                max_score = tmp;
                t[i] = j;
            }
        }
        lasts[t[i]] = i as i64;
    }

    for &a in &t {
        println!("{}", a + 1);
    }
}

fn calc_score(i: usize, j: usize, c: &Vec<i64>, s: &Vec<Vec<i64>>, lasts: &mut [i64; 26]) -> i64 {
    let mut res = s[i][j];
    let tmp = lasts[j];
    lasts[j] = i as i64;

    for j in 0..26 {
        let i = i as i64;
        let last = lasts[j];
        res -= c[j] * (i - last);
    }

    lasts[j] = tmp;
    res
}

fn search(
    i: usize,
    t: usize,
    c: &Vec<i64>,
    s: &Vec<Vec<i64>>,
    lasts: &mut [i64; 26],
    depth: usize,
    d: usize,
    cscore: i64,
    l: usize,
) -> i64 {
    if depth == 0 || i == d - 1 {
        return calc_score(i, t, &c, &s, lasts) + cscore;
    }

    let l = max(1, l - 1);
    let mut max_score = -1000000;
    let tmp_last = lasts[t];
    lasts[t] = i as i64;
    let tmp_score = calc_score(i, t, &c, &s, lasts);
    let mut cands = BinaryHeap::new();
    cands.reserve(26);
    for j in 0..26 {
        let tmp_score = calc_score(i + 1, j, &c, &s, lasts);
        cands.push((tmp_score, j));
    }
    let w = if l > 1 { 2 } else { 1 };
    for &(_, j) in cands.iter().take(w) {
        let tmp = search(i + 1, j, &c, &s, lasts, depth - 1, d, cscore + tmp_score, l);

        if tmp > max_score {
            max_score = tmp;
        }
    }

    lasts[t] = tmp_last;
    max_score + cscore
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int H, W, D, A;
int Q, L, R;
int px[90001], py[90001];
int d[90001];

int main() {
   cin >> H >> W >> D;
   rep (i, H) {
      rep (j, W) {
         cin >> A;
         px[A] = i, py[A] = j;
      }
   }

   for (int i = D+1; i <= H*W; i++) {
      d[i] = d[i-D] + abs(px[i] - px[i-D]) + abs(py[i] - py[i-D]);
   }

   cin >> Q;
   while (Q--) {
      cin >> L >> R;
      cout << d[R] - d[L] << endl;
   }

}

Measured memory_bytes: 2176
# 169A
# A * Bを整数として出力

# 1.入力をプログラムで扱えるように受け取る
a, b = map(int, input().split())
# print(a, b)

# 2.受け取った入力値を使って、適切に処理（計算）すること
answer = a * b

# 3.計算した結果を出力すること
print(answer)

Measured memory_bytes: 9084
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    w = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    sw=sum(w)
    ss=0
    ans=1000000
    for i in range(N):
        ss+=w[i]
        ans=min(ans,abs(ss-(sw-ss)))

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 77556
#include <cstdio>
#include <functional>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	vector<pair<int,int> > dat;
	dat.reserve(n);
	for (int i = 0; i < n;i ++) {
		int a,b;
		scanf("%d%d",&a,&b);
		dat.push_back(make_pair(b,a));
	}
	sort(dat.begin(), dat.end());
	vector<int> maxheap, minheap;
	long long cursum = 0;
	maxheap.reserve(n);
	minheap.reserve(n);
	int ans = 0;
	for (int i = n-1; i >= 0; i--) {
		int a = dat[i].second;
		int b = dat[i].first;
		long long limit = b * (long long) maxheap.size() + b - a;
		while(!minheap.empty() && cursum + minheap[0] <= limit + b) {
			cursum += minheap[0];
			limit += b;
			maxheap.push_back(minheap[0]);
			push_heap(maxheap.begin(), maxheap.end());
			pop_heap(minheap.begin(), minheap.end(), greater<int>());
			minheap.pop_back();
		}
		while(cursum > limit && !maxheap.empty()) {
			cursum -= maxheap[0];
			limit -= b;
			minheap.push_back(maxheap[0]);
			push_heap(minheap.begin(), minheap.end(),greater<int>());
			pop_heap(maxheap.begin(), maxheap.end());
			maxheap.pop_back();
		}
		if (cursum <= limit)
			ans = max(ans, (int)maxheap.size() + 1);
		if (!minheap.empty() && ans >= maxheap.size() + i + (b-1)*(long long)i / minheap[0] + 2)
			break;
		if (i && cursum + a <= dat[i-1].first * (long long)(maxheap.size() + 2) - a) {
			cursum += a;
			maxheap.push_back(a);
			push_heap(maxheap.begin(), maxheap.end());
		} else {
			minheap.push_back(a);
			push_heap(minheap.begin(), minheap.end(), greater<int>());
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4512
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0

for _ in range(N):
    x = input()
    if x == 'AC':
        ac += 1
    elif x == 'WA':
        wa += 1
    elif x == 'TLE':
        tle += 1
    else:
        re += 1

print(f'AC x {ac}')
print(f'WA x {wa}')
print(f'TLE x {tle}')
print(f'RE x {re}')


Measured memory_bytes: 9064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll> 
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;cin>>n>>m;
  print(n*(n-1)/2+m*(m-1)/2);
  return 0;
}

Measured memory_bytes: 256
/* basic header */
#include <bits/stdc++.h>
/* define */
#define ll long long
#define dou double
#define pb emplace_back
#define mp make_pair
#define sot(a,b) sort(a+1,a+1+b)
#define rep1(i,a,b) for(int i=a;i<=b;++i)
#define rep0(i,a,b) for(int i=a;i<b;++i)
#define eps 1e-8
#define int_inf 0x3f3f3f3f
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lson (curpos<<1)
#define rson (curpos<<1|1)
/* namespace */
using namespace std;
/* header end */

ll n;

int main() {
    scanf("%lld", &n);
    printf("%lld\n", (1ll + (n - 1)) * (n - 1) / 2);
    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dp[100010];
vector<vector<int>> Graph;
int dfs(int i){
    if(dp[i] != -1) return dp[i];
    int f = 0;
    for(auto k : Graph[i]){
        f = max(f,dfs(k) + 1);
    }
    return dp[i] = f;
}
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    Graph.assign(n,vector<int>());

    for(int i = 0; i < m; i++){
        int x,y;
        scanf("%d%d",&x,&y);
        Graph[x - 1].emplace_back(y - 1);
    }
    for(int i = 0; i < n; i++){
        dp[i] = - 1;
    }

    int ans = 0;
    for(int i = 0; i < n; i++)
    ans = max(ans,dfs(i));
    printf("%d\n",ans);
}

Measured memory_bytes: 7680
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
typedef long long ll;

using namespace std;



int main() {
    int a;
    cin>>a;
    int ans = a + a*a + a*a*a;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3632
class Dice:
    def __init__(self, face_vals):
        self.faces = dict(zip(['top', 'front', 'right',
                               'left', 'back', 'bottom'], face_vals.split()))

    def roll(self, direction):
        if direction == 'N':
            self.faces['top'], self.faces['front'], self.faces['bottom'], \
            self.faces['back'] = self.faces['front'], self.faces['bottom'], \
            self.faces['back'], self.faces['top']
        elif direction == 'S':
            self.faces['top'], self.faces['front'], self.faces['bottom'], \
            self.faces['back'] = self.faces['back'], self.faces['top'], \
            self.faces['front'], self.faces['bottom']
        elif direction == 'E':
            self.faces['top'], self.faces['right'], self.faces['bottom'], \
            self.faces['left'] = self.faces['left'], self.faces['top'], \
            self.faces['right'], self.faces['bottom']
        else:
            self.faces['top'], self.faces['right'], self.faces['bottom'], \
            self.faces['left'] = self.faces['right'], self.faces['bottom'], \
            self.faces['left'], self.faces['top']

    def _revolve(self, direction):
        if direction == 'R':
            self.faces['front'], self.faces['left'], self.faces['back'], \
            self.faces['right'] = self.faces['right'], self.faces['front'], \
            self.faces['left'], self.faces['back']
        else:
            self.faces['front'], self.faces['left'], self.faces['back'], \
            self.faces['right'] = self.faces['left'], self.faces['back'], \
            self.faces['right'], self.faces['front']
            
    def show_right_face(self, top, front):
        if front == self.faces['back']:
            if top == self.faces['top']:
                self._revolve('R')
                self._revolve('R')
            else:
                self.roll('S')
                self.roll('S')
        elif front == self.faces['top']:
            self.roll('S')
        elif front == self.faces['right']:
            self._revolve('R')
        elif front == self.faces['left']:
            self._revolve('L')
        elif front == self.faces['bottom']:
            self.roll('N')
        if top == self.faces['bottom']:
            self.roll('E')
            self.roll('E')
        elif top == self.faces['right']:
            self.roll('W')
        elif top == self.faces['left']:
            self.roll('E')
        print(self.faces['right'])


import sys

face_vals = sys.stdin.readline()

dice = Dice(face_vals)

n = int(sys.stdin.readline())

for i in range(n):
    top, front = sys.stdin.readline().split()
    dice.show_right_face(top, front)

Measured memory_bytes: 7848
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer n;
  for(n=nil->next; n!=nil; n=n->next){
    if(key==n->key)return n;
  }
  return NULL;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer n;
  if(nil->next==nil)return;
  deleteNode(nil->prev);
}

void delete(int key){
  NodePointer n;
  if(listSearch(key)==NULL)return;
  else n = listSearch(key); 
  deleteNode(n);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  x->prev = nil;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ) {scanf("%d", &key); insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	scanf("%d", &key);
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



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

using namespace std;

int main()
{	
	long long N;
	long long A,B;
	cin>>N>>A>>B;
	long long x,y;
	if(A<B) x=A,y=B;
	else x=B,y=A;
	if((x-y)%2==0) cout<<(y-x)/2;
	else cout<<min(min(y-1,N-x),min(x+(y-x)/2,(N-y+1)+(y-x-1)/2));
	return 0;
} 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp28 {
    class Program {
        static void Main(string[] args) {
            string N = Console.ReadLine();

            if (N[0] == N[2]) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
           
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
const int inf = 1e9;

int main(){
    int n;
    cin >> n;
    map<string, vector<int> > cd;
    for(int i=0; i<n; i++){
        string color;
        int density;
        cin >> color >> density;
        cd[color].push_back(density);
    }
    for(auto &psv: cd){
        sort(psv.second.begin(), psv.second.end());
    }

    int currd = 0;
    int m;
    cin >> m;
    for(int i=0; i<m; i++){
        string color;
        cin >> color;
        if(cd.count(color) == 0){
            currd = inf;
            break;
        }
        auto &vec = cd[color];
        auto itr = upper_bound(vec.begin(), vec.end(), currd);
        if(itr == vec.end()){
            currd = inf;
            break;
        }
        currd = *itr;
    }
    if(currd != inf){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 21892
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;

const int MAD = 80*(80+80);
int dp[80+1][80+1][MAD];

int main() {
  int H, W;
  cin >> H >> W;
  int A[H][W];
  int B[H][W];
  rep(i,H)rep(j,W) cin >> A[i][j];
  rep(i,H)rep(j,W) cin >> B[i][j];

  dp[0][0][abs(A[0][0] - B[0][0])] = 1;
  rep(i,H)rep(j,W) {
    rep(k,MAD) {
      if (dp[i][j][k] == 1) {
        if (i+1 < H) {
          int d = abs(A[i+1][j] - B[i+1][j]);
          dp[i+1][j][k+d] = 1;
          dp[i+1][j][abs(k-d)] = 1;
        }
        if (j+1 < W) {
          int d = abs(A[i][j+1] - B[i][j+1]);
          dp[i][j+1][k+d] = 1;
          dp[i][j+1][abs(k-d)] = 1;
        }
      }
    }
  }

  int ans;
  rep(i,MAD) {
    if (dp[H-1][W-1][i] == 1) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 324352
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <numeric>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>

intmax_t constexpr mod = 1e9+7;

int main() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);

  std::vector<intmax_t> S(N), T(M);
  for (auto& si: S) scanf("%jd", &si);
  for (auto& ti: T) scanf("%jd", &ti);

  std::vector<std::vector<intmax_t>> dp(N+1, std::vector<intmax_t>(M+1));

  for (size_t j = 0; j <= M; ++j) dp[0][j] = 1;

  for (size_t i = 1; i <= N; ++i) {
    for (size_t j = 1; j <= M; ++j) {
      if (S[i-1] != T[j-1]) continue;
      dp[i][j] = dp[i-1][j-1];
    }
    for (size_t j = 1; j <= M; ++j)
      (dp[i][j] += dp[i][j-1]) %= mod;
    for (size_t j = 0; j <= M; ++j)
      (dp[i][j] += dp[i-1][j]) %= mod;
  }

  // for (size_t i = 0; i <= N; ++i)
  //   for (size_t j = 0; j <= M; ++j)
  //     fprintf(stderr, "%jd%c", dp[i][j], j<M? ' ':'\n');

  printf("%jd\n", dp[N][M]);
}


Measured memory_bytes: 31616
import itertools
N,M,Q = map(int, input().split())
L = [list(map(int, input().split())) for i in range(Q)]
ans = 0
for A in itertools.combinations_with_replacement([i for i in range(1,M+1)],N):
    pre_ans = 0
    for i in range(Q):
        a,b,c,d = L[i]
        if A[b-1] - A[a-1] == c:
            pre_ans += d
        ans = max(ans,pre_ans)
print(ans)

Measured memory_bytes: 9200
fun main(args: Array<String>) {
    var result :String = "No"

    var input = readLine()!!
    val inputN = if (Regex(pattern = "^[0-9]+$").containsMatchIn(input)) input.toInt() else 0
    input = readLine()!!
    val inputS = if (Regex(pattern = "^[a-z]+$").containsMatchIn(input)) input else ""

    if( inputN >= 1 && inputN <= 100 && inputN == inputS.length){
        val firstHalf = inputS.substring(0..(inputN / 2 - 1))
        val secondHalf = inputS.substring((inputN / 2)..(inputN - 1))
        if(firstHalf == secondHalf){
            result = "Yes"
        }
    }
    println(result)
}

Measured memory_bytes: 36512
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long X, Y, Z;
  cin >> X >> Y >> Z;

  cout << (X-Z) / (Y+Z) << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

#define FOR(i,a,b)  for(int i = a; i < b; ++i)
#define FORR(i,a,b) for(int i = a; i <= b; ++i)
//#define LOCAL_DEFINE
using namespace std;

#define maxn 1234
double dist[maxn];
map<string, int>mp;
struct Edge {
    int src, dest;
    double weight;
};

struct Graph {
    int V, E;
    struct Edge* edge;
};

struct Graph* createGraph(int V, int E){
    struct Graph* graph = new Graph;
    graph->V = V;
    graph->E = E;
    graph->edge = new Edge[E];
    return graph;
};

bool flag;

bool BellmanFord(Graph* graph, int src){
    for (int i = 0; i <= graph->V - 1; ++i) {
        for (int j = 0; j < graph->E; ++j) {
            if(dist[graph->edge[j].src] * graph->edge[j].weight > dist[graph->edge[j].dest])
            dist[graph->edge[j].dest] = dist[graph->edge[j].src] * graph->edge[j].weight;
        }
    }
    for (int j = 0; j < graph->E; ++j) {
        if(dist[graph->edge[j].src] * graph->edge[j].weight > dist[graph->edge[j].dest])
            //cout << "exist negative weight cycle" <<endl;
            return true;
    }
    return false;
}

char uppper(char c){
    if(c >= 'a' && c <= 'z')return c - 'a' + 'A';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //cin.precision(10);
    //cout << fixed;g

#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif
    string a, b;
    cin>>a>>b;
    if(a.size() > b.size()){cout<<"GREATER"<<endl; return 0;}
    else if(a.size() < b.size()){cout<<"LESS"<<endl; return 0;}
    else {
        int i = 0;
        for (int i = 0; i < a.size(); ++i) {
            if (a[i] > b[i]){cout<<"GREATER"<<endl; return 0;}
            else if (a[i] < b[i]){cout<<"LESS"<<endl; return 0;}
        }
    }
    cout << "EQUAL"<<endl;
    return 0;
}

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

constexpr int MAX_N = 100;
constexpr int MAX_W = 1e5;

long long dp[MAX_N+1][MAX_W+1];
int w[MAX_N], v[MAX_N];
int N, W;

long long rec(int i, int j) {
  if (dp[i][j] >= 0)
    return dp[i][j];

  long long res;

  if (i == N)
    res = 0;
  else if (j < w[i])
    res = rec(i+1, j);
  else {
    res = max(rec(i+1, j), rec(i+1, j - w[i]) + v[i]);
  }

  return dp[i][j] = res;
}


int main() {
  fill_n(dp[0], (MAX_N+1)*(MAX_W+1), -1);
  cin >> N >> W;
  for (int i{}; i < N; ++i) {
    cin >> w[i] >> v[i];
  }

  cout << rec(0, W) << endl;
  return 0;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
#define ll long long int
#define inf 1000000000000
#define mod 998244353
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tc(t) int t; cin >> t; while (t--)
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define ps(x,y)   fixed<<setprecision(y)<<x
using namespace std;

struct segtree {

	vector<ll> sums;
	int size;
	void init(int n) {

		size = 1;
		while (size < n)size *= 2;
		sums.assign(2 * size, 0ll);
	}
	void set(int i, int v, int x, int lx, int rx)
	{
		if (rx - lx == 1) {

			sums[x] = v;
			return;
		}
		int m = (lx + rx) / 2;
		if (i < m) {

			set(i, v, 2 * x + 1, lx, m);
		}
		else {
			set(i, v, 2 * x + 2, m, rx);
		}
		sums[x] = sums[2 * x + 1] + sums[2 * x + 2];
	}

	void set(int i, int v) {

		set(i, v, 0, 0, size);
	}

	ll sum(int l, int r, int x, int lx, int rx) {

		if (lx >= r || l >= rx)return 0;
		if (lx >= l && rx <= r )return sums[x];

		int m = (lx + rx) / 2;
		ll s1 = sum(l, r, 2 * x + 1, lx, m);
		ll s2 = sum(l, r, 2 * x + 2, m, rx);

		return (s1 + s2);

	}

	ll sum(int l, int r) {

		return sum(l, r, 0, 0, size);
	}


};

void solve()
{
	int n, k;
	cin >> n >> k;
	segtree st;
	st.init(n + 10);
	vector<pair<int, int>>vec;
	vector<ll>dp(n + 1, 0);
	for (int i = 0; i < k; i++) {

		int l, r;
		cin >> l >> r;
		vec.push_back({l, r});
	}
	st.set(n, 1);
	dp[n] = 1;
	for (int i = n - 1; i >= 1; i--) {

		ll res = 0;
		for (int j = 0; j < (int)vec.size(); j++) {

			int l, r;
			l = vec[j].fi + i;
			r = vec[j].se + i;
			ll temp = st.sum(l, r + 1);
			res += temp;
			res = (res + mod) % mod;
		}
		dp[i] = res;
		st.set(i, res);
	}
	cout << dp[1] << endl;

}
int main()
{
	IOS
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	solve();
	return 0;
}

Measured memory_bytes: 9024
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

const int MOD = 1e9 + 7;

const int N = 5000001;
long long fact[N];
long long invfact[N];
long long inv[N];
void init() {
        fact[0] = fact[1] = 1;
        for (int i = 2; i < N; i ++) fact[i] = fact[i - 1] * i % MOD;
        inv[1] = 1;
        for (int i = 2; i < N; i ++) inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
        invfact[0] = invfact[1] = 1;
        for (int i = 2; i < N; i ++) invfact[i] = invfact[i - 1] * inv[i] % MOD;
}
long long C(long long n, long long r) {
        if (n < 0 || r < 0 || n < r) return 0;
        return fact[n] * invfact[n - r] % MOD * invfact[r] % MOD;
}

int main() {
        init();
        int n, a, b, c, d;
        scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
        int N = 1010;
        vector<vector<long long>> dp(N, vector<long long> (N));
        dp[1][0] = 1;
        for (int i = 1; i <= b; i ++) {
                for (int j = 0; j <= n; j ++) {
                        (dp[i + 1][j] += dp[i][j]) %= MOD;
                        if (a > i) continue;
                        int rest = n - j;
                        long long coef = 1LL;
                        for (int k = 1; k <= d; k ++) {
                                if (j + k * i > n) break;
                                (coef *= C(rest, i)) %= MOD;
                                rest -= i;
                                if (k >= c) {
                                        long long coef2 = coef * invfact[k] % MOD;
                                        (dp[i + 1][j + k * i] += dp[i][j] * coef2 % MOD) %= MOD;
                                }
                        }
                }
        }
        printf("%lld\n", dp[b + 1][n]);
        return 0;
}



Measured memory_bytes: 125440
#include<bits/stdc++.h>
using namespace std;
#define M 3005
#define mo 1000000007
#define ll long long
ll ksm(ll a,int k) {
    ll s=1;
    while(k)
	{
	    if(k&1) s=1ll*s*a%mo;
	    a=1ll*a*a%mo;
	    k>>=1;
	}
    return s;
}
ll inv=ksm(2,mo-2);
int n,m;
ll a[M],ans;
ll p[M][M],p2[M][M],g[M][M],g2[M][M];
void pre() {
    for(int i=1;i<=n;i++)
	for(int j=i+1;j<=n;j++) p[i][j]=a[i]>a[j],p2[i][j]=a[i]==a[j];
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i];
    pre();
    for(int i=1,x,y;i<=m;i++)
	{
	    cin>>x>>y;
	    if(x>y) swap(x,y);
	    for(int j=1;j<x;j++)
		{
		    g[j][x]=1ll*inv*(p[j][y]+p[j][x])%mo,g2[j][x]=1ll*inv*(p2[j][x]+p2[j][y])%mo;
		    g[j][y]=1ll*inv*(p[j][y]+p[j][x])%mo,g2[j][y]=1ll*inv*(p2[j][y]+p2[j][x])%mo;
		}
	    for(int j=x+1;j<y;j++)
		{
		    g[x][j]=1ll*inv*(p[x][j]+(1-p[j][y]-p2[j][y])%mo+mo)%mo,g2[x][j]=1ll*inv*(p2[x][j]+p2[j][y])%mo;
		    g[j][y]=1ll*inv*(p[j][y]+(1-p[x][j]-p2[x][j])%mo+mo)%mo,g2[j][y]=1ll*inv*(p2[j][y]+p2[x][j])%mo;
		}
	    for(int j=y+1;j<=n;j++)
		{
		    g[x][j]=1ll*inv*(p[x][j]+p[y][j])%mo,g2[x][j]=1ll*inv*(p2[x][j]+p2[y][j])%mo;
		    g[y][j]=1ll*inv*(p[y][j]+p[x][j])%mo,g2[y][j]=1ll*inv*(p2[y][j]+p2[x][j])%mo;
		}
	    p[x][y]=1ll*inv*(1-p2[x][y]+mo)%mo;
	    for(int j=1;j<x;j++)
		{
		    p[j][x]=g[j][x],p[j][y]=g[j][y];
		    p2[j][x]=g2[j][x],p2[j][y]=g2[j][y];
		}
	    for(int j=x+1;j<y;j++)
		{
		    p[x][j]=g[x][j],p[j][y]=g[j][y];
		    p2[x][j]=g2[x][j],p2[j][y]=g2[j][y];
		}
	    for(int j=y+1;j<=n;j++)
		{
		    p[x][j]=g[x][j],p[y][j]=g[y][j];
		    p2[x][j]=g2[x][j],p2[y][j]=g2[y][j];
		}
	}
    for(int i=1;i<=n;i++)
	for(int j=i+1;j<=n;j++) ans=(ans+p[i][j])%mo;
    ans=1ll*ans*ksm(2,m)%mo;
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 281088
import datetime

while 1:
    c = 0
    a,b = map(int,input().split())
    if a == 0:
        break

    if b > a:
        a,b = b,a

    while b != 0:
        a = a % b
        a, b = b, a
        c += 1
    print(a,c)



Measured memory_bytes: 6036
main :: IO ()
main = do
    [ a, b, c, x, y ] <- map ( read :: String -> Int) . words <$> getLine
    let
        prices = [ a, b, c ]
        choices = [ [ na, nb, nc ] |
                        nc <- [0, 2 * x, 2 * y],
                        na <- [0, x, (2 * x - nc + 1) `div` 2],
                        nb <- [0, y, (2 * y - nc + 1) `div` 2],
                        na >= 0,
                        nb >= 0,
                        nc >= 0,
                        2 * na + nc >= 2 * x,
                        2 * nb + nc >= 2 * y]
        result = minimum $ map ( sum . zipWith (*) prices ) choices
    print result


Measured memory_bytes: 508
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j;
  int A[N+1];
  int key;
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  //  trace(A, n);
  
    for(i =1; i<=n ;i++) {
    key = A[i];
    j=i-1;
    
    while (j >= 0 && A[j] > key) {    
    A[j+1] = A[j];
        j--;
    A[j+1] = key;
     }
    trace(A,n);
    }  
   

  return 0;
}

Measured memory_bytes: 608
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n, m; cin >> n >> m;
    if (n >= m) {
        cout << 0 << endl;
    } else {
        vector<ll> x(m);
        REP(i, m) {
            cin >> x[i];
        }
        sort(ALL(x));
        vector<ll> d;
        for (int i=0; i<x.size(); i++) {
            d.push_back(x[i] - x[i-1]);
        }
        sort(d.begin(), d.end(), greater<ll>());
        ll res = x.back() - x[0];
        for (int i=0; i<min((ll)d.size(), n-1); i++) {
            res -= d[i];
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 4984
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

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

  vector<ll> a(M);
  rep(i,M) cin>>a[i];

  ll sum = 0;
  rep(i,M) sum+= a[i];

  if(N>=sum) cout<<N-sum<<endl;
  else cout<<-1<<endl;


}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
  ll L, R;
  ll const MOD = 2019;
  cin >> L >> R;
  if(R-L >= MOD) {
    cout << "0" << endl;
    return 0;
  }
  ll ans = MOD;
  for(ll i=L; i<= R-1; i++){
    for(ll j=i+1; j<= R; j++){
      ans = min(ans, (i%MOD*j%MOD)%MOD);
    }
  }
  cout << ans << endl;
  return 0;
}

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

memo = {}

for i in range(1, N+1):
    memo[i] = A[i-1]

memo = sorted(memo.items(), key=lambda x:x[1])
# print(memo)
ans = []
for student, order in memo:
    ans.append(str(student))

print(" ".join(ans))


Measured memory_bytes: 25916
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        _n: usize,
        s: chars
    }
    let mut open = 0;
    let mut close = 0;
    for &c in &s {
        if c == '(' {
            open += 1;
        } else if open > 0 {
            open -= 1;
        }
    }
    for &c in s.iter().rev() {
        if c == ')' {
            close += 1;
        } else if close > 0 {
            close -= 1;
        }
    }
    print!("{}", std::iter::repeat('(').take(close).collect::<String>());
    print!("{}", s.iter().cloned().collect::<String>());
    println!("{}", std::iter::repeat(')').take(open).collect::<String>());
}


Measured memory_bytes: 4352
n,k = map(int,input().split())
p = list(map(int,input().split()))
kitai = []
for i in p:
  kitai.append((i+1)/2)
list=[kitai[0]]
for i in range(1,k):
  list.append(kitai[i]+list[i-1])
for j in range(k,n):
  list.append(list[j-1]+kitai[j]-kitai[j-k])
print(max(list))

Measured memory_bytes: 25060
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int data[1001][2];
int dp[1001][1001];
int n,w;

int solve(){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=w;j++){
			if(j >= data[i][1]){
				dp[i][j] = max(dp[i-1][j],dp[i-1][j-data[i][1]]+data[i][0]);
			}else{
				dp[i][j] =dp[i-1][j];
			}
		}
	}
	return dp[n][w];
}

int solve2(){
	for(int i=0;i<=w;i++){
		if(dp[n][w] == dp[n][i]){
			return i;
		}
	}
	return w;
}

int main(){
	int casecount = 0;
	while(true){
		casecount++;
		cin>>w;
		if(w == 0){
			break;
		}
		memset(dp,0,sizeof(dp));

		cin >> n;
		for(int i=1;i<=n;i++){
			scanf("%d,%d",&data[i][0],&data[i][1]);
		}
		
		cout << "Case " << casecount << ":" << endl;
		cout << solve() << endl;
		cout << solve2() << endl;
	}
}

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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset ((a), v, sizeof (a))

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ii> vii;

string S;

int main () {
	cin >> S;
	for (int i = 0; i < S.length() - 1; ++i) {
		if (S[i] == 'A' && S[i + 1] == 'C') {
			printf ("Yes\n");
			return 0;
		}
	}
	printf ("No\n");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int k = sc.nextInt() - 1;
			String s = sc.next();

			char[] cs = s.toCharArray();
			cs[k] = Character.toLowerCase(cs[k]);
			System.out.println(new String(cs));
		}
	}
}


Measured memory_bytes: 22868
#include<iostream>
 using namespace std;
 int main(){ int a,b,c; 
while(cin >> a >> b >> c && a!=-1||b!=-1||c!=-1){ 
if(a==-1||b==-1)cout<<"F"<<endl; 
else if(a+b>=80)cout<<"A"<<endl; 
else if(a+b>=65)cout<<"B"<<endl; 
else if((a+b>=50)||(a+b>=30&&c>=50))cout<<"C"<<endl;
 else if(a+b>=30)cout<<"D"<<endl; else cout << "F" << endl;
 } 
} 


Measured memory_bytes: 3072
#include <stdio.h>
//#include <math.h>
using namespace std;

int log10(int n) {
	int keta = 0;
	do{
		n /= 10;
		keta++;
	} while (n > 0);
	return keta;
}

int main() {
	const int MAX_N = 20;
	int N;
	int table[MAX_N][MAX_N];

	while (1) {
		for (int i = 0;i < MAX_N;i++) {
			for (int j = 0;j < MAX_N;j++) {
				table[i][j] = 0;
			}
		}
		scanf("%d", &N);
		if (!N)break;
		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				scanf("%d", &table[i][j]);
			}
		}

		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				table[i][N] += table[i][j];
				table[N][j] += table[i][j];
				table[N][N] += table[i][j];
			}
		}

		for (int i = 0;i <= N;i++) {
			for (int j = 0;j <= N;j++) {
				for (int k = 0;k < 5-log10(table[i][j]);k++) {
					printf(" ");
				}
				printf("%d", table[i][j]);
			}
			printf("\n");
		}
	}

	return 0;
}

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

const int MAX = 1001001;

struct Node {
    int parent, left, right;
};

Node T[MAX];
vector<int> D(MAX, -1);

void setDepth(int u, int p){
    D[u] = p;
    if(T[u].right != -1){
        setDepth(T[u].right, p);
    }
    if(T[u].left != -1){
        setDepth(T[u].left, p+1);
    }
}

void printChildren(int u){
    int c = T[u].left;
    while(c != -1){
        cout << c;
        c = T[c].right;
        if(c != -1){
            cout << ", ";
        }
    }
}

int main() {
    int n; cin >> n;
    int b;

    rep(i,n){
        T[i].parent = T[i].left = T[i].right = -1;
    }

    rep(i,n){
        int id; cin >> id;
        int k; cin >> k;
        rep(j, k){
            int ch; cin >> ch;
            T[ch].parent = id;
            if(j == 0){
                T[id].left = ch;
            } else {
                T[b].right = ch;
            }
            b = ch;
        }
    }

    int r;
    rep(i, n){
        if(T[i].parent == -1){
            r = i;
            break;
        }
    }
    setDepth(r, 0);

    rep(i,n){
        cout << "node " << i << ": parent = " << T[i].parent << ", depth = " << D[i] << ", ";
        if(T[i].parent == -1){
            cout << "root";
        } else if(T[i].left == -1) {
            cout << "leaf";
        } else {
            cout << "internal node";
        }
        cout << ", [";
        printChildren(i);
        cout << "]" << endl;
    }
}


Measured memory_bytes: 10884
//...Bismillahir Rahmanir Rahim...
// Code by    Asad Bin Saber

#include <bits/stdc++.h>

using namespace std;

// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

// constants...
const double PI = acos(-1);
const int MOD = 1e9+7; // 998244353;
const int MXS = 2e5+5;
const int MXI = 1e9+5;
const ll MXL = 1e15+5;
const int INF = 1e9+5;

// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

// chess moves...
// int dx[] = {+0, +0, -1, +1}; ///Up-down, Left-Right
// int dy[] = {+1, -1, +0, +0};
// int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
// int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1};
// int dx[] = {-2, -2, -1, -1,  1,  1,  2,  2}; ///Knight's Move
// int dy[] = {-1,  1, -2,  2, -2,  2, -1,  1};

// structs...
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

// functions...
ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll lcm(ll a, ll b)
{
    return (a/gcd(a, b)*b);
}
ll comb(ll a, ll b)
{
    ll x = max(a-b, b), ans=1;

    for(ll K=a, L=1; K>=x+1; K--, L++){
        ans *= K;
        ans /= L;
    }

    return ans;
}


void task()
{
	// Code here...
	
	int n, k, x;
	bool mark[10], ok=0;
	memset(mark, 0, sizeof mark);
	
	cin >> n >> k;
	
	while(k--){
		cin >> x;
		mark[x] = 1;
	}
	
	for(int K=n; ; K++){
		ok = 1;
		
		x = K;
		while(x){
			if(mark[x%10]){
				ok = 0;
				break;
			}
			x /= 10;
		}
		
		if(ok){
			cout << K << "\n";
			return;
		}
	}
}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	
	task();

    return 0;
}



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

int main() {
    string s, t;
    cin>>s>>t;
    int n = s.size(), m = t.size();
    vector<vector<int>> dp(n + 1, vector<int> (m + 1, 0));
    vector<vector<int>> p(n + 1, vector<int> (m + 1, -1));
    for(int i=0; i<n; i++) {
        for(int j=0; j<m; j++) {
            if(s[i] == t[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
                p[i+1][j+1] = 0;
            }
            else if(dp[i+1][j] > dp[i][j+1]){
                dp[i+1][j+1] = dp[i+1][j];
                p[i+1][j+1] = 1;
            }
            else {
                dp[i+1][j+1] = dp[i][j+1];
                p[i+1][j+1] = 2;
            }
        }
    }
    string ans = "";
    for(int i=n, j=m; i>0 && j>0;) {
        if(p[i][j] == 0) {
            ans += s[i-1];
            i--, j--;
        }
        else if(p[i][j] == 1) j--;
        else i--;
    }
    reverse(ans.begin(), ans.end());
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 70912
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int main(void){
    string s;
    cin >> s;
    bool flag = s[0] == s[1] && s[1] == s[2];
    if (flag) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <stack>
#include <queue>
#include <cstring>
#include <iterator>

#define FOR(n) for(int i=0;i<(n);++i)
#define FOR_R(it,cont) for(auto it=rbegin(cont);it!=rend(cont);++it)
#define FOR_F(it,cont) for(auto it=begin(cont);it!=end(cont);++it)
#define ALL(cont) begin(cont), end(cont)
#define LB(b,e,v) lower_bound(b,e,v)
#define UB(b,e,v) upper_bound(b,e,v)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define MODDING(a,b) (a) = AS_MOD(a,b)

using namespace std;
typedef pair<int,int> P;
typedef pair<P, P> PP;
typedef long long ll;
int N;
int X[1010];
vector<int> children[1010];
bool dp[1010][5010];
int maxID=10000000;
// possible minimum sum of the other color
int solveDp(int curPos) {
  vector<P> temp;
  for(int child:children[curPos]) {
    temp.push_back(P(solveDp(child), X[child]));
  }
  int maxW = X[curPos];
  for(int i=0;i<=temp.size();++i) {
    for(int j=0;j<=maxW;++j) {
      dp[i][j]=false;
    }
  }
  dp[0][0]=true;
  for(int j=0;j<temp.size();++j) {
    for(int i=0;i<=maxW;++i) {
      P p=temp[j];
      if (dp[j][i]) {
        if (i+p.first<=maxW) {
          dp[j+1][i+p.first]=true;
        }
        if (i+p.second<=maxW) {
          dp[j+1][i+p.second]=true;
        }
      }
    }
  }
  int allsum=0;
  for(P p:temp) {
    allsum+=p.first+p.second;
  }
  int res=-1;
  for(int i=0;i<=maxW;++i) {
    if(dp[temp.size()][i]) {
      res = i;
    }
  }
  if (res == -1) {
    return maxID;
  }
  return allsum - res;
}
int main() {
  scanf("%d",&N);
  FOR(N-1) {
    int p;
    scanf("%d", &p);
    children[p-1].push_back(i+1);
  }

  FOR(N) {
    int x;
    scanf("%d", &x);
    X[i]=x;
  }
  if (solveDp(0)>=maxID) {
    printf("IMPOSSIBLE\n");
  } else {
    printf("POSSIBLE\n");
  }

  return 0;
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9,mod=1e9+7;
typedef long long ll;
int read() {
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
main() {
	int n=read(),b=read();
	if((n+b)%2==0)
		printf("%d",(n+b)/2);
		else puts("IMPOSSIBLE");
}


Measured memory_bytes: 256