akhauriyash/Code-Regression huggingface dataset:
#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 mapmax(v) v.rbegin()->first
#define mapmin(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;}

map<long long,long long> prime_factor(long long n) {
    map<long long,long long> ret;
    for(long long i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

int main()
{
	ll n,p,ans=1;
	cin >> n >> p;
	map<ll,ll> m=prime_factor(p);
	for(auto&& e:m) ans*=pow(e.first,e.second/n);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
int A, B; 
cin >> A >> B; 
if(A <= 0 && B >= 0){
cout << "Zero" << endl; 
}
else if(A > 0){
cout << "Positive" << endl; 
}
else if((B-A+1) % 2 == 0){
cout << "Positive" << endl; 
}
else if((B-A+1) % 2 == 1){
cout << "Negative" << endl; 
}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static final long x = 1000000000 + 7;

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		long result = 1;
		for(int i=2;i<=n;i++){
			result *= i;
			result %= x;
		}
		System.out.println(result);
	}

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}



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

    if(400 <=X  && X<=599) cout << 8  <<endl;
    else if(600 <=X  && X<=799) cout << 7  <<endl;
    else if(800 <=X  && X<=999) cout << 6  <<endl;
    else if(1000 <=X  && X<=1199) cout << 5  <<endl;
    else if(1200 <=X  && X<=1399) cout << 4  <<endl;
    else if(1400 <=X  && X<=1599) cout << 3  <<endl;
    else if(1600 <=X  && X<=1799) cout << 2  <<endl;
    else if(1800 <=X  && X<=1999) cout << 1  <<endl;

}


Measured memory_bytes: 3620
X, K, D = map(int, input().split())

c = abs(X) // D
k = min(c, K)
K -= k
if K == 0:
    if X > 0:
        print(abs(X-D*k))
        exit()
    elif X < 0:
        print(abs(X+D*k))
        exit()

if X > 0:
    X -= D*k
    if abs(X-D) < abs(X):
        X -= D
        K -= 1
elif X < 0:
    X += D*k
    if abs(X+D) < abs(X):
        X += D
        K -= 1

if K % 2 == 0:
    print(abs(X))
else:
    print(min(abs(X-D), abs(X+D)))


Measured memory_bytes: 61312
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
//#define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 2e5 + 5, LG = 19, MOD = 998244353;
const int SQ =225;
const long double EPS = 1e-6;
int n, k, a[N], sum[N];
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  cin >> n >> k;
  f(i,0,n){
    cin >> a[i];
//    a[i] = 0;
  }

  f(i,0,k){
    memset(sum,0,sizeof sum);
    for(int i = 0; i < n; i++){
      sum[max(0,i-a[i])]++;
      sum[min(n,i+a[i]+1)]--;
    }
    f(i,0,n){
      if(i)sum[i] += sum[i-1];
      a[i] = sum[i];
    }
    if(*min_element(a,a+n) == n)break;
  }

  f(i,0,n)  cout << a[i] << ' ';


  return 0;
}


Measured memory_bytes: 5220
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;

int main(){
    int N,K;cin>>N>>K;
    vector<int> h(N,0);
    REP(i,N) cin>>h[i];
    sort(h.begin(),h.end());
    
    ll ans = INF;
    REP(i,N-K+1){
        ll tmp = h[K-1+i]-h[i];
        //cout<<h[K-1+i]<<":"<<h[i]<<endl;
        ans = min(ans,tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
def main():
    n = int(input())
    print(solve(n))

def solve(n):
    i = 1
    m = 0
    while i * i <= n:
        if n % i == 0:
            m = i
        i += 1

    return intlog10(n // m)

def intlog10(n):
    return len(str(n))

main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(char, A, B);
  print(A == B ? '=' : A > B ? '>' : '<');
}


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

int main()
{
      int n;
      cin>>n;
      int ac=0;
      int wa=0;
      int tle=0;
      int re=0;
      vector<string> s(n);
      for(int i=0;i<n;i++){
        cin>>s[i];
        if(s[i]=="AC"){
          ++ac;
        }
        else if(s[i]=="WA"){
          ++wa;
        }
        else if(s[i]=="TLE"){
          ++tle;
        }
        else if(s[i]=="RE"){
          ++re;
        }
      }
      cout<<"AC x "<<ac<<endl;
      cout<<"WA x "<<wa<<endl;
      cout<<"TLE x "<<tle<<endl;
      cout<<"RE x "<<re<<endl;
      return 0;
}

Measured memory_bytes: 6436
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int ans[1010][1010];
int A[101010];
int H, W, N;
int main(){
    cin >> H >> W >> N;
    REP(i, N) cin >> A[i];
    int cnt = 0;
    REP(y, H){
        REP(x, W){
            ans[y][x] = cnt + 1;
            A[cnt]--;
            if(!A[cnt])
                cnt++;
        }
    }
    REP(y, H){
        REP(_x, W){
            int x;
            if(y % 2 == 0)
                x = _x;
            else
                x = W - 1 - _x;
            if(_x)
                cout << " ";
            cout << ans[y][x];
        }
        cout << endl;
    }
    return 0;
}


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


int main() {
  int N;
  cin >> N;
  
  long L0=2;
  long L1=1;
  long L;
  
  if(N==1)
  {
    cout << 1 << endl;
  }
  else{
    for(int i=2;i<=N;i++){
      L=L1+L0;
      L0=L1;
      L1=L;
    } 
    cout << L << endl;
  }
}


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

#define int long long int
#define float long double
#define pb push_back
#define fi first
#define se second
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pq priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define prdec(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define mii map<int,int>
#define all(v) v.begin(),v.end()
#define inf LLONG_MAX
int exp(int x,int y,int mod){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x,int mod){return exp(x,mod-2,mod);}


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

	int a,b;
	cin>>a>>b;
	cout<<a*b;
	return 0;
}


Measured memory_bytes: 3604
Program PanasonicB
   Implicit none
   Integer(8)::i,j,k

      Read(*,*) i,j
      If (i==1 .OR. j==1) then
         Write(*,*) 1
      Else
         If (MOD(i,2)==0.OR.MOD(j,2)==0) then
            k=i*j/2
         Else
            k=(i-1)*j/2+(j+1)/2
         End If
         Write(*,*) k
      End If
      Stop

   End Program PanasonicB

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();
		Deque<Integer>[] A = new Deque[N];
		for(int i = 0; i < N; i++) {
			A[i] = new ArrayDeque<>();
			for(int j = 0; j < N-1; j++) {
				A[i].push(sc.nextInt()-1);
			}
		}
		int[] depth = new int[N];
		Deque<Integer> d = new ArrayDeque<>();
		int[] w = new int[N];
		Arrays.fill(w, -1);
		for(int i = 0; i < N; i++)
			d.push(i);
		while(d.size() > 0) {
			int x = d.poll();
			if(A[x].size() == 0)
				continue;
			int y = A[x].pop();
			if(w[y] == x) {
				depth[x] = depth[y] = Math.max(depth[x], depth[y])+1;
				d.push(x);
				d.push(y);
			}
			else
				w[x] = y;
		}
		for(int i = 0; i < N; i++) {
			if(A[i].size() != 0) {
				System.out.println(-1);
				return;
			}
		}
		System.out.println(Arrays.stream(depth).max().getAsInt());

	}

}


Measured memory_bytes: 242416
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())printf("%d ",v[_]);cout<<"\n";}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
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;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin>>n;
	int a,b;cin>>a>>b;
	int co[3]={0};
	rep(i,n){
		int c;
		cin>>c;
		if(c<=a)co[0]++;
		else if(c<=b)co[1]++;
		else co[2]++;
	}
	cout<<min({co[0],co[1],co[2]})<<endl;
}









Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		int N, M, i, j, key = 0;
		String[] ID_U;
		String ID_T;
		Scanner s = new Scanner(System.in);

		N = s.nextInt();
		ID_U = new String[N];
		for (i = 0; i < N; i++) {
			ID_U[i] = s.next();
		}

		M = s.nextInt();
		for (j = 0; j < M; j++) {
			ID_T = s.next();
			for (i = 0; i < N; i++) {
				if (ID_T.equals(ID_U[i])) {
					if (key == 0) {
						System.out.println("Opened by " + ID_T);
						key = 1;
					} else {
						System.out.println("Closed by " + ID_T);
						key = 0;
					}
					break;
				}
			}
			if (i == N)
				System.out.println("Unknown " + ID_T);
		}

		s.close();
	}

}

Measured memory_bytes: 21300
def input_from_console():
    n = int(input().rstrip())

    s_list = []
    for i in range(1, n + 1):
        s, p = input().split()
        p = int(p)
        s_list.append((i, s, p))
    return n, s_list


def solve(n, s_list):
    sorted_city_list = sorted(s_list, key=lambda x: (x[1], -x[2]))
    return '\n'.join(map(str, [item[0] for item in sorted_city_list]))


def main():
    n, s_list = input_from_console()
    print(solve(n, s_list))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		while(true) {

			int h = sc1.nextInt();
			int w = sc1.nextInt();

			if ( h == 0 && w == 0) {
				break;
			}

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

				for ( int j = 0 ; j < w ; j++) {
					System.out.print("#");
				}
				System.out.println();
			}

			System.out.println();

		}

		sc1.close();

	}

}


Measured memory_bytes: 35384
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use proconio::marker::Usize1;
use proconio::{fastout, input};
use std::vec::*;

macro_rules! echo {
  {$x:expr} => {println!("{}", $x)}
}

macro_rules! chmax {
  {$x:expr, $y:expr} => {
    $x = std::cmp::max($x, $y)
  }
}

macro_rules! chmin {
  {$x:expr, $y:expr} => {
    $x = std::cmp::min($x, $y)
  }
}

#[allow(unused_variables)]
#[fastout]
fn main() {
  let n: usize;
  let a: Vec<usize>;
  input! {
    n: usize,
    mut a: [usize; n]
  }
  let mut kazu = 1;
  let mut ans = 0;
  a.sort();
  for i in 0..a.len() - 1 {
    if a[i] == a[i + 1] {
      kazu += 1;
    } else {
      ans += kazu & 1;
      kazu = 1;
    }
  }
  ans += kazu & 1;
  echo!(ans);
}


Measured memory_bytes: 4252
import sys

stdin = sys.stdin

mod = 1000000007
inf = 1 << 60

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

a, b, t = na()
k = 1
ans = 0
while a * k <= t:
    k += 1
    ans += b

print(ans)

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll n;
ll h[e5];
ll ans;

int main(){
  cin >> n;
  for(ll i = 0;i < n;i++) cin >> h[i];
  ll a = accumulate(h,h+n,0ll);
  ll l = 0,r = 0;
  while(a > 0){
    l = r%n;
    while(l < n && h[l] == 0) l = (l+1)%n;
    r = l;
    while(r < n && h[r] != 0){
      h[r]--;
      a--;
      r++;
    }
    ans++;
  }
  cout << ans << endl;
}


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

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

  vector<int> A(N);
  rep(i,0,N-1) cin >> A[i];
  sort(A.begin(), A.end());

  ll ans = 0;
  rep(i,0,N-2) {
    ans += A[N-1-(i+1)/2];
  }

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


Measured memory_bytes: 4000
def primesbelow(N):
    # http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188
    #""" Input N>=6, Returns a list of primes, 2 <= p < N """
    correction = N % 6 > 1
    N = {0:N, 1:N-1, 2:N+4, 3:N+3, 4:N+2, 5:N+1}[N%6]
    sieve = [True] * (N // 3)
    sieve[0] = False
    for i in range(int(N ** .5) // 3 + 1):
        if sieve[i]:
            k = (3 * i + 1) | 1
            sieve[k*k // 3::2*k] = [False] * ((N//6 - (k*k)//6 - 1)//k + 1)
            sieve[(k*k + 4*k - 2*k*(i%2)) // 3::2*k] = [False] * ((N // 6 - (k*k + 4*k - 2*k*(i%2))//6 - 1) // k + 1)
    return [2, 3] + [(3 * i + 1) | 1 for i in range(1, N//3 - correction) if sieve[i]]

k=primesbelow(10000000)
ones=[]
twos=[]
threes=[]
fours=[]
for i in k:
    if i%5==1:
        ones.append(i)
    if i%5==2:
        twos.append(i)
    if i%5==3:
        threes.append(i)
    if i%5==4:
        fours.append(i)

n=int(input())
print(*ones[5:5+n])

Measured memory_bytes: 167012
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i, n) for(int i=0;i<n;++i)
#define REPR(i, n) for(int i = n-1;i>=0;--i)
#define REPI(itr, v) for(auto itr=v.begin();itr!=v.end();+itr)
#define SORT(v, n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define llong long long
#define INF 999999999
#define pb(a) push_back(a)

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

int main(){

  int n, k;
  int x, y;
  cin >> n >> k >> x >> y;

  int sum = 0;
  REP(i, n){
    if(i < k)
      sum += x;
    else
      sum += y;
  }

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



Measured memory_bytes: 256
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = []
for i in range(N):
  ans.append(V[i] - C[i])
 
ans.sort()
for i in range(N):
  if ans[i] < 0:
        ans[i] = 0
  else:
    break
print(sum(ans))

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


void solve () {
    int n, p;
    cin >> n >> p;
    set<int> s;
    s.insert(p);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        s.insert(x);
    }
    vector<int> a;
    auto f = s.begin();
    int prev = *f;
    f++;
    while(f != s.end()) {
        a.push_back(*f - prev);
        prev = *f;
        f++;
    }
    int ans = a[0];
    for (int i = 1; i < (int) a.size(); i++) {
        ans = __gcd(ans, a[i]);
    }
    cout << ans;

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


Measured memory_bytes: 8568
#include<stdio.h>
#include<string.h>
 
int main(void){
  int K;
  char c[101];
  scanf("%d",&K);
  scanf("%s",c);
  if(strlen(c)>K){
    for(int i=0;i<K;i++){
      printf("%c",c[i]);
    }
    printf("...\n");
  }else{
    printf("%s\n",c);
  }

return 0;
}

Measured memory_bytes: 1656
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,x;
    cin>>a>>b>>c;
    x=a*100+b*10+c;
    if (x%4==0)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include<string>
using namespace std;
int arr[200000];
int main() {
    int N,K;
    cin>>N>>K;
    for(int i=0;i<N;i++){
        cin>>arr[i];
    }
    for(int i=0;i<N-K;i++){
        if(arr[i]<arr[K+i]){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
    }

    return 0;
}

Measured memory_bytes: 4276
// Created by sz
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int a,b;
    cin >> a >> b;
    
    int cnt = 0;
    int sum = 1;
    while (sum < b) {
        cnt ++;
        sum += a-1;
    }
    
    cout << cnt << "\n";
    
    return 0;
}



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

int main() {
    long long w,h,x,y;
    cin>>w>>h>>x>>y;
    cout<<(double)(w*h)/2<<' ';
    if(x*2==w && y*2==h){
        cout<<1;
    }else{
        cout<<0;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<ll, ll> P;
int main()
{
    ll N;
    cin >> N;
    vector<ll> T(N), A(N);
    rep(i, N) cin >> T[i] >> A[i];

    ll t = T[0], a = A[0];
    repd(i, 1, N) {
        ll tt = 1, aa = 1;
        if (t > T[i]) {
            tt = (t + T[i] - 1) / T[i];
        }
        if (a > A[i]) {
            aa = (a + A[i] - 1) / A[i];
        }
        t = T[i] * max(tt, aa);
        a = A[i] * max(tt, aa);
    }

    cout << t + a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <deque>

using namespace std;

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

int main(){
    int n,num;
    cin >> n;
    deque<int> dq;
    rep(i,n){
        cin >> num;
        if(((i+n) % 2 )!= 0){
            dq.push_front(num);
        }else{
            dq.push_back(num);
        }
    }
    for(auto itr = dq.begin(); itr != dq.end(); ++itr){
        cout << *itr << endl;
    }

    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define N 100
using namespace std;
int n,a[N][N],ans;
 
bool checkx(int y,int x,int p){
  for(int i=0;i<n;i++)
    if(x!=i&&p>a[y][i])return false;
  return true;
}
 
bool checky(int y,int x,int p){
  for(int i=0;i<n;i++)
    if(y!=i&&p<a[i][x])return false;
  return true;
}
 
int main(){
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)cin>>a[i][j];
    ans=0;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
    if(checkx(i,j,a[i][j])&&checky(i,j,a[i][j]))
      ans=a[i][j];
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;

int main(){

    int A,B,X;
    cin >> A >> B >> X;

    if(X-A < 0){
        cout << "NO" << endl;
        return 0;
    }

    if (X-A <= B){
        cout << "YES" << endl;
        return 0;
    }

    cout << "NO" << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
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();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll A,B;
  long double AA,BB;
  cin>>AA>>BB;
  A=AA,B=BB;
  ll ans=AA*(BB-B)+A*B;
  
  co(ans);
  return 0;
}

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

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }

    map<int, int> mp;
    for(int x : a){
        if(mp[x] == 0){
            mp[x] = 1;
        }
        else{
            mp[x] = 0;
        }
    }

    int ans = 0;
    for(auto m : mp){
        if(m.second == 1){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    double dense = -1;
    int answ = 0, anss = 0;
    for (int an = 0; 100*a*an <= f; ++an) {
        for (int bn = 0; 100*a*an + 100*b*bn <= f; ++bn) {
            int totw = 100*a*an + 100*b*bn;
            for (int cn = 0; totw + c*cn <= f; ++cn) {
                for (int dn = 0; totw + c*cn + d*dn <= f; ++dn) {
                    int tots = c*cn + d*dn;
                    int maxs = (e*totw) / 100;
                    if (tots > maxs) continue;
                    if (chmax(dense, (double)(100*tots)/(totw+tots))) {
                        answ = totw + tots;
                        anss = tots;
                    }
                }
            } 
        }
    }
    cout << answ << " " << anss << endl;
}

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

int main () {
	char s[100001];
	int rs[100001] = {};
	int cr = 1, cl = 0;
	cin >> s;
	int mem;
	for (int i=1; s[i-1]!='\0'; i++) {
		if (s[i-1]=='R' && s[i]=='R')
			cr ++;
		else if (s[i-1]=='L' && s[i]=='L')
			cl ++;
		else if (s[i-1]=='R' && s[i]=='L') {
			mem = i;
			cl ++;
		} else if ((s[i-1]=='L' && s[i]=='R') || s[i]=='\0') {
			if ((cr+cl)%2==0)
				rs[mem-1] = rs[mem] = (cr+cl)/2;
			else if(cr%2==1) {
				rs[mem-1] = (cr+cl+1)/2;
				rs[mem] = rs[mem-1]-1;
			} else {
				rs[mem-1] = (cr+cl-1)/2;
				rs[mem] = rs[mem-1]+1;
			}
			cr=1;
			cl=0;
		}
	}
	for (int i=0; s[i]!='\0'; i++)
		cout << rs[i] << " ";
	cout << endl;
	return 0;
}

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

int main(){
    ll N,x;
    cin >> N >> x;
    vector<ll> box(N);
    rep(i,N){
        cin >> box[i];
    }
    ll ans = 0;
    if (box[0] + box[1] > x){
        if (box[0] > x){
            ans += (box[0] + box[1] - x);
            box[1] = 0;
        }
        else{
            ans += (box[0] + box[1] - x);
            box[1] -= (box[0] + box[1] - x);
        }
    }
    for (ll i = 1; i < N - 1; i++){
        if (box[i] + box[i + 1] > x){
            ans += (box[i] + box[i + 1] - x);
            box[i + 1] -= (box[i] + box[i + 1] - x);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toLong)
    val abList = (1..n).map {
        val (a, b) = readLine()!!.split(' ').map(String::toLong)
        Pair(a, b)
    }.sortedBy { it.first }


    var ans = 0L
    var bi = 0
    val workList = mutableListOf<Long>()
    for (i in 1..m) {
        while (bi != abList.size && abList[bi].first <= i) {
            val work = abList[bi].second
            var index = 0
            workList.run {
                if (this.size == 0) {
                    index = 0
                    return@run
                }
                var l = 0
                var r = this.size - 1
                while (l < r) {
                    val m = (l + r) / 2
                    if (this[m] < work) l = m + 1
                    else if (this[m] > work) r = m - 1
                    else {
                        index = m
                        return@run
                    }
                }
                val comp = this[l].compareTo(work)
                if (comp < 0) {
                    index = l + 1
                } else {
                    index = l
                }
            }

            workList.add(Math.min(index,workList.size), work)
            bi++
        }
        if (workList.isNotEmpty()) {
            ans += workList.removeAt(workList.size - 1)
        }
    }
    println(ans)
}



Measured memory_bytes: 85216
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
int main(){
    lint N,W;
    cin>>N>>W;
    lint w[N],v[N];
    rep(i,N){
        cin>>w[i]>>v[i];
    }
     lint dp[N+1][W+1];
     rep(i,W+1){
         dp[0][i]=0;
     }
     rep(i,N){
         rep(j,W+1){
            if(j>=w[i])dp[i+1][j]=max(dp[i][j-w[i]]+v[i],dp[i][j]);
            else dp[i+1][j]=dp[i][j];
         }
     }
     cout<<dp[N][W];
 }


Measured memory_bytes: 79104
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define debug(x) std::cout << #x << ": " << x << '\n';
#define pb push_back
const int N = 5e5 + 10;
std::vector<int> bal[2 * N];
int b[N], n;
int get(int l, int r) {
	int pred = (l == 0 ? 0 : b[l - 1]);
	auto it = std::lower_bound(bal[pred + N - 1].begin(), bal[pred + N - 1].end(), l);
	if (it == bal[pred + N - 1].end()) {
		auto LEFT = std::lower_bound(bal[pred + N].begin(), bal[pred + N].end(), l);
		auto RIGHT = std::upper_bound(bal[pred + N].begin(), bal[pred + N].end(), r);
		return RIGHT - LEFT;
	}
	auto LEFT = std::lower_bound(bal[pred + N].begin(), bal[pred + N].end(), l);
	auto RIGHT = std::upper_bound(bal[pred + N].begin(), bal[pred + N].end(), std::min(r, *it));
	return RIGHT - LEFT;
}
ll z = 1e9;
int32_t main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0); std::cout.tie(0);
	ll s;
	std::cin >> s;
	if (s <= z) {
		std::cout << "0 0 1 0 0 " << s;
		return 0;
	}
	else {
		ll y2 = (s + z - 1) / z;
		std::cout << "0 0 ";
		ll x1 = z;
		ll x2 = 1;
		ll y1 = z - s % (ll)z;
		if (y1 == z) y1 = 0;
		std::cout << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2;
	}
}

Measured memory_bytes: 23680
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) > (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)


int main(){

    int n;
    cin>>n;

    array<array<int, 100001>, 2> grid{};
    int tmp;
    array<pair<int,int>,2> max_save{make_pair(-1,0),make_pair(-1,0)};//first_maxは何 second_max_num
    REP(i,n){
        scanf("%d", &tmp);
        grid[i & 1][tmp]++;
        if(max_save[i&1].second<grid[i & 1][tmp]){
            max_save[i & 1].first = tmp;
            max_save[i & 1].second = grid[i & 1][tmp];
        }
    }
    sort(grid[0].begin(), grid[0].end(), greater<int>());
    sort(grid[1].begin(), grid[1].end(), greater<int>());
    if(max_save[0].first!=max_save[1].first){
        printf("%d\n", n - max_save[0].second - max_save[1].second);
    }else{
        printf("%d\n",min(n - grid[0][0] - grid[1][1], n - grid[0][1] - grid[1][0]) );
    }
    return 0;
}

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

char map[10][10];

void check(int x, int y);

int main()
{
	int n;
	int x, y;

	cin >> n;

	for (int i = 0; i < n; i++){
		for (int j = 0; j < 8; j++){
			cin >> map[j];
		}
		cin >> x >> y;
		check(x - 1, y - 1); // (1,1) -> map[0][0]

		cout << "Data " << i + 1 << ":" << endl;
		for (int j = 0; j < 8; j++){
			cout << map[j] << endl;
		}
	}
}

void check(int x, int y)
{
	map[y][x] = '0';

	for (int i = 1; i <= 3; i++){
		if (y + i <= 7 && map[y + i][x] == '1'){
			check(x, y + i);
		}
		if (y - i >= 0 && map[y - i][x] == '1'){
			check(x, y - i);
		}
		if (x + i <= 7 && map[y][x + i] == '1'){
			check(x + i, y);
		}
		if (x - i >= 0 && map[y][x - i] == '1'){
			check(x - i, y);
		}
	}
}

Measured memory_bytes: 1168
#include <iostream>
using namespace std;
int main(void){
  long long H;
  cin >> H;
  
  long long count = 0;
  while(H > 0){
    H /= 2;
    count ++;
  }
  
  long long ans = 1;
  for(int i=0;i<count-1;i++){
    ans = ans * 2 + 1;
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int n;
    char str[51];
    int i;
    int count = 0;

    scanf("%d", &n);
    scanf("%s", str);

    for(i=0;i<n-2;i++){
        if(str[i] == 'A'){
            if(str[i+1] == 'B'){
                if(str[i+2] == 'C'){
                    count++;
                }
            }
        }
    }
    printf("%d\n", count);

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
namespace Flandre_Scarlet
{
    #define N 155555
    #define int long long 
    #define mod 1000000007
    #define F(i,l,r) for(int i=l;i<=r;++i)
    #define D(i,r,l) for(int i=r;i>=l;--i)
    #define Fs(i,l,r,c) for(int i=l;i<=r;c)
    #define Ds(i,r,l,c) for(int i=r;i>=l;c)
    #define Tra(i,u) for(int i=G.Start(u),__v=G.To(i);~i;i=G.Next(i),__v=G.To(i))
    #define MEM(x,a) memset(x,a,sizeof(x))
    #define FK(x) MEM(x,0)

    int n,a[N];
    void R1(int &x)
    {
        x=0;char c=getchar();int f=1;
        while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar();
        while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
        x=(f==1)?x:-x;
    }
    void Input()
    {
        R1(n);
        F(i,1,n+1) R1(a[i]);
    }

    int fac[N],ifac[N];
    int qpow(int a,int b,int m)
    {
        int r=1;
        while(b)
        {
            if (b&1) r=r*a%mod;
            a=a*a%mod,b>>=1;
        }
        return r;
    }
    int C(int n,int m)
    {
        if (n<m) return 0;
        return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
    }
    void Soviet()
    {
        fac[0]=1;
        F(i,1,n+1) fac[i]=fac[i-1]*i%mod;
        ifac[n+1]=qpow(fac[n+1],mod-2,mod);
        D(i,n,0) ifac[i]=ifac[i+1]*(i+1)%mod;

        int twice=0;
        //twice=xorsum(a[1~n])^xorsum(1~n)
        F(i,1,n+1) twice^=a[i];
        F(i,1,n)   twice^=i;

        int pos,pos2;
        pos=find(a+1,a+n+1,twice)-a;
        pos2=find(a+pos+1,a+n+1,twice)-a;

        int num=(n-pos2+1)+(pos-1);

        F(i,1,n+1)
        {
            int overlap=C(num,i-1);
            int ans=C(n+1,i)-overlap;
            ans=(ans%mod+mod)%mod;
            printf("%lld\n",ans);
        }
    }

    #define Flan void
    Flan IsMyWife()
    {
        Input();
        Soviet();
    }
    #undef int //long long 
}
int main()
{
    Flandre_Scarlet::IsMyWife();
    getchar();getchar();
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  vector<int> to(n);
  rep(i, n) {
    cin >> to[i];
    to[i]--;
  }
  vector<ll> c(n);
  rep(i, n) cin >> c[i];
  ll ans = -LINF;
  rep(i, n) {
    int now = to[i];
    ll sum = c[now], cnt = 1;
    while (now != i) {
      now = to[now];
      sum += c[now];
      cnt++;
    }
    ll res = 0;
    rep(j, min(k, cnt*2)) {
      now = to[now];
      res += c[now];
      chmax(ans, res);
    }
    if (k <= cnt*2)
      continue;
    now = i;
    res = sum*(k/cnt-1);
    if (k/cnt-1 > 0)
      chmax(ans, res);
    rep(j, cnt+k%cnt) {
      now = to[now];
      res += c[now];
      chmax(ans, res);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string A;
  cin >> A;
  
  if(A[0]=='7' ||A[1]=='7'||A[2]=='7'){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
    

Measured memory_bytes: 3596
#include<string>
#include<string.h>
#include<iostream>
#include <algorithm>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;
int main(void) {
   int n, tmp;
   cin >> n;
   long long int a[n];
   for(int i=0;i<n;i++) cin >> a[i];
   sort(a, a + SIZE_OF_ARRAY(a));
   tmp = a[0];
   for(int i=1;i<n;i++) {
     if(tmp==a[i]) {
        cout << "NO" << endl;
        return 0;
     }
     tmp = a[i];
   }
   cout << "YES" << endl;

}

Measured memory_bytes: 1792
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
// ------ Classes ------ //
class Point {
public:
	long double px, py;
	Point() : px(0), py(0) {};
	Point(long double px_, long double py_) : px(px_), py(py_) {};
	friend bool operator==(const Point& p1, const Point& p2) { return p1.px == p2.px && p1.py == p2.py; }
	friend bool operator!=(const Point& p1, const Point& p2) { return p1.px != p2.px || p1.py != p2.py; }
	friend bool operator<(const Point& p1, const Point& p2) { return p1.px < p2.px ? true : (p1.px == p2.px && p1.py < p2.py); }
	friend bool operator>(const Point& p1, const Point& p2) { return p1.px > p2.px ? true : (p1.px == p2.px && p1.py > p2.py); }
	friend bool operator<=(const Point& p1, const Point& p2) { return !(p1 > p2); }
	friend bool operator>=(const Point& p1, const Point& p2) { return !(p1 < p2); }
	friend Point operator+(const Point& p1, const Point& p2) { return Point(p1.px + p2.px, p1.py + p2.py); }
	friend Point operator-(const Point& p1, const Point& p2) { return Point(p1.px - p2.px, p1.py - p2.py); }
	friend Point operator*(const Point& p1, long double d) { return Point(p1.px * d, p1.py + d); }
	friend Point operator*(long double d, const Point& p1) { return p1 * d; }
	friend Point operator/(const Point& p1, long double d) { return Point(p1.px / d, p1.py / d); }
	Point& operator+=(const Point& p1) { px += p1.px; py += p1.py; return *this; }
	Point& operator-=(const Point& p1) { px -= p1.px; py -= p1.py; return *this; }
	Point& operator*=(long double d) { px *= d; py *= d; return *this; }
	Point& operator/=(long double d) { px /= d; py /= d; return *this; }
};
// ------ Functions ------ //
long double norm(const Point& a) { return a.px * a.px + a.py * a.py; }
long double abs(const Point& a) { return sqrtl(norm(a)); }
long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; }
long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; }
int ccw(Point p0, Point p1, Point p2) {
	Point a = p1 - p0, b = p2 - p0;
	if (crs(a, b) > 1e-10) return 1;
	if (crs(a, b) < -1e-10) return -1;
	if (dot(a, b) < -1e-10) return 2;
	if (norm(a) < norm(b)) return -2;
	return 0;
}
bool is_convex(vector<Point> v) {
	if (v.size() < 3) return false;
	int s = ccw(v[0], v[v.size() - 1], v[1]);
	for (int i = 0; i < v.size(); i++) {
		int r = ccw(v[i], v[(i + v.size() - 1) % v.size()], v[(i + 1) % v.size()]);/*
		if (s == 1 && r == -1) return false;
		if (s == -1 && r == 1) return false;*/
		if (r == 1) return false;
	}
	return true;
}
// ------ Main ------ //
int n; vector<Point> v;
int main() {
	cin >> n; v.resize(n);
	for (int i = 0; i < n; i++) cin >> v[i].px >> v[i].py;
	cout << (is_convex(v) ? 1 : 0) << endl;
}

Measured memory_bytes: 3232
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<map>  
#include<set>
#include<iterator>
#include<list>
#include<utility>
#include<cstdlib>
#include<queue>
#include<stack>
#include<bitset>
//#include<bits/stdc++.h>
#define PI  2*acos(0.0)
#define pb push_back

       
using namespace std;
using ll = long long;
using lli = long long int;
using ld = long double;



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

string str;
cin>>str;
int ans=0,i;


if(str[0]=='R' && str[1]=='R'&& str[2]=='R')
{
	ans=3;
}

else if((str[0]=='R' && str[1]=='R')||(str[1]=='R' && str[2]=='R'))
{
	ans=2;
}
else if(str[0]=='S' && str[1]=='S'&& str[2]=='S')
{
	ans=0;
}
else
{
	ans=1;
}

cout<<ans<<"\n";




	      
	
	
	return 0;
	
	
	       /***Israil Hosen
	            Computer Science & Engineering
	         University Of Rajshahi.
	         ***/
	
	
	
}

Measured memory_bytes: 3128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();

		int max = Math.max(a, b);
		max = Math.max(max, c);

		int d = 0;
		d += max - a;
		d += max - b;
		d += max - c;

		if (d % 2 == 0) {
			System.out.println(d / 2);
		} else {
			System.out.println((d + 3) / 2);
		}
	}
}


Measured memory_bytes: 23252
#include<stdio.h>
int main(){

	int a,b,sum,digit=0;
	while(scanf("%d %d",&a,&b)!=EOF){
		digit=0;
		sum=a+b;
		while(sum>0){
			sum=sum/10;
			digit++;
		}
		printf("%d\n",digit);
	}
	return 0;
}


Measured memory_bytes: 1804
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(),i.end()
#define debug(i) std::cout << i << "\n"



const int INF = 100000000;
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
	if (y == 0)
		return 1;
    if(y%2){
        return (x*pow_mod(x,y-1,mod))%mod;
    }else{
        return pow_mod(x*x,y/2,mod);
    }
}

int main()
{
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!

  ll n,count=0;
  std::cin >> n;
  rep(i, 0, n) { 
    ll a;
    std::cin >> a;
    if (a != i + 1) count++;
  }
  if (count <= 2) std::cout << "YES";
  else
    std::cout << "NO";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n;
	cin>>n;
	vl a(n);
	rep(i,n){cin>>a[i];a[i]-=i+1;}
	sort(all(a));
	int m=n/2;
	ll ans=0;
	for(auto i:a)ans+=abs(i-a[m]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792