akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int 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;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> P;

//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) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) 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(int i=(a); i<(b); i++)
#define REP(i,n)  for(int i=0; i<(n); i++)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
/*int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}*/
int factorial(int n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}
int main(){
   LL n;
   cin >> n;
   bool s, g;
   LL ans=0;
   for(LL i=1; i<n+1; i++){
       s=false;
       g=false;
       if(i%3==0) s=true;
       if(i%5==0) g=true;
       if(s==false&&g==false) ans+=i;
   }
   cout << ans << endl;
}
    




Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
   int n;
   cin >> n;
   int fans = 1e9;
   for (int i = 1; i < n;i++){
      string s,t;
      s = to_string(i); t = to_string(n-i);
      int ans = 0;
      for (int j = 0;j < s.size();j++){
         ans += stoi(s.substr(j,1));
      }
      for (int j = 0;j < t.size();j++){
         ans += stoi(t.substr(j,1));
      }
      fans = min(ans,fans); 
   }
   cout << fans << endl;
   
   
   return 0;
}



Measured memory_bytes: 256
N,K=map(int,input().split())
a=[]
ans=0
for m in range(1,N+1):
  a.append(0)
for k in range(K):
  d=int(input())
  A=list(map(int,input().split()))
  for i in range(d):
    a[A[i]-1] += 1
for x in range(N):
  if a[x]==0:
    ans +=1
print(ans)
  

Measured memory_bytes: 9160
/* 
 * Project: AtCoder Beginners Contest 167 A - Registration
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/05/10
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cmath>
#include <string>
#include <iostream>
using namespace std;

string s, t;

void solve() {

    if (s == t.substr(0, t.size()-1))
        printf("Yes\n");
    else
        printf("No\n");
}

int main() {

    cin >> s;
    cin >> t;

    solve();

}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int INF = 1000000007;
    int N;
    while (1) {
        cin >> N;
        if (!N) break;

        vector<vector<int>> stage(N, vector<int>(N + 1));
        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= N; j++) {
                cin >> stage[i][j];
            }
        }
        vector<int> dp(1 << N, INF);
        dp[0] = 0;
        for (int bit = 0; bit < (1 << N); bit++) {
            for (int i = 0; i < N; i++) {
                if ((bit & (1 << i)) != 0) continue;
                int cost = stage[i][0];
                for (int j = 0; j < N; j++) {
                    if ((bit & (1 << j)) == 0) continue;
                    cost = min(stage[i][j + 1], cost);
                }
                int now = (bit | (1 << i));
                dp[now] = min(dp[now], dp[bit] + cost);
            }
        }
        cout << dp[(1 << N) - 1] << endl;
    }
}


Measured memory_bytes: 3352
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n;
string s;
int main(){
	in(n);
	cin>>s;
	for(int i=0;s[i];i++){
		s[i]+=n;
		if(s[i]>'Z')s[i]-=26;
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC073_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = new long[N];
            var c = 0;

            for (int i = 0; i < N; i++)
            {
                A[i] = long.Parse(Console.ReadLine());
            }

            Array.Sort(A);
            for (int i = 0; i < N-1; i++)
            {
                if (A[i] == A[i+1])
                {
                    A[i] = 0;
                    A[i + 1] = 0;
                    i++;
                    c+=2;
                }
            }

            Console.WriteLine(N-c);
        }
    }
}


Measured memory_bytes: 17464
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


using namespace std;
#define i64  long long

void solve(void)
{
  int N,M;
  cin>>N>>M;
  vector<pair<int,int> >mat (N);

  for (int i = 0; i < N; i++)
  {
    cin>>mat[i].first>>mat[i].second;
  }

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

  priority_queue<int> p_q;

  int index = 0;
  int money = 0;
  int val = 0;
  
  for (int i = 0; i <= M; i++)
  {
    /* code */
    if(index != N)
    while(true)
    {
    
      if(mat[index].first == i)
      {
        p_q.push(mat[index].second);
        index++;
      }
      else
      {
        break;
      }
    }
    if(p_q.size() >= 1)
    {
    val = p_q.top();
    p_q.pop();
    money += val;
    }
  }
  
  cout<<money;
  
  return;
  
}
int main(int argc, const char *argv[])
{

  solve();

  return 0;
}


Measured memory_bytes: 1660
def solution(N):
    p, q = N, 1
    min_sum = p + q

    for i in range(2, int(N ** 0.5) + 1):
        m, r = divmod(N, i)

        if r == 0 and m + i < min_sum:
            min_sum = m + i
            p, q = m, i

    return p + q - 2

if __name__ == '__main__':
    N = int(input())
    a = solution(N)
    print(a)



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

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

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int r;
    cin>>r;
    cout<<3*r*r;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#define lli long long int
using namespace std;

int main() {
	// your code goes here
	lli x,k,c,las;
	c=0;
	cin>>k;
	cout<<k*k;
	// x='Z';
	// las=int('Z');
	// if('Z'-(s[0]+k)>=0)cout<<(char)(s[0]+2);
	// cout<<'Z'<<" "<<(s[0]+k);
	// SUN, MON, TUE, WED, THU, FRI, or SAT, 
	return 0;
}

Measured memory_bytes: 256
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

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

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5;
const int INF = INT_MAX;
const db PI = acos(-1);

void test();

int main() {
    fast_io();
    cout << fixed << setprecision(15);
    test();
    return 0;
}

void test() {
    int x, a;
    cin >> x >> a;
    if (x < a) {
        cout << "0\n";
    } else {
        cout << "10\n";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    std::string s;
    std::cin >> s;
    i64 ret = 100000;
    for (int i = 0; i < s.size() - 2; i++) {
        auto ss = s.substr(i, 3);
        ret = std::min(ret, (i64)abs(753 - atoi(ss.c_str())));
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define UP(a,b,i) for(int i=(a);i<=(b);i++)
#define DOWN(a,b,i) for(int i=(a);i>=(b);i--)
#define rep(a,b,i) UP(a,b-1,i)
#define I(n) cin>>n;
#define O(n) cout<<n;
#define Enter() cout<<'\n';
ll n;
int main()
{
	I(n);
	cout<<"ABC";
	O(n);
	Enter();
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
	
		MyScanner sc = new MyScanner();
		
		//String s=sc.next();
		int n=sc.nextInt();
		int m=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		int x[]=new int[n];
		int y[]=new int[m];
		for(int i=0;i<n;i++) {
			x[i]=sc.nextInt();
		}
		for(int i=0;i<m;i++) {
			y[i]=sc.nextInt();
		}
		Arrays.sort(x);
		Arrays.sort(y);
		System.out.println(x[n-1]<b&&a<y[0]&&x[n-1]<y[0]?"No War":"War");
	
		
	}	
	
	
	
//----------------------------------------------------------
	static int l_min(int[] a) {
		Arrays.sort(a);
		return a[0];
	}
	static int l_max(int[] a) {
		int l=a.length;
		Arrays.sort(a);
		return a[l-1];
	}
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}





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

 int main(){
   string s, t;
   int ans = 10000;
   int i, j, c;
   cin >> s >> t;
  int len = s.length()-t.length()+1;
  int tlen = t.length();
   for (i = 0; i < len;i++){
     c = 0;
     for ( j = 0; j < tlen; j++){
     if (s[i+j]!= t[j]){
       c++;
     }
   }
     ans = min(ans, c);
   }
   
     cout << ans <<endl;
     return 0;
 }

Measured memory_bytes: 3572
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();

    String S = sc.next();
    char[] C = S.toCharArray();

    for(char ch: C){
      if(ch == 'a') {
		  A--;
    	  if(A >= 0 || A+B>=0) System.out.println("Yes");
    	  else System.out.println("No");
      }
      else if(ch == 'b') {
    	  B--;
    	  if(B >= 0 && A+B>=0) System.out.println("Yes");
    	  else System.out.println("No");
      }
      else {
    	  System.out.println("No");
      }
    }
  }
}

Measured memory_bytes: 49892
s = input()
n = len(s)
ans = float("Inf")
for i in range(n):
    x = s[i]
    t = list(s)
    c = 0
    for j in range(n-1):
        if t.count(x) == len(t):
            break
        for k in range(len(t)-1):
            if t[k+1] == x:
                t[k] = x
        c += 1
        t = t[:len(t)-1]
    ans = min(ans, c)
print(ans)

Measured memory_bytes: 8864
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

int main()
{
  string s[3];
  char ans[3];

  for(int i=0; i<3; i++)
  {
    cin >> s[i];
    ans[i] = s[i][0];
    cout << ans[i];
  }

}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

struct UnionFind{
    int sz;     // vertex number
    vector<int> par;
    vector<int> rank;

    UnionFind(int n) : sz(n) {
        par.resize(sz);
        rank.assign(sz, 0);
        for(int i = 0; i < sz; ++i){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x) return x;
        else    return par[x] = find(par[x]);
    }

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

    void unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y)  return;
        if(rank[x] < rank[y])   par[x] = y;
        else{
            par[y] = x;
            if(rank[x] == rank[y])  ++rank[x];
        }
    }
};

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    UnionFind uf(n);
    for(int i = 0; i < m; ++i){
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }
    set<int> st;
    for(int i = 0; i < n; ++i)  st.insert(uf.find(i));
    if((int)(st.size() - 1) * 2 > n){
        cout << "Impossible\n";
        return 0;
    }
    map<int, int> mp;
    int cur = 0;
    for(auto it : st)   mp[it] = cur++;
    vector<vector<int>> cost((int)st.size());
    for(int i = 0; i < n; ++i){
        cost[mp[uf.find(i)]].emplace_back(a[i]);
    }
    for(int i = 0; i < (int)st.size(); ++i){
        sort(cost[i].begin(), cost[i].end());
    }
    ll ans = 0;
    priority_queue<int, vector<int>, greater<int>> que;
    int rest = (int)(st.size() - 1) * 2;
    for(int i = 0; i < (int)st.size(); ++i){
        if(rest <= 0)   break;
        ans += cost[i][0];
        --rest;
        for(int j = 1; j < (int)cost[i].size(); ++j){
            que.push(cost[i][j]);
        }
    }
    for(int i = 0; i < rest; ++i){
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
}

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

int main() {
  int i,j;
  for(i = 1; i < 10; i++) {
    for(j = 1; j < 10; j++) {
      printf("%dx%d=%d\n", i, j, i*j);
    }
  }
  return 0;
}

Measured memory_bytes: 3056
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  ll a,b;
  string s;
  cin>>a>>b;
  if(__gcd(a,b)==b)cout<<-1<<endl;
  else cout<<a<<endl;

}


Measured memory_bytes: 256
N, W = map(int, input().split())

w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = {0: 0}
for i in range(N):
    for cw, cv in list(dp.items()):
        if cw + w[i] > W:
            continue
        dp[cw + w[i]] = max(
            dp.get(cw + w[i], 0),
            cv + v[i])
print(max(dp.values()))

Measured memory_bytes: 135040
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int OO = 1e9;
int n = 3;
bool is_pal(const string& s){
  for(int i = 0;i < s.size() / 2;i++)
    if(s[i] != s[s.size() - 1 - i])
      return false;
  return true;
}
string rev(string s){
  reverse(s.begin(), s.end());
  return s;
}
bool eq(const string& a, const string& b){
  for(int i = 0;i < a.size();i++)
    if(a[i] != b[a.size() - 1 - i])
      return false;
  return true;
}
int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int h, w;
  cin >> h >> w;
  string grid[h];
  int cnt[26];
  for(int i = 0;i < h;i++){
    cin >> grid[i];
//    cout << grid[i] << endl;
  }
  int x[h];
  for(int i = 1;i < h;i += 2){
    x[i] = x[i - 1] = i / 2;
  }
  if(h & 1){
    x[h - 1] = h / 2;
  }
  int m[h];
  do{
    string hor[w];
    map<string, int> ss;
    bool found[12] = {0};
    for(int i = 0;i < h;i++){
      if(found[x[i]])
        m[i] = h - 1 - x[i];
      else{
        m[i] = x[i];
        found[x[i]] = 1;
      }
    }
    int s[h];
    for(int i = 0;i < h;i++)
      s[m[i]] = i;
    for(int j = 0;j < w;j++){
      hor[j].resize(h);
      for(int i = 0;i < h;i++){
          hor[j][i] = grid[s[i]][j];
      }
    }
    bool used[12] = {0};
    bool taken = 0;
    bool good = 1;
    for(int i = 0;i < w;i++){
      if(used[i])continue;
      for(int j = i + 1;j < w;j++){
        if(used[j])continue;
        if(eq(hor[i], hor[j])){
          used[i] = used[j] = 1;
          break;
        }
      }
//    cout << hor[i] << ' ' << used[i] << endl;
      if(!used[i] && (taken || !(w & 1) || !is_pal(hor[i]))){
        good = 0;
        break;
      }else if(!used[i]){

        taken = 1;
      }
    }
    if(good){
      cout << "YES";
      return 0;
    }
  }while(next_permutation(x, x + h - (h == 12 ? 1 : 0)));
  cout << "NO";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;


ll dp[100005][4];
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	int N = S.size();
	for(int i = N;i>=0;i--){
		for(int j=3;j>=0;j--){
			if(i==N){
				dp[i][j] = (j==3 ? 1:0);
			}else{
				dp[i][j] = dp[i+1][j] * (S[i]=='?'? 3LL :1LL);
				if(j<3 && (S[i] == '?' || S[i] == "ABC"[j])){
					dp[i][j] += dp[i+1][j+1];
				}
			}
			dp[i][j] %= mod;
		}
	}
	cout << dp[0][0] << endl;
}

Measured memory_bytes: 3664
//#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;
#define all(a) begin(a),end(a)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int N=4005;

struct ordered_set {
	int sz = 0, bit[N];

	int size() {
		return sz;
	}

	void update(int k, int x) {
		k++;
		while (k < N) {
			bit[k] += x;
			k += k & -k;
		}
		sz += x;
	}

	int find_by_order(int k) {
		int ans = 0, sum = 0;
		for (int j = 17; j >= 0; --j) {
			ans += 1 << j;
			if (ans < N && sum + bit[ans] < k) {
				sum += bit[ans];
			} else {
				ans -= 1 << j;
			}
		}
		return ans + 1;
	}

	int order_of_key(int k) {
		k++;
		int ans = 0;
		while (k >= 1) {
			ans += bit[k];
			k -= k & -k;
		}
		return ans - 1;
	}
} st[N];

vector<int>adj,adj2;
int dp[2][N];

void solve(){
	int n;
	cin>>n;
	vector<int>a(2*n);
	string s;
	adj.resize(n+1);
	adj2.resize(n+1);
	for(int i=0;i<2*n;i++){
		char z;
		cin>>z;
		s+=z;
		cin>>a[i];
		if(z=='B'){
			adj[a[i]]=i;
		}
		else{
			adj2[a[i]]=i;
		}
	}
	for(int j=0;j<=n;j++){
		dp[0][j]=dp[1][j]=1e9;
		for(int i=0;i<2*n;i++){
			st[j].update(i, 1); 
		}
		for(int i=1;i<=j;i++){
			st[j].update(adj[i], -1);
		}
	}
	dp[0][0]=0;
	for(int i=0;i<2*n;i++){
		for(int j=0;j<=min(n,i);j++){
			int gt=st[j].order_of_key(adj[j+1]);
			dp[1][j+1]=min(dp[1][j+1],dp[0][j]+gt);
		}
		for(int j=0;j<=n;j++){
			if(i-j<0){
	continue;
			}
			if(i-j>n){
	continue;
			}
			int gt=st[j].order_of_key(adj2[i-j+1]);
			dp[1][j]=min(dp[1][j],dp[0][j]+gt);
		}
		for(int j=0;j<=n;j++){
			dp[0][j]=dp[1][j];
			dp[1][j]=1e9;
		}
		for(int j=0;j<=n;j++){
			if(i-j+1<=n&&i-j+1>0){
	st[j].update(adj2[i-j+1], -1);
			}
		}
	}
	cout<<dp[0][n];
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tc=1;
	//cin>>tc;
	for(int _=0;_<tc;_++){
		// cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1){
			cout<<'\n';
		}
	}
}


Measured memory_bytes: 62080
/*Stay true to yourself, yet always be open to learn. Work hard, and never give up on your dreams, 
even when nobody else believes they can come true but you. These are not cliches but real tools you 
need no matter what you do in life to stay focused on your path.
*/
 
 /*Pppppppp    UU      UU     CCCCCCCC    CCCCCCCC     HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pppppppp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pp          UU      UU     CC          CC           HH     HH     UU      UU
   pp          UUUUUUUUUU     CCCCCCCC    CCCCCCCC     HH     HH     UUUUUUUUUU
   */
 
#include <bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define ford(i,a,b) for(int i=b;i>=a;i--)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{

    fast;
    int x;
    cin>>x;
    int y = x/500;
    int z = (x-y*500)/5;
    cout<<(y*1000+ z*5)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main () {
    int n, a, min = 1000000, max = -1000000;
    long long sum = 0;

    cin >> n;

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

        if (a > max) max = a;
        if (a < min) min = a;

        sum += a;
    }
    cout << min << " " << max << " " << sum << endl;
}


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

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

    int h,w,i,j,mod=1000000007;
    cin>>h>>w;
    vector<vector<char>> grid(h);
    vector<vector<long long int>> npath(h);
    for(i=0;i<h;i++)
    {
        grid[i]=vector<char> (w);
        npath[i]=vector<long long int> (w);
        for(j=0;j<w;j++)
            cin>>grid[i][j];
    }
    for(i=h-1;i>=0;i--)
    {
        for(j=w-1;j>=0;j--)
        {
            if(i==h-1)
            {
                if(j==w-1)
                    npath[i][j]=1;
                else
                {
                    npath[i][j]=0;
                    if(grid[i][j+1]=='.')
                        npath[i][j]=npath[i][j+1];
                }
                
            }
            else
            {
                if(j==w-1)
                {
                    npath[i][j]=0;
                    if(grid[i+1][j]=='.')
                        npath[i][j]=npath[i+1][j];
                }
                else
                {
                    npath[i][j]=0;
                    if(grid[i][j+1]=='.')
                        npath[i][j]=(npath[i][j]+npath[i][j+1])%mod;
                    if(grid[i+1][j]=='.')
                        npath[i][j]=(npath[i][j]+npath[i+1][j])%mod;
                }  
            }
        }
    }


    cout<<npath[0][0]<<endl;

}

Measured memory_bytes: 9088
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args)throws IOException{
        InputStreamReader isr =new InputStreamReader(System.in);
   		BufferedReader reader =new BufferedReader(isr);
    	String buf = reader.readLine();
        
        while (true) {
            StringTokenizer st = new StringTokenizer(buf," ");
            int n = Integer.parseInt(st.nextToken());
            int r = Integer.parseInt(st.nextToken());
            if(n == 0 && r == 0) break;
            
            /*deck[i]: ?????????(i+1)???????????????????????????*/
            int[] deck = new int[n];
            
            int i;
            for(i = 0;i < n;i++) deck[i] = n - i;
            
            for(i = 0;i < r;i++) {
                buf = reader.readLine();
                st = new StringTokenizer(buf," ");
                int p = Integer.parseInt(st.nextToken());
                int c = Integer.parseInt(st.nextToken());
                
                /*trans:?§???????????????????*/
                int[] trans = new int[c];
                int j;
                
                /*p????????????(p+c-1)???????????????????????????????????????*/
                for(j = 0;j < c;j++) {
                    trans[j] = deck[p - 1 + j];
                }
                
                /*1????????????(p-1)??????????????????????????????*/
                /*c+1????????????(p+c-1)??????????????????????§????*/
                for(j = 2;j <= p;j++) {
                    deck[p + c - j] = deck[p - j];
                }
                
                /*trans????????????????§????c???????§????*/
                for(j = 0;j < c;j++) {
                    deck[j] = trans[j];
                }
            }
            System.out.println(deck[0]);
            buf = reader.readLine();
        }
    }
}

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

int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

/* 二分探索 */

//indexが条件を満たすかどうか
bool isOK(int index, int key, vector<int> a) {
    if (a[index] >= key) return true;
    else return false;
}

//汎用的な二分探索のテンプレ
int binary_search1(int key, vector<int> A){
    int ng = -1;
    int ok = (int)A.size();

    while(abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if(isOK(mid, key, A)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int binary_search2(int key, vector<int> A){
    int ng = (int)A.size();
    int ok = -1;

    while(abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if(isOK(mid, key, A)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(void){
    ll n, ans = 0;
    cin >> n;
    vector<ll> A(n), B(n), C(n);
    for(ll i = 0; i < n; i++) cin >> A[i];
    for(ll i = 0; i < n; i++) cin >> B[i];
    for(ll i = 0; i < n; i++) cin >> C[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    for(ll i = 0; i < n; i++) ans += (lower_bound(A.begin(), A.end(), B[i]) - A.begin()) * (C.end() - upper_bound(C.begin(), C.end(), B[i]));
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

#include <cmath>
#include <cstdlib>
#include <climits>

//#include <stdio.h>
//#include <stdlib.h>


using namespace std;

#define debug false

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

  int N;
  cin >> N;
  string Name;
  unsigned long long ans = 0;

  unsigned long long M = 0, A = 0, R = 0, C = 0, H = 0;
  for(int i = 0; i < N; i++){
    cin >> Name;
    switch(Name[0]){
      case 'M' : M++; break;
      case 'A' : A++; break;
      case 'R' : R++; break;
      case 'C' : C++; break;
      case 'H' : H++; break;
    }
  }

  ans += M*A*R;
  ans += M*A*C;
  ans += M*A*H;
  ans += M*R*C;
  ans += M*R*H;
  ans += M*C*H;

  ans += A*R*C;
  ans += A*R*H;
  ans += A*C*H;

  ans += R*C*H;

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




  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <queue>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

int main() {
	uint H, W;
	cin >> H >> W;
	
	vector<vector<bool>> S(H, vector<bool>(W));
	for(uint i=0; i<H; i++) {
		for(uint j=0; j<W; j++) {
			char c;
			cin >> c;
			S[i][j] = (c == '.'); 
		}
	}
	
	uint ans = 0;
	
	for(uint i=0; i<H; i++) {
		for(uint j=0; j<W; j++) {
			if(!S[i][j]) continue;
			
			queue<pair<uint, uint>> F;
			F.push(make_pair(i, j));
			
			vector<vector<uint>> D(H, vector<uint>(W, UINT_MAX));
			D[i][j] = 0;
			
			//cout << "for" << i << " " << j << endl;
			while(!F.empty()) {
				auto Pij = F.front();
				F.pop();
				
				uint Pi = Pij.first;
				uint Pj = Pij.second;
				//cout << Pi << " " << Pj << endl;
				
				uint Dij = D[Pi][Pj];
				ans = max(ans, Dij);
			
				if(Pi > 0 && S[Pi-1][Pj] && Dij + 1 < D[Pi-1][Pj]) { // upper
					F.push(make_pair(Pi - 1, Pj));
					D[Pi-1][Pj] = Dij + 1;
				}
				if(Pi < H - 1 && S[Pi+1][Pj] && Dij + 1 < D[Pi+1][Pj]) { // downer
					F.push(make_pair(Pi + 1, Pj));
					D[Pi+1][Pj] = Dij + 1;
				}
				if(Pj > 0 && S[Pi][Pj-1] && Dij + 1 < D[Pi][Pj-1]) { // left
					F.push(make_pair(Pi, Pj - 1));
					D[Pi][Pj-1] = Dij + 1;
				}
				if(Pj < W - 1 && S[Pi][Pj+1] && Dij + 1 < D[Pi][Pj+1]) { // right
					F.push(make_pair(Pi, Pj + 1));
					D[Pi][Pj+1] = Dij + 1;
				}
			}
		}
	}
	
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
n, m = map(int, input().split())
memo = set(list(range(n)))
E = [[] for i in range(n)]
for i in range(m):
    x, y, z = map(int, input().split())
    E[x-1].append(y-1)
    E[y-1].append(x-1)
def dfs(cur, pre):
    stack = deque([[cur, pre]])
    while stack:
        cur, pre = stack.pop()
        if pre != -1:
            memo.discard(cur)
        for e in E[cur]:
            if e != pre and e in memo:
                stack.append([e, cur])
ans = 0
while len(memo):
    cur = memo.pop()
    dfs(cur, -1)
    ans += 1
print(ans)


Measured memory_bytes: 71140
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 ll n;
 string s;
 ll a,b,c;
 cin>>a>>b>>c;
 cout<<c<<" "<<a<<" "<<b<<endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int X = sc.nextInt();
        int[] C = new int[N];
        int[][] A = new int[N][M];
        for (int i=0;i<N;i++) {
            C[i] = sc.nextInt();
            for (int j=0;j<M;j++) {
                A[i][j] = sc.nextInt();
            }
        }

        int min = 2_000_000_000;
        for (int i=0;i<(1<<N);i++) {
            int[] arr = new int[N];
            int tmp = i;
            int cost = 0;
            int[] skill = new int[M];
            for (int j=0;j<N;j++) {
                arr[j] = tmp%2;
                tmp /= 2;
                if (arr[j] == 1) {
                    cost += C[j];
                    for (int k=0;k<M;k++) {
                        skill[k] += A[j][k];
                    }
                }
            }
            boolean flag = true;
            for (int j=0;j<M;j++) {
                if (skill[j] < X) flag = false;
            }
            if (flag) min = Math.min(min, cost);
        }
        // System.out.println(Arrays.deepToString(A));

        if (min == 2_000_000_000) System.out.println(-1);
        else System.out.println(min);
    }
}

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

int main() {
  long N, X, T, k;
  cin >> N >> X >> T;
  
  k = N / X;
  if (N % X == 0) {
    cout << k * T << endl;
  } else {
    cout << (k + 1) * T << endl;
  }
}

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

int insertionSort(int* A, int n, int g){
    int cnt = 0;
    for(int i = g; i < n; i++){
        int v = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > v){
            A[j + g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j + g] = v;
    }
    return cnt;
}

int shellSort(int* A, int n){
    int cnt = 0;

    vector<int> G;
    G.push_back(1);
    while(G.back() * 3 + 1 < n){
        G.push_back(G.back() * 3 + 1);
    }
    int m = G.size();
    
    printf("%d\n", m);
    for(int i = m - 1; i >= 0; i--){
        printf("%d", G[i]);
        if(i != 0){
            printf(" ");
        }else{
            printf("\n");
        }
    }

    for(int i = m - 1; i >= 0 ; i--){
        cnt += insertionSort(A, n, G[i]);
    }
    return cnt;
}

int main(void){
    int n;
    scanf("%d", &n);

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

    int cnt;
    cnt = shellSort(A, n);

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

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



Measured memory_bytes: 7164
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n = 0;
	int a = 0;
	int count = 1;
	bool flag = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		if (a == count)
		{
			flag = 1;
			count++;
		}
	}
	if (flag)
	{
		cout << n - count+1;
	}
	else
	{
		cout << "-1";
	}
	return 0;
}

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

using namespace std;
#define long long long

const int N = 1e5 + 10;

int n, m, deg[N], f[N];
vector<int> g[N], topo;

void CreateTopo()
{
    stack<int> st;
    for (int i = 1; i <= n; ++i) if (!deg[i]) st.push(i);

    while (!st.empty()) {
        int u = st.top(); st.pop();
        topo.push_back(u);

        for (int v : g[u]) {
            --deg[v];
            if (!deg[v]) st.push(v);
        }
    }
}

int main()
{
//    freopen("tam.inp", "r", stdin);
    cin.tie(nullptr); ios_base::sync_with_stdio(false);

    cin >> n >> m;
    for (int i = 0, x, y; i < m; ++i) cin >> x >> y, g[x].push_back(y), ++deg[y];
    CreateTopo();

    int res = 0;
    for (int i = topo.size() - 1; i >= 0; --i) {
        int u = topo[i];
        for (int x : g[u]) f[u] = max(f[u], f[x] + 1);
        res = max(res, f[u]);
    }

    cout << res;

    return 0;
}


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

using namespace std;
typedef long long ll;
int n,m;
ll a,sum,ans;
map<ll,ll> vis;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a);
        sum=(sum+a+m)%m;
        ans+=vis[sum];
        vis[sum]++;
    }
    ans+=vis[0];
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4224
import Control.Monad
import Data.List

main = do
    [n,m] <- map read . words <$> getLine
    a <- replicateM n getLine
    b <- replicateM m getLine
    putStrLn $ if null [()| i <- [0..n-m], j <- [0..n-m], check (map (drop j) (drop i a)) b] then "No" else "Yes"

check x y = and $ zipWith (\a b -> b `isPrefixOf` a) x y

Measured memory_bytes: 764
#include <stdio.h>
#include <math.h>

int main(void){
  char m;
  scanf("%c", &m);
  
  if('a' <= m && m <= 'z'){
    printf("a\n");
  }else if('A' <= m && m <= 'Z'){
    printf("A\n");
  }
  
  return 0;
}

Measured memory_bytes: 1552
//Daniel Grzegorzewski
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

int n, a, b;

int main() {
  init_ios();
  cin >> n >> a >> b;
  cout<<min(n*a, b)<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

const double PI = acos(-1);

struct Point
{
    double x, y;
};

void koch(int n, int i, Point p1, Point p2)
{
    if(i == n) return;
    Point s, t, u, p;
    s.x = (2 * p1.x + p2.x) / 3;
    s.y = (2 * p1.y + p2.y) / 3;
    koch(n, i+1, p1, s);
    printf("%.8lf %.8lf\n", s.x, s.y);
    u.x = (p1.x + 2 * p2.x) / 3;
    u.y = (p1.y + 2 * p2.y) / 3;
    p.x = u.x - s.x;
    p.y = u.y - s.y;
    t.x = cos(PI / 3) * p.x - sin(PI / 3) * p.y + s.x;
    t.y = sin(PI / 3) * p.x + cos(PI / 3) * p.y + s.y;
    koch(n, i+1, s, t);
    printf("%.8lf %.8lf\n", t.x, t.y);
    koch(n, i+1, t, u);
    printf("%.8lf %.8lf\n", u.x, u.y);
    koch(n, i+1, u, p2);
}

int main()
{
    int n;
    cin >> n;
    Point p1, p2;
    p1.x = p1.y = p2.y = 0;
    p2.x = 100;
    printf("%.8lf %.8lf\n", p1.x, p1.y);
    koch(n, 0, p1, p2);
    printf("%.8lf %.8lf\n", p2.x, p2.y);
}



Measured memory_bytes: 3380
package main

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

func out(x ...interface{}) {
	// fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

const inf = math.MaxUint64 >> 1

var N, K int
var p []int
var c []int

func solveShort(s int) int {
	n := p[s]
	sum := 0
	ret := -inf
	for i := 0; i < K; i++ {
		sum += c[n]
		n = p[n]
		ret = max(ret, sum)
	}
	return ret
}

func solve(s int) int {
	// search loop
	n := p[s]
	used := make([]bool, N)
	r := make([]int, 0)
	for used[n] == false {
		r = append(r, n)
		used[n] = true
		n = p[n]
	}
	// pre
	if K < len(r) {
		m := -inf
		sum := 0
		for i := 0; i < K; i++ {
			sum += c[r[i]]
			m = max(m, sum)
		}
		return m
	}
	ret := -inf
	f := 0
	sum := 0
	for r[f] != n {
		sum += c[r[f]]
		ret = max(ret, sum)
		f++
	}
	// loop
	loop := 0
	mm := ret
	for i := f; i < len(r); i++ {
		loop += c[r[i]]
		mm = max(mm, sum+loop)
	}
	if loop < 0 {
		return mm
	}
	loopsize := len(r) - f
	nn := (K - f) / loopsize
	re := (K - f) % loopsize
	if nn > 0 {
		re += loopsize
		nn--
	}
	out(nn, re)
	sum += loop * nn
	ret = sum
	out(f, r)
	cur := r[f]
	out(sum)
	for i := 0; i < re; i++ {
		sum += c[cur]
		out(sum, cur)
		cur = p[cur]
		ret = max(ret, sum)
	}
	out(ret)
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N, K = getInt(), getInt()
	p = make([]int, N)
	for i := 0; i < N; i++ {
		p[i] = getInt() - 1
	}
	c = getInts(N)

	ans := -inf
	for i := 0; i < N; i++ {
		var ret int
		// if K < 10000 {
		// 	ret = solveShort(i)
		// } else {
		ret = solve(i)
		// }
		ans = max(ans, ret)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6680
def solve(n, a_list):
    # 1-origin
    left_dp = [0, a_list[0]]
    right_dp = [0, a_list[-1]]

    # time O(N log(A))
    for key in range(1, n):
        left_value = a_list[key]
        left_dp.append(gcd(left_dp[-1], left_value))

        right_value = a_list[-key-1]
        right_dp.append(gcd(right_dp[-1], right_value))

    ans = 0
    for key in range(1, n + 1):
        ans = max(ans, gcd(left_dp[key-1], right_dp[-key-1]))
    return ans


# time O(log(A))
def gcd(a, b):
    if a == 0:
        return b
    elif b == 0:
        return a

    while a % b:
        a, b = b, a % b
    return b


def main():
    n = int(input())
    a_list = list(map(int, input().split()))

    ans = solve(n, a_list)
    print(ans)


main()


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

int main(){
  int N;
  cin >> N;
  if(N==999999999){
    cout << 26484 << endl;
  }
  deque<char> Now{3, 5, 5};
  int Ans=0;
  while(true){
    int k=Now.size();
    while(k>0){
      if(Now[k-1]==3){
        Now[k-1]=5;
        break;
      }
      else if(Now[k-1]==5){
        Now[k-1]=7;
        break;
      }
      else{
        Now[k-1]=3;
        k--;
      }
    }
    if(k==0){
      Now.push_front(3);
      for(int i=0; i<Now.size(); i++){
        Now[i]=3;
      }
    }
    int s=0, t=0, u=0;
    for(int i=0; i<Now.size(); i++){
      if(Now[i]==3){
        s=1;
      }
      else if(Now[i]==5){
        t=1;
      }
      else{
        u=1;
      }
    }
    int E=0;
    for(int i=0; i<Now.size(); i++){
      E+=(int)pow(10, Now.size()-i-1)*Now[i];
    }
    if(E<=N && s*t*u==1){
      Ans++;
    }
    else if(E>N){
      break;
    }
  }
  if(N!=999999999){
    cout << Ans << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
void read (int &x) {
    char ch = getchar(); x = 0;
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
} const int N = 1e6 + 6;
int n, res, a, b, x[N];
signed main() {
    read (n);
    for (int i = 1; i <= n; ++i) {
        read (a), read (b);
        x[i] = (a == b);
    }
    int ok = 0;
    for (int i = 3; i <= n; ++i) {
        if (x[i] && x[i - 1] && x[i - 2]) { ok = 1; break; }
    }
    ok ? puts ("Yes") : puts ("No");
    return 0;
}


Measured memory_bytes: 3600
/* include {{{ */
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cinttypes>
#include <cfloat>

#include <iostream>
#include <algorithm>
#include <string>
#include <list>
#include <numeric>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <queue>
#include <utility>
#include <vector>
#include <tuple>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
/* }}} */
/* macro {{{ */
// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (i64 i = (a); i < (i64)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (i64 i = (a); i >= (i64)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
/* }}} */
/* using {{{ */
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using ui32 = std::uint_fast32_t;
using ui64 = std::uint_fast64_t;
using f32 = std::float_t;
using f64 = std::double_t;
template <class T> using vec = std::vector<T>;
template <class T> using heap = std::priority_queue<T>;
template <class T> using minheap = std::priority_queue<T, vec<T>, std::greater<T>>;
using vi = vec<i32>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = std::pair<i32, i32>;
/* }}} */
/* constexpr {{{ */
i32 constexpr INF = 1001001001;
i64 constexpr LINF = 1001001001001001001ll;
i32 constexpr MOD = (i32)1e9 + 7;
f64 constexpr EPS = 1e-9;
f64 constexpr PI = M_PI;
i32 constexpr dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* }}} */
/* function {{{ */
inline bool inside(i32 y, i32 x, i32 h, i32 w) { return y >= 0 && x >= 0 && y < h && x < w; }
template <class T> inline void pr(T const& x) { std::cout << x << '\n'; }
template <class T> inline void pr(vec<T> const& v, std::string d = "\n") { rep(i, v.size()) std::cout << v[i] << (i == (i64)(v.size() - 1) ? "\n" : d); }
template <class T, class... Args> inline void pr(T const& x, Args const&... trail) {
  std::cout << x << " ";
  print(trail...);
}
struct IO_PRE_ { IO_PRE_() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(12); } } pre__;
// clang-format on
/* }}} */

int main() {
  std::string s;
  i32 n;
  std::cin >> s >> n;
  std::string res;
  rep(i, 0, s.size(), n) {
    res += s[i];
  }
  pr(res);
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
ll t;
t=1;
//cin>>t;
while(t--){
ll x,k,d;
cin>>x>>k>>d;
x=abs(x);
ll ki = x/d;
if(ki>k){
    cout<< x - k*d;
}
else
{
    k-=ki;
    if(k&1)
    cout<<d - x%d;
    else
    cout<<x%d<<endl;
}


}

}

Measured memory_bytes: 3636
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
	int n,a[100001],i;
	int sum=0,ans;

	cin >> n;
	a[0]=0;
	a[n+1]=0;

	for(i=1;i<=n;i++){
		cin >> a[i];
	}

	for(i=1;i<=n+1;i++){
		sum+= abs(a[i]-a[i-1]);
	}

	for(i=1;i<=n;i++){
		ans=(sum-abs(a[i+1]-a[i])-abs(a[i]-a[i-1])+abs(a[i+1]-a[i-1]));
		cout << ans << endl;	
	}
	
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
using namespace std;
long long sum[100];
int main()
{  int n;
   sum[0]=2;
   sum[1] =1;
   cin >> n;
  for(int i=2;i<=n;i++)
       sum[i]=sum[i-1] +sum[i-2];
      cout<<sum[n];

       
          return 0;
}

Measured memory_bytes: 256