akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let v = read_vec::<u32>();
    let x = v[0];
    let y = v[1];
    let z = v[2];
    println!("{} {} {}", z, x, y);
}

#[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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    int n;
    cin >> n;
    int a[n];
    bool b[n];

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

    int ans=0;

    for(int i=1;i<n;i++){
        if(a[i]==a[i-1]&&!b[i-1]){
            b[i]=true;
            ans++;
        }
    }
    cout << ans << endl;
}

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

public class Test
{
    public static void Main()
    {
        int[] hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        List<int> res = new List<int>();
        for (int i = 0; i < a.Length; i++)
        {
            res.AddRange(Enumerable.Repeat(i + 1,a[i]));
        }
        for (int i = 0; i < hw[0]; i++)
        {
            int[] arr;
            if (i % 2 == 1) arr = res.Take(hw[1]).Reverse().ToArray();
            else arr = res.Take(hw[1]).ToArray();
            Console.WriteLine(string.Join(" ",arr));
            res.RemoveRange(0, hw[1]);
        }
    }
}


Measured memory_bytes: 13792
#include <bits/stdc++.h>
using namespace std;
int main() {
   int N;
   int ac=0,wa=0,tle=0,re=0;
   cin>>N;
   string s;
   for(int i=0;i<N;i++){
     cin>>s;
     if(s=="AC"){
       ac++;
     } 
     else if(s=="WA"){
       wa++;
     }  
     else if(s=="TLE"){
       tle++;
     }
     else re++;  
   }
   cout<<"AC x"<<" "<<ac<<endl;
   cout<<"WA x"<<" "<<wa<<endl;
   cout<<"TLE x"<<" "<<tle<<endl;
   cout<<"RE x"<<" "<<re<<endl;
 
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  
  int ans = 0;
  for (int i = 0;i < N-2;i++) {//N-2にしたのは配列外参照しそうだから
    if(S.substr(i,3) == "ABC") {
      ans++;
    }
  }
      cout << ans << endl;
}
       
    


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

int main()
{
    int a,b;
    cin >> a >> b;
    int cnt = b/100-a/100+1;
    if((a/100)*100+(a/1000)%10*10+a/10000<a) cnt--;
    if((b/100)*100+(b/1000)%10*10+b/10000>b) cnt--;
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a = 0,b = 0,n = 0;
    scanf("%d %d\n",&a,&b);
    if(a==3){
        n +=100000;
    }else if(a==2){
        n = n + 200000;
    }else if(a==1){
        n = n +300000;
    }
    if(b==3){
           n = n + 100000;
    }else if(b==2){
        n = n +200000;
    }else if(b==1){
        n = n + 300000;
       }
    if(a==1 && b==1){
        n = n + 400000;
    }
    printf("%d\n",n);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  int N;
  cin >> N;
  int a = 1;
  int b = 0;
  vector<int> point(N);
  for(int i = 0; i < N; i++){
    cin >> point[i]; 
  }
  for(int j = 0; j < N; j++){
    b++;
  	a = point[a-1];
    if (a == 2){
    break;
    }
  }
  if (b == N){
  cout << -1 << endl;
  }else{
  cout << b << endl;
  }
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {
    
    int n,x, v[100001]={};
    
    cin>>n;
    
    for(int i=1;i<=n;i++)
    {
        
        cin>>x;
        
        v[x]=i;
        
    }
    
    for(int i=1;i<=n;i++){
        
        cout<<v[i]<<" ";
    }
    
    
    return 0;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, M, A[111111], B, C;
  
  std::cin >> N >> M;

  for (int i = 0; i < N; i ++)
    std::cin >> A[i];

  std::sort(A, A + N);

  std::multiset<std::pair<int, int>> set;

  int a = A[0], c = 1;

  for (int i = 1; i < N; i ++)
    if (A[i] == a) {
      c ++;
    }
    else {
      set.emplace(a, c);

      a = A[i];
      c = 1;
    }

  set.emplace(a, c);

  for (int i = 0; i < M; i ++) {
    std::cin >> B >> C;

    int c = 0;

    for (auto it = std::begin(set); it != std::end(set); ) {
      if (it->first >= C)
        break;

      if (B >= it->second) {
        B -= it->second;
        c += it->second;
        
        it = set.erase(it);
      }
      else {
        set.emplace(it->first, it->second - B);

        it = set.erase(it);

        c += B;
        B  = 0;
      }

      if (B == 0)
        break;
    }

    set.emplace(C, c);
  }

  long long S = 0;

  for (const auto& pair : set)
    S += 1LL * pair.first * pair.second;

  std::cout << S << std::endl;

  return 0;
}


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

int main(){
	string s;
	cin >> s;
	int i = 0, j = s.length() - 1;
	bool flag = true;
	for(int i = 0; i < s.length(); i++){
		if(s[i] != 'x') flag = false;
	}
	if(flag){
		printf("0\n");
		return 0;
	}
	int cnt = 0;
	while(i < j){
		if(s[i] == 'x' && s[j] != 'x'){
			cnt++;
			i++;
		}else if(s[i] != 'x' && s[j] == 'x'){
			cnt++;
			j--;
		}
		else if(s[i] != s[j]){
			printf("-1\n");
			return 0;
		}
		else if(s[i] == s[j]){
			i++;
			j--;
		}
	}
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long
#define kd int
#define fors(i,a,b) for(register int i=(a);i<=(b);++i)
int main(){
    ios::sync_with_stdio(0);
    register int a,wh[9],b,c,d,e,f,g,h,i;
    cin>>a>>b>>e;
    fors(c,0,600){
        wh[1]=a+b+c;
        if(wh[1]<a+e) continue;
        fors(i,-100,200){
            wh[7]=a+e+i;
            if(wh[7]!=wh[1]) continue;
            fors(f,-100,200)
            {
                wh[6]=c+f+i;
                if(wh[6]!=wh[7]) continue;
                fors(d,-100,200){
                    wh[2]=d+e+f;
                    if(wh[2]!=wh[6]) continue;
                    fors(g,-100,200)
                    {
                        wh[4]=g+d+a;
                        wh[8]=c+e+g;
                        if((wh[8]!=wh[4])) continue;
                        fors(h,-100,200){
                            wh[3]=g+h+i;
                            wh[5]=b+e+h;
                            if((wh[3]!=wh[5]) || (wh[3]!=wh[4]) || (wh[3]!=wh[8])) continue;
                                cout<<a<<" "<<b<<" "<<c<<endl;
                                cout<<d<<" "<<e<<" "<<f<<endl;
                                cout<<g<<" "<<h<<" "<<i<<endl;
                                return 0;
                        }
                    }		
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  if((N[0] == '9') || (N[1] == '9'))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a))
#define F0R(a, b) FOR (a, 0, (b))
#define CEIL(a, b) ((a) + (b)-1) / (b)
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
  if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] "
template <typename T>
struct IsC {
  template <typename C>
  static char test(typename C::const_iterator*);
  template <typename C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream&, const C&);
template <typename T1, typename T2>
ostream& operator<<(ostream&, const pair<T1, T2>&);
template <typename... T> using TS = tuple_size<tuple<T...>>;
template<size_t idx, typename... T>
typename enable_if<TS<T...>::value == idx + 1, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return o << ", " << get<idx>(t) << ')';
}
template<size_t idx, typename... T>
typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << ", " << get<idx>(t), t);
}
template<size_t idx = 0, typename... T>
typename enable_if<1 < TS<T...>::value && !idx, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << '(' << get<idx>(t), t);
}
template<typename T>
ostream& operator<<(ostream& o, const tuple<T>& t) {
  return o << get<0>(t);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p) {
  return o << mt(p.fi, p.se);
}
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(
    ostream& o, const C& c) {
  o << '[';
  for (auto it = c.cbegin(); it != c.cend(); ++it)
    o << *it << (next(it) != c.cend() ? ", " : "");
  return o << ']';
}
template <typename T>
void tprint(vector<vector<T>>& v, size_t width = 0, ostream& o = cerr) {
  if (!DEBUG) return;
  for (const auto& vv : v) {
    for (const auto& i : vv) o << setw(width) << i;
    o << endl;
  }
}

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

  int n; ll d; cin >> n >> d;
  d *= d;
  int cnt = 0;
  F0R (_, n) {
    ll x, y; cin >> x >> y;
    x *= x; y *= y;
    cnt += (x + y <= d);
  }
  cout << cnt << endl;
  
  return 0;
}


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

int main(){
  int N;
  cin>>N;
  vector<int> h(N);
  for(int i=0;i<N;i++)cin>>h.at(i);
  int sum=h.at(0);
  for(int i=1;i<N;i++){
    if(h.at(i-1)<h.at(i)){
      sum+=h.at(i)-h.at(i-1);
    }
  }
  cout << sum << endl;
}

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

int main(){
  int i,N,K,a=0,b,cnt=0;
  char ss[100001];
  scanf("%s",ss);
  N=strlen(ss);
  b=N-1;
  while(a<b){
    if(ss[a]==ss[b]){
      a++;
      b--;
      continue;
    }else if(ss[a]=='x'){
      a++;
      cnt++;
      continue;
    }else if(ss[b]=='x'){
      b--;
      cnt++;
      continue;
    }else{
      printf("-1");
      return 0;
    }
  }
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 384
N,K = map(int,input().split())
D = list(map(int,input().split()))

i = N
while True:
    flg = True
    for j in str(i):
        if int(j) in D:
            flg = False
            break

    if flg == True:
        print(i)
        exit()

    i += 1


Measured memory_bytes: 2940
import Control.Monad
import Control.Monad.ST
import Control.Monad.State
import Control.Applicative
import Control.Arrow
import Data.List
import Data.Array
import Data.Array.IO
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import Data.Tuple
import Data.Function
import Text.Printf
import Debug.Trace
import Numeric
 
modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)
 
listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)
listToTuple5 [a,b,c,d,e] = (a,b,c,d,e)
 
getWords = getLine >>= return . words
 
readIntBS = fst . fromJust . BS.readInt
 
for = flip map
 
main :: IO ()
main = do
  s <- getLine
  (x,y) <- listToTuple2 . map read . words <$> getLine :: IO (Int,Int)
 
  let
    (xs,ys) = splitByIndexOddEven $ splitByT s
    len = length s
 
  dpx <- newArray ((0,-len),(length xs,len)) False :: IO (IOUArray (Int,Int) Bool)
  dpy <- newArray ((0,-len),(length ys,len)) False :: IO (IOUArray (Int,Int) Bool)
 
  writeArray dpx (1,head xs) True
  forM_ (zip [2..] (tail xs)) $ \(i,d) -> do  
    forM_ [-len..len] $ \x -> do
      a <- if x-d >= -len then readArray dpx (i-1,x-d) else return False
      b <- if x+d <= len then readArray dpx (i-1,x+d) else return False
      writeArray dpx (i,x) (a || b)
 
  writeArray dpy (0,0) True
  forM_ (zip [1..] ys) $ \(i,d) -> do
    forM_ [0..len] $ \y -> do
      a <- if y-d >= -len then readArray dpy (i-1,abs (y-d)) else return False
      b <- if y+d <= len then readArray dpy (i-1,y+d) else return False
      writeArray dpy (i,y) (a || b)
 
 
  putStrLn =<< (\a b -> if a && b then "Yes" else "No") <$> readArray dpx (length xs,x) <*> readArray dpy (length ys,abs y)
  
  where
    splitByT [] = []
    splitByT xs = length a : splitByT (if null b then b else tail b)
      where (a,b) = span (/='T') xs
 
    splitByIndexOddEven xs = aux xs 1
      where
        aux [] _ = ([],[])
        aux (x:xs) n
          | odd n = first (x:) $ aux xs (n+1)
          | even n = second (x:) $ aux xs (n-1)

Measured memory_bytes: 19836
#include<iostream>

using namespace std; 

const int MAX = 100000;
int A, B, D;

struct Weight {
    int x, y;
    Weight(int x_, int y_): x(x_), y(y_) {}
    bool operator<(const Weight w) const {
        if (x+y != w.x+w.y) return x+y < w.x+w.y;
        if (A*x + B*y != A*w.x + B*w.y) return A*x + B*y < A*w.x + B*w.y; 
        if (x != w.x) return x < w.x;
        return y < w.y;
    }
};

int main() {
    while (true) {
        cin >> A >> B >> D;
        if (!A && !B && !D) break;
        Weight ans = Weight(MAX, MAX);

        for (int x = 0; x < MAX; ++x) {
            int l = A*x + D;
            if (l % B == 0) {
                int y = l / B;
                Weight w = Weight(x, y);
                ans = min(ans, w);
            }
            int r = A*x - D;
            if (r >= 0 && r % B == 0) {
                int y = r / B;
                Weight w = Weight(x, y);
                ans = min(ans, w);
            }
            int m = D - A*x;
            if (m >= 0 && m % B == 0) {
                int y = m / B;
                Weight w = Weight(x, y);
                ans = min(ans, w);
            }
        }

        cout << ans.x << " " << ans.y << endl;
    }
    return 0;
}

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

using namespace std;




int main(void){
   int K,N;
   int a=0;
   int maxx=0;
   cin>>K>>N;
   vector<int> v(N);
   for(int i=0;i<N;i++){
     cin>>v[i];
   }
   v.push_back(v[0]+K);
   for(int i=1;i<=N;i++){
     maxx=max(maxx,abs(v[i]-v[i-1]));
   }
   int b=K-maxx;
   cout<<b<<endl;

   return 0;
   
}




Measured memory_bytes: 4844
N,M=list(map(int,input().split()))
X = [[] for i in range(8)]
for i in range(N):
    x,y,z=list(map(int,input().split()))
    for i in range(8):
        X[i].append(int(2*((i%2)-1/2))*x + int(2*(((i//2)%2)-1/2))*y + int(2*(((i//4)%2)-1/2))*z)
ans=0
for i in range(8):
    X[i].sort()
    X[i]=X[i][::-1]
    ans=max(sum(X[i][:M]),ans)
    
print(ans)

Measured memory_bytes: 3428
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    void shr(int n,char v);
    char u,d,r,l;
    int x1,y1,x2,y2;
   u='U';
   r='R';
   l='L';
   d='D';
    cin>>x1>>y1>>x2>>y2;
    shr(abs(y2-y1),u);
    shr(abs(x2-x1),r);
    shr(abs(y2-y1),d);
    shr(abs(x2-x1)+1,l);
    shr(abs(y2-y1)+1,u);
    shr(abs(x2-x1)+1,r);
    shr(1,d);
    shr(1,r);
    shr(abs(y2-y1)+1,d);
    shr(abs(x2-x1)+1,l);
    shr(1,u);


}
void shr(int n,char v)
{
    for(int x=0;x<n;x++)
    {
        cout<<v;
    }
}


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

int main(){
    int n,ans=0;
    double b=0;
    cin>>n;

    for(int i=0;i<n;i++){
        double x;
        string u;
        cin>>x>>u;
        if(u=="BTC") b+=x;
        else ans+=x;
    }

    cout<<ans+(b*380000)<<endl;

}


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

using namespace std;

int main() {
	int n,k; cin >> n >> k;
	vector<long long> t1(n+1),t2(n+1);
	for(int i=1;i<=n;++i) {
		long long a; cin >> a;
		t1[i]=t1[i-1]+a;
		t2[i]=t2[i-1]+(a>0?a:0);
	}
	long long ans=0;
	for(int i=k;i<=n;++i) {
		long long tmp=t1[i]-t1[i-k];
		if(tmp<0) tmp=0;
		ans=max(ans,t2[n]-(t2[i]-t2[i-k])+tmp);
	}
	cout << ans << endl;
	
	return 0;
}

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

#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

//#define max(a,b) a>b?a:b
//#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int sum() { return 0; }

template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }


const int nax = 100005;
int a[nax];
int b[nax];
int c[nax];
int n;
int memo[nax][5];
int maxValue(int i , int last){
	if(i == n) return 0;

	if(memo[i][last] != -1){
		return memo[i][last];
	}
	memo[i][last] = INT_MIN;
	if(last != 1){
		memo[i][last] = max(memo[i][last] , a[i] + maxValue(i+1 , 1));
		//dump(memo[i][last]);

	}
	if(last != 2){
		memo[i][last] = max(memo[i][last] , b[i] + maxValue(i+1 , 2));
		//dump(memo[i][last]);

	}
	if(last != 3){
		memo[i][last] = max(memo[i][last] , c[i] + maxValue(i+1 , 3));
		//dump(memo[i][last]);
	}
	return memo[i][last];
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>n;
	REP(i,n) cin>>a[i]>>b[i]>>c[i];

	//memset(memo , -1 , sizeof(memo));
	REP(i,n)REP(j , 5) memo[i][j] = -1;

	std::cout << maxValue(0 , 4) << "\n";
	return 0;
}


Measured memory_bytes: 14536
#include<bits/stdc++.h>
using namespace std;
string a;
int g,p,w;
int main(){
    cin>>a;
    for(int i=0;i<a.length();i++){
        if(a[i]=='g'){
            if(g>=(p+1)){
                w++;
                p++;
            }
            else g++;
        }
        else{
            if(g>=(p+1))p++;
            else{
                g++;
                w--;
            }
        }
    }
    cout<<w<<endl;
    return 0;
}

Measured memory_bytes: 512
fun main(args: Array<String>) {
        val (animalCount, feets) = readLine()!!.split(' ').map { it.toInt() }.toIntArray()
        if(feets % 2 != 0 || animalCount > 50) {
            println("No")
            return
        }

        var remain = feets - (animalCount * 2)
        
        if(remain == 0) {
            println("Yes")
            return
        }
        
        for(i in 0 until animalCount) {
            remain -= 2
            if(remain == 0) {
                println("Yes")
                return
            }
        }
        println("No")
    }

Measured memory_bytes: 36304
#include<bits/stdc++.h>
using namespace std;
int main(){
	int t=1;
	//cin >> t;
	while(t--){
		char a;
      	cin >> a;
      	if((int)a>=65&&(int)a<=92){cout << 'A'<<endl;}
      	else cout << 'a' <<endl;
	}
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll hoge[111][111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll h,w,p;cin>>h>>w>>p;
  for(int i=0;i<p;i++){
    ll x,y;cin>>x>>y;
    ll a;cin>>a;
    if(a==1){
      for(int i=0;i<w;i++){
	for(int j=0;j<x;j++){
	  hoge[i][j]=1;
	}
      }
    }else if(a==2){
      for(int i=0;i<w;i++){
	for(int j=x;j<h;j++){
	  hoge[i][j]=1;
	}
      }
    }else if(a==3){
      for(int i=0;i<y;i++){
	for(int j=0;j<h;j++){
	  hoge[i][j]=1;
	}
      }
    }else{
      for(int i=y;i<w;i++){
	for(int j=0;j<h;j++){
	  hoge[i][j]=1;
	}
      }
    }
  }
  ll ans=0;
  for(int i=0;i<111;i++)
    for(int j=0;j<111;j++)
      ans+=hoge[i][j];
  cout<<h*w-ans<<endl;
  return 0;
}


Measured memory_bytes: 384
N, K = map(int, input().split())

nums = [0] * K
for i in range(1, N + 1):
    nums[i % K] += 1

ans = 0
for i in range(K):
    b = (K - i) % K
    c = (K - i) % K
    if (b + c) % K != 0: continue

    ans += nums[i] * nums[b] * nums[c]

print(ans)


Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
#define fi              first
#define se              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define endl			"\n"
void fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}


int32_t main()
{
	fast();
	int n;	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++)	cin >> h[i];

	vector<int> dp(n, 0);
	for (int i = 1; i < n; i++)
	{
		if (i == 1)
			dp[i] = abs(h[i] - h[0]);
		else
			dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
	}
	//for (int i = 0; i < n; i++)	cout << dp[i] << " ";
	cout << dp[n - 1];
	return 0;
}


Measured memory_bytes: 4768
#include <stdio.h>
#include <stdlib.h>

#define N 10

static int d[N][5];
static int n;

static
read()
{
  int i, j;
  scanf("%d", &n);
  for (i = 0; i < n; ++i)
  for (j = 0; j < 5; ++j)
    scanf("%d", &d[i][j]);
  return n;
}

static
simulat(s)
int *s;
{
  int rval = 0;
  int i, j, k;
  for (i = 0; i < 5; ) {
    for (j = i + 1; j <= 5; ++j) {
      if (j < 5 && s[j] == s[i]) continue ;
      if (s[i] > 0 && j - i >= 3) {
        rval =+ s[i] * (j - i);
        for (k = i; k < j; ++k) {
          s[k] = -1;
        }
      }
      i = j;
      break ;
    }
  }
  return rval;
}

static void
compress()
{
  int i, j, k;
  for (i = 0; i < 5; ++i) {
    k = n - 1;
    for (j = k; j >= 0; --j) {
      if (d[j][i] < 0) continue ;
      d[k--][i] = d[j][i];
    }
    for (; k >= 0; --k) {
      d[k][i] = -1;
    }
  }
}

static
eval()
{
  int rval = 0;
  int i;
  for (;;) {
    const int rbak = rval;
    for (i = 0; i < n; ++i) {
      rval += simulat(d[i]);
    }
    if (rval == rbak) break ;
    compress();
  }
  return rval;
}

main()
{
  for (;;) {
    if (read() == 0) break ;
    printf("%d\n", eval());
  }
  return EXIT_SUCCESS;
}

Measured memory_bytes: 600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String[] inputWords = br.readLine().split(" ");
            String lastCharOfFirstWord = getLastCharacter(inputWords[0]);
            String firstCharOfSecondWord = getFirstCharacter(inputWords[1]);
            String lastCharOfSecondWord = getLastCharacter(inputWords[1]);
            String firstCharOfThirdWord = getFirstCharacter(inputWords[2]);

            if (lastCharOfFirstWord.equals(firstCharOfSecondWord)
                && lastCharOfSecondWord.equals(firstCharOfThirdWord)) {
                
                System.out.println("YES");
                
            } else {

                System.out.println("NO");

            }
            

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }

    private static String getFirstCharacter(String word) {
        return word.substring(0, 1);
    }

    private static String getLastCharacter(String word) {
        return word.substring(word.length() - 1, word.length());
    }
}

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


int main(){
  int n; cin>>n;
  bool check=true;
  vector<string> w(n);
  for(int i=0;i<n;i++){
    cin>>w.at(i);
    if(i>0 && w.at(i-1).at(w.at(i-1).size()-1)!=w.at(i).at(0)){
      check=false;}
    
    for(int j=0;j<i;j++){  
      if(w.at(i)==w.at(j))check=false;
    } 
   }
   if(check)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
   int H,W,D; cin >> H >> W >> D;
   vector<vector<int>> A(H,vector<int>(W));
   vector<int> x(90100),y(90100);
   rep(i,H)rep(j,W){
       cin >> A[i][j];
       x[A[i][j]] = j;
       y[A[i][j]] = i;
   }
   vector<ll> sum(90100);
   repr(i,D+1,90100){
       sum[i] = sum[i-D] + abs(x[i]-x[i-D]) + abs(y[i]-y[i-D]);
   }
   int Q; cin >> Q;
   rep(i,Q){
       int L,R; cin >> L >> R;
       ll ans = sum[R] - sum[L];
       cout << ans << endl;
   }
}


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

using namespace std;

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

    int ans = 1;
    for (int i = 0; i < n; ++i) {
        ans = min(ans * 2, ans + k);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}

int N;
int a[100010];
int gcd_l[100010], gcd_r[100010];

signed main()
{
	cin >> N;
	rep1(i, N) cin >> a[i];

	for (int i = 1; i <= N; ++i) {
		gcd_l[i] = gcd(a[i], gcd_l[i - 1]);
	}
	for (int i = N; i >= 1; --i) {
		gcd_r[i] = gcd(a[i], gcd_r[i + 1]);
	}

	int ans = 1;

	for (int i = 1; i <= N; ++i) {
		int v = 0;
		v = gcd(v, gcd_l[i - 1]);
		v = gcd(v, gcd_r[i + 1]);

		ans = max(ans, v);
	}

	cout << ans << endl;
}




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

int main() {
    int N;
    cin >> N;
    vector<pair<long long, long long>> A;
    for (int i = 0; i < N; i++) {
        int a, b; cin >> a >> b;
        A.emplace_back(a+b, a-b);
    }
    
    sort(A.begin(), A.end());
    long long now = -1e18, ans = 0;
    for (auto a : A) {
        if (now <= a.second) {
            ans++;
            now = a.first;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

vector<ll>g[maxn];
bool used[maxn];
ll d[maxn];


signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//freopen("mountains.in", "r", stdin);
	//freopen("mountains.out", "w", stdout);
	ll n; cin >> n;
	for (ll i = 0; i < n - 1; i++) {
		ll u, v; cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	queue<ll>q;
	q.push(1); used[1] = 0;
	while (!q.empty()) {
		ll u = q.front();
		q.pop();
		for (ll v : g[u]) {
			if (used[v]) continue;
			d[v] = d[u] + 1;
			used[v] = 1;
			q.push(v);
		}
	}

	vector<ll>ans(n + 1);
	vector<ll>cnt(2);
	ll lst1 = 1, lst2 = 2, lst0 = 3;
	for (ll i = 1; i <= n; i++) {
		cnt[d[i] % 2]++;
	}
	if (cnt[0] <= n / 3) {
		for (ll i = 1; i <= n; i++) {
			if (d[i] % 2 == 0) {
				ans[i] = lst0; lst0 += 3;
			} else {
				if (lst1 <= n) {
					ans[i] = lst1; lst1 += 3;
				} else if (lst2 <= n) {
					ans[i] = lst2; lst2 += 3;
				} else {
					ans[i] = lst0; lst0 += 3;
				}
			}
		}
	} else if (cnt[1] <= n/3) {
		for (ll i = 1; i <= n; i++) {
			if (d[i] % 2 == 1) {
				ans[i] = lst0; lst0 += 3;
			} else {
				if (lst1 <= n) {
					ans[i] = lst1; lst1 += 3;
				} else if (lst2 <= n) {
					ans[i] = lst2; lst2 += 3;
				} else {
					ans[i] = lst0; lst0 += 3;
				}
			}
		}
	} else {
		for (ll i = 1; i <= n; i++) {
			if (d[i] % 2 + 1 == 1) {
				if (lst1 <= n) {
					ans[i] = lst1;
					lst1 += 3;
				} else {
					ans[i] = lst0;
					lst0 += 3;
				}
			} else {
				if (lst2 <= n) {
					ans[i] = lst2;
					lst2 += 3;
				} else {
					ans[i] = lst0;
					lst0 += 3;
				}
			}
		}
	}




	for (ll i = 1; i <= n; i++) cout << ans[i] << " ";
	cout << endl;
	return 0;
}

/*


*/

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

#define dbg(...)
// #define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
// void err() { cerr << "\033[39;0m" << endl; }
// template<typename T, typename... A>
// void err(T a, A... x) { cout << a << ' '; err(x...); }
const int N = 2e5 + 5;
typedef long long LL;

#define int long long

priority_queue<pair<LL, LL>, vector<pair<int, int>>, greater<pair<int, int>>> q;

struct node
{
    int x, h;
} dat[N];

int d, a, n;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> d >> a;
    LL ans = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> dat[i].x >> dat[i].h;
        q.emplace(dat[i].x, dat[i].h);
    }
    LL cur = 0;
    while (!q.empty())
    {
        auto p = q.top(); q.pop();
        dbg(cur, p.first, p.second, ans);
        if (p.second < 0)
        {
            cur += p.second;
        }
        else if (p.second > cur)
        {
            LL del = (p.second-cur+a-1) / a;
            ans += del;
            cur += del * a;
            q.emplace(p.first + 2 * d + 1, - del * a);
        }
    }
    // printf("%lld\n", ans);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8432
s = input()
t = ""

p = 0
while p < len(s):
    if s[p:p+5] == 'dream' and s[p+5:p+6] != 'e':
        p += 5
        t += 'dream'
    elif s[p:p+5] == 'erase' and s[p+5:p+6] != 'r':
        p += 5
        t += 'erase'
    elif s[p:p+6] == 'eraser':
        p += 6
        t += 'eraser'
    elif s[p:p+7] == 'dreamer' and s[p+7:p+8] != 'a':
        p += 7
        t += 'dreamer'
    elif s[p:p+7] == 'dreamer' and s[p+7:p+8] == 'a':
        p += 5
        t += 'dream'
    else:
        break

print("YES" if t==s else "NO")




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

struct Card {char suit, val;};

void bubble(struct Card arr[], int N) {
    for (int i=0; i<N; i++) {
        for (int j=N-1; j>=i+1; j--) {
            if (arr[j-1].val > arr[j].val) 
            swap(arr[j-1], arr[j]);
        }
    }
}

void selection(struct Card arr[], int N) {
    for (int i=0; i<N-1; i++) {
        int minj=i;
        for (int j=i; j<N; j++) {
            if (arr[minj].val > arr[j].val) minj=j;
        }
        swap(arr[i], arr[minj]);
    }
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
    for (int i=0; i<N; i++) {
        if (C1[i].suit != C2[i].suit) return false;
    }
        return true;
}

int main() {
    Card C1[36], C2[36];
    int N;
    char ch;
    
    cin >> N;
    
    for (int i=0; i<N; i++) {
        cin >> C1[i].suit >> C1[i].val;
    }


for (int i=0; i<N; i++) C2[i]=C1[i];

bubble(C1, N);
selection(C2, N);

for (int i=0; i<N; i++) {
    if (i>0) cout << " ";
    cout << C1[i].suit << C1[i].val;
}
cout << endl;
cout << "Stable" << endl;

for (int i=0; i<N; i++) {
    if (i>0) cout << " ";
    cout << C2[i].suit << C2[i].val;
}
cout << endl;
cout <<(isStable(C1, C2, N)? "Stable":"Not stable") << endl;

return 0;
}



Measured memory_bytes: 3104
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    s = S()
    t = "".join(s.split("hi"))
    if t == "":
        return "Yes"

    return "No"


print(main())





Measured memory_bytes: 5444
#include<bits/stdc++.h>
#define ll long long

using namespace std;
int n,m,ans;
int table[10][100]={{0,0,0,0,0,0,0,0,0,0},
                   {0,1,-1,-1,-1,-1,-1,-1,-1,-1},
				   {0,2,4,-1,-1,-1,-1,-1,-1,-1},
				   {0,3,6,9,-1,-1,-1,-1,-1,-1,},
				   {0,4,8,12,16,-1,-1,-1,-1,-1},
				   {0,5,10,15,20,25,-1,-1,-1,-1},
				   {0,6,12,18,24,30,36,-1,-1,-1},
				   {0,7,14,21,28,35,42,49,-1,-1},
				   {0,8,16,24,32,40,48,56,64,-1},
				   {0,9,18,27,36,45,54,63,72,81}};

ll read(){
	ll ans=0;
	char last=' ',ch=getchar();
	while(ch<'0' || ch>'9')last=ch,ch=getchar();
	while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
	if(last=='-')ans=-ans;
	return ans;
}

int main(){
	memset(table,0x7f7f7f7f,sizeof(table));
	int table[105][105]={{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
                   {-1,1,-1,-1,-1,-1,-1,-1,-1,-1},
				   {-1,2,4,-1,-1,-1,-1,-1,-1,-1},
				   {-1,3,6,9,-1,-1,-1,-1,-1,-1,},
				   {-1,4,8,12,16,-1,-1,-1,-1,-1},
				   {-1,5,10,15,20,25,-1,-1,-1,-1},
				   {-1,6,12,18,24,30,36,-1,-1,-1},
				   {-1,7,14,21,28,35,42,49,-1,-1},
				   {-1,8,16,24,32,40,48,56,64,-1},
				   {-1,9,18,27,36,45,54,63,72,81}};
	n=read();
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			if(n==-1){
				printf("No");
				return 0;
			}
			if(table[i][j]!=n)
				continue;	
			else{
				printf("Yes"); 
				return 0;	
			}
		}
	}
	printf("No");
	return 0; 
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll T;
ll K[200010], L[200010], R[200010];

ll calcGreedy( std::vector<P> &ps ) {
  ll n = ps.size();
  rep( i, n )
    ps[i].first = std::min( ps[i].first, n );

  std::vector<std::vector<ll>> vs(n+1);
  rep( i, n )
    vs[ps[i].first].emplace_back( ps[i].second );

  std::priority_queue<ll> pque;

  ll ret = 0;
  
  repd( i, n ) {
    for( auto v : vs[i+1] )
      pque.emplace( v );

    if( !pque.empty() )
      ret += pque.top(), pque.pop();
  }

  return ret;
}

int main()
{
  std::cin >> T;

  rep( t, T ) {
    ll N;
    std::cin >> N;

    std::vector<P> ls, rs;

    ll ans = 0;

    rep( i, N ) {
      std::cin >> K[i] >> L[i] >> R[i];

      if( L[i] > R[i] )
        ls.emplace_back( K[i], L[i]-R[i] ), ans += R[i];
      else if( L[i] < R[i] )
        rs.emplace_back( N-K[i], R[i]-L[i] ), ans += L[i];
      else
        ans += R[i];
    }

    ans += calcGreedy(ls);
    ans += calcGreedy(rs);

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

  return 0;
}

Measured memory_bytes: 17100
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if X == 500*i + 100*j + 50*k:
                count += 1
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

ll a[100001];
ll c[100001]={};
int main() {

	ll total=0;
	int n,k;

	cin>>n>>k;

	rep(i,n){
		cin>>a[i];
		c[i]=a[i]-a[i-1]-1;
	}
	c[0]=1000000001;
	sort(c,c+n);
	total+=n;

	rep(i,n-k){
		total+=c[i];
	}

	cout<<total<<endl;
	return 0;
}



Measured memory_bytes: 4720
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
typedef long long ll;

int n,m,k;
string s,t;

int main() {
  cin >> n;
  int a[201010];
  rep(i,n) cin >> a[i];
  deque<int> b;
  rep(i,n){
    if(i%2==0) b.push_back(a[i]);
    else b.push_front(a[i]);
  }
  rep(i,n){
    int x;
    if(n%2==0) x=b.front(),b.pop_front();
    else x=b.back(),b.pop_back();
    cout << x << " ";
  }
  cout << endl;
}


Measured memory_bytes: 3840
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <functional>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl
#define MOD 1000000007
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

//  int a[5] = {1,2,3,4,5};
//  vector<int> v = {1,2,3,4,5};
//  cout << lower_bound(a,a+5, 4) - a << endl;
//  cout << lower_bound(ALL(v), 4) - v.begin() << endl;
//
//  return 0;

  // 二分探索，lower_bound
  // https://qiita.com/e869120/items/702ca1c1ed6ff6770257
  // https://scrapbox.io/ganariya/AtCoderBeginnerContest077_C%E5%95%8F%E9%A1%8C300%E7%82%B9_%E3%80%8CSnuke_Festival%E3%80%8D_(copy)
  ll N; cin>>N;
  vector<ll> A(N), B(N), C(N);
  rep(i,N) cin>>A[i]; sort(ALL(A));
  rep(i,N) cin>>B[i]; sort(ALL(B));
  rep(i,N) cin>>C[i]; sort(ALL(C));

  ll res = 0;
  rep(i,N) {
    ll left = lower_bound(ALL(A), B[i]) - A.begin();
    ll right = C.end() - upper_bound(ALL(C), B[i]);
    res += left*right;
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
long long M=1e9+7,a[100010];
int mbk(long long a,int n,int m){return n?(mbk((a*a)%m,n/2,m)*(n%2?a:1))%m:1;}
int inv(int a,int m){return mbk((long long)a,m-2,m);}
int ub(int l,int r,int n,int *d){
  int m=(l+r)/2;
  if(l==r)return m;
  return n<d[m]?ub(l,m,n,d):ub(m+1,r,n,d);
}
long long f(int n,int m,int *d){
  long long ans=0;
  int i,c;
  for(i=m-1;i<n;i++){
    //c=ub(0,n,d[i],d)-1;//printf("%d %d %d %lld\n",i,c,d[i],a[c]);
    ans=(ans+(d[i]*a[i])%M)%M;
    //printf("!%lld\n",ans);
  }//printf("%lld\n",ans);
  return ans;
}
int main(){
  int n,m,d[100010],i,e[100010];
  long long p[100010]={1};
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++)scanf("%d",&d[i]);
  for(i=0;i<n;i++)hin(d[i]);
  for(i=0;i<n;i++)d[i]=N[hout()];
  for(i=0;i<n;i++)e[n-i-1]=d[i];
  for(i=0;i<=n;i++)p[i+1]=(p[i]*(i+1))%M;
  for(i=m-1;i<=n;i++)a[i]=p[i]*inv(p[i-m+1],M)%M*inv(p[m-1],M)%M;
  //for(i=0;i<=n;i++)printf("%lld\n",a[i]);
  printf("%lld\n",(f(n,m,d)-f(n,m,e)+M)%M);
  return 0;
}


Measured memory_bytes: 8320
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N;
ll A[100000];
ll allXOR = 0;
ll ans = 0;

signed main(){
    cin >> N;
    rep(i, N) cin >> A[i];

    rep(i, N) allXOR ^= A[i];

    int k = 0;
    rep(i, 60){
        if((allXOR>>59-i)&1) ans += 1LL<<59-i;
        else{
            for(int j=k; j<N; j++){
                if((A[j]>>59-i)&1){
                    swap(A[k], A[j]);
                    break;
                }
            }
            if((A[k]>>59-i)&1){
                ans += 1LL<<60-i;
                for(int j=0; j<N; j++){
                    if(j == k) continue;
                    if((A[j]>>59-i)&1) A[j] ^= A[k];
                }
                k++;
            }
            else{
                int cnt = 0;
                rep(j, N){
                    cnt += (A[j]>>59-i)&1;
                }
                if(cnt%2) ans += 1LL<<60-i;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
'use strict'

function main(s) {

  s = s.split('\n');

  const q = s[1].split(' ').map(n => Number(n));
  const drink = s.slice(3, -1).map(l => l.split(' ').map(n => Number(n)));

  const base_sum = q.reduce((a, b) => a + b);
  const ans = [];

  for (let i = 0; i < drink.length; i++) {
    const nsum = base_sum + (drink[i][1] - q[drink[i][0] - 1]);
    ans.push(nsum);
  }

  console.log(ans.join('\n'));
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 9420
n = int(input())
list_s1 = list(str(input()))
ans = 1
list_s1.append("!")
for i in range(n):
    if i == 0:
        ans *= 3
    elif i == 1:
        ans *= 2
    else:
        if list_s1[i] == list_s1[i-1]:
            ans *= 1
        else:
            if list_s1[i-1] == list_s1[i-2]:
                if list_s1[i] != list_s1[i+1]:
                    ans *= 1
                else:
                    ans *= 3
            else:
                ans *= 2
print(ans%(10**9+7))


Measured memory_bytes: 3064