akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
 int o,e,total;   
 int sum1=0;
 int sum2=0; 
 scanf("%d %d",&e,&o);
 
  for(int i=1;i<e;i++){
   sum1=sum1+i;
  }
  for(int i=1;i<o;i++){
   sum2=sum2+i;
  }
 
 total = sum1 + sum2;
 printf("%d",total);
 return 0;
}

Measured memory_bytes: 2096
package main

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

func max(vals ...int) (max int) {
	max = 0
	for i := 0; i < len(vals); i++ {
		max = int(math.Max(float64(max), float64(vals[i])))
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var N int
	scanner.Scan()
	N, _ = strconv.Atoi(scanner.Text())
	var A [][]int = make([][]int, 2)
	for i := 0; i < 2; i++ {
		A[i] = make([]int, N)
	}
	for j := 0; j < 2; j++ {
		for i := 0; i < N; i++ {
			scanner.Scan()
			A[j][i], _ = strconv.Atoi(scanner.Text())
		}
	}

	for i := 1; i < N; i++ {
		A[0][i] += A[0][i-1]
		A[1][N-i-1] += A[1][N-i]
	}
	var B []int = make([]int, N)
	for i := 0; i < N; i++ {
		B[i] = A[0][i] + A[1][i]
	}
	fmt.Println(max(B...))
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
 
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
 
using namespace std;
 
typedef long long ll;
 
bool check(int a, int b){
    int x = a+b;
    int y = b-a;
 
    if(x%2 || y%2) return false;
    if(x < 0 || y < 0) return false;
 
    //cout << x/2 << ' ' << y/2 << endl;
 
    return true;
}
 
int main(){
    string a;
    cin >> a;
    int ans = 0;
    FOR(i, 0, a.size()){
        if(a[i] == '0') continue;
        ans += check(atoi(a.substr(0, i).c_str()), atoi(a.substr(i).c_str()));
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 1200
from collections import Counter
s=[i for i in input()]
t=[i for i in input()]
S=Counter(s)
T=Counter(t)
#print(S)辞書形式で返ってくるが、欲しいのはvalues、値
#print(T)
if sorted(S.values())==sorted(T.values()):
    #print(sorted(S.values()),sorted(T.values()))
    print("Yes")
else:print("No")

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

#define MAX_V 105

#define MAX_N 100
#define MAX_M 100

int main() {
    ll ans = 0;
    int n;
    cin >> n;

    REP(i, n+1) {
        if(i % 3 == 0 || i % 5 == 0) {

        } else {
            ans += i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define   ll    long long int
#define   sz    1000100
#define   pb    push_back
#define   py    printf("Yes\n")
#define   pn    printf("No\n")
#define   sc(a) scanf("%lld",&a)
const  double pi=acos(-1);

using namespace std;


int main()
{

     ll n,a,b,c,d,p,i;

     string s;

     c=0;
     a=0;

     cin>>n;
     cin>>s;
     if(n==1)
     {
         cout<<1<<endl;
         return 0;
     }

     for(i=1;i<n;i++)
     {
         if(s[i]==s[i-1])c++;
         else
         {
             c=1;
             a++;
         }
     }
    // cout<<c<<endl;

     if(c>0)a++;

     cout<<a<<endl;



    return 0;
}


Measured memory_bytes: 512
import java.util.*;

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

        int N = sc.nextInt();
        String str = sc.next();
        int ans = 0;
        char[] c = new char[N];
        String s = "ABC";
        char a = s.charAt(0);
        char b = s.charAt(1);
        char d = s.charAt(2);

        for(int i=0; i<=N-3; i++){
            c[i] = str.charAt(i);
            if(a==(c[i])){
                c[i+1] = str.charAt(i+1);
                if(b==(c[i+1])){
                    c[i+2] = str.charAt(i+2);
                    if(d==(c[i+2])){
                        ans += 1;
                    }
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
    Node *cur = nil->next;
    while (cur != nil && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList() {
    Node *cur = nil->next;
    int isf = 0;
    while (1) {
        if (cur == nil) {
            break;
        }
        if (isf++ > 0) {
            printf(" ");
        }
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t) {
    if (t == nil) {
        return;
    }
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
}

void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main() {
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++) {
        scanf("%s%d", com, &key);
        if (com[0] == 'i') {
            insert(key);
            np++;
            size++;
        } else if (com[0] == 'd') {
            if (strlen(com) > 6) {
                if (com[6] == 'F') {
                    deleteFirst();
                } else if (com[6] == 'L') {
                    deleteLast();
                }
            } else {
                deleteKey(key);
                nd++;
            }
            size--;
        }
    }
    
    printList();
    
    return 0;
}


Measured memory_bytes: 33836
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    int ans=0;
    rep(is,1<<h)rep(js,1<<w){
        int cnt=0;
        rep(i,h)rep(j,w){
            if(is>>i&1) continue;
            if(js>>j&1) continue;
            if(s[i][j] == '#') ++cnt;
        }
        if(cnt == k) ++ans;
    }
    cout << ans << "\n";
    return 0;
}   

Measured memory_bytes: 3656
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n").map(Number);
Arr.forEach(function(v){
   var arr=[0,v];
   for(var i=2;i<=10;i++){
         arr[i]=(i%2==0)?arr[i-1]*2 : arr[i-1]/3;
   }
   var sum=arr.reduce(function(a,b){return a+b;});
   console.log(sum.toFixed(8));
});

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

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

    int resultCount = 0;

    int minItem = n + 1;

    for (int i = 0; i < n; ++i)
    {
        int input;
        cin >> input;

        if (minItem > input)
        {
            resultCount += 1;

            minItem = input;
        }
    }

    cout << resultCount << endl;
}

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

using namespace std;

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int num;
  string str;
  cin >> num >> str;
  if (str.length() > num){
    for (int i = 0; i < num; i++)
      cout << str[i];
    cout << "...";
  }
  else
    cout << str;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define oo 2000000000
#define inf 1000000000000000000
#define P1 31
#define P2 37
#define M  1000000007
#define M2 1000000009
#define pii pair<ll,ll>
typedef long long ll;
using namespace std;
const int N = 355001;
const int SQRTN = 320;
const int LOGN = 20;
const long double PI = acos(-1);
const long double TAU = 2*PI;

int ans = 0, n , a[N];

int calc(int idx){
    ans++;
    if(idx==n-1)return n;
    bool b1,b2;
    b1=b2=0;
    for(int i = idx+1 ; i < n ; i++){
        if(a[i]>a[i-1])b1=1;
        if(a[i]<a[i-1])b2=1;
        if(b1&&b2)return i;
    }
    return n;
}

signed main(){
    cin >> n ;
    for(int i = 0 ; i < n ;i++)scanf("%d",a+i);
    int i = 0;
    while(i!=n){
        i=calc(i);
    }
    cout << ans << endl;
}

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

int popcount(int x) {
	return __builtin_popcount(x);
}

int f(int x) {
	if (x == 0) return 0;
	return f(x % popcount(x)) + 1;
}

int main() {
  int n;
	string s;
	cin >> n >> s;
	vector<int> x(n);
	rep(i, n) x[i] = s[i] - '0';
	int pc = 0;
	rep(i, n) pc += x[i];
	vector<int> ans(n);
	rep(b, 2) {
		int npc = pc;
		if (b == 0) npc++;
		else npc--;
		if (npc <= 0) continue;
		int r0 = 0;
		rep(i, n) {
			r0 = (r0 * 2) % npc;
			r0 += x[i];
		}
		int k = 1;
		for (int i = n - 1; i >= 0; i--) {
			if (x[i] == b) {
				int r;
				if (b == 0) r = (r0 + k) % npc;
				else r = (r0 - k + npc) % npc;
				ans[i] = f(r) + 1;
			}
			k = (k * 2) % npc; 
		}
	}
	rep(i, n) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 5124
n,k = map(int,input().split())
p_list = list(map(int,input().split()))
ans = 0
save = 0
sum = 0
ans_o = 0
ans_check = 0
for j in range(k):
    ans_check += p_list[0 + j]
    ans_o += p_list[0 + j]
for i in range(1,n-k+1):
    ans = ans_o-p_list[i-1]+p_list[i+k-1]
#    print(ans)
    if ans > ans_check:
        save = i
        ans_check = ans
    ans_o = ans
    #print(save)

for i in range(save,save+k):
    sum += p_list[i]*0.5 + 0.5
print(sum)

Measured memory_bytes: 71792
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

__MAX_N = 300000
fac = [0] * __MAX_N
finv = [0] * __MAX_N
inv = [0] * __MAX_N

def combinit(m):
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1

    for i in range(2, __MAX_N):
        fac[i] = fac[i - 1] * i % m
        inv[i] = m - inv[m % i] * (m // i) % m
        finv[i] = finv[i - 1] * inv[i] % m

def modpow(n, p, m):
	if p == 0:
		return 1
	if p % 2 == 0:
		t = modpow(n, p // 2, m)
		return t * t % m
	return n * modpow(n, p - 1, m) % m

def comb(n, k, m):
    if n == 0 and k == 0:
        return 1
    if n < k or n < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % m) % m

def comb2(n, k, m):
    if n == k or k == 0:
        return 1
    if n < k:
        return 0

    res = 1
    for i in range(k):
        res *= (n - i)
        res %= m
        res *= modpow(i + 1, m - 2, m)
        res %= mod
    
    return res

n, a, b = na()
ans = modpow(2, n, mod) - 1
ans -= comb2(n, a, mod)
ans -= comb2(n, b, mod)
ans %= mod
print(ans)

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

int main() {
	string S;
	cin >> S;
	int tf = 0;
	if (S[0] == '0'&&S[1] != '0') tf++;
	else if (S[0] == '1' && (S[1] == '0' || S[1] == '1' || S[1] == '2')) tf++;
	if (S[2] == '0'&&S[3] != '0') tf += 2;
	else if (S[2] == '1' && (S[3] == '0' || S[3] == '1' || S[3] == '2')) tf += 2;
	if (tf == 0) cout << "NA" << endl;
	else if (tf == 1)cout << "MMYY" << endl;
	else if (tf == 2)cout << "YYMM" << endl;
	else if (tf == 3)cout << "AMBIGUOUS" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100020
#define zyy 1000000007
#define ll long long
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
	while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return f?x:-x;
}
int a[N];
int fast_pow(int x) {
	int ans = 1;
	for (int i = 1; i <= x; i++)
		ans = (ans << 1) % zyy;
	return ans;
}
int main(int argc, char const *argv[]) {
	int n = read();
	for (int i = 1; i <= n; i++)
		a[i] = read();
	sort(a + 1, a + n + 1);
	if (n & 1) {
		for (int i = 1; i <= n; i++)
			if (a[i] != ((i & 1) ? i - 1 : i))
				return puts("0")&0;
		printf("%d\n", fast_pow(n >> 1));
	} else {
		for (int i = 1; i <= n; i++)
			if (a[i] != ((i & 1) ? i : i - 1))
				return puts("0")&0;
		printf("%d\n", fast_pow(n >> 1));
	}
	return 0;
}

Measured memory_bytes: 640
use std::io::Read;
 
fn main() {
    let mut buf = String::new();
 
    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();
 
    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();
    let u: usize = iter.next().unwrap().parse().unwrap();
    let _q: usize = iter.next().unwrap().parse().unwrap();
 
    let mut lrt: Vec<String> = (0..u)
        .map(|_| {
                String::from(iter.next().unwrap())
        }).collect();
  
      lrt.sort();
      
      let result = lrt.concat();

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

Measured memory_bytes: 2120
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    double ans = 0.0;
    double rada = (double)(h+m/60)*M_PI/6;
    double radb = (double)m*M_PI/30;
    // double sa = max(rada,radb)-min(rada,radb);
    // if(sa > M_PI)sa = 2*M_PI - sa;
    double c = cos(rada)*cos(radb) + sin(rada)*sin(radb);
    ans = sqrt(a*a+b*b-2*a*b*c);
//  printf("%.12f\n",rada);
//  printf("%.12f\n",radb);
//  printf("%.12f\n",sa);



    // cout << ans << endl;
 printf("%.12f\n",ans);


    return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int arr[110];
  fill(arr, arr + 110, 0);
  arr[a]++;
  arr[b]--;
  arr[c]++;
  arr[d]--;
  for (int i = 1; i < 110; i++) {
    arr[i] += arr[i-1];
  }

  int ans = 0;
  for (int i = 0; i < 110; i++) {
    if (arr[i] == 2) ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n,m=map(int, input().split())
list1=[list(map(int,input().split())) for i in range(m)]

ans=['x']*n
non=0
for i in range(m):
    if ans[list1[i][0]-1]!='x':
        if int(ans[list1[i][0]-1])==list1[i][1]:
            continue
        else:
            non=-1
            break
    else:
        ans[list1[i][0]-1]=str(list1[i][1])

if non==-1:
    print(-1)
else:
    if ans[0]=='0' and n!=1:
        print(-1)
    else:
        if 'x' in ans:
            if ans[0]=='x' and n!=1:
                ans[0]='1'
            for i in range(n):
                if ans[i]=='x':
                    ans[i]='0'
        print(''.join(ans))

Measured memory_bytes: 38384
#include<iostream>
using namespace std;
int main()
{
	int a, b, sum;
	while (1){
		sum = 0;
		cin >> a >> b;
		if (a == 0){ 
			break;
		}
		for (int i = 1; i <= a; i++){
			for (int j = i + 1; j <= a; j++){
				for (int k = j + 1; k <= a; k++){
					if (i + j + k == b){
						sum += 1;
					}
				}
			}
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3072
#include <stdio.h>

int main()
{
    int a;
    scanf("%d", &a);
    int h, m, s;
    h = a / 3600;
    m = (a - h * 3600) / 60;
    s = a - (h * 3600 + m * 60);
    printf("%d:%d:%d\n", h, m, s);
}


Measured memory_bytes: 2064
n, m = gets.split.map(&:to_i)
heights = [0] + gets.split.map(&:to_i)

graph = Array.new(n + 1) {[]}
m.times do
  a, b = gets.split.map(&:to_i)
  graph[a] << b
  graph[b] << a
end

visited = Array.new(n + 1)
count = 0

dfs = ->(node) {
  return if visited[node]
  visited[node] = true
  highest = graph[node].map {|nxt| heights[nxt]}.max
  count += 1 if !highest || heights[node] > highest
  graph[node].each {|child| dfs.(child)}
}

(1..n).each do |node|
  next if visited[node]
  dfs.(node)
end

puts count

Measured memory_bytes: 57632
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;

/*
ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}
ll pw(int x, int n) {
	ll y = 1;
	ll p = x;
	while (n != 0) {
		if (n % 2) {
			y = y*p%mod;
			n = n - 1;
		}
		else {
			p = p*p%mod;
			n = n / 2;
		}
	}
	return y;
}

ll modinv(ll x) {
	return pw(x, mod - 2);
}*/


string s;

int main() {
	cin >> s;
	s += 'X';
	lp(s.size() - 2) {
		if (s[i] == s[i + 1]) {
			cout << i + 1 << sp << i + 2 << endl;
			return 0;
		}
		if (s[i] == s[i + 2]) {
			cout << i + 1 << sp << i + 3 << endl;
			return 0;
		}
	}
	cout << -1 << sp << -1 << endl;
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;


int main(){
  ll n, m;
  cin >> n >> m;
  vll a(m);
  vin(a);
  vrep(i, a) n -= i;
  cout << (n >= 0 ? n : -1) << endl; 
}


Measured memory_bytes: 3676
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
long int a[900000][2];
int l(long int x1,long int x2,long int y1,long int y2){
  return x1==y1?x2<y2:x1<y1;
}
void q(long int s,long int t){
  long int b[2];
  long int i=s,j=t;
  b[0]=a[s][0];b[1]=a[s][1];
  if(s<t){
    while(1){
      while(l(a[i][0],a[i][1],b[0],b[1]))i++;
      while(l(b[0],b[1],a[j][0],a[j][1]))j--;
      if(i>=j)break;
      a[i][0]^=a[j][0]^=a[i][0]^=a[j][0];
      a[i][1]^=a[j][1]^=a[i][1]^=a[j][1];
      i++;j--;
    }
    q(s,i-1);q(j+1,t);
  }
}
int main(){
  long int h,w,n,n2=0,i,j,x,y,k,x2,y2;
  long int b[2],z[10];
  for(i=0;i<10;i++)z[i]=0;
  scanf("%ld %ld %ld",&h,&w,&n);
  for(i=0;i<n;i++){
    scanf("%ld %ld",&y,&x);
    for(j=0;j<3;j++)for(k=0;k<3;k++){
      x2=x-k;y2=y-j;
      if(x2>0&&x2<w-1&&y2>0&&y2<h-1){a[n2][0]=x2;a[n2][1]=y2;n2++;}
    }
  }
  q(0,n2-1);
  b[0]=a[0][0];b[1]=a[0][1];
  k=0;
  for(i=1;i<n2;i++){
    k++;
    if(a[i-1][0]!=a[i][0]||a[i-1][1]!=a[i][1]){z[k]++;k=0;}
  }
  if(n2)z[k+1]++;
  z[0]=(h-2)*(w-2);
  for(i=1;i<10;i++)z[0]-=z[i];
  for(i=0;i<10;i++)printf("%ld\n",z[i]);

}


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

using namespace std;

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int l = a + b;
  int r = c + d;

  if (l > r) {
    cout << "Left" << endl;
  } else if (l < r) {
    cout << "Right" << endl;
  } else {
    cout << "Balanced";
  }
}


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

using namespace std;
vector<int>v;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		v.push_back(x);
	}
	int ans=0;
	int p=1;
	for(int i=0;i<n;i++){
		ans+=v[i]*p;
		p*=-1;	
	}
	cout<<ans<<" ";
	for(int i=0;i<n-1;i++){
		ans=2*(v[i]-ans/2);
		cout<<ans<<" ";
	}
	return 0;
}

Measured memory_bytes: 1784
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;

#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832795

#define fill(x, v)  fillchar(x, v, sizeof(x))
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector< pii >   vpii;

#define MAXN 21
#define MOD (int)(1e9 + 7)
int f[MAXN][1 << MAXN];
int a[MAXN][MAXN];
int n, M;
vi  g[MAXN + 1];

int main() {
    scanf("%i", &n);
    M = 1 << n;
    for(int m = 0; m < M; ++m) {
        int cnt = 0;
        for(int i = 0; i < n; ++i)
            if ((m >> i) & 1) cnt++;
        g[cnt].pb(m);
    }

    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j) scanf("%i", &a[i][j]);

    for(int i = 0; i < n; ++i) 
        if (a[0][i]) f[0][1 << i] = 1;

    for(int i = 1; i < n; ++i)
        for(int m : g[i + 1])
            for(int j = 0; j < n; ++j)
                if (a[i][j] && ((m >> j) & 1)) f[i][m] = (f[i][m] + f[i - 1][m ^ (1 << j)]) % MOD;

    printf("%i\n", f[n - 1][M - 1]);
    return 0;
}

Measured memory_bytes: 169404
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
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;}

P f(int x) {
    int a = x%10;
    int b = 0;
    while (x) {
        b = x;
        x /= 10;
    }
    return P(a,b);
}

int main() {
	int N;
	cin >> N;
    map<P,int> freq;
    rep(i,N) {
        P p = f(i+1);
        freq[p]++;
    }
    ll ans = 0;
    rep(i,N) {
        P p = f(i+1);
        P q(p.second, p.first);
        ans += freq[q];
    }
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd); FUNC(printde);
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, d;
    cin >> h >> w >> d;
    vector<vector<char>> cs(h, vector<char> (w, 'x'));
    char colors[] = {'R', 'Y', 'G', 'B'};
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int y = i - j + w, x = i + j;
            cout << colors[y / d % 2 * 2 + x / d % 2];
        }
        cout << '\n';
    }
}


Measured memory_bytes: 768
#include <stdio.h>

int main(){
    int a,b,c,d,e, x;
    scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
    if(a == 0)
        x = 1;
    if(b == 0)
        x = 2;
    if(c == 0)
        x = 3;
    if(d == 0)
        x = 4;
    if(e == 0)
        x = 5;
    printf("%d", x);
    

    return 0;
}

Measured memory_bytes: 1728
#include<stdio.h>

char p[9][4];
int map[9];
int use[9];
int dic[9];
int ans;

int check(char a, char b){
  if(a == 'w' && b == 'W')return 1;
  else if(a == 'W' && b == 'w')return 1;
  else if(a == 'b' && b == 'B')return 1;
  else if(a == 'B' && b == 'b')return 1;
  else if(a == 'g' && b == 'G')return 1;
  else if(a == 'G' && b == 'g')return 1;
  else if(a == 'r' && b == 'R')return 1;
  else if(a == 'R' && b == 'r')return 1;
  else return 0;
}

char mapdic(int num, int purse){
  return p[map[num]][(4+purse-dic[num])%4];
}

void backtrack(int num){
  int i,j;
  int f1,f2;

  if(num == 9)ans++;
  else {
    for(i=0;i<9;i++){
      if(!use[i]){
	use[i] = 1;
	map[num] = i;
	for(j=0;j<4;j++){
	  dic[num] = j;
	  f2 = 1;
	  if(num >= 3){
	    f1 = check(mapdic(num,0),mapdic(num-3,2));
	    if(!f1)f2 = 0;
	  }
	  if(num % 3 != 0){
	    f1 = check(mapdic(num,3),mapdic(num-1,1));
	    if(!f1)f2 = 0;
	  }
	  if(f2)backtrack(num+1);
	}
	use[i] = 0;
      }
    }
  }	
}

int main(void){
  int i,k,l;
  int n;

  scanf("%d",&n);

  for(k=0;k<n;k++){
    for(l=0;l<9;l++){
      for(i=0;i<4;i++){
	scanf(" %c ",&p[l][i]);
      }
    }

    for(i=0;i<9;i++)use[i] = 0;
    ans = 0;

    backtrack(0);
    printf("%d\n",ans);

  }
  return 0;
}

Measured memory_bytes: 412
from sys import stdin

lines = stdin.readlines()
counter = []
each_line = []
for i, line in enumerate(lines):
    if i == 0:
        counter = [int(x) for x in (line.rstrip().split())]
    else:
        each_line = [str(x) for x in (line.rstrip().split())]

str_n = str(counter[0])
digit = len(str_n)

for num in range(counter[0], 100000, 1):
    num_str = str(num)
    for char in num_str:
        for dame in each_line:
            if char == dame:
                break
        else:
            continue
        break
    else:
        print(num)
        break

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

using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	if (a >= 13){
		cout << b << endl;
	}else if (a >= 6 && a < 13){
		cout << b * 1.0 / 2 << endl;
	} else{
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a+b==15)
        cout<<'+'<<endl;
    else if(a*b==15)
        cout<<'*'<<endl;
    else
        cout<<'x'<<endl;
}

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

const ll INF = 1LL << 60;

class UnionFind {
    public:
        vector<ll> Parent;
        UnionFind(ll N) {
            Parent = vector<ll>(N, -1);
        }

        ll root(ll A) {
            if (Parent[A] < 0) return A;
            return Parent[A] = root(Parent[A]);
        }

        ll size(ll A) {
            return -Parent[root(A)];
        }

        bool unite(ll A, ll B) {
            A = root(A);
            B = root(B);

            if (A == B) {
                return false;
            }

            if (size(A) < size(B)) swap(A, B);

            Parent[A] += Parent[B];
            Parent[B] = A;

            return true;
        }
};

ll N, M;
int main() {
    cin >> N >> M;
    vector<P> v;
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        v.push_back(P(a, b));
    }

    ll ans = 0;
    rep(i, M) {
        UnionFind uf2 = UnionFind(N);
        rep(j, M) {
            if (i == j) continue;
            uf2.unite(v[j].first, v[j].second);
        }
        if (uf2.size(v[i].first) == N) continue;
        if (uf2.size(v[i].second) == N) continue;

        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let numbers = input_number();
    let n = numbers[0];
    for index in 1..n + 1 {
        if index % 3 == 0 || index % 10 == 3 {
            print!(" ");
            print!("{}", index);
        } else {
            let mut i = index;
            loop {
                i = i / 10;
                if i < 3 { break }
                else if i % 10 == 3 {
                    print!(" ");
                    print!("{}", index);
                    break
                }
            }
            
        }
    }
    println!("");
}

#[allow(dead_code)]
fn input_number() -> Vec<i64> {
    let mut input = String::new();

    io::stdin().read_line(&mut input)
        .expect("Failed to read line");

    let vec: Vec<i64> = input
        .split_whitespace()
        .map(|x| x.parse().unwrap_or(0))
        .collect();
    vec
}



Measured memory_bytes: 5024
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>

using namespace std;

struct Frac {
    int64_t num;
    int den;

    bool operator<(const Frac& that) const {
        return num * that.den < that.num * den;
    }
};

struct Func {
    int a; int64_t b;

    int64_t operator()(int x) {
        return 1LL * a * x + b;
    }

    Frac time_to_skip(const Func& that) const {
        return Frac{b - that.b, that.a - a};
    }
};

int main() {
    ios::sync_with_stdio(false);

    int N; int64_t C; cin >> N >> C;

    vector<int> H(N);
    for (int i = 0; i < N; ++i)
        cin >> H[i];

    vector<int64_t> dp(N, 0);
    deque<Func> functions;
    for (int i = 0; i < N; ++i) {
        while (functions.size() > 1 && functions[0](H[i]) > functions[1](H[i]))
            functions.pop_front();

        if (i > 0)
            dp[i] = functions[0](H[i]) + 1LL * H[i] * H[i] + C;

        Func now{-2 * H[i], dp[i] + 1LL * H[i] * H[i]};
        while (functions.size() > 1) {
            auto x = functions[functions.size() - 2];
            auto y = functions.back();

            if (now.time_to_skip(y) < y.time_to_skip(x))
                functions.pop_back();
            else
                break;
        }

        functions.push_back(now);
    }

    cout << dp.back() << "\n";
}


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

typedef long long int ll;

ll abc[100005][4];
ll dp[100005][4];
ll maximum[100005];

bool isPrime(ll n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

int main()
{
    ios::sync_with_stdio(false);

    ll i,j,k,l,m,n;

    cin >> n;

    for(i=1;i<=n;i++)
    {
        cin >> abc[i][1];
        cin >> abc[i][2];
        cin >> abc[i][3];
    }

    dp[1][1] = abc[1][1];
    dp[1][2] = abc[1][2];
    dp[1][3] = abc[1][3];

    for(i=2;i<=n;i++)
    {
        dp[i][1] = max(dp[i-1][2]+abc[i][1],dp[i-1][3]+abc[i][1]);
        dp[i][2] = max(dp[i-1][1]+abc[i][2],dp[i-1][3]+abc[i][2]);
        dp[i][3] = max(dp[i-1][1]+abc[i][3],dp[i-1][2]+abc[i][3]);
    }

    cout << max(dp[n][1],max(dp[n][2],dp[n][3])) << '\n';


    
    
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main(){
	int i,j,a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int ans=0;
	if ((a>=b)&&(a>=c)) ans=10*a+b+c;
		else if ((b>=a)&&(b>=c)) ans=10*b+c+a;
			else ans=10*c+a+b;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include "stdlib.h"
#include "stdio.h"

typedef struct {
	int math;
	int information;
	int science;
	int English;
}StudentScore;

int main(void)
{
	int sum1 = 0, sum2 = 0;
	StudentScore StudentScore1;
	StudentScore StudentScore2;
	scanf("%d", &StudentScore1.math);
	scanf("%d", &StudentScore1.information);
	scanf("%d", &StudentScore1.science);
	scanf("%d", &StudentScore1.English);
	sum1 += (StudentScore1.math + StudentScore1.information + StudentScore1.science + StudentScore1.English);
	scanf("%d", &StudentScore2.math);
	scanf("%d", &StudentScore2.information);
	scanf("%d", &StudentScore2.science);
	scanf("%d", &StudentScore2.English);
	sum2 += (StudentScore2.math + StudentScore2.information + StudentScore2.science + StudentScore2.English);
	if (sum1 > sum2) { printf("%d\n",sum1);}
	else { printf("%d\n",sum2); }
}

Measured memory_bytes: 1804
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int n,i,k=0;
long long int j=0,ans=0;
cin>>n;
vector<int>a(n),b(n),c(n);
for(i=0;i<n;i++){
cin>>a[i];
}
sort(a.begin(),a.end());
for(i=0;i<n;i++){
cin>>b[i];
}
sort(b.begin(),b.end());
for(i=0;i<n;i++){
cin>>c[i];
}
sort(c.begin(),c.end());
for(i=0;i<n;i++){
while(a[j]<b[i]&&j<n)j++;
while(c[k]<=b[i]&&k<n)k++;
ans+=j*(n-k);
}
cout<<ans<<endl;
return 0;

}

Measured memory_bytes: 1408
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


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

  vi add(n), sub(n);

  rep(i, n){
    int a;
    cin >> a;
    add[i] = a + i;
    sub[i] = i - a;
  }
  sort(add.begin(), add.end());
  sort(sub.begin(), sub.end());

  map<int, int> ad;
  map<int, int> sd;
  rep(i, n){
    ad[add[i]]++;
    sd[sub[i]]++;
  }

  ll ans = 0;
  for (const auto& [key, value] : ad){
    ans += (ll) ad[key] * sd[key];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 30224
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
		long Y = sc.nextLong();
		int ans = 1;
		long n = X;
		for (int i = 0; i < 1000; i++) {
			n *= 2;
			if (n <= Y) {
				ans++;
			} else {
				break;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22740
def bubble_sort(c, n)
  0.upto(n - 1) do |i|
    (n - 1).downto(i + 1) do |j|
      # ?????¶??????????????°?????????????????????????????????????????\???????????????????????????
      c[j], c[j - 1] = c[j - 1], c[j] if c[j][1] < c[j - 1][1]
    end
  end

  @bubble_sort_result = c.dup

  puts c.join(' ')
  puts 'Stable'
end

def selection_sort(c, n)
  0.upto(n - 1) do |i|
    minj = i
    i.upto(n - 1) do |j|
      minj = j if c[j][1] < c[minj][1]
    end

    c[i], c[minj] = c[minj], c[i]
  end

  puts c.join(' ')
  puts (c == @bubble_sort_result) ? 'Stable' : 'Not stable'
end

N = gets.to_i
C = gets.chomp.split.freeze

bubble_sort(C.dup, N)
selection_sort(C.dup, N)

Measured memory_bytes: 8784
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd
from itertools import accumulate

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N,M = map(int, sys.stdin.readline().split())
    l= [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
    s = sorted(l,key=lambda x:x[0])
    n=0
    for i in range(N):
        if M - s[i][1] > 0:
            M=M - s[i][1]
            n += s[i][0]*s[i][1]
        else:
            n += s[i][0]*M
            break
    print(n)

Measured memory_bytes: 31944
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    ld d = 0;
    for (int z=0;z<n;z++){
        ld temp;
        cin >> temp;
        d += ld(1)/ld(temp);
    }
    cout << setprecision(60) << ld(1)/ld(d) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
int p[100010];
int main()
{
	int ans=0,n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&p[i]);
	int len=0;
	for(int i=1;i<=n;i++)
	{
		if(p[i]==i) len++;
		else ans+=(len+1)/2,len=0;
	}
	ans+=(len+1)/2;
	printf("%d",ans);
}

Measured memory_bytes: 640
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_9_A: Complete Binary Tree

#include <cstdio>

static int parent(int i) { return i/2; }
static int left(int i) { return 2*i; }
static int right(int i) { return 2*i+1; }

int main()
{
  int h;
  std::scanf("%d", &h);
  int as[h+1]; // 1-origin
  for (auto i = 1; i < h+1; ++i) {
    std::scanf("%d", &as[i]);
  }

  for (auto i = 1; i < h+1; ++i) {
    std::printf("node %d: key = %d, ", i, as[i]);
    if (parent(i) >= 1) {
      std::printf("parent key = %d, ", as[parent(i)]);
    }
    if (left(i) <= h) {
      std::printf("left key = %d, ", as[left(i)]);
    }
    if (right(i) <= h) {
      std::printf("right key = %d, ", as[right(i)]);
    }
    std::printf("\n");
  }
}

// eof

Measured memory_bytes: 2672
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000
 
struct Card {
  char suit;
  int value;
};
 
struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];
 
void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for( i = 0; i < n1; i++ ) L[i] = A[left + i];
  for( i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for ( k = left; k < right; k++ ) {
    if ( L[i].value <= R[j].value ) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}
 
void mergeSort(struct Card A[], int n, int left, int right){
  int mid;
  if ( left + 1 < right ) {
    mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}
 
int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ ) {
    if ( A[j].value <= x.value ) {
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
   t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
   return i + 1;
}
 
void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if ( p < r) {
    q = partition(A, n, p, r);
    quickSort(A, n, p, q - 1);
    quickSort(A, n, q + 1, r);
  }
}
 
int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;
 
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++) {
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }
 
  mergeSort(A, n, 0, n);
  quickSort(B, n, 0, n - 1);
 
  for ( i = 0; i < n; i++) {
    if ( A[i].suit != B[i].suit ) stable = 0;
  }
 
  if ( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  for ( i = 0; i < n; i++ ) {
    printf("%c %d\n", B[i].suit, B[i].value);
  }
 
  return 0;
}



Measured memory_bytes: 3992
type 'a mutable_list = Nil | Cons of 'a * 'a mutable_list ref

(* 与えられたリストからn要素を選ぶ順列 *)
let perm n xs =
  let head = ref Nil in
  ignore (List.fold_left (fun tail x ->
    let tail' = ref Nil in
    tail := Cons (x, tail'); tail') head xs);
  let rec perm_aux ys n ptr acc =
    if n <= 0
    then ys :: acc
    else match !ptr with
         | Nil -> acc
         | (Cons (x, next)) as here ->
             let acc = perm_aux ys n next acc in
             ptr := !next; (* リストからconsセルhereを削除 *)
             (* consセルを削除したリストから，n-1要素を選ぶ *)
             let acc = perm_aux (x :: ys) (n - 1) head acc in
             ptr := here; (* consセルを戻す *)
             acc in
  perm_aux [] n head []

let () = Scanf.scanf "%d\n" @@ fun n ->
  let ps = Array.to_list @@ Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun p -> p in
  let qs = Array.to_list @@ Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun q -> q in
  let perms =
    List.mapi (fun i xs -> (i, List.rev xs)) @@
    perm n @@
    Array.to_list @@
    Array.init n succ in
  Printf.printf "%d\n" @@ abs @@
  fst (List.find (fun (_, xs) -> xs = ps) perms)
  - fst (List.find (fun (_, xs) -> xs = qs) perms)



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

char arr1[3001], arr2[3001];
int dp[3002][3002];

int recursive_say(int a, int b){
	if(dp[a][b]!=-1)return dp[a][b];
	if(!arr1[a]||!arr2[b])return 0;
	if(arr1[a]==arr2[b]){
		dp[a][b]=1+recursive_say(a+1, b+1);
	}else{
		dp[a][b]=max(recursive_say(a, b+1), recursive_say(a+1,b));
	}
	return dp[a][b];
}
int recursive_print(int a, int b){
	if(!arr1[a]||!arr2[b])return 0;
	if(arr1[a]==arr2[b]){
		cout<<arr1[a];
		recursive_print(a+1, b+1);
	}else{
		if(dp[a][b+1]<dp[a+1][b])recursive_print(a+1, b);
		else recursive_print(a, b+1);
	}
	return 0;
}

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	memset(dp, -1, 3002*3002*sizeof(int));
	cin>>arr1;
	cin>>arr2;
	recursive_say(0, 0);
	recursive_print(0, 0);
	return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  
  vector<int> L(m);
  vector<int> R(m);
  int under = 0;
  int top = 100000;
  for(int i = 0; i < m; i++) {
    cin >> L.at(i) >> R.at(i);
    if(under < L.at(i))
      under = L.at(i);
    if(top > R.at(i))
      top = R.at(i);
  }

  if(top - under >= 0)
    cout << top - under + 1 << endl;
  else
    cout << 0 << endl;
}


Measured memory_bytes: 1024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

pub fn keta_sum(mut n: u64) -> u64 {
    let mut sum = 0;
    let d = 10;
    while n != 0 {
        sum += n % d;
        n /= d;
    }
    sum
}

fn main() {
    input! {
        n: u64
    }
    println!("{}", if n % keta_sum(n) == 0 {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define frn(i,a,n) for(i=a;i<=n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
//#define map map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>
#define ma 500000
ll power(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return power(x*x,n/2);
    else                             //n is odd
        return x*power(x*x,(n-1)/2);
}
int highestPowerof2(int n)
{
   int p = (int)log2(n);
   return (int)pow(2, p);  
}
ll powermod(ll x, ll y, ll p)  
{  
    ll res = 1;
    x = x % p;
    if (x == 0) return 0;  
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}
 
int main()
{
   ll n,w=0,r=0;
cin>>n;
string s;
cin>>s;
for(ll i=0;i<n;i++) s[i]=='W'?w++:r++;
if(w==0) cout<<"0\n";
else if(w==n) cout<<"0\n";
else{
ll count=0;
for(ll i=n-w;i<n;i++) if(s[i]=='W') count++;
cout<<w-count<<"\n";
}
}


Measured memory_bytes: 3724
require 'pp'

def gets; ARGF.gets; end

class Solver

  def main
    a, b = gets.chomp.split.map(&:to_i)

    a = 14 if a == 1
    b = 14 if b == 1

    if a < b
      puts "Bob"
    elsif a == b
      puts "Draw"
    else
      puts "Alice"
    end
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2172
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>

int main(void){
  int n=0;
  int a;
  int s_n=0;

  std::cin>>n;
  a=n;

  while(a!=0){
   s_n+=(a%10);
   a/=10;
  }
  if(n%s_n==0)std::cout<<"Yes"<<std::endl;
  else std::cout<<"No"<<std::endl;

  return 0;
}

Measured memory_bytes: 256