akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define SZ(a) ((int)a.size())
//#pragma GCC optimize(2)
using namespace std;
const int N=1e5+10;
const int M=1e9+7;
const int inf=1e9+7;
const double eps=1e-6;
typedef complex<double>C;
const double PI(acos(-1.0));
//for(int mask=i;mask>0;mask=(mask-1)&i)
//int a[25]= { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
//__gcd, atan2(y,x)=y/x , __int128
//c(n,k)=c(n-1,k-1)+c(n-1,k)
//c(i,r),i for r to n =c(n+1,r+1)
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){int t=0;while(x){t+=BIT[x];x-=x&-x;}return t;}
//LL pw(LL a,LL b){LL t=1;for(;b;b>>=1,a=a*a%M)b&1?t=t*a%M:0;return t;}
//log() = ln() , log(x)/log(y)=log(y)-base-x
//INT_MAX 127,INT_MIN 128
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
//cout<<fixed<<setprecision(12)<<ans<<endl;
//__builtin_popcount(mask)
int u,v;
LL s;
vector<pair<int,LL>>g[N];
int n,m;
vector<int>vis;//�@���l�̤p���@�ܤj���� ,�t���l�̤j���@�ܤp���� 
vector<int>w;
LL mn,mx;
void dfs(int u){
	for(auto it:g[u]){
		int v=it.F;LL s=it.S;
		if(vis[v]==-1){
			vis[v]=vis[u]^1;
			w[v]=s-w[u];
			if(vis[v]){
				mn=max(mn,1LL-w[v]);
			}
			else{
				mx=min(mx,w[v]-1LL);
			}
			if(mn>mx){
				cout<<0<<endl;
				exit(0);
			}
			dfs(v);
		}
		else{
			if(vis[u]!=vis[v]){
				if(w[u]+w[v]!=s){
					cout<<0<<endl;
					exit(0);
				}
			}
			else{
				LL dis=s-(w[u]+w[v]);
				if(dis==0)continue;
				if(dis&1){//���ܤ@�w�O���� 
					cout<<0<<endl;
					exit(0);
				}
				if(vis[u]^(dis>0)){//�ۮt�����t�M�i�H���ܪ����t���P 
					cout<<0<<endl;
					exit(0);
				}
				if(dis<0)dis=-dis;
				mx=min(mx,dis/2);
				mn=max(mn,dis/2);
			}
		}
		
	}
}
int main(){Accel

	cin>>n>>m;
	REP(i,m){
		cin>>u>>v>>s;
		
		g[u].PB(MP(v,s));
		g[v].PB(MP(u,s));
	}
	// �]���I��0  ���@���I�ܰʽd�� 
	mn=1,mx=1e18;
	vis.resize(n+1,-1);
	w.resize(n+1);
	vis[1]=1;
	dfs(1);
	//cout<<mn<<" "<<mx<<endl;
	cout<<max(0LL,mx-mn+1)<<endl;
}


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


int main(){
  int n;
  cin >> n;
  vector<ll> l(n);
  for(int i=0;i<n;++i) cin >> l[i];
  int ans=0;
  for(int i=0;i<n;++i){
    for(int j=i+1;j<n;++j){
      for(int k=j+1;k<n;++k){
        if(l[i]==l[j] || l[i]==l[k] || l[j]==l[k])continue;
        if(l[i]<l[j]+l[k] && l[j]<l[i]+l[k] && l[k]<l[i]+l[j]) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

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

    int N = (1 << n);

    multiset<int> T;
    vector<int> V(1);

    REP(i, N) {
        int s;
        cin >> s;
        T.insert(s);
        chmax(V[0], s);
    }

    REP(i, n){
        vector<int> W = V;
        for(int s : V){
            auto ite = T.lower_bound(s);
            if(ite == T.begin()){
                cout << "No" << endl;
                return 0;
            }
            ite--;
            W.push_back(*ite);
            T.erase(ite);
        }
//        sort(all(W), greater<>());
        swap(V, W);
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 14200
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr int INF = 1001001001;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

bool comp(P a, P b) {return a.second > b.second;}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep (i, n) cin >> a[i];
    vector<P> p(m);
    rep (i, m) {
        int b, c;
        cin >> b >> c;
        p[i] = make_pair(b, c);
    }
    
    sort(p.begin(), p.end(), comp);
    priority_queue<int> q;
    for (auto v : a) q.push(v);
    rep (i, m) {
        int b = p[i].first, c = p[i].second;
        rep (j, b) q.push(c);
        if (q.size() > n*2)
            break;
    }
    
    ll ans = 0;
    rep(i,n) {
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 6560
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int i,j,l;
int N,M;
cin >> N >> M;
int count = 1;
for(i=0;i<N;i++)count*=2;
vector<int> S[M];
int s;
int p[M];
int k[M];
int ans=0;
for(i=0;i<M;i++){
  cin >> k[i];
  for(j=0;j<k[i];j++){cin >> s;
  S[i].push_back(s);}}
for(i=0;i<M;i++)cin >> p[i];
int sw[N];
for(i=0;i<N;i++)sw[i]=0;
int tmp;
int anco;
for(i=0;i<count;i++){
    tmp=i;
    j=0;
    while(tmp!=0){
        sw[j]=tmp%2;
        tmp/=2;
        j++;
    }
    for(j=0;j<M;j++){
        anco=0;
        for(l=0;l<k[j];l++)if(sw[S[j].at(l)-1]==1)anco++;
        if((anco%2)!=p[j])break;
        else if(j==M-1)ans++;
    }
}
cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  vector<int> v(3);
  for (auto& e : v) cin >> e;

  int ans = INT_MAX;
  for (int i = 0; i < 2; ++i) {
    for (int j = i + 1; j < 3; ++j) {
      int tmp = v.at(i) + v.at(j);
      ans = min(ans, tmp);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int N;

int main(){

	int minimum = BIG_NUM;

	scanf("%d",&N);

	int tmp;
	int ans = 0;

	for(int i = 0; i < N; i++){

		scanf("%d",&tmp);
		minimum = min(minimum,tmp);

		if(tmp == minimum)ans++;
	}

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

	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

from collections import Counter
C = Counter(A)

sumA = sum(A)
for i in range(Q):
    b, c = map(int, input().split())
    sumA = sumA + (c-b)*C[b]
    C[c] += C[b]
    C[b] = 0
    print(sumA)


Measured memory_bytes: 86880
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;


int main()
{
long long n,m;
scanf("%lld",&n);
long long a=sqrt(n)+0.5;
long long b=n/a,sum;
long long ans=98000000000000000;
for(int i=1;i<=a;i++)
{
  b=n/i;
   if(i*b==n)
   {
     sum=i-1+b-1;
     if(sum<ans)
     ans=sum;
   }
   else
   continue;

}
printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
constexpr i64 MOD = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    vvi as(n, vi(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> as[i][j];
        }
    }

    vi dp(1 << n);
    // dp[i] : popcount(i)人までの男子が集合iの女子と完全マッチングする場合の数
    dp[0] = 1;
    for (int i = 1; i < 1 << n; i++) {
        int p = __builtin_popcount(i);
        for (int j = 0; j < n; j++) {
            if (i >> j & 1) {
                if (as[p - 1][j]) {
                    dp[i] += dp[i ^ 1 << j];
                    dp[i] %= MOD;
                }
            }
        }
    }
    cout << dp.back() << endl;
}

Measured memory_bytes: 16640
x1,y1,x2,y2 = map(int,input().split())
xsa = x2 - x1
ysa = y2 - y1
x3 = x2 - ysa
y3 = y2 + xsa
x4 = x1 - ysa
y4 = y1 + xsa
print(x3,end=" ")
print(y3,end=" ")
print(x4,end=" ")
print(y4)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int cnt = 0;
    for (int i=0;i<n-2;i++){
        if(s.at(i)=='A' && s.at(i+1)=='B' && s.at(i+2)=='C')
            cnt++;
    }
    cout <<  cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void right_triangle(int x, int y, int z);

int main(void)
{
        int n;
	scanf("%d", &n);
	int i = 0;
        int x, y, z;
	while (i < n) {
	scanf("%d %d %d", &x, &y, &z);
	right_triangle(x, y, z);
	i++;
	}
	return 0;
}

void right_triangle(int x, int y, int z)
{
    int i, j, k;
    i = x * x;
    j = y * y;
    k = z * z;
    if(i == j + k || j == k + i || k == i + j) {
    printf("YES\n");
    } else {
    printf("NO\n");
    }
}

Measured memory_bytes: 1008
// 23
#include <bits/stdc++.h>
using namespace std;
#define coutc "\033[48;5;196m\033[38;5;15m"
#define endc "\033[0m"
#define endl '\n'
#define M(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) \
  M(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep4(_, x, n, s) \
  for (int _ = x; (s < 0) ? _ > n : _ < n; _ += s)
#define rep3(_, x, n) rep4(_, x, n, (x < n ? 1 : -1))
#define rep2(_, n) rep3(_, 0, n)
#define rep1(n) rep2(i, n)
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define len(x) int(x.size())
#define lli __int128_t
#define li long long int
#define ld long double
#ifdef DEBUG
// 3
ostream &operator<<(ostream &o, pair<auto, auto> p) {
  return o << "(" << p.fi << ", " << p.se << ")";
}
// 4
ostream &operator<<(ostream &o, vector<auto> v) {
  rep(i, len(v)) o << setw(7) << right << v[i];
  return o << endc << endl << coutc;
}
// 4
ostream &operator<<(ostream &o, map<auto, auto> m) {
  for (auto &kv : m) o << kv;
  return o;
}
// 7
void debug(const auto &e, const auto &... r) {
  cerr << coutc << e;
  ((cerr << " " << r), ..., (cerr << endc << endl));
}
#else
#define debug(...)
#endif
// 3
void _main(int tc) {
  li a, b, c, k;
  cin >> a >> b >> c >> k;
  li ans = 0;
  ans += min(a, k);
  k -= min(a, k);
  if (k == 0) {
    cout << ans << endl;
    return;
  }
  k -= min(b, k);
  if (k == 0) {
    cout << ans << endl;
    return;
  }
  ans -= min(c, k);
  k -= min(c, k);
  if (k == 0) {
    cout << ans << endl;
    return;
  }
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 3640
# -*- coding: utf-8 -*-
import sys
N,M=map(int, sys.stdin.readline().split())

mod=10**9+7
fact, inv_fact=[1], [1]
fact_tmp=1
for i in range(1, M+1):
    fact_tmp*=i
    fact_tmp%=mod
    fact.append(fact_tmp)
    inv_fact.append(pow(fact_tmp, mod-2, mod))

def ncr(n,r):
	if n<0 or r<0 or n<r:	return 0
	else:   return (fact[n]*inv_fact[r]*inv_fact[n-r])%mod

def npr(n,r):
	if n<0 or r<0 or n<r:	return 0
	else:   return (fact[n]*inv_fact[n-r])%mod

ans=0
for k in range(N+1):
    if k%2==0: ans+=ncr(N,k)*ncr(M,k)*npr(k,k)*(npr(M-k,N-k)**2)
    else:      ans-=ncr(N,k)*ncr(M,k)*npr(k,k)*(npr(M-k,N-k)**2)
    ans%=mod
print ans

Measured memory_bytes: 159648
s = input()

x = int(s[:2])
y = int(s[2:])

if 1 <= x <= 12 and 1 <= y <= 12:
    print("AMBIGUOUS")
elif 1 <= x <= 12:
    print("MMYY")
elif 1 <= y <= 12:
    print("YYMM")
else:
    print('NA')

Measured memory_bytes: 61792
# -*- coding: utf-8 -*-
# B

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

n = int(input())
d = [] * n * 2
cnt = 0
for _ in range(n):
    a, b = map(int, input().split())
    d.append(a)
    d.append(b)
    if a == b:
        cnt += 1
        if cnt == 3:
            print('Yes')
            sys.exit()
    else:
        cnt = 0
print('No')

Measured memory_bytes: 65548
//============================================================================
// Name        : AOJ.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;
typedef long long ll;
int main(){

	int n,d,x;
	int a[101];
	int y=0;

	cin>>n;
	cin>>d>>x;

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

	for(int i=1; i<n+1; ++i){
		y+=(d-1)/a[i]+1;
	}

	cout<<y+x<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;  
            
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	int x=sizeof(arr)/sizeof(arr[0]);
	sort(arr,arr+x);
	int ans=0;
	for(int i=0;i<k;i++)
	{
		ans+=arr[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3616
n = int(input())
h = list(map(int,input().split()))
i = 0
ans = []
s = 0
while True:
    if i == n-1:
        ans.append(s)
        break
    elif h[i] >= h[i+1]:
        s += 1
    else:
        ans.append(s)
        s = 0
    i += 1

ans.sort(reverse=True)
print(ans[0])

Measured memory_bytes: 15020
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll A,B;
	while(cin>>A>>B) {
		ll ans=0;
		while(1+ans*(A-1)<B) ans++;
		cout<<ans<<endl;
	}
	
	return 0;
}


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

using namespace std;

int D, G;
int f[20][1010];

int p[20], c[20];

int main(){
	cin >> D >> G;
	
	for(register int i=1; i<=D; i++){
		cin>>p[i]>>c[i];
	}
	
	for(register int i=1; i<=D; i++){
		for(register int j=0; j<p[i]; j++){
			for(register int k=j; k<=1000; k++)
				f[i][k] = max(f[i][k], f[i-1][k-j] + j *(100 * i));
		}
		
		for(register int k=p[i]; k<=1000; k++)
			f[i][k] = max(f[i][k], f[i-1][k-p[i]] + p[i] * (100 * i) + c[i]);
	}
	
	int ans = 1000;
	for(register int i=1000; i>=0; i--)
		if(f[D][i] >= G)
			ans = i;
	
	printf("%d", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	V a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(all(a), greater<int>());
	ll ans = 0;
	// うまい割り当て方には規則性がある?
	if (n % 2 == 0) {
		ans += a[0];
		for (int i = 1; i < n / 2; i++) {
			ans += a[i] * 2;
		}
	}
	else{
		ans += a[0];
		for (int i = 1; i < n / 2; i++) {
			ans += a[i] * 2;
		}
		ans += a[n / 2];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4048
int main(void) {
    char a[100],b[100];
    scanf("%s%s",a,b);
    strcat(a, b);
    int d = atoi(a);
    double c = sqrt((double)d);
    if (c == (int)c) {
        printf("Yes\n");
    } else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define maxn ((ll)(1e5+10))
#define mod ((ll)(1e9+7))
typedef long long ll;
using namespace std;
int n,a[maxn];
ll b[maxn],s[maxn],s1[maxn];
int pos[maxn],t1,t2;
ll ksm(int x,int y) {
	if (y==1)
		return x;
	ll res=ksm(x,y/2);
	res*=res; res%=mod;
	if (y%2==1) {
		res*=x;
		res%=mod;
	}
	return res;
}
ll c(int x,int y) {
	if (x<y)
		return 0;
	ll res=s[x]*s1[y];
	res%=mod;
	res*=s1[x-y];
	res%=mod;
	return res;
}
int main() {
	//freopen("1.txt","r",stdin);
	scanf("%d",&n);
	memset(pos,0,sizeof(pos));
	for (int i=1;i<=n+1;i++) {
		scanf("%d",&a[i]);
		if (pos[a[i]]>0) {
			t1=pos[a[i]];
			t2=i;
		}
		else pos[a[i]]=i;
	}
	s[0]=1; s[1]=1; b[1]=1;
	for (int i=2;i<=n+1;i++) {
		b[i]=ksm(i,mod-2);
		s[i]=(s[i-1]*i)%mod;
	}
	s1[0]=1;
	for (int i=1;i<=n+1;i++)
		s1[i]=(s1[i-1]*b[i])%mod;
	printf("%d\n",n);
	for (int k=2;k<=n+1;k++) {
		ll x=c(n+1,k);
		x-=c(t1+n-t2,k-1);
		while (x<0) x+=mod;
		printf("%lld\n",x);
	}
	return 0;
}

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

using namespace std;
    

int main(int argc, char const *argv[])
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    
    if(abs(a-c) <= d){
        cout << "Yes" << endl;
        return 0;
    }
    if(abs(b-a) <= d and abs(c-b) <= d){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}


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

int main() {
 int n, m;
 vector<int> road(50, 0);
  
 cin >> n >> m;
  rep(i, m){
  	int a, b;
    cin >> a >> b;
    road.at(a - 1)++;
    road.at(b - 1)++;
  }
  
  rep(i, n)
    cout << road.at(i) << endl;
  
}


Measured memory_bytes: 256
n, m = map(int, input().split())

data = [ tuple(map(int, input().split())) for _ in range(n) ] 

sortedData = sorted(data, key=lambda a: a[0])
cost = 0
tmpM = 0
for a, b in sortedData:
	if (m - tmpM) >= b:
		cost += a * b
		tmpM += b
	else:
		cost += a * (m-tmpM)
		break

print(cost)

Measured memory_bytes: 18892
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

vector<int> read_vec(int n){
    vector<int> ret(n);
    for (int i = 0; i < n; i++){
        cin >> ret[i];
    }
    return ret;
}

int main() {
    int n, y, ans;
    cin >> n >> y;
    vector<int>x = read_vec(n);
    for (int i = 0; i < n; i++){
        x[i] = abs(y - x[i]);
    }
    for (int i = 0; i < n; i++){
        if (i == 0){
            ans = x[0];
        }
        ans = __gcd(ans, x[i]);
    }
    cout << ans << endl;
}

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

int N;
int a, b;
bool fg = false;
string S;

int main() {

	cin >> N;
	
	int cnt = 0;

	for (int i = 0; i < N; i++) {
		cin >> a >> b;

		if (a == b) {
			cnt += 1;
		}
		else {
			cnt = 0;
		}

		if (cnt >= 3) {
			fg = true;
		}
	}

	if (fg) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3588
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    a,b,c,d,e,f=map(int,readline().split())

    w=[]
    for i in range(0,f+1,100):
        for j in range(0,f+1,100):
            n=a*i+b*j
            if n<=f:
                w.append(n)
    w.sort()

    s=[]
    for i in range(f+1):
        for j in range(f+1):
            n=c*i+d*j
            if n<=f:
                s.append(n)
    s.sort()

    cnt=-1
    res=[0,0]
    for x in w:
        for y in s:
            if x+y>f:
                break

            ma=x//100*e
            if y>ma:
                continue
            
            if (x+y)!=0 and cnt<100*y/(x+y):
                cnt=100*y/(x+y)
                res=[x+y,y]

    print(*res)

if __name__=="__main__":
    main()

Measured memory_bytes: 13372
$$_++for@S=<>=~/./g;
$g=grep$$_,a..c;
if($g==1){
	print@S==1?YES:NO
}elsif($g==2){
	print@S==2?YES:NO
}else{
	($a,$b,$c)=sort{$a-$b}$a,$b,$c;
	print$c-$a<=1?YES:NO
}


Measured memory_bytes: 13952
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#include<vector>
using namespace std;
int main(){
    int P,Q,R; cin >> P >> Q >> R;
    int a = max({P,Q,R});
    if(a == P)
        cout << Q+R << endl;
    else if(a == Q)
        cout << P+R << endl;
    else
        cout << P+Q << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[5],b,c;
int main()
{
    cin>>a[1]>>a[2]>>a[3];
    sort(a+1,a+4);
    if(a[2]-a[1]==a[3]-a[2])
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<int>> a(n, vector<int>(n, 0));
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    a[--l][--r]++;
  }
  for (int d = 1; d < n; d++) {
    for (int l = 0; l < n - d; l++) {
      int r = l + d;
      a[l][r] += a[l][r - 1] + a[l + 1][r];
      if (d >= 2) {
        a[l][r] -= a[l + 1][r - 1];
      }
    }
  }
  while (q--) {
    int p, q;
    cin >> p >> q;
    cout << a[--p][--q] << '\n';
  }
  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;cin>>n;
    string s;cin >> s;
    if (n<3)
    {
        cout << 0 << endl;
        return 0;
    }

    int ary_r[n+1];
    int ary_g[n+1];
    int ary_b[n+1];
    ary_r[0] = 0;
    ary_g[0] = 0;
    ary_b[0] = 0;
    rep(i,n)
    {
        if (s[i]=='R')
        {
            ary_r[i+1] = ary_r[i]+1;
        }
        else
        {
            ary_r[i+1] = ary_r[i];
        }

        if (s[i]=='G')
        {
            ary_g[i+1] = ary_g[i]+1;
        }
        else
        {
            ary_g[i+1] = ary_g[i];
        }
        
        if (s[i]=='B')
        {
            ary_b[i+1] = ary_b[i]+1;
        }
        else
        {
            ary_b[i+1] = ary_b[i];
        }
    }
    ll ans = 0;

    rep(i,n-2) REP(j,i+1,n-1)
    {
        if (s[i]==s[j])
        {
            continue;
        }
        else
        {
            bool r=false;
            bool g=false;
            bool b=false;
            if (s[i]=='R' || s[j]=='R') r = true;
            if (s[i]=='G' || s[j]=='G') g = true;
            if (s[i]=='B' || s[j]=='B') b = true;

            if (!r)
            {
                ans+=ary_r[n]-ary_r[j+1];
                if (j+j-i<n && s[j+(j-i)]=='R') ans--;
            }

            if (!g)
            {
                ans += ary_g[n] - ary_g[j+1];
                if (j+j-i<n && s[j+j-i]=='G') ans--;
            }

            if (!b)
            {
                ans += ary_b[n] - ary_b[j+1];
                if (j+j-i<n && s[j+j-i]=='B') ans--;
            }
        }
    }
    cout << ans << endl;
    
}




Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
char T;int l,a,b,x[999],d[999],M,N,y[999],z[999],i,j;
int main(){
	while(1){
		M=0;
		memset(y,0,3996);
		cin>>b>>l;if(!l){break;}
		for(i=1;i<=b;i++){
			cin>>T>>x[i];
			if(T=='L'){d[i]=0;M=max(M,x[i]);}
			else{d[i]=1;M=max(M,l-x[i]);}
		}
		N=0;
		for(i=1;i<M+2;i++){
			memset(z,0,sizeof(z));
			for(j=b;j>0; j--) {
				if(!y[j]) {
					if(!d[j]){
						x[j]--;
					}
					else{
						x[j]++;
					}
					if(x[j]<0||x[j]>l){
						y[j]=1;
					}
					else{
						z[x[j]]++;
					}
					if(M+1==i){
						if(N){
							if(x[j]<0){N=j;}
						}
						else{
							N=j;
						}
					}
				}
			}
			for(j=b;j>0;j--){
				if(z[x[j]]>1){
					if(d[j]){d[j]=0;}
					else{d[j]=1;}
				}
			}
		}
		printf("%d %d\n",M,N);
	}
}

Measured memory_bytes: 1160
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    char s[102];
    scanf("%s", s);
    int i, r, b;
    r = b = 0;
    for (i = 0; i < n; i++)
        if (s[i] == 'R')
            r++;
        else
            b++;
    if (r > b)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k, s;
    cin >> n >> k >> s;
    if (s == 1000000000) {
        rep(i, n) {
            if (i != 0) cout << " ";
            if (i < k) cout << s;
            else cout << s-1;
        }
        cout << endl;
    } else {
        rep(i, n) {
            if (i != 0) cout << " ";
            if (i < k) cout << s;
            else cout << s+1;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl

const ll INF=1e9+7;
const ll N = 100001;
ll n,ans=0;
vector<ll> a;
vector<ll> v;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	FOR(i,0,n){
		ll k;
		cin>>k;
		a.pb(k);
	}
	SORT(a);
	ll i=0;
	while(1){
		ll k=NUM(a,a[i]);
		i+=k;
		ll p=1;
		if(k%2==0){
			p=2;
			ans++;
		}
		v.pb(p);
		if(i>=n)break;
	}
	ans%=2;
	cout<<(v.size()-ans)<<endl;
	return 0;
}

Measured memory_bytes: 2548
n = int(input())
ar = []

for i in range(n):
  ar.append(input())


for i in range(n-1):
  
 
  if ar[i][-1] != ar[i+1][0]:
    print('No')
    exit()
  if ar.count(ar[i])>1:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 9168
void main(){
	int a, b;
	scanf("%d %d", &a, &b);
	int ans = (a + b)%24;
	ans.writeln();
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;      
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
int main(){
string str, ans = "No";
  cin >> str;
  if(str.at(0) == str.at(1) && str.at(2) == str.at(3) && str.at(0) != str.at(2))
    ans = "Yes";
    else if(str.at(0) == str.at(2) && str.at(1) == str.at(3) && str.at(0) != str.at(1))
      ans = "Yes";
  		else if(str.at(0) == str.at(3) && str.at(1) == str.at(2) 
                && str.at(0) != str.at(1))
          ans = "Yes";
          cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
    int n;
    cin >> n;
    map< int,int > students;
    for(int i=1;i<=n;i++){
        int x;
        cin >> x;
        students[x]=i;
    }
    for(map< int,int >::iterator it = students.begin();it != students.end();it++)   cout << it->second << " ";
    cout << endl;
}


Measured memory_bytes: 5504
using System;
using System.Collections.Generic;
using System.Linq;
//using System.Numerics;
class Program
{     
    
    public void Slove()
    {
        var inputs = Console.ReadLine().Split();
        int xCount = int.Parse(inputs[2]) - int.Parse(inputs[0]);
        int yCount = int.Parse(inputs[3]) - int.Parse(inputs[1]);
        List<char> result = new List<char>();
        foreach(int i in Enumerable.Range(0, xCount))
            result.Add('R');
        foreach(int i in Enumerable.Range(0, yCount))
            result.Add('U');
        foreach(int i in Enumerable.Range(0, xCount))
            result.Add('L');
        foreach(int i in Enumerable.Range(0, yCount + 1))
            result.Add('D');

        foreach(int i in Enumerable.Range(0, xCount + 1))
            result.Add('R');
        foreach(int i in Enumerable.Range(0, yCount + 1))
            result.Add('U');
        result.Add('L');
        result.Add('U');
        foreach(int i in Enumerable.Range(0, xCount + 1))
            result.Add('L');
        foreach(int i in Enumerable.Range(0, yCount + 1))
            result.Add('D');
        result.Add('R');
        System.Console.WriteLine(string.Join("", result));
    }
    
    static void Main(string[] args)
    {
        new Program().Slove();
    }
}


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

int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<int> dist(n);
  for (int i = 1; i < n; ++i) {
    dist[i] = a[i] - a[i - 1];
  }
  dist[0] = k - a[n - 1] + a[0];
  int sum = accumulate(dist.begin(), dist.end(), 0);
  int mx = *max_element(dist.begin(), dist.end());
  cout << sum - mx << endl;
}


Measured memory_bytes: 1792
def main(le=len):
    n, k = map(int, raw_input().split())
    a = []
    g = [[] for _ in xrange(n)]
    for _ in xrange(n - 1):
        u, v = map(int, raw_input().split())
        u -= 1
        v -= 1
        a.append((u, v))
        g[u].append(v)
        g[v].append(u)
    st = []
    pu = st.append
    po = st.pop
    ans = 0
    if k % 2:
        k = k / 2 + 1
        for u, v in a:
            c = 0
            pu((u, k, v))
            pu((v, k, u))
            while c < le(st):
                u, d, p = st[c]
                d -= 1
                if d:
                    for v in g[u]:
                        if v != p:
                            pu((v, d, u))
                c += 1
            if ans < c:
                ans = c
            del st[:]
    else:
        k = k / 2 + 1
        for i in xrange(n):
            c = 0
            pu((i, k, -1))
            while c < le(st):
                u, d, p = st[c]
                d -= 1
                if d:
                    for v in g[u]:
                        if v != p:
                            pu((v, d, u))
                c += 1
            if ans < c:
                ans = c
            del st[:]
    print n - ans
main()


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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define FORR(v, c) for (auto &v : c)
#define F first
#define S second
#define SQ(x) (x)*(x)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define dbg(x) cerr<<#x<<" = " << (x) << endl
#define pnl(x) cout << x << '\n'
#define pns(x) cout << x << ' '
#define read(x) cin >> x
#define read2(x,y) cin >> x >> y
#define read3(x, y, z) cin >> x >> y >> z
#define read4(a, b, c, d) cin >> a >> b >> c >> d
#define readv(v) FORR(c,v) read(c)

struct Arrete { int v, c;};
struct Point {int x, y; double distance(Point other) const {return sqrt(SQ(x-other.x)+SQ(y-other.y));}};

typedef	vector<int>	vi;
typedef pair<int,int>	ii;
typedef vector<string>	vs;
typedef vector<ii>	vii;
typedef vector<Arrete>	vg;
typedef vector<long long>	vl;
typedef	long long ll;

const int MAXN = 3000;

double prob[MAXN];

int		main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	int N;
	read(N);
	FOR(i, 0, N)
	{
		double p;
		read(p);
		if (i == 0)
			prob[0] = 1-p, prob[1] = p;
		else
			for (int j(i+1); j >= 0; --j)
				prob[j] = p * (j ? prob[j-1] : 0)+ (1-p)*prob[j];
	}

	double ans = 0;
//	FOR(i,0, N+1)
//	cout << i << ':' << prob[i] << endl;
	for (int i(0); i <= N; ++i)
		if (i > N-i)
			ans += prob[i];
	cout << setprecision(9) << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
//#include <string.h>

int main() {
    int n, m, l, i, j, k;
    long s;

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

    int first[n][m];
    int second[m][l];
    long out[n][l];

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

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

    for (i = 0; i < n; i++) {
        for (j = 0; j < l; j++) {
            s = 0;
            for (k = 0; k < m; k++) {
                s += first[i][k] * second[k][j];
            }
            out[i][j] = s;
        }
    }

    for (int i1 = 0; i1 < n; ++i1) {
        for (int j1 = 0; j1 < l; ++j1) {
            if (j1 == l-1)
                printf("%ld\n", out[i1][j1]);
            else
                printf("%ld ", out[i1][j1]);
        }
    }

    return 0;
}


Measured memory_bytes: 2080
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}
func ch(a byte, R, S, P int) (byte, int) {
	var ret byte
	var pt int
	switch a {
	case 'r':
		ret = 'p'
		pt = P
	case 's':
		ret = 'r'
		pt = R
	case 'p':
		ret = 's'
		pt = S
	}
	return ret, pt
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N, K := getInt(), getInt()
	R, S, P := getInt(), getInt(), getInt()
	T := getString()

	ans := 0
	m := make([]byte, N)
	for i := 0; i < N; i++ {
		my, pt := ch(T[i], R, S, P)
		if i-K >= 0 && m[i-K] == my {
			my = 'x'
			pt = 0
		}
		ans += pt
		m[i] = my
	}
	out(ans)
}


Measured memory_bytes: 1024
t = input()
a1, a2 = 0, 0
for i in range(len(t)):
  if i % 2 == 0:
    if t[i] == '0':
      a1 += 1
    else:
      a2 += 1
  else:
    if t[i] == '1':
      a1 += 1
    else:
      a2 += 1
print(min(a1, a2))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;cin>>n>>m;
  lvector a(m+10,0),b(m+10,0);
  vector<lvector> c(20,lvector(m+10,0));
  rep(i,m) {
    cin>>a[i+1]>>b[i+1];
    rep(j,b[i+1]) {cin>>c[j+1][i+1];}
  }
  ll inf=1e9,tmp;
  lvector dp(5000,inf);dp[0]=0;
  for(ll k=1;k<=m;k++) {
    tmp=0;
    for(ll j=1;j<=b[k];++j) tmp|=(1<<(c[j][k]-1));
    for(ll bits=0;bits<(1<<n);bits++) dp[bits|tmp]=min(dp[bits|tmp],dp[bits]+a[k]);
  }
  print((dp[(1<<n)-1]==inf)?-1:dp[(1<<n)-1]);
  return 0;
}

Measured memory_bytes: 512
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};



int main(){
    IOS;
    make(ll,n);
    make2(ll,a,b);
    cout<<max(0ll,(n-2)*(b-a)+1)<<endl;


    return 0;
}


Measured memory_bytes: 3616
A, B = map(int, input().split())

sum_A = 0
for i in range((A-1) % 4 + 1):
    sum_A = sum_A ^ ((A-1) - i)

sum_B = 0
for i in range(B % 4 + 1):
    sum_B = sum_B ^ (B - i)

result = sum_A ^ sum_B

print(result)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#include<typeinfo>
#define ll  long long 
#define ull unsigned long long 
#define ld  long double
#define pb  push_back
#define eb  emplace_back
#define pf  push_front
#define mp  make_pair
#define all(v)  v.begin(),v.end()
#define BP(n)  __builtin_popcount(n)
#define bs(v,x)  binary_search(all(v),x)
#define lb(v,x) lower_bound(all(v),x) //first equal to or lower than element
#define ub(v,x) upper_bound(all(v),x) //first greater than element
#define rep(i,n)  for(i=0;i<n;i++)
#define rep1(j,n)  for (j=i+1;j<n;j++)
#define Unique(v)  vector<int>::iterator it; sort(all(v)); it= unique(all(v)); v.resize(distance(v.begin(),it))
#define M  1000000007
#define PI  acos(-1.0)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
using namespace std;
void input(vector<int>& v,int n){ int i,io; rep(i,n) { cin>>io; v.pb(io);} }
void output(vector<int> v) { int i; rep(i,v.size()) cout<<v.at(i); }
map<int,int>  frequency(vector<int> v){ int i; map<int,int> m; rep (i,v.size()) {  if (m.find(v[i])==m.end()) m.insert({v.at(i),1}); else m[v.at(i)]++; } return m; }
bool perfsq(ll n){ return (ceil(sqrt(n))==floor(sqrt(n))); }
bool ispower2(int n) { if (n&(n-1)==0) return true; else return false; }
bool binary_pred(int a,int b){ return a==b; }
int string_to_int(string s) { stringstream geek(s); ll x = 0; geek >> x; return x; }
int digcount(ll n) { return (floor(log10(n)) + 1); }
bool isprime(ll n) {
    if (n <= 1)
        return false;
    for (ll i = 2; i*i <= n; i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}
vector<ll> get_factors(ll n) {
    vector<ll> ans;
    for (ll i=2;i*i<=n;i++) {
        if (n % i == 0) {
            ans.pb(i);
            if (n/i != i)
                ans.pb(n/i);
        }
    }
    if (n != 1) {
        ans.pb(1);
        ans.pb(n);
    }
    else 
        ans.pb(1); 
    sort(all(ans));
    return ans;
}

void getans() {
   int i,n,a,b;
   long ans = 0;
   cin >> n;
   bool f = true,f1 = true;
   vector<int> v1,v2;
    for (i=0;i<n;i++) {
        cin >> a >> b;
        v1.pb(a),v2.pb(b);
    }
    for (i=0;i<n;i++)  {
        for (int j=i+1;j<n;j++) {
            for (int k=j+1;k<n;k++) {
                if (v1[i] == v2[i] and v1[j] == v2[j] and v1[k] == v2[k]) {
                    f = false;
                    cout<<"Yes"<<endl;
                    j = n;
                    i = n;
                    break;
                }
                else {
                    j = n;
                    break;
                }
            }
        }
    }
    if (f)  
        cout<<"No"<<endl;
}
int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt", "w", stderr);
    #endif
    int T = 1;
    //cin >> T;
    while (T--) 
        getans();
}
// Check for corner cases
// Check for special case like n = 0 or n = INT_MAX
// Check for Buffer Overflow or use of unsigned variable if any
// Check if problem can be solved mathematically

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }



int main() {
  int a,b;
  cin >> a >> b;
  cout << a+b/2 << endl;
}



Measured memory_bytes: 256
fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main(args: Array<String>) {
    data class History(val from: Pair<Int, Int>, val to: Pair<Int, Int>) {
        override fun toString(): String {
            return "${from.first + 1} ${from.second + 1} ${to.first + 1} ${to.second + 1}"
        }
    }
    val (h, w) = intList()
    val hw = Array(h) { Array(w) { 0 } }
    repeat(h) { y ->
        val a = intList()
        a.forEachIndexed { x, v ->
            hw[y][x] = v
        }
    }
    var n = 0
    val history = mutableListOf<History>()
    repeat(h) { y ->
        repeat(w) { x ->
            val v = hw[y][x]
            if (y + 1 == h) {
                if (x + 1 < w && v % 2 == 1) {
                    n++
                    hw[y][x]--
                    hw[y][x + 1]++
                    history.add(History(Pair(y, x), Pair(y, x + 1)))
                }
            } else {
                if (v % 2 == 1) {
                    n++
                    hw[y][x]--
                    hw[y + 1][x]++
                    history.add(History(Pair(y, x), Pair(y + 1, x)))
                }
            }
        }
    }
    buildString {
        appendln(n)
        history.forEach {
            appendln(it)
        }
    }.let {
        println(it.trimIndent())
    }
}


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

int main()
{
  long long a,b,c,d,e;
  cin >> a >> b >> c >> d;
  e=a*c;
  if(e<a*d){
    e=a*d;
  }
  if(e<b*c){
    e=b*c;
  }
  if(e<b*d){
    e=b*d;
  }
  cout << e;
 return 0;
}

Measured memory_bytes: 3648