akhauriyash/Code-Regression huggingface dataset:
type uf_node = {
  mutable par: int;
  mutable rank: int;
}
;;

let uf_make n = Array.init n (fun i -> { par = i; rank = 0 })
;;

(* 根を求める *)
let rec uf_find uf x =
  if uf.(x).par == x
  then x
  else
    let par = uf.(x).par in
    let v = uf_find uf par in
    uf.(x).par <- v;
    v
;;

(* xとyの集合を併合 *)
let uf_unite uf x y =
  let x = uf_find uf x in
  let y = uf_find uf y in
  if x != y then
    if uf.(x).rank < uf.(y).rank
    then (
      uf.(x).par <- y;
      ()
    )
    else (
      uf.(y).par <- x;
      if uf.(x).rank == uf.(y).rank then (
        uf.(x).rank <- uf.(x).rank + 1;
        ()
      )
    )
;;

let uf_some uf x y = uf_find uf x == uf_find uf y
;;

let rec parse_xy_list_ m l =
  if m == 0
  then l
  else parse_xy_list_ (m - 1) ((match (read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string : int list) with | [x;y ] -> x, y | _ -> raise Not_found) :: l)
;;

let parse_xy_list m = parse_xy_list_ m [] |> List.rev
;;

let () =
  let n, m = match read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string with
    | [n; m] -> n, m
    |  _ -> raise Not_found in
  let p_list = read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string in
  let xy_list = parse_xy_list m in
  let uf = uf_make n in
  List.iter (fun xy -> let x, y = xy in uf_unite uf (x - 1) (y - 1)) xy_list;
  let res = p_list |> List.mapi (fun i x -> uf_some uf i (x - 1)) |> List.filter (fun x -> x) |> List.length in
  Printf.printf "%d\n" res
;;


Measured memory_bytes: 26240
#include <bits/stdc++.h>
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;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == '?') {
            s[i] = 'D';
        }
    }
    print(s);
}

Measured memory_bytes: 3784
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (declare #.OPT)
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  ;; (return-from read-fixnum 0)
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (the fixnum (* result 10))))
              (return (if minus (- result) result))))))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (dotimes (_ (read) (write-line "second"))
    (when (oddp (read))
      (write-line "first")
      (return-from main))))

#-swank(main)


Measured memory_bytes: 59880
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <fstream>
#include <assert.h>
#include <string>
#include <cstring>
#include <unordered_map>
#include <bitset>
#include <climits>
#include <time.h>
#include <stdio.h>
#include <cstdlib>
#include <math.h>
#include <deque>
#include <cmath>
#include <set>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int> > vii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpi;

#define INF 1000000000
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define loop(i,a,b) for (int i = a; i < b; i++)

void setIO(string name) {
	freopen((name+".in").c_str(), "r", stdin); 
	freopen((name+".out").c_str(), "w", stdout);
}
const int MOD = 998244353;

ll dp[3001][3001];
int counter = 0;
int A,B,C,D;
ll ans(int x, int y) {
	if (dp[x][y]) return dp[x][y];
	if (x < A || y < B) return dp[x][y] = 0;
	if (x == 1 || y == 1 || (x == A && y == B)) return dp[x][y] = 1;
	ll a = (ans(x-1,y)*y) % MOD;
	ll b = (ans(x,y-1)*x) % MOD;
	ll c = ((x-1)*(y-1)*ans(x-1,y-1)) % MOD;
	return dp[x][y] = ((a + b - c + MOD) % MOD);
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
	//int A, B, C, D;
	cin >> A >> B >> C >> D;

	//dp[A][B] = 1;
  	cout << ans(C, D) << endl;
	return 0;
}










Measured memory_bytes: 73876
#include <bits/stdc++.h>
#define mod 998244353
using namespace std;
unordered_map <string,int> mp;
inline string get(string a,string b)
{int len=a.size(),i;
for (i=0;i<len;i++)
{if (a[i]=='0'||b[i]=='0') {a[i]='0';}
else {a[i]='1';}
}
return a;
}
int cal(string s)
{if (s.size()==1) return (s[0]=='0'?1:2);
if (mp.find(s)!=mp.end()) return mp[s];
int len=s.size(),i,j,ans=0;
ans=(s[0]=='0'?1:2)*cal(s.substr(1,len-1));
if (ans>=mod) ans-=mod;
for (i=1;i*2<=len;i++)
{string tp=get(s.substr(0,i),s.substr(i,i));
int pos=2*i,fd,rem;
fd=cal(tp);
rem=(pos==len?1:cal(s.substr(pos,len-pos)));
ans+=1ll*fd*rem%mod;
if (ans>=mod) ans-=mod;
while (pos+i<=len)
{tp=get(tp,s.substr(pos,i));pos+=i;
fd=cal(tp);
rem=(pos==len?1:cal(s.substr(pos,len-pos)));
ans+=1ll*fd*rem%mod;
if (ans>=mod) ans-=mod;
}
}
return mp[s]=ans;
}
int main (){
	string s;cin>>s;
	printf ("%d\n",cal(s));
	return 0;
}

Measured memory_bytes: 5388
import std.stdio, std.string, std.range, std.algorithm, std.math, std.conv;

enum po = 1000_000_000 + 7;

void main() {
  auto N = readln.chomp.to!int;
  auto A = readln.split.to!(int[]);
  auto B = new int[N];
  foreach (i, a; A) {
    auto m = N - a - 1;
    if (m % 2) {
      writeln(0);
      return;
    }
    m /= 2;
    B[i] = m;
  }
  auto res = 1;
  foreach (g; sort(B).group.array) {
    if (g[1] == 1) {
      if (N % 2 == 0 || g[0] != N / 2) {
        writeln(0);
        return;
      }
    } else if (g[1] == 2) {
      res *= 2;
      res %= po;
    } else {
      writeln(0);
      return;
    }
  }
  writeln(res);
}


Measured memory_bytes: 4164
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};

int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
 int n;
 cin>>n;
 vector<double>v;
 for(int i=0;i<n;i++){
    double a;
    cin>>a;
    v.push_back(a);
 }
 sort(all(v));
 double sum=(v[0]+v[1])/2.0;
 for(int i=2;i<n;i++){
    sum=(sum+v[i])/2.0;
 }
 cout<<setprecision(10)<<fixed<<sum<<endl;

    return 0;
}


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

int main(){
     ll i, j, k;
     ll n;
     cin >> n;
     vector< ll > freq(ll(1e5+5), 0);
     ll sm=0;
     for(i=0; i<n; ++i){
          cin >> k;
          freq[k]++;
          sm+=k;
     }
     ll q;
     cin >> q;
     while(q--){
          cin >> i >> j;
          sm-=freq[i]*i, sm+=freq[i]*j;
          freq[j]+=freq[i];
          freq[i]=0;
          cout << sm << endl;
     }
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int ans=0;
	string s;
	cin>>s;
	int start=0,end=s.size()-1;
	while(start<=end)
	{
		if(s[start]!=s[end])ans++;
		start++;end--;
	}
	cout<<ans;
	return 0;
}


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

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

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

int main(void) {
    string s, z[4] = {"maerd", "remaerd", "esare", "resare"};
    cin >> s;
    reverse(s.begin(), s.end());
    while (true) {
        bool flag = false;
        for (int i = 0; i < 4; i++) {
            if (equal(z[i].begin(), z[i].end(), s.begin())) {
                flag = true;
                s.erase(0, z[i].size());
                break;
            }
        }
        if (!flag) {
            cout << "NO" << endl;
            return 0;
        }
        if (s.empty()) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "こわれる" << endl;
}


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

int main() {
  int K,A,B;
  cin>>K;
  cin>>A>>B;
  int c=A/K;
  int d=(c+1)*K;
  if((c*K)<A&&d>B)cout<<"NG"<<endl;
  else cout<<"OK"<<endl;
}








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

#include <atcoder/all>
typedef long long lint;
using namespace std;
using namespace atcoder;

int n, q;

int op(int x, int y) {
    return max(x, y);
}
int id() {
    return INT_MIN;
}
int target;
bool f(int x) {
    return x < target;
}

int main() {
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    segtree<int, op, id> seg(a);
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 1) {
            int x, v;
            cin >> x >> v;
            x--;
            seg.set(x, v);
        } else if (t == 2) {
            int l, r;
            cin >> l >> r;
            l--;
            cout << seg.prod(l, r) << endl;
        } else {
            int x, v;
            cin >> x >> v;
            target = v;
            x--;
            auto ans = seg.max_right<f>(x) + 1;
            cout << ans << endl;
        }
    }
}

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

int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  int kotae=0;
  int keta1=0;
  int keta2=0;
  bool hantei=false;
  bool hantei2=false;
  bool hantei3=false;
  for(int i=0;i<10;i++){
    hantei=false;
    for(int l=0;l<n-2;l++){
      if(s[l]-'0'==i){
        keta1=l;
        hantei=true;
        break;
      }
    }
    if(hantei==true){
      for(int j=0;j<10;j++){
        hantei=false;
        for(int m=keta1+1;m<n-1;m++){
          if(s[m]-'0'==j){
            keta2=m;
            hantei=true;
            break;
          }
        }
        if(hantei==true){
          for(int k=0;k<10;k++){
            for(int o=keta2+1;o<n;o++){
              if(s[o]-'0'==k){
                //cout<<i<<j<<k<<"kore"<<s[keta1]<<s[keta2]<<s[o]<<" ";
                kotae++;
                break;
              }
            }
          }
        }
      }
    }
  }
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
 
signed main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<int> b(n);
 
    rep(i,n+1)cin >> a[i];
    rep(i,n)cin >> b[i];
 
    int ans = 0;
    rep(i,n){
        if(a[i] >= b[i]){
            ans += b[i];
        }else{
            ans += a[i];
            b[i] -= a[i];
            if(a[i+1] >= b[i]){
                a[i+1] -= b[i];
                ans += b[i];
            }else{
                ans += a[i+1];
                a[i+1] = 0;
            }
        }
    }
    cout << ans << endl;
 
 
    
 
 
    
    return 0;
}

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

public class Main {

	static BufferedReader reader;
	final static boolean MODE_DEBUG = true;
	static int[] a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	//static field here
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		//code here
		
		int[] NM = readLineInt();
		int N = NM[0];
		print(a[N-1]);
		
		//String[] s = readLine();
		//print(num);
	}
	
	//functions here
	//note that all methods should be STATIC

	private static <T> int arraySearch(T needle, T[] heystack) {
		for(int i=0;i<heystack.length;i++) {
			if(needle.equals(heystack[i])) {
				return i;
			}
		}
		return -1;
	}
	private static String[] readLine(){
		try{
			return reader.readLine().split(" ");
		}catch(Exception e){
			e.printStackTrace();
			return new String[]{e.getMessage()};
		}
	}
	private static int[] readLineInt(){
		try{
			String[] s = readLine();
			int[] ints = new int[s.length];
			for(int i=0;i<ints.length;i++) {
				ints[i] = Integer.parseInt(s[i]);
			}
			return ints;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static byte[] readLineByte(){
		try{
			String[] s = readLine();
			byte[] bytes = new byte[s.length];
			for(int i=0;i<bytes.length;i++) {
				bytes[i] = Byte.parseByte(s[i]);
			}
			return bytes;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static char[] readLineChar(){
		try{
			String[] s = readLine();
			char[] chars = new char[s.length];
			for(int i=0;i<chars.length;i++) {
				chars[i] = (char)Integer.parseInt(s[i]);
			}
			return chars;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	private static void print(Object o){
		System.out.println(o);
	}
	private static void print(){
		System.out.println();
	}
	private static void printd(Object o){
		if(MODE_DEBUG)System.err.println(o);
	}
	private static void printd(){
		if(MODE_DEBUG)System.err.println();
	}
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n,m,x;
  cin >> n >> m >> x;
  int c[n] = {};
  int a[m*n] = {};
  int minCost = 0;
  int totalScore[m] = {0};
  for(int i=0;i<n;i++){
    cin >> c[i];
    minCost += c[i];
    for(int j=0;j<m;j++){
      cin >> a[m*i+j];
      totalScore[j] += a[m*i+j];
    }
  }
  bool impossible = false;
  for(int j=0;j<m;j++){
    if(x>totalScore[j])impossible = true;
  }
  if(impossible){
    cout << "-1" << endl;
    return 0;
  }

  bool found = false;
  for(int i=1;i<(1<<n); i++)
  {
    int cost = 0;
    int score[m] = {0};
    for(int j=0;j<n;j++){
      if((i&(1<<j)) == 0) continue;
      cost += c[j];
      bool isCleared = true;
      for(int k=0;k<m;k++){
        score[k] += a[j*m+k];
        if(score[k]<x) isCleared=false;
      }
      if(isCleared){
        found = true;
        if(minCost>=cost){
          minCost = cost;
        }
        continue;
      }
    }    
  }
  
  if(found) cout << minCost << endl;
  else cout << "-1" << endl;
   
  return 0;
}

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

int main(){
  int n,x,y;
  cin>>n>>x>>y;
  --x; --y;
  vector<int> num(n);
  int d;
  rep(i,n){
    for(int j=i+1; j<n ; j++){
      d=min( abs(i-j), min(abs(i-x)+abs(j-y)+1, abs(i-y)+abs(j-x)+1));
      num[d-1]++;
    }
  }
  
 rep(i,n-1) cout<<num[i]<<endl;
 
  
    
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int t,a;
	int h[1001];
	cin>>n;
	cin>>t>>a;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	int MIN;
	int x=INT_MAX;
	int z;
	a*=1000;
	for(int i=1;i<=n;i++){
		MIN=t*1000-h[i]*6;
		if(x>abs(MIN-a)){
			x=abs(MIN-a);
			z=i;
		}
	}
	cout<<z<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include<iomanip>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>

i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

i64 cup(i64 xxx, i64 yyy) {//切り上げ
	return (xxx + yyy - 1) / yyy;
}

//メモリ置き場
deque<string> s;
int q;

//inputします
void input() {
	string ss;
	cin >> ss;
	s.push_back(ss);
	cin >> q;
}

//ライブラリ置き場

//main
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
	input();
	int gk = 0;
	ff(i, 0, q) {
		int t;
		//scanf("%d", &t);
		cin>>t;
		if (t == 1) {
			gk++;
		}
		if (t == 2) {
			int f;
			//scanf("%d", &f);
			cin>>f;
			string cc;
			//scanf("%s", &cc, 1);
			cin>>cc;
			if ((f + gk) % 2 == 1) {
				s.push_front(cc);
			}
			if ((f + gk) % 2 == 0) {
				s.push_back(cc);
			}
		}
	}
	if (gk % 2 == 1) {
		ffrvs(i, s.size() - 1, 0) {
			ffrvs(j,s[i].size()-1,0) {
				cout << s[i][j];
			}
		}
		return 0;
	}
	ff(i, 0, s.size()) {
		cout << s[i];
	}
	return 0;
}


Measured memory_bytes: 11728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mp make_pair
const int maxn = 4e5+5;
const int MOD = 1e9+7;
#define mod(x) x % MOD
#define INF 0x3f3f3f3f

char a[2000][2000];
ll dp[2000][2000];

int main(){
    int n, m;
    while(~scanf("%d %d", &n, &m)){
        for(int i = 0;i < n;i++){
            scanf("%s", a[i]);
        }
        dp[0][0] = 1;
        for(int i = 1;i < n;i++){
            if(a[i][0]=='.') dp[i][0] = dp[i-1][0];
            else{
                dp[i][0] = 0;
            }
            //dp[i][0] = 1;
        }
        for(int i = 1;i < m;i++){
            if(a[0][i] == '.') dp[0][i] = dp[0][i-1];
            else{
                dp[0][i] = 0;
            }
            //dp[0][i] = 1;
        }
        for(int i = 1;i < n;i++){
            for(int j = 1;j < m;j++){
                if(a[i][j-1]=='.'){
                    dp[i][j] += dp[i][j-1];
                    dp[i][j] = mod(dp[i][j]);
                }
                if(a[i-1][j]=='.'){
                    dp[i][j] += dp[i-1][j];
                    dp[i][j] = mod(dp[i][j]);
                }
            }
        }
        printf("%lld\n",mod(dp[n-1][m-1]));
    }    
    return 0;
}

Measured memory_bytes: 20224
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<deque>
using namespace std;

using ll = long long;
const int INF = 1001001001;

#define rep(i,n) for (int i = 0; i < (n); ++i)

ll gcd(ll a, ll b)
{
  ll small = min(a, b);
  ll large = small == a ? b : a;
  if (large % small == 0) {
    return small;
  } else {
    return gcd(small, large % small);
  }
}

int main(void)
{
  int k;
  cin >> k;

  ll result = 0;

  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int l = 1; l <= k; l++) {
        result += gcd(i, gcd(j, l));
      }
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 3640
N = int(input())
r = []
b = []
for i in range(N):
    r.append([int(i) for i in input().split()])

for i in range(N):
    b.append([int(i) for i in input().split()])

#print("r", r)
#print("b", b)

sorted_r = sorted(r, key=lambda r:r[1], reverse=True)
sorted_b = sorted(b)
#print("sorted_r", sorted_r)
#print("sorted_b", sorted_b)

ans = 0
for e1 in sorted_b:
    for e2 in sorted_r:
        if e2[0] < e1[0] and e2[1] < e1[1]:
            ans += 1
            sorted_r.remove(e2)
            break
print(ans)


Measured memory_bytes: 3064
// AOJ 1182 Railway Connection
// 2018.2.22 bal4u
 
#include <stdio.h>
#include <string.h>

#define QMAX 10000
typedef struct { int t; int s; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int s, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF 0x10101010
#define MAX 20010

int hi[250], to[102][250], w[102][250];
int d[22][102][102];
int val[22][20010];
int p[22], q[22][52], r[22][52];
int dist[102];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	while (c <= ' ') c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int dijkstra(int s, int g)
{
	int i, e, d;

	memset(dist, INF, sizeof(dist));
	qsize = 0;
	enq(s, 0), dist[s] = 0;
	while (qsize) {
		s = que[0].s, deq();
		for (i = 0; i < hi[s]; i++) {
			e = to[s][i], d = dist[s] + w[s][i];
			if (d < dist[e]) dist[e] = d, enq(e, d);
		}
	}
	if (dist[g] >= INF) return -1;
	return dist[g];
}

int main()
{
	int N, M, C, S, G, i, j, k;
	int x, y, c, t;

     while (N = in()) {
		M = in(), C = in(), S = in()-1, G = in()-1;

		memset(d, INF, sizeof(d));
		for (c = 0; c < C; c++) for (i = 0; i < N; i++) d[c][i][i] = 0;

    	for (i = 0; i < M; i++) {
			x = in()-1, y = in()-1, t = in(), c = in()-1;
			if (t < d[c][x][y]) d[c][x][y] = d[c][y][x] = t;
    	}

    	for (c = 0; c < C; c++) {
    		for (k = 0; k < N; k++) for (i = 0; i < N; i++) for (j = 0; j < N; j++) {
				t = d[c][i][k] + d[c][k][j];
				if (t < d[c][i][j]) d[c][i][j] = t;
			}
		}

    	for (c = 0; c < C; c++) p[c] = in();
		for (c = 0; c < C; c++) {
    		for (i = 1; i < p[c]; i++) q[c][i] = in();
			q[c][p[c]] = MAX-1;
    		for (i = 1; i <= p[c]; i++) r[c][i] = in();
    		for (i = 1; i <= p[c]; i++) {
    			for (j = q[c][i-1]+1; j <= q[c][i]; j++) val[c][j] = val[c][j-1] + r[c][i];
    		}
    	}

		memset(hi, 0, sizeof(hi));
    	for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) {
			t = INF;
    		for (c = 0; c < C; c++) if (d[c][i][j] < MAX) {
				if (t > val[c][d[c][i][j]]) t = val[c][d[c][i][j]];
    		}

			if (t < INF) {
				k = hi[i]++, to[i][k] = j, w[i][k] = t;
				k = hi[j]++, to[j][k] = i, w[j][k] = t;
			}
		}
    	printf("%d\n", dijkstra(S, G));
    }
    return 0;
}



Measured memory_bytes: 4472
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::min;
using std::max;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long

ll n, k, p[500000], pos[500000], ans;

ll min_on_segm[500000];
ll max_on_segm[500000];

int eq(int l1, int r1, int l2, int r2)
{
    int a = min_on_segm[l1];
    int b = max_on_segm[l2];
    if (pos[a] == l1 && pos[b] == r2)
        return 1;
    return 0;
}

int cnt = 0;
int gcnt[500000];
int equals[500000];

signed main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
        pos[p[i]] = i;
    }
    int r = n - k + 1;
    set<int> s;
    for (int i = 0; i < k; i++)
    {
        s.insert(p[i]);
    }
    for (int i = 0; i + k <= n; i++)
    {
        auto it1 = s.begin();
        auto it2 = s.end();
        it2--;
        min_on_segm[i] = *it1;
        max_on_segm[i] = *it2;
        s.erase(p[i]);
        if (i + k != n)
            s.insert(p[i + k]);
    }
    for (int i = 0; i < k - 1; i++)
    {
        cnt += (p[i] < p[i + 1]);
    }
    for (int i = 0; i + k <= n; i++)
    {
        gcnt[i] = cnt;
        cnt -= (p[i] < p[i + 1]);
        if (i + k != n)
            cnt += (p[i + k - 1] < p[i + k]);
    }
    for (int i = 1; i + k <= n; i++)
    {
        if (eq(i - 1, i + k - 2, i, i + k - 1))
            equals[i] = 1;
    }
    ans = n - k + 1;
    int t = 0;
    for (int i = 0; i + k <= n; i++)
    {
        if (gcnt[i] == k - 1)
        {
            t = 1;
            ans--;
        }
    }
    ans += t;
    for (int i = 0; i + k <= n; i++)
    {
        if (equals[i] && !(gcnt[i] == k - 1))
            ans--;
    }
    cout << ans;
}


Measured memory_bytes: 26752
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

#define ll long long

ll a;
ll n;
double b;
string s;
int main(){
	cin >> a >> s;
	ll c;
	c = (s[0]-'0')*100+(s[2]-'0')*10+s[3]-'0';
	cout << a*c/100;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int a,b;
  while(scanf("%d%d",&a,&b)&&a&&b){
    int fld[a][b];
    bool f[a][b];
    memset(f,true,sizeof(f));
    int n;
    scanf("%d",&n);
    while(n--){
      int x,y;
      scanf("%d%d",&x,&y);x--;y--;
      f[x][y]=false;
    }
    fld[0][0]=1;
    for(int i=1;i<a;i++){
      if(!f[i][0])fld[i][0]=0;
      else fld[i][0]=fld[i-1][0];
    }
    for(int i=1;i<b;i++){
      if(!f[0][i])fld[0][i]=0;
      else fld[0][i]=fld[0][i-1];
    }
    for(int i=1;i<a;i++){
      for(int j=1;j<b;j++){
        if(!f[i][j])fld[i][j]=0;
        else fld[i][j]=fld[i-1][j]+fld[i][j-1];
      }
    }
    printf("%d\n",fld[a-1][b-1]);
  }
}

Measured memory_bytes: 1196
#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;
template<typename x>
using ordered_set = tree<x,null_type,less<x>,rb_tree_tag,tree_order_statistics_node_update>;
#define sorta(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n,greater<__typeof(a[0])>())
#define all(x) (x).begin(),(x).end()
#define ms0(x) memset((x),0,sizeof((x)))
#define ms1(x) memset((x),-1,sizeof((x)))
typedef pair<int,int> pi;
#define inarr(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define prinarr(arr) {for(int x:arr)cout<<x<<" ";} cout<<"\n";
#define cout1(a) cout<<a<<"\n";
#define cout2(a,b) cout<<a<<" "<<b<<"\n";
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define setpre(n) cout<<fixed<<setprecision(8)<<n<<"\n";
#define filldp(arr,n,m,k) for(int i=0;i<n;i++){for(int j=0;j<m;j++) arr[i][j]=k;}

#define mod 1000000007
#define mod1 998244353

const int N=1e5+5;

vector<vector<int>> adj;
bool visited[N];
int dis[N];
//int parent[N];

void newgr(){
    adj= vector<vector<int>>(N);
    for(int i=0;i<N;i++){
        dis[i]=0;
        visited[i]=false;
       // parent[i]=-1;
    }
}

long long power(long long x,long long y){  
    long long ans=1;
    x%=mod;
    while(y>0){
        if(y&1) ans=(ans*x)%mod;
        y>>=1;
        x=(x*x)%mod;
    }
    return ans;
}

long long modinv(long long b){ 
    return power(b,mod-2);
}

void dfs(int s){
    visited[s]=true;
    if(adj[s].size()==0){
        return;
    }
    int lt=0;
    for(int u:adj[s]){
        if(!visited[u]){
        dfs(u);
        }
        lt=max(lt,dis[u]);
    }
    dis[s]=lt+1;
}
queue<int> qu;
void bfs(int x){
    visited[x] = true;
    dis[x] = 0;
    qu.push(x);
    while (!qu.empty()) {
    int s = qu.front();
     qu.pop();
    for (auto u : adj[s]) {
    if (visited[u]) continue;
    visited[u] = true;
    dis[u] = dis[s]+1;
    qu.push(u);
    }
    }
}


int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    newgr();
    int u,v;
    for(int i=0;i<m;i++){
        cin>>u>>v;
        adj[u].push_back(v);
    }
    for(int i=1;i<=n;i++){
        if(!visited[i])dfs(i);
    }
    cout1(*max_element(dis+1,dis+n+1));

    return 0;
}

Measured memory_bytes: 8320
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int a[N],max_element=-1,sum=0;
    for(int i=1;i<=N;i++){
        cin >> a[i];
        max_element=max(max_element,a[i]);
        sum+=a[i];
    }
    sum-=max_element;
    if(max_element<sum){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;


int main() {
	int n;
	scanf("%d", &n);
	int c0 = 0, c1 = 0;
	for (int i = 0; i < n; ++i) {
		int x;
		scanf("%d", &x);
		if (x % 2 == 0)
			++c0;
		else
			++c1;
	}
	if (c1 % 2 == 1) {
		cout << "NO\n";
	}
	else {
		cout << "YES\n";
	}
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
//#include <fstream>
//#include <vector>

using namespace std;

int main(int argc, const char * argv[]) {
//    ifstream in("input.txt");
//    cin.rdbuf(in.rdbuf());
    
    int X, A;
    cin >> X >> A;
    
    cout << ((X < A) ? 0 : 10) << endl;
    
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <string> 
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define frn(i,a,n) for(i=a;i<=n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
//#define map map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>
ll power(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return power(x*x,n/2);
    else                             //n is odd
        return x*power(x*x,(n-1)/2);
}

int main()
{
    fastio;
    string s,t;
    cin>>s>>t;
    ll n=s.length();
    ll f=0;
    for(ll i=0;i<n;i++)
    {
        if(s[i]==t[i])
        continue;
        else
        {
            f=1;
            break;
            
        }
    }
    ll n1=t.length();
    if((n1-n==1)&&f==0)
     cout<<"Yes"<<endl;
     else
     cout<<"No"<<endl;
}

Measured memory_bytes: 3616
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
const int inf=1e9;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,a[200005]={},cnt=0,b[200005]={},j,ans=0;
  cin >> n;
  for(int i=1; i<=n; i++) {
    cin >> a[i];
  }
  j=n;
  while(j>0) {
    cnt=0;
    for(int k=j; k<=n; k+=j) {
      cnt+=b[k];
    }
    if(cnt%2!=a[j]) {
      b[j]=1,ans++;
    }
    j--;
  }
  cout << ans << endl;
  for(int i=1; i<=n; i++) {
    if(b[i]) {
      cout << i << " ";
    }
  }
  cout << endl;
}

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
const ll INF = LLONG_MAX / 2;

vector<int> z_algorithm(const string &s) {
    vector<int> prefix(s.size());
    for(int i = 1, j = 0; i < s.size(); i++) {
        if(i + prefix[i - j] < j + prefix[j]) {
            prefix[i] = prefix[i - j];
        } else {
            int k = max(0, j + prefix[j] - i);
            while(i + k < s.size() && s[k] == s[i + k])
                ++k;
            prefix[i] = k;
            j = i;
        }
    }
    prefix[0] = (int)s.size();
    return prefix;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        vector<int> z = z_algorithm(S.substr(i));
        for(int j = 0; j < z.size(); j++) {
            ans = max(ans, min(j, z[j]));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
int a,b,c,d;
while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF){
 if(c>b||a>d) 
 printf ("0\n");
        else if(a<=c&&d<=b){
            printf("%d",d-c);
        }
       else if(c<=a&&b<=d){
           printf("%d",b-a);;
        }
        else if(a<=c&&c<=b&&b<=d){
            printf("%d",b-c);
      }
       else if(c<=a&&a<=d&&d<=b){
         printf("%d",d-a);
         }
     }
     return 0;
 }


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    ll n;cin>>n;
    ll a[n];
    ll c[n+1];rep(i,1,n)c[i]=0;
    rep(i,0,n-1){
        cin>>a[i];
        c[a[i]]++;
    }
    ll sum=0;
    rep(i,1,n){
        sum=sum+(c[i]*(c[i]-1))/2;
    }
    rep(i,0,n-1){
        ll ans;
        ans=sum-(c[a[i]]*(c[a[i]]-1))/2+((c[a[i]]-2)*(c[a[i]]-1))/2;
        cout<<ans<<endl;
    }
    
    
    
    return 0;
}






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

int main(void)
{
    vector<vector<int>> c(3, vector<int>(3));
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> c[i][j];
        }
    }

    int a[3] = {0}, b[3] = {0};
    for (int i = 0; i < 3; i++) { b[i] = c[0][i]; }
    for (int i = 0; i < 3; i++) { a[i] = c[i][0] - b[0]; }
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            if (a[i]+b[j] != c[i][j])
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

using namespace std;

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

bool mv[10][4] = {{1, 0, 0, 0},
				 {0, 1, 0, 0},
				 {0, 0, 1, 0},
				 {0, 0, 0, 1},
				 {1, 0, 1, 0},
				 {1, 0, 0, 1},
				 {0, 1, 1, 0},
				 {0, 1, 0, 1},
				 {1, 1, 0, 0},
				 {0, 0, 1, 1}};

int w, h;
int board[8][8], state[8][8];
bool con[49][49];

bool check()
{
	memset(con, 0, sizeof(con));
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			for (int k = 0; k < 4; k++){
				if (~state[i][j] && mv[state[i][j]][k] && ~state[i + dy[k]][j + dx[k]])
					con[i * w + j][(i + dy[k]) * w + j + dx[k]] = con[(i + dy[k]) * w + j + dx[k]][i * w + j] = true;
			}
		}
	}
	for (int k = 0; k < w * h; k++)
		for (int i = 0; i < w * h; i++)
			for (int j = 0; j < w * h; j++)
				con[i][j] |= (con[i][k] & con[k][j]);
	for (int i = 0; i < w * h; i++){
		for (int j = 0; j < w * h; j++){
			if (~state[i / w][i % w] && ~state[j / w][j % w] && !con[i][j]) return (false);
		}
	}
	return (true);
}

bool check(int npos)
{
	if (npos == w * h){
		return (check());
	}
	
	int ny = npos / w, nx = npos % w;
	if (0) printf("ny = %d nx = %d\n", ny, nx);
	if (!board[ny][nx]) return (check(npos + 1));
	
	for (int i = 4; i < 10; i++){
		state[ny][nx] = i;
		for (int j = 0; j < 4; j++) if (mv[i][j] &&
										(!(0 <= ny + dy[j] && ny + dy[j] < h && 0 <= nx + dx[j] && nx + dx[j] < w) ||
										 !board[ny + dy[j]][nx + dx[j]])) goto ng;
		if (mv[i][1] && !(state[ny - 1][nx] == 0 || state[ny - 1][nx] == 4 || state[ny - 1][nx] == 5 || state[ny - 1][nx] == 8)) goto ng;
		if (ny > 0 && !mv[i][1] && (state[ny - 1][nx] == 0 || state[ny - 1][nx] == 4 || state[ny - 1][nx] == 5 || state[ny - 1][nx] == 8)) goto ng;
		if (mv[i][3] && !(state[ny][nx - 1] == 2 || state[ny][nx - 1] == 4 || state[ny][nx - 1] == 6 || state[ny][nx - 1] == 9)) goto ng;
		if (nx > 0 && !mv[i][3] && (state[ny][nx - 1] == 2 || state[ny][nx - 1] == 4 || state[ny][nx - 1] == 6 || state[ny][nx - 1] == 9)) goto ng;
		if (check(npos + 1)) return (true);
		ng:;
		state[ny][nx] = -1;
	}
	
	return (false);
}

int main()
{
	while (scanf("%d %d", &w, &h) && w){
		int count = 0;
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				scanf("%d", &board[i][j]);
				board[i][j] ^= 1;
				state[i][j] = -1;
				count += board[i][j];
			}
		}
		printf("%s\n", count && check(0) ? "Yes" : "No");
	}
	
	return (0);
}

Measured memory_bytes: 1016
#include <iostream>
#include <cstdio>
#define N 15
using namespace std;

int M = 2e9;
int n, m, X, mn = 2e9, w[N], a[N][N], s[N];
void f(int p, int q) {
	int i;
	if (q >= mn) return;
	if (p == n) {
		for (i = 0; i < m; i++) {
			if (s[i] < X) break;
		}
		if (i == m) {
			mn = q;
		}
		return;
	}
	f(p + 1, q);
	for (i =0; i < m; i++) {
		s[i] += a[p][i];
	}
	f(p + 1, q + w[p]);
	for (i =0; i < m; i++) {
		s[i] -= a[p][i];
	}
}

int main()
{
	int i, j;
	cin >> n >> m >> X;
	for (i = 0; i < n; i++) {
		scanf ("%d", &w[i]);
		for (j = 0; j < m; j++) {
			scanf ("%d", &a[i][j]);
		}
	}
	mn = M;
	f(0, 0);
	if (mn == M) cout << -1 << endl;
	else cout << mn << endl;
    return 0;
}


Measured memory_bytes: 3728
ab=input().rstrip().split(" ")
a=int(ab[0])
b=int(ab[1])
string=""
if a>b:
    for i in range(a):
        string=string+str(b)
elif a==b:
    for i in range(a):
        string=string+str(a)
elif a<b:
    for i in range(b):
        string=string+str(a)
print(string)

Measured memory_bytes: 3060
import sys
from collections import deque

n, m, *ab = map(int, sys.stdin.read().split())
ab = zip(*[iter(ab)] * 2)
graph = [[] for _ in range(n)]
for a, b in ab:
    a -= 1; b -= 1
    graph[a].append(b)
    graph[b].append(a)

def main():
    parent = [None] * n 
    parent[0] = 0
    queue = deque([0])
    while queue:
        x = queue.popleft()
        for y in graph[x]:
            if parent[y] is not None: continue 
            parent[y] = x
            queue.append(y)

    if None in parent:
        print('No')
    else:
        print('Yes')
        for i in range(1, n):
            print(parent[i] + 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 54072
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s, t;cin>>s>>t;
int a,b;cin>>a>>b;
string u;cin>>u;
if (u==s){
a-=1;
}
if(u==t){
b-=1;
}
cout<<a<<" "<<b;

 return 0;
}


Measured memory_bytes: 256
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    ab = [list(map(lambda x: int(x) - 1, readline().split())) for _ in range(n-1)]
    tmd = collections.defaultdict(list)
    tmdd = collections.defaultdict(int)
    m_in = 0
    m_no = -1
    for a, b in ab:
        tmd[a] += [b]
        tmd[b] += [a]
        tmdd[a] += 1
        tmdd[b] += 1
    cnt = 0
    for k, v in tmdd.items():
        if v > m_in:
            m_in = v
            m_no = k
        elif v == m_in:
            cnt += 1
    m_in = m_in + 1 if cnt == len(tmd) - 1 and len(tmd) == 3 else m_in

    ql = [[0, m_no]]
    ql = collections.deque(ql)
    fq = collections.defaultdict(list)
    fq[m_no]
    aq = collections.defaultdict(int)
    while True:
        if len(ql) != 0:
            cost, tmp = ql.popleft()
            ls = []
            limit = tmdd[tmp]
            for i in range(1, m_in + 1):
                if i != cost:
                    ls.append(i)
                if len(ls) >= limit:
                    break
            for tmv in tmd[tmp]:
                if tmv not in fq:
                    p = ls.pop()
                    ql.append([p, tmv])
                    fq[tmv]
                    aq[tmp, tmv] = p
                    aq[tmv, tmp] = p
        else:
            break
    print(m_in)
    for a, b in ab:
        print(aq[a, b])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 125308
n = int(input())
c = 0
xa = 0
bx = 0
ba = 0
for _ in range(n):
  si = str(input())
  l = len(si)
  s1 = si[0]
  s2 = si[-1]
  if s1=="B":
    if s2=="A":
      ba += 1
    else:
      bx += 1
  elif s2 == "A":
    xa += 1
  for i in range(l-1):
    if si[i]=="A" and si[i+1]=="B":
      c += 1
if ba == 0:
  print(c+min(bx,xa))
  exit()
if bx == 0:
  if  xa == 0:
    print(ba-1+c)
    exit()
  else:
    print(ba+c)
    exit()
if xa == 0:
  print(ba+c)
  exit()
print(min(bx,xa)+ba+c)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,x,y;
  cin >> n >> x >> y;
  int t=0;
  set<P> s;
  s.in(P(x,y));
  while(1) {
    if(!t) {
      if(x<y) {
        if(x+1<y) x++;
        else if(!x) {
          pr("Borys");
          return;
        } else x--;
      } else {
        if(y<x-1) x--;
        else if(x==n) {
          pr("Borys");
          return;
        } else x++;
      }
    } else {
      if(y<x) {
        if(y+1<x) y++;
        else if(!y) {
          pr("Alice");
          return;
        } else y--;
      } else {
        if(x<y-1) y--;
        else if(y==n) {
          pr("Alice");
          return;
        } else y++;
      }
    }
    if(s.count(P(x,y))) {
      pr("Draw");
      return;
    }
    s.in(P(x,y));
    t^=1;
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
a, b, c, d = map(int, input().split())

if a==1 or a==9 or a==7 or a==4:
	if b==1 or b==9 or b==7 or b==4:
			if c==1 or c==9 or c==7 or c==4:
					if d==1 or d==9 or d==7 or d==4:
						s = a+b+c+d
						if s==21:
							print('YES')
						else:
							print('NO')
					else:
						print('NO')
			else:
				print('NO')
	else:
		print('NO')
else:
	print('NO')

Measured memory_bytes: 3064
N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())), reverse=True)

def check(X):
    i = N-1
    n = 0
    for ax in A:
        while i>=0 and A[i]+ax<X: i-=1
        n+=i+1
    return n>=M

# check(X) := 幸福度がX以上上がる握手をすべて行うとき、握手の回数がM以上になるか？
# check(X)==True となる最大のXを二分探索で求める
min_ng = 10**6
max_ok = 0
while min_ng-max_ok>1:
    tgt = (min_ng+max_ok)//2
    if check(tgt):
        max_ok = tgt
    else:
        min_ng = tgt

i = N-1
k = sum(A)
ans = 0
n = 0
for ax in A:
    while i>=0 and A[i]+ax<max_ok:
        k-=A[i]
        i-=1
    ans += k + ax*(i+1)
    n += i+1
print(ans-max_ok*(n-M)) # Mを超えた分を引く

Measured memory_bytes: 14268