akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

// INFTY is over max num
const INFTY = 100000 * 100000

var (
	s   = bufio.NewScanner(os.Stdin)
	cnt = 0
)

func main() {
	s.Split(bufio.ScanWords)

	n := nextInt(s)
	S := make([]int, n)

	for i := range S {
		S[i] = nextInt(s)
	}
	mergeSort(S, 0, n)
	fmt.Println(trimBracket(fmt.Sprint(S)))
	fmt.Println(cnt)
}

func nextInt(s *bufio.Scanner) int {
	s.Scan()
	r, err := strconv.Atoi(s.Text())
	if err != nil {
		panic(err)
	}
	return r
}

func trimBracket(s string) string {
	return strings.Trim(s, "[]")
}

func mergeSort(A []int, left, right int) {
	if left+1 < right {
		mid := (left + right) / 2
		mergeSort(A, left, mid)
		mergeSort(A, mid, right)
		merge(A, left, mid, right)
	}
}

func merge(A []int, left, mid, right int) {
	n1 := mid - left
	n2 := right - mid
	L := make([]int, n1+1)
	R := make([]int, n2+1)

	for i := 0; i < n1; i++ {
		L[i] = A[left+i]
	}
	for i := 0; i < n2; i++ {
		R[i] = A[mid+i]
	}

	L[n1], R[n2] = INFTY, INFTY
	i, j := 0, 0
	for k := left; k < right; k++ {
		cnt++
		if L[i] <= R[j] {
			A[k] = L[i]
			i++
			continue
		}
		A[k] = R[j]
		j++
	}
}



Measured memory_bytes: 33080
#include <iostream>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <cmath>
//#include <vector>
#include <string>
//typedef long long LL;
using namespace std;

int main(){
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    s[k-1] += 0x20;
    cout << s << endl;
}

Measured memory_bytes: 256
// Given an array of integers of size ‘n’.
// Our aim is to calculate the maximum sum of ‘k’
// consecutive elements in the array.

/*{{{*/
#include<bits/stdc++.h>
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(), (X).end()
#define rep(I, A, B) for (int I = (A); I <= (B); ++I)
#define repr(I, A, B) for (int I = (A); I >= (B); --I)
#define fors(I, S) for (int I = 0; S[I]; ++I)
#define get_pos(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define mp make_pair
#define pb emplace_back
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X) memset((X), -1, sizeof((X)))
#define len(X) strlen(X)
#define in insert
#define cn count
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef set<int> si;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T, class U> void _W(const pair<T, U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
#define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
#define DEBUG(...)
#endif
int MOD = 1e9 + 7;
/*}}}*/

const int SIZE = 1e6 + 10;

bool isEqual(vi a, vi b) {
	rep(i, 0, sz(a) - 1) {
		if (a[i] != b[i])
			return false;
	}
	return true;
}

void solve() {
	int n;
	R(n);
	int cnt1, cnt2;
	vi ma, p(n), q(n);
	rep(i, 1, n) ma.pb(i);
	rep(i, 0, n - 1) cin >> p[i];
	rep(i, 0, n - 1) cin >> q[i];
	int cnt = 0;
	do {
		cnt++;
		if (isEqual(ma, p))
			cnt1 = cnt;
		if (isEqual(ma, q))
			cnt2 = cnt;
	} while (next_permutation(all(ma)));
	W(abs(cnt1 - cnt2));
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

#define MULTITEST 0
#if MULTITEST
	CASET {
		solve();
	}
#else
	solve();
#endif
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  int d[n];
  for(int i = 0; i < n; i++){
    cin >> d[i];
  }
  sort(d, d + n, greater<int>());
  int ans = d[(n / 2) - 1] - d[(n / 2)];
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+1;
int n, k, a[100], dp[N];
bool f(int cnt)
{
	if( cnt == 0 ){
		return 0;
	}
	int &dp = ::dp[cnt];
	if( dp != -1 )
		return dp;
	dp = 0;
	for(int i=0; i<n; ++i){
		if( cnt - a[i] >= 0 )
			dp |= !f(cnt - a[i]);
	}
	return dp;
}
int main()
{
	memset(dp, -1, sizeof dp);
	cin >> n >> k;
	for(int i=0; i<n; ++i)
		cin >> a[i];
	bool yes = f(k);
	cout << ( yes ? "First" : "Second" );
}

Measured memory_bytes: 5376
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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; }

int N,M,ans;
bool g[50][50];
bool visited[50];

void dfs(int v){
    visited[v]=1;
    rep(i,N){
        if(!g[v][i])continue;
        if(visited[i])continue;
        dfs(i);
    }
}

int main(){
    cin>>N>>M;
    int a[M],b[M];

    rep(i,N){
        rep(j,N){
            g[i][j]=0;
        }
    }
    rep(i,M){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
        g[a[i]][b[i]]=1;
        g[b[i]][a[i]]=1;
    }

    rep(i,M){
        g[a[i]][b[i]]=0;
        g[b[i]][a[i]]=0;
        rep(j,N)visited[j]=0;
        dfs(0);
        rep(j,N){
            if(!visited[j]){
                ans++;
                break;
            }
        }
        g[a[i]][b[i]]=1;
        g[b[i]][a[i]]=1;
    }
    out(ans);

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n, m;
	cin >> n >> m;
	vector<int> s(m), c(m);
	vector<int> ans(n);
	rep(i, m) {
		cin >> s[i] >> c[i];
		s[i]--;
		if (ans[s[i]] && ans[s[i]] != c[i]) {
			cout << -1 << endl;
			return 0;
		}
		if (n != 1 && s[i] == 0 && c[i] == 0) {
			cout << -1 << endl;
			return 0;
		}
		ans[s[i]] = c[i];
	}
	if (ans[0] == 0 && n != 1) ans[0] = 1;
	for (int i : ans) cout << i;
	cout << endl;
}


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

typedef long long ll;

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

    int N;

    cin >> N;

    vector<int> a(N + 1);

    for(int i = 1; i < N + 1; i++) {
        cin >> a[i];
    }

    vector<int> b(N + 1);

    int ans = 0;

    for(int i = N; i > 0; i--) {
        int mul = 2;
        int count = 0;
        while(i * mul < N + 1) {
            count += b[i * mul];
            mul++;
        }
        if(count % 2 != a[i]) {
            b[i] = 1;
            ans++;
        }
    }

    cout << ans << endl;

    if(ans) {
        for(int i = 1; i < N + 1; i++) {
            if(b[i]) {
                cout << i << " ";
            }
        }
    }

    cout << endl;
}

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

int main() {
    int n;
    string s,t;
    cin>>s>>t;
    n=stoi(s+t);
    for (int i=0;i<100000;i++){
        if (i*i==n){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;

}



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

int main(){
  int n;
  cin >> n;
  int m=0,h,i;
  for(i=0;i<n;i++){
    cin >> h;
    if(h<=m-2){
      cout << "No" << endl;
      return 0;
    }
    m=max(m,h);
  }
  
  cout << "Yes" << endl;
}

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}



use std::cmp;
use std::iter::Iterator;

fn main() {
    input! {
        a:usize,
        b:usize,
        c:usize,
    }

    debug!(a);
    println!("{} {} {}", c ,a ,b)



}



Measured memory_bytes: 2096
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
const int inf = 1e9;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
char dc[5] = "NESW";

struct state{
	int x,y,d;
	state(int x, int y, int d):x(x),y(y),d(d){}
	state(){}
	bool operator<(const state &a) const{
		return x!=a.x? x<a.x: y!=a.y? y<a.y: d<a.d;
	}
};

int main(){
	int n,sx,sy,t;
	cin >> n >> sx >> sy >> t;
	
	bool adj[51][51][4];
	memset(adj, 0, sizeof(adj));
	for(int i=0; i<n; i++){
		int xs,ys,xe,ye;
		cin >> xs >> ys >> xe >> ye;
		if(xs == xe){
			if(ys > ye) swap(ys, ye);
			for(int y=ys; y<ye; y++){
				adj[xs][y][0] = true;
				adj[xs][y+1][2] = true;
			}
		}else{
			if(xs > xe) swap(xs, xe);
			for(int x=xs; x<xe; x++){
				adj[x][ys][1] = true;
				adj[x+1][ys][3] = true;
			}
		}
	}
	
	set<state> curr;
	for(int i=0; i<4; i++){
		if(adj[sx][sy][i]){
			curr.insert(state(sx, sy, i));
		}
	}
	for(int i=0; i<t; i++){
		int d;
		char last;
		cin >> d >> last;
		int ld;
		for(int i=0; i<4; i++){
			if(dc[i] == last) ld = i;
		}
		for(int j=0; j<d; j++){
			set<state> next;
			for(state e: curr){
				int nx = e.x +dx[e.d];
				int ny = e.y +dy[e.d];
				for(int dir=0; dir<4; dir++){
					if((dir+2)%4 == e.d) continue;
					if(!adj[nx][ny][dir]) continue;
					if(j==d-1 && dir!=ld && e.d!=ld) continue;
					next.insert(state(nx, ny, dir));
				}
			}
			curr = next;
		}
	}
	
	set<state> unique;
	for(state e: curr){
		unique.insert(state(e.x, e.y, 0));
	}
	for(state e: unique){
		cout << e.x << " " << e.y << endl;
	}
	return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <cstdio>


using namespace std;

const int max_n=100;
int n;
int a[max_n];

int Select_sort(int a[],int n)
{
    int cnt=0;
    for(int i=0;i<n-1;++i)
    {
        int min_j=i;
        for(int j=i+1;j<n;++j)
        {
            if(a[j]<a[min_j])
            {
                min_j=j;
            }
        }
        if(min_j!=i)
        {
            a[min_j]^=a[i];
            a[i]^=a[min_j];
            a[min_j]^=a[i];
            cnt++;
        }
    }
    return cnt;
}


int main()
{
    //  输入数据
    scanf("%d",&n);
    for(int i=0;i<n;++i)
    {
        scanf("%d",&a[i]);
    }

    int cnt=Select_sort(a,n);

    for(int i=0;i<n-1;++i)
    {
        cout<<a[i]<<' ';
    }
    cout<<a[n-1]<<endl;
    cout<<cnt<<endl;

    return 0;
}



Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    
    int A,B,C,D;
    
    cin >> A >> B >> C >> D;
    
    int L = A + B,R = C + D;
    
    if(L > R){
        
        cout << "Left" << endl;
        
    }else if(L < R){
        
        cout << "Right" << endl;
        
    }else{
        
        cout << "Balanced" << endl;
        
    }
    
    
    
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br   = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String	strStdin = null;

		while((strStdin = parseStdin()) != null) {
			for (int nA = 1; nA < 26; nA += 2) {
				if (nA == 13) {
					continue;
				}
				for (int nB = 0; nB < 26; nB++) {
					if (strStdin.contains(encode("this", nA, nB)) || strStdin.contains(encode("that", nA, nB))) {
						System.out.println(decode(strStdin, nA, nB));
					}
				}
			}
		}
	}

	private static String encode(String strNum, int nA, int nB) {
		String	strTmp = "";
		int		nTmp   = 0;

		for (char c : strNum.toCharArray()) {
			// Ck = APk + K (mod M)
			if (Character.isLowerCase(c)) {
				nTmp = (nA * (c - 'a') + nB) % 26 + 'a';
				c    = (char)nTmp;
			}
			strTmp += c;
		}

		return strTmp;
	}

	private static String decode(String strNum, int nA, int nB) {
		String	strTmp = "";
		int		nInvA  = inverse(nA);
		int		nTmp   = 0;

		for (char c : strNum.toCharArray()) {
			// Pk = A-1(Ck - K) (mod M)
			if (Character.isLowerCase(c)) {
				nTmp = (nInvA * (c - 'a' - nB + 26)) % 26 + 'a';
				c    = (char)nTmp;
			}
			strTmp += c;
		}

		return strTmp;
	}

	private static int inverse(int nA) {
		int	nInvA  = 0;

		switch (nA) {
        case 1:
        	nInvA = 1;
        	break;
        case 3:
        	nInvA = 9;
        	break;
        case 5:
        	nInvA = 21;
        	break;
        case 7:
        	nInvA = 15;
        	break;
        case 9:
        	nInvA = 3;
        	break;
        case 11:
        	nInvA = 19;
        	break;
        case 15:
        	nInvA = 7;
        	break;
        case 17:
        	nInvA = 23;
        	break;
        case 19:
        	nInvA = 11;
        	break;
        case 21:
        	nInvA = 5;
        	break;
        case 23:
        	nInvA = 17;
        	break;
        case 25:
        	nInvA = 25;
        	break;
		}

		return nInvA;
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

Measured memory_bytes: 24140
import math

n = int(input())
xs = []
for _ in range(5):
    xs.append(int(input()))


# TLE
def sim(n, xs):
    state = [n] + [0] * 5
    step = 0
    while state[5] < n:
        moves = [min(state[i], xs[i]) for i in range(5)]
        for i in range(5):
            state[i] -= moves[i]
            state[i + 1] += moves[i]
        step += 1

    return step


def solve(n, xs):
    return math.ceil(n / min(xs)) + 4


print(solve(n, xs))

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descsort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    int h,w,n;
    cin>>h>>w>>n;
    int ma=max(h,w);
    cout<<n/ma+(n%ma?1:0)<<endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  if(N%K==0) cout << 0 << endl;
  else cout << 1 << endl;
  return 0;
}


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

int main()
{
	int64_t n, p;
	string s;
	cin >> n >> p >> s;

	if (p == 2 || p == 5)
	{
		int64_t ans = 0;

		for (int64_t i = 0; i < n; i++)
		{
			if ((s[i] - '0') % p == 0)
			{
				ans += (i + 1);
			}
		}

		cout << ans << endl;

		return 0;
	}

	auto pow_mod = [](int64_t a, int64_t n, int64_t mod) {
		int64_t r = 1;
		for (; n; n >>= 1)
		{
			if (n & 1)
			{
				(r *= a) %= mod;
			}
			(a *= a) %= mod;
		}
		return r;
	};

	reverse(s.begin(), s.end());

	vector<int64_t> dp(n + 1, 0);
	dp[0] = 0;
	for (int64_t i = 0; i < n; i++)
	{
		dp[i + 1] = (pow_mod(10, i, p) * (s[i] - '0') % p + dp[i]) % p;
	}

	vector<int64_t> cnt(10001, 0);

	int64_t ans = 0;

	for (auto &&x : dp)
	{
		ans += cnt[x]++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 ll gcd(ll a,ll b){
   if(b == 0) return a;
   gcd(b,a%b);
 }
int main() {
  ll A,B,C,D;
  cin >> A >> B >> C >> D;
  ll lcm = (C/gcd(C,D))*D;
  ll U = B-A +1;
  ll nc = B/C - (A-1)/C;
  ll nd = B/D - (A-1)/D;
  ll ncd = B/lcm - (A-1)/lcm;
 
  cout << U -(nc + nd -ncd) << endl;
  
}

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

int main(void) {

    int N;
    cin >> N;
    int A[N+10];
    for(int i = 0; i < N; i++) cin >> A[i];

    sort(A, A+ N);


    for(int i = 0; i < N; i++){
        if(i == N){
            break;
        }
        if(A[i] == A[i+1]){
            cout << "NO" << endl;
            return 0;
        }
        
    }
    cout << "YES"  << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include <cmath>
using namespace std;
int main()
{   int n;
    cin>>n;
    int height[n];
    for(int i=0;i<n;i++)
        cin>>height[i];
    int dp[n];
    dp[0]=0;
    if(n>1); 
       dp[1]=abs(long (height[1]-height[0]));
    for(int i=2;i<n;i++)
      { dp[i]=min(dp[i-1]+abs(long (height[i]-height[i-1])),dp[i-2]+abs(long(height[i]-height[i-2])));
           

      }
   cout<<dp[n-1];
     system("pause");
    return 0;
}


Measured memory_bytes: 1272
#include <iostream>
using namespace std;
int main(void){
  int n,a[100],ans=0;
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i];
  for(int i=0;i<n-1;i++){
    for(int j=n-1;j>i;j--){
      if(a[j-1]>a[j]){
	swap(a[j-1],a[j]);
	ans++;
      }
    }
  }
  for(int i=0;i<n-1;i++)
    cout<<a[i]<<" ";
  cout<<a[n-1]<<endl;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3080
import math

def readInt():
	return int(input())

def readInts():
	return list(map(int, input().split()))

def readChars():
	return input().split()

s = reversed(input())

ai = 0
si = 0

p = 2019
countarr = [0]*2019

for i, j in enumerate(s):
	ai = (int(j)*pow(10,i,p))%p
	si = (si+ai)%p
	countarr[si]+=1

res = countarr[0]
for i in range(p):
	c = countarr[i]
	res += c*(c-1)//2

print(res)

Measured memory_bytes: 9216
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(int*)b - *(int*)a; // 大きい順
}

//　min
int main(void){
  long int n, m;
  long int x[100001] = {0};
  long int d[100001] = {0};
  long int ans = 0;

  scanf("%ld%ld", &n, &m);

  // 訪れたい座標がコマの数よりも少ない、もしくは同じなら移動なし。
  if(n >= m){
    printf("0\n");
    return 0;
  }

  // 訪れたい座標の取得
  for(int i = 0; i < m; i++){
    scanf("%ld", &x[i]);
  }

  // 座標を並び替え
  qsort(x, m, sizeof(long int), compare_int);
  /*
  for(int i = 0; i < m; i++){
    printf("%ld\n", x[i]);
  }
  */

  // 距離を測定
  for(int i = 1; i < m; i++){
    d[i] = x[i - 1] - x[i];
  }

  // 距離を並び替え
  qsort(d, m, sizeof(long int), compare_int);
  
  // 距離が離れているところに石を置く。
  for(int i = n-1; i < m; i++){
    ans += d[i];
  }

  printf("%ld\n", ans);
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  for (int i = 0;i < n;i++){
    cin >> p.at(i);
  }
  for (int i = 0;i < n;i++){
    cin >> q.at(i);
  }
  
  int f = 1;
  for (int i = 0;i < n;i++){
    f *= i+1;
  }
  
  map<vector<int>, int> m;
  int iter = 0;
  
  vector<int> v(n);
  for (int i = 0;i < n;i++){
    v.at(i) = i+1;
  }

  for (int i = 0;i < f;i++){
    m[v] = iter;
    iter++;
    next_permutation(v.begin(), v.end());
  }
  
  cout << abs(m[p] - m[q]) << endl; 
}

Measured memory_bytes: 8628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
int main(void){
    int h,w,n;cin>>h>>w>>n;
    vector<int>v;int x;
    rep(i,n){
        cin>>x;
        rep(j,x)v.push_back(i+1);
    }
    vector<vector<int>>Grid(h,vector<int>(w));
    rep(i,h){
        if(i%2==0){
            rep(j,w)Grid.at(i).at(j)=v.at(w*i+j);
        }
        else{
            rep(j,w)Grid.at(i).at(w-1-j)=v.at(w*i+j);
        }
    }
    rep(i,h){
        rep(j,w-1)cout<<Grid.at(i).at(j)<<' ';
        cout<<Grid.at(i).at(w-1)<<endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll max_n = 2500010;
const ll mod = 1000000007;
vector<ll> fac(max_n);
vector<ll> ifac(max_n);

ll mpow(ll x, ll n){
    ll ans = 1;
    while(n){
        if(n % 2){
            ans = ans * x % mod;
        }
        x = x * x % mod;
        n >>= 1;
    }
    return ans;
}

ll comb(ll a, ll b){
    if(a == 0 && b == 0) return 1;
    if(a < 0 || b < 0) return 0;
    if(a < b) return 0;
    ll tmp = ifac[b] * ifac[a-b] % mod;
    return tmp * fac[a] % mod;
}



int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    ll X, Y;cin>>X>>Y;
    if((X+Y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }

    ll a = (2 * Y - X) / 3;
    ll b = (2 * X - Y) / 3;

    //ll N = X+Y;  //ここを変えたらコンパイルエラーが出なくなった
    ll N = a+b+10;
    fac[0] = 1;
    ifac[0] = 1;
    REP(i,N){
        fac[i+1] = fac[i] * (i+1) % mod; // fac[i] = n! % mod;
        ifac[i+1] = ifac[i] * mpow(i+1,mod-2) % mod; // ifac[i] = (i!) * pow(i, mod-2) % mod;
    }

    cout << comb(a+b,a) << endl;

}

Measured memory_bytes: 39296
#include <iostream>
#include<math.h>
using namespace std;

int main(){
    long long A,B,V,W ,T;
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;
    if(T*(V-W)>=abs(B-A)){
        cout << "YES";
    }else{
        cout << "NO";
    }
}

Measured memory_bytes: 3128
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

string S,T;

LL ans = 0;

void solve(){
	for(int i=0;i<S.size();i++){
		ans += (S[i]!=T[i]);
	}
}

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

    solve();

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

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N,K;
LL V[1001];
priority_queue<LL,vector<LL>,greater<LL> >que;

int main(){
	cin>>N>>K;
	REP(i,N){
		cin>>V[i];
	}
	LL ans=0;
	REP(i,51){
		REP(j,51){
			if(i+j>K)continue;
			if(i+j>N)continue;
			//cout<<i<<" "<<j<<endl;
			REP(l,i){
				que.push(V[l]);
			}
			REP(l,j){
				que.push(V[N-1-l]);
			}
			int res=K-i-j;
			REP(l,res){
				if(que.empty()){
					break;
				}
				LL a=que.top();
				if(a<0){
					que.pop();
				}
			}
			LL now=0;
			while(que.empty()==false){
				LL a=que.top();
				que.pop();
				now+=a;
			}
			ans=max(ans,now);
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;

int N;

void dfs(string s, char mx){
    if(s.length() == N){
        cout << s << endl;
    }else{
        for(char c = 'a'; c <= mx; c++){
            dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx));
        }
    }
}

int main(){
    cin >> N;
    dfs("", 'a');
    return 0;
}

Measured memory_bytes: 1536
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-8;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int x, k, d;
    cin >> x >> k >> d;
    auto m = abs(x) / d;
    if (k <= m) {
        cout << min(abs(x + d * k), abs(x - d * k)) << endl;
        return;
    }

    k -= m;
    if (x > 0)
        x -= d * m;
    else
        x += d * m;
    k %= 2;
    cout << min(abs(x + d * k), abs(x - d * k)) << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}

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

#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define beg begin
#define dbg(x) cerr << #x << " = " << x << endl;

template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}

template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i;
    }
    return str;
}

template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}

template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}

void solve(); signed main() {
#ifdef LOCAL
    freopen("C:\\Users\\artma\\CLionProjects\\problems\\input.txt", "r", stdin);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();
    return 0;
}

const int MOD = 1e9 + 7, MAXN = 1e6 + 10, INF = 1e18 + 10, BASE = 37;

void solve() {
    int n, s;
    cin >> n >> s;
    if (s > n) {
        cout << -1 << endl;
        return;
    }
    if (n == s) {
        cout << n + 1 << endl;
        return;
    }

    int K = (int)sqrt(max(n, s)) + 1;
    int ans = INF;
    for (int b = 2; b <= 2 * K + 1; ++b) {
        int sum = 0;
        int N = n;
        while (N > 0) {
            sum += N % b;
            N /= b;
        }
        if (sum == s) {
            ans = min(ans, b);
        }
    }

    for (int a1 = 1; a1 <= 2 * K + 1; ++a1) {
        if ((n - s) % a1 == 0) {}
        int b = (n - s) / a1 + 1;
        if (b >= 2) {
            int sum = 0;
            int N = n;
            while (N > 0) {
                sum += N % b;
                N /= b;
            }
            if (sum == s) {
                ans = min(ans, b);
            }
        }
    }

    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3596
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""

from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def floor(a, b):
    """floor(a/b) 整数値を返す"""
    c = (a - a % b)/b
    return int(c)


def main():

    def dfs(x):
        lunlun.append(x)
        d = x % 10
        if len(str(x)) == 11:
            return

        for v in [d+1, d, d-1]:
            if 0 <= v <= 9:
                dfs(x*10+v)

    K = int(input())
    cnt = 0
    lunlun = []

    for i in range(1, 10):
        dfs(i)

    lunlun.sort()
    print(lunlun[K-1])


if __name__ == '__main__':
    main()


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

void solve(int TestCase) {
    int n;
    cin >> n;

    if(n <= 9) {
        cout << to_string(n) << endl;
        return;
    }

    vector<set<string>> A(2);
    for(auto i = 0; i < 10; ++i)
    {
        A[1].insert(to_string(i));
    }

    n -= 9;
    while(true) {
        set<string> s;
        int c = 0;
        for(auto& x : A.back())
        {
            for(auto i = 0; i < 10; ++i)
            {
                if(abs(x[0] - '0' - i) <= 1) {
                    s.insert(to_string(i) + x);
                    if(i) c++;
                }
            }
        }

        if(n <= c) {
            for(auto& x : s)
            {
                if(x[0] == '0')
                    continue;
                if(n == 1)
                {
                    cout << x << endl;
                    return;
                }
                n--;
            }
        }

        n -= c;
        A.push_back(s);
    }
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i) {
    //    cout << "Case #"<< i << ": ";
        solve(i);
    }
}

Measured memory_bytes: 19840
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for i in range(N):
        d[A[i]-1] += 1
        d[A[i]] += 1
        d[A[i]+1] += 1
    print(max(d.values()))
if __name__ == '__main__':
    main()

Measured memory_bytes: 20028
// G++ MACRO.CPP -STD=C++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>

#define pb(a) push_back(a)
#define mp make_pair


int main(){
  CIN(n);VC1(n,a);
  int cnt=0;
  REP(i,n-1)
    if(a[i]==a[i+1]){++cnt;++i;}
    COUT(cnt);

  return 0;
}


Measured memory_bytes: 764
package main

import (
	"bufio"
	"flag"
	"fmt"
	"io"
	"math/big"
	"os"
)

var reader *bufio.Reader
var writer *bufio.Writer

var inputFile = flag.String("input", "", "")

func init() {
	flag.Parse()
	var i io.Reader
	if *inputFile != "" {
		i, _ = os.Open(*inputFile)
	} else {
		i = os.Stdin
	}
	reader = bufio.NewReaderSize(i, 1<<20)
	writer = bufio.NewWriterSize(os.Stdout, 1<<20)
}

func println(a ...interface{}) {
	_, _ = fmt.Fprintln(writer, a...)
}

func printf(format string, a ...interface{}) {
	_, _ = fmt.Fprintf(writer, format, a...)
}

func scanf(format string, a ...interface{}) {
	_, _ = fmt.Fscanf(reader, format, a...)
}

func scan(a interface{}) {
	_, _ = fmt.Fscan(reader, a)
}

func NextInt64() int64 {
	var res int64
	scan(&res)
	return res
}

func NextInt() int {
	var res int
	scan(&res)
	return res
}

func NextIntArray(n int) []int {
	res := make([]int, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		scan(&res[i])
	}
	return res
}

func NextString() string {
	var res string
	scan(&res)
	return res
}

func NextBigInt() *big.Int {
	n := new(big.Int)
	n, _ = n.SetString(NextString(), 10)
	return n
}

func AbsInt64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func MinInt64(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func MaxInt64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func MaxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	defer writer.Flush()

	n := NextInt()
	m := NextInt()

	g := make([][]int, n)

	for i := 0; i < m; i++ {
		u := NextInt() - 1
		v := NextInt() - 1

		g[u] = append(g[u], v)
	}

	cache := make([]int, n)
	var solve func(x int ) int

	solve = func(x int ) int {
		if cache[x] != 0 {
			return cache[x]
		}
		for _, to := range g[x] {
			t := solve(to) + 1
			if t > cache[x] {
				cache[x] = t
			}
		}
		return cache[x]
	}

	answer := 0

	for i := 0; i < n; i++ {
		t := solve(i)
		if t > answer {
			answer = t
		}
	}

	println(answer)
}


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

int main() {
	vector<int> abcde(5);
	for(int i = 0; i < 5; i++)
	{
		cin >> abcde.at(i);
	}
	
	int k; cin >> k;
	bool frag = true;

	for(int i = 0; i < 4; i++)
	{
		for(int j = i + 1; j < 5; j++)
		{
			if (k < abcde.at(j) - abcde.at(i)) {
				frag = false;
				break;
			}
			
		}
		if (!frag) {
			break;
		}
		
	}
	
	
	if (frag) {
		cout << "Yay!" << endl;
	} else {
		cout << ":(" << endl;
	}
}

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second


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

    for(ll i=-2000; i<=2000; i++)
    {
        for(ll j=-2000; j<=2000; j++)
        {
            tmp = i*i*i*i*i - j*j*j*j*j;
            if (tmp == x) return cout << i << ' ' << j << '\n' , 0;
        }
    }


    return 0;
}

Measured memory_bytes: 3636
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from math import pi, atan2

a, b, x = [int(x) for x in input().split()]
# a, b, x = [2, 2, 4]
# a, b, x = [12, 21, 10]
# a, b, x = [3, 1, 8]

s = x / a

if s < (a * b) / 2:
    # w = (2 * s) / b コース
    w = (2 * s) / b
    rad = atan2(b, w)
else:
    # h = ((a * b - s) * 2) / a コース
    h = ((a * b - s) * 2) / a
    rad = atan2(h, a)

# radian から角度への変換 [radian に (180 / pi) をかける]
print(rad * (180 / pi))


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mk make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }



int main() {
	int n;
	cin >> n;
	vector<ll> c;
	vector<ll> z(200001,0);
	vector<ll> ans(n, 1);
	rep(i, n) {
		ll c2;
		cin >> c2;
		if (i > 0 && c[c.size() - 1] == c2) {

		}
		else {
			c.push_back(c2);
		}
	}
	z[c[0]] = 1;
	FOR(i,1, c.size()) {
		ans[i] = ans[i - 1] + z[c[i]];
		z[c[i]] += ans[i - 1];
		ans[i] %= mod;
		z[c[i]] %= mod;
	}
	cout << ans[c.size() - 1] << endl;
}



Measured memory_bytes: 5492
<?php
// C
define('BLACK', '#');
define('WHITE', '.');
fscanf(STDIN, '%d %d', $h, $w);
for ($i  = 0; $i < $h; $i++) {
    $s[] = trim(fgets(STDIN));
}
$g = array_fill(0, $h * $w, []);
for ($i  = 0; $i < $h * $w; $i++) {
    $l = intval(floor($i / $w));
    $m = $i % $w;

    if ($s[$l][$m] === WHITE) continue;

    // 上
    if ($l > 0 && $s[$l - 1][$m] === BLACK) continue;
    // 右
    if ($m < $w - 1 && $s[$l][$m + 1] === BLACK) continue;
    // 下
    if ($l < $h - 1 && $s[$l + 1][$m] === BLACK) continue;
    // 右
    if ($m > 0 && $s[$l][$m - 1] === BLACK) continue;

    exit('No');
}
echo 'Yes';

Measured memory_bytes: 4728
# -*- coding: utf-8 -*-
 
a = list(map(int,input().split()))

A, B, C, K = a[0], a[1], a[2], a[3]

if ( K <= A ):
  print(K)
elif ( K <= A+B ):
  print(A)
elif ( K <= A+B+C ):
  print(2*A+B-K)
else:
  print(A-C)

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

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

    vector<int>A(N);

    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        A.at(i)--;
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (A.at(i) == i) {
            if (i != N-1) swap(A.at(i), A.at(i+1));
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 640
import sys

data = sys.stdin.readline().strip().split(' ')
w = int(data[0])
h = int(data[1])
x = int(data[2])
y = int(data[3])
r = int(data[4])

if x-r >= 0 and y-r >= 0 and x+r <= w and y+r <= h:
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 7700
import * as fs from 'fs'

const input = fs.readFileSync('/dev/stdin', 'utf8');
const args: string[][] = input.split('\n').map(l => l.split(' '));

const n = parseInt(args[0][0])
const a = args[1].map(x => parseInt(x));

const m = Array(n).fill(0);

a.forEach(x => {
  m[x - 1]++;
});

m.forEach(x => {
  console.log(x);
})


Measured memory_bytes: 62172
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define inf (int)(1e18)

typedef struct {
	int L;
	int R;
}pair;

signed compair(const void *a, const void *b){
	int sub = (((pair *)a)->L + ((pair *)a)->R) - (((pair *)b)->L + ((pair *)b)->R);
	if(sub > 0){
		return -1;
	}
	else if(sub == 0){
		return 0;
	}
	else{
		return 1;
	}
}

int min(int a, int b){
	return a <= b ? a : b;
}

signed main(){
	int N, i, j, k, l;
	scanf("%lld", &N);
	pair *ps = (pair *)malloc(sizeof(pair) * N);
	for(i = 0; i < N; i++){
		scanf("%lld%lld", &ps[i].L, &ps[i].R);
	}
	qsort(ps, N, sizeof(pair), compair);
	int ***dp = (int ***)malloc(sizeof(int **) * (N / 2 + 2));
	for(i = 0; i <= N / 2 + 1; i++){
		dp[i] = (int **)malloc(sizeof(int *) * (N / 2 + 2));
		for(j = 0; j <= N / 2 + 1; j++){
			dp[i][j] = (int *)malloc(sizeof(int) * (N % 2 + 1));
			for(k = 0; k <= N % 2; k++){
				dp[i][j][k] = inf;
			}
		}
	}
	dp[0][0][0] = 0;
	for(i = 0; i <= N / 2; i++){
		for(j = 0; j <= N / 2; j++){
			for(k = 0; k <= N % 2; k++){
				l = i + j + k;
				if(l >= N){
					continue;
				}
				dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k] + i * (ps[l].L + ps[l].R) + ps[l].R);
				dp[i][j + 1][k] = min(dp[i][j + 1][k], dp[i][j][k] + j * (ps[l].L + ps[l].R) + ps[l].L);
				if(k == 0 && N % 2 == 1 && l < N){
					dp[i][j][1] = min(dp[i][j][1], dp[i][j][0] + (N / 2) * (ps[l].L + ps[l].R));
				}
			}
		}
	}
/*	for(i = 0; i < N; i++){
		for(j = 0; j < N; j++){
			for(k = 0; k <= N % 2; k++){
				printf("dp[%lld][%lld][%lld] = %lld\n", i, j, k, dp[i][j][k]);
			}
		}
	}
*/	printf("%lld\n", dp[N / 2][N / 2][N % 2]);
	return 0;
}

Measured memory_bytes: 244860
N = int(input())
T = [int(i) for i in input().split()]
M = int(input())

P = []
X = []
for i in range(M):
    p,x = (int(i) for i in input().split())
    P.append(p)
    X.append(x)

add = 0
for i in T:
    add += i

for i in range(M):
    ans = add
    Y = T[P[i]-1] - X[i]
    ans = ans - Y
    print(ans)



    

Measured memory_bytes: 3064
N,W = map(int, input().split())
dp = [0]*(W+1)
temp = [0]*(W+1)

for i in range(1,N+1):
    v,w = map(int,input().split())
    for j in range(1, W+1):
        if w <= j and v + temp[j-w] > temp[j]:
            dp[j] = temp[j-w]+v
    temp[0:W+1] = dp[0:W+1]

print(dp[W])

Measured memory_bytes: 6664
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
using namespace std;

ll solve(ll x)
{
    ll cnt=1;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
        {
            cnt++;
            while(x%i==0)
            {
                x/=i;
            }
        }
    }
    if(x>1)
        cnt++;
    return cnt;
}

ll gcd(ll a,ll b)
{
    while(b)
    {
        ll t=b;
        b=a%b;
        a=t;
    }
    return a;
}

int main(){
    ll a,b;
    scanf("%lld%lld",&a,&b)==2;
    ll x=gcd(a,b);
    printf("%lld\n",solve(x));
	return 0;
}


Measured memory_bytes: 3804