akhauriyash/Code-Regression huggingface dataset:
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.12 02:54:17
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;



template< typename T >
struct BinaryIndexedTree {
    std::vector< T > data;
    BinaryIndexedTree(int sz) {
        data.assign(++sz, 0);
    }
    
    inline T sum(int k) {
        T ret = 0;
        for (++k; k > 0; k -= k & -k) ret += data[k];
        return (ret);
    }
    
    inline T sum(int left, int right) {
        return sum(right) - sum(left - 1);
    }
    
    
    inline void add(int k, T x) {
        for (++k; k < data.size(); k += k & -k) data[k] += x;
    }
    
    
    
    int get(int64_t k) {
        ++k;
        int res = 0;
        int N = 1; while (N < (int)data.size()) N *= 2;
        for (int i = N / 2; i > 0; i /= 2) {
            if (res + i < (int)data.size() && data[res + i] < k) {
                k = k - data[res + i];
                res = res + i;
            }
        }
        return res + 1;
    }
    void print() {
        std::cout << "[ ";
        for (int i = 0; i < data.size() - 1; i++) {
            std::cout << sum(i, i);
            if (i < data.size() - 2) std::cout << ", ";
        }
        std::cout << " ]" << std::endl;
    }
};
int main() {
    int n,k;cin >> n >> k;
    vector<ll> sum(n+1);
    set<pair<ll,int>> st;
    ll ans = 0;
    map<ll,int> mp; 
    mp[0LL] = 0;
    for (int i = 0; i < n; i++) {
        ll a;cin >> a;
        a -= k;
        sum[i + 1] = sum[i] + a;
        mp[sum[i+1]] = 0;
    }
    int idx = 0;
    for(auto p : mp) {
        mp[p.first] = idx++;
    }
    BinaryIndexedTree<ll> bit(idx);
    for (int i = 0; i <= n; i++) {
        ans += bit.sum(0,mp[sum[i]]);
        bit.add(mp[sum[i]],1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 18812
#include <bits/stdc++.h>
using namespace std;
#define N 100100
const int mod=1e9+7;

char s[N];
int flag,n;
int f[N],sum[N],last[3]={0,-1,-1};

int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	for (int i=1;i<n;i++)
		if (s[i]==s[i+1]) {flag=1; break;}
	if (!flag) return puts("1"),0;
	
	f[0]=1;
	for (int i=1;i<=n;i++)
	{
		sum[i]=(sum[i-1]+(s[i]-'a'+1))%3;
		if (!sum[i] && i<n) f[i]=1;
		if (last[(sum[i]+1)%3]>=0) f[i]=(f[i]+f[last[(sum[i]+1)%3]])%mod;
		if (last[(sum[i]+2)%3]>=0) f[i]=(f[i]+f[last[(sum[i]+2)%3]])%mod;
		last[sum[i]]=i;
	}
	printf("%d\n",f[n]);
	return 0;
}

Measured memory_bytes: 1152
r, d, x = input().split()
intr, intd,intx = int(r), int(d), int(x)
mgrm = []
mgrm.append(intx)

for i in range(1, 11):
    mgrm.insert(i, intr * mgrm[i - 1] - intd)
    print(mgrm[i])


Measured memory_bytes: 2940
def max(a,b);       a > b ? a : b                              end
def min(a,b);       a < b ?  a : b                             end
def swap(a,b);      a, b = b, a                                end

n = gets.to_s.to_i
# a = gets.to_s.split.map{|e|e.to_i}
# m = Array.new(n){ gets.to_s.split.map{|e|e.to_i} }
# s = gets.to_s.chomp

puts n * 3.1415 * 2

Measured memory_bytes: 14288
N, M, Q = map(int, input().split())
LR = [[0] * N for _ in range(N)]
for _ in range(M):
    l, r = map(int, input().split())
    LR[l - 1][r - 1] += 1

for d in range(1, N):
    for p in range(N - d):
        q = p + d
        LR[p][q] += LR[p + 1][q] + LR[p][q - 1] - LR[p + 1][q - 1]

for _ in range(Q):
    p, q = map(int, input().split())
    print(LR[p - 1][q - 1])


Measured memory_bytes: 9344
H, W = gets.split.map(&:to_i)
s = H.times.map do
  gets.chomp.chars
end

q = [[H-1, W-1, 1]]
DIR = [
  [0, 1], [1, 0], [0, -1], [-1, 0]
]
s[H-1][W-1] = 1

q.each do |i, j, d|
  DIR.each do |di, dj|
    next if i+di < 0
    next if j+dj < 0
    next if i+di >= H
    next if j+dj >= W
    n = s[i+di][j+dj]
    next if n == "#"
    next if n.is_a?(Integer) && n <= d + 1
    if i+di == 0 && j+dj == 0
      w = s.join.chars.count("#")
      p H*W - w - d - 1
      exit
    end
    s[i+di][j+dj] = d+1
    q << [i+di, j+dj, d+1]
  end
end

p -1


Measured memory_bytes: 4220
N = int(input())

H = list(map(int, input().split()))
for i in range(1,N+1):
    tmp = H[-i]
    if not i==N:
        if tmp < H[-i-1]:
            if tmp == H[-i-1]-1:
                H[-i-1] -= 1
            else:
                print('No')
                exit()
print('Yes')


Measured memory_bytes: 20740
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define alphabet 26
#define ascii 96
typedef long long ll;
using namespace std;

int main() {
	string S;
	int N, i, alnum[alphabet];
	ll ans = 1;
	cin >> N;
	cin >> S;
	for (i = 1; i <= alphabet; i++)
	{
		alnum[i] = 0;
	}
	for (i = 0; i < N; i++)
	{
		alnum[(int)S[i] - ascii]++;
	}
	for (i = 1; i <= alphabet; i++)
	{
		ans *= (alnum[i] + 1);
		if (ans > 1000000007)
			ans = ans % 1000000007;
	}
	ans = ans - 1;
	if (ans == -1)
		ans = 1000000006;
	cout << ans << endl;
}

Measured memory_bytes: 512
k = int(input())
i = int(str(k)[-1])
if(i % 2 == 0 | i % 5 == 0 ):
    print(-1)
else:
    num = 7
    result=1
    for i in range(k):
        if(num % k == 0):
            break
        else:
            num = (7+ num*10)%k
            result+=1
    else:
        result = -1
    print(result)

Measured memory_bytes: 63272
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

bool check(vector<int> h, int index) {
    int val = h[index];
    for (int i = 0; i < index; i++) {
        if (h[i] > val) return false;
    }
    return true;
}

int main() {
    int n;
    scanf("%d", &n);
    vector<int> h = vector<int>(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &h[i]);
    }

    int cnt = 1;
    for (int i = 1 ; i < n; i++) {
        if (check(h, i)) cnt++;
    }
    printf("%d\n", cnt);

    return 0;
}


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

using namespace std;

uint64_t keta(uint64_t n){
  uint64_t d = 1;
  while(n /= 10) d++;

  return d;
}

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

  uint64_t A = 1;
  uint64_t ans = 100;
  uint64_t rootedN = floor(sqrt(N)) + 1.1;
  for(uint64_t A = 1; A < rootedN; A++){
    if(N % A == 0) {
      ans = min(ans, keta(max(A, N/A)));
    }
  }

  cout << ans << endl;

  return 0;
}

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

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

// Graph
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;

void dfs(int N, int u, Graph &G, vector<bool> &used, vector<ll> &dist, bool &can, ll cost)
{
  if (used[u])
  {
    if (dist[u] != cost)
      can = false;
  }
  else
  {
    used[u] = true;
    dist[u] = cost;
    for (auto v : G[u])
    {
      dfs(N, v.to, G, used, dist, can, cost + v.weight);
    }
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  Graph G(N);
  for (int i = 0; i < M; i++)
  {
    int L, R, D;
    cin >> L >> R >> D;
    L--, R--;
    G[L].push_back(Edge(R, D));
    G[R].push_back(Edge(L, -D));
  }
  bool can = true;
  vector<bool> used(N, false);
  vector<ll> dist(N, -1);
  dist[0] = 0;
  for (int i = 0; i < N; i++)
  {
    if (!used[i])
    {
      dist[i] = 0; // 適当に座標を設定
      dfs(N, i, G, used, dist, can, 0);
    }
  }
  if (can)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

// 1つ数を決めるとそれと連結の座標の数がすべて決まる．


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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}
 
int main(void){
	
	int N, M, X;
    cin >> N >> M >> X;
    int C[N], A[N][M];
    rep(i, N){
        cin >> C[i];
        rep(j, M)
            cin >> A[i][j];
    }

    int ans = 100000000;

    for(int bit = 0; bit < (1<<N); ++bit){
        vector<int> S = IntegerToVector(bit, N);

        int sum = 0, und[M] = {};
        for(int i : S){
                sum += C[i];
            for(int j = 0; j < M; j++){
                und[j] += A[i][j];
            }
        }
        bool flag = true;
        for(int j = 0; j < M; j++){
            if(und[j] < X)
                flag = false;
        }
        if(flag){
            ans = min(ans, sum);
        }
    }
    if(ans == 100000000)
        cout << -1 << endl;
    else
        cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	cout << a << " " << b << " " << (3*c-a-b) << endl << (4*c-2*a-b) << " " << c << " " << (2*a+b-2*c) << endl << (a+b-c) << " " << (2*c-b) << " " << (2*c-a) << endl;
	return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_table(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")

def main():
    a, b, x = LI()

    if x <= a * a * b / 2:
        c = 2 * x / (a * b)
        rad = math.atan(b / c)
    else:
        x = a * a * b - x
        c = 2 * x / (a * a)
        rad = math.atan(c / a)
    print(math.degrees(rad))

if __name__ == '__main__':
    main()

Measured memory_bytes: 77484
#include <bits/stdc++.h>
using namespace std;
const int N = 8;

vector<int>adjList[70];
int n, m;

int dfs (bitset<N> visited, int node) {
	if ((int)visited.count() == n)
		return 1;
	int path = 0;
	for (auto i : adjList[node]) {
		if (!visited[i-1]) {
			visited[i-1] = true;
			path += dfs(visited, i);
			visited[i-1] = false;
		}
	}
	return path;
}


int main ()
{
	cin >> n >> m;
	for (int i = 0; i < m ; i ++) {
		int x,y ;
		cin >> x >> y;
		adjList[x].push_back(y);
		adjList[y].push_back(x);
	}
	bitset<N>bs(1);
	cout << dfs(bs, 1) << endl;
  	return 0;
}


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

int main() {
    int str1Cnt;
    int str2Cnt;
    vector<int> score(200);
    int max = 0;

    cin >> str1Cnt;
    vector<string> str1(str1Cnt);
    for(int i = 0; i < str1Cnt; i++) {
        cin >> str1[i];
    }

    cin >> str2Cnt;
    vector<string> str2(str2Cnt);
    for(int i = 0; i < str2Cnt; i++) {
        cin >> str2[i];
    }
    
    for(int i = 0; i < str1Cnt; i++) {
        for(int j = 0; j < str1Cnt; j++) {
            if(str1[i] == str1[j]) {
                score[i]++;
            }
        }
        for(int j = 0; j < str2Cnt; j++) {
            if(str1[i] == str2[j]) {
                score[i]--;
            }
        }
    }

    max = score[0];
    for(int i = 0; i < str1Cnt; i++) {
        if(max < score[i]) {
            max = score[i];
        }
    }

    if(max < 0) {
        cout << 0;
    } else {
        cout << max;
    }


    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll max(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
double max(double a, double b) {

	if (a > b)return a;
	else return b;

}
//aとbの大きい方

ll min(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//aとbの小さい方

ll avd_i(ll a, ll b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//aとbの差の絶対値

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	ll r;
	r = b%a;
	if (r == 0)return a;
	else return gcd(r, a);

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

int main() {
	
	string S;

	cin >> S;

	cout << S.substr(0, S.size() - 8) << endl;

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;
  cin >> s;
  int a = 0;
  if(s >= 110){
    a += 2;
  }
  else if(s >= 010){
    a += 1;
  }
    
    if(s % 2 == 1){
    a += 1;
    }
      cout << a << endl;
    
}

Measured memory_bytes: 256
s = list(map(int, input().split()))
t = list(map(int, input().split()))
u = list(map(int, input().split()))

bingo = [s, t, u]

n = int(input())
numbers = [int(input()) for _ in range(n)]

for i in range(3):
    for j in range(3):
        if bingo[i][j] in numbers:
            bingo[i][j] = 0

for i in range(3):
    if bingo[i][0] == 0 and bingo[i][1] == 0 and bingo[i][2] == 0:
        print('Yes')
        exit()

if (bingo[0][0] == 0 and bingo[1][1] == 0 and bingo[2][2] == 0) or \
        (bingo[0][2] == 0 and bingo[1][1] == 0 and bingo[2][0] == 0):
    print('Yes')
    exit()

for i in range(3):
    if bingo[0][i] == 0 and bingo[1][i] == 0 and bingo[2][i] == 0:
        print('Yes')
        exit()

print('No')

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	ll T;
	cin >>T;
	cout << (T+T*T+T*T*T)<<endl;
}

Measured memory_bytes: 3608
s = input()
if s != s[::-1]:
    print('No')
elif s[:len(s) // 2] != s[:len(s) // 2][::-1]:
    print('No')
elif s[len(s) // 2 + 1:] != s[len(s) // 2 + 1:][::-1]:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int n, i;
    cin >> n >> i;
    cout << n-i+1 << endl;
    return 0;
}


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

int main() {
	int num = 0;
	int a, b;
	scanf("%d", &num);
	a = num / 100;
	b = num % 100;

	if (a >= 1 && a <= 12) {
		if (b >= 1 && b <= 12) {
			printf("AMBIGUOUS\n");
		}
		else {
			printf("MMYY\n");
		}
	}
	else{
		if (b >= 1 && b <= 12) {
			printf("YYMM\n");
		}
		else {
			printf("NA\n");
		}
	}
		
	return 0;

}

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

int main(){
    int n;
    ll time;
    cin >> n >> time;
    ll res = 0;
    vector<ll> t(n);
    rep(i,n) cin >> t[i];
    rep(i,n-1){
        if(t[i+1]>t[i]+time){
            res += t[i+1]-t[i]-time;
        }
    }
    ll ans = t[n-1] + time - res;
    cout << ans << endl;
}

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

int main()
{
    vector<string> v = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s;
    cin >> s;
    for(int i=0; i<7; i++){
        if(s == v[i]) {
            cout << 7-i << endl;
        }
    }
    return 0;
}

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

int main() {
	int N,sum;
	cin >>N;
	vector<int> bn(N-1);
	for (int i=0;i<N-1;i++){
		cin >>bn.at(i);
	}
	
	sum=0;
	
	for (int i=0;i<N;i++){
		if(i==0){
			sum =bn.at(i);
		}
		
		else if(i!=0 && i!=N-1){
			sum= sum+min(bn.at(i),bn.at(i-1));
		}
		
		else if (i==N-1){
			sum=sum+bn.at(N-2);
		}
	}
	
	cout << sum <<endl;
			
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N; cin >> N;
    long long Lucus[N+1];
    Lucus[0] = 2;
    Lucus[1] = 1;
    for(int i=2; i<N+1; i++){
    Lucus[i] = Lucus[i-1] + Lucus[i-2];
    }
    cout << Lucus[N] << endl;
    return 0;
}
    

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

int main(){
  int N;
  cin >> N;
  int h[N];
  rep(i,N) cin >> h[i];

  int dp[N] = {0};
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);

  for(int i=2;i<N;i++){
    dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
  }

  cout << dp[N-1] << endl;

  return 0;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
probs = [False]*n
wrongs = [0]*n
for i in range(m):
    p,s=map(str,input().split())
    if probs[int(p)-1] == False:
        if s == "AC":
            probs[int(p)-1] = True
        elif s == "WA":
            wrongs[int(p)-1] += 1

ac=0
wa=0
for i,a in enumerate(probs):
    if a == True:
        ac+=1
        wa+=wrongs[i]
print(ac,wa)

Measured memory_bytes: 4596
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};



int main(void){
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string s;
    cin >> s;
    int si = s.size()/2;
    int ans = 0;
    rep(i,si){
        if(s[i] != s[s.size() - 1 - i]) ans++;
    }
    print(ans);
    

}


Measured memory_bytes: 256
from fractions import gcd
import math

mod = 998244353

def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft

def rec(s, dp, i, l):
    if i == 0:
        return 1
    if dp[i][l] != -1:
        return dp[i][l]
    ret = [0, 0]
    if s[i-1] != s[i]:
        ret[0] = rec(s, dp, i-1, 1)
    if 1 < i  and s[i-2:i] != s[i:i+2]:
        ret[1] = rec(s, dp, i-2, 2)
    dp[i][l] = max(ret)
    return dp[i][l]


def main():
    s = input()
    n = len(s)
    inf = 100000000
    dp = [[-inf] * 2 for i in range(n+2)]
    dp[0][0] = 1
    dp[1][1] = 1
    for i in range(n-1):
        if s[i] != s[i+1]:
            dp[i+1][0] = max(dp[i][0] + 1, dp[i+1][1]) if -inf != dp[i][0] else dp[i+1][1]
        dp[i+2][1] = max(dp[i][0] + 1, dp[i+2][1]) if -inf != dp[i][0] else dp[i+2][1]
        dp[i+1][0] = max(dp[i][1] + 1, dp[i+1][0]) if -inf != dp[i][1] else dp[i+1][0]
        if i > 1 and s[i-1:i+1] != s[i+1:i+3]:
            dp[i+2][1] = max(dp[i][1] + 1, dp[i+2][1]) if -inf != dp[i][1] else dp[i+2][1]

    print(max(dp[n-1]))
    # print([i[0] for i in dp])
    # print([i[1] for i in dp])

main()


Measured memory_bytes: 38484
program main
  implicit none
  integer i,D,j,last(26),day, score(26)
  integer,allocatable :: c(:),s(:,:)
  read(*, *)D
  allocate(c(26))
  allocate(s(D,26))
  read(*, *) (c(i), i = 1,26)
  do i = 1,D
    read(*, *) (s(i,j), j = 1,26)
  end do
  last = 0
  do i = 1,D-3
    last = last + 1
    score = 0
    do j = 1,26
      score(j) = s(i,j) - s(i+1,j) - s(i+2,j) - s(i+3,j) + 10*last(j)*c(j)
    end do
    day = 1
    do j = 1,26
      if (score(j) > score(day)) then
        day = j
      end if
    end do
    write(*, *) day
    last(day) = 0
  end do
  do i = D-2,D
    last = last + 1
    score = 0
    do j = 1,26
      score(j) = s(i,j) + 10*last(j)*c(j)
    end do
    day = 1
    do j = 1,26
      if (score(j) > score(day)) then
        day = j
      end if
    end do
    write(*, *) day
    last(day) = 0
  end do
end program main

Measured memory_bytes: 2904
import java.io.*;
import java.util.*;

public class Main{
  public static void main(String[] args)throws IOException{
    //BufferedReader br = new BufferedReader(System.in);
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    
    int N = sc.nextInt();
		String S = sc.next();
		int BLACK = 0;
		int WHITE = 0;
		for(int i=0;i<N;i++) {
			if(S.charAt(i)=='.') {
				WHITE++;
			}
		}
		int min = WHITE;
		for(int i=0;i<N;i++) {
			if(S.charAt(i)=='#') {
				BLACK++;
			}
			else {
				WHITE--;
			}
 
			min = Math.min(min, WHITE + BLACK);
		}
		System.out.println(min);
    
    out.flush();
  }
}

Measured memory_bytes: 26808
#include<iostream>
#include<string>
using namespace std;
string bin(int n){
int i;
string s="       ";
for(i=0;i<7;i++){
if(n%2==0)s[6-i]='0';else s[6-i]='1';
n>>=1;
}
return s;
}
int main(){
int n,i,j,k,p[10]={63,6,91,79,102,109,125,39,127,111};
while(cin>>n){
if(n==-1)break;
for(i=0;i<n;i++){
k=j;cin>>j;
if(i>0)cout<<bin(p[j]^p[k])<<endl;
else cout<<bin(p[j])<<endl;
}
}
return 0;
}

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

int main() {
  int in_h, in_m, in_s;
  int out_h, out_m, out_s;

  for(int i = 0; i < 3; i++) {
    cin >> in_h >> in_m >> in_s >> out_h >> out_m >> out_s;

    int in_time, out_time;

    in_time = 60*60*in_h + 60*in_m + in_s;
    out_time = 60*60*out_h + 60*out_m + out_s;

    int res_time;

    res_time = out_time - in_time;

    if(res_time >= 60*60) {
      cout << res_time / (60*60) << ' ';
      res_time = res_time % (60*60);
    }
    else
      cout << '0' << ' ';
    if(res_time >= 60 ) {
      cout << res_time/ 60 << ' ';
      res_time= res_time % 60;
    }
    else
      cout << '0' << ' ';
    cout << res_time << endl;
  }
  return 0;
}



Measured memory_bytes: 3068
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


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;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

int main() {
	int n, sum = 0;
	string s, tar = "ABC";
	cin >> n >> s;
	for (int i = 0; i < n - 2; ++i) {
		string x = s.substr(i, 3);
		if (x == tar) sum++;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<iostream>
using namespace std;
int n,m,a[100005],f[100005],x,y,ans;
int find(int k){
	if(f[k]!=k) f[k]=find(f[k]);
	return f[k];
}
void pa(int a,int b){
	int t1=find(a),t2=find(b);
	if(t1!=t2) f[t2]=t1;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		f[i]=i;
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		pa(x,y);
	}
	for(int i=1;i<=n;i++){
		if(find(i)==find(a[i]))ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<numeric>
#include<vector>
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  int h[n];
  for (int i=0;i<n;i++) cin >> h[i];
  sort(h,h+n);
  int m = h[k-1] - h[0];
  for (int i=0;i<n-k+1;i++) m = min(m,h[k+i-1]-h[i]);
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

ll m_pow(ll x, int n) {
        if (n == 0) {
                return 1;
        } else {
                return x * m_pow(x, n - 1);
        }
}

int main() {
        ll x;
        cin >> x;

        int m = 1e3;
        for (int a = -m; a <= m; a++) {
                for (int b = -m; b <= m; b++) {
                        ll t = m_pow(a, 4) + m_pow(a, 3) * b + m_pow(a, 2) * m_pow(b, 2)
                                + a * m_pow(b, 3) + m_pow(b, 4) ;
                        if (t != 0 && x % t == 0) {
                                if (a - b < 0) {
                                        a = -a;
                                        b = -b;
                                }

                                cout << a << " " << b << endl;

                                return 0;
                        }
                }
        }

        return 0;
}


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

#define endl '\n'
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define deb cout<<"HOLA\n";
#define UNIQUE(v) (v).resize(unique(ALL(v))-(v).begin())
#define forn(i,n) for (ll i = 0; i < n; i++)
#define forr(i,a,b) for (ll i = a; i <= b; i++)
#define bs(v,f) binary_search(ALL(v),f)
#define lb(v,f) lower_bound(ALL(v),f)
#define ub(v,f) upper_bound(ALL(v),f)
#define pb push_back

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<ii> vii;

vi a;int n,k;
vl dp(100005,-1);
ll ans(ll x){
    if(x==n-1)return 0;
    if(x>n-1)return INT_MAX;
    if(dp[x]!=-1)return dp[x];
    ll a1,mini=INT_MAX;
    forn(i,k){
        a1=ans(x+i+1)+abs(a[x]-a[x+i+1]);
        mini=min(a1,mini);
    }
    return dp[x]=mini;
}

void solve(){
	cin>>n>>k;
    a.resize(n+5);
    forn(i,n)cin>>a[i];
    cout<<ans(0);
}
int main(){
    fast
	/*int t;
	cin>>t;
	while(t--)*/
		solve();
	return 0;
}


Measured memory_bytes: 7680
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,i;
    cin>>n;
    ll dp[n+1][3]={0};
    for(i=1;i<=n;i++)
    {
        ll a,b,c;
        cin>>a>>b>>c;
        if(i==1)
            dp[i][0]=a,dp[i][1]=b,dp[i][2]=c;
        else
        {
            dp[i][0]=max(a+dp[i-1][1],a+dp[i-1][2]);
            dp[i][1]=max(b+dp[i-1][0],dp[i-1][2]+b);
            dp[i][2]=max(c+dp[i-1][0],c+dp[i-1][1]);
        }
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
}


Measured memory_bytes: 2560
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map { it.toLong() }

    var ans = 0L
    for (i in k .. n+1) {
        val min = ((0 + i)* i)/2
        val max = ((n+1) + (n+1-i)) * i /2
        ans = modAdd(ans,max+1)
        ans = modSub(ans,min)
        if (ans < 0) ans = modAdd(ans, mod)
    }
    println(ans)
}

const val mod = 1000000007L
fun modAdd(a: Long, b:Long):Long = (a + b) % mod
fun modSub(a: Long, b:Long):Long = (a - b) % mod


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

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

using namespace std;

bool ispali(string s){
	string t=s;
	reverse(t.begin(),t.end());
	return s==t;
}

int main(){
	string s; cin>>s;
	int n=s.length();
	puts(ispali(s)&&ispali(s.substr(0,n/2))?"Yes":"No");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

vector<int> graph[1000000];
int dist[2][1000000];
int main()
{
    int n;
    cin >> n;

    rep(i, 0, n - 1)
    {
        int a, b;
        cin >> a >> b;
        --a, --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    rep(c, 0, 2)
    {
        queue<pii> que;
        int start = (c == 0)? 0: n - 1;
        que.push(make_pair(start, 1));
        while(que.size() > 0)
        {
            int now, d;
            tie(now, d) = que.front();
            que.pop();

            if (dist[c][now] > 0) continue;
            dist[c][now] = d;
            
            for (auto next: graph[now])
                que.push(make_pair(next, d + 1));
        }
    }
    int cnt1, cnt2;
    cnt1 = cnt2 = 0;
    rep(i, 0, n)
    {
        if (dist[0][i] <= dist[1][i])
            ++cnt1;
        else
            ++cnt2;
        
        // cout << i << ' ' << dist[0][i] << ' ' << dist[1][i] << endl;
    }
    if (cnt1 > cnt2)
        cout << "Fennec" << endl;
    else
        cout << "Snuke" << endl;
    // cout << cnt1 << ' ' << cnt2 << endl;
    return 0;
}

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

int main () {
    string str;
    while (cin >> str){

        if (str.at(0) == 'o' && str.at(1) == 'o' && str.at(2) == 'o'){
            cout << "o" << endl;
        }
        else if (str.at(3) == 'o' && str.at(4) == 'o' && str.at(5) == 'o'){
            cout << "o" << endl;
        }
        else if (str.at(6) == 'o' && str.at(7) == 'o' && str.at(8) == 'o'){
            cout << "o" << endl;
        }
        else if (str.at(0) == 'o' && str.at(3) == 'o' && str.at(6) == 'o'){
            cout << "o" << endl;
        }
        else if (str.at(1) == 'o' && str.at(4) == 'o' && str.at(7) == 'o'){
            cout << "o" << endl;
        }
        else if (str.at(2) == 'o' && str.at(5) == 'o' && str.at(8) == 'o'){
            cout << "o" << endl;
        }
        else if (str.at(0) == 'o' && str.at(4) == 'o' && str.at(8) == 'o'){
            cout << "o" << endl;
        }
        else if (str.at(2) == 'o' && str.at(4) == 'o' && str.at(6) == 'o'){
            cout << "o" << endl;
        }

        else if (str.at(0) == 'x' && str.at(1) == 'x' && str.at(2) == 'x'){
            cout << "x" << endl;
        }
        else if (str.at(3) == 'x' && str.at(4) == 'x' && str.at(5) == 'x'){
            cout << "x" << endl;
        }
        else if (str.at(6) == 'x' && str.at(7) == 'x' && str.at(8) == 'x'){
            cout << "x" << endl;
        }
        else if (str.at(0) == 'x' && str.at(3) == 'x' && str.at(6) == 'x'){
            cout << "x" << endl;
        }
        else if (str.at(1) == 'x' && str.at(4) == 'x' && str.at(7) == 'x'){
            cout << "x" << endl;
        }
        else if (str.at(2) == 'x' && str.at(5) == 'x' && str.at(8) == 'x'){
            cout << "x" << endl;
        }
        else if (str.at(0) == 'x' && str.at(4) == 'x' && str.at(8) == 'x'){
            cout << "x" << endl;
        }
        else if (str.at(2) == 'x' && str.at(4) == 'x' && str.at(6) == 'x'){
            cout << "x" << endl;
        }
        else{
            cout << "d" << endl;
        }
    }
}




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

using namespace std;
using ll = long long;

#define MOD 1000000007

int main()
{
    string S;
    cin >> S;

    int L = S.length();
    vector<vector<ll>> dp(L+1, vector<ll>(13));

    dp[0][0] = 1;
    for(int i=0; i<L; ++i){
        if(S[i] == '?'){
            for(int j=0; j<13; ++j){
                for(int k=0; k<10; ++k)
                    dp[i+1][(10*j+k)%13] += dp[i][j] % MOD;
            }
        }
        else{
            for(int j=0; j<13; ++j)
                dp[i+1][(10*j+(int)(S[i]-'0'))%13] += dp[i][j] % MOD;
        }
    }

    cout << dp[L][5] % MOD << endl;

    return 0;
}

Measured memory_bytes: 13696
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[100] = {};
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  if(a[0] + a[1] == a[2]) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
from collections import deque
H,W = map(int,input().split())
maze = []
for _ in range(H):
  maze.append(list(input()))

res = 0
move = [(1,0),(0,1),(0,-1),(-1,0)]
for i in range(H):
  for j in range(W):
    if maze[i][j] == ".":
      visited = [[False]*W for _ in range(H) ]
      q = deque([(i,j)])
      depth = -1
      while q:
        depth += 1
        L = len(q)
        new = deque([])
        for _ in range(L):
          i,j = q.popleft()
          if visited[i][j]: continue
          visited[i][j] = True
          for y,x in move:
            if 0<=i+y<H and 0<=j+x<W and not visited[i+y][j+x]:
              if maze[i+y][j+x] == ".":
                new.append((i+y,j+x))
        q = new
      res = max(res, depth)

print(res)

Measured memory_bytes: 43740
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = read.to!int;
	
	S[] ss;
	foreach(i; 0 .. n) ss ~= S(read.to!long, read.to!long);
	
	int[long[2]] cnt;
	foreach(i; 0 .. n) foreach(j; 0 .. i){
		long[2] k = [ss[i].x - ss[j].x, ss[i].y - ss[j].y];
		if(k[0] < 0 || k[0] == 0 && k[1] < 0) k = [-k[0], -k[1]];
		if(k !in cnt) cnt[k] = 0;
		cnt[k] += 1;
	}
	log("cnt:", cnt);
	
	int best = 0;
	auto ks = cnt.keys;
	foreach(k; ks) best = max(best, cnt[k]);
	
	int ans = n - best;
	ans.writeln;
}
struct S{
	long x, y;
}


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

int main() {
  
  int N;
  cin >> N;
  
  int x, y;
  int sw=2000000000, se=1000000000, ne=0, nw=-1000000000;
  
  for (int i = 0; i < N; i++) {
    cin >> x >> y;
    sw = min(sw,x+y);
    se = min(se,y-x);
    ne = max(ne,x+y);
    nw = max(nw,y-x);
  }
  
  cout << max(ne-sw,nw-se) << endl;

return 0;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int gcd(int a, int b)
{
	if(a % b == 0)
	{
		return b;
	}
	else
	{
		return(gcd(b, a % b));
	}
}

void solve()
{
	int m, n;
	while(cin >> m >> n)
	{
		if(m < n)
		{
			swap(m, n);
		}
		cout << gcd(m, n) << endl;;
	}
}

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

Measured memory_bytes: 0
a, b = map(int, input().split())
p = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]
if p.index(a) < p.index(b): print('Bob')
elif p.index(a) > p.index(b): print('Alice')
else: print('Draw')


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

using namespace std;

bool check(const vector<int>& a){
    if(all_of(a.begin(), a.end(), [](int t){ return t==0; })) return true;
    if(a.size()%3 != 0) return false;
    int d = a.size()/3;
    for(int i=0;i<a.size();i++){
        if(a[i] != a[i/d*d]) return false;
    }
    return (a[0]^a[d]) == a[2*d];
}

int main(){
    int N; cin >> N;
    vector<int> a(N);
    for(auto& t : a) cin >> t;
    sort(a.begin(), a.end());
    cout << (check(a) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>

int main()
{
    double base, power=3, result;

    scanf("%lf", &base);
    if(base==1)
    {
        printf("1");
        return 0;
    }
    result = pow(base,power);
    printf("%.lf",result);

    return 0;
}


Measured memory_bytes: 2464
i = raw_input().strip().split()

W = int(i[0])
H = int(i[1])
x = int(i[2])
y = int(i[3])
r = int(i[4])

flag = True

if x-r < 0 or x+r > W:
    flag = False
elif y-r < 0 or y+r > H:
    flag = False

if flag:
    print "Yes"
else:
    print "No"

Measured memory_bytes: 6432
def swapRange(A,b,e,t):
    for k in range(e-b):
        A[b+k],A[t+k]=A[t+k],A[b+k]
    return A

n=int(input())
A=list(map(int,input().split()))
q=int(input())

for i in range(q):
    query=list(map(int,input().split()))
    A=swapRange(A,query[0],query[1],query[2])
print(' '.join(map(str,A)))



Measured memory_bytes: 5716
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

#define FOR(i, l, r) for (i = (l); i < r; i++ )

using namespace std;
typedef long long ll;
typedef struct {
    int p;
    int l;
    int r;
} Node;
#define NIL (-1)
#define MAX_N (30)

int n;
Node N[MAX_N];

void preorder( int id ) {
    if ( id == NIL ) return;
    printf(" %d", id);
    preorder( N[id].l );
    preorder( N[id].r );
}

void inorder( int id ) {
    if ( id == NIL ) return;
    inorder( N[id].l );
    printf(" %d", id);
    inorder( N[id].r );
}

void postorder( int id ) {
    if ( id == NIL ) return;
    postorder( N[id].l );
    postorder( N[id].r );
    printf(" %d", id);
}


int main()
{
    scanf("%d", &n);
    for ( int i = 0; i < n; i++ ) {
	N[i].p = N[i].l = N[i].r = NIL;
    }

    for ( int i = 0; i < n; i++ ) {
	int id;
	scanf("%d", &id);
	scanf("%d %d", &N[id].l, &N[id].r);
	if ( N[id].l != NIL ) N[N[id].l].p = id;
	if ( N[id].r != NIL ) N[N[id].r].p = id;
    }

    // find the root.
    int root = NIL;
    for ( int i = 0; i < n; i++ ) {
	if ( N[i].p == NIL ) {
	    root = i;
	    break;
	}
    }


    printf("Preorder\n");
    preorder( root );
    printf("\n");

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

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

    return 0;
}

Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		int k=scan.nextInt();
		if(k<=a) {
			System.out.println(k);
		}
		else if(k<=a+b) {
			System.out.println((a*1));
		}
		else {
			System.out.println((a*1)+(-1*(k-a-b)));
		}
	}

}


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

using namespace std;

typedef pair<int, int> P;

P usagi[1000001], neko[1000001];
int urow[505], ucol[505], udia[2], uwin;
int nrow[505], ncol[505], ndia[2], nwin;
int n, u, v, m;

int main()
{
  fill(usagi, usagi+1000001, P(-1, -1));
  fill( neko,  neko+1000001, P(-1, -1));
  cin >> n >> u >> v >> m;
  for(int t = 0; t < 2; t++) {
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
	int num; cin >> num;
	(t ? neko[num] : usagi[num]) = P(i, j);
      }
    }
  }
  for(int i = 0; i < m; i++) {
    int card; cin >> card;
    if(~usagi[card].first) {
      P p = usagi[card];
      if(n == 1) {
	uwin++;
      } else {
	urow[p.first]++, uwin += (urow[p.first] == n);
	ucol[p.second]++, uwin += (ucol[p.second] == n);
	if(p.first == p.second) udia[0]++, uwin += (udia[0] == n);
	if(p.first == n-1-p.second) udia[1]++, uwin += (udia[1] == n);
      }
    }
    if(~neko[card].first) {
      P p = neko[card];
      if(n == 1) {
	nwin++;
      } else {
	nrow[p.first]++, nwin += (nrow[p.first] == n);
	ncol[p.second]++, nwin += (ncol[p.second] == n);
	if(p.first == p.second) ndia[0]++, nwin += (ndia[0] == n);
	if(p.first == n-1-p.second) ndia[1]++, nwin += (ndia[1] == n);
      }
    }

    if(u <= uwin && v <= nwin) {
      cout << "DRAW" << endl; return 0;
    } else if(u <= uwin) {
      cout << "USAGI" << endl; return 0;
    } else if(v <= nwin) {
      cout << "NEKO" << endl; return 0;
    }
  }
  cout << "DRAW" << endl;
  return 0;
}

Measured memory_bytes: 18712
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
B = []
x = 0
for j in range((N - 1) // 2):
	x += A[2 * j + 1]
B.append(S - 2 * x)
for i in range(N - 1):
	x = A[i] * 2 - B[i]
	B.append(x)
C = [str(a) for a in B]
print(' '.join(C))

Measured memory_bytes: 21320
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

void solve() {
    int n; cin >> n;
    vector <pi> xy(n);
    vector <int> p(n);
    loop(i, n) {
        cin >> xy[i].F >> xy[i].S;
        p[i] = i;
    }
    double ans = 0;
    do {
        loop1(i, n - 1) {
            double xd = xy[p[i]].F - xy[p[i - 1]].F, yd = xy[p[i]].S - xy[p[i - 1]].S;
            ans += sqrt(xd * xd + yd * yd);
        }
    } while (next_permutation(all(p)));
    loop1(i, n)
        ans /= i;
    cout << fixed << setprecision(7) << ans;
}

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


Measured memory_bytes: 3792
import sys
from datetime import datetime

if __name__ == '__main__':
    N, K = map(lambda x:int(x), sys.stdin.readline().split())
    S = list(map(lambda x: int(x), list(sys.stdin.readline().rstrip())))
    start, end = 0, 0
    bStart, bEnd = 0, 0
    # 01010110
    #  * *
    # 広げる時:
    #   前回のz=1
    #   前回のs_end=1
    #   今回広がったもの=0
    #   今回のz=2
    # 狭める時:
    #   前回のz=1
    #   前回のs_start=1
    #   今回狭まったもの=0
    #   今回のz=1
    extend = True
    
    z = 0
    # print(S)
    while True:
        # assert start <= end
        # print(start, end, 'z:', z)
        
        # S[start:end]にある孤立した0がK個以下か
        # prev = 1
        # z = 0
        # for i in range(start, end):
        #     if prev == 1 and S[i] == 0:
        #         z += 1
        #     prev = S[i]
        if extend:
            end_back = 1 if end == 0 else S[end-1]
            if end_back == 1 and S[end] == 0:
                z += 1
        else:
            start_back = 1 if start == 0 else S[start-1]
            if start_back == 0 and S[start] == 1:
                z -= 1
        # input()
        # 全員を起立させられるので，広げる
        # print(z)
        if z <= K:
            if bEnd - bStart < end - start:
                bStart, bEnd = start, end
            end += 1
            if end == len(S):
                break
            extend = True
        # 反転しても逆立ちが残るので，狭める
        else:
            start += 1
            if start == len(S)-1:
                break
            extend = False
    bEnd += 1
    S[bStart:bEnd] = [1 for _ in range(bStart, bEnd)]
    # print(S, bStart, bEnd)

    o, maxO = 0, 0
    prev = 1
    for s in S:
        # print(prev, s)
        if prev == 1 and s == 0:
            if o > maxO:
                maxO = o
            o = 0
        elif s == 1:
            o += 1
        prev = s
    else:
        if o > maxO:
            maxO = o

    print(maxO)


Measured memory_bytes: 5648
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int tap = 1;
        int ans = 0;
        while (tap < B){
            tap += (A-1);
            ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35700
H, W = [int(item) for item in input().split()]
grid = [[item for item in input()] for _ in range(H)]

dp = [[0 for _ in range(W+1)] for _ in range(H+1)]
max_num = 10**9 +7

def main():
    dp[0][1] = 1

    for i in range(H):
        for j in range(W):
            if grid[i][j] != '#':
                dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j]) % max_num
            

    # print(dp)
    print(dp[H][W])

if __name__ == "__main__":
    main()


Measured memory_bytes: 52296
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
const int mod = 1e9+9;
const int INF = 1e9;

int main(){
    string s;
    int k;
    cin >> s >> k;
    int n = (int)s.size();

    set<string> st;
    rep(i,n){
        REP(j,1,k+1){
            st.insert(s.substr(i, j));
        }
    }

    int m = 1;
    for (auto ele : st){
        if (m == k){
            cout << ele << endl;
            return 0;
        }
        m++;
    }

    return 0;
}


Measured memory_bytes: 4732
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
const ll MOD=1000000007,MOD2=998244353,INF=1e18;



int main() {
    int S,W;
    cin>>S>>W;
    if(W>=S){cout<<"unsafe"<<endl;}
    else{cout<<"safe"<<endl;}
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  string s;
  cin>>s;
  int ans=0;
  int cnt=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='L')cnt--;
    else cnt++;
    if(cnt==-4)cnt=0;
    if(cnt==4)cnt=0,ans++;
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3208
li = [list(map(int,input().split())) for i in range(3)]

lia = li[0]
lib = li[1]
lic = li[2]

if lia[0]-lia[1]==lib[0]-lib[1]==lic[0]-lic[1] and lia[1]-lia[2]==lib[1]-lib[2]==lic[1]-lic[2]\
and lia[0]-lib[0]==lia[1]-lib[1]==lia[2]-lib[2] and lib[0]-lic[0]==lib[1]-lic[1]==lib[2]-lic[2]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064