akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.HashSet;
import java.util.Set;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
        if(x<1200){
            System.out.println("ABC");
        }else{
            System.out.println("ARC");
        }


        }
       
        
    }


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <numeric>
#include <functional>
using namespace std;

int main(void) {

	int N;
	cin >> N;

	vector<int> A(N);
	vector<int> B(N);
	vector<int> 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());

	long long result = 0;

	for (int i = 0; i < N; i++) {
		long long bound_A = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
		long long bound_C = C.end() - upper_bound(C.begin(), C.end(), B[i]);
		result += bound_A * bound_C;
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 1536
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	N, _ := strconv.Atoi(scanner.Text())

	result := 0

	for i := 1; i <= N; i += 2 {
		kazu := 0
		for j := 1; j <= i; j++ {
			if i % j == 0 {
				kazu++
			}
		}
		if kazu == 8 {
			result++
		}
	}
	fmt.Println(result)
}

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main(){
    string s, t; cin >> s >> t;
    int S = s.size(), T = t.size();
    int ans = 0;

    rep(i, S-T+1){
        int cnt = 0;
        rep(j, T){
            if (s[i+j] == t[j]) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << T - ans << endl;
    return 0;
}

Measured memory_bytes: 3624
a, b, k = map(int, raw_input().split())
L1 = [a + i for i in range(k)]
L2 = [b - k + 1 + i for i in range(k)]
in_range = lambda x: a <= x <= b
print "\n".join(map(str, filter(in_range, sorted(set(L1 + L2)))))

Measured memory_bytes: 2692
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
    char B;
    int A, C, D;
    cin >> A >> B >> C;
    if (B == '+')
        D = A + C;
    if (B == '-')
        D = A - C;
    cout << D << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,begin,end) for(int i=(begin),i##_end = (end);i<i##_end;i++)
long long MOD = 1000000007;
int main()
{
    int n,k,a,b,isFirstChild = 1;
    cin>>n>>k;
    long long ans = k;
    vector<vector<int> > ag(n+1,vector<int>());
    vector<int> visited(n+1);
    queue<int> tq;
    while(--n){
        cin>>a>>b;
        ag[a].emplace_back(b);
        ag[b].emplace_back(a);
    }
    tq.emplace(1);
    visited[1] = 1;
    while(!tq.empty()){
        int v = tq.front();
        tq.pop();
        isFirstChild = 1;
        int color = k;
        for(auto a : ag[v]){
            if(visited[a])
                continue;
            if(v == 1){
                if(isFirstChild){
                    ans = ans * (--color) % MOD;
                    isFirstChild = 0;
                }
                else ans = ans * (--color) % MOD;
            }
            else{
                if(isFirstChild){
                    ans = ans * (--color - 1) % MOD;
                    isFirstChild = 0;
                }
                else ans = ans * (--color - 1) % MOD;
            }
            tq.emplace(a);
            visited[a] = 1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6904
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 10;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	if (*ci == '-') ci++;
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (72 - dig >> 3);
	return tmp;
}


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


	ll N = getint(), D = getint();
	D = D * D;

	int kotae = 0;
	rep(i, N) {
		ll X = getint(), Y = getint();
		kotae += (D >= X * X + Y * Y);
	}
	printf("%lld\n", kotae);


	Would you please return 0;
}

Measured memory_bytes: 1696
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pi;
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair

int n,m,p[1000];

main(){
	while(cin>>n>>m,n){
		rep(i,n)cin>>p[i];
		sort(p,p+n,greater<int>());
		int ans=0;
		
		rep(i,n)if((i+1)%m)ans+=p[i];
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 0
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    ll a[n+10];
    REP(i,n) cin >> a[i+1];
    a[0]=0;
    rep(i,n){
        a[i+1]+=a[i];
    }
    ll ans=INF;
    for(int i=2;i<n-1;i++){
        int *p1,*p2,s;
        p1=lower_bound(a+1,a+i+1,a[i]/2+1);
        p2=lower_bound(a+i+1,a+n+1,(a[n]+a[i])/2+1);
        for(int j=0;j<2;j++){
            for(int k=0;k<2;k++){
                s=max({*p1,a[i]-*p1,*p2-a[i],a[n]-*p2})-min({*p1,a[i]-*p1,*p2-a[i],a[n]-*p2});
                ans=min(ans,s);
                p1--;
            }
            p1+=2;
            p2--;
        }
    }

    cout<<ans<<endl;


    
}

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

int main()
{
    int i,n,c=0;
    cin >> n;
    char s[n];
    cin >> s;
    for(i=0; i<n; i++)
    {
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
            c++;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

vector<int> pl;
vector<int> mn;

string bin(int x){
  string s = "";
  while(x){
    if(x%2==1){
      s.push_back('1');
    }
    x/=2;
  }
  reverse(ALL(s));
  return s;
}

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

  int cnt = 0;
  REP(i,N){
    if(S.at(i)=='1'){
      cnt++;
    }
  }

  
  int cnt2 = 1;
  REP(i,N){
    pl.push_back(cnt2%(cnt+1));
    cnt2=(cnt2%(cnt+1))*2;
  }
  int cnt3 = 1;
  REP(i,N){
    if(cnt>1){
      mn.push_back(cnt3%(cnt-1));
      cnt3=(cnt3%(cnt-1))*2;
    }
  }
  reverse(ALL(pl));
  reverse(ALL(mn));

  int plans=0;
  int mnans=0;
  REP(i,N){
    if(S.at(i)=='1'){
      plans+=pl.at(i);
      plans%=(cnt+1);
      if(cnt>1){
        mnans+=mn.at(i);
        mnans%=(cnt-1);
      }
    }
  }

  REP(i,N){
    int x = 0;
    int ans = 0;
    if(S.at(i)=='1'&&cnt>1){
      x = (mnans+(cnt-1)-mn.at(i))%(cnt-1);
      ans++;
    }else if(cnt==1&&S.at(i)=='1'){
      x=0;
    }else{
      x = (plans+pl.at(i))%(cnt+1);
      ans++;
    }
    while(x){
      string st = bin(x);
      int cnt4 = 0;
      REP(j,st.size()){
        if(st.at(j)=='1'){
          cnt4++;
        }
      }
      x%=cnt4;
      ans++;
    }
    cout << ans << endl;
  }


}

Measured memory_bytes: 5844
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())
l = prime_factorize(n)
set = list(set(l))
result = 0

for i in range(len(set)):
    tmp = l.count(set[i])
    for j in range(l.count(l[i])):
        if j+1 <= tmp:
            result += 1
            tmp -= j+1
        else:
            break

print(result)





Measured memory_bytes: 9220
l = list(map(int, input().split()))
n, a, b = l[0], l[1], l[2]
total, ans = 0, 0

for i in range(n+1):
    s = list(str(i))
    for j in s:
        total += int(j)
    if a<=total  and b>=total:
        ans += i
    total = 0
print(ans)


Measured memory_bytes: 3060
import collection.mutable.ArrayBuffer
import scala.reflect.ClassTag
import scala.language.implicitConversions

trait Graph { 
    case class Edge[T:Numeric](from : Int, to : Int, cost : T)

    class Edges[T:Numeric](val data : ArrayBuffer[Edge[T]]) {
        def size = data.size
    }
    object Edges {
        def apply[T:Numeric](xs : Edge[T]*) = new Edges(ArrayBuffer(xs:_*))
        implicit def toUnderLying[T](x:Edges[T]) = x.data
    }

    class WeightedGraph[T:Numeric](val size : Int, val data : Array[Edges[T]]) {
        def this(size : Int) = this(size, Array.fill(size)(Edges()))
    }
    object WeightedGraph {
        // def apply[T:Numeric](size : Int) = new WeightedGraph[T](size)
        implicit def toUnderLying[T](x:WeightedGraph[T]) = x.data
    }

    class UnWeightedGraph[T:Numeric](val size : Int, val data: Array[ArrayBuffer[T]]) {
        def this(size : Int) = this(size, Array.fill(size)(ArrayBuffer[T]()))
    }
    object UnWeightedGraph {
        // def apply[T:Numeric](size : Int) = new UnWeightedGraph[T](size)
        implicit def toUnderLying[T](x:UnWeightedGraph[T]) = x.data
    }
   
    class Matrix[T:Numeric:ClassTag](val row : Int, val col : Int, val data : Array[Array[T]]) {
        def this(row : Int, col : Int) = this(row, col, Array.fill(row, col)(implicitly[Numeric[T]].zero))
        def this(size : Int) = this(size, size)
    }
    object Matrix {
        implicit def toUnderLying[T](x:Matrix[T]) = x.data
    }
}

object BellmanFord extends Graph {
    import Edges._

    // return ArrayBuffer() when find a negative cycle
    def bellmanFord[T:ClassTag](edges : Edges[T], V : Int, s : Int, INF : T)(implicit num : Numeric[T]) : Array[T] = {
        val dist = Array.fill[T](V)(INF)
        dist(s) = num.zero
        for (i <- 1 to V) {
            for (e <- edges) {
                if(dist(e.from) != INF 
                    && num.lt(num.plus(dist(e.from), e.cost), dist(e.to))) {
                        dist(e.to) = num.plus(dist(e.from), e.cost)
                        if (i == V && e.to == V-1) return Array.empty
                    }
            }
        }
        dist
    }
}

import BellmanFord._

object Main {
    def main(args: Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val N, M = sc.nextInt
        val edges = Edges[Long]()
        for (_ <- 1 to M) {
            val s, t = sc.nextInt
            val c : Long = sc.nextLong
            edges += Edge[Long](s-1, t-1, -c)
        }
        // println(edges.toList)
        val res = bellmanFord(edges, N, 0, Long.MaxValue)
        // println(res.toList)
        if (res.isEmpty) println("inf")
        else {
            println(-res(N-1))
        }
    }
}

Measured memory_bytes: 72156
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=1e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

ll h,w;
char ch[1001][1001];
ll dp[1001][1001];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> h >> w;
	rep(i,1,h+1){
		rep(j,1,w+1){
			cin >> ch[i][j];
		}
	}
	dp[1][1]=1;
	for(ll i=1; i<=h; i++){
		for(ll j=1; j<=w; j++){
			if(i+j==2 || ch[i][j]=='#') continue;
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
 		}
	}
	cout << dp[h][w];
	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  while (true) {
    int n; cin >> n;
    if (n == 0) break;
    VI a(26);
    bool f = true;
    for (int i = 0; i < n; i++) {
      char c; cin >> c;
      a[c - 'A']++;
      VI s = a;
      sort(s.rbegin(), s.rend());
      if (f && s[0] - s[1] > n - i - 1) {
        cout << (char) ('A' + max_element(a.begin(), a.end()) - a.begin()) << ' ';
        cout << i + 1 << '\n';
        f = false;
      }
    }
    if (f) cout << "TIE" << '\n';
  }
  return 0;
}


Measured memory_bytes: 3216
#include <stdio.h>
int main(){
int n,k,x,y;
  int a=0,b=0;
  scanf("%d",&n);
    scanf("%d",&k);
    scanf("%d",&x);
    scanf("%d",&y);
  if(n >k){
    a=k;
    b=n-a;
  }else{
  a=n;}
  printf("%d\n",a*x+b*y);
  return(0);
}


Measured memory_bytes: 128
// AtCoder template
// 見た奴全員saba!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)



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

    ll n; cin >> n;
    ll ans = n;
    for(ll i = 1LL; i*i <= n; ++i){
        if(n%i == 0){
            ans = min(ans, i-1+n/i-1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	int num[3]={0},i;
	cin >> s;
	for(i=0;i<s.size();i++)
		num[s[i]-'a']++;
	i=min(num[0],min(num[1],num[2]));
	if(num[0]-i>1 || num[1]-i>1 || num[2]-i>1) puts("NO");
	else puts("YES");
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main()
{
	int a,b,c,ans,result;
	cin>>a>>b>>c;
	if(a>b)
	{
		ans=a;
		a=b;
		b=ans;
	}
	if(a>c)
	{
		ans=a;
		a=c;
		c=ans;
	}
	if(b>c)
	{
		ans=b;
		b=c;
		c=ans;
	}
	result=c-a;
	cout<<result;
	return 0;
}


Measured memory_bytes: 256
/*
 * 2684.cc: RLE Replacement
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

typedef pair<char,int> pci;
typedef vector<pci> vpci;

/* global variables */

/* subroutines */

void read_rle(vpci &v) {
  for (;;) {
    char ch;
    cin >> ch;
    if (ch == '$') break;

    int l;
    cin >> l;
    v.push_back(pci(ch, l));
  }
}

void print_rle(vpci &v) {
  for (int i = 0; i < v.size(); i++)
    printf("%c %d ", v[i].first, v[i].second);
  putchar('$'); putchar('\n');
}

/* main */

int main() {
  vpci va, vb, vc;
  read_rle(va);
  read_rle(vb);
  read_rle(vc);
  int van =  va.size(), vbn = vb.size(), vcn = vc.size();
  //printf("%d %d %d\n", an, bn, cn);


  int k = 0;
  for (; k <= van - vbn; k++) {
    bool ok = true;
    if (va[k].first != vb[0].first ||
	va[k].second < vb[0].second ||
	va[k + vbn - 1].first != vb[vbn - 1].first ||
	va[k + vbn - 1].second < vb[vbn - 1].second) ok = false;
    else
      for (int i = 1; ok && i < vbn - 1; i++)
	if (va[k + i].first != vb[i].first ||
	    va[k + i].second != vb[i].second) ok = false;
    if (ok) break;
  }
  //printf("k=%d\n", k);

  if (k > van - vbn) {
    print_rle(va);
    return 0;
  }

  vpci vt;
  if (vbn == 1) {
    for (int i = 0; i < k; i++) vt.push_back(va[i]);
    for (int i = 0; i < vcn; i++) vt.push_back(vc[i]);
    int l0 = va[k].second - vb[0].second;
    if (l0 > 0) vt.push_back(pci(va[k].first, l0));
    for (int i = k + vbn; i < van; i++) vt.push_back(pci(va[i]));
  }
  else {
    for (int i = 0; i < k; i++) vt.push_back(va[i]);
    int l0 = va[k].second - vb[0].second;
    if (l0 > 0) vt.push_back(pci(va[k].first, l0));
    for (int i = 0; i < vcn; i++) vt.push_back(vc[i]);
    int l1 = va[k + vbn - 1].second - vb[vbn - 1].second;
    if (l1 > 0) vt.push_back(pci(va[k + vbn - 1].first, l1));
    for (int i = k + vbn; i < van; i++) vt.push_back(pci(va[i]));
  }
  //print_rle(vt);

  vpci vr;
  pci prv = vt[0];
  for (int i = 1; i < vt.size(); i++) {
    if (prv.first == vt[i].first) prv.second += vt[i].second;
    else {
      vr.push_back(prv);
      prv = vt[i];
    }
  }
  vr.push_back(prv);

  print_rle(vr);
  return 0;
}

Measured memory_bytes: 1248
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

// void solve(int M, int N, std::vector<int> A, std::vector<int> B)
void solve(int N, int M, std::vector<std::vector<int>> vv)
{
  long long score = 0;
  std::priority_queue<int> pq;
  for (int i = 1; i <= M; i++)
  {
    for(const auto& v: vv[i]){
      pq.push(v);
    }
    if(!pq.empty())
    {
      score += pq.top();pq.pop();
    }
  }
  std::cout << score << std::endl;


}

int main(void)
{
  int M;
  int N;
  std::cin >> N;
  std::cin >> M;
  // std::vector<std::pair<int, int>> vec(N);
  std::vector<std::vector<int>> vv(M+1);
  for(auto i0 = 0; i0 < N; ++i0)
  {
    int a, b;
    std::cin >> a;
    std::cin >> b;
    if(a>M) continue;
    vv[a].push_back(b);
    // vec[i0]=(std::make_pair(a, b));
  }
  solve(N, M ,vv);
  return 0;
}


Measured memory_bytes: 10880
H, W = map(int, input().split())
coin_from_upper_row = 0
hand = []
for i in range(H):
    Ai = list(map(int, input().split()))
    for j in range(W):
        if j == W-1:
            Ai[j] += coin_from_upper_row
            coin_from_upper_row = 0
        if not Ai[j] % 2:
            continue
        if j < W-1:
            hand.append("{} {} {} {}".format(i+1, j+1, i+1, j+2))
            Ai[j+1] += 1
        else:
            if i == H-1:
                break
            hand.append("{} {} {} {}".format(i+1, j+1, i+2, j+1))
            coin_from_upper_row = 1

N = len(hand)
print(N)
for h in hand:
    print(h)


Measured memory_bytes: 13988
n=int(input())
*h,=map(int,input().split())
p=h[-1]
for i in range(n-1)[::-1]:
    if p>=h[i]:
        p=h[i]
        continue
    else:
        if p>=h[i]-1:
            p=h[i]-1
            continue
        else:
            print('No')
            exit()
    
print('Yes')

Measured memory_bytes: 14224
#include<cstdio>
#include<algorithm>
const int N=100007;
int read(){int x;scanf("%d",&x);return x;}
int d[N],p[N],e[N],f[N],id[N],w[N*2];
int main()
{
    int n=read(),m=read();
    for(int i=1;i<=n;++i) d[p[i]=i]=read();
    std::sort(p+1,p+n+1,[](int i,int j){return d[i]<d[j];});
    for(int i=1,u,v;i<=m;++i)
	if(d[u=read()]==d[v=read()])
	{
	    if(!f[u]&&!f[v]) f[u]=1;
	    if(!f[u]) f[u]=-f[v];
	    if(!f[v]) f[v]=-f[u];
	    if(f[u]==-f[v]) w[i]=d[u];
	}
	else
	{
	    if(d[u]<d[v]) std::swap(u,v);
	    e[u]=v,id[u]=i;
	}
    for(int i=1,x;i<=n;++i)
	if(!f[x=p[i]])
	{
	    if(!e[x]) return puts("-1"),0;
	    f[x]=f[e[x]],w[id[x]]=d[x]-d[e[x]];
	}
    for(int i=1;i<=n;++i) putchar(f[i]>0? 'B':'W');
    for(int i=1;i<=m;++i) printf("\n%d",w[i]? w[i]:1000000000);
}


Measured memory_bytes: 5120
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define mp make_pair

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
    return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
    return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
    int sign = 1;
    T ret = 0;
    char c;

    do{
        c = getc();
    }while(c == ' ' || c == '\n');
    if(c == '-')sign = -1;
    else ret = c-'0';
    while(1){
        c = getc();
        if(c < '0' || c > '9')break;
        ret = 10*ret + c-'0';
    }
    return sign * ret;
}

inline void ini(int& x){
    x = getnum<int>();
}

inline void scani(int& x){
    scanf("%d",&x);
}

//end of macro

const int N = 1e5 + 5;

int n;
int x[N], y[N];
vii pts;
int prevy[N];

int p[N], sz[N];
set<int>sx[N], sy[N];
int cek(int x){
    if(p[p[x]] != p[x])p[x] = cek(p[x]);
    return p[x];
}
void combine(int a, int b){
    if(cek(a) == cek(b))return;
    int pa = cek(a);
    int pb = cek(b);
    int sa = sx[pa].size() + sy[pa].size();
    int sb = sx[pb].size() + sy[pb].size();
    // combine a <- b
    if(sa < sb)swap(pa, pb);
    for(int x : sx[pb]){
        sx[pa].insert(x);
    }
    for(int x : sy[pb]){
        sy[pa].insert(x);
    }
    sz[pa] += sz[pb];
    p[pb] = pa;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);

    cin>>n;
    REP(i,1,n){
        cin>>x[i]>>y[i];
        pts.pb(mp(x[i], i));
        p[i] = i;
        sz[i] = 1;
        sx[i].insert(x[i]);
        sy[i].insert(y[i]);
    }
    sort(pts.begin(), pts.end());

    FOR(i,pts.size()){
        int id = pts[i].S;

        if(prevy[y[id]] != 0){ // combine y
            combine(prevy[y[id]], id);
        }
        prevy[y[id]] = id;
        if(i > 0 && x[id] == pts[i-1].F){ // combine x
            combine(id, pts[i-1].S);
        }
    }

    ll ans = 0;
    REP(i,1,n){
        if(i == cek(i)){
            // printf("lead %d, sx %d, sy %d, size %d\n",i, sx[i].size(), sy[i].size(), sz[i]);
            ans += (ll)sx[i].size() * sy[i].size() - sz[i];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 47092
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  int num = 1;
  rep(i, n){
    int nx1 = num*2;
    int nx2 = num + k;
    num = min(nx1, nx2);
  }
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int k = in.nextInt();
		if(k%2==0) {
			System.out.println(k*k/4);
		}else {
			System.out.println((k-1)*(k+1)/4);
		}
		

	}

}


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

#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 500001
#define MAXL 20
#define INF 200001
#define mod 1000000007

int n, q, block;
int m[MAXN];
int v[MAXN];
int ans[MAXN];
vector<pii> queries;

bool cmp(pii x, pii y)
{
  if (x.fir / block != y.fir / block)
    return x.fir / block < y.fir / block;
  return x.sec.fir < y.sec.fir;
}
void sqrt_decomposition()
{
  block = (int)sqrt(n);
  sort(queries.begin(), queries.end(), cmp);
  int curr_left = 0, curr_right = 0, curr_sum = 0;
  for (int i = 0; i < queries.size(); i++)
  {
    int l = queries[i].fir, r = queries[i].sec.fir;
    while (curr_left < l)
    {
      m[v[curr_left]]--;
      if (m[v[curr_left]] == 0)
        curr_sum--;
      curr_left++;
    }
    while (curr_left > l)
    {
      m[v[curr_left - 1]]++;
      if (m[v[curr_left - 1]] == 1)
        curr_sum++;
      curr_left--;
    }
    while (curr_right <= r)
    {
      m[v[curr_right]]++;
      if (m[v[curr_right]] == 1)
        curr_sum++;
      curr_right++;
    }
    while (curr_right > r + 1)
    {
      m[v[curr_right - 1]]--;
      if (m[v[curr_right - 1]] == 0)
        curr_sum--;
      curr_right--;
    }
    ans[queries[i].sec.sec] = curr_sum;
  }
}
signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> q;
  for (int i = 0; i < n; i++)
    cin >> v[i];
  for (int i = 0; i < q; i++)
  {
    int l, r;
    cin >> l >> r;
    l--, r--;
    queries.pb(mp(l, mp(r, i)));
  }
  sqrt_decomposition();
  for (int i = 0; i < q; i++)
    cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 15604
###
### atcorder test program
###

### math class
class math:
    ### pi
    pi = 3.14159265358979323846264338

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

math = math()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#A, B, C = [x for x in input().split()]
#templist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

N = input()
L = [x for x in input().split()]

output.list(reversed(L))



Measured memory_bytes: 5604
#include<iostream>
#include<climits>
#define INF INT_MAX;
void merge(int*, int, int, int);
void mergeSort(int*, int, int);
int cnt=0;
int main(){
  int n;
  std::cin >> n;
  int A[n];
  for(int i=0; i<n; i++) std::cin >> A[i];
  mergeSort(A, 0, n);
  for(int i=0; i<n;i ++)
    std::cout << A[i] << (i != n-1 ? " " : "\n");
  std::cout << cnt << "\n";
  return 0;
}
void merge(int *A, int l, int m, int r){
  int n1=m-l, n2=r-m, i, j, L[n1+1], R[n2+1];
  for(i=0; i<n1; i++) L[i] = A[l+i];
  for(i=0; i<n2; i++) R[i] = A[m+i];
  L[n1] = R[n2] = INF;
  i = j = 0;
  for(int k=l;k<r;k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
      cnt++;
    }
    else{
      A[k] = R[j];
      j++;
      cnt++;
    }
  }
}
void mergeSort(int *A, int l, int r){
  int m;
  if(l+1 < r){
    m = (l + r) / 2;
    mergeSort(A, l, m);
    mergeSort(A, m, r);
    merge(A, l, m, r);
  }
}

Measured memory_bytes: 6976
N = int(input())

def dfs(s): # 文字列 s で始まる七五三数の個数
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1
    for c in '753':
        ret += dfs(s + c)
    return ret

print(dfs('0')) #

Measured memory_bytes: 3064
H, N = map(int, input().split())
ab_array = [list(map(int, input().split())) for _ in range(N)]

dp = [[100000000] * (H + 1) for _ in range(N + 1)]
dp[0][0] = 0

for i in range(1, N + 1):
    for j in range(H + 1):
        if ab_array[i - 1][0] <= j:
            dp[i][j] = min(dp[i - 1][j], dp[i]
                           [j - ab_array[i - 1][0]] + ab_array[i - 1][1])
        else:
            dp[i][j] = min(dp[i - 1][j], ab_array[i - 1][1])

print(dp[N][H])


Measured memory_bytes: 119388
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
class Pair implements Comparable<Pair>
{
	int n;
	int dis;
	public Pair(int x,int d)
	{
		this.n=x;
		this.dis=d;
	}
	public int compareTo(Pair p)
	{
		if(this.dis>p.dis)
			return 1;
		else if(this.dis<p.dis)
			return -1;
		return 0;
	}
}
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}                                              
		return ans;
	} 
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n=cin();
        String s=br.readLine();
        char[] ch=s.toCharArray();
        int r=0;
        int w=0;
        for(int i=0;i<n;i++)
        {
        	if(ch[i]=='R')
        		r++;
        	else
        		w++;
        }
        int ind1=-1;
        for(int i=0;i<n;i++)
        {
        	if(ch[i]=='W')
        	{
        		ind1=i;
        		break;
        	}
        }
        int ind2=-1;
        for(int i=n-1;i>=0;i--)
        {
        	if(ch[i]=='R')
        	{
        		ind2=i;
        		break;
        	}
        }
        if(ind1==-1)
        	System.out.println(0);
        else
        {
        	int ans=0;
        	while(ind1<ind2)
        	{
        		ans++;
        		ind1++;
        		while(ind1<n && ch[ind1]=='R')
        			ind1++;
        		ind2--;
        		while(ind2>=0 && ch[ind2]=='W')
        			ind2--;
        	}
        	System.out.println(Math.min(ans,w));
        }
    }
}


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

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

    long long sum = 0;
    for (int i = 0; i < N.length(); i++) {
        sum += N[i] - '0';
    }
    if (sum % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <math.h>
#include <string>
#include <iomanip>
#include <locale>
#include <list>
#include <bitset>
#include <tuple>
using namespace std;
#define FORN(i,m,n) for(int i=(m); i<int(n); i++)
#define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);}
typedef long long ll;
 
int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n; cin>>n;
  int ans = (n >> 1) + (n & 1);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

vector<PLL> point;
vector<PLL> area;

bool exist(LL x, LL y){
    int pos = lower_bound(point.begin(),point.end(),PLL(x,y)) - point.begin();
    if(pos < point.size() && point[pos] == PLL(x,y)) return true;
    else return false;
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL H,W,N; cin >> H >> W >> N;
    dump("inp")
    REP(i,N){
        LL a,b; cin >> a >> b;
        a--; b--;
        dump("ok")
        point.eb(PLL(a,b));
        for(LL j = a-2; j <= a; j++){
            for(LL k = b-2; k <= b; k++){
                if(0 <= j && j+2 < H && 0 <= k && k+2 < W){
                    area.pb(PLL(j,k));
                }
            }
        }
    }
    dump("input")
    VL cnt(10,0);
    sort(area.begin(),area.end());
    area.erase(unique(area.begin(),area.end()),area.end());
    sort(point.begin(),point.end());
    cnt[0] = (H-2)*(W-2)-area.size();
    for(LL i = 0; i < area.size(); i++){
        LL x = area[i].first;
        LL y = area[i].second;
        int num = 0;
        for(LL j = x; j <= x+2; j++){
            for(LL k = y; k <= y+2; k++){
                if(exist(j,k)) num++;
            }
        }
        cnt[num]++;
    }
    REP(i,10){
        cout << cnt[i] << endl;
    }


}

Measured memory_bytes: 20456
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    for (int i = 1; ; i++) {
    int x = sc.nextInt();
    if(x==0)break;
    System.out.println("Case " + i + ": "+ x);
    
}
}
}


Measured memory_bytes: 42980
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N = keyboard.nextInt();
		int[] A = new int[100010];
		long ans = 0;
		
		for(int n = 0; n<N; n++) {
			int a = keyboard.nextInt();
			A[a]++;
			ans += a;
		}
		
		int Q = keyboard.nextInt();
		
		for(int q = 0; q<Q; q++) {
			int b = keyboard.nextInt();
			int c = keyboard.nextInt();
			//掛け算してLongになるとき、先頭にLongの形式で1をかけておくと、型がlongになる
			ans += 1L*c*A[b];
			ans -= 1L*b*A[b];
			
			A[c] += A[b];
			A[b] = 0;
			
			System.out.println(ans);
		}
		
		keyboard.close();
	}
}


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

const int MOD = 998244353;

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    int N; cin >> N;
    int m = 0;
    vector<int> dis(N, 0);
    int t; cin >> t; dis[t]++;
    for (int i = 0; i < N-1; i++) {
        int d; cin >> d;
        dis[d]++;
        m = max(m, d);
    }
    if (dis[0] != 1 || t != 0) {
        cout << 0 << endl;
    } else {
        ll ans = 1;
        for (int i = 1; i <= m; i++) {
            ans = (ans * modpow(dis[i-1], dis[i])) % MOD;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 640
#include <cstdio>
#include <queue>
#include <cctype>
#include <vector>

using namespace std;

struct Position {
    int h, w, time, strength;
    Position (int h, int w, int t, int s): h(h), w(w), time(t), strength(s) {}
};

const int max_h = 1005;
const int max_w = 1005;
int g_h, g_w, g_strength, g_max_strength, si, sj;
char mat[max_h][max_w];
pair<int, int> factories[20];
int dh[] = {0, 1, 0, -1};
int dw[] = {1, 0, -1, 0};

int main() {
    scanf("%d%d%d", &g_h, &g_w, &g_max_strength);
    for (int i = 0; i < g_h; i++) {
        getchar();
        for (int j = 0; j < g_w; j++) {
            mat[i][j] = getchar();
            if (mat[i][j] == 'S') {
                si = i;
                sj = j;
                mat[i][j] = '.';
            } else if (isdigit(mat[i][j])) {
                factories[mat[i][j]-'0'].first = i;
                factories[mat[i][j]-'0'].second = j;
                mat[i][j] = '.';
            }
        }
    }
    queue<Position> q;
    g_strength = 1;
    q.push(Position(si, sj, 0, 1));
    int result = -1;
    while (!q.empty()) {
        Position p = q.front();
        q.pop();
        if (p.strength < g_strength) continue;
        pair<int, int> f = factories[p.strength];
        if (p.h == f.first && p.w == f.second) {
            if (p.strength == g_max_strength) {
                result = p.time;
                break;
            }
            p.strength++;
            g_strength++;
        }
        for (int i = 0; i < 4; i++) {
            int w = p.w + dw[i];
            int h = p.h + dh[i];
            if (w >= 0 && w < g_w && h >= 0 && h < g_h &&
                    (mat[h][w] == '.' || (isdigit(mat[h][w]) && p.strength+'0' > mat[h][w]))) {
                mat[h][w] = p.strength+'0';
                q.push(Position(h, w, p.time+1, p.strength));
            }
        }
    }
    printf("%d\n", result);
    return 0;
}

Measured memory_bytes: 2036
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;


const int NMAX=1000001;


signed main() {
    int n;
    cin >> n;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
 
    vll prime(NMAX), cnt(NMAX, 0);
    rep(i, NMAX){
        prime[i] = i;
    }
    ll p = 2;
    while(p*p <= NMAX){
        if(prime[p] != p){
            p++;
            continue;
        }
        for(int i = p; i < NMAX; i += p){
            prime[i] = p;
        }
        p++;
    }
    
 
    bool pairwise = true;
    bool setwise = true;
 
    rep(i, n){
        ll tmp = a[i];
        while(prime[tmp] != tmp){
            ll sis = prime[tmp];
            cnt[sis]++;
            while(tmp != 1 && tmp%sis == 0) tmp /= sis;
        }
        cnt[prime[tmp]]++;
    }
 
    for(int i = 2; i < NMAX; i++){
        if(cnt[i] == n){
            pairwise = false;
            setwise = false;
            break;
        } else if(cnt[i] > 1){
            pairwise = false;
        }
    }
 
    if(pairwise){
        mes("pairwise coprime");
    } else if(setwise){
        mes("setwise coprime");
    } else {
        mes("not coprime");
    }
 
  
    
    
}

Measured memory_bytes: 26736
#include<stdio.h>
int main(){
  int a = 0, b = 0, c = 0, tmp = 0;
  scanf("%d %d %d", &a, &b, &c);
  if (a > b) {
    tmp = a;
    a = b;
    b = tmp;
  } 
  if (b > c) {
    tmp = b;
    b = c;
    c = tmp;
    if (a > b) {
      tmp = a;
      a = b;
      b = tmp;
    }
  }
  printf("%d %d %d\n", a, b, c);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
int k=0,n=0, m=0, l=0,a=0, b=0, c=0, d=0,ans=0,ans2=0;
string s;
signed main() {
    cin >> n >> k;
    vector<int> A(n);
    REP(i,n){
      cin>>A[i];
        if(A[i]<abs(k-A[i])){
            ans += A[i]*2;
        }
        else{
            ans += abs(k - A[i])*2;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3616
import time
import random
t1 = time.time()

D = int(input())

last_list = [0 for i in range(27)]
c_list = list(map(int, input().split()))
c_list = [0] + c_list
max_c = 0
max = 0
for j in range(1,27):
    if max <= c_list[j]:
        max = c_list[j]
        max_c = j
# max_c =
# for i in range(1,27):

# print(c_list)
S_list = [[]for i in range(D)]
P_list = [0 for i in range(27)]
max_list = [0 for i in range(D)]
max_list = [""] + max_list
for i in range(D):
    max = 0
    S_list[i] = list(map(int, input().split()))
    S_list[i] = [""] + S_list[i]
    for j in range(1,27):
        if max <= S_list[i][j]:
            max = S_list[i][j]
            max_list[i+1] = j
S_list = [""] + S_list
# print(S_list)


t_list = max_list
# for i in range(D):
#     t_list.append(random.randint(1,26))

for i in range(1,D+1):
    S = 0
    t = t_list[i]
    for j in range(1,27):
        if j == t:
            P_list[j] += S_list[i][j]
            last_list[j] = i
            # print(S_list[i][j])
        else:
            P_list[j] -= c_list[j] * (i-last_list[j])
    for i in range(1,27):
        S += P_list[i]
    # print(S)

t2 = time.time()
Time = t2 - t1
# print(M)
while t2 - t1 <= 1.8:
    last_list = [0 for i in range(27)]
    P_list = [0 for i in range(27)]
    C_A = random.randint(1,D)
    C_B = max_c
    t_new = t_list
    t_new[C_A] = C_B
    for i in range(1,D+1):
        S_new = 0
        t = t_new[i]
        for j in range(1,27):
            if j == t:
                P_list[j] += S_list[i][j]
                last_list[j] = i
                # print(S_list[i][j])
            else:
                P_list[j] -= c_list[j] * (i-last_list[j])
        for i in range(1,27):
            S_new += P_list[i]
    if S_new >= S:
        S = S_new
        t_list = t_new
    t2 = time.time()

for i in range(1,D+1):
    print(t_list[i])


Measured memory_bytes: 85028
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 9e18;

signed main() {
    string S;
    cin >> S;
    int ans = S.length();
    for (int i = 0; i < S.length() - 1; i++) {
        if (S[i] != S[i + 1]) {
            ans = min(ans, max(i + 1, (int)S.length() - i - 1));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int count[1001][1001][3];
int m, n, o;
char maps[1000][1001];

int main() {
	char tmp[] = {'J', 'O', 'I'};
	cin >> m >> n >> o;
	REP(i, m) scanf("%s", maps[i]);

	REP(i, m) REP(j, n) {
		REP(k, 3) {
			count[i + 1][j + 1][k] = count[i + 1][j][k] + count[i][j + 1][k] - count[i][j][k];
			if (maps[i][j] == tmp[k]) count[i + 1][j + 1][k]++; 
		}
	}

	REP(i, o) {
		int a, b, c, d, ans[3]; 
		scanf("%d %d %d %d", &a, &b, &c, &d);
		REP(j, 3)
			ans[j] = count[c][d][j] - count[a-1][d][j] - count[c][b-1][j] + count[a-1][b-1][j];
		printf("%d %d %d\n", ans[0], ans[1], ans[2]);
	}
	return 0;
}

Measured memory_bytes: 13820
macro_rules! scan_sub {
    ( $itr:ident, $t:ty ) => {
        let mut buf = String::new();
        let $itr = {
            while buf.trim().len() == 0 {
                buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
            }
            buf.split_whitespace().map(|n| n.parse::<$t>().unwrap())
        };
    };
}

macro_rules! scan {
    ( $x:ident; Vec<$t:ty> ) => {
        scan_sub!(itr, $t);
        let $x = itr.collect::<Vec<_>>();
    };
    ( $( $x:ident ),*; $t:ty ) => {
        scan_sub!(itr, $t);
        let mut itr = itr;
        $(
            let $x = itr.next().unwrap();
        )*
    };
}

fn main() {
    scan!(x, y; u64);

    let mut ans = 0;
    let mut t = x;

    while t <= y {
        t *= 2;
        ans += 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352