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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define fi first
#define se second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr ll MOD = 1000000007;

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

ll dp[2][100005];

int main(int argc, char* argv[]) {
  string l;
  cin >> l;
  int s = sz(l);

  Fill(dp, 1LL);
  rep(i, 0, 2) rep(j, 1, s + 1) {
    if (i == 0) {
      dp[0][j] = (dp[0][j - 1] * (l[j - 1] == '1' ? 2 : 1)) % MOD;
      continue;
    }

    if (j == 1) continue;
    dp[1][j] = (dp[1][j - 1] * 3) % MOD;
    if (l[j - 1] == '0') continue;
    dp[1][j] = (dp[1][j] + dp[0][j - 1]) % MOD;
  }

  cout << ((dp[0][s] + dp[1][s]) % MOD) << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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 <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    
    int a, b;
    cin >> a >> b;
    
    string u;
    cin >> u;
    
    if(s == u) {
        cout << a - 1 << " " << b << endl;
    }
    else {
        cout << a << " " << b - 1 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a, b, c,n=0;
	cin >> a >> b >> c;
	for(int i = 0; i < 10000; i++){
		if ((b*i+c) % a == 0){
			cout<<"YES";
			return 0;
		}
	}
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
L,R = map(int,input().split())

x = R - L
if x > 2018:
  ans = 0
else:
  ans = 2019
  for i in range(L,R+1):
   for j in range(i+1,R+1):
     ans = min(ans,(i*j)%2019)
     if ans == 0:
       break

print(ans)
    
#332701087 1753412895


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll MOD = 1000000007;
const int MN = 310;

inline void add(ll &x, ll y) { x += y; if (x >= MOD) x -= MOD; }

ll dp[MN][MN][MN];
vector<pii> cond[MN];

bool ok(int r, int i, int j, int k)
{
	bool ok = 1;

	for (pii c : cond[r]) {
		int cnt = 0;
		if (i-1 >= c.fi) {
			++cnt;
		}
		if (j-1 >= c.fi) {
			++cnt;
		}
		if (k-1 >= c.fi) {
			++cnt;
		}
		if (cnt != c.se) {
			return false;
		}
	}
	return true;
}

int main() {
	int N, M;
	cin >> N >> M;

	rep(i, M) {
		int l, r, x;
		cin >> l >> r >> x;
		--l; --r;
		cond[r].eb(l, x);
	}

	dp[0][0][0] = 1;
	ll ret = 0;

	rep(i, N+1) {
		rep(j, N+1) {
			rep(k, N+1) {
				int nx = max({i, j, k});
				if (nx == N) {
					add(ret, dp[i][j][k]);
					continue;
				}

				if (ok(nx, nx+1, j, k)) {
					add(dp[nx+1][j][k], dp[i][j][k]);
				}

				if (ok(nx, i, nx+1, k)) {
					add(dp[i][nx+1][k], dp[i][j][k]);
				}

				if (ok(nx, i, j, nx+1)) {
					add(dp[i][j][nx+1], dp[i][j][k]);
				}				
			}
		}
	}

	cout << ret << endl;

	return 0;
}

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

using namespace std;

#define int long long
#define INF 1e9
#define LINF 1e18

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

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

    int N;
    cin >> N;
    P blue[100], red[100];
    for(int i = 0; i < N; ++i) cin >> red[i].second >> red[i].first;
    for(int i = 0; i < N; ++i) cin >> blue[i].first >> blue[i].second;

    sort(red, red + N, greater<P>());
    sort(blue, blue + N);
    bool used[100] = {false};
    int res = 0;
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            if(red[j].second < blue[i].first && red[j].first < blue[i].second && !used[j]) {
                ++res;
                used[j] = true;
                break;
            }
        }
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

//#define FILE_IO
#define x first
#define y second

typedef long double LD;
typedef pair<LD, LD> point;

const LD eps = 1e-7;

int n, m, q;
point v[105], r[105], bck[105];
int stv[105];
map<point, LD> mp;

LD det(point A, point B, point C)
{
    LD r = A.x * B.y - A.y * B.x + B.x * C.y - C.x * B.y + C.x * A.y - A.x * C.y;
    return r;
}

vector<point> convexHull()
{
    int i;
    cin >> n;

    if(n == 1)
    {
        cout << 1.0;
        exit(0);
    }
    if(n == 2)
    {
        cout << 0.5 << "\n" << 0.5;
        exit(0);
    }

    for(int i = 1; i <= n; i++)
        cin >> v[i].x >> v[i].y;
    for(int i = 1; i <= n; i++) bck[i] = v[i];
    sort(v + 1, v + n + 1);
    m = 2;
    stv[1] = 1;
    stv[2] = 2;
    for(i = 3; i <= n; i++)
    {
        while(m > 1 && det(v[ stv[m - 1] ], v[ stv[m] ], v[i]) < eps)
            m--;
        stv[++m] = i;
    }

    q = m;
    for(i = 1; i <= q; i++)
        r[i] = v[ stv[i] ];

    m = 2;
    stv[1] = n;
    stv[2] = n - 1;
    for(i = n - 2; i >= 1; i--)
    {
        while(m > 1 && det(v[ stv[m - 1] ], v[ stv[m] ], v[i]) < eps)
            m--;
        stv[++m] = i;
    }

    for(i = 1; i <= m; i++)
        r[ ++q ] = v[ stv[i] ];

    vector<point> ans;
    for(i = 1; i < q; i++)
    {
        if(r[i] == r[i - 1] && i > 1)
            continue;
        ans.push_back(r[i]);
    }
    return ans;
}

LD dist(point A, point B)
{
    LD d = (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);
    d = sqrt(d);
    return d;
}

LD ang[105];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    auto pts = convexHull();

    int N = pts.size();
    pts.push_back(pts[0]);
    pts.push_back(pts[1]);

    LD sum = 0;
    LD PI = atan(1.0) * 4.0;
    for(int i = 1; i <= N; i++)
    {
        LD ab = dist(pts[i], pts[i - 1]);
        LD ac = dist(pts[i], pts[i + 1]);
        LD bc = dist(pts[i - 1], pts[i + 1]);

        LD a = (ab * ab + ac * ac - bc * bc) / (2.0 * ab * ac);
        ang[i] = acos(a);
        ang[i] = PI - ang[i];
        sum += ang[i];
    }

    for(int i = 1; i <= N; i++)
        ang[i] /= sum;

    for(int i = 1; i <= N; i++)
        mp[ pts[i] ] = ang[i];

    for(int i = 1; i <= n; i++)
        cout << fixed << setprecision(20) << mp[ bck[i] ] << '\n';

    return 0;
}


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

int main() {
	int N, K, A, count = 0;

	cin >> N >> K;

	for (int i = 0; i < N; i++) cin >> A;

	N -= K;
	count++;

	while (N > 0) {
		N -= (K - 1);
		count++;
	}
	cout << count << endl;

//	cin >> N;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(begin(a), end(a));
	
	std::vector<int> latte = a;
	latte.erase(unique(begin(latte), end(latte)), end(latte));
	if(latte.size() > 3) {
		printf("No\n");
		return 0;
	}
	
	bool ans = true;
	if(latte.size() == 1) {
		if(latte[0] != 0) ans = false;
	} else if(latte.size() == 2) {
		if(latte[0] != 0) ans = false;
		int A = 0, B = 0;
		for(auto v: a) {
			if(v == 0) A++;
			else B++;
		}
		if(A * 2 != B) ans = false;	
	} else if(latte.size() == 3) {
		std::vector<int> vec(3, 0);
		for(auto v: a) for(int i = 0; i < 3; i++) if(latte[i] == v) vec[i]++;
	
		bool flag = false;
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				for(int k = 0; k < 3; k++) {
					if(i == j or j == k or k == i) continue;
					
					bool f = true;
					std::vector<int> malta = vec;
					std::vector<int> tmp;
					for(int l = 0; l < n; l++) {
						int p = 0;
						if(l % 3 == 0) p = i;
						if(l % 3 == 1) p = j;
						if(l % 3 == 2) p = k;
						
						malta[p]--;
						tmp.push_back(latte[p]);
						
						if(malta[p] < 0) f = false;
					}
					for(int l = 0; l < n; l++) {
						int A = (l - 1 + n) % n, B = (l + 1) % n;
						f &= ((tmp[A] ^ tmp[B]) == tmp[l]);
					}
					
					flag |= f;
				}
			}
		}
		if(!flag) ans = false;
	}
	
	if(ans) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 1984
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
vector<long long> m1,m2,a,G[100005];
vector<vector<long long> > C;
long long cnt;
bool visited[100005];
void dfs(long long u)
{
	long long i;
	visited[u]=true;
	C[cnt].push_back(a[u]);
	for(i=0;i<G[u].size();i++)
	{
		if(!visited[G[u][i]])
		{
			dfs(G[u][i]);
		}
	}
}
int main()
{
	long long j,N,M,i,u,v,ans;
	cin>>N>>M;
	memset(visited,false,sizeof(visited));
	a.resize(N+1);
	for(i=1;i<=N;i++)
		cin>>a[i];
	while(M--)
	{
		cin>>u>>v;
		u++;
		v++;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	cnt=0;
	for(i=1;i<=N;i++)
	{
		if(!visited[i])
		{
			C.push_back(vector<long long>());
			dfs(i);
			cnt++;
		}
	}
	if(cnt==1)
	{
		cout<<0<<"\n";
		return 0;
	}
	for(i=0;i<cnt;i++)
	{
		sort(C[i].begin(),C[i].end(),greater<long long>());
		m1.push_back(C[i].back());
		C[i].pop_back();
		for(j=0;j<C[i].size();j++)
			m2.push_back(C[i][j]);
	}
	ans=0;
	for(i=0;i<m1.size();i++)
	{
		ans+=m1[i];
	}
	sort(m2.begin(),m2.end());
	if((long long)m2.size()<cnt-2)
	{
		cout<<"Impossible\n";
		return 0;
	}
	for(i=0;i<cnt-2;i++)
	{
		ans+=m2[i];
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 11568
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
   int n;
   cin >>n;
   int a[n];
   for(int i = 0; i < n; i++){
       cin >> a[i];
   }
   sort(a, a+n);
   
   int cnt = 1;
   for(int i = 1; i < n; i++){
       if(a[i] != a[i-1]){
           cnt++;
       }
   }
   cout << cnt << endl;
   return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def bit_count(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#############
# Main Code #
#############

N,X = inputIL()
L = inputIL()

x = 0
count = 1
for i in L:
  x += i
  if x<=X:
    count += 1

print(count)

Measured memory_bytes: 72928
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	string s;
	cin >> s;

	int res = inf;
	for (int i = 2; i < s.length(); i++)
	{
		res = min(res, abs(753 - stoi(s.substr(i - 2, 3))));
	}

	println(res);
}


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

const int N = 200000 + 10;
int n, k;
using namespace std;
double a[N], b[N];
inline double sum(double x);
inline double cal(int x);
signed main() {

	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		b[i] = sum(a[i]) / a[i];
	}
	

	double ans = 0;
	for (int i = 1; i <= k; i++) {
		ans += b[i];
	}
	double res = ans;
	for (int i = k + 1, j = 1; i <= n; i++, j++) {
		ans = max(ans, res - b[j] + b[i]);
		res = res - b[j] + b[i];
	}
	cout << fixed << setprecision(7) << ans << endl;
	return 0;
}
inline double sum(double x) {
	return (1 + x) * x  / 2;
}



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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if (a < b)
		cout << "a < b\n";
	else if (a > b)
		cout << "a > b\n";
	else
		cout << "a == b\n";
	return 0;
}


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

int n;
int a[105],b[105];

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i]>>b[i];
	for(int i=1;i+2<=n;i++)
	{
		if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2])	
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
}

Measured memory_bytes: 3628
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let x = get!();
    let y = get!();
    
    println!("{}", x + y/2);
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    ll c = a % b;
    return (c ? gcd(b, c) : b);
}

int main(void)
{
    ll A, B;
    cin >> A >> B;
    auto g = gcd(A, B);
    set<ll> s, p;
    bool flag;
    for (ll n = 2; n * n <= g; n++)
    {
        if (g % n) continue;
        s.insert(n);
        s.insert(g/n);
    }
    if (g != 1) s.insert(g);
    fa(n, s)
    {
        flag = true;
        fa(m, p)
        {
            if (!(n % m))
            {
                flag = false;
                break;
            }
        }
        if (flag) p.insert(n);
    }
    cout << (p.size()+1) << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int(a.size())
bool good(int n){
	string s = to_string(n);
	char t = s[0];
	for(char c: s){
		if(c != t) return false;
	}	
	return true;
}
int main(){
	int n; cin>>n;
	while(!good(n)){
		n++;
	}
	cout<<n<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a >= 13) cout << b << endl;
	else if (a <= 5) cout << 0 << endl;
	else cout << b / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
//	-*- mode: C++ -*-
//	Maximum Profit
//		You can obtain profits from foreign exchange margin transactions. For example, if you buy 1000 dollar at a rate of 100 yen per dollar, and sell them at a rate of 108 yen per dollar, you can obtain (108 - 100) × 1000 = 8000 yen.
//
//		Write a program which reads values of a currency Rt at a certain time t (t=0,1,2,...n−1), and reports the maximum value of Rj−Ri where j>i .
//
//	Input
//		The first line contains an integer n. In the following n lines, Rt (t=0,1,2,...n−1) are given in order.
//
//	Output
//		Print the maximum value in a line.
//
//	Constraints
//		2≤n≤200,000
//		1≤Rt≤109
//	Sample Input 1
//		6
//		5
//		3
//		1
//		3
//		4
//		3
//	Sample Output 1
//		3
//	Sample Input 2
//		3
//		4
//		3
//		2
//	Sample Output 2
//		-1

#include <iostream>
#include <vector>

int	main(int	argc,
		 char*	argv[])
{
	unsigned int	n	{0};
	std::vector<int>	R{};

	std::cin >> n;

	for(unsigned int i = 0; i < n; i++){
		unsigned int	r	{0};
		std::cin >> r;
		R.push_back(r);
	}

	int	min		= R[0];
	int	max		= R[1];
	int	profit	= max - min;

	for(unsigned int i = 0; i < n - 1; i++){
		if(min < R[i]){
			continue;
		}

		min	= R[i];
		max	= R[i + 1];
		for(unsigned int j = i + 1; j < n; j++){
			if(max < R[j]){
				max	= R[j];
			}

			if(profit < (max - min)){
				profit	= max - min;
			}
		}
	}

	std::cout << profit << '\n';
		
    return 0;
}



Measured memory_bytes: 3920
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
};
 
// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ---------------------------------------------------------------------------
 
int main(){
  int H,W,K;
  cin >> H >> W >> K;
  vector<string> G(H);
  for(int i=0; i<H; i++){
    cin >> G[i];
  }
  vector<int> ex(H,false);
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(G[i][j] == '#') ex[i] = true;
    }
  }
  int cnt = 1;
  vector<vector<int>> ans(H, vector<int> (W,-1));
  for(int i=0; i<H; i++){
    if(ex[i]){
      bool fst = true;
      for(int j=0; j<W; j++){
        if(G[i][j] == '#'){
          if(fst){
            fst = false;
          }else{
            cnt++;
          }
        }
        ans[i][j] = cnt;
      }
      cnt++;
    }
  }
  for(int i=0; i<H; i++){
    if(!ex[i]){
      for(int j=0; j<W; j++){
        int temp = i;
        bool ch = false;
        while(1){
          if(temp == H) break;
          if(ans[temp][j] != -1){
            ch = true;
            break;
          }else{
            temp++;
          }
        }
        if(ch){
          ans[i][j] = ans[temp][j];
        }else{
          temp = i;
          while(1){
            if(ans[temp][j] != -1){
              ans[i][j] = ans[temp][j];
              break;
            }
            temp--;
          }
        }
      }
    }
  }
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(j) cout << " ";
      cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    string s; cin >> s;
    int q; cin >> q;
    deque<char> deq;
    rep(i,s.size()) deq.push_back(s[i]);
    bool isReverse = false;
    rep(i,q){
        int t;cin >> t;
        if (t == 1){
            isReverse = !isReverse;
            // cout << s << endl;
        }
        else if (t == 2){
            int f;cin >> f;
            char c;cin >>c;
            if (f == 1){
                  if (!isReverse){
                      deq.push_front(c);
                  }else{
                      deq.push_back(c);
                  }
                
                // cout << s << endl;
            }
            else  {
                if (!isReverse){
                      deq.push_back(c);
                  }else{
                      deq.push_front(c);
                  }
                // cout << s << endl;
            }
        }
    }
    if (!isReverse) {
        rep(i,deq.size()){
            cout << deq[i];
        }
    }
    else{
        for (int i = deq.size()-1;i>=0;i--){
            cout << deq[i];
        }
    }
}


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

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

  int res = 0;
  for (int i = 1; i < N + 2; i++) {
    res += abs(A[i] - A[i - 1]);
  }

  for (int i = 1; i <= N; i++) {
    cout << res - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) +
                abs(A[i + 1] - A[i - 1])
         << endl;
  }
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define ROUNDUP(divisor,dividend) (divisor + (dividend - 1)) / dividend
int w,h,c,l;

int gcd(int a,int b){
  if(a<b){
    int tmp = a;
    a = b;
    b = tmp;
  }
  int r = a%b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main(){
  cin >> w >> h >> c;
  l = gcd(w,h);
  cout << (w/l)*(h/l)*c << endl;
}



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el cout << "\n"
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);

int main()
{
	IOS;
    cout.precision(30);
    long long A ,B , C , D;
    cin >> A >> B >> C >> D;
    long long ncm=((A/C)+int(A%C!=0)),ncM=(B/C),ndm=(A/D)+int(A%D!=0),ndM=(B/D),ncdm=(A/((C*D)/__gcd(C,D)))+int(A%((C*D)/__gcd(C,D))!=0);
      ll ncdM=(B/((C*D)/__gcd(C,D)));

    cout << (B-A+1)-(ncM-ncm+1+ndM-ndm-ncdM+ncdm);
    cout << endl;
   // cout << (floor(A/C)+int(A%C!=0));

    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

ll func(ll a, ll b, ll x) {
  return floor(a * x / b) - a * floor(x / b);
} 

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

  ll a, b, n;
  cin >> a >> b >> n;
  if (b - 1 < n) {
    cout << func(a, b, b -1) << endl;
  } else {
    cout << func(a, b, n) << endl;
  }

}

Measured memory_bytes: 3616
import sys
import itertools


def resolve(in_):
    H, W, M = map(int, next(in_).split())
    targets = tuple(tuple(map(int, line.split())) for line in in_)
    
    target_h = {}
    target_w = {}
    target_hw = set()
    for h, w in targets:
        target_h[h] = target_h.setdefault(h, 0) + 1
        target_w[w] = target_w.setdefault(w, 0) + 1
        target_hw.add((h, w))

    max_h = max(target_h.values())
    max_w = max(target_w.values())

    h_set = {h for h, v in target_h.items() if max_h == v}
    w_set = {w for w, v in target_w.items() if max_w == v}

    ans = max_h + max_w - 1
    for hw in itertools.product(h_set, w_set):
        if hw not in target_hw:
            ans += 1
            break
    
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 230452
#include<stdio.h>

long long GCDis(long long a, long long b) {
	long long p, q, buff;
	p = a; q = b;
	while (q != 0) {
		buff = p;
		p = q;
		q = buff % q;
	}
	return p;
}

int main() {
	long long a, b;
	long long GCD, LCM;

	while (1) {
		if (scanf("%lld %lld", &a, &b) == EOF)break;
		GCD = GCDis(a, b);
		LCM = a * b / GCD;
		printf("%lld %lld\n", GCD, LCM);
	}
	return 0;
}



Measured memory_bytes: 2028
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, ans = M;
    string s;
    cin >> n >> s;
    vector<ll> r(n + 1);
    for (ll i = 1; i <= n; i++)
        r[i] = r[i - 1] + (s[i - 1] == 'R');
    for (ll i = 0; i <= n; i++)
        ans = min(ans, max(i - r[i], r[n] - r[i]));
    cout << ans;
}

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

int main(){
  string s,t;
  cin >> s >> t;
  // sort(s.begin(),s.end());
  // sort(t.begin(),t.end());

  int n = s.size();
  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    if(s[i]!=t[i]) ans++;
  }
  cout << ans << endl;
  
}

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

typedef unsigned uint;

inline bool is_exist_bin_search(uint v, std::vector<uint> s){
  uint min = 0, max = s.size();
  while(min < max){
    uint mid = (min + max) / 2;
    uint v_mid = s[mid];
    if(v_mid == v) return true;

    if(v_mid >= v) max = mid;
    else min = mid+1;
  }
  return false;
}

inline unsigned count(std::vector<uint> s, std::vector<uint> t){
  uint n = 0;
  for(uint i = 0; i < t.size(); i++){
    if(is_exist_bin_search(t[i],s)) n++;
  }
  return n;
}

int main(){
  std::ios_base::sync_with_stdio(false);

  uint n;
  std::cin >> n;
  std::vector<uint> s(n,0);
  for(uint i = 0; i < n; i++){
    std::cin >> s[i];
  }
  s.erase(std::unique(s.begin(),s.end()),s.end());

  uint q;
  std::cin >> q;
  std::vector<uint> t(q,0);
  for(uint i = 0; i < q; i++){
    std::cin >> t[i];
  }

  std::cout << count(s,t) << '\n';
}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector< tuple<int,int,int> > PY;
  vector< pair<int,int> > CITY(M);
  REP(i,M) {
    int a,b;
    cin >> a >> b;
    PY.emplace_back( a,b,i );
  }
  sort( PY.begin(), PY.end());
  ll pre_p = 0;
  int yn = 1;
  REP(i,M) {
    int p,y,c;
    tie(p,y,c) = PY[i];
//    cout << p << " "  << y << " "  << c << endl;
    if ( pre_p != p ) yn=1;
    CITY[c] = make_pair( p,yn );
    pre_p = p;
    yn++;
  }
  REP(i,M) {
    printf("%06d%06d\n", CITY[i].first,CITY[i].second);
  }
}


Measured memory_bytes: 3572
#include <iostream>
#include<iomanip>
using namespace std;
int main(void){
    int d,r,a,b;
    double f;
    cin>>a>>b;
    d = a/b;
    r = a%b;
    f = (double)a/(double)b;
    cout<<d<<" "<<r<<" "<<fixed<<setprecision(5)<<f<<endl;
    
}



Measured memory_bytes: 3272
while True:

	string=list(input())
	if string[0]=='-':
		break
	n=int(input())
	lis=[]
	for i in range(n):
		lis.append(int(input()))

	for x in lis:
		for m in range(x):
			howmuch=m
			t=string.pop(0)
			string.append(t)
	for i in string:
		print(i,end="")
	print()





Measured memory_bytes: 5620
N, M = map(int, input().split())

X = [[0] * N for _ in range(8)]



for i in range(N):
    x, y, z = map(int, input().split())
    calc = [x+y+z, -x+y+z, x-y+z, -x-y+z,
            x+y-z, -x+y-z, x-y-z, -x-y-z]
    for j in range(8):
        X[j][i] = calc[j]

answer = 0
for i in range(8):
    a = sum(sorted(X[i], reverse=1)[:M])
    answer = max(a, answer)

print(answer)

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

int main(){
    int N, M, X;
    std::cin >> N >> M >> X;
    std::vector< int > C(N);
    std::vector< std::vector< int > > A(N, std::vector< int >(M));
    
    for(int i=0; i<N; i++){
        std::cin >> C[i];
        for(int j=0; j<M; j++){
            std::cin >> A[i][j];
        }
    }
    
    std::deque< std::vector< bool > > pat;
    std::deque< std::vector< bool > > pat_pre;
    std::vector< bool > tmp(1, true);
    pat.push_back(tmp);
    tmp.assign(1, false);
    pat.push_back(tmp);
    for(int i=1; i<N; i++){
        pat_pre = pat;
        pat.clear();
        while(!pat_pre.empty()){
            tmp = pat_pre[0];
            tmp.push_back(true);
            pat.push_back(tmp);
            tmp[tmp.size() - 1] = false;
            pat.push_back(tmp);
            pat_pre.pop_front();
        }
    }
    
    int min = 1e9;
    while(!pat.empty()){
        tmp = pat[0];
        int price = 0;
        std::vector< int > Xcur(M, 0);
        for(int i=0; i<N; i++){
            if(tmp[i]){
                for(int j=0; j<M;j++){
                    Xcur[j] += A[i][j];
                }
                price += C[i];
            }
        }
        bool ok = true;
        for(int i=0; i<M; i++){
            if(Xcur[i] < X){
                ok = false;
            }
        }
        if(ok){
            if(min > price){
                min = price;
            }
        }
        pat.pop_front();
    }
        
    
    if(min == 1e9){
        std::cout << -1 << std::endl;
    }else{
        std::cout << min << std::endl;
    }
    
    return 0;
}



Measured memory_bytes: 3960
#include <iostream>

using namespace std;

void show_array(int a[], int n) {
  for (int i = 0; i < n - 1; i++) {
    cout << a[i] << " ";
  }
  cout << a[n-1] << endl;
}

int get_min_elem_index(int a[], int n, int begin, int end) {
  int min_elem = 10000;
  int min_elem_index;
  for (int i = begin; i <= end; i ++) {
    if (a[i] < min_elem) {
      min_elem = a[i];
      min_elem_index = i;
    }
  }
  //cout << "min_index:" << min_elem_index << endl;
  return min_elem_index;
}

int selection_sort2(int a[], int n) {
  int sw = 0;
  int minj;
  for (int i = 0; i < n - 1; i++) {
    minj = i;
    // 最小値探す
    //cout << "imakara min sagasu for " << i << endl;
    for (int j = i; j < n; j++) {
      //cout << "a[j]" << a[j] << endl;
      if (a[j] < a[minj]) {
        minj = j;
      }
    }
    //cout << "min:" << minj << "(" << a[minj] << ")" << " wo i:" << i << " to torikae" << endl;
    // 交換
    int tmp = a[minj];
    a[minj] = a[i];
    a[i] = tmp;

    if (i != minj) {
      sw++;
    }
  }
  return sw;
}


int selection_sort(int a[], int n) {
  int sw = 0;
  int b[110];
  for (int i = 0; i < n; i++) {
    int min_elem_index = get_min_elem_index(a, n, sw, n-1);
    //cout << "min_elem_index:" << min_elem_index << endl;
    if (sw == min_elem_index) {
      continue;
    }
    if (a[i] > a[min_elem_index]) {
      int tmp = a[min_elem_index];
      a[min_elem_index] = a[sw];
      a[sw] = tmp;
      sw++;
      //cout << "change" << endl;
      //show_array(a, n);
    }
    //cout << "-----------" << endl;
  }
  return sw;
}

int main() {
  int n;
  int a[110];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int sw = selection_sort2(a, n);
  show_array(a, n);
  cout << sw << endl;
}



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

#define MAX 100001

int main(){
	int n,m;	cin>>n>>m;
	
	pair<int,pair<int,int>> city[m+1];
	int num,time;
	for(int i=1;i<=m;i++){
		cin>>num>>time;
		city[i]=make_pair(time,make_pair(num,i));
	}
	city[0]=make_pair(0,make_pair(0,0));
	int c[MAX];	for(int i=1;i<=MAX;i++)c[i]=1;
	string ans[m+1];
	sort(city, city+m+1);
	for(int i=1;i<=m;i++){
		int pos=city[i].second.second;
		int pre=city[i].second.first;
		string P=to_string(pre);
		string id=to_string(c[pre]++);
		while(P.length()<6)P='0'+P;
		while(id.length()<6)id='0'+id;

		ans[pos]=P+id;
	}

	for(int i=1;i<=m;i++)cout<<ans[i]<<endl;

	return 0;
}


Measured memory_bytes: 8576
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(int i=(ll)(b);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,w;cin>>n>>w;
  vector<ll>dp(w+1);
  rep(i,n){
    ll tw,tv;cin>>tw>>tv;
    rrep(j,w-tw+1){
      chmax(dp[j+tw],dp[j]+tv);
    }
  }
  ll res=0;
  rep(i,w+1)chmax(res,dp[i]);
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			int r = int.Parse(Console.ReadLine());
			//long n = long.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			string ans;
			if (r < 1200) {
				ans = "ABC";
			} else if (r < 2800) {
				ans = "ARC";
			} else {
				ans = "AGC";
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}
	}
}


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

int main() {
  int A, B , C , D;
  cin >> A >> B >> C >> D;

  if ((A + B) == (C + D)) {
    cout << "Balanced" << endl;
  }
  else if ((A + B) > (C + D)){
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] In = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int n = In[0];
            int m = In[1];
            var uf = new unionFind(n);
            for(int i = 0; i < m; i++)
            {
                int[] In2 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                int a = In2[0];
                int b = In2[1];
                a--; b--;
                uf.Connect(a, b);
            }
            int max = 0;
            for(int i = 0; i < n; i++)
            {
                max = (int)Math.Max(max, uf.Size(i));
            }
            Console.WriteLine(max);
        }
        public class unionFind
        {
            //親の番号を格納、親だった場合は-1 <-ふつうのunionfind
            //今回は、親だった場合　-(その集合のサイズ)にする
            int[] Parent;
            //まずすべて-1で初期化、
            public unionFind(int n)
            {
                Parent = new int[n];
                Parent = Enumerable.Repeat(-1, n).ToArray();
            }
            //aがどのグループに属しているか
            public int root(int a)
            {
                if (Parent[a] < 0) return a;
                return Parent[a] = root(Parent[a]);
            }
            //自分のいるグループの頂点数を調べる
            public int Size(int a)
            {
                return -Parent[root(a)];//親をとってきたい
            }
            //aとｂをくっつける
            public bool Connect(int a, int b)
            {
                //aとbをくっつけるのではなく、root(A)とroot(B)をくっつける
                a = root(a);
                b = root(b);
                //すでにくっついているとき
                if (a == b) return false;
                //大きい方(a)が小さいほう(b)をくっつけたい
                //大小が逆ならひっくり返す
                if (Size(a) < Size(b))
                {
                    int tmp = a;
                    a = b;
                    b = tmp;
                }
                //aのサイズを更新する
                Parent[a] += Parent[b];
                //bの親をaに変更する
                Parent[b] = a;
                return true;
            }
        }
        public struct Pair
        {
            public int x, y;
            public Pair(int x, int y)
            {
                this.x = x;
                this.y = y;
            }
        }
    }
}


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

int R, S, P;
int score (char c) {
  if (c == 'r') return P;
  if (c == 's') return R;
  if (c == 'p') return S;
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N; cin >> N;
  int K; cin >> K;
  cin >> R;
  cin >> S;
  cin >> P;
  string T; cin >> T;

  int ans = 0;
  bool check = false;
  if (K == 1) {
    ans = score(T[0]);
    for (int i = 1; i < N; i++) {
      if (T[i] != T[i - 1]) {
        check = false;
        ans += score(T[i]);
      } else if (check) {
        check = false;
        ans += score(T[i]);
      } else {
        check = true;
      }
    }
  } else {
    for (int i = 0; i < K; i++) {
      ans += score(T[i]);
    }
    for (int i = 0; i < K; i++) {
      check = false;
      for (int j = 1; j < N; j++) {
        int c = K * j + i;
        int p = c - K;
        if (c >= N) break;

        if (T[c] != T[p]) {
          check = false;
          ans += score(T[c]);
        } else if (check) {
          check = false;
          ans += score(T[c]);
        } else {
          check = true;
        }
      }
    }

  }
  cout << ans << '\n';
  return 0;
}

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


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

  long double a,b,h,m;
  cin >> a >> b >> h >> m;

  long double x = ((long double) (2*M_PI) )*(60*h+m)/60./12.;
  long double y = ((long double) (2*M_PI) )*(m)/60.;
  long double dif = abs(x-y);
  long double eps = 1e-10;
  cout << fixed << setprecision(12) <<  sqrt(a*a + b*b - 2*a*b*cos(dif)) << endl;



  
  return 0;
    

}


Measured memory_bytes: 4184
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);    
#define f(i,j,k)  for(int i=j;i<k;i++)
#define fr(i,j,k) for(int i<=k-1;i>=j;i--)
#define ll long long
#define ld long double

using namespace std;

int main()
{
	fio
	int TC;
	TC=1;
	while(TC--)
	{
		int n;
		cin>>n;
		std::vector<ll> v;
		ll temp,sum=0;
		for (int i = 0; i < n; ++i)
		{
			cin>>temp;
			sum+=temp;
			v.push_back(temp);
		}
		sort(v.begin(),v.end());
		sum/=n;
		ll s2=sum+1;

		ll stamina = 0,stamina2=0;
		for (int i = 0; i < n; ++i)
		{
			stamina+=pow( (sum-v[i]),2);
			stamina2 += pow((s2-v[i]),2);
		}
		cout<<min(stamina,stamina2)<<endl;
		

	}
	return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "2 3", "0 1 1", "1 0 1", "1 4 0", "1 2", "3 3" ].solve == 3 );
	assert( [ "4 3", "0 12 71", "81 0 53", "14 92 0", "1 1 2 1", "2 1 1 2", "2 2 1 3", "1 1 2 2" ].solve == 428 );
	
	assert( [ "2 4", "100 100 100 100", "100 0 1 1", "100 1 0 1", "100 1 4 0", "2 3", "4 4" ].solve == 3 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto c = 0L;
	input.front.formattedRead!"%s %s"( n, c );
	auto dss = new long[][]( c, c );
	foreach( ref ds; dss )
	{
		input.popFront;
		ds = input.front.split.to!( long[] );
	}
	auto css = new long[][]( n, n );
	foreach( ref cs; css )
	{
		input.popFront;
		cs = input.front.split.to!( long[] );
		cs[] -= 1;
	}
	
	auto tss = new long[][]( 3, c );
	foreach( x; 0L .. css.length.signed )
	{
		foreach( y; 0L .. css[ x ].length.signed )
		{
			foreach( z; 0L .. c )
			{
				tss[ ( x + y ) % 3 ][ z ] += dss[ css[ x ][ y ] ][ z ];
			}
		}
	}
	
	auto ans = long.max;
	foreach( i; 0L .. c )
	{
		foreach( j; 0L .. c )
		{
			if( i == j ) continue;
			foreach( k; 0L .. c )
			{
				if( i == k || j == k ) continue;
				ans = min( ans, tss[ 0 ][ i ] + tss[ 1 ][ j ] + tss[ 2 ][ k ] );
			}
		}
	}
	return ans;
}


Measured memory_bytes: 8048
N = int(input())

def solve(N):
    for i in range(N // 4 + 1):
        for j in range(N // 7 + 1):
            if 4 * i + 7 * j == N:
                return True
    else:
        return False

if solve(N):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
    using namespace std;
    
    long long gcd(long long a, long long b) {
        if(b == 0)
            return a;
        else
            return gcd(b, a % b);
    }
    
    long long lcm (long long a, long long b) {
        return a / gcd(a, b) * b;
    }

    int main(){
        long n;
        vector<long> v;
        long long ans = 0;
        long a;
        cin >> n;
        for(long i = 0 ; i < 3 * n  ; i++){
            cin >> a;
            v.push_back(a);
            //cout << a << endl;
        }  
        sort(v.begin() , v.end());
        for(long i = 1 ; i <= n ; i++){
            ans += v[3*n-2*i];
        }
        cout << ans << endl;
        return 0;
    }

Measured memory_bytes: 5872