akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
  long n,right = 0,left = 0;
  cin >> n;
  long a[n];
  for(long i = 0;i < n;i++){
    cin >> a[i];
  }
  left = a[0];
  for(long i = 1;i < n;i++){
    right += a[i];
  }
  long kekka = 100000000000000000;
  for(long i = 1;i < n;i++){
    long cur = abs(left - right);
    kekka = min(kekka,cur);
    if(i < n-1){
      left += a[i];
      right -= a[i];
    }
  }
  cout << kekka << endl;
}

Measured memory_bytes: 1792
x,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*x
#dp[1]=abs(a[1]-a[0])
for i in range(1,x):
    p=10000000001
    for j in range(max(0,i-k),i):
        p=min(p,dp[j]+abs(a[i]-a[j]))
        
    dp[i]=p
print(dp[x-1])    

Measured memory_bytes: 52448
#include <stdio.h>
 
int number[10];
 
int check(int num) {
	int i;
	
	while(num > 0) {
		if (number[num%10]) {
			return 0;
		}
		num /= 10;
	}
	
	return 1;
}
 
int main(void) {
	int n,k,d,i,ans;
 
	scanf("%d %d",&n,&k);
	
	for (i = 0;i < k;i++) {
		scanf("%d",&d);
		number[d] = 1;
	}
	
	ans = n;
	while(!check(ans)) {
		ans++;
	}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		
		char Af = A.charAt(0);
		char Al = A.charAt(A.length()-1);
		char Bf = B.charAt(0);
		char Bl = B.charAt(B.length()-1);
		char Cf = C.charAt(0);
		char Cl = C.charAt(C.length()-1);
		
		if(Al==Bf && Bl==Cf){
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 21972
#!/usr/bin/env python3
from functools import reduce

mod = 10**9 + 7


def cmb(n, r, m):
    def mul(a, b):
        return a * b % m

    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over * pow(under, m - 2, m)


n, a, b = map(int, input().split())
print((pow(2, n, mod) - 1 - cmb(n, a, mod) - cmb(n, b, mod)) % mod)


Measured memory_bytes: 74000
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }

//Topological_Sort
const int max_v = 200005;
vector<int> g[max_v], rev[max_v], tsort;
bool used[max_v];
int v, m, dp[max_v], ans;
void ts_dfs(int u){
    if(used[u]) return;
    used[u] = true;
    for(int j = 0; j < g[u].size(); j++) ts_dfs(g[u][j]);
    tsort.push_back(u);
}
void t_sort(){
    for(int i = 0; i < v; i++) ts_dfs(i);
    reverse(tsort.begin(), tsort.end());
}

int main(){
	cin >> v >> m;
	rep(i,1,m){
		int xx, yy;
		cin >> xx >> yy;
		xx--;  yy--;
		g[xx].pb(yy);
		rev[yy].pb(xx);
	}
	t_sort();
	ans = 0;
	rep(i,1,v-1){
		for(auto from: rev[tsort[i]]){
			chmax(dp[tsort[i]], dp[from]+1);
		}
		chmax(ans, dp[tsort[i]]);
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 17532
n = gets.to_i
arr =[]
n.times do
  arr << gets.chomp
end

ans_arr = []

13.times do |i|
  ans_arr << "S"+" "+(i+1).to_s
  ans_arr << "H"+" "+(i+1).to_s
  ans_arr << "C"+" "+(i+1).to_s
  ans_arr << "D"+" "+(i+1).to_s
end

arr.each do |v|
  ans_arr.delete(v)
end

puts ans_arr.select{|v| v.include?("S")}
puts ans_arr.select{|v| v.include?("H")}
puts ans_arr.select{|v| v.include?("C")}
puts ans_arr.select{|v| v.include?("D")}



Measured memory_bytes: 6876
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ll n;
  cin >> n;
  vector<ll> a(n, 0), ans(n, 0);
  rep(i, n) cin >> a[i];
  ll x = 0;
  rep(i, n) x ^= a[i];
  rep(i, n) {
    ll y = a[i];
    rep(j, 34) {
      if(x & (1LL<<j)) y ^= (x & (1LL<<j));
    }
    if(i) cout << " ";
    cout << y;
  }
  cout << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

int main() {
	long long int ans=0,n,x,t,a,b;
	scanf("%lld %lld %lld",&a,&b,&n);
	long long p = min(b-1,n);
	
	printf("%lld",(a*p)/b-a*(p/b));
	
}

Measured memory_bytes: 3828
#include <bits/stdc++.h> 
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	int mx_operation=a.size();
	int op=0;
	while(a!=b&&op<mx_operation)
	{
		int x;
		a=a[a.size()-1]+a;
		a.erase(a.size()-1,1);
		op++;
	}
	if(a==b)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}

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

using namespace std;
map<int,int> mp,ind;
typedef long long ll;
int imos[400010] = {};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i,n,d,a;
    cin >> n >> d >> a;
    for(i=0;i<n;i++){
        int x,h; cin >> x >> h;
        mp[x] += h; mp[x + 2*d + 1] += 0;
    }
    int now = 0;
    for(auto x:mp){
        ind[x.first] = now; now++;
    }
    ll ans = 0; int dm = 0;
    for(auto x:mp){
        dm += imos[ind[x.first]];
        if(x.second<=dm) continue;
        ll t = (x.second - dm + a - 1)/a;
        ans += t; dm += a*t;
        imos[ind[x.first + 2*d + 1]] -= a*t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 39296
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())


void solve() {
  int n, d;
  cin >> n >> d;
  cout << (n-1)/(d*2+1) + 1 << endl;
}

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


Measured memory_bytes: 256
// c++ cpp.cpp -o cpp.exe -std=c++14

#include <iostream>
#include <string>
#include <map>
using namespace std;

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

int main()
{
    map<string, int> dic;
    string w, t;

    cin >> w;
    while (cin >> t, t != "END_OF_TEXT")
    {
        dic[t]++;
    }

    int ans = 0;
    for (auto i : dic)
    {
        string s = i.first;
        rep(i, s.size())
        {
            s[i] += 'A' <= s[i] && s[i] <= 'Z' ? 'a' - 'A' : 0;
        }
        ans += w == s ? i.second : 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3180
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <time.h>
int main(){
    int i,length,ans=0;
    char s[101]={};
    scanf("%s",s);
    length=strlen(s);
    for(i=0; i<length/2; i++){
        if(s[i]!=s[length-i-1])ans++;
    }
    printf("%d",ans);
    return 0;
}

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

vector<string> v;
int main(){
	string s1;
    int n,m;
    cin>>n>>m;
    for(int i = 0; i < n; ++i){
    	cin>>s1;
    	v.push_back(s1);
    }
    
    sort(v.begin(), v.end());
    for(int i = 0; i < n; ++i){
    	cout<<v[i];
    }


}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def add(i):
        while i < len(bit):
            bit[i] += 1
            i += i&-i
    def sum(i):
        res = 0
        while i > 0:
            res += bit[i]
            i -= i&-i
        return res
    n = I()
    a = LI()
    f = list(set(a))
    f.sort()
    c = [bisect.bisect_left(f,i) for i in a]
    k = ((n*(n+1)) >> 1) >> 1
    l = 0
    r = len(f)
    while r-l > 1:
        m = (l+r) >> 1
        b = [2*(i < m)-1 for i in c]
        s = [0]
        for i in b:
            s.append(s[-1]+i)
        b = list(set([i for i in s]))
        b.sort()
        s = [bisect.bisect_left(b,i)+1 for i in s]
        bit = [0]*(max(s)+1)
        res = 0
        for i in s:
            res += sum(i)
            add(i+1)
        if res <= k:
            l = m
        else:
            r = m
    print(f[l])
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 120228
import { count } from 'console';

process.stdin.resume();
process.stdin.setEncoding('utf8');

// 標準入力取込
let gInput = '';
process.stdin.on('data', (chunk) => (gInput += chunk));
process.stdin.on('end', () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {
  const s = Number(inputs[0].split(' ')[0]);
  const w = Number(inputs[0].split(' ')[1]);

  if (s <= w) {
    console.log('unsafe');
  } else {
    console.log('safe');
  }
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const ll INF=1e9;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,n){cout<<arr[i][j]<<" ";}cout<<endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    string s;
    cin>>s;
    if(s=="Sunny"){
        cout<<"Cloudy"<<endl;

    }else if(s=="Cloudy"){
        cout<<"Rainy"<<endl;


    }else if(s=="Rainy"){
        cout<<"Sunny"<<endl;

    }
    return  0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  string S; cin>>S;
  int N=S.size();
  vi A(N+1),C(N+1);
  int sum=1;
  rep(i,0,N){
    if(S[i]=='A') A[i+1]=A[i]+sum;
    else if(S[i]=='?'){
      A[i+1]=A[i]*3+sum;
      sum*=3;
      sum%=MOD;
    }
    else A[i+1]=A[i];
    A[i+1]%=MOD;
  }
  sum=1;
  REP(i,1,N){
    int j=N-i;
    if(S[j]=='C') C[j]=C[j+1]+sum;
    else if(S[j]=='?'){
      C[j]=C[j+1]*3+sum;
      sum*=3;
      sum%=MOD;
    }
    else C[j]=C[j+1];
    C[j]%=MOD;
  }
  int ans=0;
  rep(i,0,N){
    if(S[i]=='B'||S[i]=='?'){
      ans+=A[i]*C[i+1]%MOD;
      ans%=MOD;
    }
  }
  cout<<ans<<endl;
  }



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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  vector<tuple<ll, ll, ll>> t(n);
  REP(i, n) {
    ll a, b;
    cin >> a >> b;
    ll sum = a + b;
    t[i] = make_tuple(sum, a, b);
  }
  sort(ALL(t));

  ll sumT = 0, sumA = 0;
  REPR(i, n - 1) {
    ll sum, a, b;
    tie(sum, a, b) = t[i];
    if (n % 2 == 0) {
      if (i % 2 != 0) {
        sumT += a;
      } else {
        sumA += b;
      }
    } else {
      if (i % 2 == 0) {
        sumT += a;
      } else {
        sumA += b;
      }
    }
  }

  cout << sumT - sumA << endl;
  return 0;
}

Measured memory_bytes: 2560
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String line = sc.nextLine();
    int lineLength = line.length();
    System.out.println(line.substring(0, 1) + (lineLength - 2) + line.substring(lineLength - 1, lineLength));
    
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <utility>
#include <algorithm>
#include <math.h>

using namespace std;

#define ll long long

int main(){
    ll N, K, ans = 0;
    cin >> N >> K;
    ll h[N];
    for(ll i = 0; i < N; i++){
        cin >> h[i];
        if(h[i] >= K)ans++;
    }
    cout << ans << endl; 
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>

using namespace std;

int sai[6]={1,2,3,4,5,6};

int fun(char c)
{
	int fsai[6];
	if(c=='N')
	{
		fsai[0]=sai[1];
		fsai[1]=sai[5];
		fsai[2]=sai[2];
		fsai[3]=sai[3];
		fsai[4]=sai[0];
		fsai[5]=sai[4];
	}
	if(c=='E')
	{
		fsai[0]=sai[3];
		fsai[1]=sai[1];
		fsai[2]=sai[0];
		fsai[3]=sai[5];
		fsai[4]=sai[4];
		fsai[5]=sai[2];
	}
	if(c=='W')
	{
		fsai[0]=sai[2];
		fsai[1]=sai[1];
		fsai[2]=sai[5];
		fsai[3]=sai[0];
		fsai[4]=sai[4];
		fsai[5]=sai[3];
	}
	if(c=='S')
	{
		fsai[0]=sai[4];
		fsai[1]=sai[0];
		fsai[2]=sai[2];
		fsai[3]=sai[3];
		fsai[4]=sai[5];
		fsai[5]=sai[1];
	}
	if(c=='R')
	{
		fsai[0]=sai[0];
		fsai[1]=sai[2];
		fsai[2]=sai[4];
		fsai[3]=sai[1];
		fsai[4]=sai[3];
		fsai[5]=sai[5];
	}
	if(c=='L')
	{
		fsai[0]=sai[0];
		fsai[1]=sai[3];
		fsai[2]=sai[1];
		fsai[3]=sai[4];
		fsai[4]=sai[2];
		fsai[5]=sai[5];
	}
	for(int i=0;i<6;i++)
	{
		sai[i]=fsai[i];
	}
	return sai[0];
}

int main()
{
	while(true)
	{
		for(int i=0;i<6;i++)
		{
			sai[i]=i+1;
		}
		int n;
		int answer=1;
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			char c[10];
			scanf("%s",c);
			answer+=fun(c[0]);
		}
		printf("%d\n",answer);
	}
	return 0;
}

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

int main()
{
	int N, T, A;
	cin >> N >> T >> A;
	vector<int> H( N );
	for( int i = 0; i < N; i++ ) {
		cin >> H[i];
	}

	T *= 1000;
	A *= 1000;
	int mi = INT32_MAX / 2;
	int ans;
	for( int i = 0; i < N; i++ ) {
		int t = T - H[i] * 6;
		if( abs( A - t ) < mi ) {
			mi = abs( A - t );
			ans = i + 1;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3640
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		long max = Long.MIN_VALUE;
		int A[] = new int[N];
		int C[] = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt() - 1;
		}
		for (int i = 0; i < N; i++) {
			C[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			int count = 0;
			long cost = 0;
			int now = A[i];
			Set<Integer> set = new HashSet<Integer> ();
			for (; count < N && count < K; count++) {
				if (set.contains(now)) {
					break;
				}
				set.add(now);
				cost += C[now];
				now = A[now];
				if (cost > max) {
					max = cost;
				}
			}
			if (count <K) {
				int roop = count ;
				if (cost>0) {
					if (K%roop!=0) {
						cost = cost *(K/roop);
						if (cost > max) {
							max = cost;
						}
						for (int j=0;j<K%roop;j++) {
							cost += C[now];
							now = A[now];
							if (cost > max) {
								max = cost;
							}
						}
					} else {
						cost = cost *(K/roop-1);
						if (cost > max) {
							max = cost;
						}
						for (int j=0;j<roop;j++) {
							cost += C[now];
							now = A[now];
							if (cost > max) {
								max = cost;
							}
						}
					}

				}
			}
		}
		System.out.println(max);
	}
}

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

string s;

int main() {
  cin >> s;
  bool res = 0;
  for (int i = 0; i <= 7; ++i) {
    string t;
    for (int j = 0; j < i; ++j) t += s[j];
    for (int j = i; j < 7; ++j) t += s[s.size() - 7 + j];
    if (t == "keyence") res = 1;
  }
  if (res)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 3600
import sys

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return

    if self.parents[x] > self.parents[y]:
      x, y = y, x

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def size(self, x):
    return -self.parents[self.find(x)]

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, K = map(int, input().split())

Ps = [0]+list(map(int, input().split()))
Cs = [0]+list(map(int, input().split()))

uf = UnionFind(N+1)
dic = {}

rlt = -sys.maxsize
for i in range(1,N+1):
  uf.union(i,Ps[i])
  
for i in range(1,N+1):
  j = uf.find(i) 
  if j in dic:
    dic[j] += Cs[Ps[i]]
  else:
    dic[j] = Cs[Ps[i]]
    
rlt = -sys.maxsize

for i in range(1,N+1):
  k = uf.find(i)
  cnt = K//uf.size(k)
  if cnt == 0:
    tmp2 = -sys.maxsize
    tmp3 = 0
    j = i
    for _ in range(1, K+1):
      j = Ps[j]
      tmp3 += Cs[j]
      tmp2 = max(tmp2, tmp3) 
    tmp = tmp2
  
  elif dic[k] <= 0:
    tmp2 = -sys.maxsize
    tmp3 = 0
    j = i
    for _ in range(1, uf.size(k)+1):
      j = Ps[j]
      tmp3 += Cs[j]
      tmp2 = max(tmp2, tmp3)
    tmp = tmp2
    
  else:
    md = K % uf.size(k)
    tmp = 0
    tmp2 = -sys.maxsize
    tmp3 = 0
    j = i
    for l in range(1, md+uf.size(k)+1):
      j = Ps[j]
      if l <= md:
        tmp += Cs[j]
      else:
        tmp3 += Cs[j]
        tmp2 = max(tmp2, tmp3)

    tmp += tmp2 + dic[k]*(cnt-1)
  rlt = max(rlt, tmp)

print(rlt)

Measured memory_bytes: 76080
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func get_int(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

type w struct {
	weight, deadline int
}
type byDeadline []w

func (ws byDeadline) Len() int {
	return len(ws)
}
func (ws byDeadline) Swap(i, j int) {
	ws[i], ws[j] = ws[j], ws[i]
}
func (ws byDeadline) Less(i, j int) bool {
	return ws[i].deadline < ws[j].deadline
}

func main() {
	sc := wordScanner()
	var n = get_int(sc)
	ws := make(byDeadline, n)
	for i := range ws {
		ws[i].weight = get_int(sc)
		ws[i].deadline = get_int(sc)
	}
	sort.Sort(ws)
	sum := 0
	ans := true
	for _, w := range ws {
		sum += w.weight
		if sum > w.deadline {
			ans = false
		}
	}
	if ans {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 6400
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int A=scan.nextInt();
		int B=scan.nextInt();
		int C=scan.nextInt();
		int D=scan.nextInt();
		int l=0,r=0;
		l=A+B;
		r=C+D;
		if(l<r){
			System.out.println("Right");
		}
		else if(l>r){
			System.out.println("Left");
		}
		else if(l==r){
			System.out.println("Balanced");
		}
	}
}

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

int main(){
    int a,b,c,h,t;
    h=0;
    t=0;
    while(scanf("%d,%d,%d",&a,&b,&c) != EOF){
        if(a == b) h++;
        else if(a*a + b*b == c*c) t++;
    }
    cout << t << endl << h << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> a(3);
  REP(i, 3) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a[0] + a[1] << endl;
  return 0;
}

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

using namespace std;
const int MAXN = 200010;
int _w;

int n, a[MAXN];

int b[MAXN], c[MAXN];
bool check( int mid ) {
	for( int i = 1; i <= n; ++i ) {
		b[i] = a[i] >= mid;
		c[i] = 0;
	}
	for( int i = 1; i <= n-1; ++i )
		if( b[i] == b[i+1] )
			c[i] = c[i+1] = 1;
	bool all0 = true;
	for( int i = 1; i <= n; ++i )
		if( c[i] ) all0 = false;
	if( all0 ) {
		return b[1];
	} else {
		int m = (n+1)>>1;
		for( int i = 0; ; ++i )
			if( c[m-i] ) return b[m-i];
			else if( c[m+i] ) return b[m+i];
		return -1;
	}
}

int main() {
	_w = scanf( "%d", &n );
	n = (n<<1)-1;
	for( int i = 1; i <= n; ++i )
		_w = scanf( "%d", a+i );
	int low = 1, high = 1000000000;
	while( low < high ) {
		int mid = (low + high + 1)>>1;
		if( check(mid) ) low = mid;
		else high = mid-1;
	}
	printf( "%d\n", low );
	return 0;
}


Measured memory_bytes: 2560
import sys
sys.setrecursionlimit(100000000)


def main():
    solve()


def solve():
    for data in get_dataset():
        print search(data)


def search(data):
    count = 0
    H = len(data)
    W = len(data[0])
    for i in xrange(H):
        for j in xrange(W):
            if data[i][j] == '.':
                continue
            _search(i, j, H, W, data[i][j], data)
            count += 1
    return count


def _search(i, j, H, W, cell, data):
    data[i][j] = '.'
    for a in xrange(i-1, i+2):
        if not -1 < a < H:
            continue
        for b in xrange(j-1, j+2):
            if not -1 < b < W:
                continue

            if a != i and b != j:
                continue

            if data[a][b] == '.':
                continue

            if cell == data[a][b]:
                _search(a, b, H, W, cell, data)
    return


def get_dataset():
    dataset = []
    while True:
        line = raw_input().rstrip().split()
        H = int(line[0])
        if H == 0:
            break

        data = []
        for i in xrange(H):
            data.append(list(raw_input().rstrip()))
        dataset.append(data)
    return dataset


if __name__ == '__main__':
    main()

Measured memory_bytes: 15696
#include <stdio.h>
#include <string.h>
#define N (100010)
char s[N];
int main(){
    scanf("%s", s);
    int n = strlen(s);
    int ans = 0;
    for (int i = 0, j = n-1; i < j;){
        //printf("%d %d\n", i, j);
        if (s[i] != 'x' && s[j] != 'x'){
            if (s[i] != s[j]){
                printf("-1\n");
                return 0;
            }
            else {
                i++;
                j--;
            }
        }
        else if (s[i] == 'x' && s[j] != 'x'){
            i++;
            ans++;
        }
        else if (s[j] == 'x' && s[i] != 'x'){
            j--;
            ans++;
        }
        else {
            i++;
            j--;
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
const int INF = 1e9;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
    int N,a[100000];
    cin >> N;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        ans = __gcd(ans, a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main (void) {
    int A, B;
    int C, D;
    int E;
    int F;

    cin >> A >> B >> C >> D >> E >> F;

    int ans_sw = A * 100;
    int ans_s = 0;
    double ma = 0;
    for (int a = 0; a <= F / (A * 100); a++) {
        for (int b = 0; b <= F / (B * 100); b++) {
            for (int c = 0; c <= F / C; c++) {
                for (int d = 0; d <= F / D; d++) {
                    if (a == 0 && b == 0) {
                        continue;
                    }
                    int w = 100 * A * a + 100 * B * b;
                    int s = C * c + D * d;
                    int sw = s + w;
                    if (s > w / 100 * E) {
                        continue;
                    } else if (sw > F) {
                        continue;
                    } else {
                        double p = (double)100 * s / sw;
                        if (p > ma) {
                            ma = p;
                            ans_sw = sw;
                            ans_s = s;
                        }
                    }
                }
            }
        }
    }

    cout << ans_sw << " " << ans_s << endl;

    return 0;
}


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

using namespace std;

#ifdef ACMTUYO
struct RTC{~RTC(){cerr << "Time: " << clock() * 1.0 / CLOCKS_PER_SEC <<" seconds\n";}} runtimecount;
#define DBG(X) cerr << #X << " = " << X << '\n';
#else
struct RTC{};
#define DBG(X)
#endif

#define fast_io() ios_base::sync_with_stdio(false)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(c) (c).begin(),(c).end()
#define forn(i, n) for (int i = 0; i < (n); i++)
typedef long long int ll;
int main() {
  ll X, K, D;
  scanf("%lld %lld %lld", &X, &K, &D);
  ll s = min(abs(X) / D, K);
  K -= s;
  if (K & 1LL) 
    s++;
  if (X < 0) {
    X += s * D;
  } else {
    X -= s * D;
  }
  printf("%lld\n", abs(X));
  return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
	string s;cin>>s;multiset<char>m;for(char c:s)m.insert(c);
	for(char c:m){
		if(m.count(c)&1){
			cout<<"No"; return 0;
		}
	}
	cout<<"Yes";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 300005

// it's swapnil07 ;)


signed main(){
    fast
    #ifdef SWAPNIL07
        freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
        freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
    #endif
    priority_queue<double, vector<double>, greater<double> > pq;
    int n; cin>>n;
    For(i, 0, n){
        double a; cin>>a;
        pq.push(a);
    }

    while(pq.size() > 1){
        double x = pq.top();
        pq.pop();
        double y = pq.top();
        pq.pop();
        double z = (x+y)/2.0;
        pq.push(z);
    }

    double ans = pq.top();
    printf("%.9f\n", 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>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;

long long power(long long x, long long y, long long p)
{
long long res = 1;


x = x % p;


while (y > 0)
{
if (y & 1)
res = (res*x) % p;


y = y>>1;
x = (x*x) % p;
}
return res;
}

void solve()
{
   ll n,p;
   cin>>n>>p;
   string s;
   cin>>s;
   mll m;
   ll i,j;
   ll cur=0;
   ll res=0;
   if(p==2)
   {

       for(i=0;i<n;i++)
       {
           ll no = s[i]-'0';
           if(no%2==0)
           {
               res+=(i+1);
           }
       }
       cout<<res<<"\n";
      return;
   }
   if(p==5)
   {
       for(i=0;i<n;i++)
       {
           ll no = s[i]-'0';
           if(no%5==0)
           {
               res+=(i+1);
           }
       }
       cout<<res<<"\n";
       return;
   }
   m[0]++;
   for(i=n-1;i>=0;i--)
   {
       ll no = s[i]-'0';
       ll no2 = no*power(10ll,n-1-i,p); 
       no2%=p;
       cur+=no2;
       cur%=p;
       res+=m[cur];
       m[cur]++;
   }
   cout<<res<<"\n";


}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 4220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	bool ng = A[0] != 0;
	for (int i = 1; i < N; i++) {
		if (A[i] > A[i - 1] + 1) {
			ng = true;
			break;
		}
	}
	if (ng) {
		puts("-1");
		return 0;
	}
	ll res = 0;
	for (int i = 1; i < N; i++) {
		if (A[i] == A[i - 1] + 1) {
			++res;
		}
		else {
			res += A[i];
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1024
a = [True for i in range(1000000)]
i = 3
while i * i < 1000000:
    for j in range(3 * i, 1000000, 2 * i): a[j] = False
    i += 2
 
while True:
    try:
        n = int(input())
    except:
        break
 
    count = int(n >= 2) + sum(a[i] for i in range(3, n + 1, 2))
    print(count)

Measured memory_bytes: 14524
while True:
    n = int(input())
    if n==0:
        exit()
    cnt = 0
    i = 2
    while i*(i+1) <= n*2:
        a =int(n/i-(i-1)/2) 
        if a*i + (i-1)*i/2 == n:
            cnt += 1
        i += 1
    print(cnt)

Measured memory_bytes: 6740
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define test int t; cin >> t; while (t--)
#define deb(x) cerr << "[" << #x  << " : "<< x << "]\n";
#define debv(v) { cerr << #v << " : "; for (auto x : v) cerr << x << ' '; cerr << "\n"; }
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(),x.end()
 
signed main () {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	double d, t, s;
	cin >> d >> t >> s;
	
	if (1.0 * (double)(d / s) <= t) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	
	return 0;
}


Measured memory_bytes: 3728
//#define		FILE_INPUT_DEFINE
#ifdef		FILE_INPUT_DEFINE
#include	<fstream>
#endif		// FILE_INPUT_DEFINE

#include	<iostream>
#include	<cstdio>

using namespace std;

#define		NIL			(-1)
#define		MAX			25

struct BinaryTree
{
	int		parent;
	int		left;
	int		right;

	BinaryTree()
	{
		parent = left = right = NIL;
	}
};

BinaryTree		tree[MAX];

enum class WalkType
{
	ePreorder,
	eInorder,
	ePostorder
};


void	Walk(int id, const WalkType &wt)
{
	if (WalkType::ePreorder == wt)
		cout << " " << id;

	if (NIL != tree[id].left)
		Walk(tree[id].left, wt);

	if (WalkType::eInorder == wt)
		cout << " " << id;

	if (NIL != tree[id].right)
		Walk(tree[id].right, wt);

	if (WalkType::ePostorder == wt)
		cout << " " << id;
}


int main()
{
#ifdef		FILE_INPUT_DEFINE
	// input from txt
	std::ifstream in(R"(C:\Temp\input.txt)");
	std::cin.rdbuf(in.rdbuf());
#endif		// FILE_INPUT_DEFINE

	int		n;
	cin >> n;

	int		id, left, right;
	
	for (int i = 0; i < n; ++i)
	{
		cin >> id >> left >> right;
		tree[id].left = left;
		tree[id].right = right;

		if (NIL != left)	tree[left].parent = id;
		if (NIL != right)	tree[right].parent = id;
	}

	int		root;
	for (int i = 0; i < n; ++i)
	{
		if (NIL == tree[i].parent)
		{
			root = i;
			break;
		}
	}

	cout << "Preorder\n";
	Walk(root, WalkType::ePreorder);

	cout << "\nInorder\n";
	Walk(root, WalkType::eInorder);

	cout << "\nPostorder\n";
	Walk(root, WalkType::ePostorder);

	cout << "\n";

	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef pair<ll,ll> pl;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(v) (v).begin(),(v).end()
#define max(a,b) (a>b ? a : b)
#define min(a,b) (a<b ? a : b)
 
const int MOD = 998244353;
const int N = 1000002;
const double PI =4*atan(1);
const double eps = 1e-7;
const long long oo = 1e18;
  

ll n,a,b;



int main(){
    ios::sync_with_stdio(0);
    //freopen("easy.txt","r",stdin);
    cin >> n >> a >> b;
    ll x=max(a,b);
    ll y=min(a,b);
    if((x-y)%2==0){
        cout << (x-y)/2;
    }else{
        ll z=(n-x);
        ll ans=2e18;
        ll w= y+z;
        if((n-w)%2==0){
            ans=min(ans,z+(n-w)/2);
        }else{
            ans=min(ans,z+(n-w)/2+1);
        }
        z=y-1;
        w=x-z;
        if((w-1)%2==0){
            ans=min(ans,z+(w-1)/2);
        }else{
            ans=min(ans,z+(w-1)/2+1);
        }
        cout << ans << endl;
    }

    return 0;
}

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

template <class T>
using V = vector<T>;

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

int main(){
    int N;
    cin >> N;
    V<int> A(N);
    rep(i, N) cin >> A.at(i);
    
    vector<int> D(1000001, 1000000);
    
    rep2(i, 2, 1000001){
        int t = i;
        while(t<=1000000){
            if(D.at(t) == 1000000){
                D.at(t) = i;
            }
            t += i;
        }
    }
    
    set<int> divisor;
    bool flg = true; 
    rep(i, N){
        int a = A.at(i);
        set<int> div;
        while(a > 1){
            int Da = D.at(a);
            div.insert(Da);
            a /= Da; 
        }
        for(auto itr=div.begin();itr!=div.end();itr++){
            if(!divisor.insert(*itr).second) flg = false;
        }
    }

    if(flg) cout << "pairwise coprime" << endl;

    else{
        set<int> old_gcd;
        int a0 = A.at(0);
        while(a0 > 1){
            int Da = D.at(a0);
            old_gcd.insert(Da);
            a0 /= Da;
        }
        rep2(i, 1, N){
            int a = A.at(i);
            set<int> new_gcd;
            while(a > 1){
                int Da = D.at(a);
                if(old_gcd.find(Da) != old_gcd.end()) new_gcd.insert(Da);
                a /= Da; 
            }
            old_gcd = new_gcd;
            new_gcd.clear();
        }

        if(old_gcd.empty()) cout << "setwise coprime" << endl;
        else cout << "not coprime" << endl;
    }
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  //
  string s;
  cin >> s;
  if (s.back() == 's') {
    cout << s << "es" << '\n';
  } else {
    cout << s << 's' << '\n';
  }

  return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    sc.close();
    int count = 0;
    for (int i = 0; i < s.length() - 1 - i; i++) {
      if (s.charAt(i) == s.charAt(s.length() - 1 - i)) {
        continue;
      }
      count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 21972
#include <iostream>
#include <cstdio>
#include <memory>

using namespace std;

struct Node {
  int key;
  Node* parent;
  Node* left;
  Node* right;
  
  Node(int key = -1) : key(key), parent(nullptr), left(nullptr), right(nullptr) {};
};

struct Tree {
  Node* root;  
  
  Tree() : root(nullptr) {};
};

static void insert(Tree& tree, int v) {
  Node* z = new Node(v);
  Node* x(tree.root);
  Node* y(nullptr);
  while (x != nullptr) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  
  z->parent = y;
  if (y == nullptr) {
    tree.root = z;
  } else if (z->key < y->key) {
    y->left = z;
  } else {
    y->right = z;
  }
}

void preorderWalk(const Node* node) {
  if (node->key == -1) {
    return;
  }
  cout << " " << node->key;
  if (node->left != nullptr) {
    preorderWalk(node->left);
  }
  if (node->right != nullptr) {
    preorderWalk(node->right); 
  }
}

void inorderWalk(const Node* node) {
  if (node->key == -1) {
    return;
  }
  if (node->left != nullptr) {
    inorderWalk(node->left);
  }
  cout << " " << node->key;

  if (node->right != nullptr) {
    inorderWalk(node->right); 
  }
}

static Tree TREE;

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

  string command;
  int v;
  for (int i = 0; i < n; i++) {
    cin >> command;
    if (command[0] == 'i') {
      scanf("%d", &v);
      insert(TREE, v);
    } else {
      inorderWalk(TREE.root);
      cout << endl;
      preorderWalk(TREE.root);
      cout << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 26712
LIST = [int(input()) for i in range(5)]
if  max([LIST[i]%10 for i in range(5)]) != 0:
    print(sum([(LIST[i]-1)//10 + 1 for i in range(5)]) * 10 
               + min([LIST[i]%10 for i in range(5) if LIST[i]%10 != 0]) - 10)
else:
    print(sum([(LIST[i]-1)//10 + 1 for i in range(5)]) * 10)

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

using namespace std;

int main(void)
{
  int h, w; cin >> h >> w;
  char s[22][22];
  for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j) cin >> s[i][j];
  for (int i = 1; i <= w; ++i) s[0][i] = s[h+1][i] = '#';
  for (int i = 1; i <= h; ++i) s[i][0] = s[i][w+1] = '#';
  
  const int INF = 1000;
  int d[22][22][22][22];
  for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j)
    for (int k = 1; k <= h; ++k) for (int l = 1; l <= w; ++l) d[i][j][k][l] = INF;
  for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j) d[i][j][i][j] = 0;
  for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j) if (s[i][j] == '.') {
    if (s[i-1][j] == '.') d[i-1][j][i][j] = d[i][j][i-1][j] = 1;
    if (s[i+1][j] == '.') d[i+1][j][i][j] = d[i][j][i+1][j] = 1;
    if (s[i][j-1] == '.') d[i][j-1][i][j] = d[i][j][i][j-1] = 1;
    if (s[i][j+1] == '.') d[i][j+1][i][j] = d[i][j][i][j+1] = 1;
  }
  
  for (int m = 1; m <= h; ++m) for (int n = 1; n <= w; ++n)
    for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j)
      for (int k = 1; k <= h; ++k) for (int l = 1; l <= w; ++l)
        d[i][j][k][l] = min(d[i][j][k][l], d[i][j][m][n] + d[m][n][k][l]);
  
  int mx = 0;
  for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j)
    for (int k = 1; k <= h; ++k) for (int l = 1; l <= w; ++l)
      if (d[i][j][k][l] != INF) mx = max(mx, d[i][j][k][l]);
  
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 1024
n =int(input().split()[0])
m = map(int, input().split())

c = [ i for i in range(n+1) ]
coins = []

for coin in m:
    if coin <= n:
        c[coin] = 1
        coins.append(coin)

for p in range(2,n+1):
    minc = c[p]
    if minc <= 2:
        continue
    for coin in coins:
        if p > coin:
            if minc > c[p-coin]+1:
                minc = c[p-coin]+1
    c[p] = minc

print(c[n])

Measured memory_bytes: 9656
// C++ code to find number of distinct numbers
// in a subarray
#include<bits/stdc++.h>
using namespace std;

const int N = 5e5 + 5;

int a[N];
// structure to store queries
struct Query
{
    int l, r, idx;
};

Query queries[N];
// cmp function to sort queries according to r
bool cmp(Query x, Query y)
{
    return x.r < y.r;
}

// updating the bit array
void update(int idx, int val, int bit[], int n)
{
    for (; idx <= n; idx += idx & -idx)
        bit[idx] += val;
}

// querying the bit array
int query(int idx, int bit[], int n)
{
    int sum = 0;
    for (; idx > 0; idx -= idx & -idx)
        sum += bit[idx];
    return sum;
}

void answeringQueries(int arr[], int n, Query queries[], int q)
{
    // initialising bit array
    int bit[N];
    memset(bit, 0, sizeof(bit));

    // holds the rightmost index of any number
    // as numbers of a[i] are less than or equal to 10^6
    int last_visit[N];
    memset(last_visit, -1, sizeof(last_visit));

    // answer for each query
    int ans[q];
    int query_counter = 0;
    for (int i = 0; i < n; i++)
    {
        // If last visit is not -1 update -1 at the
        // idx equal to last_visit[arr[i]]
        if (last_visit[arr[i]] != -1)
            update (last_visit[arr[i]] + 1, -1, bit, n);

        // Setting last_visit[arr[i]] as i and updating
        // the bit array accordingly
        last_visit[arr[i]] = i;
        update(i + 1, 1, bit, n);

        // If i is equal to r of any query store answer
        // for that query in ans[]
        while (query_counter < q && queries[query_counter].r == i)
        {
            ans[queries[query_counter].idx] =
                query(queries[query_counter].r + 1, bit, n) -
                query(queries[query_counter].l, bit, n);
            query_counter++;
        }
    }

    // print answer for each query
    for (int i = 0; i < q; i++)
        cout << ans[i] << "\n";
}

// driver code
int main()
{
    // int a[] = {1, 1, 2, 1, 3};
    // int n = sizeof(a)/sizeof(a[0]);
    // Query queries[3];
    // queries[0].l = 0;
    // queries[0].r = 4;
    // queries[0].idx = 0;
    // queries[1].l = 1;
    // queries[1].r = 3;
    // queries[1].idx = 1;
    // queries[2].l = 2;
    // queries[2].r = 4;
    // queries[2].idx = 2;
    // int q = sizeof(queries)/sizeof(queries[0]);
    // sort(queries, queries+q, cmp);
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n; i++) cin >> a[i];

    for (int i = 0; i < q; i++) {
        cin >> queries[i].l >> queries[i].r;
        queries[i].l--;
        queries[i].r--;
        queries[i].idx = i;
    }

    sort(queries, queries + q, cmp);
    answeringQueries(a, n, queries, q);

    return 0;
}


Measured memory_bytes: 17424
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if b-a <= k and c-a <= k and d-a <= k and e-a <= k and c-b <= k and d-b <= k and e-b <= k and d-c <= k and e-c <= k and e-d <= k:
  print("Yay!")
else:
  print(":(")

Measured memory_bytes: 3060
/*
 * Author : Sadi
 * Sat 27/06/2020
 * 20:31:16.87
 */
#include <bits/stdc++.h>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif

    int n, i;
    cin >> n >> i;
    cout << n - i + 1 << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())

typedef long long ll;

int main() {

	ll N; cin >> N;

	ll t = N;
	ll sum = 0;
	while (t > 0) {
		sum += t % 10;
		t /= 10;
	}

	if (N % sum == 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while(true) {
      String[] str = sc.nextLine().split("");
      int sum = 0;
      if(str[0].equals("0")) {
        break;
      } else {
        for(int i = 0; i < str.length; i++) {
          int a = Integer.parseInt(str[i]);
          sum += a;
        }
        System.out.println(sum);
      }
    }
  }
}



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

int main() {
  int A;
  cin >> A;
  
  if (A < 1200){
    cout << "ABC" << endl;
  }
  else if (1200 <= A, A < 2800){
    cout << "ARC" << endl;
  }
  else  if (2800 <= A) {
    cout << "AGC" << endl;
  }
}


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

int main(void){
    string s;
    cin >> s;
    for (int i = 0; i < s.length() -1; i++)
    {
        if(s[i] == s[i+1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
    return 0;
}

Measured memory_bytes: 256