akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL) x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
    }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x=y;
    y=y->parent;
  }
  return y;  
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);
  
  if(y->left != NIL){
    x = y->left;
  }
  else{
    x = y->right;
  }

  if(x != NIL){
    x->parent = y->parent;
  }

  if(y->parent == NIL){
    root = x;
  }
  else{
    if(y == y->parent->left){
      y->parent->left = x;
    }
    else{
      y->parent->right = x;
    }
  }

  if(y != z){
    z->key = y->key;
  }

  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y=x;
    if(z->key < x->key){
      x = x->left;
      }
    else{
      x = x-> right;
      }
    }
    z->parent = y;
    if(y == NIL){
    root = z;
    }
    else{
      if(z->key < y->key){
        y->left = z;
      }
      else{
        y->right = z;
      }
   }
}

void inorder(Node u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node u){
  if(u==NIL) return;
  printf( " %d", u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 20484
MOD = 10 ** 9 + 7
$n, k = gets.split.map(&:to_i)
nums = gets.split.map(&:to_i)
$minus_nums = []
$plus_nums = []
nums.each do |num|
  if num > 0
    $plus_nums << num
  elsif num < 0
    $minus_nums << num
  end
end

$minus_nums.sort!
$plus_nums.sort!
$plus_nums.reverse!

if $minus_nums.reject { |num| num == 0 }.size + $plus_nums.reject { |num| num == 0 }.size < k
  puts 0
  exit
end

$minus_nums_size = $minus_nums.size
$plus_nums_size = $plus_nums.size
$used_minus = -1
$used_plus = -1
def multiply
  minus = 0
  if $minus_nums_size > $used_minus + 2
    minus = $minus_nums[$used_minus + 1] * $minus_nums[$used_minus + 2]
  end
  plus = 0
  if $plus_nums_size > $used_plus + 2
    plus = $plus_nums[$used_plus + 1] * $plus_nums[$used_plus + 2]
  end
  if $minus_nums_size == $used_minus + 2 && $plus_nums_size == $used_plus + 2
    if $minus_nums.reject { |num| num == 0 }.size + $plus_nums.reject { |num| num == 0 }.size < $n
      puts 0
      exit
    else
      $ans *= $minus_nums[$used_minus + 1]
      $ans *= $plus_nums[$used_plus + 1]
      $used_minus += 1
      $used_plus += 1
      $ans %= MOD
      return
    end
  end
  if minus > plus
    $ans *= minus
    $ans %= MOD
    $used_minus += 2
  else
    $ans *= plus
    $ans %= MOD
    $used_plus += 2
  end
end

$ans = 1
if k.odd?
  if $plus_nums_size > 0
    $ans *= $plus_nums[0]
    $used_plus += 1
    k -= 1
  else
    if $minus_nums.reject { |num| num == 0 }.size + $plus_nums.reject { |num| num == 0 }.size < $n
      puts 0
      exit
    else
      puts $minus_nums.reverse[0...k].inject(1) { |res, num| res * num % MOD } % MOD
      exit
    end
  end
end

until k == 0
  multiply
  k -= 2
end

puts $ans % MOD


Measured memory_bytes: 37092
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()

int32_t main(){
	int n,k,s;
	cin>>n>>k>>s;
	for(int i=1;i<=k;i++){
		cout<<s<<" ";
	}
	for(int i=k+1;i<=n;i++){
		cout<<s-(s!=1)+(s==1)<<" ";
	}
}


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

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

    int ans = 0;
    for (int i = 1; i < N; i++)
    {
        if (S[i - 1] == S[i])
        {
            ans++;
        }
    }
    ans = min(N - 1, ans + 2 * K);
    cout << ans << endl;
}


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

void spreadCountToChildren(const vector<vector<int>>& all_connected_nodes, vector<int>& counter, const int node,
                           const int parent_node) {
  for (const auto& connected_node : all_connected_nodes[node]) {
    if (connected_node != parent_node) {
      counter[connected_node - 1] += counter[node - 1];
      spreadCountToChildren(all_connected_nodes, counter, connected_node, node);
    }
  }
}

vector<int> solve(const int N, const int Q, const vector<int>& a, const vector<int>& b, const vector<int>& p,
                  const vector<int>& x) {
  // Save connected nodes
  vector<vector<int>> all_connected_nodes(N + 1, vector<int>{});
  for (auto i = 0; i < N - 1; ++i) {
    all_connected_nodes[a[i]].push_back(b[i]);
    all_connected_nodes[b[i]].push_back(a[i]);
  }

  // Apply each count
  vector<int> counter(N, 0);
  for (auto j = 0; j < Q; ++j) {
    counter[p[j] - 1] += x[j];
  }

  // Spread count to children using DFS
  spreadCountToChildren(all_connected_nodes, counter, 1, -1);

  return counter;
}

int main() {
  // Input
  int N, Q;
  cin >> N >> Q;

  vector<int> a(N - 1), b(N - 1);
  for (auto i = 0; i < N - 1; ++i) {
    cin >> a[i] >> b[i];
  }

  vector<int> p(Q), x(Q);
  for (auto j = 0; j < Q; ++j) {
    cin >> p[j] >> x[j];
  }

  // Solve
  auto ans = solve(N, Q, a, b, p, x);

  // Answer
  for (const auto& c : ans) {
    cout << c << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 30720
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 105
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<ll> PQ;
typedef pair<double, double> doup;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef map<ll, ll> Map;

int main(void) {
    string s, t;
    cin >> s >> t;
    ll start[26], goal[26];
    memset(start, -1, sizeof(start));
    memset(goal, -1, sizeof(goal));
    for(ll i=0; i<s.size(); i++) {
        ll a=s[i]-'a';
        ll b=t[i]-'a';
        
        if(start[a]!=-1 || goal[b]!=-1) {
            if(start[a]!=b || goal[b]!=a) {
                pNo;
                return 0;
            }
        }else {
            start[a]=b;
            goal[b]=a;
        }
    }
    
    pYe;
}


Measured memory_bytes: 776
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

signed main(void) {
    int n,m;
    cin >> n >> m;
    vector<vi> g(n);
    vi in(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--,b--;
        g[a].push_back(b);
        in[b]++;
    }
    vi d(n, -INF);
    queue<int> q;
    rep(i,n)if(in[i] == 0){
        d[i] = 0;
        q.push(i);
    }
    while(q.size()){
        int now = q.front();
        q.pop();
        rep(i,g[now].size()){
            int to = g[now][i];
            d[to] = max(d[to], d[now]+1);
            in[to]--;
            if(in[to] == 0)q.push(to);
        }
    }
    int ans = 0;
    rep(i,n)ans = max(ans, d[i]);
    cout << ans << endl;
}


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

int main(){
	long N,M,tmp;
	cin >> N >> M;
	if(M>N){
		tmp=N;
		N=M;
		M=tmp;
	}
	if(M==1){
		if(N==1){
			cout << N <<endl;
		}
		else{
			cout << N-2 <<endl;
		}
	}
	else {
		cout << (N-2)*(M-2) <<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main () {
    char tahun[12];
    scanf("%s", tahun) ;

    tahun [0] = '2' ;
    tahun [1] = '0' ;
    tahun [2] = '1' ;
    tahun [3] = '8' ;
    printf("%s", tahun) ; 
    return 0 ; 
}


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

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

    vector<int> a(n);
    vector<int> a_tmp(n);

    int max_index = 0;
    int max = 0;
    int second_max = 0;
    int max_cnt = 0;
    for ( int i = 0; i < n; i++ ) {
        cin >> a[i];
        if ( a[i] > max ) {
            max_index = i;
            second_max = max;
            max = a[i];
            max_cnt = 0;
        }
        else if ( a[i] == max ) {
            max_cnt++;
        }
        else if ( a[i] > second_max ) {
            second_max = a[i];
        }
    }

//    cout << max_index << endl;
//    cout << max << endl;
//    cout << second_max << endl;

    for ( int i = 0; i < n; i++ ) {
        if ( max_cnt >= 1 ) {
            cout << max << endl;
        }
        else if ( i == max_index ) {
            cout << second_max << endl;
        }
        else {
            cout << max << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3200
N = int(input())
ans,a,b,ab = 0,0,0,0

for i in range(N):
    s = input()
    ans += s.count("AB")
    if s[-1] == "A" and s[0] == "B":
        ab += 1
    elif s[-1] == "A":
        a += 1
    elif s[0] == "B":
        b += 1

ans += ab + min(a,b)
if ab > 0 and a == b == 0:
    ans -= 1
print(ans)

Measured memory_bytes: 9240
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

int dice[]={1,2,3,4,5,6};
enum{UP,FRONT,RIGHT,LIGHT,BACK,DOWN};//ツ湘」ツ、ツ偲ィツ前ツ、ツ右ツ、ツ債カツ、ツ可慊、ツ可コ

void init(){
	for(int i=0;i<6;i++){
		dice[i]=i+1;
	}
}

void north(){
	int t=dice[UP];
	dice[UP]=dice[FRONT];
	dice[FRONT]=dice[DOWN];
	dice[DOWN]=dice[BACK];
	dice[BACK]=t;
}

void east(){
	int t=dice[UP];
	dice[UP]=dice[LIGHT];
	dice[LIGHT]=dice[DOWN];
	dice[DOWN]=dice[RIGHT];
	dice[RIGHT]=t;
}

void south(){
	int t=dice[UP];
	dice[UP]=dice[BACK];
	dice[BACK]=dice[DOWN];
	dice[DOWN]=dice[FRONT];
	dice[FRONT]=t;
}

void west(){
	int t=dice[UP];
	dice[UP]=dice[RIGHT];
	dice[RIGHT]=dice[DOWN];
	dice[DOWN]=dice[LIGHT];
	dice[LIGHT]=t;
}

void right(){
	int t=dice[FRONT];
	dice[FRONT]=dice[RIGHT];
	dice[RIGHT]=dice[BACK];
	dice[BACK]=dice[LIGHT];
	dice[LIGHT]=t;
}

void left(){
	int t=dice[FRONT];
	dice[FRONT]=dice[LIGHT];
	dice[LIGHT]=dice[BACK];
	dice[BACK]=dice[RIGHT];
	dice[RIGHT]=t;
}

int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		
		int sum=0;
		init();
		string ss;
		for(int i=0;i<n;i++){
			cin>>ss;
			if(ss=="North")north();
			if(ss=="East")east();
			if(ss=="South")south();
			if(ss=="West")west();
			if(ss=="Right")right();
			if(ss=="Left")left();
			//cout<<"UP "<<dice[UP]<<endl;
			sum+=dice[UP];
		}
		cout<<sum+1<<endl;
	}
}

Measured memory_bytes: 0
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    int N;
    scan(N);
    auto p = readln.split.to!(int[]);
    auto q = readln.split.to!(int[]);
    if (p > q) swap(p, q);

    int ans;

    do {
        if (p == q) break;
        ans++;
    } while (nextPermutation(p));

    writeln(ans);
}









void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m, q = map(int, input().split())
abcd = [0] * q
for i in range(q):
    abcd[i] = list(map(int, input().split()))

def dfs(seq):
    if len(seq) == n:
        yield seq
        return
    else:
        if not seq:
            last = 1
        else:
            last = seq[-1]
    for i in range(last, m+1):
        new_seq = seq.copy()
        new_seq.append(i)
        yield from dfs(new_seq)

ans = 0
for s in dfs([]):
    tmp_ans = 0
    for a, b, c, d in abcd:
        if s[b-1] - s[a-1] == c:
            tmp_ans += d
    ans = max(ans, tmp_ans)
print(ans)


Measured memory_bytes: 83820
#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
using namespace std;

void print_vector(vector<int> &num)
{
	for(int i = 0; i < num.size(); i++){
		if(i == 0){
			cout << num[i];
		}
		else{
			cout << " " << num[i];
		}
	}
	cout << endl;
}
void insertionSort(vector<int> &num)
{
	print_vector(num);

	for(int i = 1; i <= num.size() - 1; i++){
		int a = num[i];
		int j = i - 1;
		while(j >= 0 && num[j] > a){
			num[j + 1] = num[j];
			j--;
		}
		num[j + 1] = a;
		print_vector(num);
	}
}
int main(void)
{	
	int n;//??°????????????
	cin >> n;
	
	vector<int> num(n);
	
	for(int i = 0; i < n; i++){
		cin >> num[i];
	}
	
	insertionSort(num);
		
	return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

bool isPrime(int x) {
    for(int i = 2; i * i <= x; ++i) {
        if(x % i == 0) return false;
    }
    return true;
}

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

    while(!isPrime(x)) ++x;
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int A,B,C,K,x,sum=0;
	cin >> A >> B >> C >> K;
	if(A>=K)
		sum = K;
	else if( K>A and A+B>=K)
		sum = A;
	else if ( K > A+B)
	{
		x = K-(A+B); // that much C cards
		sum = A-x;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3592
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
  int n,k,x,ans=0;
  scanf("%d",&n);
  scanf("%d",&k);
  for(int i=0;i<n;i++){
    scanf("%d",&x);
    ans+=min(x,k-x);
  }
  printf("%d\n",2*ans);
}

Measured memory_bytes: 256
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         fozubaoyou    pass System Test!
*/

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const long long LINF = 1000000000000000018ll;
const int INF = 1000000009;
const int mod = 1000000007;
const int mod2 = 998244353;

int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }

int main() {
  std::cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::setprecision(20) << std::fixed;

  int k;
  cin >> k;

  ll sum = 0;
  for (int a = 1; a <= k; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= k; c++) {
        sum += gcd(gcd(a, b), c);
      }
    }
  }
  cout << sum << endl;

  return 0;
}


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

int ans;
int maxdif;
vector<int> t(5);

int main(){
  rep(i, 5){
    cin >> t[i];
    int tentime = 10*((t[i]+9)/10);
    ans += tentime;
    maxdif = max(maxdif, tentime-t[i]);
  }
  ans -= maxdif;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define F first
#define S second

typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1000000;
const int minf = -1000000;
const ll lnf = 1e12;
const ll mlnf = -1e12;

// Graph problem
using Graph = vector<vector<int>>;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

// solve

int main()
{
    long long N, K;
    cin >> N >> K;
    long long ans = 0;
    long long min_wa = (K - 1) * K / 2;
    long long max_wa = N * (N + 1) / 2 - (N - K) * (N - K + 1) / 2;
    ans += max_wa - min_wa + 1;
    ans %= MOD;
    for (long long i = 1; i < (N + 2 - K); i++) {
        max_wa += N - K + 1 - i;
        min_wa += K - 1 + i;
        ans += max_wa - min_wa + 1;
        ans %= MOD;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3764
n, q = map(int, input().split())
bit = [0] * (n + 1)


def fenwick_add(x, w):
    while x <= n:
        bit[x] += w
        x += x & -x


def fenwick_sum(x):
    sm = 0
    while x > 0:
        sm += bit[x]
        x -= x & -x
    return sm


c = list(map(int, input().split()))
p = [-1] * (n + 1)
ps = [[] for _ in range(n + 1)]
for i, v in enumerate(c):
    l = p[v]
    if l != -1:
        ps[l].append(i)
    p[v] = i

qs = [[] for _ in range(n + 1)]
for i in range(q):
    l, r = map(int, input().split())
    qs[l - 1].append([r - 1, i])

ans = [0] * q
for i in range(n - 1, -1, -1):
    for v in ps[i]:
        fenwick_add(v, 1)
    for v in qs[i]:
        r, qi = v
        ans[qi] = r - i + 1 - fenwick_sum(r)
print(*ans, sep="\n")


Measured memory_bytes: 245176
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int days[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    char* week[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};

    for(;;){
        int m, d;
        cin >> m >> d;
        if(m == 0)
            return 0;

        int num = 0;
        for(int i=0; i<m-1; ++i)
            num += days[i];
        num += d;

        cout << week[(num+2)%7] << endl;
    }
}

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

int main() {
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<int> res(n, 0);
	rep(i, n - 1) {
		if (s[i] == 'A' && s[i + 1] == 'C') res[i]++;
	}
	vector<int> sum(n + 1, 0);
	rep(i, n) sum[i + 1] = sum[i] + res[i];
	rep(i, q) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		int ans = sum[r] - sum[l];
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1792
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s1 = S()
s2 = S()

for i in range(len(s1)):
    rot = s1[i:] + s1[:i]
    if rot == s2:
        print("Yes")
        exit()
print("No")


Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k;
  cin>>n>>k;
  int ans=1;
  int b=1;
  for(int i=0;i<10000;i++){
    for(int j=0;j<ans-1;j++){
      b*=k;
    }
    if(b<=n&&n<=(b*k)-1){
      cout<<ans<<endl;
      break;
    }
    b=1;
    ans++;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){

  int n,a,b,c,d,result;

  while(scanf("%d",&n) != EOF){

    result=0;
    for(a = 0; a < 10; a++) for(b = 0; b < 10; b++) for(c = 0; c < 10; c++) for(d = 0; d < 10; d++) if(a+b+c+d == n) result++;

    printf("%d\n",result);

  }

  return 0;

}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(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 repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,t;
	cin >>n>>t;
	int ans=INF;
	V a(n);
	rep(i,n){
		cin>>a[i];
	}
	map<ll,int>dis;
	P data=mp(INFLL,-INFLL);//mim ,max
	ll cnt=0;
	rep(i,n){
		if(chmin(data.F,a[i])){
			data.S=-INFLL;
		}else{
			if(chmax(data.S,a[i])){
				dis[data.S - data.F]+=0;
				dis[data.S-data.F]++;

			}
		}
	}
	auto ter=dis.end();
	ter--;
	cout<<ter->S<<endl;
}

Measured memory_bytes: 10384
n = gets.to_i
r = []
for i in 0...n do
  r[i] = gets.split.map(&:to_i)
end
r.sort! do |e1, e2|
  e1[0] <=> e2[0]
end
prev = -(10 ** 9)
count = n
for i in 0...n do
  if prev > r[i][0] - r[i][1]
    count -= 1
    prev = [prev, r[i][0] + r[i][1]].min
  else
    prev = r[i][0] + r[i][1]
  end
end
puts count


Measured memory_bytes: 10488
#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.at(i);
	}
	sort(a.begin(), a.end());
	a.at(n - 1) = a.at(n - 1) / 2;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a.at(i);
	}
	cout << sum << endl;
}

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

int main(void) {
    int n;
    cin >> n;
    int a[n];
    int b[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];

    int aa[n];  // cumulative sum
    int bb[n];  // cumulative sum (reverse)
    int sumA = 0;
    int sumB = 0;
    for (int i = 0; i < n; i++) {
        sumA += a[i];
        aa[i] = sumA;
    }
    for (int i = n - 1; i >= 0; i--) {
        sumB += b[i];
        bb[i] = sumB;
    }

    int max = 0;
    for (int i = 0; i < n; i++) {
        int sum = 0;
        sum += aa[i];
        sum += bb[i];
        if (sum > max) max = sum;
    }
    cout << max << endl;
    return 0;
}

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

int INF = 1001001001;

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;
}

int main() {
    int h, n;
    cin >> h >> n;
    vector<vector<int>> dp(n+1, vector<int>(h+1));
    rep(i,n+1)rep(j,h+1) {
        if (j == 0) dp[i][j] = 0;
        else dp[i][j] = INF;
    }
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        for (int j = 0; j <= h; j++) {
            //chmin(dp[i+1][j], dp[i][j]);
            if (j - a >= 0) chmin(dp[i+1][j], dp[i+1][j-a] + b);
            else chmin(dp[i+1][j], b);
            chmin(dp[i+1][j], dp[i][j]);
        }
    }
    cout << dp[n][h] << endl;
    return 0;
}

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

const int MAXN = 1000 * 1000 + 10;
const long long INF = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 10;

bool is_first_dp[MAXN];

int stone[200];
int n, k;

bool update(int t)
{
    //cerr << "k :" << t << endl;
    bool result = false;

    for(int i = 0; i < n; i++){
        if(stone[i] > t) break;
        if(!is_first_dp[t - stone[i]]) result = true;
        //cerr << stone[i] << ' ' << result << endl;
    }
    return result;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //cout << fixed << setprecision(10);

    cin >> n >> k;

    for(int i = 0; i < n; i++) cin >> stone[i];

    is_first_dp[0] = false;

    for(int i = 1; i <= k; i++) is_first_dp[i] = update(i);

    if(is_first_dp[k]){
        cout << "First" << endl;
    }
    else{
        cout << "Second" << endl;
    }

    return 0;
}



Measured memory_bytes: 3744
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    A, B = map(int, input().split())
    logging.info("Hello!")

    print(max([A + B, A - B, A * B]))
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 4584
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
int s[200005];
int main() {
    int n, k; cin >> n >> k;
    for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
    for (int i = k+1; i <= n; i++)
        if (s[i] > s[i-k]) printf("Yes\n");
        else printf("No\n");
    return 0;
}


Measured memory_bytes: 4540
#include<iostream>
using namespace std;
int main(){
	char a[10];
	for(int i = 0;i<10;i++){
		scanf("%c",&a[i]);
	}
	a[3] = '8';
	for(int i = 0;i<10;i++){
		printf("%c",a[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値取得
		int A = scan.nextInt();
		int B = scan.nextInt();

		//WK変数

		//演算

		//結果出力
			System.out.println(A * B);
	}
}

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

void solve()
{
    char a;
    cin >> a;
    if (a >= 'A' && a <= 'Z')
    {
        cout << "A";
    }
    else
        cout << "a";
}

int main()
{
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

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

#define int long long

using namespace std;

const int maxn = 110, maxl = 5;
int dp[maxn][maxl], K;
string N;

int C(int n, int k)
{
        if (n < k)
                return 0;
        if (k == 0)
                return 1;
        int res = 1;
        for (int i = 1; i <= k; i++)
                res *= n--;
        for (int i = 1; i <= k; i++)
                res /= i;
        return res;
}

signed main()
{
        cin >> N >> K;

        int sz = N.size();
        dp[sz][0] = 1;
        for (int i = sz - 1; ~i; i--) {
                for (int k = 0; k <= K; k++) {
                        if (!k)
                                dp[i][k] = 1;
                        else if (N[i] == '0')
                                dp[i][k] = dp[i + 1][k];
                        else {
                                dp[i][k] = (N[i] - '1') * C(sz - i - 1, k - 1) * pow(9, k - 1)
                                    + C(sz - i - 1, k) * pow(9, k);
                                dp[i][k] += dp[i + 1][k - 1];
                        }
                }
        }

        cout << dp[0][K];

        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(std::string s){
    cout << s[0] << s.size() - 2 << s[s.size() - 1] << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


Measured memory_bytes: 256
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new File("c:\\0508-input.txt"));

		while (true) {
			int n = scan.nextInt();
			if (n == 0)
				break;

			Ring r = new Ring(n);

			for (int i = 0; i < n; i++) {
				int x = scan.nextInt();
				int y = scan.nextInt();
				r.add(x, y, i);
			}

			r.sort();

			int max = 0;
			for (int x = r.elem(); x > 0; x = r.elem()) {
				int mm = r.maxRing(x);
				if (mm > max)
					max = mm;
			}
			System.out.println(max);

		}

		scan.close();
		System.exit(0);
	}
}

class Ring {
	private int[] st;
	private int[] ed;

	public Ring(int n) {
		st = new int[n * 2];
		ed = new int[n * 2];
	}

	private boolean[] used = new boolean[101];

	public int maxRing(int r) {
		used[r] = true;
		int len = 0;
		for (int i = this.startPos(r); i < st.length; i++) {
			if (st[i] > r)
				break;
			if (st[i] < r)
				continue;
			if (used[ed[i]])
				continue;
			int le = this.maxRing(ed[i]);
			if (len < le)
				len = le;
		}
		used[r] = false;
		return len + 1;
	}

	private int startPos(int r) {
		int i = st.length / 2;
		for (int m = i / 2; m > 2 && st[i] != r; m /= 2)
			if (st[i] < r)
				i += m;
			else
				i -= m;

		int j = i;
		for (; j > 0 && st[j] >= r; j--)
			;
		return j;
	}

	private int elemP = 0, elemV = -1;

	public int elem() {
		for (; elemP < st.length; elemP++)
			if (st[elemP] != elemV) {
				elemV = st[elemP];
				return elemV;
			}
		return -1;
	}

	public void sort() {
		for (int i = 0; i < st.length; i++)
			for (int j = st.length - 1; j > i; j--)
				if (st[j] < st[j - 1] || (st[j] == st[j - 1] && ed[j] < ed[j - 1])) {
					int tmp = st[j];
					st[j] = st[j - 1];
					st[j - 1] = tmp;
					tmp = ed[j];
					ed[j] = ed[j - 1];
					ed[j - 1] = tmp;
				}
	}

	public void add(int x, int y, int i) {
		st[i * 2] = x;
		ed[i * 2] = y;
		st[i * 2 + 1] = y;
		ed[i * 2 + 1] = x;
	}

}

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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&b==c){
    cout<<"1"<<endl;
  }
  else if(a==b&&b!=c){
    cout<<"2"<<endl;
  }
  else if(b==c&&a!=b){
    cout<<"2"<<endl;
  }
  else if(a==c&&a!=b){
    cout<<"2"<<endl;
  }
  else{
    cout<<"3"<<endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

// rectangle 1 <= a, b <= 100, a * b

int main(){
	int a, b, area, perimeter;
	cin >> a;
	cin >> b;

	area = a * b;
	perimeter = 2 * (a + b);

	cout << area << " " << perimeter << endl;

	return 0;
}


Measured memory_bytes: 3108
n = gets.to_i
a = gets.split.map(&:to_i)
a.sort!.reverse!
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
c.sort!

ans = 0
0.upto(b.length-1) do |i|
  ci = c.bsearch_index{|v| v > b[i]}
  ai = a.bsearch_index{|v| v < b[i]}
  if !ai.nil? && !ci.nil?
    ans += (c.length - ci) * (a.length - ai)
  end
end

puts ans


Measured memory_bytes: 23172
#include <bits/stdc++.h>
using namespace std;
//#define LOCAL
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define sz size()
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
//cout << fixed << setprecision(12) <<x<<endl;
const int MAX=1001;
int a[MAX];
int b[MAX];
int main(){
fastIO;
#ifdef LOCAL
     freopen("in.txt", "r", stdin);
#endif

      string s;
      cin>>s;
      int a=0,b=0;
      for(int i=0; i<3; i++){
        if(s[i]=='A'){
            a++;
        }
        else{
          b++;
        }
      }
      if((b==2 && a==1) || (b==1 && a==2)){
       cout<<"Yes"<<endl;
      }
      else {
        cout<<"No"<<endl;;
      }

}



Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long x = sc.nextLong();
		double v = Math.pow(a, 2)*b/2;
		double ans = 0;
		if (x<=v) {
			double s = 2*x/(a*Math.pow(b, 2));
			ans = 90 - Math.atan(s)*180/Math.PI;
			System.out.println(ans);
		} else {
			double t = a/(2*b - (2*x/Math.pow(a,2)));
			ans = 90 - Math.atan(t)*180/Math.PI;
			System.out.println(ans);
		}

	}
}


Measured memory_bytes: 21844
N = input()
A = input()
n = []
arr = [N]
i = 0
cnt = -1
arr = A.split(" ")
while "".join(n).replace("o","") == "":
	for num in arr:
		if int(num)%2 == 0:
			n.append("o")
			arr[i] = int(arr[i])/2
		else:
			n.append("x")
		i += 1
	i = 0
	cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=1e5+50; 

int n,a[N],k,ans;
vector<int> g[N];

int dfs(int v,int p){
	int len=1;
	for(int d:g[v])if(d!=p){
		int w=dfs(d,v);
		if(v!=1&&w>=k)++ans,w=0;
		len=max(len,w+1);
	}
	Pr("dfs v=%d,len=%d\n",v,len); 
	return len;
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	read(n),read(k); 
	rep(i,1,n){
		read(a[i]); 
	}
	ans+=a[1]!=1;
	rep(i,2,n)g[a[i]].pb(i);
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef pair< double,double> dd;
#define pb push_back
#define eb emplace_back
#define sz(a) (int)a.size()
#define all(c) c.begin(),c.end()
#define FOR(i,a,b) for(i=a; i<b; i++)
#define FORR(i,a,b) for(i=a;i>=b;i--)
#define REP(i,n) FOR(i,0,n)
#define x first
#define y second
#define mp make_pair

const int INF = 1000000007;
const long long INFLL = (ll)INF * (ll)INF;

int32_t main()
{
	IOS;
	char c;
	cin>>c;
	if(isupper(c))
	{
		cout<<"A";
	}
	else
	{
		cout<<"a";
	}
	return 0;
}


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

public class Main {
	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {
		int n = scanner.nextInt(), l[] = new int[n * 2], tmp = 0;
		for(int i = 0; i < l.length; i++) {
			l[i] = scanner.nextInt();
		}
		Arrays.sort(l);
		reverse(l);
		for(int i = 0; i < n; i++) {
			tmp += l[(i * 2) + 1];
		}
		System.out.println(tmp);
	}

	public static void reverse(int[] array) {
		int len = array.length, tmp;
		for (int i = 0; i < len / 2; i++) {
			tmp = array[i];
			array[i] = array[len - 1 - i];
			array[len - 1 - i] = tmp;
		}
	}
}


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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  if ( s == "RRR" ) { ans = 3; }
  else if ( s == "RRS" || s == "SRR" ) { ans = 2; }
  else if ( s == "SSS" ) { ans = 0; }
  else { ans = 1; }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


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


    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        ll c = n / i;
        ll s = c * (2 * i + (c - 1) * i) / 2;
        ans += s;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3660
while 1:
  n=int(input())
  if n==0: break
  cs=input()
  a,b=[0]*n,0
  for i in range(100):
    if cs[i]=="M":
      a[i%n]+=1
    elif cs[i]=="S":
      a[i%n],b=0,b+1+a[i%n]
    elif cs[i]=="L":
      a[i%n],b=a[i%n]+1+b,0
  a.sort()
  print(" ".join(map(str,a+[b])))

Measured memory_bytes: 6724
#include<iostream>
#include<vector>
#include<stdio.h>
using namespace std;

int main(){

    int n,x,num=0,count=0;
    std::vector<int> vec_n,vec_x;

    while(1){
        cin >> n >> x;
        if(n==0 && x==0){
            break;
        }else{
            vec_n.push_back(n);
            vec_x.push_back(x);
            num++;
        }
    }

    for(int i=0;i<num;i++){
        for(int j=1;j<=vec_n[i];j++){
            for(int k=j+1;k<=vec_n[i];k++){
                for(int l=k+1;l<=vec_n[i];l++){
                    if(j+k+l == vec_x[i]){
                        //printf("(%d,%d,%d):sum=%d\n",j,k,l,j+k+l);
                        count++;
                    }
                }
            }
        }
        cout << count << endl;
        count=0;
    }
}


Measured memory_bytes: 3160
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


int main(){
  ll n;
  cin >> n;
  vector<ll> a(n + 1), b(n);
  rep(i, n+1) cin >> a[i];
  rep(i, n) cin >> b[i];
  ll ans = 0;

  for(ll i = n - 1; i >= 0; --i){
    ll m = min(b[i], a[i + 1]);
    b[i] -= m;
    a[i + 1] -= m;
    ans += m;

    m = min(b[i], a[i]);
    b[i] -= m;
    a[i] -= m;
    ans += m;
    
  }
  
  cout << ans << endl;

}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX 1000
int main(){
    vi v(10); string s;
    while (cin>>s) {
        rep(i,10)v[i]=s[i]-48;
        rep(i,9)for(int j=0;j<=(10-i-1);j++)v[j]+=v[j+1];
        s=to_string(v[0]);
        cout<<s.back()<<endl;
    }
}

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

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

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

const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;

int main()
{
	ll a, b, n, ans;
	cin >> n >> a >> b;
	ans = min(max(a, b) - 1, n - min(a, b));
	if((a - b) % 2 == 0)
		ans = min(ans, abs(a - b) / 2);
	else{
		ans = min(ans, (a + b) / 2);
		ans = min(ans, (n - a + n - b + 2) / 2);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
/* 
 * File:   main.cpp
 * Author: masa
 *
 * Created on 2016/03/12, 7:31
 */

#include <cstdlib>
#include <string>
//#include <fstream>
#include <iostream>

using namespace std;


#define MAX 26
#define NIL -1

struct Node {
    int parent;
    int left;
    int right;
};

Node treeNodes[MAX];

/*
 * 
 */

void printPreOrder(int id) {
    cout << " " << id;
    
    if(treeNodes[id].left != NIL) {
        printPreOrder(treeNodes[id].left);
    }
    if(treeNodes[id].right != NIL) {
        printPreOrder(treeNodes[id].right);
    }
}

void printInOrder(int id) {
    if(treeNodes[id].left != NIL) {
        printInOrder(treeNodes[id].left);
    }
    
    cout << " " << id;
    
    if(treeNodes[id].right != NIL) {
        printInOrder(treeNodes[id].right);
    }
}

void printPostOrder(int id) {
    if(treeNodes[id].left != NIL) {
        printPostOrder(treeNodes[id].left);
    }
    if(treeNodes[id].right != NIL) {
        printPostOrder(treeNodes[id].right);
    }
    cout << " " << id;
}

int main(void) {
    
    //ifstream ifs;
    int num;
    
    //ifs.open("./input.txt", ios::in);
    
    //ifs >> num;
    cin >> num;
    
    for(int i = 0; i < num; i++) {
        treeNodes[i].parent = treeNodes[i].left = treeNodes[i].right = NIL;
    }
    
    int id, child;
    for(int i = 0; i < num; i++) {
    //    ifs >> id;
        cin >> id;
        for(int j = 0; j < 2; j++) {
            //ifs >> child;
            cin >> child;
            if(j == 0) {
                treeNodes[id].left = child;
            }
            else {
                treeNodes[id].right = child;
            }
            if(child != NIL) {
                treeNodes[child].parent = id;
            }
        }
    }
    
    int rootId;
    for(int i = 0; i < num; i++) {
        if(treeNodes[i].parent == NIL) {
            rootId = i;
        }

    }
    cout << "Preorder" << endl;
    printPreOrder(rootId);
    cout << endl;
    
    cout << "Inorder" << endl;
    printInOrder(rootId);
    cout << endl;
    
    cout << "Postorder" << endl;
    printPostOrder(rootId);
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 1164
let input = require("fs").readFileSync("/dev/stdin", "utf8")

function main() {
    const [X] = load()
    
    for(let i = -120; i <= 120; i++) {
        for(let j = -120; j <= 120; j++) {
            if(Math.pow(i,5) - Math.pow(j,5) === X) {
                return [i,j].join(' ')
            }
        }
    }
}


let inputs = input.split(/[\s\n]/)
console.log(main())


// 入力値を読み込む
function load(rows = 1, cols = 1, type = Number) {
    const length = rows * cols
    let result = inputs.splice(0, length)

    if(type !== String) result = result.map(type)
    if(cols > 1) {
        const arrays = new Array(cols)
        for(let col = 0; col < cols; col++) {
            arrays[col] = new Array()
            for(let row = 0; row < rows; row++) {
                arrays[col].push(result[row * cols + col])
            }
        }
        result = arrays
    }

    return result
}


Measured memory_bytes: 33240
import sys
x, k, d=map(int,input().split())
x=abs(x)
if x>=d:
    tm=x//d
    if tm>=k:
        ans = x-k*d
        print(ans)
        sys.exit()
    x -= tm*d
    k -= tm
    if k%2==0:
        ans=x
    else:
        ans=abs(x-d)
else:
    if k%2==0:
        ans=x
    else:
        ans=d-x
print(ans)

Measured memory_bytes: 9116
#include<stdio.h>
int main(void)
{
	int N,p[51],i;
	int cnt=0;
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%d",&p[i]);
		
	}
	for(i=0;i<N;i++)
	{
		if(i!=p[i]-1)
		{
			cnt++;
		}
		if(cnt>2)
		break;
	}
	if(cnt>2)
	printf("NO");
	else
	printf("YES");
	return 0;
}


Measured memory_bytes: 128
N, K = map(int, input().split())
S = input()

t = S[0]
c = 0
for i in range(N):
    if S[i] != t:
        c += 1
        t = S[i]

if c <= 2 * K:
    print(N - 1)
else:
    a = c - 2 * K
    print(N - a - 1)

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

int sum(vector<int> A){
  int s = 0;
  for (int i = 0; i < A.size()-1; i++){
    s += A.at(i);
  }
  return s;
}

vector<int> input(int N){
  vector<int> vec(N);
  for (int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  return vec;
}



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

  vector<int>B = input(N);
  sort(B.begin(), B.end());
  
  int sumB = sum(B);

  int C;
  C = B.at(N-1)/2;

  cout << sumB + C << endl;
 
  
}


Measured memory_bytes: 3572
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = [0]*M
y = [0]*M
c = [0]*M
for i in range(M):
    x[i],y[i],c[i] = map(int,input().split())

ans = min(a) + min(b)
for i in range(M):
    if a[x[i]-1] + b[y[i]-1] - c[i] < ans:
        ans = a[x[i]-1] + b[y[i]-1] - c[i]
print(ans)

Measured memory_bytes: 23396
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int n;
int a[1000000];

int main(){
  cin>>n;
  rep(i,n){
    cin>>a[i];
  }
  sort(a,a+n);

  cout<<a[n-1]<<' ';
  int in = inf,res=n-2;
  for(int i=n-2;i>=0;i--){
    if(abs(a[n-1]/2-a[i])<in){
      in = abs(a[n-1]/2-a[i]);
      res = i;
    }
  }

  cout<<a[res]<<endl;

  return 0;
}



Measured memory_bytes: 640