akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }

int n, k;
vector<pair<int, int>> vp;
vector<int> G[100100];
vector<int> d(100100, 0), p(100100, -1);

void dfs(int v) {
  for (int u: G[v]) {
    if (u == p[v]) continue;
    d[u] = d[v] + 1;
    p[u] = v;
    dfs(u);
  }
}

bool ng() {
  int f = (vp[0].second + d[vp[0].first]) % 2;
  FOR(i, 1, k) {
    if ((vp[i].second + d[vp[i].first]) % 2 != f) return true;
  }
  return false;
}

vector<int> minv(100100, -inf), maxv(100100, inf);
vector<bool> visited(100100, false);

void bfs() {
  rep(i, k) minv[vp[i].first] = maxv[vp[i].first] = vp[i].second;
  priority_queue<pair<int, int>> pq;
  rep(i, k) pq.push({d[vp[i].first], vp[i].first});
  while (pq.size()) {
    int v = pq.top().second;
    pq.pop();
    if (v == 0) continue;
    if (visited[v]) continue;
    visited[v] = true;
    chmax(minv[p[v]], minv[v] - 1);
    chmin(maxv[p[v]], maxv[v] + 1);
    if (minv[p[v]] > maxv[p[v]]) {
      cout << "No\n";
      exit(0);
    }
    pq.push({d[p[v]], p[v]});
  }
}

vector<int> ans(100100, inf);

void dfs2(int v) {
  for (int u: G[v]) {
    if (u == p[v]) continue;
    if (minv[u] <= ans[v] + 1 && ans[v] + 1 <= maxv[u]) {
      ans[u] = ans[v] + 1;
      dfs2(u);
    }
    else {
      ans[u] = ans[v] - 1;
      dfs2(u);
    }
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n;
  cin >> n;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  cin >> k;
  vp.resize(k);
  rep(i, k) {
    cin >> vp[i].first >> vp[i].second;
    vp[i].first--;
  }

  dfs(0);
  if (ng()) {
    cout << "No\n";
    return 0;
  }
  bfs();
  cout << "Yes\n";
  ans[0] = minv[0];
  dfs2(0);
  rep(i, n) cout << ans[i] << '\n';





  




  
  return 0;
}

Measured memory_bytes: 15896
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
int a[200010],b[200010],ans[200010];
int main() {
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; i++)scanf("%d",a+i);
	for(int i=n;i>=1;i--){
		int cmp=0,kmp=0;
		for(int o=i;o<=n;o+=i)cmp+=a[o],kmp+=b[o];
		if(kmp%2==a[i])b[i]=0;
		else b[i]=1,ans[++ans[0]]=i;
	}
	sort(b+1,b+1+b[0]);
	printf("%d\n",ans[0]);
	for(int i=1;i<=ans[0];i++)printf("%d ",ans[i]);
}

Measured memory_bytes: 2944
#include <stdio.h>

int main(void)
{
	int h, w, k;
	char map[8][8];
	int i, j, mh, mw, b, ans = 0;

	scanf("%d%d%d", &h, &w, &k);

	for (i = 0; i < h; i++)
	{
		scanf("%s", map[i]);
	}

	for (mh = 0; mh < 1<<h; mh++)
	{
		for (mw = 0; mw < 1<<w; mw++)
		{
			b = 0;
			for (i = 0; i < h; i++)
			{
				for (j = 0; j < w; j++)
				{
					if (((mh >> i) & 1) == 0 && ((mw >> j) & 1) == 0 && map[i][j] == '#') b++;
				}
			}
			if (b == k) ans++;
		}
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 1736
while True:
  a, op, b = input().split()
  a = int(a)
  b = int(b)
  if(op == "?") :
    break
  elif(op == "+") :
    print(a + b)
  elif(op == "-") :
    print(a - b)
  elif(op == "*") :
    print(a * b)
  else :
    print(a // b)


Measured memory_bytes: 5592
N = int(input())
S = [input() for i in range(N)] 
s = []
for i in range(N):
  s+=["".join(sorted(S[i]))]
s.sort()
s+=[""]
before=s[0]
num=0
num2=1
for i in range(1,N+1):
#  print(num2)
  if s[i]==before:num2+=1
  else:
    if num2>1:
      num+=num2*(num2-1)//2
      num2=1
    before=s[i]
print(num)

Measured memory_bytes: 17808
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int n;
    cin >> n;
    cout << (n/2)*(n/2+n%2) << endl;

    return 0;
}

Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
X=int(input())
num=0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k==X:
                num+=1

print(num)


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/02  Problem: 088_arc_b / Link: https://abc083.contest.atcoder.jp/tasks/arc088_b?lang=en  ----- */
/* ------問題------

0 と 1 からなる文字列 S が与えられます。 以下の操作を好きな回数繰り返すことで S の要素をすべて 0 にできるような、|S| 以下の最大の整数 K を求めてください。
S の長さ K 以上の連続する区間 [l,r] を選ぶ(すなわち、r−l+1≥K が満たされる必要がある)。l≤i≤r なるすべての整数 i に対し、Si が 0 なら Si を 1 に、Si が 1 なら Si を 0 に置き換える。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	string s; cin >> s;

	ans = SZ(s);
	
	FOR(i, 0, SZ(s)-1) {
		if (s[i] != s[i + 1]) {
			ans = min(ans, (LL)max(i + 1, SZ(s) - (i + 1)));
		}
	}


	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

int main(void)
{
	string s;
	cin >> s;
	
	int m = atoi(s.substr(5, 2).c_str()), d = atoi(s.substr(7, 2).c_str());
	if(m <= 4) cout << "Heisei" << endl;
	else cout << "TBD" << endl;
	
	return 0;
}

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define MAX_N 20
int m[MAX_N][MAX_N];

int dfs(ll x, ll y) {

  if (m[x][y] != 0)
    return m[x][y];

  int res = 1;

  for (int i = x - 2, j = y + 1; i >= 0; i -= 2, j += 1) {
    res = min(res, dfs(i, j));
  }

  for (int i = x + 1, j = y - 2; j >= 0; j -= 2, i += 1) {
    res = min(res, dfs(i, j));
  }

  if (res == -1)
    m[x][y] = 1;
  else
    m[x][y] = -1;

  return m[x][y];
}

int main() {

  ll x, y;
  cin >> x >> y;

  /*
  // 1  -> Alice Win
  // -1 -> Alice Lose

  m[0][0] = -1;
  m[1][0] = -1;
  m[0][1] = -1;
  m[1][1] = -1;

  REP(i, 10) REP(j, 10) dfs(i, j);

  REP(i, 19) {
    REP(j, 19) {
      if (m[i][j] == 0)
        cout << "0";
      else if (m[i][j] > 0)
        cout << "W";
      else
        cout << "L";

      cout << " ";
    }
    cout << endl;
  }

  */

  if (x - y <= 1L and x - y >= -1L) {
    cout << "Brown" << endl;
  } else {
    cout << "Alice" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
N = int(input())
S = {}
for i in range(N):
    tmp = input()
    if tmp in S:
        S[tmp] += 1
    else:
        S[tmp] = 1

most_com = max(S.values())
keys = [k for k,v in S.items() if v == most_com]
keys.sort()

for i in range(len(keys)):
    print(keys[i])


Measured memory_bytes: 32096
#include<iostream>

using namespace std;

// 判定問題用
#define yes "YES"
#define no "NO"
// 短縮実験(Aiが10^9までなので)
// #define long long int lli -> 失敗

// Problem https://atcoder.jp/contests/agc010/tasks/agc010_a
/**
 * 戦略:偶数+偶数なら答えも偶数→1操作につき1つ偶数削除
 * 奇数+奇数なら答えは偶数→1操作につき奇数が2こ削除偶数が1つ追加
 * 偶数だけなら最後は1つまで削除、奇数は偶数個あれば全部偶数だけになり他の偶数に混ざるが
 * 奇数個であると最後に「奇数が」1つだけ残る。偶数も1つだけ残る。
 * よって奇数が奇数個あるかないか調べれば良い
 * かりに奇数が奇数個あれば 全数の合計が 奇数*奇数+偶数*(偶数or奇数)でこれば奇数になるので
 * この数で判定できる
 */
bool solver(int number){
    bool result;
    result = true;
    long long int allSum;
    long long int inputNo;
    allSum=0;
    for(int j=0;j<number;j++){
        inputNo=0;
        cin >> inputNo;
        allSum = allSum+inputNo;
    }
    if(allSum % 2 == 1){ // 合計が奇数の時2つ必ず残る
        result = false;
    }
    return result;
}

int main(void){
    bool answer;
    answer= true;
    int N;
    cin >> N;
    answer = solver(N);
    if(answer){
        cout << yes << endl;
    }
    else{
        cout << no << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int V[5];
    int li = -1;
    int x = 999;
    for(int i = 0; i < 5 ; i++){
        cin >> V[i];
        int tmp = V[i]%10;
        if(tmp < x && tmp != 0){
            x = tmp;
            li = i;
        }
    }
    int ans = 0;
    for(int i = 0; i < 5 ; i++){
        if(i == li){
            ans += V[i];
        }else{
            int x = V[i]%10;
            x = 10 - x;
            if(x!= 10){
                ans += (V[i]+x);
            }else{
                ans += V[i];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define M 100000

int binarySearch(int [ ], int , int );

int main (){
	int n, S[M],q,i,fact;
	int count = 0;
	scanf("%d",&n);
	for(i = 0; i < n ; i++){
		scanf("%d",&S[i]);
	}
	scanf("%d",&q);
	for(i = 0; i < q ; i++){
		scanf("%d",&fact);
		if( binarySearch(S,n,fact)) count++;
	}
	printf("%d\n",count);
}

int binarySearch(int R[ ],int n,int x) {
	int left = 0;
	int right = n;
	int mid;
	while(left < right){
		mid = (left + right) /2;
		if(R[mid] == x){
			return mid;
		}else if(x < R[mid]){
			right = mid;
		}else {
			left = mid +1;
		}
	}
	return 0;
}


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

int main() {
  int a[100010];
  int n;
  cin>>n;
  for (int i=0; i<n; i++) {
    scanf("%d",a+i);
  }

  int ans=1;
  bool p=false,m=false;
  for (int i=0; i<n-1; i++) {
    if (!p&&!m) {
      if (a[i]<a[i+1]) p=true;
      if (a[i]>a[i+1]) m=true;
    }
    if (p)
      if (a[i]>a[i+1]) {
	p=false;
	ans++;
      }
    if (m)
      if (a[i]<a[i+1]) {
	m=false;
	ans++;
      }
  }

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

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

int main() {
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    int x = i+1;
    if(x%3==0 || x%10 ==3){
      cout << " " << i+1;
      continue;
    }
    while(x/=10){
      if ( x % 10 == 3 ){
      cout << " " << i+1;
      break;
      }
    }
  }
  cout << endl;
}


Measured memory_bytes: 3092
#include<iostream>
using namespace std;
int a[5000];
int b[5000][5000];
int main() {
	int n;
	while (cin >> n&&n != 0) {
		int sum = -100000;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			if (i == 0) {
				b[0][i] = a[i];
				if (sum < b[0][i])
					sum = b[0][i];
			}
			else {
				b[0][i] = b[0][i - 1] + a[i];
				if (sum < b[0][i])
					sum = b[0][i];
			}
		}
		
		for (int j = 1; j < n; j++) {
			for (int i = j; i < n ; i++) {
				b[j][i] = b[j - 1][i] - a[j - 1];
				if (sum < b[j][i])
					sum = b[j][i];
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 32620
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define forn(i,a,b) for(long long i=a;i<=b;i++)
#define fork(i,a,b,k) for(long long i=a;i<=b;i+=k)
using namespace std;
typedef long long ll;
int n,k,a[105],ans[100005];
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>k;
	forn(i,1,n)cin>>a[i];
	forn(i,1,k)ans[i]=0;
	for(ll i=1;i<=k;i++){
		for(ll j=1;j<=n;j++){
			if(a[j]<=i){
				if(ans[i-a[j]]==0){
					ans[i]=1;
					break;
				}
			}
		}
	}
	if(ans[k]==1)cout<<"First";
	else cout<<"Second";
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
const int N=400005;
int n;
long long k;
int a[N];
int pos[N],nxt[N];
int f[N][60];
int vis[N];
int main()
{
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),a[i+n]=a[i];
	for(int i=n*2;i>=1;i--)
		nxt[i]=pos[a[i]],pos[a[i]]=i;
	f[0][0]=1;
	for(int i=n;i>=1;i--)
		if(nxt[i]>n)
		{
			if(nxt[i]==n+n) f[i][0]=0;
			else f[i][0]=nxt[i]-n+1;
		}
		else
		{
			if(nxt[i]==n) f[i][0]=1;
			else f[i][0]=f[nxt[i]+1][0];
		}
	for(int i=1;i<=log2(k);i++)
		for(int u=0;u<=n;u++)
			f[u][i]=f[f[u][i-1]][i-1];
	int p=0;
	for(int i=0;i<=log2(k);i++)
		if(k&(1LL<<i)) p=f[p][i];
	stack<int>s;
	for(int i=p;i<=n;i++)
	{
		if(vis[a[i]])
		{
			while(!s.empty()&&s.top()!=a[i]) vis[s.top()]--,s.pop();
			if(!s.empty()) vis[s.top()]--,s.pop();
		}
		else s.push(a[i]),vis[a[i]]++;
	}
	vector<int>res;
	while(!s.empty()) res.push_back(s.top()),s.pop();
	reverse(res.begin(),res.end());
	for(int u:res)
		printf("%d ",u); 
	return 0;
}

Measured memory_bytes: 56716
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    vector<int> a(n), b(m);
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    for(int z=x+1; z<=y;z++){
        bool downz=true, upz=true;
        rep(i,n){
            if(a[i]>=z)downz = false;
        }
        rep(i,m){
            if(b[i]<z)upz = false;
        }
        if(downz&&upz){
            cout<<"No War"<<endl;
            return 0;
        }
    }
    cout<<"War"<<endl;
    
}


Measured memory_bytes: 256
'use strict'

function Main(input) {
  const list = input.split('');
  let answer = 0;

  for(let i=0; i<4; i++) {
    if(list[i] === '+') {
      answer++;
    } else {
      answer--;
    }
  }

  console.log(answer);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define Task ""

using namespace std;
typedef long long ll;

const int maxn = 2e5 + 5;

struct BIT
{
    int cnt[maxn];
    void init(void)
    {
        fill(begin(cnt), end(cnt), 0);
    }
    void update(int i, int v)
    {
        for(; i<=maxn-5; i+=i&-i){
            cnt[i] += v;
        }
    }
    int sum(int i)
    {
        int res = 0;
        for (; i; i-=i&-i){
            res += cnt[i];
        }
        return res;
    }
}ft;

int N, a[maxn];

bool check(int x)
{
    vector<int> sum(N + 5);
    for (int i=1; i<=N; ++i){
        if (a[i] <= x) sum[i] = sum[i-1] + 1;
        else sum[i] = sum[i-1] - 1;
    }
    ft.init();
    ft.update(N + 1, 1);
    ll res = 0;
    for (int i=1; i<=N; ++i){
        res += ft.sum(sum[i] + N);
        ft.update(sum[i] + N + 1, 1);
    }
    ll val = ( 1ll * N * ( N + 1)) / 2;
    val /= 2;
    return res >= val + 1;
}

signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen("A.INP", "r")){
        freopen("A.INP", "r", stdin);
        freopen("A.OUT", "w", stdout);
    }
    if (fopen(Task".INP", "r")){
        freopen(Task".INP", "r", stdin);
        freopen(Task".OUT", "w", stdout);
    }
    cin >> N;
    for (int i=1; i<=N; ++i){
        cin >> a[i];
    }
    int l=1, r=1e9, mid;
    while (l <= r){
        mid = (l + r) / 2;
        if (check(mid)) r = mid - 1;
        else l = mid + 1;
    }
    cout << l << '\n';
    return 0;
    for (int i=1; i<=30; ++i)
        cerr << i << ' ' << check(i) << '\n';
}


Measured memory_bytes: 1796
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int c = 0;
    string s , t;
    cin >> s >> t;
    for( int i = 0 ; i < s.length() ; i++ ) if( s[i] != t[i] ) c++;
    cout << c;
}


Measured memory_bytes: 3884
N = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(N):
    if p[i] == i+1 and i<N-1:
        p[i+1]=p[i]
        ans += 1
    elif p[i] == N and i == N-1:
        ans +=1
    else:
        continue
print(ans)


Measured memory_bytes: 52908
from collections import defaultdict

N, K = map(int, input().split())
sum = 0
array = defaultdict(int)
for i in range(N):
    a, b = map(int, input().split())
    array[a]+= b

array = sorted(array.items(), key = lambda x: x[0])
for i in range(10 ** 5 + 1):
    sum += array[i][1]
    if sum >= K:
        print(array[i][0])
        exit()

Measured memory_bytes: 15328
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
using ll = long long;
int dd[] = { 0, 1, 0, -1, 0 }; //→↓←↑

void solve()
{
	int N, L;
	cin >> N >> L;
	vector<int> A(N);
	map<int, int> M;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		M[A[i]]++;
		if (i == L - 1)
		{
			cout << M.begin()->first;
		}
		if (L <= i)
		{
			M[A[i - L]]--;
			if (M[A[i - L]] == 0)
			{
				M.erase(A[i - L]);

			}
			cout << " " << M.begin()->first;
		}
	}
	cout << endl;
}

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


Measured memory_bytes: 11360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

#define PT pair<ll, int>

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


	int N, M, L;
	cin >> N >> M >> L;
	ll C[301][301];
	rep1(i, N) rep1(j, N) C[i][j] = 1e16;
	rep1(i, N) C[i][i] = 0;
	rep(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		C[a][b] = c;
		C[b][a] = c;
	}

	rep1(k, N) rep1(i, N) rep1(j, N) {
		C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
	}

	rep1(i, N) rep1(j, N) {
		if (C[i][j] <= L) C[i][j] = 1;
		else C[i][j] = 1e16;
	}

	rep1(k, N) rep1(i, N) rep1(j, N) {
		C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
	}

	int Q;
	cin >> Q;
	rep(i, Q) {
		int s, t;
		cin >> s >> t;
		if (C[s][t] < 1e16) co(C[s][t] - 1);
		else co(-1);
	}


	Would you please return 0;
}

Measured memory_bytes: 1280
import sys
for s in sys.stdin:
  a=map(int,s.split(" "))
  w=a[0]
  a=sorted(a[1:])
  A=[]
  try:
    while a:
      A+=[a.pop(0)]
      A=[a.pop()]+A
      A+=[a.pop()]
      A=[a.pop(0)]+A
  except: pass
  a=A[0]+A[-1]
  for i in range(len(A)-1): a+=2*(A[i]*A[i+1])**.5
  print ["OK","NA"][a>w]

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

using namespace std;

int main(void) {
    int dish[5];
    for (int i = 0; i < 5; i++) {
        cin >> dish[i];
    }

    int min_mod10 = 50;
    for (int i = 0; i < 5; i++) {
        if (dish[i] % 10 != 0) {
            if (dish[i] % 10 < min_mod10) {
                min_mod10 = dish[i] % 10;
            }
            dish[i] = (dish[i] / 10 + 1) * 10;
        }
    }

    int sum = 0;
    for (int i = 0; i < 5; i++) {
        sum += dish[i];
    }

    if (min_mod10 == 50) {
        cout << sum << endl;
    } else {
        cout << sum - 10 + min_mod10 << endl;
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

signed main() {
	string s;
	while(cin >> s) {
		while (s.size() != 1) {
			string tmp = "";
			rep (j, s.size() - 1){
				tmp += '0' + ((s[j] - '0') + (s[j + 1] - '0')) % 10;
			}
			s = tmp;
		}
		cout << s << endl;
	}
}


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

#define EQ(a,b) (abs((a)-(b)) < EPS)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define sz size()
#define all(a) (a).begin(),(a).end()

using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;

const D EPS = 1e-8;
const D PI = acos(-1);

namespace std{
  bool operator<(const P &a,const P &b){
    return EQ(real(a),real(b))?imag(a)<imag(b):real(a)<real(b);
  }
  bool operator==(const P &a, const P &b){return EQ(a,b);}
}

//for vector

inline D dot(P x, P y){return real(conj(x)*y);}

inline D cross(P x, P y){return imag(conj(x)*y);}

//rotate a point counter-clockwise on the origin
inline P rotate(P v, D s){
  return P(real(v)*cos(s) - imag(v)*sin(s), real(v)*sin(s) + imag(v)*cos(s) );
}

inline int ccw(P a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;   //counter clockwise
  if (cross(b,c)<-EPS) return -1; //clockwise
  if (dot(b, c)<-EPS) return 2;   //c--a--b on line
  if (abs(b)+EPS<abs(c)) return -2;   //a--b--c on line
  return 0;                       //on segment
}

inline bool is_cp(L a,L b){
  if(ccw(a.fs,a.sc,b.fs)*ccw(a.fs,a.sc,b.sc)<=0)
    if(ccw(b.fs,b.sc,a.fs)*ccw(b.fs,b.sc,a.sc)<=0)return true;
  return false;
}

inline D seg_p_dis(L a,P x){
  if(dot(a.sc-a.fs,x-a.fs)<EPS)return abs(x-a.fs);
  if(dot(a.fs-a.sc,x-a.sc)<EPS)return abs(x-a.sc);
  return abs(cross(a.sc-a.fs,x-a.fs))/abs(a.sc-a.fs);
}

inline D seg_seg_dis(L a,L b){
  D res = 1e10;
  res = min(res,seg_p_dis(a,b.fs));
  res = min(res,seg_p_dis(a,b.sc));
  res = min(res,seg_p_dis(b,a.fs));
  res = min(res,seg_p_dis(b,a.sc));
  return res;
}

int main(){
  int n,m,l;
  while(cin >> n >> m >> l, n){
    vector< vector<L> > stars(n);
    for(int i=0;i<n;i++){
      int x,y,a,r;
      cin >> x >> y >> a >> r;
      P c = P(x,y);

      vector<P> v;
      P p = P(0,r);
      for(int j=0;j<5;j++){
	v.push_back(c+rotate(p,PI*(a+j*72)/180));
      }
      
      vector<L> l;
      for(int j=0;j<5;j++){
	l.push_back(L(v[j],v[(j+2)%5]));
	l.push_back(L(v[j],v[(j+3)%5]));
      }
      stars[i] = l;
    }

    vector< vector<D> > g(n, vector<D>(n,0));
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	D dis = 1e9;
	for(L a : stars[i]){
	  for(L b : stars[j]){
	    if(is_cp(a,b))dis = 0;
	    else dis = min(dis, seg_seg_dis(a,b));
	  }
	}
	g[i][j] = g[j][i] = dis;
      }
    }

    for(int k=0;k<n;k++){
      for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	  g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
	}
      }
    }

    cout << fixed << setprecision(9) << g[m-1][l-1] << endl;
  }
}	

Measured memory_bytes: 1420
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    float a,k;
    if(n%2==0)
    {
        a=n/2;
    }
    else
    {
        a=(n+1)/2;
    }
    k=a/n;
    cout << k;
    return 0;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int N = sc.nextInt();
			int K = sc.nextInt();
			int[] nums = new int[N];
			for (int i = 0; i < N; i++) {
				nums[i] = sc.nextInt();
			}
			long total = 0;
			long no = 0;
			for (int i = N - 1; i > 0; i--) {
				for (int j = i - 1; j >= 0; j--) {
					if (nums[j] > nums[i]) {
						total++;
					}else if(nums[j] < nums[i]) {
						no ++;
					}
				}
			}
			long div = 1000000007;

			BigDecimal k = new BigDecimal(K).multiply(new BigDecimal(K + 1)).divide(new BigDecimal(2));
			BigDecimal NO =  new BigDecimal(K).multiply(new BigDecimal(K - 1)).divide(new BigDecimal(2));
			long ans = k.multiply(new BigDecimal(total)).add(NO.multiply(new BigDecimal(no))).remainder(new BigDecimal(div)).longValue();
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 26348
#include <iostream>

using namespace std;

int main()
{
    int n,k,z=1;
    cin>>n;
    cin>>k;
    for(int i=0;i<n;i++){
    if((z*2)<(z+k))
    {z=z*2;
    }else z=z+k;
    }
    cout<<z;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int A,B;cin>>A>>B;
  
  if((A+B)%2==1){
    cout<<"IMPOSSIBLE"<<endl;
  }
  else{
    cout<<(A+B)/2<<endl;
  }
}

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


int main() {
  string a, b;
  cin >> a >> b;
  string ans = "NO";
  if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0])
    ans = "YES";
  cout << ans << endl;
  return 0;
  
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

// Vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
  s << "[";
	for (int i = 0; i < len; i++) {
    if (i > 0) s << ", ";
		s << v[i];
	}
  s << "]";
	return s;
}

// Supports two operations.
// - Updates a single element.
// - Returns a sum of a range.
// Verified: CF573Div1D
class BinaryIndexedTree {
 private:
  int n;
  vector<int> xs;
 public:
  BinaryIndexedTree(int n) : n(n), xs(n) {}

  // Adds x to the i-th element.
  void Add(int i, int x) {
    int cur = i;
    while (cur < n) {
      xs[cur] += x;
      cur = cur | (cur + 1);
    }
  }

  // Returns a sum of a range [l r).
  int SumOfRange(int l, int r) {
    if (l >= r) return 0;
    if (l > 0) {
      return SumOfRange(0, r) - SumOfRange(0, l);
    }
    int s = 0;
    int i = r - 1;
    while (i >= 0) {
      s += xs[i];
      i = (i & (i + 1)) - 1;
    }
    return s;
  }
};

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

  int n;
  cin >> n;
  vector<int> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }

  auto is_valid = [&](int k) {
    if (DEBUG) cout << "k: " << k << endl;

    vector<int> signs(n);
    for (int i = 0; i < n; i++) {
      if (xs[i] >= k) signs[i] = 1;
      else signs[i] = -1;
    }
    vector<int> cs(n + 1);
    for (int i = 0; i < n; i++) {
      cs[i + 1] = cs[i] + signs[i];
    }

    if (DEBUG) cout << "signs: " << signs << endl;
    if (DEBUG) cout << "cs: " << cs << endl;

    BinaryIndexedTree bit(2 * n + 1);
    int64 count = 0;
    for (int i = n; i >= 0; i--) {
      int c = cs[i];
      count += bit.SumOfRange(n + c, 2 * n + 1);
      bit.Add(n + c, 1);
    }

    if (DEBUG) cout << "count: " << count << endl;

    int64 n64 = n;
    int64 total = n64 * (n64 + 1) / 2;
    return count >= (total + 1) / 2;
  };

  int l = 0;
  int r = 1 << 30;
  while (r - l >= 2) {
    int m = (l + r) / 2;
    if (is_valid(m)) {
      l = m;
    } else {
      r = m;
    }
  }
  cout << l << endl;
}

Measured memory_bytes: 2280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
#ifdef LOCAL
#include "../../../DBG/dbg.h"
#endif
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> vec(3);
  rep(i, 3) cin >> vec[i];
  sort(vec.begin(), vec.end());
  if ((vec[0]==vec[1] && vec[1]!=vec[2]) || (vec[1]==vec[2] && vec[1]!=vec[0])) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli n;
	cin>>n;

	map<lli,lli> d;

	REP(i,0,n){
		lli tmp;
		cin>>tmp;
		d[tmp]++;
	}

	queue<lli> q;

	for(auto e:d){
		if(e.second>=4){
			while(q.size())q.pop();
			q.push(e.first);
			q.push(e.first);
		}
		else if(e.second>=2){
			while(q.size()>1)q.pop();
			q.push(e.first);
		}
	}

	if(q.size()<2){
		cout<<0<<endl;
		return 0;
	}
	lli a = q.front();
	q.pop();
	lli b = q.front();

	cout<<a*b<<endl;



	return 0;
}

Measured memory_bytes: 6528
use std::collections::{HashMap, HashSet};
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut it = s.split_whitespace();
    let n: usize = parse!(it);
    let mut g: HashMap<(usize, usize), HashSet<(usize, usize)>> = HashMap::new();
    for i in 1..(n + 1) {
        let mut prev: Option<(usize, usize)> = None;
        for _ in 0..(n - 1) {
            let j = parse!(it);
            let p = if i < j { (i, j) } else { (j, i) };
            if let Some(q) = prev {
                let e = g.entry(q).or_insert(HashSet::new());
                e.insert(p);
            }
            prev = Some(p);
        }
    }

    let mut ret = vec![];
    let mut seen: HashMap<(usize, usize), State> = HashMap::new();
    for i in 0..n {
        for j in 0..n {
            let node = (i + 1, j + 1);
            if i < j && *seen.get(&node).unwrap_or(&Unseen) == Unseen {
                if !dfs(node, &mut seen, &g, &mut ret) {
                    println!("{}", -1);
                    return;
                }
            }
        }
    }
    ret.reverse();
    let mut d: HashMap<(usize, usize), isize> = HashMap::new();
    for &p in &ret {
        d.insert(p, std::isize::MIN);
    }
    let mut is_source: HashMap<(usize, usize), bool> = HashMap::new();
    for i in 0..n {
        for j in 0..n {
            let v = (i + 1, j + 1);
            if v.0 < v.1 {
                is_source.entry(v).or_insert(true);
                if let Some(us) = g.get(&v) {
                    for u in us {
                        is_source.insert(*u, false);
                    }
                }
            }
        }
    }
    for (k, v) in is_source {
        if v {
            d.insert(k, 1);
        }
    }
    for &u in ret.iter() {
        for v in g.get(&u).unwrap_or(&HashSet::new()) {
            if d[v] < d[&u] + 1 {
                let w = d[&u] + 1;
                d.insert(*v, w);
            }
        }
    }
    println!("{}", d.values().max().unwrap());
}

#[derive(PartialEq, Eq)]
enum State {
    Unseen,
    Checked,
    Seen,
}

use State::*;
fn dfs(
    node: (usize, usize),
    seen: &mut HashMap<(usize, usize), State>,
    g: &HashMap<(usize, usize), HashSet<(usize, usize)>>,
    ret: &mut Vec<(usize, usize)>,
) -> bool {
    match seen.get(&node) {
        Some(&Checked) => return false,
        _ => (),
    }
    seen.insert(node, Checked);
    for &v in g.get(&node).unwrap_or(&HashSet::new()) {
        if seen.get(&v) != Some(&Seen) && !dfs(v, seen, g, ret) {
            return false;
        }
    }
    seen.insert(node, Seen);
    ret.push(node);
    true
}


Measured memory_bytes: 612916
// SeeAlso: https://atcoder.jp/contests/abc131/tasks/abc131_e

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int N, K;

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

  int M = (N-1)*(N-2)/2 - K + (N-1);
  
  if (M < (N-1)) {
    print(-1);
	return 0;
  }
 
  print(M);
  REP(i, N-1) {
    print(1, (i+2));
  }
  int s = 2;
  int t = 3;
  REP(i, M - (N-1)) {
    print(s, t);
    t++;
    if (N < t) {
      s++;
      t = s+1;
    }
  }

    return 0;
}


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

int main(){
  string S, T;
  cin >> S >> T;
  
  int s, t;
  s = S.size();
  t = T.size();
  
  int min = t;
  
  for(int i = 0; i < s - t + 1; i++){
    int diff = 0;
    for(int j = 0; j < t; j++){
      if(S.at(i+j) != T.at(j)){
        diff++;
      }
    }
    if( diff < min ){
      min = diff;
    }
  }
  cout << min << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
vector<string> bit;

vector<int> l(8);
int N, A, B, C;

bool used[8];

int solve(int no, int a, int b, int c){
    if(no >= N){
        if(min(a, min(b, c)) <= 0)return 1000000;
        return abs(A - a) + abs(B - b) + abs(C - c) - 30;
    }

    int uno = solve(no+1, a, b, c);
    int ua = solve(no+1, a+l[no], b, c) + 10;
    int ub = solve(no+1, a, b+l[no], c) + 10;
    int uc = solve(no+1, a, b, c + l[no]) + 10;

    return min(uc, min(ub, min(uno, ua)));
}
int main(){
    cin >> N >> A >> B >> C;

    rep(i, N)cin >> l[i];

    cout << solve(0, 0, 0, 0);
    
}

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

int nC2(int n)
{
    return (n*(n-1))/2;
}

void solve()
{
    int n,m;
    cin>>n>>m;
    cout<<nC2(n)+nC2(m);
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 256
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
t1 = t2 = t3 = ti = 0.0
for a, b in zip(x, y):
	d1 = abs(a - b)
	ti = max(ti, d1)
	t1 += d1
	t2 += d1**2
	t3 += d1**3
print(t1)
print(math.sqrt(t2))
print(t3 ** (1.0/3))
print(ti)

Measured memory_bytes: 7840
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	cout << (1 - n) << endl;

	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll a, b;
    cin >> a >> b;
    out(max({a+b, a-b, a*b}));
    re0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner tan = new Scanner(System.in);
        int x,a,b;
        x=tan.nextInt();
        a=x/500;
        b=(x%500)/5;
        System.out.println(a*1000+b*5);
    }
}


Measured memory_bytes: 35720
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int main() {
    int N;
    cin >> N;
    N *= 2;
    int L[MAX_N];
    rep(i, N){ cin >> L[i];}
    sort(&L[0], &L[N]);

    int ret = 0;
    rep(i, N/2){
        ret += min(L[i*2], L[i*2+1]);
    }
    cout << ret << endl;

}

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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) {
    ll a;
    cin >> a;
    --a;
    A[i] = a;
  }
  vector<bool> gone(N, false);
  gone[0] = true;
  ll num = A[0];
  map<ll, ll> mp;
  vector<ll> order(1, 0);
  mp[0] = 0;
  ll cnt = 0;
  while(!gone[num]) {
    gone[num] = true;
    order.push_back(num);
    cnt++;
    mp[num] = cnt;
    num = A[num];
  }
  cnt++;
  ll b = mp[num];
  ll roop = cnt - mp[num];
  if (K-b < 0) {
    printf("%lld\n", order[K]+1);
  }
  else {
    printf("%lld\n", order[b + (K-b)%roop]+1);
  }
}

Measured memory_bytes: 18588
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;

class Program
{
    static void Main(string[] args)
    {
        var (N, M) = ReadLine().Split(' ').Select(int.Parse).ToArray();
        var xyz = Range(0, N).Select(i => ReadLine().Split(' ').Select(long.Parse).ToArray()).ToArray();
        
        static long Sum(long[] xyz, int p) => xyz.Select((v, i) => (p & 1 << i) == 0 ? v : -v).Sum();

        var ans = Range(0, 8).Select(p => xyz.Select(a => Sum(a, p)).OrderByDescending(x => x).Take(M).Sum()).Max();

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 30232
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<functional>

using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);

	int n, m, k;

	scanf("%d %d %d", &n, &m, &k);

	vector<string> grid;

	for (int i = 0; i < n; i++)
	{
		char input[10];
		string str;

		scanf("%s", input);
		str = input;

		grid.push_back(str);
	}

	int rmask = (int)pow(2.0, n);
	int cmask = (int)pow(2.0, m);
	int cell[6][6];

	int sol = 0;

	for (int i = 0; i < rmask; i++)
	{
		vector<int> rows;

		int temp = i;

		for (int z = 0; z < n; z++)
		{
			rows.push_back(temp % 2);

			temp /= 2;
		}

		for (int j = 0; j < cmask; j++)
		{
			memset(cell, 0, sizeof(cell));

			vector<int> cols;

			int temp = j;

			for (int z = 0; z < m; z++)
			{
				cols.push_back(temp % 2);

				temp /= 2;
			}

			for (int z = 0; z < n; z++)
			{
				if (rows[z])
				{
					for (int y = 0; y < m; y++)
					{
						cell[z][y] = 1;
					}
				}
			}

			for (int z = 0; z < m; z++)
			{
				if (cols[z])
				{
					for (int y = 0; y < n; y++)
					{
						cell[y][z] = 1;
					}
				}
			}

			int cnt = 0;

			for (int z = 0; z < n; z++)
			{
				for (int y = 0; y < m; y++)
				{
					if (grid[z][y] == '#' && !cell[z][y])
					{
						cnt++;
					}
				}
			}

			if (cnt == k)
			{
				sol++;
			}
		}
	}

	printf("%d\n", sol);

	return 0;
}

Measured memory_bytes: 3740
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 100005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    srand((unsigned)time(NULL));
    ll D,C = 26;
    cin >> D;
    vector<ll> c(C);
    vector<vector<ll>> s(D,vector<ll>(C));
    cins(all(c));
    rep(i,D){
        rep(j,C){
            cin >> s[i][j];
        }
    }
    vector<ll> t(D);
    cins(all(t));
    vector<vector<ll>> last(D,vector<ll>(C,-1));
    ll ans = 0;
    rep(i,D){
        t[i]--;
        ans += s[i][t[i]];
        last[i][t[i]] = i;
        rep(j,C){
            if (i > 0 && j != t[i]) last[i][j] = last[i-1][j];
            ans -= c[j]*(i-last[i][j]);
        }
    }
    ll q;
    cin >> q;
    rep(_,q){
        ll day,nc;
        cin >> day >> nc;
        day--;
        nc--;
        ll dis = 0;
        dis += s[day][nc];
        dis -= s[day][t[day]];
        rep(j,D){
            if (j >= day && last[j][t[day]] == day){
                if (day == 0){
                    dis -= c[t[day]];
                    last[j][t[day]] = -1;
                }
                else{
                    dis -= c[t[day]]*(day-last[day-1][t[day]]);
                    last[j][t[day]] = last[day-1][t[day]];
                }
            }
            if (j >= day && last[j][nc] < day){
                dis += c[nc]*(day-last[j][nc]);
                last[j][nc] = day;
            }
        }
        ans += dis;
        PRINT(ans);
        t[day] = nc;
    }
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    int cnt = 0;
    rep(i, 0, n) {
        ll x;
        cin >> x;
        if (x % 2) cnt++;
    }
    if (cnt%2) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		long N, M;
		string S, T;
		cin >> N >> M >> S >> T;

		long g = gcd( N, M );
		long n = N / g;
		long m = M / g;
		long ans = M / g * N;
		for( long i = 0; i < g; ++i ) {
			if( S[i*n] != T[i*m] ) {
				ans = -1;
				break;
			}
		}

		cout << ans << endl;
	}

	template<class T> static T gcd( T a, T b ) { return b ? gcd( b, a%b ) : a; }
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 640
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
   int n;
 
   cin >> n;
  
   int a[n];
  
  for(int i = 0;i<n;i++){
     
    cin >> a[i];

   }

  
   int sum = 1;
   int max = a[0];
  
   for(int i = 1;i<n;i++){
     
     if(max<a[i]){
       
       max=a[i];
       
     }
     
     if(max<=a[i]&&a[i-1]<=a[i]){
       
      
         
          sum=sum+1;
         
       
     }
  

   }
   cout << sum << endl;
   
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,d;
    cin>>m>>d;
    int con=0;
    int ar[1000];
   for(int i=0;i<=100;i++)
   {
       ar[i]=0;
   }
    int dd=22,m1=m;
    int ck=0;
     //cout<<"ss"<<endl;
    while(1)
    {
        //cout<<"d="<<d<<" m="<<m<<endl;
        if(d<22||m<2)
        {
            ck=1;
            cout<<"0"<<endl;
            break;
        }
        if(dd<=d)
        {
            int d1=0;
            d1=dd%10;
            int d2=0;
            d2=dd/10;
            //cout<<"dd="<<dd<<endl;
            //cout<<"d1="<<d1<<" d2="<<d2<<endl;
            if(d1*d2<=m)
            {
                if(d1>=2&&d2>=2)
                {
                    ar[d1*d2]+=1;
                     //cout<<"d1*d2="<<d1*d2<<endl;
                }

            }
            dd++;
        }
        else
        {
            break;
        }


    }
    int sum=0;
    for(int i=0;i<=min(m,d);i++)
    {
        if(ar[i]!=0)
        {
            //cout<<"i="<<i<<endl;
            sum+=ar[i];
            //cout<<"ar[i]="<<ar[i]<<endl;
        }
    }
    if(ck==0)
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256