akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


class RollingHash:
    def __init__(self, s: str, base=1007, mod=10 ** 9 + 7):
        self.mod = mod
        length = len(s)
        self.pw = [1] * (length + 1)
        self.h = [0] * (length + 1)
        
        v = 0
        for i in range(length):
            self.h[i + 1] = v = (v * base + ord(s[i])) % mod
        v = 1
        for i in range(length):
            self.pw[i + 1] = v = v * base % mod
    
    def query(self, left, right):
        return (self.h[right] - self.h[left] * self.pw[right - left]) % self.mod


def solve():
    N = int(rl())
    S = input()
    
    rh = RollingHash(S)
    
    def check(t):
        dist = dict()
        for i in range(N - t + 1):
            h = rh.query(i, i + t)
            if h in dist:
                if t <= i - dist[h]:
                    return True
            else:
                dist[h] = i
        return False
    
    ok, ng = 0, N // 2 + 1
    while 1 < ng - ok:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 4140
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    ll A,B,Q;
    cin >> A >> B >> Q;
    vector<ll> S(A),T(B),X(Q);
    for(int i=0;i<A;i++){
        cin >> S[i];
    }
    for(int i=0;i<B;i++){
        cin >> T[i];
    }
    for(int i=0;i<Q;i++){
        cin >> X[i];
    }
    
    sort(S.begin(),S.end());
    sort(T.begin(),T.end());
    for(int i=0;i<Q;i++){
        ll sdx = lower_bound(S.begin(),S.end(),X[i])-S.begin();
        ll tdx = lower_bound(T.begin(),T.end(),X[i])-T.begin();
        ll tmp = 1LL << 60;
       int tt[4] = {0,1,0,1};
       int ts[4] = {0,0,1,1};
       for(int j=0;j<4;j++){
           ll nsdx = sdx - ts[j];
           ll ntdx = tdx - tt[j];
           if(nsdx >= A || nsdx < 0 || ntdx >= B || ntdx < 0) continue;
           else{
               tmp = min(tmp,llabs(S[nsdx]-T[ntdx])+min(llabs(X[i]-S[nsdx]),llabs(X[i]-T[ntdx])));
           }
       }
       cout << tmp << endl;
    }
    
}

Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	int a,b,ca,cb;
	ca=cb=0;
	cin>>a>>b;
	if(a>=2) ca=a*(a-1)/2;
	if(b>=2) cb=b*(b-1)/2;
	cout<<ca+cb<<endl;
}

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

typedef long long ll;
#define rep(i,n) for( ll (i)=0; (i)<(n); ++(i) )
#define rpi(i,n) for( int (i)=0; (i)<(n); ++(i) )
#define rpv(d) for(auto& v:d)
#if __cplusplus < 201703L
  std::ostream& co_(){ return std::cout << std::endl; }
  std::istream& cn_(){ return std::cin; }
  template<class Head, class... Args>
  std::ostream& co_( Head&& head, Args&&... args ){ std::cout << head; return co_(std::forward<Args>(args)...); }
  template<class Head, class... Args>
  std::istream& cn_( Head&& head, Args&&... args ){ std::cin >> head; return cn_(std::forward<Args>(args)...); }
#else
  template<class... Args>
  std::ostream& co_( Args... args ){ return std::cout << ... << args << std::endl; }
  template<class... Args>
  std::istream& cn_( Args... args ){ return std::cin >> ... >> args; }
#endif
#define co(...) co_(__VA_ARGS__);
#define cn(...) cn_(__VA_ARGS__);
#define all(x) (x).begin(), (x).end()
#define rgt(x,i) (x).begin(), (x).begin()+(i)

int main(){
  ll n,m,k;cn(n,m,k)
  vector<vector<int>> fr(n);
  vector<int> gr(n,-1);
  vector<int> frcnt(n,0);
  vector<int> grcnt(n,0);
  vector<int> blcnt(n,0);
  
  rep(i,m){
    ll a,b;cn(a,b)
    --a;--b;
    fr[a].push_back(b);
    fr[b].push_back(a);
    ++frcnt[a];
    ++frcnt[b];
  }
  int g = 0;
  rep(i,n){
    if (gr[i]<0){
      queue<int> q;q.push(i);
      while(!q.empty()){
        if (gr[q.front()] == g){
          q.pop();
          continue;
        }
        gr[q.front()] = g;
        rpv(fr[q.front()]){if (gr[v]!=g)q.push(v);}
        q.pop();
        ++grcnt[g];
      }
      ++g;
    }
  }
  rep(i,k){
    int a,b;cn(a,b)
    --a;--b;
    if (gr[a]==gr[b]){
      ++blcnt[a];
      ++blcnt[b];
    }
  }
  rep(i,n){
    //cout << "#" << i << " : " << gr[i] << " , " << grcnt[gr[i]] << " , " << blcnt[i] << endl;
    cout << grcnt[gr[i]]-frcnt[i]-blcnt[i]-1;
    if (i<n-1)cout << " ";
  }
  cout << endl;
}

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

int main(){
    int n;
    cin >> n;

    int h[n];
    rep(i, n){
        cin >> h[i];
    }

    int tmp = 0, MAX = 0;
    rep(i, n-1){
        if(h[i] >= h[i+1]){
            tmp++;
            MAX = max(MAX, tmp);
        }else{
            tmp = 0;
        }
    }
    cout << MAX << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 640
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        p: [(i64, i64); n],
    }
    let mut p = p;
    for p in &mut p {
        if p.0 > p.1 {
            std::mem::swap(&mut p.0, &mut p.1);
        }
    }
    p.sort();
    let mut max = 0;
    for i in 1..n {
        if p[i].1 >= p[max].1 {
            max = i;
        }
    }
    let mut r = [p[0].0, p[max].0];
    let mut b = [p[0].1, p[max].1];
    for i in 1..n {
        r[1] = std::cmp::max(r[1], p[i].0);
        b[0] = std::cmp::min(b[0], p[i].1);
    }
    let mut ans = (r[1] - r[0]) * (b[1] - b[0]);
    if max != 0 {
        let mut bmax = std::cmp::max(p[max].0, p[0].1);
        let bmin = std::cmp::min(p[max].0, p[0].1);
        let mut local = bmin;
        let mut h = std::collections::BinaryHeap::new();
        for i in 1..n {
            if i == max {
                continue;
            }
            h.push((-p[i].0, i));
            bmax = std::cmp::max(bmax, p[i].0);
            local = std::cmp::min(local, p[i].0);
        }
        ans = std::cmp::min(ans, (p[max].1 - p[0].0) * (bmax - local));
        while let Some((v, k)) = h.pop() {
            if k == n {
                ans = std::cmp::min(ans, (p[max].1 - p[0].0) * (bmax - std::cmp::min(bmin, -v)));
                break;
            }
            bmax = std::cmp::max(bmax, p[k].1);
            h.push((-p[k].1, n));
            if let Some(&(u, _)) = h.peek() {
                ans = std::cmp::min(ans, (p[max].1 - p[0].0) * (bmax - std::cmp::min(bmin, -u)));
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 17772
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    int a[10000];
    int i,sum=0;
    cin>>n>>m;
    if(n>=1&&n<=1000000&&m>=1&&m<=10000)
    {
        for(i=0;i<m;i++)
            cin>>a[i];
        for(i=0;i<m;i++)
            sum+=a[i];
        if(sum>n)
            cout<<-1<<endl;
        else
            cout<<n-sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0); 
	int N; cin >> N; 
	long long A[100010] = {}; 
	long long pro = 1LL; 
	for(int i = 0; i < N; i++){
		cin >> A[i]; 
		if(A[i] == 0){
			cout << 0 << "\n"; return 0; 
		}
	}
	for(int i = 0; i < N; i++){
		if(A[i] > 1000000000000000000LL / pro){
			cout << -1 << "\n"; return 0; 
		}
		pro *= A[i]; 
	}
	cout << pro << "\n"; 
}

Measured memory_bytes: 4432
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int h, w;
    int i, j;

    for(;;){
      h = sc.nextInt();
      w = sc.nextInt();
      if(h == 0 && w == 0)break;

      for(i = 0;i < h;i++){
        for(j = 0;j < w;j++){
          System.out.print("#");
        }
        System.out.println();
      }
      System.out.println();
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 27044
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define lower(a,x) lower_bound(all(a), x) - a.begin();
#define COUNT(a,x)  upper_bound(all(a), x) - lower_bound(all(a), x);
#define MCOUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x);
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end());
#define scan(x) scanf("%lld",&x);
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
typedef double D;
const ll inf = 5555555555555555555;
const ll mod = 1000000007;
const D pi = acos(-1);
const D eps = 1e-10;

ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool ok, flag;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111


int main(void) {
  cin >> n >> m;
  if (n <= 8 && m <= 8)cout << "Yay!" << endl;
  else cout << ":(" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
        int a,b,x;
        char op;
        
        scanf("%d %c %d",&a,&op,&b);
        
        while(1){//加算
                if(op == '+'){
                        x = a + b;
                }//減算
                else if(op == '-'){
                        x = a - b;
                }//乗算
                else if(op == '*'){
                        x = a * b;
                }//除算
                else if(op == '/'){
                        x = a / b;
                }//ループを抜ける
                else if(op == '?'){
                        break;
                }
                printf("%d\n",x);
                scanf("%d %c %d",&a,&op,&b);
        }
        return 0;
}


Measured memory_bytes: 2108
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

// > 11*100000
#define BUF_SIZE 1200000


int get_int5(int *a1, int *a2, int *a3, int *a4, int *a5) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d %d %d %d", a1, a2, a3, a4, a5);
#else
#error
#endif
  return 0;
}


struct pair {
    int num;
    char type;
};

enum {
    TYPE_A,
    TYPE_B,
    TYPE_ALL,
};

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(struct pair *arr, int size, int type) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    char *tmpbuf = line;
    int i;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    for(i = 0; i < size; i++) {
        char *tmp = strtok(tmpbuf, " ");
        arr[i].num = strtol(tmp, NULL, 10);
        arr[i].type = type;
        tmpbuf = NULL;
    }
#else
#error
#endif
    return 0;
}

#define NUM_MAX 300000

int desc(const void *a, const void *b) {
    struct pair *pa = (struct pair*)a;
    struct pair *pb = (struct pair*)b;
    return pb->num - pa->num;
}

int main(void) {
    int a, b, c, xa, xb;
    struct pair arr[NUM_MAX];
    get_int5(&xa, &xb, &a, &b, &c);
    int size = a + b + c;

    fget_array(arr, a, TYPE_A);
    fget_array(&arr[a], b, TYPE_B);
    fget_array(&arr[a+b], c, TYPE_ALL);

    qsort(arr, size, sizeof(struct pair), desc);
    int i;
    int cnt[3];
    int sumcnt = 0; // requires xa+xb
    uint64_t sum = 0;
    for(i = 0; i < size; i++) {
        int type = arr[i].type;
        if(sumcnt == xa+xb) break;
        if(type == TYPE_A && cnt[TYPE_A] >= xa) continue;
        if(type == TYPE_B && cnt[TYPE_B] >= xb) continue;
        sumcnt++;
        cnt[type]++;
        sum += (uint64_t)arr[i].num;
    }
    printf("%llu\n", sum);
    return 0;
}

Measured memory_bytes: 5884
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n; cin >> n;
    string s = "";
    while(n){
        if(n%2==0){
            s = '0'+s;
        }else{
            s = '1'+s;
            n--;
        }
        n/=-2;
    }
    if(s=="") cout << 0 << endl;
    else cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
// ABC042_B
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値

int main() {
    // input
    ll N, L;
    cin >> N >> L;
    vector<string> vec(N);
    REP(i, N) cin >> vec[i];
    sort(vec.begin(), vec.end());
    
    // calculation
    for (ll i = 0; i < N; ++i) {
        cout << vec[i];
    }
    cout << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8) cout << "Yay!" << endl;
	else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;
long long f(long long a){
	if(a==1){
      return 1;
    }else{
      return 2*f(a/2)+1;
    }
}
int main(){
  long long h;
  cin >> h;
  long long ans;
  ans = f(h);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  qsort(a, n, sizeof(long), cmpnum);
  long must_eat = 0;
  for (long i = 1; i < n; i++) {
    if (a[i] == a[i-1]) {
      must_eat++;
    }
  }
  long left = n-must_eat;
  if (must_eat%2 != 0) {
    left--;
  }
  printf("%ld\n", left);

  return 0;
}

Measured memory_bytes: 1788
object Main extends App {

  import scala.io.StdIn._

  solve
  def solve: Unit = {
    val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
    if (n == 0) return
    val cities = Array.tabulate(n){_ ⇒ new UnionFindTree}
    var cost = 0
    for ((a, b, c) ← Array.tabulate(m){_ ⇒
      val Array(a, b, cost) = readLine.trim.split(' ').map(_.toInt)
      (a, b, cost)
    }.sortBy(_._3)){
      if (!cities(a).isSameUnion(cities(b))){
        cities(a).merge(cities(b))
        cost += c
      }
    }
    println(cost)
    solve
  }
  class UnionFindTree{
    private var mParent: Option[UnionFindTree] = None
    private var mSize: Int = 1
    private def parent: UnionFindTree = {
      mParent.map{_.parent} match {
        case None ⇒ this
        case c@Some(p) ⇒
          mParent = c
          p
      }
    }
    def isSameUnion(that: UnionFindTree): Boolean = {
      parent == that.parent
    }
    def merge(that: UnionFindTree): Unit = {
      if (!isSameUnion(that)){
        val p = parent
        val tp = that.parent
        if (p.mSize > tp.mSize){
          tp.mParent = Some(p)
          p.mSize += tp.mSize
        }else {
          p.mParent = Some(tp)
          tp.mSize += p.mSize
        }
      }
    }
  }
  implicit class Extension[T](val value :T) extends AnyVal {
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}


Measured memory_bytes: 44876
#include<bits/stdc++.h>
#define ALL(c) (c).begin(), (c).end()
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6+6;


int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	
	int n, m;
	
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;++i) cin>>a[i];
	
	ll l = 2, r = 2;
	for(int i=n-1;i>=0;--i){
		ll x = a[i];
		if(l%x!=0){
			l+=x-l%x;
		}
		if(r%x!=0){
			r-=r%x;
		}
		r+=x-1;
		if(l>r){
			cout<<-1<<endl;
			return 0;
		}
	}
	
	cout<<l<<' '<<r<<endl;
	
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>
using namespace std;

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define llrp(i,n) for(long long i=0;i<n;i++)
#define llrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define vcin(a); rp(i,a.size()){cin>>a[i];}
#define vcout(a); rp(i,a.size()){cout<<a[i]<<endl;}
#define allchar(c) for(char c='a';c<='z';c++)

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;
typedef queue<int> qi;

const int mod=1e9+7;

ll modpow(ll a,ll b,ll p){
    if(b==0){
        return 1;
    }elif(b%2==0){
        return modpow((a*a)%p,b/2,p);
    }else{
        return (a*modpow(a,b-1,p))%p;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<double> a(n);
    vcin(a);
    double ave=0;
    rp(i,n){
        ave += a[i];
    }
    ave /= n;
    double dmin=INT_MAX,ans=0;
    rp(i,n){
        if(abs(a[i]-ave)<dmin){
            dmin=abs(a[i]-ave);
            ans=i;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int dp[21][11][156] = {0};

int main(){
    int n,k,s;
    for(int i=1;i<21;++i)
            dp[i][1][i] = 1;
    for(int i=1;i<21;++i){
        for(int j=1;j<11;++j){
            for(int l=1;l<156;++l){
                dp[i][j][l] += dp[i-1][j][l];
                if(l - i > 0)
                    dp[i][j][l] += dp[i-1][j-1][l-i];
            }
        }
    }
    while(scanf("%d %d %d",&n,&k,&s), n != 0 || k != 0 || s != 0){
        printf("%d\n",dp[n][k][s]);
    }

    return 0;
}

Measured memory_bytes: 3264
int main(void){
	float x1,x2,x3,x4,y1,y2,y3,y4;
	int n;
	
	scanf("%d",&n);
	
	for(;n > 0;n--){
		scanf("%f %f %f %f %f %f %f %f",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
		if((y2-y1)/(x2-x1) == (y4-y3)/(x4-x3)){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 616
#include <stdio.h>
#define swap(type, x, y)  do{ type t = x; x = y; y = t; }while(0)

void quick(int array[], int left, int right){
  int pl = left, pr = right, x = array[(left + right) / 2];
  do{
    while(array[pl] < x)  pl++;
    while(array[pr] > x)  pr--;
    if(pl <= pr){
      swap(int, array[pl], array[pr]);
      pl++, pr--;
    }
  }while(pl <= pr);
  if(pl < right)  quick(array, pl, right);
  if(pr > left)  quick(array, left, pr);
}

int main(){
  int n, m, d[200005], t[200005];
  scanf("%d", &n);
  for(int i=0; i<n; i++)  scanf("%d", d+i);
  quick(d, 0, n-1);
  scanf("%d", &m);
  for(int i=0; i<m; i++)  scanf("%d", t+i);
  quick(t, 0, m-1);
    
  int flag = 1, start = 0;
  for(int i=0; i<m; i++){
    int notFound = 1;
    for(int j=start; (d[j]<=t[i] && j<n); j++)
      if(d[j] == t[i]){
	notFound = 0;
	start = j + 1;
	break;
      }
    if(notFound){
      flag = 0;
      break;
    }
  }
  if(flag)  printf("YES\n");
  else  printf("NO\n");
  return 0;
}


Measured memory_bytes: 1664
#!/usr/bin/env python3
import sys


YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: int, B: int, C: int):
    print(YES if A <= C <= B else NO)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
int main() {
  ios::sync_with_stdio(false);
  int x;
  cin>>x;
  cout<<(x+1)/2<<'\n';
  return 0;
}


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

int main() {
    char s[11];
    char t[4]={'\0'};
    int i, j, n, ans=10000;
    scanf("%s", s);
    n=strlen(s);
    for (i=0;i<n-2;i++) {
        for (j=0;j<3;j++) t[j]=s[i+j];
        if (abs(atoi(t)-753)<ans) ans=abs(atoi(t)-753);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1680
#include<iostream>
#include<string>
#include<stdio.h>
#include<cmath>
using namespace std;

#define max(a,b) a > b ? a : b

int main() {

    int N;

    cin >> N;

    if (N % 2 == 0)
    {
        cout << (N / 2) << endl;
    }
    else
    {
        cout << (N+1)/2 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6;

int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    string s;
    cin>>s;
    int f1=0,f2=0;
    for(int i=0;i<3;i++){
        if(s[i]=='A')f1=1;
        else f2=1;
    }
    if(f1+f2==2){
        puts("Yes");
    }
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;

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

int main() {
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  vector<vector<char>> ans(h,vector<char>(w));
  rep(i,h) cin >> s[i];
  rep(i,h){
    rep(j,w){
      int now=0;
      rep(k,8){
        if(i + dy[k] < 0 || i + dy[k] >= h || j + dx[k] < 0 || j + dx[k] >= w) continue;
				if(s[i+dy[k]][j+dx[k]] == '#') now++;
      }
      ans[i][j]=now+'0';
    }
  }
  rep(i,h){
    rep(j,w){
      if(s[i][j]=='#')
        cout << '#';
      else cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)

int main() {
    string s;
    bool c=false;
    int count=0,len;
    cin >> s;
    while(1) {
        c=false;
      	len = s.length()-1;
        REP(i,len) {
            if(s[i] != s[i+1]) {
                s.erase(i,2);
                c=true;
                count+=2;
                break;
            }
        }
        if(c==false) break;
    }
    cout << count;
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

int main(){
  int N, M;
  cin >> N >> M;
  N == M ? yes : no;
}

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


int main() {

    int a, b;
    string s;
    cin >> a >> b >>s;
    for (int i = 0; i < a; ++i) {
        if (s[i] == '-') {
            cout << "No" << endl;
            return 0;
        }
    }
    if (s[a] != '-') {
        cout << "No" << endl;
        return 0;
    }
    for (int i = a+1; i < a+b+1; ++i) {
        if (s[i] == '-') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

/* 配列の要素を順番に出力 */
void trace(int A[],int N) {
	int i;
	for(i=0;i<N;i++) {
		/* 隣接する要素の間に1つの空白を出力 */
		if(i>0) printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
}

/* 挿入ソート(0オリジン配列) */
void insertionSort(int A[], int N) {
	int i,j,v;
	for(i=1;i<N;i++) {
		v=A[i];
		j=i-1;
		while(j>=0 && A[j] > v) {
			A[j+1] = A[j];
			j--;
		}
		A[j+1]=v;
		trace(A,N);
	}
}

int main(void)
{
	int N, i, j;
	int A[100];
	scanf("%d",&N);
	for(i=0;i<N;i++) scanf("%d",&A[i]);
	
	trace(A,N);
	insertionSort(A,N);
	return 0;
}

Measured memory_bytes: 604
using System;

namespace abc120_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] array = Console.ReadLine().Split(' ');
            int a = int.Parse(array[0]);
            int b = int.Parse(array[1]);
            int c = int.Parse(array[2]);
            int max = b / a;
            if (max > c)
            {
                Console.WriteLine(c);
            }
            else if(max < c)
            {
                Console.WriteLine(max);
            }
            else
            {
                Console.WriteLine(max);
            }
        }
    }
}


Measured memory_bytes: 13140
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;
typedef long long ll;


int main(int argc, char *args[]) {
	int N;
	int A[101];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int counter;
	counter = 1;
	sort(A, A + N, greater<int>());
	for (int i = 0; i < N - 1; i++) {
		if (A[i] > A[i + 1]) {
			counter++;
		}
	}
	cout << counter << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top,S[1000];

void push(int x){

 S[++top]=x;

}

int pop(){
 top--;
 return S[top+1];
}

int main(){
 int a,b;
 top=0;
 char s[100];


 while(scanf("%s",s)!=EOF){
  if(s[0]=='+'){
   a=pop();
   b=pop();
   push(a+b);
  }else if(s[0]=='-'){
   b=pop();
   a=pop();
   push(a-b);
  }else if(s[0]=='*'){
   a=pop();
   b=pop();
   push(a*b);
  }else{
   push(atoi(s));
  }
 }

printf("%d\n",pop());
 return 0;
}

Measured memory_bytes: 1840
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll x, y, z;std::cin >> x >> y >> z;
  swap(x, y);
  swap(x, z);
  std::cout << x << " " << y << " " << z << '\n';
  return 0;
}


Measured memory_bytes: 504
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array


def is_valid_number(sequence):
    q = lambda n: (n + 1) if 1 <= n <= 6 else (n - 5)
    sum_pq = 0
    for index in range(1, 12):
        sum_pq += sequence[index] * q(index)
    rem_pq = sum_pq % 11
    check_digit = 0 if rem_pq <= 1 else (11 - rem_pq)
    return sequence[0] == check_digit


def string2array(st):
    return array.array("B", map(int, st[::-1]))


def solve(s):
    candidates = set()
    for r in range(0, 10):
        sequence = string2array(s.replace("?", str(r)))
        if is_valid_number(sequence):
            candidates.add(r)
    if len(candidates) == 1:
        return candidates.pop()
    else:
        return -1


def main():
    answer = solve(input())
    print("MULTIPLE" if answer == -1 else answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 7852
#include <cstdio>

int main()
{
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  puts(
    ((a == 5 ? 1 : 0) + (b == 5 ? 1 : 0) + (c == 5 ? 1 : 0)) == 2 &&
    ((a == 7 ? 1 : 0) + (b == 7 ? 1 : 0) + (c == 7 ? 1 : 0)) == 1 ? "YES" : "NO"
  );
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

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

        switch (sc.next()) {
            case "Sunny":
                System.out.println("Cloudy");
                break;
            case "Cloudy":
                System.out.println("Rainy");
                break;
            default:
                System.out.println("Sunny");
        }
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int m,n;
char s[21][21];
int dp[2][1<<20][2];

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

	cin >> m >> n;

	int cnt = 0;

	for (int i = 0;i < m;i++){
		for (int j = 0;j < n;j++){
			cin >> s[i][j];
			if(s[i][j] == '?') cnt++;
		}
	}

	memset(dp,0,sizeof(dp));
	
	int crt = 0, next = 1;
	int mod = 100000;
	int ans = 0;
	
	dp[crt][0][0] = 1;
	for (int i = 0;i < m;i++){
		for (int j = 0;j < n;j++){
			memset(dp[next],0,sizeof(dp[next]));
			for (int k = 0;k < (1<<n);k++){
				int a=0, b=0,c=0;
				if(dp[crt][k][0] != 0){
					if(s[i][j] != '?'){
						if(s[i][j] == 'J') a += dp[crt][k][0];
						if(s[i][j] == 'O') b += dp[crt][k][0];
						if(s[i][j] == 'I' && !(k&1)) b += dp[crt][k][0];
						//if(s[i][j] == 'I' && (k&1)) cout << i << " " << j << endl;
					}else{
						a += dp[crt][k][0];
						b += dp[crt][k][0];
						if(!(k&1)) b += dp[crt][k][0];
						//else cout << dp[crt][k][0] << endl;
					}
				}
				if(dp[crt][k][1] != 0){
					if(s[i][j] != '?'){
						if(s[i][j] == 'J') a += dp[crt][k][1];
						if(s[i][j] == 'O') c += dp[crt][k][1];
						if(s[i][j] == 'I'){
							if(!(k&1)) b += dp[crt][k][1];
						}
					}else{
						a += dp[crt][k][1];
						c += dp[crt][k][1];
						if(!(k&1)) b += dp[crt][k][1];
					}
				}
				//cout << a << " " << b << " " << c << " " << bitset<4>(k) << endl;
				//cout << dp[crt][k][0] << " " << dp[crt][k][1] << endl;
				dp[next][k>>1][1] += a % mod;
				dp[next][k>>1][0] += b % mod;
				if(j != 0)dp[next][k>>1|1<<(n-2)][0] += c % mod;
				else dp[next][k>>1][0] += c % mod;
			}
			swap(crt,next);
		}
	}

	int tmp = 1;

	for (int i = 0;i < cnt;i++){
		tmp *= 3;
		tmp %= mod;
	}

	for (int i = 0;i < (1<<n);i++){
		for (int j = 0;j < 2;j++){
			ans += dp[crt][i][j];
			ans %= mod;
		}
	}
	//cout << ans << endl;
	cout << (tmp+mod-ans)%mod << endl;

	return 0;

}



Measured memory_bytes: 19560
#include<bits/stdc++.h>
using namespace std;
vector<int> g[100000+5], v;
int dp[100000+10];
bool in[100000+5];
int n, m;
int bfs(int i){
    if(dp[i]!=-1) return dp[i];
    dp[i] = 0;
    for(auto x : g[i]){
        dp[i] = max(bfs(x)+1, dp[i]);
    }
    return dp[i];
}
int main(){
    cin >> n >> m;
for(int i=0; i<m; i++){
int x, y;
cin >> x >> y;
x--, y--;
g[x].push_back(y);
in[y] = true;
}
for(int i=0; i<n; i++){
dp[i] = -1;
if(in[i]==false) v.push_back(i);
}
int ans = 0;
for(int i=0; i<v.size(); i++){
if(dp[v[i]]==-1){
    dp[v[i]] = bfs(v[i]);
    ans = max(ans, dp[v[i]]);
}
}
cout << ans ;
return 0;
}


Measured memory_bytes: 13992
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool isprime(ll n) {
    if (n < 2) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}
vll sieve(ll n) {
    str flg = str(n + 1, '1');
    for (ll i = 2; i * i <= n; i++) if (flg[i] ^ '0')
        for (ll j = i * i; j <= n; j += i)
            flg[j] = '0';
    vll res;
    for (ll i = 2; i <= n; i++)
        if (flg[i] ^ '0') res.push_back(i);
    return res;
}
ll rpow(ll x, ll n) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) k *= x;
        x *= x;
    }
    return k * x;
}
ll modpow(ll x, ll n, ll mod) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) (k *= x) %= mod;
        (x *= x) %= mod;
    }
    return k * x % mod;
}
ll modcomb(ll n, ll r, ll mod) {
    if (r < 0 || n < r) return 0;
    chmin(n - r, r);
    ll mul = 1, div = 1;
    for (ll i = 0; i < r; i++) {
        (mul *= n - i) %= mod;
        (div *= i + 1) %= mod;
    }
    return mul * modpow(div, mod - 2, mod) % mod;
}

/*------------------------------------------------------------------------*/

constexpr ll MOD = 1e9 + 7;

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}
void solve() {
    ll n;
    std::cin >> n;

    auto legendre = [&](ll n, ll p) -> ll {
        ll res = 0;
        for (ll i = p; i <= n; i *= p)
            res += n / i;

        return res;
    };

    ll ans = 1;
    for (ll p : sieve(n))
        (ans *= legendre(n, p) + 1) %= MOD;

    std::cout << ans << '\n';
}


Measured memory_bytes: 3608
#include<cstdio>
using namespace std;
int n;
int f[4];
int main()
{
	for (int i=1;i<=2;++i)
	{
		scanf("%d",&n);
		f[n]=1;
	}
	for (int i=1;i<=3;++i)
		if (!f[i])
		{
			printf("%d",i);
			break;
		}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define ld long double
#define pii pair <int,int>
#define pll pair <ll,ll>
#define pil pair <int,ll>
#define pli pair <ll,int>
#define ull unsigned long long
#define pdd pair <double,double>
#define pb push_back
#define mp make_pair
#define puu pair<ull,ull>
#define pvv pair<vector<int>, vector<int> >
#define _bp __builtin_popcount
#define ptt pair <Tree*,Tree*>
#define all(v) v.begin(),v.end()
#define en "\n"
const long double pi = acos(-1);
void boos()
{
     ios_base :: sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
}
void file()
{
   freopen("max.in","r",stdin);
   freopen("max.out","w",stdout);
}
const ll INF = 1e9 + 7;
const ll INF1 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTmx = (int)1e9;
const ld EPS = (ld)1e-9;
const int N = 3e5 + 100;
int main()
{
    //file();
    boos();
    ll x;
    cin >> x;
    ll ans = (x / 500ll) * 1000ll;
    x %= 500;
    x = (x / 5) * 5;
    ans += x;
    cout << ans;
}

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

int main(){
	char c;
	cin >> c;
	if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o'){
		cout << "vowel" << "\n";
	} else cout << "consonant" << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<utility>
#include<vector>
class Card {
public:
	//private????????????
	int check;
	std::string DesignCard;
	int ValueCard;
	//public
	int ReturnValue();
	void SetCheck(int InputValueCard, std::string InputDesignCard, int num);
	
	
};
void Card::SetCheck(int InputValueCard, std::string InputDesignCard, int num) {
	check = num;
	ValueCard = InputValueCard;
	DesignCard = InputDesignCard;
}
int Card::ReturnValue() {
	return ValueCard;
}

int  partition(std::vector<Card>&A, int p, int r) {
	int x = A[r].ValueCard;
	int i = p - 1;
	for (int j = p; j <= r - 1; ++j) {
		if (A[j].ValueCard <= x) {
			++i;
			std::swap(A[i], A[j]);
			}
	}
	std::swap(A[i + 1], A[r]);
	return i + 1;
}

void  quickSort(std::vector<Card>&A, int p, int r) {

	if (p < r) {
	int	q = partition(A, p, r);
	quickSort(A, p, q - 1);
	quickSort(A, q + 1, r);
	}
		     
	return;
}
bool stable(std::vector<Card> InputCard) {
	for (unsigned int i = 0; i < InputCard.size() - 1; ++i) {
		if (InputCard[i].ReturnValue() == InputCard[i + 1].ReturnValue()) {
			if (InputCard[i].check > InputCard[i + 1].check) {
				return false;
			}
		}
	}
	return true;
}
void print_stable(bool stable) {
	if (stable == true) {
		std::cout << "Stable" << std::endl;
	}
	else {
		std::cout << "Not stable" << std::endl;
	}
}
int main(void) {
	std::ios_base::sync_with_stdio(false);
	int n;
	std::cin >> n;
	std::vector<std::pair<std::string, int> >Input(n, { "",0 });
	for (int i = 0; i < n; ++i) {
		std::cin >> Input[i].first >> Input[i].second;
	}
	std::vector<Card>QuickCard(n);
	for (int i = 0; i < n; ++i) {
		QuickCard[i].SetCheck(Input[i].second, Input[i].first, i);
			}
	quickSort(QuickCard, 0, n - 1);
	 print_stable(stable(QuickCard));
	for (int i = 0; i < n; ++i) {
	  std::cout << QuickCard[i].DesignCard << " " << QuickCard[i].ValueCard << std::endl;
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 13824
A = []
for i in range(3):
  A.append(list(map(int, input().split())))

a1 = 0
b1 = A[0][0]
b2 = A[0][1]
b3 = A[0][2]
a2 = A[1][0] - b1
a3 = A[2][0] - b1

if A[1][1] == a2 + b2 and A[2][1] == a3 + b2 and A[1][2] == a2 + b3 and A[2][2] == a3 + b3:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
import sys

input = sys.stdin.readline


def main():
    S = input().strip()
    K = int(input())

    dic = []
    for i in range(len(S)):
        j = 0
        tmp = ""
        while i + j < len(S) and j < 5:
            tmp += S[i + j]
            if tmp not in dic:
                dic.append(tmp)
            j += 1

    dic.sort()
    print(dic[K - 1])



    
    
    


if __name__ == '__main__':
    main()


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

int mod = 1e9 + 7;
int dp[100005][2];

int main() {
    string L; cin >> L;
    int ss = L.size();

    dp[0][0] = 1;
    rep(i, ss){
        //a+b[i] = 0
        if(L[i] == '0'){
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][1];
        } else {
            dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod;
        }
        //a+b[i] = 1
        if(L[i] == '0'){
            (dp[i+1][1] += (dp[i][1] * 2) % mod) %= mod;
        } else {
            (dp[i+1][0] += (dp[i][0] * 2) % mod) %= mod;
            (dp[i+1][1] += (dp[i][1] * 2) % mod) %= mod;
        }
    }

    int ans = dp[ss][0] + dp[ss][1];
    ans %= mod;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4548
k,t=map(int,input().split())
a=[int(x) for x in input().split()]
a.sort()
now1=0
now2=0
al=sum(a)
ans=float('inf')
for i in range(t):
  now1+=a[i]
  now2=al-now1
  ans=min(ans,abs(now1-now2)-1)

if ans<=0:
  print(0)
else:
  print(ans)


Measured memory_bytes: 61984
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int n=s.nextInt();
		
		long ans=0;
		
		for(int i=1;i<1000001;i++)
		{
			if(n%i==0)
			{
				ans=ans+(n/i)-1;
			}
			else
			{
				ans=ans+(n/i);
			}
		}
		
		System.out.println(ans);
		
	}
	
}

Measured memory_bytes: 35772
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll x;
	cin>>x;
	__int128 y=x;
	__int128 a=100;
	__int128 p=101,q=100;
	int c=0;
	while(a<y)
	{
		c++;
		a*=p;
		a/=q;
	}
	cout<<c<<"\n";
	return 0;
}

Measured memory_bytes: 3640
N,M = map(int,input().split())
H = list(map(int,input().split()))
G = [0]*N
for _ in range(M):
    a,b = map(int,input().split())
    G[a-1] = max(G[a-1],H[b-1])
    G[b-1] = max(G[b-1],H[a-1])
cnt = 0
for i in range(N):
    if H[i]>G[i]:
        cnt += 1
print(cnt)

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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < t.length(); i++) {
        cout << t[i];
    }
    for(int i = 0; i < s.length(); i++) {
        cout << s[i];
    }
    cout << endl;
    return 0;
}

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

int main() {
  int N, l,r,t;
  t = 0;
  cin >> N ;
  for(int i = 0; i<N ; i++){
  cin >> l >> r;
  t = t + (r - l + 1);
  }
cout << t <<endl;
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static int digitSum(int input) {
        int output = 0;
        int tmp = 1;
        while (tmp <= input) {
            output += (input / tmp) % 10;
            tmp *= 10;
        }
        return output;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int val = sc.nextInt();

        String res = (val % digitSum(val) == 0) ? "Yes" : "No";
        System.out.println(res);

    }
}


Measured memory_bytes: 23380
k=io.read("n")
q={1,2,3,4,5,6,7,8,9}
for i=1,k-1 do
    for j=-1,1 do
        a=(q[i]%10)+j
        if 0<=a and a<=9 then
            table.insert(q,q[i]*10+a)
        end
    end
end
print(q[k])

Measured memory_bytes: 6668
#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;
int n,m,a[100][100],b[100][100],dp[81][81][12810];

bool check(int i , int j){
    return (i < n && j < m);
}

int Rec(int i , int j , int sum){

    if(i == n - 1 && j == m - 1)  return min(abs(sum  + a[i][j] - b[i][j] - 6400) , abs(sum - a[i][j] + b[i][j] - 6400));

    if(dp[i][j][sum] != -1)  return dp[i][j][sum];

    int Res = 1e9;
    if(check(i + 1 , j))
    {
        Res = min(Res , Rec(i + 1 , j , sum - a[i][j] + b[i][j]));
        Res = min(Res , Rec(i + 1 , j , sum + a[i][j] - b[i][j]));
    }

    if(check(i , j + 1)){
        Res = min(Res , Rec(i , j + 1 , sum - a[i][j] + b[i][j]));
        Res = min(Res , Rec(i , j + 1, sum + a[i][j] - b[i][j]));
    }
    return dp[i][j][sum] = Res;
}

int main()
{
    memset(dp , -1 , sizeof(dp));
    cin >> n >> m;
    for(int i =0;i<n;i++){
        for(int j =0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(int i =0;i<n;i++){
        for(int j =0;j<m;j++){
            scanf("%d",&b[i][j]);
        }
    }
    cout << Rec(0 , 0 , 6400);
    return 0;
}


Measured memory_bytes: 328576
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

int n,k,c;
string s;

set<int> greed(bool flip){
    set<int> ans;
    int last = -c;
    for(int i = 0; i < n; ++i){
        if(s[i]=='o' && i-last>=c){
            last = i;
            if(!flip) ans.insert(i);
            else ans.insert(n-1-i);
        }
    }
    return ans;
}

void solve(){
    cin>>n>>k>>c>>s;
    ++c;
    set<int> s1 = greed(false); 
    if((int)s1.size()==k){
        reverse(s.begin(), s.end());
        set<int> s2 = greed(true);
        for(int i : s1){
            if(s2.count(i)){
                cout << i+1 << "\n";
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 22300