akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

// sort ------------------------------------------------------------

type int64Array []int64

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

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

func main() {
	s := readString()
	var b byte
	for i := range s {
		if s[i] == b {
			fmt.Println("Bad")
			return
		}
		b = s[i]
	}

	fmt.Println("Good")
}


Measured memory_bytes: 640
#include<stdio.h>
#define MAX 100005
#define NIL -1

/*
 p: parent
 l: left-child
 r: right sibling
 */
struct Node{
  int p, l, r;
};
struct Node T[MAX]; // Tree
int n;
void preorder(int u){
  printf(" %d",u);
  if(T[u].l!=NIL) preorder(T[u].l);
  if(T[u].r!=NIL) preorder(T[u].r);
}

void inorder(int u){
    if (T[u].l!=NIL) inorder(T[u].l);
    printf(" %d",u);
    if (T[u].r!=NIL) inorder(T[u].r);
}

void postorder(int u){
    if (T[u].l!=NIL) postorder(T[u].l);
    if (T[u].r!=NIL) postorder(T[u].r);
    printf(" %d",u);
}

void print(int u){
  printf("Preorder\n");
  preorder(u);
  printf("\n");
  printf("Inorder\n");
  inorder(u);
  printf("\n");
  printf("Postorder\n");
  postorder(u);
  printf("\n");
}

int main(){
  int i, j, d, v, c, l,tmp;
  
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r = NIL;
  }
  
  for ( i = 0; i < n; i++ ){
    scanf("%d %d %d", &v, &d, &c);
    T[v].l = d;
    T[v].r = c;
    T[d].p = T[c].p = v;
  }
  for ( i = 0; i < n; i++ ){
    if(T[i].p==NIL) print(i);
  }
  return 0;
}

Measured memory_bytes: 620
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
#include <ctime>
#include <functional>
#include <cassert>
using namespace std;
const double pi=3.141592653589793238;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> l(n);
    for(int i=0; i<n; i++) cin >> l[i];
    sort(l.begin(),l.end());
    long long ans=0;
    for(int i=n-1; i>n-k-1; i--){
        ans+=l[i];
    }
    cout << ans << endl;
}



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

using ll = long long;
#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, n, m) for(int (i)=(n); (i)<(m); ++i)
constexpr ll INF = 1LL << 60;
constexpr int mod = 1e9+7;

int N, K;
vector<vector<int>> g;
vector<bool> homon;
ll ans = 1;
void dfs(int v){
  homon[v] = true;
  int cnt = 1;
  if(v != 0) cnt++;
  for(auto nv : g[v]){
    if(homon[nv]) continue;
    ans *= K-cnt;
    ans %= mod;
    dfs(nv);
    cnt++;
  }
}
int main(){
  cin >> N >> K;
  g.resize(N);
  REP(i, N-1){
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  homon.resize(N);
  ans *= K;
  dfs(0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9216
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0157
{
    public class Matryoshka
    {
        public int Height { get; }
        public int Radius { get; }
        public Matryoshka(int[] items) { Height = items[0]; Radius = items[1]; }
    }

    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                List<Matryoshka> mats = new List<Matryoshka>();

                int n = RInt(); if (n == 0) break;
                for (int i = 0 ; i < n ; i++) mats.Add(new Matryoshka(RIntAr()));

                int m = RInt();
                for (int i = 0 ; i < m ; i++) mats.Add(new Matryoshka(RIntAr()));

                List<int> rads = mats.OrderBy(x => x.Height).ThenByDescending(x => x.Radius).Select(x => x.Radius).ToList();
                Console.WriteLine(LIS(rads));
            }
        }

        private static int LIS(List<int> rads)
        {
            int[] dp = new int[rads.Count()];
            for (int i = 0 ; i < dp.Count() ; i++) { dp[i] = int.MaxValue; }
            for (int i = 0 ; i < rads.Count() ; i++)
            {
                dp[LowerBound(dp, rads[i])] = rads[i];
            }

            return LowerBound(dp, int.MaxValue);
        }

        public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer)
        {
            int low = start;
            int high = end;
            int mid;
            while (low < high)
            {
                mid = ((high - low) >> 1) + low;
                if (comparer.Compare(arr[mid], value) < 0)
                    low = mid + 1;
                else
                    high = mid;
            }
            return low;
        }

        public static int LowerBound<T>(T[] arr, T value) where T : IComparable
        {
            return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default);
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 14244
/*

強連結成分アルゴリズムアルゴリズム

input:有向グラフG
output:各店の属する強連結成分を表す関数comp:V(G)->N

*/

#include <vector>
#include <functional>
using namespace std;

vector<int> scc(const vector<vector<int>>& G){
    vector<int> comp(G.size(),-1);
    vector<int> R(G.size(),0);
    int N = 0;
    vector<int> psi(G.size(),-1);
    vector<int> psi_inv(G.size(),-1);

    function<void(int)> visit1 = [&](int v){
        R[v] = 1;
        for(int w : G[v]){
            if(R[w] == 0) visit1(w);
        }
        psi[v] = N;
        psi_inv[N] = v;
        N = N + 1;
    };

    for(int i = 0;i < G.size();i++){
        if(R[i] == 0) visit1(i);
    }

    R.assign(G.size(),0);
    int K = 0;

    vector<vector<int>> rev_G(G.size());

    for(int v = 0;v < G.size();v++){
        for(int to : G[v]) rev_G[to].push_back(v);
    }

    function<void(int)> visit2 = [&](int v){
        R[v] = 1;
        for(int w : rev_G[v]){
            if(R[w] == 0) visit2(w);
        }
        comp[v] = K;
    };

    for(int i = G.size() - 1;i >= 0;i--){
        if(R[psi_inv[i]] == 0){
            visit2(psi_inv[i]);
            K = K + 1;
        }
    }
    return comp;
}

#include <iostream>

int main(){
    int v;
    int e;
    cin >> v >> e;
    vector<vector<int>> G(v);
    for(int i = 0;i < e;i++){
        int x,y;
        cin >> x >> y;
        G[x].push_back(y);
    
    }

    auto res = scc(G);

    int q;
    cin >> q;

    for(int i = 0;i < q;i++){
        int x,y;
        cin >> x >> y;
        cout << (res[x] == res[y]) << endl;
    }
}


Measured memory_bytes: 4716
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class EFriendships {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int max = (n - 1) * (n - 2) / 2;

            if (k > max) {
                out.println(-1);
            } else {
                out.println(n - 1/*ウニの分*/ + (max - k));
                // 1を核としたウニをつくる
                for (int i = 2; i <= n; i++) {
                    out.println(1 + " " + i);
                }
                for (int i = 2; i <= n; i++) {
                    for (int j = i + 1; j <= n; j++) {
                        if (k == max) return;
                        max--;
                        out.println(i + " " + j);
                    }
                }
            }
        }

    }
}



Measured memory_bytes: 23252
#include<cstdio>
using namespace std;
int a,b;
int main(){
    scanf("%d%d",&a,&b);
    if(a>0)puts("Positive");             
    else if(b>=0)puts("Zero");             
    else if((a&1)^(b&1))puts("Positive");  
    else puts("Negative");
}

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

#ifdef DEBUG
#define debug(...) __VA_ARGS__
#else
#define endl '\n'
#define debug(...)
#endif
#define debugf(...) debug(printf(__VA_ARGS__))

const int N = 1e5 + 5;

bool eq(const vector<int>& a, const vector<int>& b) {
    int n = a.size();
    for (int i = 0; i < n; i++) {
        if (a[i] != b[i])
            return false;
    }
    return true;
}

int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;
    vector<int> p(n), q(n);
    for (auto& x : p) cin >> x;
    for (auto& x : q) cin >> x;

    vector<int> a(n);
    iota(a.begin(), a.end(), 1);

    int pi = 0, qi = 0;

    int i = 0;
    do {
        if (eq(a, p)) pi = i;
        if (eq(a, q)) qi = i;
        i++;
    } while (next_permutation(a.begin(), a.end()));

    cout << abs(pi - qi);

    return 0;
%>

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,k,i;
    cin >>a>>b>>k;
    for(i=min(a,b);i>0;i--){
        if(a%i==0&&b%i==0){
            k--;
          if(k==0){
            cout << i<<endl;
            break;
          }
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll unsigned long long int
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;

main(){
    ll n=in();
    ll x=in();
    vector<ll> a;
    rep(i,n){
        a.pb(lin());
    }
    vecll r;
    r.pb(0ll);
    rep(i,n){
        r.pb(r[i]+a[i]);
    }
    ll M=-1;
    rep2(i,1,n){
        //cout<<"calculating "<<i<<endl;
        ll res=n%i;
        ll d=n/i;
        ll tmp=(d*2ll+3ll)*r[res];
        for(ll j=res;j<n;j+=i){
            if(j+i==n){
            tmp+=(r[j+i]-r[j])*5ll;
            //cout<<" "<<r[j+i]-r[j]<<" "<<5<<endl;
            }
            else{
            tmp+=(r[j+i]-r[j])*(d*2+1);
            //cout<<" "<<r[j+i]-r[j]<<" "<<d*2+1<<endl;
            }
            d--;
        }
        tmp+=(n+i)*x;
        if(M==-1)M=tmp;
        M=min(M,tmp);
        //cout<<tmp<<endl;
    }
    cout<<M<<endl;
}



Measured memory_bytes: 4848
import sys
import numpy as np
def main():
    x = int(sys.stdin.readline().rstrip())
    
    if x < 100:
        print(0)
        sys.exit()
    if 100 <= x <= 105:
        print(1)
        sys.exit()

    dp = np.zeros_like(np.arange(x+1), dtype=bool)
    dp[100:106] = True
    for i in range(106, x+1):
        dp[i] =  np.any(dp[i-105:i-99])

    print(dp[x] & 1)

if __name__ == '__main__':
    main()

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

int main(){
  int64_t a;
  string b;
  cin >> a >> b;
  if (a == 0) {
    cout << 0 << endl;
    return 0;
  }

  bool afterFix = false;
  int badj = 0;
  int afterDiv = 1;
  for (int i = 0; i < (int)b.length(); ++i) {
    if (b[i] == '.') {
      afterFix = true;
      continue;
    }
    if (afterFix) {
      afterDiv *= 10;
    }
    badj = badj * 10 + (b[i] - '0');
  }
  cout << (a * badj) / afterDiv << endl;

  return 0;
}


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

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

using namespace std;

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

	int max = 0;

	int counter = 0;
	
	for(int i = 0; i < s.size(); ++i){
		bool f = (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T');

		if(f){
			++counter;
			if(max < counter) max = counter;
		}
		else counter = 0;
	}

	cout << max << "\n";
}

Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int D; std::cin >> D;
    std::vector<int> c(26), t(D);
    std::vector<std::vector<int>> s(D, std::vector<int>(26));
    for(int i(0); i < 26; ++i) std::cin >> c[i];
    for(int i(0); i < D; ++i){
        for(int j(0); j < 26; ++j) std::cin >> s[i][j];
    }

    for(int i(0); i < D; ++i){
        std::cin >> t[i];
        --t[i];
    }
    std::vector<long long> v(D+1, 0);
    std::vector<int> last(26, 0);
    for(int i(1); i <= D; ++i){
        last[t[i-1]] = i;
        long long dcr(0);
        for(int j(0); j < 26; ++j){
            dcr += c[j] * (i - last[j]);
        }
        v[i] = v[i-1] + s[i-1][t[i-1]] - dcr;
        std::cout << v[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 3648
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.regex.Pattern
import java.util.{ArrayList, Collections, Comparator, List => JList}

import scala.math._
import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val t = input
    t.toSeq.foldRight(Vector.empty[String]){(c, list) =>
      if (c == '?') "D" +: list else c.toString +: list
    }.mkString
  }

  def divisors(n: Long): Vector[Long] = {
    val halfList = (1 to sqrt(n).toInt).toVector.filter(_ % n == 0).map(_.toLong)
    val reversedList = if (sqrt(n).floor == sqrt(n)) halfList.reverse.tail.map(n/_) else halfList.reverse.map(n/_)
    halfList ++ reversedList
  }

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """PD?D??P""".stripMargin -> """PDPDPDP
                                   |
                                        |""".stripMargin,
    """P?P?""".stripMargin -> """PDPD
                                         |""".stripMargin
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 67980
function main(input) {
  const a1 = parseInt(input.split(" ")[0], 10);
  const a2 = parseInt(input.split(" ")[1], 10);
  const a3 = parseInt(input.split(" ")[2], 10);
  var arr=[a1,a2,a3]
  var max=Math.max.apply(null,arr );
  var min=Math.min.apply(null, arr);
  console.log(max-min);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include<bits/stdc++.h>
#define INF 0x7fffffff
using namespace std;
typedef long long ll;
int a,b;
int main()
{
    cin>>a>>b;
    if(a+b==15)
        puts("+");
    else
        if(a*b==15)
            puts("*");
        else
            puts("x");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char t, start[100005];
bool flag = false;
int Q, t1, t2;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> start;
	list<char> L(start, start + strlen(start));
	cin >> Q;
	while (Q--)
	{
		cin >> t1;
		if (t1 == 1)
		{
			flag = !flag;
		}
		else
		{
			cin >> t2 >> t;
			if (flag)
			{
				if (t2 == 1)
				{
					L.push_back(t);
				}
				else
				{
					L.push_front(t);
				}
			}
			else
			{
				if (t2 == 1)
				{
					L.push_front(t);
				}
				else
				{
					L.push_back(t);
				}
			}
		}
	}
	if (flag)
	{
		for (list<char>::reverse_iterator rit = L.rbegin(); rit != L.rend(); ++rit)
			cout << *rit;
		cout << '\n';
	}
	else
	{
		for (list<char>::iterator it = L.begin(); it != L.end(); ++it)
		{
			cout << *it;
		}
	}
	cout << '\n';
	return 0;
}

Measured memory_bytes: 9984
#include <iostream>
#include <string>
#include <cstdio>
#include <sstream>
#include <vector>
using namespace std;

int main(int argc, char * argv[]) {
    int n,l;
    cin >> n >> l;
    string s;
    vector<string> str;
    
    int lenth = 0;
    while (lenth != n) {
        cin >> s;
        if(s.length()!= l) return 0;
        str.push_back(s);
        ++lenth;
    }
    
    string ss;
    for(int i = 0;i!=n;i++){
        for(int j=0;j!=n-1;j++){
            if(str[j] > str[j+1]){
                s = str[j+1];
                str[j+1] = str[j];
                str[j] = s;
            }
        }
    }
    
    for(int i=0;i!=n;i++){
        ss += str[i];
    }
    cout << ss << endl;
    return 0;
    
}

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

using namespace std;

long long solve(long long N, const vector<pair<int,int>>& value){
    vector<long long> dp(N+1, 0);
    for(int i=0;i<N;i++){
        dp[i+1] = max(dp[i+1], dp[i]+1);
        for(auto& p : value){
            if(i+p.first <= N) dp[i+p.first] = max(dp[i+p.first], dp[i] + p.second);
        }
    }
    return dp.back();
}

int main(){
    int N;
    while(cin >> N){
        int ga, sa, ba, gb, sb, bb;
        cin >> ga >> sa >> ba;
        cin >> gb >> sb >> bb;
        vector<pair<int,int>> value;
        value.emplace_back(ga, gb);
        value.emplace_back(sa, sb);
        value.emplace_back(ba, bb);
        N = solve(N, value);
        for(auto& p : value) swap(p.first, p.second);
        cout << solve(N, value) << endl;
    }
}

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

using namespace std;
int n,q,len;
int dep[100005];
int dis[100005];
int anc[100005][30];
int fel[100005],ccnt[100005],csums[100005];
int eul[200005];
vector<pair<int,int>> ct[100005];
vector<int> csum[100005];

struct it{
    int f,s,t;
    it(int ff,int ss,int tt){
        f=ff;s=ss;t=tt;
    }
};

vector<it> rad[100005];
vector<pair<int,int>> cr[100005];

void dfs(int now,int from,int ds)
{

    eul[++len] = now;
    fel[now] = len;
    dis[now] = ds;

    dep[now] = dep[from]+1;
    anc[now][0] = from;

    for(int i=1;i<20;++i)
    {
        anc[now][i] = anc[anc[now][i-1]][i-1];
    }

    for(int i=0;i<rad[now].size();++i)
    {
        if(rad[now][i].f==from) continue;
        ct[rad[now][i].s].push_back(pair<int,int>(len+1,++ccnt[rad[now][i].s]));
        csum[rad[now][i].s].push_back(csums[rad[now][i].s]+=rad[now][i].t);
        dfs(rad[now][i].f,now,ds+rad[now][i].t);
        eul[++len] = now;
        ct[rad[now][i].s].push_back(pair<int,int>(len,--ccnt[rad[now][i].s]));
        csum[rad[now][i].s].push_back(csums[rad[now][i].s]-=rad[now][i].t);
    }
}

int lca(int u,int v)
{
    if(dep[u]<dep[v])swap(u,v);
    int tmp = dep[u] - dep[v];
    for(int j=0;tmp;++j,tmp>>=1)
        if(tmp&1) u = anc[u][j];

    for(int i=19;i>=0&&u!=v;--i)
    {
        if(anc[u][i]!=anc[v][i])
        {
            u = anc[u][i];
            v = anc[v][i];
        }
    }
    if(u!=v)
    return anc[u][0];
    return u;
}

bool cmp(const pair<int,int> a,const pair<int,int> b)
{
    return a.first < b.first;
}

int gcost(int u,int x,int y)
{
    int pos = upper_bound(ct[x].begin(),ct[x].end(),
                          pair<int,int>(fel[u],0),cmp) - ct[x].begin();
    --pos;
    return dis[u] - csum[x][pos] + ct[x][pos].second*y;
}

int main()
{
    scanf("%d%d",&n,&q);
    int a,b,c,d;
    for(int i=1;i<n;++i)
    {
        scanf("%d%d%d%d",&a,&b,&c,&d);
        rad[a].push_back(it(b,c,d));
        rad[b].push_back(it(a,c,d));
    }

    for(int i=0;i<=100002;++i)
    {
        ct[i].push_back(pair<int,int>(-1,0));
        csum[i].push_back(0);
    }

    dfs(1,0,0);

    int x,y,u,v;
    for(int i=0;i<q;++i)
    {
        scanf("%d%d%d%d",&x,&y,&u,&v);
        int l = lca(u,v);
        printf("%d\n",gcost(u,x,y)+gcost(v,x,y)-2*gcost(l,x,y));
    }
    return 0;
}


Measured memory_bytes: 44276
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl '\n'
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
  int n;
  cin>>n;
  bool ok=false;
  for(int i=0;i<=n;i++){
	  for(int j=0;j<=n;j++){
		   if(4*i+7*j==n){
			    ok=true;
			    break; 
			  } 
		 }
	 }
	cout<<(ok?"Yes":"No")<<endl;	
}
int32_t main(){
  IOS;
  solve();
  //debug();
 #ifdef LOCAL_DEFINE
 cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
 #endif	
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
using namespace std;

int main(){
	int S1, S2;
	while(true){
		int ma_idx, ma_s = 0;
		for(int i = 0; i < 5; i++){
			cin >> S1 >> S2;
			if(S1 == 0 && S2 == 0) return 0;
			if(ma_s < S1 + S2){
				ma_idx = i; ma_s = S1 + S2;
			}
		}
		printf("%c %d\n", 'A' + ma_idx, ma_s );
	}
	return 0;
}

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

using namespace std;

string s, t;
int dp[3003][3003];
int n, m;
// vector<pair<int, int> > v;
pair<int, int> v[3003][3003];
string str;

int get(int a, int b) {
    if (a < 0 || b < 0) {
        return 0;
    }

    if (dp[a][b] != -1) return dp[a][b];

    int ans = dp[a][b];
    if (s[a] == t[b]) {
        ans = 1 + get(a-1, b-1);
    }
    ans = max(ans, get(a-1, b));
    ans = max(ans, get(a, b-1));
    // if (a ==1 && b == 1) {
    //     cout<<"s: "<<s[a]<<" t: "<<t[b]<<endl;
    // }
    dp[a][b] = ans;
    if (dp[a][b] == 1 + get(a-1, b-1) && s[a] == t[b]) v[a][b] = make_pair(a-1, b-1);
    else if (dp[a][b] == get(a-1 ,b))   v[a][b] = make_pair(a-1, b);
    else  v[a][b] = make_pair(a, b-1);

    // if (dp[a][b] == 1 + get(a-1, b-1) && s[a] == t[b])  str += s[a];

    return dp[a][b];
}

int main(void) {
    cin>>s>>t;
    memset(dp, -1, sizeof(dp));
    n = s.size();
    m = t.size();
    get(n-1, m-1);

    // for (int i = 0; i < n; ++i) {
    //     for (int j = 0; j < m; ++j) {
    //         cout<<v[i][j].first<<" "<<v[i][j].second<<"  ";
    //     }
    //     cout<<endl;
    // }
    // for(int i = 0; i < v.size(); ++i) {
    //     cout<<v[i].first<<" "<<v[i].second<<endl;
    // }    
    // cout<<str;
    string finalans = "";
    int x = v[n-1][m-1].first;
    int y = v[n-1][m-1].second;
    if (s[n-1] == t[m-1])   finalans = s[n-1];
    while(x >= 0 && y >= 0) {
        if (s[x] == t[y]) finalans += s[x];
        pair<int, int> other = v[x][y];
        if (other.first ==x && other.second == y) {
            break;
        }
        x = other.first;
        y = other.second;
    }

    reverse(finalans.begin(), finalans.end());
    cout<<finalans;

    return 0;
}



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

int len;
char s[110], code[110];

int main() {
	scanf("%s", s);
	for (int i = 0; i < strlen(s); ++i) {
		if (s[i] == 'B' && len) --len;
		else if (s[i] == '0' || s[i] == '1') code[++len] = s[i];
	}
	for (int i = 1; i <= len; ++i) printf("%c", code[i]);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 256
/**
 * author  : UshanGhosh
 * created : 2020-09-19 17:42:25
**/ 

#include<bits/stdc++.h>
using namespace std;

#define    ll      long long
#define    pii     pair<int,int>
#define    vii     vector<int>
#define    vcc     vector<char>
#define    pll     pair<long long, long long>
#define    mem     memset
#define    sof     sizeof
#define    co1     __builtin_popcountll
#define    PB      push_back
#define    UB      upper_bound
#define    LB      lower_bound
#define    MP      make_pair
#define    TS      to_string
#define    F       first
#define    S       second
#define    pi      acos(-1)
#define    mod     (int)1e9+7
#define    inf     (long long)1e18
#define    endl    '\n'

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long a,b,c,d,e,f,i,j,k,m,n,o,x,y;
    cin>>a>>b;
    ll ans = 0;
    for(i=a;i<=b;i++){
        string s = TS(i);
        ll err = 0;
        for(j=0;j<2;j++){
            if(s[j]!=s[4-j]) err++;
        }
        if(!err) ans++;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 3708
#include <stdio.h>
int main()
{   int n,a,b,f=0,p=0;
    scanf("%d%d%d",&n,&a,&b);
    char s[n+1];
    scanf("%s",s);
    for(int i=0;i<n;i++){
        if(s[i]=='c'){
            printf("No\n");
        }
        if(s[i]=='a'){
            if(p<a+b){
                printf("Yes\n");
                p++;
            }else{
                printf("No\n");
            }
        }
        if(s[i]=='b'){
            if(p<a+b&&f<b){
                printf("Yes\n");
                p++;
                f++;
            }else{
                printf("No\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int N;
int L[2000];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    rep(i,N) cin >> L[i];
    sort(L, L+N);
    ll ans = 0;
    rep(i,N) {
        for (int j = i+1; j < N; j++) {
            ans += upper_bound(L, L+N, L[i]+L[j]-1)-(L+j+1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <math.h>
#include <algorithm>
#include <string.h>

using namespace std;

int main(void){
    char s[10];
    char year[5];
    char month[3];
    char day[3];
    int y,m,d,out;
    for(int i = 0; i < 10 ; i++){
        cin >> s[i];
    }
    y = atoi(strtok(s,"/"));
    m = atoi(strtok(NULL,"/"));
    d = atoi(strtok(NULL,"/"));
    if(y < 2019){
        out = 1;
    }else if (y > 2019){
        out = 0;
    }else if(m < 5){
        out = 1;
    }else{
        out = 0;
    }
    if(out == 1){
        cout << "Heisei" << endl;
    }
    else{
        cout << "TBD" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define abu ios_base::sync_with_stdio(0)
#define said cin.tie(0)
using namespace std;
ll const MOD = 1000000007;

void yes(){
    cout<<"YES"<<'\n';
}

void no(){
    cout<<"NO"<<'\n';
}

ll fact(int n){
    ll ans = 1;
    for(int i=2;i<=n;i++){
        ans = (ans*i)%MOD;
    }

    return ans;
}

ll powM(int n, int x){
    if(x==0){
        return 1;
    }
    if(x==1){
        return n%MOD;
    }

    if(x%2==0){
        ll a = powM(n,x/2);
        return (a*a)%MOD;
    }else{
        return (n*powM(n,x-1))%MOD;
    }
}

ll C(int n, int k){
    return (fact(n) * powM((fact(k)*fact(n-k))%MOD,MOD-2))%MOD;
}

ll A(int n, int k){
    return (fact(n) * powM(fact(n-k)%MOD,MOD-2))%MOD;
}



void solve(){
    int n;
    cin>>n;
    vector<double> dp(n+1);
    dp[0] = 1;
    for(int i=0;i<n;i++){
        double p;
        cin>>p;

        for(int tr = i+1;tr>=0;tr--){
            if(tr>0)
                dp[tr] = dp[tr-1] * p + dp[tr]*(1-p);
            else
                dp[tr] = dp[tr]*(1-p);
        }
    }
    double ans = 0;
    for(int i=n/2+1;i<=n;i++){
        ans+=dp[i];
    }
    printf("%0.10f\n",ans);
}

int main(){
    abu;
    said;
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 256
n,x = map(int,input().split())

a = [int(i) for i in input().split()]

ans = max(a[0] - x,0)
tmp = min(a[0],x)

for i in range(1,n):
    if tmp + a[i] > x:
        ans += tmp + a[i] - x
        a[i] = x - tmp
    tmp = a[i]
    #print(ans,a[i])
        
print(ans)

Measured memory_bytes: 14540
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, q; cin >> n;
	ll ans = 0;
	vector<ll> freq(1e5 + 1);
	for(int i = 0; i < n; i++)
	{
		int a; cin >> a;
		freq[a]++;
		ans += a;
	}
	cin >> q;
	while(q--)
	{
		ll b, c; cin >> b >> c;
		ans -= freq[b] * b;
		ans += freq[b] * c;
		freq[c] += freq[b];
		freq[b] = 0;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3984
#include "bits/stdc++.h"
using namespace std;
int main(){
    int H, W;
    cin >> H >> W;
    string s;
    vector<vector<char> > data(H, vector<char> (W));
    for(int i = 0; i < H; i++){
        cin >> s;
        for(int j = 0; j < W; j++){
            data.at(i).at(j) = s.at(j);
        }
    }
    vector<vector<char> > newdata(H * 2, vector<char> (W));
    for(int i = 0; i < 2 * H; i++){
        for(int j = 0; j < W; j++){
            newdata.at(i).at(j) = data.at(i / 2).at(j);
        }
    }
    for(int i = 0; i < 2 * H; i++){
        for(int j = 0; j < W; j++){
            if(j != W - 1)
            cout << newdata.at(i).at(j);
            else 
            cout << newdata.at(i).at(j) << endl;
        }
    }
    return 0; 
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(1000000)

import bisect
import math
import collections
import heapq


def solve(L, R, d ):
    c = 0
    for i in range(L, R+1):
        if i % d == 0:
            c += 1
    return c


if __name__ == "__main__":
    L, R, d = tuple(map(int, input().split(" ")))
    print(solve(L, R, d ))


Measured memory_bytes: 9456
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,f;
int res1=0,res2=0;
int main(){
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	for(int ia=0;ia<=f/(100*a);++ia){
		for(int ib=0;ib<=(f-ia*100*a)/(100*b);++ib){
			int ff=f-ia*100*a-ib*100*b,t=ia*a+ib*b;
			// cout<<ia<<' '<<ib<<' '<<ff<<' '<<t<<endl;
			for(int ic=0;ic*c<=ff&&ic*c<=t*e;++ic){
				for(int id=0;id*d<=ff-ic*c&&ic*c+id*d<=t*e;++id){
					if(ia==0&&ib==0)continue;
					// cout<<"!!!"<<endl;
					if(res1==0)res1=ic*c+id*d+t*100,res2=ic*c+id*d;
					else if((res2*1.0)/(1.0*res1)<(1.0*(id*d+ic*c))/(1.0*(100*t+ic*c+id*d)))res1=ic*c+id*d+t*100,res2=ic*c+id*d;
				}
			}
		}
	}
	printf("%d %d",res1,res2);
	return 0;
}

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

const int maxn = 1e6+10;

int a[maxn];


long long get(int x) {
	return 1ll * (x-1) * x / 2;
}

int main() {
//	freopen("inp.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >>s ;
	int n= s.length();
	
	long long res = 0;
	for(int i=0;i<n;i++) {
		int j = i;
		while (j < n && s[j] == '<') {
			j ++;
		}
		
		int len = j - i;
		int i1 = j;
		while (j < n && s[j] == '>') {
			j ++;
		}
		int len1 = j - i1;
//		cerr << len <<" " << len1 << endl;
		res += get(min(len, len1)) + get(max(len, len1) + 1);
		i = j - 1;
	}
	
	cout << res;
	return 0;
}


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

int main(){
  int64_t N, C;
  cin >> N >> C;
  vector<vector<int64_t>> A(N,vector<int64_t>(2));
  vector<vector<int64_t>> B(N,vector<int64_t>(2));
  for(int i=0; i<N; i++){
    for(int j=0; j<2; j++){
      cin >> A.at(i).at(j);
      B.at(i).at(j) = A.at(i).at(j);
    }
  }
  
  int64_t A_pos = 0;
  int64_t A_MAX = 0;
  int64_t B_pos = 0;
  int64_t B_MAX = 0;
  
  vector<int64_t> A_sum(N,0);
  vector<int64_t> B_sum(N,0);
  vector<int64_t> A_good(N,0);
  vector<int64_t> B_good(N,0);
  
  
  for(int i=0; i<N; i++){
    if(i == 0){
      A_sum.at(i) = A.at(i).at(1);
    }
    else{
      A_sum.at(i) = A_sum.at(i-1) + A.at(i).at(1);
    }
    if(A_sum.at(i) - A.at(i).at(0) >= A_MAX){
      A_pos = i;
      A_MAX = A_sum.at(i) - A.at(i).at(0);
    }
    A_good.at(i) = A_MAX;
  }
  for(int i=N-1; i>=0; i--){
    if(i == N-1){
      B_sum.at(i) = B.at(i).at(1);
    }
    else{
      B_sum.at(i) = B_sum.at(i+1) + B.at(i).at(1);
    }
    if(B_sum.at(i)  - (C - B.at(i).at(0)) >= B_MAX){
      B_pos = i;
      B_MAX = B_sum.at(i) - (C - B.at(i).at(0));
    }
    B_good.at(i) = B_MAX;
  }
  
  int64_t ans = max(A_MAX, B_MAX);
  for(int64_t i=0; i<=A_pos; i++){
    if(A_pos == N-1 && i == N-1){
      continue;
    }
    ans = max(ans,A_sum.at(i) - A.at(i).at(0)*2 + B_good.at(min(i+1,N-1)));
  }
  for(int64_t i=N-1; i>=B_pos; i--){
    if(B_pos == 0 && i == 0){
      continue;
    }
    ans = max(ans,B_sum.at(i) - (C - B.at(i).at(0))*2 + A_good.at(max(int64_t(0),i-1)));
  }
  cout << ans << endl;
  
}

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

using namespace std;

string s;

int shrinking(char c) {
  int counter = 0;
  bool loop = true;
  string str = s;
  while (true) {
    loop = false;
    if (str.empty()) {
      counter = 101;
      break;
    }
    for (int i = 0; i < str.size(); ++i) {
      if (str[i] != c) {
        loop = true;
      }
    }
    if (!loop) break;

    for (int i = 0; i < str.size()-1; ++i) {
      if (str[i] == c) {
        str[i] = c;
      } else if (str[i + 1] == c) {
        str[i] = c;
      }
    }
    str.pop_back();

    counter++;
  }
  return counter;
}

void solve() {
  bool c[0xff] = {};
  for (char tmp : s) {
    c[tmp] = true;
  }

  int ans = 101;
  for (char i = 'a'; i <= 'z'; ++i) {
    if (c[i]) {
      ans = min(ans, shrinking(i));
    }
  }

  cout << ans << endl;
}

int main() {
  cin >> s;

  solve();
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		int taro=0;
		int hanako=0;
		//ターン数を入力
		Scanner sc=new Scanner(System.in);
		int n=Integer.parseInt(sc.next());
		int[] num=new int[26];
		for(int i=0;i<26;i++) {
			num[i]=i+1;
		}
		//ターン数分繰り返す
		for(int i=0;i<n;i++) {
			//カード入力
			String a=sc.next();
			String b=sc.next();

			if(a.compareTo(b)>0) {
				taro+=3;
			}else if(a.compareTo(b)<0) {
				hanako+=3;
			}else if(a.compareTo(b)==0) {
				taro+=1;
				hanako+=1;
			}
		}
		System.out.println(taro+" "+hanako);
	}

}



Measured memory_bytes: 30148
#include <iostream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> p_i;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repext(i, a, b) for (int i = a; i < b; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define repextrev(i, a, b) for (int i = b - 1; i >= a; i--)
#define vec_all(vec) vec.begin(), vec.end()
#define sum(vec) accumulate(vec_all(vec), 0)

// vectorデバッグ
template <typename T>
void dump_vec(vector<T> vec)
{
    rep(i, vec.size())
    {
        cout << i << ": " << vec[i] << endl;
    }
}

ll mod_pow(ll x, ll y, ll mod) {
    ll ret = 1;
    rep(i, y) {
        ret *= x;
        ret %= mod;
    }

    return ret;
}

// --- notice ---
// intの和はllにしろ

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }

    vector<int> n_cnt(n + 1, 0);
    if (n % 2 == 0) {
        rep(i, n) {
            if (a[i] % 2 == 0) {
                cout << 0 << endl;
                return 0;
            }
            n_cnt[a[i]]++;
            if (n_cnt[a[i]] > 2) {
                cout << 0 << endl;
                return 0;
            }
        }
        for (int i = 1; i < n; i += 2) {
            if (n_cnt[i] == 1) {
                cout << 0 << endl;
                return 0;
            }
        }
    } else {
        rep(i, n) {
            if (a[i] % 2 == 1) {
                cout << 0 << endl;
                return 0;
            }
            n_cnt[a[i]]++;
            if (n_cnt[a[i]] > 2) {
                cout << 0 << endl;
                return 0;
            }
        }
        if (n_cnt[0] != 1) {
            cout << 0 << endl;
            return 0;
        }
        for (int i = 2; i < n; i += 2) {
            if (n_cnt[i] == 1) {
                cout << 0 << endl;
                return 0;
            }
        }

    }

    cout << mod_pow(2LL, (ll) (n / 2), 1000000007LL) << endl;

    return 0;
}

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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;

bool prime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    return a.fi>b.fi;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,m; cin>>n>>m;
    ll sum = 0;
    rep(i,0,m)
    {
        ll x; cin>>x;
        sum+=x;
    }
    if(sum>n)cout<<-1<<endl;
    else cout<<n-sum<<endl;
    return 0;

}
/*
1
4
4 2
10 3
3 4
9 2
*/


Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll n, A, B, C;
vl L;

ll dfs(ll depth, ll a, ll b, ll c) {
    if(depth == n) {
        if(a == 0 || b == 0 || c == 0) {
            return INF;
        }
        return abs(A - a) + abs(B - b) + abs(C - c);
    }
    ll res  = INF;
    chmin(res, dfs(depth+1, a, b, c));
    chmin(res, dfs(depth+1, a + L[depth], b, c) + 10);
    chmin(res, dfs(depth+1, a, b + L[depth], c) + 10);
    chmin(res, dfs(depth+1, a, b, c + L[depth]) + 10);
    return res;
}

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

    L.resize(n);
    rep(i, n) {
        cin >> L[i];
    }

    out(dfs(0, 0, 0, 0) - 30);
    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int ll
#define N 210010
#define ls c[rt][0]
#define rs c[rt][1]
#define lw w[rt][0]
#define rw w[rt][1]
using namespace std;
typedef long long ll;
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
struct node{ll x,y;};
int n,c[N][2],w[N][2];
vector <node> V[N];
node tt1[N],tt2[N];

inline void Insert(int x,node d)
{
	int i=V[x].size()-1;
	if(V[x].empty()) { V[x].push_back(d); return ;}
	if(V[x][i].y<=d.y) return ;
	while(i>=0&&V[x][i].x>=d.x) i--,V[x].pop_back();
	V[x].push_back(d);
} 
/* void Insert(int x,node y){
	//x sorted
	//compare y is ok
	int i=V[x].size()-1;
	if(V[x].empty()){V[x].push_back(y);return;}
	if(V[x][i].y<=y.y)return;
	while(!V[x].empty()&&V[x][i].x>=y.x)V[x].pop_back();
	V[x].push_back(y);
}
  */
bool check(int rt,ll tar)
{
	V[rt].clear();
	if(!ls){Insert(rt,(node){0,0}); return 1;}
	int ck=check(ls,tar)|check(rs,tar);
	if(!ck) return ck; 	int tmp1=0, tmp2=0; 
	int lls=V[ls].size()-1,rr=V[rs].size()-1;
	for(int i=lls,j=rr;i>=0;i--)
	{
		while(j>=0&&V[ls][i].y+V[rs][j].x+lw+rw>tar) j--;
		if(j>=0) tt1[++tmp1]=(node){V[ls][i].x+lw,V[rs][j].y+rw};
	}
	for(int j=rr,i=lls;j>=0;j--)
	{
		while(i>=0&&V[rs][j].y+V[ls][i].x+lw+rw>tar) i--;
		if(i>=0) tt2[++tmp2]=(node){V[rs][j].x+rw,V[ls][i].y+lw};
	}
	reverse(tt1+1,tt1+1+tmp1); reverse(tt2+1,tt2+1+tmp2);
	int i=1,j=1; while(i<=tmp1&&j<=tmp2)
	{
		if(tt1[i].x<tt2[j].x) Insert(rt,tt1[i]),i++;
		else Insert(rt,tt2[j]),j++;
	} while(i<=tmp1) Insert(rt,tt1[i]),i++;
	  while(j<=tmp2) Insert(rt,tt2[j]),j++;
	  return !V[rt].empty();
}
signed main()
{
	//freopen("read.in","r",stdin);
	n=read(); for(int i=2;i<=n;i++)
	{
		int rt=read(),y=read();
		if(!ls) ls=i,lw=y; else rs=i,rw=y;
	}
	ll l=0, r=1000000000000ll, ans=0;
	while(l<=r)
	{
		ll mid=(l+r)>>1;// mid=14;
		if(check(1,mid)) ans=mid,r=mid-1;
		else l=mid+1;
	}cout << ans << endl; return 0;
}

Measured memory_bytes: 35444
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
int main()
{
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);
    swap(A, B);
    swap(A, C);
    printf("%d %d %d", A, B, C);
	return 0;
}


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

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> l(m), r(m);
    int lm = 1, rm = n;
    for (int i = 0; i < m; i++)
    {
        cin >> l[i] >> r[i];
        lm = max(lm, l[i]);
        rm = min(rm, r[i]);
    }
    cout << max(rm - lm + 1, 0) << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(){
	int w,h,x,y,r,decid;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);

	if((x-r>=0) && (x+r<=w) && (y-r>=0) && (y+r<=h)){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 584