akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h> 
#include <set>
#include <map>

using namespace std;

#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
const int MOD = 1e9 + 7;





int main() {
    int n;
    cin >> n;
    vll a(n + 1);
    rep(i, n) cin >> a[i];
    ll even = 0;
    ll odd = 0;

    vll sum(n + 1);
    sum[0] = a[0];
    rep(i, n) {
        if (i % 2 == 0 && sum[i] <= 0) {
                even += 1 - sum[i];
                sum[i] = 1;
        }
        else if (i % 2 == 1 && sum[i] >= 0) {
                even += 1 + sum[i];
                sum[i] = -1;
        }
        sum[i + 1] = sum[i] + a[i + 1];
    }

    vll summ(n + 1);
    summ[0] = a[0];
    rep(i, n) {
        if (i % 2 == 0 && summ[i] >= 0) {
                odd += 1 + summ[i];
                summ[i] = -1;
            }
        else if (i % 2 == 1 && summ[i] <= 0) {
                odd += 1 - summ[i];
                summ[i] = 1;
        }
        summ[i + 1] = summ[i] + a[i + 1];
    }
    ll ans = min(odd, even);
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <functional>
#include <math.h>
using namespace std;
int main(){
  int x[10000];
  int i=0;
  while(1){
    cin>>x[i];
    if(x[i]==0) break;
    i++;
  }
  for(int j=0;j<i;j++){
    cout<<"Case "<<j+1<<": "<<x[j]<<'\n';
  }
  return 0;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;cin >> n >> m;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end(),greater<ll>());
    vector<ll> sum(n+1),d(200005);
    for(int i=0;i<n;i++){
        sum[i+1]=sum[i]+a[i];
        d[a[i]]++;
    }
    for(int i=200004;i>0;i--){
        d[i-1]+=d[i];
    }
    ll l=0,r=200005;
    while(r-l>1){
        ll mid=(l+r)/2;
        ll cnt=0;
        for(int i=0;i<n;i++){
            cnt+=d[max(0LL,mid-a[i])];
        }
        if(cnt>=m){
            l=mid;
        }
        else{
            r=mid;
        }
    }
    ll ans=0;
    ll t=0;
    for(int i=0;i<n;i++){
        ll p=-1,q=n;
        while(q-p>1){
            int mid=(p+q)/2;
            if(a[mid]>=l-a[i]){
                p=mid;
            }
            else{
                q=mid;
            }
        }
        ans+=sum[p+1]+(p+1)*a[i];
        t+=p+1;
    }
    ans-=(t-m)*l;
    cout << ans << endl;
}

Measured memory_bytes: 3456
from bisect import bisect_left
def main():
    n, w = map(int, input().split())
    item = [list(map(int, input().split())) for _ in range(n)]
    dp = [w+1]*(10**5+1)
    dp[0] = 0
    item.sort(key=lambda x: x[1])
    x = 0
    for p, q in item:
        for i in reversed(range(q, min(len(dp), x+q+1))):
            dp[i] = min(dp[i-q]+p, dp[i])
        x += q
    ans = 0
    for i in reversed(range(len(dp))):
        if dp[i] <= w:
            ans = i
            break
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 5364
N,M = map(int, input().split(' '))
ret = {}

for n in range(N):
  p = input().split(' ')
  for k in range(int(p[0])):
    key = p[int(k)+1]
    if key in ret:
      ret[key] += 1
    else:
      ret[key] = 1

print(list(ret.values()).count(N))


Measured memory_bytes: 3060
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools

N,MOD = map(int,readline().split())
m = map(int,read().split())
XY = zip(m,m)

mult = lambda x,y: x*y%MOD

graph = [[] for _ in range(N+1)]
for x,y in XY:
    graph[x].append(y)
    graph[y].append(x)

root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

# 自身を黒く塗ったときの根側
dp1 = [0]*(N+1)

for v in order[::-1]:
    x = 1
    for w in graph[v]:
        x *= dp1[w]+1
        x %= MOD
    dp1[v] = x

# 親側
dp2 = [1]*(N+1)

for v in order:
    p = parent[v]
    arr = [dp1[c]+1 if c != p else dp2[v] for c in graph[v]]
    # 1元を除く積を取得
    from_left = [1] + list(itertools.accumulate(arr,mult))[:-1]
    from_right = list(itertools.accumulate(reversed(arr),mult))[-2::-1] + [1]
    prod = [x*y%MOD for x,y in zip(from_left,from_right)]
    for c,x in zip(graph[v],prod):
        if c != p:
            dp2[c] = 1+x

answer = '\n'.join(str(x*y%MOD) for x,y in zip(dp1[1:],dp2[1:]))
print(answer)

Measured memory_bytes: 41420
#include <stdio.h>
#define MAX 200000
int main(){
  int i,j,n,min = 100000000,time,max,A[MAX];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  min = A[0];
  max = A[1] - A[0];
  for(i=1;i<n;i++){
    if(max < A[i] -min)
      max = A[i] -min;
    if(min > A[i])
      min = A[i];
  }
  printf("%d\n",max);
  return 0;
}



Measured memory_bytes: 2572
#include <stdio.h>

int getAns(int, int a[]);

int main() {
    int n;
    int p[100000] = {0};
    
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++) {
        scanf("%d ", p + i);
    }
    scanf("%d", p + n - 1);

    printf("%d", getAns(n, p));

    return 0;
}

int getAns(int n, int p[]) {
    int count = 0;
    int num[100000] = {0};
    int s = -1, e;
 
    for (int i = 0; i < n; i++) {
        num[p[i]]++;
    }

    for (int i = 0; i < 100000; i++) {
        count += num[i];
        if (s == -1 && count == n / 2) {
            s = i;
        } else if (count > (n / 2)) {
            e = i;
            break;
        }
    }

    if (s < 0) {
        return 0;
    }

    return e - s;
}



Measured memory_bytes: 896
import java.util.Scanner;

public class Main{
    public static void main(String[]argc){
        Scanner sc =new Scanner(System.in);
        for(int k=0;;k++){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H==0&&W==0) break;
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if(i%2==j%2){
                        System.out.printf("#");
                    }else{
                        System.out.printf(".");
                    }
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}


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

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

#define MOD 1000000007  //E9

ll mod(ll val,ll m=MOD){
    ll r=val%m;
    return (r<0)?r+m:r;
}
//a^n%m
ll modpow(ll a,ll n,ll m=MOD){
    ll r=1;
    while(n>0){
        if(n&1)r=r*a%m;
        a=a*a%m;
        n>>=1;
    }
    return r;
}

//nCk mod m
//init:O(n),COM:O(1)
const int COMMAX=2000002;
ll fac[COMMAX],finv[COMMAX],inv[COMMAX];
void COMinit(int m=MOD){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<COMMAX;i++){
        fac[i]=fac[i-1]*i%m;
        inv[i]=m-inv[m%i]*(m/i)%m;
        finv[i]=finv[i-1]*inv[i]%m;
    }
}ll COM(int n,int k,int m=MOD){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%m)%m;
}


int main(void){
    int k;
    cin>>k;
    string stmp;
    cin>>stmp;
    int s=stmp.size();
    
    COMinit();
    ll ans=0;
    for(int i=0;i<=k;i++){
        ans+=COM(s+i-1,s-1)*((modpow(25,i)*modpow(26,k-i))%MOD);
        ans%=MOD;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 51180
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <limits>

int main() 
{
    long double A;
    long double B;
    std::cin >> A >> B;

    long double ans = A * B;

    std::cout << static_cast<int64_t>(ans) << std::endl;

    return 0;
}

Measured memory_bytes: 3792
def square(n):
  mp = [[0 for _ in range(n)] for _ in range(n)]
  
  x, y = n // 2 , n // 2 + 1
  mp[y][x] = 1
  
  for i in range(2, n ** 2 + 1):
    x = (x + 1) % n
    y = (y + 1) % n
    
    while mp[y][x]:
      y = (y + 1) % n
      x = (x - 1) % n
    
    mp[y][x] = i
  
  for line in mp:
    s = ""    
    for i in line:
      si = str(i)
      s += si.rjust(4)
    print(s)

while True:
  n = int(input())
  if not n:
    break
  square(n)


Measured memory_bytes: 5596
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int field[12][6];
bool visit[12][6];
bool erase[12][6];
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

void fall() {
  REP(iter, 12) {
    for (int y = 11; y > 0; y--) {
      REP(x, 6) {
        if (field[y][x] == -1) {
          field[y][x] = field[y - 1][x];
          field[y - 1][x] = -1;
        }
      }
    }
  }
}

int dfs1(int y, int x, int color) {
  if (visit[y][x] || field[y][x] != color) { return 0; }
  visit[y][x] = true;
  int ret = 1;
  REP(i, 4) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (nx < 0 || nx >= 6 || ny < 0 || ny >= 12) { continue; }
    ret += dfs1(ny, nx, color);
  }
  return ret;
}

void dfs2(int y, int x, int color) {
  if (erase[y][x]) { return; }
  if (field[y][x] == 5 || field[y][x] == color) {
    erase[y][x] = true;
  }
  if (field[y][x] != color) { return; }
  REP(i, 4) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (nx < 0 || nx >= 6 || ny < 0 || ny >= 12) { continue; }
    dfs2(ny, nx, color);
  }
}

int main() {
  int mapto[300];
  mapto[(int)'R'] = 0;
  mapto[(int)'G'] = 1;
  mapto[(int)'B'] = 2;
  mapto[(int)'Y'] = 3;
  mapto[(int)'P'] = 4;
  mapto[(int)'O'] = 5;
  mapto[(int)'.'] = -1;
int test;
scanf("%d", &test);
while (test--) {
  REP(y, 12) {
    REP(x, 6) {
      char c;
      scanf(" %c ", &c);
      field[y][x] = mapto[(int)c];
    }
  }
  int chain;
  for (chain = 0;; chain++) {
    bool end = true;
    MEMSET(visit, false);
    MEMSET(erase, false);
    REP(y, 12) {
      REP(x, 6) {
        if (field[y][x] != -1 && field[y][x] != 5) {
          if (dfs1(y, x, field[y][x]) >= 4) {
            dfs2(y, x, field[y][x]);
          }
        }
      }
    }
    REP(y, 12) {
      REP(x, 6) {
        if (erase[y][x]) {
          field[y][x] = -1;
          end = false;
        }
      }
    }
    fall();
    if (end) { break; }
  }
  printf("%d\n", chain);
}
}

Measured memory_bytes: 0
s = input()

na = nb = nc = 0
for c in s:
  if c == 'a':
    na += 1
  if c == 'b':
    nb += 1
  if c == 'c':
    nc += 1

if abs(na - nb) < 2 and abs(na - nc) < 2 and abs(nb - nc) < 2:
  print("YES")
else:
  print("NO")


Measured memory_bytes: 67664
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>pat[101000];
vector<int>ko[101000];
bool flag[101000];
int deg[101000];
void dfs(int node)
{
	flag[node] = true;
	for (int i = 0; i < pat[node].size(); i++)
	{
		if (!flag[pat[node][i]])
		{
			dfs(pat[node][i]);
			ko[node].push_back(pat[node][i]);
		}
	}
}
int calc(int node, int med)
{
	vector<int>vec;
	for (int i = 0; i < ko[node].size(); i++)vec.push_back(calc(ko[node][i], med));
	sort(vec.begin(), vec.end());
	if (vec.size() % 2 == 0)
	{
		bool f = true;
		for (int i = 0; i < vec.size() / 2; i++)if (vec[i] + vec[vec.size() - 1 - i]>med)f = false;
		if (f)return 1;
		if (vec[vec.size() - 1]>med)return 10000000;
		vec.pop_back();
		int b = 0, e = vec.size();
		for (;;)
		{
			if (b == e)break;
			int m = (b + e) / 2;
			vector<int>z;
			for (int i = 0; i < vec.size(); i++)if (m != i)z.push_back(vec[i]);
			bool g = true;
			for (int i = 0; i < z.size() / 2; i++)if (z[i] + z[z.size() - 1 - i]>med)g = false;
			if (g)e = m;
			else b = m + 1;
		}
		if (b == vec.size())return 10000000;
		else return vec[b] + 1;
	}
	else
	{
		int b = 0, e = vec.size();
		for (;;)
		{
			if (b == e)break;
			int m = (b + e) / 2;
			vector<int>z;
			for (int i = 0; i < vec.size(); i++)if (m != i)z.push_back(vec[i]);
			bool g = true;
			for (int i = 0; i < z.size() / 2; i++)if (z[i] + z[z.size() - 1 - i]>med)g = false;
			if (g)e = m;
			else b = m + 1;
		}
		if (b == vec.size())return 10000000;
		else return vec[b] + 1;
	}
}
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)pat[i].clear(), ko[i].clear(), flag[i] = false, deg[i] = 0;
	for (int i = 0; i < num - 1; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		pat[za].push_back(zb);
		pat[zb].push_back(za);
		deg[za]++, deg[zb]++;
	}
	int root;
	for (int i = 0; i < num; i++)if (deg[i] == 1)root = i;
	dfs(root);
	int beg = 1, end = num - 1;
	for (;;)
	{
		if (beg == end)break;
		int med = (beg + end) / 2;
		if (calc(root, med) <= med + 1)end = med;
		else beg = med + 1;
	}
	int r = 0;
	for (int i = 0; i < num; i++)r += deg[i] % 2;
	printf("%d %d\n", r / 2, beg);
}

Measured memory_bytes: 24192
#include<stdio.h>
int check(int h[],int n){
  int flag = 0,i;
  for(i=0;i<n-1;i++){
    if(h[i]>h[i+1]) flag=1;
  }
  return flag;
}
int main(void){
  int n,i;
  scanf("%d",&n);
  int h[n],t[n];
  for(i=0;i<n;i++){
    scanf("%d",&h[i]);
    t[i] = 0;
  }
  if(n==1){
    printf("Yes\n");
    return 0;
  }
  while(check(h,n)){
    for(i=n-2;i>-1;i--){
      if((h[i]>h[i+1]) && t[i]==0){
        h[i]--;
        t[i]++;
      }else if((h[i]>h[i+1]) && t[i]==1){
        printf("No\n");
        return 0;
      }
    }
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 896
n=int(input())
a=list(map(int,input().split()))
ans=0
k=0
Xor=0
Add=0
for i in range(n):
    while k<n and Xor^a[k]==Add+a[k]:
        Xor^=a[k]
        Add+=a[k]
        k+=1
    ans+=k-i
    Xor^=a[i]
    Add-=a[i]
print(ans)

Measured memory_bytes: 24424
from sys import stdin
def nC2(n):
    return n*(n-1)//2

def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    s=[""]*N
    for i in range(N):
        a=list(readline().strip())
        a.sort()
        s[i]="".join(a)

    d=dict()
    for i in range(N):
        if s[i] not in d:
            d[s[i]]=1
        else:
            d[s[i]]+=1

    res=0
    for v in d.values():
        if v==1:
            pass
        else:
            res+=nC2(v)

    print(res)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 19460
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <math.h>
#include <bitset>

using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;

#define rep(i,s,n)for(int i = s;i<n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=s;i--)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define repe_r(i,s,n)for(int i = n;i>=s;i--)

ll Pow(ll n, ll p) {
	if (p == 0)return 1;
	if (p == 1)return n;
	ll t = Pow(n, p / 2);
	if (p & 1) return (t * t % MOD) * n % MOD;
	else return t * t % MOD;
}

ll K[100001] = {};
int main() {
	ll n, k; cin >> n >> k;
	ll m = min(n, k - 1);

	ll x = k;
	ll po = 1;
	while (x) {
		rep(i, x / 2 + (x & 1), x) {
			K[i] = po;
		}
		if (x == 1)break;
		x = x / 2 + (x & 1);
		po++;
	}
	double ans = 0;
	if (n >= k) {
		ans += (double)((double)(n - k + 1) / (double)n);
	}

	repe(i, 1, m) {
		ll q = K[i];
		ans += (double)(1.0 / n) * (double)(1.0 / Pow(2, q));
	}

	printf("%.10f", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


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

	string s;
	cin >> s;
	vector<string> t = { "KIH","B","R" };
	rep(i, (1 << 4)) {
		string check = "";
		rep(j, 4) {
			if ((i >> j) & 1) check += "A";
			if (j != 3) check += t[j];
		}
		if (check == s) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

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

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

    set<int> values;
    for (int i = a; i >= 0; i--)
    {
        int tmp ;
        cin >>tmp;
        values.insert(tmp);
    }
    cout << values.size()<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a,b;
cin>>a>>b;
if(a%3==0||b%3==0||(a+b)%3==0)cout<<"Possible"<<endl;
else cout<<"Impossible"<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)
l_1 = [0 if i%2==0 else 1 for i in range(N)]
l_2 = [1 if i%2==0 else 0 for i in range(N)]

l_s = [int(i) for i in S]

a1 = 0
a2 = 0
for i in range(N):
    d = l_s[i] - l_1[i]
    if d!=0:
        a1+=1
for i in range(N):
    d = l_s[i] - l_2[i]
    if d!=0:
        a2+=1
if a1>a2:
    print(a2)
else:
    print(a1)


Measured memory_bytes: 5620
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

from itertools import accumulate

def sum_max(line,n_min,n_max):
    n = len(line)
    ac = list(accumulate([0]+line))
    l = 0
    r = n_min
    ans = ac[r]-ac[l]
    i  = 0
    if n_min>n_max:
        ans = 0
    elif n_min==n_max:
        for i in range(n-n_min+1):
            ans = max(ans,ac[i+n_min]-ac[i])
    else:
        while r!=n or i%2==1:
            if i%2==0:
                r = ac[r+1:l+n_max+1].index(max(ac[r+1:l+n_max+1])) + r+1
            else:
                l = ac[l+1:r-n_min+1].index(min(ac[l+1:r-n_min+1])) + l+1
            i+=1
            ans = max(ans,ac[r]-ac[l])
    return ans

def sum_min(line,n_min,n_max):
    n = len(line)
    ac = list(accumulate([0]+line))
    l = 0
    r = n_min
    ans = ac[r]-ac[l]
    i  = 0
    if n_min>n_max:
        ans = 0
    elif n_min==n_max:
        for i in range(n-n_min+1):
            ans = min(ans,ac[i+n_min]-ac[i])
    else:
        while r!=n or i%2==1:
            if i%2==0:
                r = ac[r+1:l+n_max+1].index(min(ac[r+1:l+n_max+1])) + r+1
            else:
                l = ac[l+1:r-n_min+1].index(max(ac[l+1:r-n_min+1])) + l+1
            i+=1
            ans = min(ans,ac[r]-ac[l])
    return ans

def circle_sum_max(circle,n_min,n_max):
    n = len(circle)
    s = sum(circle)
    if n_min>n_max:
        ans = 0
    else:
        ans = max(sum_max(circle,n_min,n_max), s-sum_min(circle,n-n_max,n-n_min))
    return ans

def circle_sum_min(circle,n_min,n_max):
    n = len(circle)
    s = sum(circle)
    if n_min>n_max:
        ans = 0
    else:
        ans = max(sum_min(circle,n_min,n_max), s-sum_max(circle,n-n_max,n-n_min))
    return ans
 
n,k = readints()
p = [x-1 for x in readints()]
c = readints()

circles = []
used = [0]*n

for i in range(n):
    if not used[i]:
        circles.append([c[i]])
        used[i] = 1
        j = p[i]
        while not used[j]:
            circles[-1].append(c[j])
            used[j] = 1
            j = p[j]

score = -10**20

for cir in circles:
    m = len(cir)
    a = sum(cir)
    if k>m:
        if a>0:
            score = max(score, (k//m)*a + circle_sum_max(cir,1,k%m), (k//m-1)*a + circle_sum_max(cir,1,m))
        else:
            score = max(score,circle_sum_max(cir,1,m))
    else:
        score = max(score,circle_sum_max(cir,1,k))

print(score)










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

struct SuffixArray{
    vector<int> ord2idx, idx2ord, rank;
    int k, N;

    SuffixArray(vector<int>& S){ initialize(S); }
    SuffixArray(string S=""){ initialize(S); }
    
    void initialize(vector<int>& S){
        N = S.size();
        ord2idx.resize(N);
        idx2ord.resize(N);
        rank.resize(N);
        for(int i=0; i<N; i++){
            ord2idx[i] = i;
            rank[i] = S[i];
        }

        vector<int> tmp(N);

        auto cmp = [&](int i, int j) -> bool{
            if(rank[i] != rank[j]) return (rank[i] < rank[j]);
            int ri = (i+k < N ? rank[i+k] : -1);
            int rj = (j+k < N ? rank[j+k] : -1);
            return ri < rj;
        };

        for(k=1; k<N; k*=2){
            sort(ord2idx.begin(), ord2idx.end(), cmp);

            tmp[ord2idx[0]] = 0;
            for(int i=1; i<N; i++){
                tmp[ord2idx[i]] = tmp[ord2idx[i-1]] + cmp(ord2idx[i-1], ord2idx[i]);
            }
            for(int i=0; i<N; i++) rank[i] = tmp[i];
        }
        for(int i=0; i<N; i++) idx2ord[ord2idx[i]] = i;
    }

    void initialize(string& S){
        vector<int> s;
        for(int i=0; i<S.size(); i++) s.push_back((int)S[i]);
        initialize(s);
    }
};

int K, N, L;
string S;
SuffixArray sa;

bool check(int X){
    int i = 0, res = 0;
    while(i < N){
        if(sa.idx2ord[i] <= X){
            i += L;
        }else{
            i += L-1;
        }
        res++;
        if(res > K) return false;
    }
    return (res <= K);
}

int main(){
    cin >> K >> S;
    N = S.size();
    K++;
    L = (N+K-1)/K;
    sa.initialize(S);
    int ok = N-1, ng = -1;
    while(ok-ng>1){
        int mid = (ok+ng)/2;
        (check(mid) ? ok : ng) = mid;
    }
    while(sa.ord2idx[ok]+L > N) ok++;
    string ans = S.substr(sa.ord2idx[ok], L);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2552
import java.util.Scanner;

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

		int i;

		for (i = 1; i <= 10000; i++)
		{
			int x = sc.nextInt();
			if (x > 0) {
				System.out.println("Case " + i + ": " + x);
			} else {
				break;
			}
		}
	}
}

Measured memory_bytes: 41404
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <set>
#include <vector>
#include <queue>
using namespace std;
#define loop(i,n) for(int i=0;i<n;i++)

int t[100002]={};
int a[100002]={};
int pmax[100002]={};
int pmin[100002]={};

int main(){
    
    int n;
    long long res=1;
    
    cin>>n;
    loop(i,n)cin>>t[i+1];
    loop(i,n)cin>>a[i+1];
    /*
    if(a[1]!=t[n]){
        cout<<0<<endl;
        return 0;
    }
    */
    loop(i,n){
        if(t[i]!=t[i+1]){
            pmin[i]=pmax[i]=t[i+1];
        }else{
            pmin[i]=1;
            pmax[i]=t[i+1];
        }
        //cout<<pmin[i]<<"~"<<pmax[i]<<" ";
    }
    //cout<<endl;
    loop(i,n){
        if(a[i+1]!=a[i+2]){
            if(a[i+1]<pmin[i] || pmax[i]<a[i+1]){
                cout<<0<<endl;
                return 0;
            }
            pmin[i]=pmax[i]=a[i+1];
        }else{
            if(a[i+1]<pmin[i]){
                cout<<0<<endl;
                return 0;
            }
            pmax[i]=min(pmax[i],a[i+1]);
        }
        //cout<<pmin[i]<<"~"<<pmax[i]<<" ";
    }
    
    loop(i,n){
        res*=pmax[i]-pmin[i]+1;
        res%=1000000007;
    }
    
    cout<<res<<endl;
    
    return 0;
}


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

int main()
{
  int N;
  cin>>N;
  int* h = new int[N];
  int* ans = new int[N];
  for(int i=0;i<N;i++)
  {
    cin>>h[i];
  }
  ans[N-1] = 0;
  ans[N-2] = abs(h[N-1]-h[N-2]);
  for(int i=N-3;i>=0;i--)
  {
    ans[i] = min(ans[i+1]+abs(h[i+1]-h[i]),ans[i+2]+abs(h[i+2]-h[i]));
  }
  cout<<ans[0];
  return 0;
}


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

public class Main {
	public static void main(String args[]){
		BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));
		try{
			String strS = insBR.readLine();
			int intS = Integer.parseInt(strS);
			int intM = 0;
			int intH = 0;
			if(3600 <= intS){
				intH = intS / 3600;
			}

			if(3600 <= intS){
				intM = intS / 60 % 60;
			}else if(60 <= intS){
				intM = intS / 60;
			}
			if(60 <= intS){
				intS = intS % 60;
			}
			System.out.println(intH + ":" + intM + ":" + intS);
		}catch(IOException e){
			System.out.println("入力が無効です。");
		}catch(NumberFormatException e){
			System.out.println("数値を入力してください。");
		}
	}
}


Measured memory_bytes: 24408
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        mut s_a: Chars,
        mut s_b: Chars,
        mut s_c: Chars,
    }

    println!("{}", solve(&mut s_a, &mut s_b, &mut s_c));
}

fn solve(s_a: &mut Vec<char>, s_b: &mut Vec<char>, s_c: &mut Vec<char>) -> String {
    s_a.reverse();
    s_b.reverse();
    s_c.reverse();

    let mut x = s_a.pop().unwrap();
    loop {
        if x == 'a' && s_a.len() == 0 {
            return String::from("A");
        }
        if x == 'b' && s_b.len() == 0 {
            return String::from("B");
        }
        if x == 'c' && s_c.len() == 0 {
            return String::from("C");
        }
        match x {
            'a' => x = s_a.pop().unwrap(),
            'b' => x = s_b.pop().unwrap(),
            _ => x = s_c.pop().unwrap(),
        }
    }
}


Measured memory_bytes: 2152
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <climits>
#include <numeric>
#include <cstring>
#include <utility>
#include <bitset>
#include <ctime>
#include <cmath>
#include <complex>
#include <iomanip>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef vector<vector<int> > vvint;

typedef long double D;
typedef complex<D> P;
typedef const P &rP;

#define ALL(v) (v).begin(),(v).end()

const D EPS = 1e-9L;


D pi;

D dot(rP a, rP b){
	return real(a) * real(b) + imag(a) * imag(b);
}

D cross(rP a, rP b){
	return real(a) * imag(b) - imag(a) * real(b);
}

D sqtri(rP a, rP b, rP c){
	return cross(b - a, c - a) * 0.5;
}

vector<P> intrccl(rP p1, D r1, rP p2, D r2){
	vector<P> ret;
	D d = abs(p2 - p1);
	if(d < EPS){ return ret; }
	D phi = arg(p2 - p1);
	D ct = (d * d + r1 * r1 - r2 * r2) / (2.0 * d * r1);
	if(abs(ct) > 1.0){ return ret; }
	D theta = acos(ct);
	ret.resize(2);
	ret[0] = p1 + polar(r1, phi - theta);
	ret[1] = p1 + polar(r1, phi + theta);
	return ret;
}

D difangle(D a, D b){
	b = b - a + 4.0 * pi;
	while(b >= 2.0 * pi){ b -= 2.0 * pi; }
	return b;
}

D sqintr(D ra, D rb, D dist){
	P ptd(dist);

	if(ra < rb){ swap(ra, rb); }
	vector<P> intr = intrccl(P(), ra, ptd, rb);
	if(intr.empty()){
		if(dist < ra + rb - EPS){
			return rb * rb * pi;
		}
		return 0.0;
	}

	if(imag(intr[0]) > imag(intr[1])){
		swap(intr[0], intr[1]);
	}


	D da1 = difangle(arg(intr[0]), arg(intr[1]));
	D s1 = ra * ra * 0.5 * da1 - sqtri(P(), intr[0], intr[1]);
	D da2 = difangle(arg(intr[1] - ptd), arg(intr[0] - ptd));
	D s2 = rb * rb * 0.5 * da2 - sqtri(ptd, intr[1], intr[0]);

	return s1 + s2;
}


D w, h, sa, sb, sab;


void solve(){
	bool sw = false;
	if(sa < sb){
		swap(sa, sb);
		sw = true;
	}

	D ra = sqrt(sa / pi), rb = sqrt(sb / pi);

	if(ra * 2.0 > min(w, h)){
		cout << "impossible\n";
		return;
	}

	D left = max(ra - rb - 1e-6L, 0.0L), right = ra + rb + 1e-6L;
	for(int tm = 300; --tm; ){
		D mid = (left + right) * 0.5;
		D sq = sqintr(ra, rb, mid);
		if(sq > sab){
			left = mid;
		}
		else{
			right = mid;
		}
	}

	P pa(ra, ra);
	P u(w - ra - rb, h - ra - rb);
	if(norm(u) > EPS){
		u /= abs(u);
	}
	P pb = pa + u * left;

	if(real(pb) + rb > w || imag(pb) + rb > h){
		cout << "impossible\n";
		return;
	}
	
	if(sw){
		swap(pa, pb);
		swap(ra, rb);
	}
	cout << real(pa) << ' ' << imag(pa) << ' ' << ra << ' ';
	cout << real(pb) << ' ' << imag(pb) << ' ' << rb << endl;
}


int main(){
	pi = acos(-1.0L);
	cout << fixed << setprecision(15);
	cerr << fixed << setprecision(6);
	
	while(cin >> w >> h >> sa >> sb >> sab, w){
		solve();
	}
}

Measured memory_bytes: 1308
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int n,m;
  int num;
  int sum=0;
  int count=0;
  vector<double> v;
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>num;
    sum+=num;
    num*=4;
    num*=m;
    v.push_back(num);
  }
  
  for(int i=0;i<n;i++){
    if(v[i]>=sum)count++;
  }
  if(count>=m)cout<<"Yes";
  else cout<<"No";
}

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

int main()
{
    int n;
    cin>>n;
    vector <pair<int,int>> a(n);  //first:それまでの人数 second:出席番号
    for(int i=0;i<n;i++)
    {
        int num=0;
        cin>>num;
        a[i].first = num;
        a[i].second = i+1;
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n;i++)
    {
        cout<<a[i].second<<" ";
    }
    cout<<endl;
    return 0;
}

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

int main(){
	int n, k;
	cin >> n >> k;
	int cnt=0;
	for(int i=0; i<n; i++){
		int height;
		cin>>height;
		if(height>=k) cnt++;
	}
	cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}


long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

//ここまでライブラリ
//ここから本文

long long int tpimin(vector<int> a) {
	int MIN = 1000000000;
	int number = 0;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
		number = i;
	}
	return number;
}


int main() {
	int  i = 0;
	int a, b, c;
	cin >> a >> b >> c;
	for (int i = 1; i <= b; i++) {
		if ((a * i) % b == c) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}



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

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

Measured memory_bytes: 1208
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    String t=sc.next();
    char[] ss=new char[s.length()];
    char[] tt=new char[t.length()];
    for(int i=0;i<ss.length;i++){
      ss[i]=s.charAt(i);
    }
    for(int i=0;i<tt.length;i++){
      tt[i]=t.charAt(i);
    }
    int count;
    int min=tt.length;
    for(int i=0;i<1+ss.length-tt.length;i++){
      count=0;
      int j=i,k=0;
      while(k<tt.length){
        if(ss[j]!=tt[k]) count++;
        j++;k++;
      }
      if(min>count)min=count;
    }
    System.out.println(min);
  }
}

Measured memory_bytes: 35460
#include<iostream>
using namespace std;
int main(){
  int n,i;
  cin >> n;
  int count=0;
  for(i=1;i<=n;i++){
    int j=i;
    int sum=0;
    
    while(j!=0){
     j=j/10;
     ++sum;
    }
    if(sum%2==1){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

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

#define ll long long
#define int long long
#define MOD 1000000007
#define MAX 100001
#define debugStart cout << "\n[DEBUG START]\n"
#define debugStop cout << "\n[DEBUG STOP]\n"
#define KHATAM cout << std::endl;


auto solve ( int arr[][3], int size ) -> int {

        int DP[size][3];
        memset(DP, 0, sizeof(DP));
        DP[0][0] = arr[0][0];        
        DP[0][1] = arr[0][1];
        DP[0][2] = arr[0][2];
        for ( int i = 1; i < size; ++i ) {
                DP[i][0] = max(DP[i-1][1], DP[i-1][2]) + arr[i][0];
                DP[i][1] = max(DP[i-1][0], DP[i-1][2]) + arr[i][1];;
                DP[i][2] = max(DP[i-1][1], DP[i-1][0]) + arr[i][2];;                
        }        
        return max(DP[size - 1][0], max(DP[size-1][1], DP[size-1][2]));
}


signed
main() {

        ios_base::sync_with_stdio(0);
        cin.tie(0);
        int T = 1; 
        // cin >> T;
        for ( int testcase = 1; testcase <= T; ++testcase ) {
                
                int size;
                std::cin >> size; 
                int arr[size][3];
                for ( int i = 0; i < size; ++i ) {
                        std::cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
                }
                std::cout << solve(arr, size); 
                std::cout << '\n';
        }
        return 0;
}

Measured memory_bytes: 4992
// oh yea mr krabs
// REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
#include<bits/stdc++.h>
using namespace std;

const long double pi = (long double)104348/33215 ;
const int maxn = 1e5+10 ;
const long double mod = 1e9+7 ;


long double rad2deg(long double a){

    return a*180/pi ;

}

long double a[maxn] ;
long double ans ;

int main(){

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

    long double a, b, c ;
    cin >> a >> b >> c ;

    if(c <= a*a*b/2){

        cout << fixed << setprecision(15) << 90-rad2deg(atan(c*2/(a*b*b))) ;

    }else{

        c = a*a*b-c ;
        cout << fixed << setprecision(15) << rad2deg(atan(c*2/(a*a*a))) ;

    }

}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[][][] hu = new int[4][3][10];

        //b?£?f???r?????????v?????\????????????
        while (n != 0) {
            int b = scan.nextInt();
            int f = scan.nextInt();
            int r = scan.nextInt();
            int v = scan.nextInt();
            hu[b - 1][f - 1][r - 1] += v;
            n--;
        }

        //????????¨??????0?????\??????
        for (int num = 0; num < 4; num++) {
            for (int i = 0; i < 3; i++) {
                for (int a = 0; a < 10; a++) {
                    hu[num][i][a] += 0;
                }
            }
        }

        //??¨?????????
        for (int num = 0; num < 4; num++) {
            for (int i = 0; i < 3; i++) {
                for (int a = 0; a < 10; a++) {
                    System.out.print(" " + hu[num][i][a]);
                }
                System.out.println();
            }

            if (num != 4 - 1) {
                for (int i = 0; i < 20; i++) {
                    System.out.print("#");
                }
                System.out.println();
            }
        }
    }
}

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

Measured memory_bytes: 592
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<set>
#include<vector>
using namespace std;

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

//infinity
#define INTINF 2000000000
#define LONGINF 2000000000

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PRIME 55556
int p[PRIME];
int nn[56];

int main(){
	p[0] = p[1] = 1;
	long long count = 0;
	for(int i = 2; i * i <= PRIME; i++){
		if(p[i]) continue;

		for(int j = i+i; j < PRIME; j+=i){
			count++;
			p[j] = 1;
		}
	}

	int n; cin >> n;
	vector<int> pl;
	set<int> pp;
	REP(i, PRIME) if(!p[i]) pp.insert(i);

	REP(i, n){
		for(int x : pp){
			if(x%5==1){
				pl.push_back(x);
				pp.erase(x);
				cout << x;
				break;
			}
		}
		if(i != n-1) cout << " ";
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main(){
  cin.tie(nullptr);ios::sync_with_stdio(false);
  int n,i,ans,now;string s;cin >> n >> s;
  ans = count(s.begin(),s.end(),'.');
  now = ans;
  for(i=0;i<n;i++){
    if(s[i] == '.') now--;
    else now++;
    ans = min(ans,now);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3780
#include <stdio.h>

int main(void)
{
	int n;
	int c;
	
	while (1){
		c = 0;
	
		scanf("%d" , &n);
	
		if (n == 0){
			break;
		}
		
			while (n != 1){
		
				if (n % 2 == 0){
					n = n / 2 ;
					c++;
			}
		
			else if (n % 2 == 1){
				n = 3 * n + 1;
				c++;
			}
		}
	
	printf("%d\n" ,c);
	
	}
	
	return (0);
}

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

using namespace std;
int main()
{
	int a[3], b[3], s = 0;
	for (int i = 0; i < 3; i++) {
		cin >> a[i] >> b[i];
		s += a[i] + b[i];
	}
	if (s == 15)cout << "YES" << endl;
	else { cout << "NO" << endl; }
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int V(int d[10],int c[10][10]);
int main()
{
    int m, n, i, j, temp, sum=0;
    int a[11]={0},c[10][10],d[10];
    scanf("%d%d",&m,&n);
    for(i=0;i<10;i++)
    {
        for(j=0;j<10;j++)
        {
            scanf("%d",&c[i][j]);
        }
    }
    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            scanf("%d",&temp);
            a[1+temp]++;
        }
    }
    for(i=0;i<10;i++) d[i]=c[i][1];
    while(V(d,c));
    for(i=0;i<10;i++)
    {
        sum+=a[i+1]*d[i];
    }printf("%d",sum);
    return 0;
}
int V(int d[10],int c[10][10])
{
    int count =0,i,j,temp;
    for(i=0;i<10;i++)
    {
        for(j=0;j<10;j++)
        {
            if(d[i]>d[j]+c[i][j])
            {
                d[i]=d[j]+c[i][j];
                count++;
            }
        }
    }
    return count;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		atcode();
	}

	public static void atcode() {
		String[] info = new Scanner(System.in).nextLine().split(" ");
		int max = Integer.parseInt(info[0]);
		int sMin = Integer.parseInt(info[1]);
		int sMax = Integer.parseInt(info[2]);
		Long sum=0l;
		for (Integer i = 1; i <= max; i++) {
			int s=0;
			for(int temp =i;temp>0;temp/=10){
				s+=temp%10;
			}
			if (s >= sMin && s <= sMax)
				sum+=i.longValue();
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
 
using namespace std;
typedef long long ll;

ll ans,mx,sum;
int main(){
	ll n;
	cin>>n;
	ll a[n];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	for(int i=0; i<=n-2; i++){
		if(i > 0){
			if(a[i] > a[i-1] && a[i] < a[i+1]) ans++;
			else if(a[i] < a[i-1] && a[i] > a[i+1]) ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import itertools
N, M = map(int, input().split())
A = []
for i in range(M):
    a, b = map(int, input().split())
    A += [[a, b]]
L = list(range(2, N+1))
count = 0
for v in itertools.permutations(L):
    v = list(v)
    v.insert(0, 1)
    BOOL = 'T'
    i = 0
    while BOOL == 'T' and i < N-1:
        if sorted(v[i:i+2]) in A:
            i += 1
        else:
            BOOL = 'F'
    if BOOL == 'T':
        count += 1
print(count)

Measured memory_bytes: 3064
N, M= map(int, input().split())
A = list(map(int, input().split()))

A.sort()
l = -1
r = A[-1] + 1


while r - l > 1:
    m = (r + l) // 2
    mc = 0
    a = 0
    for i in range(N):
        s = A[i]
        while m < s:
            s //= 2
            mc += 1
        a += s
    if mc <= M:
        r = m
        ans = a - (M - mc) * ((m // 2) + m % 2)
    else:
        l = m 
            
print(ans)

Measured memory_bytes: 14100
#include<iostream>
#include <iomanip>

using namespace std;

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

	long long int d, r;
	double f;

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

	cout << d << " " << r << " " << fixed<<setprecision(15)<< f << endl;
	return 0;
}

Measured memory_bytes: 1248
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if(b - a == c - b) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <climits>

using namespace std;

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

const ll MOD = 1000000007;
const ll INF = LLONG_MAX;
const ll MAX_N = 100000;

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

ll N, a[MAX_N * 3], lsum = 0, rsum = 0, l[MAX_N+1], r[MAX_N+1], def;
priority_queue<ll, vector<ll>, greater<ll> > lmax;
priority_queue<ll> rmin;

int main() {
	
	cin >> N;
	for (int i = 0; i < N * 3; i++) {
		cin >> a[i];
	}
	
	for (int i = 0; i < N; i++) {
			lmax.push(a[i]);
			lsum += a[i];
			rmin.push(a[N*3-i-1]);
			rsum += a[N*3-i-1];
	}
	l[0] = lsum; r[N] = rsum;
	for (int i = N; i < N*2; i++) {
		if (lmax.top() < a[i]) {
			lsum -= lmax.top();
			lmax.pop();
			lmax.push(a[i]);
			lsum += a[i];
		}
		if (rmin.top() > a[N*3-i-1]) {
			rsum -= rmin.top();
			rmin.pop();
			rmin.push(a[N*3-i-1]);
			rsum += a[N*3-i-1];
		}
		int k = i - N + 1;
		l[k] = lsum;
		r[N - k] = rsum;
	}
	def = l[0] - r[0];
	for (int k = 1; k <= N; k++) {
		def = max(def, l[k] - r[k]);
	}
	cout << def << endl;
}

Measured memory_bytes: 5996
/***********************************************
 *                   _ooOoo_                   *
 *                  o8888888o                  *
 *                  88" . "88                  *
 *                  (| -_- |)                  *
 *                  O\  =  /O                  *
 *               ____/`---'\____               *
 *             .'  \\|     |//  `.             *
 *            /  \\|||  :  |||//  \            *
 *           /  _||||| -:- |||||-  \           *
 *           |   | \\\  -   * |    |           *
 *           | \_|  ''\---/''  |   |           *
 *           \  .-\__  `-`  ___/-. /           *
 *         ___`. .'  /--.--\  `. . __          *
 *      ."" '<  `.___\_<|>_/___.'  >'"".       *
 *     | | :  `- \`.;`\ _ /`;.`/ - ` : | |     *
 *     \  \ `-.   \_ __\ /__ _/   .-` /  /     *
 *======`-.____`-.___\_____/___.-`____.-'======*
 *                   `=---='                   *
 *^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

             佛祖保佑       永无BUG

   本程序已经经过开光处理，绝无可能再产生bug
 **********************************************/
#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define ll long long
#define INF 0x3f3f3f3f
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
using namespace std;

int num[11];

int main(void)
{
    #ifdef test
    freopen("in.txt","r",stdin);
    //freopen("in.txt","w",stdout);
    clock_t start=clock();
    #endif //test

    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    num[a]++,num[b]++,num[c]++;
    if(num[a]==2||num[b]==2||num[c]==2)printf("Yes\n");
    else printf("No\n");

    #ifdef test
    clockid_t end=clock();
    double endtime=(double)(end-start)/CLOCKS_PER_SEC;
    printf("\n\n\n\n\n");
    cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位
    cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位
    #endif //test
    return 0;
}


// ━━━━━━神兽出没━━━━━━
//      ┏┓       ┏┓
//     ┏┛┻━━━━━━━┛┻┓
//     ┃           ┃
//     ┃     ━     ┃
//     ????━????   ┃
//     ┃           ┃
//     ┃    ┻      ┃
//     ┃           ┃
//     ┗━┓       ┏━┛
//       ┃       ┃
//       ┃       ┃
//       ┃       ┗━━━┓
//       ┃           ┣┓
//       ┃           ┏┛
//       ┗┓┓┏━━━━━┳┓┏┛
//        ┃┫┫     ┃┫┫
//        ┗┻┛     ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
    int i,j;
    char mozi[21];
    scanf("%s",mozi);
    for(i=0;mozi[i]!=0;i++);
    for(j=i-1;j>=0;j--)printf("%c",mozi[j]);
    printf("\n");
    return 0;
}

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

ll pow5(int m) {
  return (ll)m*m*m*m*m;
}

int main() {
  int x; cin >> x;
  int a = 0, b = 0;

  while (true) {
    a++;
    ll a5 = pow5(a);
    b = a;
    ll b5 = a5;
    while (a5-b5 < x) {
      b--;
      b5 = pow5(b);
    }
    if (a5-b5 == x) break;
  }

  cout << a << " " << b << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <numeric>
using namespace std;
#define inf 1000000007

int main(void){
    int n;
    cin >> n;
    int a[n];
    int count[9];
    int ans = 0;
    int MIN = 0, MAX = 0;
    for(int i = 0; i < 9; i++)
        count[i] = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] >= 3200)
            a[i] = 3200;
        count[a[i]/400]++;
    }
    for(int i = 0; i < 8; i++){
        if(count[i] >= 1)
            ans++;
    }
    MIN = ans; MAX = ans;
    if(count[8] > 0){
        MAX = ans+count[8];
    }
    if(ans == 0){
        MIN = 1; MAX = count[8];
    }
    cout << MIN << " " << MAX << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

public class MainCls
{
	public static void Main(string[] args)
	{
		string m = Console.ReadLine();
		int min = 999;
		for(int i = 0; i < m.Length - 2; i++) {
			min = Math.Min(min, Math.Abs(753-int.Parse(m.Substring(i,3))));
		}
		Console.WriteLine(min);
	}
}

Measured memory_bytes: 13140