akhauriyash/Code-Regression huggingface dataset:
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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

int solve(){
  int N,x;cin>>N>>x;
  int a[2*N]; rep(n, N){
    cin>>a[n];
    a[N+n] = a[n];
  }
  int dp[2*N][2*N] = {};
  rep(i, 2*N){ dp[i][i] = a[i]; }

  rep(i, 2*N){
    rep(j, i+1, i+N){
      if (j>= 2*N) continue;
      dp[i][j] = min(dp[i][j-1], a[j]);
    }
  }
  dump_2d(dp, 2*N, 2*N);

  int res = INF;
  rep(k, N){
    int tmp = k*x;
    rep(i, N, 2*N){
      tmp += dp[i-k][i];
    }
    chmin(res, tmp);
    dump(k, res, tmp);
  }

  cout << res << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 125312
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  auto divs = divisor(n);
  sort(divs.begin(), divs.end());
  ll left = -1;
  ll right = divs.size();
  while (right - left > 1) {
    ll mid = left + (right - left) / 2;
    ll v1 = divs[mid];
    ll v2 = n / divs[mid];
    if (to_string(v1).size() >= to_string(v2).size())
      right = mid;
    else
      left = mid;
  }
  ll v1 = divs[right];
  ll v2 = n / divs[right];
  cout << max(to_string(v1).size(), to_string(v2).size()) << endl;
  return 0;
}

Measured memory_bytes: 3684
import sys
sys.setrecursionlimit(10**9)

H, N = map(int, input().split())
magic = [_ for _ in range(N)]

for k in range(N):
  magic[k] = list(map(int, input().split()))
  magic[k].append(magic[k][0]/magic[k][1])

magic.sort(key = lambda x: x[2], reverse=True)
ans = [0 for _ in range(H+1)]
visited = [0]
anskouho = [float('inf')]

def solve(start, power, point, maryoku):
  if start == H:
    print(min(point, min(anskouho)))
    exit()
  elif start > H:
    anskouho.append(point)
    #visited.sort(reverse=True)
    return 0
  elif ans[start] != 0:
    #visited.sort(reverse=True)
    return 0
  else:
    visited.append(start)
    ans[start] = point
    solve(start+power, power, point+maryoku, maryoku)

for k in range(N):
  for item in visited:
    solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])

print(min(anskouho))

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

using namespace std;

#define tr(c, i) for (typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define all(c) (c).begin(), (c).end()
#define sz(a) int((a).size())
#define pb push_back
#define fo(i, n) for (int i = 0; i < n; i++)
#define FO(i, k, n) for(int i = k; i < n; i++)
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ii = pair<int, int>;
using ll = long long;


int main(){
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    int n;
    cin >> n;
    int d1[n+1];
    int d2[n+1];
    fo(i, n)
    {
        cin >> d1[i];
        cin >> d2[i];
    }

    for(int i = 2; i < n; i++)
    {
        if (d1[i] == d2[i] && d1[i-1] == d2[i-1] && d1[i-2] == d2[i-2])
        {
            cout << "Yes";
            return 0;
        }
    }

    cout << "No";
    return 0;
}


Measured memory_bytes: 3632
// <------------- Template -----------------------> //


#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(2);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
#define N 1000000007 // prime modulo value 
 
typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	2 * 1e18;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAX5]; ll visit[] = {};

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, y, q, m;
string s, t, d;
ll sum = 0;
ll cou = 0;


// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n;
	vll a(n);
	for(ll i=0;i<n;i++) {
		cin >> a[i];
	}
	sort(all(a));
	x = a[n-1];
	y = 0;
	ll ans = 0;
	for(ll i=0;i<n-1;i++) {
		if(y <= min(a[i],x-a[i])) {
			ans = a[i];
			y = (min(a[i],x-a[i]));
		}
		//cout<<a[i]<<" "<<y;newl;
	}
	cout<<x<<" "<<ans;
}

int main() {
	fastio; randomINT;
	//cin>>T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    int ans = INT_MAX;
    for (int i = 0; i <= n - k; i++) {
        int left = x[i], right = x[i + k - 1];
        ans = min(ans, abs(left) + abs(left - right));
        ans = min(ans, abs(right) + abs(left - right));
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
h,w = list(map(int, input().split()))
a = [input() for _ in range(h)]

compress_row = []

for i in range(h):
    if '#' not in a[i]:
        compress_row.append(i)

compress_col = []
for i in range(w):
    for j in range(h):
        if a[j][i] == '#':
            break
    else:
        compress_col.append(i)

row = []
for i in range(h):
    col = []
    for j in range(w):
        if j in compress_col:
            continue
        col.append(a[i][j])
    if i in compress_row:
        continue
    row.append(col)

print(*[''.join(r) for r in row], sep='\n')

Measured memory_bytes: 9072
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  int l = 1;
  int r = N;
  for(int i=0; i<M; i++){
    int L, R;
    cin >> L >> R;
    l = max(l, L);
    r = min(r, R);
  }
  cout << max(0, r-l+1) << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define ll long long int
#define pb push_back
vector<ll> adj[50001];
int visited[50001];
map<vector<ll>, ll> mp;
void dfs(vector<ll> &v,int u)
{
	// cout<<u<<" ";
	visited[u] = 1;
	v.pb(u);
	for(auto i:adj[u])
	{
		if(!visited[i])
			dfs(v,i);
	}
}

int main(){
	ll n, k;
	cin>>n>>k;
	vector<ll> p(n+1);
	vector<ll> c(n+1);
	int i, j;
	ll ans = LONG_MIN;
	for(i = 1; i <= n; i++)
		cin>>p[i];
	for(i = 1; i <= n; i++){
		cin>>c[i];
		ans = max(ans,c[i]);
	}
	memset(visited,0,sizeof(visited));
	int curr = 1, f = 0;
	while(curr<=n)
	{
		// cout<<curr<<" ";
		if(visited[curr]==1){
			curr++;
			continue;
		}
		// cout<<curr<<" ";
		adj[curr].pb(p[curr]);
		visited[curr] = 1;
		curr = p[curr];
	}
	// cout<<"\n";
	vector<vector<ll>> w;
	memset(visited,0,sizeof(visited));
	for(i = 1; i <= n; i++)
	{
		vector<ll> v;
		if(visited[i]==0){
			dfs(v, i);
			// cout<<"\n";
			w.pb(v);
		}
	}
	int x = w.size();
	vector<ll> sum;
	for(i = 0; i < w.size(); i++)
	{
		ll s = 0;
		for(j = 0; j < w[i].size(); j++)
			s = s + c[w[i][j]];
		sum.pb(s);
		// cout<<s<<" ";
	}
	// cout<<"\n";
	int m;
	for(i = 0; i < w.size(); i++)
	{
		for(j = 0; j < w[i].size(); j++)
		{
			ll s = 0;
			ll r = k%w[i].size();
			ll q = k/w[i].size();
			if(r==0)
			{
				r = w[i].size();
				q--;
			}
			if(sum[i]<0)
			{
				ll lim;
				if(q>=1)
					lim = w[i].size();
				else
					lim = r;
				for(int cnt = 0,m = j; cnt<lim; m++,cnt++)
				{
					s = s + c[w[i][m%w[i].size()]];
					ans = max(ans,s);
				}
				continue;
			}
			s = s + q*sum[i];
			// cout<<w[i].size()<<"\n";
			ans = max(ans , s);
			for(m = j; m < r + j; m++)
			{
				s = s + c[w[i][m%w[i].size()]];
				ans = max(ans,s);
				// cout<<s<<" "<<c[w[i][m%w[i].size()]]<<"\n";
			}
		}
	}
	// cout<<"\n";
	cout<<ans;
}
  

Measured memory_bytes: 5732
//BINARY_BOY!!
//Bool THINK TWICE CODE ONCE = true;
//Im back basterds
//KEEP CALM AND FUCK PYTHON
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <iomanip>
#include <sstream>
#include <limits>
#include <queue>
using namespace std;
const int MAXN = 1e5 + 200;
#define salar long double
#define mp make_pair
#define sp setprecision
#define pb push_back
#define pp pop_back
#define oold numeric_limits<long double>::max()
#define _oold numeric_limits<long double>::min()
#define ooint numeric_limits<int>::max()
#define _ooint numeric_limits<int>::min()
#define ooll numeric_limits<long long>::max()
#define _ooll numeric_limits<long long>::min()
#define ct cout
#define vec vector
#define fx fixed
#define cn cin
#define input readInt()
#define print writeInt
#define pc(x) putchar(x)
typedef long long ll;
#define pii pair < int , int>
#define ppi pair < pair < int , int > , int>

void show(long double a , int x , bool endofline , bool space)
{
	ct << fx << sp(x) << a;
	if(endofline)
		ct << endl;
	if(space)
		ct << ' ';
}
int readInt () {
	bool minus = false;
	int result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch-'0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result*10 + (ch - '0');
	}
	if (minus)
		return -result;
	else
		return result;
}
inline void writeInt (long long n) {
	long long  N = n, rev, count = 0;
	rev = N;
	if (N == 0) { pc('0'); pc('\n'); return ;}
	while ((rev % 10) == 0) { count++; rev /= 10;} //obtain the count of the number of 0s
	rev = 0;
	while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}  //store reverse of N in rev
	while (rev != 0) { pc(rev % 10 + '0'); rev /= 10;}
	while (count--) pc('0');
}
ll i , z , j;
ll ar [ MAXN ] , dp [ MAXN ];
vec < ll > v , v2;
set < ll > st;
pii p;
string s;
bool flag2 , flag ;
void debug() {
	cout << "DEBUGGING\n";
}
int main()
{
	ll n , m;
	cin >> n >> m;
	ll preok = (1LL<<31) - 1;
	for(i = 0 ; i < n + 10 ; i++)
		ar [ i ] = preok;
	for(i = 0 ; i < n + 50 ; i++)
		dp [ i ] = (1LL<<31) - 1;
	ll k = sqrt(n);
	for(i = 0 ; i < n / k; i += k)
		for(j = i ; j < i + k ; j++)
			dp [ i ] = min(dp [i ] , ar[ j ]);
	for(i = 0 ; i < m ; i++)
	{
		ll a;
		a = input;
		if(a)
		{
			ll s1 , e1;
			s1 = input;
			e1 = input;
			if(s1 == e1)
			{
				cout << ar [ s1 ] << endl;
				continue;
			}
			ll minans = (1LL<<31) - 1;
			flag = false;
			for( ; s1 <= e1 && (s1 % k); s1++)
				minans = min(minans , ar [ s1 ]);
			for(j = s1/k ; (j + 1)* k - 1 <= e1 ; j++ , s1 += k , flag = true)
				minans = min(minans , dp [ j ]);
				if(flag)
					s1+= -k;
			for( ; s1 <= e1 ; s1++)
				minans = min(minans , ar [ s1 ]);
			cout << minans << endl;		
		}
		else
		{
			ll ii , x;
			cn >> ii >> x;
			ar [ ii ] = x;
			ii = ii/k;
			ii *= k;
			if(ii + k - 1 < n)
			{
				dp [ ii / k ] = (1LL<<31);
				for(j = 0 ; j < k ; j++)
					dp [ ii / k ] = min(dp [ ii / k ] , ar [ ii + j ]);
			}
		}
		
	}
}



Measured memory_bytes: 4696
package main

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

var sc *bufio.Scanner

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

const MOD = 1000000007

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0), 1000000001*3)
	sc.Split(bufio.ScanWords)
	h, w, a, b := nextInt(), nextInt(), nextInt(), nextInt()

	fact := make([]int, h+w-1)
	inv := make([]int, h+w-1)
	finv := make([]int, h+w-1)
	fact[0], fact[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1
	for i := 2; i < h+w-1; i++ {
		fact[i] = (fact[i-1] * i) % MOD
		inv[i] = MOD - ((inv[MOD%i] * (MOD / i)) % MOD)
		finv[i] = (finv[i-1] * inv[i]) % MOD
	}

	n1, n2 := h-a+b-1, w+a-b-1
	ans := 0
	for k := 0; b+k <= n1 && a+k <= n2; k++ {
		c1 := (fact[n1] * ((finv[b+k] * finv[n1-(b+k)]) % MOD)) % MOD
		c2 := (fact[n2] * ((finv[a+k] * finv[n2-(a+k)]) % MOD)) % MOD
		ans = (ans + ((c1 * c2) % MOD)) % MOD
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

const int INF = 1 << 30;
typedef long long ll;

int main()
{
	int n, c;
	int P[36];
	int L[36];
	
	while(cin >> n >> c)
	{
		int dp[1 << 16][31];

		if(n == 0 && c == 0)
		{
			break;	
		}

		//puts("run");
		memset(dp, -1, sizeof(dp));
		memset(P, 0, sizeof(P));
		memset(L, 0, sizeof(L));

		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < 16; j++)
			{
				int a;
				cin >> a;
				P[i] |= (a << 15-j);
			}
		}
		for(int i = 0; i < c; i++)
		{
			for(int j = 0; j < 16; j++)
			{
				int a;
				cin >> a;
				L[i] |= (a << 15-j);
			}
		}

		dp[0][0] = 0;

		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < 1<<16; j++)
			{
				if(dp[j][i]<0)
				{
					continue;
				}

				int S = j bitor P[i];

				for(int k = 0; k < c; k++)
				{
					int push = S bitand L[k];
					int T = S xor push;
					dp[T][i+1] = max(dp[T][i+1], dp[j][i] + __builtin_popcount(push));
				}
			}
		}

		int res = 0;

		for(int i = 0; i < 1<<16; i++)
		{
			res = max(res, dp[i][n]);
		}

		cout << res << endl;
	}
}

Measured memory_bytes: 9108
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#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 ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
// a^n mod を計算する
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long Combi(ll n, ll a){
  if(n - a < a) return Combi(n, n - a);

  long long res = 1;
  for(ll i = n ; n - a + 1 <= i ; i--){ res *= i;  res %= MOD; }
  for(ll i = 2 ; i <= a ; i++){ res = res * modinv(i, MOD) % MOD; }
  
  return res;
}

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    long long n, a, b;  cin >> n >> a >> b;

    ll ans = modpow(2, n) - 1 - Combi(n, a) - Combi(n , b);
  	while(ans < 0) ans += MOD;
    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int w, h; cin >> w >> h;
		if (w == 0 && h == 0) break;
		vector< vector<int> > a(h, vector<int>(w - 1)), b(h - 1, vector<int>(w));
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w - 1; j++) cin >> a[i][j];
			if (i + 1 == h) continue;
			for (int j = 0; j < w; j++) cin >> b[i][j];
		}
		vector< vector<int> > d(h, vector<int>(w));
		d[0][0] = 1;
		queue<i_i> q;
		q.push(i_i(0, 0));
		while (!q.empty()) {
			i_i p = q.front(); q.pop();
			int i = p.first, j = p.second;
			if (i - 1 >= 0 && !b[i - 1][j] && !d[i - 1][j]) {
				d[i - 1][j] = d[i][j] + 1;
				q.push(i_i(i - 1, j));
			}
			if (i + 1 < h && !b[i][j] && !d[i + 1][j]) {
				d[i + 1][j] = d[i][j] + 1;
				q.push(i_i(i + 1, j));
			}
			if (j - 1 >= 0 && !a[i][j - 1] && !d[i][j - 1]) {
				d[i][j - 1] = d[i][j] + 1;
				q.push(i_i(i, j - 1));
			}
			if (j + 1 < w && !a[i][j] && !d[i][j + 1]) {
				d[i][j + 1] = d[i][j] + 1;
				q.push(i_i(i, j + 1));
			}
		}
		cout << d[h - 1][w - 1] << endl;
	}
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, X, Y;
  cin >> N >> X >> Y;
  X--, Y--;
  vector<vector<int>> G(N);
  for (int i = 0; i < N - 1; i++) {
    G[i].emplace_back(i + 1);
    G[i + 1].emplace_back(i);
  }
  G[X].emplace_back(Y);
  G[Y].emplace_back(X);
  vector<int> res(N, 0);
  for (int i = 0; i < N; i++) {
    vector<int> dist(N, -1);
    dist[i] = 0;
    queue<int> que;
    que.push(i);
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      for (int v : G[u]) {
        if (dist[v] != -1) continue;
        dist[v] = dist[u] + 1;
        que.push(v);
        if (v > i) res[dist[v]]++;
      }
    }
  }
  for (int i = 1; i < N; i++) {
    cout << res[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'

const int N = 200005;
int n, h[N];
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1 ; i <= n ; i ++)
		cin >> h[i];
	int cur = 0, ans = 0;
	h[n + 1] = LLONG_MAX;
	for(int i = n ; i >= 1 ; i --){
		if(h[i] >= h[i + 1]){
			cur ++;
			ans = max(ans, cur);
		}
		else cur = 0;
	}
	cout << ans;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==v.size()?"":" ");
    return os;
}


struct RangeTree{
    // xの各値がyのソート済み配列を持つ
    vector<vector<int>>seg;
    vector<int>x;
    int sz;
    RangeTree(vector<pair<int,int>> a){
        sz=1;
        while((int)a.size()>sz)sz<<=1;
        sort(begin(a),end(a));
        if(a.size())x.push_back(a[0].first);
        for(auto &p:a)if(x.back()!=p.first)x.push_back(p.first);
        while(x.size()<sz)x.push_back(INF);
        seg.resize(2*sz);
        int pos=0;
        for(auto &p:a){
            if(x[pos]!=p.first)pos++;
            seg[pos+sz].push_back(p.second);
        }
        for(int i=sz-1;i>0;i--){
            seg[i].resize(seg[2*i].size()+seg[2*i+1].size());
            merge(begin(seg[2*i]),end(seg[2*i]),begin(seg[2*i+1]),end(seg[2*i+1]),begin(seg[i]));
        }
    }
    // [x1,x2),[y1,y2)
    int count(int x1,int y1,int x2,int y2){
        int l=lower_bound(begin(x),end(x),x1)-begin(x),r=lower_bound(begin(x),end(x),x2)-begin(x);
        l+=sz,r+=sz;
        int ret=0;
        for(;l<r;l>>=1,r>>=1){
            if(l&1){
                ret+=lower_bound(begin(seg[l]),end(seg[l]),y2)-lower_bound(begin(seg[l]),end(seg[l]),y1);
                l++;
            }
            if(r&1){
                r--;
                ret+=lower_bound(begin(seg[r]),end(seg[r]),y2)-lower_bound(begin(seg[r]),end(seg[r]),y1);
            }
        }
        return ret;
    }
};

int c[500010];
map<int,int> pre;

signed main(){

    int n,q;cin>>n>>q;
    rep(i,n) cin>>c[i];

    vector<pair<int,int>> d;
    rep(i,n){
        if(pre.count(c[i])) d.push_back({i,pre[c[i]]});
       pre[c[i]]=i;
    }

    RangeTree seg(d);

    while(q--){
        int l,r;
        cin>>l>>r;l--;

        int ans=r-l-seg.count(l,l,r,r);
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 101916
N, C, K = map(int, input().split())
T = [int(input()) for i in range(N)]
sorted_T = sorted(T)

first = sorted_T[0]
cap = C-1
limit = first + K
ans = 1

for i in range(1, N):
    if (cap > 0) and (sorted_T[i] < limit):
        cap -= 1
    elif (cap == 0) or ((cap > 0) and (sorted_T[i] > limit)):
        cap = C-1
        first = sorted_T[i]
        limit = first + K
        ans += 1

print(ans)

Measured memory_bytes: 8256
def resolve():
    n = int(input())
    s = str(input())
    count = 0
    ans = []
    for i in s:
        if i == 'I':
            count += 1
            ans.append(count)
        if i == 'D':
            count -= 1
            ans.append(count)

    print(max(max(ans), 0))


resolve()

Measured memory_bytes: 3060
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
a_rev = a[::-1]

ok, ng = 1, 200001
while ng-ok > 1:
	x = (ok+ng)//2
	num = 0
	cur = 0
	for i in range(n-1, -1, -1):
		while cur < n and a[i] + a[cur] >= x:
			cur += 1
		num += cur
	if num < m:
		ng = x
	else:
		ok = x
just = ok

ans = 0
larger_cnt = 0
cur = 0

a_cum = [0]
for i in range(n):
	a_cum.append(a_cum[-1] + a[i])

for i in range(n):
	while cur < n and a[i] + a_rev[cur] <= just:
		cur += 1
	larger_cnt += n - cur
	ans += (n - cur) * a[i] + a_cum[n - cur]

ans += just * (m - larger_cnt)
print(ans)

Measured memory_bytes: 61320
#include<cstdio>
#define rep(i,a) for(int i=0;i<(a);++i)

typedef long long ll;

ll N, D[100];
ll dp[100][21];

int main()
{
	scanf( "%lld", &N );
	rep( i, N )
		scanf( "%lld", D+i );

	dp[0][D[0]] = 1;
	rep( i, N-2 ) rep( j, 21 )
	{
		if( j+D[i+1] <= 20 )
			dp[i+1][j+D[i+1]] += dp[i][j];
		if( j-D[i+1] >= 0 )
			dp[i+1][j-D[i+1]] += dp[i][j];
	}

	printf( "%lld\n", dp[N-2][D[N-1]] );

	return 0;
}

Measured memory_bytes: 1020
require 'prime'

N = gets.to_i

pows = []
0.upto(75) do |i|
  0.upto(75) do |j|
    0.upto(75) do |k|
      pows << [i - 1, j - 1, k - 1].select(&:positive?).sort.reverse if i * j * k == 75
    end
  end
end
pows.uniq!

n_primes = Array.new(N + 1, 0)
2.upto(N) do |n|
  n.prime_division.each do |pd|
    n_primes[pd[0]] += pd[1]
  end
end
n_primes.select! { |n| n >= 2 }

ans = pows.inject(0) do |ans, pow_nums|
  a = n_primes.count { |n| n >= pow_nums[0] }
  a *= n_primes.count { |n| n >= pow_nums[1] } - 1 if pow_nums[1]
  a = a * (n_primes.count { |n| n >= pow_nums[2] } - 2) / 2 if pow_nums[2]
  ans + a
end

puts ans

Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()
using ll = long long;
using namespace std;
 
int main() {
    ll n, k; cin >> n >> k;
    vector<ll> pp, mm;
    ll zero = 0;
    rep(i,n) {
        ll a; cin >> a;
        if (a > 0) pp.pb(a);
        else if (a < 0) mm.pb(-a);
        else zero++;
    }
    sort(all(pp)); ll p = (ll)pp.size();
    sort(all(mm)); ll m = (ll)mm.size();
 
    if (p * m >= k) {
        ll left = 1, right = 1ll<<60;
        while (right - left > 1) {
            ll mid = (right + left) / 2;
            ll count = 0; // mid以下になる個数
            ll id = m;
            rep(i,p) {
                while (id > 0 && pp[i] * mm[id - 1] >= mid) id--;
                count += m - id; 
            }
            if (count >= k) left = mid;
            else right = mid;
        }
        cout << -left << endl;
        return 0;
    }
    else if (p * m + (p + m) * zero + zero * (zero - 1) / 2 >= k) {
        cout << 0 << endl;
        return 0;
    }
    else {
        k -= p * m + (p + m) * zero + zero * (zero - 1) / 2;
        ll left = 1, right = 1ll<<60;
        while (right - left > 1) {
            ll mid = (right + left) / 2;
            ll count = 0; // mid以下になる個数
            ll id = p;
            rep(i,p) {
                while (id > 0 && pp[i] * pp[id - 1] > mid) id--;
                count += id;
                if (pp[i] * pp[i] <= mid) count--;
            }
            id = m;
            rep(i,m) {
                while (id > 0 && mm[i] * mm[id - 1] > mid) id--;
                count += id;
                if (mm[i] * mm[i] <= mid) count--;
            }
            if (count < 2 * k) left = mid; 
            else right = mid;
        }
        cout << right << endl;
        return 0;
    }
    return 0;
}


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

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  rep(i, k){
    if(i % 2){
      a += b/2;
      b /= 2;
    } else {
      b += a/2;
      a /= 2;
    }
  }
  cout << a << " " << b << endl; 
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int A[100 + 10], N;
int count;
bool flag;

void bubbleSort(int A[], int N);
void swap(int& a, int& b);
void trace(int A[], int N);

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) { scanf("%d", &A[i]); }

  bubbleSort(A, N);

  trace(A, N);
  printf("%d\n", count);

  return 0;
}

void bubbleSort(int A[], int N) {
  flag = true;

  while (flag) {
    flag = false;
    for (int j = 0; j < N; ++j) {
      if (A[j] < A[j - 1]) { swap(A[j], A[j - 1]); flag = true; }
    }
  }

}

void swap(int& a, int& b) {
  int temp = a;
  a = b;
  b = temp;
  count++;
}

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

Measured memory_bytes: 1032
from random import randint
import sys
input = sys.stdin.readline
INF = 9223372036854775808


def calc_score(D, C, S, T):
    """
    開催日程Tを受け取ってそこまでのスコアを返す
    コンテストi 0-indexed
    d 0-indexed
    """
    score = 0
    last = [0]*26  # コンテストiを前回開催した日
    for d, t in enumerate(T):
        last[t] = d + 1
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
        score += S[d][t]
    return score


def evaluate(D, C, S, T, k):
    """
    d日目終了時点での満足度を計算し，
    d + k日目終了時点での満足度の減少も考慮する
    """
    score = 0
    last = [0]*26
    for d, t in enumerate(T):
        last[t] = d + 1
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
        score += S[d][t]

    for d in range(len(T), min(len(T) + k, D)):
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
    return score


def update_score(D, C, S, T, score, ct, ci):
    """
    ct日目のコンテストをコンテストciに変更する
    スコアを差分更新する

    ct: change t 変更日 0-indexed
    ci: change i 変更コンテスト 0-indexed
    """
    last = [0]*26  # コンテストiを前回開催した日
    for d in range(ct):
        last[T[d]] = d + 1
    prei = T[ct]  # 変更前に開催する予定だったコンテストi
    score -= S[ct][prei]
    score += S[ct][ci]
    for d in range(ct, D):
        if d != ct and T[d] == prei:
            break
        score += C[prei]*(d + 1 - ct - 1)
        score -= C[prei]*(d + 1 - last[prei])
    for d in range(ct, D):
        if d != ct and T[d] == ci:
            break
        score += C[ci]*(d + 1 - last[ci])
        score -= C[ci]*(d + 1 - ct - 1)
    T[ct] = ci
    return score, T


def greedy(D, C, S):
    Ts = []
    for k in range(5, 8):
        T = []  # 0-indexed
        max_score = -INF
        for d in range(D):
            # d+k日目終了時点で満足度が一番高くなるようなコンテストiを開催する
            best_i = 0
            for i in range(26):
                T.append(i)
                score = evaluate(D, C, S, T, k)
                if max_score < score:
                    max_score = score
                    best_i = i
                T.pop()
            T.append(best_i)
        Ts.append((max_score, T))
    res = max(Ts, key=lambda pair: pair[0])
    return res


def local_search(D, C, S, score, T):
    ct = randint(0, D-1)
    ci = randint(0, 25)
    for _ in range(100):
        new_score, new_T = update_score(D, C, S, T, score, ct, ci)
    res = -1
    return res


if __name__ == '__main__':
    D = int(input())
    C = [int(i) for i in input().split()]
    S = [[int(i) for i in input().split()] for j in range(D)]
    init_score, T = greedy(D, C, S)
    for t in T:
        print(t+1)


Measured memory_bytes: 83732
import numpy as np

n,d = list(map(int,input().split()))
dis = []
data = [None] * n
for i in range(n):
  data[i] = [[int(s) for s in input().split()]]
  

count = 0

for i in range(n):
  for j in range(i):
    if data[i] != data[j]:
      a = np.array(data[i])
      b = np.array(data[j])
      l = np.linalg.norm(b-a)
      
      if (l.is_integer()):
        count += 1
print(count)




Measured memory_bytes: 12448
N,K = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]

AB.sort(key = lambda x:x[0])
import math 

K2 = bin(K)
K2 = K2[2:]

L = len(K2)

ans = 0
zeroidx = [L-i-1 for i in range(len(K2)) if K2[i] == '0']

for a,b in AB:
    if a > K: break
    for z in zeroidx:
        if (a>>z)%2 == 1:
            break
    else:
        ans += b
    
MAX = ans
    


for i in range(len(K2)):
    if K2[i] == '0':continue
    
    Knew2 = K2[:i] +'0' +  ''.join(map(str,['1']*(len(K2)-1-i)))
    Knew = int(Knew2,2)
    zeroidx = [L-i-1 for i in range(len(K2)) if Knew2[i] == '0']
    ans = 0
    for a,b in AB:
        if a > Knew: break
        for z in zeroidx:
            if (a>>z)%2 == 1:
                break
        else:
            ans += b
        
    MAX = max(MAX,ans)
    
print(MAX)

    
    

Measured memory_bytes: 68568
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a <= c && b >= c) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }

}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  if (N == 0) {
    cout << 2 << endl;
  }
  if (N == 1) {
    cout << 1 << endl;
  }
  if (N > 1) {
  	vector<int64_t> result(N+1);
  	result.at(0) = 2;
  	result.at(1) = 1;
    int i = 2;
    for (i; i < N+1; i++) {
      result.at(i) = result.at(i-1) + result.at(i-2);
    }
    //cout << result.at(2) << endl;
    cout << result.at(N) << endl;
  }
}


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

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(int N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
	const int N = inputVal<int>();
	string S = inputVal<string>();

	int a = 'A';
	int z = 'Z';

	rep(i, S.size()) {
		int s = S[i];
		int pos = s - a;
		int newpos = (pos + N) % 26;
		S[i] = 'A' + newpos;
	}

	outputVal(S);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	double tmp;
	cin >> tmp;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A,B,C;
		A = sc.nextInt();
		B = sc.nextInt();
		C = sc.nextInt();
		if (B+C<A) {
			System.out.println(0);
		} else {
			System.out.println(B+C-A);
		}
	}
}

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

using namespace std;

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

    int N;
    cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; ++i) {
        cin >> v[i];
    }
    sort(begin(v), end(v));
    double res = v[0];
    for (int i = 1; i < N; ++i) {
        res = (res + v[i]) / 2;
    }

    cout.precision(17);
    cout << fixed << res << "\n";

    return 0;
}

Measured memory_bytes: 256
n = int(input())
x = list(map(int,input().split()))
ans = []
if len(set(x)) == 1:
    print(0)
else: 
    for p in range(min(x), max(x)):
        meter = 0
        for xi in x:
            meter += pow((xi-p),2)
        ans.append(meter)
    print(min(ans))

Measured memory_bytes: 9188
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // KEYENCE-C - Subarray Sum

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();
        int s = sc.nextInt();

        int out = s;
        for (int i = 0; i < n; i++) {
            out = s;
            if (i >= k) {
                if (s < 1000000000) {
                    out++;
                } else {
                    out--;
                }
            }
            System.out.print((i > 0 ? " " : "") + out);
        }

        System.out.println();
    }
}

Measured memory_bytes: 45372
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, i, totalVotes = 0;
    cin >> n >> m;
    int a[n];
    for(i=0; i<n; i++){
        cin >> a[i];
        totalVotes += a[i];
    }
    double m1 = m*4;
    m1 = 1/m1;
    m1 *= totalVotes;
    int cnt = 0;
    for(i=0; i<n; i++){
        if(a[i] >= m1)
            cnt++;
        if(cnt == m){
            cout << "Yes\n";
            exit(0);
        }
    }
    cout << "No\n";
    return 0;
}



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

int n;
vector<int> a;

bool solve(int p, int t) {
  if (a[p] == t) {
    return true;
  }
  if (p == n - 1) {
    return false;
  }
  if (solve(p + 1, t)) {
    return true;
  }
  if (solve(p + 1, t - a[p])) {
    return true;
  }
  return false;
}

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

  cin >> n;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    a.push_back(t);
  }

  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int m;
    cin >> m;
    if (solve(0, m)) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3216
K, N = map(int, input().split())
As = [int(n) for n in input().split()]

maxd = 0

b = 0
for a in As:
    maxd = max(maxd, a - b)
    b = a
maxd = max(maxd, K - As[-1] + As[0])

print(K - maxd)

Measured memory_bytes: 78028
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        int[] array = new int[n];
        boolean[] visited = new boolean[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        ArrayList<Integer> loop = new ArrayList<>();
        loop.add(1);
        visited[0] = true;
        int index = 0;
        int to = array[index] - 1;
        while (!visited[to]) {
            visited[to] = true;
            loop.add(to + 1);
            index = to;
            to = array[index] - 1;
        }
        int loopHead = loop.indexOf(to + 1);
        if (k < loopHead) {
            System.out.println(loop.get((int)k));
        } else {
            k -= loopHead;
            int v = (int)(k % (loop.size() - loopHead));
            System.out.println(loop.get(v + loopHead));
        }
    }
}

Measured memory_bytes: 60584
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin>>s;
    for(int i=s.size()/2-1;i>=0;i--) if(s.substr(0,i)==s.substr(i,i)) {cout<<i*2<<endl; break;}
    return 0;
}


Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

//const ll MOD = 998244353;
const ll MOD = 1e9+7;
 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,a,b,max=0;
  std::cin>>n>>a>>b;
  std::vector<ll> h(n);
  rep(i,0,n){
    std::cin>>h[i];
    max=std::max(max,h[i]);
  }

  ll left=0,right=max/b+1;

  while(right-left>1){
    ll mid=left+(right-left)/2;

    ll count=0;
    rep(i,0,n){
      if(h[i]-mid*b>0){
        count+=(h[i]-mid*b-1)/(a-b)+1;
      }
    }

    if(count<=mid)right=mid;
    else left=mid;
  }

  std::cout<<right;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n, k;
  cin >> n >> k;

  ll ans = 1;
  REP(i, n){
    if(i == 0) ans *= k;
    else ans *= k - 1;
  }

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


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int N,K,C;
int A[200001];
int B[200001];
vector<int> ans;
 
 
 
int main(){
    int k = 0;
    int cntt=0;
    cin >> N >> K >> C;
    int cnt=10000001;
    for(int i=0;i<N;i++){
        char s;
        cin >> s;
        if (s == 'o' && cnt < C){
            A[i] = 1;
            cnt++;
        } else if (s == 'x'){
            A[i] = 0;
            cnt++;
        } else {
            A[i] = 2;
            B[k] = cnt;
            cnt = 0;
            k++;
            cntt = i;
        }
    }
    B[k] = N-cntt-1;
    
    if (k>K){
        return 0;
    }
    int i=N-1;
    int cnttt = C;
    while(k>0){
        for (int j=0;j<B[k]+1;j++){
            if(A[i-j] == 1){
                if(C-j <= cnttt){
                    cnttt = B[k]-j;
                    break;
                }
            }else if(A[i-j] == 2){
                cnttt = 0;
                ans.push_back(i-j+1);
            }
        }
        i -= (B[k]+1);
        k--;
    }
    for(ll j=ans.size()-1;j>=0;j--){
        cout << ans[j] << endl;
    }
    
}

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

struct Card{ char suit, value; };

void bubble(struct Card A[], int N) {
  for(int i = 0; i<N; i++) {
    for(int j = N-1; j >= i; j--) {
      if(A[j].value < A[j-1].value) {
        Card t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(struct Card A[], int N) {
  for(int i=0;i<N;i++) {
    int minj = i;
    for(int j=i; j<N; j++) {
      if(A[j].value < A[minj].value) minj = j;
    }
    Card t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(struct Card A[], int N) {
  for(int i=0; i<N; i++) {
    if(i>0) cout << " ";
      cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
  for(int i=0; i<N; i++) {
    if(C1[i].suit != C2[i].suit) return false;
  }
  return true;
}

int main(void) {
  Card C1[100], C2[100];
  int N;

  cin >> N;
  for(int i=0;i<N; i++) {
    cin >> C1[i].suit >> C1[i].value;
  }

  for(int i=0; i<N; i++) C2[i] = C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  cout << "Stable" << endl;
  print(C2,N);
  if(isStable(C1,C2,N)) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }

  return 0;
}



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

const int INF = 1e9;

int main(){
  int lim = 1e6;
  vector<int> cube;
  for(int i=1;;i++){
    int c = i*(i+1)*(i+2)/6;
    if(c>lim)break;
    cube.push_back(c);
  }

  vector<int> dp1(lim+1,INF), dp2(lim+1,INF);
  dp1[0] = dp2[0] = 0;

  for(int i=0;i<=lim;i++){
    for(int c : cube){
      if(i+c<=lim){
	dp1[i+c] = min(dp1[i+c], dp1[i]+1);
	if(c%2==1){
	  dp2[i+c] = min(dp2[i+c], dp2[i]+1);
	}
      }
    }
  }

  int n;
  while(cin >> n){
    if(n==0)break;
    cout << dp1[n] << " " << dp2[n] << endl;
  }
}

Measured memory_bytes: 8784
import sys
input = sys.stdin.readline

INF = float('inf')
    
def warshall_floyd(V, dist):
    for k in range(V):
        for i in range(V):
            for j in range(V):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    return dist

def check_negative_cycle(V, dist):
    dist = warshall_floyd(V, dist)
    
    for i in range(V):
        if dist[i][i] != 0: return dist, True
        
    return dist, False

def main():
    V, E = list(map(int, input().split()))
    
    dist = [[INF for i in range(V)] for j in range(V)]
    
    for i in range(V): dist[i][i] = 0
    
    for i in range(E):
        s, t, d = list(map(int, input().split()))
        dist[s][t] = min(dist[s][t], d)
    
    dist, negative_cycle = check_negative_cycle(V, dist)
    
    if negative_cycle: print('NEGATIVE CYCLE')
    else: 
        for i in range(V):
            for j in range(V):
                if dist[i][j] == INF: dist[i][j] = 'INF'
            print(' '.join(map(str, dist[i])))

if __name__ == '__main__':
    main()
    


Measured memory_bytes: 6032