akhauriyash/Code-Regression huggingface dataset:
#include <cctype>
#include <cstdio>
#include <algorithm>
#define rep(i,x,y) for (int i=x; i<=y; ++i)

int get()
{
    char c;
    while (!isdigit(c=getchar()));
    int k=c-'0';
    for (; isdigit(c=getchar()); k=k*10+c-'0');
    return k;
}

using namespace std;
const int N=3010,mod=1e9+7;
char s[N];
int n,m,ans,l[N],r[N],c[N][N],f[N][N],a[N];

int main()
{
    n=get(),m=get();
    rep(i,0,n)
    {
        c[i][0]=1;
        rep(j,1,i)
            c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
    }
    scanf("%s",s+1);
    rep(i,1,n)
        a[i]=a[i-1]+s[i]-48;
    int t=0;
    rep(i,1,m)
    {
        int x=get(),y=get();
        if (x==l[t])
            r[t]=max(r[t],y);
        else if (y>r[t])
            ++t,l[t]=x,r[t]=y;
    }
    m=t,l[m+1]=n+1,f[0][0]=1;
    rep(i,1,m)
    {
        int w=a[r[i]]-a[max(l[i]-1,r[i-1])];
        int s=min(r[i],l[i+1]-1)-l[i]+1;
        int mx=r[i]-l[i]+1-s;
        rep(j,0,s)
            rep(k,max(0,w-j),mx)
                f[i][k]=(f[i][k]+1ll*f[i-1][j+k-w]*c[s][j])%mod;
    }
    rep(i,0,n)
        ans=(ans+f[m][i])%mod;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 51072
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline int read()
{int x=0,f=0;
char c=getchar();
while (c<'0'||c>'9') 
{if (c=='-') f=1;
c=getchar();
}
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
if (f) x=-x;
return x;
}
int main (){
	int ans=1;ll x,y;
	scanf ("%lld%lld",&x,&y);
	while (x*2<=y) {x*=2;ans++;}
	printf ("%d\n",ans);
	return 0;
}

Measured memory_bytes: 764
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c;
	cout<<a<<" "<<b<<" "<<3*c-a-b<<endl;
	cout<<4*c-2*a-b<<" "<<c<<" "<<2*a+b-2*c<<endl;
	cout<<a+b-c<<" "<<2*c-b<<" "<<2*c-a<<endl;
return 0;
}


Measured memory_bytes: 256
MOD=10**9+7
n=int(input())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
l=[[1,10**9] for i in range(n)]
tmp=0
for num,i in enumerate(la):
    if i>tmp:
        l[num][0]=i
        l[num][1]=i
    else :
        l[num][1]=i
    tmp=max(tmp,i)
tmp=0
ans=1
for i in range(n-1,-1,-1):
    if lb[i]<l[i][0]:
        print(0);exit()
    elif lb[i]>tmp:
        if lb[i]<=l[i][1]:ans*=1 
        else:print(0);exit()
    else:
        ans=ans*(min(lb[i],l[i][1])-l[i][0]+1)%MOD
    tmp=max(tmp,lb[i])
print(ans)

Measured memory_bytes: 21700
# 貪欲　嘘解法 




N,K = map(int,input().split())
A = list(map(int,input().split()))
degit = len(format(10**12,"b"))
bit_1 = [0]*degit
bit_0 = [0]*degit
for a in A:
    string = format(a,"b")
    length = len(string)
    for i in range(length):
        index = degit - length + i
        if string[i] == "1":
            bit_1[index] += 1
        elif string[i] == "0":
            bit_0[index] += 1
    for j in range(degit-length):
        bit_0[j] += 1
        
can = ["0"]*degit

for i in range(degit):
    if bit_1[i] >= bit_0[i]:
        can[i] = "0"
    elif bit_1[i] < bit_0[i]:
        copy = can[:]
        copy[i] = "1"
        res = int("".join(copy),2)
        if res <= K:
            can = copy

can = int("".join(can),2)

ans = 0
for a in A:
    ans += can ^ a

print(ans)

Measured memory_bytes: 14620
package main

import (
	"fmt"
)

func main() {
	var n, m, c, a, cal int
	fmt.Scan(&n, &m, &c)

	arrB := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&arrB[i])
	}

	count := 0
	for i := 0; i < n; i++ {
		cal = c
		for j := 0; j < m; j++ {
			fmt.Scan(&a)
			cal += a * arrB[j]
		}

		if cal > 0 {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 200500000000000
#define MOD 10007
#define N 100005
#define M 1000005
#define LOG 18
#define KOK 4000000
using namespace std;

int n,a[3][N];
ll pre[3][N],suf[3][N];
ll ans;

int main() {

	//freopen("input.txt","r",stdin);

	scanf("%d",&n);

	for(int i=1;i<=2;i++) {

		for(int j=1;j<=n;j++) scanf("%d",&a[i][j]);

	}

	for(int i=1;i<=2;i++) {

		for(int j=1;j<=n;j++) pre[i][j]=pre[i][j-1]+a[i][j];

		for(int j=n;j>=1;j--) suf[i][j]=suf[i][j+1]+a[i][j];	

	}

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

		umax(ans,pre[1][i]+suf[2][i]);

	}

	printf("%lld",ans);

}



Measured memory_bytes: 2304
#include <iostream>

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

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll A, ll B, ll C, ll X) {
  int ans{};
  for (int i = 0; i <= A; ++i) {
    for (int j = 0; j <= B; ++j) {
      for (int k = 0; k <= C; ++k) {
        if (500 * i + 100 * j + 50 * k == X) ++ans;
      }
    }
  }
  cout << ans << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  ll C;
  cin >> C;
  ll X;
  cin >> X;
  solve(A, B, C, X);
  return 0;
}


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

using namespace std;

int main(){
	int n, m, c;
	cin >> n >> m >> c;
	vector<int> vec(m);
	for (int i = 0; i < m; i++) cin >> vec[i];
	int ans = 0;
	while (n--) {
		int sum = 0;
		for (int i = 0; i < m; i++) {
			int k;
			cin >> k;
			sum += k * vec[i];
		}
		sum += c;
		if (sum > 0) ans++;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 100010
#define M 2000100
#define LL long long
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define RR(i,a,b) for(int i=a;i>=b;--i)
#define FJ(i,a,b) for(int i=a;i<b;++i)
#define SC(x) scanf("%d",&x)
#define SCC(x,y) scanf("%d%d",&x,&y)
#define SCCC(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define SS(x) scanf("%s",x)
#define PR(x) printf("%d\n",x)
#define CL(a,b) memset(a,b,sizeof(a))
#define FD T&q=fd[rt],&ql=fd[rt<<1],&qr=fd[rt<<1|1]
#define MID int mid=((l+r)>>1)
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define zero(x) (((x)>0?(x):-(x))<EPS)
#define PB push_back
#define SZ size
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define MP make_pair
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
using namespace std;
const int MOD=1000000007;
const double PI=acos(-1.0);
const double EPS=1e-8;
inline int II(){int n=0,ch=getchar();bool t=0;if(ch==-1)return 0;
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')t=1;
for(;ch>='0'&&ch<='9';n=n*10+ch-'0',ch=getchar());if(t)return -n;return n;}
int n;
int a[N];
map<int,int>mp;
map<int,int>L;
LL s[N];
int main(){
// IN;
    SC(n);
    FF(i,1,n){
        SC(a[i]);
        ++mp[a[i]];
        if(L.find(a[i])==L.end()){
            L[a[i]]=i;
        }
    }
    sort(a+1,a+n+1,greater<int>());
    int tot=unique(a+1,a+1+n)-(a+1);
    a[tot+1]=0;
    FF(i,1,tot){
        int pos=L[a[i]];
        int cnt=mp[a[i]];
        s[pos]+=1LL*cnt*(a[i]-a[i+1]);
        if(pos<L[a[i+1]])L[a[i+1]]=pos;
        mp[a[i+1]]+=cnt;
    }
    FF(i,1,n)printf("%lld\n",s[i]);
    return 0;
}


Measured memory_bytes: 11648
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { 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; }
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;
struct Node{
    int num;
    int pre;
    int cnt;
};
int main(int argc, char const *argv[]){
    ll N, Q;
    vector<ll> cnt(100000);
    ll ans=0;
    cin >> N;
    vector<ll> a(N+10);
    rep(i,N){
        cin >> a[i];
        cnt[a[i]]++;
        ans+=a[i];
    }
    cin >> Q;
    vector<ll> b(Q+10), c(Q+10);
    rep(i,Q){
        cin >> b[i] >> c[i];
        cnt[c[i]]+=cnt[b[i]];
        ans+=cnt[b[i]]*(c[i]-b[i]);
        cnt[b[i]]=0;
        cout << ans << endl;
    }


    return 0;
}




Measured memory_bytes: 6420
program prob4
    implicit none
    integer::a,b,x
    real(8)::aa,bb,xx
    real(8),parameter::pi=3.141592653589793_8
    read(*,*) a,b,x
    aa = dble(a)
    bb = dble(b)
    xx = dble(x)
    if(2*x < a*a*b) then
        write(*,*) 90.0_8 - atan(2.0_8*xx / (aa*bb*bb))*180.0_8/pi
    else
        write(*,*) atan((2.0_8*bb - 2.0_8*xx/aa**2) / aa)*180.0_8/pi
    end if
    stop
end program

Measured memory_bytes: 3160
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

ll a[100001],b[100001];
P1 x[100001]={};
ll total=0,r=0;
int main(){

	int n;

	cin>>n;
	rep(i,n){
		cin>>a[i]>>b[i];
		x[i].first=a[i]+b[i];
		x[i].second=i;
		r+=b[i];
	}
	sort(x,x+n);

	int f=n-1;
	rrep(i,n){
		if(i==f){
			total+=x[i].first;
			f-=2;
		}
	}
	cout<<total-r<<endl;
	return 0;
}


Measured memory_bytes: 3328
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def dfs(u=0,pu=-1):
    if aa[u]<0:dp[u][0][0]=aa[u]
    else:dp[u][1][0]=aa[u]
    for v in to[u]:
        if v==pu:continue
        dfs(v,u)
        size[u]+=size[v]
        ndp0=[inf]*n
        ndp1=[inf]*n
        for k in range(size[u]):
            pre=dp[u][0][k]
            if pre==inf:continue
            for kv in range(size[v]):
                s=dp[v][0][kv]
                if s!=inf:ndp0[k+kv+1]=min(ndp0[k+kv+1],pre+s)
                if s<0:ndp0[k+kv]=min(ndp0[k+kv],pre)
                s = dp[v][1][kv]
                if s != inf: ndp0[k + kv+1] = min(ndp0[k + kv+1], pre + s)
                if s != inf: ndp0[k + kv] = min(ndp0[k + kv], pre)

        for k in range(size[u]):
            pre=dp[u][1][k]
            if pre==inf:continue
            for kv in range(size[v]):
                s=dp[v][0][kv]
                if s!=inf:ndp0[k+kv+1]=min(ndp0[k+kv+1],pre+s)
                if s<0:ndp1[k+kv]=min(ndp1[k+kv],pre)
                s = dp[v][1][kv]
                if s != inf: ndp1[k + kv+1] = min(ndp1[k + kv+1], pre + s)
                if s != inf: ndp1[k + kv] = min(ndp1[k + kv], pre)

        dp[u][0]=ndp0
        dp[u][1]=ndp1

inf=10**16
n=II()
aa=LI()
to=[[] for _ in range(n)]
for _ in range(n-1):
    u,v=MI1()
    to[u].append(v)
    to[v].append(u)

dp=[[[inf]*n for _ in range(2)] for _ in range(n)]
size=[1]*n
dfs()

mx=0
for k in range(n-1,-1,-1):
    if dp[0][0][k]<0:
        mx=max(mx,k)
        break
for k in range(n-1,-1,-1):
    if dp[0][1][k]!=inf:
        mx=max(mx,k)
        break
print(n-1-mx)


Measured memory_bytes: 753012
#include <iostream>
#include<bits/stdc++.h>
using namespace std ;
int main()
 {
 	int k ;
 	cin>>k ;
 	if(k==0)
 	{
 		cout<<" " ;
 		return 0 ;
	 }
	 string str = "ACL" ;
	 string n = "" ;
	 while(k--)
	 {
	 
	 n+=str ;
	 }
	 cout<<n ;
	return 0;
}

Measured memory_bytes: 3592
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        if (c - (a - b) < 0) {
            System.out.print(0);
            return;
        }
        System.out.print(c - (a - b));
    }

}

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

int main() {
  string s;
  cin >> s;
  
  if(s.at(0)=='7' ||s.at(1)=='7' || s.at(2)=='7') cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}




Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
    int a, b, c;
    int tmp;
 
    scanf("%d%d%d", &a, &b, &c);
    if (a > b) tmp = a, a = b, b = tmp;
    if (b > c) {
        tmp = b, b = c, c = tmp;
        if (a > b) tmp = a, a = b, b = tmp;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 2044
#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	string s;
	cin >> s;
	if((s[0] == s[1] and s[1] == s[2]) or (s[1] == s[2] and s[2] == s[3])) {
		P("Yes");
	}else{
		P("No");
	}
}

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


Measured memory_bytes: 256
//
// Created by 13783 on 2020/4/2.
//
#include<iostream>
using namespace std;

const int MAX_N=100;
const int MAX_V=1E3;
const int inf=1e9+1;
int N,W;
int v[MAX_N];
int w[MAX_N];
int dp[MAX_N+1][MAX_N*MAX_V+1];
void solve(){
    //dp[i][j]为前i个物品，总价值为j时，总重量的最小值
    for(int i=0;i<MAX_N*MAX_V+1;i++)
        dp[0][i]=inf;
    dp[0][0]=0;//设置初值
    for (int i = 0; i <N ; ++i) {
        for(int j=0;j<=MAX_V*MAX_N;j++){
            if(j>=v[i]){
                dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
            } else
                dp[i+1][j]=dp[i][j];
        }
    }
    int res=0;
    for(int i=0;i<=MAX_N*MAX_V;i++){
        if(dp[N][i]<=W){
            res=i;
        }
    }
    cout<<res;
}
int main(){
    cin>>N>>W;
    for(int i=0;i<N;i++){
        cin>>w[i]>>v[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 39680
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

int main(){
	int n,m,a;
	long long ans=0;
	vector<int> v;
	cin>>n;
	for(int i = 0;i<3*n;i++){
		cin>>a;
		v.pb(a);
	}
	sort(v.begin(),v.end());
	int j=3*n-2;
	while(n--){
		ans +=v[j];
		j-=2; 
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

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

const int MAX = 1299809;
bool is_prime[MAX];
int n;


void solve() {
    int ans=0;
    int m=n;
    while(!is_prime[m]) {
        m--;
        ans++;
    }
    while(!is_prime[n]) {
        n++;
        ans++;
    }
    cout<<ans<<endl;
}

int main() {
    fill(is_prime,is_prime+MAX,true);
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<MAX;i++) {
        if(is_prime[i]) for(int j=i+i;j<MAX;j+=i) is_prime[j]=false;
    }

    while(cin>>n) {
        if(!n) return 0;
        solve();
    }

    return 0;
}

Measured memory_bytes: 2428
import java.util.*;

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

		int n=sc.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=sc.nextInt()-1;
		}
		int b[]=new int[n];
		for(int i=0;i<n;i++){
				b[a[i]]=i;
		}

		for(int i=0;i<n;i++){
			System.out.print(b[i]+1+" ");
		}

	}
}


Measured memory_bytes: 64996
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  string s;
  cin >> n >> s;
  int ans = 0, nasu = 0;
  rep(i, n){
    if(s[i] == 'I'){
      nasu ++;
    } else {
      nasu --;
    }
    ans = max(ans, nasu);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
s = str(stdin.readline().rstrip())
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに
q= int(stdin.readline().rstrip())
hanten = 0
t=""
u=""

for i in range(q):
    l = list(map(str, stdin.readline().rstrip().split()))
    if int(l[0]) == 1:
        t,u = u,t
        hanten ^= 1
    else:
        if int(l[1])==1:
            t+=l[2]
        else:
            u+=l[2]


if hanten==0:
    print(t[::-1]+s+u)
else:
    print(t[::-1]+s[::-1]+u)


Measured memory_bytes: 4340
p = 10**9+7
h, w = map(int, input().split())
maze = [[-1 for i in range(w)] for j in range(h)]

ans = 0
for i in range(h):
    maze[i] = input()

dp = [[0]*(w+1) for _ in range(h+1)]
dp[1][1] = 1

for i in range(1,h+1):
    for j in range(1,w+1):
        if maze[i-1][j-1] == '.':
            dp[i][j] += dp[i-1][j]%p + dp[i][j-1]%p


ans = dp[h][w]%p

print(ans)

Measured memory_bytes: 47112
import sys
input = sys.stdin.readline
from collections import defaultdict, deque

def F(n: int):
    i = 2
    while i * i <= n:
        while n % i == 0: yield i; n //= i
        i += 1
    if n != 1: yield n

(a, b), c = map(lambda x: set(F(int(x))), input().split()), 0
for i in a: c += 1 if i in b else 0
print(c + 1)

Measured memory_bytes: 65560
jobs, limit = map(int, input().split())
fees = [[] for _ in range(limit)]
for _ in range(jobs):
    day, fee = map(int, input().split())
    if day - 1 < limit:
        fees[day - 1] += [fee]
        
import heapq  # heapqライブラリのimport

res = 0
array = []
for fee_list in fees:
    [heapq.heappush(array, -f) for f in fee_list]
    if len(array) > 0:
        res += -heapq.heappop(array)
print(res)

Measured memory_bytes: 18468
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, const map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
constexpr int MOD = 1e9 + 7;

signed main() {
  int N, Q; cin >> N >> Q;
  VI A(N);
  REP (i, N) cin >> A[i];
  VI X(Q);
  REP (q, Q) cin >> X[q];
  VI odd(N), even(N), acc(N);
  REP (i, N) {
    acc[i] += (i == 0 ? 0 : acc[i - 1]) + A[i];
    odd[i] = (i == 0 ? 0 : odd[i - 1]);
    even[i] = (i == 0 ? 0 : even[i - 1]);
    (i % 2 ? odd[i] : even[i]) += A[i];
  }

  for (int x: X) {
    dump(x);
    int left = upper_bound(ALL(A), x) - A.begin();
    int l = left, r = N;
    while (r - l > 1) {
      int m = (l + r) / 2;
      int tmp = 2 * x - A[m - 1];
      int first = lower_bound(ALL(A), tmp) - A.begin();
      dump(m, first);
      if (N - m == m - first) {
        l = m; break;
      }
      bool f = N - m > m - first;
      (f ? l : r) = m;
    }
    int p = 2 * l - N;
    dump(p, l);
    int ans = acc[N - 1] - (l <= 0 ? 0 : acc[l - 1]);
    dump(ans);
    if (p >= 1) {
      if ((p - 1) % 2) {
        ans += odd[p - 1];
      } else {
        ans += even[p - 1];
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 5632
#include<stdio.h>
int main(){
  int a,b,c,d,n,count=0;
  while(scanf("%d",&n)!=EOF){
    for(a=0;a<10;a++){
      for(b=0;b<10;b++){
	for(c=0;c<10;c++){
	  for(d=0;d<10;d++){
	    if(a+b+c+d==n){
	      count++;
	    }
	  }
	}
      }
    }
    printf("%d\n",count);
    count=0;
  }
  return(0);
}

Measured memory_bytes: 596
//om namah shivaaay//
#include <bits/stdc++.h>
#define input int t;cin>>t;while(t--)
#define Om_namah_Shivaay ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL),cout.precision(10)
 #define ll long long
 #define vi(x)  vector<int>vec(x)
 #define pb push_back
 #define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
 #define f(i, a, b) for (int i = 0; i<(b); i++)
 #define w(t) int t;cin>>t;while(t --)
#define fr(i, a, b) for (int i = (a); i >= (b); i--)
 const int N=1e5 +5;
 using namespace std;
 int32_t main()
 {
    Om_namah_Shivaay;
    int n;
    cin>>n ;
   string s;
   cin>>s;
   if((int)s.size()>n)
   cout<<s.substr(0,n)+"...";
   else
    cout<<s;
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
const int N = 40010, B = N * 8, M = N * 20;
int n, x[N], y[N];
 
struct edge{ int to, pre; }e[N * 2 * 40]; int u[M], l = 0;
void ins(int a, int b) { e[++l] = (edge){b, u[a]}, u[a] = l; }
#define v e[i].to
#define reg(i,a) for(int i = u[a]; i; i = e[i].pre)
void add(int a, int b) { ins(a, b), ins(b^1, a^1); }
 
pair<int, int> nd[N * 2];
#define mid ((l + r) >> 1)
#define lc (x << 1)
#define rc (lc | 1)
#define lcq lc, l, mid
#define rcq rc, mid + 1, r
void build(int x, int l, int r) {
	if (l == r) 
		add(x << 1, nd[l].second ^ 1); 
	else 
		build(lcq), build(rcq), 
		add(x << 1, lc << 1), add(x << 1, rc << 1);
}
 
int a, b, c;
 
void modi(int x, int l, int r) {
	if (a <= l && r <= b) add(c, x << 1);
	else {
		if (a <= mid) modi(lcq); 
		if (b >  mid) modi(rcq);
	}
}
 
int pre[M], low[M], dfn = 0; 
int st[M], top = 0, cnt = 0, scc[M];
void dfs(int x) {
	pre[x] = low[x] = ++dfn; st[top++] = x;
	reg(i,x) if (!pre[v]) dfs(v), low[x] = min(low[x], low[v]);
	else if (!scc[v]) low[x] = min(low[x], pre[v]);
	if (pre[x] == low[x]) {
		cnt++; st[top] = 0;
		while (st[top] != x) top--, scc[st[top]] = cnt;
	}
}
 
void tarjan() {
	memset(pre, 0, sizeof(pre)), memset(scc,0,sizeof(scc));dfn = 0;
	rep(i,1,n * 2) if (!pre[nd[i].second]) dfs(nd[i].second);
}
 
bool check(int m) {
	memset(u, 0, sizeof(u)); l = 0;
	rep(i,1,n) 
		nd[i*2-1] = mp(x[i], B + (i << 1)), 
		nd[i*2] = mp(y[i],B + ((i << 1) | 1));
	sort(nd + 1, nd + 2 * n + 1);
	build(1, 1, n * 2);
	rep(i,1,n * 2) {
		int t = lower_bound(nd + 1, nd + n * 2 + 1, mp(nd[i].first - m + 1, 0)) - nd;
		a = t, b = i - 1, c = nd[i].second; if (a <= b) modi(1, 1, n * 2);
		t = lower_bound(nd + 1, nd + n * 2 + 1, mp(nd[i].first + m - 1, int(1e9))) - nd;
		a = i + 1, b = t - 1, c = nd[i].second; if (a <= b) modi(1, 1, n * 2);
	}
	tarjan();
	rep(i,1,2 * n) if (scc[nd[i].second] == scc[nd[i].second ^ 1]) return false;
	return true;
}
 
int main() {
	scanf("%d",&n); rep(i,1,n) scanf("%d%d",&x[i],&y[i]);
	int l = 0, r = 1e9 + 1;
	while (l + 1 < r) {
		int m = (l + r) >> 1;
		if (check(m)) l = m; else r = m;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 30976
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun dprint(v: Any?, indent: Int = 0) {
    val indentStr = (1..indent).joinToString("") { " " }
    when (v) {
        is Iterable<*> -> {
            System.err.println("$indentStr[")
            v.forEach { dprint(it, indent + 1) }
            System.err.println("$indentStr]")
        }
        is Array<*> -> {
            System.err.println("$indentStr[")
            v.forEach { dprint(it, indent + 1) }
            System.err.println("$indentStr]")
        }
        is IntArray -> System.err.println(indentStr + "[" + v.joinToString(",") + "]")
        is LongArray -> System.err.println(indentStr + "[" + v.joinToString(",") + "]")
        is DoubleArray -> System.err.println(indentStr + "[" + v.joinToString(",") + "]")
        else -> System.err.println(indentStr + v)
    }
}

fun <A : Comparable<A>> min(a: A, b: A) = if (a < b) a else b
fun <A : Comparable<A>> min(vararg a: A) = a.reduce { acc, x -> min(acc, x) }
fun <A : Comparable<A>> max(a: A, b: A) = if (a > b) a else b
fun <A : Comparable<A>> max(vararg a: A) = a.reduce { acc, x -> max(acc, x) }

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    val sc = Scanner(System.`in`)
//    for (t in 1..sc.next().toInt()) {
    Problem.solve(sc, pw)
//    }
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val K = sc.next().toInt()
        val X = sc.next().toInt()
        val ans = (X - K + 1..X + K - 1).map {
            it
        }.joinToString(" ")
        pw.println(ans)
    }
}


Measured memory_bytes: 31516
from math import ceil
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

K = int(input())
L = list(map(int, input().split()))

maxr = 2
minr = 2
r = 0
for n in reversed(L):
    #print("max={}min={}".format(maxr, minr))
    if ceil(maxr//n)*n >= minr:
        # if any(x % n == 0 for x in range(minr, maxr+1)):
        # if minr//n <= maxr//n:
        minr = ceil(minr/n)*n
        maxr = (maxr)//n*n+n-1
    else:
        n = -1
        break

if n == -1:
    print(n)
else:
    print(int(minr), maxr)


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

using namespace std;

int a,b,c,d,e;
int na,nb,nc;


int main(){

  while(cin >> a >> b >> c >> d >> e && (a|b|c|d|e)){
    cin >> na >> nb >> nc;

    if(nc >= d){
      cout << e*nc+na*a+nb*b << endl;
    }else{
      int cost = na*a+nb*b+nc*c;
      int tmp = 0;
      for(int i = 0; i < d; i++){
	if(nc > 0){
	  nc--;
	  tmp += c;
	}else if(nb > 0){
	  nb--;
	  tmp += b;
	}else if(na > 0){
	  na--;
	  tmp += a;
	}
	cost = min(cost, min(tmp, d*e) + na*a + nb*b + nc*c);
      }
      cout << cost << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl
template<typename T>
T ncr(T left, T right) {
	right = min(left - right, right);
	T ans = 1;
	for (T i = 1; i <= right; i++) {
		ans = ans * (left - right + i) / i;
	}
	return ans;
}

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;


int main() {
	string s;
	cin >> s;
	int black = 0;
	int white = 0;
	bool odd = true;
	for (int i = 0; i < s.size(); i++) {
		if (odd) {
			if (s[i] == '0') {
				white++;
			}
			else {
				black++;
			}
		}
		else{
			if (s[i] == '1') {
				white++;
			}
			else {
				black++;
			}
		}
		odd = !odd;
	}
	cout << min(white, black) << endl;
	return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll N,M,a,sum=0;cin>>N>>M;
  priority_queue<int> p;
  for(ll i=0;i<N;i++){cin>>a;p.push(a);sum+=a;}
  for(ll h=0;h<M;h++){a=p.top();p.pop();p.push(a/2);sum-=a-a/2;}
  cout<<sum<<endl;
}

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

int main(){
  ll n;
  cin>>n;
  ll ans=0;
  if(n%2==1) ans=0;
  else{
    ll div=5;
    while(n/div!=0){
      ans+=n/div/2;
      div*=5;
    }
  }
  cout<<ans<<endl;
}


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

int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a+b+c>=22)
	printf("bust\n");
	else
	printf("win\n");
	
	
	
	
	
	
	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);
		String X = sc.next();
		String T = sc.next();

		String H = T.substring(0, T.length()-1);

		if(X.equals(H)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}
}


Measured memory_bytes: 35660
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define all(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };

int N, W, w, v;
ll tmp;
vector<int> vec[4];

int main()
{
	cin >> N >> W;
	rep(i, N) {
		if (!i) {
			cin >> tmp >> v;
			vec[0].push_back(v);
		}
		else {
			cin >> w >> v;
			vec[w - tmp].push_back(v);
		}
	}
	
	ll sum[4][100] = {};
	rep(i, 4) sort(vec[i].rbegin(), vec[i].rend());
	rep(i, 4) {
		rep(j, vec[i].size()) {
			sum[i][j + 1] = sum[i][j] + vec[i][j];
		}
	}
	ll ma = 0LL;
	rep(i, vec[0].size() + 1) {
		rep(j, vec[1].size() + 1) {
			rep(k, vec[2].size() + 1) {
				rep(l, vec[3].size() + 1) {
					ll pos = i * tmp + j * (tmp + 1) + k * (tmp + 2) + l * (tmp + 3);
					ll mv = sum[0][i] + sum[1][j] + sum[2][k] + sum[3][l];
					if (pos <= W) ma = max(ma, mv);
				}
			}
		}
	}
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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 (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int k;cin >> k;
    ll ans = 0;
    FOR(a,1,k){
        FOR(b,1,k){
            FOR(c,1,k){
                ll cur = GCD(a,b);
                ans+=GCD(c,cur);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
  int a,b,c,k1,k2,k3;
int main()
{

   cin>>a>>b>>c;
   k1=a+b;
   k2=b+c;
   k3=a+c;
   if (k1<=k2&&k1<=k3)
     cout<<k1;
   else
     if (k2<=k1&&k2<=k3)
       cout<<k2;
     else
	   if (k3<=k1&&k3<=k2)
         cout<<k3;

 	
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long


std::vector<P> node[1000001];// n to first , distance
int n;

//i ざひょー dis スタート地点からの距離
int res[100001];
void func(int i, int dis){
  if(res[i]!=0)return;
  res[i]= dis%2 ? 1 : -1;
  LOOP(j,node[i].size()){
    func(node[i][j].first, dis + node[i][j].second);
  }
  return;
}

signed main(){
  cin >> n;

  LOOP(i,n-1){
    int u,v,w;
    cin >> u >> v >> w;
    node[u].push_back(P(v,w));
    node[v].push_back(P(u,w));
  }
  func(1,0);
  LOOP1(i,n){
    cout << ((res[i]==1) ? 1 : 0) << endl;
  }

}


Measured memory_bytes: 29440
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	string s;cin>>s;
	string sun = "Sunny", clo = "Cloudy", rai = "Rainy";
	if(s==sun)cout<<clo<<endl;
	if(s==clo)cout<<rai<<endl;
	if(s==rai)cout<<sun<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define RI register int
#define CI const int&
using namespace std;
const int N=200005;
char s[N]; int n,ans,pos;
int main()
{
	scanf("%s",s+1); n=strlen(s+1); ans=n; pos=1;
	for (RI i=2;i<=n;++i)
	if (s[i]==s[pos]) --ans,pos=i+2,i+=2; else pos=i;
	return printf("%d",ans),0;
}

Measured memory_bytes: 384
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main() {
    int n, m, p;
    cin >> n >> m >> p;

    vector<int> a(m), b(m), c(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
        c[i] = p - c[i];
    }

    vector<bool> reach_fwd(n, false);
    reach_fwd[0] = true;
    queue<int> que_fwd;
    que_fwd.push(0);
    while (!que_fwd.empty()) {
        int fwd = que_fwd.front();
        que_fwd.pop();

        for (int i = 0; i < m; i++) {
            if (a[i] == fwd && !reach_fwd[b[i]]) {
                reach_fwd[b[i]] = true;
                que_fwd.push(b[i]);
            }
        }
    }

    vector<bool> reach_rev(n, false);
    reach_rev[n - 1] = true;
    queue<int> que_rev;
    que_rev.push(n - 1);
    while (!que_rev.empty()) {
        int rev = que_rev.front();
        que_rev.pop();

        for (int i = 0; i < m; i++) {
            if (b[i] == rev && !reach_rev[a[i]]) {
                reach_rev[a[i]] = true;
                que_rev.push(a[i]);
            }
        }
    }

    vector<long long> dist(n, 1LL << 50);
    dist[0] = 0;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (reach_fwd[a[j]] && reach_rev[a[j]] && reach_fwd[b[j]] && reach_rev[b[j]]
                    && dist[b[j]] > dist[a[j]] + c[j]) {
                dist[b[j]] = dist[a[j]] + c[j];
            }
        }
    }

    bool flag = true;
    for (int i = 0; i < m; i++) {
        if (reach_fwd[a[i]] && reach_rev[a[i]] && reach_fwd[b[i]] && reach_rev[b[i]]
                && dist[b[i]] > dist[a[i]] + c[i]) {
            flag = false;
        }
    }

    if (flag) {
        cout << (dist[n - 1] < 0 ? -dist[n - 1] : 0) << endl;
    } else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll N = 5e3 + 5;

ll n,k,p[N],c[N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>p[i];
    for(int i=1;i<=n;i++) cin>>c[i];
    ll ans=-1e18;
    for(int i=1;i<=n;i++){
    	ll s=c[i];
    	vector<ll> V;
    	V.emplace_back(s);
    	for(int j=p[i];j!=i;j=p[j]) s+=c[j],V.emplace_back(s);
    	int len=V.size();
    	for(int j=0;j<len;j++){
    		ll rest=k-j-1;
    		if(rest<0) break;
    		ans=max(ans,V[j]+(rest/len)*max(s,0ll));
    	}
    	cout<<'\n';
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3852
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main()
{
	ll n;
	cin >> n;
	n--;
	string ans;
	ans += char(n % 26 + 'a');
	n -= n % 26 + 1;
	n = (n + 1) / 26;
	while (n != 0) {
		n--;
		ans = char(n % 26 + 'a') + ans;
		n -= n % 26 + 1;
		n = (n + 1) / 26;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
N = int(input())
A = [0] + [int(a) for a in input().split()]

ans = [0]*(N+1)

for i in range(N,0,-1):   
    j=2   
    ball = 0
    while(i*j<=N):
        ball += ans[i*j]
        j += 1
    if (ball%2) != A[i]:
        ans[i] = 1 
        
print(sum(ans)) 
for i in range(N+1):
    if ans[i]==1:
        print(i)


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

#define pb push_back
#define loop(i,l,r) for(int i = (l); i < (r); i++)
#define rloop(i,r,l) for(int i = (r-1); i >= (l); i--)
#define refloop(x, v) for(auto& x : (v))
#define exists(m,e) if((m).find(e) != (m).end())
#define nexists(m,e) if((m).find(e) == (m).end())
#define sortaka(v) sort((v).begin(), (v).end())
#define rsort(v) sort((v).rbegin(), (v).rend())
#define lower_bound_index(v, x) (lower_bound((v).begin(), (v).end(), x)-(v).begin()) // returns minimum i s.t v[i] >= x
#define upper_bound_index(v, x) (upper_bound((v).begin(), (v).end(), x)-(v).begin()) // returns minimum i s.t v[i] > x
#define scanint(x) scanf("%d", &(x))
#define scanfloat(x) scanf("%f", &(x))
#define scanll(x) scanf("%lld", &(x))
#define scanchar(x) scanf("%c", &(x))
#define scanstring(x) scanf("%s", &(x))
#define printint(x) printf("%d", x)
#define printfloat(x) printf("%.9f", x)
#define printll(x) printf("%lld", x)
#define printchar(x) printf("%c", x)
#define printstring(x) printf("%s", x)
#define printintnewline(x) printf("%d\n", x)
#define printfloatnewline(x) printf("%.9f\n", x)
#define printllnewline(x) printf("%lld\n", x)
#define printcharnewline(x) printf("%c\n", x)
#define printstringnewline(x) printf("%s\n", x)
#define square(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))

typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<long long, long long>> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef vector<string> vs;
typedef vector<vector<pair<int, int>>> vvpii;
typedef vector<vector<pair<long long, long long>>> vvpll;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef long long ll;

int main(){
    ios::sync_with_stdio(0);

    const int MOD = (int)1e9+7;
    int n; cin >> n;

    ll m10 = 1, m9 = 1, m8 = 1;
    for(int i = 0; i < n; i++){
        m10 = (m10*10)%MOD;
    }
    for(int i = 0; i < n; i++){
        m9 = (m9*9)%MOD;
    }
    for(int i = 0; i < n; i++){
        m8 = (m8*8)%MOD;
    }

    cout<<(MOD+(m10-2*m9+m8)%MOD)%MOD<<endl;
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(10e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)
set<ll> st;

int main(void)
{
    ll n; cin >> n;
    ll in;
    REP(i, n) {
        cin >> in;
        if(st.find(in) == st.end()) {
            st.insert(in);
        } else {
            st.erase(in);
        }
    }
    cout << st.size() << endl;

}


Measured memory_bytes: 4864
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<int>a(N);
	vector<int>b(N);
	vector<bool>flag(51);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> b[i];
	}
	for (int i = 50; i > 0; i--) {
		vector<vector<int>>edge(51, vector<int>(51, MOD));
		for (int j = 0; j <= 50; j++)edge[j][j] = 0;
		for (int j = 1; j < i; j++) {
			for (int k = 0; k <= 50; k++) {
				edge[k][k%j] = 0;
			}
		}
		for (int j = i + 1; j <= 50; j++) {
			if (flag[j]) {
				for (int k = 0; k <= 50; k++) {
					edge[k][k%j] = 0;
				}
			}
		}
		for (int l = 0; l <= 50; l++) {
			for (int j = 0; j <= 50; j++) {
				for (int k = 0; k <= 50; k++) {
					edge[j][k] = min(edge[j][k], edge[j][l] + edge[l][k]);
				}
			}
		}
		bool ma = true;
		for (int j = 0; j < N; j++) {
			if (edge[a[j]][b[j]]) {
				ma = false;
			}
		}
		if (!ma) {
			flag[i] = true;
		}
	}
	vector<vector<int>>edge(51, vector<int>(51, MOD));
	for (int i = 0; i <= 50; i++) {
		if (flag[i]) {
			for (int j = 0; j <= 50; j++) {
				edge[j][j%i] = 0;
			}
		}
	}
	for (int i = 0; i <= 50; i++)edge[i][i] = 0;
	for (int k = 0; k <= 50; k++) {
		for (int i = 0; i <= 50; i++) {
			for (int j = 0; j <= 50; j++) {
				edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
			}
		}
	}
	for (int i = 0; i < N; i++) {
		if (edge[a[i]][b[i]]) {
			cout << -1 << endl;
			return 0;
		}
	}
	long long int ans = 0;
	for (int i = 1; i <= 50; i++) {
		if (flag[i]) {
			ans += 1LL << i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define mkpr(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()

typedef long long int ll;

ll general,total;
//ll num[ten5];
//ll num2[ten5];
//char cmap[10][10];
//priority_queue<ll> pqll;   //decrease
//priority_queue<double> pqd;
//stack<int> stk;
//vector<pair<ll,ll>> vpll;
//vector<pair<double,double>> vpdd;
//vector<ll> vll[ten52];
//vector<double> vd;
//deque<ll> deq[55];
//list<int> li;
//set<int> sint;
//set<ll> sll;
//set<char> sch;
//set<string> sStr;
map<ll,ll> mp;

/*ll cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    return a.first<b.first;
    //arrising
}*/


int main()
{
    long long int sum,sum2;
    long long int m,n,o,i,j,k=1;
    long long int a,a1,a2,a3,a4,a5,a6;
    string s;
    sum=sum2=0;
    a=a1=a2=a3=a4=a5=a6=0;
    cin>>n>>a1>>a2;
    for(i=1;i<n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            a=min(abs(i-a1)+1+abs(j-a2),j-i);
            mp[a]++;
        }
    }
    for(i=1;i<n;i++)
        cout<<mp[i]<<endl;
    return 0;
}





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

int main(){
    int N;
    cin>>N;
    string S;
    cin>>S;
    string T=S.substr(N/2);
    if(N%2==1){
        cout<<"No"<<endl;
    }else if(T+T==S){
        cout<<"Yes"<<endl;
    }else if(T+T!=S){
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#define MAX_INT 2147483647
using namespace std;
int main(){
  int n,q;
  scanf("%d %d",&n,&q);
  vector<int>a(n+1);
  for(int i=0;i<n+1;i++)
    a[i]=MAX_INT;
  for(int i=0;i<q;i++){
    int com,x,y;
    scanf("%d %d %d",&com,&x,&y);
    if(com){
      int M=MAX_INT;
      for(int j=x;j<=y;j++)
	M=min(M,a[j]);
      printf("%d\n",M);
    }else{
      a[x]=y;
    }
  }
  return 0;
}

Measured memory_bytes: 3352
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
from pprint import pprint



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

h, w, k = LI()
sy, sx, gy, gx = LI()
cost = [[INF] * w for _ in range(h)]
cost[sy - 1][sx - 1] = 0
grid = SR(h)
q = deque([(sy - 1, sx - 1)])
while q:
    cy, cx = q.popleft()
    for i, j in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        for l in range(1, k + 1):
            ny, nx = cy + i * l, cx + j * l
            if 0 > nx or nx >= w or 0 > ny or ny >= h or grid[ny][nx] == "@":
                break
            if 0 <= cost[ny][nx] <= cost[cy][cx]:
                break
            if cost[ny][nx] == INF:
                q.append((ny, nx))
            cost[ny][nx] = cost[cy][cx] + 1


print(cost[gy - 1][gx - 1] if cost[gy - 1][gx - 1] != INF else -1)










Measured memory_bytes: 120248