akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //------------------------------
    ll n,a,b;cin>>n>>a>>b;
    ll c=a+b;
    ll d=n/c;
    ll ans=d*a;
    if(n%c!=0){
        ans+=mmin(a,n%c);
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------

/*
ll n;cin>>n;
vector<ll>a(n);
for(ll i=0;i<n;i++)
    cin>>a[i];
 
ll n;cin>>s;
string s;cin>>s;

ll n,m;cin>>n>>m;
vector<ll>a(n),b(m);
for(ll i=0;i<n;i++){
    cin>>a[i];
}
for(ll i=0;i<m;i++){
    cin>>b[i];
}

ll n;cin>>n;
vector<Pll>xy;
for(ll i=0;i<n;i++){
    ll x,y;cin>>x>>y;
    xy.pb({x,y});
}
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

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

const ll INF = 1e17;
const ll MOD = 1e9+7;

int main() {
    // input, ready
    int N,K,C;
    string S;
    cin >> N >> K >> C;
    cin >> S;
    vector<bool> entry(N);
    int cnt = 0;
    for (auto s: S) {
      if (s == 'o') entry[cnt] = true;
      else entry[cnt] = false;
      cnt++;
    }

    // resolve
    vector<int> left(N);
    vector<int> right(N);
    for (int i=0; i<N; i++) {
      left[i] = 0;
      right[i] = 0;
    }
    int k = 0;
    int c = C;
    for (int i=0; i<N; i++) {
      if (entry[i] && C <= c) {
        k++;
        left[i] = k;
        c = 0;
      }
      else {
        left[i] = 0;
        c++;
      }
      if (k >= K) break;
    }

    k = K;
    c = C;
    for (int i=N-1; i>=0; i--) {
      if (entry[i] && C <= c) {
        right[i] = k;
        k--;
        c = 0;
      }
      else {
        right[i] = 0;
        c++;
      }
      if (k <= 0) break;
    }    

    // output
    for (int i=0; i<N; i++) {
      if (left[i] == right[i] && left[i] > 0) cout << i+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 3460
#include<iostream>
using namespace std;
#include<bits/stdc++.h>
int main(){
  int n,a,b;
  cin>>n>>a>>b;
  string s;cin>>s;
  int no=0,r=0;
  for(int i=0;i<n;i++){
    if(s[i]=='a'){
      if(no<(a+b)){
        no++;
        cout<<"Yes\n";
      }
      else
        cout<<"No\n";
    }
    else if(s[i]=='b'){
      if(no<(a+b) and r<b){
        r++;
        no++;
        cout<<"Yes\n";
      }
      else
        cout<<"No\n";
    }
    else{
      cout<<"No\n";
    }
  }
  return 0;
}

Measured memory_bytes: 896
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, A, B := ReadInt(), ReadInt(), ReadInt()
	q := N / (A + B)
	r := N % (A + B)
	if r > A {
		fmt.Println(q*A + A)
	} else {
		fmt.Println(q*A + r)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
using namespace std;
const int N = 1e6 + 10, Mod = 1e9 + 7;
int n, m, q, r, t, a, b, c, d, A[N], B[N];
int main()
{
    scanf("%d", &n);
    long long suma = 0, sumb = 0;
    for (int i = 1; i <= n; i++)
        scanf("%d", &A[i]), suma += A[i];
    for (int i = 1; i <= n; i++)
        scanf("%d", &B[i]), sumb += B[i];
    if (suma < sumb)
        return !printf("-1");
    long long need = 0;
    vector < int > V;
    for (int i = 1; i <= n; i++)
    {
        if (A[i] < B[i])
        {
            need += B[i] - A[i];
            c ++;
        }
        else
            V.push_back(A[i] - B[i]);
    }
    sort(V.begin(), V.end());
    reverse(V.begin(), V.end());
    for (int &a : V)
    {
        if (need <= 0)
            return !printf("%d\n", c);
        need -= a;
        c ++;
    }
    printf("%d\n", c);
    return (0);
}

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

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> T(N);
    ll ans = 1LL;
    for (int i = 0; i < N; i++)
    {
        ll T;
        cin >> T;
        ans = lcm(ans, T);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

int main(void){
  int h, w, i, j, d, q, l, r, a;

  vector<pair<int,int> > b;
  vector<int> c;

  cin >> h >> w >> d;
  b.resize(h*w+1,{-1,-1});
  c.resize(h*w+1,-1);
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      cin >> a;
      b[a] = {i,j};
    }
  }
  for(i=0;i<d;i++){
    j = i;
    c[j] = 0;
    j += d;
    while(j<=h*w){
      c[j] = c[j-d] + abs(b[j].first-b[j-d].first) + abs(b[j].second-b[j-d].second);
      j += d;
    }
  }

  cin >> q;
  for(i=0;i<q;i++){
    cin >> l >> r;
    cout << c[r] - c[l] << endl;
  }

  return 0;
}


Measured memory_bytes: 2176
import java.util.HashMap;
import java.util.Scanner;

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

		int n = sc.nextInt();
		int k = sc.nextInt();
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		int a = 0;

		for (int i = 0; i < k; i++) {
			int d = sc.nextInt();
			for (int j = 0; j < d; j++) {
				a = sc.nextInt();
				if (!map.containsKey(a))
					map.put(a, a);
			}
		}
		System.out.println(n - map.size());
	}

}


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

int gcm(int x,int y){
  int num;
	while (y != 0) {
		num = y;
		y = x % y;
		x = num;
	}
	return x;
}

int main(){
  int N,X;
  cin >> N >> X;
  int x[N];
  for(int i=0;i<N;i++){
    cin >> x[i];
  }
  int ans=0;
  for(int i=0;i<N;i++){
    ans=gcm(ans,abs(x[i]-X));
  }
  cout << ans <<endl;
}

Measured memory_bytes: 640
#145d
import scipy.misc

X,Y = map(int, input().split())

MOD_BY = 7 + 10**9

#たどり着くマスは
#(i+1,j+2)の移動回数をA
#(i+2,j+1)の移動回数をB
#とすると
#X = A + 2B
#Y = 2A + B
#となる
# A = X - 2B
# Y = 2(X - 2B) + B
# Y = 2X - 4B + B = 2X - 3B
# Y - 2X = - 3B
# 2X - Y = 3B
# ∴ B = (2X - Y)/3
# A = X - 2B = X -2{(2X - Y)/3}
# 3A = 3X -2(2X - Y) = 3X -4X +2Y = -X + 2Y
# ∴ A = (2Y - X)/3

A = (2*X - Y) / 3
B = (2*Y - X) / 3

#移動回数なのでA,Bともに整数かつマイナスはNG
#OKならば、白赤のボールの並べ方は何通り? という設問と同じ。
# (A+B)C(A)
# https://qiita.com/derodero24/items/91b6468e66923a87f39f#%E6%97%A2%E5%AD%98%E3%83%84%E3%83%BC%E3%83%AB%E3%82%92%E7%94%A8%E3%81%84%E3%81%9F%E6%89%8B%E6%B3%95%EF%BC%93%E8%A9%95%E4%BE%A1-

def prepare(n, MOD):
 
    # n! の計算
    f = 1
    for m in range(1, n + 1):
        f *= m
        f %= MOD
    fn = f
     
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    
    return fn, inv


if A >= 0 and B >= 0 and A.is_integer() is True and  B.is_integer() is True: 
    A = int(A)
    B = int(B)
    
    #print(scipy.misc.comb(A+B, A, 1)%MOD_BY) #これだと間に合わない
    
    #https://ikatakos.com/pot/programming_algorithm/number_theory/mod_combination
    #nCr ≡ n! * r!^(-1) * (n-r)!^(-1)   (mod m)
    #n = A+B
    #r = A　より
    fn_A_plus_B = prepare(A+B,MOD_BY)[0]
    inv_A = prepare(A,MOD_BY)[1]
    inv_B = prepare(B,MOD_BY)[1]
    
    print(fn_A_plus_B * inv_A * inv_B % MOD_BY)
    
else:
    print(0)

Measured memory_bytes: 13336
/* basic header */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <climits>
#include <float.h>
/* STL */
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <array>
#include <iterator>
/* define */
#define ll long long
#define dou double
#define pb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define init(a,b) fill(begin(a),end(a),b)
#define sot(a,b) sort(a+1,a+1+b)
#define rep1(i,a,b) for(int i=a;i<=b;++i)
#define rep0(i,a,b) for(int i=a;i<b;++i)
#define repa(i,a) for(auto &i:a)
#define eps 1e-8
#define int_inf 0x3f3f3f3f
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lson curPos<<1
#define rson curPos<<1|1
/* namespace */
using namespace std;
/* header end */

int n, k;
string s;

int main()
{
    cin >> n >> k >> s;
    for (int i = 0; i < n; i++)
            if (i != k - 1) cout << s[i]; else cout << (char)(s[i] + 'a' - 'A');
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
// ##MohK
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int s;
    cin>>s;
    if(s<10) cout<<s;
    else if(s<100) cout<<9;
    else if(s>=100&&s<1000) cout<<9+(s-100+1);
    else if(s>=1000&&s<10000) cout<<9+899+1;
    else if(s>=10000&&s<100000) cout<<(9+900+s-10000+1);
    else if(s==100000) cout<<9+900+90000;



        return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        int M = sc.nextInt();
        int N = sc.nextInt();
        int[] A = new int[N];

        for (int i = 0; i < N; i++) {
            M -= sc.nextInt();
        }

        System.out.println(M >= 0 ? M : -1);
        
    }
}


Measured memory_bytes: 46364
#include <cstdio>
#include <algorithm>
const int MAXN = 200;
int D[MAXN];
int main()
{
	int N, i;
	scanf("%d", &N);
	N <<= 1;
	for(i=0; i<N; ++i)
		scanf("%d", D+i);
	std::sort(D, D+N);
	int ans = 0;
	for(i=0; i<N; i+=2)
		ans += D[i];
	printf("%d\n", ans);
}

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

typedef long long ll;

ll L, A, B, M;
typedef vector<ll> Row, Vec;
typedef vector<Row> Matrix;

Matrix zero() {
  return Matrix({Row({0, 0, 0}), Row({0, 0, 0}), Row({0, 0, 0})});
}
Matrix eye() {
  return Matrix({Row({1, 0, 0}), Row({0, 1, 0}), Row({0, 0, 1})});
}
Matrix mult(Matrix a, Matrix b) {
  Matrix res = zero();
  for (ll i : {0, 1, 2})
    for (ll j : {0, 1, 2})
      for (ll k : {0, 1, 2}) (res[i][j] += (a[i][k] * b[k][j]) % M) %= M;
  return res;
}
Vec mult(Matrix a, Vec v) {
  Vec res = {0, 0, 0};
  for (ll i : {0, 1, 2})
    for (ll j : {0, 1, 2}) (res[i] += (a[i][j] * v[j]) % M) %= M;
  return res;
}
Matrix pow(Matrix a, ll n) {
  Matrix res = eye();
  for (ll bit = 1; bit < (1ll << 60); bit <<= 1) {
    if (n & bit) res = mult(res, a);
    a = mult(a, a);
  }
  return res;
}

ll pow10(ll n) {
  ll res = 1;
  for (ll i = 0; i < n; ++i) res *= 10;
  return res;
}
ll no_more_than_i_digits(ll i) {
  ll limit = pow10(i) - 1;
  return limit < A ? 0 : min(1 + (limit - A) / B, L);
  ;
}
int main() {
  cin >> L >> A >> B >> M;
  Matrix all = eye();
  for (ll i = 1; i <= 18; ++i) {
    ll cnt = no_more_than_i_digits(i) - no_more_than_i_digits(i - 1);
    Matrix elem = {Row({pow10(i) % M, 1, 0}), Row({0, 1, B % M}),
                   Row({0, 0, 1})};
    all = mult(pow(elem, cnt), all);
  }
  Vec res = mult(all, Vec({0, A % M, 1}));
  cout << res[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

long long gcd(int a, int b) {
  if (b == 0)
    return a;
  else {
    return gcd(b, a % b);
  }
}

long long gcd_pre(int a, int b, int c) { return gcd(gcd(a, b), c); }

int main() {
  int K;
  cin >> K;
  long long sum = 0;
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; j++) {
      for (int k = 1; k <= K; k++) {
        int ret = gcd_pre(i, j, k);
        // cout << ret << endl;
        sum += ret;
      }
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3192
ar = input()
c1 = 0
c2 = 0
for i in range(len(ar)):
    if i % 2 == 0:
        if ar[i] == "0":
            c1 += 1
        elif ar[i] == "1":
            c2 += 1
    elif i % 2 == 1:
        if ar[i] == "0":
            c2 += 1
        elif ar[i] == "1":
            c1 += 1
print(min(c1,c2))

Measured memory_bytes: 3316
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b){
  return *(int*)a - *(int*)b;
}

int main(void){
  int a[5],k,i;
  for(i=0;i<5;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&k);
  qsort(a,sizeof(a)/sizeof(int),sizeof(int),cmp);
  if(a[4]-a[0]<=k) printf("Yay!\n");
  else printf(":(\n");
  return 0;
}

Measured memory_bytes: 128
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
        (cons (subseq str 0 pos)
              (split x (subseq str (+ pos size))))
        (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defmacro aif (expr then else)
  `(let ((it ,expr))
     (if it ,then ,else)))

(defmacro awhen (expr &rest then)
  `(aif ,expr (progn ,@then) nil))

(defun comulative (function list &key base)
  (if base
      (comulative function (cons base list))
      (do ((lst (cdr list) (cdr lst))
           (acc (list (car list))))
          ((null lst) (reverse acc))
        (push (funcall function (car acc) (car lst)) acc))))

(defun binary-search (function left right
                      &optional
                        (eps 1)
                        (average-function (lambda (x y) (ash (+ x y) -1))))
  (if (<= (abs (- left right)) eps)
      right
      (let ((mid (funcall average-function left right)))
        (if (funcall function mid)
            (binary-search function left mid eps average-function)
            (binary-search function mid right eps average-function)))))

(defun arithmetic-mean (&rest body)
  (/ (apply #'+ body) (length body)))

(defvar +MOD+ (+ (expt 10 9) 7))

(defun mapa-b (fn a b &optional (step 1))
  (do ((i a (+ i step))
       (result nil))
      ((> i b) (nreverse result))
    (push (funcall fn i) result)))

(defun map0-n (fn n)
  (mapa-b fn 0 n))

(defun map1-n (fn n)
  (mapa-b fn 1 n))

(defun read-string (&optional (stream *standard-input*))
  (labels ((is-empty (x)
             (or (char= x #\space) (char= x #\newline))))
    (loop for char = (read-char stream)
          with result
          when (is-empty char)
            do (return (concatenate 'string (nreverse result)))
          do (push char result))))

(defun main (str)
  (and (char= (aref str 0) #\A)
      (= 1 (count #\C (subseq str 2 (1- (length str)))))
      (every #'lower-case-p (remove-if (lambda (x) (or (char= x #\A) (char= x #\C))) str))))

(princ (if (main (read-string)) "AC" "WA"))


Measured memory_bytes: 24764
from bisect import bisect_left

def Triangles(N, L):
    asc = sorted(L)
    cnt = 0
    for i in range(N-2):
        l1 = asc[i]
        for j in range(i+1, N-1):
            l2 = asc[j]
            pos = bisect_left(asc, l1+l2)
            cnt += pos - 1 - j
    return cnt

N = int(input())
L = list(map(int, input().split()))
print(Triangles(N, L))

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main()
{
	int a, b, c;
	int count;

	cin >> a >> b >> c;

	count = 0;
	for(int i = a; i <= b; i++){
		if(c % i == 0)
			count++;
	}
	cout << count << endl;

	return 0;
}


Measured memory_bytes: 3116
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        long K = sc.nextLong();
        char c = 'a';
        int a = 0;
        for(int i = 0;i < S.length();i++){
            if(S.charAt(i) != '1'){
                c = S.charAt(i);
                a = i+1;
                break;
            }
        }
        if(a == 0 || a > K)  System.out.println(1);
        else    System.out.println(c);
    }
}

Measured memory_bytes: 23508
#include <cstdio>
#include <map>
using namespace std;
int n, m, a;
map<int, int> mp;
int main() {
	scanf("%d", &n);
	while(n--) {
		scanf("%d", &a);
		mp[a]++;
	}
	scanf("%d", &m);
	while(m--) {
		scanf("%d", &a);
		if(mp[a]==0) return !puts("NO");
		mp[a]--;
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 9600
# -*- coding: utf-8 -*-
X,K,D=map(int,input().split())

X=abs(X)
ii=int(X/D)
if K<=ii:
    X-=K*D
else:
    X-=ii*D
    if (K-ii)%2==1:
        X-=D

print(abs(X))
        


Measured memory_bytes: 9080
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long ll;

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

  vector<ll> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  cout << A[N-1] - A[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> L(M), R(M);
    for (ll i = 0; i < M; i++) {
        cin >> L[i] >> R[i];
    }

    ll ans = *min_element(R.begin(), R.end()) - *max_element(L.begin(), L.end()) + 1;
    cout << max(ans, (ll)0) << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define dcout cout<<fixed<<setprecision(20)
#define Accepted_MAGIC cin.tie(0);ios::sync_with_stdio(false)

// typedef long long ll;
using Real = long double;
#define int long long

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;
constexpr Real eps = 1e-9, pi = acos(-1);

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

signed main(void){
  Accepted_MAGIC;
  
  int X, Y, A, B, C, p[100000], q[100000], r[100000];
  cin >> X >> Y >> A >> B >> C;
  REP(i, A) cin >> p[i];
  REP(i, B) cin >> q[i];
  REP(i, C) cin >> r[i];
  sort(p, p+A); reverse(p, p+A);
  sort(q, q+B); reverse(q, q+B);
  sort(r, r+C); reverse(r, r+C);
  pque<int, vector<int>, greater<int> > que;
  int Asum = 0, Bsum = 0;
  REP(i, X){
    que.push(p[i]); Asum += p[i];
  }
  REP(i, Y){
    que.push(q[i]); Bsum += q[i];
  }
  int minus[200010] = {};
  for(int i = 1; i <= min(X+Y, C); i++){
    int num = que.top(); que.pop();
    minus[i] = minus[i-1] + num;
  }
  for(int i = 1; i < C; i++) r[i] += r[i-1];
  int ans = Asum+Bsum;
  for(int Z = 1; Z <= min(X+Y, C); Z++){
    cerr << minus[Z] << endl;
    chmax(ans, Asum+Bsum+r[Z-1]-minus[Z]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 5748
#include <iostream>
#include <string>
using namespace std;

int main(){
	int n , score , runner , outcount;
	cin >> n;
	for(int i=0 ; i<n ; i++){
		score=runner=outcount=0;
		string event;
		while(outcount<3){
			cin >> event;
			if (event=="HIT"){
				if(runner==3){
					score++;
				} else {
					runner++;
				}
			} else if (event=="HOMERUN"){
				score+=runner+1;
				runner=0;
			} else {
				outcount++;
			}
		}
		cout << score << endl;
	}
	return 0;
}

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

#define mp make_pair
#define pb push_back
#define f first
#define s second 
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define int long long
#define forn(i, x, y) for(int i = x; i <= y; i++)
#define forev(i, y, x) for(int i = y; i >= x; i--)

using namespace std;

const int maxn = (int)3e6 + 100;
const int mod = (int)1e9 + 7;
const int P = (int)1e6 + 7;
const int inf = (int)1e9 + 7;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef long double ld;

using namespace std;

string add, s,t;
map<char,int>cnt;
vi g[30];
int n;
main () {
  cin>>s>>t;	
  int i=0;
  n=sz(s);
  for(auto x:s)cnt[x]++,g[x-'a'].pb(i++);
  for(auto x:t){
  	if(!cnt[x]){
  		cout<<-1;
  		return 0;
		}
	}
	int pos=0,res=0,ok=0;
	for(auto x:t){
		pos=res%n;
		auto it=upper_bound(all(g[x-'a']),pos);
		if(!ok)
			it=lower_bound(all(g[x-'a']),pos),ok=1;
		if(it==g[x-'a'].end()){
			int len=n-pos+*g[x-'a'].begin();
			res+=len;
		}else{
			int len=*it-pos;
			res+=len;
		}
	}
	cout<<res+1;
}

Measured memory_bytes: 1724
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <numeric>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for(int i = (int)n - 1; j <= i; --i)



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

    int n; cin >> n;
    int* a = new int[n];
    rep(i, 0, n) cin >> a[i];

    ll ans = 0;
    rep(i, 0, n - 1) {
        if (a[i] & 1 && a[i + 1] > 0) {
            ++ans;
            --a[i];
            --a[i + 1];
        }
    }
    rep(i, 0, n) ans += a[i] / 2;
    cout << ans << endl;
    delete[] a;
    return 0;
}

Measured memory_bytes: 3688
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e18
typedef long long ll;
typedef pair<ll,ll> P;



int main(void){
    ll n;
    cin>>n;
    vector<ll>a(n),b(n),c(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    for(int i=0;i<n;i++)cin>>c[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll ans = 0;
    for(int i=0;i<n;i++){
        ll med = b[i];
        ll index1 = lower_bound(a.begin(),a.end(),b[i])-a.begin();
        ll index2 = upper_bound(c.begin(),c.end(),b[i])-c.begin();
        //cout<<index1<<" "<<index2<<endl;
        ans+=index1*(n-index2);
    }
    cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 2688
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()

void solve (int a)
{
    int b, c;
    cin >> b >> c;

    int cnt = 0;
    while (true)
    {
        if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1)
            break;
        if (min({a, b, c}) == max({a, b, c}))
        {
            cout << -1 << endl;
            return;
        }
        int na = (b + c) / 2;
        int nb = (a + c) / 2;
        int nc = (a + b) / 2;
        cnt++;
        a = na, b = nb, c = nc;
    }

    cout << cnt << endl;
}

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

    int n;
    while (cin >> n)
        solve(n);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll h,w,a;
	cin>>h>>w;
	a=0;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			char now;
			cin>>now;
			if(now=='#'){
				a++;
			}
		}
	}
	if(h+w-1==a){
		cout << "Possible";
	}
	else{
		cout << "Impossible";
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);


//変数
int N;
vector<int> a;






//サブ関数
//入力
void input()
{
	cin >> N;
	a.resize(N);
	REP(i, N)cin >> a[i];
}


//計算
void calc()
{
	int ans = 0;
	int cnt = 0;
	REP(i, N - 1) {
		if (a[i] == a[i + 1]) {
			cnt++;
		}
		else {
			ans += (cnt + 1) / 2;
			cnt = 0;
		}
	}
	ans += (cnt + 1) / 2;
	cout << ans << endl;
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	calc();
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 256
import * as fs from "fs";

const [line1, ...linesA] = fs.readFileSync("/dev/stdin", "utf8").split("\n");
let N = Number(line1)

let B: number[] = linesA.slice(0, N).map((n) => {return Number(n)-1});
let visited: boolean[] = Array(N).fill(false);

let position = 0;
let steps = 0;

while (position != 1 && visited[position] == false) {
	visited[position] = true;
	position = B[position];
	steps += 1;
}

if (position == 1)
	console.log(steps);
else
	console.log(-1);


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

    string s[200010],ans[200010];
int main() {
    int n;
    map<string,int> mp;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> s[i];
        mp[s[i]]++;
    }
    int max = 0,num=0;

    for(int i=0;i<n;i++){
        if(mp[s[i]] >= max){
            max = mp[s[i]];
        }
    }

    for(int i=0;i<n;i++){
        if(mp[s[i]] == max){
            mp[s[i]] = 0;
            ans[num] = s[i];
            num++;
        }
    }
    sort(ans,ans + num);

    for(int i=0;i<num;i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 28288
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(string, s);
  int ans = 0;
  string t, p;
  rep(i, sz(s)) {
    t += s[i];
    if (t == p) continue;
    p = t;
    t = "";
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define int long long
#define pb push_back
#define endl "\n";
#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
#define vii vector<int>
#define pii pair<int, int>
#define prec(n) fixed << setprecision(n)
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define MOD LLONG_MAX
#define INF 1e18 + 5
inline void get(vector<int> &arr, int n)
{
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        arr.push_back(a);
    }
}
inline void print(vector<int> &arr, int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}
/*----------------------------------TEMPLATE------------------------------------*/
int track[3005][3005];
void solve(string a, string b, vector<vector<int>> &dp)
{
    int n = a.size(), m = b.size();
    rep(i, 0, n)
    {
        rep(j, 0, m)
        {
            if (a[i] == b[j])
            {
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
                track[i + 1][j + 1] = 3;
                continue;
            }
            dp[i + 1][j + 1] = dp[i][j + 1];
            track[i + 1][j + 1] = 1;
            if (dp[i + 1][j] > dp[i + 1][j + 1])
            {
                dp[i + 1][j + 1] = dp[i + 1][j];
                track[i + 1][j + 1] = 2;
            }
        }
    }
    return;
}
int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    fast;
    int t;
    t = 1;
    while (t--)
    {
        string a, b;
        cin >> a >> b;
        int n = a.size(), m = b.size();
        vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
        solve(a, b, dp);
        //building the string
        int i = n, j = m;
        string ans = "";
        while (i > 0 && j > 0)
        {
            if (track[i][j] == 3)
            {
                ans.pb(a[i - 1]);
                i--;
                j--;
            }
            else if (track[i][j] == 1)
            {
                i--;
            }
            else if (track[i][j] == 2)
            {
                j--;
            }
        }
        reverse(all(ans));
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 144088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using static Input;
using static Util;
class Program
{
    static int N,W;
    static int[] w,v;
    static void INPUT()
    {
        N = NextInt();
        W = NextInt();
        w = new int[N];
        v = new int[N];
        for (int i = 0; i < N; i++)
        {
            w[i] = NextInt();
            v[i] = NextInt();
        }
    }

    static void OUT()
    {
        var len = v.Sum() + 1;
        var dp = new int[N + 1, len];
        for (int i = 1; i < dp.Length; i++)
        {
            dp[i / len, i % len] = INF;
        }
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < len; j++)
            {
                dp[i + 1, j] = Math.Min(dp[i + 1, j], dp[i, j]);
                if (j + v[i] >= len) continue;
                dp[i + 1, j + v[i]] = Math.Min(dp[i + 1, j + v[i]], dp[i, j] + w[i]);
            }
        }

        for (int i = len - 1; i >= 0; i--)
        {
            if (dp[N, i] > 0 && dp[N, i] <= W)
            {
                Console.WriteLine(i);
                return;
            }
        }

        Console.WriteLine(0);
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




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

int main() {
    int N;
    cin >> N;
    if(N==1){
        cout <<"Hello World" << endl;
        return 0;
    }
    ll A,B;
    cin >> A >>B;
    cout << A +B <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
int n, m, dsu[N], sz[N];

int root(int x) {
	while (x != dsu[x]) {
		dsu[x] = dsu[dsu[x]];
		x = dsu[x];
	}
	return x;
}

void join(int a, int b) {
	a = root(a);
	b = root(b);

	if (a == b) return;

	dsu[a] = b;
	sz[b] += sz[a];
}


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

	cin >> n >> m;

	for (int i = 1; i <= n; i++) {
		dsu[i] = i;
		sz[i] = 1;
	}

	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		join(a, b);
	}

	cout << *max_element(sz, sz + n + 1) << '\n';

	return 0;
}


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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  string s;
  cin >> s;

  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '-') ans--;
    else ans++;
  }

  // 解答
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

object MainKt {
  @JvmStatic fun main(args:Array<String>) {
    val A=readLine()!!
    val B=readLine()!!
    
  println(when(A.length==B.length)
    {
      true -> if(A==B) {"EQUAL"} else{
        if((0..(A.length-1)).map{A[it]-B[it]}.filter{it!=0}.toList().get(0)>0) {"GREATER"} else {"LESS"}
      }
      else ->   if(A.length>B.length) {"GREATER"}  else {"LESS"}
    })
  }
}

Measured memory_bytes: 23976
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i, beg, end) for (int i = (beg); i < (end); i++)
#define rrep(i, beg, end) for (int i = (beg); i >= (end); i--)
#define sp(i) setprecision(i) << fixed
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
typedef unsigned long long ull;
const ll INF = 1e18+10;
const int mod = 1e9 + 7;
const int N = 30;
ull p_hash(ull x, ull y) { return (x + y) * (x + y + 1) / 2 + y; } //NxN->N
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll fast_power(int a, int b, int p)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
            res = (ll)res * a % p;

        b >>= 1;
        a = (ll)a * a % p;
    }

    return res;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll a[2], b[2];
    cin >> a[0] >> a[1] >> b[0] >> b[1];

    ll ans = -INF;
    rep(i, 0, 2)
        rep(j, 0, 2)
            ans = max(ans, a[i] * b[j]);

    if ((a[0] <= 0 && a[1] >= 0) || (b[0] <= 0 && b[1] >= 0))
        ans = max(ans, (ll)0);

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int A, B;
int D[10][10];
int f[101][101];
int main(){
    cin >> A >> B;

    for (int i = 0; i < A; ++i) {
        for (int j = 0; j < B; ++j) {
            cin >> D[i][j];
        }
    }

    for (int a = 0; a <= 100; ++a) {
        for (int b = 0; b <= 100; ++b) {
            int fmax = 0;
            for (int x = 1; x <= A; ++x) {
                for (int y = 1; y <= B; ++y) {
                    int tmp = max(0, D[x - 1][y - 1] - a * x - b * y);
                    if (tmp > fmax) fmax = tmp;
                }
            }
            f[a][b] = fmax;
            //cout << fmax << " ";
        }
        //cout << endl;
    }

    bool possible = true;

    for (int x = 1; x <= A; ++x) {
        for (int y = 1; y <= B; ++y) {
            int dmin = 1000;
            for (int a = 0; a <= 100; ++a) {
                for (int b = 0; b <= 100; ++b) {
                    int dist = a * x + b * y + f[a][b];
                    if (dmin > dist) dmin = dist;
                }
            }
            if (dmin != D[x - 1][y - 1]) {
                possible = false;
                break;
            }
        }
        if (!possible) break;
    }

    if (possible) {
        cout << "Possible" << endl;
        cout << 202 << " " << 101 * 101 + 200 << endl;
        for (int i = 1; i <= 100; ++i) {
            cout << i << " " << i + 1 << " X" << endl;
            cout << i + 101 << " " << i + 102 << " Y" << endl;
        }

        for (int a = 0; a <= 100; ++a) {
            for (int b = 0; b <= 100; ++b) {
                cout << a + 1 << " " << 202 - b << " " << f[a][b] << endl;
            }
        }
        cout << "1 202" << endl;
    } else {
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 384
from collections import deque
def bfs(graph, N, start):
    visited = [0] * N
    visited[start] = 1
    que = deque([start])
    while que:
        node = que.popleft()
        for n in graph[node]:
            if not visited[n]:
                visited[n] = node + 1
                que.append(n)
    return visited
 
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(lambda n: int(n) - 1, input().split())
    graph[a].append(b)
    graph[b].append(a)
visited = bfs(graph, N, 0)[1:]
if all(visited):
    print("Yes")
    print(*visited, sep="\n")
else:
    print("No")

Measured memory_bytes: 38396
def solve():
    N = int(input())
    score = 0
    for i in range(1, N+1):
        score += i
        if score >= N:
            break
    x = score - N
    res = list(range(1, x)) + list(range(x+1, i+1))
    return '\n'.join(map(str, res))
    
print(solve())

Measured memory_bytes: 3444
#include <stdio.h>
#include <stdlib.h>
#define L_MAX 6
#define I_MAX 20

int anagram(int n, int l, int (*comp)(const void*, const void*))
{
    char arr[L_MAX];
    int i;

    for(i = l - 1; i >= 0; i--, n /= 10)
        arr[i] = n % 10;

    qsort(arr, l, 1, comp);

    for(n = i = 0; i < l; i++)
        n = n * 10 + arr[i];

    return n;
}

int smallest(const void* a, const void* b) { return *(char*)a - *(char*)b; }
int largest(const void* a, const void* b) { return *(char*)b - *(char*)a; }

int main(void)
{
    int history[I_MAX], n, l, i, j;

  next:

    while(scanf("%d %d", &n, &l), n + l)
    {
        i = 0;

        while(1)
        {
            history[i] = n;

            n = anagram(n, l, largest) - anagram(n, l, smallest);
            i++;

            for(j = 0; j < i; j++)
                if(history[j] == n)
                {
                    printf("%d %d %d\n", j, n, i - j);
                    goto next;
                }
        }
    }

    return 0;
}

Measured memory_bytes: 608
#include <bitset>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <vector>
#include <set>

using namespace std;

int main() {
  int64_t N;
  cin >> N;

  vector<int64_t> divs(N, 1);
  for (int64_t n = 2; n < N; ++n) {
    for (int64_t m = n; m < N; m+=n) {
      ++divs[m];
    }
  }
  int64_t sum = 0;
  for (int64_t n : divs) sum +=n;
  cout << sum - 1 << endl;
  
  return 0;
}


Measured memory_bytes: 11148
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s = sc.next();
		char[] chrs = s.toCharArray();
		int count=0;
		for(int i=2; i<N; i++)
		{
			if(chrs[i]=='C' && chrs[i-1]=='B'&& chrs[i-2]=='A' )
			{
				count++;
			}
		}
		System.out.println(count);
	}
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int x, y, z; cin >> x >> y >> z;
    int tmp = x;
    x = y;
    y = tmp;
    tmp = x;
    x = z;
    z = tmp;
    cout << x << " " << y << " " << z << endl;
}


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

using namespace std;

#define ll long long




void solve() {

	int a, b;
	cin >> a >> b;
	cout << max(a + b, max(a -b, a * b));

	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();

	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int n,m; cin >> n >> m;
  priority_queue<long long int> a;

  for(int i = 0; i < n; i++){
    long long int temp; cin >> temp;
    a.push(temp);
  }

  for(int i = 0; i < m; i++){
    long long int temp = a.top();
    a.pop(); a.push(temp/2);
  }
  
  long long int ans = 0;

  for(int i = 0; i < n; i++){
    ans += a.top(); a.pop();
  }

  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1400
n, k = map(int, input().split())
x = list(map(int, input().split()))
min_time  = abs(x[0]) + abs(x[-1] - x[0])

for i in range(n-k+1):
    time = min(abs(x[i]) + abs(x[i+k-1] - x[i]), \
        abs(x[i+k-1]) + abs(x[i+k-1] - x[i]))

    if time < min_time:
        min_time = time

print(min_time)

Measured memory_bytes: 14224
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;


int main(){
    char x;
    cin >> x;
    if('a' <= x && 'z' >= x) cout << "a" << endl;
    if('A' <= x && 'Z' >= x) cout << "A" << endl;
}

Measured memory_bytes: 3644
from sys import stdin

def main():
    a = stdin.readline().rstrip()
    counter = 0
    if a[0] == "1":
        counter += 1
    if a[1] == "1":
        counter += 1
    if a[2] == "1":
        counter += 1
    print(counter)

if __name__ == "__main__":
    main()

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

int main()
{
	long long l, r;
	cin>>l >>r;
	int a=l%2019, b=r%2019;
	if(a==0 || b==0)
	{
		cout<<"0";
		return 0;
	}
	if(r/2019>l/2019)
	{
		cout<<"0";
		return 0;
	}
	long long ans=2020;
	for(long long i=l;i<=r;i++)
	{
		for(long long j=i+1;j<=r;j++) ans=min((i%2019*j%2019)%2019,ans);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
from functools import reduce, lru_cache

INF = float("inf")

N, a, b, *A = map(int, open(0).read().split())
c = reduce(lambda a, b: a ^ b, A, 0)

@lru_cache(None)
def solve(a, b, c):
    if (a % 2) ^ (b % 2) != (c % 2):
        return INF
    if c == 0:
        return INF if a < b else (a - b) // 2

    return min(
        2 * solve(a // 2, b // 2, c // 2),
        1 + 2 * solve((a - 1) // 2, (b + 1) // 2, c // 2)
    )

print(-1 if (res := solve(a, b, c)) >= a else res)

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

using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin >> n;
    ll arr[n];
    for(int i = 0 ; i < n ; i++)
    {
        cin >> arr[i];
    }
    reverse(arr,arr+n);
    for(int i = 1 ; i < n ;i++)
    {
        if(arr[i]>arr[i-1])
        {
            arr[i]--;
        }
        else
        {
            continue;
        }
        if(arr[i]!=arr[i-1])
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 1024