akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template <typename T>
struct edge {
    int from, to;
    T cost;

    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}

    explicit operator int() const {return to;}
};

template <typename T>
vector<vector<T>> all_dijkstra(vector<vector<edge<T>> > &G){
    int n=G.size();
    const T INF = numeric_limits<T>::max();
    using P = pair<T, int>;
    vector<vector<T>> ans(n, vector<T>(n, INF));
    for (int i = 0; i < n; ++i) {
        vector<int> b(n,-1);
        priority_queue<P,vector<P>,greater<> > Q;
        ans[i][i]=0;
        Q.emplace(ans[i][i],i);
        while(!Q.empty()){
            T cost;
            int j;
            tie(cost, j) = Q.top(); Q.pop();
            if(ans[i][j] < cost) continue;
            for (auto &&e : G[j]) {
                auto cost2 = cost + e.cost;
                if(ans[i][e.to] <= cost2) continue;
                ans[i][e.to] = cost2;
                Q.emplace(ans[i][e.to], e.to);
            }
        }
    }
    return ans;
}

int main() {
    u32 n, m, r;
    cin >> n >> m >> r;
    vector<vector<edge<int>>> v(n);
    vector<int> R(r);
    for (int i = 0; i < r; ++i) {
        int x;
        cin >> x;
        R[i] = x-1;
    }
    sort(R.begin(), R.end());
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        v[a-1].emplace_back(b-1, c);
        v[b-1].emplace_back(a-1, c);
    }
    vector<vector<int>> p = all_dijkstra(v);
    ll ans = numeric_limits<ll>::max();
    do{
        ll x = 0;
        for (int i = 0; i < r - 1; ++i) {
            x += p[R[i]][R[i+1]];
        }
        ans = min(x, ans);
    }while(next_permutation(R.begin(), R.end()));
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A, B;
    cin >> A >> B;
    
    int ans = 0;
    ans = max(ans, A + A - 1);
    ans = max(ans, B + B - 1);
    ans = max(ans, A + B);
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int x[5],K;
  for(int i=0;i<5;i++){
    scanf("%d",&x[i]);
  }
  scanf("%d",&K);

  if(x[4]-x[0]>K){
    printf(":(\n");
  }else{
    printf("Yay!\n");
  }

  return 0;
}



Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AAirConditioner solver = new AAirConditioner();
        solver.solve(1, in, out);
        out.close();
    }

    static class AAirConditioner {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int x = in.nextInt();

            out.println(x >= 30 ? "Yes" : "No");
        }

    }

    static class InputReader {
        public final BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		Hunter hunter = new Hunter();
		while(true){
			String[] tmpStr = br.readLine().split(",");
			int inputDir = Integer.parseInt(tmpStr[0]);
			int inputAngle = Integer.parseInt(tmpStr[1]);
			
			if(inputDir == 0&&inputAngle == 0){
				break;
			}
			
			hunter.move(inputDir, inputAngle);
		}
		
		System.out.println((int)hunter.x);
		System.out.println((int)hunter.y);
	}

}

class Hunter {
	double x = 0;
	double y = 0;
	int angle = 90;
	
	public void move(int distance, int angle){
		int newAngle = this.angle - angle;
		this.x += distance*Math.cos(Math.toRadians(this.angle));
		this.y += distance*Math.sin(Math.toRadians(this.angle));
		this.angle = newAngle;
		
		//System.out.println("(x,y) "+x+" "+y+"angle "+this.angle);
	}
}

Measured memory_bytes: 24192
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

typedef vector<ll> Array;
typedef vector<Array> Matrix;

// 正方行列の掛け算 O(N^3)
Matrix mul(const Matrix &a, const Matrix &b){
  const int N = a.size();
  Matrix res(N, Array(N, 0));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      for(int k = 0; k < N; k++){
        res[i][j] += a[i][k] * b[k][j];
        res[i][j] %= MOD;
      }
    }
  }
  return res;
}
// サイズNの単位行列
Matrix Mat_E(int N){
  Matrix res(N, Array(N, 0));
  for(int i = 0; i < N; i++){
    res[i][i] = 1;
  }
  return res;
}
// 正方行列の累乗 O(M^3 * logn)
Matrix pow(const Matrix &a, long long n){
  const int M = a.size();
  if(n == 0) return Mat_E(M);
  Matrix res = pow(mul(a, a), n / 2);
  if(n & 1) res = mul(res, a);
  return res;
}

int main(){
  int mat[5][5] = {
    {1, 1, 1, 0, 1},
    {1, 1, 1, 0, 0},
    {1, 1, 1, 1, 0},
    {1, 0, 0, 1, 0},
    {0, 0, 1, 0, 1}
  };
  int W, H;
  cin >> W >> H;
  if(H == 1){
    int ans = 1;
    REP(i, W) ans = (ans * 2) % MOD;
    cout << ans << endl;
  }else{
    Matrix M(5, Array(5));
    REP(i, 5)REP(j, 5) M[i][j] = mat[i][j];
    M = pow(M, W - 1);
    int ans = 0;
    REP(i, 4)REP(j, 4) ans = (ans + M[i][j]) % MOD;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE BangPatterns #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Map.Strict (Map)
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import Data.Set (Set)

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Mutable as MVector
import Data.Vector.Mutable (STVector)
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToVector :: ByteString -> Vector Int
readIntToVector = Vector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToVectorN :: Int -> ByteString -> Vector.Vector Int
readIntToVectorN n = Vector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace


first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

average :: Fractional a => [a] -> a
average xs = sum xs / (fromIntegral . length) xs

-- ----------

check 0 = False
check n = n `mod` 10 == 7 || check (n `div` 10)

main :: IO ()
main = do
	n <- readLn
	putStrLn $ if check n
		then "Yes"
		else "No"


Measured memory_bytes: 3844
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N,K,h[100000],minH[100000];
	cin>>N>>K;
	for(int i=0;i<N;i++){
		cin>>h[i];
	}
	minH[0]=0;
	for(int i=1;i<N;i++){
		minH[i] = minH[i-1]+abs(h[i]-h[i-1]);
		for(int j=max(0,i-K);j<i;j++){
			minH[i] = min(minH[i],minH[j]+abs(h[i]-h[j]));
		}
	}
	cout<<minH[N-1];
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int func(int x) {
	if (x % 2 == 1) return 0;
	else return func(x / 2) + 1;
}

int main(void) {
	int n;
	cin >> n;
	int ans = 1;
	for (int i = 1; i <= n; i++) {
		if(func(i) > func(ans)) ans = i;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
int main() {
  int64_t N;
  cin >> N;
  int64_t sum = 0;
  rep(i,N+1){
    if(i % 3 != 0 && i % 5 !=0){
      sum += i;
    }
  }
  cout << sum << endl;
  return 0;
}



Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T>
vector<vector<T> > make_v(size_t a,size_t b){
  return vector<vector<T> >(a,make_v<T>(b));
}
template<typename T>
vector<vector<vector<T> > > make_v(size_t a,size_t b,size_t c){
  return vector<vector<vector<T> > > (a,make_v<T>(b,c));
}

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

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
struct Precision{
  Precision(){
    cout<<fixed<<setprecision(20);
  }
}precision_beet;

signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,k;
  while(cin>>n>>k,n){
    using T = tuple<Int, Int, Int>;
    vector<T> v;
    map<Int, Int> cnt;
    for(Int i=0;i<n;i++){
      Int x,y,z;
      cin>>x>>y>>z;
      v.emplace_back(z,x,y);
      cnt[z]++;
    }
    sort(v.rbegin(),v.rend());
    v.erase(unique(v.begin(),v.end()),v.end());
    assert((Int)v.size()==n);
    
    const double inf = 1e18;
    auto dist=make_v<double>(n,n);
    fill_v(dist,0);
    auto calc=[&](T a,T b){
      if(get<0>(a)==get<0>(b)) return inf;
      double sum=0;
      sum+=(get<0>(a)-get<0>(b))*(get<0>(a)-get<0>(b));
      sum+=(get<1>(a)-get<1>(b))*(get<1>(a)-get<1>(b));
      sum+=(get<2>(a)-get<2>(b))*(get<2>(a)-get<2>(b));
      return sqrt(sum);
    };
    
    for(Int i=0;i<n;i++)
      for(Int j=0;j<n;j++)
	dist[i][j]=calc(v[i],v[j]);

    auto di=[&](Int i,Int j){
      if(min(i,j)<0) return (double)0.;
      return dist[i][j];
    };

    auto dp=make_v<double>(n+1,n+1,n+1);
    fill_v(dp,inf);
    dp[0][0][0]=0;
    
    auto nx=make_v<double>(n+1,n+1,n+1);    
    for(Int i=0;i<n;i++){
      fill_v(nx,inf);
      for(Int a=-1;a<i;a++){
	for(Int b=-1;b<0||b<a;b++){
	  for(Int c=-1;c<0||c<b;c++){
	    if(dp[a+1][b+1][c+1]>=inf) continue;
	    //cout<<i-1<<" "<<a<<" "<<b<<" "<<c<<":"<<dp[a+1][b+1][c+1]<<endl;
	    chmin(nx[a+1][b+1][c+1],dp[a+1][b+1][c+1]+di(i-1,i));
	    chmin(nx[i+0][b+1][c+1],dp[a+1][b+1][c+1]+di(a,i));
	    chmin(nx[i+0][a+1][c+1],dp[a+1][b+1][c+1]+di(b,i));
	    chmin(nx[i+0][a+1][b+1],dp[a+1][b+1][c+1]+di(c,i));
	  }
	}
      }
      swap(dp,nx);
    }
    double ans=inf;
    
    for(Int a=-1;a<n;a++){
      for(Int b=-1;b<0||b<a;b++){
	for(Int c=-1;c<0||c<b;c++){
	  Int s=(a==-1)+(b==-1)+(c==-1);
	  if(k+s>=4) chmin(ans,dp[a+1][b+1][c+1]);
	}
      }
    }
    if(ans>inf/2) cout<<-1<<endl; 
    else cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 20072
#include <iostream>
using namespace std;
class AABCSwap {
public:
	void solve(std::istream& in, std::ostream& out) {
        int X = 0;
        int Y = 0;
        int Z = 0;
        in >> X >> Y >> Z;
        out << Z << " " << X << " " << Y;
	}
};


int main() {
	AABCSwap solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

typedef long long ll;

//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};

// const int C ;
// const int M = 1000000007;

typedef pair<int, int> point;

set<point> S;
ll H, W;
int N;
ll ans[10];
int a[100010], b[100010];

void calc(int x, int y) {
  if (!(0 <= x && x+2 < H && 0 <= y && y+2 < W)) {
    return;
  }
  int cnt = 0;
  for (auto i = x; i < x+3; i++) {
    for (auto j = y; j < y+3; j++) {
      if (S.find(make_pair(i, j)) == S.end()) {
        
      } else {
        cnt++;
      }
    }
  }
  if (cnt != 0) {
    // cerr << "x = " << x << ", y = " << y << ", cnt = " << cnt << endl;
    ans[cnt]++;
  }
}

int main () {
  cin >> H >> W >> N;
  for (auto i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    S.insert(make_pair(a[i], b[i]));
  }
  fill(ans, ans+10, 0);
  for (auto i = 0; i < N; i++) {
    for (auto j = a[i]-2; j <= a[i]; j++) {
      for (auto k = b[i]-2; k <= b[i]; k++) {
        calc(j, k);
      }
    }
  }
  ll sum = (H-2) * (W-2);
  for (auto i = 1; i < 10; i++) {
    sum -= ans[i]/i;
  }
  cout << sum << endl;
  for (auto i = 1; i < 10; i++) {
    cout << ans[i]/i << endl;
  }
  
}


Measured memory_bytes: 5760
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;
NodePointer nil;

void init(){
  nil=(struct node*)malloc(sizeof(struct node));
  nil->next=nil;
  nil->prev=nil;
}

void printList(){
  struct node *p;
  for(p=nil->next;p!=nil;p=p->next){
    if(p!=nil->prev){
      printf("%d ", p->key);
    }else if(p == nil->prev){
      printf("%d\n", p->key);
    }
  }
}

void deleteNode(NodePointer q){
  //First
  if(q->prev==nil){
    nil->next=q-> next;
    q->next->prev=nil;
    free(q);
  }
  //Last
  else if(q->next==nil){
    nil->prev=q->prev;
    q->prev->next=nil;
    free(q);
  }
  else{
    q->prev->next=q->next;
    q->next->prev=q->prev;
    free(q);
  }
}

void deleteFirst(){
  NodePointer q=nil->next;
  if(q==nil) return;
  deleteNode(q);
}

void deleteLast(){
  NodePointer q=nil->prev;
  if(q==nil) return;
  deleteNode(q);
}

void del(int key){
  struct node *p;

  if(nil->key==key){
    deleteFirst();
    return;
  }
  for(p=nil->next;p!=nil;p=p->next){
    if(p->key==key){
      deleteNode(p);
      return;
    }
  }

}

void insert(int key){
  NodePointer x;
  x = (struct node*)malloc(sizeof(struct node));
  x->key=key;

  if(nil->next==nil){
    nil-> prev=x;
  }
  x->next=nil->next;
  x->prev=nil;
  nil->next->prev=x;
  nil->next=x;
}

int main(void){
  int n,i,key;
  char com[200];
  scanf("%d", &n);

  init();

  for(i=0;i<n;i++){
    scanf("%s", com);
    if(com[0]=='i'){
      scanf("%d", &key);
      insert(key);
    }
    else if(com[0]=='d'){
      if(strlen(com) > 6){
        if(com[6]=='F') deleteFirst();
        else if(com[6]=='L') deleteLast();
      }
      else{
        scanf("%d", &key);
        del(key);
      }
    }
  }
  printList();
  return 0;
}

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

class C
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var s = Console.ReadLine();

		var c = new int[h[0]];
		for (int i = 1; i < h[0]; i++)
			c[i] = c[i - 1] + (s[i - 1] == 'A' && s[i] == 'C' ? 1 : 0);
		Console.WriteLine(string.Join("\n", new int[h[1]].Select(_ => read()).Select(x => c[x[1] - 1] - c[x[0] - 1])));
	}
}


Measured memory_bytes: 22588
# coding: utf-8
# Your code here!
"""
int #整数
float #小数

#標準入力
a=input()
a,b=map(int,input().split()) #入力は行ごと
#標準出力
print(a)
ptrint("Hello")
#for
for name in fruits: #fruitの頭から操作
    print(name)
#リスト
list0 = [] #リスト生成
list0 = [1,2,3,4] #初期化
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1 = list(map(int, input().split()))　# 複数の入力をリストに入れる
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加　最後に（）内が足される
list.insert(3,10) #リストの追加　任意の位置（追加したい位置,追加したい値）
len(list4) #リストの要素数
max(sa) #list saの最小値
list5.count(2) #リスト内の2の数
abs(a) #aの絶対値
max(a,b) min(a,b) #最大値　最小値

extension_1 = []
for i in range(10):
    extension_1.append(i)
extension_1
#>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

comprehension_1= [i for i in range(10)]
comprehension_1
#>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
a,b,c= input().split()
a=int(a)
c=int(c)
if b=="+":
    print(a+c)
else:
    print(a-c)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
  
int main()
{
  int Q;
  string S;
  cin >> S >> Q;
 
  int a = 0;
  string Sa="";
  string Sb="";
  
  for(int n=0; n<Q; n++)
  { int T;
    cin >> T;
    if(T==1)
    { if(a==0) a = 1; // 逆
      else     a = 0; // 正
    }
    else // T==2
    {  int F;
       string C;
       cin >> F >> C;
       if((F==1 && a==0)
       || (F==2 && a==1))
       {
         Sa = C + Sa;         
       }
       else
       {
         Sb = Sb + C;
       }
    }
  }
  
  S = Sa + S + Sb;
  if(a==1)
  {
    std::reverse(S.begin(), S.end());
  }
  cout << S << endl;          
}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;
struct edge{int to, cost;};

template<typename T> bool chmin(T &a,const T b){if(a>b){a=b; return true;}return false;}
template<typename T> bool chmax(T &a,const T b){if(a<b){a=b; return true;}return false;}

template <typename T>
vector<pair<T, T>> prime_factor(T n){
    vector<pair<T, T>> ret;
    for(T i=2; i*i<=n; i++){
        T tmp=0;
        while(n%i == 0){
            tmp++;
            n/=i;
        }
        if(tmp > 0) ret.push_back({i, tmp});
    }
    if(n != 1) ret.push_back({n, 1});
    return ret;
}

const int MAX=1001001;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD; //i!の計算
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; //iの逆元の計算
        finv[i] = finv[i - 1] * inv[i] % MOD; //i!の逆元の計算
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    ll N, M; cin >> N >> M;
    
    vector<pii> p=prime_factor((int)M);
    COMinit();
    ll ans=1;
    for(int i=0; i<(int)p.size(); i++){
        ans=(ans*COM(p[i].second+N-1, N-1))%MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27064
n = int(input())
h = list(map(int,input().split()))

cnt = 0
for hh in range(1,max(h)+1):
  flg = False
  for i in range(n):
    if h[i] >= hh:
      flg = True
    else:
      if flg:
        flg = False
        cnt += 1
  if flg:
    flg = False
    cnt += 1      
print(cnt)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
//static const int MAX = 100;
int in(){int x; scanf("%d",&x); return x;}

int main(){
  int A = in(), P = in();
  cout << (A * 3 + P)/2 << endl;
}

Measured memory_bytes: 256
dx = [-1,-1,-1,0,0,1,1,1,0]
dy = [-1,0,1,-1,1,-1,0,1,0]
H,W,N = map(int,input().split())
from collections import defaultdict, Counter
d = defaultdict(int)
for i in range(N):
    a,b = map(int,input().split())
    for j in range(9):
        A = a + dy[j]
        B = b + dx[j]
        f = 0
        if 2 <= A <= H-1:
            if 2 <= B <= W-1:
                f = 1
        if f == 1:
            d[(A,B)] += 1
s = 0
c = Counter(d.values())
for i in range(1,10):
    s += c[i]
c[0] = (H-2)*(W-2) - s
for i in range(10):
    print(c[i])

Measured memory_bytes: 166900
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>  // std::greater<T>()

using namespace std;

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define DESCEND greater<int>()  // sort 降順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから

// func declaration
template <class T> void printVec(vector<T>);


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

    int count = 0;
    REP(i, str.size()) {
        if (str.at(i) == '1') {
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

// function
template <class T> void printVec(vector<T> vec) {
    // 1要素ずつ、空白・改行なしで出力
    REP(i, vec.size()) {
        cout << vec.at(i);
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

    int A = 0;
    int B = 0;
    int C = 0;

    scanf("%d %d %d", &A, &B, &C);

    if (A == B && A != C){

        printf("Yes\n");

    } else if (A == C && A != B){

         printf("Yes\n");

    } else if (B == C && B != A){

        printf("Yes\n");

    } else {

        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
n = int(input())
sum = 0
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
for i in range(n):
    sum += b_list[a_list[i] - 1]
for i in range(n-1):
    if a_list[i+1] == a_list[i] + 1:
        sum += c_list[a_list[i]-1]
print(sum)



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

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))

#define INF 1000000000

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &b);

	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}

int lcm(int a, int b)
{
	return a*b/gcd(a, b);
}

void bubble_sort(int* p, int n)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n - i - 1; j++)
		{
			if (p[j] > p[j + 1])
				swap(&p[j], &p[j + 1]);
		}
	}
}

int array_max(int* p, int n)
{
	int max = 0;
	for (int i = 0; i < n; i++)
	{
		if (p[i] > max)
			max = p[i];
	}
	return max;
}

int binary_search(int* p, int key, int n)
{
	int low = 0, high = n - 1;
	int middle;

	while (low <= high)
	{
		middle = (low + high) / 2;

		//printf("low %d  middle %d  high %d\n", low, middle, high);

		//for (int i = 0; i < n; i++)
		//{
		//	if (i == middle)
		//		printf(" ^ ");
		//	else if (i == low)
		//		printf(" [ ");
		//	else if (i == high)
		//		printf(" ] ");
		//	else if (i == middle)
		//		printf(" ^ ");
		//	else
		//		printf("   ");
		//}
		//printf("\n");

		if (key == p[middle])
			return key;
		else if (key < p[middle])
			high = middle - 1;
		else if (key > p[middle])
			low = middle + 1;
	}

	//printf("low %d  middle %d  high %d\n", low, middle, high);
	return -1;
}

int main()
{
	int H, W;

	char a[100][100];
	int h[100] = { 0 }, w[100] = { 0 };

	scanf("%d%d", &H, &W);

	for (int i = 0; i < H; i++)
		scanf("%s", a[i]);

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (a[i][j] == '#')
			{
				h[i] = 1;
				w[j] = 1;
			}
		}
	}

	for (int i = 0; i < H; i++)
	{
		if (h[i] == 1)
		{
			for (int j = 0; j < W; j++)
			{
				if (w[j] == 1)
					printf("%c", a[i][j]);

			}
		}
			printf("\n");
	}


	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using ll = long long;
using namespace std;

int main() {
    int H,W; cin >> H >> W;

    for(int i=0;i<W+2;i++){
        cout << '#';
    }
    cout << endl;

    for(int i=0;i<H;i++){
        cout << '#';
         for(int j=0;j<W;j++){
            char in;
            cin>>in;
            cout<<in;
        }
        cout << '#' << endl;
    }

    for(int i=0;i<W+2;i++){
        cout << '#';
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
set<int>s;
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    int temp;
    for(int i=0;i<k;i++)
    {
        cin>>temp;
        s.insert(temp);
    }
    for(int j=n;j<=INT_MAX;j++)
    {
        int t=j;
        while(t)
        {
            if(s.count(t%10)==1)
            {
                break;
            }
            t=t/10;
        }
        if(t==0)
        {
            cout << j <<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, K;
ll S[1010];

void solve() {
	cin >> N >> K;
	rep(i, 0, N) {
		cin >> S[i + 1];
		S[i + 1] += S[i];
	}
	queue<ll> que;
	rep(i, 0, N) {
		rep(j, i + 1, N + 1) que.push(S[j] - S[i]);
	}
	ll res = 0;
	rer(i, 41, 0) {
		int cnt = 0;
		int n = sz(que);
		rep(q, 0, n) {
			ll v = que.front(); que.pop();
			if(v & (1ll << i)) cnt++;
			que.push(v);
		}
		if(cnt >= K) {
			res |= (1ll << i);
			rep(q, 0, n) {
				ll v = que.front(); que.pop();
				if(v & (1ll << i)) que.push(v);
			}
		}
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

int main(){
	int n,a[100],p[102] = {};
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		p[a[i]]++;
	}
	for(int i = 100;i >= 0;i--){
		p[i] += p[i + 1];
		if(p[i] >= i){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

template<typename ...Ts>
void show(Ts... ts){
  cout<<"#:";
  auto print=[](auto v){cout<<v<<" ";};
  initializer_list<int>{(void(print(ts)),0)...};
  cout<<endl;
}


vector<int> subv(vector<int> s,int n,int d){
    vector<int> rt;
    rep(i,d)rt.push_back(s[n+i]);
    return rt;
}

void solve(vector<int> a){
    int n=a.size()-2;
    int len=0;
    rep(i,n+1){
        len+=abs(a[i+1]-a[i]);
    }
    
    REP(i,1,n+1){
        int diff=abs(a[i+1]-a[i-1]) - ( abs(a[i]-a[i-1])+abs(a[i+1]-a[i]) );
        cout<<len+diff<<endl;
    }
    return;
}


int main(void){
    int n,ans=0;
    cin>>n;
    vector<int> t(n+2,0);
    rep(i,n)cin>>t[i+1];
    solve(t);
}

Measured memory_bytes: 2048
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(a, b) << " " << max(0, a + b - n) << endl;

  return 0;
}


Measured memory_bytes: 256
// 2014/07/17 Tazoe

#include <iostream>
using namespace std;

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

	int i = 1;

	do{
		int x = i;

		if( x % 3 == 0 ){
			cout << " " << i;
			continue;
		}

		do{
			if( x % 10 == 3 ){
				cout << " " << i;
				break;
			}
			x /= 10;
		}while( x );

	}while( ++i <= n );

	cout << endl;

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>  // This will work only for g++ compiler.

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) int((a).size())
#define mod 1000000007
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

void fast()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
bool isprime(ll x)
{
    for(int i=2;i<=sqrt(x);i++)
    {
        if(x%i==0) return false;
    }
return true;
}
void solve()
{
  ll a,b;
  cin >> a >> b;
  if(a>=13)cout << b << endl;
  else if(a>=6 && a<=12)cout << b/2 << endl;
  else cout << 0 <<endl;
}
int main()
{
  fast();
  solve();

return 0;
}


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

int main(){
	int n, a, b;
	while (true)
	{
		int point_a = 0, point_b = 0;
		cin >> n;
		if (cin.eof()||n==0) { break; }
		for(int i =0;i<n;i++){
			cin >> a >> b;
			if(a==b){
				point_a += a;
				point_b += b;
			}
			else if (a>b){
				point_a += a + b;
			}
			else {
				point_b += a + b;
			}
		}
		cout << point_a << " " << point_b << endl;
	}
}

Measured memory_bytes: 3004
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	ll r;
	r = b%a;
	if (r == 0)return a;
	else return gcd(r, a);

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
//MAX

bool func(ll p) {

	if (p == 1)return false;
	else if (p == 2)return true;
	else {

		bool flag = true;
		for (int i = 2; i <= sqrt(p); i++) {

			if (p%i == 0) {

				flag = false;
				break;

			}

		}
		return flag;

	}

}
//素数判定,素数=true,合成数=false

int main() {

	ll X, Y, ans = 0;
	cin >> X >> Y;

	while (1) {

		if (X <= Y)ans++;
		else break;
		X *= 2;

	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main()
{
    char s;
    int sum = 0;

    for(int i=0; i<5; i++)
    {
        scanf("%c", &s);
        if(s == '+')
            sum++;
        else if(s == '-')
            sum--;
    }
    printf("%d\n", sum);

    return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String strArray[] = br.readLine().split(" ");
	int A, B, C, result;
	A = Integer.parseInt(strArray[0]);
	B = Integer.parseInt(strArray[1]);
	C = Integer.parseInt(strArray[2]);
	result = C - (A - B);
	System.out.println(result >= 0 ? result : 0);

    }
}

Measured memory_bytes: 21072
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)
struct UnionFind { vector<int> d; UnionFind(int n=0): d(n,-1) {} int find(int x) { if (d[x] < 0) return x; return d[x] = find(d[x]); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (d[x] > d[y]) swap(x,y); d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return find(x) == find(y);} int size(int x) { return -d[find(x)];} };
long long INF = 1LL<<60;
int main( ){
    ll N,M;
    cin>>N>>M;
    UnionFind UnionFind(N);
    vi p;
    rep(i,0,N){
        int v;
        cin>>v;
        v--;
        p.push_back(v);
    }
    rep(i,0,M){
        int x,y;
        cin>>x>>y;
        x--,y--;
        UnionFind.unite(x,y);
    }
    int ans=0;
    rep(i,0,N){
        if(p[i]==i||UnionFind.same(p[i],i))ans++;
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 1276
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long

typedef tree< pair<int,int>, null_type, less< pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update>Order_Set;

Order_Set X;

const int mxn = 1e7+100;
const int Mod = 1e9+7;

int arr[mxn], qs[mxn];
int bitOn[55];
map<int,int>Mp, cnt, op;
vector< pair<int, pair<int,int> > >Pi, Ans;
vector<int>G[mxn];
set<int>seet[mxn];

int main()
{
     ios::sync_with_stdio(false);

     int n;
     cin>>n;
     int k = n-1, ct = 1, Ans = 0;
     for(int i=1 ; i<=n ; i++){
        int x;
        cin>>x;
        if(x == ct) ct++, Ans++;
     }

     if(k < (n-Ans)) cout<<-1<<endl;
     else cout<<n-Ans<<endl;

     return 0;
}




Measured memory_bytes: 704896
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define itn int
#define mod 1000000007
#define INFi 2147483647
#define INFl 9223372036854775807LL
#define fi first
#define se second
#define be begin()
#define en end()
#define re reverse
int abs(int a,int b){
    return max(a,b)-min(a,b);
}
int a,b[1000000];
int c[1000000];
itn q,w=0;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>a;
    for(int i=0;i<a;i++){
      cin>>b[i];
    }
    for(int i=0;i<a;i++){
      if(b[0]!=1){
	if(i==0) q=b[0];
	if(b[i]<=q){
	  q=min(q,b[i]);
	  w++;
	}
      }
      else{
	w=1;
	break;
      }
    }
    cout<<w<<"\n";
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC139D
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long ans = (N - 1) * N / 2;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27504
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
set<int> st;
int main()
{
	int a[3];
	for (int i = 0; i < 3; i++)
		cin >> a[i];
	for (int i = 0; i < 3; i++)
	{
		st.insert(a[i]);
	}
	if (st.size() == 2)cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int R, G, B, N;
	cin >> R >> G >> B >> N;

	int ans = 0;
	eREP(i, 3000) {
		eREP(j, 3000) {
			int cnt = R * i + G * j;
			if ((N - cnt) % B == 0 && N-cnt>=0)ans++;
		}
	}

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



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <assert.h>
    
using namespace std;
  
const int LIMIT = 1000000000;
  
struct Data {
  int id;
  int st;
  int num;
  Data(int id, int st, int num) : id(id), st(st), num(num) {}
  bool operator<(const Data& rhs) const { return st<rhs.st; }
};
    
int N;
vector<Data> storage;
   
void dump() {
  cout << "-----------------------------" << endl;
  for(int i=0; i<(int)storage.size(); i++) {
    cout << "storage["<<i<<"]:" << endl;
    cout << "id: " << storage[i].id << " st: " << storage[i].st << " num: " << storage[i].num << endl;
  }
  cout << "-----------------------------" << endl;
}
  
void write(const int id, int remain) {
  int st = 0;
  while(remain > 0) {
    int num = -1;
    int into = -1;

    for(int i=0; i<(int)storage.size(); i++) {
      if(st < storage[i].st) {
        num = min(remain, storage[i].st - st);
        into = i;
        break;
      }
      else if(st < storage[i].st+storage[i].num) {
        st = st+storage[i].num;
      }
        
      if(st > LIMIT) return;
    }
    
    if(num == -1) {
      // insert data back
      num = remain;
      into = storage.size();
    }
    storage.insert(storage.begin()+into, Data(id, st, num));
    remain -= num;
    assert(remain>=0);
  }
}
  
class EqualsID {
private:
  int id;
public:
  EqualsID(int id) : id(id) {}
  bool operator() (const Data &d) { return d.id == id; }
};
void del(int id) {
  storage.erase(remove_if(storage.begin(), storage.end(), EqualsID(id)), storage.end());
}

int refer(int sect) {
  for(int i=0; i<(int)storage.size(); i++) {
    if(storage[i].st<=sect && sect<storage[i].st+storage[i].num) {
      return storage[i].id;
    }
  }
  return -1;
}
    
int main() {
  while(scanf("%d", &N) && N) {
    storage.clear();
    for(int i=0; i<N; i++) {
      char ch; cin >> ch; //scanf("%c", &ch);
      if(ch=='W') {
        int id, num; scanf("%d%d", &id, &num);
        write(id, num);
        //dump();
      }
      if(ch=='D') {
        int id; scanf("%d", &id);
        del(id);
      }
      if(ch=='R') {
        int sect; scanf("%d", &sect);
        printf("%d\n", refer(sect));
      }
    }
    puts("");
  }
  return 0;
}

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

using namespace std;

#define min(a, b) ((a) < (b)? (a):(b))
#define max(a, b) ((a) > (b)? (a):(b))
#define rep(i, n) REP((i), 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)

bool isp[1000000];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1) {
        int a, d, n; cin >> a >> d >> n;
        if(a == 0 && d == 0 && n == 0) break;

        // eratosthenes
        int N = 1000010;
        memset(isp, true, N);
        isp[1] = false;
        REP(i, 2, sqrt(N)) {
            if(isp[i]) {
                for(int j=0; i*(j+2)<N; j++) {
                    isp[i*(j+2)] = false;
                }
            }
        }
        
        int cnt = 0;
        for(int i=0; ; i++) {
            if(isp[a+i*d]) cnt++;
            if(cnt == n) {
                cout << a+i*d << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 4140
/*@shutoshsuman99*/
#include<bits/stdc++.h>
using namespace std;
#include<cstdio>
#define pi 3.141592653589
#define pb push_back
#define ld long double
#define rem 1000000007
#define rem1 998244353
#define inf 1e18+1e17
#define F first
#define S second
#define pii pair<long long,long long>
#define p_q priority_queue <ll, vector<ll>, greater<ll> >
#define m_sp multiset <pair <ll,ll> > 
#define el "\n"
#define sp " "
typedef long long ll;
ll Pow(ll x,ll y,ll m) 
{ if (y == 0) return 1; ll p = Pow(x, y/2, m) % m; 
p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m; } 
main()
{ 
	// fast io
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);ll i; 
	ll n,m;
	cin>>n>>m;
	ll l1=1,r1=n;
	for(i=0;i<m;i++)
	{
		ll l,r;
		cin>>l>>r;
		l1=max(l1,l);
		r1=min(r1,r);
	}
	if(r1<l1)
	cout<<0<<el;
	else
	cout<<r1-l1+1<<el;
}

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

int main() {
	int A[3];
	int i;
	for(i=0; i!=3; i++) cin >> A[i];
	int M=0;
	for(i=1; i!=3; i++) if(A[M]<A[i]) M=i;
	int S=0;
	for(i=0; i!=3; i++)
	{
		if(i==M) S=S+10*A[i];
		else S=S+A[i];
	}
	cout << S << endl;
	return 0;
} 

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

string in;
int tot[55][55];

int main()
{
	int n;
	scanf("%d",&n);
	string ans = "";
	for(int a=0;a<n;a++)
	{
		cin>>in;
		int len = in.length();
		for(int b=0;b<len;b++)
		tot[a][in[b]-'a']++;
	}
	for(int a=0;a<26;a++)
	{
		int maxi;
		for(int b=0;b<n;b++)
		{
			if(b==0) maxi = tot[b][a];
			maxi = min(maxi,tot[b][a]);
		}
		for(int b=0;b<maxi;b++) ans+=(a+'a');
	}
	cout<<ans<<endl;
	
	
}

Measured memory_bytes: 256
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

function mul(){for(var a=arguments,r=a[0],i=a.length;--i;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i])%mod;return r;}
var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var x = next();
  var ans = x / 500 | 0;
  x -= ans * 500;
  ans *= 1000;
  ans += (x/5|0) * 5;
  return ans;
}

Measured memory_bytes: 21064