akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	long long N, K; cin >> N >> K;
	vector<char>D(K);
	for (long long i = 0; i < K; i++) {
		cin >> D.at(i);
	}
	for (long long i = N; i < 100000; i++) {
		string S = to_string(i);
		bool check = true;
		for (long long j = 0; j < S.size(); j++) {
			for (long long k = 0; k < K; k++) {
				if (S.at(j) == D.at(k)) check = false;
			}
		}
		if (check) {
			cout << S << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3664
#include<stdio.h>

int main(){

  int n, m, c, i, j;

  scanf("%d %d", &n, &m);

  int A[n][m], b[m];

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

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

  for(i=0; i < n; i++){
    c = 0;
    for(j=0; j < m; j++){
      c += A[i][j]*b[j];
    }
    printf("%d\n",c);
  }

  return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline

s = input().rstrip()

from collections import Counter

c = Counter(s)

if len(s) == 1:
    print("YES")
    sys.exit()

if len(c.keys()) == 1:
    print("NO")
    sys.exit()

values = list(c.values())
values.sort()

if len(c.keys()) == 2:
    if values[0] == 1 and values[1] == 1:
        print("YES")
    else:
        print("NO")
    sys.exit()

values[1] -= values[0]
values[2] -= values[0]

if values[1] == 1 and values[2] == 1:
    print("YES")
elif values[1] == 0 and values[2] == 1:
    print("YES")
elif values[1] == 1 and values[2] == 0:
    print("YES")
elif values[1] == 0 and values[2] == 0:
    print("YES")
else: 
    print("NO")
sys.exit()



Measured memory_bytes: 39408
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=200000+5;
const int inf=1e9;
const ll mod=1e9+7;


int main()
{
    FasterIO;
    ll tc, a, b, n;
    cin>>a>>n;
    ll sm=0;
    for(int i=1; i<=n; i++)
    {
        cin>>b; sm+=b;
    }
    if(a<=sm) cout<<"Yes"<<endl;
    else      cout<<"No"<<endl;
    return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  ll n; cin>>n;
  vi d(n);
  rep(i,n) cin>>d[i];
  ll m; cin>>m;
  vi t(m);
  rep(i,m) cin>>t[i];
  S s;
  rep(i,n) s.insert(d[i]);
  bool f=true;
  rep(i,m){
    if(s.count(t[i])) s.erase(s.find(t[i]));
    else{
      f=false; break;
    }
  }
  if(f) out("YES");
  else out("NO");
}

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


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define ALL(v) (v).begin(),(v).end()
#define REP(i, x, n) for(ll (i)=(x); (i)<(n); (i)++)
#define RREP(i, x, n) for(ll (i)=(n)-1; (i)>=x; (i)--)
#define FOR(i, n) for(ll (i)=0; (i)<(n); (i)++)
#define RFOR(i, n) for(ll (i)=(n)-1; (i)>=0; (i)--)

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

        ll n; cin >> n;
        if (n % 10 == 3) cout << "bon" << endl;
        else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) cout << "pon" << endl;
        else cout << "hon" << endl;

        return 0;
}

Measured memory_bytes: 3664
package main
 
import (
	"fmt"
)
 
func main() {
	var n, k int
	fmt.Scan(&n)
	fmt.Scan(&k)
 
	m := make([]int, n + 1, n + 1)
 
	for i := 1; i <= n; i++ {
		for j := 1; j <= 2 * k; j *= 2 {
			if int64(j) * int64(i) >= int64(k) {
				m[i] = j
				break;
			}
		}
	}
 
	answer := 0.0
	for i := 1; i <= n; i++ {
		answer += 1.0 / (float64(n) * float64(m[i]))
	}
	fmt.Println(answer)
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 1) break;
        cout << n << ": ";
        vector<bool> prime(n + 1, true);
        bool f = true;
        for (int i = 2; i <= n; i++) {
            if (i % 7 == 1 or i % 7 == 6) {
                if (n % i == 0 and prime[i]) {
                    if (not f) {
                        cout << " ";
                    }
                    f = false;
                    cout << i;
                }
                for (int j = 2; i * j <= n; j++) {
                    if (i * j % 7 == 1 or i * j % 7 == 6) {
                        prime[i * j] = false;
                    }
                }
            }
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3116
n, k = map(int, input().split())
s = list(input())
group_num = 1
tmp_char = s[0]
for index in range(1, len(s)):
    if s[index] == tmp_char:
        continue
    else:
        tmp_char = s[index]
        group_num += 1
group_num = max(1, group_num - (k-1)*2)
if group_num >= 3:
    group_num -= 2
elif group_num == 2:
    group_num = 1

happy = len(s) - group_num
print(happy)

Measured memory_bytes: 4084
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

struct mint {
	long long x;
	mint(long long x = 0) :x((x% mod + mod) % mod) {}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
}; 

const int MAX = 4000000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

mint COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return mint(fac[n] * (finv[k] * finv[n - k] % mod) % mod);
}

mint LCOM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (k > n / 2) k = n - k;
	mint res = 1;
	for (int i = 0; i < k; i++) res *= (n - i);
	res *= finv[k];
	return res;
}
int main()
{

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


	COMinit();
	ll X, Y; cin >> X >> Y;
	if ((X + Y) % 3 != 0) {
		cout << 0 << endl;
		return 0;
	}
	ll b = X - (X + Y) / 3;
	ll a = Y - (X + Y) / 3;
	if (a < 0 or b < 0) {
		cout << 0 << endl;
		return 0;
	}
	cout << COM(a + b, a).x << "\n";
	return 0;
}

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

#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)

namespace solver {
  using namespace std;
  typedef long long ll;
  typedef pair<ll, ll> P;

  static const ll MAX = 100010LL;
  ll X, Y, A, B, C;
  vector<P> v;
  // ll xs[MAX], ys[MAX];

  void init() {
    scanf("%lld %lld %lld %lld %lld", &X, &Y, &A, &B, &C);
    ll w;
    rep(i, A) {
      scanf("%lld", &w);
      v.push_back({w, 0});
    }
    rep(i, B) {
      scanf("%lld", &w);
      v.push_back({w, 1});
    }
    rep(i, C) {
      scanf("%lld", &w);
      v.push_back({w, 2});
    }
    sort(v.begin(), v.end(), greater<P>());
  }

  void solve() {
    ll used_c = 0ll, ans = 0ll;
    for(const auto& u : v) {
      if(X+Y==used_c) break;
      if(u.second == 0 && X > 0) {
        X--;
        ans += u.first;
      }
      if(u.second == 1 && Y > 0) {
        Y--;
        ans += u.first;
      }
      if(u.second == 2 && (X > 0 || Y > 0)) {
        used_c++;
        ans += u.first;
      }
    }
    printf("%lld\n", ans);
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 10604
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

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;}

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

    int min = INT_MAX;
    int ans = 0;
    rep(i, n) {
        capi(p);

        if (chmin(min, p)) ++ans;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <queue>
typedef long long ll;
using namespace std;
const int mod=1e9+7;
const ll inf=(1e14);

ll solve(){
	ll n;
	cin>>n;
	if(n&1) return 0;
	ll ans=0;
	n>>=1;
	while(n){
		ans+=(n/5);
		n/=5;
	}
	return ans;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while(t--) cout<<solve()<<'\n';
    //while(t--) solve(),cout<<'\n';
    return 0;
}


Measured memory_bytes: 3620
N = gets
T, A = gets.strip.split.map(&:to_i)
locations = gets.strip.split.map(&:to_i)
result, point = 10 ** 10, 0

locations.each_with_index do |location, i|
  diff = ( T - location * 0.006 - A ).abs
  if diff < result
    result = diff
    point = i 
  end
end
puts point + 1

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  int n;
  cin>>n;
  vector<int>a(n+1),b(n);
  rep(i,n+1) cin>>a[i];
  rep(i,n) cin>>b[i];
  ll ans=0;
  rep(i,n){
    int at1=min(b[i],a[i]);
    ans+=at1;
    b[i]-=at1;
    a[i]-=at1;
    int at2=min(a[i+1],b[i]);
    ans+=at2;
    a[i+1]-=at2;
    b[i]-=at2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
		
		static void solve() {
			Scanner sc = new Scanner(System.in);
			String s = new String();
			s = sc.next();
			int check = 0;
			int n = s.length();
			String res = "Yes";
			for(int i = 0; i < n;i++) {
			if(i%2==1&&s.charAt(i)=='R') {
				check++;
			}
			if(i%2==0&&s.charAt(i)=='L') {
				check++;
			}
			}
			if(check>0) res = "No";
			System.out.println(res);
			sc.close();
			
		}
	public static void main(String[] args) {
		solve();

	}

}


Measured memory_bytes: 25044
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

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

int main() 
{
    int ans = 0;
    int n; cin >> n;

    for(int i = 1; i <= n; i++) {
       for(int j = 1; j <= i; j++) {
            //cout << "i," << i << ",j,"<< j << endl;
            if((i % 2 ==0) && (j % 2 != 0)) ans++; 
            if((j % 2 ==0) && (i % 2 != 0)) ans++; 
       }
    }

    cout << ans << endl;

    return 0;
}



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

#define pb push_back

void solve(){
   int n;cin>>n;
   int a,A[100000]{};
   for(int i=0;i<n;++i) cin>>a,++A[a];
    A[0]+=n%2;
   for(int i= (n+1)%2 ; i < n; i+=2) 
    if(A[i]!=2) {
      cout<<"0"<<endl;
      return;
    }

   n/=2;
   ll temp=1;
   while(n--) temp=(temp*2)%1000000007;
    cout<<temp<<endl;
}


int main() {
   #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
 ios_base::sync_with_stdio(0);
 cin.tie(0);
 cout.tie(0);
solve();
  return 0;
}


Measured memory_bytes: 4008
/*
 	author:: tamajit banerjee
*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include <iomanip>
using namespace std;
#define pb push_back
#define ll long long int
# define pll pair<ll,ll>
  
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  	ll n;
  	cin>>n;
  	ll x=7;
  	for(int i=1;i<=n;i++){
  		if(x%n==0){
  			cout<<i;
  			return 0;
		  }
		  x=(x*10+7)%n;
	}
	cout<<-1;
	return 0;    
}
    

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

int main(){
    int a;
    cin >> a;
    cout << a + pow(a, 2) + pow(a, 3) << endl;
    return 0;
}

Measured memory_bytes: 4080
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
  lint N,ans=0;
  cin >> N;
  multiset<lint> A;
  lint pow2[40];
  pow2[0]=1;
  rep(i,39) pow2[i+1]=pow2[i]*2;
  rep(i,N){
    lint X;
    cin >> X;
    A.insert(X);
  }
  while(A.size()>1){
    bool check=false;
    auto itr=A.end();
    itr--;
    rep(i,33){
      if(A.count(pow2[i]-*itr)){
        auto itr2=A.find(pow2[i]-*itr);
        if(itr==itr2 && A.count(pow2[i]-*itr)==1) continue;
        else if(itr==itr2) itr2++;
        ans++;
        A.erase(itr);
        A.erase(itr2);
        check=true;
        break;
      }
    }
    if(!check) A.erase(*itr);
  }
  cout << ans << endl;
}

Measured memory_bytes: 9600
N, C = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(C)]

color = [[0] * C for _ in range(3)]

for i in range(N):
    c = input().split()
    for j in range(N):
        color[(i+j)%3][int(c[j])-1] += 1

sumcolor = [[0] * C for _ in range(3)]


for i in range(3):
    for j in range(C):
        for c in range(C):
            sumcolor[i][j] += color[i][c] * data[c][j]

answer = 10 ** 18
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i != j and i != k and j != k:
                answer = min(answer, sumcolor[0][i]+sumcolor[1][j]+sumcolor[2][k])


print(answer)

Measured memory_bytes: 3188
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n;
long long kk;
char s[1000];
int main(){
        scanf("%s",s);
        scanf("%lld",&kk);
        n=strlen(s);
        for(int i=0;i<n;i++){
                if(s[i]>'1') return printf("%c",s[i]),0;
                else kk--;
                if(kk==0) return printf("%c",s[i]),0;
        }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	if(a*500+b*100+c*50<x)
	{
		cout<<"0\n";
		return 0;
	}
	int o=0;
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
		{
			for(int k=0;k<=c;k++)
			{
				if(i*500+j*100+k*50==x) o++;
				//printf("%d %d %d\n",i,j,k);
			}
		}
	}
	cout<<o<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) {
        cin >> p[i];
    }
    vector<int> s(n-k+1,0);
    rep(i,k) s[0] += p[i];
    rep(i,n-k) s[i+1] = s[i] - p[i] + p[i+k];
    int ans = 0;
    rep(i,n-k+1) chmax(ans, s[i]);
    cout << std::fixed << (ans+k)/2.0  << endl;
}


Measured memory_bytes: 4636
uses math;
var
  x,y:longint;
 function mi(x,y:longint):longint;
  begin if x<=y then exit(y-x) else exit(x-y+2);end;
begin
  readln(x,y);
  writeln(min(mi(x,y),min(mi(-x,y)+1,min(mi(x,-y)+1,mi(-x,-y)+2))));
end.

Measured memory_bytes: 128
n = int(input())
l = list(map(int, input().split()))
l.sort()
ret = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if len(set([l[i], l[j], l[k]])) == 3 and l[i] + l[j] > l[k]: ret += 1
print(ret)

Measured memory_bytes: 9192
# -*- coding: utf-8 -*-
from itertools import product

H, W , K = [int(i) for i in input().split()]
c = [list(input()) for _ in range(H)]
ans = 0

for row_bit in product(range(2),repeat=H):
    for col_bit in product(range(2),repeat=W):
        cnt = 0
        for row in range(H):
            for col in range(W):
                if c[row][col] == "#" and  (row_bit[row] and col_bit[col]):
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)


Measured memory_bytes: 9028
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,d,e;
  cin >> a;
  b = a/100;
  c = a%100;
  d = c/10;
  e = c%10;
  if ((b == 7)|| (d == 7) || (e == 7)) {
    cout << "Yes";
  } else{ cout << "No";
  }
}

Measured memory_bytes: 3636
def main():
  n = int(input())
  ls = list(map(int, input().split()))
  if 0 in ls:
    print(0)
    return
  ans = 1
  for l in ls:
    ans *= l
    if ans > 1000000000000000000:
      print(-1)
      return
  print(ans)
  
main()

Measured memory_bytes: 21580
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define next _______next
#define before ______before
vector<int> edge[108000];
int size[108000];
vector<int> edges[108000];
vector<int> nodes[108000];
int before[108000];
int next[108000];
bool done[108000];
int pp, n, gr;
int p[108000], a[108000];
int dep[108000];
int ord[108000];
int group[108000];
int pos[108000];
vector<int> ans;
void dfs(int x){
	size[x] = 1;
	next[x] = -1;
	nodes[dep[x]].push_back(x);
	for(int i = 0;i < edge[x].size();i++){
		int to = edge[x][i];
		dep[to] = dep[x] + 1;
		dfs(to);
		size[x] += size[to];
	}
	for(int i = 0;i < edge[x].size();i++){
		int to = edge[x][i];										 
		if(size[to] * 2 >= size[x]){
			next[x] = to;
			before[to] = x;
		}
		else{
			before[to] = -1;
		}
	}
}

void go(int x){
	if(x == 0)return;
	ans.push_back(x);
	int tmp = a[x];
	a[x] = a[0];
	while(x){
		swap(tmp, a[p[x]]);
		x = p[x];
	}
}

int good_place(int d){
	for(int i = n-1;i >= 0;i--){
		for(int j = 0;j < nodes[i].size();j++){
			int node = nodes[i][j];
			if(ord[group[a[node]]] != d)continue;
			if(!done[a[node]])return node;
		}
	}
	return 0;
}

void solve(int d){
	int rest = 0;
	for(int i = 0;i < n;i++){
		done[i] = false;
		if(ord[group[i]] == d)rest++;
		else done[i] = true;
	}
	while(rest){
		int now = a[0];
		if(ord[group[now]] != d){
			int nxt = good_place(d);
			done[now] = true;
			go(nxt);
		}
		else{
			gr = group[now];
			rest--;
			done[now] =true;
			for(int i = edges[gr].size() - 1;i >= 0;i--){
				int tmpp = edges[gr][i];
				int tmp = a[tmpp];
				if(group[tmp] != gr || !done[tmp]){
					go(tmpp);
					break;
				}
				if(pos[tmp] < pos[now]){
					go(tmpp);
					break;
				}
			}
		}
	}
}

int main(){
	cin >> n;
	fill(before, before + n, -1);
	for(int i = 1;i < n;i++){
		cin >> p[i];
		edge[p[i]].push_back(i);
	}
	for(int i = 0;i < n;i++)cin >> a[i];
	dfs(0);


	for(int d = 0;d < n;d++){
		for(int i = 0;i < nodes[d].size();i++){
			int n = nodes[d][i];
			if(before[n] == -1){
				group[n] = pp++;
				if(d != 0){
					ord[group[n]] = ord[group[p[n]]] + 1;
				}
			}
			else group[n] = group[before[n]];
			pos[n] = edges[group[n]].size();
			edges[group[n]].push_back(n);
		}
	}

	for(int i = 11;i >= 0;i--){
		solve(i);
		//ans.push_back(-1);
		//for(int i = 0;i < n;i++)cout << a[i] << endl;
		//cout << endl;
	}
	cout << ans.size() << endl;
	if(ans.size() > 250000)return -10;
	for(int i = 0;i < ans.size();i++){
		cout << ans[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 10112
#include<iostream>

using namespace std;

int main(){
        int n; cin >> n;
        int A[1000];
    
        for (int i = 0; i < n; i++){
                cin >> A[i];
        }   
    
        for ( int i = 1; i <= n; i++){
                for ( int k = 0; k < n; k++){
                        cout << A[k];
                        if ( k != n - 1){ 
                                cout << " ";
                        }   
                }   
                cout << endl;
                int v = A[i];
                int j = i - 1;
                while( j >= 0 and A[j] > v){ 
                        A[j+1] = A[j];
                        j--;
                }   
                A[j+1] = v;
        }   

return 0;
}

Measured memory_bytes: 3072
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String[] inputs = scanner.nextLine().split(" ");
		int dx = Integer.parseInt(inputs[2]) - Integer.parseInt(inputs[0]);
		int dy = Integer.parseInt(inputs[3]) - Integer.parseInt(inputs[1]);
		StringBuilder sb = new StringBuilder();
		appendChars(sb, 'D', 1);
		appendChars(sb, 'R', dx + 1);
		appendChars(sb, 'U', dy + 1);
		appendChars(sb, 'L', dx + 1);
		appendChars(sb, 'D', dy);
		appendChars(sb, 'R', dx);
		appendChars(sb, 'U', dy + 1);
		appendChars(sb, 'L', dx + 1);
		appendChars(sb, 'D', dy + 1);
		appendChars(sb, 'R', 1);
		System.out.println(sb);
	}

	private static void appendChars(StringBuilder sb, char c, int times) {
		for (int i = 0; i < times; i++) sb.append(c);
	}
}


Measured memory_bytes: 23764
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <ctime>
#include <cstdlib>
#include <iterator>
using namespace std;

//#define TEST
int main()
{
#ifdef TEST
	freopen("data.in", "r", stdin);
	freopen("data.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	int a, b;
	while(cin>> a >> b) {
		a -= b;
		if(a < 0) a = 0;
		cout << a << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>

using namespace std;

unsigned long long gcd(unsigned long long a, unsigned long long b) {
  
  if (b == 0) return a;
  return gcd(b, a%b);
}

int main(void) {
  unsigned long long a, b, c, d, i, m, t1, t2, t3;
  
  cin >> a >> b >> c >> d;
  if (c < d) 
    m = gcd(d, c);
  else
    m = gcd(c, d);
  m = c * d / m;
  //cout << "m = " << m << endl;
  t1 = (b / c - a / c) * (c - 1) + b % c - (a % c != 0 ? ((a - 1) % c) : 0);
  t2 = (b / d - a / d) * (d - 1) + b % d - (a % d != 0 ? ((a - 1) % d) : 0);
  t3 = (b / m - a / m) * (m - 1) + b % m - (a % m != 0 ? ((a - 1) % m) : 0);
  //cout << t1 << endl;
  //cout << t2 << endl;
  //cout << t3 << endl;
  cout << t1 + t2 - t3 << endl;
  
  return 0;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
int main ()
{
	int N, L;
	cin>>N>>L;
	string a[100];
	int b[100];
	for(int i=0;i<N;i++)
	{
		cin>>a[i];
	}
	sort(a, a+N); 
	for (int j=0;j<N;j++)
		cout<<a[j];
	return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int q;
	cin >> q;
	REP(i, q) {
		ll a, b;
		cin >> a >> b;
		if (a > b)swap(a, b);
		ll ans = a - 1;
		ll l = 0, r = b;
		while (r - l > 1) {
			ll mid = (r + l) / 2;
			if (mid < a) {
				if ((a + 1)*mid < a*b)l = mid;
				else r = mid;
			}
			else {
				if ((a + mid) % 2) {
					ll i = (a + mid + 1) / 2;
					if (i*i < a*b)l = mid;
					else r = mid;
				}
				else {
					ll i = (a + mid) / 2;
					if (i*(i + 1) < a*b)l = mid;
					else r = mid;
				}
			}
		}
		cout << ans + l << endl;
	}
}


Measured memory_bytes: 256
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define SORTD(a) sort(a.rbegin(), a.rend());
#define UNIQUE(a) unique(a.begin(), a.end())
#define ll long long
#define INF 1000000000000000000
#define INT_MAX 2147483647

#include <iostream>
#include <vector>
#include <cmath>
#include <cctype>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <utility>
#include <ios>
#include <iomanip>

using namespace std;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }

  bool unionSet(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main(){
    int n,m;
    cin >> n >> m;
    UnionFind u = UnionFind(n);
    vi ans;

    REP(i,m){
        int x,y,z;
        cin >> x >> y >> z;
        x--;
        y--;
        u.unionSet(x,y);
    }
    
    REP(i,n){
        ans.push_back(u.root(i));
    }
    SORT(ans);
    ans.erase(UNIQUE(ans),ans.end());

    cout << ans.size() << endl;

}

Measured memory_bytes: 1276
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
// #include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int X[M];
  for (int i = 0; i < M; i++) cin >> X[i];
  sort(X, X + M);

  int y[M - 1];
  for (int i = 0; i < M - 1; i++) {
    y[i] = X[i + 1] - X[i];
  }
  sort(y, y + M - 1, greater<int>());

  if (N >= M) {
    cout << 0 << endl;

  } else {
    int ans = X[M - 1] - X[0];
    for (int i = 0; i < N - 1; i++) {
      ans -= y[i];
    }

    cout << (ans < 0 ? 0 : ans) << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define mod 1000000007
#define mk make_pair
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin>>h>>w;
    int a[h+1][w+1];char c;int dp[h+1][w+1];
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {   dp[i][j]=0;
            cin>>c;
            if(c=='.')
            a[i][j]=1;
            else
            a[i][j]=0;          //0=wall
        }
    }
    for(int i=0;i<=h;i++)
    {a[i][0]=0;dp[i][0]=0;}
    for(int i=0;i<=w;i++)
    {a[0][i]=0;dp[0][i]=0;}
    dp[1][1]=1;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(i==1&&j==1)
            continue;
            if(a[i-1][j]==1)
            dp[i][j]+=dp[i-1][j];
            if(a[i][j-1]==1)
            dp[i][j]+=dp[i][j-1];
            dp[i][j]%=mod;
        }
    }
    cout<<dp[h][w];
    return 0;
}

Measured memory_bytes: 8064
while line = gets
	n, x = line.split( " " ).map { | val | val.to_i }
	break if 0 == n && 0 == x

	cnt = 0
	goto = false
	for i in ( 1 .. n-2 )
		break if x < 3*(i+1)
		for j in ( i+1 .. n-1 )
			break if x < i+j
			for k in ( j+1 .. n )
				s = ( i + j + k )
				if x < s
					goto = true
					break
				elsif x == s
					cnt += 1
					break
				end
			end
			break if goto
		end
		goto = false
	end
	
	puts( cnt )
end

Measured memory_bytes: 6112
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> d(K);
    set<int> A;
    for (int i = 0; i < K; i++)
    {
        cin >> d.at(i);
        for (int j = 0; j < d.at(i); j++)
        {
            int a;
            cin >> a;
            A.insert(a);
        }

    }
    int ans = 0;

    for (int i = 1; i <= N; i++)
    {
        for (auto value : A)
        {
            if (value == i)
            {
                ans ++;
            }
            
        }
        
    }

    cout << N-ans;
    
    
    
}

Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>

using namespace std;

const int maxn = 1005;

int dp[maxn][maxn];

char s[maxn][maxn];
int n, m;

const int mod = 1e9 + 7;

int main(){
    cin >> n >> m;
    memset(dp, 0, sizeof(dp));
    for(int i = 1;i <= n;i++){
        scanf("%s", s[i] + 1);
    }
    dp[1][1] = 1;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++){
            if(i + 1 <= n and s[i + 1][j] == '.'){
                dp[i + 1][j] += dp[i][j];
                if(dp[i + 1][j] >= mod)
                    dp[i + 1][j] -= mod;
            }
            if(j + 1 <= m and s[i][j + 1] == '.'){
                dp[i][j + 1] += dp[i][j];
                if(dp[i][j + 1] >= mod)
                    dp[i][j + 1] -= mod;
            }
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}


Measured memory_bytes: 5120
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  // first go horizon
  for (int i = 0; i < tx - sx; ++i)
    cout << "R";

  // first go verticall
  for (int i = 0; i < ty - sy; ++i)
    cout << "U";

  // first back horizon
  for (int i = 0; i < tx - sx; ++i)
    cout << "L";

  // first back vertical
  for (int i = 0; i < ty - sy; ++i)
    cout << "D";

  // second go horizon
  cout << "D";
  for (int i = 0; i < tx - sx + 1; ++i)
    cout << "R";

  // second go vertical
  for (int i = 0; i < ty - sy + 1; ++i)
    cout << "U";
  cout << "L";

  // second back horizon
  cout << "U";
  for (int i = 0; i < tx - sx + 1; ++i)
    cout << "L";

  // second back vertical
  for (int i = 0; i < ty - sy + 1; ++i)
    cout << "D";
  cout << "R";

  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    ll K; cin >> K;
    ll a = 7;
    ll cnt = 1;
    veci mod(1000010);
    REP(i,1000010) {
        if(mod[a]) {
            cout << -1 << endl;
            return 0;
        }
        mod[a] = 1;
        if(a%K == 0) {
            cout << cnt << endl;
            return 0;
        }
        a = (((a%K)*(10%K))%K+7)%K;
        cnt++;
    }
}

Measured memory_bytes: 7196
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions

import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    def euclid(a, b):
        if b == 0:
            return a
        else:
            return euclid(b, a % b)

    def multiple(a, b):
        return a * b // euclid(a, b)

    n, m = ns()
    s = list(input())
    t = list(input())

    gcd = multiple(n, m)

    s_idx = [gcd // n * i for i in range(n)]
    t_idx = [gcd // m * i for i in range(m)]
    t_set = set(t_idx)

    for idx in s_idx:
        if idx in t_set:
            if s[idx * n // gcd] != t[idx * m // gcd]:
                print(-1)
                exit(0)

    print(gcd)


if __name__ == '__main__':
    main()


Measured memory_bytes: 80664
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
                         **/
#include<bits/stdc++.h>
using namespace std;
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz size
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 3*1e5+5;
const int mod = 1000000009;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 10000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b;
    int pwur = qpow(b,e>>1);
    return pwur * pwur;
}
int modinv(int x){
    return qpow(x,mod-2);
}

/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));

    ///freopen("a.in","r",stdin);
    ///freopen("a.out","w",stdout);
    int n;
    cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    sort(all(v));
    cout<<v[n-1]-v[0]<<enl;


    return 0;
}


Measured memory_bytes: 3612
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    N = int(input())
    a = list(map(int, input().split()))

    c = Counter(a)
    ans = "No"
    if len(c) == 3:
        v = list(c.values())
        if v[0] == v[1] == v[2]:
            k = list(c.keys())
            if (k[0] ^ k[1] == k[2]) and (k[1] ^ k[2] == k[0]) and (k[2] ^ k[0] == k[1]):
                ans = "Yes"
    elif len(c) == 2:
        v = list(c.values())
        k = list(c.keys())
        v[0], v[1] = min(v), max(v)
        k[0], k[1] = min(k), max(k)
        if k[0] == 0 and v[0] * 2 == v[1]:
            ans = "Yes"
    elif len(c) == 1:
        k = list(c.keys())
        if k[0] == 0:
            ans = "Yes"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14468
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
namespace Solve
{
	typedef long long LL;
	inline LL mymax(LL a,LL b){return a>b?a:b;}
	const int MAXN=5005;
	const LL INF=1e+15;
	int N,K,P[MAXN],C[MAXN];
	int cyc[MAXN],len;LL F[MAXN],ans;
	void div(int i,int s)
	{
		cyc[len++]=i;
		if(P[i]==s)
		{
			memset(F,0,sizeof(F));
			F[0]=C[cyc[0]];
			for(int t=1;t<len;t++)
				F[t]=F[t-1]+C[cyc[t]];
			LL lmx=-INF,mx=-INF,tot=F[len-1];
			for(int t=0;t<len;t++)
				mx=mymax(mx,F[t]);
			for(int t=0;t<K%len;t++)
				lmx=mymax(lmx,F[t]);
			LL tmin=INF;
			for(int t=0;t<len;t++)
			{
				if(t<K%len) lmx=mymax(lmx,F[t]-tmin);
				mx=mymax(mx,F[t]-tmin);
				if(F[t]<tmin) tmin=F[t];
			}
			int num=K/len;
			ans=mymax(ans,num*tot+lmx);
			if(num)
			{
				ans=mymax(ans,mx);
				ans=mymax(ans,(num-1)*tot+mx);
			}
			return;
		}
		div(P[i],s);
		return;
	}
	void work()
	{
		while(scanf("%d%d",&N,&K)!=EOF)
		{
			for(int i=1;i<=N;i++) scanf("%d",&P[i]);
			for(int i=1;i<=N;i++) scanf("%d",&C[i]);
			len=0;ans=-INF;
			for(int i=1;i<=N;i++){len=0;div(i,i);}
			cout<<ans<<endl;
		}
		return;
	}
}
int main()
{
	#ifdef LOCAL
	freopen("00test.in","r",stdin);
	freopen("00test.out","w",stdout);
	#endif
	Solve::work(); 
	return 0;
}

Measured memory_bytes: 3856
//Try until you reach your goal
#include <bits/stdc++.h>
using namespace std;
# define ll long long
# define endl "\n"
# define str string
# define vll vector<ll>
# define pb push_back
# define mll map<ll,ll>
# define mp make_pair
# define ff first
# define ss second
# define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll y;
    cin>>y;
    if(y%2 !=0){
        cout<<0;
    }
    else{
        ll ans=0;
        ll k=10;
        while(k<=y){
            ans=ans+y/k;
            k=k*5;
        }
        cout<<ans;
    }
    return 0;
}

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

using I = long long;

int main() {
  int N;
  cin >> N;
  vector<I> A(N);
  for(auto& i: A) cin >> i;

  for(auto i=0; i<N; ++i) A[i] -= i+1;

  auto score = [&](auto b) {
    return accumulate(begin(A), end(A), 0ll, [b](auto s, auto x) {return s + abs(x - b);});
  };

  I l = -1e9, h = 1e9;
  for(auto i=0; i<99; ++i) {
    auto m1 = (h+2*l)/3, m2 = (2*h+l)/3;
    auto s1 = score(m1), s2 = score(m2);
    if(s1 > s2) l = m1;
    else        h = m2;
  }
  auto m1 = (h+2*l)/3, m2 = (2*h+l)/3;
  cout << min({score(l), score(m1), score(m2), score(h)}) << endl;
}


Measured memory_bytes: 1792
/* ex4_3
  key_tree */

#include <stdio.h>
 // プロトタイプ宣言
int snow_depth(int west_height, int east_height);

int main(void){
    //埋もれていない高さを西側はwest_height、東側はeast_height
    int west_height, east_height;
    scanf("%d %d ",&west_height, &east_height);

    printf("%d\n", snow_depth(west_height, east_height));

    return 0;
}

int snow_depth(int west_height, int east_height){
    int dif, ans;
    dif = east_height - west_height;
    ans =(1 + dif) * dif /2 - east_height;

    return ans;
}


Measured memory_bytes: 128
n, m = [int(i) for i in input().split()]
xs = sorted([int(i) for i in input().split()])
li = sorted([xs[i+1] - xs[i] for i in range(m-1)])
if n >= m:
    print(0)
elif n == 1:
    print(sum(li))
else:
    print(sum(li[:-n+1]))

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

const int maxn = 1e5 + 10;
typedef long long int ll;
ll sum[maxn][4]; 
void solved(){
	ll n;cin>>n;
	char s[5000];scanf("%s",s + 1);
	ll r = 0, b = 0,g = 0;
	for(int i = 1; i <= n; i++){
		if(s[i] == 'R'){
			r++;
			sum[i][1] = sum[i - 1][1] + 1;
			sum[i][2] = sum[i - 1][2];
			sum[i][3] = sum[i - 1][3];
		}else if(s[i] == 'G'){
			g++;
			sum[i][1] = sum[i - 1][1];
			sum[i][2] = sum[i - 1][2] + 1;
			sum[i][3] = sum[i - 1][3];
		}else if(s[i] == 'B'){
			b++;
			sum[i][1] = sum[i - 1][1];
			sum[i][2] = sum[i - 1][2];
			sum[i][3] = sum[i - 1][3] + 1;
		}
	}
	//cout<<"r :"<<r<<"  G:"<<g<<"  B:"<<b<<endl;
	//cout<<"R:  "<<sum[n][1]<<"  G:"<<sum[n][2]<<"   B:"<<sum[n][3]<<endl;
	ll ans = 0;
	for(int i = 1; i <= n; i++)
	for(int k = i + 1; k <= n; k++){
		if(s[i] == 'R' && s[k] == 'B' ){
			if((k - i + 1) & 1 && s[(i + k) /2] == 'G')ans --;
			ans += sum[k - 1][2] - sum[i][2];
		}
		if(s[i] == 'B' && s[k] == 'R'){
			if((k - i + 1) & 1 && s[(i + k) /2] == 'G')ans --;
			ans += sum[k - 1][2] - sum[i][2];
		}
		if(s[i] == 'G' && s[k] == 'B'){
			if((k - i + 1) & 1 && s[(i + k) /2] == 'R')ans --;
			ans += sum[k - 1][1] - sum[i][1];
		}
		if(s[i] == 'B' && s[k] == 'G'){
			if((k - i + 1) & 1 && s[(i + k) /2] == 'R')ans --;
			ans += sum[k - 1][1] - sum[i][1];
		}
		if(s[i] == 'R' && s[k] == 'G'){
			if((k - i + 1) & 1 && s[(i + k) /2] == 'B')ans --;
			ans += sum[k - 1][3] - sum[i][3];
		}
		if(s[i] == 'G' && s[k] == 'R'){
			if((k - i + 1) & 1 && s[(i + k) /2] == 'B')ans --;
			ans += sum[k - 1][3] - sum[i][3];
		}
	}
	cout<<ans<<endl;
}
int main(){
	solved();
	return 0;
} 


Measured memory_bytes: 3772
#include<stdio.h>;

int main(void)
{
	int n,i;
	int count = 0;
	int numbers[201];

	scanf("%d", &n);
	for (i = 0;i < n; i++) 
	{
		scanf("%d", &numbers[i]);
	}
	while (1) {

		for (i = 0;i < n; i++)
		{
			if ((numbers[i] % 2) == 0)
			{
				numbers[i] = numbers[i] / 2;
			}
			else
			{
				printf("%d", count);
				return 0;
			}
		}
		count++;
	}
	
	
}

Measured memory_bytes: 128
import Control.Applicative
import Control.Monad

printFrame :: Int -> Int -> IO()
printFrame h w = do
    putStrLn $ replicate w '#'
    replicateM_ (h - 2) (putStrLn $ ("#" ++ (replicate (w - 2) '.') ++ "#"))
    putStrLn $ replicate w '#'

main :: IO()
main = do
    args <- (map (read :: String -> Int) . words) <$> getLine
    if (args == [0, 0])
    then return ()
    else do
        printFrame (args !! 0) (args !! 1)
        putStrLn ""
        main

Measured memory_bytes: 4124
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T;
  cin >> S;
  cin >> T;
  
  int A, B;
  cin >> A;
  cin >> B;
  
  string U;
  cin >> U;
  
  if(S == U){
    A--;
  }
  
  else{
    B--;
  }
  
  cout << A;
  cout << " ";
  cout << B << endl;
}

Measured memory_bytes: 256
/**
 *    author:  math2do
 *    created: 20.04.2020 15:02:47 IST
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector <int> arr(m);
  for (int &v : arr) {
    cin >> v;
  } 
  int sum = accumulate(arr.begin(), arr.end(), 0);
  cout << (sum <= n ? n - sum : -1) << endl;
  return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  deque<int> ans;
  if (n == 0) cout << 0 << endl;
  else {
    while (n != 0) {
      ans.push_front(abs(n%2));
      if (ans.front() == 1) {
        n--;
      }
      n /= -2;
    }
    for (int i = 0; i < (int) ans.size(); i++) {
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
k,a,b = (int(i) for i in input().split())
yen = 0
bisc = 1
kouritu = b/a
#最後にaが多ければいい
tmp1 = 1+k
tmp2 = 0
#交換してた方がお得か？
if k+1-a >= 0 and a<= b:
 kaisuu = (k-a+1)//2
 sabun =  (k-a-1)%2 #最後にbiscに加える
 tmp2 = a + kaisuu*(b-a) +sabun
print(max(tmp1,tmp2))

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
 
int main()
{
  int a,b,c; cin >> a >> b >> c;
  if(a>=b && a>=c) a *= 10;
  else if(b>=a && b>=c) b *=10;
  else c*=10;
  cout << a+b+c << endl;
}

Measured memory_bytes: 256
implicit none
integer(8):: n,y,i,j,count,s_len
character(10**5+5)::s,s_rev
character(5)::a
character(5)::b
character(6)::c
character(7)::d
 
a="maerd"
b="esare"
c="resare"
d="remaerd"
 
s_rev=""
 
read(5,*) s
s_len=len_trim(s)
 
do i=1,s_len
    s_rev(s_len+1-i:s_len+1-i)=s(i:i)
enddo
 
!write(6,*) trim(s_rev)
 
count=1
 
do while (count<=s_len)
 
    
    if (index(s_rev,a)==1) then
        count=count+len(a)
        s_rev=s_rev(len(a)+1:) 

    else if (index(s_rev,b)==1) then
        count=count+len(b)
        s_rev=s_rev(len(b)+1:)

    else if (index(s_rev,c)==1) then
        count=count+len(c)
        s_rev=s_rev(len(c)+1:)

    else if (index(s_rev,d)==1) then
        count=count+len(d)
        s_rev=s_rev(len(d)+1:)

    else 
        write(6,*) "NO"
        goto 100
        
    endif

    
enddo
 
write(6,*) "YES"
 
100 end

Measured memory_bytes: 828