akhauriyash/Code-Regression huggingface dataset:
class Card
  attr_reader :suit, :value
  def initialize(card_str)
    @suit = card_str[0]
    @value = card_str[1..-1].to_i
  end

  def to_s
    @suit + @value.to_s
  end

  def ==(other)
    if other.is_a?(Card)
      suit == other.suit && value == other.value
    else
      false
    end
  end
end

def bubble_sort!(arr)
  n = arr.length
  for i in 0..(n-1)
    for j in (n-1).downto(i+1)
      if arr[j].value < arr[j-1].value
        arr[j], arr[j-1] = arr[j-1], arr[j]
      end
    end
  end
  return arr
end

def selection_sort!(arr)
  n = arr.length
  for i in 0...n
    minj = i
    for j in i...n
      if arr[j].value < arr[minj].value
        minj = j
      end
    end
    if i != minj
      arr[i], arr[minj] = arr[minj], arr[i]
    end
  end
  return arr
end

def is_stable?(input, out)
  n = input.length
  for i in 0...n
    for j in (i+1)...n
      for a in 0...n
        for b in (a+1)...n
          if input[i].value == input[j].value && input[i] == out[b] && input[j] == out[a]
            return false
          end
        end
      end
    end
  end
  true
end

def print_is_stable(input, out)
  if is_stable?(input, out)
    puts 'Stable'
  else
    puts 'Not stable'
  end
end

n = gets().to_i
arr = gets().split.map{ |card_str| Card.new(card_str)} 

input_arr = arr.map(&:clone)
bubble_sort!(arr)
puts arr.join(' ')
print_is_stable(input_arr, arr)
arr = input_arr
input_arr = arr.map(&:clone)
selection_sort!(arr)
puts arr.join(' ')
print_is_stable(input_arr, arr)



Measured memory_bytes: 6888
#include <stdio.h>

int selection(int [],int );
int main(void){
    int n,A[100];
    int i,c;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    c=selection(A,n);
    for(i=0;i<n;i++){
        printf("%d",A[i]);
        if(i!=n-1) printf(" ");
        else printf("\n");
    }
    printf("%d\n",c);
    
    return 0;
}

int selection(int A[],int n){
    int i,j,min,a,count=0;
    for(i=0;i<n;i++){
        min=i;
        for(j=i;j<n;j++){
            if(A[j]<A[min]) min=j;
        }
        if(i!=min){
            a=A[i];
            A[i]=A[min];
            A[min]=a;
            count++;
        }
    }
    return count;
}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;
#define MAX_N 100000

int main(void) {
    int n;
    
    int a[MAX_N], b[MAX_N];

    scanf("%d", &n);
    vector<pair<int, int> > pairs(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d %d", &a[i], &b[i]);
        pairs[i] = make_pair(a[i]+b[i], b[i]);
    }

    long long fi=0, se=0;
    sort(pairs.begin(), pairs.end(), greater<pair<int, int> >());

    for(i=0; i<n; i++) {
        if (i%2==0) fi += pairs[i].first-pairs[i].second;
        else se += pairs[i].second;
    }

    printf("%lld\n", fi-se);
    return 0;
}


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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

void ALLOUT_WITH_SPACE(vector<ll> V)
{
    ll Vsize = V.size();
    for(int i=0;i<Vsize;i++)
    {
        cout << V[i];
        if(i!=Vsize-1)
        {
            cout << ' ';
        }
    }
    cout << endl;
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

ll Even(vector<ll> V)
{
    ll N = V.size();

    ll ans = 0;
    for(ll i=0;i<N;i++)
    {
        if(i<N/2-1) ans -= 2 * V[i];
        if(i==N/2-1) ans -= V[i];
        if(i==N/2) ans += V[i];
        if(i>N/2) ans += 2 * V[i];
    }
    return ans;
}

ll Odd(vector<ll> V)
{
    ll N = V.size();

    auto f = [N](vector<ll> V)
    {
        ll ans1 = 0;
        for(ll i=0;i<N;i++)
        {
            if(i<(N-1)/2-1) ans1 -= 2 * V[i];
            else if(i==(N-1)/2-1) ans1 -= V[i];
            else if(i==(N-1)/2) ans1 -= V[i];
            else ans1 += 2 * V[i];
        }

        ll ans2 = 0;
        for(ll i=0;i<N;i++)
        {
            if(i<(N-1)/2) ans2 -= 2 * V[i];
            else if(i==(N-1)/2) ans2 += V[i];
            else if(i==(N-1)/2+1) ans2 += V[i];
            else ans2 += 2 * V[i];
        }

        return max(ans1,ans2);
    };
    return f(V);
}

ll Ans(ll N, vector<ll> A)
{
    sort(ALL(A));

    if(N%2==0)
    {
        return Even(A);
    }
    else
    {
        return Odd(A);
    }
}

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

    vector<ll> A(N);
    ALLIN1_NUMBER(A);

    sort(ALL(A));

    OUT0(Ans(N,A));

    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

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

void solve() {

}

int main() {
  int x,ans;
  rep(i,5) {
    cin >> x;
    if( x == 0 ) {
      ans = i + 1;
    }
  }
  cout << ans << endl;
  return 0;
}


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

inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}

inline bool read(int& a){
    int s=0,w=1;
    char ch=getchar();
    if(ch==EOF){
		return false;
	}
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=s*w;
    return true;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

inline void writeln(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    puts("");
}

signed main(){
	int n=read();
	int a[n+1],b[n+1];
	
	for(int i=1;i<=n;i++){
		a[i]=read(),b[i]=read();
	}
	
	for(int i=1;i<=n-2;i++){
		if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2]){
			puts("Yes");
			return 0;
		}
	}
	
	puts("No");
	 return 0;
}

Measured memory_bytes: 3628
N,M=map(int,input().split())
a=[]
b=[]
for i in range(0,M):
	c,d=map(int,input().split())
	a.append(c)
	b.append(d)

pos=0
i=0
g=[0 for i in range(0,200000)]
e=[]
f=[]
k=0
l=0
while i < M and pos == 0:
	if a[i] == 1:
		g[b[i]] = 1
	if b[i] == 1:
		g[a[i]] = 1
	i=i+1
i=0
while i < M and pos == 0:
	if a[i] == N:
		if g[b[i]] == 1:
			pos=1
	if b[i] == N:
		if g[a[i]] == 1:
			pos=1
	i = i + 1
if pos == 1:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

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

int h,w;
char s[20][20];

void dfs(int y,int x){
	if((x<0)||(w<=x)||(y<0)||(h<=y)){
		return;
	}
	if((s[y][x]=='.')||(s[y][x]=='@')){
		s[y][x]='x';
	}else{
		return;
	}
	dfs(y,x+1);
	dfs(y,x-1);
	dfs(y+1,x);
	dfs(y-1,x);
}

int main(){
	while(cin >> w >> h,h){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin >> s[i][j];
			}
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(s[i][j]!='@');
				else{
					dfs(i,j);
					j=w;
					i=h;
				}
			}
		}
		int count=0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(s[i][j]=='x')
					count++;
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 3108
#include <stdio.h>
#include <stdbool.h>
#include <string.h>

int count = 0;
bool isConstruction[16][16];
int a,b;

void rec(int i, int j) {
    if (isConstruction[i][j]) {
        return ;
    }

    if (i == a && j == b) {
        count += 1;
        return;
    }

    if (i != a) {
        rec(i+1, j);
    }

    if (j != b) {
        rec(i, j+1);
    }
}

int main() {
    while (1) {
        int i;
        int n;

        scanf("%d %d", &a, &b);
        if (a == 0 && b == 0) return 0;

        a -= 1;
        b -= 1;

        for (i=0;i<16;i++) {
            int j;
            for (j=0;j<16;j++) {
                isConstruction[i][j] = 0;
            }
        }

        scanf("%d", &n);
        for (i=0;i<n;i++) {
            int i, j;
            scanf("%d %d", &i, &j);
            isConstruction[i-1][j-1] = 1;
        }

        count = 0;
        rec(0, 0);

        printf("%d\n", count);
    }
}

Measured memory_bytes: 1028
import java.util.*

fun main(args:Array<String>){
    solve()
}

fun solve(){
    val a = read()
    val b = read()
    val c = read()
    val card = arrayOf(a,b,c)
    var num = intArrayOf(0,0,0)
    val s = "ABC"
    var win = 0
    var turn = 0
    while(true){
        if(num[turn] == card[turn].length){
            win = turn
            break
        }
        var next = 0
        if(card[turn][num[turn]] == 'a'){
            next = 0
        }
        else if(card[turn][num[turn]] == 'b'){
            next = 1
        }
        else{
            next = 2
        }
        num[turn]++
        turn = next
    }
    println(s[win])
}

fun read() = readLine()!!
fun reads() = readLine()!!.split(" ")
fun readint() = readLine()!!.toInt()
fun readints() = readLine()!!.split(" ").map{it.toInt()}
fun readlong() = readLine()!!.toLong()
fun readlongs() = readLine()!!.split(" ").map{it.toLong()}

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

int main(){
  int s[13] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
  int h[13] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
  int c[13] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
  int d[13] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
  
  int x;
  cin >> x;
  string m;
  int n;
  for (int i = 0; i < x; i++){
    cin >> m >> n;
    if (m == "S"){
      s[n - 1] = 100;
    }else if(m == "H"){
      h[n - 1] = 100;
    }else if(m == "C"){
      c[n - 1] = 100;
    }else{
      d[n - 1] = 100;
    }
  }

  for (int i = 0; i < 13; i++){
    if (s[i] != 100){
      cout << "S " << s[i] << endl;
    }
  }

  for (int i = 0; i < 13; i++){
    if (h[i] != 100){
      cout << "H " << h[i] << endl;
    }
  }

  for (int i = 0; i < 13; i++){
    if (c[i] != 100){
      cout << "C " << c[i] << endl;
    }
  }

  for (int i = 0; i < 13; i++){
    if (d[i] != 100){
      cout << "D " << d[i] << endl;
    }
  }
}


Measured memory_bytes: 3092
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
	long h = Long.parseLong(stdIn.next());
	int n = stdIn.nextInt();
	int sum=0;
	int[] a=new int[n];
	String result="No";
	for(int j=0;j<n;j++){
	    a[j]=stdIn.nextInt();
	    sum+=a[j];
	    if(sum>=h){
		result = "Yes";
		break;
	    }
	}
	System.out.println(result);
    }
}
	


Measured memory_bytes: 49636
#include<iostream> 
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int k;string s;
	cin>>k;
	cin>>s;
	int n=s.length();
	if(n<=k) cout<<s<<endl;
	else{
		for(int i=0;i<k;i++)
		{
			printf("%c",s[i]);
		}
		printf("...\n");
	}
	return 0;
}

Measured memory_bytes: 3108
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    Z = list(tuple(map(int,input().split())) for _ in range(N))
    L = []

    L1 = sorted(z[0]+z[1] for z in Z)
    L.append(L1[-1]-L1[0])

    L1 = sorted(z[0]-z[1] for z in Z)
    L.append(L1[-1]-L1[0])

    L1 = sorted(-z[0]+z[1] for z in Z)
    L.append(L1[-1]-L1[0])

    L1 = sorted(-z[0]-z[1] for z in Z)
    L.append(L1[-1]-L1[0])
    return str(max(L))

if __name__ == '__main__':
    print(solve())



Measured memory_bytes: 52512
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main(){
  int a,b;
  cin >>b >>a;
  int right = a+b-1;
  int left = a-b+1;
  for(int i=left; i<=right;i++){
    cout<<i <<" ";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <algorithm>
using namespace std;

int main(void){
    long long n, a[100010], b[100010], ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    
    for (int i = n - 1; i >= 0; i--) {
        if (b[i] != 1 && (a[i] + ans) % b[i] != 0) ans += b[i] - ((a[i] + ans) % b[i]);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 1792
"use strict";
function Main(input) {
	input = input.split("\n");
  	var inputValue = input[0];
  	var mostDivideCount = 0;
  	var mostValue = 0
  for (let i=0; i<=inputValue; i++)
  {
    var divideCount = 0;
    var testValue=i;
    while(testValue>=2 && testValue%2==0){
      divideCount+=1;
      testValue/=2;
    }
    if(divideCount>=mostDivideCount){
      mostDivideCount = divideCount;
      mostValue = i;
    }
  }
	console.log('%d',mostValue);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7496
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <boost/multiprecision/cpp_int.hpp> 
using namespace boost::multiprecision; 
using namespace std;
using namespace __gnu_pbds;
#define ll cpp_int
#define ld long double
#define vin ll n; cin>>n; vector<ll>x(n); for(ll i=0; i<n; i++) cin>>x[i]
#define vout for(ll i=0; i<n; i++) cout<<x[i]<<" "
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,i,k; cin>>n>>k; ll a[n]; for( i=0; i<n; i++) cin>>a[i]
#define aout for(ll i=0; i<n; i++) cout<<a[i]<<" "
#define matin ll m,n; cin>>m>>n; ll a[m][n]; for(ll i=0;i<m;i++) for(ll j=0;j<n;j++) cin>>a[i][j];
#define matout for(ll i=0;i<m;i++){for(ll j=0;j<n;j++) cout<<a[i][j]<<" "; cout<<"\n";}
#define F first
#define S second
#define I insert
#define sin set<ll>s; ll n; cin>>n; ll tmp; for(ll i=0;i<n;i++){cin>>tmp; s.I(tmp);}
#define sout for(auto it=s.begin();it!=s.end();++it) cout<<*it<<" "
#define AISORT sort(a,a+n)
#define ADSORT sort(a,a+n,greater<ll>())
#define VISORT sort(x.begin(),x.end())
#define VDSORT sort(x.begin(),x.end(),greater<ll>())
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define N_ cout<<"\n"
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
 

ll highestPowerof2(long long n) 
{ 
   long long p = (long long)log2(n); 
   return (long long)powl(2, p);  
} 
// ll highestPowerof2(ll n) 
// { 
//     // Invalid input 
//     if (n < 1) 
//         return 0; 
  
//     ll res = 1; 
  
//     // Try all powers starting from 2^1 
//     for (ll i=0; i<8*sizeof(ll); i++) 
//     { 
//         ll curr = 1 << i; 
  
//         // If current power is more than n, break 
//         if (curr > n) 
//            break; 
  
//         res = curr; 
//     } 
  
//     return res; 
// } 

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long x;
    cin >> x;
    ll ans =  highestPowerof2(x);
    long cnt = 0;
    while(x)
    {
        x/=2;
        cnt++;
    }
   // cnt++;
   ll ANS = (ll)powl((long long)2,(cnt)) - 1;
    cout << ANS;
    
//     ll n,k,t1,t2;
//     cin >> n >> k;
//     ll i;
//     vector< pair<ll,ll> >vp;
//     for(i = 0;i < n; ++i)
//     {
//         cin >> t1 >> t2;
//         vp.pb(mp(t1,t2));
        
//     }
}

Measured memory_bytes: 384
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
arrA = list(map(int,input().split()))
arrA.sort()

breakpoint1 = len(arrA)//2 -1
breakpoint2 = breakpoint1+1

ans = arrA[breakpoint2] - arrA[breakpoint1]
print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



Measured memory_bytes: 14428
n=int((input()))
a=list(map(int,input().split()))
c=[]
p=0
t=0
for i in range(n):
    p+=a[i]
    c.append(p)
t+=c.count(0)
c.sort()
d=1
for i in range(1,n):
    if c[i-1]==c[i]:
        d+=1
    else:
        if d>1:
            t+=d*(d-1)//2
            d=1
        else:
            d=1
if d>1:
    t+=d*(d-1)//2
print(t)

Measured memory_bytes: 25976
x=0.0
y=0.0
deg=90

while true
	input=gets.chomp.split(",")
	a=input[0].to_i
	d=input[1].to_i
	if(a==0&&d==0) 
		break
	end
	rad=(deg*Math::PI/180.0)
	x+=a*Math.cos(rad)
	y+=a*Math.sin(rad)
	deg-=d
end
puts x.to_i
puts y.to_i


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

int main() {
	int n;cin>>n;
	int tot = 0;
	int tot_sq = 0;
	for(int i =0;i<n;++i){
		int tmp; cin >> tmp;
		tot += tmp;
		tot_sq += tmp*tmp; 
	}
	cout << (tot*tot - tot_sq)/2 << endl;
	return 0;
}

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

using namespace std;

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

  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  for (int i = 0; i < m; i++) {
    cin >> x[i];
  }
  sort(x.begin(), x.end());
  vector<int> d(m-1);
  for (int i = 0; i < m - 1; i++) {
    d[i] = x[i+1] - x[i];
  }
  sort(d.rbegin(), d.rend());
  int ans = x[m-1] - x[0];
  for (int i = 0; i < min(n - 1, m - 1); i++) {
    ans -= d[i];
  }
  cout << ans << '\n';

  return 0;
}


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

using namespace std;
const int MAX=1e5;
int n,arr[MAX+2],k;
long long dp[MAX+3];

long long solve(int ind){
if(ind>=n) return 1e17;
if(ind==n-1) return 0;
if(dp[ind]!=-1) return dp[ind];
long long ans=1e17;
for(int i=ind+1;i<=ind+k;i++)
    ans=min(ans,solve(i)+abs(arr[ind]-arr[i]));
return dp[ind]=ans;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<solve(0);
    return 0;
}


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

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

  cin >> a >> b;

  c = stoi(a + b);

  if (sqrt(c)==int(sqrt(c)))
  {
    cout << "Yes" << endl;
  }

  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
#define ld long double
using namespace std;

int main()
{ 
fast;
ll x;
cin>>x;


for(ll a=-2000;a<=2000;a++)
    for(ll b=-2000;b<=2000;b++)
        if(a*a*a*a*a-b*b*b*b*b==x)
        {
          cout<<a<<" "<<b<<endl;
           return  0;
        }
}

Measured memory_bytes: 3584
#!/usr/bin/env python3
from collections import deque

base = ["3", "5", "7"]
N = int(input())
q = deque(base)
ans = 0
while q:
    num = q.pop()
    for i in base:
        next = num + i
        if int(next) <= N:
            q.append(next)
            if next.count("3") and next.count("5") and next.count("7"): 
                ans += 1
print(ans)




Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
bool p[100010] = { false };
int main() {
	int sum[100010] = { 0 };
	int q;
	cin >> q;
	for (int i = 2; i < 100001; i++) {
		for (int j = 2; j * j <= i; j++) {
			if (i % j == 0) {
				p[i] = true;
			}
		}
		if (i % 2 != 0) {
			if (p[(i + 1) / 2] == false && p[i] == false) {
				sum[i]++;
			}
		}
		sum[i] += sum[i - 1];
	}
	for (int k = 0; k < q; k++) {
		int l, r;
		cin >> l >> r;
		cout << sum[r] - sum[l - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;



int main(){
  ll n;
  cin >> n;
  vector<vector<ll>> data(10, vector<ll>(10));
  for(int i=1; i<=9; i++){ for(int j=1; j<=9; j++){
    for(int k=1; k<=6; k++){
      int now;
      if(k==1 && i!=j){continue;}
      if(k==1 && i==j && i<=n){data[i][j]++;}
      if(k==2){if(i*10+j<=n){data[i][j]++;}}
      if(k==3){
        int tes=i*100+0+j;
        while(tes<=n && tes<=i*100+90+j){
          data[i][j]++;
          tes+=10;
        }
      }
      if(k==4){
        int tes=i*1000+0+j;
        while(tes<=n && tes<=i*1000+990+j){
          data[i][j]++;
          tes+=10;
        }
      }
      if(k==5){
        int tes=i*10000+0+j;
        while(tes<=n && tes<=i*10000+9990+j){
          data[i][j]++;
          tes+=10;
        }
      }
      if(k==6){
        int tes=i*100000+0+j;
        while(tes<=n && tes<=i*100000+99990+j){
          data[i][j]++;
          tes+=10;
        }
      }
    }
  }}
  ll ans=0;
  for(int i=1; i<=9; i++){ for(int j=1; j<=9; j++){
    ans += data[i][j]*data[j][i];
  }}
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
mycode = r'''
# distutils: language=c++
# cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True
ctypedef long long LL
# cython: cdivision=True
from libc.stdio cimport scanf
from libcpp.vector cimport vector
ctypedef vector[LL] vec

cdef class SegmentTree():
    cdef LL num,n
    cdef vec tree

    def __init__(self,vec A):
        cdef LL n,i
        n = A.size()
        self.n = n
        self.num = 1 << (n-1).bit_length()
        self.tree = vec(2*self.num,0)
        for i in range(n):
            self.tree[self.num + i] = A[i]
        for i in range(self.num-1,0,-1):
            self.tree[i] = max(self.tree[2*i],self.tree[2*i+1])

    cdef void update(self,LL k,LL x):
        k += self.num
        self.tree[k] = x
        while k>1:
            self.tree[k>>1] = max(self.tree[k],self.tree[k^1])
            k >>= 1

    cdef LL query(self,LL l,LL r):
        cdef LL res
        res = 0
        l += self.num
        r += self.num
        while l<r:
            if l&1:
                res = max(res,self.tree[l])
                l += 1
            if r&1:
                res = max(res,self.tree[r-1])
            l >>= 1
            r >>= 1
        return res

    cdef LL bisect_l(self,LL l,LL r,LL x):
        cdef LL Lmin,Rmin,pos
        l += self.num
        r += self.num
        Lmin = -1
        Rmin = -1
        while l<r:
            if l&1:
                if self.tree[l] >= x and Lmin == -1:
                    Lmin = l
                l += 1
            if r&1:
                if self.tree[r-1] >= x:
                    Rmin = r-1
            l >>= 1
            r >>= 1

        if Lmin!=-1:
            pos = Lmin
            while pos<self.num:
                if self.tree[2*pos] >= x:
                    pos = 2*pos
                else:
                    pos = 2*pos + 1
            return pos-self.num

        elif Rmin!=-1:
            pos = Rmin
            while pos<self.num:
                if self.tree[2*pos] >= x:
                    pos = 2*pos
                else:
                    pos = 2*pos + 1
            return pos-self.num

        else:
            return self.n


cdef LL N,Q,i
cdef vec A

scanf("%lld %lld",&N,&Q)
A = vec(N,-1)
for i in range(N):
    scanf("%lld",&A[i])

cdef SegmentTree S = SegmentTree(A)
cdef LL t,x,v

for i in range(Q):
    scanf("%lld %lld %lld",&t,&x,&v)
    if t==1:
        S.update(x-1,v)
    elif t==2:
        print(S.query(x-1,v))
    else:
        print(S.bisect_l(x-1,N,v)+1)
'''
import sys
import os
if sys.argv[-1] == 'ONLINE_JUDGE':  # コンパイル時
    with open('mycode.pyx', 'w') as f:
        f.write(mycode)
    os.system('cythonize -i -3 -b mycode.pyx')

import mycode


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MAX=100005;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,n){cout<<arr[i][j]<<" ";}cout<<endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    string s;
    string ans;
    cin>>n>>k>>s;
    rep(i,n){
        if(i+1==k){
            ans += tolower(s[i]);
        }else{
            ans += s[i];
        }
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int dis[60][60],h,w;
char m[60][60];
queue<pair<int,pair<int,int> > >Q;
void Qpush(int cost,int y,int x){
    Q.push(make_pair(cost,make_pair(y,x)));
}
int main(){
    cin>>h>>w;
    int cnt=0;
    lol(i,h)lol(j,w){
	cin>>m[i][j];
	dis[i][j]=mod;
	if(m[i][j]=='.')cnt++;
    }
    Qpush(0,0,0);
    while(!Q.empty()){
	int cost=Q.front().first;
	int y=Q.front().second.first;
	int x=Q.front().second.second;
	Q.pop();
	if(dis[y][x]<=cost)continue;
	dis[y][x]=cost;
	int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
	lol(i,4){
	    int xx=x+dx[i],yy=y+dy[i];
	    if(xx<0||yy<0||xx==w||yy==h)continue;
	    if(dis[yy][xx]<mod||m[yy][xx]=='#')continue;
	    Qpush(cost+1,yy,xx);
	}
    }
    if(dis[h-1][w-1]==mod)cout<<"-1"<<endl;
    else cout<<cnt-dis[h-1][w-1]-1<<endl;
    return 0;
}


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

def calc(s,number,sign):
    if sign:
        if s+number>0:
            return (s+number,0,sign^1)
        else:
            return (1,1-s-number,sign^1)
    else:
        if s+number<0:
            return (s+number,0,sign^1)
        else:
            return (-1,s+number+1,sign^1)
signPlus=1
ansP = 0
s = 0
for number in a:
    s,d,signPlus=calc(s,number,signPlus)
    ansP+=d
signPlus=0
ansM = 0
s = 0
for number in a:
    s,d,signPlus=calc(s,number,signPlus)
    ansM+=d
print(min(ansP,ansM))

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

int main() {
    int n, x, t;
    cin >> n  >> x >>t;
    int temp;
    if(n%x == 0)
    temp = n/x;
    else
    temp = n/x + 1;

    cout<< temp*t;
  
    return 0;
}

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    cout << n + n * n + n * n * n << en;
}

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

    solve();
    // ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define N 
#define ll long long
#define db double
#define dbg1(x) cout<<#x<<"="<<x<<" "
#define dbg2(x) cout<<#x<<"="<<x<<"\n"
int T,a,b;ll ans;
db cal(ll x) {return (-(ll)b*x-1)*1./(a+x);}
int main()
{
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	for(scanf("%d",&T);T--;)
	{
		scanf("%d%d",&a,&b),ans=0;
		if(a<b) swap(a,b);
		if(a==1&&b==1) {puts("0");continue;}
		if(b>=1)
		{
			ll dd=sqrt(1ll*a*b),ans=dd*2-1;
			if(dd*dd==1ll*a*b)
			{
				if(a==b)ans--;
				else ans-=2;
			}
			else if(dd*(dd+1)>=1ll*a*b)ans--;
			cout<<ans<<endl;
			continue;
		}
		/*
		for(ll x=-a+1,y,tmp;;x++)
		{
			tmp=floor(((ll)-b*x-1)*1./(a+x));
			dbg1(x),dbg2(tmp);
			if(tmp==-b) break;
			if(tmp)
			{
				if(tmp^last) ans++,last=tmp;
				else
				{
					ans+=tmp+b-1;
					if(tmp>0) ans--;
					break;
				}
			}
		}
		dbg2(ans);*/
		ll l=-a+1,r=1e10,mid;
		for(;l<r;)
		{
			mid=l+r>>1;
//			dbg2(mid);
//			dbg1(cal(mid+1)),dbg2(cal(mid));
			cal(mid)-cal(mid+1)<1?r=mid:l=mid+1;
		}
//		dbg2(l);
		ll tmp1=floor((-(ll)b*l-1)*1./(a+l));
		ans=l+a+tmp1+b-1;
		if(l==-a+1)
		{
			if(tmp1>=0) ans--;
			cout<<ans<<"\n";
			continue;
		}
		ll tmp2=floor((-(ll)b*(l-1)-1)*1./(a+l-1));
//		dbg1(l-1),dbg1(cal(l-1)),dbg2(tmp2);
//		dbg1(l),dbg1(cal(l)),dbg2(tmp1);
//		dbg1(tmp1),dbg2(tmp2);
		if(tmp1>=0||tmp2<=0) ans--;
//		printf("%lld\n",ans);
		cout<<ans<<"\n";
	}
	return 0;
}


Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. 175C.
*>
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC  X(51).
01 X          PIC S9(16) COMP.
01 WX         PIC  9(16) COMP.
01 K          PIC  9(16) COMP.
01 D          PIC  9(16) COMP.
01 S          PIC  9(16) COMP.
01 R          PIC  9(16) COMP.
01 ZA         PIC S9(16).
01 OUT        PIC  Z(16)9.
*> 
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO X K D.
*>
  MOVE X TO WX.
  DIVIDE WX BY D GIVING S REMAINDER R.
  IF (S > 0)
    IF (X > 0)
      IF (S > K)
        COMPUTE ZA = X - K * D
        MOVE 0 TO K
      ELSE
        COMPUTE ZA = X - S * D
        COMPUTE K  = K - S
      END-IF
    ELSE
      IF (S > K)
        COMPUTE ZA = X + K * D
        MOVE 0 TO K
      ELSE
        COMPUTE ZA = X + S * D
        COMPUTE K  = K - S
      END-IF
    END-IF
  ELSE
    MOVE X TO ZA
  END-IF.
*>
  IF (K > 0)
    DIVIDE K BY 2 GIVING S REMAINDER R
    IF (R = 0)
      MOVE ZA TO OUT
    ELSE
      IF (ZA > 0)
        COMPUTE OUT = ZA - D
      ELSE
        COMPUTE OUT = ZA + D
    END-IF
  ELSE
    MOVE ZA TO OUT
  END-IF.
*>
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.


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

typedef std::pair<int, int> pair;
const int N = 100005, mod = 1000000007, inf = 1000000000;
int n, m, x[N], y[N];

pair point[N];

void reduce(int &x) { x += x >> 31 & mod; }

const int LN = 30;
int sum[N * LN], lc[N * LN], rc[N * LN], root, idx;

void modify(int &root, int pos, int v, int l = 1, int r = inf) {
	if (!root) root = ++idx; reduce(sum[root] += v - mod);
	if (l == r) return;
	int mid = l + r >> 1;
	if (pos <= mid) modify(lc[root], pos, v, l, mid);
	else modify(rc[root], pos, v, mid + 1, r);
}

int query(int root, int pos, int l = 1, int r = inf) {
	if (!root || pos == r) return sum[root];
	int mid = l + r >> 1;
	if (pos <= mid) return query(lc[root], pos, l, mid);
	return (query(rc[root], pos, mid + 1, r) + sum[lc[root]]) % mod;
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> m;
	for (int i = 0; i < n; ++i)
		std::cin >> x[i];
	for (int i = 0; i < m; ++i)
		std::cin >> y[i];
	int tot = 0, ans = 1;
	for (int i = 0; i < n; ++i) {
		if (x[i] < y[0] || x[i] > y[m - 1])
			continue;
		int j = std::lower_bound(y, y + m, x[i]) - y;
		point[tot++] = pair(x[i] - y[j - 1], y[j] - x[i]);
	}
	std::sort(point, point + tot, [] (pair a, pair b) {
		return a.first == b.first ? a > b : a < b;
	});
	tot = std::unique(point, point + tot) - point;
	for (int i = 0; i < tot; ++i) {
		int sum = 1 + query(root, point[i].second - 1);
		reduce(ans += sum - mod), modify(root, point[i].second, sum);
	}
	std::cout << ans << '\n';
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec P(N), Q(N);
    REP(i,0,N) cin >> P[i];
    REP(i,0,N) cin >> Q[i];
    
    vec A(N);
    REP(i,0,N) A[i] = i+1;

    ll cnt = 1, a, b;
    do {
        if(P == A) a = cnt;
        if(Q == A) b = cnt;
        ++cnt;
    } while(next_permutation(ALL(A)));
    PR(abs(a-b));

    return 0;
}

/*



*/

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;
ll yojo(ll x){
	ll num=1;
	for(int i=1;i<=x;i++){
		num*=i;
		num%=mod;
	}
	return num;
}
ll r(ll x){
	ll yan=1e9+5;
		ll tama=1;
		while(yan>0){
			if(yan%2)tama=(tama*x)%mod;
			x=(x*x)%mod;
			yan/=2;
		}
		tama%=mod;
		return tama;
}
int main(){
	ll x,y,ans=1;
	cin>>x>>y;
	if(x<y)swap(x,y);
	if((x+y)%3)ans=0;
	else{
		ll k=(2*y-x)/3,l=(2*x-y)/3;
		if(k<0||l<0){
			cout<<0;
			return 0;
		}
		ll p[2]={yojo(k),yojo(l)};
		ans=yojo(k+l);
		ans%=mod;
		ans*=r(p[0]);
		ans%=mod;
		ans*=r(p[1]);
		ans%=mod;
	}
	cout<<ans;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;


const int MAX_N = 100005;

int n,h[MAX_N],dp[MAX_N];

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
		scanf("%d",h+i);
	dp[1]=0,dp[2]=abs(h[1]-h[2]);
	for (int i=3; i<=n; i++)
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	printf("%d\n",dp[n]);
	return 0;
}


Measured memory_bytes: 896
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int h,n;cin>>h>>n;
  int a[n];
  int sum = 0;
  REP(i,n){
    cin>>a[i];
    sum += a[i];
  }

  if(h<=sum){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
 

  return 0;
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
 static int[][] road={{0,1},{1,0}};
 static int num=0;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		num = sc.nextInt();
		int[][] array = new int[3][num+1];
		for (int i = 1; i <=2; i++) {
			for (int j = 1; j <= num; j++) {
				array[i][j] = sc.nextInt();
			}
		}
		int sum=0;
		List<Integer> list=new ArrayList();
		deepRoad(0,0,array,sum,list);
		
		Collections.sort(list);
		System.out.println(list.get(list.size()-1));
	}

	static void deepRoad(int x,int y,int [][]array,int sum,List<Integer> list) {
		sum+=array[x][y];
		if(x==2&&y==num){
			list.add(sum);
		}
		int m=0,n=0;
		for(int i=0;i<2;i++){
			m=x+road[i][0];
			n=y+road[i][1];
			if(m<=2&&n<=num){
				deepRoad(m,n,array,sum,list);
			}
		}
	}

}


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

int main() {

  int a, b, c, d;

  cin >> a >> b >> c >> d;

  if ((a + b) > (c + d)) {
    cout << "Left" << endl;
  }
  else if ((a + b) < (c + d)) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }

}


Measured memory_bytes: 256
n = int(input())
XY = list(map(int, input().split()) for _ in range(n))
x_max = -float("inf")
y_max = -float("inf")
x_min = float("inf")
y_min = float("inf")
for x, y in XY:
    a, b = x-y, x+y
    x_max = max(x_max, a)
    x_min = min(x_min, a)
    y_max = max(y_max, b)
    y_min = min(y_min, b)
s = x_max - x_min
t = y_max - y_min
ans = max(s, t)
print(ans)

Measured memory_bytes: 132736
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { assert(x > 0); return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { assert(x > 0); return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
void fail() { puts("-1"); exit(0); }


const V dx = {1, 0, -1, 0};
const V dy = {0, 1, 0, -1};


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

  ll ans = 0;
  VV occ(n, V(n, 1));
  VV d(n, V(n));
  rep(i, n) rep(j, n) d[i][j] = min({i, n-i-1, j, n-j-1});

  rep(i, n*n) {
    int p; cin >> p;
    --p;
    int si = p/n;
    int sj = p%n;
    queue<P> que;
    que.emplace(si, sj);
    ans += d[si][sj];
    occ[si][sj] = 0;

    while (!que.empty()) {
      auto [i, j]  = que.front(); que.pop();
      rep(dir, sz(dx)) {
        int ii = i + dx[dir];
        int jj = j + dy[dir];
        if (ii < 0 || ii >= n || jj < 0 || jj >= n) continue;
        int dd = d[i][j] + occ[i][j];
        if (chmin(d[ii][jj], dd)) {
          que.emplace(ii, jj);
        }
      }
    }
  }

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 5524
//Scannerクラスをimport
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//Scannerクラスのインスタンスを作成
		//標準入力はSystemクラスのinフィールドから取得できる
		Scanner sc = new Scanner(System.in);

		//nextIntにて整数を取得
		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.println(a + b/2);
	}

}


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

int main() {
	vector<int> v;
	int i, t;
	for (i = 0; i < 10; i++) {
		cin >> t;
		v.push_back(t);
	}
	std::sort(v.begin(), v.end(), std::greater<int>());
	cout << v[0] << endl
	     << v[1] << endl
	     << v[2] << endl;
	return 0;	
}

Measured memory_bytes: 3124
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N, an = 0;
	string S;
	cin >> N >> S;
	
	rep(i, N - 2) {
		if (S.at(i) == 'A'&& S.at(i+1) == 'B'&& S.at(i+2) == 'C') {
			an++;
		}
	}
	cout << an << endl;
	
	
	
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
 
 
int main()
{
 int x,a,b;
 cin >> x >> a >> b;
 int dis_a = abs(x - a);
 int dis_b = abs(x - b);
 if(dis_a < dis_b)
 {
  cout << "A";
 }
 else
  cout << "B";
 
 return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		for (int i = 0; i < 3; i++) {
			a[i] = sc.nextInt();
		}
		int k = sc.nextInt();
		long sum = 0l;
		while (a[0] > 0 && k > 0) {
			int min = Math.min(a[0], k);
			sum += min;
			k -= min;
			a[0] -= min;
		}
		while (a[1] > 0 && k > 0) {
			int min = Math.min(a[1], k);
			k -= min;
			a[1] -= min;
		}
		while (a[2] > 0 && k > 0) {
			int min = Math.min(a[2], k);
			sum -= min;
			k -= min;
			a[2] -= min;
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 35820
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vec<lint> cylinder;
    range(i, 0, N) {
        lint jewelry;
        cin >> jewelry;
        cylinder.emplace_back(jewelry);
    }
    lint max_sum_value = 0;
    range(num_taken, 0, min(K + 1, N + 1)) {
        range(left, 0, num_taken + 1) {
            multiset<lint> taken;
            range(i, 0, left) taken.emplace(cylinder.at(i));
            range(i, 0, num_taken - left) taken.emplace(cylinder.at(N - i - 1));
            int remaining_steps = K - num_taken;
            while (remaining_steps && !taken.empty() && *taken.begin() < 0) {
                lint poped_item = *taken.begin();
                taken.erase(poped_item);
                remaining_steps -= 1;
            }
            lint sum_value = 0;
            for (const auto item : taken) sum_value += item;
            max_sum_value = max(max_sum_value, sum_value);
        }
    }
    cout << max_sum_value << "\n";
}

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

typedef long long ll;

int N,K;
ll A[100010];
ll cmp1[100010] = {0},cmp2[100010] = {0};

int main()
{
    scanf("%d%d",&N,&K);
    for(int i = 1; i <= N; i++)scanf("%lld",A + i);
    for(int i = 1; i <= N; i++)cmp1[i] = cmp1[i - 1] + A[i];
    for(int i = 1; i <= N; i++)cmp2[i] = cmp2[i - 1] + max(0LL,A[i]);

    ll ans = -1001001001001001001;
    for(int i = 1; i <= N - K + 1; i++)
    {
        ans = max(ans,max(cmp1[i + K - 1] - cmp1[i - 1],0LL) + cmp2[i - 1] - cmp2[0] + cmp2[N] - cmp2[i + K - 1]);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N=100+10,mod=1e9+7,inf=INT_MAX;
int n;
//2^n
const int bt=1<<21;
bool a[25][25];
ll dp[25][bt];


/*Note that the expression "mask | (1 << j)" sets j'th bit in mask.
*/
ll solve(int ind,int mask){
if(ind==n)return 1;
ll&r =dp[ind][mask];
if(r!=-1)return r;
ll ans=0;
for(int i=0;i<n;i++){
    if(a[ind][i]&&!(mask&1<<i)){
        int m=mask^(1<<i);
       ans+= solve(ind+1,m);
       ans%=mod;
    }
}
return r=ans;
}

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

cin>>n;
for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
       cin>>a[i][j];
    }
}
memset(dp,-1,sizeof dp);
cout<<solve(0,0);

    return 0;
}


Measured memory_bytes: 413264