akhauriyash/Code-Regression huggingface dataset:
//header{{{
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/math/common_factor_rt.hpp>
  
using namespace std;
//using namespace boost::multiprecision;  
//using namespace boost::math;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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


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

    int l,r, d;
    cin >> l >> r >> d;

    int cnt = 0;
    for(int i = l; i <= r; ++i){
        if(i % d == 0){
            ++cnt;
        }
    }

    cout << cnt << '\n';

    return 0;
}


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

using namespace std;
#define ll long long
#define ld long double

ll gcd(ll a, ll b) {
    return b ? gcd(b,a % b) : a;    
}

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

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n;
    cin >> n;
    int cur = 0;
    for(int i=0;i<n;i++) {
        int x;
        cin >> x;
        if(x == cur + 1) {
            cur++;
        }
    }
    cout << ((cur == 0) ? -1 : n - cur);
    return 0;
}


Measured memory_bytes: 256
/*
          Life before Death
          Strength before Weakness
          Journey before Destination
    */
    
    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define rep(i,a,n) for(ll i=a;i<n;i++)
    #define per(i,n,a) for (ll i=n;i>a;i--)
    #define te ll t; std::cin >> t; while(t--)
    #define SZ 100011
    //#define M_PI  3.141592653589793238462643383279502884L
    /*------Just DO IT--------------------------------------*/

    ll dp[4000][4000], mod = 1e9+7;

    ll solve(){
      ll n,m;
      cin>>n>>m;
      string s[n];
      rep(i,0,n) cin>>s[i];
      dp[0][0] = 1;
      rep(i,1,n) dp[i][0] = (s[i][0]=='#' ? 0:dp[i-1][0]);
      rep(i,1,m) dp[0][i] = (s[0][i]=='#' ? 0:dp[0][i-1]);
      
      rep(i,1,n) rep(j,1,m) {
        if(s[i][j]=='#') continue;
        dp[i][j] = ((s[i-1][j]!='#' ? dp[i-1][j] : 0)%mod +  (s[i][j-1]!='#' ? dp[i][j-1] : 0)%mod )%mod;
      }
      cout<<dp[n-1][m-1]<<endl;
    } 
    
   int main() {
       fastio
       solve();
    }

Measured memory_bytes: 32768
#include <iostream>

int main(int argc, char const* argv[])
{
  while (true) {
    int N;
    std::cin >> N;
    if (N == 0)
      break;
    int ans = 0;
    for (int i = 1; i <= N / 2; ++i) {
      int sum = i;
      for (int j = i + 1; j < N; ++j) {
        sum += j;
        if (sum == N) {
          ++ans;
          break;
        } else if (sum > N) {
          break;
        }
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
#include <functional>
//#pragma optimize GCC("O3")
typedef long long ll;
typedef long double ld;
using namespace std;

const int abc = 26;
ll answ = 0;
class trie
{
	class node
	{
	public:
		vector<int> son;
		vector<int> f;
		node()
		{
			son.resize(abc, -1);
			f.resize(abc, 0);
			end = false;
		}
		bool end;
	};
public:
	trie()
	{
		v.resize(1);
	}
	vector<node> v; // aby sme nemuseli mat smerniky :P
	void pridaj(int nd, const string& s, int i)
	{
		if (i == s.size())
		{
			v[nd].end = true;
			return;
		}
		if (v[nd].son[s[i] - 'a'] == -1)
		{
			v.resize(v.size()+1);
			v[nd].son[s[i] - 'a'] = v.size() - 1;
		}
		pridaj(v[nd].son[s[i] - 'a'], s, i + 1);
	}
	int set_f(int nd)
		// kolko celkove slov tam mame
	{
		int sum = 0;
		for (int i =0;i<abc;i++)
		{
			if (v[nd].son[i] != -1)
			{
				int tmp = set_f(v[nd].son[i]);
				v[nd].f[i] += tmp;
				sum += tmp;
				for (int j = 0; j < abc; j++)
					if (i != j)
						v[nd].f[j] += v[v[nd].son[i]].f[j];
			}
		}
		if (v[nd].end) sum++;
		return sum;
	}
	int answer_word(int nd, const string& s, int i)
	{
		if (i == s.size() - 1)
			return v[nd].f[s[i] - 'a'] - 1;
		return answer_word(v[nd].son[s[i]-'a'], s, i + 1);
	}
};
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// Urobime si trie reverznutych slov
	// V kazdom vrchole si budeme pamatat, ci tu konci nejake
	// slovo, a ak ano, kolko slov je pod nim, a ze kolko slov obsahujucich pismeno x v zvysku
	// je pod nim.
	int n;
	cin >> n;
	vector<string> v(n);
	trie t;
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
		reverse(v[i].begin(), v[i].end());
		t.pridaj(0, v[i], 0);
	}
	t.set_f(0);
	for (int i = 0; i < n; i++)
		answ += 1ll*t.answer_word(0, v[i], 0);
	cout << answ << "\n";
	return 0;
}

Measured memory_bytes: 319760
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let s = scan "%s" id

let () =
  let s = String.to_list s |> Array.of_list in
  let acc = Array.make n (0,0,0) in
  ArrayL.iteri s ~f:(fun i c ->
      let (r,g,b) = if i = 0 then (0,0,0) else acc.(pred i) in
      acc.(i) <- match c with
        | 'R' -> (succ r, g, b)
        | 'G' -> (r, succ g, b)
        | 'B' -> (r, g, succ b)
        | _ -> (r,g,b));
  ListL.map (1++^n) ~f:(fun j ->
      ListL.map (0++^j) ~f:(fun i ->
          let k = j + (j-i) in
          let same = if k < n && s.(i) <> s.(j) && s.(j) <> s.(k) && s.(k) <> s.(i) then -1 else 0 in
          let (r,g,b) = acc.(n-1) in
          let (r0,g0,b0) = acc.(j) in
          same + (match s.(i), s.(j) with
              | 'R', 'G' -> b-b0
              | 'R' ,'B' -> g-g0
              | 'G', 'R' -> b-b0
              | 'G', 'B' -> r-r0
              | 'B', 'R' -> g-g0
              | 'B', 'G' -> r-r0
              | _ -> 0)
        ) |> List.sum
    ) |> List.sum
  |> Printf.printf "%d\n"


Measured memory_bytes: 9288
#include <cstdio>
#include <tuple>
#include <utility>
using namespace std;
typedef long long ll;
ll L, A, B, M;
int len(ll x)
{
	int res = 0;
	while (x) ++res, x /= 10;
	return res;
}
tuple<ll, ll, ll> calc(ll C, ll N)
{
	if (N == 1)
		return make_tuple(C, 1, 0);
	auto z = calc(C, N / 2);
	z = make_tuple(get<0>(z) * get<0>(z) % M, get<1>(z) * (1 + get<0>(z)) % M, (get<2>(z) * (1 + get<0>(z)) + (N / 2) % M * get<1>(z)) % M);
	if (N & 1)
		z = make_tuple(get<0>(z) * C % M, (get<1>(z) + get<0>(z)) % M, (get<2>(z) * C + N - 1) % M);
	return z;
}
pair<ll, ll> solve(ll l, ll r)
{
	int xl = len(A + B * l), xr = len(A + B * r);
	if (xl == xr)
	{
		ll pw = 1;
		for (int i = 1; i <= xl; ++i) pw = pw * 10 % M;
		ll X = (A + B * l) % M, Y = B % M;
		auto tmp = calc(pw, r - l + 1);
		return make_pair(get<0>(tmp), (get<1>(tmp) * X + get<2>(tmp) * Y) % M);
	}
	ll mid = l + r >> 1;
	pair<ll, ll> ansl = solve(l, mid), ansr = solve(mid + 1, r);
	return make_pair(ansl.first * ansr.first % M, (ansl.second * ansr.first + ansr.second) % M);
}
int main()
{
	scanf("%lld%lld%lld%lld", &L, &A, &B, &M);
	printf("%lld\n", solve(0, L - 1).second);
	return 0;
}


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

typedef long long ll;
const int mod = 1e9 + 7;

ll H, W, N;

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

    ll tmp = 0;
    ll cnt = 0;
    while (tmp < N) {
        if (H > W) {
            tmp += H;
            W--;
        } else {
            tmp += W;
            H--;
        }
        cnt++;
        // cout << tmp << endl;
    }

    cout << cnt << endl;
}

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

int main() {
  int N,T,A;
  cin>>N>>T>>A;
  vector<int>H(N);
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  int ans=999999999;
  int ans1;
  for(int i=0;i<N;i++){
    if(ans>abs((T*1000-H[i]*6)-A*1000)){
      ans=abs((T*1000-H[i]*6)-A*1000);
      ans1=i+1;
    }
  }
  cout<<ans1<<endl;
}
    


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define MAXN 2000
using namespace std;
vector<int> G[MAXN+5];
int N,K,tot=0;
void DFS(int u,int fa,int depn)
{
	if(depn>K)
		return;
	tot++;
	for(int i=0;i<(int)G[u].size();i++)
	{
		int v=G[u][i];
		if(v==fa)
			continue;
		DFS(v,u,depn+1);
	}
}
int main()
{
//	freopen("shorten.in","r",stdin);
//	freopen("shorten.out","w",stdout);
	scanf("%d %d",&N,&K);
	int u,v,typ;
	for(int i=1;i<N;i++)
	{
		scanf("%d %d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	if(K%2==0)	typ=1;
	else		typ=0;
	int ans=N;
	K/=2;
	if(typ==1)
	{
		for(int i=1;i<=N;i++)
		{
			tot=0;
			DFS(i,-1,0);
			ans=min(ans,N-tot);
		}
	}
	else if(typ==0)
	{
		for(u=1;u<=N;u++)
			for(int j=0;j<(int)G[u].size();j++)
			{
				v=G[u][j];
				tot=0;
				DFS(v,u,0);
				DFS(u,v,0);
				ans=min(ans,N-tot);
			}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int n;
	cin>>n;
	int h[n];
	for(int i=0;i<n;i++)cin>>h[i];
	int ans=0;
	int d=0;
	for(int i=0;i<n-1;i++){
		if(h[i]>=h[i+1])d++;
		else{
			ans=max(d,ans);
			d=0;
		}
		
			ans=max(d,ans);
		//cout<<i<<d<<endl;
	}
	
	cout<<ans<<endl;
}


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

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
#define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%lld", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

#define int long long
#define float long double 

const int upper = 4e5 + 2;
const int M = (int) 1e9 + 7;
const int inf = (int) 1e17;
const double eps =  1e-8;

signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif

	bool flag = false;
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		int haha; cin >> haha;
		if (haha % 2) flag = true;
	}

	if (flag) cout << "first";
	else cout << "second";
	
 	end_routine();	
}

Measured memory_bytes: 256
import sys
import numpy as np

def main():
    input = sys.stdin.readline
    N = int(input())
    A = [int(input()) for _ in range(N)]
    MOD = 998244353

    S = sum(A)
    a = A[0]
    # dp0[i][j]: DP table
    #            the number of combinations that the one side length is j 
    #            until using the i-th A[i].
    dp0 = np.zeros((N, S+1), dtype=np.int64)
    dp0[0, a] = 1
    dp0[0, 0] = 2

    # dp1[i][j]: DP table
    #            the number of one side length is j and the other one is 0
    #            until using the i-th A{i].
    dp1 = np.zeros((N, S+1), dtype=np.int64)
    dp1[0, a] = 1
    dp1[0, 0] = 1
    for i in range(1, N):
        a = A[i]

        dp0[i, :] += dp0[i-1, :] * 2
        dp0[i, a:] += dp0[i-1, :-a]
        dp0[i, :] %= MOD

        dp1[i, :] += dp1[i-1, :]
        dp1[i, a:] += dp1[i-1, :-a]
        dp1[i, :] %= MOD


    ng = 0
    if S % 2 == 1:
        ng = np.sum(dp0[N-1, S//2 + 1:])
        ng = (ng * 3) % MOD

    else:
        ng = np.sum(dp0[N-1, S//2:])
        ng = (ng * 3 - dp1[N-1][S//2] * 3) % MOD

    ans = (pow(3, N, MOD) - ng) % MOD
    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 432816
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt()
  val As = Array.fill(3*N)(sc.nextInt() - 1)

  def comp(a: Int, b: Int): Int = a*N + b
  val dp = Array.fill(N*N)(Int.MinValue)
  val m1 = Array.fill(N)(Int.MinValue)
  val m2 = Array.fill(N)(Int.MinValue)
  var m = 0
  var ans = 0
  dp(comp(As(0), As(1))) = 0
  m1(As(0)) = 0
  m2(As(1)) = 0
  var update = List[(Int, Int, Int)]()
  for (i <- 1 until N) {
    val p = As(3*i - 1)
    val q = As(3*i)
    val r = As(3*i + 1)
    if (p == q && q == r) {
      ans += 1
    } else {
      if (p == q || p == r || r == q) {
        val x = if (p == q || r == p) p else q
        val y = if (p == q) r else if (r == p) q else p
        for (i <- 0 until N) {
          update ::= (i, y, dp(comp(x, i)).max(dp(comp(i, x))) + 1)
        }
      }
      update ::= (q, r, dp(comp(p, p)) + 1)
      update ::= (p, r, dp(comp(q, q)) + 1)
      update ::= (p, q, dp(comp(r, r)) + 1)
      update ::= (p, q, m)
      update ::= (p, r, m)
      update ::= (q, r, m)
      for (i <- 0 until N) {
        update ::= (i, p, m1(i).max(m2(i)))
        update ::= (i, q, m1(i).max(m2(i)))
        update ::= (i, r, m1(i).max(m2(i)))
      }
      for ((i, j, v) <- update) {
        dp(comp(i, j)) = dp(comp(i, j)).max(v)
        m1(i) = m1(i).max(dp(comp(i, j)))
        m2(j) = m2(j).max(dp(comp(i, j)))
        m = m.max(dp(comp(i, j)))
      }
      update = Nil
    }
  }
  val last = As(3*N - 1)
  m = m.max(dp(comp(last, last)) + 1)
  println(ans + m)
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int n; cin >> n;
    vector<int> t(n);
    REP(i,n) cin >> t[i];
    int sum = 0;
    REP(i,n) sum += t[i];
    int m; cin >> m;
    REP(i,m){
        int p,x; cin >> p >> x;
        p--;
        cout << sum - t[p] + x << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//?????°?????£?¨?
		int num = 3;
		//???????????£?¨?
		int list[] = new int[num];

		//?????????????´?
		for(int i =0; i < num; i++){
			//i?????????????´?
			list[i] = sc.nextInt();
			//System.out.print(list[i]);
		}
		//?????????????????????
		Arrays.sort(list);

		//??????????????°?????????
		for(int i = 0; i < num; i++){
			//??????????????°
			if(i == num - 1){
				//??????????????????????????¨???
				System.out.println(list[i]);
			//???????????¶?????§???????????????????????°
			}else{
				System.out.print(list[i] + " ");
			}
		}
	}
}

Measured memory_bytes: 26172
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

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

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, K := sc.nextInt(), sc.nextInt()
	mx := (N - 1) * (N - 2) / 2
	if mx < K {
		fmt.Fprintln(wtr, -1)
		return
	}
	G := make([][]int, N)
	for i := 1; i < N; i++ {
		G[0] = append(G[0], i)
	}
	now := mx
	for i := 1; i < N-1 && K < now; i++ {
		for j := i + 1; j < N && K < now; j++ {
			G[i] = append(G[i], j)
			now--
		}
	}

	m := 0
	for i := 0; i < N; i++ {
		m += len(G[i])
	}
	fmt.Fprintln(wtr, m)
	for i := 0; i < N; i++ {
		for j := 0; j < len(G[i]); j++ {
			fmt.Fprintln(wtr, i+1, G[i][j]+1)
		}
	}
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define vpll vector <pll>
#define pb push_back
#define f(i,a,n) for(ll i=a;i<n;i++)
#define PI 3.14159265358979323846
const ll N=2e5;

int main()
{
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    double angle=abs((30*h+0.5*m)-6*m);
    angle=min(angle,360-angle);
    angle=angle*M_PI/180;
    cout<<setprecision(20)<<fixed<<sqrt(a*a+b*b-2*a*b*cos(angle));
    return 0;
}



Measured memory_bytes: 4220
class Dice
	def initialize(array)
		@a = Array.new(array)
		@a = @a[0..5]
	end
	
	def rotate(direction)
		if direction == "N" then
			tmp = @a[0]
			@a[0] = @a[1]
			@a[1] = @a[5]
			@a[5] = @a[4]
			@a[4] = tmp
		elsif direction == "S" then
			tmp = @a[0]
			@a[0] = @a[4]
			@a[4] = @a[5]
			@a[5] = @a[1]
			@a[1] = tmp
		elsif direction == "E" then
			tmp = @a[0]
			@a[0] = @a[3]
			@a[3] = @a[5]
			@a[5] = @a[2]
			@a[2] = tmp
		elsif direction == "W" then
			tmp = @a[0]
			@a[0] = @a[2]
			@a[2] = @a[5]
			@a[5] = @a[3]
			@a[3] = tmp
		end
	end
	
	def get_top
		@a[0]
	end
	
	def get_right
		@a[2]
	end
	
	def get_front
		@a[1]
	end
	
	def get_left
		@a[3]
	end
	
	def get_bottom
		@a[5]
	end
	
	def get_rear
		@a[4]
	end
	
	def check_same_dice(d)
		if self.get_top == d.get_top &&
		   self.get_bottom == d.get_bottom &&
		   self.get_front == d.get_front &&
		   self.get_rear == d.get_rear &&
		   self.get_left == d.get_left &&
		   self.get_right == d.get_right
		then
			return true
		else
			return false
		end
	end
	
	def get_dice
		@a
	end
	
	def is_same_dice(d)
		answer = false
		0.upto(1) {
			0.upto(3) {
				0.upto(3) {
					if self.check_same_dice(d) then
						answer = true
						break
					else
					d.rotate("E")
					end
				}
				break if answer
				d.rotate("S")
			}
			d.rotate("E")	
		}
		return answer
	end
end

def array_to_i(a)
	0.upto(a.length) {|i|
		a[i] = a[i].to_i
	}
	return a
end

num = STDIN.gets.chomp.to_i
dices = Array.new(num)

0.upto(num - 1) {|i|
	read = STDIN.gets.chomp.split(" ")
	read = array_to_i(read)
	read = read[0..5]
	dices[i] = Dice.new(read)
}

answer = "Yes"

0.upto(num - 2) {|i|
	(i+1).upto(num - 1) {|j|
		answer = "No" if dices[i].is_same_dice(dices[j])
	}
	break if answer == "No"
}

print answer, "\n"



Measured memory_bytes: 6876
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
 
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif
    
    string s;
    cin >> s;
    if (s[0] == 'S')
        cout << "Cloudy\n";
    else if (s[0] == 'C')
        cout << "Rainy\n";
    else
        cout << "Sunny\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
#define eps 1e-8
using namespace std;
const ll maxn = 1e6 + 5;
unsigned long long temp1,temp2;
ll a,b,c;
int main()
{
    cin >> a >> b >> c;
    temp1 = (c - a - b) * (c - a - b);
    temp2 = 4 * a * b;
    if(c - a - b <= 0)
    {
        cout << "No" << endl;
        return 0;
    }
    if(temp1 > temp2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

ans = 0
for a in range(A+1):
    tmp_a = X - a * 500
    if tmp_a == 0:
        ans += 1
        continue
    elif tmp_a < 0:
        break
    else:
        for b in range(B+1):
            tmp_b = tmp_a - b * 100
            if tmp_b == 0:
                ans += 1
                continue
            elif tmp_b < 0:
                break
            else:
                for c in range(C+1):
                    tmp_c = tmp_b - c * 50
                    if tmp_c == 0:
                        ans += 1
                        continue
                    elif tmp_b < 0:
                        break

print(ans)

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

int main()
{
	string s;
	cin>>s;
	s+="R";
	int n=s.size();
	vector<int>a(n);
	int p=0,k=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='L'&&s[i-1]=='R')
			p=i;
		if(s[i]=='R'&&s[i-1]=='L')
		{
			int t=p-k+1;
			int n=t/2;
			int m=t-n-1;
			a[p-1]=n+(i-p)/2;
			a[p]=m+(i-p)-((i-p)/2);
			k=i;
		}
		else
			a[i]=0;
	}
	for(int i=0;i<n-1;i++)
		cout<<a[i]<<" ";
	cout<<endl;

	return 0;
}

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

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

    int h, w;
    cin >> h >> w;

    char C[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> C[i][j];
        }
    }

    long long dp[h][w] = {};
    dp[0][0] = 1;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(i + 1 < h and C[i + 1][j] == '.'){
                dp[i + 1][j] = (dp[i][j] + dp[i + 1][j]) % MOD;
            }
            if(j + 1 < w and C[i][j + 1] == '.'){
                dp[i][j + 1] = (dp[i][j] + dp[i][j + 1]) % MOD;
            }
        }
    }

    cout << dp[h - 1][w - 1] << endl;

    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
vector<int> Factor(int N){
    vector<int> ans;
    while(N != 1){
        for(int a = 2;a <= N;a++){
            if(N%a == 0){
                N/=a;
                ans.push_back(a);
                break;
            }
        }
    }
    return ans;

}

int main(){
    CIN(N);
    map<int,int> mp;
    for(int a = 1;a <= N;a++){
        vector<int> vec = Factor(a);
        for(int b : vec){
            if(mp.find(b) == mp.end()){
                mp[b]=1;
            }else{
                mp[b]++;
            }
        }
    }
    LL ans = 1;
    for(auto a : mp){
        ans *= a.second+1;
        ans %= MOD;
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 256
/*
Author : N_o_o_B
Created : April 22 2020 15:41:23 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    int n,k;
    cin >> n >> k;
    ll ans = 0;
    fori(i,n) { 
        int x;
        cin >> x;
        ans += 2*min(x,k-x);
    }

    cout << ans << endl;


    time_taken();
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
void print(char a[]);
void reverse(char a[]);
char replace(char a[]);
int main(void){
    char o,c[2000],d[20];
    int i,z;
    scanf("%s",c);
    scanf("%d",&z);
    for (i = 0; i < z; i++){
        scanf("%s",d);
        if (strstr(d,"print")!='\0'){ print(c); }
        else if (strstr(d, "reverse") != '\0'){ reverse(c); }
        else if (strstr(d, "replace") != '\0'){ replace(c); }
    }
    return 0;
}
void print(char a[]){
    int i, n;
    char o;
    scanf("%d %d",&i,&n);
    int r;
    for (r = i ; r<=n; r++){
        printf("%c", a[r]);
    }
    printf("\n");
    return;
}
void reverse(char a[]){
    int i, n,r;
    char o;
    char b[2000];
    scanf("%d %d",&i,&n);
    for (r = i; r <= n; r++){
        b[r-i] = a[n - (r - i)];
    }
    for (r = i; r <= n; r++){
        a[r] = b[r-i];
    }
    return;
}
char replace(char a[]){
  
    int i, n, r;
    char o;
    char b[2000];
    scanf("%d %d %s", &i, &n, b);
    for (r = 0; r <= n - i; r++){
        a[i + r] = b[r];
    }
    return;
}

Measured memory_bytes: 584
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		  Scanner sc = new Scanner(System.in);
		  int A = sc.nextInt();
		  int B = sc.nextInt();
		  sc.close();
		  
		  int answer = A + B;
		  answer = Math.max(answer, A - B);
		  answer = Math.max(answer, A * B);
		  
		  System.out.println(answer);
	          System.exit(0);
	    }
}

Measured memory_bytes: 21716
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main()
{
	map<string , int> cpp;
	string str;
	int n, com, q;
	cin >> q;
	while (q--)
	{
		cin >> com >> str;
		if (com)cout << cpp[str] << endl;
		else {
			cin >> n;
			cpp[str] = n;
		}
	}
	return 0;	
}


Measured memory_bytes: 27888
fn main() {
	let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut vec = s.trim().split_whitespace().map(|c| c.parse::<u32>().ok().unwrap());
    let a = vec.next().unwrap();
    let b = vec.next().unwrap();
    println!("{}", (a + b) % 24)
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>a;
    for(int i=0;i<n;i++){
        int j;
        cin>>j;
        a.push_back(j);
    }
    sort(a.begin(),a.end());
    long long sum=0;
    for(int i=0;i<n;i++){
        sum +=a[i];
    }
    cout<<a[0]<<' '<<a[n-1]<<' '<<sum<<endl;
    
}


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

int main() {

  string S, T;
  cin >> S >> T;

  if (S == T.substr(0, T.size()-1)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll, ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // Emily <3
  int a, b;
  cin >> a >> b;
  cout << max(a+b, max(a-b, a*b)) << nl;
  
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a<b){
        cout<<"a"<<" "<<"<"<<" "<<"b"<<endl;
    }else if(a>b){
        cout<<"a"<<" "<<">"<<" "<<"b"<<endl;
    }else{
        cout<<"a"<<" "<<"=="<<" "<<"b"<<endl;
    }
}


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

using namespace std;

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = min(a, k);
    k -= min(a, k);
    k -= min(b, k);
    ans -= min(c, k);
    cout << ans << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll A,B,N; cin >> A >> B >> N;
  cout << min(B-1, N)*A/B << endl;
  return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long int ll;

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

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main() {
  string s;
  cin >> s;
  string r = s;
  reverse(r.begin(), r.end());

  if (s != r) {
    No;
    return 0;
  }

  int flag2, flag3;
  flag2 = flag3 = 1;

  for (int i = 0; i < (s.size() - 1) / 2; i++) {
    // cout << s[i] << " == " << s[(s.size() - 1) / 2 - i - 1] << endl;
    if (s[i] != s[(s.size() - 1) / 2 - i - 1]) {
      No;
      return 0;
    }
  }

  for (int i = 0; i < s.size() - ((s.size() + 3) / 2); i++) {
    // cout << s[(s.size() + 3) / 2 + i - 1] << " == " << s[s.size() - i - 1] << endl;
    if (s[(s.size() + 3) / 2 + i - 1] != s[s.size() - i - 1]) {
      No;
      return 0;
    }
  }
  Yes;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
const long long inf=6000000000000000000ll;
int Q,n,m,D,c[27],a[N][27],t[N],as[N],su[27],ans,i,j,x,y,s=-1000000000;
set<int> p[27];
int cal(int x,int y)
{
	int sum=ans;
	sum-=a[x][t[x]];
	sum+=a[x][y];
	auto it=p[t[x]].find(x);
	auto e=it;
	--e;
	++it;
	sum+=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	it=p[y].lower_bound(x);
	e=it;
	--e;
	sum-=c[y]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	return sum;
}
void Change(int x,int y)
{
	ans-=a[x][t[x]];
	ans+=a[x][y];
	auto it=p[t[x]].find(x);
	auto e=it;
	--e;
	++it;
	ans+=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	p[t[x]].erase(x);
	t[x]=y;
	p[t[x]].insert(x);
	it=p[t[x]].find(x);
	e=it;
	--e;
	++it;
	ans-=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
}
void up()
{
	if(s<ans)
	{
		s=ans;
		for(int i=1;i<=D;++i)
			as[i]=t[i];
	}
}
mt19937 rnd(time(0));
double rand_f() {return double(rnd())/double(RAND_MAX);}
int u=0;
void SA()
{
	double T=100000000;
	while(T>0.001)
	{
		u=u%D+1;
		int a=u,b=rnd()%26+1;
		while(b==t[a])
			b=rnd()%26+1;
		int tmp=cal(a,b);
		if(tmp>ans||rand_f()<exp((tmp-ans)/T))
		{
			Change(a,b);
			up();
		}
		T=T*0.9995;
	}
	//cout<<s<<' '<<ans<<endl;
}
void Find()
{
	int i,j;
	for(i=1;i<=26;++i)
	{
		p[i].clear(); 
		p[i].insert(D+1);
		p[i].insert(0);
	}
	memset(su,0,sizeof(su));
	ans=0;
	for(i=1;i<=D;++i)
	{
		for(j=1;j<=26;++j)
			++su[j];
		t[i]=1;
		for(j=2;j<=26;++j)
			if(su[t[i]]*c[t[i]]+a[i][t[i]]<su[j]*c[j]+a[i][j])
				t[i]=j;
		ans+=a[i][t[i]];
		su[t[i]]=0;
		for(j=1;j<=26;++j)
			ans-=su[j]*c[j];
		p[t[i]].insert(i);
		//as[i]=t[i];
	}
}
int main()
{
	scanf("%d",&D);
	for(i=1;i<=26;++i)
		scanf("%d",&c[i]);
	for(i=1;i<=D;++i)
		for(j=1;j<=26;++j)
			scanf("%d",&a[i][j]);
	Find();
	up();
	while(1.0*clock()/CLOCKS_PER_SEC<1.8)
	{
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		SA();
		Find();
		up();
		//cout<<'?'<<' '<<s<<' '<<ans<<endl;
	}
	for(i=1;i<=D;++i)
	{
		cout<<as[i]<<endl;
		assert(as[i]>=1&&as[i]<=26);
	}
}

Measured memory_bytes: 4432
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;


/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back


/*---  Type ---*/
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;


/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// 4-direction
int dy4[] = {0,  1, -1,  0};
int dx4[] = {1,  0,  0, -1};

// 8-direction
int dy8[] = {0,  1,  1,  1,  0, -1, -1, -1};
int dx8[] = {1,  1,  0, -1, -1, -1,  0,  1};

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

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

  if(x < a) cout << 0 << endl;
  else cout << 10 << endl;
  return 0;
}

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

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<double> p(n), sum_p(n);
    for (int i = 0; i < n; i++)
    {
        double x;
        cin >> x;
        p[i] = (1 + x) / 2;
    }

    sum_p[0] = p[0];
    for (int i = 1; i < n; i++)
    {
        sum_p[i] = sum_p[i - 1] + p[i];
    }

    auto max_sum = sum_p[k - 1];
    auto start_index = 0;
    for (int i = k; i < n; i++)
    {
        if (sum_p[i] - sum_p[i - k] > max_sum)
        {
            max_sum = sum_p[i] - sum_p[i - k];
            start_index = i - k + 1;
        }
    }

    cout << setprecision(10) << max_sum << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int t,a,b,temp;
  	cin >> t >> a >> b;
  	temp = t * a;
  	
  	if (temp >= b){
    	cout << b << endl;
    }
   	else {
    	cout << temp << endl;
    }
  	
  	
}

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

int main(void){
  int64_t a, b, k;
  cin >> a >> b >> k;
  
  if(a>=k){
    cout << a-k << " " << b << endl;
  }else if(a+b>=k){
    cout << 0 << " " << b-(k-a) << endl;
  }else{
    cout << 0 << " " << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    long long a, b,c, d;
    std::cin>>a>>b>>c>>d;

    std::cout<<std::max(a * b, c * d)<<std::endl;
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    long long sum=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            for(int k=1;k<=n;k++)
                sum += gcd(gcd(i,j),k);
                
    cout<<sum<<endl;
}

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

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int score;
  if(a >= k){
    score = k;
  }
  else if(a+b >= k){
    score = a;
  }
  else{
    score = a - (k-a-b);
  }
  cout << score << endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	static long bignum = 1000000000+7;

	public static int[] rudder = new int[200001];

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int a = x/500;
		x = x%500;
		int b = x/5;
		System.out.println(1000*a+5*b);
	}





}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 21844
typedef long long L;
a1,m1,a2,m2,a3,m3;
L gcd(L x,L y){
	if(y)
		return gcd(y,x%y);
	else
		return x;
}
L lcm(L x,L y){
	return x/gcd(x,y)*y;
}
cycle(a,m){
	int r,v;
	for(r=1,v=a%m;v!=1;r++)
		v=v*a%m;
	return r;
}
main(){
	for(;scanf("%d%d%d%d%d%d",&a1,&m1,&a2,&m2,&a3,&m3),a1|m1|a2|m2|a3|m3;){
		printf("%lld\n",lcm(lcm(cycle(a1,m1),cycle(a2,m2)),cycle(a3,m3)));
	}
	exit(0);
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
using namespace std;

#define sz(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
///////////////////////

int const N = 1e5 + 41;
int const INF = 1e9 + 41;

vector<pii> edges[N * 10];
vector<int> col[N];
int n, m;

int getFirstEdge(int ver, int col){
	int l = -1;
	int r = sz(edges[col]);
	while(r-l>1){
		int m = (l+r)/2;
		if(edges[col][m].first >= ver) r = m;
		else l = m;
	}
	return r;
}

int getLastEdge(int ver, int col){
	int l = -1;
	int r = sz(edges[col]);
	while(r-l>1){
		int m = (l+r)/2;
		if(edges[col][m].first <= ver) l = m;
		else r = m;
	}
	return l;
}

pii getEdgesRange(int ver, int col){
	return mp(getFirstEdge(ver, col), getLastEdge(ver, col));	
}

typedef pair<int, pair<int, int> > State;
#define DIST first
#define ID second.first
#define COL second.second

set<State> q;
map<pii, int> dist;
int w[N];

State getState(int d, int id, int col){
	return mp(d, mp(id, col));
}

void solve(){
	cin >> n >> m;
	rep(i, 0, m){
		int u, v, c;
		cin >> u >> v >> c;
		--u;--v;
		col[u].pb(c);
		col[v].pb(c);
		edges[c].pb(mp(u, v));
		edges[c].pb(mp(v, u));
	}
	rep(i, 0, N * 10) sort(edges[i].begin(), edges[i].end());
	rep(i, 0, N) sort(col[i].begin(), col[i].end());
	q.insert(getState(0, 0, 0));
	dist[mp(0, 0)] = 0;
	int ans = INF;
	while(sz(q)){
		State cur = (*q.begin());
		q.erase(cur);
		int id = cur.ID;
		int d = cur.DIST;
		int c = cur.COL;
		if(id == n - 1) ans = min(ans, d);
		if(w[id] == 0){
			rep(i, 0, sz(col[id])){
				if(i > 0 && col[id][i] == col[id][i-1]) continue;
				int color = col[id][i];
				pii eR = getEdgesRange(id, color);
				int l = eR.first;
				int r = eR.second;
				rep(i, l, r+1){
					pii to = mp(edges[color][i].second, color);
					int add = (color == c ? 0 : 1);
					if(dist.find(to) == dist.end() || dist[to] > add + d){
						q.erase(getState(dist[to], to.first, to.second));
						dist[to] = add + d;
						q.insert(getState(dist[to], to.first, to.second));
					}
				}
			}
		}else{
			pii eR = getEdgesRange(id, c);
			int l = eR.first;
			int r = eR.second;
			rep(i, l, r+1){
				pii to = mp(edges[c][i].second, c);
				if(dist.find(to) == dist.end() || dist[to] > d){
					q.erase(getState(dist[to], to.first, to.second));
					dist[to] = d;
					q.insert(getState(dist[to], to.first, to.second));
				}
			}
		}
		w[id] = 1;
	}

	if(ans == INF) ans = -1;
	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();


	return 0;
}

Measured memory_bytes: 64768
from collections import deque
n=int(input())
a=list(input().split())
b=deque()

for i in range(1,n+1):
  if (i%2==1 and n%2==0) or (i%2==0 and n%2==1):
    b.append(a[i-1])
  else:
    b.appendleft(a[i-1])
print(" ".join(b))

Measured memory_bytes: 108212
//#pragma warning(disable:4996)
//#include <Windows.h>
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

template<class T>
inline void chmin(T& a, T b) {
	a = min(a, b);
}

template<class T>
inline void chmax(T& a, T b) {
	a = max(a, b);
}

void input();
void solve();

void daminput();

int main() {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	input();
	//daminput();
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////

string S;
int Q;

void input() {
	cin >> S;
	cin >> Q;
}

void daminput() {
}

void solve() {
	deque<string> strs;
	strs.push_back(S);
	bool rev = false;
	for (int q = 0; q < Q; q++)
	{
		int T;
		cin >> T;
		if (T == 1) {
			rev = !rev;
		}
		else {
			int F;
			string C;
			cin >> F >> C;
			if (!rev) {
				if (F == 1)strs.push_front(C);
				else strs.push_back(C);
			}
			else {
				if (F == 1)strs.push_back(C);
				else strs.push_front(C);
			}
		}
	}
	if (!rev) {
		for (int i = 0; i < strs.size(); i++)
		{
			cout << strs[i];
		}
		cout << "\n";
	}
	else {
		for (int n = strs.size()-1; n >= 0; n--) {
			reverse(strs[n].begin(), strs[n].end());
			cout << strs[n];
		}
		cout << "\n";
	}
}

Measured memory_bytes: 7876
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

int main()
{

    int a, b, c, flag = -1;
    std::cin >> a >> b >> c;

    for(int i = 1;;i++){
        if((a * i) % b == c){
            std::cout << "YES";

            return 0;
        }
        else{
            if(flag == -1){
                flag = (a * i) % b;
            }
            else if(flag == (a * i) % b){
                std::cout << "NO";

                return 0;
            }
        }
    }
}

Measured memory_bytes: 256