akhauriyash/Code-Regression huggingface dataset:
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

calc table n (ab : abs) = do
  let [h, l] = ab
  let k = if h == 1 || h == n then l else if l == 1 || l == n then h else 0
  if k == 0
    then do
      if abs /= []
        then calc table n abs
        else return "IMPOSSIBLE"
    else do
      p <- VUM.read table k
      if p == 1
        then return "POSSIBLE"
        else do
          VUM.write table k 1
          if abs /= []
            then calc table n abs
            else return "IMPOSSIBLE"

main = do
  [n, m] <- getIntList
  abs <- getIntNList m
  table <- VUM.replicate (n + 1) 0 :: IO (VUM.IOVector Int)
  result <- calc table n abs
  putStrLn result


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

using namespace std;

int main(){
  long long  n,k;
  cin >> n >> k;
  long long res = 0;
  
  for (int b= k+1; b<=n;b++){
    int x = n/b;
    res += x*(b-k);
    int y = n%b;
    if(y>=k && y!= 0) {
        if(k!=0) res += y-k+1;
        else res += y-k;
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,n,ara[1000];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&ara[i]);
    }
    for(i=(n-1);i>0;i--){
        printf("%d ",ara[i]);
}
    printf("%d\n",ara[i]);
    return 0;
}


Measured memory_bytes: 2040
n, k = [int(i) for i in input().split()]

if k == 2:
  if n % 2 == 0:
      odd = n / 2
      even = n / 2
  else:
      odd = int(n / 2) + 1
      even = int(n / 2)  
  print(int(odd ** 3 + even ** 3))

elif k % 2 != 0:
  num = int(n / k)
  print(num ** 3)
  
else:
  num = int(n / k)
  num2 = int(int((n - k / 2)) / k + 1)
  print(num ** 3 + num2 ** 3)
  
  

Measured memory_bytes: 3064
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n, k;
	scanf("%d%d", &n, &k);
	vector<int> a(n), b(n);
	rep(i, n)scanf("%d", &a[i]);
	if (k >= 75)rep(i, n)printf("%d\n", n);
	else {
		while (k) {
			--k;
			fill(all(b), 0);
			rep(i, n) {
				int l = max(0, i - a[i]), r = min(n - 1, i + a[i]);
				++b[l];
				if (r + 1 < n)--b[r + 1];
			}
			rep(i, n - 1)b[i + 1] += b[i];
			a = b;
		}
		rep(i, n)printf("%d\n", a[i]);
	}

	Please AC;
}

Measured memory_bytes: 4860
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = input()
    if 'RRR' in s:
        print(3)
    elif 'RR' in s:
        print(2)
    elif 'R' in s:
        print(1)
    else:
        print(0)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61764
#include <iostream>
using namespace std;
int score[100000];
int main(){
  int n,k,q;cin>>n>>k>>q;
  for(int i = 0; q > i; i++){
    int tmp;cin>>tmp;tmp--;
    score[tmp]++;
  }
  for(int i = 0; n > i; i++){
    //cout << k << " " << score[i] << endl;
     if(1 > k-(q-score[i])){
       cout << "No" << endl;
     }else{
       cout << "Yes" << endl;
     }
  }
}

Measured memory_bytes: 1024
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define ifYN(x) cout<<(x?"Yes":"No")<<"\n" 
#define dcml(n) fixed<<setprecision(n)

 
ll GCD(ll a,ll b) { return b ? GCD(b,a%b) : a; } 
ll LCM(ll a,ll b) { return a/GCD(a,b)*b; } 
ll Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; } 
ll modPow(ll x,ll n,ll mod=MOD){ 
    return (!n?1:!n%2?modPow(x*x,n/2,mod)%mod:x%mod*modPow(x,n-1,mod)%mod); 
} 
using namespace std;
//-------------------------------------------
typedef pair<ll,ll> P;
int main(void){
    ll N;cin>>N;
    ll A;ld ans=0;

    REP(i,N){
        cin>>A;
        ans+=1.0/A;
    }
    cout<<dcml(10)<<1/ans;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){ 
    int x,i; 
    1<=x<=10000; 
    for(i=1; i<=10000; i++){
        scanf("%d",&x); 
        if(x==0)break; 
        printf("Case %d: %d\n",i,x);
        
    }
    return 0;
    
} 



Measured memory_bytes: 2036
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    s=input()
    mod=10**9+7
    #i(1-)番目の数まで決めた時，それより小さな数がj個ある場合の数
    dp=[[0]*(n+1) for _ in range(n+1)] 
    for i in range(n):
        dp[1][i]=1
    cum=[0]*(n+1)
    for i in range(2,n+1):
        cum[0]=dp[i-1][0]
        for j in range(1,n-i+2):
            cum[j]=(cum[j-1]+dp[i-1][j])%mod
        if s[i-2]=="<":
            for j in range(n-i+1):
                dp[i][j]=(cum[j])%mod
        else:
            for j in range(n-i+1):
                dp[i][j]=(cum[n-i+1]-cum[j])%mod
    print(dp[n][0])
if __name__=='__main__':
    main()

Measured memory_bytes: 112220
a=input()
b=input()
c=b.split()
d=map(int,c)
main=list(d)
sum=0
for i in range(len(main)-2):
    stool=main[i]-main[i+1]
    if stool>0:
        main[i+1]+=stool
        sum+=stool

stool=main[len(main)-2]-main[len(main)-1]
if stool>0:
    sum+=stool
    main[len(main)-1]+=stool

print(sum)    


Measured memory_bytes: 33560
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

n = onem()

a = l()


dp = [[0,0] for i in range(n)]

den = [0 for i in range(n)]

for i in range(n-2,-1,-1):
	if a[i] > a[i-1]:
		den[i-1] = 1
	else:
		break

po = [0 for i in range(n)]

for i in range(1,n):
	if a[i] < a[i-1]:
		po[i] = po[i-1]+1
	else:
		po[i] = po[i-1] 

now = a[0]
st = 0
for i in range(n):
	for j in range(i+1,n):
		if a[j] >= a[j-1]:
			1
		else:
			dp[i][0] = j-1
			break
	else:
		dp[i][0] = j
	for j in range(i+1,n):
		if a[j] <= a[j-1]:
			1
		else:
			dp[i][1] = j-1
			break
	else:
		dp[i][1] = j

lb = 0
hav = 0
mo = 1000

for i in range(n):
	if dp[i][0] == i:
		mo += hav * a[i]
		hav = 0
	if dp[i][1] == i:
		hav += mo // a[i]
		mo %= a[i]
		lb = a[i]
print(mo + lb * hav)

Measured memory_bytes: 67856
#include <stdio.h>

int main(void) {

    int i;
    int num;
    int a  = 0;
    int min = 1000000;
    int max = -1000000;
    long sum = 0;

    scanf("%d", &num);

    for(i = 0; i < num; i++) {
        scanf("%d", &a);

        if(a > max) {
            max = a;
        }
        if(a < min) {
            min = a;
        }
        sum += a;
    }
    
    printf("%d %d %ld\n", min, max, sum);

    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int a,b; cin >> a >> b;
  vector<string> s(100);
  rep(i,100)rep(j,100){
    if(j<50) s[i] += "#";
    else s[i] += ".";
  }
  
  a--; b--;
  rep(j,25)rep(i,50){
    if(a>0){
      s[2*i][2*j]='.';
      a--;
    }
  }
  rep(j,25)rep(i,50){
    if(b>0){
      s[2*i][99-2*j]='#';
      b--;
    }
  }

  printf("%d %d\n",100,100);
  rep(i,100){
    cout << s[i] << endl;
  }
  
  return 0;
}

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

int print[10005];
int n;


int main() {
	int n, k;
	cin>>n>>k;
	int ans = 0;
	for(int i= 1; i<=n; i++ )
	{
	    ans +=1;
	    i+=(k*2);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    k = I()
    a,b = LI()
    for i in range(a,b+1):
        if i % k == 0:
            return 'OK'

    return "NG"


print(main())





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

using namespace std;

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

#define fi				first
#define se 				second
#define pb 				push_back
#define mp 				make_pair
#define all(v)			v.begin(),v.end()
#define sz(v)			s.size()
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define per(i,a,b) 		for(int i=a;i>=b;i--)
#define fill(a,v)		memset(a,v,sizeof(a))
#define tc				int T;cin>>T;while(T--)
#define nl				printf("\n")
#define aya				printf("yaha aya\n")
#define debug(x,y)		printf("%d %d\n",x,y)
#define fast_io			ios_base::sync_with_stdio(false);cin.tie(NULL);
#define grt				greater<int>()

const int mod = 1e9+7;
const int mod2= 1e9+9;

inline int pow_(ll a, int n, int p=mod){
	int r=1;while(n){if(n&1)r=r*a%p;n>>=1;a=a*a%p;}return r;
}

const int N = 1e5+1;
vi g[N];
int dp[N];

void dfs(int u){
	// printf("now at %d\n",u);
	bool visit = false;
	for(int node: g[u]){
			visit = true;
		if(dp[node] == -1){
			dp[node] = 0;
			dfs(node);
		}
	}

	if(!visit) dp[u] = 0;
	else
	{
		for(int node:g[u])
			dp[u] = max(dp[u],dp[node]);
		dp[u] += 1;	
	}
	// printf("dp[%d] = %d\n",u,dp[u]);
}

int main(void)
{
	int n,m;cin>>n>>m;
	rep(i,1,m)
	{
		int u,v;cin>>u>>v;
		g[u].pb(v);
	}
	rep(i,1,n) dp[i] = -1;
	rep(i,1,n){
		if(dp[i] == -1){
			dfs(i);
		}
	}
	int ans = 0;
	rep(i,1,n) ans = max(ans,dp[i]);
	cout<<ans<<"\n";
}

Measured memory_bytes: 8192
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pf(n) printf("%d\n",n)
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

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

	cout << max(a + b, max(a - b, a*b)) << endl;
	
	return 0;
}

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

int main(int argc, char const *argv[]) {
  string s;
  cin>>s;
  int count=0,max=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
      count++;
    }else{
      if(count>max) max=count;
      count=0;
    }
  }
  if(count>max) max=count;
  cout<<max<<endl;
  return 0;
}


Measured memory_bytes: 256
N=int(input())
ans=0
p=2

while N>1 and p*p<=N:
  if N%p==0:
    c=0
    while N%p==0:
      N=N/p
      c=c+1
    Y=1
    U=2
    while c>=Y:
      ans=ans+1
      Y=Y+U
      U=U+1
  p=p+1

if N>1:
  ans=ans+1

print(ans)

Measured memory_bytes: 9268
/*    三玖天下第一！！！  */
#include<bits/stdc++.h>
using namespace std;
int len,ans=0;
string sl;
inline void sread(string &s)
{
	s="";char ch=getchar();
	for(;ch<'a'||ch>'z';ch=getchar());
	for(;ch>='a'&&ch<='z';ch=getchar())s+=ch;
}
inline int dread()
{
	int x=0;bool f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) f^=(ch=='-');
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch^48);
	return f?x:-x;
}
inline void Kaslana()
{
	len=dread();
	sread(sl);
}
inline void Raiden()
{
	char temp='#';
	for(int i=0;i<len;i++) if(temp!=sl[i]) ans++,temp=sl[i];
}
inline void Zaychik()
{
	printf("%d\n",ans);
}
int main()
{
    Kaslana(),Raiden(),Zaychik();return 0;
}


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

using namespace std;

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

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

int main(void) {
  int i,j;
  string s;
  cin>>s;
  rep(i,s.size()-1)
    if(s[i]==s[i+1]){
      cout<<i+1<<" "<<i+2<<endl;
      return 0;
    }
  rep(i,s.size()-2)
    if(s[i]==s[i+2]){
      cout<<i+1<<" "<<i+3<<endl;
      return 0;
    }
  cout<<-1<<" "<<-1<<endl;
}


Measured memory_bytes: 512
#include<stdio.h>
int main(){
	int a;
	int b;
	int c;
	
	scanf("%d %d %d", &a,&b,&c);
	if(a==b && a!=c && b!=c){
		printf("Yes");
	}
	else if (b==c && b!=a && c!=a){
		printf("Yes");
	}
	else if (a==c && a!=b && b!=c){
		printf("Yes");
	}
	else if (a==b && a==c && b==c){
		printf("No");
	}
	else if(a!=b && a!=c && b!=c){
		printf("No");
	}
	
	return 0;
}

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

using namespace std;

const int inf = 1e9 + 7;
const int N = 1e6 + 5;

int main() {
	int n, k, x, y;
	long long ans = 0;
	cin >> n >> k >> x >> y;
	ans = min(n, k) * x;
	n -= min(n, k);
	ans += n * y;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# 組み合わせはitertoolsを使う

import itertools
N, M, Q = map(int, input().split())
pair = [list(map(int, input().split())) for i in range(Q)]
ans = 0

for A in itertools.combinations_with_replacement(range(1, M+1), N):
    tmp = 0
    for p in pair:
        # pはリスト
        if A[p[1] - 1] - A[p[0] - 1] == p[2]:
            tmp += p[3]
            ans = max(ans, tmp)
            # print("p[1]-1 = ", p[1]-1)
            # print("p[0]-1 = ", p[0]-1)

print(ans)


Measured memory_bytes: 9056
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  VEC<int> s(n);
  int sum = 0;
  REP(i, 0, n) {
    cin >> s[i];
    sum += s[i];
  }
  sort(ALL(s));
  int ans = sum;
  if (sum % 10 == 0) {

    bool all = true;
    REP(i, 0, n) {
      if (s[i] % 10 != 0) {
        cerr << "HI" << endl;
        ans = sum - s[i];
        all = false;
        break;
      }
    }
    if (all)
      ans = 0;
  }
  DUMP(s, sum, ans);

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


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

using namespace std;
using ll = long long;

int main(){

    ll A, B;
    cin >> A >> B;
    ll ans = 0;
    A = max(A - 1, 0LL);
    for(int i = 0; i < 40; i++){
        ll cnt1 = (A >> (i + 1)) * (1LL << i) + max(0LL, (A % (1LL << (i + 1))) - (1LL << i) + 1);
        ll cnt2 = (B >> (i + 1)) * (1LL << i) + max(0LL, (B % (1LL << (i + 1))) - (1LL << i) + 1);
        cnt1 %= 2;
        cnt2 %= 2;
        if((cnt2 ^ cnt1)){
            ans |= (1LL << i);
        }
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;


int main() {
	int W,H,x,y,r;
	cin >> W >> H >> x >> y >> r;
	if (0 < x&&x < W && 0 < y&&y < W) {
		if (0 <= x + r&&x + r <= W && 0 <= y + r&&y + r <= H)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll a,v,b,w,t; cin >> a >> v >> b >> w >> t;
    if(a > b) swap(a,b);
    if(a+v*t >= b+w*t) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3640
include Math
def calc(l)
  l.map!{ |i| sin(i*PI/180) }
  l.reduce(:+)
end
while n = gets.to_i
  break if n == 0
  l1 = []
  (n-1).times{ l1 << gets.to_i }
  l1 << 360 - l1.reduce(:+)
  l2 = []
  (gets.to_i-1).times{ l2 << gets.to_i }
  l2 << 360 - l2.reduce(:+)
  a = calc(l1) - calc(l2)
  if a.abs < 1e-9 then p 0
  elsif a >= 1e-9 then p 1
  else p 2
  end  
end

Measured memory_bytes: 9000
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n,q;
  string s;
  cin >> n >> q >> s;
  vector<int> c(n+1,0);
  vector<int> p;

  int pos = s.find("AC");  
  while(pos != std::string::npos){  
    p.emplace_back(pos);    
    pos = s.find("AC", pos+2);  
  }
  int now=0;
  for(auto to:p){
    while(now<to){
      c[now+1] = c[now];
      now++;
    }
    c[now] = c[now-1]+1;
  }
    while(now<n){
      c[now+1] = c[now];
      now++;
    }
  
  
  rep(i,q){
    int l,r; cin >> l >> r; l--; r--;
    cout << c[r-1]-((l==0)?0:c[l-1]) << endl;
  }
  return 0;
}

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

     printf("%d %d %d\n", a, b, c);
 
      return 0;
}
 

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>
#include <fstream>
#include <ctime>

using namespace std;
using ll = long long;

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

template<typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct ToUpper {
    char operator()(char c) { return toupper(c); }
};

struct ToLower {
    char operator()(char c) { return tolower(c); }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<int> B(N - 1);
    cin >> B;
    vector<int> A(N);
    A[0] = B[0];
    A[N - 1] = B[N - 2];
    FOR(i, 1, N - 1) {
        A[i] = min(B[i - 1], B[i]);
    }

    cout << accumulate(ALL(A), 0) << endl;
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int h, w, n, t, x, y;

int main() {
    cin >> h >> w >> n;
    int ans[h][w];
    for (int i = 1; i <= n; ++i) {
        cin >> t;
        while (t) {
            ans[x][y] = i;
            --t;
            if (x & 1) {
                if (y == 0) {
                    ++x;
                } else {
                    --y;
                }
            } else {
                if (y == w - 1) {
                    ++x;
                } else {
                    ++y;
                }
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cout << ans[i][j] << ' ';
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
int isprime1(int n){
	int i;
	for(i = 2; i < n; i++){
		if(n % i == 0) return 0;
	}
	return 1;
}
int main() {
	int n, p, q, i;
	scanf("%d", &n);
	while(1){
		if(n == 0) break;
		for(i = n; n >= 5; i--){
			if(isprime1(i) == 1 && isprime1(i-2) == 1){
				p = i-2;
				q = i;
				break;
			}
		}
		printf("%d %d\n", p, q );
		scanf("%d", &n);
	}
	return 0;
}

Measured memory_bytes: 1760
#include<bits/stdc++.h>
 using namespace std;
 const long long mod=1e9+7;

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

 vector<int>oks(N+1,true);
 for(int i=0;i<M;++i){
 int a;cin>>a;
 oks[a]=false;
 }

 vector<long long int>dp(N+1);
 dp[0]=1;
 for(int now=0;now<N;++now){
 for(int next=now+1;next<=min(N,now+2);++next){
 if(oks[next]){
 dp[next]+=dp[now];
 dp[next]%=mod;
 }
 }
 }

 cout<<dp[N]<<endl;
 return 0;
 }


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

ll _pow(ll a, ll n) {
	if(n == 0) return 1;
	else {
		ll res = 1;
		ll buf = a;
		while(n > 0) {
			if(n % 2 == 1) {
				res *= buf;
			}
			buf *= buf;
			n /= 2;
		}
		return res;
	}
}

void solve() {
	ll tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
	cin >> tmp1 >> tmp2 >> tmp3 >> tmp4 >> tmp5 >> tmp6;
	__int128 n, m, a, b, p, q;
	n = tmp1;
	m = tmp2;
	a = tmp3;
	b = tmp4;
	p = tmp5;
	q = tmp6;
	__int128 ans = m;
	if(n == 1) {
		ans = min(m, (__int128)abs((ll)((p + q) - m)));
		cout << (ll)ans << endl;
		return;
	}
	__int128 c = max(a, b);
	if(c == 1) {
		if((p + q) * n > m) {
			ans = min(m - m / (p + q) * (p + q), (m / (p + q) + 1) * (p + q) - m);
		} else ans = m - (p + q) * n;
	} else if(c == 2 || c == 3) {
		__int128 _n = 0;
		if(c == 2) _n = min((__int128)41, n);
		if(c == 3) _n = min((__int128)29, n);
		ll div1 = _n / 2;
		ll div2 = _n - div1;
		vector<__int128> d1;
		vector<__int128> d2;
		REP(bit, (1ll << div1)) {
			bitset<31> bi(bit);
			__int128 sum = 0;
			REP(i, div1) if(bi[i]) sum += p * _pow(a, i) + q * _pow(b, i);
			d1.pb(sum);
		}
		REP(bit, (1ll << div2)) {
			bitset<31> bi(bit);
			__int128 sum = 0;
			REP(i, div2) if(bi[i]) sum += p * _pow(a, div1 + i) + q * _pow(b, div1 + i);
			d2.pb(sum);
		}
		sort(ALL(d1));
		sort(ALL(d2));
		REP(i, d1.size()) {
			auto ite = upper_bound(ALL(d2), m - d1[i]);
			if(ite != d2.end()) ans = min(ans, (d1[i] + *ite) - m);
			if(ite == d2.begin()) continue;
			ite--;
			ans = min(ans, m - (d1[i] + *ite));
		}
	} else /* c >= 4 */ {
		vector<__int128> num;
		num.pb(0);
		num.pb(p + q);
		REP(i, min((__int128)23, n - 1)) {
			if((__int128)1000000000007 / (ld)_pow(c, i) < c) break;
			ll val = p * _pow(a, i + 1) + q * _pow(b, i + 1); 
			vector<__int128> nnum = num;
			REP(j, num.size()) nnum.pb(num[j] + val);
			num = nnum;
		}
		UNIQUE(num);
		REP(i, num.size()) ans = min(ans, (__int128)abs((ll)(m - num[i])));
	}
	cout << (ll)ans << endl;
}

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



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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N,M;
  cin>>N>>M;
  vector<int>a(M),b(M);
  for(int i=0;i<M;i++)cin>>a[i]>>b[i],a[i]--,b[i]--;
  vector<pii>x(M);
  for(int i=0;i<M;i++)x[i]={b[i],a[i]};
  sort(rng(x));
  vector<bool>f(M,true);
  int last=-1;
  int ans=0;
  for(int i=0;i<M;i++){
    int A=x[i].second;
    int B=x[i].first;
    if(A>=last){
      last=B;
      ans++;
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
const int N = 1e5;  // limit for array size
ll n;  // array size

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
*/
vector<int>v[2*100009];
ll add[2*100009];
bool vis[2*1000005];

void dfs(int i,ll c){
	vis[i]=1;
	add[i]+=c;
	for(int j=0;j<v[i].size();j++){
		if(vis[v[i][j]]==0){
			dfs(v[i][j],add[i]);
		}
	}
}

int main(){
   int n,q,x,y;cin>>n>>q;
   for(int i=1;i<n;i++){
   	  cin>>x>>y;
   	  v[x].pb(y);
   	  v[y].pb(x);
    }
    int p;
    
    while(q--){
    	cin>>p>>x;
    	add[p]+=x;
	}
    dfs(1,0LL);
    
    for(int i=1;i<=n;i++){
    	cout<<add[i]<<" ";
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 24448
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
queue<ll> que;
int n, m, q;
vector<int> a(100), b(100), c(100), d(100);
//vector<int> e(10, 1);
ll ans = 0;
void dfs(int k, int mini, vector<int>e) {
  if(k == n + 2) {
    ll sum = 0;
    for(int i = 0; i < q; i++) {
      if(e[b[i]] - e[a[i]] == c[i]) {
        sum += d[i];
      }
    }
    ans = max(ans, sum);
    return;
  }
  
  e.push_back(mini);
  for(int i = mini; i <= m; i++) {
    dfs(k + 1, i, e);
  }
}

int main() {
  cin >> n >> m >> q;
  for(int i = 0; i < q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(1, 1, vector<int>(0));

  // cout << que.front() << endl;

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

Measured memory_bytes: 3580
#include<iostream>
#include<map>
#include<vector>
#include<queue>
using namespace std;

int n, m, x, y;
bool visited[200009];

int ans[200009];

vector<int> g[200009];

// map<int, vector<int> > g;
int cntr = 0;

void BFS() {
	int start = 1;
	queue<int> q;
	q.push(start);

	int dist = 1;
	visited[1] = true;

	while(!q.empty()) {
		int sz = q.size();
		// cout<<"at level"<<dist<<endl;
		while(sz--) {
			int node = q.front();
			q.pop();
			// cout<<node<<endl;
			cntr++;

			for(auto u: g[node]) {
				// int u = g[node][i];
				if(!visited[u]) {
					visited[u] = true;
					ans[u] = node;
					q.push(u);
				}
			}
		}
		dist++;
	}

}


int main() {

	cin>>n>>m;
	
	// for(int i = 0; i < n; i++)
	// 	ans[i] = INT_MAX;

	for(int i = 0; i < m; i++) {
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	
	BFS();
	if(cntr < n)
		cout<<"No\n";
	else {
		cout<<"Yes\n";
		for(int i = 2; i <= n; i++) {
			cout<<ans[i]<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 12860
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

  	int M; cin >> M;
    cout << 48-M << endl;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(5e1 + 5);
const int MAX_M = (int)(5e1 + 5);

int n, m;

char a[MAX_N][MAX_M];
char b[MAX_N][MAX_M];

bool check(int i, int j) {
  for (int x = 0; x < m; ++x) {
    for (int y = 0; y < m; ++y) {
      if (a[i + x][j + y] != b[x][y]) {
        return false;
      }
    }
  }

  return true;
}

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &m);

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

  for (int i = 0; i < m; ++i) {
    scanf("%s", &(b[i]));
  }

  for (int i = 0; i <= n - m; ++i) {
    for (int j = 0; j <= n - m; ++j) {
      if (check(i, j)) {
        printf("Yes\n");
        return 0;
      }
    }
  }

  printf("No\n");

  return 0;
}


Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        TreeMap<Integer, Integer> map = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(map.containsKey(a)) {
                map.put(a, map.get(a) + b);
            }else {
                map.put(a, b);
            }
        }
        long ans = 0l;
        int count = 0;
        while(true) {
            Set<Map.Entry<Integer,Integer>> entries = map.entrySet();
            for(Map.Entry<Integer, Integer> entry : entries) {
                int aa = entry.getKey();
                int bb = entry.getValue();
                for(int i = 0; i < bb; i++) {
                    if(count >= m) {
                        System.out.println(ans);
                        return;
                    }
                    ans += aa;
                    count++;
                }
            }
        }
    }
}

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string S; cin >> S;
  ll cnt = 0;
  for (ll i = 0; i < (ll)S.size()-1; i++) {
    if (S.at(i) != S.at(i+1)) cnt++;
  }
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
int main()
{
	SPEED
	ld d, t, s;
	cin >> d >> t >> s;
	ld time = d/s;
	if(time <= t){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
	return 0;
}

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

   int x, y, r, tmp;
 
   scanf("%d %d", &x, &y);
 
   if (x < y){
     tmp = x;
     x = y;
     y = tmp;
   }
 
   r = x % y;

   while (r != 0){
     x = y;
     y = r;
     r = x % y;
   }
 
   printf("%d\n", y);
 
   return 0;
 
}

Measured memory_bytes: 1844
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int a = sc.nextInt();
			int b = sc.nextInt();

			if (a == b) {
				System.out.println("Draw");
			} else if (a == 1 || (b != 1 && a > b)) {
				System.out.println("Alice");
			} else {
				System.out.println("Bob");
			}

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli P[5100];
lli C[5100]; 

void func(int N, int K){

    lli ans = -INF;
    REP(i,0,N){
        lli now = P[i];
        lli sum = C[now];
        chmax(ans,sum);
        lli cnt = 1;
        while(now!=i){
            now = P[now];
            sum+=C[now];
            cnt++;
            if(cnt<=K)chmax(ans,sum);
        }
        if(cnt>K)continue;
        if(sum<=0)continue;

        lli temae = K/cnt - 2;
        if(temae < 0)temae = 0;
        lli nowSum = sum*temae;
        lli nowCnt = temae*cnt;
        chmax(ans,nowSum);

        while(nowCnt < K){
            now = P[now];
            nowSum+=C[now];
            nowCnt++;
            chmax(ans,nowSum);
        }
    }

    cout<<ans<<endl;

}
 
int main(){
    // cout << fixed << setprecision(5);
 
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&P[i]);
        P[i]--;
    }
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&C[i]);
    }
    func(N, K);
    return 0;
}

Measured memory_bytes: 3760
#include <iostream>
using namespace std;
int main(){
  int a,b;
  cin >>a>>b;
  if((a+b)==3){
    cout <<3<<endl;
  }
  else if((a+b)==4){
    cout <<2<<endl;
  }
  else if((a+b)==5){
      cout <<1<<endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>
#include <list>
#include <bitset>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
using namespace std;
typedef long long ll;
const int maxn=200050;
int n;

void solve(){
	scanf("%d",&n);
	int sum=0;
	for(int i=1;i<=n;i++){
		sum+=n/i;
		if(n%i==0)	sum--;
	}
	printf("%d\n",sum);
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
int main(){
int h,w;
  cin>>h>>w;
  
  for(int j=1;j<=h;j++){
  for(char i='A';i<'A'+w;i++){
  string s;
    cin>>s;
    if(s=="snuke") cout<<i<<j<<endl;
  }
  }
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repM(i, n) for (int i = n; i > 0; i--)

int main() {
    vector<int> a(3);
    rep(i,3)cin >> a[i];
    int sum = 0;
    rep(i,3)sum += a[i];
    if(sum >= 22)cout << "bust" << endl;
    else cout << "win" << endl;

    return 0;
}

Measured memory_bytes: 256
n=input()
a=map(int,raw_input().split())
z=[0]*n
z[1]=abs(a[1]-a[0])
for i in xrange(2,n):
  z[i]=min(z[i-1]+abs(a[i]-a[i-1]),z[i-2]+abs(a[i]-a[i-2]))
print z[-1]

Measured memory_bytes: 11168
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int ans;
bool isprime(ll x){
	for(ll i=2;i*i<=x;i++){
		if(x%i==0)
		re false;
	}
	re true;
}
bool ip[1000001]; 
vector<ll> prime;
vi j;
vi v;
int main(){ 
	ios::sync_with_stdio(0);
	ll sum=0;
	rep(i,100){
		sum+=i+1;
		j.pb(sum);
	}
	ll n;
	cin>>n;
	if(n==1){
		cout<<0;
		re 0;
	}
	if(isprime(n)){
		cout<<1;
		re 0;
	}
	for(ll i=2;i<=1000000;i++){
		if(ip[i])
		continue;
		for(ll j=i*i;j<=1000000;j+=i)
		ip[j]=true; 
	}
	for(int i=2;i<=1000000;i++)
	if(!ip[i])
	prime.pb(i);
	int now=0;
	while(n>1){
		int nn=0;
		while(now<(int)(sz(prime))&&n%prime[now])now++;
		if(now==(int)(sz(prime))){
			ans++;
			break;
		}
		while(n%prime[now]==0){
			nn++;
			n/=prime[now];
		}
		v.pb(nn);
	}
	rep(i,sz(v)){
		int pos=upper_bound(j.begin(),j.end(),v[i])-j.begin();
		ans+=pos;
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 5296
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    let a:u32 = read();
    let b:u32 = read();

    println!("{}", if a<=b {a} else {a-1});

}


Measured memory_bytes: 4352
function Main(arg)
{
  var H = arg.split("\n")[0].split(" ")[0]-0;
  var W = arg.split("\n")[0].split(" ")[1]-0;

  var f = true;
  var ans = 0;
  
  if(H===1 || W===1){
    console.log(1);
    return;
  }

  if (H % 2 == 0) {
    console.log((H * W) / 2);
  }
  else {
    console.log(W * (H - 1) / 2 + Math.ceil(W / 2));
  }

  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main(){
    int x ;
    cin >> x ;
    vector<int> p(0);
    p.push_back(2);
    if (x == 2)
    {
        cout << 2 << endl ;
        return 0;
    }
    int j = 3 ;
    bool prime = true ;
    while(1){
        prime = true ;
        for (size_t i = 0; i < p.size(); i++)
        {
            if (j % p.at(i) ==0)
            {
                prime = false;
                break;
            }
            
        }
        if (prime == true)
        {
            if (j >= x)
            {
                cout << j << endl ;
                return 0;
            }else
            {
                p.push_back(j) ;
            }
        }
        j ++ ;
    }
    
}

Measured memory_bytes: 384
#include <iostream>

int main(){
	using namespace std;
	int i,j,D = 0;
	string s;
	cin >> i >> s;
	if (i % 2 == 0) {
		for (j = 0; j < (i / 2); j++) {
			if (s[j] != s[(i / 2) + j]) {
				D++;
			}
		}
	}
	else {
		D = 1;
	}

	if (D == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   int a,c;
  int j;
   int d[2000];
  cin >> a >> c;
  int tmp;
  for(int i = 0;i<a;i++){
    cin >> d[i];
  }
  for(int i=0;i<a-1;i++){
    j = i;
    for(int k=i+1;k<a;k++){
      if(d[j]>d[k]){ j=k; }
    }
    tmp = d[j];
    d[j]=d[i];
    d[i]=tmp;
  }
  int ans=0;
  for(int i=0;i<c;i++){
    ans += d[i];
  }
  cout << ans << endl;

}

Measured memory_bytes: 3636
#include<stdio.h>
#define nmax 20
#define qmax 200

int solve(int i,int m);

int n,A[nmax];

int main(){
  int q,m[qmax];
  int i;
  int judge;

  scanf("%d",&n);

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

  scanf("%d",&q);

  for( i = 0 ; i < q ; i++ )
    scanf("%d",&m[i]);

  for( i = 0 ; i < q ; i++ )
    {
      judge = solve(0,m[i]);
      if( 1  ==  judge )
	printf("yes\n");
      else if( 0 == judge )
	printf("no\n");   
    }
return 0;
}

int solve(int i, int m)
{
  int res;
  if( m == 0 )
    return 1;
  if( i >= n )
    return 0;
  res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

Measured memory_bytes: 580
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define MOD 1000000007
using namespace std;
const int MAXN = 100005;
int fac[MAXN],n,f[MAXN],m;
inline int ksm(int x,int k)
{
  int ret=1;
  while(k){
    if(k&1)ret=(long long)ret*x%MOD;
    x=(long long)x*x%MOD;
    k>>=1;
  }
  return ret;
}
inline void sub(int &x,int a)
{
  x-=a;
  if(x<0)x+=MOD;
}
inline void add(int &x,int a)
{
  x+=a;
  if(x>=MOD)x-=MOD;
}
int main()
{
  scanf("%d%d",&n,&m);
  for(int i=1;i*i<=n;++i){
    if(n%i==0){
      fac[++fac[0]]=i;
      if(i*i!=n)fac[++fac[0]]=n/i;
    }
  }
  int ans=0;
  sort(fac+1,fac+fac[0]+1);
  for(int i=1;i<=fac[0];++i){
    f[i]=ksm(m,(fac[i]+1)>>1);
    for(int j=1;j<i;++j)
      if(fac[i]%fac[j]==0)sub(f[i],f[j]);
    if(fac[i]&1){
      add(ans,(long long)f[i]*fac[i]%MOD);      
    }else{
      add(ans,(long long)f[i]*fac[i]%MOD*500000004%MOD);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256