akhauriyash/Code-Regression huggingface dataset:
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL A,B;

LL ans = 0;

void solve(){
	ans = A*B;
}

int main(){
    cin >> A >> B;

    solve();
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3164
require 'prime'
N=gets.to_i
MOD=10**9+7
PRIMES = {}
(2..N).each do |i|
    Prime.prime_division(i).each do |n, e|
        PRIMES[n] ||= 0
        PRIMES[n] += e
    end
end
ret = 1
PRIMES.each do |k,v|
    ret *= (v+1)
    ret %= MOD
end
puts ret


Measured memory_bytes: 14484
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=input()
Q=[input().rsplit() for _ in range(q)]
l,r=-1,n
while r-l>1:
	c=m=(l+r)//2
	for t,d in Q:
		if s[c]==t:
			c+= 1 if d=="R" else -1
			if c==-1 or c==n:
				break
	if c==-1:l=m
	else:r=m
a=l
l,r=-1,n
while r-l>1:
	c=m=(l+r)//2
	for t,d in Q:
		if s[c]==t:
			c+= 1 if d=="R" else -1
			if c==-1 or c==n:
				break
	if c==n:r=m
	else:l=m
b=r
print(0 if b<=a else b-a-1)

Measured memory_bytes: 80564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;


int main(){
    ll N , M; cin >> N >> M;
    ll ans;
    if(N == 1 || M == 1){
        if(N == 1 && M == 1) ans = 1;
        else if(N == 1) ans = M-2;
        else ans = N-2;
        cout << ans << endl;
        return 0;
    }
    ans = (N-2) * (M-2);
    cout << ans << endl;
    


}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;

int main()
{
    fastio;
    ll n=0,k=0;
    cin>>n>>k;
    ll ans=log(n)/log(k)+1;
    cout<<ans;
}

Measured memory_bytes: 256
function main(input){
    var line1 = input[0];
    var win = 0;
    for(var i = 0; i<line1.length; i++) {
        if (line1[i] === 'o') {
            win++;
        }
    }
    if (win + 15 - line1.length >= 8) {
        console.log('YES');
    } else {
        console.log('NO');
    }
}


function parse(line){
  var ret = [];
  var arr = line.split(' ');
  for (var i = 0; i < arr.length; i++) {
    ret.push(parseInt(arr[i]));
  }
  return ret;
}

var input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main(input);
});


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

int main()
{
  long long  A,V,B,W,T;
  
  cin >> A >> V >> B >> W >> T;
    
  long long dis, rv;
  
  dis = abs(B-A);
  rv = V-W;
  
  if(rv < 1) 
  { // muri 
    cout << "NO" << endl;
    return 0;      
  }
  else  // rv=>1
  {
    if( rv*T < dis )
    {
    cout << "NO" << endl;
    return 0;      
      
    }else{
    cout << "YES" << endl;
    return 0;      
      
    }  
  }
  
  
 
  
  return 0;  
}

Measured memory_bytes: 3620
import Data.List
import Data.Maybe
import Control.Monad
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  [n,k] <- map read.words <$> getLine
  hs <- V.fromList . sort <$> (replicateM n $ (readLn :: IO Int))
  print $ minimum [ (hs V.! (i+k-1)) - (hs V.! i) | i <- [0..n-k]]

Measured memory_bytes: 65916
import numpy as np
from itertools import groupby

N = int(input())
T = np.array(['0'] + input().split() + ['10000000000'], np.int64)
A = np.array(['10000000000'] + input().split() + ['0'], np.int64)
mod = 10 ** 9 + 7

t = (T[1:] != T[:-1]) * T[1:]
a = (A[1:] != A[:-1]) * A[:-1]
t = t[:-1]
a = a[1:]
seq = np.zeros(N, np.int64)

flag = True
tmp = np.where((t != 0) & (a != 0))[0]
if np.any(t[tmp] != a[tmp]):
    flag = False
seq = np.maximum(t, a)
if np.any(seq > T[1:-1]) or np.any(seq > A[1:-1]):
    flag = False

if flag:
    group = [(i, len(list(j))) for i, j in groupby(seq.tolist())]
    answer = 1
    for i in range(len(group)):
        if group[i][0] == 0:
            answer *= pow(min(group[i - 1][0], group[i + 1][0]), group[i][1], mod)
            answer %= mod
    print(answer)
else:
    print(0)


Measured memory_bytes: 27832
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input!(s: chars);
    let mut a = 0;
    for i in 0..4 {
        if s[i] == '+' {
            a += 1
        } else {
            a -= 1
        }
    }
    puts!("{}\n", a);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//CODE
void solve(void)
{
  int N,M,X;
  cin>>N>>M>>X;
  vector<int> vec(N+1,0);
  for (int i = 0; i < M; i++)
  {
    int A;
    cin>>A;
    vec[A]++;
  }
  for (int i = 0; i < N; i++)
  {
    vec[i+1] += vec[i];
  }
  cout<<min(vec[X],vec[N]-vec[X])<<endl;
  
  
  
  

  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>

int compare_int(const void *a, const void *b);

int main(void)
{
    int N,K,i,j;
    int A[2000];
    long long int count=0;
    long long int count2=0;
    
    scanf("%d %d",&N, &K);
    
    for(i=0; i<N; i++){
        scanf("%d",&A[i]);
    }
    
    for(i=0; i<N; i++){
        for(j=i; j<N; j++){
            if(A[i] > A[j]){
               // printf("A[%d] > A[%d]\n",i,j);
                count++;
                //printf("count = %lld\n",count);
            }
        }
    }
    
    qsort(A, N, sizeof(int), compare_int);
    
    for(i=0; i<N; i++){
        for(j=0; j<N; j++){
            if(A[i] > A[j]){
                //printf("A[%d] > A[%d]\n",i,j);
                count2++;
                //printf("count2 = %lld\n",count2);
            }
        }
    }
    
    
    if(K%2 == 0){
        count= count*K%1000000007 + ((K-1)*count2%1000000007)*(K/2)%1000000007;
    } else {
        count= count*K%1000000007 + (K*( (((K-1)/2)*count2)%1000000007 ))%1000000007;
    }
    
    if(count >= 1000000007){
        count%=1000000007;
    }
        //printf("count = %lld\n",count);
    
    printf("%lld\n",count);
}

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


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

int main(){
  int a; cin >>a;
  for(int i=a; i<=200000; i++)
  {
    bool x=1;
    for(int j=2; j<=sqrt(a); j++)
    {
      if(i%j==0){x=0; break;}
    }
    if(x){a=i; break;}
  }

  cout <<a;

return 0;
}

Measured memory_bytes: 256
/*
       Hi there <3 
──────▄▀▄─────▄▀▄
─────▄█░░▀▀▀▀▀░░█▄
─▄▄──█░░░░░░░░░░░█──▄▄
█▄▄█─█░░▀░░┬░░▀░░█─█▄▄█

*/
#include <bits/stdc++.h>
#define MOD 1000000007
#define re return
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repa(i,a,n) for(int i=a;i<n;i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrepa(i,a,n) for (int i = n; i >= a; i--)
#define fill(x, y) memset(x, y, sizeof(x))
#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(abs(x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define ba back()
#define popcount __builtin_popcountll
#define fastIO()                 \
    {                            \
        ios::sync_with_stdio(0); \
        cin.tie(0);              \
        cout.tie(0);             \
    }
#define in(x) \
    int x;    \
    cin >> x;
#define in1(x) \
    int x;     \
    cin >> x;  \
    x--;
#define inll(x) \
    ll x;       \
    cin >> x;
#define ins(x) \
    string x;  \
    cin >> x;

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef pair<double, double> pdd;
typedef long double LD;
typedef double D;

void Solve()
{
    ll n;
    cin>>n;
    string ans;
    ll rem=0;
    while(n>0)
    {
        rem=n%26;
        ll  k=n/26;

        if(rem==0)
        {
            k--;
            ans=(char)('z')+ans;
        }
        else
        {
            ans=(char)('a'+rem-1) + ans;
        }
        n=k;
    }
    
    cout<<ans<<endl;
}

int main()
{
    fastIO();
    int t;
    t=1;
    while (t--)
    {
        Solve();
    }
    return 0;
}

Measured memory_bytes: 3616
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    
    for(int i=0; i<5; i++){
      int x;
      x = sc.nextInt();

      if(x == 0){
        System.out.println(i+1);
        break;
      }
    }
    return;
  }
}

Measured memory_bytes: 35788
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
ilelec = lambda: map(int1,input().split())
alelec = lambda: list(map(int1, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])

a,b,c,d = ilele()
print(max(a*c,a*d,b*c,b*d))

Measured memory_bytes: 65532
from collections import deque

def calc(seq):
  score = 0
  for a, b, c, d in req:
    if seq[b - 1] - seq[a - 1] == c:
      score += d
  return score

n, m, q = map(int, input().split())
req = [list(map(int, input().split())) for _ in range(q)]

ans = 0
que = deque()
for i in range(1, m + 1):
  que.append([i])
  
while que:
  seq = que.popleft()
  
  if len(seq) == n:
    score = calc(seq)
    ans = max(ans, score)
  else:
    for i in range(seq[-1], m + 1):
      seq_next = seq + [i]
      que.append(seq_next)
      
print(ans)

Measured memory_bytes: 23068
import sys
from queue import deque

sys.setrecursionlimit(200000)


def hierarchize(source):
    global hierarchy
    hierarchy = [-1] * n
    queue = deque([(0, source)])
    while queue:
        h, v = queue.popleft()
        if hierarchy[v] != -1:
            continue
        hierarchy[v] = h
        if v == sink:
            return True
        queue.extend((h + 1, target)
                     for remain, target, _ in edges[v] if hierarchy[target] == -1 and remain)
    return False


def augment(v, limit):
    if v == sink:
        return limit
    res = 0
    for e in edges[v]:
        remain, target, idx = e
        if remain == 0 or hierarchy[v] >= hierarchy[target]:
            continue
        aug = augment(target, min(limit, remain))
        e[0] -= aug
        edges[target][idx][0] += aug
        res += aug
        limit -= aug
        if not limit:
            break
    return res


xn, yn, e = map(int, input().split())
n = xn + yn + 2
sink = n - 1
edges = [[] for _ in range(n)]

hierarchy = [-1] * n

for x in range(xn):
    xi = x + 1
    edges[0].append([1, xi, 0])
    edges[xi].append([0, 0, x])
for y in range(yn):
    yi = xn + y + 1
    edges[yi].append([1, sink, y])
    edges[sink].append([0, yi, 0])

for _ in range(e):
    x, y = map(int, input().split())
    xi, yi = x + 1, xn + y + 1
    ex, ey = edges[xi], edges[yi]
    lx, ly = len(ex), len(ey)
    ex.append([1, yi, ly])
    ey.append([0, xi, lx])

res = 0
while hierarchize(0):
    res += augment(0, 100)
print(res)

Measured memory_bytes: 11296
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n, m;
  cin >> n >> m;
  vector< vector< int > > s(m);
  vector< int > p(m);
  for (int i=0; i<m; ++i) {
    int k;
    cin >> k;
    for (int j=0; j<k; ++j) {
      int si;
      cin >> si;
      si--;
      s[i].push_back(si);
    }
    sort(s[i].begin(), s[i].end());
  }

  for (int i=0; i<m; ++i) cin >> p[i];
  ul b = 1;
  for (int i=0; i<n; ++i) b *= 2;
  int ans = 0;
  for (int i=0; i<b; ++i) {
    ul j=1;
    vector< int > on(n);
    int k=0;
    while (j < b) {
      if (i&j) on[k] = 1;
      else on[k] = 0;
      k++;
      j*=2;
    }
    bool flg = true;
    for (int x=0; x<m; ++x) {
      int ison = 0;
      for (int y=0; y<s[x].size(); ++y) {
        if (on[s[x][y]] == 1) ison++;
      }
      if (ison%2!=p[x]) {
        flg = false;
        break;
      }
    }
    if (flg) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
INF = 10 ** 20

dp = [{} for i in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    for j in range(max((i + 1) // 2 - 4, 0), (i + 1) // 2 + 3):
        dp[i + 1][j + 1] = -INF
        if j in dp[max(0, i - 1)]:
            dp[i + 1][j + 1] = max(dp[max(0, i - 1)][j] + a[i], dp[i + 1][j + 1])
        if j in dp[max(0, i - 2)]:
            dp[i + 1][j + 1] = max(dp[max(0, i - 2)][j] + a[i], dp[i + 1][j + 1])
        if j in dp[max(0, i - 3)]:
            dp[i + 1][j + 1] = max(dp[max(0, i - 3)][j] + a[i], dp[i + 1][j + 1])
            
ans = -INF
for i in range(n + 1):
    if n // 2 in dp[i]:
        ans = max(ans, dp[i][n // 2])
print(ans)

Measured memory_bytes: 197884
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# Nと空白区切の入力値を数値の配列で返却する
def gets_n_and_i_list()
  return gets.chomp.to_i, gets.chomp.split(" ").map(&:to_i)
end
N, a_list = gets_n_and_i_list

a_list.sort!

def xxx(arr)
  loop do
    return arr[0] if arr.length == 1
    arr = arr.each_slice(2).map { |a, b| b ? a * b : a }
  end
end

total = xxx(a_list)

if total > 10**18
  puts -1
else
  puts total
end

Measured memory_bytes: 45120
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
using namespace std;
typedef long long int ll;
typedef pair<int,int>P;
int main(){
  int n,u,v;
  cin>>n>>u>>v;
  vector<int>uod[n+1];
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        uod[a].push_back(b);
        uod[b].push_back(a);
    }
    int rit[n+1];
    for(int i=0;i<=n;i++){
        rit[i]=-1;
    }
    rit[v]=0;
    queue<int>que;
    que.push(v);
    while(!que.empty()){
        int no=que.front();que.pop();
        for(int i=0;i<uod[no].size();i++){
            if(rit[uod[no][i]]==-1){
                que.push(uod[no][i]);
                rit[uod[no][i]]=rit[no]+1;
            }
        }
    }
    queue<P>pq;
    pq.push(MP(u,0));
    int ans=0;
    while(!pq.empty()){
        P now=pq.front();pq.pop();
        int nv=now.F;
        int cos=now.S;
        ans=max(rit[nv],ans);
        rit[nv]=-1;
        for(int i=0;i<uod[nv].size();i++){
            if(rit[uod[nv][i]]!=-1&&rit[uod[nv][i]]>=cos+1){
                pq.push(MP(uod[nv][i],cos+1));
            }
        }
    }
    cout<<ans-1<<endl;
    return(0);
}

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

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

  int red = 0, blue = 0;

  rep(i, s.size()) {
    if (s[i] == '0') {
      red++;
    } else {
      blue++;
    }
  }

  int ans = min(red, blue) * 2;

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

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline int readint() {
	char c = getchar(); int w = 1; int x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
	x *= w;
	return x;
}
inline ll readll() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
	x *= w;
	return x;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};

int main(){
    ll n,h,k;
    cin>>n>>h>>k;
    if(n%h!=0){
        cout<<(n/h+1)*k<<endl;
        return 0;
    }
    else{
        cout<<(n/h)*k<<endl;
        return 0;
    }
}
/* stuff to remember
	* int overflow, array bounds
	* special cases (n=1? n=0?)
	* do something instead of nothing and stay organized
	* USE STATIC ARRAYS
	* DEFINING ARRAYS BEFORE main()
	* DO NOT DEFINE ARRAYS IN main()
	* USE INT INSTEAD OF LL,NOTICE THE MLE
*/

Measured memory_bytes: 3680
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,c = li()
d = [list(li()) for _ in range(c)]
initial = [list(li_()) for _ in range(n)] 

mod_col = [[0]*c for _ in range(3)]

for i,initi in enumerate(initial):
    for j, initij in enumerate(initi):
        mod_col[(i+j) % 3][initij] += 1
        
ans = float('inf')
colors = [-1]*3
for c0 in range(c):
    for c1 in range(c):
        for c2 in range(c):
            if c0 == c1 or c1 == c2 or c2 == c0:
                continue
            
            colors = [c0, c1, c2]
            
            tmp = 0
            for modnum in range(3):
                tmp += sum([d[color][colors[modnum]] * mod_col[modnum][color] for color in range(c)])
                
            ans = min(ans, tmp)


print(ans)

Measured memory_bytes: 5620
N, M = [int(v) for v in input().split()]
tbl = [[0] * (N + 1) for _ in range(N+1)]
for _ in range(M):
    a, b = [int(v) for v in input().split()]
    tbl[a][b] = 1
    tbl[b][a] = 1

ans = 0
paths = [[1, ]]
while paths:
    p = paths.pop()

    for i in range(1, N + 1):
        if p[-1] == i: continue
        if tbl[p[-1]][i] and i not in p:
            np = p + [i]
            if len(np) == N:
                ans += 1
            paths.append(np)
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)


//suffix arrayのO(NlogN)構築
//p[i]=辞書順i番目のsuffixは何文字目から始まるものか
//*
int*makeSA(char*s,int len){
	len++;
	int*SAidx=(int*)calloc(len,sizeof(int));
	int*ord=(int*)calloc(len,sizeof(int));
	//1文字目
	int cnt1[256]={},cnt2[256]={};
	for(int i=0;i<len;i++)cnt1[s[i]+1]++,cnt2[s[i]+1]|=1;
	for(int i=1;i<256;i++)cnt1[i]+=cnt1[i-1],cnt2[i]+=cnt2[i-1];
	for(int i=0;i<len;i++)SAidx[cnt1[s[i]]++]=i,ord[i]=cnt2[s[i]];
	
	int*cnt=(int*)calloc(len+1,sizeof(int));
	int*idx2=(int*)calloc(len,sizeof(int));
	int*temp=(int*)calloc(len,sizeof(int));
	for(int k=1;k<len;k*=2){
		//2*k文字まで見る
		for(int i=0;i<len;i++)cnt[i]=0;
		for(int i=0;i<len;i++)cnt[ord[i]+1]++;
		for(int i=1;i<len;i++)cnt[i]+=cnt[i-1];
		for(int i=0;i<len;i++)idx2[cnt[ord[(SAidx[i]-k+len)%len]]++]=(SAidx[i]-k+len)%len;
		temp[idx2[0]]=0;
		for(int i=1;i<len;i++)temp[idx2[i]]=temp[idx2[i-1]]+(ord[idx2[i-1]]!=ord[idx2[i]]||ord[(idx2[i-1]+k)%len]!=ord[(idx2[i]+k)%len]);
		for(int i=0;i<len;i++)ord[i]=temp[i],SAidx[i]=idx2[i];
	}
	free(temp);
	free(idx2);
	free(cnt);
	free(ord);
	return SAidx+1;
}
//*/

//SAを使ってlongest common prefix arrayをO(N)構築
//p[i]=s[SA[i-1]:n]とs[SA[i]:n]のLCP
//*
int*makeLCPA(char*s,int len,int*SA){
	int*SAr=(int*)calloc(len,sizeof(int));
	int*LCPA=(int*)calloc(len,sizeof(int));
	for(int i=0;i<len;i++)SAr[SA[i]]=i;
	int cnt=0;
	for(int i=0;i<len;i++){
		if(SAr[i])while(s[SA[SAr[i]-1]+cnt]==s[i+cnt])cnt++;
		else cnt=0;
		LCPA[SAr[i]]=cnt;
		if(cnt)cnt--;
	}
	free(SAr);
	return LCPA;
}
//*/


char s[500010];

int main(){
	scanf("%s",s);
	int n=strlen(s);
	int*SA=makeSA(s,n);
	int*LCPA=makeLCPA(s,n,SA);
	ll ans=n*(n+1LL)/2;
	rep(i,1,n)ans-=LCPA[i];
	printf("%lld\n",ans);
}

Measured memory_bytes: 11488
import numpy as np
N=int(input())
P=200003
a=[int(i) for i in input().split()]
b=[0 for i in range(P)]
for i in range(N):
    b[a[i]]+=1
M=1<<19
c=np.zeros(M)
for i in range(P-1):
    c[i]=b[pow(2,i,P)]
X=[int(i+0.1) for i in np.real(np.fft.ifft(np.fft.fft(c)*np.fft.fft(c)))]
ans=0
for k in range(M):
    ans+=X[k]*pow(2,k,P)
for i in range(N):
    ans-=(a[i]*a[i])%P
print(ans//2)

Measured memory_bytes: 72552
#include <iostream>
#include <vector>
using namespace std;
vector<pair<pair<int,int>,int> > e;
int main()
{
	int l,p=0;
	scanf("%d",&l);
	while ((1<<p)<=l)
	p++;
	int cur=(1<<(p-1));
	for (int i=1;i<p;i++)
	{
		e.push_back({{i,i+1},0});
		e.push_back({{i,i+1},(1<<(i-1))});
	}
	for (int i=p-1;i>0;i--)
	{
		if (cur+(1<<(i-1))<=l)
		{
			e.push_back({{i,p},cur});
			cur+=(1<<(i-1));
		}
	}
	printf("%d %d\n",p,e.size());
	for (auto p:e)
	printf("%d %d %d\n",p.first.first,p.first.second,p.second);
}

Measured memory_bytes: 256
nums = gets.split(" ").map(&:to_i)
x = nums[0]
y = nums[1]

prize = 0

if x == 1 && y == 1
  prize += 400000
end

if x == 3 
  prize += 100000
elsif x == 2
  prize += 200000
elsif x == 1
  prize += 300000
end

if y == 3
  prize += 100000
elsif y == 2
  prize += 200000
elsif y == 1
  prize += 300000
end
puts prize

Measured memory_bytes: 3836
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

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

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	string s;
	cin >> s;
	int ans = 700;
	REP(i, 3) {
		if (s[i] == 'o') ans += 100;
	}
	cout << ans;
	system("pause");
	return 0;
}

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

void fnInsertionSort(vector<int> &argviSort, int argiGap, int &argiSortCnt)
{
  for (int ixSorting = argiGap; ixSorting < argviSort.size() ; ixSorting++)
  {
    int iTarget = argviSort[ixSorting];
    int ixSorted = ixSorting - argiGap;

    while (ixSorted >= 0              &&
           iTarget < argviSort[ixSorted])
    {
      argviSort[ixSorted + argiGap] = argviSort[ixSorted];
      ixSorted -= argiGap;

      argiSortCnt++;
    }
    argviSort[ixSorted + argiGap] = iTarget;
  }
}

void fnShellSort(vector<int> &argviSort, vector<int> &argviGap, int &argiSortCnt)
{
  for (int iGap = 1; iGap <= argviSort.size(); iGap = 3 * iGap + 1)
    argviGap.push_back(iGap);
  
  for (int i = argviGap.size() - 1; i >= 0; i--)
    fnInsertionSort(argviSort, argviGap[i], argiSortCnt);
}

void fnOutput(const vector<int> &argviSort, const vector<int> &argviGap, int argiSortCnt)
{
  cout << argviGap.size() << endl;

  for (int i = argviGap.size() - 1; i >= 0; i--)
  {
    if (i != argviGap.size() - 1) cout << " ";
    cout << argviGap[i];
  }
  cout << endl;

  cout << argiSortCnt << endl;

  for (int i = 0; i < argviSort.size(); i++)
    cout << argviSort[i] << endl;
}

int main()
{
  vector<int> viSort;
  vector<int> viGap;
  int iSortCnt = 0;
  int iMaxSize;
  
  cin >> iMaxSize;
  for (int i = 0; i < iMaxSize; i++)
  {
    int iNum;
    cin >> iNum;
    viSort.push_back(iNum);
  }

  fnShellSort(viSort, viGap, iSortCnt);
  fnOutput(viSort, viGap, iSortCnt);

  return 0;
}

Measured memory_bytes: 6464
N, M, R = gets.split.map(&:to_i)
rs = gets.split.map(&:to_i)
as, bs, cs = [], [], []
M.times do |i|
    as[i], bs[i], cs[i] = gets.split.map(&:to_i)
end

dist = Array.new(N){Array.new(N, Float::INFINITY)}
N.times {|i| dist[i][i] = 0}
M.times do |m|
    dist[as[m]-1][bs[m]-1] = cs[m]
    dist[bs[m]-1][as[m]-1] = cs[m]
end

N.times do |k|
    N.times do |i|
        N.times do |j|
            nd = dist[i][k] + dist[k][j]
            dist[i][j] = nd if dist[i][j] > nd
        end
    end
end

dp = Array.new(1<<R){Array.new(R, Float::INFINITY)}
R.times do |r|
    dp[(1<<R) - 1][r] = 0
end

((1<<R) - 2).downto(0) do |s|
    R.times do |r1|
        next if (s >> r1) & 1 == 1
        v1 = rs[r1] - 1
        R.times do |r2|
            v2 = rs[r2] - 1
            nd = dp[s|(1<<r1)][r1] + dist[v1][v2]
            dp[s][r2] = nd if dp[s][r2] > nd
        end
    end
end

puts R.times.map{|r|dp[1<<r][r]}.min

Measured memory_bytes: 2684
# Problem C - Train Ticket ビット全探索の問題

# input process
Num = input()
ABCD = [Num[0], Num[1], Num[2], Num[3]]

# initialization
opt_list = []
for i in range(8):
    opt = [0, 0, 0]
    for j in range(3):
        if ((i>>j)&1):
            opt[3-j-1] = 1
    opt_list.append(opt)

# bit search start
for opt in opt_list:
    math_formula = ""
    for i in range(3):
        if opt[i]==1:
            math_formula += ABCD[i] + "+"
        else:
            math_formula += ABCD[i] + "-"
    math_formula += ABCD[3]
    if eval(math_formula)==7:
        print(math_formula+"=7")
        break


Measured memory_bytes: 38256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<(x)<<endl
#define fi first
#define se second

#define INF 2147483600
#define EPS 1e-8

// ???????°???°???????????????
inline double add(double a, double b){
  if(abs(a+b) < EPS*(abs(a) + abs(b))) return 0;
  return a+b;
}

struct Point{
  double x,y;
  Point() {}
  Point(double nx, double ny) : x(nx), y(ny) {}
  Point operator + (const Point & p){ return Point(add(x, p.x), add(y, p.y)); }
  Point operator - (const Point & p){ return Point(add(x,-p.x), add(y,-p.y)); }
  Point operator * (double d){ return Point(x*d, y*d); }
  double dot(const Point & p){ return add(x * p.x, y*p.y); }  //??????
  double det(const Point & p){ return add(x * p.y, -y*p.x); } //??????
  double dist(const Point & p){ return sqrt((x-p.x)*(x-p.x) + (y-p.y)*(y-p.y)); }
  bool operator < (const Point & p) const {
    if(y != p.y) return y < p.y;
    else return x < p.x;
/*
    if(x != p.x) return x < p.x;
    else return y < p.y;
    */
  }
};

// Graham Scan
// ???????????????????¨?????????§return
// ???????????????????????????
vector<Point> convexHull(vector<Point> points){
  int n = points.size();
  sort(all(points));
  int k=0;
  vector<Point> qs(n+1);
  for(int i=0; i<n; qs[k++] = points[i++]){
    while(k>1 && (qs[k-1] - qs[k-2]).det(points[i] - qs[k-1]) < 0) k--;
  }
  for(int i=n-2,t=k; i>=0; qs[k++] = points[i--]){
    while(k>t && (qs[k-1] -qs[k-2]).det(points[i] - qs[k-1]) < 0) k--;
  }
  qs.resize(k-1);
  return qs;
}

int main(){
  int n;
  cin>>n;
  vector<Point> vec(n);
  rep(i,n){
    double x, y;
    scanf("%lf %lf", &x, &y);
    vec[i] = Point(x,y);
  }
  vector<Point> conv = convexHull(vec);

  printf("%d\n", conv.size());
  rep(i,conv.size()){
    printf("%.0f %.0f\n", conv[i].x, conv[i].y);
  }

  return 0;
}

Measured memory_bytes: 7596
import itertools

N = int(input())

listing=[]

for i in range(2):
    try:
        listing.append(tuple(map(lambda x: x-1, map(int, input().split()))))
        #listA<-[1,2,2,3,1]
        #print(listA)
        #ここに逐次処理を書けばいいと思う。
    except:
        break;
        #または、quit(),os.exit()をして止める。

p_list = list(itertools.permutations([i for i in range(N)]))

count=0

for i in p_list:
    if i == listing[0]:
        a=count
    if i == listing[1]:
        b=count
    count+=1


print(abs(a-b))

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
  cin >> v.at(i);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int k;
    cin >> k;
    auto itr = lower_bound(v.begin(), v.end(), k);
    cout << itr - v.begin() << endl;
  }
}


Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    String s = input.nextLine();

    String[] d = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };

    for (int i = 0; i < d.length; i++) {
      if (d[i].equals(s)) {
        System.out.println(7 - i);
      }
    }
  }
}


Measured memory_bytes: 21844
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int solve(int y, int m, int d) {
  int ret = 0;
  if(y > 1) {
    ret += (y - 1) / 3 * 200;
    ret += (y - 1 - (y - 1) / 3) * 195;
  }
  if(y % 3 == 0 && m > 1) {
    ret += (m - 1) * 20;
  }
  if(y % 3 != 0 && m > 1) {
    ret += (m - 1) / 2 * 19;
    ret += (m - 1 - (m - 1) / 2) * 20;
  }
  ret += d;
  return ret;
}

int main()
{
  int n;
  cin >> n;
  while(n--) {
    int y, m, d;
    cin >> y >> m >> d;
    cout << solve(1000, 1, 1) - solve(y, m, d) << endl;
  }
  return 0;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N){
    rep(i,1,N+1) {
        ll answer = 0;
        rep(x,1,i) {
            if (x*x > i) break;
            rep(y,x,i) {
                if (x*x + y*y > i) break;
                rep(z,y,i) {
                    ll f = x*x + y*y + z*z + x*y + y*z + z*x;
                    if (f > i) break;
                    if (f < i) continue;
                    if (x == y && y == z) {
                        answer++;
                    } else if (x==y || y==z) {
                        answer += 3;
                    } else {
                        answer += 6;
                    }
                }
            }
        }
        cout << answer << endl;
    }
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  cin >> N;
  bool ok = false;
  REP(k, 1, sqrt(2*N)+1) {
    if(k*(k+1)/2==N) {
      ok = true;
      cout << "Yes" << endl;
      cout << k+1 << endl;
      vector<vector<int> > ans(k+1);
      int i = 1;
      int tmp = 0;
      while(i <= N) {
	int tmp2 = 1;
	while(ans[tmp].size() < k) {
	  ans[tmp].push_back(i);
	  ans[tmp+tmp2].push_back(i);
	  tmp2++;
	  i++;
	}
	tmp++;
      }
      rep(i, k+1) {
	cout << k << ' ';
	for(int a: ans[i]) cout << a << ' ';
	cout << endl;
      }
      break;
    }
  }
  if(!ok) cout << "No" << endl;
  return 0;
}


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

int main() {
    int n, a[205][3], sum[205]{};
    set<int> used[105];
    cin >> n;
    REP(i,n){
        REP(j,3){
            cin >> a[i][j];
        }
    }
    REP(j,3){
        REP(i,n){
            used[a[i][j]].insert(i);
        }
        REP(i,n){
            if(used[a[i][j]].size()==1) sum[i] += a[i][j];
        }
        REP(i,105) used[i].clear();
    }
    REP(i,n) cout << sum[i] << endl;
    return 0;
}   



Measured memory_bytes: 3080
#include<stdio.h>

int main(void)
{
	int a[3000], b[3000];
	int i, count=0;
	for(i=0; i<3000; i++)
	{
		scanf("%d %d", &a[i], &b[i]);
		if (a[i]==0 && b[i]==0)
			break;
		count++;
	}

	for(i=0; i<count; i++)
	{
		if (a[i]>b[i])
			printf("%d %d\n", b[i], a[i]);
		else
			printf("%d %d\n", a[i], b[i]);
	}
	return 0;
}


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

using namespace std;

#define scan(x) scanf("%d", &x)
#define scan2(x, y) scanf("%d %d", &x, &y)
#define PRI(x) printf("%d\n", x)
#define FOR(A, B, C) for (int A=B;A<C;A++)
#define RFOR(A, B, C) for (int A=B;A>=C;A--)
#define MEM(A, B) memset(A,B, sizeof A)
#define mod 1000000007
typedef long long int LL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b == c + d) 
	 	printf("Balanced\n");
	else {
		if (a + b > c + d)
			printf("Left\n");
		else printf("Right\n");
	}	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
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<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill( (T*)array, (T*)(array+N), val ); }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
char s[500000];
int main() {
    /*string s;
    int q;
    cin>>s>>q;
    int t,f;
    char c;
    bool flag=true;
    REP(i,q){
        cin>>t;
        if(t==1){
            if(flag)flag=false;
            else flag=true;
        }
        else {
            cin>>f>>c;
            if(flag){
                if(f==1){
                    s=c+s;
                }
                else {
                    s=s+c;
                }
            }
            else {
                if(f==1){
                    s=s+c;
                }
                else {
                    s=c+s;
                }
                
            }
            
        }
    }
    if(flag)cout<<s<<endl;
    else {
        reverse(all(s));
        cout<<s<<endl;
    }*/
    int b,e;
    string S;
    int q;
    cin>>S>>q;
    int n=S.size();
    REP(i,n){
        s[i+200000]=S[i];
    }
    b=200000,e=200000+n-1;
    int t,f;
    char c;
    bool flag=true;
    REP(i,q){
        cin>>t;
        if(t==1){
            if(flag)flag=false;
            else flag=true;
        }
        else {
            cin>>f>>c;
            if(flag){
                if(f==1){
                    s[b-1]=c;
                    b--;
                }
                else {
                    s[e+1]=c;
                    e++;
                }
            }
            else {
                if(f==1){
                    s[e+1]=c;
                    e++;
                }
                else {
                    s[b-1]=c;
                    b--;
                }
                
            }
            
        }
    }
    if(flag){
        REP(i,e-b+1)
        cout<<s[b+i];
    }
    else {
        REP(i,e-b+1)
        cout<<s[e-i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main(){
    int a[1000];
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    cout<<unique(a,a+n)-a;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,t,c=1001,a; cin>>n>>t;
  for(int i=1; i<=n; i++){
    int cn,tn; cin>>cn>>tn;
    if(tn<=t) c=min(c,cn);
  }
  cout<<(c<1001?to_string(c):"TLE");
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_V 310

ll N, M, L, Q, V;
ll d[MAX_V][MAX_V];
ll d2[MAX_V][MAX_V];

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

    cin >> N >> M >> L;
    V = N;

    // 初期化
    REP(i, V) {
        REP(j, V) {
            d[i][j] = (i==j) ? 0 : LLINF;
        }
    }

    // -- ここでコストの入力 -- //
    REP(i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        d[a][b] = c;
        d[b][a] = c;
    }

    // ワーシャルフロイド
    REP(k, V) {
        REP(i, V) {
            REP(j, V) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    // L で行けるところに辺を貼る
    REP(i, V) {
        REP(j, V) {
            d2[i][j] = (d[i][j] <= L) ? 1 : LLINF;
        }
    }

    // ワーシャルフロイド
    REP(k, V) {
        REP(i, V) {
            REP(j, V) {
                d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
            }
        }
    }

    cin >> Q;
    REP(i, Q) {
        ll s, t;
        cin >> s >> t;
        s--; t--;
        if(d2[s][t] >= LLINF) {
            printf("-1\n");
        }
        else {
            printf("%lld\n", d2[s][t] - 1);
        }
    }

    return 0;
}


Measured memory_bytes: 2048
# -*- coding: utf-8 -*-


def main():
    n, k = map(int, input().split())
    d = list(map(int, input().split()))
    like_numbers = [i for i in range(10) if i not in d]
    digit_count = len(list(map(str, list(str(n)))))
    digit = [0] * digit_count
    ans = list()

    def dfs(count):
        if count == digit_count:
            return ans.append(int(''.join(map(str, digit))))

        for like_number in like_numbers:
            digit[count] = like_number
            dfs(count + 1)

    dfs(0)

    if max(ans) >= n:
        print(min([a for a in ans if a >= n]))
    else:
        digit_count += 1
        digit = [0] * digit_count
        dfs(0)
        print(min([a for a in ans if a >= n]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
	int n,k;
	cin >>n>>k;
	int p[n];
	for(int i=0;i<n;i++){
		cin >>p[i];
	}
	sort(p,p+n);
	long sum=0;
	for(int i=0;i<k;i++){
		sum+=p[i];
	}
	cout <<sum<<endl;
	return 0;
}

Measured memory_bytes: 3608
import math
from heapq import heappush, heappop

n, m = map(int, input().split(' '))

a = list(map(int, input().split(' ')))

h = []

for i in a:
    heappush(h, -i)

for i in range(m):
    v = heappop(h)
    heappush(h, -(-v // 2))

print(-sum(h))

Measured memory_bytes: 14380
#include <bits/stdc++.h>
using namespace std;
int a[50][50],c[50],sum[50],ans=INT_MAX;
bool f=0;
int main(){
	int n,m,x;
	cin>>n>>m>>x;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		for(int j=1;j<=m;j++)cin>>a[i][j];
	}
	for(int i=0;i<(1<<n);++i){
		memset(sum,0,sizeof(sum)); 
		int cost=0;
		for(int j=0;j<n;++j){
			if(i&(1<<j)){
				cost+=c[j+1];
				for(int k=1;k<=m;++k)sum[k]+=a[j+1][k];
			}
		}
		f=0;
		for(int k=1;k<=m;++k){
			if(sum[k]<x)f=1;
		}
		if(f)continue;
		ans=min(ans,cost);
//		cout<<i<<":";
//		cout<<cost<<" ";
//		for(int k=1;k<=m;++k)cout<<sum[k]<<' ';
//		cout<<endl;
	}
	if(ans==INT_MAX)cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 112000000012345678LL

using P = pair<long,int>;
// cost, idx

int t[10005];

long d[200*2*10005];
vector<P> vec[200*2*10005];

int main(){
  int n,m,x;
  cin>>n>>m>>x;
  rep(i,n) cin>>t[i];

  rep(_,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    rep(__,2){
      int ai = a*2*x, bi = b*2*x;
      if(t[b]==1){
        if(t[a]!=1){
          // [0,2] -> 1
          if(t[a]==2) bi += x;
          vec[ai].pb(mp(c, bi + max(0, x-c)));
        }
        else {
          // 1 -> 1
          vec[ai].pb(mp(c, bi));
          repl(i,1,x){
            vec[ai+i].pb(mp(c, bi + max(0, i-c)));
            vec[ai+x+i].pb(mp(c, bi + x + max(0, i-c) ));
          }
        }
      }
      else if(t[a] == t[b]){
        // 0 -> 0, 2 -> 2
        vec[ai].pb(mp(c, bi));
      }
      else if(t[a]==1){
        // 1 -> 2, 1 -> 0
        if(t[b]==2) ai += x;
        rep(i,x) vec[ai + i].pb(mp(c, bi));

        ai = a*2*x;
        if(t[b]==0) ai += x;
        rep(i,min(c+1,x)) vec[ai + i].pb(mp(c, bi));
      }
      else {
        // 0->2, 2->0
        if(x <= c) vec[ai].pb(mp(c, bi));
      }

      swap(a,b);
    } // make edges
  }

  rep(i,n) if(t[i]==1){
    int ai = 2*i*x;
    vec[ai].pb(mp(0,ai+x));
    vec[ai+x].pb(mp(0,ai));
  }

  priority_queue<P, vector<P>, greater<P>> pq;
  fill(d, d + 2*x*n, INF);
  d[0] = 0;
  pq.push(mp(0,0));
  while(!pq.empty()){
    auto p = pq.top(); pq.pop();
    if(d[p.se] < p.fi) continue;
    for(auto to : vec[p.se]){
      long nd = p.fi + to.fi;
      int ni = to.se;
      if(d[ni] > nd){
        pq.push(mp(nd,ni));
        d[ni] = nd;
      }
    }
  }

  long ans = INF;
  rep(i,2*x) ans = min(ans, d[(n-1)*2*x + i]);

  cout << ans << endl;

  return 0;
}

// WA?¨????
// mp(cost, idx)?????????????????´?????§???????????????fi??¨se???????????£???
// t[i]==1 ????????????x????????????????????£???

Measured memory_bytes: 341668
#include<bits/stdc++.h>
using namespace std;
long long a, b;
int main(){
	scanf("%lld%lld", &a, &b);
	long long ans = 0;
	
	if(b - a <= 4)
		for(long long i = a ; i <= b; ++i)
			ans ^= i;
	
	else{
		while(a % 4)
			ans ^= a++;
		while(b % 4 != 3)
			ans ^= b--;	
	}
	
	printf("%lld\n", ans);	
	return 0;
}
 

Measured memory_bytes: 256