akhauriyash/Code-Regression huggingface dataset:
gradeList = []
i = 0

while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    mf= m + f
    if m == -1 or f == -1:
        grade = 'F'
    elif m + f >= 80:
        grade = 'A'
    elif mf >=65 and mf < 80:
        grade = 'B'
    elif mf >= 50 and mf < 65:
        grade = 'C'
    elif mf >= 30 and mf < 50:
        if r >= 50:
            grade = 'C'
        else:
            grade = 'D'
    else:
        grade = 'F'
    
    gradeList.append(grade)

for i in range(len(gradeList)):
    print(gradeList[i])


Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(v) (v).size()
using namespace std;
template <typename T> void chmax(T &x,T y){x=x>y?x:y;return;}
template <typename T> void chmin(T &x,T y){x=x<y?x:y;return;}

int n;
set<string> s;

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		string str;
		cin>>str;
		s.insert(str);
	}
	cout<<sz(s)<<endl;
	return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int ans=-1;
  rep(i,10000){
    if(i*8/100==a&&i/10==b){
      ans=i;
      break;
    }
  }
  cout << ans << endl;
}


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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x));
#define umin(m, x) (m = min(m, x));

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

using ll = long long int;

using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;

using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;

inline void yn(bool f) { cout << (f ? "Yes" : "No") << endl; }


int main() {
    ll n, m;
    cin >> n >> m;

    vl a(m);
    rep(i, m) cin >> a[i];

    ll cnt = 0;
    rep(i, m) cnt += a[i];

    if (cnt > n)
        cout << -1 << endl;
    else
    {
        cout << n - cnt << endl;
    }
    

    return 0;
}


Measured memory_bytes: 3676
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,k,c;cin>>n>>k>>c;
  string s;cin>>s;
  V<int> v(n,0);
  ll rem=0,cnt=0;

  rep(i,0,n){
    if(rem){
      rem--;
      continue;
    }

    if(s[i]=='x')continue;

    rem=c;
    v[i]++;
    cnt++;
    if(cnt>k)return 0;
  }
//cerr<<"DE"<<ENDL;

  rem=0;cnt=0;
  repr(i,0,n){
    if(rem){
      rem--;
      continue;
    }

    if(s[i]=='x')continue;

    rem=c;
    v[i]++;
    cnt++;
    if(cnt>k)return 0;
  }

  rep(i,0,n){
    if(v[i]==2)cout<<i+1<<ENDL;
  }
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 2580
N, Ma, Mb = map(int, input().split())
ABC = [list(map(int, input().split())) for _ in range(N)]

inf = float("inf")

dp = [ [ [inf] * 401 for _ in range(401)] for _ in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
  a,b,c = ABC[i]
  for ma in range(400):
    for mb in range(400):
      dp[i+1][ma][mb] = min(dp[i+1][ma][mb],
                            dp[i][ma][mb])
      if ma + a > 400: continue
      if mb + b > 400: continue
        
      dp[i+1][ma+a][mb+b] = \
      min(dp[i+1][ma+a][mb+b],
          dp[i][ma][mb]+c)
      
ans = inf
for i in range(1,40000):
  if Ma*i > 400 or Mb*i > 400: break
  ans = min(ans, dp[N][Ma*i][Mb*i])

if ans == inf:
  print(-1); exit()
print(ans)

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

#define endl '\n'
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define SORT(v) sort(all(v))
#define SORTD(v) sort(all(v), greater<int>())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<30
#define v(T) vector<T>
#define vv(T) v(v(T))
#define print(x) cout<<x<<endl
#define printv(v) for(auto i : v){cout<<i<<" ";}cout<<endl
#define printu(v) for(auto i : v){print(i);}
#define readv(v, n) for (int i=0;i<n;i++)cin >> v[i]
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

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

int i, j, k;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;
	cin >> a >> b >> c;
	int ans = std::min({a + b, a + c, b + c});
	print(ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,n,ANS[200005],Ne[400005],E[400005],HEAD[200005],m,s,e;
void ADD(int s,int e) {
	Ne[++b]=HEAD[s],HEAD[s]=b,E[b]=e;
}
void DFS(int i,int f) {
	for(int z=HEAD[i]; z; z=Ne[z])
		if(E[z]!=f)ANS[E[z]]+=ANS[i],DFS(E[z],i);
}
int main() {
	scanf("%d %d",&n,&m);
	for(int i=1; i<n; i++) {
		scanf("%d %d",&s,&e);
		ADD(s,e),ADD(e,s);
	}
	for(int i=1; i<=m; i++)scanf("%d %d",&a,&c),ANS[a]+=c;
	DFS(1,0);
	for(int i=1; i<=n; i++)printf("%d ",ANS[i]);
	return 0;
}

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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long, long>;
using pdd = pair<ld, ld>;

template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<ll>;
V(size_t) -> V<ll>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

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; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll N;
    cin >> N;
    V<ll> P(N);
    REP(i, N) cin >> P[i];

    V<ll> ids(N);
    iota(ids.begin(), ids.end(), 0);

    sort(ids.begin(), ids.end(), [&](ll x, ll y){
        return P[x] > P[y];
    });  

    ll res = 0;
    multiset<ll> st;
    st.insert(-1);
    st.insert(-1);
    st.insert(N);
    st.insert(N);

    REP(i, N){
        ll id = ids[i];
        st.insert(id);
        auto itr = st.lower_bound(id);
        ll a = *prev(itr, 2);
        ll b = *prev(itr, 1);
        ll c = *next(itr, 1);
        ll d = *next(itr, 2);
        ll tmp = 0;
        tmp += (b-a)*(c-id);
        tmp += (d-c)*(id-b);
        res += tmp * P[id];
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 9516
N, K = map(int, input().split())
R,S,P = map(int, input().split())
T = input()

dict_sample = {
    "r":P,
    "s":R,
    "p":S
}
ans = 0

A = [[] for k in range(K)]
for i in range(N):
    A[i%K].append(T[i])
    ans += dict_sample[T[i]]
#print(ans)    
for k in range(K):
    cnt = 0
    tmp = A[k]
    for i in range(len(tmp)-1):
        if tmp[i]!=tmp[i+1]:
            if cnt > 0:
                cnt+=1
                ans -= (cnt // 2 ) * dict_sample[tmp[i]]
            cnt = 0
        else:
            cnt += 1

    if cnt>0:
        cnt+=1
        ans -= (cnt // 2 ) * dict_sample[tmp[-1]]
        
print(ans)



Measured memory_bytes: 13436
def main():
    n = int(input())
    a = list(map(int, input().split()))

    mask = 0
    for i in range(n):
        mask = mask ^ a[i]

    ans = [0 for _ in range(n)]
    for i in range(n):
        ans[i] = a[i] ^ mask

    print(' '.join([str(x) for x in ans]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 41780
#include<stdio.h>


int main(){

  int n, i, x, y, b, p;
  int fee[400];

  scanf("%d", &n);

  for(i=0;i<n;i++){

    scanf("%d %d %d %d", &x, &y, &b, &p);

    if(b>=5 && p>=2){
      fee[i] = (x*b + y*p)*0.8;
    }else if(b>=5 && p<2){
      if(x*b+y*p < (x*b+y*2)*0.8)
	fee[i] = x*b + y*p;
      else
	fee[i] = (x*b + y*2)*0.8;
    }else if(b<5 && p>=2){
      if(x*b+y*p < (x*5+y*p)*0.8)
	fee[i] = x*b + y*p;
      else
	fee[i] = (x*5+y*p)*0.8;
    }else if(b<5 && p<2){
      if(x*b+y*p < (x*5+y*2)*0.8)
	fee[i] = x*b + y*p;
      else
	fee[i] = (x*5 + y*2)*0.8;
    }
  }

  for(i=0;i<n;i++){
    printf("%d\n", fee[i]);
  }
  
  
  return 0;
  
}

Measured memory_bytes: 600
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
ll dp[100001];
int q(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int n;
int f(int a[]){
  int m=0;
  FOR(n){
    if(m<i*10)return 0;
    m=max(m,a[i]+i*10);
  }
  return 1;
}
int main(void) {
  scanf("%d",&n);
  int a[n],b[n];
  FOR(n){
    scanf("%d",&a[i]);
    b[n-i-1]=a[i];
  }
  char s[2][4]={"no","yes"};
  PRS(s[f(a)*f(b)]);
  return 0;
}


Measured memory_bytes: 4080
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstdio>
#include <random>

#define fol(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    int x,a,b;
    string s;
    cin >> s;
    char al = 'a';
    bool flag = false;
    fol(i,26){
        if (s.find(al)==-1) {
            flag = true;
            break;
        }
        al = (char)(al + 1);

    }
    flag ? cout << al << endl : cout << "None" <<endl;
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define SIZE(x) ((ll)(x).size()) 
#define MAX(x) *max_element(ALL(x)) 
#define MIN(x) *min_element(ALL(x)) 
#define ALL(x) (x).begin(),(x).end() 

#define INF 1000000000000 
#define MOD 1000000007 
#define MAXR 100000 

#define PB push_back 
#define MP make_pair 
#define F first 
#define S second 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int m, n;
    cin >> n >> m;
    ll a[100005];
    REP(i, n) cin >> a[i];
    priority_queue<ll> q;
    REP(i, n) q.push(a[i]);
    REP(i, m){
        ll p = q.top() / 2;
        q.pop();
        q.push(p);
    }
    ll ans = 0;
    REP(i, n){
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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(){
    ll N,sum=0;
    cin>>N;
    sum=N*(N+1)/2;
    for(ll i=1;i<=N;i++){
        if(i%3==0||i%5==0) sum-=i;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3624
package main

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

func run() {
	n := nextInt()
	Println((n) * (n - 1) / 2)
}

// --- template ---
// Thanks https://gist.github.com/halllllll/853ab587fd82ee3ffe6f7fb7fb499695

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

// Caution: You will get unexpected result if a single token is larger than this size.
const BufferSize = 64 * 1024 * 1024

func Print(a ...interface{}) (n int, err error) {
	return fmt.Fprint(out, a...)
}

func Printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, format, a...)
}

func Println(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(out, a...)
}

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

func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		log.Fatal(err)
	}
	return a
}

func nextFloat() float64 {
	a, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}

func main() {
	sc.Buffer(make([]byte, 0, BufferSize), BufferSize)
	sc.Split(bufio.ScanWords)
	run()
	out.Flush()
}


Measured memory_bytes: 2816
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	int N;
	cin >> N;
	vector<lint>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	int M;
	cin >> M;
	lint tmp = 0;
	set<lint>S;
	rep(i, M) {
		cin >> tmp;
		S.insert(tmp);
	}
	rep(i, N) {
		if (S.count(A[i])) {
			cout << A[i] << endl;
		}
	}
}




Measured memory_bytes: 13624
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

vector<int> fac(300001); //n!(mod M)
vector<int> ifac(300001); //k!^{M-2} (mod M)

long long fpow(long long a,long long n){
  long long ret=1;
  if(n==1) return a;
  if(n%2==0) {
      ret = fpow(a*a%mod, n/2) %mod ;
  }else {
      ret = (a%mod)*fpow(a*a%mod, n/2) %mod;
  }
  return ret %mod;
}
int comb(int a, int b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    int tmp = ifac[a-b]* ifac[b] % mod;
    return tmp * fac[a] % mod;
}
const int D = 60;
int to[D][MX];


signed main(){
    int n,m;
    cin >> n >> m;
    vector<int> a, c;
    vector<int> dp(5000, inf);
    dp[0] = 0;
    rep(i,m) {
        int x, y;
        cin >> x >> y;
        a.push_back(x);
        int num=0;
        rep(j,y) {
            int k;
            cin >> k;

            k--;
            num |= 1<<k;
        }
        c.push_back(num);
    }


    rep(j,1<<n) {
        if(dp[j]==inf) continue;
        rep(i,m) {
            dp[j|c[i]] = min(dp[j] + a[i], dp[j|c[i]]);
        } 
    }
    if(dp[(1<<n)-1]==inf) cout << -1 << endl;
    else cout<<dp[(1<<n) - 1] << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int N,K; cin >>N>>K;
  int r,s,p; cin >>r>>s>>p;
  string T; cin >>T;
  ll ans = 0;
  vector<string> groups(K, "");
  rep(i, N) {
    groups[i%K] += T[i];
  }
  rep(i,K) {
    for(int j=0; j<groups[i].length(); j++) {
      if (groups[i][j] == 'r') ans += p;
      if (groups[i][j] == 'p') ans += s;
      if (groups[i][j] == 's') ans += r;
      if (j+1 < groups[i].length() && groups[i][j] == groups[i][j+1]) j++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5120
def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

n = iinp()
a = lmiinps()

ans = 0

for i in range(n-1):
    if a[i+1] < a[i]:
        ans += (a[i] - a[i+1])
        a[i+1] = a[i]

print(ans)

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

#define PI acos(-1.0)
#define nl '\n'

typedef long long int ll;
typedef unsigned long long int  llu;

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

    double s,ans;
    cin>>s;
    ans=2*PI*s;
    cout<<fixed<<setprecision(20)<<ans<<nl;
    return 0;
}


Measured memory_bytes: 3804
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	String a = sc.next();
    System.out.println("ABC" + a);
  }
}

Measured memory_bytes: 21972
#include <vector>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <map>
#include <unordered_map>
#include <ctime>
#include <cassert>
#include <cstring>
#include <sys/time.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[]){
  int a, b;
  cin >> a >> b;
  int c = a*b;
  if(a<1||a>9||b<1||b>9){
    c = -1;
  }
  cout << c << endl;
  return 0;
}


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

using namespace std;

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int a, total;
  cin >> a;
  total = a + (a*a) + (a*a*a);
  cout << total;
}

Measured memory_bytes: 3600
#include <stdio.h>
void swap(int *x, int *y) //二つの変数の値を入れ替える関数
{
    int tmp = *x;
    *x = *y;
    *y = tmp;
}
int main(void)
{
    int a, b, c;

    scanf("%d %d %d", &a, &b, &c);

    while (1)
    {
        if (a > b)
        {
            swap(&a, &b); //関数が機能しない。何故？
        }
        if (b > c)
        {
            swap(&b, &c);
        }
        if (a <= b && b <= c)
        {
            break;
        }
    }

    printf("%d %d %d\n", a, b, c);

    return 0;
}


Measured memory_bytes: 2704
#include <bits/stdc++.h> 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
  string s;
  cin>>s;
  bool ans=true;
  rep(i,s.size()){
    if(i%2==0&&s[i]=='L'){ans=false;}
    if(i%2==1&&s[i]=='R'){ans=false;}}
  if(ans){cout<<"Yes"<<endl;}
  else cout<<"No"<<endl;
}

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

int main() {
    vector<ll> a(3); REP(i, 3) cin >> a[i];

    if ((a[0] % 2) * (a[1] % 2) * (a[2] % 2) == 0)
        cout << 0 << endl;
    else {
        sort(a.begin(), a.end());
        cout << a[0] * a[1] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <boost/range/algorithm/find.hpp>

using namespace std;

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

    vector<int> p_arr(n);
    for (auto& p : p_arr) {
        cin >> p;
    }

    int approx = x;
    auto is_decided = false;
    for (auto i = 0; ; ++i) {
        if (boost::find(p_arr, x + i) == end(p_arr)) {
            approx = x + i;
            is_decided = true;
        }
        if (boost::find(p_arr, x - i) == end(p_arr)) {
            approx = x - i;
            is_decided = true;
        }
        if (is_decided) {
            break;
        }
    }

    cout << approx << endl;

    return 0;
}


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

using namespace std;

#define null -1

struct node{

    int parent, left, right;

};

node T[30];
int Depth[30], Height[30], sibling[30];

//??±?????¢?´¢

void setDepth( int u, int p ){

    Depth[u] = p;

    if( T[u].right != null ){

        setDepth( T[u].right, p + 1 );

    }

    if( T[u].left != null ){

        setDepth( T[u].left, p + 1 );

    }

}

//????????¢?´¢

int setHeight( int u){

    int h1 = 0, h2 = 0;

    if( T[u].right != null ){

        h1 = setHeight(  T[u].right ) + 1;

    }

    if( T[u].left != null ){

        h2 = setHeight(  T[u].left ) + 1 ;

    }

    return Height[u] = max( h1, h2);

}

//????????¢???

void getsibling( int u){

    if( T[u].parent == null ) sibling[u] = -1;

    else if( T[ T[u].parent ].left != u ){

        sibling[u] = T[ T[u].parent ].left;

    }else if( T[ T[u].parent ].right != u ){

        sibling[u] = T[ T[u].parent ].right;

    }

}

//??????????????¢??°

void print( int n){

    int i, j;

    for( i = 0; i < n; i++ ){

        printf("node %d: parent = %d, sibling = %d, degree = ", i, T[i].parent, sibling[i] );

        if( T[i].left != null && T[i].right != null ) printf("2, ");
        else if( T[i].left == null && T[i].right == null ) printf("0, ");
        else printf("1, ");

        printf("depth = %d, height = %d, ", Depth[i], Height[i]);

        if( T[i].parent == null ) printf("root");
        else if( Height[i] == 0 ) printf("leaf");
        else printf("internal node");


        printf("\n");

    }

}


int main(){

    int n, i, num, l, r,  root, v;

    scanf("%d", &n);

    for( i = 0; i < n; i++ ){

        T[i].left = null;
        T[i].right = null;
        T[i].parent = null;

    }

    for( i = 0; i < n; i++ ){

        scanf("%d", &num);

        scanf("%d %d", &l, &r);

        T[num].left = l;
        T[num].right = r;

        if( l != null && r != null ){

            T[l].parent = num;
            T[r].parent = num;

        } else if( l != null && r == null ){

            T[l].parent = num;

        } else if( r != null && l == null ){

            T[r].parent = num;

        } 

    }

    for( i = 0; i < n ; i++ ){

        if( T[i].parent == null ) root = i;

        getsibling(i);

    }

    setDepth( root, 0);
    setHeight( root );

    print(n);

}

Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

int main(){
    int n;
    while(cin >>n,n){
        vector<ll> ux,uy;

        vector<pi> window(n);
        rep(i,n){
            int x,y;
            cin >>x >>y;
            window[i] = {x,y};
            ux.pb(x);
            uy.pb(y);
        }

        vector<pi> curtain(4);
        rep(i,4){
            int x,y;
            cin >>x >>y;
            curtain[i] = {x,y};
            ux.pb(x);
            uy.pb(y);
        }

        sort(all(ux));
        ux.erase(unique(all(ux)), ux.end());
        sort(all(uy));
        uy.erase(unique(all(uy)), uy.end());

        auto cover = [&](const vector<pi> &v, double X, double Y){
            int ct = 0;
            int V = v.size();
            rep(i,V){
                int j = (i+1)%V;
                if(v[i].fi==v[j].fi && X<v[i].fi){
                    int ly = min(v[i].se, v[j].se);
                    int ry = max(v[i].se, v[j].se);

                    if(ly<Y && Y<ry) ++ct;
                }
            }
            return ct%2 == 1;
        };

        int X = ux.size();
        int Y = uy.size();
        ll ans = 0;
        rep(i,X-1)rep(j,Y-1){
            ll area = (ux[i+1]-ux[i])*(uy[j+1]-uy[j]);
            double px = (ux[i]+ux[i+1])/2.0;
            double py = (uy[j]+uy[j+1])/2.0;

            if(cover(window,px,py) && !cover(curtain,px,py)) ans += area;
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3072
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long LL;

struct mat {
	LL a[2][2];
	mat() {memset(a, 0, sizeof a);}
};

const LL mod = 998244353;
LL c[1005000], f[1005000];
LL n, m;

mat operator * (mat a, mat b) {
	mat c;
	for(int i = 0; i <= 1; ++ i) for(int j = 0; j <= 1; ++ j) for(int k = 0; k <= 1; ++ k) (c.a[i][j] += a.a[i][k] * b.a[k][j] % mod) %= mod;
	return c;
}

mat ksm(mat a, LL b) {
	mat ans;
	ans.a[0][0] = 0; ans.a[0][1] = 0;
	ans.a[1][0] = 1; ans.a[1][1] = 1;
	if(b < 0) return ans;
	while(b) {
		if(b & 1) ans = ans * a;
		a = a * a;
		b >>= 1;
	}
	return ans;
}

LL ksm(LL a, LL b) {
	LL ans = 1;
	while(b) {
		if(b & 1) ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans % mod;
}

int main() {
	scanf("%lld%lld", &n, &m);
	mat fib;
	fib.a[1][0] = 1, fib.a[1][1] = 1, fib.a[0][0] = 0, fib.a[0][1] = 1;
	fib = ksm(fib, m + 2 * (n - 1) - 2);
	LL ans = fib.a[1][1];
	f[1] = 1, f[2] = 1;
	for(int i = 3; i <= (n << 1) + 10; ++ i) f[i] = (f[i - 1] + f[i - 2]) % mod;
	c[0] = 1; for(int i = 1; i <= n; ++ i) c[i] = c[i - 1] * ((m - 1 + i) % mod) % mod * ksm(i, mod - 2) % mod;
	for(int i = 1; i < n; ++ i) ans = (ans - f[i << 1] * c[n - i - 1] % mod) % mod;
	printf("%lld\n", (ans + mod) % mod);
} 

Measured memory_bytes: 8320
#include <iostream>

using namespace std;

int main()
{
    int n,a,i,s=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        if((i&1)&&(a&1)) s++;

    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 3616
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
au = []
at = []
for i in range(m):
  if a[i] < x:
    au.append(a[i])
  else:
    at.append(a[i])

auv = len(au)
atv = len(at)
print(min(auv,atv))

Measured memory_bytes: 9168
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int n;
vi v;

bool test() {
  string s , t;
  for(auto e : v) {
    s += char(".#"[e>>1]);
    t += char(".#"[e&1]);
  }
  cout << s << endl;
  cout << t << endl;
  cin >> s;
  if(s == "end")
    exit(0);
  return s[0] == 'T';
}

int main(){
  cin >> n;
  bool rev = false;
  while(true) {
    int i = 0;
    for(;i < 4;++i) {
      if(rev) v.insert(v.begin() , i);
      else v.pb(i);
      if(test()) break;
      if(rev) v.erase(v.begin());
      else v.pop_back();
    }
    if(i == 4) rev = true;
  }
  return 0;
}


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

class Program {
    private static int Main() {
        // 1行目は読み捨て
        var input = Console.ReadLine();
        // 2行目を読む
        input = Console.ReadLine();
        var values = input.Split( ' ' );

        var longValues = values.Select( _ => long.Parse( _ ) );
        long min = longValues.Min();
        long max = longValues.Max();
        long sum = longValues.Sum();

        var output = string.Format( "{0} {1} {2}", min, max, sum );
        Console.WriteLine( output );

        return 0;
    }
}

Measured memory_bytes: 6704
// C - Bugged
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

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

	int MAX = 0;
	vi S(N+1);
	for(int i=1; i<=N; ++i){
		cin>>S[i];
		MAX += S[i];
	}

	vvi dp(N+1, vi(MAX+1, false));
	dp[0][0] = true;
	for(int i=0; i<N; ++i){
		int s = S[i+1];
		for(int j=0; j<MAX; ++j){
			if(dp[i][j]){
				dp[i+1][j] = true;
				if(j+s<=MAX) dp[i+1][j+s] = true;
			}
		}
	}

	int ans = 0;
	for(int j=MAX; j>=0; --j){
		if(dp[N][j] && j%10){
			ans = j;
			break;
		}
	}
	cout<< ans <<endl;
}

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

#define int long long
#define uint unsigned int
#define pii pair<int, int>

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

#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)

#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))

#define PW(n) (1LL << (n))

using namespace std;

template <class T> inline bool CHMIN(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline void SORT(T &a) { sort(a.begin(), a.end()); }
template <class T> inline void REV(T &a) { reverse(a.begin(), a.end()); }
template <class T> inline void UNI(T &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }

template <class S, class T> ostream& operator << (ostream& os, const pair<S, T> v) {
  os << "(" << v.first << ", " << v.second << ")"; return os;
}

const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

/* ---------------------------------------------------------------------------------------------------- */

int N;
vector<int> G[150010];
double dp1[150010];
double dp2[150010];

void dfs1(int v, int pv) {
  int num = G[v].size();
  if (!(pv < 0)) num--;
  for (int& nv : G[v]) if (nv != pv) {
    dfs1(nv, v);
    dp1[v] += (dp1[nv] + 1) / num;
  }
}

void dfs2(int v, int pv, double d_pv) {
  double sum = 0;
  for (int& nv : G[v]) {
    sum += (nv == pv ? d_pv : dp1[nv]) + 1;
  }
  dp2[v] = sum / G[v].size();
  for (int& nv : G[v]) if (nv != pv) {
    double d_v = (G[v].size() == 1 ? 0 : (sum - dp1[nv] - 1) / (G[v].size() - 1));
    dfs2(nv, v, d_v);
  }
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  REP(i, N-1) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    G[u].PB(v);
    G[v].PB(u);
  }
  dfs1(0, -1);
  dfs2(0, -1, 0);
  REP(i, N) cout << dp2[i] << endl;

  return 0;
}

Measured memory_bytes: 18560
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int head(ll x){
    int ret = -1;
    while (x){
        ret = x % 10;
        x /= 10;
    }
    return ret;
}

int main() {
    int n, m = 10;
    cin >> n;
    VVL cnt(m, VL(m));
    FOR(x,1,n){
        cnt[x % 10][head(x)]++;
    }
    ll ans = 0;
    REP(a,m) REP(b,m){
        ans += cnt[a][b] * cnt[b][a];
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

static const int N = 4;
static const int N2 = 16;
static const int LIMIT = 45;

int MDTable[N2][N2];

struct Puzzle {
    int piece[N2];
    int space;
    int MD;
};

Puzzle state;
int limit;
int path[LIMIT];

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};

int getAllMD(Puzzle puzzle)
{
    int sum = 0;
    for (int i = 0; i < N2; i++)
    {
        if (puzzle.piece[i] == N2)
            continue;
        sum += MDTable[i][puzzle.piece[i] - 1];
    }
    return sum;
}

bool isSolved()
{
    for (int i = 0; i < N2; i++)
        if (state.piece[i] != (i + 1)) // 不正解
            return false;

    return true;
}

bool dfs(int depth, int prev)
{
    if (state.MD == 0)
        return true;
    if (depth + state.MD > limit)
        return false;

    int sx = state.space / N; // 空きマスのx座標
    int sy = state.space % N; // 空きマスのy座標
    Puzzle tmp;

    for (int direct = 0; direct < 4; direct++)
    {
        int tx = sx + dx[direct]; // 遷移先の空きマスのx座標
        int ty = sy + dy[direct]; // 遷移先の空きマスのy座標
        if (tx < 0 || tx >= N || ty < 0 || ty >= N)
            continue; // 枠外にでたら無視
        if (max(prev, direct) - min(prev, direct) == 2)
            continue;
        tmp = state;
        state.MD -= MDTable[tx * N + ty][state.piece[tx * N + ty] - 1];
        state.MD += MDTable[state.space][state.piece[tx * N + ty] - 1];
        swap(state.piece[state.space], state.piece[tx * N + ty]); // ピースを移動
        state.space = tx * N + ty;
        if(dfs(depth + 1, direct))
        {
            path[depth] = direct;
            return true;
        }
        state = tmp;
    }
    return false;
}

string iterative_deepening(Puzzle input)
{
    input.MD = getAllMD(input);
    
    for(limit = input.MD; limit <= LIMIT; limit++)
    {
        state = input;
        if(dfs(0, -100))
        {
            string answer = "";
            for(int i = 0; i < limit; i++)
                answer += dir[path[i]];
            return answer;
        }
    }
    return "unsolvable";
}

int main()
{
    for (int i = 0; i < N2; i++)
        for (int j = 0; j < N2; j++)
            MDTable[i][j] = abs(i / N - j / N) + abs(i % N - j % N);

    Puzzle input;

    for (int i = 0; i < N2; i++)
    {
        cin >> input.piece[i];
        if (input.piece[i] == 0)
        {
            input.piece[i] = N2;
            input.space = i;
        }
    }

    string answer = iterative_deepening(input);
    cout << answer.size() << endl;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl
using namespace std;
int main()
{
    int n, a;
    cin >> n >> a;
    yorn (n % 500 <= a)
    return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>
int main(){
	int a=100000,b,n;
	scanf("%d",&n);
	for(b=0;b<n;b++){
		a=a*1.05;
		if(a!=(a/1000)*1000){a=(a/1000+1)*1000;}
	}
	printf("%d\n",a);
	return 0;
}

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

using namespace std; 

const int MAX = 2e5 + 10 ;

long long dp[MAX] ;

vector< vector<int> >adj(MAX) ;

void dfs(int node , int par)
{
	dp[node] += dp[par] ;
	for(auto &child : adj[node])
	{
		if(child == par)
			continue ;
		dfs(child , node) ;
	}
	return ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n , q ;
	cin>>n>>q ;
	for(int i = 0 ; i < n-1 ; ++i)
	{
		int x , y ;
		cin>>x>>y ;
		adj[x].push_back(y) ;
		adj[y].push_back(x) ;
	}
	while(q--)
	{
		long long x , y ;
		cin>>x>>y ;
		dp[x] += y ;
	}
	dfs(1, 0) ;
	for(int i = 1 ; i <= n ; ++i)
		cout<<dp[i]<<" ";
	return 0 ;
}

Measured memory_bytes: 24320
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int cmp(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}

int binary(int v,int *b,int n){
  if(b[0]>=v) return 0;
  int l=0;
  int r=n;
  while(l+1<r){
    int m=(l+r)/2;
    if(b[m]<v){
      l=m;
    } else {
      r=m;
    }
  }
  return r;
}

int calc(int a,int *b,int n,int bit){
  int shift=1<<bit;
  return (binary(2*shift-a,b,n)-binary(shift-a,b,n))+(binary(4*shift-a,b,n)-binary(3*shift-a,b,n));
}

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)malloc(sizeof(int)*n);
  int *b=(int *)malloc(sizeof(int)*n);
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  for(i=0;i<n;i++) scanf("%d",b+i);
  int ans=0;
  int bit;
  for(bit=28;bit>=0;bit--){
    for(i=0;i<n;i++){
      a[i]%=(1<<(bit+1));
      b[i]%=(1<<(bit+1));
    }
    qsort(b,n,sizeof(int),cmp);
    int cnt=0;
    for(i=0;i<n;i++){
      cnt^=calc(a[i],b,n,bit);
    }
    if(cnt&0x01){
      ans|=1<<bit;
    }
  }
  printf("%d\n",ans);
  free(a);
  free(b);
  return;
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 2556
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int gcd(int x,int y)
{
	return y?gcd(y,x%y):x;
}
int a[100100];
int main()
{
	int n,i,k,g,mx=0;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)	scanf("%d",&a[i]),mx=max(mx,a[i]),i==1?g=a[i]:g=gcd(g,a[i]);
	if(k%g==0&&k<=mx)printf("POSSIBLE\n");
	else	printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 512
k="keyence"
S=input()
check=0
for i in range(7):
  if k[i]!=S[i]:
    for j in range(-1,-8+i,-1):
      if k[j]!=S[j]:
        check=1
        break
    break
if check==0:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int INF = 1 << 30;
int dy[] = {-1, 0, 0, 1};
int dx[] = {0, -1, 1, 0};
int n, m;
string c[110];

void solve() {
  c[0] = c[m + 1] = string(n + 2, '.');
  for (int i = 1; i <= m; i++) {
    cin >> c[i];
    c[i] = "." + c[i] + ".";
  }
  n += 2, m += 2;
  int dis[110][110];
  fill_n((int*)dis, 110 * 110, INF);
  dis[0][0] = 0;
  deque<pii> deq = {{0, 0}};
  while (!deq.empty()) {
    int y, x;
    tie(y, x) = deq.front(); deq.pop_front();
    if (c[y][x] == '&') {
      cout << dis[y][x] << endl;
      return;
    }
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny >= 0 && ny < m && nx >= 0 && nx < n) {
        int cost = (c[y][x] == '.' && c[ny][nx] == '#');
        if (dis[ny][nx] > dis[y][x] + cost) {
          dis[ny][nx] = dis[y][x] + cost;
          if (cost) deq.emplace_back(ny, nx);
          else deq.emplace_front(ny, nx);
        }
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while (cin >> n >> m, n) {
    solve();
  }  

  return 0;
}


Measured memory_bytes: 3264
x1,y1,x2,y2 = [int(i) for i in input().split()]
x3 = x2-(y2-y1)
y3 = y2+(x2-x1)
x4 = x1-(y2-y1)
y4 = y1+(x2-x1)
print(*[x3,y3,x4,y4])

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

int main() {
	// your code goes here
	int k;
	cin>>k;
	string str;
	cin>>str;
	if(str.size()<=k){
		cout<<str;
	}
	else{
		cout<<str.substr(0,k)<<"...";
	}
	return 0;
}

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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 2e3 + 5;
ll a[N], b[N], cnt = 0, n;
void bfs(){
        priority_queue<ll, vector<ll>, greater<ll>> q;
        for (int i = 1; i <= cnt; i++){
                if (b[i] > 0) q.push(b[i]);
        }
        while (true){
                ll now = q.top();
                q.pop();
                if (now >= n) {
                        cout << now;
                        exit(0);
                }
                for (int i = 1; i <= cnt; i++){
                        q.push(now * 10 + b[i]);
                }
        }
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        //freopen("VLJUM.INP", "r", stdin);
        //freopen("VLJUM.OUT", "w", stdout);
        ll k;
        cin >> n >> k;
        for (int i = 1; i <= k; i++){
                cin >> a[i];
        }
        for (int i = 0; i <= 9; i++){
                bool flag = true;
                for (int j = 1; j <= k; j++){
                        if (a[j] == i) flag = false;
                }
                if (flag){
                        cnt++;
                        b[cnt] = i;
                }
        }
        bfs();
}



Measured memory_bytes: 892
package main

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

func main() {
  var n,m int = NextInts()
  var num []int = make([]int,n)
  for i:=0;i<m;i++ {
    var a,b int = NextInts()
    num[a-1]++
    num[b-1]++
  }
  for i:=0;i<n;i++ {
    if num[i]%2 != 0 {
      fmt.Println("NO")
      return
    }
  }
  fmt.Println("YES")
}

var reader = bufio.NewReaderSize(os.Stdin,1000000)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInts() (int,int) {
  var s []string = strings.Split(NextLine()," ")
  a,_ := strconv.Atoi(s[0])
  b,_ := strconv.Atoi(s[1])
  return a,b
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    vector<pair<int,int> > ans;
    int ma=a[n-1],mi=a[0];
    for(int i=1;i<n-1;i++){
        if(a[i]<0){
            ans.push_back(make_pair(ma,a[i]));
            ma-=a[i];
        }
        else{
            ans.push_back(make_pair(mi,a[i]));
            mi-=a[i];
        }
    }
    ans.push_back(make_pair(ma,mi));
    cout << ma-mi <<endl;
    for(int i=0;i<n-1;i++){
        cout <<ans[i].first<<" "<<ans[i].second<<endl;
    }
    return 0;
}

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

int main() {
    int n, m, ans=0;
    long long k;
    cin >> n >> m >> k;
    vector<long long>  a(n), b(m), sa(n+1), sb(m+1);
    sa[0]=0;
    sb[0]=0;
    for(int i=0; i<n; i++) {
        cin >> a[i];
        if(sa[i]>=1000000000) sa[i+1]=1000000001;
        else{
            sa[i+1]=sa[i]+a[i];
        }
       
    }
    for(int i=0; i<m; i++) {
        cin >> b[i];
        if(sb[i]>=1000000000) sb[i+1]=1000000001;
        else{
            sb[i+1]=sb[i]+b[i];
        }
    }
    
    for(int i=0; i<n+1; i++){
        int left=0, right=m+1;
        
        while(left<right){
            int mid=(left+right)/2;
            if(sa[i]+sb[mid]==k){
                ans=max(i+mid, ans);
                break;
            }
            else if(sa[i]+sb[mid]<k){
                ans=max(i+mid, ans);
                left=mid+1;
            }
            else{
                right=mid;
            }
        }
    }
    cout << ans;
}

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

#define ll long long
#define ar array

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string c;
    cin >> c;
    if (c[2] == c[3] && c[4] == c[5]){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}


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

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		sc.close();
		if((a.equals("H")&&b.equals("H"))||(a.equals("D")&&b.equals("D"))) {
			System.out.println("H");
		}else {
			System.out.println("D");
		}
	}
}

Measured memory_bytes: 21844