akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS

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

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef pair<int, ii> edge;


#define sc(x)  scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(v) (int)v.size()
#define rsz(v) v.resize
#define clr(v) v.clear()
#define rev(v) reverse(all(v))
#define lop(i,end) for(int i=0; i<end; i++)
#define rlop(i,start) for(int i=start-1; i>=0; i--)
#define loop(i,start,end) for(int i=start; i<end; i++)
#define rloop(i,start,end) for(int i=start-1; i>=end; i--)
#define PB push_back
#define pb pop_back
#define mP make_pair
#define f first
#define s second

const ll OO = (ll)(4e18) + 9;
const int MOD = (int)(1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-8;
const double PI = acos(-1.0);

//enum dir { D, R, U, L , dr, ur, dl, ul };
int dx[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiouy"; //and sometimes "aeiouy"

template<typename X, typename Y> bool ckmin(X& a, Y b) { return a > b ? a = b, true : false; }
template<typename X, typename Y> bool ckmax(X& a, Y b) { return a < b ? a = b, true : false; }
bool cklex(string &a, string b) {
	if (b == "") return false;
	if (a == "") return a = b, true;
	if (sz(a) < sz(b)) return false;
	if (sz(b) < sz(a)) return a = b, true;
	if (a < b) return false;
	return a = b, true;
}

int dcmp(ld d1, ld d2) { return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1; } //Compare Double Numbers
ll gcd(ll x, ll y) { return !y ? x : gcd(y, x%y); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
int conv_2_1(int r, int c, int nCol) { return (nCol*r) + c + 1; } //convert index from 2D array to 1D array. (Zero-indexed)
ii conv_1_2(int n, int nCol) { return{ n / nCol, n % nCol }; } //convert index from 1D array to 2D array (row, col). (Zero-indexed)
template<typename T> void inter(T X) { cout << X << endl; fflush(stdout); }


void _solve_() {
	int x;
	cin >> x;
	if (not x) cout << 1 << endl;
	else cout << 0 << endl;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t = 1, tt = 0;
	//cin >> t;
	while (tt++ != t) {
		_solve_();
	}


	return 0;
}


Measured memory_bytes: 3648
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define dump(x)  cout << #x << " = " << (x) << endl;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(4);
    cout << std::fixed;
    // freopen("ex.in","r",stdin);
    // freopen("ex.out","w",stdout);
    ll n;
    cin >> n;
    ll a[n],b[n],c[n-1];
    rp(i,n) cin >> a[i];
    rp(i,n) cin >> b[i];
    rp(i,n-1) cin >> c[i];
    ll ans = 0;
    rp(i,n){

        ll curDish = a[i];
        ans += b[curDish-1];
        if(i != 0 && a[i-1] == curDish - 1)
        {
            ans += c[curDish-2];
        }
    }
    cout << ans;
    cout << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!int;
    auto G = new Tuple!(int, int)[][](N);
    foreach (i; 0..N-1) {
        auto s = readln.split.map!(to!int);
        G[s[0]-1] ~= tuple(s[1]-1, s[2] & 1);
        G[s[1]-1] ~= tuple(s[0]-1, s[2] & 1);
    }

    auto ans = new int[](N);
    ans[] = 2;

    void dfs(int n, int c) {
        if (ans[n] != 2) return;
        ans[n] = c;
        foreach (to; G[n]) {
            if (ans[to[0]] != 2) continue;
            dfs(to[0], c^to[1]);
        }
    }

    dfs(0, 0);
    ans.each!writeln;
}


Measured memory_bytes: 14332
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)

int main(){
    double a, b, xa, xb, ans = -1;
    bool flag = true;
    cin >> a >> b;
    RAP(i,pow(10,4)){
        xa = floor(i*0.08);
        xb = floor(i*0.1);
        if(xa == a && xb == b){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    
    return 0;
}


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

using namespace std;

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

    //初期値は大きい値
    int ans = S.size();

    //iは0番目のタイルに使う色 i==0 => 黒, i==1 => 白
    for (int i = 0; i < 2; i++)
    {
        //iを0番目に使ったときに変えなければならないタイルの数
        int cnt = 0;

        for (int j = 0; j < S.size(); j++)
        {
            /*
            //数値iを文字iへキャスト
            //(char)(0 + '0') -> '0';
            //(char)(1 + '0') -> '1';

            //string型の要素とcharは比較可能
            //0,2,4,...番目が、色iでないならば
            if (j % 2 == 0 && S[j] != (char)(i + '0'))
            {
                cnt++;
            }
            //1,3,5,...番目が、色iであるならば
            if (j % 2 == 1 && S[j] == (char)(i + '0'))
            {
                cnt++;
            }
            */

            //XORの解法
            //左右のオペランドの真偽が一致しないとき、全体として真になる
            //0,2,4,...番目なのに色iでないなら塗り替え
            //1,3,5,...番目なのに色iであるなら塗り替え
            if ( (j % 2 == 0) ^ (S[j] == (char)(i + '0')) )
            {
                cnt++;
            }
            
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,ma=0,a=INT_MAX,l=-1;

void nhap()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        int x;
        scanf("%d",&x);
        if (x<=a)
        {
            l++;
            ma=max(ma,l);
        }
        else
        {
            l=0;
        }
        a=x;
    }
    cout<<ma;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
int main()
{
    ll k;
    ll temp = 7;
    ll count = 1;
    bool flag = false;
    std::cin >> k;

    while (k >= count) {
        if (temp % k == 0) {
            flag = true;
            break;
        } else {
            temp *= 10;
            temp += 7;
            temp %= k;
            ++count;
        }
    }
    if (flag) {
        std::cout << count << std::endl;
    } else {
        std::cout << "-1" << std::endl;
    }
}

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

int main(){
  int n,m;
  cin >>n>>m;
  int a[m][2];
  rep(i,m){
    rep(j,2){
      cin>>a[i][j];
    }
  }
  int bucket[n]={0};
  rep(i,m){
    rep(j,2){
      bucket[a[i][j]-1]++;
    }
  }
  rep(i,n) cout<<bucket[i]<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define DEC(i, s) for (int i = (s); i >= 0; i--)

#define SIZE(v) (int)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())

int main() {
  int test;
  cin >> test;
  while (test--) {
    ll first;
    cin >> first;
    int n, m;
    cin >> n >> m;
    ll ans = 0;
    REP(i, m) {
      ll o, c;
      double rate;
      cin >> o >> rate >> c;
      ll num = first;
      REP(j, n) {
        if (o == 0) {
          num += (first - c * j) * rate;
          num -= c;
          if (num <= 0) { break; }
        } else if (o == 1) {
          num += num * rate;
          num -= c;
          if (num <= 0) { break; }
        }
      }
      ans = max(ans, num);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include<cstdio>
struct Card{
    char color;
    int num;
};
int partition(Card A[],int p,int r)
{
    int i=p-1;
    int j=p;
    int x=A[r].num;
    for(;j<r;j++)
    {
        if(A[j].num<=x)
        {
            i++;
            Card t;
            t=A[j];
            A[j]=A[i];
            A[i]=t;
        }
    }
    Card t;
    t=A[i+1];
    A[i+1]=A[r];
    A[r]=t;
    return i+1;
}
void quickSort(Card A[],int p,int r)
{
    if(p<r)
    {
        int q;
        q=partition(A,p,r);
        quickSort(A,p,q-1);
        quickSort(A,q+1,r);
    }
}
void merge(Card A[],int left,int mid,int right)
{
    int n1=mid-left;
    int n2=right-mid;
    Card M[100000],N[100000];
    for(int i=0;i<n1;i++)
    M[i]=A[left+i];
    for(int i=0;i<n2;i++)
    N[i]=A[mid+i];
    int flag1=0;
    int flag2=0;
    int flag3=0;
    int i;
    for(i=0; i<right-left;i++)
    if(M[flag1].num<=N[flag2].num)
    {
        A[left+i]=M[flag1++];

    //    printf("cs1");
    if(flag1==n1) {flag3=1;break;}
    }
    else{
    A[left+i]=N[flag2++];

    if(flag2==n2) {flag3=2;break;}
    //printf("cs2");
    }
    for(int k=left+i+1;k<right;k++)
    if(flag3==1)
    {
        A[k]=N[flag2++];
        }
    else
    {
        A[k]=M[flag1++];
        }
/*        for(int i=0;i<n;i++)
    {
        if(i!=0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");*/
}
void mergeSort(Card A[],int left,int right)
{
    if(left<right-1)
    {
      //  printf("sss\n");
        int mid;
        mid=(left+right)/2;
        mergeSort(A,left,mid);
        //printf("mmm\n");
        mergeSort(A,mid,right);
        //printf("kkk\n");
        merge(A,left,mid,right);
        //printf("cs3");
    }

}
int main()
{
    int n;
    scanf("%d",&n);
    char S[10];
    Card cards[100000];
    for(int i=0;i<n;i++)
    {
        scanf("%s%d",S,&cards[i].num);
        cards[i].color=S[0];
    }
    Card cards2[100000];
    for(int i=0;i<n;i++)
    {
    cards2[i]=cards[i];
    }
    quickSort(cards,0,n-1);
    mergeSort(cards2,0,n);
    int i;
    for(i=0;i<n;i++)
    if(cards2[i].color!=cards[i].color)
    {
    printf("Not stable\n");
    break;
    }
    if(i==n)
    printf("Stable\n");

    for(int i=0;i<n;i++)
    {
        printf("%c %d\n",cards[i].color,cards[i].num);
    }
    return 0;
}



Measured memory_bytes: 5060
#include <iostream>
#include <vector>
#include <cstdlib>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int N, M;
    cin >> N >> M;
    vector<int> a(N), b(N);
    vector<int> c(M), d(M);
    REP (i, 0, N) cin >> a[i] >> b[i];
    REP (i, 0, M) cin >> c[i] >> d[i];
    REP (i, 0, N) {
        int res = -1;
        int cost = 1 << 30;
        REP (j, 0, M) {
            int len = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (cost > len) {
                res = j + 1;
                cost = len;
            }
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
A = []
B = []
for i in range(N):
    a,b = I()
    A.append(a)
    B.append(b)
num = 0
for i in range(N-1,-1,-1):
    if (A[i]+num)%B[i] == 0:
        k = 0
    else:
        k = B[i]-((A[i]+num)%B[i])
    A[i] += k+num
    num += k
print(num)

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

class pro{
public:
  int t;
  string n;
};

void solve(){
  int n, q; cin >> n >> q;
  vector<pro> a(n + 1);

  for(int i = 0; i < n; i++){
    cin >> a[i].n >> a[i].t;
  }
  int head = 0, tail = n, t = 0;
  while(head != tail){
    pro x = a[head++];
    if(x.t > q){
      x.t -= q;
      a[tail++] = x;
      t += q;
    }
    else{
      t += x.t;
      cout << x.n << " " << t << endl;
    }
    head %= (n+1);
    tail %= (n+1);
  }
  return;
}

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



Measured memory_bytes: 5996
#!/usr/bin/perl

while (<>) {
    ($n, $m) = split /\s/, $_;
}

$mh = sprintf("%d", $m / 2);
if ($mh <= $n) {
    $max = $mh;
} else {
    $dm = $n * 2;
    $a = $m - $dm;
    $add = sprintf("%d", $a / 4);
    $max = $n + $add;
}

print "$max\n";


Measured memory_bytes: 512
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    s1 = gets.chomp
    s2 = gets.chomp.reverse

    if s1 == s2
      puts "YES"
    else
      puts "NO"
    end

  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int n, x;
  cin >> n >> x;

  vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v.at(i);
  }

  sort(v.begin(), v.end());

  int res = 0;
  for (int i = 0; i < n; ++i) {
    x -= v.at(i);
    res++;
    if (x < 0) {
      res--;
      break;
    }
    if (x == 0) {
      break;
    }
    if (x > 0 && i == n - 1) {
      res--;
    }
  }

  cout << res << endl;
}


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

#define nguyendz the_best
using namespace std;

#define ll long long
#define endl "\n"
#define ld long double
#define pb push_back
#define all(n) n.begin(),n.end()
#define eb emplace_back
#define pll pair<ll,ll>
#define YES cout <<"YES"<<endl;
#define NO cout <<"NO"<<endl;
#define ff first
#define ss second
#define setpre(x) fixed<<setprecision(x)


const ll maxn=5e3+100;

const ll maxx=1e13;
const ll mod=1000000007;
const ll mod1 =998244353;
const ll base=31;
ll dp[maxn][maxn];
ll nxt[maxn];
ll a[maxn];
ll n;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.txt","r",stdin);
    ll n,k;
    cin>>n>>k;
    ll ans=0;

    for (int i=k;i<=n+1;i++)
    {
        ll l = (i-1);
        l=l*i/2;
        ll r=(2*n+1-i) ;
        r=r*i/2;
        ans=(ans+(r-l+1))%mod;
    }
    cout <<ans%mod ;

}


Measured memory_bytes: 3680
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////

    int H,W;
    cin>>H>>W;
    vector<string>S(H);
    vector<int>Number(H*W);
    for(int i=0;i<H;i++){
        cin>>S.at(i);
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W-1;j++){
            if(S.at(i).at(j+1)=='#'){
                Number.at(i*W+j)+=1;
            }
        }
        for(int j=1;j<W;j++){
            if(S.at(i).at(j-1)=='#'){
                Number.at(i*W+j)+=1;
            }
        }
    }
    for(int i=0;i<H-1;i++){
        for(int j=0;j<W;j++){
            if(S.at(i+1).at(j)=='#'){
                Number.at(i*W+j)+=1;
            }
        }
        for(int j=0;j<W-1;j++){
            if(S.at(i+1).at(j+1)=='#'){
                Number.at(i*W+j)+=1;
            }
        }
        for(int j=1;j<W;j++){
            if(S.at(i+1).at(j-1)=='#'){
                Number.at(i*W+j)+=1;
            }
        }
    }
    for(int i=1;i<H;i++){
        for(int j=0;j<W;j++){
            if(S.at(i-1).at(j)=='#'){
                Number.at(i*W+j)+=1;
            }
        }
        for(int j=0;j<W-1;j++){
            if(S.at(i-1).at(j+1)=='#'){
                Number.at(i*W+j)+=1;
            }
        }
        for(int j=1;j<W;j++){
            if(S.at(i-1).at(j-1)=='#'){
                Number.at(i*W+j)+=1;
            }
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S.at(i).at(j)=='.'){
                if(Number.at(i*W+j)==0){
                    S.at(i).at(j)='0';
                }
                else if(Number.at(i*W+j)==1){
                    S.at(i).at(j)='1';
                }
                else if(Number.at(i*W+j)==2){
                    S.at(i).at(j)='2';
                }
                else if(Number.at(i*W+j)==3){
                    S.at(i).at(j)='3';
                }
                else if(Number.at(i*W+j)==4){
                    S.at(i).at(j)='4';
                }
                else if(Number.at(i*W+j)==5){
                    S.at(i).at(j)='5';
                }
                else if(Number.at(i*W+j)==6){
                    S.at(i).at(j)='6';
                }
                else if(Number.at(i*W+j)==7){
                    S.at(i).at(j)='7';
                }
                else if(Number.at(i*W+j)==8){
                    S.at(i).at(j)='8';
                }
            }
        }
    }
    for(int i=0;i<H;i++){
        cout<<S.at(i)<<endl;
    }
        return 0;
}

Measured memory_bytes: 256
from collections import deque
n = int(input())
even = n%2
ans = deque()
s = list(map(int,(input().split())))
for i in range(n):
    if i%2 != even:#i(コード上はi+1) と n の偶奇が一致していれば、数列の前に ai を追加する。
        ans.appendleft(s[i])
    else:
        ans.append(s[i])
print(" ".join(map(str,ans)))


Measured memory_bytes: 29124
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(2*1e5)+5
#define fim '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << fim
#define debug2(x, y) cout << "DEBUG " << x << " " << y << fim
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< fim
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << fim
#define max3(x, y, z) max(x, max(y, z))
#define ull unsigned long long
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<unsigned ll, pair<int, int> > piii;
typedef pair<pair<int, int>, int> piii2;
typedef tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll MOD = 1e9+7;
 
using namespace std;
 
int main() {
    string s;
    cin >> s;
    bool ans = false;
    for(auto i : s)
        if(i == '7') ans = true;
    cout << (ans == false ? "No" : "Yes") << endl;
}

Measured memory_bytes: 3628
N,X,Y=[int(e) for e in input().split(' ')]

a=X-1
b=N-Y
c=Y-X+1

for k in range(1,N):
    #print('--k={}--'.format(k))
    ans=0
    #A
    if a < k:
        pass
    else:
        ans+=a-k+1
    #print('a')
    #print(ans)
    #B
    if b < k:
        pass
    else:
        ans+=b-k+1
    #print('b')
    #print(ans)
    #c
    if c/2 < k:
        pass
    elif c%2==0 and c//2 == k:
        ans+=c//2
    else:
        ans+=c
    #print('c')
    #print(ans)
    #ABC
    if a!=0 and b!=0 and 3<=k<=a+b+1:
        suba=(k-3)-(a-1) if (k-3)-(a-1)>0 else 0 
        subb=(k-3)-(b-1) if (k-3)-(b-1)>0 else 0
        ans += k-2-suba-subb
    #print('abc')
    #print(ans)
    #AC
    if a!=0 and 2<=k<=a+c//2:
        aa=a-1
        cc=c//2
        suba=(k-2)-(aa) if (k-2)-(aa)>0 else 0 
        subc=(k-1)-(cc) if (k-1)-(cc)>0 else 0
        ans += (k-1-suba-subc)*2
        #print('suba={},subc={},{}'.format(suba,subc,k-c//2))
        if c%2==0 and 0<k-c//2:
            ans-=1

    #print('ac')
    #print(ans)
    #print(suba)
    #print(subc)
    #BC
    if b!=0 and 2<=k<=b+c//2:
        bb=b-1
        cc=c//2
        subb=(k-2)-(bb) if (k-2)-(bb)>0 else 0 
        subc=(k-1)-(cc) if (k-1)-(cc)>0 else 0
        ans += (k-1-subb-subc)*2

        if c%2==0 and 0<k-c//2:
            ans-=1
    #print('bc')
    #print(ans)
    print(ans)


Measured memory_bytes: 3444
#include <iostream>
#include <string>
using namespace std;
int main(){
  string str;
  cin >> str;
  //str.replace(","," ")
  std::string target = ",";     // 検索文字列
  std::string replacement = " "; // 置換文字列
  if (!target.empty()) {
    std::string::size_type pos = 0;
    while ((pos = str.find(target, pos)) != std::string::npos) {
      str.replace(pos, target.length(), replacement);
      pos += replacement.length();
    }
  }
  cout<<  str <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int M=scan.nextInt();
		if(N==M)
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 35612
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int min = 11;
    long N = scanner.nextLong();
    for (long a = 1; a * a <= N; a++) {
      if (N % a == 0) {
        long b = N / a;
        min = Math.min(min, numDigits(b));
      }
    }
    System.out.println(min);
  }

  private static int numDigits(long n) {
    int i = 0;
    while (n > 0) {
      n /= 10;
      i++;
    }
    return i;
  }
}


Measured memory_bytes: 23764
import sys
sys.setrecursionlimit(1000000) # 再帰上限を増やす

def main():
    input = sys.stdin.readline  # 文字列に対してinputした場合は、rstripするのを忘れずに！
    N, W = map(int, input().rstrip().split())
    item_list = []
    for _ in range(N):
        w, v = map(int, input().rstrip().split())
        item_list.append((w, v))

    # dp[i][w] = i番目まで見て重さwで持ち帰れる最大の価値
    dp = [[0] * (W + 1) for _ in range(N)]

    for i, item in enumerate(item_list):
        for w in range(W+1):
            # もし品物iが入れられる
            if w + item[0] <= W:
                dp[i][w+item[0]] = max(dp[i][w+item[0]], dp[i-1][w]+item[1])
            # 入れないパターン
            dp[i][w] = max(dp[i][w], dp[i-1][w])
    print(dp[N-1][W])

if __name__ == '__main__':
    main()

Measured memory_bytes: 120176
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
using namespace std;

int main()
{
    int h, w;
    int i;
    
    cin >> h >> w;
    
    vector<string> c(h, "");
    
    for(i = 0; i < h; i++) {
        cin >> c[i];
    }
    
    for(i = 0; i < h; i++) {
        cout << c[i] << endl;
        cout << c[i] << endl;
    }
    
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<int> A2(N);
    A2 = A;
    sort(A2.begin(), A2.end(), greater<int>());
    int one = A2[0];
    int two = A2[1];
    rep(i, N) {
        if (A[i] == one) {
            cout << two << endl;
        } else {
            cout << one << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3200
#pragma region macro
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace std {
template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for(int i = 0; i < static_cast<int>(v.size()); i++) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for(size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std
#pragma endregion

void solve() {
    int X, Y, Z, K;
    scanf("%d%d%d%d", &X, &Y, &Z, &K);
    std::vector<long long> A(X);
    rep(i, X) scanf("%lld", &A[i]);
    std::vector<long long> B(Y);
    rep(i, Y) scanf("%lld", &B[i]);
    std::vector<long long> C(Z);
    rep(i, Z) scanf("%lld", &C[i]);
    std::priority_queue<long long, std::vector<long long>, std::greater<long long>> AB;
    rep(i, X) {
        rep(j, Y) {
            AB.push(A[i] + B[j]);
            if(AB.size() > K) {
                AB.pop();
            }
        }
    }
    std::priority_queue<long long, std::vector<long long>, std::greater<long long>> ABC;
    while(!AB.empty()) {
        long long ab = AB.top();
        AB.pop();
        rep(i, Z) {
            ABC.push(ab + C[i]);
            if(ABC.size() > K) ABC.pop();
        }
    }
    std::vector<long long> ans(K);
    rep(i, K) {
        ans[i] = ABC.top();
        ABC.pop();
    }
    for(int i = K - 1; i >= 0; i--) {
        std::cout << ans[i] << std::endl;
    }
}

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

Measured memory_bytes: 384
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<queue>
#define Max 100005
using namespace std;




priority_queue<pair<int,int> >q;

int main(){
	
	int n,i,a[Max];
	int jmp[Max];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	jmp[n-1] = 0;
	int max = 0;
	for(i=n-2;i>=0;i--){
		if(a[i] >= a[i+1]){
			jmp[i] = jmp[i+1]+1;
		}else{
			jmp[i] = 0;
		}

		if(max < jmp[i])
			max = jmp[i];
	}

	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int hp,time;
    cin >> hp >> time;
    int sum = 0;
    for(int i = 0;i<time;i++){
        int b;
        cin >> b;
        sum += b;
    }
    if(sum >= hp)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
fn main() {
    let (n, m) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        let v: Vec<u32> = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();
        (v[0], v[1])
    };

    let ans = (1900 * m + 100 * (n - m)) * 2u32.pow(m);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    v = [[] for i in range(n)]
    d = [[float("inf")]*n for i in range(n)]
    f = [-1]*n
    for i in range(n):
        d[i][i] = 0
    for i in range(n-1):
        a,b = LI()
        a -= 1
        b -= 1
        d[a][b] = 1
        d[b][a] = 1
        f[a] += 1
        f[b] += 1
        v[a].append(b)
        v[b].append(a)
    for k in range(n):
        for i in range(n):
            for j in range(n):
                nd = d[i][k]+d[k][j]
                if nd < d[i][j]:
                    d[i][j] = nd

    for i in range(n):
        f[i] = max(f[i],1)
    x = 0
    for i in range(n):
        if d[0][x] < d[0][i]:
            x = i
    y = 0
    for i in range(n):
        if d[x][y] < d[x][i]:
            y = i
    k = (d[x][y]>>1)+1
    ans = float("inf")
    for s in range(n):
        if max(d[s]) < k:
            m = [0]*k
            m[0] = f[s]+1
            for i in range(n):
                fi = f[i]
                di = d[s][i]
                if m[di] < fi:
                    m[di] = fi
            na = 1
            for i in m:
                na *= i
            if na < ans:
                ans = na
        for t in v[s]:
            nd = [min(d[s][i],d[t][i]) for i in range(n)]
            if max(nd) < k:
                m = [0]*k
                m[0] = max(nd[s],nd[t])+1
                for i in range(n):
                    fi = f[i]
                    di = nd[i]
                    if m[di] < fi:
                        m[di] = fi
                na = 2
                for i in m:
                    na *= i
                if na < ans:
                    ans = na
    print(k,ans)
    return

#Solve
if __name__ == "__main__":
    solve()


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


long long a,b,c,n;

int main(){
	cin>>n;
	long long maxs=0;
	for(int i=0;i<n;i++){
		cin>>a>>b>>c;
		int total=a+b+c;
		maxs=max(a,b);
		maxs=max(maxs,c);

		 if(maxs==c){
			if(c*c==(a*a+b*b)) cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		else if(maxs==b){
			if(b*b==(a*a+c*c)) cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
		}
		else if(maxs==a){
			if(a*a==(c*c+b*b)) cout<<"YES"<<endl;
			else cout<<"NO"<<endl;
			}
		}
	}

Measured memory_bytes: 3080
#include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    #define MAXN  1000
    long long ans=0;
    struct node
    {
    	long long x,y,z;
    }fam[MAXN+5];
    int n,m;
    int t[4];
    void Init(int i)
    {
    		for(int j=0;j<3;j++)
    		{
    			if(i&(1<<j))
    				t[j+1]=1;
    			else t[j+1]=-1;
    		}
    }
    long long cmp(node x,node y)
    {
    	long long t1=x.x*t[1]+x.y*t[2]+x.z*t[3];
    	long long t2=y.x*t[1]+y.y*t[2]+y.z*t[3];
    	return t1>t2;
    }
    int main()
    {
    	scanf("%d %d",&n,&m);
    	for(int i=1;i<=n;i++)
    		scanf("%lld %lld %lld",&fam[i].x,&fam[i].y,&fam[i].z);
    	for(int i=0;i<8;i++)
    	{
    		long long cnt=0;
    		Init(i);
    		sort(fam+1,fam+1+n,cmp);
    		for(int j=1;j<=m;j++)
    			cnt+=fam[j].x*t[1]+fam[j].y*t[2]+fam[j].z*t[3];
    		ans=max(ans,cnt);
    	}
    	printf("%lld\n",ans);
    }

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n) + 1; i++)
#define all(vecto) vecto.begin(),vecto.end()
typedef long long ll;

int main(){
    int x;
    cin>>x;
    if(x%2==0){
        cout << x * x / 4 << endl;
    }
    else
        cout << x * (x * 1) / 4 << endl;
}

Measured memory_bytes: 256
import math
N,M = map(int,input().split())
Max = 1
for m in range(1,int(math.sqrt(M))+1):
    if M%m == 0 and m <= M//N :
        if Max < m:
            Max = m
        if M//m <= M//N and Max < M//m :
            Max = M//m
            
print(Max)

Measured memory_bytes: 3060
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll B, ll mod){
  if (B == 0) return 1;
  else{
    if (B % 2 == 0){
      return Pow(A * A % mod, B / 2, mod) % mod;
    }else{
      return A * Pow(A * A % mod, B / 2, mod) % mod;
    }
  }
}

ll nCr(ll N, ll C, ll mod){
  ll ans = 1; C = min(C, N - C);
  for (ll i = 1; i <= C; i++){
    ans *= N - i + 1; ans %= mod;
    ans *= Pow(i, mod - 2, mod); ans %= mod;
  }
  return ans;
}

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

  int N = S.length();
  ll DP1[N][K + 1], DP2[N][K + 1];

  for (int i = 0; i < K + 1; i++){
    DP1[0][i] = 0; DP2[0][i] = 0;
  }
  DP1[0][0] = 1; DP1[0][1] = S[0] - '0' - 1;
  DP2[0][1] = 1;

  for (int i = 1; i < N; i++){
    for (int j = 0; j < K + 1; j++){
      DP1[i][j] = DP1[i - 1][j];
    }
    for (int j = 1; j < K + 1; j++){
      DP1[i][j] += DP1[i - 1][j - 1] * 9;
    }

    if (S[i] == '0'){
      for (int j = 0; j < K + 1; j++){
        DP2[i][j] = DP2[i - 1][j];
      }
    }else{
      for (int j = 0; j < K + 1; j++){
        DP1[i][j] += DP2[i - 1][j];
      }

      int num = S[i] - '0' - 1;
      for (int j = 1; j < K + 1; j++){
        DP1[i][j] += DP2[i - 1][j - 1] * num;
      }
      
      DP2[i][0] = 0;
      for (int j = 1; j < K + 1; j++){
        DP2[i][j] = DP2[i - 1][j - 1];
      }
    }
  }
  
  cout << DP1[N - 1][K] + DP2[N - 1][K] << endl;

  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n, m;
vi v[200200];
int u[200200];

bool bfs(int x){
    queue<int> q;
    u[x] = 0;
    q.push(x);
    while(!q.empty()){
        int cur = q.front();
        q.pop();

        for(int i = 0; i < sz(v[cur]); ++i){
            int to = v[cur][i];
            if(!u[to]){
                u[to] = u[cur] + 1;
                q.push(to);
            }
        }
    }

    return u[n - 1] == 2;
}

string solve(){
    cin >> n >> m;
    for(int i = 0, x, y; i < m; ++i){
        cin >> x >> y;
        --x, --y;
        v[x].pb(y);
        v[y].pb(x);
    }

    return (bfs(0) ? "POSSIBLE" : "IMPOSSIBLE");
}

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

    cout << solve() << "\n";
    
    return 0;
}


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

using namespace std;

const int MAXN = 2e5 + 10;

vector<int> adj[MAXN];

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i < n; i++) {
        int a;
        cin >> a;

        a--;

        adj[a].push_back(i);
    }

    for (int i = 0; i < n; i++)
        cout << adj[i].size() << endl;
}


Measured memory_bytes: 14524
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int itemCount = int.Parse(Reader.ReadLine());

        long[] items = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

        int ans = 0;
        foreach(long item in items) {
            char[] tmp = Convert.ToString(item, 2).Reverse().ToArray();

            int cnt = 0;
            for (int i = 0; i < tmp.Length; i++) {
                if(tmp[i] != '0') {
                    break;
                }
                cnt++;
            }
            ans += cnt;
        }
        Console.WriteLine(ans);
    }


    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"





10
2184 2126 1721 1800 1024 2528 3360 1945 1280 1776


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 20832
from collections import*
z,v,a=input,range,print
h,w,k=map(int,z().split());r,s,t,u=map(lambda x:int(x)-1,z().split())
b=[z()for _ in v(h)];l=[[-1]*w for _ in v(h)];l[r][s]=0
d=deque([(r,s)])
while d:
  x,y=d.popleft();j=l[x][y]
  if(x==t)&(y==u):exit(a(j))
  for e,f in[[1,0],[-1,0],[0,-1],[0,1]]:
    for i in v(1,k+1):
      p,q=x+e*i,y+f*i
      if not((0<=p<h)&(0<=q<w))or b[p][q]=="@" or 0<=l[p][q]<=j:break
      if l[p][q]<0:d+=[(p,q)];l[p][q]=j+1
a(-1)

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

int main() {

    ll a, b, k; cin >> a >> b >> k;
    ll ansA = 0;
    ll ansB = 0;
    if (k <= a) {
        ansA = a - k;
        ansB = b;
    }
    else { // a < k
        ansB = max(0LL, b - k + a);
    }
    cout << ansA << " " << ansB << endl;
    return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;while(t--)
#define pb push_back
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(int i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
#define vinn(n,v) int n;cin>>n;vector<int>v(n);loop(i,0,n)cin>>v[i];
#define vinm(n,m,v) int n,m;cin>>n>>m;vector<int>v(n);loop(i,0,n)cin>>v[i];
#define debug(x) cerr<<#x<<" : "<<x<<endl;
signed main() 
{
    fastio();

    int n,r;
    cin>>n>>r;
    if(n>=10)cout<<r;
    else cout<<r+100*(10-n);

    return 0;
}


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

signed main(){
	ll N,K;
	cin>>N>>K;
	ll h[N],DP[N],min,tmp;
	rep(i,N) cin>>h[i];
	DP[0]=0;
	DP[1]=abs(h[1]-h[0]);
	repx(2,i,N){
		min=DP[i-1]+abs(h[i]-h[i-1]);
		ll cnt=K;
		if(i<K) cnt=i;
		repx(2,j,cnt+1){
			tmp=DP[i-j]+abs(h[i]-h[i-j]);
			if(min>tmp) min=tmp;
		}
		DP[i]=min;
	}
	cout<<DP[N-1]<<endl;
	return 0;
}


Measured memory_bytes: 1792
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
class Z
{
	static void Main()
	{
		var N = int.Parse(ReadLine());
		var b = ReadLine().Split().Select(t => -int.Parse(t)).ToArray();
		var g = new Dinic(N + 2);
		var s = 0L;
		for (var i = 0; i < N; i++)
			if (b[i] < 0)
			{
				s -= b[i];
				g.AddEdge(0, i + 1, 0);
				g.AddEdge(i + 1, N + 1, -b[i]);
			}
			else
			{
				g.AddEdge(0, i + 1, b[i]);
				g.AddEdge(i + 1, N + 1, 0);
			}
		for (var i = 1; i <= N; i++) for (var j = 2 * i; j <= N; j += i) g.AddEdge(i, j, Dinic.INF);
		WriteLine(s - g.MaxFlow(0, N + 1));
	}
}
class Dinic
{
	public const long INF = 4011686018427387913L;
	class Edge
	{
		public readonly int To;
		public long Capacity;
		public Edge Reverse;
		public Edge(int t, long c, Edge r)
		{
			To = t;
			Capacity = c;
			Reverse = r;
		}
	}
	public Dinic(int v)
	{
		V = v;
		level = new int[V];
		es = new List<Edge>[v];
		for (var i = 0; i < V; i++) es[i] = new List<Edge>();
	}
	readonly int V;
	int[] iter;
	readonly int[] level;
	readonly List<Edge>[] es;
	public void AddEdge(int f, int t, long c)
	{
		var e1 = new Edge(t, c, null);
		var e2 = new Edge(f, 0, e1);
		e1.Reverse = e2;
		es[f].Add(e1);
		es[t].Add(e2);
	}
	long DFS(int v, int t, long f)
	{
		if (v == t) return f;
		for (; iter[v] < es[v].Count; iter[v]++)
		{
			var e = es[v][iter[v]];
			if (level[v] >= level[e.To] || e.Capacity <= 0) continue;
			var g = DFS(e.To, t, Min(e.Capacity, f));
			if (g > 0)
			{
				e.Capacity -= g;
				e.Reverse.Capacity += g;
				return g;
			}
		}
		return 0;
	}
	void BFS(int s)
	{
		for (var i = 0; i < V; i++) level[i] = -1;
		var queue = new Queue<int>();
		level[s] = 0;
		queue.Enqueue(s);
		while (queue.Count > 0)
		{
			var v = queue.Dequeue();
			foreach (var e in es[v])
				if (e.Capacity > 0 && level[e.To] < 0)
				{
					level[e.To] = level[v] + 1;
					queue.Enqueue(e.To);
				}
		}
	}
	public long MaxFlow(int s, int t)
	{
		var flow = 0L;
		while (true)
		{
			BFS(s);
			if (level[t] < 0) return flow;
			iter = new int[V];
			while (true)
			{
				var f = DFS(s, t, INF);
				if (f <= 0) break;
				flow += f;
			}
		}
	}
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const long long INF = 9223372000000000000/2145;
//static const int INF = 1000010000;
//static const int NIL = -1;
//static const int MOD = 1000000007;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
//#define int ll

int visited[114514]={};
int button[114514]={};
int n;



signed main(){
    scanf("%d",&n);
    REP(i,n){
        scanf("%d",&button[i]);
        button[i]--;
    }

    int cur = 0,dist = 1;
    while(!visited[1] && !visited[cur]){
        visited[cur]=dist;
        dist++;
        cur = button[cur];
    }

    printf("%d\n",visited[1]-1);
    return 0;
}

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

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

void solve(long long N, long long X, std::vector<long long> x){
    vector<ll> dist_X(N);
    for(ll i = 0; i < N; ++i) dist_X[i] = abs(X - x[i]);
    ll ans;
    if(N == 1) ans = dist_X[0];
    else{
        for(ll i = 0; i < N-1; ++i){
            if(i == 0) ans = gcd(dist_X[0], dist_X[1]);
            else ans = gcd(ans, dist_X[i+1]);
        }
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    std::vector<long long> x(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
    }
    solve(N, X, std::move(x));
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define ll long long
#define pii pair<int,int>
const ll mod=1e9+7;
typedef struct node{
    int x;
    ll y;
}node;
ll power(ll x,int y){
    ll temp=x;
    for(int i=1;i<y;i++){
        x*=temp;
    }
    return x;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("inputf.txt","r",stdin);
    freopen("outputf.txt","w",stdout);
#endif
    
    int n;
    cin>>n;
    int x,y;
    int count=0;
    bool flag=0;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        if(x==y) count++;
        else count=0;
        if(count>2) flag=1;
    }
    if(flag) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

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

int main(){
    int x;
    cin >> x;
    vector<int> s;
    
    int k=0, M=0, cnt=0;
    for(int i=1; i<=x; i++){
        k = i;
        cnt=0;
        do{
            k *= i;
            if(k<=x) s.push_back(k);
            cnt++;
            if(cnt>10) break;
        } while(k<x);
        if(k<=x) s.push_back(k);
    }
    sort(s.begin(),s.end());
    s.erase(unique(s.begin(),s.end()), s.end());
    //for(int i=0; i<s.size(); i++) cout << s[i] <<" ";
    reverse(s.begin(),s.end());
    //cout << endl;
    cout << s[0] << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using pq = priority_queue<int>;
using Graph = VV;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
	int x, y;
	cin >> x >> y;
	int d, e, f;
	cin >> d >> e >> f;
	V a(d);
	V b(e);
	V c(f);
	pq app;
	rep(i, d) cin >> a[i];
	rep(i, e) cin >> b[i];
	rep(i, f) cin >> c[i];
	ll ans = 0;
	sort(all(a));
	sort(all(b));
	sort(all(c));
	reverse(all(a));
	reverse(all(b));
	reverse(all(c));
	rep(i, x) app.push(a[i]);
	rep(i, y) app.push(b[i]);
	rep(i, f) app.push(c[i]);
	rep(i, x + y) {
		ans += app.top();
		app.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3572
#include<stdio.h>
int main(){
  char x[1001];
  int cou,i,len,rode;
  while(scanf("%s",x)!=EOF){
    cou = 0;
    if(x[0] == '0')break;
    len = strlen(x);
    for(i=0;i<len;i++){
      rode = x[i]- '0';
      cou += rode;
    }
    printf("%d\n",cou);
  }
  return 0;
}

Measured memory_bytes: 536
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  string a,b;cin >> a >> b;
  sort(a.begin(),a.end());
  sort(b.rbegin(),b.rend());
  cout << (a<b?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256