akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    dwacon5th_prelims_a()
}

fun dwacon5th_prelims_a() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toDouble() }

    val average = aList.sum() / n

    var answer = 0
    var minDiff = 999.0
    aList.forEachIndexed { index, l ->
        val diff = Math.abs(average - l)
        if (diff < minDiff) {
            answer = index
            minDiff = diff
        }
    }

    println(answer)
}


Measured memory_bytes: 38260
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (b==0) {
			System.out.println(a);
			return;
		}
		int [] c = new int[b];
		String str = sc.nextLine();
		int min = 100;
		int ans = 0;
		for (int i=0; i<b; i++) {
			c[i]= sc.nextInt();
		}
		int f = 0;
		for (int i=-101; i<201; i++) {
			for (int j=0; j<b; j++) {
				if (c[j]==i) {
					f = 1;
					break;
				}
			}
			if (f == 0) {
				if(Math.abs(i-a) < min) {
					min = Math.abs(i-a);
					ans = i;
				}
			} else {
				f = 0;
			}
		}

		sc.close();
		System.out.println(ans);
	}
}


Measured memory_bytes: 27244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> v=input(m);
  int sum=0;
  rep(i,m){
    sum += v[i];
  }
  if(sum>n){
    cout << -1 << endl;
  }else{
    cout << n-sum << endl;
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int A,B,C;
cin >> A >> B >> C;
if(A==5&&B==5&&C==7) {
  cout << "YES" << endl;
} else if(A==5&&B==7&&C==5) {
  cout << "YES" << endl;
} else if(A==7&&B==5&&C==5) {
  cout << "YES" << endl;
} else {
  cout << "NO" << endl;
}
return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
	int H,W;
	cin>>H>>W;
	char field[110][110];
	
	for(int i=1;i<H+1;i++){
		for(int j=1;j<W+1;j++){
			cin>>field[i][j];
		}
	}

	for(int i=0;i<H+2;i++) field[i][0] = '#';
	for(int i=0;i<H+2;i++) field[i][W+1] = '#';
	for(int i=0;i<W+2;i++) field[0][i] = '#';
	for(int i=0;i<W+2;i++) field[H+1][i] = '#';

	for(int i=0;i<H+2;i++){
		for(int j=0;j<W+2;j++){
			cout<< field[i][j] ;
		}
		cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int _s,a,b;
int solve(int c,int n,int s){
      if(!n) return s==_s;
      if(c>=10) return 0;
      return solve(c+1,n-1,s+c) + solve(c+1,n,s);
}
int main(){while(cin >> a >> _s,a||_s)cout <<solve(0,a,0)<< endl;}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
using ll = long long;

int main(int argc, char const* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    char s[H][W+1];
    for (int i=0; i<H; ++i) {
        cin >> s[i];
    }
    for (int i=0; i<H; ++i) {
        for (int j=0; j<W; ++j) {
            if (s[i][j] == '#') {
                if (i >= 0 && i < H && j-1 >= 0 && j-1 < W && s[i][j-1] == '#') {
                    continue;
                }
                if (i-1 >= 0 && i-1 < H && j >= 0 && j < W && s[i-1][j] == '#') {
                    continue;
                }
                if (i+1 >= 0 && i+1 < H && j >= 0 && j < W && s[i+1][j] == '#') {
                    continue;
                }
                if (i >= 0 && i < H && j+1 >= 0 && j+1 < W && s[i][j+1] == '#') {
                    continue;
                }
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

X = int(readline())

if X <= 599:
    print(8)
elif X <= 799:
    print(7)
elif X <= 999:
    print(6)
elif X <= 1199:
    print(5)
elif X <= 1399:
    print(4)
elif X <= 1599:
    print(3)
elif X <= 1799:
    print(2)
elif X <= 1999:
    print(1)


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

int main() {
    int N,f=0,b=0;
    string S;
    cin >> N >> S;

    rep(i,N)
        if(S.at(i) == '(') {
            f++;
        } else {
            if(f > 0)
                f--;
            else
                b++; 
        }

    rep(i,b)
        cout << '(';
    cout << S;
    rep(i,f)
        cout << ')';
    cout << endl;
}

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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	int ans = 0;
	if (n <= k)
		ans = n * x;
	else
		ans = k * x + (n - k) * y;
		print(ans);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
module app;

import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main()
{
	auto input = parseInput();
	auto result = main2(input);
    writefln("%d", result);
}

int main2(Input input)
{
    int countMax = 0;
    int count = 0;
    auto h = input.h ~ int.max;
    for (int i = 1; i < h.length; i++)
    {
        if (h[i-1] >= h[i])
        {
            count++;
        }
        else
        {
            if (countMax < count)
                countMax = count;
            count = 0;
        }
    }
    return countMax;
}

unittest
{
    Input input = {5, [10,4,8,7,3]};
    auto result = main2(input);
    assert(result == 2);
}
unittest
{
    Input input = {7, [4,4,5,6,6,5,5]};
    auto result = main2(input);
    assert(result == 3);
}
unittest
{
    Input input = {4, [1,2,3,4]};
    auto result = main2(input);
    assert(result == 0);
}

struct Input
{
	uint n;
	int[] h;
}

Input parseInput()
{
	Input input = void;
	input.n = readln().strip().to!uint;
	input.h = readln().strip().split().map!(s => s.to!int).array;
	return input;
}


Measured memory_bytes: 4156
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
using P = pair<int, int>;

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> map0(h);
    for(int i = 0; i < h; i++) cin >> map0[i];

    vector<vector<int>> map1(h, vector<int>(w, 0));
    vector<vector<bool>> isvisit(h, vector<bool>(w, false));
    int whitenum = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(map0[i][j] == '#') isvisit[i][j] = true;
            else whitenum++;
        }
    }

    queue<P> Q;
    Q.push(make_pair(0, 0));
    isvisit[0][0] = true;
    while(!Q.empty()){
        int i = Q.front().first;
        int j = Q.front().second;
        Q.pop();

        for(int ii = -1; ii <= 1; ii += 2){
            if(i+ii >= 0 && i+ii < h && !isvisit[i+ii][j]){
                isvisit[i+ii][j] = true;
                map1[i+ii][j] = map1[i][j]+1;
                Q.push(make_pair(i+ii, j));
            }
        }
        
        for(int jj = -1; jj <= 1; jj += 2){
            if(j+jj >= 0 && j+jj < w && !isvisit[i][j+jj]){
                isvisit[i][j+jj] = true;
                map1[i][j+jj] = map1[i][j]+1;
                Q.push(make_pair(i, j+jj));
            }
        }
    }

    if(isvisit[h-1][w-1]){
        cout << whitenum - map1[h-1][w-1] -1 << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = [2]
x, y = map(int, input().split())
def sarch(j):
    for i in a:
        if j == i:
            return "a"
    for i in b:
        if j == i:
            return "b"
    return "c"
if sarch(x) == sarch(y):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>
#include<tuple>
#include<stack>


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tpl;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 200005

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;

ll cnt[ARRAY_MAX];


int main() {

	ll n;
	cin >> n;
	ll ans = 1;
	for (ll i = 1; i <= n; i++)
	{
		ans *= i;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3088
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import networkx as nx
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**10
mod = 10 ** 9 + 7

H, W = MAP()
a = [list(input()) for _ in range(H)]
G = nx.Graph()
G.add_nodes_from(range(0, H+W+2))

for i in range(H):
    for j in range(W):
        if a[i][j] == "S":
            sy, sx = i, j
            G.add_edge(0, i+1, capacity=INF)
            G.add_edge(0, H+j+1, capacity=INF)
        elif a[i][j] == "T":
            gy, gx = i, j
            G.add_edge(i+1, H+W+1, capacity=INF)
            G.add_edge(H+j+1, H+W+1, capacity=INF)
        elif a[i][j] == "o":
            G.add_edge(i+1, H+j+1, capacity=1)
            G.add_edge(H+j+1, i+1, capacity=1)

if sy == gy or sx == gx:
	print(-1)
	exit()

print(nx.maximum_flow_value(G, 0, H+W+1))


Measured memory_bytes: 63612
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <list>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI  = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

int solve(int a, int b, int c, int d){
    int r1 = a * b;
    int r2 = c * d;
    if(r1 > r2){
        return r1;
    }else{
        return r2;
    }
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << solve(a, b, c, d) << endl;

    return 0;
}


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

main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE    
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout); 
    #endif

    int n;cin>>n;
    ll ans=0;
    for(int a=1;a<=n;a++){
        ans+=n/a;
        if(n%a==0)  ans--;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 3648
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    size, jumps = map(int, input().split())
    array = list(map(int, input().split()))
    dp = [999999999] * size
    dp[0]= 0
    dp[1] = abs(array[0]- array[1])
    for i in range(2,size):
        dp[i] = min(abs(array[i] - array[j]) + dp[j] for j in range(max(0, i - jumps), i))
    print(dp[size-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 13980
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,m,a[1000],b[1000],t;
	string s[1000];
	while(cin>>n>>m,n){
		r(i,n)cin>>s[i]>>a[i]>>b[i];
		while(m--){
			int c=0;
			cin>>t;
			r(i,n){
				if(b[i]>=t&&b[i]-a[i]<t){
					cout<<s[i]<<' '<<a[i]-(b[i]-t)<<endl;
					c++;
				}
			}
			if(!c)cout<<"Unknown"<<endl;
		}
	}
}

Measured memory_bytes: 3104
#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

int main(void) {
	int n;
	vector<string> v;

	while (cin >> n) {
		if (n == 0) {
			break;
		}

		int a = 0, b = 0, t_a = 0, t_b = 0;
		for (int i = 0; i < n; i++) {
			cin >> a >> b;
			if (a > b) {
				t_a += a + b;
			}
			else if(a < b){
				t_b += a + b;
			}
			else {
				t_a += a;
				t_b += b;
			}
		}
		
		stringstream ss;
		ss << t_a << " " << t_b;
		v.push_back(ss.str());
	}

	for (int j = 0; j < v.size(); j++) {
		cout << v[j] << endl;
	}

	return 0;
}

Measured memory_bytes: 3120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node {
    int key;
    Node *prev, *next;
};

Node *nil;
int n;

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

Node *listSearch(int key) {
    Node *cur = nil->next;
    while (cur != nil && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *t) {
    if ( t == nil ) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
}

int main() {
    char moji[20];
    int key;
    
    init();
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%s %d", moji, &key);
        if ( moji[0] == 'i' ) {
            insert(key);
        } else if ( moji[0] == 'd' ) {
            if ( moji[6] == 'F' ) {
                deleteFirst();
            } else if ( moji[6] == 'L' ) {
                deleteLast();
            } else {
                deleteKey(key);
            }
        }
    }
    
    Node *cur = nil->next;
    int i = 0;
    while (cur != nil) {
        if (i) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
        i++;
    }
    free(cur);
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 34472
import numpy as np

s = str(input())
t = str(input())
# a = map(int, input().split())
# b = [int(input()) for i in range(n)]
# c = [list(map(int, input().split())) for i in range(n)]

# s = "hoge"
# t = "hogex"

sub = t[0:len(t) - 1]

check = s == sub
res = "Yes" if check else "No"

print(res)

Measured memory_bytes: 27120
/*input
1 2
*/
 
 
 
#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
#define F first
#define S second  
#define pb push_back  
#define INF 3e18
#ifdef gaviria
#define TRACE
#endif
#ifdef TRACE
#define trace(...) _f(#VA_ARGS, __VA_ARGS_)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< ll, ll > ii;
typedef unordered_set<int> usi;
 


ll n,i,j,k,m;

void solve()
{
cin>>j>>k;

if(k>4*j||k<2*j)
{
    cout<<"No";
}
else {
    for(i=0;i<=j;i++)
    {
        if(i*2+(j-i)*4==k)
        {
            cout<<"Yes";
            return;
        }

    }
    cout<<"No";
}

}



 
 
 
signed main()
{
 
    // inputFile;
    // outputFile;
    fast;
    int T = 1;
 // cin >> T;
ll h=T;
    while(T--){
 
        solve();
        cout<<endl;
 
     
        
        
 
    }
    
    
    return 0;
 
}

Measured memory_bytes: 3628
# coding: utf-8
N = int(input())
S = 'D' + input()


rgb_count = [[0 for i in range(3)] for j in range(N+1)]
for i in range(1, N+1):
    if S[i] == 'R':
        rgb_count[1][0] += 1
    elif S[i] == 'G':
        rgb_count[1][1] += 1
    else:
        rgb_count[1][2] += 1


dict={'R':1, 'G':2, 'B':4}
d = ['', 'B', 'G', 'R']
dic = {'R': [1,2], 'G': [0,2], 'B': [0,1]}
ret = rgb_count[1][0]*rgb_count[1][1]*rgb_count[1][2]
for i in range(2,N):
    ran = min([i-1, N-i])
    if ran < 1: continue
    for k in range(1, ran+1):
        if dict[S[i-k]]+dict[S[i]]+dict[S[i+k]] == 7:
            ret -= 1

print(ret)

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

using namespace std;

enum Action {
  A = 0,
  B,
  C,
};

int v[3][100000];
int dp[3][100000];

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

  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> v[0][i] >> v[1][i] >> v[2][i];
  }
  for (auto&& a : {A, B, C}) {
    dp[a][0] = v[a][0];
  }
  for (int i = 1; i < N; i++) {
    dp[A][i] = max(dp[B][i - 1], dp[C][i - 1]) + v[A][i];
    dp[B][i] = max(dp[A][i - 1], dp[C][i - 1]) + v[B][i];
    dp[C][i] = max(dp[A][i - 1], dp[B][i - 1]) + v[C][i];
  }
  const auto ans = max({dp[A][N - 1], dp[B][N - 1], dp[C][N - 1]});
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5988
#include<stdio.h>

#define N 100000
#define nil -1

struct Node
{
  int le;
  int ri;
  int pa;
};
int deep(int, int);

struct Node tree[N];


void post(int);
void pre(int);
void ino(int);

int D[N];

int main()
{
  int n,i,v,l,r,root;

  scanf("%d",&n);

  for(i=0; i<n; i++) tree[i].pa = nil;

  for(i=0; i<n; i++)
    {
      scanf("%d%d%d",&v,&l,&r);

      tree[v].le=l;
      tree[v].ri=r;
      if(l != nil) tree[l].pa=v;
      if(r != nil) tree[r].pa=v;
    }

  for(i=0; i<n; i++) if(tree[i].pa==nil) root=i;

  for(i=0; i<n; i++)
    {
      if(tree[i].pa==nil) r=i;
    }
  
  printf("Preorder\n");
  pre(root);
  printf("\n");

  printf("Inorder\n");
  ino(root);
  printf("\n");

  printf("Postorder\n");
  post(root);
  printf("\n");

  for(i=0; i<n; i++)
    {
      if(tree[i].pa==nil) r=i;
    }
  

  return 0;
}


void post(int u)
{
  if(u==nil) return;

  post(tree[u].le);
  post(tree[u].ri);
  printf(" %d",u);
}

void pre(int u)
{
  if(u==nil) return;
  printf(" %d",u);
  pre(tree[u].le);
  pre(tree[u].ri);
}

void ino(int u)
{
  if(u==nil) return;
  ino(tree[u].le);
  printf(" %d",u);
  ino(tree[u].ri);
}
    
int deep(int u,int p)
{
  D[u]=p;
  if(tree[u].ri != nil) deep(tree[u].ri,p);
  if(tree[u].le != nil) deep(tree[u].le,p+1);
}



Measured memory_bytes: 2120
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

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

cout << max(0 , c - (a - b));

return 0;
}

Measured memory_bytes: 256
let input = readLine()!.split(separator: " ").map { Int($0)! }
let H = input[0]
let N = input[1]
var A: [Int] = .init(repeating: 0, count: N)
var B: [Int] = .init(repeating: 0, count: N)

for i in 0..<N {
  let tmp = readLine()!.split(separator: " ").map { Int($0)! }
  A[i] = tmp[0]
  B[i] = tmp[1]
}

var dp: [Int] = .init(repeating: Int.max, count: H + 1)
dp[0] = 0

for i in 1...H {
  for j in 0..<A.count {
    let offset = i - A[j] >= 0 ? dp[i - A[j]] : 0
    dp[i] = min(dp[i], B[j] + offset)
  }
}
print(dp[H])

Measured memory_bytes: 8388
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
const int INF = 1e9;
const ll INFll = 1e18;
#define put(n) cout<<(n)<<endl
#define Cout(n) cout<<(n)
#define rep(i,num,N) for(int(i)=(num);(i)<(N);++(i))
#define rrep(i,num,N) for(int (i)=(num);(i)>(N);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define MP make_pair
#define pb(q) push_back(q)
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int X1,Y1,X2,Y2;
    cin>>X1>>Y1>>X2>>Y2;
    int X3 = Y1-Y2+X2;
    int Y3 = X2+Y2-X1;
    int X4 = X1+Y1-Y2;
    int Y4 = X2-X1+Y1;
    cout<<X3<<" "<<Y3<<" "<<X4<<" "<<Y4<<endl;
}

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

int main()
{
    int A,B;
    scanf("%d %d",&A,&B);
    if(A<10&&B<10&&A>0&&B>0)
    {
       printf("%d",A*B);
    }
    else
    {
        printf("-1");
    }
    return 0;
}


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	reverse(a,a+n);
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		if (i%2==0)
		{
			ans+=a[i];
		}
		else
		{
			ans-=a[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
        }
        long ans = 0, sum = 0;
        for (int i = 0; i < n; i++) {
            if(a[i] == 0) {
                ans += sum / 2;
                sum = 0;
            } else {
                sum += a[i];
            }
        }
        ans += sum / 2;
        System.out.println(ans);
    }
}   

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

bool ok(string s){
	for(int i = 0;i < s.length() / 2;i++){
		if(s[i] != s[i + s.length() / 2]) return false;
	}
	return true;
}

int main(){
	string s;
	cin >> s;
	if(s.length() % 2) s = s.substr(0,s.length() - 1);
	else s = s.substr(0,s.length() - 2);
	while(1){
		if(ok(s)){
			cout << s.length() << endl;
			return 0;
		}
		s = s.substr(0,s.length() - 2);
	}
	return 0;
}

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

int main(){
  int N,K = 0;
  cin >> N >> K;
  if(N%2 == 1){
    N = N + 1;
  }
  N = N/2;
  if(N >= K){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

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

int check(const std::vector<int> &h, int i, int K) {
    return h[i+K-1] - h[i];
}

int main() {
    int N, K, temp;
    std::cin >> N >> K;
    
    std::vector<int> h;
    for (int i=0; i<N; ++i) {
        std::cin >> temp;
        h.push_back(temp);
    }
    
    std::sort(h.begin(), h.end());
    
    std::vector<int> diff;
    for (int i=0; i<=N-K; ++i) {
        temp = check(h, i, K);
        diff.push_back(temp);
    }
    
    std::cout << *std::min_element(diff.begin(), diff.end()) << std::endl;
}

Measured memory_bytes: 1400
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10


N = INT()
S = input()

former = S[:N]
latter = S[N:][::-1]

dic_f = defaultdict(int)
dic_l = defaultdict(int)

for x in product([0, 1], repeat=N):
	tmp_red = ""
	tmp_blue = ""
	for i in range(N):
		if x[i]:
			tmp_red += former[i]
		else:
			tmp_blue += former[i]
	dic_f["{},{}".format(tmp_red, tmp_blue)] += 1

for x in product([0, 1], repeat=N):
	tmp_red = ""
	tmp_blue = ""
	for i in range(N):
		if x[i]:
			tmp_red += latter[i]
		else:
			tmp_blue += latter[i]
	dic_l["{},{}".format(tmp_red, tmp_blue)] += 1

ans = 0

for key in dic_f:
	ans += dic_f[key] * dic_l[key]

print(ans)




Measured memory_bytes: 103248
import bisect
N = int(input())
S = [input() for _ in range(N)]
T = input()

S1 = []
S2 = []
for s in S:
    S1.append(s.replace('?', 'z'))
    S2.append(s.replace('?', 'a'))
S1 = sorted(S1)
S2 = sorted(S2)
ans1 = bisect.bisect_left(S1, T)+1
ans2 = bisect.bisect_right(S2, T)+1


print(*range(ans1, ans2+1))


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

#define ll                   long long int
#define MOD                  1000000007
#define fast()               ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define loop(i,a,b)          for(ll i=(ll)a;i<(ll)b;i++)
#define pool(i,a,b)          for(ll i=(ll)a;i>=(ll)b;i--)
#define pb                   push_back
#define vi                   vector<ll>
#define test()               ll t; cin>>t; while(t--)
#define endl                 "\n"
#define param                greater<ll>()
#define ff                   first
#define ss                   second
#define all(v)               v.begin(),v.end()
#define keep_unique(v) sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
#define sor(vec) sort(vec.begin(),vec.end());

using namespace std;

// const int N = 105;
// const int W = 1e5+10;

const ll MAX = 10000000000000;
// const int MOD = 998244353;

ll fast_exp(ll x,ll n){ll ans=1;while(n){if(n&1)ans*=x;n=n>>1;x=x*x;}return ans;}
ll mod_exp(ll x, ll y,ll p){ll res = 1;x = x % p;while(y>0){if(y&1)res = (res*x) % p;y = y>>1;x=(x*x)%p;}return res;}


//  vector < ll > vec(N);

// ll fib[N];




int main()
{

    fast()


    ll t;
    // cin>>t;
    t=1;

    while(t--)
    {
        ll a,b,c,i,n,k,j,d,m,r,w;

        string p,q;

        cin>>p>>q;
        
        n=p.size();
        m=q.size();

      
        
        ll dp[3010][3010];
        
        //   for(i=0;i<=n;i++)
        // {
        //     for(j=0;j<=m;j++)
        //     {
                
        //         dp[i][]

        //     }
        // }
        
        memset(dp, 0 ,sizeof(dp));
        
        string vec;
        

        for(i=0;i<=n;i++)
        {
            for(j=0;j<=m;j++)
            {
                
                if(p[i]==q[j])
                {
                    dp[i+1][j+1]=1+dp[i][j];
                }
                
                else
                {
                    dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
                }
                


            }
        }
        
        
        i=n;j=m;
        
        while(i>0&&j>0)
        {
            if(p[i-1]==q[j-1])
            {
                vec.pb(p[i-1]);
                i--;
                j--;
            }
            else
            {
                if(dp[i-1][j]>=dp[i][j-1])
                i--;
                else
                j--;
            }
        }
        
        reverse(vec.begin(),vec.end());
        cout<<vec<<endl;

        // for(i=0;i<=n;i++)
        // {
        //     for(j=0;j<=sum;j++)
        //     {

        //         cout<<dp[i][j]<<" ";


        //     }
        //     cout<<endl;
        // }








        // string ans=vec[0];

    }




    return 0;
}


Measured memory_bytes: 71040
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n;

		try {
			while ((n = Integer.parseInt(br.readLine())) != 0) {
				String[] input = br.readLine().split("\\s+");
				// 平均を取得
				double ava = Arrays.stream(input).mapToDouble(Double::parseDouble).sum() / n;
				// スクエアの平均値を取得
				double square = Arrays.stream(input).mapToDouble(Double::parseDouble).map(i -> (i - ava) * (i - ava))
						.sum() / n;
				// 回答
				System.out.println(Math.sqrt(square));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}


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

int main()
{
  int n;cin>>n;
  vector<int>  h(n);
  int i;
  for(i=0;i<n;i++)cin>>h.at(i);
  vector<int> cost(n);
  cost.at(0)=0;
  cost.at(1)=abs(h.at(1)-h.at(0));
  for(i=2;i<n;i++)
  {
    cost.at(i)=min(cost.at(i-2)+abs(h.at(i-2)-h.at(i)),cost.at(i-1)+abs(h.at(i-1)-h.at(i)));
  }
  cout<<cost.at(n-1)<<endl;
}


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

using namespace std;

typedef long long ll;

#define rep(i,x) for(int i=1;i<=x;i++)
#define put(ans)    cout << ans << endl;
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main(){
    int k;
    ll ans(0);
    cin >> k;

    rep(i,k){
        rep(j,k){
            rep(m,k){
                ans += gcd(i,gcd(j,m));
            }
        }
    }
    put(ans);

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


ll A,B,C;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C;
	
	ll a=min(B,C);
	ll ret=0;
	ret+=2*a;
	B-=a;
	C-=a;
	a=min(A,C);
	ret+=a;
	C-=a;
	A-=a;
	
	ret+=min(C,1LL);
	ret+=B;
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

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

  int w[100];
  int v[1000];
  for(int i=0; i<N; i++){
    cin >> v[i] >> w[i];
  }

  int DP[N+1][W+1];

  for(int j=0; j<=W; j++)
    DP[0][j] = 0;

  for(int i=1; i<=N; i++)
    for(int j=0; j<=W; j++)
      if(j<w[i-1]){
        DP[i][j] = DP[i-1][j];
      }else{
        if(DP[i-1][j]>DP[i][j-w[i-1]]+v[i-1])
          DP[i][j] = DP[i-1][j];
        else
          DP[i][j] = DP[i][j-w[i-1]]+v[i-1];
        }

  cout << DP[N][W] << endl;

  return 0;
}



Measured memory_bytes: 7020
#include<stdio.h>

int main(){
	int n, x, y;
	int ans[2005] = {0};
	int i, j;

	scanf("%d %d %d", &n, &x, &y);

	for(i=1; i<n; i++){
		for(j=i+1; j<=n; j++){
			if(i <= x){
				if(j <= x){
					ans[j-i]++;
				}else if(j >= x && j < y){
					if(j-x < y-j+1){
						ans[j-i]++;
					}else{
						ans[x-i + y-j+1]++;
					}
				}else{
					ans[j-i-(y-x-1)]++;
				}
			}else if(i > x && i < y){
				if(j >= x && j < y){
					if(j-i < i-x + y-j + 1){
						ans[j-i]++;
					}else{
						ans[i-x + y-j + 1]++;
					}
				}else{
					if(y-i < i-x+1){
						ans[j-i]++;
					}else{
						ans[j-y + i-x+1]++;
					}
				}
			}else{
				ans[j-i]++;
			}

//			printf("%d %d:", i, j);
//			int k;
//			for(k=1; k<n; k++){
//				printf("%d ", ans[k]);
//			}
//			printf("\n");
		}
	}

	for(i=1; i<n; i++){
		printf("%d\n", ans[i]);
	}

	return 0;
}


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

int main() {

	int nums[100];

	int n;

	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> nums[i];

	for (int i = n; i > 0; i--) {
		cout << nums[i - 1];
		if (i - 1 != 0) cout << " ";
	}

	cout << endl;

	return 0;
}


Measured memory_bytes: 3088
using System;

namespace ALDS1_2_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int n = int.Parse(str);
            int[] A = new int[n];

            for (int i = 0; i < n; ++i)
            {
                str = Console.ReadLine();
                A[i] = int.Parse(str);
            }

            int m = 0;
            while (Math.Pow(2, m) < n) 
            {
                m += 1;
            }

            if (m == 0)
            {
                m = 1;
            }

            int[] G = new int[m];
            for (int i = 0; i < m; ++i) 
            {
                G[i] = (int)Math.Pow(2, m - i - 1);
            }


            int cnt = 0;
            sellSort(A, G, n, ref cnt);
            Console.WriteLine("{0}",G.Length);
            Output(G);
            Console.WriteLine("{0}", cnt);
            for(int i=0;i<n;++i)
            {
                Console.WriteLine("{0}", A[i]);
            }
//            Console.ReadLine();
        }

        static private void insertionSort(int[] A, int n, int g, ref int cnt)
        {
            for (int i = g; i < n; ++i)
            {
                int v = A[i];
                int j = i - g;
                while (A[j] > v)
                {
                    A[j + g] = A[j];
                    j = j - g;
                    cnt += 1;
                    if (j < 0)
                    {
                        break;
                    }
                }
                A[j + g] = v;
            }
        }

        static private void sellSort(int[] A,int[] G,int n,ref int cnt)
        {
            for (int i = 0; i < G.Length; ++i)
            {
                insertionSort(A, n, G[i], ref cnt);
            }
        }

        static private void Output(int[] A)
        {
            for (int i = 0; i < A.Length; ++i)
            {
                Console.Write("{0}", A[i]);
                if (i < A.Length - 1)
                {
                    Console.Write(" ");
                }
                else
                {
                    Console.Write("\n");
                }
            }
        }

    }
}

Measured memory_bytes: 20732
/*
      HET PAGHADAR
      DA-IICT
      @HET262
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long double ld;
typedef long long ll;
 
typedef vector<ll> vec;
#define INF LLONG_MAX
 
#define P pair<ll,ll>
#define int long long int
 
#define ff first
#define ss second
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

#define N 100005
#define MOD 1000000007

signed main()
{
      
      FAST;
      
      string s;
      cin>>s;
      
      ll n=s.size();
      
      ll lt[n+2];
      ll gt[n+2];
      
      s='a'+s;
      
      memset(lt,0,sizeof(lt));
      memset(gt,0,sizeof(gt));
      
      for(int i=n;i>=1;i--)
      {
            if(s[i]=='>')
            {
                  gt[i]=1+gt[i+1];
            }
      }
      
      for(int i=2;i<=n+1;i++)
      {
            if(s[i-1]=='<')
            {
                  lt[i]=1+lt[i-1];
            }
      }
      
      ll ans=0;
      
      for(int i=1;i<=n+1;i++)
            ans+=max(lt[i],gt[i]);
            
      cout<<ans<<"\n";
      
      
      
      
}     

Measured memory_bytes: 8624
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpll vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
#define modA(cccc,bbbb ,p) (((cccc+bbbb)%p+p)%p)
#define modS(cccc,bbbb ,p) (((cccc-bbbb)%p+p)%p)
#define modM(cccc,bbbb ,p) ((((cccc%p)*(bbbb%p))%p+p)%p)

long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

// lld fac[500005]; 

// void getfac(lld p)
// {
//     fac[0] = 1; 
//     for (lld i=1 ; i<=500005; i++) 
//         fac[i] = fac[i-1]*i%p; 
// }    

// long long int nCrmodp(lld n, lld r,lld p) 
// { 
//    // Base case 
//    if (r==0) 
//       return 1; 
     
//     return (fac[n]* modInverse(fac[r], p) % p * 
//             modInverse(fac[n-r], p) % p) % p; 
// }

// bool sorter(lld a, lld b)
// {
//     vector<lld> v2;
//     vector<lld> w;
//     // cout<<"A == " <<a<<"  B== "<<b;
//     while(a>=1)
//     {
//         v2.pb(a%10);
//         a/=10;
//     }
//     while(b>=1)
//     {
//         w.pb(b%10);
//         b/=10;
//     }   
       
//     reverse(all(v2));
//     reverse(all(w));
//     lld l1 = v2.size();
//     lld l2 = w.size();
//     lld  l = (l1*l2)/__gcd(l1,l2);
//     // cout<<l1<< " "<<l2<< " "<<l<< " ";
//     for(int i=0;i<l;i++)
//     {
//         if(v2[i%l1]!=w[i%l2])
//         {
//             // cout<< "   "<< (v2[i%l1] > w[i%l2])<<"\n";
//             return v2[i%l1] > w[i%l2];
//         }
//     }
//     // printf("false\n");
//     return false;
// }


lld p1=1e9 + 7,p2=998244353;
lld l,r,mid,ans;
lld n,i,j,k,g,m;
lld x,y,n1,n2,h,z,c;
lld aa=1;
lld ss;


void solve()
{
    string s;
    cin>>s;
    x=0;
    x-=4;
    for(i=0;i<4;i++)
    {
        if(s[i]=='+') x+=2;
    }
    cout<<x;


}
int main()
{

  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    
    // cin>>t;
    // cout<<t;
     // getfac(p1);
    //check the value by which modulo is to be taken
    lld ans=0;
    for(int i=0;i<t;i++)
    {
        // cout<<"Case #"<<i+1<<": ";
        solve();
        // cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3652
from queue import Queue

def calcReachableTileNumByBFSearch(room, start_pos):
    q = Queue()
    q.put(start_pos)

    count = 1
    while not q.empty():
        cur_pos = q.get()
        D0 = [1, 0, -1, 0]
        D1 = [0, -1, 0, 1]
        for d in range(4):
            nc = [0,0]
            nc[0] = cur_pos[0]+D0[d]
            nc[1] = cur_pos[1]+D1[d]
            if room[nc[0]][nc[1]] == '.':
                room[nc[0]][nc[1]] = '*'
                q.put([nc[0],nc[1]])
                count +=1
    return count


def solve(width, height):
    room = [['#' for i in range(width+2)] for j in range(height+2)]
    for i in range(height):
        row = input()
        for j in range(width):
            room[i+1][j+1] = row[j]
            if room[i+1][j+1] == '@':
                start = [i+1,j+1]

    return calcReachableTileNumByBFSearch(room, start)


def main():
    while True:
        width, height = map(int, input().split())
        if width == 0 and height == 0:
            break
        print(solve(width, height))


if __name__ == "__main__":
    main()



Measured memory_bytes: 6848
#include<bits/stdc++.h>
using namespace std;
void dfs(int i,vector<int>adj[],vector<int>&dp){
	//cout << i << endl;
	if(dp[i]!=-1)return;
	dp[i]=0;
	for(int j=0;j<adj[i].size();j++){
	
	dfs(adj[i][j],adj,dp);
	dp[i]=max(dp[i],dp[adj[i][j]]+1);
	}
	}

int main(){
	int n,m;
	cin >> n >> m;
	vector<int>dp(n+1,-1);
	vector<int>adj[n+1];

	for(int i=1;i<=m;i++){
	int a,b;cin >> a >>b;
	adj[a].push_back(b);
	}
    //vector<bool>visited(n+1,false);
    int ans=0;
    for(int i=1;i<=n;i++){
    if(dp[i]==-1){
    dfs(i,adj,dp);
    }
    ans=max(ans,dp[i]);
   // cout << dp[i] << " ";
    }
   // cout <<endl;
    cout << ans;
}

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

using namespace std;

int main(void){
  int dim, x[1000], y[1000];
  scanf("%d", &dim);
  long long int p1 = 0, p2 = 0, p3 = 0, chev = 0;
  for(int i = 0;i < dim;++i){
    scanf("%d", x + i);
  }
  for(int i = 0;i < dim;++i){
    scanf("%d", y + i);
  }
  for(int i = 0;i < dim;++i){
    p1 += abs(x[i] - y[i]);
    p2 += (x[i] - y[i]) * (x[i] - y[i]);
    p3 += abs(x[i] - y[i])*abs(x[i] - y[i])*abs(x[i] - y[i]);
    if(chev < abs(x[i] - y[i])){
      chev = abs(x[i] - y[i]);
    }
  }
  printf("%lf\n%lf\n%lf\n%lf\n", (double) p1, sqrt(p2), cbrt(p3), (double) chev);
}



Measured memory_bytes: 3404
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<int>;
const int maxn = 1<<19, mod = 1e9 + 7;
ll n, m, x, pos[maxn], d[maxn], ans[maxn];
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> x;
	for(int i = 1; i <= n; i++) {
		cin >> d[i];
	}
	ll cur = 0;
	for(int i = n; i; i--) {
		ll tcur = cur;
		while(abs(tcur+1-d[i]) <= cur) {
			tcur++;
		}
		ans[i] = cur = tcur;
	}
	ll ps = x;
	pos[0] = x;
	for(int i = 1; i <= n; i++) {
		ps = min(ps, abs(ps-d[i]));
		pos[i] = ps;
	}
	cin >> m;
	for(int q, i = 0; i < m; i++) {
		cin >> q;
		cout << (pos[q-1] > ans[q+1] ? "YES" : "NO") << '\n';
	}
}


Measured memory_bytes: 14208
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    if(n==1){
        cout<<1<<endl;
        cout<<1<<endl;
    }
    else if(n==2){
        cout<<2<<endl;
        cout<<0<<endl;
        cout<<11<<endl;
    }
    else {
        cout<<n-1<<endl;
        rep(i,n-1){
            cout<<1;
            rep(j,i)cout<<0;
            cout<<1<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int mx=3500;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll N; cin>>N;
	for (ll a=1; a<=mx; a++)
		for (ll b=1; b<=mx; b++) {
			ll p=N*a*b;
			ll q=4*a*b-N*(a+b);
			if(q<=0)
				continue;
			if(p%q)
				continue;
			ll c=p/q;
			if(c>mx)
				continue;
			cout<<a<<" "<<b<<" "<<c<<"\n";
			return 0;
		}
	return 0;
}

Measured memory_bytes: 256
N,M=gets.split.map(&:to_i)
as=M.times.map{gets.split.map(&:to_i)}.map{|x|x[0]*(N+1)+x[1]}
as.sort!{|a,b|(a % (N+1)<=>b % (N+1))}
cnt=0
lb=0
as.each do |i|
	f=i / (N+1)
	s=i % (N+1)
	if lb < f
		cnt+=1
		lb=s-1
	end
end
puts cnt


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

int main(){
  int a,b,c;
  std::cin >> a>>b>>c;
  std::cout << c << '\n';
  std::cout << a << '\n';
  std::cout << b << '\n';


  return 0;
}


Measured memory_bytes: 3576
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;

    ll n,k;
    cin>>n>>k;
    ll x[100010];
    rep(i,n){
        cin>>x[i];
    }
    //ll a=index,b=n-index;
    ll ans=LLINF;
    rep(i,n){
        ll cnt=0;
        if(i+k>n) continue;
        ll a=x[i],b=x[i+k-1];
        if(a<=0&&b>=0){
            cnt=min(abs(a)*2+b,abs(a)+b*2);
        }
        else if(a>=0){
            cnt=b;
        }
        else if(b<=0){
            cnt=abs(a);
        }
        // cout<<cnt<<" ";
        ans=min(ans,cnt);
        // cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024