akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
#include<utility>
#include<vector>
using namespace std;

const long mod = 1000000007;
const long indlim = 5368709119;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
long fact(long x) { if (x == 0) return 1; else return((fact(x - 1) * x) % mod); }
long mybase(long N, long B) { if (N == 0) return 0; string S = ""; while (N != 0) { string M = to_string(N % B); N -= N % B; N /= B; S = M + S; }return stol(S); }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long res = 0;
	long N; cin >> N;
	vector<pair<long, long>> red, blue;
	long a, b; 
	
	for (int i = 0; i < N; i++) { cin >> a >> b; red.push_back(make_pair(a, b)); }
	for (int i = 0; i < N; i++) { cin >> a >> b; blue.push_back(make_pair(a, b)); }

	sort(red.begin(), red.end(), [&](pair<long, long> p, pair<long, long> q) {return p.second > q.second; }); //赤い点をY座標の大きい順にソート。
	sort(blue.begin(), blue.end(), [&](pair<long, long> p, pair<long, long> q) {return p.first < q.first; }); //青い点をX座標の小さい順にソート。
 
	for (int j = 0; j < N; j++) for (int i = 0; i < N; i++) if (red[i].first < blue[j].first && red[i].second < blue[j].second) {
		red[i].first = INT_MAX; red[i].second = INT_MAX;
		res++;
		break;
	}
    
	cout << res << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n,k;
    cin>>n>>k;
    VL h(n);
    REP(i,n)cin>>h[i];

    VL dp(n);
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    FOR(i, 2, n){
        LL st = max(LL(0), i - k);
        LL min_cost = 1e10;
        FOR(j, st, i){
            min_cost = min(min_cost, dp[j] + abs(h[j] - h[i]));
        }
        dp[i] = min_cost;
    }

    PUTS(dp[n-1]);

}

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
    string s;
    cin >> s;
    vector<vector<ll>> dp(s.length() + 1, vector<ll>(4));
    dp[0][0] = 1;
    dp[0][1] = dp[0][2] = dp[0][3] = 0;
    ll n = s.length();
    for (int i = 0; i < n; ++i) {
        dp[i + 1][0] = (s[i] == '?' ? 3ll : 1ll) * dp[i][0] % MOD;
        for (int j = 1; j <= 3; ++j) {
            dp[i + 1][j] = (s[i] == '?' ? 3ll : 1ll) * dp[i][j] % MOD;
            if (s[i] == '?' || s[i] == "ABC"[j - 1]) {
                dp[i + 1][j] += dp[i][j - 1];
                dp[i + 1][j] %= MOD;
            }
        }
    }
    cout << dp[n][3] << endl;
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

Measured memory_bytes: 7376
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int b;
  cin >> a >> b;
  int c = a+b;
  int d = a-b;
  int e = a*b;
  
  if (c >= d && c >= e) {
    cout << c << endl;
  } else if (d >= c && d >= e) {
    cout << d << endl;
  } else {
    cout << e << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const string p[2] = {"JOI", "IOI"};

int main(void){
    for(string in; cin >> in;)
        rep(i, 2){
            int ind, cnt = 0;
            while(~(ind = in.find(p[i])))
                cnt ++, in[ind] = '.';

            cout << cnt << endl;
        }

    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}



int main()
{
	int N;cin>>N;
    string s;cin>>s;
    string saki,ato;
    saki=s.substr(0,N/2);
    ato=s.substr(N/2,N/2);
    if(saki==ato&&N!=1&&N%2==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

 
    

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

int main(void){
    int n,l;
    cin >> n >> l;
    vector<string> vec(n);
    rep(i,n) cin >> vec.at(i);
    sort(vec.begin(),vec.end());

    for(int i=0;i<n;i++){
        cout << vec.at(i);
    }
    cout << endl;
}

Measured memory_bytes: 256
def insertion_sort(A):
    for i in range(1,len(A)):
        print(*A)
        key = A[i]
        #/* insert A[i] into the sorted sequence A[0,...,j-1] */
        j = i - 1
        while j >= 0 and A[j] > key:
            A[j+1] = A[j]
            j-=1
        A[j+1] = key

if __name__=='__main__':
   n=int(input()) 
   A=list(map(int,input().split()))
   insertion_sort(A)
   print(*A)

Measured memory_bytes: 8108
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int a = scn.nextInt();
        int b = scn.nextInt();
        int c = scn.nextInt();
        if (a + b >= c) {
            System.out.println(b+c);
        } else {
            System.out.println(a + b + 1 + b);
        }
    }
}


Measured memory_bytes: 22612
from collections import*
n,*a=map(int,open(0).read().split())

b=Counter(a)

ans=sum(v*(v-1)//2 for k,v in b.items())

for i in range(n):
    x=b[a[i]]
    print(ans-x*(x-1)//2+(x-1)*(x-2)//2)

Measured memory_bytes: 25932
const main = (input) => {
  input = input.trim().split('\n')
  const n = parseInt(input[0], 10)
  const nums = input[1].split(' ').map(Number)
  const q = parseInt(input[2], 10)
  const [,,, ...diffs] = input

  let sum = 0

  const d = {}

  for (let i=0; i<nums.length; i++) {
    d[nums[i]] = ~~d[nums[i]] + 1
    sum += nums[i]
  }

  for (let i=0; i<diffs.length; i++) {
    const [a, b] = diffs[i].split(' ').map(Number)

    const count = ~~d[a]

    sum += (b - a) * count
    console.log(sum)
    delete d[a]
    d[b] = ~~d[b] + count
  }


}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 65412
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]

data=[[0]*w for i in range(h)]
for i in range(h):
  for j in range(w):
    if s[i][j]=='#':
      data[i][j]='#'
    else:
      for p in range(-1,2):
        for q in range(-1,2):
          if 0<=i+p<h and 0<=j+q<w and s[i+p][j+q]=='#':
            data[i][j]+=1
for i in range(h):
  print(*data[i],sep='')

Measured memory_bytes: 9296
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
x=[t-h[i]*0.006 for i in range(n)]
y=[abs(a-t) for t in x]
mi,mx=-1,1<<32
for i in range(n):
    if y[i]<mx:
        mx=y[i]
        mi=i
print(mi+1)

Measured memory_bytes: 38384
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  vi v(4);
  rep(i, 4) cin >> v[i];
  int s = accumulate(all(v), 0);
  cout << s / 60 << endl
       << s % 60 << endl;
}

Measured memory_bytes: 3064
import java.util.Scanner;
import java.io.PrintWriter;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());

        String res = "";
        if( a < b && b < c ) res = "Yes";
        else res = "No";

        PrintWriter pw = new PrintWriter(System.out);
        pw.println(res);
        pw.flush();
    }
}


Measured memory_bytes: 26128
# coding: utf-8
N,M,X = map(int,input().split())
item = [list(map(int,input().split())) for i in range(N)]
bag = []

for i in range(2**N):
  temp = []
  job = [0] * M
  for s in range(N):
    if (i>>s)&1:
      temp.append(s)
      for j in range(M):
        job[j] += item[s][j+1]
  for s in range(len(job)):
    if job[s]<X:
      break
  else:
    ans = 0
    for s in temp:
      ans += item[s][0]
    bag.append(ans)
print(min(bag) if len(bag)>=1 else -1)  


Measured memory_bytes: 9196
#include<stdio.h>
#include<iostream>
using namespace std;

int ft(double N)
{int f=0;
if(N<=48.00)f=11;
else if(N<=51.00)f=12;
else if(N<=54.00)f=1;
else if(N<=57.00)f=2;
else if(N<=60.00)f=3;
else if(N<=64.00)f=4;
else if(N<=69.00)f=5;
else if(N<=75.00)f=6;
else if(N<=81.00)f=7;
else if(N<=91.00)f=8;
else if(N>91.00)f=9;

return f;
}

int main()
{
int f=0;
int x;
double N;
while(scanf("%lf",&N)!=EOF)
{
f=ft(N);
switch(f){
case 11:
cout<<"light fly"<<endl;break; 

case 12:
cout<<"fly"<<endl;break; 

case 1:
cout<<"bantam"<<endl;break; 

case 2:
cout<<"feather"<<endl;break; 

case 3:
cout<<"light"<<endl;break; 

case 4:
cout<<"light welter"<<endl;break; 

case 5:
cout<<"welter"<<endl;break; 

case 6:
cout<<"light middle"<<endl;break; 

case 7:
cout<<"middle"<<endl;break; 

case 8:
cout<<"light heavy"<<endl;break; 

case 9:
cout<<"heavy"<<endl;break; 

}
}
return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
int main()
{
    // #ifndef ONLINE_JUDGE
    //    freopen ("input.txt" , "r" , stdin);
	// 	// freopen ("OUTPUT.txt" , "w" , stdout);
	// #endif
    fio;
    ll s,w;
    cin>>s>>w;
    if(w>=s)
    {
        cout<<"unsafe";
    }
    else
    cout<<"safe";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3640
using System;

namespace ITP1_4_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            string op;
            
            while(true)
            {
                string[] str = Console.ReadLine().Split(' ');
                a = int.Parse(str[0]);
                b = int.Parse(str[2]);
                op = str[1];

                if (op == "+")
                    Console.WriteLine("{0}", a + b);
                else if (op == "-")
                    Console.WriteLine("{0}", a - b);
                else if (op == "*")
                    Console.WriteLine("{0}", a * b);
                else if (op == "/")
                    Console.WriteLine("{0}", a / b);
                else break;
            }
        }
    }
}

Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long int lld;
#define sq(x) x*x
#define fr(i,m,n) for(i=m;i<n;i++)
#define vec vector<int>
#define sint set<int>
#define qint queue<int>
#define mip map<int,int>
#define pint priority_queue<int>
#define pb push_back
#define pp pop_back()
#define ft first
#define sd second
#define full(v) v.begin(),v.end()

int main()
{
    int i,j,k,a,b,c,x,y,z,n,m,t;
    string s,u,v;
    cin>>a>>b;
    if(a>9 || b>9) cout<<-1<<endl;
    else cout<<a*b<<endl;
}


Measured memory_bytes: 3628
const input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/);
let s = [];
let h = [];
let c = [];
let d = [];
for (let i = 1; i < input.length; i++) {
    let card = input[i].split(' ');
    let num = Number(card[1]);
    if (card[0] === 'S') {
        s.push(num);
    }
    if (card[0] === 'H') {
        h.push(num);
    }
    if (card[0] === 'C') {
        c.push(num);
    }
    if (card[0] === 'D') {
        d.push(num);
    }
}
let SArray = [];
let HArray = [];
let CArray = [];
let DArray = [];
    for(i = 1; i <= 13; i ++){
        if (s.indexOf(i) === -1) {
          SArray.push(i)
        }
    }
    for (const value of SArray) {
    console.log('S' + ' ' + value);
    }
    
    for(i = 1; i <= 13; i ++){
        if (h.indexOf(i) === -1) {
          HArray.push(i)
        }
    }
    for (const value of HArray) {
    console.log('H' + ' ' + value);
    }
    
    for(i = 1; i <= 13; i ++){
        if (c.indexOf(i) === -1) {
          CArray.push(i)
        }
    }
    for (const value of CArray) {
    console.log('C' + ' ' + value);
    }
    
    for(i = 1; i <= 13; i ++){
        if (d.indexOf(i) === -1) {
          DArray.push(i)
        }
    }
    for (const value of DArray) {
    console.log('D' + ' ' + value);
    }





Measured memory_bytes: 15192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+12;
char s[maxn];
int main()
{
    scanf("%s",s);
    int len=strlen(s);
    ll cnt=0;
    ll ans=0;
    for(int i=len-1;i>=0;)
    {
        if(i>=1&&s[i]=='C'&&s[i-1]=='B')
        {
            cnt++;
            i-=2;
        }
        else if(s[i]=='A')
        {
            ans+=cnt;
            i--;
        }
        else {cnt=0;i--;}
    }
    cout<<ans;
}
/*
char s[maxn];
int main()
{
    int A,B,C,D,N;
    scanf("%d",&N);
    cin>>A>>B>>C>>D;
    scanf("%s",s+1);
    if(A>B)
    {
        swap(A,B);
        swap(C,D);
    }
    s[A]='A';
    s[B]='B';
    for(int i=1;i<=N;i++)
    {

    }
}
*/


Measured memory_bytes: 384
N = int(input())
D = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
     'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
a = 26
b = 1
while True:
    if N // (a + 1) == 0:
        break
    b += 1
    a += 26 ** b
A = [0] * b
for i in range(b):
    N -= 26 ** i
for i in range(b - 1, -1, -1):
    A[i] = N // (26 ** i)
    N -= A[i] * (26 ** i)
A = A[::-1]
for a in A:
    print(D[a], end='')
print('')

Measured memory_bytes: 9216
n = gets.to_i
nnn = 1
line = nnn.times.map{gets.split}[0]
#line = ["5", "1 3 4 5 7"]
#line = ["15", "13 76 46 15 50 98 93 77 31 43 84 90 6 24 14"]


datas_arr = line.map(&:to_i)
# datas_arr = [1, 3, 4, 5, 7]

counts = 0

(1..n).each do |num|
    if num % 2 == 1
        if datas_arr[num - 1] % 2 == 1
            counts += 1
        end
    end
end

puts counts

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

using namespace std;

void solve() {
    int H, W;
    cin >> H >> W;

    vector<string> S(H);
    for (auto& s : S) cin >> s;

    vector<vector<bool>> on(26, vector<bool>(26, false));
    // on[x][y] => xがyより上にある

    bool judge = true;
    for (char c = 'A'; c <= 'Z'; ++c) {
        int lx = H, rx = -1, ly = W, ry = -1;
        for (int x = 0; x < H; ++x) {
            for (int y = 0; y < W; ++y) {
                if (S[x][y] != c) continue;
                lx = min(lx, x), rx = max(rx, x);
                ly = min(ly, y), ry = max(ry, y);
            }
        }

        for (int x = lx; x <= rx; ++x) {
            for (int y = ly; y <= ry; ++y) {
                if (S[x][y] == '.') {
                    judge = false;
                } else if (S[x][y] != c) {
                    // S[x][y]はcの上にある
                    on[S[x][y] - 'A'][c - 'A'] = true;
                }
            }
        }
    }

    bool update;
    do {
        update = false;
        for (int k = 0; k < 26; ++k) {
            for (int i = 0; i < 26; ++i) {
                for (int j = 0; j < 26; ++j) {
                    if (on[i][k] && on[k][j] && !on[i][j]) {
                        update = true;
                        on[i][j] = true;
                    }
                }
            }
        }
    } while (update);

    for (int i = 0; i < 26; ++i) {
        if (on[i][i]) judge = false;
    }

    cout << (judge ? "SAFE" : "SUSPICIOUS") << endl;
}

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) solve();
    return 0;
}


Measured memory_bytes: 3112
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<sstream>
#include<stack>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;

int main() {
	char in='-', in2='-';
	bool judge = false;
	while (in2 != 'C') {
		while (in != 'A') {
			cin >> in;
			if (cin.peek() == '\n')
				break;
		}
		if (cin.peek() == '\n')
			break;
		cin >> in2;
		if (in2 != 'C') {
			if (in2 == 'A')
				in = 'A';
			else
				in = '-';
		}
		else {
			judge = true;
			break;
		}
		if (cin.peek() == '\n')
			break;
	}
	if (judge == true)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){

  ll N, x;  cin >> N >> x;
  vector<ll> a(N);  for(int i = 0 ; i < N ; i++)  cin >> a[i];
  vector<ll> cp(N);
  if(x < a[0])  cp[0] = x;
  else          cp[0] = a[0];

  for(int i = 1 ; i < N ; i++){
    if(x < cp[i - 1] + a[i])  cp[i] = x - cp[i - 1];
    else                      cp[i] = a[i];
  }

  ll ans = 0;
  for(int i = 0 ; i < N ; i++)  ans += a[i] - cp[i];

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


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

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

  //整数列が与えられるならば
  vector<int> p(100,0);
  rep(i,n){
    int a;
    cin >> a;
    p[a-1] = a;
  }

  //整数列が与えられなけば答えはX
  if(n==0){
    cout << x << endl;
    return 0;
  }

  //含まれない数の配列を生成
  vector<int> non;
  non.push_back(0);
  non.push_back(101);
  rep(i,100){
    if(p[i]==0) non.push_back(i+1);
  }

  //差の絶対値の最小値を求める
  int mi = 500;
  for(int i : non){
    if(mi>abs(i - x)) mi = abs(i - x);
  }

  //解の候補のうち小さい方を出力
  bool sma = false;
  bool lar = false;
  for(int i : non){
    if(i==x-mi) sma = true;
    if(i==x+mi) lar = true;
  }
  if(sma) cout << x - mi << endl;
  else cout << x + mi << endl;

  return 0;
}


Measured memory_bytes: 3616
N = int(input())
W = list(input() for _ in range(N))

s = W[0][0]

ans = "Yes"
if N != len(list(set(W))):
  ans = "No"
else:
  for i in range(N):
    if W[i][0] == s:
      s = W[i][-1]
      continue
    ans = "No"
print(ans)

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

using namespace std;

int sum[200005];
char s[200005];

int main(){
	int n;
	scanf("%d",&n);
	int i;
	scanf("%s",s + 1);
	for(i = 1;i <= n;i++)sum[i] = sum[i-1] + (s[i] == '.');
	int ans = 2147483647;
	for(i = 0;i <= n;i++)ans = min(ans,i - sum[i] + sum[n] - sum[i]);
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int x,y;
    cin>>x>>y;
    if(y%2==1)
    {
    cout<<"No"<<"\n";
    return 0;
    }
    int crane = abs(y-4*x)/2;
    int turtle = abs(x-crane);
    if(2*crane+4*turtle==y)
    cout<<"Yes"<<"\n";
    else
    cout<<"No"<<"\n";
    
}


Measured memory_bytes: 3588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Main {

    public static void main(String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            String ans = br.readLine();
            if (ans.equals("ABC")) {
                ans = "ARC";
            } else {
                ans = "ABC";
            }
            System.out.println(ans);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 25256
N=int(input())
L=[]
for h in range(N):
    Cx,Cy,h=map(int,input().split())
    L.append([h,Cx,Cy])
L.sort(reverse=True)

for x in range(101):
    for y in range(101):
        cond=True
        H=L[0][0]+abs(x-L[0][1])+abs(y-L[0][2])
        for i in range(1,N):
            h=L[i][0]+abs(x-L[i][1])+abs(y-L[i][2])
            if L[i][0]>0:
                if h!=H:
                    cond=False
                    break
            else:
                if h<H:
                    cond=False
                    break
        if cond:
            break
    if cond:
        break

print(x,y,H)


Measured memory_bytes: 9184
#include <iostream>

using namespace std;

int main()
{
	int a,b,c;
	cin >> a >> b;

	c = a - b;

	if (c == 0) cout << "a == b" << endl;
	else if (c < 0) cout << "a < b" << endl;
	else cout << "a > b" << endl;

	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define FAST_INPUT ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long

using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    
    for (int i=0; i<n; i++) {
        if (i+1-k>0) {
            cout << (a[i]>a[i-k]?"Yes":"No") << endl;
        }
    }
}

int main() {
    FAST_INPUT;

    solve();

    return 0;
}


Measured memory_bytes: 3992
n = int(input())

res = n
for i in range(n + 1):
	cc = 0
	t = i
	while t > 0:
		cc += t % 6
		t //= 6
	t = n - i
	while t > 0:
		cc += t % 9
		t //= 9
	if res > cc:
		res = cc
print(res)

Measured memory_bytes: 40812
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#ifndef NULL
#define NULL 0
#endif
using namespace std;

const int MAXN = 50000 + 10;
const double pi = acos(-1.0);
const double inf = 1e100;
const double eps = 1e-10;

inline double read() //浮点型快读
{
    double num;
    char in;
    double Dec = 0.1;
    bool IsN = false, IsD = false;
    in = getchar();
    while (in != '-' && in != '.' && (in < '0' || in > '9'))
        in = getchar();
    if (in == '-') {
        IsN = true;
        num = 0;
    } else if (in == '.') {
        IsD = true;
        num = 0;
    } else
        num = in - '0';
    if (!IsD) {
        while (in = getchar(), in >= '0' && in <= '9') {
            num *= 10;
            num += in - '0';
        }
    }
    if (in != '.') {
        if (IsN)
            num = -num;
        return num;
    } else {
        while (in = getchar(), in >= '0' && in <= '9') {
            num += Dec * (in - '0');
            Dec *= 0.1;
        }
    }
    if (IsN)
        num = -num;
    return num;
}

int sgn(double d)
{
    if (fabs(d) < eps)
        return 0;
    if (d > 0)
        return 1;
    return -1;
}
int dcmp(double x, double y)
{
    if (fabs(x - y) < eps)
        return 1;
    if (x > y)
        return 0;
    return -1;
}

struct vec{
    double x,y;
    vec(double x,double y) {
        this->x=x;
        this->y=y;
    }
    vec(){}
    vec operator *(const vec& i_T)const{
        return vec(x*i_T.x,y*i_T.y);
    }
    vec operator *(double u)const{
        return vec(x*u,y*u);
    }
    vec operator /(double u)const{
        return vec(x/u,y/u);
    }
    vec operator +(const vec& i_T){
        return vec(x+i_T.x,y+i_T.y);
    }
    vec operator -(const vec& i_T){
        return vec(x-i_T.x,y-i_T.y);
    }
}p[MAXN];
double chaji(vec A, vec B)
{
    return A.x * B.y - A.y * B.x; // 正为A->B左旋
}
double dianji(vec A,vec B)
{
    return A.x*B.x+A.y*B.y;
}
double xiangliang(vec a, vec b, vec c) // 祖父点a,父点b,新增儿子点c
{
    vec A = b-a; // 向量ab
    vec B = c-a; // 向量ac
    return chaji(A, B);
}
double changdu(vec a) //长度
{
    return sqrt(a.x*a.x+a.y*a.y);
}
vec touying(vec a,vec b,vec c) //c投影在ab上的位置
{
    vec A=b-a;
    vec B=c-a;
    double La=changdu(A);
    double Lc=dianji(A,B)/(La*La);
    return vec(Lc*A.x,Lc*A.y)+a;
}
vec fanshe(vec a,vec b,vec c)   //求c关于ab的对称点c'
{
    vec A=touying(a,b,c);
    return vec(A.x*2.0-c.x,A.y*2.0-c.y);
}
vec xiangjiao(vec a,vec b,vec c,vec d); //两直线是否相交
vec zhixian_jiaodian(vec a,vec b,vec c,vec d);   //两直线交点
int main()
{
    int n;
    vec p1,p2;
    cin>>p1.x>>p1.y>>p2.x>>p2.y>>n;
    for(int i=0;i<n;i++)
        cin>>p[i].x>>p[i].y;
    for(int i=0;i<n;i++){
        vec point=touying(p1,p2,p[i]);
        printf("%.8f %.8f\n",point.x+eps,point.y+eps);
    }
    return 0;
}


Measured memory_bytes: 3308
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		Set<Card> exists = new HashSet<Card>();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] tmp;
		String suite;
		int rank;
		for(int i = 0;i < n;i++){
			tmp = br.readLine().split(" ");
			suite = tmp[0];
			rank = Integer.parseInt(tmp[1]);
			exists.add(new Card(suite, rank));
		}
		
		String[] suiteTable = {"S", "H", "C", "D"};
		for(int i = 0;i < suiteTable.length;i++){
			for(int j = 1;j <= 13;j++){
				if(!exists.contains(new Card(suiteTable[i], j))){
					StringBuilder sb = new StringBuilder();
					sb.append(suiteTable[i]);
					sb.append(" ");
					sb.append(j);
					System.out.println(sb.toString());
					sb = null;
				}
			}
		}
	}

}

class Card {
	private String suite;
	private int rank;
	
	Card(){
		
	}
	
	Card(String suite, int rank){
		this.suite = suite;
		this.rank = rank;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + rank;
		result = prime * result + ((suite == null) ? 0 : suite.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Card other = (Card) obj;
		if (rank != other.rank)
			return false;
		if (suite == null) {
			if (other.suite != null)
				return false;
		} else if (!suite.equals(other.suite))
			return false;
		return true;
	}

}

Measured memory_bytes: 16956
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

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

    if (K == 1)
        cout << 0 << endl;
    else
        cout << N - K << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <unordered_map>
#include <algorithm> // std::sort(begin,end)
#include <utility> // std::swap

using namespace std;
using ll = long long;

int main(int argc, char const* argv[])
{
  string s;
  cin >> s;
  int count = 15-s.size();
  for(char &c:s){
    if(c=='o')count++;
  }
  if(count >= 8)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  



  return 0;
}


Measured memory_bytes: 256
/**
*   Bismillahir Rahmanir Rahim.
*   Imtiaz_rafi
*   PCIU, CHITTAGONG
**/
#include<bits/stdc++.h>
using namespace std;
#define speed ios::sync_with_stdio(0);cin.tie(0);
#define rep(i,a) for(ll i=0;i<a;i++)
#define all(v)   v.begin(),v.end()
#define pb push_back
#define pf push_front
#define mp make_pair
// bitshift (1LL<<(3)) *2^3
typedef long long int ll;
int main()
{
    speed;
    ll t,i,c=0;
    string a,b;
    cin>>a>>b;
    for(i=0;i<a.size();i++)
    {
        if(a[i]!=b[i])
        {
            c=-1;
            break;
        }
    }
    if(c==-1)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
}


Measured memory_bytes: 3652
#include <iostream>
using namespace std;
 
int main() {
	
  long n,W;
  cin>>n;
  cin>>W;
  long val[n],wt[n],dp[n][W+1];
  for(long i=0;i<n;i++){
    cin>>wt[i];
    
    cin>>val[i];}
  for(long i=0;i<n;i++){
    for(long w=0;w<=W;w++){
      if(w==0) dp[i][w]=0;
      else if(i==0){
        if (wt[0]<=w) dp[i][w]=val[i];
        else dp[i][w]=0;
      }
      else{
      dp[i][w]=(wt[i]<=w)? max(dp[i-1][w],val[i]+dp[i-1][w-wt[i]]) : dp[i-1][w];
      }
    }
  }
  cout<<dp[n-1][W];
}

Measured memory_bytes: 78336
n = int(input())
lst = list(map(int,input().split()))

s = 0
diff_lst = []
sign_lst = []
for i in lst + [0]:
    diff = i - s
    diff_lst.append(abs(diff))
    sign_lst.append(1) if diff > 0 else sign_lst.append(-1)
    s = i

su = sum(diff_lst)
for i in range(n):
    if sign_lst[i] * sign_lst[i+1] > 0:
        print(su)
    else:
        print(su - diff_lst[i] - diff_lst[i+1] + abs(diff_lst[i] - diff_lst[i+1]))

Measured memory_bytes: 20388
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
x_dis=[0 for _ in range(m-1)]
for i in range(m-1):
    x_dis[i]=x[i+1]-x[i]
x_dis.sort(reverse=True)
ans=0
for j in range(m-1):
    if j>=n-1:
        ans+=x_dis[j]
if n>=m:
    ans=0
print(ans)

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

def lcm(a, b):
    return a * b // gcd (a, b)

A, B, C, D = map(int, input().split())

b_num = B//C + B//D - B//lcm(C, D)
a_num = (A-1)//C + (A-1)//D - (A-1)//lcm(C, D)

print((B-A+1) -(b_num - a_num))

Measured memory_bytes: 3060
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn gcd(a: u64, b: u64) -> u64 {
    assert!(a != 0 || b != 0);
    if a == 0 {
        b
    } else {
        gcd(b % a, a)
    }
}

fn main() {
    input! {
        t: usize,
        abcd: [(u64, u64, u64, u64); t],
    }
    for &(a, b, c, d) in &abcd {
        if a < b || d < b {
            println!("No");
        } else if b <= c {
            println!("Yes");
        } else {
            let gcd_ = gcd(b, d);
            if b - gcd_ + a % gcd_ > c {
                println!("No");
            } else {
                println!("Yes");
            }
        }
    }
}


Measured memory_bytes: 4352
#include <bits//stdc++.h>
using namespace std;
#define int long long
#define rep(i,n,k) for(int i=n;i<k;i++)
#define P make_pair
#define F first
#define S second
#define M LLONG_MAX
signed main(void){
    int n,m,ans,w,p,q;
    ans=0;
    string s,s1,s2;
    vector<int> v;
   cin>>n;
   rep(i,1,n+1){
       if(i%3!=0&&i%5!=0)
       ans+=i;
   }
   cout<<ans<<endl;
   
}


Measured memory_bytes: 3572
#include<stdio.h>
#include<math.h>
#include<string.h>

int main(){
  int h, t, o, n, min = 643, ans;
  char s[11];
  scanf("%s", s);
  
  for (int i = 0; i < strlen(s) - 2; i++){
    h = s[i] - '0';
    t = s[i + 1] - '0';
    o = s[i + 2] - '0';
    n = 100*h + 10*t + o;
    if(min >= fabs(n - 753)){
      min = fabs(n - 753);
    }
  }
  
  printf("%d\n", min);
  
  return 0;
}

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

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

int main(){
    int x,n; cin >> x >> n;
    vector<int> p(n);
    if(n==0){
        cout << x << endl;
        return 0;
    }
    rep(i,n) cin >> p[i];
    sort(p.begin(),p.end());
    vector<int> q(0);
    int now2=0;//pの何番目かをマーク
    rep(i,102){//101の可能性もある
        if(p[now2]==i){
            now2++;
        } else {
            q.push_back(i);
        }
    }
    int ans=0;
    int now=0;
    while(q[now]<=x){
        ans=q[now];
        now++;
    }
    if(q[now]-x<x-ans){
        ans=q[now];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <list>
#include <iomanip>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}

int main() {

	//int n; cin >> n;
	//vector<int>l(n);

	//for (int i = 0; i < n; i++)
	int a, b, c; cin >> a >> b >> c;
	if (c - (a - b)>0) cout << c - (a - b);
	else cout<<0;
		



	//cout<<

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long lli;

const lli inf=1e18;
int n;
lli arr[200001];
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		scanf("%lld",arr+i);
		arr[i]-=i;
	}
	sort(arr+1,arr+n+1);

	lli val=arr[1],sum=0,mx=inf;
	for(int i=1;i<=n;i++) arr[i]-=val,sum+=arr[i];

	mx=sum;
	for(int i=2;i<=n;i++) {
		sum+=(i-1)*(arr[i]-arr[i-1])- (n-i+1)*(arr[i]-arr[i-1]);
		mx=min(mx,sum);
	}
	printf("%lld\n",mx);

	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll INF = 1e12;
const ll MOD = 1000000000 + 7;
#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define mii map<int, int>
#define mci map<char, int>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << "debug: " << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int n, k;
  cin >> n >> k;
  vi p(n), c(n);
  rep(i, n) cin >> p[i], p[i]--;
  rep(i, n) cin >> c[i];
  vi f(n, -1);
  int cta = 0;
  rep(i, n) {
    if (f[i] != -1) continue;
    set<int> st;
    ll nx = p[i];
    st.insert(i), f[i] = cta;
    while (st.find(nx) == st.end()) f[nx] = cta, nx = p[nx];
    ++cta;
  }
  map<int, ll> mp;
  rep(i, n) mp[f[i]] += c[i];
  cta = 0;
  ll ans = -INF;
  rep(i, n) {
    int sz = count(all(f), f[i]);
    if (sz == 0) break;
    ll num = 0;
    ll fund = mp[f[i]];
    int x;
    x = i;
    if (fund < 0)
      rep(j, min(k, sz)) num += c[p[x]], x = p[x], chmax(ans, num);
    else {
      int a = k / sz;
      int b = k - a * sz;
      rep(j, sz) {
        num += c[p[x]], x = p[x];
        if (j < b)
          chmax(ans, a * fund + num);
        else
          chmax(ans, (a - 1) * fund + num);
      }
    }
  }
  out(ans);
}

int main(void) { solve(); }

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007

int main() {

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    ll t = 1;
    //cin>>t;

    while(t--) {
       ll n;
       string s;
       cin>>n>>s;

       int r[n+1]={0},g[n+1]={0},b[n+1]={0};

       for(int i=n-1;i>=0;i--) {

            if(s[i] == 'R') {
                r[i] = r[i+1] + 1;
                g[i] = g[i+1];
                b[i] = b[i+1];
            }
            else if(s[i] == 'G') {
                g[i] = g[i+1] + 1;
                r[i] = r[i+1];
                b[i] = b[i+1];
            }
            else {
                b[i] = b[i+1] + 1;
                r[i] = r[i+1];
                g[i] = g[i+1];
            }
       }



       ll ans = 0;
       char c;

       for(int i=0;i<n;i++) {

                for(int j=i+1;j<n;j++) {
                    if(s[j] != s[i]) {
                        int k = 2*j-i;
                        if((s[i]=='R' && s[j]=='G')||(s[i]=='G'&&s[j]=='R')) c = 'B';
                        else if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R')) c = 'G';
                        else c = 'R';

                        if((k<n && s[k]!=c) || k>=n)  {
                            if(c == 'R') ans+=r[j];
                            else if(c=='G')ans+=g[j];
                            else ans+=b[j];
                        }
                        else if(k<n && s[k]==c ) {
                            if(c == 'R') ans+=r[j]-1;
                            else if(c=='G')ans+=g[j]-1;
                            else ans+=b[j]-1;
                        }
                    }
                }

       }

       cout<<ans<<"\n";

    }
}


Measured memory_bytes: 3640
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k, s; cin >> n >> k >> s;
    V<int> ans(n, 0);
    for (int i = 0; i < k; i++) ans[i] = s;
    
    int pad = 1000000000;
    if (s == 1000000000) pad--;
    for (int i = k; i < n; i++) ans[i] = pad;

    for (int i = 0; i < n; i++) cout << ans[i] << (i == n - 1 ? '\n' : ' ');
    return 0;
}


Measured memory_bytes: 1792
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # map(int, input().split())
    n = int(input())
    ans = 0
    for i in range(1, n + 1):
        if len(str(i)) % 2 == 1:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
n = gets.to_i
rest = Array.new(n).map{Array.new()}
for i in 0..n-1
  rest[i] = gets.chomp.split
  rest[i][1] = rest[i][1].to_i
  rest[i].push(i+1)
end
rest.sort! do |a,b|
   (a[0] <=> b[0]).nonzero? || (b[1] <=> a[1])
end
n.times{|i| puts rest[i][2]}


Measured memory_bytes: 1788
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    S = input().strip()
    print("".join(["x" for i in range(len(S))]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 62188