akhauriyash/Code-Regression huggingface dataset:
N = int(input())
S = [input() for i in range(N)]
from collections import Counter
ctr = Counter([s[0] for s in S])

ans = 0
import itertools
for ptn in itertools.combinations('MARCH', 3):
    t = 1
    for c in ptn:
        t *= ctr[c]
    ans += t
print(ans)

Measured memory_bytes: 10876
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
string A;
  string B;
  string C;
  cin >>A>>B>>C;
  cout <<A.at(0)<<B.at(0)<<C.at(0)<< endl;
}
  
  


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

int main(){
  int n;cin>>n;
  
  cout<<(n%1000==0?0:1000-n%1000);
}

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

ll dp[51][51][2501];

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

  vector<int> x(N + 1);
  rep(i, N) cin >> x[i + 1];

  dp[0][0][0] = 1;
  for (int i = 1; i <= N; i++)
    for (int j = 0; j <= N; j++)
      for (int k = 0; k <= N * 50; k++) {
        ll n = (j < 1 || k < x[i]) ? 0 : dp[i - 1][j - 1][k - x[i]];
        dp[i][j][k] = dp[i - 1][j][k] + n;
      }

  ll ans = 0;
  for (int t = 1; t <= N; t++)
    ans += dp[N][t][A * t];
  cout << ans << endl;
}


Measured memory_bytes: 50048
#include <iostream>
#include<vector>

using namespace std;

int main()
{
    vector<long long> L;
    int N;
    int cnt = 0;
    cin >> N;
    L.resize(N);
    for (int i = 0; i < N; i++){
        cin >> L[i];
    }
    for (int i = 0; i < N - 2; i++)
    {
        for (int j = i + 1; j < N - 1; j++)
        {
            for (int k = j + 1; k < N; k++)
            {
                long long sum = L[i] + L[j] + L[k];
                long long mL = max(max(L[i], L[j]), L[k]);
                if(sum > (2 * mL)){
                    if((L[i] != L[j]) && (L[j] != L[k]) && (L[k] != L[i])){
                        cnt++;
                    }
                }
            }
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	string S, T;
	cin >> S;
	cin >> T;
	T.pop_back();
	string ans = (S == T) ? "Yes" : "No";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
ABC = list(map(int, input().split()))
ans = 0

while ABC[0] != ABC[1] or ABC[1] != ABC[2] or ABC[2] != ABC[0]:
    max_ABC = ABC.index(max(ABC))
    min_ABC = ABC.index(min(ABC))

    if ABC[max_ABC] - ABC[min_ABC] > 1:
        ABC[min_ABC] += 2
        ans += 1
    else:
        ABC[min_ABC] += 1
        for i in range(3):
            if i != min_ABC and i != max_ABC:
                ABC[i] += 1
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
const int N=100005;
typedef long long LL;
int n,a[N],b[N],p[N],ans;
LL sum;

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

bool cmp(int a,int b)
{
	return a>b;
}

int main()
{
	n=getint();
	rep(i,1,n) a[i]=getint(),sum+=a[i];
	rep(i,1,n) b[i]=getint(),sum-=b[i];
	if(sum<0) return puts("-1"),0;
	sum=0;
	rep(i,1,n) if(a[i]<b[i]) sum+=b[i]-a[i],++ans;
		else p[++*p]=a[i]-b[i];
	sort(p+1,p+1+*p,cmp);
	rep(i,0,*p)
	{
		if(i) sum-=p[i];
		if(sum<=0) return printf("%d\n",i+ans),0;
	}
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a,b,c;
    for(int i=0;i<n;i++){
        int ta;
        cin>>ta;
        a.push_back(ta);
    }
    for(int i=0;i<n;i++){
        int tb;
        cin>>tb;
        b.push_back(tb);
    }
    for(int i=0;i<n-1;i++){
        int tc;
        cin>>tc;
        c.push_back(tc);
    }
    int sum=0;
    for(int i=0;i<n-1;i++){
        sum+=b[a[i]-1];
        if(a[i+1]==a[i]+1){
            sum+=c[a[i]-1];
        }
    }
    sum+=b[a[n-1]-1];
    cout << sum << endl;
}
/*
int main(){
    int n;
    cin>>n;
    vector<int> a,b,c;
    for(int i=0;i<n;i++){
        int ta,tb,tc;
        cin>>ta>>tb;
        a.push_back(ta);
        b.push_back(tb);
        if(i!=n-1){
            cin>>tc;
            c.push_back(tc);
        }
    }
    int sum=0;
    int prev=-1;
    for(int i=0;i<n;i++){
        sum+=b[a[i]-1];
    }
    cout <<sum<<endl;
}*/


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] set = br.readLine().split(" ");
		double a = Double.parseDouble(set[0]);
		double b = Double.parseDouble(set[1]);
		double c = Double.parseDouble(set[2]) * Math.PI / 180;

		double S = a * b * Math.sin(c) / 2;
		double L = a + b + Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(c));
		double h = b * Math.sin(c);
		System.out.println(S + "\n" + L + "\n" + h);
	}
}

Measured memory_bytes: 24272
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <set>
#include <map>
#include <math.h>
#include <bitset>
#include <vector>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

typedef long long ll;

const ll INF = 1e18, MOD = 1e9 + 7;
const int INT_MAX = 1e9;

ll n;

ll a[100000], st1[100000], ptr1, st2[100000], ptr2;



int main () 
{
	cin >> n;

	cout << n * (n - 1) / 2 - n / 2 << endl;

	int sum = 1 + n - n % 2;

	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
			if (i + j != sum)
			{
				printf ("%d %d\n", i, j);
			}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a,b,d,r;
  double f;

  scanf("%d %d",&a,&b);

 d= a / b;
 r= a % b;
 f= (double)a / b;

  printf("%d %d %f\n",d,r,f);
           

return 0;
}


Measured memory_bytes: 2000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int pre[100005];
int main()
{
   int a , b , k;
  	cin >> a >> b >> k;
  	vector< int > v;
  	for(int i = 1 ; i <= min(a , b) ; i++)
    {
		if(a % i == 0 && b % i == 0)
          v.push_back(i);
    }
  	cout << v[v.size() - 1 - k + 1] << endl;
  	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;


int main() {
    ll a,b;cin>>a>>b;
    if(a<=0&&0<=b){cout<<"Zero"<<endl; return 0;}
    else if(a<0&&b<0){
        if((abs(a-b)+1)%2==0){cout<<"Positive"<<endl; return 0;}
        else{cout<<"Negative"<<endl; return 0;}
    }
    else if(a>0&&b>0){
        cout<<"Positive"<<endl;
    }
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int sum=0,mx=0;
	for(int i=0;i<n;++i){
		int p; cin>>p;
		sum+=p;
		mx=max(mx,p);
	}
	cout<<sum-mx/2<<"\n"s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll d[200000];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin>>N;
    rep(i,0,N){
        ll p;
        cin>>p;
        d[p-1]=i;
    }
    ll res=0;
    ll l=0,r=0;
    while(l<N){
        ll t=d[l];
        while(r<N&&t<=d[r]){
            t=d[r];
            r++;
        }
        res=max(res,r-l);
        l=r;
    }
    cout <<N-res<<"\n";
}

Measured memory_bytes: 1792
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY
#====PriorityQueue====

class PriorityQueue
    attr_accessor:heap,:size,:fanc
    def initialize(size,init,&fanc)
      @fanc=fanc
      @size=0
      @heap=Array.new(size){ init }
    end

    def push(x)
        i=@size
        @size+=1
        while i>0
            par=(i-1)/2
            break if @fanc.call(@heap[par],x)!=1
            @heap[i]=@heap[par]
            i=par
        end
        @heap[i]=x
    end

    def pop()
        min_v=@heap[0]
        i=0
        @size-=1
        x=@heap[@size]
        while i*2+1<@size
            left=i*2+1
            right=i*2+2
            left=right if right<@size and @fanc.call(@heap[left],@heap[right])==1
            break if @fanc.call(x,@heap[left])!=1
            @heap[i]=@heap[left]
            i=left
        end
        @heap[i]=x
        return min_v
    end

    def empty?
        return @size.zero?
    end
end
N,M=get_i
A=get_i
pq=PriorityQueue.new(N,-INF){|x,y| y<=>x}
A.each do|a|
    pq.push(a)
end
M.times do
    v=pq.pop/2
    pq.push(v) 
end
ans=0
until pq.empty?
    ans+=pq.pop 
end
puts ans

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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll a, b, c;
    cin >> a >> b >> c;
    ll x = c-a-b;
    if(x>0&&4*a*b < x*x) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int N; cin >> N;
  int d = N % 10;
  if (d == 3) cout << "bon" << endl;
  else if (d == 0 || d == 1 || d == 6 | d == 8) cout << "pon" << endl;
  else  cout << "hon" << endl;
}


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

ll memo[15];

const ll MOD = 1e9+7;

ll fib(ll n){
    if(n <= 0) return 1LL;
    
    if(memo[n] > 0) return memo[n];
    else return memo[n] = (fib(n-1) + fib(n-2))%MOD;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int h,w,k; cin >> h >> w >> k;
    if(w == 1){
        cout << 1 << endl;
        return 0;
    }
    --k;
    vector<ll> bef(w+1, 0LL), now(w+1, 0LL);

    // fib前計算
    fib(w);

    bef[0] = 1LL;
    rep(i,h){
        rep(j, w){
            if(j == 0){
                now[0] = bef[1]*fib(w-3)%MOD + bef[0]*fib(w-2)%MOD;
                now[0] %= MOD;
                continue;
            }
            if(j == w-1){
                now[w-1] = bef[w-2]*fib(w-3)%MOD + bef[w-1]*fib(w-2)%MOD;
                now[w-1] %= MOD;
                continue;
            }
            // 1
            now[j] = (( (fib(w-j-2)*fib(j-2))%MOD )*bef[j-1]) % MOD;
            now[j] %= MOD;
            // 2
            now[j] += (( (fib(w-j-3)*fib(j-1))%MOD )*bef[j+1]) % MOD;
            now[j] %= MOD;
            // 3
            now[j] += (( (fib(w-j-2)*fib(j-1))%MOD )*bef[j]) % MOD;
            now[j] %= MOD;
        }

        rep(j,w){
            bef[j] = now[j];
            now[j] = 0LL;
        }
    }
    
    cout << bef[k] << endl;
}

Measured memory_bytes: 3608
/* UnionFindの練習問題の項にあったのでそれっぽくやってみた
 * ぶっちゃけ愚直に実装したほうがいい
 */
#include <cstdio>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <queue>
#include <utility>
#include <stack>

using namespace std;

typedef long long Long;

#define MN 100000
#define MQ 100000
int N, Q;
int parent[MN + 1];
bool marked[MN + 1];
pair<int, int> queries[MQ];
int group[MN + 1];

int root(int x) {
    if (marked[x]) return x;
    return parent[x] = root(parent[x]);
}
void merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return;
    parent[x] = y;
}

bool input() {
    scanf("%d %d", &N, &Q);
    if (N == 0 && Q == 0) return false;
    for (int i = 2; i <= N; i++) {
        int p;
        scanf("%d", &p);
        parent[i] = p;
    }
    memset(marked, false, N + 1);
    marked[1] = true;
    for (int i = 0; i < Q; i++) {
        char t; int n;
        scanf("%*[ \t\r\n]%c %d", &t, &n);
        if (t == 'M') {
            if (marked[n]) {
                queries[i] = make_pair('X', 0);
                continue;
            }
            marked[n] = true;
        }
        queries[i] = make_pair(t, n);
    }
    return true;
}

void solve() {
    Long ans = 0;
    for (int q = Q - 1; q >= 0; q--) {
        pair<int, int> query = queries[q];
        if (query.first == 'Q') {
            ans += root(query.second);
        } else if (query.first == 'M') {
            marked[query.second] = false;
        }
    }
    printf("%lld\n", ans);
}

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

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

int main() {
  int N, T; cin >> N >> T;
  vector<int> t(N + 2); for (int i = 1; i <= N; i++) cin >> t[i];

  t[N + 1] = 2000000001;
  long long ans = 0;
  for (int i = 1; i <= N + 1; i++) if (t[i] - t[i - 1] < T) ans += t[i] - t[i - 1]; else ans += T;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(int (i) = 1; (i) < (n); (i)++)
int main(){
    int N, T; cin >> N >> T;
    int A[N+1], B[N+1];
    rep(i, N) cin >> A[i+1] >> B[i+1];

    int dp[N+1][T+1][2];
    rep(j, T+1) rep(k, 2) dp[0][j][k] = 0;
    rep(i, N+1) rep(k, 2) dp[i][0][k] = 0;

    rep1(i, N+1) rep1(j, T+1) rep(k,2){
        if(k == 0){
            if(A[i] > j) dp[i][j][k] = dp[i-1][j][0];
            else dp[i][j][k] = max(dp[i-1][j][0], dp[i-1][j-A[i]][0] + B[i]);
        }
        else{ // k == 1
            if(A[i] > j) dp[i][j][k] = max(dp[i-1][j][1], dp[i-1][j-1][0] + B[i]);
            else dp[i][j][k] = max(max(dp[i-1][j][1], dp[i-1][j-1][0] + B[i]), dp[i-1][j-A[i]][1] + B[i]);
        }
    }

    cout << max(dp[N][T][0], dp[N][T][1]) << endl;
}

Measured memory_bytes: 70656
n = int(input())
h = list(map(int, input().split()))

dp = [0]*n
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
  dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))
  
print(dp[-1])

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

int main() {
	int n;
	while (scanf("%d", &n), n) {
		vector<int>E[110];
		rep(i, n) {
			int m; scanf("%d", &m);
			rep(j, m) {
				int p; scanf("%d", &p);
				E[--p].push_back(i);
			}
		}
		vector<int>ans(n);
		iota(ans.begin(), ans.end(), 0);
		int k; scanf("%d", &k);
		rep(i, k) {
			int l; scanf("%d", &l); l--;
			rep(j, ans.size()) {
				if (find(E[l].begin(), E[l].end(), ans[j]) == E[l].end()) {
					ans.erase(ans.begin() + j); j--;
				}
			}
		}
		if (ans.size() != 1)puts("-1");
		else printf("%d\n", ans[0] + 1);
	}
}

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

int main(){
  int N;
  cin >> N;
  
  int coin_500 = 0;
  int coin_5 = 0;
  
  coin_500 = N/500;
  N = N % 500;
  coin_5 = N/5;
  
  cout << coin_500*1000 + coin_5*5 << endl;
}

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

int main(){
  int n; cin >> n;
  int a=0,b=0;
  for(int i=0; i<n; i++){
    string sa,sb; cin >> sa >> sb;
    if(sa > sb) a += 3;
    else if(sa < sb) b += 3;
    else{
      a++;b++;
    }
  }
  cout << a << " " << b << endl;
}

Measured memory_bytes: 1216
def resolve():
    N = int(input())
    W = list(map(int, input().split()))

    ans = sum(W)
    for i in range(N):
        tmp = abs(sum(W[:i + 1]) - sum(W[i + 1:]))
        # print(W[:i + 1], W[i + 1:])
        ans = min(ans, tmp)

    print(ans)


resolve()

Measured memory_bytes: 3060
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
mod = 10**9+7
from itertools import accumulate
lis = list(accumulate([0]+[i for i in range(N+1)]))
ans = 0
for k in range(K, N+2):
    MIN = lis[k]
    MAX = lis[-1]-lis[-1-k]
    ans += (MAX-MIN+1)
    ans %= mod
print(ans)

Measured memory_bytes: 83176
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 3e18;
const double INFD = 1e30;
const double EPS = 1e-9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 25;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
int c[MAXN];
int a[MAXN][MAXN];
int clr[MAXN];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    scanf("%d%d%d", &n, &m, &k);
    bool can = true;
    for (int i = 0; i < n; i++) {
        scanf("%d", &c[i]);
        for (int j = 0; j < m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    for (int j = 0; j < m; j++) {
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += a[i][j];
        }
        if (sum < k) can = false;
    }
    if (!can) {
        printf("-1");
        return 0;
    }
    int ans = INF2;
    for (int i = 0; i < (1 << n); i++) {
        memset(clr, 0, sizeof(clr));
        int cost = 0;
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                cost += c[j];
                for (int s = 0; s < m; s++) {
                    clr[s] += a[j][s];
                }
            }
        }
        bool flag = true;
        for (int s = 0; s < m; s++) {
            if (clr[s] < k) {
                flag = false;
                break;
            }
        }
        if (flag) {
            ans = min(ans, cost);
        }
    }
    printf("%d", ans);
    return 0;
}

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

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

using namespace std;

string x[] = {
    ".,!? ",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz"
};

int n;
string s;

void solve(int i){
    if(!s[i]){
        return;
    }
    if(s[i] == '0'){
        solve(i + 1);
        return;
    }
    int t = s[i++];
    int c = 0;
    while(s[i] == t){
        ++i;
        ++c;
    }
    int p = t - '1';
    cout << x[p][c % x[p].size()];
    solve(i + 1);
}

int main(){
    cin >> n;
    rep(i, n){
        cin >> s;
        solve(0);
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3124
N,*A_=`dd`.split.map &:to_i
A=0,*A_,0
S=A.each_cons(2).reduce(0){|s,(x,y)|s+(y-x).abs}
(1..N).map{|i|
	a=A[i]-A[i-1];b=A[i+1]-A[i]
	if a*b>0
		p S
	else
		p S-[a.abs,b.abs].min*2
	end
}

Measured memory_bytes: 17904
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#define ll long long

using namespace std;


int main(void){
   ll n, a, b;
   cin >> n >> a >> b;
   ll ans = 0;
   if(n%(a+b)==0)
      ans = n/(a+b)*a;
   else{
      ans = n/(a+b)*a;
      ll check = n%(a+b);
      if(check >= a)
         ans += a;
      else
         ans += check;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,a[1005],i,j,k,x=0,y=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
        j=1;k=n-2;x=a[0];y=a[n-1];
        while(j<=k)
        {
            if(x<=y)
            {
                x+=a[j];
                j+=1;
            }
            else
            {
                y+=a[k];
                k-=1;
            }
        }
        if(x>=y)
            printf("%d\n",x-y);
        else
            printf("%d\n",y-x);


}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double	
signed main(){
	ll n, i, j;
	ld p_head;
	cin >> n;
	vector<ld> dp(n+1,0);
	dp[0] = 1;
	for( i = 1 ; i <= n ; i++ ){
		cin >> p_head;
		for( j = i ; j >= 0 ; j-- ){
			dp[j] = dp[j]*(1-p_head) + ( j == 0 ? 0 : dp[j-1])*p_head;
		}
	}
	ld ans = 0;
	for( ll head = 1 , tail ; head <= n ; head++ ){
		tail = n - head;
		if( head > tail ){
			ans += dp[head];
		}
	}
	// printf("%.10lf", ans );
	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        double sum = 0;

        int n = sc.nextInt();

        for (int i = 0; i < n; i++) {
            double amount = sc.nextDouble();

            String type = sc.next();

            if (type.equals("BTC")) {
                amount *= 380000;
            }

            sum += amount;
        }

        System.out.println(sum);
    }
}

Measured memory_bytes: 22612
import java.util.Scanner;
import java.util.Arrays;

class Main{
    public static void main(String[] arg){
	Scanner cin = new Scanner(System.in);
	int[] a = new int[10];
	int[] c = new int[10];
	for(int i=0; i<10; i++){
		a[i] = cin.nextInt();
		c[i] = a[i];
	}
	int count = 1;
	while(count == 1){
		count = 0;
		for(int k=0; k<9; k++){
			if(a[k] < a[k+1]){
				c[k] = a[k+1];
				c[k+1]=a[k];
				for(int i=0; i<10; i++){ a[i] = c[i];}
				count = 1;
			}
		}
	}
	for(int i=0; i<3; i++){System.out.println(a[i]);}
   }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;

int main()
{
    ll k;
    cin >> k;
    ll tmp = pow(10, 7);

    ll sev = 7;
    rep(i, tmp)
    {
        if(sev%k==0){
            cout<<i+1<<endl;
            return 0;
        }
        sev=(sev*10+7)%k;
    }

    cout<<-1<<endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main(){
    lli arr[200001],n,sum,current;
    cin>>n;
    for(lli i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    sum=arr[n-1];
    lli j=n-2;
    lli i=n-3;
    while(i>=0){
        if(i>=0){
            sum+=arr[j];
            i--;
        }
        if(i>=0){
            sum+=arr[j];
            i--;
        }
        j--;
    }
    cout<<sum;
}


Measured memory_bytes: 5164
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> C(N - 1), S(N - 1), F(N - 1);
	for (int i = 0; i < N - 1; i++) cin >> C[i] >> S[i] >> F[i];

	vector<int> ans(N);
	for (int sta = 0; sta < N; sta++) {
		for (int i = sta; i < N - 1; i++) {
			if (ans[sta] >= S[i]) {
				ans[sta] = !!(ans[sta] % F[i]) * F[i] - ans[sta] % F[i] + ans[sta] + C[i];
			}
			else ans[sta] = S[i] + C[i];
		}
	}

	for (const auto &e : ans) cout << e << "\n";

	return 0;
}

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

enum Dir { U, R, D, L };
struct Tank { char x, y; Dir dir; };

const char tank_code[4] = {'^', '>', 'v', '<'};
const pair<char, char> vd[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};

char pool[22][21];
char (*f)[21] = (char (*)[21])pool[1];

int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    // load
    Tank tank;
    int h, w;
    cin >> h >> w;
    memset(pool, '#', sizeof(pool));
    for (int y = 0; y < h; y++) {
      for (int x = 0; x < w; x++) {
        char v;
        cin >> v;
        const char* found = find(tank_code, tank_code + 4, v);
        if (found == tank_code + 4) {
          f[y][x] = v;
        } else {
          tank.x = x;
          tank.y = y;
          tank.dir = (Dir)(found - tank_code);
          f[y][x] = '.';
        }
      }
    }

    // op
    int n;
    cin >> n;
    for (int j = 0; j < n; j++) {
      char op;
      cin >> op;
      if (op == 'S') {
        // shoot
        char x = tank.x;
        char y = tank.y;
        auto& v = vd[tank.dir];
        while (f[y][x] != '#') {
          if (f[y][x] == '*') {
            f[y][x] = '.';
            break;
          }
          x += v.second;
          y += v.first;
        }
      } else {
        // move
        Dir dir = op == 'U' ? U : op == 'R' ? R : op == 'D' ? D : L;
        tank.dir = dir;
        char dest_x = tank.x + vd[tank.dir].second;
        char dest_y = tank.y + vd[tank.dir].first;
        if (f[dest_y][dest_x] == '.') {
          tank.x = dest_x;
          tank.y = dest_y;
        }
      }
    }
    f[tank.y][tank.x] = tank_code[tank.dir];

    // draw
    if (i != 0) cout << endl;
    for (int y = 0; y < h; y++) {
      for (int x = 0; x < w; x++) {
        cout << f[y][x];
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main(){
	int P, Q, R;
	int out;
	cin >> P >> Q >> R;
	out = min(P + Q, Q + R);
	out = min(out, R + P);

	print(out);







	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using lint=long long;
using namespace std;

int main()
{
	int N,K;
	
	cin >> N >> K;
	
	int tmp;
	if(N%2==0)tmp=N/2;
	else tmp=N/2+1;
	
	if(K<=tmp)cout << "YES";
	else cout << "NO";
	cout << endl;
	return 0;
}



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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e4+7;

int dp[8][1010];

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

  int N; cin >> N;
  VI xs(N);
  REP(i,N){
	char c; cin >> c;
	xs[i] = (c=='J'?0:c=='O'?1:2);
  }
  dp[1][0] = 1;
  
  REP(i,N){
	REP(b,8) REP(pb,8){
	  if((b>>xs[i]&1) && pb&b){
		(dp[b][i+1] += dp[pb][i]) %= MOD;
	  }
	}
  }
  
  int ans = 0;
  REP(i,8) (ans += dp[i][N]) %= MOD;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3212
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int n = sc.nextInt();
    int max = 0;
    ArrayList<Integer> list = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      list.add(sc.nextInt());
    }
    list.add(k+list.get(0));
    for (int i = 0; i < n; i++) {
      max = Math.max(max, list.get(i+1)-list.get(i));
    }
    System.out.println(k-max);
    sc.close();
  }
}

Measured memory_bytes: 82408
function Main(input){
  input = input.split(" ").map(a=>~~a)
	var H = input[0];
  var W = input[1];
  var K = input[2];
  var mod = 1000000007;
  
  if(W == 1)return 1;
  
  var validAmidaList = Array(Math.pow(2,(W-1)))
  	.fill(0)
    .map((a,b)=>b)
    .map(a=>a.toString(2))
    .filter(a=>!/11/.test(a))
    .map(a=>"000000"+a)
    .map(a=>a.slice(1-W))
    .map(a=>"0"+a+"0")
  
  var dp = Array(H+1);
  for(var i = 0; i <= H;i++){
  	dp[i] = Array(W).fill(0);
  }
  dp[0][0] = 1;
  
  for(var i = 1; i <= H;i++){
  	validAmidaList.forEach(function(elem){
    	for(var j = 0; j < W; j++){
      	({
        	"10":a=>dp[i][j] += dp[i-1][j-1],
          "01":a=>dp[i][j] += dp[i-1][j+1],
          "00":a=>dp[i][j] += dp[i-1][j]
        })[elem[j]+elem[j+1]]();
        dp[i][j] %= mod;
      }
    })
  }
  
  return dp[H][K-1];
}

if(typeof require !== 'undefined')console.log(Main(require("fs").readFileSync("/dev/stdin", "utf8")));

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

typedef long long ll;
typedef long double ld;

const ll INF = 1000000000000000LL;

ll niz[100005];
ll dist[405][405];

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;

    ll n, m, r;
    cin >> n >> m >> r;
    for(ll i=1; i<=r; i++){
        cin >> niz[i];
    }
    for(ll i=1; i<=n; i++){
        for(ll j=i+1; j<=n; j++){
            dist[i][j] = dist[j][i] = INF;
        }
    }
    for(ll i=1; i<=m; i++){
        ll a, b, c;
        cin >> a >> b >> c;
        dist[a][b] = min(dist[a][b], c);
        dist[b][a] = min(dist[b][a], c);
    }
    for(ll i=1; i<=n; i++){
        for(ll j=1; j<=n; j++){
            for(ll k=1; k<=n; k++){
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
    ll res = INF;
    sort(niz+1, niz+1+r);
    do{
        ll g = 0;
        for(ll i=2; i<=r; i++){
            g += dist[niz[i-1]][niz[i]];
        }
        res = min(res, g);
    } while(next_permutation(niz+1, niz+1+r));
    cout << res << "\n";
    return 0;
}


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

using namespace std;

#define PB push_back
#define SZ(a) (int)a.size()
#define MP make_pair

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
typedef __uint128_t bint;

int main() {

	int N;
	scanf("%d", &N);

	bint product = 1;
	bint check = 1000000000000000000LL;
	bool pos = true;

	for(int i = 0; i < N; i++) {
		ll in;
		scanf("%lld", &in);

		if(in == 0) {
			printf("0\n");
			return 0;
		}

		product *= in;
		if (product > check) {
			pos = false;
		}
	}

	if(pos)
		printf("%lld\n", (ll)product);
	else
		printf("-1\n");

	return 0;
}


Measured memory_bytes: 3828
# 整数列A 
# 3箇所で切って、４つに
# それぞれの総和の最大値と最小値の差の絶対値の最小値

# 中央を固定することを考える(結局、その固定を全検索するが)
# 中央固定後、左側について、両方が同じくらいの値になるのが最適と考えて良いらしい

from itertools import accumulate

N=int(input())
A=list(map(int,input().split()))
SumA=list(accumulate(A))

tmpP=tmpQ=tmpR=tmpS=0
P=Q=R=S=0
ans=10e9
l = 0
r = 2

# midとmid+1の間が中間の切断
for mid in range(1,N-2):

	# l,rは、単調増加であるため、全ての中間点を求めるループの間、クリアの必要がないらしい

	# 次のやつよりも、今のやつの方が大きい限り、継続
	# 必ず、それが逆転する時が最小のはず、という考え。。。
	while l < mid and abs((SumA[mid] - SumA[l+1])-SumA[l+1]) < abs((SumA[mid] - SumA[l])-SumA[l]):
		l += 1

	# 次のやつよりも、今のやつの方が大きい限り、継続
	# 必ず、それが逆転する時が最小のはず、という考え。。。
	while r < N-1 and abs((SumA[N-1]-SumA[r+1])-(SumA[r+1]-SumA[mid])) < abs((SumA[N-1] - SumA[r])-(SumA[r] - SumA[mid])):
		r += 1

	#print("{},{}".format(mid,l))

	P=SumA[l]
	Q=SumA[mid]-SumA[l]
	R=SumA[r]-SumA[mid]
	S=SumA[N-1]-SumA[r]

	#print(P,Q,R,S)
	diff=max(P,Q,R,S)-min(P,Q,R,S)
	diff=abs(diff)
	ans = min(ans,diff)

print(ans)


Measured memory_bytes: 24180
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc088/d.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e9)
typedef long long ll;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int h, w;
    cin >> h >> w;
    vector<vector<char>> m;
    vector<vector<int>> g;
    queue<int> q;

    m.resize(h, vector<char>(w));
    rep(i, h){
        rep(j, w){
            cin >> m[i][j];
        }
    }

    vector<int> dist(h * w);
    rep(i, h * w){
        dist[i] = -1;
    }
    dist[0] = 0;

    g.resize(h * w);
    rep(i, h){
        rep(j, w){
            if(m[i][j] == '#') continue;
            if(i < h - 1 && m[i + 1][j] == '.'){
                g[i * w + j].push_back((i + 1) * w + j);
                g[(i + 1) * w + j].push_back(i * w + j);
            }
            if(j < w - 1 && m[i][j + 1] == '.'){
                g[i * w + j].push_back(i * w + j + 1);
                g[i * w + j + 1].push_back(i * w + j);
            } 
        }
    }
    q.push(0);
    while(!q.empty()){
        int p = q.front();
        q.pop();

        rep(i, g[p].size()){
            if(dist[g[p][i]] >= 0) continue;

            q.push(g[p][i]);
            dist[g[p][i]] = dist[p] + 1;
        }
    }

    if(dist[h * w - 1] > 0){
        int ans = 0;
        rep(i, h){
            rep(j, w){
                if(m[i][j] == '.') ans++;
            }
        }
        cout << ans - dist[h * w - 1] - 1 << "\n";
    }else{
        cout << -1 << "\n";
    }
    return 0;
}

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

int main() {
    
    int n,k;cin>>n>>k;
    long long int h[n],ans=0;
    
    for(int i=0;i<n;++i){
        cin>>h[i];
    }
    sort(h,h+n,greater< long long int >());
    
    for(int i=k;i<n;++i){
        ans+=h[i];
    }

    cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1792
import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
print(n * (n + 1) // 2)

Measured memory_bytes: 3064
N,K=map(int,input().split())

mod=10**9+7

ans=0
for k in range(K,N+1):
    n1=k*(k-1)//2
    n2=N*(N+1)//2-(N-k)*(N-k+1)//2
    ans+=n2-n1+1
    ans%=mod

ans+=1
print(ans)



Measured memory_bytes: 9192
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = intin()

    if n % 2:
        print(n * 2)
    else:
        print(n)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3544
N,K = map(int,input().split())

P = list(map(int,input().split()))

C = list(map(int,input().split()))

ans = -10000000000

if K <= N:
    for i in range(N):
        count = 0
        tmp_point = 0
        nv = i
        while count < K:
            nvv = P[nv]
            nvv -= 1
            tmp_point += C[nvv]
            count += 1
            nv = nvv
            ans = max(ans, tmp_point)
    print(ans)
else:
    loop = [0]*N
    for i in range(N):
        count = 0
        check = [False]*N
        tmp_point = 0
        nv = i
        while True:
            nvv = P[nv]
            nvv -= 1
            if check[nvv] == True:
                break
            check[nvv] = True
            tmp_point += C[nvv]
            count += 1
            nv = nvv
            ans = max(ans, tmp_point)
        loop[i] = [tmp_point, count, i]
    loop.sort(reverse=True)
    #print(loop)
    new_ans = -10000000
    for value, counter, key in loop:
        if value < 0:
            break
        shou = K//counter-1
        amari = K%counter+counter
        tmp_ans = value*shou
        new_ans = max(new_ans, tmp_ans)
        count = 0
        nv = key
        while count < amari:
            nvv = P[nv]
            nvv -= 1
            tmp_ans += C[nvv]
            count += 1
            nv = nvv
            new_ans = max(new_ans, tmp_ans)

        
    print(max(loop[0][0], ans, new_ans))



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

using namespace std;

int N,R;
vector<vector<pair<int, int> > > MapData;
int ShortDistOfEachNode[1501][1501];
bool Used[1501];
set<int> Result;

const int INF = 1e9;

void findShortDistOfEachNode(int StartNode, int *dist) {
	int curNode, cost, sizeOfTo, nextNode, costTo;
	priority_queue<pair<int, int> > NodeList;
	pair<int, int> tmp;

	for (int i = 1; i <= N; ++i) {
		fill(dist, dist + N + 1, INF);
	}
	dist[StartNode] = 0;
	NodeList.push({ StartNode,0 });
	while (!NodeList.empty()) {
		tmp = NodeList.top();
		NodeList.pop();

		curNode = tmp.first;
		cost = tmp.second;
		if (cost > dist[curNode]) {
			continue;
		}
		sizeOfTo = MapData[curNode].size();
		for (int i = 0; i < sizeOfTo; ++i) {
			nextNode = MapData[curNode][i].first;
			costTo = MapData[curNode][i].second;
			if (cost + costTo < dist[nextNode]) {
				dist[nextNode] = cost + costTo;
				NodeList.push({ nextNode,dist[nextNode] });
			}
		}

	}
}

void findNode(int startNode, int curNode, int *dist) {
	int sizeOfTo, preNode, cost;

	if (Used[curNode]) {
		return;
	}
	Used[curNode] = true;
	Result.insert(curNode);
	if (startNode == curNode) {
		return;
	}

	sizeOfTo = MapData[curNode].size();
	for (int i = 0; i < sizeOfTo; ++i) {
		preNode = MapData[curNode][i].first;
		cost = MapData[curNode][i].second;
		if (dist[curNode] == dist[preNode] + cost) {
			findNode(startNode, preNode, dist);
		}
	}
}

int main() {
	int s, t, d, maxShortLen;

	cin >> N >> R;
	MapData.resize(N + 1);
	for (int i = 0; i < R; ++i) {
		cin >> s >> t >> d;
		MapData[s].push_back({ t,d });
		MapData[t].push_back({ s,d });
	}
	for (int i = 1; i <= N; ++i) {
		findShortDistOfEachNode(i,ShortDistOfEachNode[i]);
	}
	
	maxShortLen = 0;
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) {
			if (ShortDistOfEachNode[i][j] == INF) {
				continue;
			}
			maxShortLen = max(maxShortLen, ShortDistOfEachNode[i][j]);
		}
	}

	for (int i = 1; i <= N; ++i) {
		memset(Used, false, sizeof(Used));
		for (int j = 1; j <= N; ++j) {
			if (ShortDistOfEachNode[i][j] == maxShortLen) {
				findNode(i, j, ShortDistOfEachNode[i]);
			}
		}
	}

	cout << N - Result.size() << endl;
	for (int i = 1; i <= N; ++i) {
		if (Result.find(i) == Result.end()) {
			cout << i << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 12096
MODINT = 1000000007
n,k = map(int,input().split())
prod = [0]*(n+1)

for i in range(1,n+1):
    prod[i] = prod[i-1]+i
# print(prod)
ans = 0
for s in range(k-1,n+1):
    L = prod[s]
    R = prod[n] - prod[n-s] + (n-s)
    # print(L,R)
    ans += R-L+1
    ans %= MODINT
print(ans)

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

typedef long long ll;

int main() {
    string N;
    int ans = 0;
    cin >> N;
    int len = N.size();
    if (len == 1) {
        cout << N << endl;
        return 0;
    }
    int total = 0;
    for (int i = 0; i < len; i++) {
        total += N[i] - '0'; 
    }
    ans = max(ans, total);
    for (int i = 0; i < len; i++) {
        total = 0;
        if (N[i]-'0' > 0) {
            for (int j = 0; j <= i; j++) {
                total += N[j] - '0';
            } 
            total--;
            total += 9 * (len-i-1);
            ans = max(ans, total);
            
        } else {
            continue;
        }
    }
    cout << ans << endl;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  int correct = 0;
  for (int i = 0; i < 3; ++i)
    correct += (s[i] == t[i]);
  cout << correct << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  int p[5011], z[5011],sum,ans;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> p[i];
  }
  ans=1000000;
  for(int a=0;a<=p[0];a++){
    sum=a;
    z[0]=a;
    for(int i=1;i<n;i++){
      sum+=(p[i-1]-z[i-1])*2;
      z[i]=p[i-1]-z[i-1];
      if(p[i]<z[i]){
	z[i]=p[i];
      }
    }
    sum+=p[n-1]-z[n-1];
    if(ans>sum){
      ans=sum;
    }
  }
  cout << ans << endl;
  return(0);
}



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

int main( )
{
  string s;
  int count = 0;
  cin >> s;
  
  for(int i = 0; i < 3; i++) {
    if(s[i] == '1'){
      count++;
    }
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
 
using namespace std;
 
int main()
{
	int n, k;
	long long int ans=0;
	scanf("%d %d", &n, &k);
	
	for(int b=k+1; b<=n; b++){
		for(int x=0; x<=((n-k)/b); x++){
			if(x==0 && k==0 && n-b*x<=b-1){
				ans=ans+n-k;
			}else if(x==0 && k==0 && n-b*x>b-1){
				ans=ans+b-1;
			}else if(n-b*x<=b-1){
				ans=ans+n-k-b*x+1;
			}else{
				ans=ans+b-k;
 
			}
		}
	}
 
	printf("%lld\n", ans);
 
	return 0;
}

Measured memory_bytes: 128
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    n <- readLn :: IO Int
    let nLen = length (show n)
    let rest = if odd nLen then (if nLen==1 then n else 1 + n - (10 ^ (nLen-1))) else 0
    print (solve (nLen-1) + rest)



solve n
    | n <= 0    = 0
    | n == 1    = 9
    | even n    = solve (n-1)
    | otherwise = (9*(10 ^ (n-1))) + solve (n-2)



Measured memory_bytes: 508
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int[][] c = new int[3][3];
        for(int i=0; i<3; i++) {
            for(int j=0; j<3; j++) {
                c[i][j] = sc.nextInt();
            }
        }
 
        int[] x = new int[3];
        int[] y = new int[3];
        x[0] = 0;
        for(int i=0; i<3; i++) {
            y[i] = c[0][i] - x[0];
        }
        for(int i=0; i<3; i++) {
            x[i] = c[i][0] - y[0];
        }
 
        for(int i=0; i<3; i++) {
            for(int j=0; j<3; j++) {
                if(c[i][j] != x[i]+y[j]) {
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 35628