akhauriyash/Code-Regression huggingface dataset:
#include<set>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
//#define scanf scanf_s
#define fir first
#define sec second
#define mp make_pair
#define mt make_tuple
#define pub push_back
using namespace std;
typedef long long int llint;
const llint one = 1;
const llint big = (one<<30);
const llint mod=1000000007;

int N,K,gen,root;
vector<double> uans;
vector<double> dans;
vector<set<int>> ko;
vector<int> oya;
void make_tree(int per,int ter){
	ko[ter].erase(per);
	for(auto it=ko[ter].begin();it!=ko[ter].end();it++){
		make_tree(ter,*it);
	}
}
double find_dans(int ter){
	double ans=0;
	if(ko[ter].size()==0){return 0;}
	for(auto it=ko[ter].begin();it!=ko[ter].end();it++){
		ans+=find_dans(*it);
	}
	ans/=ko[ter].size();
	ans+=1;
	dans[ter]=ans;
	return ans;
}
void find_uans(int per,int ter){
	
	if(ter==root){uans[ter]=dans[ter];}
	else if(per==root){uans[ter]=((dans[per]*ko[per].size())-dans[ter]-1)/(ko[per].size()-1)+1;}
	else{ uans[ter]=((dans[per]*ko[per].size()-dans[ter]-1)+uans[per])/ko[per].size()+1; }
	for(auto it=ko[ter].begin();it!=ko[ter].end();it++){find_uans(ter,*it);}
}
int main(void){
	int i,j,a,b;
	double ans;
	scanf("%d",&N);
	if(N==1){
		printf("0\n");
		return 0;
	}
	if(N==2){
		printf("1.0\n1.0\n");return 0;
	}
	uans.resize(N);
	dans.resize(N);
	ko.resize(N);
	oya.resize(N);
	for(i=1;i<N;i++){
		scanf("%d %d",&a,&b);
		a--;b--;
		ko[a].insert(b);
		ko[b].insert(a);
	}
	root=0;a=0;
	if(ko[a].size()==1){root=*ko[a].begin();}
	make_tree(-1,root);
	find_dans(root);
	find_uans(-1,root);
	for(i=0;i<N;i++){
		if(i==root){ans=dans[i];}
		else{ans=(dans[i]*ko[i].size()+uans[i])/(ko[i].size()+1);}
		printf("%lf\n",ans);
	}
	return 0;
}


Measured memory_bytes: 31488
import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Scanner;

/**
 * Created by Harry on 5/3/20.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        int x = scanner.nextInt();
        HashMap<Integer, Long> map = new HashMap<>();
        for(int i=-1000; i<=1000; i++){
            map.put(i, (long)Math.pow(i, 5));
        }
        calc:
        for(int cur=-1000; cur<=1000; cur++){
            for(int other: map.keySet()){
                if(map.get(cur)-map.get(other)==x){
                    System.out.println(cur+" "+other);
                    break calc;
                }
            }
        }
    }
}


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

#define int long long

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

int N, K;
int A[4000], B[4000];
vector<int> G[4001];

signed main() {
    cin >> N >> K;
    for (int i = 1; i < N; i++) {
        cin >> A[i] >> B[i];
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }
    int ans = LLONG_MAX;
    if (K % 2 == 0) {
        for (int i = 1; i <= N; i++) {
            bool used[4001] = {};
            used[i] = true;
            stack<pair<int, int> > stk;
            stk.push(make_pair(i, 0));
            int cur = 0;
            while (!stk.empty()) {
                pair<int, int> x = stk.top();
                stk.pop();
                if (x.second > K / 2) {
                    cur++;
                }
                for (int j = 0; j < G[x.first].size(); j++) {
                    if (!used[G[x.first][j]]) {
                        stk.push(make_pair(G[x.first][j], x.second + 1));
                        used[G[x.first][j]] = true;
                    }
                }
            }
            ans = min(cur, ans);
        }
    } else {
        for (int i = 1; i < N; i++) {
            bool used[4001] = {};
            used[A[i]] = true;
            used[B[i]] = true;
            stack<pair<int, int> > stk;
            stk.push(make_pair(A[i], 0));
            stk.push(make_pair(B[i], 0));
            int cur = 0;
            while (!stk.empty()) {
                pair<int, int> x = stk.top();
                stk.pop();
                if (x.second > (K - 1) / 2) {
                    cur++;
                }
                for (int j = 0; j < G[x.first].size(); j++) {
                    if (!used[G[x.first][j]]) {
                        stk.push(make_pair(G[x.first][j], x.second + 1));
                        used[G[x.first][j]] = true;
                    }
                }
            }
            ans = min(cur, ans);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#!/usr/bin/ruby

def solve(t, x)
  t.to_f / x
end

def each_case(str)
  str.each_line
    .map {|ln| 
      ln.chomp.split(/\s+/).map(&:to_i)
    }
    .each {|t, x| yield t,x }
end

each_case(STDIN.read) do |t, x|
  puts solve(t, x).to_s
end



Measured memory_bytes: 2044
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N = int(input())
a = []
for _ in range(N): a.append(int(input()))
res = a[0] - 1
a[0] = 1
mx = 1
mxa = max(a)
for i in range(N - 1):
  mx = max(mx, a[i])
  t = (a[i + 1] - 1) // (mx + 1)
  ok = mx + 1
  ng = mxa
  while ng - ok > 1:
    m = (ok + ng) // 2
    if (a[i + 1] - 1) // m == t: ok = m
    else: ng = m
  if t > 0: a[i + 1] = 1
  res += t
  #print(res, mx)
  #print(a)
print(res)

Measured memory_bytes: 44892
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
#define mst(a,x) memset(a,x,sizeof(a))
#define qwq (cerr<<"qwq"<<endl)
#define orz(x) (cerr<<#x": "<<x<<endl)
#define orzarr(a,n) {cerr<<#a": "; repeat(__,0,n)cerr<<(a)[__]<<" "; cerr<<endl;}
#define orzeach(a) {cerr<<#a": "; for(auto __:a)cerr<<__<<" "; cerr<<endl;}
#define fi first
#define se second
typedef long long ll; const int inf=~0u>>2; const ll INF=~0ull>>2; ll read(){ll x; if(scanf("%lld",&x)==-1)exit(0); return x;}
typedef double lf; typedef long double llf; const lf err=1e-11; const lf pi=acos(-1); lf readf(){lf x; if(scanf("%lf",&x)==-1)exit(0); return x;} template<typename T> T sqr(const T &x){return x*x;}
typedef pair<int,int> pii; template<typename A,typename B> ostream &operator<<(ostream &o,const pair<A,B> &x){return o<<'('<<x.fi<<','<<x.se<<')';}
//mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=110;
const int mod=(1?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;} ll getinv(ll v,ll m=mod){return qpow(v,m-2,m);}
//#define int ll
char s[N][N];
int dp[N][N];
signed main(){
	//ios::sync_with_stdio(0); cin.tie(0);
	int n,m;
	cin>>n>>m;
	repeat(i,0,n)cin>>s[i];
	repeat(i,0,n)
	repeat(j,0,m){
		int &x=dp[i][j];
		x=(i+j==0?0:inf);
		if(i>0){
			x=min(x,dp[i-1][j]+(s[i][j]!=s[i-1][j]));
		}
		if(j>0){
			x=min(x,dp[i][j-1]+(s[i][j]!=s[i][j-1]));
		}
	}
	cout<<dp[n-1][m-1]/2+(s[0][0]=='#' || s[n-1][m-1]=='#');
	return 0;
}

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

#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  string s; cin >> s;
  map<char,int> mp;

  rep(i, 4) ++mp[s[i]];
  if (si(mp) != 2) {
    cout << "No" << endl;
    return (0);
  }

  for (auto e : mp) {
    if (e.se != 2) {
      cout << "No" << endl;
      return (0);
    }
  }

  cout << "Yes" << endl;
  
  return (0);
}

Measured memory_bytes: 3628
import java.io.*;
import java.util.*;

public class Main {
	static int mod = (int)1e9+7;
	static Comparator<Integer> lower_bound = (x, y) -> x.compareTo(y) >= 0 ? 1 : -1;
	static Comparator<Integer> upper_bound = (x, y) -> x.compareTo(y) > 0 ? 1 : -1;

	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		out.println((int)Math.ceil(n/(d*2d+1d)));
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}

	public static long factorial(int n) {
		long a;

		if(n > 0) {
			a = n * factorial(n - 1);
		}else{
			a = 1;
		}

		return a;
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(K key, V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class UnionFind {
	int[] par;

	public UnionFind(int n) {
		par = new int[n];

		Arrays.fill(par, -1);
	}

	int root(int x) {
		if(par[x] < 0) return x;
		return par[x] = root(par[x]);
	}

	boolean unite(int x,int y) {
		x = root(x);
		y = root(y);

		if(x == y) return false;

		if(size(x) < size(y)) {
			int tmp = x;
			x = y;
			y = tmp;
		}

		par[x] += par[y];
		par[y] = x;

		return true;
	}

	boolean same(int x,int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}

	int size(int a) {
		return -par[root(a)];
	}
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

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

 using namespace std;
  vector<int> G[101];
  bool V[101]={};
   int N;
   int Ans = 0;
  void DFS(int n,int len){
      Ans = max(Ans,len);
    bool Vis = false;
   int S = G[n].size();
   for(int i=0;i<S;i++){
    if(!V[G[n][i]]){
        Vis = true;
        V[G[n][i]] = true;
        DFS(G[n][i],len+1);
        V[G[n][i]] = false;
    }
   }
   return;
  }
  int main(){
      do{
   for(int i=0;i<101;i++){
    G[i].clear();
    V[i] = false;
   }
   Ans = 0;
   scanf("%d",&N);
   if(N==0)break;
   for(int i=0;i<N;i++){
    int A,B;
    scanf("%d%d",&A,&B);
    G[A].push_back(B);
    G[B].push_back(A);
   }

   for(int i=1;i<=100;i++){
    V[i] = true;
    DFS(i,1);
    V[i] = false;
   }
   printf("%d\n",Ans);
      }while(true);
  }

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;
 
typedef long long lo;
 
template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
#define db long double
const db pi = acos(-1.);
const int N = 4444;
int n, L; db t[N];

int main(void) {
	read(n); read(L);
	rep (i, n) scanf("%Lf", &t[i]), t[i] = t[i] * 2 * pi / L;
	db X = 0., Y = 0.;
	rep (i, n) rep (j, i - 1) {
		int in = i - j - 1, out = n - 2 - in;
		db per = (t[i] + t[j]) / 2.;
		X += cos(per) * (out - in); Y += sin(per) * (out - in);
	}
	db all = (db) n * (n - 1) * (n - 2) / 6;
	printf("%.10Lf %.10Lf\n", X / all, Y / all);
		
}


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

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

    ll ans = 0;
    int k = n - 1;
    for(int i = 1; i < n; i++){
        ans += k / i;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	long long n, k;

	std::cin >> n >> k;

	std::vector<long long> v(n);

	for (long long i = 0; i < n; i++)
	{
		std::cin >> v[i];
	}

	std::sort(v.begin(), v.end());
	std::reverse(v.begin(), v.end());

	long long ans = 1000000000000000000LL;

	for (size_t i = 0; i + k - 1 < n; i++)
	{
		ans = std::min(ans, v[i] - v[i + k - 1]);
	}

	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 1024
import sys
import math

a, b, h, m = tuple(map(int, sys.stdin.buffer.read().split()))

mm = m / 60
hh = (h + mm)  / 12
r = (mm - hh) * math.pi * 2

print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(r)))

Measured memory_bytes: 9460
N=int(input())
flg=True
L=list(map(int,input().split()))

for i in range(N):
    if L[i]%2==0 and (L[i]%3!=0 and L[i]%5!=0):
        flg=False
        break
if flg:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#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;

typedef long long ll;

typedef tree<
pair <int, int>,
null_type,
less<pair <int, int>>,
rb_tree_tag,
tree_order_statistics_node_update>
os;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

int main() {
  int n; cin >> n;
  vector <int> dp(n + 1, 1e9);
  dp[0] = 0;
  set <int> coins;
  coins.insert(1);
  for(int i : {6, 9}) {
    int p = i;
    while(p <= n) {
      coins.insert(p);
      p *= i;
    }
  }
  for(int i = 1; i <= n; i++) {
    for(auto x : coins) {
      if(i - x < 0) continue;
      dp[i] = min(dp[i], dp[i - x] + 1);
    }
  }
  cout << dp[n] << '\n';
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int N;
int Y;

int main() {
	cin >> N >> Y;

	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N - i; j++) {
			if (i * 10000 + j * 5000 + (N - i - j) * 1000 == Y) {
				cout << i << " " << j << " " << (N - i - j) << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define   ull unsigned long long 
#define mp make_pair
#define pb push_back
const int MAX=2e5+9;
const long long mod=1e9+7;
using namespace std;
vector<int>adj[MAX];
int d[MAX];
int deg[MAX];
void dfs(int x, int y){
	d[x]=y;
	for(int i=0;i<adj[x].size();i++){
		if(d[adj[x][i]]==0){
			dfs(adj[x][i] , y+1);
			if(deg[adj[x][i]]%2==0){
				deg[x]++;
				cout<<x+1<<" "<<adj[x][i]+1<<"\n";
			}
			else{
				deg[adj[x][i]]++;
				cout<<adj[x][i]+1<<" "<<x+1<<"\n";
			}
		}
		else if(d[adj[x][i]]>d[x]){
			deg[x]++;
			cout<<x+1<<" "<<adj[x][i]+1<<"\n";
		}

	}
}

int main(){
	int n , m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x, y;
		cin>>x>>y;
		x--;
		y--;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	if(m%2){
		cout<<-1;
	}
	else
	{
		dfs(0, 1);
	}
}

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

using namespace std;

int main() {

    int W, H, x, y, r;

    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

    if(((y - r) >= 0 && (x - r) >= 0) && ((y + r) <= H && (x + r) <= W)) {
            
        printf("Yes\n");

    } else {

        printf("No\n");

    }

    return 0;
}


Measured memory_bytes: 2696
N, M = map(int, input().split())
s = []
for i in range(M):
    s.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))

ans = 0
for i in range(2**N):   # sw status bit
    #print("ptn="+str(i))
    mismatch = False
    for j in range(M):  # check each bulb
        num = 0 # num of sw=on
        for sw in s[j]:
            num += ((i >> (sw - 1)) & 1)
        #print("bulb no = {}, sw_on={}, bulb_on={}".format(j, num, num%2 == p[j]))
        if num % 2 != p[j]:
            mismatch = True
            break
    if mismatch:
        continue
    ans += 1

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll n; cin >> n;
    if(n%2==1){
        cout << 0 << endl;
        return 0;
    }

    ll cnt = 0;
    ll x = 5;
    while(x <= n){
        cnt += n / x / 2;
        x *= 5;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	String s = sc.next();
	int count = 0;
	int t = s.length() / 2;
	for (int i=0; i<t; i++) {
	    if (s.charAt(i) != s.charAt(s.length()-1-i)) {
		count++;
	    }
	}
	System.out.print(count);
    }
}


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

using namespace std;

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

P merge(P a,P b) {
  P ret;
  int c[4] = {a.first,a.second,b.first,b.second};
  sort(c,c+4);
  ret.first = c[3];ret.second = c[2];
  return ret;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(1 << n,0);
  vector<P> ans(1 << n);
  for (int i = 0;i < (1 << n);++i) {
    cin >> a[i];
    ans[i].first = a[i];
  }

  for (int i = 0;i < n;++i) for (int j = 0;j < (1 << n);++j) if (j&(1 << i)) ans[j] = merge(ans[j],ans[j^(1 << i)]);

  int m = 0;
  for (int i = 1;i < (1 << n);++i) {
    m = max(ans[i].first+ans[i].second,m);
    cout << m << endl;
  }
  return 0;
}

Measured memory_bytes: 6144
import math
from typing import NoReturn


def main() -> NoReturn:
    a, b, h, m = map(int, input().split())  # type: int, int, int, int

    diag: float = (5.5 * (60 * h + m)) % 360

    if diag == 180:
        print(a + b)
        return
    elif diag > 180:
        diag = 360 - diag

    answer: float = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(diag / 180 * math.pi))
    print(answer)


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    set<int> s;
    s.insert(n);
    for (int i = 2; ;++i) {
        if (n & 1) n = 3*n+1;
        else n /= 2;
        if (s.count(n)) {
            cout << i << endl;
            return 0;
        }
        s.insert(n);
    }
    return 0;
}


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

int main(){
	int n;
	cin>>n;
	vector<int>arr(n+1,0);
	for(int i=1; i<=n; i++) cin>>arr[i];
	vector<int>temp(arr.begin(),arr.end());
	sort(arr.begin(),arr.end());
	int mid = n/2;
	for(int i=1; i<=n; i++){
		if(temp[i]<=arr[mid]) cout<<arr[mid+1]<<'\n';
		else cout<<arr[mid]<<'\n';
	}
}

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

int main(){
  int a,b,c;cin >> a >> b >> c;
  int result = 0;
  if(a == 5){
    ++result;
  }if(b == 5){
    ++result;
  }if(c == 5){
    ++result;
  }

  if(result == 2){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  }


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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 505;
const long long INF = 0x3f3f3f3f3f3f3f3fll;

int n;
int a[N][N];
long long s1[N][N], s2[N][N], f[N][N];

long long getsum(long long s[N][N], int sx, int sy, int tx, int ty) {
	return s[tx][ty] - s[sx][ty] - s[tx][sy] + s[sx][sy];
}

int main() {
	read(n);
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			if (i != j) {
				read(a[i][j]);
			}
			s1[i][j] = s1[i - 1][j] + s1[i][j - 1] - s1[i - 1][j - 1] + (i < j ? a[i][j] : 0);
			s2[i][j] = s2[i - 1][j] + s2[i][j - 1] - s2[i - 1][j - 1] + (i > j ? a[i][j] : 0);
		}
	}
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= i; ++j) {
			f[i][j] = INF;
		}
	}
	f[0][0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j <= i; ++j) {
			for (int k = i + 1; k <= n; ++k) {
				f[k][i] = std::min(f[k][i], f[i][j] + getsum(s1, i, i, k, k) + getsum(s2, i, 0, k, j));
			}
		}
	}
	long long ans = INF;
	for (int i = 0; i < n; ++i) {
		ans = std::min(ans, f[n][i]);
	}
	print(ans);
}


Measured memory_bytes: 12808
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sidha(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int> 
#define pb push_back
#define mod 1000000007

int solve(int n){
	int dp[n+1];
	dp[0]=0;
	dp[1]=1;
	for(int i=2;i<n+1;i++){
		dp[i]=(dp[i-1]+dp[i-2])%mod;
	}
	return dp[n];
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
	int n,m;cin>>n>>m;
	vector<int> arr(n+1,true);
	for(int i=0;i<m;i++){
		int a;cin>>a;
		arr[a]=false;
	}
	vector<ll> dp(n+1);
	dp[0]=1;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<=min(n,i+2);j++){
			if(arr[j]){
				dp[j]+=dp[i];
				dp[j]%=mod;
			}
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 4484
#include <stdio.h>
char str[1025];
char ans[53];
int min(int a, int b) {
	if(a > b) return b;
	return a;
}
int max(int a, int b) {
	if(a > b) return a;
	return b;
}
int main() {
	int I, N;
	scanf("%d", &N);
	for(I = 0; I < N; ++ I) {
		scanf("%s", str);
		int n = 26;
		int Mi = 26, mi = 26;
		int i;
		for(i = 0; ;) {
			ans[n] = str[i];
			if(str[i + 1] == '-') {
				n ++;
				Mi = max(Mi, n);
				i += 3;
			} else if(str[i + 1] == '<') {
				n --;
				mi = min(mi, n);
				i += 3;
			} else {
				break;
			}
		}
		ans[Mi + 1] = 0;
		printf("%s\n", ans + mi);
	}
	return 0;
}

Measured memory_bytes: 588
n = int(input())

lis = [111,222,333,444,555,666,777,888,999]

for i in range(len(lis)):
    if n < 111:
        print(111)
        break
    elif lis[i] == n:
        print(lis[i])
        break
    elif lis[i] < n and lis[i+1] > n:
        print(lis[i+1])
        break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
using namespace std;
const int N=5005;
const int mo=1000000007;
int n,m;
int f[N][N];
int g[N][N];
int main(){
	scanf("%d%d",&n,&m);
	For(i,1,m) f[0][i]=1;
	For(i,1,n) For(j,1,m){
		g[i-1][j]=(2*g[i-1][j-1]+1ll*f[i-1][j]*j)%mo;
		f[i][j]=(1ll*f[i-1][j]*(j+1)+g[i-1][j-1])%mo; 
	}
	printf("%d\n",f[n][m]);
}

Measured memory_bytes: 199308
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();

        String asStringN = String.valueOf(n);
        int length = asStringN.length();
        int sum = 0;
        for(int k = 1; k < length;k=k+2) {
          sum += 9*Math.pow(10,k-1);
        }
        if(length % 2 != 0) {
          sum += n-Math.pow(10, length-1) + 1;
        }
        
        System.out.println(sum);
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
const int dx[] = { -1 , -1 , -1 , 0 , 0 , 0 , 1 , 1 , 1 };
const int dy[] = { -1 , 0 , 1 , -1 , 0 , 1 , -1 , 0 , 1 };
#define N 8010000
#define TC int t;cin>>t;for(int T=1;T<=t;T++)
#define mod 1000000007
#define PI acos(-1)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
void AIA() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isprim(int x){
	for(int j=2;j*j<=x;j++){
		if(x%j==0){
			return 0;
		}
	}
	return (x!=1);
}

//cout<<fixed<<setprecision(20);
// freopen("stand.in","r",stdin);
// freopen("stand.out","w",stdout);

/*
 _____________              __                ___        ___       __________________________     ____        ____
|             |            /\ \              |   |      |   |     |                          |    \   \      /   /
|   __________|           / /\ \             |   |      |   |     |     _____      _____     |     \   \    /   /
|  |                     / /  \ \            |   |      |   |     |    |     |    |     |    |      \   \  /   /
|  |                    / /    \ \           |   |      |   |     |    |     |    |     |    |       \   \/   /
|  |______             / /      \ \          |   |______|   |     |    |     |    |     |    |        \      /
|         |           / /        \ \         |              |     |    |     |    |     |    |         \    /
|   ______|          / /          \ \        |    ______    |     |    |     |    |     |    |          |  |
|  |                / /============\ \       |   |      |   |     |    |     |    |     |    |          |  |
|  |               / /==============\ \      |   |      |   |     |    |     |    |     |    |          |  |
|  |              / /                \ \     |   |      |   |     |    |     |    |     |    |          |  |
|  |             / /                  \ \    |   |      |   |     |    |     |    |     |    |          |  |
|__|            /_/                    \_\   |___|      |___|     |____|     |____|     |____|          |__|

							<<<<<<<<<<< NEVER GIVE UP !! >>>>>>>>>>>
							<<<<<<<< YOU CAN DO IT IF YOU WANT !! >>>>>>>>
							<<<<<<<<< BELIEVE IN YOURSELF !! >>>>>>>>>

*/

int main()
{
	//cout<<fixed<<setprecision(20);
	//freopen("stand.in","r",stdin);
	//freopen("stand.out","w",stdout);
	AIA();
	int arr[5];
	for(int i=0;i<5;i++){
		cin>>arr[i];
		if(arr[i]==0){
			cout<<i+1;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3584
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
S=sum(A)
for i in range(N):
    if A[i]<B[i]:
        B[i]-=A[i]
        A[i]=0
        A[i+1]=max(0,A[i+1]-B[i])
    else:
        A[i]-=B[i]
print(S-sum(A))

Measured memory_bytes: 18476
#include <iostream>

using namespace std;

int main() {
    int x;
    int y;
   cin>>x;
   cin>>y;
   if(x>y)
   {
       for(int i=0;i<x;i++)
       {
           cout<<y;
       }
       cout<<endl;
   }
   else
   {
       for(int i=0;i<y;i++)
       {
           cout<<x;
       }
   }
}

Measured memory_bytes: 256
while True:
  x = []
  x = input()
  if x=="-":
    break
  else:
    m = int(input())
    for i in range(m):
      h = int(input())
      x_list = list(x)
      y = x_list[0:h]
      del x_list[:h]
      x_list += y
      x = "".join(x_list)
    print(x)



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  double n,m,d,ans=0;
  cin>>n>>m>>d;
  if(d>=n)cout<<0<<endl;
  else{
    ans=((n-d)*2/(n*n))*(m-1);
    if(d==0)ans/=2.0;
    printf("%.10lf\n",ans);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int l = s.size();
	char ini = s[0], fin = s[l-1];
	bool x,y;
	x = (l+1)%2;
	y = ini==fin;
	if(x^y){
		cout << "Second" <<endl;
	}else{
		cout << "First" << endl;
	}
}


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

int main(void)
{
	int num, minj, tmt, i, j, n = 0;
	int a[200];

	scanf("%d", &num);

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

	for (i = 0; i < num; i++) {
		minj = i;
		for (j = i; j < num; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		tmt = a[i];
		a[i] = a[minj];
		a[minj] = tmt;

		if (minj != i) {
			n++;
		}

	}
	
	for (i = 0; i < num; i++) {
		printf("%d", a[i]);

		if (i != num - 1) {
			putchar(' ');
		}
		else {
			putchar('\n');
		}
	}

	printf("%d\n", n);

	return 0;
}


Measured memory_bytes: 2140
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt(), y = sc.nextInt(), z = sc.nextInt(), k = sc.nextInt();
        long[] a = new long[x], b = new long[y], c = new long[z];
        for (int i = 0; i < x; i++) {
            a[i] = sc.nextLong();
        }
        for (int i = 0; i < y; i++) {
            b[i] = sc.nextLong();
        }
        for (int i = 0; i < z; i++) {
            c[i] = sc.nextLong();
        }
        long[] ab = new long[(int)1e6];
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < y; j++) {
                ab[i + y * j] = a[i] + b[j];
            }
        }
        Arrays.sort(ab);
        PriorityQueue<Long> pq = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < Math.min(x * y, k); i++) {
            for (int j = 0; j < z; j++) {
                pq.add(ab[(int)1e6-1-i] + c[j]);
            }
        }
        for (int i = 0; i < k; i++) {
            System.out.println(pq.poll());
        }
    }
}


Measured memory_bytes: 154256
N = int(input())
S = input()

s = list(S)

max = 0
for i in range(1,N-1):
    count = 0
    X = s[0:i]
    Y = s[i:N]
    x = list(set(X))
    y = list(set(Y))
    for j in x:
        if j in y:
            count += 1

    if count > max:
        max = count

print(max)

Measured memory_bytes: 3064
n = gets.chomp.to_i

i = 1
max_count = 0
max_num = 1

while i <= n
    count = 0
    a = i
    while a.even? && a != 0
        count += 1
        a = a / 2
    end
    if max_count < count
        max_count = count
        max_num = i
    end
    i += 1
end

puts max_num

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

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

string s;
map<char, bool> hm;

typedef string::const_iterator State;
class ParseError{};

template<typename T> class Parsing
{
public:
  static void consume(State& begin, char expected) {
    if (*begin == expected) {
      begin++;
    } else {
      cerr << "Expected '" << expected << "' but got '" << *begin << "'"
           << endl;
      cerr << "Rest string is '";
      while (*begin) {
        cerr << *begin++;
      }
      cerr << "'" << endl;
      throw ParseError();
    }
  }

  static T equation(State& begin){
    T v = formula(begin);    consume(begin, '=');
    T w = formula(begin);
    return v == w;
  }

  static T formula(State& begin){
    T ret;
    if(*begin == '-'){
      consume(begin, '-');
      ret = !formula(begin);
    }
    else if(isalpha(*begin)){
      ret = number(begin);
    }
    else if(*begin == '('){
      consume(begin, '(');
      ret = formula(begin);
      if(*begin == '+'){
        consume(begin, '+');
        ret = formula(begin) || ret;
      }
      else if(*begin == '*'){
        consume(begin, '*');
        ret = formula(begin) && ret;
      }
      else if(*(begin+1) == '>'){
        consume(begin, '-');
        consume(begin, '>');
        T t = formula(begin);
        ret = (t && ret) || !ret;
      }
      consume(begin, ')');
    }
    return ret;
  }

  static T number(State& begin){
    return hm[*(begin++)];
  }
};

int main()
{
  while(getline(cin, s), s != "#"){
    bool ok = true;
    hm['T'] = true;
    hm['F'] = false;
    rep(i, 1 << 11){
      rep(j, 11) hm['a' + j] = i & 1 << j;
      State begin = s.begin();
      ok &= Parsing<bool>::equation(begin);
      if(!ok) break;
    }
    puts(ok ? "YES" : "NO");
  }

  return 0;
}

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

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>

using namespace std;

int main() {

	int r, g, b, N;
	cin >> r >> g >> b >> N;
	int a = 0;

	for (int i = 0; i <= N; i += r) {
		int N2 = N - i;
		for (int j = 0; j <= N2; j += g) {
			if ((N2 - j) % b == 0) a++;
		}
	}

	cout << a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int n;
int a[100010], b[100010], c[100010];
int dp[100010][3];
int ma = 0;
int main(){
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	for (int j = 0; j < n; j++) {
		for (int k = 0; k < 3; k++) {
			if (k == 0) {
				dp[j][k] += max(dp[j-1][1]+a[j], dp[j-1][2]+a[j]);
			}
			else if (k == 1) {
				dp[j][k] += max(dp[j-1][0]+b[j], dp[j-1][2]+b[j]);
			}
			else {
				dp[j][k] += max(dp[j-1][0]+c[j], dp[j-1][1]+c[j]);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (dp[i][0] > ma) {
			ma = dp[i][0];
		}
		if (dp[i][1] > ma) {
			ma = dp[i][1];
		}
		if (dp[i][2] > ma) {
			ma = dp[i][2];
		}
	}
	cout << ma << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dbg(x) cerr << #x << " : " << x << endl;
int main(){
    int l,r;
    cin >> l >> r;
    if(r-l>=2019){
       cout << 0 << endl;
        return 0;
    }
    l%=2019;
    r%=2019;
    int ans=2019;
    for(int i=l;i<=r;i++){
        for(int j=i+1;j<=r;j++){
            ans=min(ans,i*j%2019);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int n, t, a;
  cin >> n >> t >> a;
  vector<int> h(n);
  REP(i,n) cin >> h[i];

  const int INF = 100000;

  double temp;
  double mabs = INF;
  int pos;

  REP(i,n){
    temp = t - h[i] * 0.006;
    if(abs(a-temp) < mabs){
      pos = i;
      mabs = abs(a-temp);
    }
  }

  ++pos;

  cout << pos << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iterator>

using namespace std;

long long gcd(long long a, long long b){
    if(a < b)
        swap(a,b);
    while(a%b != 0){
        long long c = a%b;
        a = b;
        b = c;
    }
    return b;
}

int main(){
    long long n; cin >> n;
    vector<long long> a(n);
    vector<long long> l(n);
    vector<long long> r(n);
    for(long long i = 0; i< n ;i++){
        cin >> a[i];
    }
    l[0] = a[0];
    r[n-1] = a[n-1];
    for(long long i = 1; i <n;i++){
        l[i] = gcd(l[i-1],a[i]);
    }
    for(long long i = n-2; i >= 0;i--){
        r[i] = gcd(r[i+1],a[i]);
    }
    long long ans = max(r[1],l[n-2]);
    for(long long i = 1; i < n-1;i++){
        long long tmp = gcd(l[i-1],r[i+1]);
        if(tmp > ans)
            ans = tmp;
    }
    cout << ans << endl;
    // for(long long i = 0; i< n ;i++){
    //     cout << a[i] << " " << l[i] << " " << r[i] << endl;
    // }
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int R,S,P;
int p(char c){
  if(c=='r') return P;
  if(c=='p') return S;
  if(c=='s') return R;  
}
int main()
{
  int n,k;cin >> n >> k;
  cin >> R >> S >> P;
  string t;cin >> t;
  int res = 0;
  rep(i,n){
    if(i-k>=0){
      if(t[i-k]==t[i]) t[i] = 'x';
      else res += p(t[i]);
    }
    else res += p(t[i]);
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main()
{
  long long n, k;
  cin >> n >> k;
  long long p[n];
  rep(i, n) { cin >> p[i]; }
  long long max = 0;
  rep(i, k) { max += p[i]; }
  long long sum = max;
  rep(i, n - k)
  {
    sum += p[i + k];
    sum -= p[i];
    if (sum > max)
    {
      max = sum;
    }
  }
  max += k;
  cout << setprecision(15) << max / 2.0 << endl;

  return 0;
}


Measured memory_bytes: 1920
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	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;
	}
	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;
	}
};

int n;

int popcount(int S){
    int res = 0;
    rep(i,n) if(S >> i & 1) res++;
    return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    cin >> n ;
    vector<vector<int>> a(n, vector<int>(n));
    rep(i,n)rep(j,n) cin >> a[i][j];
    vector<mint> dp(1 << n);
    dp[0] = 1;
    rep(S,(1 << n)){
        int idx = popcount(S);
        rep(i,n){
            if(!(S >> i & 1) && a[idx][i] == 1){
                int nextS = S | (1 << i);
                dp[nextS] += dp[S];
            }
        }
    }
    cout << dp[(1 << n)-1].x << endl;
	return 0;
}


Measured memory_bytes: 16640
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
D = np.zeros((10**5)+1)
S = sum(A)
for i in range(len(A)):
    D[A[i]] += 1
Q = int(input())
for _ in range(Q):
    b, c = list(map(int, input().split()))
    S += D[b]*(c-b)
    D[c] += D[b]
    D[b] = 0
    print(int(S))

Measured memory_bytes: 38912
#include<iostream>
using namespace std;
typedef long long ll;
int s[100005]={0};
ll dp[100005]={0};
const ll MOD = 1000000007;
int main(){
    int n,m,a;
    cin>>n>>m;
    for(int i=0;i<m;++i){
        cin>>a;
        s[a]=1;
    }
    dp[0]=1;
    for(int i=0;i<n;++i){
        if(s[i+1]==0) dp[i+1]=(dp[i+1]+dp[i])%MOD;
        if(s[i+2]==0) dp[i+2]=(dp[i+2]+dp[i])%MOD;
    }
    cout<<dp[n]<<endl;
}




Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
	string a, b;
  	cin >> a >> b;
  	int num = stoi(a+b);
  	for(int i = 0; i <= 2000; i++) {
    	if (i*i == num) {
        	cout << "Yes" << endl;
          	return 0;
        }
    }
  	cout << "No" << endl;
    return 0;
}



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


template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v){
    if(!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}
//---------

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> ame(3);
    cin >> ame[0] >> ame[1] >> ame[2];
    sort(ame.begin(), ame.end());
    if(ame[2] == ame[1] + ame[0]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bitset<4000005>mask(1);
int main(){
	int n,sum=0;cin>>n;
	for(int i=0;i<n;i++){
		int x;cin>>x;
		mask|=mask<<x,sum+=x;
	}
	for(int i=sum+1>>1;;i++){
		if(mask.test(i)){cout<<i;break;}
	}
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007



int main() {
    int M, K;
    cin >> M >> K;
    if (M == 0) {
        cout << (K == 0 ? "0 0" : "-1") << endl;
    }
    else if (M == 1) {
        cout << (K == 0 ? "0 0 1 1" : "-1") << endl;
    }
    else {
        int x = pow(2, M);
        if (K >= x) cout << "-1" << endl;
        else {
            vi a;
            for (int i = 0 ; i < x ; i++) {
                if (i == K) continue;
                a.pb(i);
            }
            a.pb(K);
            for (int i = x - 1; i >= 0; i--) {
                if (i == K) continue;
                a.pb(i);
            }
            a.pb(K);

            rep(i,2*x){
                cout << a[i] << " ";
            }
            cout << endl;
        }

    }

}


Measured memory_bytes: 2932
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
using ll = long long;


int main(){
    double r; cin >> r;
    double pi = 3.141592;
    double ans = 2* r * pi;
    cout << ans << endl;

    return 0;
}



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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

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

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

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int a, b, c;
	cin >> a >> b >> c;

	if(a == b) cout << c << endl;
	else if(a == c) cout << b << endl;
	else if(b == c) cout << a << endl;

	return 0;
}

Measured memory_bytes: 256