akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

constexpr ll MOD = (ll)1e6 + 3;

ll MODpow(ll n, ll m) {
    ll result = 1;
    while (m) {
        if (m % 2 == 1) {
            result *= n;
            result %= MOD;
        }

        m /= 2;
        n *= n;
        n %= MOD;
    }

    return result;
}

int main() {
    ll Q;
    cin >> Q;
    vector<ll> x(Q), d(Q), n(Q);
    for (ll i = 0; i < Q; i++) {
        cin >> x[i] >> d[i] >> n[i];
    }

    constexpr ll max_num = 1e6 + 2;
    vector<ll> fact, inv_fact;
    fact.resize(max_num + 1, 1);
    inv_fact.resize(max_num + 1, 1);
    for (ll i = 2; i <= max_num; i++) {
        fact[i] = i * fact[i - 1] % MOD;
        inv_fact[i] = MODpow(fact[i], MOD - 2);
        assert(fact[i] * inv_fact[i] % MOD == 1);
    }

    for (ll i = 0; i < Q; i++) {
        if (d[i] == 0) {
            cout << MODpow(x[i], n[i]) << endl;
        } else {
            ll x_var_d = x[i] * MODpow(d[i], MOD - 2) % MOD;
            if (x_var_d == 0 || x_var_d + n[i] - 1 >= MOD) {
                cout << 0 << endl;
            } else {
                ll a = x_var_d + n[i] - 1;
                ll b = x_var_d - 1;
                cout << MODpow(d[i], n[i]) * fact[a] % MOD * inv_fact[b] % MOD << endl;
            }
        }
    }
}

Measured memory_bytes: 18816
n, m = gets.strip.split.map(&:to_i)
ab = readlines.map {|line| line.strip.split.map(&:to_i) }

graph = Array.new(n+1) { [] }
ab.each do |f, t|
  graph[f] << t
  graph[t] << f
end

result = 0
(1..n).to_a.permutation.each do |arr|
  next if arr.first != 1
  ok=true
  arr.each_cons(2) do |f, t|
    ok = false unless graph[f].include?(t)
  end
  result += 1 if ok
end

p result


Measured memory_bytes: 2172
n = int(input())
s = [input() for _ in range(n)]
d = {}
for w in s:
    if w not in d:
        d[w] = 0
    d[w] += 1
d2 = sorted(d.items(), key=lambda x:x[1], reverse=True)
maxcnts = [w[0] for w in d2 if w[1] == d2[0][1]]
maxcnts.sort()
for ans in maxcnts:
    print(ans)

Measured memory_bytes: 47240
import java.io.{BufferedReader, InputStream, InputStreamReader}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}

object Main {
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val A = sc.nextLong()
    val B = sc.nextLong()
    val X = Array.fill[Long](N)(sc.nextLong())
    val ans = (X zip X.drop(1) map { case (x, y) =>
      val c = y - x
      min(c * A, B)
    }).sum

    println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
  }


  private class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

}


Measured memory_bytes: 50664
w,h,n=map(int,input().split())
xl=0
xr=w
yu=h
ys=0
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        if xl<x:
            xl=x
    elif a==2:
        if xr>x:
            xr=x
    elif a==3:
        if ys<y:
            ys=y
    elif a==4:
        if yu>y:
            yu=y
if (xr-xl)>=0 and (yu-ys)>=0:
    print((yu-ys)*(xr-xl))
else:
    print(0)

Measured memory_bytes: 3064
#!/usr/bin/env python3

def main():
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())

    n = 0
    for i in range(a + 1):
        y = 500 * i
        if x < y:
            break
        for j in range(b + 1):
            if x < y + 100 * j:
                break
            if (x - y - 100 * j) / 50 <= c:
                n += 1

    print(n)


if __name__ == '__main__':
    main()



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

int main(){
    int s;
    cin >> s;
    int n = s;
    int used[100005] = {};
    used[s] = 1;
    for(int i = 2; ; i++){
        if(n % 2 == 0){
            n /= 2;
        }else{
            n = 3 * n + 1;
        }
        if(used[n] == 1){
            cout << i << endl;
            break;
        }
        used[n] = 1;
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main()
{
    int X, A, B;
    std::cin >> X >> A >> B;
    if (-A + B <= 0)
    {
        cout << "delicious" << endl;
    }
    else if ( -A + B <= X)
    {
        cout << "safe" << endl;
    }
    else
    {
        cout << "dangerous" << endl;
    }
}


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

int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<long int>> place(N, vector<long int>(2));
    vector<vector<long int>> check(M, vector<long int>(2));

    for(int i=0; i<N; i++){
        cin >> place.at(i).at(0) >> place.at(i).at(1);
    }
    for(int i=0; i<M; i++){
        cin >> check.at(i).at(0) >> check.at(i).at(1);
    }
    vector<int> goal(N);

    for(int i=0; i<N; i++){
        long int lmin = abs(place[i][0] - check[0][0]) + abs(place[i][1] - check[0][1]);
        int goali = 1;
        for(int j=0; j<M; j++){
            if ((abs(place[i][0] - check[j][0]) + abs(place[i][1] - check[j][1])) < lmin){
                lmin = abs(place[i][0] - check[j][0]) + abs(place[i][1] - check[j][1]);
                goali = j+1;
            }
        }
        goal.at(i) = goali;
    }
    for(int i=0; i<N; i++){
        cout << goal[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    vector<vector<int>> a(2,vector<int>(n));
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < n; j++) cin >> a[i][j];
    }    
    for(int i = 0; i < n; i++){
        int can = 0;
        for(int j = 0; j <= i; j++) can += a[0][j];
        for(int j = i; j < n; j++) can += a[1][j];
        ans = max(ans,can);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll a,b;cin>>a>>b;
  if(a<=b)cout<<a<<endl;
  else cout<<a-1<<endl;
}

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

int main(){
    int n;
    scanf("%d", &n);
    int arr[n], num[201];
    for(int i=0; i<n; i++){
        scanf("%d", &arr[i]);
    }
    int mx=*max_element(arr,arr+n);
    int mn=*min_element(arr,arr+n);
    int res=10000000, suma;
    for(int i=mn; i<=mx; i++){
        suma=0;
        for(int j=0; j<n; j++){
            suma+=pow(arr[j]-i,2);
        }
        if(suma<res)
            res=suma;
    }
    printf("%d", res);
return 0;
}


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

class Dice {
private:
    int d[7];
public:
    void set_number(int i, int num) {
        d[i] = num;
    }

    int get_number(int i) {
        return d[i];
    }

    void roll_dice(char c) {
        int buf;
        switch(c) {
            case 'N':
            buf = d[6];
            d[6] = d[5];
            d[5] = d[1];
            d[1] = d[2];
            d[2] = buf;
            break;
            case 'E':
            buf = d[6];
            d[6] = d[3];
            d[3] = d[1];
            d[1] = d[4];
            d[4] = buf;
            break;
            case 'S':
            buf = d[6];
            d[6] = d[2];
            d[2] = d[1];
            d[1] = d[5];
            d[5] = buf;
            break;
            case 'W':
            buf = d[6];
            d[6] = d[4];
            d[4] = d[1];
            d[1] = d[3];
            d[3] = buf;
        }
    }

    bool compare_direction(Dice another_dice) {
        for(int i=1;i<7;i++) {
            if(d[i] != another_dice.d[i]) return false;
        }
        return true;
    }
    
    bool compare_4times(Dice another_dice) {
        for(int i=0;i<4;i++)
        {
            another_dice.roll_dice('E');
            if(this->compare_direction(another_dice)) return true;
        }
        return false;
    }
    
    bool is_same_dice(Dice another_dice) {
        if(compare_4times(another_dice)) return true;

        another_dice.roll_dice('N');
        if(compare_4times(another_dice)) return true;

        another_dice.roll_dice('N');
        if(compare_4times(another_dice)) return true;

        another_dice.roll_dice('N');
        if(compare_4times(another_dice)) return true;

        another_dice.roll_dice('E');
        another_dice.roll_dice('N');
        if(compare_4times(another_dice)) return true;
        
        another_dice.roll_dice('N');
        another_dice.roll_dice('N');
        if(compare_4times(another_dice)) return true;        
        
        return false;
    }
};

int main()
{
    int n;
    cin >> n;
    Dice* dice;
    dice = new Dice[n];

    int buf;
    for(int i=0;i<n;i++)
    {
        for(int j=1;j<7;j++)
        {
            cin >> buf;
            dice[i].set_number(j, buf);
        }
    }

//    for(int i=0;i<n;i++)
//    {
//        for(int j=1;j<7;j++)
//        {
//            cout << "dice:" << i << ", d[" << j << "]:" << dice[i].get_number(j) << endl;
//        }
//    }    

    string judge = "Yes";
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<i;j++)
        {
            if(dice[i].is_same_dice(dice[j])) judge = "No";
        }
    }
    cout << judge << endl;
    return 0;
}



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

int main(){
  int h,w;
  cin>>h>>w;
  map<char,int> mp;
  rep(i,h)rep(j,w){
    char a;
    cin>>a;
    mp[a]++;
  }
  bool ans=1;
  bool k=0;
  if(h%2==1 && w%2==1) k=1;
  for(auto x : mp){
    if(x.second%2==1){
      if(k){
        mp[x.first]--;
        k=0;
      }else{
        ans=0;
      }
    }
  }
  int odd=0;
  if(h%2==1) odd+=w/2; 
  if(w%2==1) odd+=h/2;
  for(auto x : mp){
    if(x.second%4!=0) odd--;
  }
  if(ans && odd>=0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  for (int i = 0; i < h; i++) {
    cin >> a[i];
    a[i] = "#" + a[i] + "#";
  }

  for (int i = 0; i < h; i++) {
    if (i == 0) {
      for (int j = 0; j < w + 2; j++)
        cout << "#";
      cout << endl;
    }
    cout << a[i];
    cout << endl;
    if (i == h - 1) {
      for (int j = 0; j < w + 2; j++)
        cout << "#";
      cout << endl;
    }
  }
}

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

ldp = [0] * (N+1)
rdp = [0] * (N+1)

for i in range(N):
    if S[i] == "#":
        ldp[i+1] = ldp[i] + 1
    else:
        ldp[i+1] = ldp[i]

for i in range(N-1, -1, -1):
    if S[i] == ".":
        rdp[i] = rdp[i+1] + 1
    else:
        rdp[i] = rdp[i+1]

#print(ldp)
#print(rdp)
ans = 10 ** 9
for i in range(N+1):
    ans = min(ans, rdp[i]+ldp[i])

print(ans)

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

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

int a[105][105];

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n;
    cin>>n;
    for(int i=1;i<=2;i++)
        for(int j=1;j<=n;j++)
            cin>>a[i][j];

    for(int i=1;i<=2;i++){
        for(int j=1;j<=n;j++){
            a[i][j]+=max(a[i-1][j],a[i][j-1]);
        }
    }
    cout<<a[2][n]<<enl;

    return 0;
}


Measured memory_bytes: 3660
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};
 
typedef struct node * NodePointer;
 
NodePointer nil;
 
NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while(cur != nil && cur->key != key)
    cur = cur->next;
  return cur;
}
 
void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}
 
void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}
 
void deleteNode(NodePointer t){
  if(t == nil)return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}
 
void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}
 
void deleteLast(){
  deleteNode(nil->prev);
}
 
void delete(int key){
  deleteNode(listSearch(key));
}
 
 
void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}
 
int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
    if ( com[6] == 'F' ) deleteFirst();
    else if ( com[6] == 'L' ) deleteLast();
      } else {
    delete(key); nd++; 
      }
      size--;
    }
  }
 
  printList();
  return 0;
}

Measured memory_bytes: 31788
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <math.h>
using namespace std;

int main(void){
	int n;
	int *x, *y;
	double p1, p2, p3, pi;

	cin >> n;
	x = new int[n];
	y = new int[n];

	for (int i = 0; i < n; i++){
		cin >> x[i];
	}
	for (int i = 0; i < n; i++){
		cin >> y[i];
	}

	p1 = p2 = p3 = pi = 0;
	for (int i = 0; i < n; i++){
		p1 += abs(x[i] - y[i]);
		p2 += abs((x[i] - y[i])*(x[i] - y[i]));
		p3 += abs((x[i] - y[i])*(x[i] - y[i])*(x[i] - y[i]));
		if (pi < abs((x[i] - y[i]))){
			pi = abs((x[i] - y[i]));
		}
	}

	p2 = sqrt(p2);

	double temp = pow(p3, 1. / 3);
	if (temp == 0)
		p3 = 0.0;
	else
		p3 = (2 * temp + p3 / temp / temp) / 3;

	cout << fixed << setprecision(10) << p1 << "\n" << p2 << "\n" << p3 << "\n" << pi << "\n";

	delete[] x, y;
	return 0;
}

Measured memory_bytes: 1312
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;
 
int main() {
 
	int x;
  	cin>>x;
	if (x >= 30)cout << "Yes" << endl;
	else cout << "No" << endl;
 
}


Measured memory_bytes: 3624
n=int(input())
A=list(map(int,input().split()))
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

d=defaultdict(int)
for i in A:
    d[i-1]+=1
    d[i]+=1
    d[i+1]+=1
print(max(d.values()))

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

int main(){
  string s;
  cin>>s;
  int n=s.size();
  int a=-1;
  int b=-1;
  rep(i,0,n-1){
    if(s[i]==s[i+1]){
      a=i+1;
      b=i+2;
    }
  }
  rep(i,0,n-2){
    if(s[i]==s[i+2]){
      a=i+1;
      b=i+3;
    }
  }
  cout<<a<<' '<<b<<endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
long long cmpfunc (const void * a, const void * b) {
   return ( *(long long*)a - *(long long*)b );
}



int main(void){
   
long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,sum2,min,f,c,r,o,sum1,sum=0,y,b[100000]={0},count1=0,k,a2[100000]={0},b2;
char a[100000];
scanf("%s",a);
count=0;
count1=0;
for(i=0;i<strlen(a);i++){
    if(a[i]=='o'){
        count++;
    }else{
        count1++;
    }
}
l=15-strlen(a);
if(count>=8 || count+l>=8){
    printf("YES");
}else{
    printf("NO");
}
return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int n, t;
vector<long long> a;
map<int, int> mp;

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

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> t;
        mp[t]++;
        if (mp[t] == 2) {
            mp[t] = 0;
            a.push_back(t);
        }
    }

    sort(a.begin(), a.end(), greater<int>());
    if (a.size() < 2) {
        cout << 0 << endl;
    }
    else {
        cout << a[0] * a[1] << endl;
    }

    return 0;
}

Measured memory_bytes: 4992
a, b, c = int(input()), int(input()), int(input())
x = int(input())

cnt = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if i * 500 + j * 100 + k * 50 == x:
                cnt += 1
print(cnt)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n, k;
    string s;
    cin >> n >> k >> s;
    VI cnts;
    char c = s[0];
    for(int i = 1; i < n; i++){
        if (s[i] != c){
            cnts.push_back(1);
            c = s[i];
        }
    }
    cnts.push_back(1);
    
    int ans = 0;
    rep(i,n-1){
        if (s[i] == s[i+1]) ans++;
    }

    int sz = cnts.size();
    if (sz / 2 <= k){
        ans += 2 * (sz / 2);
        if (sz % 2 == 0) ans--;
    }else{
        ans += 2 * k;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4072
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline void myassert(bool a,string s){ if(!a)cerr<<s<<endl,exit(0);}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=2e3+20;
const int mod=1e9+7;
int jc[maxn*5],jcn[maxn*5],inv[maxn*5];
int x[maxn*100],y[maxn*100];
int n;

int f[maxn<<1][maxn<<1];
int ans;
#define F(x,y) (f[(x)+maxn][(y)+maxn])

inline int C(int n,int m){ return 1ll*jc[n]*jcn[m]%mod*jcn[n-m]%mod;}

inline void init()
{
	n=read();
	REP(i,1,n)
	{
		x[i]=read();y[i]=read();
		ans=(ans-C(x[i]+y[i]<<1,x[i]<<1)+mod)%mod;
		F(-x[i],-y[i])++;
	}
}

inline void pls(int &a,int b){ a+=b; a-=a>=mod?mod:0;}

inline void doing()
{
	REP(i,-2000,2000)REP(j,-2000,2000)
		pls(F(i,j),F(i-1,j)),pls(F(i,j),F(i,j-1));
	REP(i,1,n)pls(ans,F(x[i],y[i]));
	ans=(ll)ans*(mod+1>>1)%mod;
	printf("%d\n",ans);
}

inline void prepare()
{
	jc[0]=jc[1]=jcn[1]=jcn[0]=inv[1]=1;
	REP(i,2,1e4)jc[i]=(ll)jc[i-1]*i%mod,inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod,jcn[i]=(ll)jcn[i-1]*inv[i]%mod;
}

int main()
{
	prepare();
	init();
	doing();
	return 0;
}


Measured memory_bytes: 65152
fn main() {
    let v = read_vec::<u32>();
    yn(v[0] == v[1]);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int len = S.length();
    int ans = len;
    if(len % 2 == 0){
        REP(i,len/2){
            if(S[i] != S[i+1]){
                ans = len - 1- i;
            }
            if(S[len-1-i] != S[len-2-i]){
                ans = len - 1- i;
            }
        }
    }
    else{
        REP(i,len/2){
            if(S[i] != S[i+1]){
                ans = len - 1 - i;
            }
            if(S[len-1-i] != S[len-2-i]){
                ans = len - 1 - i;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<char>>();

    let n = s.len();
    let mut ans = vec![0; n];
    let mut i = 0;
    while i < n {
        let mut mv = i;
        let mut cnt = 0;
        let past = s[mv];

        loop {
            if past != s[mv] {
                if past == 'R' {
                    cnt = i + cnt - (cnt % 2);
                } else {
                    cnt = i - cnt + (cnt % 2);
                }
                ans[cnt] += 1;

                while i+1 < n && s[i] == s[i+1] {
                    i+=1;
                    if s[i] == 'R' {
                        if s[cnt] == 'R' {
                            cnt+=1;
                        } else {
                            cnt-=1;
                        }
                    } else {
                        if s[cnt] == 'R' {
                            cnt+=1;
                        } else {
                            cnt-=1;
                        }
                    }
                    ans[cnt] += 1;
                }
                break;
            }

            if s[mv] == 'R' {
                mv += 1;
            } else {
                mv -= 1;
            }
            cnt+=1;
        }
        i += 1;
    }
    for i in 0..n {
        print!("{} ", ans[i])
    }
}

Measured memory_bytes: 4476
import sys
import bisect
input = sys.stdin.readline
N,K=map(int,input().split())
V=[int(x) for x in input().split()]
M=min(N,K)
ans=0
for a in range(M+1):
    for b in range(0,M+1-a):
        #print(a,b)
        if b != 0:
            #print(V[0:a],V[-b:])
            Get = V[0:a] + V[-b:]
            Get.sort()
            #print('bisect: %d' % bisect.bisect_left(Get,0))
            del Get[0:min(K-(a+b),bisect.bisect_left(Get,0))]
            ans=max(ans,sum(Get))
            #print(Get,sum(Get))
        else:
            Get = V[0:a]
            #print(V[0:a])
            Get.sort()
            del Get[0:min(K-(a+b),bisect.bisect_left(Get,0))]
            ans=max(ans,sum(Get))
            #print(Get,sum(Get))
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,m; cin>>n>>m;
    vector<int> a(m);
    vector<vector<int>> c(m);
    rep(i,m) {
        int b; cin>>a[i]>>b;
        c[i].resize(b);
        rep(j,b) cin>>c[i][j];
    }
    
    vector<int> dp((1<<n),INF);
    dp[0] = 0;

    for (int bit = 0; bit < (1<<n); ++bit) {
        rep(i,m) {
            int nv = bit;
            for (auto &&e: c[i]) {
                nv |= (1<<(e-1));
            }
            chmin(dp[nv], dp[bit]+a[i]);
        }
    }

    if (dp[(1<<n)-1] == INF) cout << -1 << '\n';
    else cout << dp[(1<<n)-1] << '\n';
    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 501;

int a[N][N];

struct Move {
  int x1, y1, x2, y2;
};

            // up, left, down, right
int dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0};

void solve() {
  int h, w; scanf("%d%d", &h, &w);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      scanf("%d", a[i]+j);
    }
  }
  vector<Move> v;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (a[i][j]%2 == 0) continue;
      for (int k = 0; k < 4; ++k) {
	if (i+dy[k] < 0 || i+dy[k] >= h || j+dx[k] < 0 || j+dx[k] >= w) continue;
	if (a[i+dy[k]][j+dx[k]]%2==0) continue;
	v.push_back({i+1, j+1, i+dy[k]+1, j+dx[k]+1});
	--a[i][j];
	++a[i+dy[k]][j+dx[k]];
	break;
      }
      if (a[i][j]%2 == 0) continue;
      for (int k = 2; k < 4; ++k) {
	if (i+dy[k] < 0 || i+dy[k] >= h || j+dx[k] < 0 || j+dx[k] >= w) continue;
	v.push_back({i+1, j+1, i+dy[k]+1, j+dx[k]+1});
	--a[i][j];
	++a[i+dy[k]][j+dx[k]];
	break;
      }
    }
  }
  printf("%d\n", v.size());
  for (const auto &e: v) {
    printf("%d %d %d %d\n", e.x1, e.y1, e.x2, e.y2);
  }
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 6356
N = int(input())
P2 = [[0, 0, 0] for _ in range(5000)]
P3 = [[0, 0] for _ in range(2500)]
limit = 30000
for i in range(5000):
  P2[i] = [6 * (i + 1) - 2, 6 * (i + 1), 6 * (i + 1) + 2]
P2[-1][-1] = 2
for i in range(2500):
  P3[i] = [12 * i + 3, 12 * i + 9]
if N == 3:
  print(2,3,25)
elif N == 4:
  print(2,3,4,9)
elif N == 6:
  print(2,3,4,6,9,12)
else:
  def SP(N):
    if N == 19999:
      P = P2 + P3
      P[0] = [4, 8]
      return P
    _k = -(-max(N - 12500, 0) // 3)
    N -= 3 * _k
    k = N // 5
    m = N % 5
    if m == 0:
      P = P2[:k + _k] + P3[:k]
    elif m == 1:
      P = P2[:k + 1 + _k] + P3[:k - 1]
    elif m == 2:
      P = P2[:k + _k] + P3[:k + 1]
    elif m == 3:
      P = P2[:k + 1 + _k] + P3[:k]
    elif k >= 2499:
      P = P2[:k + 2 + _k] + P3[:k - 1]
    else:
      P = P2[:k + _k] + P3[:k + 2]
    return P
  P = SP(N)
  print(' '.join([' '.join([str(_p) for _p in p]) for p in P]))

Measured memory_bytes: 5108
/*************************************************************************
    > File Name: Coin_Changing_Problem.cpp
    > Author: Frade
    > Mail: frade@vip.sina.com.cn 
    > Created Time: 2017年05月02日 星期二 16?09分33秒
 ************************************************************************/

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int Getint()
{
    char c = getchar();
    bool flag = false;
    int ans = 0;
    while(c != '-' && (c <'0' || c > '9'))c = getchar();
    if(c == '-')flag = true,c = getchar();
    while(c >= '0' && c <= '9')ans = ans*10 + c - '0',c = getchar();
    return (flag == true) ? -ans : ans;
}

const int maxn = 50000;

int w[maxn],f[maxn];

int main()
{
	for(int j = 1;j < maxn; j++)f[j] = -999999;

	int W = Getint();
	int N = Getint();
	for(int i = 1;i <= N; i++)w[i] = Getint();

	f[0] = 0;

	for(int i = 1;i <= N; i++)
	{
		for(int j = w[i];j <= W; j++)
		{
			if(f[j] <= 0)f[j] = max(f[j],f[j-w[i]]+1);
			else f[j] = min(f[j],f[j-w[i]]+1);
		}
	}
	printf("%d\n",f[W]);
    return 0;
}

Measured memory_bytes: 3412
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][][] info = new int[4][3][10];
        for(int i = 0; i < n; i++){
            int b = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            int v = sc.nextInt();
            info[b - 1][f - 1][r - 1] += v;
        }
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 3; j++){
                for(int k = 0; k < 10; k++){
                    System.out.print(" " + info[i][j][k]);
                }
                System.out.println();
            }
            if(i != 3){
                System.out.println("####################");
            }
        }
    }
}


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

int main() {
	int N;
	cin >> N;
	if (N % 10 == 7)
		cout << "Yes" << endl;
	else if ((N / 10) % 10 == 7)
		cout << "Yes" << endl;
	else if ((N / 100) % 10 == 7)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, d;
    cin >> H >> W >> d;
    vector<string> ans(H);
    string S = "RYGB";
    string s(W, ' ');
    for(int i=0; i<H; i++)
        ans[i] = s;

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            int y = i+j;
            int x = i-j;
            int p1 = (y+(H+W)*d)/(d)%2;
            int p2 = (x+(H+W)*d)/(d)%2;
            ans[i][j] = S[2*p1+p2];
        }
    }
    for(int i=0; i<H; i++)
        cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 768
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int W, H, N; cin >> W >> H >> N;
    vi X(N), Y(N), A(N);
    REP(i, N) cin >> X[i] >> Y[i] >> A[i];
    
    int xl = 0, xr = W;
    int yb = 0, yt = H;
    REP(i,N) {
        switch(A[i]){
        case 1:
            xl = max(xl, X[i]);
            break;
        case 2:
            xr = min(xr, X[i]);
            break;
        case 3:
            yb = max(yb, Y[i]);
            break;
        case 4:
            yt = min(yt, Y[i]);
            break;
        }
    }

    int w = max(xr - xl, 0);
    int h = max(yt - yb, 0);

    int ans = w * h;
    cout << ans << endl;

    return 0;
}

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

int main(){
    int n; cin >> n;
    vector<pair<int, int> > tasks(n);
    for(int i = 0; i < n; i++){
        int a, b; cin >> a >> b;
        tasks[i] = make_pair(b, a);  //ソートの優先順位　b > a
    }
    sort(tasks.begin(), tasks.end());
    int sumt = 0;
    for(int i = 0; i < n; i++){
        sumt +=tasks[i].second;
        if(sumt > tasks[i].first){
            cout << "No" << endl; return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  string s, t;
  cin >> s >> t;
  vector<int> s_num(26, 0), t_num(26, 0);
  vector<vector<int>> a(26);
  rep(i, s.size()) {
    s_num[s[i] - 'a'] ++;
    a[s[i] - 'a'].push_back(i + 1);
  }
  rep(i, t.size()) t_num[t[i] - 'a'] ++;
  rep(i, 26) {
    if (s_num[i] == 0 && t_num[i] > 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  LL ans = a[t[0] - 'a'][0];
  LL pos_before_char = a[t[0] - 'a'][0];
  for (LL i = 1; i < t.size(); i ++) {
    int j = t[i] - 'a';
    int x = lower_bound(a[j].begin(), a[j].end(), pos_before_char + 1) - a[j].begin();
    if (x == a[j].size()) {
      ans += s.size() - pos_before_char + a[j][0];
      pos_before_char = a[j][0];
    } else {
      ans += a[j][x] - pos_before_char;
      pos_before_char = a[j][x];
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1216
A, B, C, X, Y = list(map(int, input().split()))
ans = A * X + B * Y

for Z in range(10**5 + 1):
    Z *= 2
    price = A * max(X - Z//2, 0) + B * max(Y - Z // 2, 0) + C * Z
    ans = min(ans, price)

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#define PI 3.141592653589793
using namespace std;
int main()
{
  double a,b,x;
  cin>>a>>b>>x;
  double ans;
  ans = ((2*(a*a*b-x))/(a*a*a));
  if(b/a>(float)ans)
    ans = atan(ans)*180.0/PI;
  else
    ans = atan((b*b*a)/(2*x))*180.0/PI;
  printf("%.10lf",ans);
  return 0;
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    string s, t;
    cin >> s >> t;

    // O(nlog(n))
    map<char, vi> sdict;
    rep(i, 0, 26) { sdict[char(i + 'a')] = vi(); }
    rep(i, 0, s.size()) {
        sdict[s[i]].push_back(i);
        sdict[s[i]].push_back(i + s.size());
    }

    rep(i, 0, 26) { sort(all(sdict[char(i + 'a')])); }

    ll ans = 0;
    int pos = 0;

    for (char c : t) {
        // s内に文字が無ければ終了．
        if (sdict[c].empty()) {
            cout << -1 << endl;
            return 0;
        }

        // pos以降で最も近く一致する文字を探す．
        int next_pos = *upper_bound(sdict[c].begin(), sdict[c].end(), pos - 1);

        // 文字数をカウント．
        ans += next_pos - pos + 1;

        // posを更新．
        pos = (next_pos + 1) % s.size();
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1736
#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__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a[205];
    cin >> n;
    rep(i,2*n) cin >> a[i];
    sort(a,a+2*n);
    int ans = 0;
    rep(i,n){
        ans += a[2*i];
    }
    PRINT(ans);
}

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

typedef long long lint;
const int maxn = 200005;

int n, w[maxn], fa[maxn];

struct edge1
{
	int to, next, w;
} e[maxn * 2];
int h[maxn], tot;

struct edge2
{
	int u, v;
	lint w;
	bool operator < (const edge2 &a) const {
		return w < a.w;
	}
} E[maxn * 25];
int cnt;

int Siz, siz[maxn], mxsz[maxn], p, rt, vis[maxn];
lint dis[maxn];

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

inline void add(int u, int v, int w)
{
	e[++tot] = (edge1) {v, h[u], w}; h[u] = tot;
	e[++tot] = (edge1) {u, h[v], w}; h[v] = tot;
}

void getroot(int u, int fa)
{
	siz[u] = 1; mxsz[u] = 0;
	for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
		if (v != fa && !vis[v]) {
			getroot(v, u); siz[u] += siz[v];
			mxsz[u] = max(mxsz[u], siz[v]);
		}
	mxsz[u] = max(mxsz[u], Siz - siz[u]);
	if (mxsz[u] < mxsz[rt]) rt = u;
}

void dfs(int u, int fa)
{
	if (dis[u] + w[u] < dis[p] + w[p]) p = u;
	for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
		if (v != fa && !vis[v]) dis[v] = dis[u] + e[i].w, dfs(v, u);
}

void link(int u, int fa)
{
	if (u != p) E[++cnt] = (edge2) {u, p, w[u] + w[p] + dis[u] + dis[p]};
	for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
		if (v != fa && !vis[v]) link(v, u);
}

void solve(int u)
{
	rt = 0; getroot(u, 0); u = rt; vis[u] = 1;
	p = u; dis[u] = 0; dfs(u, 0); link(u, 0);
	for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
		if (!vis[v]) Siz = siz[v], solve(v);
}

inline int find(int x)
{
	if (!fa[x]) return x;
	return fa[x] = find(fa[x]);
}

int main()
{
	n = gi();
	for (int i = 1; i <= n; ++i) w[i] = gi();
	for (int u, v, i = 1; i < n; ++i) u = gi(), v = gi(), add(u, v, gi());
	
	Siz = n; mxsz[0] = n; solve(1);

	lint ans = 0;
	sort(E + 1, E + cnt + 1);
	for (int i = 1, j = 1; i < n; ++i) {
		while (find(E[j].u) == find(E[j].v)) ++j;
		fa[find(E[j].u)] = E[j].v; ans += E[j].w;
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 69888
#include <cstdio>
#include <map>

using namespace std;

typedef long long ll;

int main() {
    ll n, k, a, b;
    scanf("%lld%lld", &n, &k);
    map<ll, ll> q;
    for (ll i = 0; i < n; ++i) {
        scanf("%lld%lld", &a, &b);
        q[a] += b;
    }
    for (auto i = q.begin(); i != q.end(); ++i) {
        k -= (*i).second;
        if (k <= 0) {
            printf("%lld\n", (*i).first);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 4224
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
double EPS=1e-10;
double EQ(double a,double b){
    return abs(a-b)<EPS;
}
void fast_stream(){
  std::ios_base::sync_with_stdio(0);
}
template<class T>
string IntToString(T num){
  string res;stringstream ss;ss<<num;
  return ss.str();
}
ll StringToInt(string &str){
  ll res=0;
  for(int i=0;i<(int)str.size();i++)
    res=(res*10+str[i]-'0');
  return res;
}

bool isDig(string s){
  for(int i=0;i<(int)s.size();i++)
    if(!(s[i]>='0'&&s[i]<='9'))return false;
  return true;
}

map<string,set<int> > mp;
int main(){
  int m;
  cin>>m;
  for(int i=0;i<m;i++){
    string s;
    int lb,ub;
    cin>>s>>lb>>ub;
    set<int> v;
    for(int j=lb;j<=ub;j++)v.insert(j);
    mp[s]=v;
  }
  int n;
  cin>>n;
  stack<set<int> > stk;
  for(int i=0;i<n;i++){
    string e;
    cin>>e;
    if(isDig(e)){
      int num=StringToInt(e);
      set<int> v;v.insert(num);
      stk.push(v);
    }
    else if(mp.count(e)>0)stk.push(mp[e]);
    else{
      set<int> v1=stk.top();stk.pop();
      set<int> v2=stk.top();stk.pop();
      set<int> v3;
      for(set<int>::iterator it1=v1.begin();it1!=v1.end();it1++){
	for(set<int>::iterator it2=v2.begin();it2!=v2.end();it2++){
	  if(e=="+")v3.insert((*it1+*it2)%256);
	  else if(e=="-")v3.insert((*it2-*it1+256)%256);
	  else if(e=="*")v3.insert(((*it1)*(*it2))%256);
	  else if(e=="/"){
	    if(*it1==0){
	      cout<<"error"<<endl;
	      return 0;
	    }
	    v3.insert(((*it2)/(*it1))%256);
	  }
	}
      }
      stk.push(v3);
    }
  }
  cout<<"correct"<<endl;
  
  return 0;
}

Measured memory_bytes: 1392
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

class UnionFind
{
    vector<int> par;

public:
    UnionFind(int n) : par(n, -1) {}

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

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
            swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

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

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    akari<int> xs(n), ys(n);
    akari<pair<int, int>> xp(n), yp(n);
    for (int i = 0; i < n; i++)
    {
        cin >> xs[i] >> ys[i];
        xp[i] = make_pair(xs[i], i);
        yp[i] = make_pair(ys[i], i);
    }
    sort(xp.begin(), xp.end());
    sort(yp.begin(), yp.end());
    UnionFind uf(n);
    for (int i = 0; i < n - 1; i++)
    {
        if (xp[i].first == xp[i + 1].first)
        {
            uf.merge(xp[i].second, xp[i + 1].second);
        }
        if (yp[i].first == yp[i + 1].first)
        {
            uf.merge(yp[i].second, yp[i + 1].second);
        }
    }
    int group = 0;
    akari<int> used(n, -1);
    map<int, int> cnt[n];
    set<int> s[n];
    for (int i = 0; i < n; i++)
    {
        int p = uf.root(i);
        if (used[p] == -1)
        {
            used[p] = group++;
        }
        p = used[p];
        cnt[p][ys[i]]++;
        s[p].insert(xs[i]);
    }
    i64 ans = 0;
    for (int i = 0; i < group; i++)
    {
        i64 m = s[i].size();
        for (auto &p : cnt[i])
        {
            ans += m - (i64)p.second;
        }
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

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

using namespace std;

typedef long long ll;

ll patty(ll k) {
    return pow(2LL, k + 1) - 1;
}

ll total(ll k) {
    return pow(2LL, k + 2) - 3;
}

ll pts(ll x, ll k) {
    if (x <= 1) {
        if (k == 0 && x == 1)
            return 1;
        return 0;
    }
    if (x >= total(k))
        return patty(k);
    if (x <= 1 + total(k - 1))
        return pts(x - 1, k - 1);
    return patty(k - 1) + pts(x - 2 - total(k - 1), k - 1) + 1;
}

int main() {
    ll n, x; cin >> n >> x;
    cout << pts(x, n);
    return 0;
}



Measured memory_bytes: 256