akhauriyash/Code-Regression huggingface dataset:
Scanf.scanf "%d" (fun n ->
    let l = Array.make n 0 in
    let r = Array.make n 0 in
    for i = 0 to n - 1 do
        Scanf.scanf " %d %d" (fun a b -> l.(i) <- a; r.(i) <- b + 1)
    done;

    let rec loop i p q =
        if i = n then p, q else
            let p = if l.(i) > l.(p) then i else p in
            let q = if r.(i) < r.(q) then i else q in
            loop (i + 1) p q
    in
    let p, q = loop 0 0 0 in

    let result1 =
        let rec loop j acc =
            if j = n then acc + max (r.(q) - l.(p)) 0 else
            if j = p || j = q then loop (j + 1) acc else
                loop (j + 1) (max acc (r.(j) - l.(j)))
        in
        loop 0 0
    in
 
    Printf.printf "%d\n" @@ (
        let work = Array.init n (fun i -> max (r.(i) - l.(p)) 0, max (r.(q) - l.(i)) 0) in
        Array.sort (fun (a0, b0) (a1, b1) -> compare (a0, -b0) (a1, -b1)) work;
        let s = Array.make (n + 1) 0 in
        let t = Array.make (n + 1) 0 in
        t.(0) <- r.(q) - l.(q);
        s.(n) <- r.(p) - l.(p);
        for i = 1 to n do
            t.(i) <- min t.(i - 1) (snd work.(i - 1));
        done;
        for i = n - 1 downto 0 do
            s.(i) <- min s.(i + 1) (fst work.(i));
        done;

        let rec loop i acc =
            if i = n + 1 then acc else loop (i + 1) (max acc (s.(i) + t.(i)))
        in
        loop 0 result1
    )
)

Measured memory_bytes: 12860
#include<bits/stdc++.h>
# define M_PI           3.14159265358979323846  /* pi */
using namespace std;

#define int long long
#define loop(x) for(int i = 0;i<(x);i++)
string alpha = "abcdefghijklmnopqrstuvwxyz";
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout.tie(0);
	int n, m,total = 0; cin >> n >> m;
	while (m--) {
		int x; cin >> x; total += x;
	}
	cout << max(-1LL, n - total);
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
   ll N,A;
   cin >> N;
   map<ll,ll> data;
   bool over=false;
   for (int i=0;i<N;i++){
       cin >> A;
       data[A]++;
       if(data[A]==2){
           over=true;
           break;
       }
   }
   if(over==true){
       cout << "NO" << endl;
   }
   else{
       cout << "YES" << endl;
   }
}


Measured memory_bytes: 15984
import scala.annotation.tailrec
import scala.collection.mutable

object Main extends App {
  import scala.io.StdIn._

  val n = readInt
  val swapCost = Array.fill(n){readLine.trim.split(' ').map(_.toInt)}
  val permutations = (1 to n).permutations.map{p ⇒ p.foldLeft(0){case (acc, i) ⇒ acc * 10 + i}}.toArray.sorted
  val memo = Array.fill((2 to n).product){Long.MaxValue}
  memo(0) = 0
  val queue = mutable.PriorityQueue((0, 0L))(Ordering.by[(Int, Long), Long](_._2).reverse)
  while (queue.nonEmpty) {
    val (c, cost) = queue.dequeue()
    if (memo(c) == cost) {
      val current = permutations(c)
      for (i ← 0 until n) for (j ← i until n) {
        val swapped = current.swap(i, j)
        val next = permutations.lowerBound(swapped)
        if (memo(next) > cost + swapCost(current(i) - 1)(current(j) - 1)) {
          memo(next) = cost + swapCost(current(i) - 1)(current(j) - 1)
          queue.enqueue((next, memo(next)))
        }
      }
    }
  }
  println(memo.max)
  object DigitsArray {
    val digits = Array.fill(8){1}
    for (i ← digits.indices.tail) digits(i) = 10 * digits(i - 1)
  }
  implicit class DigitsArray(val value: Int) extends AnyVal {
    def apply(digit: Int): Int = value / DigitsArray.digits(digit) % 10
    def swap(i: Int, j: Int): Int = value.replace(i, value(j)).replace(j, value(i))
    def replace(i: Int, d: Int): Int = value - value(i) * DigitsArray.digits(i) + d * DigitsArray.digits(i)
  }
  implicit class SortedArray[T: Ordering](val array: Array[T]) {
    def lowerBound(target: T): Int = {
      var left = 0
      var right = array.length
      while (left < right){
        val mid = (left + right) / 2
        if (implicitly[Ordering[T]].compare(array(mid), target) < 0) left = mid + 1
        else right = mid
      }
      right
    }
  }
}


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

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	vector<vector<int>> dp(N + 1, vector<int>(K + 1)), rdp(N + 1, vector<int>(K + 1));
	dp[0][0] = rdp[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		for (int j = K; j >= 0; j--) {
			if (dp[i - 1][j]) {
				dp[i][j] = 1;
				dp[i][min(j + a[i - 1], K)] = 1;
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		for (int j = K; j >= 0; j--) {
			if (rdp[i - 1][j]) {
				rdp[i][j] = 1;
				rdp[i][min(j + a[N - i], K)] = 1;
			}
		}
	}
	for (int i = 0; i <= N; i++) {
		for (int j = 1; j <= K; j++) {
			rdp[i][j] += rdp[i][j - 1];
		}
	}
	int res = 0;
	for (int i = 0; i < N; i++) {
		bool flag = true;
		for (int j = 0; j < K; j++) {
			if (dp[i][j] && rdp[N - i - 1][K - j - 1] - (K - j - a[i] > 0 ? rdp[N - i - 1][K - a[i] - j - 1] : 0) > 0) {
				flag = false;
				break;
			}
		}
		if (flag) {
			res++;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 195968
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    B = list(map(int,input().split()))
    ans = B[0]
    for i in range(1,N-1):
        ans += min(B[i-1],B[i])
    ans += B[N-2]
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
from collections import Counter

N = int(input())
if N <= 9:
    print(0)
    exit()

def factorize(n):
    d = Counter()
    m = 2
    while m*m <= n:
        while n%m == 0:
            n //= m
            d[m] += 1
        m += 1
    if n > 1:
        d[n] += 1
    return d

factors = Counter()
for n in range(2,N+1):
    factors += factorize(n)


# 5-5-3
four = two = 0
for v in factors.values():
    if v >= 2:
        two += 1
    if v >= 4:
        four += 1
ans = four*(four-1)//2
two -= 2
ans *= two

# 15-5
d14 = d4 = 0
for v in factors.values():
    if v >= 4:
        d4 += 1
    if v >= 14:
        d14 += 1
ans += d14 * (d4-1)

# 25-3
d24 = d2 = 0
for v in factors.values():
    if v >= 2:
        d2 += 1
    if v >= 24:
        d24 += 1
ans += d24 * (d2-1)

# 75
d74 = 0
for v in factors.values():
    if v >= 74:
        d74 += 1
ans += d74

print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
#include <map>
#include <stack>
using namespace std;
 
int dx[8]={1,-1,0,0,1,1,-1,-1};
int dy[8]={0,0,1,-1,-1,1,-1,1};
 
 
int main() {
int yoko,tate,px,py;
while(cin>>yoko>>tate &&yoko){
 
    int m[55][55]={0};
 
string st;
//cin>>yoko>>tate;
for(int i=1;i<tate+1;i++){
for(int j=1;j<yoko+1;j++){
cin>>m[i][j];
}
}
int ans=0;

for(int i=0;i<tate+1;i++){
for(int j=0;j<yoko+1;j++){
if (m[i][j]==0) continue;  

stack<pair<int,int> > s;
s.push(make_pair(i,j));
m[i][j]=0;
//cout<<"pxpy "<<px<<" "<<py<<endl;
while(s.empty()==false){
px=s.top().first;
py=s.top().second;
s.pop();
 
for(int i=0;i<8;i++){
//cout<<px+dx[i]<<" "<<py+dy[i]<<endl;
    if(0<px+dx[i] && px+dx[i]<tate+1 && py+dy[i]>0 && py+dy[i]<yoko+1){
     
        if(m[px+dx[i]][py+dy[i]]==1){
            m[px+dx[i]][py+dy[i]]=0;
            s.push(make_pair(px+dx[i],py+dy[i]));
            
//cout<<px+dx[i]<<" "<<py+dy[i]<<" "<<ans<<endl;
        }
 
    }}
}
 ans++;
}}
cout<<ans<<endl;
 
}
 
 
 
    return 0;
}

Measured memory_bytes: 1244
# pragma GCC optimize("Ofast")
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
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; }


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> num(n,0);
    vector<int> ans(n,0);
    rep(i,n) cin >> num[i];
    rep(i,n){
        ans[num[i]-1] = i+1;
    } 
    rep(i,n){
        if(i!=0) cout << " ";
        cout << ans[i];
    }
    return 0;
}

Measured memory_bytes: 1664
h,w=map(int,input().split())

ans=9999999999999

#|-----|
#| | | |
#| | | |
#|-----|
if(w%3==0):
    ans=min(ans,0)
else:
    ans=min(ans,(((w//3)+1)*h)-((w//3)*h))


#|-----|
#|-----|
#|-----|
#|-----|
if(h%3==0):
    ans=min(ans,0)
else:
    ans=min(ans,(((h//3)+1)*w)-((h//3)*w))

#|-----| |-----|
#| |   | |   | |
#| |---| |---| |
#|-----| |-----|
if(h%2==0):
    for wi in range(1,w):
        a=(h//2)*wi
        b=(h//2)*wi
        c=h*(w-wi)
        ans=min(ans, max(a,b,c)-min(a,b,c))
else:
    for wi in range(1,w):
        a=(h//2)*wi
        b=((h//2)+1)*wi
        c=h*(w-wi)
        ans=min(ans, max(a,b,c)-min(a,b,c))


#|-----| |-----|
#|  |  | |-----|
#|-----| |  |  |
#|-----| |-----|
if(w%2==0):
    for hi in range(1,h):
        a=(w//2)*hi
        b=(w//2)*hi
        c=w*(h-hi)
        ans=min(ans, max(a,b,c)-min(a,b,c))
else:
    for hi in range(1,h):
        a=(w//2)*hi
        b=((w//2)+1)*hi
        c=w*(h-hi)
        ans=min(ans, max(a,b,c)-min(a,b,c))

print(ans)

Measured memory_bytes: 3188
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()


def valuecheck(x, k):
    
    
    if (x * 2) <= (x + k):
    
        return x * 2
    
    else:
        
        return x + k

n = int(arr_data[0][0])
k = int(arr_data[1][0])


#print(n, k)

cnt = 0

x = 1

while cnt < n:

    x = valuecheck(x, k)
    
    cnt += 1


print(x)

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

#define int long long
const int INF = 1e9;

int dp[1<<18][50];
vector<int> ch[1<<18];
int N;
vector<int> A, B;

int dfs(int b, int p) {
  // cout << b << " " << p << endl;
  if ( dp[b][p] >= 0 ) return dp[b][p];
  if ( b == (1<<N)-1 ) return 0;
  
  int n = __builtin_popcount(b);  
  int nxt = (1<<N) - 1;
  vector<int> v = ch[b];

  int ret = INF;
  int cnt = 0;
  for ( int i = 0; i < N; i++ ) {
    if ( !(b&(1<<i)) ) {
      int tmp;
      if ( v[cnt] ^ (cnt%2) ) {
	tmp = B[i];
      } else {
	tmp = A[i];
      }

      if ( tmp >= p ) ret = min(ret, dfs(b|(1<<i), tmp)+cnt);
      cnt++;
    }
  }

  return dp[b][p] = ret;  
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N;
  A.resize(N);
  B.resize(N);
  fill_n(*dp, (1<<18)*50, -1);
  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 < (1<<N); i++ ) {
    int b = 0;
    for ( int j = 0; j < N; j++ ) {
      if ( i&(1<<j) ) {
	for ( int k = 0; k < j; k++ ) b = b ^ (1<<k);	
      }
    }
    vector<int> v;
    for ( int j = 0; j < N; j++ ) {
      if ( !(i&(1<<j)) ) {
	if ( b&(1<<j) ) {
	  v.push_back(1);	  
	} else {
	  v.push_back(0);	  
	}
      }
    }
    /*
    cout << bitset<3>(i) << " ";
    for ( int j: v ) cout << j;
    cout << endl;
    */
    ch[i] = v;    
  }

  int ans = dfs(0, 0);
  if ( ans == INF ) cout << -1 << endl;
  else cout << ans << endl;
    
  return 0;
}


Measured memory_bytes: 130304
import java.util.Scanner;

public class Main {

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

        String s = scanner.next();
        String t = scanner.next();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        String u = scanner.next();

        if (u.equals(s)) {
            a--;
        }
        if (u.equals(t)) {
            b--;
        }

        System.out.println(a + " " + b);
    }
}

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

int kaizyiou(int n){
    int a = 1;
    for(int i = 1;i <= n; i++){
        a *= i;
    }
    return a;
}

int main() {
    int n;
    cin >> n;
    vector<double> x(n);
    vector<double> y(n);
    for(int i = 0; i < n; i++){
        cin >> x.at(i) >> y.at(i);
    }

    double sum = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            sum += sqrt(pow((x.at(i)-x.at(j)),2)+pow((y.at(i)-y.at(j)),2));
        }
    }

    cout << fixed << setprecision(10); 
    cout << sum * (n-1) / ((n-1)*n/2) << endl;

}

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

int main() {
  //1円硬貨の枚数を変数Ａで表す。
  int A;
  //支払わなくてはいけない金額を変数Ｎで表す。
  int N;
  //５００円で支払った残りの数を変数amariで表す。
  int amari;
  
  cin >> N >> A;
  
  amari = N % 500;
  if((A - amari) >= 0){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
a = input().split()
n = int(a[0])
m = int(a[1])
 
d = {}
ret = True
for i in range(m):
  a = input().split()
  s = int(a[0])
  c = int(a[1])
  if (d.get(s,-1) != -1) & (d.get(s,-1) != c):
    ret = False
  if (n >1) & (s == 1) & (c == 0):
    ret = False
  if s > n:
    ret = False
  d[s] = c
 
p = ""    
for i in range(1,n+1):
  if d.get(i,-1) == -1:
    if (i == 1) & (n > 1):
      p += "1"
    else:
      p += "0"
  else:
    p += str(d[i])
if ret:
  print(p)
else:
  print("-1")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int q = scan.nextInt();
		for(int i = 0; i < q; i++) {
			int[]p0 = new int[2];
			int[]p1 = new int[2];
			int[]p2 = new int[2];
			int[]p3 = new int[2];
			p0[0] = scan.nextInt();
			p0[1] = scan.nextInt();
			p1[0] = scan.nextInt();
			p1[1] = scan.nextInt();
			p2[0] = scan.nextInt();
			p2[1] = scan.nextInt();
			p3[0] = scan.nextInt();
			p3[1] = scan.nextInt();
			int[]u = vec(p0, p1);
			int[]v = vec(p2, p3);
			if(dot(u, v) == 0) {
				System.out.println(1);
			}else if(u[0] * v[1] - u[1] * v[0] == 0) {
				System.out.println(2);
			}else {
				System.out.println(0);
			}
		}
	}
	static int norm(int[]p) {
		return p[0] * p[0] + p[1] * p[1];
	}
	static int[] vec(int[]p1, int[]p2) {
		int[]u = {p2[0] - p1[0], p2[1] - p1[1]};
		return u;
	}
	static int dot(int[]u, int[]v) {
		return u[0] * v[0] + u[1] * v[1];
	}
	static int cross(int[]u, int[]v) {
		return u[0] * v[1] + u[1] * v[0];
	}
}


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

int main()
{
    int N;
    cin >> N;
    int A;
    int cumulative_sum[2][N + 1] = {{0}};
    for (int i = 1; i <= N; i++)
    {
        cin >> A;
        cumulative_sum[0][i] = cumulative_sum[0][i - 1] + A;
    }
    for (int i = 1; i <= N; i++)
    {
        cin >> A;
        cumulative_sum[1][i] = cumulative_sum[1][i - 1] + A;
    }

    int ans = 0;
    for (int i = 1; i <= N; i++)
    {
        ans = max(ans, cumulative_sum[0][i] + cumulative_sum[1][N] - cumulative_sum[1][i - 1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    l_0 = []
    r_0 = []
    ls_plus = []
    ls_minus = []
    sum_l = 0
    sum_r = 0
    for i in range(n):
        s = input()
        left, right = 0, 0
        for j in range(len(s)):
            if s[j] == '(':
                right += 1
            else:
                if right > 0:
                    right -= 1
                else:
                    left += 1
        if left == right == 0:
            continue

        if left == 0:
            l_0.append((left, right))
        elif right == 0:
            r_0.append((left, right))
        elif left < right:
            ls_plus.append((left, right))
        else:
            ls_minus.append((left, right))
        sum_l += left
        sum_r += right

    if len(ls_plus) == len(ls_minus) == len(l_0) == len(r_0) == 0:
        print("Yes")
        return

    if len(l_0) == 0 or len(r_0) == 0:
        print("No")
        return
    if sum_l != sum_r:
        print("No")
        return

    # r-lの大きい順
    ls_plus.sort(key=lambda x: x[1] - x[0], reverse=True)
    # lの小さい順
    ls_plus.sort(key=lambda x: x[0])

    # l-rの小さい順
    ls_minus.sort(key=lambda x: x[0] - x[1])
    # lの大さい順
    ls_minus.sort(key=lambda x: x[0], reverse=True)

    now_r = 0
    for ll in l_0:
        now_r += ll[1]

    for _ in ls_plus:
        r = _[1]
        x = now_r - _[0]
        if x >= 0:
            now_r = x + r
        else:
            print("No")
            return

    for _ in ls_minus:
        r = _[1]
        x = now_r - _[0]
        if x >= 0:
            now_r = x + r
        else:
            print("No")
            return

    print("Yes")


main()


Measured memory_bytes: 80280
#include <stdio.h>
#define MAX 1001
void c2s(char str[]){
	int i;
	for(i = 0; str[i] != 0; i++){
		if(str[i] == ','){
			str[i] = ' ';
		}
	}
}

int main(void){
	char str[MAX];
	int single,num;
	int p_sum = 0;
	int n_sum = 0;
	int ave, ctr;
	ctr = 0;
	while(scanf("%s",str) != EOF){
		c2s(str);
		sscanf(str,"%d%d",&single,&num);
		p_sum += single * num;
		n_sum += num;
		ctr++;
	}
	if(ctr){
		ave =  n_sum  * 10 / ctr;
		if(ave % 10 >= 5){
			ave = ave / 10 + 1;
		}else{
			ave /= 10;
		}
		printf("%d\n",p_sum);
		printf("%d\n",ave);
	}
	return 0;
}

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

#define endl '\n'
#define int ll
using namespace std;
typedef long long ll;

int n, k;
string str;

void init();
void process();

int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> n >> k >> str;
    k--;
}

void process()
{
    str[k] = tolower(str[k]);
    cout << str << endl;
}



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

#define MAX(A, B) (((A) > (B)) ? (A) : (B))

int acgt(char* s, int i) {
  if (*(s + i) == 'A') {return 1;}
  else if (*(s + i) == 'C') {return 1;}
  else if (*(s + i) == 'G') {return 1;}
  else if (*(s + i) == 'T') {return 1;}
  else {return 0;}
}

int main() {
  char* s = malloc(30 * sizeof(char));
  int count=0;
  int max = 0;
  
  scanf("%s", s);
  int length=0;
  while(*(s+length)) {length++;}
  for (int i=0; i<length; i++) {
    if (acgt(s, i)) {count++;}
    else if (count) {count = 0;}
    max = MAX(max, count);
  }
  printf("%d", max);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define REV(v) rbegin(v), rend(v)
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

typedef pair<int, int> P;

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

	vector<string> v(n);
	rep(i, n) cin >> v[i];

	vector<P> a[26];
	rep(i, n) rep(j, m){
		if (v[i][j] != '.') a[v[i][j] - 'A'].push_back(MP(j, i));
	}

	vector<int> bits[26];
	int ex[26] = {};

	auto f_x = [&bits, &v](int x1, int x2, int y, int i, int j){
		for (int x = x1; x <= x2; ++x) if (v[y][x] != '.') bits[i][j] |= 1 << v[y][x] - 'A';
		bits[i][j] &= ~(1 << i);
	};
	auto f_y = [&bits, &v](int y1, int y2, int x, int i, int j){
		for (int y = y1; y <= y2; ++y) if (v[y][x] != '.') bits[i][j] |= 1 << v[y][x] - 'A';
		bits[i][j] &= ~(1 << i);
	};

	rep(i, 26){
		if (a[i].empty()) continue;
		ex[i] = 1;
		bits[i].resize(1);

		int t, b, l, r;
		t = a[i][0].Y;
		b = a[i][1].Y;
		l = a[i][0].X;
		r = a[i][1].X;
		if (l == r){
			if (t > b) swap(t, b);
			f_y(t, b, l, i, 0);
			if (b - t == 1) bits[i][0] = -1;
		}
		else if (t == b){
			if (l > r) swap(l, r);
			f_x(l, r, t, i, 0);
			if (r - l == 1) bits[i][0] = -1;
		}
		else{
			bits[i].resize(2);
			vector<int> j = { 0, 1, 1, 0 };
			if (l > r){
				swap(j[1], j[3]);
				swap(l, r);
			}
			f_x(l, r, t, i, j[0]);
			f_y(t, b, l, i, j[1]);
			f_x(l, r, b, i, j[2]);
			f_y(t, b, r, i, j[3]);
		}
	}

	int cnt = 0;
	int state = (1 << 26)-1;
	while (1){
		bool upd = false;

		rep(i, 26){
			if (!ex[i]) continue;
			bool er = false;
			for(auto x : bits[i]){
				if (x&state) continue;
				er = true;
			}
			if (er){
				ex[i] = 0, upd = true, ++cnt;
				state &= ~(1 << i);
			}
		}

		if (!upd) break;
	}
	cout << cnt * 2 << endl;

	return 0;
}

Measured memory_bytes: 1476
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long sum = 1;
        if(H==1) System.out.println(1);
        else{
            long num = 2;
            while(num<=H){
                sum+=num;
                num*=2;
            }
            System.out.println(sum);
        }
    }
}

Measured memory_bytes: 23764
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var b = cin.ReadLine;
            if (b == "A") WriteLine("T");
            else if (b == "T") WriteLine("A");
            else if (b == "C") WriteLine("G");
            else WriteLine("C");

        }

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

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

class Main {

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

	int N = sc.nextInt();
	int A[] = new int[N];
	int B[] = new int[N];
	for (int i = 0; i < N; i++) {
	    A[i] = sc.nextInt();
	    B[i] = A[i];
	}

	Arrays.sort(B);
	for (int i = 0; i < N; i++) {
	    if (A[i] < B[N - 1])
		System.out.println(B[N - 1]);
	    else
		System.out.println(B[N - 2]);
	}
    }
}

Measured memory_bytes: 87248
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>           // 整数を使う時
using namespace boost::multiprecision;

int main() {
  int N;
  std::cin >> N;
  cpp_int ans = 1;
  int fin = 0;
  cpp_int X[N];
  for (int i = 0; i < N; i++ ) {
    std::cin >> X[i];
    if (X[i] == 0) {
      ans = 0;
      break;
    }
  }
  for (int i = 0; i < N; i++ ) {
    ans = ans * X[i];
    if (ans == 0) {
      break;
    }
    if (ans > 1000000000000000000) {
      ans = -1;
      break;
    }
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 6812
#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 <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n,k;
    cin>>n>>k;
    VL p(n);
    REP(i,n)cin>>p[i];
    vector<double> x(n);
    REP(i,n)x[i] = (p[i] + 1)/2.0;
    double sum = 0.0;
    REP(i,k){
        sum += x[i];
    }
    double ans = sum;
    FOR(i,k,n){
        sum += x[i];
        sum -= x[i-k];
        ans = max(ans, sum);
    }
    printf("%.9f\n", ans);
}

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

int main(){
    int n,i,count=0;
    cin >> n;
    vector<int> a(n);
    for(i=0;i<n;i++){
        cin >> a.at(i);
    }
    for(i=0;i<n-1;i++){
        if(a.at(i)==a.at(i+1)){a.at(i+1)=0;count++;}
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cassert>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <deque>

using namespace std;

#define all(x) (x).begin(), (x).end()

#ifdef LOCAL
#define dbg(x) cerr << #x " = " << x << endl;
#define idbg(x) #x " = " << x
#include "pretty_print.h"
#else
#define dbg(x)
#define idbg(x) ""
#endif

#ifdef _WIN32
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }


int main(int /* argc */, char** /* argv */)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    assert(freopen("inp", "r", stdin));
    assert(freopen("out", "w", stdout));
    #endif

    deque<char> d;
    string s;
    while (cin >> s) {
        for (auto& c : s) {
            d.push_back(c);
        }
        int rev = 0;
        int n;
        cin >> n;
        while (n--) {
            int c;
            cin >> c;
            if (c == 1) {
                rev ^= 1;
            } else {
                int t;
                char v;
                cin >> t >> v;
                if (rev ^ (t - 1)) {
                    d.push_back(v);
                } else {
                    d.push_front(v);
                }
            }
        }
        vector<char> a;
        while (d.size()) {
            a.push_back(d.front());
            d.pop_front();
        }
        if (rev) {
            reverse(all(a));
        }
        for (auto& c : a) {
            cout << c;
        }
        cout << "\n";
    }


    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


Measured memory_bytes: 1364
#include <iostream>
#include <set>

#define N_MAX (2*100000)
#define MOD (998244353)

unsigned int dp[N_MAX];

int main() {
  int N, K;
  std::cin >> N >> K;

  int L[10], R[10];
  for (int i = 0; i < K; i++) {
    std::cin >> L[i] >> R[i];
  }
  dp[0] = 1;
  for (int i = 1; i < N; i++) {
    dp[i] = dp[i-1];
    for (int k = 0; k < K; k++) {
      if (i-L[k] >= 0 && i-R[k]-1 >= 0) {
        dp[i] += (MOD + dp[i-L[k]] - dp[i-R[k]-1]) % MOD;
      } else if (i-L[k] >= 0) {
        dp[i] += dp[i-L[k]];
      }
      dp[i] %= MOD;
    }
  }
  std::cout << (MOD + dp[N-1] - dp[N-2]) % MOD << std::endl;
  return 0;
}


Measured memory_bytes: 3888
#include <algorithm>
#include <cstdint>
#include <iostream>

auto main() -> int {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  std::string s{};
  std::cin >> s;

  const auto l = s.length();

  // 01010101... か
  // 10101010... にすればよさそう？
  std::int64_t bw = 0;
  std::int64_t wb = 0;

  constexpr char c[] = {'0', '1'};

  for (auto i = 0ul; i < l; ++i) {
    if (s[i] != c[i % 2]) bw++;
    if (s[i] != c[(i + 1) % 2]) wb++;
  }

  std::cout << std::min(bw, wb) << std::endl;
}


Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def f(A, B, C, D, S):
    T = list(S)
    T[A] = "A"
    T[B] = "B"
    T[C] = "C"
    T[D] = "D"
    print("".join(T))


def solve(N: int, A: int, B: int, C: int, D: int, S: str):
    A = A-1
    B = B-1
    C = C-1
    D = D-1
    # f(A, B, C, D, S)

    def reachable(A, C, S):     # O(N)
        if A > C:
            return False
        # AからCへ到達可能ですか
        if S[A:C+1].find("##") == -1:
            return True
        else:
            return False

    if C > D:
        # できるだけ早く追い越す
        # 追い越すためには、"..."という領域が必要。
        oikoshi = S[B-1:].find("...")
        if oikoshi == -1:
            no()
            return
        if reachable(A, B-1+oikoshi, S) and reachable(B, B-1+oikoshi+1, S):
            A = B-1+oikoshi + 2
            B = B-1+oikoshi + 1
            # f(A, B, C, D, S)
        else:
            no()
            return

    # ２連岩なければ通れる
    if reachable(A, C, S) and reachable(B, D, S):
        yes()
    else:
        no()
    return


def main():

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


if __name__ == '__main__':
    main()


Measured memory_bytes: 3636
#include <cstdio>

using namespace std;

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

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

    printf("\n");
    return 0;
}

Measured memory_bytes: 2748
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int a, ans, m = 10;
int main(){
	rep(i,5){
		scanf("%d", &a);
		m = min(m, (a-1) % 10 + 1);
		ans += (a + 9) / 10 * 10;
	}
	printf("%d\n", ans - 10 + m);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define clr(A, x) memset(A, x, sizeof(A))
#define cpy(A, B) memcpy(A, B, sizeof(B))
#define g(s) getline(cin, s) ///ai grija la fin/cin ///
#define FASTIO ios_base::sync_with_stdio(0)
const long long INFLL = 2 * 1e18 + 100;
const int INFINT = 2 * 1e9 + 100;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
//ifstream fin("input.txt");
//ofstream fout("output.txt");
void die()
{
    cout << "-1";
    exit(0);
}
const int NMAX = 1e5 + 5;
const int MOD = 1e9 + 7; /// careful here (7 or 9, 66.. etc)
const double PI = atan(1) * 4;
const double EPS = 1e-12;

string s;
int br;
deque<char> sol;

int main()
{
    FASTIO;
    int blah; cin >> blah;
    cin >> s;
    for(auto i: s)
    {
        if(i == ')')
        {
            if(br)
                br--;
            else sol.push_front('(');
        }
        else br++;
        sol.push_back(i);
    }
    for(auto i: sol) cout << i;
    for1(i, br) cout << ')';


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
//#include <string>
#define ll long long
using namespace std;

void motome(ll t, ll &n, ll &m, ll &q, vector<ll> &a, vector<ll> &b, vector<ll> &c, vector<ll> &d, ll &ans, vector<ll> &hai)
{
    if(t == n) {
        for(hai.at(t - 1) = hai.at(t - 2); hai.at(t - 1) <= m; hai.at(t - 1)++) {
            ll ma = 0;
            for(ll j = 0; j < q; j++) {
                if(hai.at(b.at(j) - 1) - hai.at(a.at(j) - 1) == c.at(j)) {
                    ma += d.at(j);
                }
            }
            if(ans < ma)
                ans = ma;
        }
        return;
    }

    else {
        for(hai.at(t - 1) = hai.at(t - 2); hai.at(t - 1) <= m; hai.at(t - 1)++) {
            motome(t + 1, n, m, q, a, b, c, d, ans, hai);
        }
        return;
    }
}


int main() 
{
    ll n, m, q, ans = 0;
    cin >> n >> m >> q;
    vector<ll> a(q), b(q), c(q), d(q), hai(n, 1);
    for(ll i = 0; i < q; i++)
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);

    for(hai.at(0) = 1; hai.at(0) <= m; hai.at(0)++)
        motome(2, n, m, q, a, b, c, d, ans, hai);

    cout << ans << endl;
}

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

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    int cnt = 1;
    while(cnt <= min(a,k)){
        ans++;
        cnt++;
    }
    while(cnt <= min(a+b,k)){
        cnt++;
    }
    while(cnt <= min(a+b+c,k)){
        cnt++;
        ans--;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define fi first
#define se second
#define db double
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 5e5 + 5;
char str[MAXN];int n;
int f[MAXN][2];

int main(){
    scanf("%s",str+1);n = strlen(str+1);
    f[0][0] = 0;f[0][1] = -1e9;// 0:D 1:P
    FOR(i,1,n){
        if(str[i] == 'P'){
            f[i][1] = std::max(f[i-1][0],f[i-1][1]);
            f[i][0] = -1e9;
        }
        else if(str[i] == 'D'){
            f[i][1] = -1e9;
            f[i][0] = std::max(f[i-1][0],f[i-1][1]+1)+1;
        }
        else{
            f[i][1] = std::max(f[i-1][0],f[i-1][1]);
            f[i][0] = std::max(f[i-1][0],f[i-1][1]+1)+1;
        }
    }
    int now = f[n][0] > f[n][1] ? 0 : 1;std::vector<char> ans;
    ROF(i,n,1){
        if(now == 0){
            ans.pb('D');
            if(f[i-1][0]+1 == f[i][0]) now = 0;
            else now = 1;
        }
        else{
            ans.pb('P');
            if(f[i-1][0] == f[i][1]) now = 0;
            else now = 1;
        }
    }
    std::reverse(all(ans));
    for(auto x:ans) putchar(x);
    return 0;
}


Measured memory_bytes: 5580
#include<bits/stdc++.h>
#define up(j,k,i) for(i=j;i<k;i++)
#define down(j,k,i) for(i=j;i>k;i--)
#define pp(n) printf("%lld\n",n)
#define pps(n) printf("%lld ",n)
#define all(x) x.begin(),x.end()
#define ps(s) printf("%s",s)
#define is(n) scanf("%lld",&n)
#define ips(n) scanf("%lld",n)
#define ss(s) scanf("%s",s)
#define cool 0
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define f(i) cout<<i<<endl;
#define pll pair<lld,lld> 
#define pi acos(-1)
#ifdef G
#define dg(x) cout<<#x<<' '<<x<<endl;
#define dg2(x,y) cout<<#x<<' '<<x<<' '<<#y<<' '<<y<<endl;
#define dg3(x,y,z) cout<<#x<<' '<<x<<' '<<#y<<' '<<y<<' '<<#z<<' '<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<' '<<x<<' '<<#y<<' '<<y<<' '<<#z<<' '<<z<<' '<<#zz<<' '<<zz<<endl;
#else
#define dg(x) ;
#define dg2(x,y) ;
#define dg3(x,y,z) ;
#define dg4(x,y,z,zz) ;
#endif
#define ds(n,m) scanf("%lld %lld",&n,&m)
#define ts(n,m,k) scanf("%lld %lld %lld",&n,&m,&k)
#define yes printf("YES\n")
#define no printf("NO\n")
typedef long double ld;
typedef long long int lld;
using namespace std;
const lld M =2e5+1;
const lld mod=1e9+7;
const lld infi =LLONG_MAX;
lld ans,k,n,x,y,m,mymax=LLONG_MIN,mymin=LLONG_MAX,c,z,sum;
vector<lld>a,b;
lld sa[M],sb[M];
int main()
{
 lld i,j;
 ds(n,k);
 up(1,n+1,i)
 {
 	is(x);
 	if(x>=0)
 	{
 		a.pb(x);
 	}
 	else
 	{
 		b.pb(-x);
 	}
 }
 lld nb=b.size(),na=a.size();
 if(na>=k)mymin=min(mymin,a[k-1]);
 if(nb>=k)mymin=min(mymin,b[nb-k]);
 up(max(k-na,(lld)1),min(nb+1,k),i)
 {
 	ans=a[k-i-1]+b[nb-i]+min(a[k-i-1],b[nb-i]);
 	dg3(i,a[k-i-1],b[nb-i]);
 	//dg4(i,sb[nb],sb[nb-i],sa[k-i]);
 	mymin=min(ans,mymin);
 }
 pp(mymin);
 return 0;
}

Measured memory_bytes: 1656
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<bitset>
using namespace std;
int GCD(int x,int y)
{
	while(int z=x%y)x=y,y=z;
	return y;
}
int LCM(int x,int y){return x/GCD(x,y)*y;}
int A(char c)
{
	char s[2]={c};
	return strtol(s,0,16);
}
int F(vector<int>&v,int n)
{
	vector<int>u;
	for(int i=0;i<v.size();++i)
	{
		if(i%n)
		{
			if(v[i])return 0;
		}
		else u.push_back(v[i]);
	}
	v=u;
	return 1;
}
int main()
{
	const int N=2050;
	int n,T,i,j,d;
	bitset<N>P;
	P.set();
	P[0]=P[1]=0;
	for(i=2;i*2<N;++i)if(P[i])for(j=i*2;j<N;j+=i)P[j]=0;
scanf("%d",&T);
	vector<vector<int> >r;
	vector<int>v;
	char*p,s[2049];
	while(T--)
	{
		r.clear();
		scanf("%d",&n);
		while(n--)
		{
			v.clear();
			scanf("%s",s);
			for(p=s;*p;p+=2)v.push_back(A(*p)*16+A(p[1]));
			for(i=v.size();i>1;)
			{
				if(P[i]&&v.size()%i==0 && F(v,i));
				else --i;
			}
			r.push_back(v);
		}
		for(d=1,i=0;i<r.size();++i)
		{
			d=LCM(d,r[i].size());
			if(d>1024)goto E;
		}
		v.clear();
		v.resize(d,0);
		for(i=0;i<r.size();++i)
			for(j=0;j<r[i].size();++j)
				v[d/r[i].size()*j]|=r[i][j];
		for(i=0;i<v.size();++i)printf("%02X",v[i]);
		puts("");

		continue;
E:;
		puts("Too complex.");
	}
	return 0;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

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

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}

ll ncr(ll x){
    ll a = x*(x-1);
    ll b = 2;
    return a/b;
}



int main(){
    ll n;
    cin >> n;
    map<string,ll> s;
    rep(i,n){
        string a; 
        cin >> a;
        sort(a);
        s[a]++;
    } 

    ll ans=0;

    for(auto p:s){
        ans+=ncr(p.second);
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    vector<int> v(3);
    rep(i, 3) cin >> v[i];
    sort(v.begin(), v.end());
    cout << v[0] + v[1] << endl;
}


Measured memory_bytes: 256
k,a,b=gets.chomp.split.map(&:to_i)
ans=0
if b-a>2
  if k>=a-1
    ans = a
    k -= a-1
    ans += (b-a) * (k/2)
    ans += 1 if k.odd?
  else
    ans = 1+k
  end
else
  ans = 1+k
end
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s;
    cin >> s;
    int n = sz(s);
    int a = 0, b = 0;
    rep(i, n) {
        if (s[i] == '0') a++;
        else b++;
    }
    cout << min(a, b) * 2 << endl;
}

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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif


void solve(ll N, ll M, vector<ll> A) {
    map<ll, ll> c;
    c[0] = 1;
    ll sum = 0, ans = 0;
    for (int i = 0; i < N; i++) {
        sum += A[i];
        sum %= M;
        ans += c[sum % M];
        c[sum]++;
    }
    cout << ans << endl;
}


void main_(istream &cin) {
    ll N;
    ll M;
    cin >> N;
    vector<ll> A(N - 1 + 1);
    cin >> M;
    for (int i = 0; i <= N - 1; i++) {
        cin >> A[i];
    }
    solve(N, M, A);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





Measured memory_bytes: 5760
n,k=int(input()),1
while k*2<=n:k*=2
p=print
if n==k:p("No");exit()
p("Yes",v:=n+1,3)
for i in range(2,n,2):p(1,i,i,i+1,1,v+i,v+i,n+i)
if~n&1:p(n,n+k+1,n+n,n^k)

Measured memory_bytes: 9200
from sys import exit
n=int(input())
h=list(map(int,input().split()))
for i in range(n-1,0,-1):
  if h[i-1] > h[i]:
    h[i-1] -= 1
  if h[i-1] > h[i]:
    print("No")
    exit(0)
print("Yes")

Measured memory_bytes: 20804
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  a.push_back(-1);
  int m;
  cin >> m;
  vector<int> b(m);
  for (int i = 0; i < m; i++){
    cin >> b[i];
  }
  b.push_back(-1);
  for (int i = 0; i <= min(n, m); i++){
    if (a[i] > b[i]){
      cout << 0 << endl;
      break;
    }
    if (a[i] < b[i]){
      cout << 1 << endl;
      break;
    }
    if (i == min(n, m) && a[i] == b[i]){
      cout << 0 << endl;
    }
  }
}


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

int main(){
    int n;cin>>n;
    vector<int> h(n);
    rep(i,n)cin>>h[i];
    int res = 0;
    int l = 0;
    for(int r = 0; r <n-1;r++){
        if(h[r]>=h[r+1]){
            l++;
        }else{
            l=0;
        }
        res = max(res,l); 
    }
    cout << res <<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N];
int main(){
	int n,k;
	cin>>n>>k;
	int cnt=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]>=k)
			cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 640
S = input()
ans = 0
A = 0
BC = 0
prv = 0
if S[0] == 'A':
    A += 1
    prv = 'A'
else:
    prv = S[0]
for i in S[1:]:
    if prv == 'A':
        if i == 'A':
            A += 1
        elif i == 'B':
            prv = 'B'
        else:
            ans += A*BC
            A = 0
            BC = 0
            prv = 'C'
    elif prv == 'B':
        if i == 'A':
            ans += A*BC
            A = 1
            BC = 0
            prv = 'A'
        elif i == 'B':
            ans += A*BC
            A = 0
            BC = 0
        else:
            BC += 1
            prv = 'C'
    else:
        if i == 'A':
            ans += A*BC
            A += 1
            BC = 0
            prv = 'A'
        elif i == 'B':
            prv = 'B'
        else:
            ans += A*BC
            A = 0
            BC = 0
ans += A*BC
print(ans)

Measured memory_bytes: 3628
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args){
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		String s;
		int one;
		int five;
		int ten;
		int oturi;
		int p;
		int q;
		try{
			while((s=reader.readLine()) != null){
				String[] t=s.split(" ");
				int x=Integer.parseInt(t[0]);
				int y=Integer.parseInt(t[1]);
				if(x==0 && y==0){
					break;
				}
				oturi=y-x;
				if(oturi/1000 ==0){
					if(oturi/500 ==0){
						one=oturi/100;
						five=0;
						ten=0;
					}else{
						five=oturi/500;
						q=oturi-five*500;
						one=q/100;
						ten=0;
					}
				}else{
					ten=oturi/1000;
					p=oturi-ten*1000;
					five=p/500;
					q=p-five*500;
					one=q/100;
				}
				System.out.print(one+" "+five+" "+ten);
				System.out.println("");
			}
		}catch(IOException e){
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 24964
#include<stdio.h>
int main(void){
   int a,b,x,y,z,work,c;

   x=y=z=0;
   while(scanf("%d,%d",&a,&b)!=EOF){
      x+=a*b;
      y+=b;
      z++;
   }
   c=10*y/z;
   work=c;
   c/=10;
   work%=10;
   if(work>4)c++;
   printf("%d\n%d\n",x,c);



   return 0;
}

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

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

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define FOR_EX(i, a, b) for (int i = a; i < b; i++)
#define FOR_IN(i, a, b) for (int i = a; i <= b; i++)

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

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    int n;
    cin >> n;
    long long tot = 0;
    FOR_EX(i, 0, n) {
        int temp;
        cin >> temp;
        tot += temp;
    }
    cout << tot - n << endl;
}


Measured memory_bytes: 256