akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    auto a = make_vec<ll>(N, N);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> a[i][j];
        }
    }

    vector<ll> G(1 << N);
    for (int bits = 0; bits < (1 << N); bits++) {
        ll sum = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int maski = 1 << i;
                int maskj = 1 << j;
                if ((bits & maski) > 0 && (bits & maskj) > 0) {
                    sum += a[i][j];
                }
            }
        }
        G[bits] = sum;
    }

    vector<ll> dp(1 << N);
    for (int bits = 0; bits < (1 << N); bits++) {
        dp[bits] = G[bits];
        for (int S = bits; S > 0; S = (S - 1) & bits) {
            chmax(dp[bits], G[bits ^ S] + dp[S]);
        }
    }

    cout << dp[(1 << N) - 1] << endl;
}


Measured memory_bytes: 1408
n,m=map(x->parse(Int,x),split(readline()))
a=[0 for i in 1:n]
for i=1:m
	b,c=map(x->parse(Int,x),split(readline()))
	a[b]+=1
	a[c]+=1
end
for i=1:n
	println(a[i])
end


Measured memory_bytes: 167900
#include<stdio.h>
int main(void){
int h,w,n;
  scanf("%d",&h);
  scanf("%d",&w);
  scanf("%d",&n);
  
  int  ans=0;
  
  if(h>w){
   if(n%h==0) {
     ans=n/h;
              }
	else {ans=n/h+1;}
  }
  else{
    if(n%w==0)ans=n/w;
    else ans=n/w+1;
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def ceil(a, b):return (a + b - 1) // b


def up(a, b):
    s = ceil(a, b)
    for i in range(s - 1, s + 3):
        if i * b > a:
            return i * b


def check(n, A):
    for a in A:
        n = (n // a) * a
    return n == 2


def solve(A):


    if A[-1] != 2:
        return [-1]

    min_a, max_a = 2, 3
    for a in A[::-1][1:]:
        if a > max_a:
            return [-1]
        else:
            max_a = up(max_a, a) - 1

        if a >= min_a:
            min_a = a
        else:
            min_a = ceil(min_a, a) * a

    if min_a > max_a:
        return [-1]
    return min_a, max_a

def solve2(A):
    min_a = INF
    max_a = 0
    for i in range(0, 100):
        if check(i, A):
            min_a = min(min_a, i)
            max_a = max(max_a, i)

    if min_a == INF or max_a == 0:
        return [-1]
    return min_a, max_a

def solve3(A):
    # [low, high)
    min_a = INF
    max_a = 0

    low, high = 0, int(1e14) - 1
    while high - low > 1:
        middle = (low + high) // 2
        if check(middle, A):
            min_a = middle
            low = middle
        else:
            high = middle

    low, high = 0, int(1e14) - 1
    while high - low > 1:
        middle = (low + high) // 2
        if check(middle, A):
            max_a = middle
            high = middle
        else:
            low = middle

    if min_a == INF or max_a == 0:
        return [-1]
    return min_a, max_a

def main():
    K = int(input())
    A = list(map(int, input().split()))

    print(*solve(A))



if __name__ == '__main__':
    main()


Measured memory_bytes: 15024
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)		memset(v, d, sizeof(v))
const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int>P;
const ll mod = 998244353;
int dx[] = { 0, 0, -1, 1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, 1, -1, -1, 1 };
const int N = 500001;
#define endl '\n'
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
void stop(){
#ifndef ONLINE_JUDGE
	system("pause");
#endif
}
struct point{
	double x, y;
};
ll gcd(ll a, ll b){ return !b ? a : gcd(b, a % b); }
ll fixMod(ll a, ll b){ return ((a%b) + b) % b; }
double triangle_area(int x1, int y1, int x2, int y2, int x3, int y3) {
	return abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2.;
};
ll dis(point a, point b) {
	ll x = a.x - b.x, y = a.y - b.y;
	return x * x + y * y;
}
double traingleArea(double a, double b, double c) {
	double s = (a + b + c) / 2.0;
	return sqrt(s * (s - a) * (s - b) * (s - c));
}
double circleArea(double r) {
	return acos(-1) * r * r;
}
ll power(ll x, ll y)
{
	if (y == 0)return 1;
	if (y == 1)return x;
	ll r = power(x, y / 2) % mod;
	return r%mod*r%mod*power(x, y % 2) % mod;
}

int main(){
	fast
		int n;
	cin >> n;
	ll ans = 0;
	int a, b;
	ll arr[1000];
	cin >> a >> b;
	int x = 0, y = 0, z = 0;
	for (int i = 0; i < n; i++){
		int f;
		cin >> f;
		if (f <= a)x++;
		if (f>a&&f <= b)y++;
		if (f > b)z++;
	}
	cout << min({ x, y, z });
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

const int nax = 1000 * 1000 + 10;
int cnt[nax];
bool ok[nax];
int n;

int main() {_
	cin >> n;
	for(int a, i = 1; i <= n; ++i) {
		cin >> a;
		cnt[a]++;
	}
	int ans = 0;
	for(int i = 1; i <= 1000 * 1000; ++i) {
		if(!ok[i]) {
			if(cnt[i] == 1) ans++;
			if(cnt[i] == 0) continue;
			for(int j = 2 * i; j <= 1000*1000; j += i) {
				ok[j] = 1;
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 8528
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
count = 0
_sum  = 0
for i, x in enumerate(A):
    for j in range(M):
        _sum += x[j] * B[j]
    if _sum + C > 0:
        count += 1
    _sum = 0
print(count)

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define IN freopen("transposition-115.txt","r",stdin)
#define OUT freopen("dichromatic.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 2000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define SZ(v) ((int)v.size())
#define sq(x)  ((x)*(x))

using namespace __gnu_pbds;
using namespace std ;

#define maxn 2005
#define mod 1000000007LL

typedef pair<i64,i64> pii ;
typedef  long long int T ;

char s[maxn] ;
int cnt[maxn] , sum[maxn] , mxOperation[maxn] ;
vector <int> g[maxn] ;

void dfs(int u, int par)
{
    cnt[u] = s[u] ;

    int mx = 0 ;
    int id = 0 ;

    for(auto v:g[u])
    {
        if(v==par) continue ;
        dfs(v,u) ;
        sum[u] += (sum[v] +cnt[v]) ;
        cnt[u] += cnt[v] ;

        if( sum[v] + cnt[v] > mx )
        {
            mx = sum[v] + cnt[v] ;
            id = v ;
        }
    }

    int op = min( sum[u] - mx , sum[u]/2 ) ;
    mxOperation[u] = op ;

    if( op <  sum[u]/2 ) mxOperation[u] = min( sum[u]/2 , op + mxOperation[id] ) ;

 //   printf("%d: %d %d\n",u,sum[u],cnt[u]) ;
    return ;
}

int main()
{
    int n ;
    scanf("%d",&n) ;
    scanf("%s",s+1) ;

    for(int i=1 ; i<n ; i++)
    {
        int u , v ;
        scanf("%d %d",&u,&v) ;
        g[u].pb(v) ; g[v].pb(u) ;
    }
    for(int i=1 ; i<=n ; i++) s[i] -= '0' ;

    int ans = INF ;

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

        vector <int> res ;

        memset(sum,0,sizeof(sum)) ;
        memset(cnt,0,sizeof(cnt)) ;

        int sm = 0 , mx = 0 , id=0 ;

        for(int i=0 ; i<g[root].size() ; i++)
        {
            int v = g[root][i] ;
            dfs( v ,root ) ;
       //     res.pb( sum[v] + cnt[v] ) ;
            sm += (sum[v] + cnt[v]) ;
            if( sum[v] + cnt[v] > mx )
            {
                mx = sum[v] + cnt[v] ;
                id = v ;
            }
        }

        if(  2*(mx- mxOperation[id]*2)  <= sm - mxOperation[id]*2 )
        {
    //        printf("root: %d sum: %d mxOp: %d\n",root,sm,mxOperation[id] ) ;
            if(sm%2==0) ans = min(ans,sm/2) ;
        }
    }

    if( ans==INF ) printf("-1\n") ;
    else printf("%d\n",ans) ;

    return 0 ;
}
/*
6
010110
1 2
1 3
1 6
3 4
4 5
*/


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<string>
 
using namespace std;
 
int main() {
	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
		cout << "vowel" << endl;
	else cout << "consonant" << endl;
}

Measured memory_bytes: 256
N,D=map(int,input().split())
x=[]
for i in range(N):
    z=list(map(int,input().split()))
    x.append(z)
count=0
for i in range(N):
    for j in range(N-i-1):
        d=0
        for k in range(D):

            d+=(x[i][k]-x[j+i+1][k])**2
        d=d**(0.5)

        #print(d)
        if d%1==0:
            #print(d,d%1)
            count+=1
print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
long long f[101],tmp[101];
char k[10001];
int main()
{
	int l,i,d,a=0,b,j;
	long long ans=0;
    scanf("%s",k);
    scanf("%d",&d);
    l=strlen(k);
    for(i=0;i<l;i++)
		a+=k[i]-'0';
    f[0]=1;
    a%=d;
    if(a==0)
		ans++;
	l--;
    while(l>=0)
	{
        if(k[l]!='0')
		{
            b=k[l]-'0';
            a-=b;
            while(a<0)
                a+=d;
            if(a)
                j=d-a;
            else
                j=0;
            for(i=0;i<b;i++)
			{
                ans+=f[j--];
                if(j<0)
					j+=d;
            }
            ans%=1000000007;
        }
        tmp[0]=0;
        j=d-1;
        for(i=0;i<9;i++)
		{
            tmp[0]+=f[j--];
            if(j<0)
				j+=d;
            tmp[0]%=1000000007;
        }
        for(i=1;i<d;i++)
        {
			j++;
			tmp[i]=tmp[i-1]+f[i-1]-f[j%d];
		}
        for(i=0;i<d;i++)
		{
            f[i]=f[i]+tmp[i];
            f[i]%=1000000007;
            f[i]+=1000000007;
            f[i]%=1000000007;
        }
        l--;
    }
    ans--;
    if(ans<0)
		ans+=1000000007;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	cout << min(c, b/a) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int single[100001];
int all[100001];

int main() {
  int n;
  while(cin>>n,n) {
    int hp[n];
    int maxhp = 0;
    REP(i,n) {
      cin >> hp[i];
      maxhp = max(maxhp, hp[i]);
    }
    int m;
    cin >> m;
    REP(i,maxhp+1)
      single[i] = all[i] = INF;
    single[0] = all[0] = 0;
    REP(i,m) {
      string s;
      int mp,damage;
      cin >> s>>mp>>s>>damage;
      REP(j,maxhp+1) {
        if (s == "Single")
          single[j] = min(single[j], ((j>=damage)?single[j-damage]:0) + mp);
        else
          all[j] = min(all[j], ((j>=damage)?all[j-damage]:0) + mp);
      }
    }
    // REP(i,maxhp+1) {
    //   printf("%d : %d, %d\n", i, single[i], all[i]);
    // }
    int ans = INF;
    REP(i, maxhp+1) {
      int smp = 0;
      bool f = 0;
      REP(j,n) {
        if (hp[j]>=i) {
          if (single[hp[j]-i] == INF) {
            f = 1;
            break;
          }
          smp += single[hp[j]-i];
        }
      }
      if (f) continue;
      ans = min(ans, all[i] + smp);
    }
    cout << ans << endl;
    
  }
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int N; cin >> N;
    vector<double> p(N); readv(p);
    vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0.0));
    dp[0][0] = 1.0;
    FOR(i, 1, N + 1){
        REP(j, i + 1){
            dp[i][j] += (1.0 - p[i - 1]) * dp[i - 1][j];
            if(j > 0) dp[i][j] += p[i - 1] * dp[i - 1][j - 1];
        }
    }
    double ans = 0.0;
    REP(i, N + 1) if(2 * i > N) ans += dp[N][i];
    cout << setprecision(15) << ans;

    
    return 0;
}

Measured memory_bytes: 70656
import sys
from collections import deque
n = int(sys.stdin.readline())
lines = sys.stdin.readlines()
 
Q = deque()
for i in range(n):
    command = lines[i].split()
    if command[0] == "insert":
        Q.appendleft(command[1])
    elif command[0] == "deleteFirst":
        Q.popleft()
    elif command[0] == "deleteLast":
        Q.pop()
    elif command[0] == "delete":
        try:
            Q.remove(command[1])
        except:
            pass
print(" ".join(Q))

# 0.158sec??§?????????????¢????

Measured memory_bytes: 214392
N,M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()
sa = [0 for i in range(M-1)]
# print(X)
for i in range(M-1):
    sa[i] = X[i+1]-X[i]
sa = sorted(sa)
# print(sa)
if N >= M:
    print(0)
elif N == 1:
    print(sum(sa))
else:
    print(sum(sa[0:-N+1]))

Measured memory_bytes: 13968
import itertools
def bit(n, m):
    bit_list = list(itertools.product([i for i in range(m)], repeat=n))
    return bit_list

l = [int(input()) for _ in range(5)]
bit = bit(5,5)
bit_n = []
for i in bit:
    if len(set(i)) == 5:
        bit_n.append(i)

res = float("inf")
for i in bit_n:
    time = 0
    for j in i:
        if time == 0:
            time += l[j]
        else:
            if time % 10 != 0:
                while time % 10 != 0:
                    time += 1
                time += l[j]
            else:
                time += l[j]
    if res > time:
        res = time

print(res)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int A, B;
      int x = 1;
      int y = 0;
      cin >> A >> B;
      
	for (int i = 0; i < 30; i++) {
      x = x - 1 + A;
      y++;
  //    cout << x << endl;
      if (x >= B) {break;}
    }
      if (B == 1) { y = 0;}
      cout << y << endl;

    }

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int M = input.nextInt();
        int[] A = new int[M];
        for (int i = 0; i < M; i++){
            A[i] = input.nextInt();
        }
        int ans = N;
        for (int i = 0; i < M; i++){
            ans -= A[i];
        }
        System.out.println(Math.max(-1,ans));
    }
}

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

int main() {
    int n;
    cin >> n;
    vector<int> up (n);
    vector<int> down (n);
    for(int i=0; i<n; i++){
        cin >> up.at(i);
    }
    for(int i=0; i<n; i++){
        cin >> down.at(i);
    }
    int ans = 0;
    int sum = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<=i; j++){
            sum += up.at(j);
        }
        for(int k=i; k<n; k++){
            sum += down.at(k);
        }
        ans = max(ans,sum);
        sum = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,ans=0; cin>>n;
	if(n>=500){
		long long num=n/500;
		n=n-(num*500);
		ans=ans+(num*500*2);
	}
	if(n>=5){
		long long num=n/5;
		ans=ans+(num*5);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i< (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
//long long ccw(const Point& A, const Point& B, const Point& C) {
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int k, x; cin >> k >> x;
	for (int i = x - k + 1; i < x + k; i++) {
		cout << i << ' ';
	}

	

}


Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {

	var N int
	fmt.Scan(&N)

	var S string
	fmt.Scan(&S)

	var nowString int32 = -100

	var ans = 0


	for _, x := range S {
		if x != nowString {
			ans++
			nowString = x
		}
	}

	fmt.Println(ans)

}



Measured memory_bytes: 1280
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
bool p[MAX + 1];
void sieve()
{
    memset(p, true, sizeof p);
    p[0] = p[1] = false;
    for(ll i = 2; i * i <= MAX; i++)
        if(p[i])
            for(ll j = i * i; j <= MAX; j += i)
                p[j] = false;
}
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll a, b;
    sieve();
    cin >> a >> b;
    ll g = __gcd(a, b);
    ll ans = 1;
    for(ll i = 2; i <= MAX; i++)
    {
        if(p[i] && g % i == 0)
        {
            ans++;
            while(g % i == 0)
                g /= i;
        }
    }
    if(g > 1)
        ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] t = new long[n];
		for(int i=0; i<n; i++) {
			t[i] = sc.nextLong();
		}
		sc.close();
		
		System.out.println(nlcm(t, n));
	}
	
	static long gcd(long a, long b) {
		long tmp;
		if(a<b) {
			tmp = b;
			b = a;
			a = tmp;
		}
		tmp = a%b;
		while(tmp!=0) {
			a = b;
			b = tmp;
			tmp = a%b;
		}
		return b;
	} 
	
	static long lcm(long a, long b) {
		return a/gcd(a, b)*b;
	}
	
	static long nlcm(long[] list, int n) {
		if(n==1) return list[0];
		return lcm(list[n-1], nlcm(list, n-1));
	}
}

Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(400*400*400)

H, W = map(int, input().split())
S = [input() for i in range(H)]

mask = ["".join(["#" if (i + j) % 2 else "." for j in range(W)]) for i in range(H)]

masked_S = [[1 if S[i][j] == mask[i][j] else 0 for j in range(W)] for i in range(H)]

S_colored = [[-1 for j in range(W)] for i in range(H)]

color_count = dict()


def fill(i, j, color):
    S_colored[i][j] = color

    if S[i][j] == "#":
        color_count[color][0] += 1
    else:
        color_count[color][1] += 1

    for yx in [(-1, 0), (0, 1), (1, 0), (0, -1)]:
        dy, dx = yx
        i2, j2 = i + dy, j + dx

        if i2 < 0 or i2 >= H or j2 < 0 or j2 >= W:
            continue

        if S_colored[i2][j2] != -1:
            continue

        if masked_S[i2][j2] != masked_S[i][j]:
            continue

        fill(i2, j2, color)


def main():
    color = -1
    for i in range(H):
        for j in range(W):
            if S_colored[i][j] != -1:
                continue
            color += 1
            color_count[color] = [0, 0]
            fill(i, j, color)

    result = 0
    for k in color_count.keys():
        result += color_count[k][0] * color_count[k][1]

    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 180044
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e15;

int main() {
  ll w,a,b;
  cin >> w >> a >> b;
  ll ans=max(abs(a-b)-w,0LL);
  cout << ans << endl;
}

Measured memory_bytes: 256
/*Lucky_Glass*/
#include<cstdio>
#include<algorithm>
int n,A[10005],B[10005];
long long sumA,sumB;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	for(int i=0;i<n;i++) scanf("%d",&B[i]);
	for(int i=0;i<n;i++)
	{
		if(A[i]-B[i]>0)
			sumA+=A[i]-B[i];
		else
			sumB-=(A[i]-B[i])/2;
	}
	printf("%s\n",sumA<=sumB?"Yes":"No");
	return 0;
}
/*
9 9 1 3 2
8 4 9 0 1

9 9 3 3 2
9 4 9 0 1

9 5 3 2
5 9 0 1

9 7 3 2
6 9 0 1

9 3 2
7 0 1


*/

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


int main(void){
    while(true){
        int n,x;
        cin>>n>>x;
        if(n==0){
            if(x==0){
                break;
            }
        }
        int ans = 0;
        for(int i=1;i<=n-2;i++){
            for(int j=i+1;j<=n-1;j++){
                for(int k=j+1;k<=n;k++){
                    if(i!=j){
                        if(j!=k){
                            if(k!=i){
                                if(i+j+k==x)ans++;
                            }
                        }
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S; cin>>S;
  int N=S.size();
  long long ans=(S.size()*(S.size()-1))/2;
  vector<long long>al(26);
  for(int i=0;i<N;i++)al[S[i]-97]++;
  for(int i=0;i<26;i++)ans-=al[i]*(al[i]-1)/2;
  cout<<ans+1<<endl;
}

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

int main() {
    int N;
    cin >> N;
    if (N == 100000) {
        cout << 90909 << endl;
    }
    if (N >= 10000 && N < 100000) {
        cout << N - 9999 + 909 << endl;
    }
    if (N >= 1000 && N < 9999) {
        cout << 909 << endl;
    }
    if (N >= 100 && N < 1000) {
        cout << N - 99 + 9 << endl;
    }
    if (N >= 10 && N < 100) {
        cout << 9 << endl;
    }
    if (N < 10) {
        cout << N << endl;
    } 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

 
int main() {
  int n=4;
  vector<int> a(4);
  int num;
  cin>>num;
  REP(i,n){
    a[n-1-i]=num%10;
    num=(num-num%10)/10;
  }

  for(int tmp=0;tmp<(1<<(n-1));tmp++){
    int ans=a[0];
    bitset<4> s(tmp);
    REP(j,n-1){
      if(s.test(j)){
        ans+=a[j+1];
      }else{
        ans-=a[j+1];
      }
    }
    if(ans==7){
      REP(i,n){
        cout<<a[i];
        if(i!=n-1){
          if(s.test(i)){
            cout<<'+';
          }else{
            cout<<'-';
          }
        }
      }
      cout<<'='<<7<<endl;
      break;
    }


  }
  
  return 0;
}

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

using ll = long long;

ll N, X;

// f(3,2) = 2*2*1+f(2,1)
// f(2,1) = 2*1*2+f(1,0)
// f(1,0) = 0
ll f( ll a, ll b )
{ return a%b ? 2*b*(a/b)+f(b,a%b) : ((a/b)*2-1)*b; }

int main()
{
  scanf( "%lld%lld", &N, &X );

  ll a = N-X, b = X;
  if( a < b )
    std::swap( a, b );

  printf( "%lld\n", N+f(a,b) );

  return 0;
}

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

int main() {
	long long n,k;
	cin >> n >> k;
	if(n<k){
	    
	}
	else{
	    n = n%k;
	}
	cout << min(n,abs(n-k)) << endl;
	return 0;
}


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

using namespace std;
using ll = int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using tpi = tuple<int, int, int>;

using vqi = vector<queue<int>>;
using vpi = vector<pii>;
using bs = bitset<60>;
using vbi = vector<bs>;

ll gcd(ll a, ll b) {
    if (a < b) {
        swap(a, b);
    }

    /* ユークリッドの互除法 */
    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

constexpr int64_t __pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        int64_t t = __pow_mod(n, p / 2, mod);
        return (t * t) % mod;
    }
    return (n * (__pow_mod(n, p - 1, mod) % mod)) % mod;
}

constexpr int64_t pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    int64_t res = __pow_mod(n, p, mod);
    if (res == 0) {
        res = mod;
    }
    return res;
}

constexpr int64_t nCr_mod(int64_t n, int64_t r, int64_t mod) noexcept {
    int64_t count = 1;
    auto a = r;
    for (auto i = n; i > n - r; i--) {
        count *= i;
        if (count % mod != 0) {
            count %= mod;
        }
        int64_t inv = pow_mod(a, mod - 2, mod);
        count *= inv;
        if (count % mod != 0) {
            count %= mod;
        }
        a--;
    }
    return count;
}

void solve(long long N, std::string S) {
    if (N < 3) {
        cout << 0 << endl;
        return;
    }
    ll nr = 0;
    ll ng = 0;
    ll nb = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') {
            nr++;
        } else if (S[i] == 'G') {
            ng++;
        } else {
            nb++;
        }
    }
    if (nr == 0 || ng == 0 || nb == 0) {
        cout << 0 << endl;
        return;
    }
    ll ans = nr * ng * nb;
    for (int i = 0; i < N - 2; i++) {
        for (int m = 1; (i + 2 * m) < N; m++) {
            if ((S[i] != S[i + m]) && (S[i] != S[i + 2 * m]) && (S[i + m] != S[i + 2 * m])) {
                ans--;
            }
        }
    }
    cout << ans << endl;
}

int main() {
    long long N;
    std::cin >> N;
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
const ll mod = 1e9 + 7;
const int mxN = 200005;
ll h, w, a, b, ans, f[mxN], inv[mxN];
 
ll binpow(ll a, ll b)
{
	if (b == 0)	return 1;
	if (b % 2 == 0) {
		ll temp = binpow(a, b/2) % mod;
		return (temp * temp) % mod;
	}
	else {
		return binpow(a, b-1)*a % mod;
	}
}
 
ll inverse(ll n) {
	return binpow(n, mod - 2);
}
 
void fact() {
	f[0] = inv[0] = 1;
	for(ll i = 1; i < mxN; i++){
		f[i] = (f[i-1]*i)%mod;
		inv[i] = inverse(f[i]);
	}
}
 
ll calc(ll n, ll m) {
	return ((f[m]*inv[n]%mod)*inv[m-n])%mod;
}
 
signed main() {
	fact();
	cin >> h >> w >> a >> b;
	for(ll i = 0; i <= h - a; i++){
		ans += (calc(i-1,i+b-2)% mod * calc(h - i,h - i + w - b - 1)) % mod;
		ans%=mod;
	}
	cout << ans << endl;
}

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

using namespace std;

#define MAX 500
#define MAX_M 10000

int main(){
  int N,M;
  while(cin >> N >> M,(N | M)){
    bool F[MAX] = {0},C[MAX] = {0};
    int A[MAX_M],B[MAX_M], idx = 0;
    for(int i = 0 ; i < M ; i++){
      int a,b;
      cin >> a >> b; a--; b--;
      if(!a){
        F[b] = C[b] = true;
      }else{
        A[idx] = a; B[idx++] = b;
      }
    }
    for(int i = 0 ; i < idx ; i++){
      if(!F[A[i]] && F[B[i]]){
        C[A[i]] = true;
      }else if(F[A[i]] && !F[B[i]]){
        C[B[i]] = true;
      }
    }
    cout << count(C,C+N,true) << endl;
  }
  return 0;
}

Measured memory_bytes: 1236
N = int(input())
s = [int(input()) for _ in range(N)]

MAX_VALUE = 100001
dp = [[False for _ in range(MAX_VALUE)] for _ in range(N+1)]

dp[0][0] = True
for i in range(N):
    score = s[i]
    for j in range(MAX_VALUE):
        dp[i+1][j] |= dp[i][j]
        if j >= score:
            dp[i+1][j] |= dp[i][j-score]
ans = 0

for i in range(MAX_VALUE):
    if dp[N][i] == True and i % 10 != 0:
        ans = i
print(ans)



Measured memory_bytes: 173516
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] b = new int[9];
		
		for(int i = 0; i < N; i++) {
			int a = sc.nextInt();
			for(int j = 0; j < 8; j++) {
				if(400 * j <= a && a <= 399 + 400 * j) {
					b[j]++;
					break;
				}
			}
			if(3200 <= a) {
				b[8]++;
			}
		}
		
		int sum = 0;
		
		for(int i = 0; i < 9; i++) {
			if(b[i] >= 1) {
				sum++;
			}
		}

		if(b[8] == 0) {
			System.out.println(sum + " " + sum);
		} else {
			if(sum == 1) {
				System.out.println(sum + " " + (sum - 1 + b[8]));
			} else {
				System.out.println(sum - 1 + " " + (sum - 1 + b[8]));
			}
		}
	}
}


Measured memory_bytes: 21844
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()

	if N == 1:
		print(0)
		sys.exit()

	ans = 0
	for i in range(1,N):
		ans += i

	print(ans)

if __name__ == "__main__":
	main()


Measured memory_bytes: 40464
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto abc = readln.split.to!(int[]);
    auto d = abc[0] + abc[1] + abc[2];
    writeln(d + max(abc[0], abc[1], abc[2]) * 9);
}

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

int main() {
    int n, k;
    cin >> n >> k;

    vector<int> v(n);
    int vmin = INT32_MAX;
    int idx = n;

    for(int i = 0; i < n; i++) {
        cin >> v[i];
        if(vmin > v[i]) {
            idx = i;
            vmin = v[i];
        }
    }

    int cnt = 0;
    int len = 1;
    while(len < n) {
        len += k - 1;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 1;
const ll mo = 1000000007;

int main()
{
ll n ;
cin >> n ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
}
vector<ll> v(3);
rep(i,n){
  ll cnt=0;
  rep(j,3)if(v[j]==a[i])cnt++;
  if(cnt==0){
    cout << 0 << endl;
    return 0;
  }
  ans*=cnt;
  ans%=mo;
  rep(j,3)if(v[j]==a[i]){
    v[j]++;
    break;
    }
}

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define M ((ll)(1e9)+7)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
ll power(ll x,ll y)
{
    if(y==0)
    return 1;
    ll res=power(x,y/2);
    res=(res*res)%M;
    if(y&1)
    res=(res*x)%M;
    return res;
}
void solve()
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    ll fact[n+1];fact[0]=1;
    
    for(ll i=1;i<n+1;i++)
    fact[i]=(i*fact[i-1])%M;
    ll ans1=0,ans2=0;
    for(ll i=0;i<n;i++)
    {
        if(i>=k-1)
        {
            ll va=fact[i];
            va=(va*power(fact[k-1],M-2))%M;
            va=(va*power(fact[i-k+1],M-2))%M;
            va=(va*a[i])%M;
            ans1=(ans1+va)%M;
        }
        ll b=n-i-1;
        if(b>=k-1)
        {
            ll va=fact[b];
            va=(va*power(fact[k-1],M-2))%M;
            va=(va*power(fact[b-k+1],M-2))%M;
            va=(va*a[i])%M;
            ans2=(ans2+va)%M;
        }
    }
    ans1=(ans1-ans2+M)%M;
    cout<<ans1<<endl;
}

int main()
{
    solve();
}

Measured memory_bytes: 1792
x,y = map(int,input().split())
li = list(map(int,input().split()))	
cnt = 0
for i in range(len(li)):
    if li[i] >= sum(li) / (4*y):
        cnt += 1
else:
    pass

if cnt >= y:
    print("Yes")
else:
    print("No")    

Measured memory_bytes: 38512
#include <bits/stdc++.h>
#include <vector>
#include <cstdlib> //abs(int)
using namespace std;
int main(void){
  string A;
  cin >> A;
  int count;
  for(int i = 0; i < 3; i++){
    if(A.at(i) == 'o'){
      count++;
    }
  }
  cout << 700 + count * 100;
}

Measured memory_bytes: 256
n, rate_min = int(input()), int(input())
for i in range(1, n):
    rate_t = int(input())
    prof = rate_t - rate_min
    if i==1:
        max_prof = prof
    elif max_prof < prof:
        max_prof = prof
    if rate_t < rate_min:
        rate_min = rate_t
print(max_prof)



Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
int main() {
    double a,b,x,theta;
    cin >> a >> b >> x;
    double s = x/a,ans = 0,a2 = 0;
    if(s == a*b) ans = 0;
    else{
        if(s > a*b/2){
            double y = 2*x/a/a-b;
            b -= y;
            theta = atan(b/a);
        }else{
            a2 = 2*s/b;
            theta = atan(b/a2);
        }
    }
    ans = theta*180.0/M_PI;
    cout << fixed <<  setprecision(10) << ans << endl;
    return 0;
}


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

int main() {
  ll N; cin >> N;
  vector<ll> vec;
  for(ll i = 1; i*i <= N; i++) {
    if(N % i == 0) vec.push_back(i), vec.push_back(N/i);
  }
  sort(vec.begin(), vec.end());
  ll ans = 0;
  for(ll v: vec) {
    ll m = N/v - 1;
    if(m == 0) continue;
    if(N/m == N%m) ans += m;
  }
  cout << ans << endl;
  return 0;
}


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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

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

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//std out
template<typename T>
void print_container(const vector<T> vals) {
    REPinit(i, 0, vals.size() - 1) cout << vals.at(i) << " ";
    cout << vals.back();
}


bool judge(int a, int b, int c) {
    if ((a > b && b > c) || (a < b && b < c)) return true;
    return false;
}

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

    int N;
    cin >> N;
    cout << (N * N * N) << endl;

    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define re() pop_back()
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define all(a) a.begin(),a.end()
#define msort(a) sort(a.begin(),a.end())
#define pii pair<int,int>
#define sz(x) int(x.size())
#define mk make_pair
#define endl '\n'

const int maxn=5e3+5;
vector<int> p(maxn+1,0);
vector<int> c(maxn,0);
unordered_map<int,int> mp;
vector<pair<int,ll>> num;
void solve()
{
    int n,k;
    cin>>n>>k;
    for (int i = 1; i < n+1; i++)
    {
        cin>>p[i];
    }
    for (int i = 1; i < n+1; i++)
    {
        cin>>c[i];
    }
    
    ll ans=LLONG_MIN;

    for (int i = 1; i < n+1; i++)
    {
        mp.clear();
        num.clear();
        ll mx=LLONG_MIN;
        num.eb(mk(i,0));
        int count=0;
        ll mpans=0;
        while(count<k)
        {
            pair<int,ll> last=num.back();
            int go=p[last.first];

            if(mp.count(go))
            {
                int preind=mp[go];
                ll sm=num[preind-1].second; 
                if(last.second-sm<=0) {
                    count=k;
                    break;
                }
                int ind=num.size()-1 -(preind-1);
                int val=(k-count)/ind;
                if(val>0) val--;
                count+=ind*val;
                mpans+=val*(last.second-sm);
                mx=max(mx,mpans);
                break;
            }
            
            mpans+=c[go];
            mx=max(mx,mpans);
            mp[go]=num.size();
            num.eb(mk(go,mpans));
            count++;
        }

        while(count<k){
            pair<int,ll> last=num.back();
            int go=p[last.first];
            mpans+=c[go];
            mx=max(mx,mpans);
            num.eb(mk(go,mpans));
            count++;
        }

        ans=max(ans,mx);
    }
    
    cout<<ans;
}

int main()
{
    IOS;
    ll t=1;
    while (t--)
    {
        solve();
    }
}


Measured memory_bytes: 3972
#include<bits/stdc++.h>
#include<unordered_map>
#include<string>
#include<math.h>
#define ll long long
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int N= 1e8;
inline void fastio()
{ 
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

ll gcd(ll a,ll b)
{
    ll m = max(a, b);
    b = a + b - m, a = m;
    while(a%b!=0)
    {
        ll temp = b;
        b = a % b;
        a = temp;
    }
    return b;
}

void mul(int* a,int b)
{
    ll product = 0;
    for (int i = 0; i <= 999;i++)
    {
        a[i] = a[i] * b + product;
        product = a[i] / 10;
        a[i] %= 10;
    }
}
void add(int*a,int*b)
{
    int sum = 0;
    for (int i=0; i <= 999;i++)
    {
        a[i] = a[i] + b[i] + sum;
        sum = a[i] / 10;
        a[i] %= 10;
    }
}
int isPrime[N+10];//isPrime[i] == 1表示：i是素数
int Prime[N], cnt = 0;//Prime存质数
void GetPrime(int n)//筛到n
{
    memset(isPrime, 1, sizeof(isPrime));
    isPrime[1] = 0;
    Prime[cnt] = 1;
    for (int i = 2; i <= n;i++)
    {
        if(isPrime[i])  Prime[++cnt] = i;

        for (int j = 1; (j <= cnt)&& ((ll)Prime[j] * i <= n); j++)
        {
            isPrime[i * Prime[j]] = 0;
            if(i%Prime[j]==0)
                break;
        }
    }
}
bool isPalindromes(int n)
{
    int num = n, reverse_n = 0;
    while(n)
    {
        reverse_n *= 10;
        reverse_n += n % 10;
        n /= 10;
    }
    return (num==reverse_n);
}
int main()
{
    int a, b;
    cin >> a >> b;
    cout << a * b;
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define INF	123456789

int N, W, v[112], w[112];
int memo[112][11234];

int dp(int i, int j) {
	if (j < 0) { return -INF; }
	if (i == 0) { return 0; }
	if (memo[i][j] != -1) { return memo[i][j]; }
	return memo[i][j] = std::max(dp(i - 1, j), dp(i - 1, j - w[i - 1]) + v[i - 1]);
}

int main(void) {
	scanf("%d%d", &N, &W);
	for (int i = 0; i < N; ++i) { scanf("%d%d", &v[i], &w[i]); }

	memset(memo, -1, sizeof(memo));

	printf("%d\n", dp(N, W));
	return 0;
}

Measured memory_bytes: 7596
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let N: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    if N == 1 {
        let ans = "Hello World";
        println!("{}", ans);
    } else {
        let A: i64 = {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse().unwrap()
        };
        let B: i64 = {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse().unwrap()
        };

        let ans = A + B;

        println!("{}", ans);
    }
}


Measured memory_bytes: 4352
import numpy as np

def main():
    n=int(input())
    a=[int(x)-1 for x in input().split()]
    b=[int(x) for x in input().split()]
    c=[int(x) for x in input().split()]

    s=0
    p=n
    for i in range(n):
        s += b[a[i]]
        if p == a[i]-1:
            s += c[p]
        p=a[i]

    print(s)




if __name__ == '__main__':
    main()

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

#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 10000000;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem2204 : Kagisys **/
int main()
{
	set<string> s;
	int N, M; bool open=false;
	cin>>N;
	rep(i, N) {
		string st;
		cin>>st;
		s.insert(st);
	}
	cin>>M;
	rep(i, M) {
		string st;
		cin>>st;
		if (s.count(st)) {
			if (!open)
				cout << "Opened by " << st << endl;
			else
				cout << "Closed by " << st << endl;
			open = !open;
		} else {
			cout << "Unknown " << st << endl;
		}
	}
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    double aa;
    if (d%2==1){
        aa=(c*60+d)/2+0.5;
    }
    else{
        aa=(c*60+d)/2;
    }
    double ww=d*6;
    double t=min(abs(aa-ww), 360-abs(aa-ww));
    double ca=cos(t*3.1415926535897932*2/360);
    double ou=sqrt(a*a+b*b-2*a*b*ca);
    cout << fixed << setprecision(17) << ou << endl;
}


Measured memory_bytes: 4156
n, m = gets.split.map(&:to_i)
ab = m.times.map {gets.split.map(&:to_i)}

ab.sort_by!{|a,b| a}

x = ans = 0
ab.each do |a, b|
    if x > a
        x = [x, b].min
    else
        x = b
        ans += 1
    end
end

p ans

Measured memory_bytes: 12664
n=int(input())
slist=[]
tlist=[]
ans=0
yn=0
for i in range(n):
    s,t=input().split()
    slist.append(s)
    tlist.append(int(t))
x=input()
for i in range(n):
    if yn==1:
        ans+=tlist[i]
    if x==slist[i]:
        yn=1
print(ans)


Measured memory_bytes: 3060
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[9];
		int ans=0;
		
		for(int i=0;i<n;i++){
    		int b=sc.nextInt();
            if(b<3200){
                a[b/400]++;
            }else{
          	    a[8]++;
            }
    	}
        
  		for(int i=0;i<8;i++){
        	if(a[i]>0){
                ans++;
            }
        }
        
        System.out.print(Math.max(ans,1)+" ");
     	System.out.println(ans+a[8]);
   }
}


Measured memory_bytes: 38520
N,K = map(int,input().split())
List = list(input().split())
Digit = ['0','1','2','3','4','5','6','7','8','9']
for item in List:
  if item in Digit:
    Digit.remove(item)
for i in range(N,10*N):
  if set(list(str(i))) <= set(Digit):
    print(i)
    exit()

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


int main(){
	int a,b,c,d,i;
	
	while(1){
		cin >> a >> b ;

		/*if((a >= 0) && (a <= 1000000)){
			if((b >= 0) && (b <= 1000000))
				break ;
		}*/

		if(cin.eof() )
			break ;
		

		c = a + b ;

		for(i=1;i<7;i++){
			c = c / 10 ;
			if(c == 0) break;

		}

		cout << i << endl ;

		
	}
	
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define CLR(a,x) memset(a,x,sizeof(a))
#define MP make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pa;
const int maxn=1e5+10;

inline ll rd(){
    ll x=0;char c=getchar();int neg=1;
    while(c<'0'||c>'9'){if(c=='-') neg=-1;c=getchar();}
    while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*neg;
}

int N,K;

inline int gcd(int a,int b){return a?gcd(b%a,a):b;}

int main(){
    //freopen("","r",stdin);
	N=rd(),K=rd();
	int g=0,ma=0;
	for(int i=1;i<=N;i++){
		int x=rd();
		g=gcd(g,x);
		ma=max(ma,x);
	}
	if(ma>=K&&K%g==0) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 256