akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val h = sc.nextInt()
    val w = sc.nextInt()
    val d = sc.nextInt()
    val t = mutableListOf<Triple<Int, Int, Int>>()
    val a = (1..h).map { i ->
        (1..w).map { j ->
            val x = sc.nextInt()
            t.add(Triple(x, i, j))
            x
        }
    }
    t.sortBy { it.first }

    val sum = Array(h * w) { 0L }
    for (from in t) {
        val fromValue = from.first
        val fromI = from.second
        val fromJ = from.third

        val toValue = fromValue + d
        if (toValue <= h * w) {
            val to = t[toValue - 1]
            val toI = to.second
            val toJ = to.third
            sum[toValue - 1] = sum[fromValue - 1] + Math.abs(fromI - toI) + Math.abs(fromJ - toJ)
        }
    }

    val q = sc.nextInt()
    repeat(q) {
        val l = sc.nextInt() - 1
        val r = sc.nextInt() - 1
        println(sum[r] - sum[l])
    }
}


Measured memory_bytes: 119916
#include<bits/stdc++.h>
using namespace std;
#define fast                         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int                          long long int
#define double                       long double
#define ff                           first
#define ss                           second
#define pb                           push_back
#define eb                           emplace_back
#define all(x)                       (x).begin(), (x).end()
#define sz(x)                        ((int)(x).size())
#define len(x)                       ((int)(x).length())
#define pii                          pair<int,int>
#define vi                            vector<int>
#define vd                           vector<double>
#define vs                            vector<string>
#define mp                          map<int,int>

#define ump                         unordered_map<int,int>

#define lb                            lower_bound
#define ub                            upper_bound
#define nx                            cout<<"\n";
#define inf                           9223372036854775807
#define PI                            3.14159265

const int MOD = 1e9 + 7;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a * b / gcd(a, b); }
inline int add(int a, int b) {    return ((a % MOD) + (b % MOD)) % MOD;}

inline int multi(int a, int b) {   return ((a % MOD) * (b % MOD)) % MOD;}

inline int sub(int a, int b) {       a %= MOD; b %= MOD; a -= b; if (a < 0) a += MOD; return a;}

inline int power(int a, int b) {       a %= MOD; int res = 1; while (b > 0) {if (b & 1) {res = multi(res, a);} a = multi(a, a); b >>= 1;}  return res;}

bool isPrime(int  x) {      if (x <= 4 || x % 2 == 0 || x % 3 == 0) {return x == 2 || x == 3;} for (int i = 5; i * i <= x; i += 6) {if (x % i == 0 || x % (i + 2) == 0) { return 0;}} return 1;}

int solve(int i, int n, int h[], int dp[])
{
  if (i > n)return INT_MAX;
  if (dp[i] != -1)return dp[i];
  if (i == n)return 0;

  return dp[i] = min(solve(i + 1, n, h, dp) + abs(h[i] - h[i + 1]), solve(i + 2, n, h, dp) + abs(h[i] - h[i + 2]));
}
int32_t main()
{
  fast ;


  int n; cin >> n;
  int h[n + 5];
  for (int i = 0; i < n; i++)cin >> h[i];
  h[n] = INT_MAX;
  int dp[n];
  memset(dp, -1, sizeof(dp));

  cout << solve(0, n - 1, h, dp) << endl;


}



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

int main()
{
	string s;

	while (getline(cin, s)) {
		for (int i = 0; i < 26; i++) {
			for (int j = 0; j < s.size(); j++) {
				if (s[j] >= 'a' && s[j] < 'z')
					s[j]++;
				else if (s[j] == 'z')
					s[j] = 'a';
			}

			if (s.find("the") != std::string::npos)
				break;
			if (s.find("this") != std::string::npos)
				break;
			if (s.find("that ") != std::string::npos)
				break;
		}

		cout << s << endl;
	}

	return 0;
}


Measured memory_bytes: 3020
import math
from itertools import product


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def sums(a, N):
    ans = ((N//a)*((N//a)+1)//2)*a
    return ans


def solve():
    K = read_int()
    return sum(math.gcd(math.gcd(a, b), c)
               for a, b, c in product(range(1, K+1), range(1, K+1), range(1, K+1)))


if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 9016
S = list(input())
mae = []
ato = []
rev = False
Q = int(input())
for i in range(Q):
    A = list(input().rstrip().split(" "))
    if int(A[0]) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        if (rev and int(A[1]) == 2 or not rev and int(A[1]) == 1):
            mae.append(A[2])
        else:
            ato.append(A[2])
if rev:
    ato.reverse()
    S.reverse()
    print("".join(ato) + "".join(S) + "".join(mae))
else:
    mae.reverse()
    print("".join(mae) + "".join(S) + "".join(ato))

Measured memory_bytes: 6432
// AOJ 0387 Taxi
// 2018.3.20 bal4u

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

// 高速数値入出力
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()   // 非負整数の入力
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}


// 優先度付きキュー（最大値）
#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)
#define QSIZE 300010
int que[QSIZE + 5];
int qsize;

void max_heapify(int i)
{
	int l, r, max;
	int qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l] > que[i]) max = l; else max = i;
	if (r < qsize && que[r] > que[max]) max = r;
	if (max != i) {
		qt = que[i], que[i] = que[max], que[max] = qt;
		max_heapify(max);
	}
}

void deq()
{
	que[0] = que[--qsize];
	max_heapify(0);
}

void enq(int c)
{
	int i, max;
	int qt;

	i = qsize++;
	que[i] = c;
	while (i > 0 && que[max = PARENT(i)] < que[i]) {
		qt = que[i]; que[i] = que[max], que[max] = qt;
		i = max;
	}
}


// 本問題関連
int c[300010];
int top[300010], sz[300010]; int N;

int main()
{
	int i, k, M;
	unsigned ans;

	N = in(), k = 0;
	for (i = 0; i < N; i++) {
		sz[i] = M = in();
		top[i] = k;
		while (M--) c[k++] = in();
	}
	
	// 各列のデータを逆順に優先度付きキューに追加
	ans = 0, qsize = 0;
	for (i = N - 1; i >= 0; i--) {
		M = sz[i], k = top[i];
		while (M--) enq(c[k++]);
		ans += (unsigned)que[0];
		deq();
	}
	printf("%u\n", ans);
	return (0);
}



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

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb(x) push_back(x)
#define sz(x) x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-9

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(ch) scanf("%s",ch)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(x,y,z) printf("%d %d %d",x,y,z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(x,y,z) printf("%lld %lld %lld",x,y,z)
#define ps(ch) printf("%s",ch)
#define Afridi 0
#define NL printf("\n")
#define debug(x) printf("wow  %d !!\n",x)
#define Max 300005
#define INF 100000000
#define mod 1000000007
#define un(x) x.erase( unique( x.begin() , x.end() ) , x.end() )

#define FI freopen("in.txt","r",stdin)

#define D(x) cout << #x << " = " << (x) << endl
#define DD(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;


LL bigmod(LL b,LL p,LL m)
{
    if(p == 0)return 1;
    LL my = bigmod(b,p/2,m);
    my*=my;my%=m;
    if(p & 1)my*=b,my%=m;
    return my;
}
int setb(int n,int pos){return n=n | (1 << pos);}
int resb(int n,int pos){return n=n & ~(1 << pos);}
bool checkb(int n,int pos){return (bool)(n & (1 << pos));}

LL ara[100],N;
char str[2][100];
LL n;

void prework()
{
	LL i;
	Rep(i,n)
	{
		if( str[0][i] == str[1][i] )
		{
			ara[++N] = 1;
		}
		else
		{
			ara[++N] = 2;
			i++;
		}
	}
}

LL dp[100][10][10];
LL F(LL pos,LL up,LL down)
{
	if( pos > N )return 1;

	if( dp[pos][up][down] != -1 )return dp[pos][up][down];

	LL ret = 0;
	if( ara[pos] == 1 )
	{
		if( up == 0 )
		{
			LL i;
			rep(i,3)ret = ret + F(pos+1,i,i);
		}
		else
		{
			LL i;
			rep(i,3)
			{
				if( up != i && down != i )ret = ret + F(pos+1,i,i);
			}
		}
	}
	else
	{
		if( up == 0 )
		{
			LL i,j;
			rep(i,3)
			{
				rep(j,3)
				{
					if( i == j )continue;
					ret = ret + F(pos+1,i,j);
				}
			}
		}
		else
		{
			LL i,j;
			rep(i,3)
			{
				if( up == i ) continue;
				rep(j,3)
				{
					if( down == j )continue;
					if(i == j)continue;
					ret = ret + F(pos+1,i,j);
				}
			}
		}
	}

	return dp[pos][up][down] = ret % mod;
}

int main()
{
	//FI;
	sl(n);
	ss(str[0]);
	ss(str[1]);
	prework();
	mem(dp,-1);
	LL ret = F(1,0,0);
	pl(ret); NL;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

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

    ll n;
    cin >> n;
    pair<ll,ll> arr[n];
    for (ll i=0;i<=n-1;i++)
    {
        cin >> arr[i].first;
    }
    for (ll i=0;i<=n-1;i++)
    {
        cin >> arr[i].second;
    }

    ll ans=0;
    for (ll i=0;i<=n-1;i++)
    {
        if (arr[i].second<arr[i].first)
        {
            ans=ans+arr[i].first-arr[i].second;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
int e[101];
int main(){
int i,j,k,l,m,n=0,a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
for(i=a;i<=b;i++)e[i]++;
for(i=c;i<=d;i++)e[i]++;
for(i=0;i<=100;i++){
	if(e[i]==2)n++;
}
if(n<2)printf("0");
else printf("%d",n-1);
return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;

typedef vector<int> vi;

template<typename T>
static inline void p(T x) { cout << x << endl; }

int main()
{
    cin.sync_with_stdio(false);

	int n, cnt = 0;
	cin >> n;

	vi A(n), G;
	for (int &x: A)
		cin >> x;

	for (int i = 1, x = 1; x <= n; x = (pow(3, ++i) - 1) / 2)
		G.push_back(x);
	reverse(G.begin(), G.end());

	for (int g: G)
		for (int i = g; i < n; i++) {
			int v = A[i], j = i - g;
			for(; j >= 0 && A[j] > v; j -= g)
				A[j+g] = A[j], cnt++;
			A[j+g] = v;
		}

	p(G.size());
	for (int &x: G)
		cout << (&x == &G[0] ? "" : " ") << x;
	p("");
	p(cnt);
	for (int x: A)
		p(x);
}


Measured memory_bytes: 6728
import sys
input = sys.stdin.readline
n = int(input())
h = tuple(map(int,input().split()))

dp = [0]*n
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])


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



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

    int N;
    cin>>N;
    int A[N];
    rep(i,N) cin>>A[i];
    sort(A,A+N);
    int ans=1;

    if(N%2==A[0]%2) ans=0;
    if(N%2==1){
        for(int i=1;i<N;i+=2){
            if(A[i-1]!=A[i]-2 || A[i-1]!=A[i+1]-2) ans=0;
            else {
                ans=(ans*2)%MOD;
            }
        }
    }else{
        if(A[0]!=1 || A[1]!=1) ans=0;
        ans*=2;
        for(int i=2;i<N;i+=2){
            if(A[i-1]+2!=A[i]||A[i-1]+2!=A[i+1]) ans=0;
            ans=(ans*2)%MOD;
        }
    }
    cout << ans << endl;



}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double area3(double x1, double y1, double x2, double y2, double x3, double y3) {
 double a, b, c, z;
 a = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
 b = sqrt((x1 - x3)*(x1 - x3) + (y1 - y3)*(y1 - y3));
 c = sqrt((x2 - x3)*(x2 - x3) + (y2 - y3)*(y2 - y3));
 z = (a + b + c) / 2.0;
 return sqrt(z*(z - a)*(z - b)*(z - c)); }

 int main() {
 double x0, y0, x1, y1, x2, y2;
 double s; scanf("%lf,%lf", &x0, &y0);
 scanf("%lf,%lf", &x1, &y1); s = 0.0;
 while (scanf("%lf,%lf", &x2, &y2) == 2) {
 s += area3(x0, y0, x1, y1, x2, y2); x1 = x2, y1 = y2; }
 printf("%.8lf\n", s); 

return 0; } 


Measured memory_bytes: 2044
N, M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
MOD = 10**9 + 7
dp = [[0 for k in range(M+1)] for l in range(N+1)]

for k in range(N):
    for l in range(M):
        if S[k] == T[l]:
            dp[k+1][l+1] = dp[k+1][l] + dp[k][l+1] + 1
        else:
            dp[k+1][l+1] = dp[k+1][l] + dp[k][l+1] - dp[k][l]
        dp[k+1][l+1] %= MOD

print(dp[N][M]+1)


Measured memory_bytes: 74588
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll MAX = 100000;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int k;
	int n;
	int first;
	int tmp1;
	int tmp2;
	int ma = 0;
	cin >> k >> n;
	cin >> first;
	cin >> tmp1;
	ma = tmp1 - first;
	for(int i = 2; i < n; ++i){
		tmp2 = tmp1;
		cin >> tmp1;
		ma = max(ma, tmp1 - tmp2);
	}
	ma = max(ma, first + k - tmp1);
	cout << k - ma << endl; 
	return 0;
}

Measured memory_bytes: 256
def f1(a,mode):
  A=[a]
  while 1:
    tmp=["@->","@<-"][mode].replace("@",a)
    if s.count(tmp)==0: break
    a=s[s.index(tmp)+3]
    if mode==0: A+=[a]
    else: A=[a]+A
  return A

def f(s):
  A=f1(s[0],0)
  A=f1(A[0],1)+A[1:]
  return "".join(A)

n=input()
for _ in [0]*n:
  s=raw_input()
  print f(s)

Measured memory_bytes: 4228
a = input().split()
N = int(a[0])
K = int(a[1])
c = input().split()
c=[int(i) for i in c]


#それぞれ頂点が向かう先。



current_num_set = set()
current_num_list=[]
#これまでの道筋
current_num = 1 #現在の位置



#今いる位置が今まで出てきていない場合に、次どこにいくのかをチェック
while (current_num not in current_num_set):
      current_num_set.add(current_num)
      current_num_list.append(current_num)
      current_num = c[current_num-1]


c = len(current_num_list)


first_index = 0
#グルグルなっているところの最初のインデックスを計算して格納
for i in range(c):
  if current_num_list[i] == current_num:
    first_index = i
    break


cicle=c-first_index
first=first_index
#cがグルグルのリストの長さ
#グルグルの始まりのインデックス
if c<=K+1 :
  index = (K - first) % cicle + first
  print(current_num_list[index])
else :
  print(current_num_list[K])

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define all(a) a.begin(),a.end()
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;

int main(){
    int n,sum=0;
    cin >> n;
    vi s(n);
    rp(i,n){
        cin >> s.at(i);
        sum += s.at(i);
    }
    sort(all(s));
    if(sum%10!=0){
        cout << sum << endl;
        return 0;
    }else{
        rp(i,n){
            if(s.at(i)%10!=0){
                cout << sum-s.at(i) << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long a[100010];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) {
        scanf("%lld",&a[i]);
    }
        
    
    int zero =0;
    
    for(int i= 0;i<n;i++){
        if(a[i]==0){
           zero++;   
        }
    }
    if(zero>0){
        printf("0\n");
        return 0;
    }
    
    long long prod=1;
    for(int i=0; i<n; i++){
        if(a[i]<=1000000000000000000/ prod ){
            prod*=a[i];
        }else{
            printf("-1\n");
            return 0;
        }
    }
    printf("%lld\n",prod);
}


Measured memory_bytes: 4532
A_1 = list(map(int, input().split()))
A_2 = list(map(int, input().split()))
A_3 = list(map(int, input().split()))
n = int(input())
b = [int(input()) for _ in range(n)]

# 横
if A_1[0] in b:
  if A_1[1] in b:
    if A_1[2] in b:
      print('Yes')
      exit(0)
      
if A_2[0] in b:
  if A_2[1] in b:
    if A_2[2] in b:
      print('Yes')
      exit(0)

if A_3[0] in b:
  if A_3[1] in b:
    if A_3[2] in b:
      print('Yes')
      exit(0)
  
# 縦
for j in range(3):
  if A_1[j] in b:
    if A_2[j] in b:
      if A_3[j] in b:
        print('Yes')
        exit(0)
# 斜め
if A_1[0] in b:
  if A_2[1] in b:
    if A_3[2] in b:
      print('Yes')
      exit(0)
      
if A_1[2] in b:
  if A_2[1] in b:
    if A_3[0] in b:
      print('Yes')
      exit(0)

print('No')

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	int x;
	cin >> x;
	if (x >= 30) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 3600
#include<stdio.h>

#define MAX 100000
#define NILL -1

struct node{
  int p;
  int l;
  int r;
};

struct node a[MAX];
int n;
int D[MAX];// Dは深さを求めるために接点を格納しておく配列

  int depth(int,int);
  void print(int);


int main(){
  int i,j;//カウンタ変数
  int d,v;//dはidvのd行目を示し、vは1〜n-1個あるidのこと
  int c;//idのv行目の内容を表す変数
  int l,r;//leftとrightを表すための適当な変数

  scanf("%d",&n);//nは節点ののこと

  for(i=0; i<n; i++){
    a[i].p=a[i].l=a[i].r=NILL;

  }

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

    for(j=0; j<d; j++){
      scanf("%d",&c);

      if(j==0){
	a[v].l=c;//dの0番目の値を読み込んでいるときleftに値をいれる
      }
      else{
	a[l].r=c;//dの1番目以降を読み込んでいるときright（前の値+1）にいれる
      }

      l=c;
      a[c].p=v;
    }
  }

  for(i=0; i<n; i++){
    if(a[i].p==NILL){//親がいないとき
      r=i;
    }
  }

  depth(r,0);

  for(i=0; i<n; i++){
    print(i);
  }

  return 0;
}


int depth(int u,int p){
  D[u]=p;

  if(a[u].r!=NILL)
    depth(a[u].r,p);
  if(a[u].l!=NILL)
    depth(a[u].l,p+1);
      }

void print(int u){
  int i,c;

  printf("node %d: ",u);
  printf("parent = %d, ",a[u].p);
  printf("depth = %d, ",D[u]);

  if(a[u].p==NILL)
    printf("root, ");
  else if(a[u].l==NILL)
    printf("leaf, ");
  else
    printf("internal node, ");

  printf("[");

  for(i=0,c=a[u].l; c!=NILL; i++, c=a[c].r){
    if(i) printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}
  

  
	



Measured memory_bytes: 6384
#include <iostream>
#include <map>

using namespace std;

int main()
{
	int N;
	map<int, int> students;
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		int k;
		cin >> k;
		students.insert(std::make_pair(k, i));

	}
	for (auto const& entry : students)
	{
		cout << entry.second << endl;
	}
	
	return 0;
}


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

int Hen(char s,char t){
  return ((s-'0')*10+(t-'0'));
}
int main()
{
  string s,f;
  int n,a,b,max,T[86401]={};
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>s>>f;
      a=(Hen(s[0],s[1])*3600+Hen(s[3],s[4])*60+Hen(s[6],s[7]));
      b=(Hen(f[0],f[1])*3600+Hen(f[3],f[4])*60+Hen(f[6],f[7]));
      for(int j=a;j<b;j++)T[j]++;
    }
    max=0;
    for(int i=0;i<86401;i++){
      if(max<T[i])max=T[i];
      T[i]=0;
    }
    cout<<max<<endl;
  }
  return 0;
}

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

int A, B, ans;

int main(){
  cin >> A >> B;
  if(A > 9){
    ans = -1;
  }else if(B > 9){
    ans = -1;
  }else{
    ans = A * B;
  }
  cout << ans << endl;
}


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

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

    map<string, int> m;
    string S;
    for(int i = 0; i < N; ++i){
        cin >> S;
        auto it = m.find(S);
        if (it == m.end()){
            m.emplace(S, 0);
        }else{
            ++m[S];
        }
    }

    int max_size = 0;
    for(const auto& s : m){
        max_size = max(max_size, s.second);
    }

    for(const auto& s : m){
        if(s.second == max_size){
            cout << s.first << endl;
        }
    }
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 
//なんかむずいんだけどw
// fuck
signed main(){
	int s,w; cin>>s>>w;
	if(w>=s) cout<<"unsafe";
	else cout<<"safe";
	
	return 0;
}

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


int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> h(n,0);
    for(int i=0;i<n;i++)
        cin>>h[i];
  
    vector<int> dp(n,0);
    dp[n-1]=0;
    for(int i=n-2;i>=0;i--)
    {
        int j=1;
        int minv=INT_MAX;
        while(i+j<=n-1 && j<=k)
        {
            minv=min(minv,(abs(h[i]-h[i+j])+dp[i+j]));
            j++;
        }
        dp[i]=minv;
    }
   cout<<dp[0]<<endl;
}

Measured memory_bytes: 4060
package main

import (
	"fmt"
)

var n, ans int

func judge753(x int) bool {
	dic := map[int]struct{}{}
	for x != 0 {
		dic[x%10] = struct{}{}
		x /= 10
	}
	if len(dic) == 3 {
		return true
	}
	return false
}

func dfs(x int) {
	if x > n {
		return
	}
	if judge753(x) {
		ans++
	}
	for _, v := range [...]int{3, 5, 7} {
		dfs(x*10 + v)
	}
}

func main() {
	fmt.Scan(&n)
	dfs(0)
	fmt.Println(ans)
}


Measured memory_bytes: 4352
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

// Created by White Knife on 15/04/20.
// doot diddly donger cuckerino Hahahahahah

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


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

// @formatter:off
#define F               first
#define S               second
#define all(x)          (x).begin(), (x).end()
#define sz(x)           (long long) (x).size()
#define sim             template<typename T
#define ris             return *this
#define dor             > debug & operator <<
#define eni(x)          sim > typename enable_if<sizeof dud<T>(0) x 1, debug&>::type operator<<(T i)
sim> struct rge { T b, e; };
sim> rge<T> rang(T i, T j) { return rge<T>{i, j}; }
sim> auto dud(T *x) -> decltype(cerr << *x, 0);
sim> char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) { cerr << boolalpha << i; ris; }
  eni(==) { ris << rang(all(i)); }
  sim, typename U dor(pair<U, T> d) { ris << "(" << d.first << ", " << d.second << ")"; }
  sim dor(rge<T> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
  sim dor(const T&) { ris; }
#endif
};
#define pr(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using li = __int128;
using uli = unsigned __int128;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vb = vector<bool>;

using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
template <typename T> using ordered_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

const ld PI = acos(-1);

template<typename T> inline T mini(T& x, T y) { return x = min(x, y); }
template<typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
template <typename T> T rand(T x, T y) { return rand() % (y - x + 1) + x; }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
// @formatter:on


class DMultipleOf2019 {
public:
  const int MOD = 2019;
  
  void solve(std::istream &cin, std::ostream &cout) {
    string s;
    cin >> s;
    int n = s.length();
    vector<ll> cnt_suf(MOD, 0);
    int suf = 0;
    cnt_suf[suf]++;
    int pow10 = 1;
    ll ans = 0;
    for (int i = n - 1; i >= 0; --i) {
      int d = s[i] - '0';
      suf = (suf + d * pow10) % MOD;
      pow10 = 10 * pow10 % MOD;
      ans += cnt_suf[suf];
      cnt_suf[suf]++;
    }
    cout << ans << '\n';
  }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
	DMultipleOf2019 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3736
#include <cstdio>
#include <string>
#include<iostream>

using namespace std;


string s;
long int k = 0;
int main(void) {
	

	

	cin >> s;
	cin >> k;


	int sp = 0;
	while (k>0)
	{
		//spが範囲外にならないように
		if (s[sp] == 'a'&&sp + 1<s.length()) {
			sp++;
			continue;
		}

		//aにするのに必要な数
		int n = ('z' - s[sp])+1;
		if (k - n >= 0){
			k -= n;
			s[sp] = 'a';
		}
		else if(sp + 1<s.length()){
			sp++;
			continue;
		}
		else {
			
			s[sp] += k;
			k = 0;
		}

	}
	cout << s;

	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;
#define MAX_N 500
int field[MAX_N+1][MAX_N+1];
int cumSum[MAX_N+1][MAX_N+1];

void init(){
	rep(i,MAX_N+1){
		rep(j,MAX_N+1){
			field[i][j] = 0;
			cumSum[i][j] = 0;
		}
	}
}

int main()
{
	init();
	int N,M,Q;
	cin>>N>>M>>Q;
	rep(i,M){
		int l,r;
		cin>>l>>r;
		field[l][r]++;
	}
	for(int i = 0; i < N+1; i++){
		for(int j = 0; j < N+1; j++){
			cumSum[i+1][j+1] = cumSum[i+1][j] + cumSum[i][j+1] -cumSum[i][j] + field[i+1][j+1];
		}
	}

	rep(i,Q){
		int p,q;
		cin>>p>>q;
		cout<<cumSum[q][q] - cumSum[p-1][q] - cumSum[q][p-1] + cumSum[p-1][p-1]<<endl;
	}
	/*rep(i,N+1){
		rep(j,N+1){
			cout<<field[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<"--------------------------"<<endl;
	rep(i,N+1){
		rep(j,N+1){
			cout<<cumSum[i][j]<<" ";
		}
		cout<<endl;
	}*/
	return 0;
}


Measured memory_bytes: 5040
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=6e2+5;
const int mod=1e9+7;
int n,m,lim,ans,g[N],to[N],sum[N],dp[N][N];

template <typename _Tp> inline void IN(_Tp&x) {
	char ch;bool flag=0;x=0;
	while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1;
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	if(flag) x=-x;
}
inline void addedge(int u=0,int v=0) {IN(u),IN(v),to[u]=v,to[v]=u;}
inline bool check(int a,int b) {
	if((b-a+1)&1) return false;
	for(int i=a;i<=b;++i) if(to[i]&&(to[i]<a||to[i]>b)) return false;
	return true;
}

int main() {
	IN(n),IN(m),lim=n<<1,g[0]=1;
	for(int i=1;i<=m;++i) addedge();
	for(int i=1;i<=lim;++i) g[i]=(i&1)?0:(1ll*g[i-2]*(i-1)%mod);
	for(int i=1;i<=lim;++i) sum[i]=sum[i-1]+(bool)(!to[i]);
	for(int a=1;a<=lim;++a) for(int b=a+1;b<=lim;++b) if(check(a,b)) {
		dp[a][b]=g[sum[b]-sum[a-1]];
		for(int k=a+1;k<b;++k) if(dp[a][k]&&g[sum[b]-sum[k]])
			(dp[a][b]+=mod-1ll*dp[a][k]*g[sum[b]-sum[k]]%mod)%=mod;
		(ans+=1ll*dp[a][b]*g[((n-m)<<1)-sum[b]+sum[a-1]]%mod)%=mod;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
#include <sstream>
#include <bitset>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
	char s;
    cin >> s;
    if(s > 96) cout << 'a' << endl;
    else cout << 'A' << endl;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
const int max_v = 1000;
int v,E,n,m;
int d[max_v][max_v];
const int INF = 1e9;
vector<int> ls;
bool dh[max_v][max_v];
void solve(){
    for(int i=0 ; i<n ; i++){
        for(int j=0 ; j<n ; j++){
            dh[i][j] = false;
        }
    }
    for(int k=0 ; k<n ; k++){
        for(int i=0 ; i<n ; i++){
             for(int j=0 ; j<n ; j++){
                if(d[i][j] > d[i][k] + d[k][j]){
                    puts("-1");
                    return;
                }else if(d[i][j] == d[i][k] + d[k][j] &&d[i][k] > 0 && d[k][j]>0){
                    dh[i][j] = true; 
                }
            }
        }
    }
    long long ans = 0;
    for(int i=0 ; i<n ; i++){
        for(int j=i+1 ; j<n ; j++){
            if(!dh[i][j])  ans += d[i][j];
        }
    }
    cout << ans << endl;
}
int main(){
    cin >> n;
    for(int i=0 ; i<n ; i++){
        for(int j=0 ; j<n ; j++){
            int x;
            cin >> d[i][j];
        }
    }
    solve();
    return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

ll N;

int F(ll x, ll y){
    return max<int>(to_string(x).size(), to_string(y).size());
}

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

    std::cin >> N;

    int res = 100;
    for(ll i=1;i*i<=N;++i){
        if(N % i > 0){continue;}
        
        res = min(res, F(i, N / i));
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define si(x) scanf("%d",&x)
#define pi(x) printf("%d\n",x)
#define s(x) scanf("%I64d",&x)
#define p(x) printf("%I64d\n",x)
#define sc(x) scanf("%s",x)
#define pc(x) printf("%s",x)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define M 1000000007
#define N 1000002
#define inf 1e15
#define PQG priority_queue< int,std::vector<int>,std::greater<int> >
#define PQL priority_queue< int,std::vector<int>,std::less<int> >
#define PQPL priority_queue<pii ,vector< pii >, less< pii > >
#define PQPG priority_queue<pii ,vector< pii >, greater< pii > >
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

using namespace std;

map<pll,ll>K;

ll knapSack(ll W, ll wt[], ll val[],ll n){
   if(K[make_pair(n,W)]) return K[make_pair(n,W)];
   if (n == 0 || W == 0)
       return K[make_pair(n,W)]=0;

   if (wt[n-1] > W)
       return K[make_pair(n-1,W)]=knapSack(W, wt, val, n-1);

   else return K[make_pair(n,W)]=max( val[n-1] + knapSack(W-wt[n-1], wt, val, n-1),
                    knapSack(W, wt, val, n-1)
                  );
}

int main() {
    fast_io;
    ll n;
    ll W;
    cin>>n>>W;
    ll wt[n],v[n];
    for(int i=0;i<n;i++){
        cin>>wt[i]>>v[i];
    }
    ll ans=knapSack(W,wt,v,n);

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


Measured memory_bytes: 6400
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	ans := cal(a, b)
	fmt.Println(ans)
}

func cal(a, b int) int {
	ans := 0
	o := 1
	for i:=0;true;i++ {
		if o >= b {
			break
		}
		o = o - 1 + a
		ans++
	}
	return ans
}

Measured memory_bytes: 512
#include<stdio.h>
int main() {
  int i, k, n, m, cnt, data[100], data2[100][100], data3[100] = {0};
  scanf("%d %d", &n, &m);
  for(i = 0; i < m; i++) {
    scanf("%d", &data[i]);
  }
  for(i = 0; i < m; i++) {
    for(k = 0; k < n; k ++) {
      scanf("%d", &data2[i][k]);
    }
  }
  for(i = 0; i < m; i++) {
    cnt = 0;
    for(k = 0; k < n; k++) {
      if(data[i] == data2[i][k]) {
        data3[k]++;
        if(k == 1) {
        }
      }else{
        data3[data[i] - 1]++;
      }
    }
  }
  for(i = 0; i < n ; i++) {
    printf("%d\n",data3[i]);
  }
  return 0;
}

Measured memory_bytes: 1064
program main
	implicit none
    character(2*10**5)::s
    character(2)::ss
    integer,allocatable::dp(:)
    integer(8)::ans,le,i,t,le2
    read(*,*) s
    le=len_trim(s)
    allocate(dp(le))
    dp(1)=1
    if(le==1)then
    	write(*,*) 1
        deallocate(dp)
        stop
    else if(le==2)then
    	if(s(1:1)==s(2:2))then
    		dp(2)=1
    	else
    		dp(2)=2
        end if
        write(*,*) dp(2)
        deallocate(dp)
        stop
    else if(le==3)then
    	if(s(1:1)==s(2:2))then
    		dp(2)=1
    	else
    		dp(2)=2
        end if
        if(s(3:3)==s(2:2))then
    		dp(3)=dp(1)+1
    	else
    		dp(3)=dp(2)+1
        end if
        write(*,*)dp(3)
        deallocate(dp)
        stop
    else
    
    	if(s(1:1)==s(2:2))then
    		dp(2)=1
            ss=s(1:2)
    	else
    		dp(2)=2
            ss=s(2:2)
    	end if
        if(s(3:3)==s(2:2))then
    		dp(3)=dp(1)+1
    	else
    		dp(3)=dp(2)+1
        end if
    	
    	do i=4,le
        	
        
    		if(s(i-1:i-1)==s(i:i))then
        		dp(i)=dp(i-3)+2
        	else
        		dp(i)=dp(i-1)+1
    		end if
    	end do
    	write(*,*) dp(le)
        deallocate(dp)
    end if
    stop
end program main
    
   

Measured memory_bytes: 1548
#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
using namespace std;
////////////// Prewritten code follows. Look down for solution. ////////////////
#define x first
#define y second
#define LEN(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
using ll = long long;
using llu = long long unsigned;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vpii = vector<pii>;

const ld EPS = 1e-9;
inline int cmp(ld x, ld y = 0, ld tol = EPS) {
	return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

const int MOD = 1;
inline int mod(ll x, int m = MOD) {
	return (int)(((x%m) + m)%m);
}

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

////////////////////////// Solution starts below. //////////////////////////////

const int N = 2e6;

int n;
ll qnt[N];

int main () {
	// ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.precision(10);
	cin >> n;
	for(int i = 1; i <= n; i++)
		for(int j = i; j*1LL*i < n; j++)
			qnt[i*j] += 1 + (i != j);

	ll ans = 0;
	for(int c = 1; c <= n; c++)
		ans += qnt[n-c];
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 11388
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;


const int MAX = 1000000;
bool is_prime[MAX + 10];
int key(int n)
{
	vector<int> p;
	for (int i = 2; i <= n; ++i)
		if (is_prime[i] && n % i == 0)
			p.push_back(i);
	return 2 * p.back() - accumulate(all(p), 0);
}
int main()
{
	fill_n(is_prime, MAX, true);
	for (int i = 2; i <= MAX; ++i)
		if (is_prime[i])
			for (int j = 2*i; j <= MAX; j += i)
				is_prime[j] = false;

	int a, b;
	while (scanf("%d%d", &a, &b), a | b)
		puts(key(a) > key(b) ? "a" : "b");
}

Measured memory_bytes: 1864
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

template <typename T, typename E>
class LazySegmentTree {
    using F = function<T(T, T)>;
    using G = function<T(T, E)>;
    using H = function<E(E, E)>;
    int n, height;
    F f;
    G g;
    H h;
    T t;
    E e;
    vector<T> dat;
    vector<E> laz;

public:
    LazySegmentTree(F f, G g, H h, T t, E e): f(f), g(g), h(h), t(t), e(e) {}

    void init(int n_) {
        n = 1;
        height = 0;
        while (n < n_) { n <<= 1; height++; }
        dat.assign(2 * n, t);
        laz.assign(2 * n, e);
    }

    void build(const vector<T> &v) {
        auto n_ = (int)v.size();
        init(n_);
        for (int i = 0; i < n_; i++) dat[n + i] = v[i];
        for (int i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
    }

    inline T reflect(int k) {
        return laz[k] == e ? dat[k] : g(dat[k], laz[k]);
    }

    inline void eval(int k) {
        if (laz[k] == e) return;
        laz[(k << 1) | 0] = h(laz[(k << 1) | 0], laz[k]);
        laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k]);
        dat[k] = reflect(k);
        laz[k] = e;
    }

    inline void thrust(int k) {
        for (int i = height; i > 0; i--) {
            eval(k >> i);
        }
    }

    inline void recalc(int k) {
        while (k >>= 1) {
            dat[k] = f(reflect((k << 1) | 0), reflect((k << 1) | 1));
        }
    }

    void update(int a, int b, E x) {
        thrust(a += n);
        thrust(b += n - 1);
        for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
            if (l & 1) laz[l] = h(laz[l], x), l++;
            if (r & 1) --r, laz[r] = h(laz[r], x);
        }
        recalc(a);
        recalc(b);
    }

    void set_val(int a, T x) {
        thrust(a += n);
        dat[a] = x;
        laz[a] = e;
        recalc(a);
    }

    T query(int a, int b) {
        thrust(a += n);
        thrust(b += n - 1);
        T vl = t, vr = t;
        for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
            if (l & 1) vl = f(vl, reflect(l++));
            if (r & 1) vr = f(reflect(--r), vr);
        }
        return f(vl, vr);
    }
};


// verified
//  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_G&lang=jp
void AOJ_DSL_2_G() {
    int n, q, c, s, t, x;
    cin >> n >> q;

    // 区間add, 区間sum
    using P = pair<ll, ll>;
    auto f = [](P a, P b) { return P(a.first + b.first, a.second + b.second); };
    auto g = [](P a, ll b) { return P(a.first + b * a.second, a.second); };
    auto h = [](ll a, ll b) { return a + b; };

    LazySegmentTree<P, ll> seg(f, g, h, P(0, 0), 0);
    seg.build(vector<P>(n, P(0, 1)));

    while (q--) {
        cin >> c;
        if (c) {
            cin >> s >> t;
            cout << seg.query(s - 1, t).first << '\n';
        } else {
            cin >> s >> t >> x;
            seg.update(s - 1, t, x);
        }
    }
}

int main() {
    AOJ_DSL_2_G();
    return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n; cin >> n;
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b;
        a--, b--;
        g[a].emplace_back(b), g[b].emplace_back(a);
    }

    vector<int> df(n, -1), ds(n, -1);
    {
        queue<int> q;
        q.emplace(0); df[0] = 0;
        while (!q.empty()) {
            int now = q.front(); q.pop();
            for (auto &nxt: g[now]) {
                if (df[nxt] >= 0) continue;
                df[nxt] = df[now] + 1;
                q.emplace(nxt);
            }
        }
    }
    {
        queue<int> q;
        q.emplace(n - 1); ds[n - 1] = 0;
        while (!q.empty()) {
            int now = q.front(); q.pop();
            for (auto &nxt: g[now]) {
                if (ds[nxt] >= 0) continue;
                ds[nxt] = ds[now] + 1;
                q.emplace(nxt);
            }
        }
    }

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (df[i] <= ds[i]) cnt++;
    }
    cout << ((cnt > n - cnt) ? "Fennec" : "Snuke") << endl;
    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  vector<int> v(n);
  cin >> v;
  sort(v.begin(), v.end());
  cout << v[n-1] << ' ';
  int vmax = v[n-1];
  sort(v.begin(), v.end(), [&](int a, int b){return min(a,vmax-a)>min(b,vmax-b);});
  cout << v[0] << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
template
<
    typename TYPE,
    size_t SIZE
>
size_t array_length(const TYPE (&)[SIZE])
{
    return SIZE;
}
int main(){
	int n;
	cin >> n;
	vector<int> v;
	for(int i=1;i<=n;i+=2){
			v.push_back(i);
	}
	
	cout << (double)v.size()/n ;
	
	return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
def dfs(now,depth):
    if used[now]:
        return 0
    if depth==n:
        return 1
    used[now]=1
    ans=0
    for i in range(n):
        if connect[now][i]:
            ans+=dfs(i,depth+1)
    used[now]=0
    return ans
edge=[[int(i)for i in input().split()]for i in range(m)]#入力値受け取り、グラフの初期設定
connect=[[0 for i in range(n)]for i in range(n)]
for i in range(m):
    connect[edge[i][0]-1][edge[i][1]-1]=1
    connect[edge[i][1]-1][edge[i][0]-1]=1
used=[0]*n
print(dfs(0,1))



Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		char ch = br.readLine().charAt(0);
		out.println((char)(ch+1));
		
	}
}




Measured memory_bytes: 21204
N = STDIN.gets.chomp.to_i

count = 0
yes = false

for i in 1..N do
    a, b = STDIN.gets.chomp.split(' ')
    if a == b
        count += 1
        if count == 3
            yes = true
        end
    else
        count = 0
    end
end

if yes
    puts 'Yes'
else
    puts 'No'
end


Measured memory_bytes: 14368
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn=100111;
char s[maxn];
int pre[maxn];
int nxta[maxn],nxtb[maxn];
ll dp[maxn];
int n;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	bool f=true;
	for(int i=1;i<n;i++)f&=s[i]!=s[i+1];
	if(f)
	{
		puts("1");
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		pre[i]=pre[i-1]+(s[i]=='a'?1:-1);
 	}
 	int lst[3]={};
 	for(int i=n;i>=0;i--)
 	{
 		if(i<n)
 		{
 			nxta[i]=lst[((pre[i]+1)%3+3)%3];
 			nxtb[i]=lst[((pre[i]+2)%3+3)%3];
		}
		lst[(pre[i]%3+3)%3]=i;
 		
 	}
 //	for(int i=0;i<n;i++)cerr<<nxta[i]<<","<<nxtb[i]<<" ";cerr<<endl;
 	dp[0]=1;
 	for(int i=0;i<n;i++)
 	{
 		if(nxta[i])dp[nxta[i]]=(dp[nxta[i]]+dp[i])%mod;
 		if(nxtb[i])dp[nxtb[i]]=(dp[nxtb[i]]+dp[i])%mod;
 	}
// 	for(int i=1;i<=n;i++)cerr<<dp[i]<<" ";cerr<<endl;
 	ll sum=0;
 	for(int i=1;i<=n;i++)if((pre[i]-pre[n])%3==0)sum=(sum+dp[i])%mod;
 	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 2304
package main

import (
	"fmt"
	"sort"
)

func Reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func reverseInts(s []int) []int {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
	return s

}

type sortRunes []rune

func (s sortRunes) Less(i, j int) bool {
	return s[i] < s[j]
}

func (s sortRunes) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func (s sortRunes) Len() int {
	return len(s)
}

func SortString(s string) string {
	r := []rune(s)
	sort.Sort(sortRunes(r))
	return string(r)
}

func main() {
	var N int
	fmt.Scan(&N)

	var vi []float64 = make([]float64, N)

	for i := range vi {
		fmt.Scan(&vi[i])
	}

	sort.Float64s(vi)

	val := vi[0]

	for i, v := range vi {
		if i != 0 {
			val = (val + v) / 2
		}
	}
	fmt.Println(val)

}


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

int main() {
    string s, ans;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'B') {
            if (!ans.empty())ans.erase(ans.length() - 1, 1);
        } else {
            ans += s[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256