akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <string>


// 1. Sの後ろ側から順に見ていく
// 2. 見ている文字がTの頭文字と一致するか?だったら、ここ以降がTと一致するか判定する
// 3. 一致したら、残りの?をaで置き換えて出力
// 4. 最後まで見て一致しなかったらUNRESTORABLE
using namespace std;
int main() {
  string S, T;
  cin >> S >> T;
  string result = "";
  bool can_satisty = false;
  for (string::reverse_iterator it = S.rbegin(); it != S.rend(); ++it) {
    if (*it == T[0] || *it == '?') {
      string::iterator it_T = T.begin();
      for (string::iterator it2 = (it+1).base(); it2 != S.end(); ++it2) {
        if (*it2 != '?' && *it2 != *it_T)
          break;
        ++it_T;
        if (it_T == T.end()) {
          can_satisty = true;
          break;
        }
        continue;
      }
      if (can_satisty) {
        string::iterator match_start = (it + 1).base();
        for (string::iterator it2 = S.begin(); it2 != S.end(); ++it2) {
          if (it2 == match_start) {
            --it2;
            for (string::iterator it_T = T.begin(); it_T != T.end(); ++it_T) {
              result += *it_T;
              ++it2;
            }
          } else if (*it2 == '?')
            result += 'a';
          else
            result += *it2;
        }
        cout << result << endl;
        break;
      }
    }
  }
  if (!can_satisty)
    cout << "UNRESTORABLE" << endl;
}


Measured memory_bytes: 256
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = get!(usize);
    let mut pp = get!(String).split_whitespace().map(|p| p.parse::<usize>().unwrap()).collect::<Vec<_>>();
    let mut r = 0;
    for i in 0..n-1 {
        let p = i+1;
        if pp[i] == p {
            pp.swap(i, i+1);
            r += 1;
        }
    }
    if pp[n-1] == n { r += 1; }
    println!("{}", r);
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define tracev(v)               for (auto& x: v) cerr << x << " "; cerr << '\n';
#define trace2v(v)              for (auto& x: v) cerr << x.fi << " - " << x.se << '\n'; cerr << '\n';
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }  

typedef long long ll; 
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

ll epow(ll a, ll b) {
    ll ret = 1;
    while (b) {
        if (b & 1) ret *= a;
        a *= a;
        b >>= 1;
    }
    return ret;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifndef ONLINE_JUDGE
    freopen("errlog", "w", stderr);
#endif
    ll h; cin >> h;
    ll lay = 0, ans = 0;
    while (h) {
        ans += epow(2LL, lay);
        h /= 2;
        lay++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        a_vec: [usize; n - 1],
    }

    let mut r_vec = vec![0; n];
    for a in a_vec {
        r_vec[a - 1] += 1;
    }

    for r in r_vec {
        println!("{}", r);
    }
}


Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int lo = 0, hi = 10000, mid;
	while(lo < hi)
	{
		mid = (lo + hi)/2;
		if((mid*(mid+1))/2 >= n)
			hi = mid;
		else
			lo = mid+1;
	}
	for (int i = lo; i >= 1; --i)
	{
		if(i <= n)
		{
			cout<<i<<"\n";
			n-=i;
		}
	}
	assert(n == 0);
	return 0;
}

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

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long k = sc.nextLong();
    int[] direct = new int[n + 1];
    int[] visitCounts = new int[n + 1];
    Arrays.fill(direct, -1);
    Arrays.fill(visitCounts, 0);

    for (int i = 1; i <= n; i++) {
      direct[i] = sc.nextInt();
    }

    int counter = 0;
    int next = 1;
    int cycle = 0;
    int step = 0;
    while (true) {
      counter++;
      if (visitCounts[next] > 0) {
        cycle = counter - visitCounts[next];
        step = visitCounts[next] - 1;
        break;
      }
      visitCounts[next] = counter;
      next = direct[next];
    }
    if (k > (long) step) {
      k -= (long)step;
      k %= (long)cycle;
    } else {
      next = 1;
    }
    for(long count = 0; count < k; count++){
      next = direct[next];
    }
    System.out.println(next);
  }
}

Measured memory_bytes: 61596
import scala.io.StdIn._
import scala.annotation.tailrec

object Main {
    def main(args: Array[String]): Unit = sub(readLine().split(" ").map(_.toInt))
    def digit(a: Int, b: Int): Int = if(b == 0) a else digit(b, a % b)

    @tailrec
    def sub(n: Seq[Int]): Unit = {
        val gcd: Int = digit(n(0), n(1))
        val lcm: Int = (n.map(_.toLong).product / gcd.toLong).toInt
        println(s"$gcd $lcm")
        val next: String = readLine()
        if(next == null) Unit else sub(next.split(" ").map(_.toInt))
    }
}

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

int main()
{
    long long int A, B, soma, sub, mult;
    scanf("%lld %lld", &A, &B);
    soma = A + B;
    sub = A - B;
    mult = A * B;
    if(soma >= sub && soma >= mult)
        printf("%lld\n", soma);
    else if(sub >= soma && sub >= mult)
        printf("%lld\n", sub);
    else
        printf("%lld\n", mult);
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main(void){
    int N, L;
    scanf("%d%d", &N, &L);
    char s[N+1][L+1];
    for(int i=0; i<N; i++){
        scanf("%s", &s[i]);
    }
    for(int i=0; i<N-1; i++){
        for (int j=0; j<N-1; j++){
            if(strcmp(s[j], s[j+1])>0){
                char temp[L+1];
                strcpy(temp, s[j]);
                strcpy(s[j], s[j+1]);
                strcpy(s[j+1], temp);
            }
        }
    }
    for(int i=0; i<N; i++){
        printf("%s", s[i]);
    }
    return 0;
}

Measured memory_bytes: 1736
!http://web.agr.ehime-u.ac.jp/~kishou/Lecture/atmosphere/Fortran90/Chap4_answer.pdf
!-----------------------------------------
! エラトステネスのふるい
implicit none
logical, dimension(100000) :: flag ! ここでは論理型を使ったが、整数型でも可
integer, dimension(100000) :: count=0, nitakazu_count=0, ruiseki_count=0
integer :: i, n, nn, a, b
flag(:) = .false. ! すべて「偽」に初期化
n = 0 ! 素数の個数を数えるカウンター
do i = 2, 100000
    if (flag(i)) cycle ! 「偽」すなわち素数でなければ次の数へ
    count(i)=1
    if ( count(int((i+1)/2))==1 ) then
        nitakazu_count(i)=1
    endif
    !write(6,*) i ! 出力して
    n = n + 1 ! カウンタをひとつ増やし
    flag(i:100000:i) = .true. ! その倍数をすべて「真」にする
enddo

!nitakazu_count(2)=0

!write(6,*) nitakazu_count

do i = 2, 99999
  ruiseki_count(i+1)=ruiseki_count(i)+nitakazu_count(i+1)
enddo

read(5,*) nn
do i= 1, nn
  read(5,*) a, b
  write(6,*) ruiseki_count(b)-ruiseki_count(a-1)
  
enddo

stop
end


Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


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

int main()
{
    int L, R, d;
    io >> L >> R >> d;
    int ans = 0;
    for (int i = L; i <= R; i++)
    {
        if (i % d == 0) ++ans;
    }
    io << ans<< BR;
}

Measured memory_bytes: 3820
#include <iostream>
using namespace std;
int h, w;
int main() {
  while (cin >> h >> w && h||w){
    for (int i=1; i<=h; i++) {
      for (int j=1; j<=w; j++) {
      cout << "#";
    }
    cout << endl;
  }
  cout << endl;
}
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <complex>
#include <fstream>
#include <cmath>

using namespace std;

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    if(a==b){
        cout << c << endl;
    }else if(a==c){
        cout << b << endl;
    }else if(b==c){
        cout << a << endl;
    }
    return 0;
}


Measured memory_bytes: 256
//Author: Pakhomovee 
#include <iostream> 
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <deque>
#include <iomanip>
#include <stdio.h>
#include <assert.h>
#include <queue>

using namespace std;
using namespace std::chrono;

#define int long long

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> cnt(1000000, 0);
	long long ans = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		++cnt[a[i]];
		ans += a[i];
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i)
	{
		int b, c;
		cin >> b >> c;
		cnt[c] += cnt[b];
		ans -= cnt[b] * b;
		ans += cnt[b] * c;
		cnt[b] = 0;
		cout << ans << '\n';
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	auto start = system_clock::now();
	
	solve();

	auto end = system_clock::now();
	cerr << "Time: " << duration_cast<milliseconds> (end - start).count() << "ms" << endl;
}

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

int main() {
  char s[11]; cin >> s;
  int maxs = 0, counter = 0;
  for(int i = 0; i < sizeof(s); i++) {
    if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T') {
      counter++;
    } else {
      counter = 0;
    }
    maxs = max(maxs, counter);
  }
  cout << maxs << endl;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

S = input()

odd = []
even = []

for i in range(len(S)) : 
    if i % 2 == 0 : 
        odd.append(S[i])
    else : 
        even.append(S[i])
        
flag = 1

for i in odd : 
    if i != "R" and i != "U" and i != "D" : 
        flag = 0
        break
    
if flag != 0 : 
    for i in even : 
        if i != "L" and i != "U" and i != "D" : 
            flag = 0
            break
        
if flag == 1 : 
    print("Yes")
else : 
    print("No")

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

#define MAX_N (100000L)
#define NUM_MOD (1000000007L)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  long N, as[MAX_N], bs[MAX_N];
  scanf("%ld", &N);
  for (long i = 0; i < N; i++) {
    scanf("%ld", &as[i]);
  }
  for (long i = 0; i < N; i++) {
    scanf("%ld", &bs[i]);
  }
  // NOTE : modified input
  sort(as, as + N);
  sort(bs, bs + N);

  // solve
  long ia = 0, ib = 0, num = 0, ans = 1;
  while (ia < N && ib < N) {
    if (as[ia] <= bs[ib]) {
      if (num < 0) {
        ans = (ans * abs(num)) % NUM_MOD;
      }
      num++;
      ia++;
    } else {
      if (num > 0) {
        ans = (ans * abs(num)) % NUM_MOD;
      }
      num--;
      ib++;
    }
    // printf("ia = %ld, ib = %ld, num = %ld, ans = %ld\n", ia, ib, num, ans);
  }
  while (ia < N) {
    if (num < 0) {
      ans = (ans * abs(num)) % NUM_MOD;
    }
    num++;
    ia++;
    // printf("ia = %ld, ib = %ld, num = %ld, ans = %ld\n", ia, ib, num, ans);
  }
  while (ib < N) {
    if (num > 0) {
      ans = (ans * abs(num)) % NUM_MOD;
    }
    num--;
    ib++;
    // printf("ia = %ld, ib = %ld, num = %ld, ans = %ld\n", ia, ib, num, ans);
  }
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int N;
	cin >> N;
	vector<int> A(N), B(N);
	REP(i, N) { cin >> A[i] >> B[i]; }
	if (N % 2) {
		SORT(A);
		SORT(B);
		cout << abs(B[N / 2] - A[N / 2]) + 1 << endl;
	} else {
		SORT(A);
		SORT(B);
		cout << abs((B[N / 2 - 1] + B[N / 2]) - (A[N / 2 - 1] + A[N / 2])) + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 4780
#include <stdio.h>

int main(void){

    int n;
    scanf("%d", &n);

    int i =1;
for (; i <= n; i++){
    if ( i%3 ==0){
        printf(" %d",i);
        continue;
    }
    int x = i;
    for(; x >0;){
        if( x % 10 == 3){
            printf(" %d",i);
            break;
        }else{
            x /=10;
        }
    }
    
}
printf("\n");
    
    return 0;
}


Measured memory_bytes: 2124
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(void){
    string a, b;

    cin >> a >> b;

    string c = a + b;

    int d = stoi(c);

    int sq = (int)sqrt(d);

    if(( sq * sq ) == d){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// ここにコードを挿入
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int price;
		if (A >= 13) {
			price = B;
		} else if (6 <= A) {
			price = B / 2;
		} else {
			price = 0;
		}
		System.out.println(price);
	}

}

Measured memory_bytes: 23764
#https://atcoder.jp/contests/abc125
# -*- coding: utf-8 -*-

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

total = 0
minus = 0
minimum = abs(a[0])

for v in a:
        total += abs(v)
        if v < 0 :
                minus += 1
        if abs(v) < minimum:
                minimum = abs(v)

if minus%2 is 1:
        total -= minimum*2

print(total)

Measured memory_bytes: 14252
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define P pair<string, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

class C{
  public:
    string first;
    int second;
    C(string _f, int _s){ first = _f; second = _s; }
    C(){}
    bool operator < (const C &c) const {
      if (first.length() < c.first.length()) return true;
      if (first.length() > c.first.length()) return false;
      return first < c.first;
    }
};

int main() {
  int N; cin >>N;
  map<string, int> m;
  REP(i, N){
    string s;
    int num;
    cin >>s >>num;
    m[s] += num;
  }
  vector<C> v;
  for(map<string, int>::iterator it = m.begin(); it != m.end(); ++it) v.push_back( C(it->first, it->second) );
  SORT(v);
  REP(i, v.size()) cout <<v[i].first <<" " <<v[i].second <<endl;
  return 0;
}

Measured memory_bytes: 1236
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;

const long long MOD = 2019;

void solve(long long L, long long R){
  if(abs(L-R)>2020){
    cout << 0 << endl;
    return;
  }
  ll ans = LINF;
  REP(i,L,R) REP(j,i+1,R+1){
    ll temp = ll(i)*ll(j)%2019;
    chmin(ans,temp);
  }
  cout << ans << endl;
}

int main(){
  long long L;
  scanf("%lld",&L);
  long long R;
  scanf("%lld",&R);
  solve(L, R);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int cnt,a[10],n,m,ans;
int read(){
	int num = 0, flag = 1; char c = getchar();
	for(; c < '0' || c > '9'; c = getchar())
		if(c == '-') flag = 0;
	for(; c >= '0' && c <= '9'; c = getchar())
		num = (num<<3)+(num<<1)+c-48;
	return flag ? num : -num;
}

bool check(int x){
	cnt = 0;
	while(x){
		a[++cnt] = x % 10;
		x /= 10;
	}
	for(int i = 1; i<=cnt; ++i)
		if(a[i] != a[cnt - i + 1]) return false;
	return true;
}

int main(){
	n = read(); m = read();
	for(int i = n; i <= m; ++i)
		if(check(i)) ++ans;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var s = new string[3];
		for (var i = 0; i < 3; i++) s[i] = Str;
		var ans = 0;
		for (var i = 0; i < N; i++)
		{
			var c = new HashSet<char>();
			for (var j = 0; j < 3; j++) c.Add(s[j][i]);
			ans += c.Count - 1;
		}
		WriteLine(ans);
	}
}


Measured memory_bytes: 13652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    ll before = 0;
    ll after = 0;
    for (int i = 0; i < k - 1; i++)
    {
        before += i;
        after += n - i;
    }
    // cout << "before:" << before << endl;
    // cout << "after:" << after << endl;
    for (int i = k - 1; i <= n; i++)
    {
        before = (before + i) % MOD;
        after = (after + n - i) % MOD;
        ans = (ans + after - before + 1 + MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
};

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N;
  cin >> N;
  vector<int> A(N-1);
  for (int i=0; i<N-1; i++) cin >> A[i];
  map<int, int> memo;
  for (int i=0; i<N-1; i++) {
    if (memo.count(A[i])) memo[A[i]]++;
    else memo[A[i]] = 1;
  }
  for (int i=0; i<N; i++) cout << memo[i+1] << endl;
}


Measured memory_bytes: 13536
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る 
        //console.log("***input = " + input);
        //console.log("type = " + typeof(input));
        //console.log("size=" + input.length);
	input = input.split("\n");
        //console.log("***input.split = " + input);
        //console.log("type = " + typeof(input));
        //console.log("size=" + input.length);
	//文字列から10進数に変換するときはparseIntを使います

	var flag = 0;
	if(input[0][0] == input[0][1]){
		if(input[0][1] == input[0][2]){
			flag = 1;
		}
	}else if(input[0][1] == input[0][2]){
		if(input[0][2] == input[0][3]){
			flag = 1;
		}
	}
	if(flag == 1){
		console.log("Yes");
	}else{
		console.log("No");
	}
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include "bits/stdc++.h"

using namespace std;

void solve()
{
	int n, k;
	string s;
	cin >> n >> k >> s;
	vector<pair<int, int>> ps;
	for (int i = 0; i < n; i++)
	{
		int d = 1 - s[i] + '0';
		if (ps.empty() || ps.back().first != d)
		{
			ps.emplace_back(d, 1);
		}
		else
		{
			ps.back().second++;
		}
	}
	int cnt = 0, ans = 0, now = 0, ptr = 0;
	for (const auto &p : ps)
	{
		while (ptr < (int)ps.size() && cnt + ps[ptr].first <= k)
		{
			now += ps[ptr].second;
			cnt += ps[ptr].first;
			ptr++;
		}
		ans = max(ans, now);
		cnt -= p.first;
		now -= p.second;
	}
	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  //cout << S.substr(0, N/2) << ' ' << S.substr(N/2) << endl;
  
  if(N%2==1){
    cout << "No" << endl;
    return 0;
  }
  
  if(S.substr(0, N/2) == S.substr(N/2, S.size())){
    cout << "Yes" << endl;
    return 0;
  }
  else{
    cout << "No" << endl;
    return 0;
  }
}



Measured memory_bytes: 256
#include<stdio.h>


int main()
{
    int N,A,B;
    scanf("%d%d%d",&N,&A,&B);
    if(A>B||(N==1&&A!=B))
    {
        printf("0\n");
        return 0;
    }
    printf("%lld\n",(long long )(N-2)*(B-A)+1);
    return 0;
}

Measured memory_bytes: 128
S = input()
s1 = int(S[:2])
s2 = int(S[2:])

if 1<=s1 and s1<=12 and 1<=s2 and s2<=12:
    print('AMBIGUOUS')
elif 1<=s1 and s1<=12 and (s2<1 or s2>12):
    print('MMYY')
elif 1<=s2 and s2<=12 and (s1<1 or s1>12):
    print('YYMM')
else:
    print('NA')

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

#define ll long long

typedef vector< ll > vi;
typedef vector< vi > vvi;
typedef pair< ll,ll > ii;
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(0)

double l;

int main(){
	fast;
	cout<<fixed<<setprecision(10);	
	cin>>l;

	l /= 3;

	cout << (l*l*l) <<endl;

		

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
using namespace std;
long long n,h;
struct kill
{
	long long a,b;
}p[100005];
bool cnt1(kill x,kill y){return x.a<y.a;}
bool cnt2(kill x,kill y){return x.b<y.b;}
int main() 
{
	scanf("%lld%lld",&n,&h);
	for(int i=1;i<=n;i++) scanf("%d%d",&p[i].a,&p[i].b);
	sort(p+1,p+n+1,cnt1);
	long long k=p[n].a;
	sort(p+1,p+n+1,cnt2);
	int cnt=0;
	for(int i=n;i>=1;i--)
	{
		if(p[i].b>k) {cnt++;h-=p[i].b;}
		if(h<=0) break;
	}
	if(h>0) 
	{
		if(h%k==0) cnt+=h/k;
		else cnt+=(h/k)+1;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
S = [input() for _ in range(N)]

hash = {}
for i in range(N):
    if S[i] in hash:
        hash[S[i]] += 1
    else:
        hash[S[i]] = 1

max_value = max(hash.values())

result = {}
for key in hash.keys():
    if hash[key] == max_value:
        result[key] = True

for key in sorted(result.keys()):
    print(key)

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

using namespace std;

int main(void) {
	int num, a, i, n = 0, mi = 1 << 30;
	long long ans = 0;
	cin >> num;
	for (i = 0; i < num; i++) {
		scanf("%d", &a);
		ans += abs(a);
		if (a < 0)
			n++;
		mi = min(mi, abs(a));
	}
	if (n & 1)
		ans -= mi << 1;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    immutable N = readln().chomp().to!int();
    foreach(_;0..N)
    {
        auto s = readln().chomp().array();
        auto a = s.sort!"a<b"().array().to!int();
        auto b = s.sort!"a>b"().array().to!int();
        writeln(b-a);
    }
}

Measured memory_bytes: 1104
#include "bits/stdc++.h"
using namespace std;
int main(void){
  int a[2],group[2];
  string ans;
  cin >> a[0] >> a[1];
  for (int i=0;i<2;i++){
    if (a[i]==1||a[i]==3||a[i]==5||a[i]==7||a[i]==8||a[i]==10||a[i]==12)
      group[i] = 0;
    else if (a[i]==4||a[i]==6||a[i]==9||a[i]==11)
      group[i] = 1;
    else
      group[i] = 2;
  }
  if (group[0]==group[1]){
    ans = "Yes";
  }else {
    ans = "No";
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main{
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int n = sc.nextInt();
		int k =sc.nextInt();
		long[] arr = input(n);
		
		long[] dp = new long[k+1];
		long[] cum = new long[k+1];
		long mod = 1000000007;

		for(int i = 0 ; i < n;i++ ) {
			
			
			
				cum = dp;
			
			for(int j = 1 ;j <= k ;j++) {
				cum[j]= (cum[j] + cum[j-1] )%mod;				
				cum[j] %=mod;
			}
			dp= new long[k+1];
			for(int j = 0 ;j <= k ;j++) {
				if(i==0) {
					if(j<=arr[i])
					dp[j]=1;
					continue;
				}
				dp[j] = cum[j]%mod;
				dp[j]= (dp[j] - ( (j - arr[i]>0)? cum[(int) (j - arr[i]-1)] : 0 ) + mod )%mod;
				dp[j]%=mod;
				
				
			}
			
			
		}
	
		System.out.println(dp[k]);
	}

	public static long[] input(int n) throws Exception {

		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		return arr;
	}

	public static int[][] input(int n, int m) throws Exception {

		int[][] arr = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {

				arr[i][j] = sc.nextInt();
			}
		}
		return arr;
	}

}


Measured memory_bytes: 55360
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let n=t.n()
  let w=t.n(n)
  let ans=200;
  let a=0
  for(let i=0;i<n;i++){
    a+=w[i]
    let b=0;
    for(let j=i+1;j<n;j++){
      b+=w[j]
    }
    ans=t.min(ans,t.abs(a-b))
  }
  t.o(ans)
}
main()


Measured memory_bytes: 9420
#!/usr/bin/env python3

s, t = list(input().split())
a, b = list(map(int, input().split()))
u = input()
ab_list = [a, b]
n_list = [s, t]

ab_list[n_list.index(u)] = ab_list[n_list.index(u)] - 1
ans = " ".join([str(x) for x in ab_list])

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <map>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){

int a[100];
int n;
cin >> n;

for(int i = 0; i < n; i++)   cin >> a[i];

sort(a,a + n);

int x=0,y=0;
for(int i = n-1; i >= 0; i--) {
if(i % 2 == 0) x += a[i];
else y += a[i];
}

cout << abs(x - y) <<endl ;

return 0;
}

Measured memory_bytes: 256
from itertools import combinations

n = int(input())
lst = list(map(int, input().split()))
comb = combinations(lst, 3)
count = 0

for i in comb:
  if i[0] != i[1] and i[1] != i[2] and i[0] != i[2]:
    if i[0] + i[1] > i[2] and i[1] + i[2] > i[0] and i[0] + i[2] > i[1]:
      count += 1
    
print(count)


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

using namespace std;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lld a,b,c;
  cin>>a>>b>>c;
  if(c<a+b){
    cout<<"No"<<endl;
    return 0;
  }
  lld A=4*a*b;
  lld B=c-a-b;
  B=B*B;
  if(A<B){
    cout<<"Yes"<<endl;
  }else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
last = -1
for a in A:
    ans += B[a-1]
    if last + 1 == a: ans += C[a-2]
    last = a
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
template<typename T> void read(T &num){
	char c=getchar();T f=1;num=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}
template<typename T> void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T> void chkmax(T &x,T y){x=x>y?x:y;}
char S[110];bool in[30];int f[30];

int main(){
	scanf("%s",S+1);int n=strlen(S+1);
	rep(i,1,n){
		if(!in[S[i]-'a'+1])chkmax(f[S[i]-'a'+1],i-1);
		in[S[i]-'a'+1]=1;
		int pos=n+1;
		rep(j,i+1,n){
			if(S[j]==S[i]){pos=j;break;}
		}
		chkmax(f[S[i]-'a'+1],pos-i-1);
	}
	
	int ans=INT_MAX;
	rep(i,1,26){
		if(!in[i])continue;
		chkmin(ans,f[i]);
	}
	write(ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <queue>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs, x) vector<vector<T>> xs(n, vector<T>(m, x))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs, 0); For(i, n) For(j, m) cin >> xs[i][j]
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"

using namespace std;
using ll = long long;

int main(void){
    Cin(int, n);
    Cins(int, n, a);
    Cusum(ll, n, a, as);
    unordered_map<ll, int> nas;
    For(i, n+1) nas[as[i]] ++;
    //for(const auto &e : nas) cout << e.first << " " << e.second << "\n";
    ll ans = 0;
    For(i, n){
        nas[as[i]] --;
        ans += nas[as[i]];
    }
    Cout(ans);
}


Measured memory_bytes: 10824
N,A,B,C,D = [int(x) for x in input().split()]
S = input()
cross = False
minG = C
maxG = D

if C > D:
    minG = D
    maxG = C
    cross = True

S_wall = S[A-1:maxG]
S_even = S[B-1-1:minG+1]

wall = S_wall.find("##")
even = S_even.find("...")

if cross == False:
    if wall == -1:
        print("Yes")
    else:
        print("No")
else:
    if wall == -1:
        if even != -1:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}


vector<ll> enum_div(int n){//yakusu
  vector<ll> ret;
  for(ll i=1 ; i*i<=n ; ++i){
      if(n%i == 0){
        ret.push_back(i);
        if(i*i!=n)ret.push_back(n/i);
      }
  }
  return ret;
}

int main(){
  ll n;
  cin >> n;
  map<ll,ll> se;
  FOR(i,0,n){
    ll a;
    cin >> a;
    se[a]++;
  }
  ll ans = 0;
  for(auto x:se){
    ll v = x.first;
    ll N = x.second;
    if(v>N)ans+=N;
    if(v<N)ans+=N-v;
  }
  cout << ans << endl;
}


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

using namespace std;
typedef long long ll;

struct Point {
    ll x;
    ll y;
};
bool operator==(const Point& lhs, const Point& rhs)
{
    return lhs.x == rhs.x && lhs.y == rhs.y;
}
bool operator<(const Point &lhs, const Point &rhs)
{
    if (lhs.x < rhs.x) {
        return true;
    }
    if (lhs.x == rhs.x && lhs.y < rhs.y) {
        return true;
    }
    return false;
}

int main() {
    ll h, w, m;
    map<ll, ll> mx;
    map<ll, ll> my;
    vector<Point> v;
    map<Point, ll> mp;
    cin >> h >> w >> m;
    vector<ll> sh(m);
    vector<ll> sw(m);
    for (ll i = 0; i < m; i++) {
        cin >> sh[i] >> sw[i];
        mx[sh[i]]++;
        my[sw[i]]++;
        Point p = {sh[i], sw[i]};
        v.push_back(p);
        mp[p]++;
    }
    vector<ll> max_x_idx;
    ll max_x = 0;
    vector<ll> max_y_idx;
    ll max_y = 0;
    for (auto e : mx) {
        if (max_x < e.second) {
            max_x_idx.clear();
        }
        if (max_x <= e.second) {
            max_x = e.second;
            max_x_idx.push_back(e.first);
        }
    }
    for (auto e : my) {
        if (max_y < e.second) {
            max_y_idx.clear();
        }
        if (max_y <= e.second) {
            max_y = e.second;
            max_y_idx.push_back(e.first);
        }
    }
    for (auto ex : max_x_idx) {
        for (auto ey : max_y_idx) {
            Point item = {ex, ey};
            if (!mp[item]) {
                cout << max_x + max_y << endl;
                return 0;
            }
            // if (find(v.begin(), v.end(), item) == v.end()) {
            //     cout << max_x + max_y << endl;
            //     return 0;
            // }
        }
    }
    cout << max_x + max_y - 1 << endl;
    return 0;
}


Measured memory_bytes: 77708
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvii = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

const ll inf = 1LL << 60;

struct Segment_Tree{  //区間和の遅延評価セグ木
    int N;
    vector<ll> data,lazy;

    Segment_Tree(vector<ll> vec){
        int n_ = vec.size();
        N = 1;
        while(n_ > N){
            N *= 2;
        }
        data.resize(2*N - 1);
        lazy.resize(2*N - 1, 0);
        REP(i,n_){
            int q = i + N -1;
            data[q] = vec[i];
        }
        for(int i = N -2; i >= 0; i--){
            data[i] = data[2*i + 1] + data[2*i + 2];
        }
    }

    void eval(int k, int l, int r){  //遅延評価　k: k番目のノードについての遅延評価  
        if(lazy[k] != 0){
            data[k] += lazy[k];

            if(r - l > 1){
                lazy[2*k + 1] += lazy[k]/2;
                lazy[2*k + 2] += lazy[k]/2; 
            }
            lazy[k] = 0;
        }
    }

    void add_sub(int a,int b, ll x, int k, int l, int r){ //[a,b)間の区間加算
        if(r <0) r = N;
        eval(k,l,r);  //遅延評価を行う

        if(b <= l || r <= a){ //もし[l,r)と[a,b)が交わらない ->なんもしない
            return;
        }
        else if(a <= l && r <= b){
            lazy[k] += (r - l) * x;
            eval(k,l,r);
        }
        else{
            add_sub(a, b, x, 2*k+1, l, (l+r)/2);
            add_sub(a, b, x, 2*k+2, (l+r)/2, r);
            data[k] = data[2*k+1] + data[2*k+2];
        }

    }

    void add(int a,int b, ll x){
        add_sub(a,b,x,0,0,N);
    }

    ll getsum_sub(int a, int b, int k, int l, int r){
        if(b <= l || a >= r){
            return 0; //maxに絶対ならない値を返す？
        }
        
        eval(k,l,r); //ここで遅延評価
        if(a <= l && r <= b){
            return data[k];
        }
        else{
            ll chl = getsum_sub(a, b, 2*k + 1, l, (l+r) / 2);
            ll chr = getsum_sub(a, b, 2*k + 2, (l+r) / 2, r);
            return chl + chr;
        }
    }

    ll getsum(int a,int b){
        return getsum_sub(a, b, 0, 0, N);
    }
};

int main(){
    int n,Q; cin>>n>>Q;
    vector<ll> vec(n,0);
    Segment_Tree tree(vec);
    //cout << tree.N << endl;
    vector<ll> ans;
    REP(i,Q){
        int a; cin>>a;
        if(a == 0){ //add
            int s,t; ll x; cin>>s>>t>>x;
            tree.add(s-1, t, x);
            /*REP(k,tree.N){
                cout << "data[k]:" << tree.data[k+tree.N - 1] << " " << tree.lazy[k + tree.N - 1] << endl;
            }*/
        }
        else{
            int s,t; cin >> s >> t;
            //tree.getsum(s-1, t);
            ans.push_back(tree.getsum(s-1, t));
        }
    }
    REP(i,ans.size()){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 9372
import java.util.Scanner;

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

        StringBuilder sub;
        for(int q=0; q<str.length(); q++){
            for(int r=q; r<=str.length(); r++){
                sub = new StringBuilder(str);
                sub.delete(q, r);
                if(sub.toString().equals("keyence")){
                    System.out.println("YES");
                    return;
                }
            }
        }
        System.out.println("NO");
    }
}

Measured memory_bytes: 21716
#include<iostream>
using namespace std;
int main() {
	double r, w, c;
	int ru;
	while (cin >> r >> w >> c >> ru) {
		if (r == 0 && w == 0 && c == 0 && ru == 0)break;
		double n = r / w;
		if (n >= c)cout << 0 << endl;
		else{
			for (int i = 1; ; i++){
				r += ru;
				n = r / w;
				if (n >= c){
					cout << i << endl; 
					goto Exit;
				}
			}
		Exit:;
		}
	}
	return 0;
}

Measured memory_bytes: 3136
N=int(input())
A=list(map(int,input().split()))

for i in range(1,N+1):
  A[i-1]-=i

A.sort()
if N%2==1:
  ma=A[N//2]
  print(sum([abs(i-ma) for i in A]))
else:
  ma=[A[N//2]-1,A[N//2]]
  a=[]
  for m in ma:
    a.append(sum([abs(i-m) for i in A]))
  print(min(a))


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int T = A + B + C;
  int X = 3 * max(max(A, B), C);
  if (X % 2 == T % 2) {
    cout << (X - T) / 2 << endl;
  } else {
    cout << (X - T) / 2 + 2 << endl;
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import Counter

def main():
    S = input()
    N = len(S)
    T = [0] * (N+1)
    
    for i in range(N-1,-1,-1):
        T[i] = (T[i+1] + int(S[i]) * pow(10,N-i,2019)) % 2019
    l = Counter(T)
    ans = 0
    for v in l.values():
        ans += v * (v-1) // 2
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 16460
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;

const int MAXK = 300010;
double dp[21][MAXK + 10];
int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    fill(dp[0], dp[N+1], LONGINF);
    for(int i=1; i<=MAXK; i++) {
        dp[1][i] = 1.0 * abs(A[0] - i) / A[0];
    }

    for(int i=1; i<N; i++) {
        for(int j=1; j<=MAXK; j++) {
            for(int k=j; k<=MAXK; k+=j) {
                chmin(dp[i+1][k], max(dp[i][j], 1.0 * abs(A[i] - k) / A[i]));
            }
        }
    }

    double ans = *min_element(dp[N], dp[N] + MAXK + 1);
    printf("%.12f\n", ans);
    return 0;
}



Measured memory_bytes: 52348
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

long long A[200001];
map<long long, int> mp;

int N;

int check(int K){
  mp.clear();
  int i,j,k;
  if (K==1) {
    for (i=1;i<N;++i) {
      if (A[i]<=A[i-1]) {
        return 0;
      }
    }
    return 1;
  }
  for (i=1;i<N;++i) {
    if (A[i]<=A[i-1]) {
      map<long long, int>::iterator it=mp.lower_bound(A[i]);
      mp.erase(it, mp.end());

      j=A[i]-1;
      while (1) {
        mp[j]+=1;
        if (mp[j]<K) {
          break;
        } else {
          mp.erase(j);
          j--;
          if (j==-1) {
            return 0;
          }
        }
      }
    }
    //cout << K << mp[0] << " " << mp[1] << " " << mp[2] << " " << mp[3] << " " << endl;
  }
  return 1;
}

int main(){
  int i,K;
  cin >> N;
  for (i=0;i<N;++i) {
    cin >> A[i];
  }
  int L=1,U=N;
  while (U>L) {
    K=(U+L)/2;
    if (check(K)==0) { //NG
      //cout << K << "NG" << endl;
      L=K+1;
    } else { //OK
      //cout << K << "OK" << endl;
      U=K-1;
    }
  }
  if (U==L) {
    if (check(L)==1) {
      cout << L << endl;
    } else {
      cout << (L+1) << endl;
    }
  } else {
    cout << L << endl;
  }
  return 0;
}


Measured memory_bytes: 1792