akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTS(s) printf("%s\n",(s))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

typedef long long ll;

int N;
int a[100000];

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

void Swap(int x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}

void ShowData(int x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%d  ", x[i]);
	printf("\n");
}
void QSort(int x[], int left, int right, int n) {
	int i, j;	//左端,右端
	int pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		Swap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}


int main() {
	REP(i, 100000)a[i] = -1;
	scanf("%d", &N);
	REP(i, N)scanf("%d", &a[i]);
	QSort(a, 0, N - 1, 1);
	int tmp = a[0];
	int cnt=1;
	int ans = 0;
	REPS(i, N - 1) {
		//PRINTD(cnt);
		if (tmp == a[i]&& i != N - 1) {
			cnt++;
			continue;
		}
		if (i != N - 1) {
			if (a[i] != tmp) {
				ans += (cnt >= tmp) ? (cnt - tmp) : cnt;
				tmp = a[i];
				cnt = 1;
			}
			else {
				cnt++;
			}
		}
		else {
			if (a[i] != tmp) {
				ans += (cnt >= tmp) ? (cnt - tmp) : cnt;
				ans++;
			}
			else {
				cnt++;
				ans += (cnt >= tmp) ? (cnt - tmp) : cnt;
			}
		}
	}
	if (N == 1 && a[0] == 1) {
		PRINTD(0); return 0;
	}
	else if(N == 1 && a[0] != 1){
		PRINTD(1); return 0;
	}
	PRINTD(ans);
}

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

int A[101][101] = {0};
int n, tt = 0, d[101] = {0}, f[101] = {0}, color[101] = {0};
stack<int> S;

int next(int u) {
    int i;
    for ( i = 1; i <= n; i++ ) {
        if ( A[u][i] == 1 && color[i] != 1 ) return i;
    }

    return -1;
}

void dfs (int u) {
    int i, j ,k;
    S.push(u);
    d[u] = ++tt;
    color[u] = 1;
    while ( !S.empty() ) {
        j = S.top();
        i = next(j);
        if ( i != -1 ) {
            color[i] = 1;
            d[i] = ++tt;
            S.push( i );
        }
    else {
        f[j] = ++tt;
        S.pop();
    }
    }

}

int main() {
    int i, j, k, v;
    cin >> n;
    for ( i = 0; i < n; i++ ) {
        cin >> j >> k;
        while ( k-- ) {
            cin >> v;
            A[j][v] = 1;
        }
    }

    for ( i = 1; i <=n; i++ ) if ( color[i] != 1 ) dfs(i);
    for ( i = 1; i <=n; i++ ) cout << i << ' ' << d[i] << ' ' << f[i] << endl;

    return 0;

}



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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

struct UnionFind {
  vector<ll> data;

  UnionFind(ll sz) { data.assign(sz, -1); }

  bool unite(ll x, ll y) {
    x = find(x), y = find(y);
    if (x == y) return (false);
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  ll find(ll k) {
    if (data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  ll size(ll k) { return (-data[find(k)]); }

  bool same(ll x, ll y) {
    int rx = find(x);
    int ry = find(y);
    return rx == ry;
  }
};

int main() {
  ll N, M;
  scanf("%lld %lld", &N, &M);

  auto uf = UnionFind(N);

  for (ll i = 0; i < M; i++) {
    ll a, b;
    scanf("%lld %lld", &a, &b);
    a--;
    b--;

    uf.unite(a, b);
  }

  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    ll size = uf.size(i);
    ans = max(ans, size);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4856
/* 

Author: Vishal Singh  
(singhvishal0304@gmail.com)

"The days that break you are the days that make you."

*/

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

#define fastio() ios_base::sync_with_stdio(false);\
cin.tie(NULL);

#define md 1000000007


#define lli long long int
#define pb push_back
#define mp make_pair
#define vvi(r,c) vector<vector<lli>> v(r,vector<lli>(c));
#define fi first
#define se second
#define mem(arr,x) memset(arr,x,sizeof(arr))

lli power(lli a,lli b){
  if(b==0)
    return 1;
  if(b%2)
    return ((a%md)*(power(a,b-1)))%md;
  else
  {
    lli x=power(a,b/2);
    return (x*x)%md;
  }
}

void solve(){
  int n,W;
  cin>>n>>W;
  vector<int> w(n),v(n);
  int sum=0;
  for(int i=0;i<n;i++){
    cin>>w[i]>>v[i];
    sum+=v[i];
  }
 // cout<<sum<<endl;
  vector<int> dp(sum+1,md);
  dp[0]=0;
  for(int j=0;j<n;j++){
  for(int i=sum;i>0;i--){
      if(i-v[j]>=0){
        dp[i]=min(dp[i],w[j]+dp[i-v[j]]);
      }  
  }
  }
  int i;
  for(i=sum;i>0;i--){
  //  cout<<dp[i]<<endl;
      if(dp[i]<=W){
        // cout<<dp[i]<<" ";
        break;
      }
  }
  cout<<i<<endl;

}


int main()
{  
    fastio();
  int t;
  
  t=1;
  while(t--){
    solve();
  }

  return 0;
}

Measured memory_bytes: 3736
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
    int n,a;
    vector<int> v;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a;
        v.push_back(a);
    }
    int min = *std::min_element(v.begin(), v.end());
    int max = *std::max_element(v.begin(), v.end());
    cout << max - min << endl;
    return 0;
}

Measured memory_bytes: 256
import queue

N = int(input())


change=[[0] * (9) for _ in range(9)]
for i in range(1, 10):
    for j in range(1, 10):
        if  i == j and i <= N:
            cnt = 1
        else:
            cnt = 0
        q = queue.Queue()
        n = i * 10 + j
        while n <= N:
            cnt += 1
            for k in range(0, 10):
                q.put((n // 10) * 100 + k * 10 + n % 10)
            n = q.get()
        change[i-1][j-1] = cnt
#print(change)
ans = 0
for s in range(1, 10):
    for t in range(1, 10):
        ans += change[s-1][t-1] * change[t-1][s-1]
print(ans)



Measured memory_bytes: 79316
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define vul vector<ull>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi2d vector<vi >
#define vl2d vector<vl >
#define vpll vector<pll >

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rz resize
#define fr(i,n) for(i=0;i<(n);i++)
#define frr(i,n) for(i=(n-1);i>=0;i--)
#define fre(i,n) for(i=0;i<=(n);i++)
#define frre(i,n) for (i=(n);i>=0;i--)
#define frab(i,a,b) for(i=(a);i<(b);i++)
#define freab(i,a,b) for(i=(a);i<=(b);i++)
#define frrab(i,a,b) for(i=(b-1);i>=a;i--)
#define frreab(i,b,a) for(i=(b);i>=a;i--)

#define sz(a) int((a).size())
#define mset(a,b) (memset(a,b,sizeof(a)))
#define max3(a,b,c) (max((a),max((b),(c))))
#define min3(a,b,c) (min((c),min((a),(b))))
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
vector <ll> sprime;
vector<char> prime (1000000, true);
void sieve(ll n)
{
  //O(nloglogn) time
  sprime.pb(0);
  prime[0] = prime[1] = false;
  ll cnt = 0;
  for (ll i = 2; i <= n; ++i)
  {
    if (prime[i])
    {
      cnt++;
      sprime.pb(i);
      for (ll j = 2 * i; j <= n; j += i)
        prime[j] = false;
    }
  }
}
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll fastpowMOD(ll a, ll p, ll MOD) { if (p == 0) return 1; ll z = fastpowMOD(a, p / 2, MOD); z = (z * z) % MOD; if (p % 2) z = (z * a) % MOD; return z; }
ll fastpow(ll a, ll p) { if (p == 0) return 1; ll z = fastpow(a, p / 2); z = (z * z); if (p % 2) z = (z * a); return z; }

#define mod 1000000007
#define inf LLONG_MAX
#define minf LLONG_MIN
#define pi 3.14
#define ex 2.71

//************************************************************///
const int N = 1e5 + 5;
ll dp[405][405];
ll a[405];
ll pre[405];
int n;

ll fun(int l,int r)
{
  int i,j;
  if(dp[l][r]!=1e18)
    return dp[l][r];
  if(r==l)
    return dp[l][r]=0;
  freab(i,l,r-1)
  {
    dp[l][r]=min(dp[l][r],fun(l,i)+fun(i+1,r)+pre[i]-pre[l-1]+pre[r]-pre[i]);
  }
//  cout<<l<<" "<<r<<" "<<dp[l][r]<<endl;
  return dp[l][r];
}

void solve()
{
  int i,j;
  cin>>n;
  freab(i,1,n)
  {
    cin>>a[i];
    pre[i]=pre[i-1]+a[i];
  }
  fr(i,n+1)
    fr(j,n+1)
      dp[i][j]=1e18;

ll ans=fun(1,n);
cout<<ans<<endl;
}

int main()
{
  fast;
  int z;
  //cin>>z;
  z=1;
  while(z--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 2560
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from functools import reduce

from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n, X = map(int, readline().split())
  x = np.array(readline().split(), dtype='int64')
  x -= X
  if len(x) == 1:
    ans = x[0]
  else:
    ans = reduce(gcd, x)
  print(abs(ans))
  
  
  
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 21580
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

vector<int> fac(300001); //n!(mod M)
vector<int> ifac(300001); //k!^{M-2} (mod M)

long long fpow(long long a,long long n){
  long long ret=1;
  if(n==1) return a;
  if(n%2==0) {
      ret = fpow(a*a%mod, n/2) %mod ;
  }else {
      ret = (a%mod)*fpow(a*a%mod, n/2) %mod;
  }
  return ret %mod;
}
int comb(int a, int b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    int tmp = ifac[a-b]* ifac[b] % mod;
    return tmp * fac[a] % mod;
}

signed main(){
    int n, a, b ;
    cin >> n >> a >> b;
    int ans = fpow(2,n) - 1;
    //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
    fac[0] = 1;
    ifac[0] = 1;
    for(int i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % mod; // n!(mod M)
        ifac[i+1] = ifac[i]*fpow(i+1,mod-2) % mod; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }

    int ia = 1;
    for (size_t i = 0; i < a; i++)
    {
        ia *= n-i;
        ia %= mod;
    }
    
    int ib = 1;
    for (size_t i = 0; i < b; i++)
    {
        ib *= n-i;
        ib %= mod;
    }
    // cout << ia <<" "<< ia*ifac[a]%mod << endl;
    // cout << ib << " " <<ifac[b] << " " <<ib*ifac[b]%mod << endl;

    ans = ans - ia*ifac[a]%mod - ib*ifac[b]%mod;
    while(ans<0) ans += mod;
    cout << ans << endl;
    
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <map>
#include <string>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<map<char,int> > mp(N);

    for(int i=0;i<N;i++){
        string str;
        cin >> str;
        for(int j=0;j<str.length();j++){
            mp[i][str[j]]++;
        }
    }

    string ans;

    for(char c='a'; c<='z';c++){
        int count_char = 100;
        for(int i=0;i<N;i++){
            count_char = min(count_char, mp[i][c]);
        }
        string tmp(count_char, c);
        ans += tmp;
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
package main

import (
	"io"
	"os"

	"fmt"
)

const (
	NONE = iota
	PRIME
	COMPOSITE_NUMBER
)

func Solve(in io.Reader, out io.Writer) {
	var n int
	fmt.Fscan(in, &n)

	a := make([]int, n)

	max := 55555
	pr := make([]int, max+1)
	for i := 2; i <= max; i++ {
		if pr[i] != NONE {
			continue
		}
		pr[i] = PRIME
		for j := i * 2; j <= max; j += i {
			pr[j] = COMPOSITE_NUMBER
		}
	}

	ni := 0
	sum := 0
	for i, v := range pr {
		if v != PRIME {
			continue
		}
		if i%5 != 1 {
			continue
		}
		if a[ni%n] == 0 {
			sum -= a[ni%n]
			a[ni%n] = i
			sum += a[ni%n]
			ni++
			continue
		}

		break
	}
	for i, s := range a {
		if i > 0 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, s)
	}
	fmt.Fprintln(out)
}

func main() {
	Solve(os.Stdin, os.Stdout)
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 2e4+1;
int h, n, DP[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  fill(DP, DP+N, IINF);
  DP[0] = 0;
  cin >> h >> n;
  FOR(_, 0, n){
    int a, b;
    cin >> a >> b;
    FOR(i, 0, h+1) mins(DP[i+a], DP[i]+b);
  }
  int ans = IINF;
  FOR(i, h, N) mins(ans, DP[i]);
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << endl;
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << endl;
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  ll a, b;
  cin >> a >> b;
  if(a <= b){
    cout << a << endl;
  }else{
    cout << a-1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            long x = long.Parse(Console.ReadLine());

            long i = 100;
            long cnt = 0;
            for(; ;cnt++)
            {
                if (i >= x) break;
                i = i + (i / 100);
            }

            Console.WriteLine(cnt);

            Console.Out.Flush();
        }
    }
}


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

int main(){
    int a,b;
    cin >> a >> b;
    int ans;
    ans = max(max(a+b,a-b),a*b);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    int n, m;
    cin >> n >> m;

    set<int> s;
    for (int i = 0; i < n; i++) {
        s.insert(i);
    }

    int j1 = 0, j2 = 1;
    set<int> s2;
    for (int i = 0; i < m; i++) {
        int d = abs(j1 - j2);
        if (d * 2 > n) d = n - d;
        if (s2.find(d) != s2.end() || d * 2 == n) {
            j2 = (j2 + 1) % n;
            --d;
        }
        assert(s2.find(d) == s2.end());
        assert(d > 0);
        s2.insert(d);

        assert(s.find(j1) != s.end());
        s.erase(j1);
        assert(s.find(j2) != s.end());
        s.erase(j2);

        cout << j1 + 1 << " " << j2 + 1 << newl;

        j1 = (j1 + n - 1) % n;
        j2 = (j2 + 1) % n;
    }

    return 0;
}


Measured memory_bytes: 12084
#include <cstdio>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <vector>
#include <set>
#include <cmath>
#include <map> 
#include <iostream>
#include <cctype>
#include <utility> // 包含pair 
using namespace std;
typedef long long LL;
const int INF = 0x3fffffff;
const int MAXN = 1000 + 10;
char maze[MAXN][MAXN];
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
struct Node {
	int x, y, t; // w为体力值, t为当前花费时间 
	Node (int _x, int _y, int _t) { x = _x; y = _y; t = _t;} 
};
int H, W, N; // H * W的地图上有N个奶酪工厂
int sx, sy; 
int ans;
bool loc_ok(int x, int y) {
	if (x < 0 || x >= H || y < 0 || y >= W || maze[x][y] == 'X') return false;
	return true;
}
bool inq[MAXN][MAXN];
int bfs(int wc) {
	memset(inq, false, sizeof(inq));
	queue<Node> que;
	que.push(Node(sx, sy, 0));
	inq[sx][sy] = true; // 标记为已经入队 
	while (!que.empty()) {
		Node u = que.front(); que.pop();
		int x = u.x, y = u.y, t = u.t;
		if (isdigit(maze[x][y])) {
			int temp = maze[x][y] - '0';
			if (temp == wc) { // 当前奶酪硬度与体力值相等 
				sx = x; // 去修改全局变量 
				sy = y;
				maze[x][y] = '.';
				return t;
			}  
		}
		for (int i = 0; i < 4; i++) {
			int ux = x + dx[i], uy = y + dy[i];
			if (loc_ok(ux, uy) && !inq[ux][uy]) {
				inq[ux][uy] = true;
				que.push(Node(ux, uy, t + 1));
			}
		}
	}
	// 队列不可能为空，所以此处不需要设出口 
}

int main() {
	while (scanf("%d %d %d\n", &H, &W, &N) != EOF) {
		ans = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				scanf("%c", &maze[i][j]);
				if (maze[i][j] == 'S') {
					sx = i; 
					sy = j;
					maze[i][j] = '.';
				}
			}
			getchar();
		}
		for (int i = 1; i <= N; i++) {
			ans += bfs(i); 
		}
		printf("%d\n", ans);
	}
    return 0;
}


Measured memory_bytes: 5180
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
const double eps = 1e-18;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int n;
void bt(vector<string> &res,int len,string ans,char cur){
	if(len==n){
		res.pb(ans);
		return ;
	}
	for(char c='a';c<=cur;c++){
		ans+=c;
		if(c!=cur)bt(res,len+1,ans,cur);else bt(res,len+1,ans,cur+1);
		ans.pop_back();
	}
}
void solve(){
	
	cin>>n;
	vector<string> res;
	//for(int i=0;i<n;i++){
		bt(res,0,"",'a');
	//}
	sort(all(res));
	rep(i,0,sz(res))cout<<res[i]<<endl;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





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

int main() {
	
	ll n, m;
	cin >> n >> m;
	cout << abs((n - 2) * (m - 2)) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {

	while (max_n >= x)
	{
		bit[x]++;
		x += x & -x;
	}
}
void sub(int x) {
	while (max_n >= x)
	{
		bit[x]--;
		x += x & -x;
	}
}
int search(int x) {

	int k = 0;
	int p = 1;
	while (p * 2 <= max_n)
	{
		p *= 2;
	}
	for (int i = p; i > 0; i /= 2)
	{
		if (i + k < max_n && bit[i + k] < x) {
			x -= bit[i + k];
			k += i;
		}
	}
	return k + 1;
}
void solv() {

	int tb[105][105];
	int r, c;
	cin >> r >> c;
	for (size_t i = 0; i < r; i++)
	{
		for (size_t j = 0; j < c; j++)
		{
			cin >> tb[i][j];
		}
	}
	int as = 0;
	for (size_t i = 0; i < r; i++)
	{
		int s = 0;
		for (size_t j = 0; j < c; j++)
		{
			s += tb[i][j];
		}
		tb[i][c] = s;
		as += s;
	}
	for (size_t i = 0; i < c; i++)
	{
		int s = 0;
		for (size_t j = 0; j < r; j++)
		{
			s += tb[j][i];
		}
		tb[r][i] = s;
	}
	tb[r][c] = as;
	for (size_t i = 0; i < r+ 1; i++)
	{
		for (size_t j = 0; j < c + 1; j++)
		{
			if (j > 0) cout << " ";
			cout << tb[i][j];
		}
		cout << endl;
	}
}
int main() {
	//	COMinit();
	solv();
	return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

int main() {
	int N;
	while (cin >> N, N) {
		int W, H; cin >> W >> H;
		int tree[101][101] = {0};
		int dp[101][101] = {0};
		rep(i, N) {
			int x, y; cin >> x >> y;
			tree[y][x] = 1;
		}
		rep(y, H + 1) rep(x, W + 1) {
			dp[y + 1][x + 1] = -dp[y][x] + dp[y + 1][x] + dp[y][x + 1] + tree[y + 1][x + 1];
		}
		int S, T; cin >> S >> T;
		int ans = 0;
		rep(y, H - T + 1) rep(x, W - S + 1) {
			int tmp = dp[y][x] + dp[y + T][x + S] - dp[y][x + S] - dp[y + T][x];
			ans = max(ans, tmp);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1244
package main

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

func main() {
	N, K := ReadInt(), ReadInt()
	sum := 0.
	for i := 1; i <= N; i++ {
		k := 0
		j := i
		for j < K {
			k++
			j <<= 1
		}
		sum += 1 / float64(N*1<<k)
	}
	fmt.Println(sum)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, A, B; cin >> N >> A >> B; cout << min(B, A * N) << endl;
}

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


Measured memory_bytes: 256
def ope(a, x, y):
    if a == '+':
        return x+y
    if a == '-':
        return x-y
    if a == '*':
        return x*y


*A, = input().split()
stack = []
for a in A:
    try:
        a = int(a)
        stack.append(a)
    except:
        tmp = stack.pop()
        tmp = ope(a, stack.pop(), tmp)
        stack.append(tmp)
print(stack.pop())



Measured memory_bytes: 5600
#include<cstdio>
#include<algorithm> 
using namespace std;
pair<int,int> a[300005];
int sum[2][300005],seg[1200005];
void build(int l,int r,int num){
	if(l==r){
		seg[num]=sum[1][l];
		return ;
	}
	int mid=l+r>>1;
	build(l,mid,num<<1);
	build(mid+1,r,num<<1|1);
	seg[num]=max(seg[num<<1],seg[num<<1|1]);
}
void modify(int k,int l,int r,int num,int v){
	if(l==k&&r==k){
		seg[num]+=v;
		return ;
	}
	int mid=l+r>>1;
	if(k<=mid){
		modify(k,l,mid,num<<1,v);
	}
	else{
		modify(k,mid+1,r,num<<1|1,v);
	}
	seg[num]=max(seg[num<<1],seg[num<<1|1]);
}
int main(){
	int h,w,m,i,zz=1,maxn=0;
	scanf("%d%d%d",&h,&w,&m);
	for(i=1;i<=m;i++){
		scanf("%d%d",&a[i].first,&a[i].second);
		sum[0][a[i].first]++;
		sum[1][a[i].second]++;
	}
	build(1,w,1);
	sort(a+1,a+m+1); 
	for(i=1;i<=h;i++){
		int zz1=zz;
		while(a[zz1].first==i){
			modify(a[zz1].second,1,w,1,-1);
			zz1++;
		}
		maxn=max(maxn,sum[0][i]+seg[1]);
		while(a[zz].first==i){
			modify(a[zz].second,1,w,1,1);
			zz++;
		}
	}
	printf("%d",maxn); 
	return 0;
}

Measured memory_bytes: 10488
n = int(input())
total = []  

for i in range(1, n + 1):
    if i % 3 == 0 and i % 5 == 0:
        "FizzBuzz"
    elif i % 3 == 0:
        "Fizz"
    elif i % 5 == 0:
        "Buzz"
    else:
        total.append(i)  
print(sum(total))  

Measured memory_bytes: 30012
#include <iostream>

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

   int max = 0;
   int count = 0;
   for(int i=0; i<S.size(); ++i){
      if(S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T'){
	 ++count;
      }else{
	 if(max<count) max = count;
	 count = 0;
      }
   }
   if(max<count) max = count;
   std::cout << max << std::endl;

   return 0;
}


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

ll n;
int main()
{
    cin >> n;
    if (n % 2 == 1) {
        cout << 0;
        return 0;
    }

    ll ans = 0;
    ll p = 5;
    while (p <= n) {
        ans += n / p / 2;
        p *= 5;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

#define LL long long

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

    string a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;

    int total = 0;
    for (int i=0; i < n; i++){
        set<char> s;
        s.insert(a[i]);
        s.insert(b[i]);
        s.insert(c[i]);
        total += s.size() - 1;
    }


    cout << total << endl;

    return 0;
}


Measured memory_bytes: 256
##mod,nについての制約は自分でいかに記入する
mod=10**9+7
def find_power(n,mod):
    # 0!からn!までのびっくりを出してくれる関数(ただし、modで割った値に対してである）
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(mod)
    return powlist
 #あるかずxのn乗をmodで割ったあまりを返す関数pow_cal(x,n,mod)
def pow_cal(x,n,mod):
    if n==0:
        return 1
    elif n==1:
        return x%mod
    elif n>=2:
        if n%2==0:
            return (pow_cal(x,n//2,mod)**2)%mod
        else:
            return (x*pow_cal(x,n//2,mod)**2)%mod

def find_inv_power(n,mod):
    #0!からn!までの逆元を素数modで割ったあまりリストを作る関数
    c=1
    uselist=[0 for i in range(n+1)]
    for i in range(1,n+1):
        c*=i
        c%=mod
    first=pow_cal(c,mod-2,mod)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(mod)
    return uselist
    
A=find_power(2*10**6+10,mod)
B=find_inv_power(2*10**6+10,mod)

def combi(n,r,mod):
    if n<r:
        return 0
    elif n>=r:
        return (A[n]*B[r]*B[n-r])%(mod)
    
r1,c1,r2,c2=map(int,input().split())

mod=10**9+7     

K=combi(r2+c2+2,c2+1,mod)-combi(r2+c1+1,c1,mod)-combi(r1+c2+1,r1,mod)+combi(r1+c1,c1,mod)

print(K%mod)


Measured memory_bytes: 161332
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> P;

int gcd(int a,int b){
  if(b==0)return a;
  return gcd(b,a%b);
}
int main(){
  int a,b;
  cin>>a>>b;
  if(b/gcd(a,b)==1)cout<<-1<<endl;
  else {
    ll tmp=(ll)a*(((ll)b/(ll)gcd(a,b))-(ll)1);
      if(tmp>1000000000000000000LL)cout<<-1<<endl;
      else cout<<tmp<<endl;
      }

}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }
    int n;

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        n = sc.nextInt();
        int[] ps = new int[n * n];

        for (int i = 0; i < n * n; i++) {
            ps[i] = sc.nextInt();
        }
        int[][] b = new int[n][n];
        boolean[][] visited = new boolean[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n - i; j++) {
                b[i][j] = b[j][i] = b[n - i - 1][j] = b[j][n - i - 1] = i + 1;
            }
        }

//        for (int[] a : b) debug(a);

        int[] dx = {-1 ,0, 1, 0}, dy = {0, -1, 0, 1};
        long sum = 0;
        for (int i = 0; i < n * n; i++) {
            P c = from(ps[i]);
            visited[c.y][c.x] = true;
            sum += Math.max(0, --b[c.y][c.x]);
            b[c.y][c.x] = Math.max(0, b[c.y][c.x]);
            LinkedList<P> q = new LinkedList<>();
            q.addLast(c);

            while (!q.isEmpty()) {
                P cur = q.removeFirst();

                for (int j = 0; j < 4; j++) {
                    if (cur.x + dx[j] < 0 || cur.y + dy[j] < 0 || cur.x + dx[j] >= n || cur.y + dy[j] >= n)
                        continue;
                    if (visited[cur.y + dy[j]][cur.x + dx[j]] && b[cur.y + dy[j]][cur.x + dx[j]] > b[cur.y][cur.x]) {
                        q.addLast(new P(cur.x + dx[j], cur.y + dy[j]));
                        b[cur.y + dy[j]][cur.x + dx[j]] = b[cur.y][cur.x];
                    }
                    else if (b[cur.y + dy[j]][cur.x + dx[j]] > b[cur.y][cur.x] + 1) {
                        q.addLast(new P(cur.x + dx[j], cur.y + dy[j]));
                        b[cur.y + dy[j]][cur.x + dx[j]] = b[cur.y][cur.x] + 1;
                    }
                }
            }
//            debug(i, ps[i]);
//            for (int[] a : b) debug(a);

        }

        out.println(sum);

        out.flush();
    }

    P from(int v) {
        int x = (v - 1) / n;
        int y = (v - 1) % n;
        return new P(x, y);
    }

    class P {
        int x, y;
        P(int x, int y) {
            this.x = x;
            this.y = y;
        }

    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 61868
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>

using namespace std;

int n,x[100020],k,mn;

int main(){
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)scanf("%d",&x[i]);
    sort(x,x+n);
    for(int i=0;i<n-k+1;i++){
        if(i==0)mn=x[i+k-1]-x[i];
        else mn=min(mn,x[i+k-1]-x[i]);
    }
    printf("%d\n",mn);
}



Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

using namespace std;

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

    sort(a, a + 3);
    cout << a[0] + a[1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define printjudge(cond) {if(cond) printf("Yes\n"); else printf("No\n");}
#define printans(ans) {printf("%d\n",(ans));}
#define intscan(x) {scanf("%d", &x);}
#define Ntimes(N) for(int i=0; i<N; i++)
#define min(x,y) (((x)<(y)) ? (x) : (y))
#define max(x,y) (((x)>(y)) ? (x) : (y))
typedef int* intarray;
typedef char* string;

int main(){
    int r, D, x;
    scanf("%d%d%d", &r, &D, &x);
    Ntimes(10){
        x = r*x-D;
        printans(x);
    }
    return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int main() {
    string ans = "";
    int K;
    cin >> K;
    for_(i,0,K) ans += "ACL";
    cout << ans << endl;
}

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

int n;
int a[100000];

int main() {
	std::cin>>n;
	for(int i=0;i<n;++i)
		std::cin>>a[i];
	std::sort(a,a+n);
	std::vector<int> vec;
	for(int i=1;i<n;++i){
		if(a[i-1]==a[i])
			vec.push_back(i-1);
	}
	int ans=n;
	if(vec.size()%2==0)
		ans-=vec.size();
	else
		ans-=vec.size()+1;
	std::cout<<ans<<std::endl;
	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
  
int main() {
    int64_t N, K;
    cin >> N >> K;
    cout << int64_t (K * powl(K - 1, N - 1)) << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
S = input()+'!'
A = [0]
tmp = 1
for i in range(1,n+1):
    if S[i] == S[i-1]:
        tmp += 1
    else:
        A.append(tmp)
        tmp = 1
for i in range(1,len(A)):
    A[i] += A[i-1]
#print(A)
res = 0
if S[0] == '0':
    for i in range(len(A)):
        if i%2 == 0:
            ans = A[min(i+2*k,len(A)-1)]-A[i]
        else:
            ans = A[min(i+2*k+1,len(A)-1)]-A[i]
        if res <= ans:
            res = ans
else:
    for i in range(len(A)):
        if i%2 == 0:
            ans = A[min(len(A)-1,i+2*k+1)]-A[i]
        else:
            ans = A[min(i+2*k,len(A)-1)]-A[i]
        if res <= ans:
            res = ans

print(res)

Measured memory_bytes: 7160
// @iamnifer
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <stack>
#include <deque>
#include <queue>
#define ll long long
#define ld long double
#define ull unsigned long long
#define elif else if
#define inf (ll)1e18
#define append push_back
#define pb push_back
#define str to_string
#define gcd __gcd
#define optimise cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define len(x) x.size()
#define add insert
#define PI 3.14159265358979323846264338327950288419716939937510
#define lcm(a,b) a/gcd(a,b)*b
#define eps 0.0000000001
#define endl '\n'
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma gcc optimize("no-stack-protector,tune=native")
//#pragma gcc optimize("sse,sse2,sse3,sse4,ssse3")
//#pragma gcc optimize("abm,mmx,avx,avx2,unroll-loops,fast-math,section-anchors")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef vector<vector<ll>>graph;
const ll MOD = (ll)1e9+7;//998244353
const ll maxN= (ll)5009;
ll p[maxN];
vector<bool>vis(maxN);
vector<ll>cur;
void dfs(ll v){
    vis[v]=true;
    cur.pb(v);
    if(!vis[p[v]]){
        dfs(p[v]);
    }
}
void solve()
{
    ll n,k;cin>>n>>k;
    for(ll i=1;i<=n;i++){
        cin>>p[i];
    }
    ll c[n+1];
    ll ans=0,cs,ff,mff,mff2;
    ll negs=0;
    for(ll i=1;i<=n;i++){
        cin>>c[i];
        if(c[i]<=0)negs++;
    }
    ll lenka;
    if(negs==n){
        cout<<*max_element(c+1,c+n+1);
        return;
    }
    for(ll i=1;i<=n;i++){
        cur.clear();
        vis.assign(n+1,false);
        dfs(i);
        cs=0;
        mff=0;mff2=0;
        lenka=len(cur);
        for(ll j=0;j<lenka;j++){
            cs+=c[cur[j]];
            if(j<k%lenka){
                mff2=max(mff2,cs);
            }
            if(j<k)mff=max(mff,cs);
        }
        if(cs<0){
            ans=max(ans,mff);
        }
        else{
            ans=max(ans,(k/lenka)*cs+mff2);
            if(k>=lenka)ans=max(ans,cs*(k/lenka-1)+mff);
        }
    }
    cout<<ans;
}
int main()
{
    optimise
    ll multitest=0;
    ll t=1;
    if(multitest)cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 3944
#include <stdio.h>

int main(void)
{
	int i = 0;
	int j = 0;
	int num[3] = {0, 0, 0};
	int temp = 0;
	
	scanf("%d %d %d", &num[0], &num[1], &num[2]);
	
	for (i = 0; i < 2; i++) {
		for (j = i + 1; j < 3; j++) {
			if (num[i] > num[j]) {
				temp = num[i];
				num[i] = num[j];
				num[j] = temp;
			}
		}

	}

	printf ("%d %d %d\n", num[0], num[1], num[2]);	

	return (0);
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;
stringstream ss;

int main() {
    vector<ll> l(3);
    rep(i, 3) cin >> l[i];
    sort(l.begin(), l.end());
    printf("%lld %lld\n", l[0], l[2]);
}


Measured memory_bytes: 3336
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n;
    cin >> n;
    vector <long> h(n);
    for(long i = 0; i < n; i++){
        cin >> h[i];
    }
    long ans = 0;
    long ansMax = 0;
    for(long i = 1; i < n; i++){
        if(h[i]<=h[i-1]){
            ans++;
        }else{
            ans = 0;
        }
        ansMax = max(ans,ansMax);
    }
    cout << ansMax << endl;
    return 0;
}

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

int main(){
  
  int n, a, cnt = 0;
  
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> a;
    
    while(a % 2 != 1){
      cnt++;
      a /= 2;
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}

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

typedef long long ll;

using namespace std;

int main()
{int N ; cin >> N;
 vector<ll> A(N);
 for(int i = 0; i < N; i++){
   cin >> A[i];}
 
 sort(A.begin(),A.end());
 reverse(A.begin(),A.end());
 //Aは降べきの順に並んでいる
 
 int cnt = 0;
 //cnt　が　２未満のときは、長方形が作れないので0出力
 
 int n = 0;
 
 ll B[N];

 
 while( n < N && cnt < 2){
   // 小文字nは、今A[n]を調べていることを示している
   int cnt2 = 0 ; ll c = A[n];
   while( n < N && A[n] == c){ cnt2++; //cnt2は、いくつ同じ数字が連続しているかを表す
                              n++;}
       if( cnt2 >= 4 ){ 
         if ( B[0] > c ) {cout << B[0] * c << endl; return 0;}
         else{cout << c * c << endl; return 0;} }
       //一度でも、4種類以上が出たらもう調べなくていい
    else if( 2<= cnt2 && cnt2 < 4){ B[cnt] = c; cnt++;} 
   //もし同じ数字が２つ以上連続していれば、cntを増やし数字記録
 }
 
 if( cnt < 2){ cout << 0 << endl;}
 else{
 ll d = B[0]; ll e = B[1];
   
   cout << d*e << endl;
   
 }
  
 return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    vector<ll> d;
    rep(i, n)
    {
        ll now = 0;
        rep2(j, i, n)
        {
            now += a[j];
            d.push_back(now);
        }
    }
    ll co = 40;
    ll ans = 0;
    while (co >= 0)
    {
        ll now = 0;
        rep(i, d.size())
        {
            if ((d[i] & (ans + (1LL << co))) == (ans + (1LL << co)))
            {
                now++;
            }
        }
        if (now >= k)
        {
            ans += (1LL << co);
        }
        co--;
    }

    cout << ans << endl;
}

Measured memory_bytes: 7364
# 行数
N = int(input().strip())

# 2次元配列
l = []
for i in range(N):
    array = list(input().split())
    array[1]=int(array[1])
    array.append(i+1)
    l.append(array)

l.sort(key=lambda x: x[1], reverse=True)
l.sort(key=lambda x: x[0])

for i in range(N):
    print(l[i][2])



Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	int n,k;
	long long int t;
	vector <long long int> v;
 
	cin >> n >> k;
 
	for(int i=0;i<n;i++)
	{
		cin >> t;
		v.push_back(t);
	}
 
	vector <unsigned long long int> v2;
 
	for(int i=0;i<n;i++)
	{
		unsigned long long int val = 0;
		for(int j=i;j<n;j++)
		{
			val += v[j];
			v2.push_back(val);
		}
	}
 
	sort(v2.rbegin(),v2.rend());
	
	unsigned long long int res = 0;
 
	for(long long int j=60;j>=0;j--)
	{
		vector <unsigned long long int> temp;
		int cnt = 0;
		for(int i=0;i<v2.size();i++)
		{
			if((v2[i]&(1LL << j)))
			{
				cnt++;
				temp.push_back(v2[i]);
			}
		}
		if(cnt >= k)
		{
			res += (1LL << j);
			v2 = temp;
		}
	}

	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  bool in = true;
  
  for ( int i = 0 ; i < 10000 ; i++ ) {
    if ( i*0.08 - a < 1 && i*0.08-a >= 0 ) {
      if ( i*0.1 - b < 1 && i*0.1-b>=0 ) {
        cout << i << endl;
        in = false;
        break;
      }
    }
  }
  
  if (in) {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 256
import io.StdIn.readLine


object Main {

  def main(args: Array[String]): Unit = {
    val Array(n, a, b) = readLine().split(' ').map(_.toInt)
    val s = readLine()

    var n_a, n_b = 0
    for (i <- 0 to (n - 1)) {
      s(i) match {
        case 'a' =>
          n_a = n_a + 1
          if (n_a + (if (n_b > b) b else n_b) <= a + b) println("Yes")
          else println("No")
        case 'b' =>
          n_b = n_b + 1
          if (n_b <= b && n_a + n_b <= a + b) println("Yes")
          else println("No")
        case 'c' => println("No")
      }
    }
  }

}


Measured memory_bytes: 32452
unittest
{
	assert( [ "36" ].parse.expand.solve == 8 );
	assert( [ "91" ].parse.expand.solve == 3 );
	assert( [ "314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170" ].parse.expand.solve == 243 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.map!( ( a ) => ( a - '0' ).to!( long ) ).retro.array;
	return tuple( n );
}

auto solve( long[] n )
{
	// dp[ 左からi桁目 ][ 繰り上げフラグ ] = 紙幣の枚数
	auto dp = new long[][]( n.length, 2 );
	dp[ 0 ][ 0 ] = n.front;						// 支払いが増える
	dp[ 0 ][ 1 ] = ( 10 - n.front ) + 1;		// お釣り＋繰り上げ支払い1枚が増える
	n.popFront;
	foreach( i, d; n )
	{
		// i-1桁目で繰り上げせず、i桁目で繰り上げしない場合（支払いが増える）
		dp[ i + 1 ][ 0 ] = dp[ i ][ 0 ] + d;
		
		// i-1桁目で繰り上げして、i桁目で繰り上げしない場合（支払いが増える）
		if( d < 9 ) dp[ i + 1 ][ 0 ] = min( dp[ i + 1 ][ 0 ], dp[ i ][ 1 ] + d );
		
		// i-1桁目で繰り上げして、i桁目で繰り上げする場合（お釣りが増える）
		dp[ i + 1 ][ 1 ] = dp[ i ][ 1 ] + ( 10 - ( d + 1 ) );
		
		// i-1桁目で繰り上げせず、i桁目で繰り上げする場合（お釣り＋繰り上げ支払い1枚が増える）
		if( 0 < d ) dp[ i + 1 ][ 1 ] = min( dp[ i + 1 ][ 1 ], dp[ i ][ 0 ] + ( 10 - d ) + 1 );
	}
	return dp[ $ - 1 ].reduce!min;
}


Measured memory_bytes: 72488