akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define MAX 100000
#define ALL 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); 
void mergeSort(struct Card A[],int n,int left,int right);
int partition(struct Card A[],int n,int p,int r);
void quickSort(struct Card A[],int n,int p,int r);

int main(){
  int n,i,va;
  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,&va);
    A[i].suit=B[i].suit=S[0];
    A[i].value=B[i].value=va;
  }

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

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=ALL;
  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);
  }
}



Measured memory_bytes: 4044
n=int(input())
dp=[[0]*(n) for _ in range(n)]
ans=-10**9
a=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    s=[0]*101
    for j in range(n):s[j+1]=s[j]+a[i][j]
    for j in range(n):
        for k in range(j,n):
            dp[j][k]=max(dp[j][k],0)+s[k+1]-s[j]
            ans=max(ans,dp[j][k])
print(ans)

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

int main() {
  string o, e;
  cin >> o >> e;
  for (int i = 0; i < e.size(); i++) cout << o[i] << e[i];
  if (o.size() > e.size()) cout << o[e.size()] << endl;
}

Measured memory_bytes: 256
using System;

class Program {
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        int[] a = new int[n];
        string input = Console.ReadLine();
        Console.WriteLine(input);
        string[] ary = input.Split(' ');
        for (int i = 0; i < n; i++) {
            a[i] = int.Parse(ary[i]);
        }
        insertionSort(a, n);
    }

    static void insertionSort(int[] a, int n) {
        int j, i, v;
        for (i = 1; i < n; i++) {
            v = a[i];
            j = i - 1;
            while (j >= 0 && a[j] > v) {
                a[j + 1] = a[j];
                j--;
            }
            a[j + 1] = v;
            string[] str = new string[n];
            for (int x = 0; x < n; x++) {
                str[x] = a[x].ToString();
            }
            Console.WriteLine(string.Join(" ", str));
       }
    }
}

Measured memory_bytes: 9356
#include<stdio.h>
int main(){
	int n,n4=0,n2=0,t;
	int flag=1;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&t);
		if(t%4==0)n4++;
		else if(t%2==0)n2++;
	}
	int nn=n-n2-n4;
	if(n2==0){
		if(nn>n4+1)flag=0;
	}else{
		if(nn>n4)flag=0;
	}
	
	if(flag)printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
#include <stdio.h>

int main () {
	int n, multi;
	int x = 1;
	scanf("%d %d", &n, &multi);
	long long int arr[n] = {};
	
	for(int i = 0; i < n; i++) {
		scanf("%d", &arr[i]);
	}
	for(int i = multi - 1; i < n; i++) {
		if(x == 1) {
			x = 0;
			continue;
		}
		if(arr[i] > arr[i - multi]) {
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 3192
import java.io.*;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.Collections;

class Index {
	String name;
	ArrayList<Integer> a = new ArrayList<Integer>();

	Index(String name,int page) {
		this.name = name;
		this.a.add(page);
	}

	void AddToIndex(ArrayList<Index> id,Index next) {
		boolean Not_Add = true;
		for (int i=0;i<id.size();i++) {
			if (id.get(i).name.compareTo(next.name)>0) {
				id.add(i,next);
				Not_Add = false;
				break;
			} else if (id.get(i).name.compareTo(next.name)==0) {
				id.get(i).a.add(next.a.get(0));
				Not_Add = false;
				break;
			}
		}
		if (Not_Add) id.add(next);
	}

	void printIndex() {
		System.out.println(this.name);
		Collections.sort(this.a);
		System.out.print(this.a.get(0));
		for (int i=1;i<a.size();i++) {
			System.out.print(" "+this.a.get(i));
		}
		System.out.println();
	}
}

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;
		ArrayList<Index> id = new ArrayList<Index>();
		boolean ff = true;

		try {

		while ((buf = br.readLine())!=null) {
			StringTokenizer st = new StringTokenizer(buf);
			String name = st.nextToken();
			int page = Integer.parseInt(st.nextToken());
			if (ff) {
				id.add(new Index(name,page));
				ff = false;
			} else {
				Index t = new Index(name,page);
				id.get(0).AddToIndex(id,t);
			}
		}
		for (int i=0;i<id.size();i++) {
			id.get(i).printIndex();
		}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16920
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// namespace
using namespace std;
// type
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
// input
#define INIT              ({ ios::sync_with_stdio(false); cin.tie(0); })
#define VAR(type, ...)    type __VA_ARGS__; var_scan(__VA_ARGS__);
template<typename T>
static void var_scan(T& t)
{
    cin >> t;
}
template<typename T, typename... R>
static void var_scan(T& t, R&... rest)
{
    cin >> t;
    var_scan(rest...);
}
// output
#define OUT(var)          cout << (var)
#define SPC               cout << ' '
#define TAB               cout << '\t'
#define BR                cout << '\n'
#define ENDL              cout << endl
#define FLUSH             cout << flush
// debug
#ifdef DEBUG
#define EPRINTF(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
#define DUMP(var)         cerr << #var << '\t' << (var) << '\n'
#define DUMPITERABLE(i) do {                            \
        cerr << #i << '\t';                             \
        for (const auto& it : i) { cerr << it << ' '; } \
        cerr << '\n';                                   \
} while (0)
#define DUMPITERABLE2(i2) do {                          \
        cerr << #i2 << '\t';                            \
        for (const auto& it : i2) {                     \
            for (const auto& it2: it) {                 \
                cerr << it2 << ' ';                     \
            }                                           \
        }                                               \
        cerr << '\n';                                   \
} while (0)
#else
#define EPRINTF(fmt, ...)
#define DUMP(var)
#define DUMPITERABLE(i)
#define DUMPITERABLE2(i)
#endif
// util
// [l, r)
#define REP(i, n)       for (int i = 0; i < (n); i++)
#define RREP(i, n)      for (int i = (n)-1; i >= 0; i--)
#define FOR(i, l, r)    for (int i = (l); i < (r); i++)
#define RFOR(i, r, l)   for (int i = (r)-1; i >= (l); i--)
#define REPLL(i, n)     for (ll i = 0; i < (n); i++)
#define RREPLL(i, n)    for (ll i = (n)-1; i >= 0; i--)
#define FORLL(i, l, r)  for (ll i = (l); i < (r); i++)
#define RFORLL(i, r, l) for (ll i = (r)-1; i >= (l); i--)

int main(void)
{
    INIT;
    string str;
    cin >> str;
    if (str[str.size()-1]!='s')
        str.push_back('s');
    else
        str+="es";
    OUT(str);
    ENDL;
    return 0;
}


Measured memory_bytes: 3660
W,H,N=map(int,input().split())
# Wはx軸、Hはy軸
x_s=0
x_g=W
y_s=0
y_g=H

for i in range(N):
  x,y,a=map(int,input().split())
  # aが1ならxの始点がxiになる
  # aが2ならxの終点がxiになる
  # aが3ならyの始点がyiになる
  # aが4ならyの始点がyiになる
  if a==1:
    if x_s<x:x_s=x
  elif a==2:
    if x_g>x:x_g=x
  elif a==3:
    if y_s<y:y_s=y
  else:
    if y_g>y:y_g=y
if (x_g-x_s) <= 0 or (y_g-y_s)<= 0:
  print(0)
else:
  print((x_g-x_s)*(y_g-y_s))


Measured memory_bytes: 9168
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}
int main() {
    ll n; cin >> n;
    vector<ll> d;
    ll mod = 998244353;
    ll mn = 1e10;
    ll mx = -1;
    set<ll> st;
    ll a[100001]; INITA(a, 0, 100000, 0);
    REP(i, n) {
        ll tmp;
        cin >> tmp;
        d.push_back(tmp);
        mn = min(mn, tmp);
        mx = max(mx, tmp);
        st.insert(tmp);
        a[tmp]++;

        if (i != 0 && tmp == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    // 0 1 1 2
    // 1 -> 2 -> 4
    //   -> 3

    // 1 -> 3 -> 4
    //   -> 2

    // 0 1 1 2 2 2 3
    // 24
    // 2 について、選び方は 2^3
    // その次に3は3^1
    // FOR(i, 0, mx) {
    //     cout << a[i] << endl;
    // }

    if ((d[0] != 0) || ((ll) st.size() != mx + 1)) {
        // できないのはいつ？
        // d[0]が1でない、あるいは0が複数、あるいは番号が飛んでいる
        // 0が複数パターンはinput時点で対応している
        cout << 0 << endl;
    } else {
        ll res = 1;
        FOR(i, 2, mx) {
            // res *= (ll) pow(a[i-1], a[i]) % mod;
            REP(j, a[i]) {
                res *= a[i-1] % mod;
                res %= mod;
            }
        }
        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 9560
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
#define LL long long
#define MO 1000000007
LL g[MAXN],p[MAXN],A,B,ans,a[MAXN];
int la[MAXN],lb[MAXN],ua[MAXN],ub[MAXN];
int n;
int main()
{
	scanf("%d%lld%lld",&n,&A,&B);
	n++;
	for(int i=2,j=2,k=2;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if(i==1) la[i]=i,lb[i]=i,ua[i]=0,ub[i]=0;
		else
		{
			if(a[i-1]+A<=a[i]) la[i]=la[i-1];
			else la[i]=i;
			while(a[j]+A<=a[i])	j++;
			ua[i]=j-1;
			if(a[i-1]+B<=a[i]) lb[i]=lb[i-1];
			else lb[i]=i;
			while(a[k]+B<=a[i]) k++;
			ub[i]=k-1;
		}
	}
	g[1]=1,p[1]=1;
	ua[n+1]=n-1,ub[n+1]=n-1;
	for(int i=2;i<=n;i++)
	{
		if(ub[i+1]>la[i]-2)
			g[i]=(p[min(ub[i+1],i-1)]-p[max(0,la[i]-2)]+MO)%MO;
		if(ua[i+1]>lb[i]-2)
			p[i]=(g[min(ua[i+1],i-1)]-g[max(0,lb[i]-2)]+MO)%MO;
		g[i]=(g[i]+g[i-1])%MO;
		p[i]=(p[i]+p[i-1])%MO;
	}
	ans=(g[n]-g[n-1]+MO)%MO+(p[n]-p[n-1]+MO)%MO;
	ans%=MO;
	printf("%lld\n",ans);
}

Measured memory_bytes: 4096
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
struct shu{
int key;
shu *left,*right,*parent;
};
shu* nil;
shu* root;
char s[100];
void charu(int k){
shu* y=nil;
shu* x=root;
shu* z;
z=new shu;
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 qianxu(shu* u){
    if(u==nil)return ;
    printf(" %d",u->key);
    qianxu(u->left);
    qianxu(u->right);
}
void zhongxu(shu* u){
    if(u==nil)return ;
    zhongxu(u->left);
    printf(" %d",u->key);
    zhongxu(u->right);
}
shu* sousuo(int k,shu* u){
    while(u!=nil&&k!=u->key){
        if(k < u->key)u=u->left;
        else u=u->right;
    }
return u;
}
shu* zuixiao(shu* u){
    while(u->left!=nil){
         u=u->left;
    }
return u;
}

shu* hou(shu* x){
         if(x->right!=nil)return zuixiao(x->right);
         shu* y=x->parent;
         while(y!=nil&&x==y->right){
               x=y;
               y=y->parent;
         }
return y;
}

void shanchu(shu* u){
             shu* x;
             shu* y;
             if(u->left==nil||u->right==nil){
                y=u;
             }
             else y=hou(u);
             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!=u){
                u->key=y->key;
             }
             free(y);
}
int main(){
int n;
int m;
scanf("%d",&n);
for(int i=0;i<n;i++){
    scanf("%s",s);
    if(s[0]=='i'){
        scanf("%d",&m);
        charu(m);
    }
    else if(s[0]=='p'){
        zhongxu(root);
        printf("\n");
        qianxu(root);
        printf("\n");
    }
    else if(s[0]=='f'){
        scanf("%d",&m);
        shu *x=sousuo(m,root);
        if(x!=nil)printf("yes\n");
        else printf("no\n");
    }
    else if(s[0]=='d'){
            scanf("%d",&m);
        shanchu(sousuo(m,root));
    }
}
return 0;
}

Measured memory_bytes: 21356
#include<stdio.h>
int main(void) {
    int i, n, expensive, sum=0;
    scanf("%d", &n);
    int p[n];
    for(i=0; i<n; i++) {
        scanf("%d", &p[i]);
        sum+=p[i];
    }
    expensive=p[0];
    for(i=1; i<n; i++) {
        if(p[i]>expensive)
            expensive=p[i];
    }
    sum-=(expensive/2);
    printf("%d\n", sum);
    return 0;
}

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

int main()
{
    string s;
    long long k;
    cin>>s>>k;
    for(int i=0;i<k;i++)if(s[i]!='1')cout<<s[i]<<endl,exit(0);
    cout<<"1\n";
    return 0;
}



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

int main(){
    char s[4];
    int num=1;
    for(int i=0;i<4;i++){
        cin>>s[i];
        if(i!=0&&s[i]==s[i-1]) num=0;
    }
    if(num==1) cout<<"Good"<<endl;
    else cout<<"Bad"<<endl;
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int m = max(max(a,b), max(b,c));
    if (m == a+b || m == c+b || m == a+c) cout << "Yes\n";
    else cout << "No\n";
}


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

int cmp(const void *a, const void *b); //比較関数

int main(){
  int n,max=0;
  int i;
  char s[200001][11];
  int ans[200000];
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%s",s[i]);
  
  qsort(s,n,sizeof(s[0]),cmp); //辞書順にソート
  
  for(i=0;i<n;i++){
    if(strcmp(s[i],s[i+1])==0){ //次の文字列と同じ文字列である場合
      ans[i]++;
      ans[i+1]=ans[i]+1; //a[i]にはi番目の文字列が重複してでてきたのは何回目か
    }
  }
  
  for(i=0;i<n;i++){
    if(max<ans[i])
      max=ans[i];
  } //重複して出てくる回数の最高値をmaxに記録する
  for(i=0;i<n;i++){
    if(max==ans[i])
      printf("%s\n",s[i]);
  }//重複している最高値と一致する文字列を出力する
}
    

int cmp(const void *a, const void *b){ //比較関数
  return strcmp((char *)a,(char *)b); //数字の大小を返す
}


Measured memory_bytes: 4988
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

char field[15][1050];

int main(void) {
  int H, W, K;
  scanf("%d%d%d", &H, &W, &K);
  REP(i, H) {
    scanf("%s", field[i]);
    REP(j, W) {
      field[i][j] -= '0';
    }
  }

  int res = H+W+10;
  REP(pat, 1 << (H-1)) {
    int ct[11] = {};
    int cur = __builtin_popcount(pat);
    int last = 0;
    REP(j, W) {
      int gi = 0;
      ct[gi] += field[0][j];
      for(int i = 1; i < H; ++i) {
        if(pat & (1 << (i-1))) {
          ++gi;
        }
        ct[gi] += field[i][j];
      }
      ++gi;
      bool ok = true;
      REP(i, gi) {
        if(ct[i] > K) {
          ok = false;
          break;
        }
      }
      if(!ok) {
        if(last == j) {
          goto NEXT;
        }
        last = j;
        ++cur;
        --j;
        REP(i, gi) {
          ct[i] = 0;
        }
      }
    }
    // cerr << "> " << cur << endl;
    res = min(res, cur);
  NEXT:
    ;
  }
  cout << res << endl;
  return 0;
}


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

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

using namespace std;

typedef long long ll;
const int MAX_W=50,MAX_H=50;

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

char S[MAX_H][MAX_W];

int main(){
	int W,H;
	cin>>H>>W;
	REP(i,H){
		cin>>S[i];
	}
	bool flg=true;
	REP(h,H){
		REP(w,W){
			if (S[h][w]=='#'){
				bool flg2=false;
				REP(i,4){
					int h2=h+dy[i],w2=w+dx[i];
					if (0<=h2 && h2<H && 0<=w2 && w2<W && S[h2][w2]=='#'){
						flg2=true;
					}
				}
				if (!flg2){
					flg=false;
				}
			}
		}
	}
	if (flg){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import math as m
N, M = input().split(' ')
N, M = int(N), int(M)

if N > 1:
    a = m.factorial(N)/(2*m.factorial(N-2))
else:
    a = 0
if M > 1:
    b = m.factorial(M)/(2*m.factorial(M-2))
else:
    b = 0

print(int(a+b))


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

int enc(const std::vector<int>& xs) {
    int ret = 0;
    for (auto x : xs) ret = ret * 3 + x;
    return ret;
}

std::vector<int> dec(int x) {
    std::vector<int> ret;
    for (int i = 0; i < 3; ++i) {
        ret.push_back(x % 3);
        x /= 3;
    }
    std::reverse(ret.begin(), ret.end());
    return ret;
}

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(3);
    for (auto& x : xs) std::cin >> x;

    std::string ans;
    if (std::accumulate(xs.begin(), xs.end(), 0LL) != 2) {
        while (n--) {
            std::string s;
            std::cin >> s;

            int i = s[0] - 'A', j = s[1] - 'A';

            if (xs[i] == 0 && xs[j] == 0) {
                std::cout << "No" << std::endl;
                return;
            }

            if (xs[i] < xs[j]) std::swap(i, j);
            --xs[i], ++xs[j];
            ans.push_back(j + 'A');
        }
    } else {
        auto dp = vec(n + 1, vec(27, std::make_pair(-1, '$')));
        dp[0][enc(xs)] = std::make_pair(-1, '#');

        for (int t = 0; t < n; ++t) {
            std::string s;
            std::cin >> s;

            int i = s[0] - 'A', j = s[1] - 'A';

            for (int b = 0; b < 27; ++b) {
                if (dp[t][b].second == '$') continue;
                auto ys = dec(b);

                for (int q = 0; q < 2; ++q) {
                    std::swap(i, j);
                    if (ys[i] == 0 || ys[j] == 2) continue;

                    --ys[i], ++ys[j];
                    dp[t + 1][enc(ys)] = std::make_pair(b, j + 'A');
                    ++ys[i], --ys[j];
                }
            }
        }

        int v = -1;
        for (int b = 0; b < 27; ++b) {
            if (dp.back()[b].first != -1) {
                v = b;
                break;
            }
        }

        if (v == -1) {
            std::cout << "No" << std::endl;
            return;
        }

        for (int t = n; t >= 1; --t) {
            ans.push_back(dp[t][v].second);
            v = dp[t][v].first;
        }
        std::reverse(ans.begin(), ans.end());
    }

    std::cout << "Yes" << std::endl;
    for (char c : ans) {
        std::cout << c << std::endl;
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 27744
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
//cout << fixed << setprecision(12);
//stoi("123");convert string to int
//to_string(123);convert int to string 

using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }

int main(){
	Lancer();
	ll n, k=100,st=0;
	cin >> n;
	while (k<n)
	{
		k += (k / 100);
		st++;
	}
	cout << st;
	cout << endl;
	return 0;
}


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

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

    int c = 0;
    if(s == "RRR") cout << 3 << endl;
    else if(s == "RRS" || s == "SRR") cout << 2 << endl;
    else if(s == "SSS") cout << 0 << endl;
    else cout << 1 << endl;
    
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main()
{
  char letter;
  cin>>letter;
  if(letter>='a'&&letter<='z')
  {
    cout<<'a'<<endl;
  }
  else if(letter>='A'&&letter<='Z')
          {
    cout<<'A'<<endl;
  }
          }

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> isPair;
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
#define Pll pair<ll,ll>
#define vpll vector<pll>
#define sll set<ll>
#define mll map<ll,ll>

const ll inf=1e18;
const ll maxs = 100005;
const ll mod = 1e9+7;

#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define LB lower_bound
#define UB upper_bound
#define line cout<<endl;
#define fr(i,a,b) for(int i=a;i<=b;++i)
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mst(x,a) memset(x,a,sizeof(x))

ll n,k;
ll a[maxs];
ll dp[2][maxs];
ll sum[2][maxs];

void solve()
{
    for(ll i=0;i<=k;i++)
        sum[0][i]=1;
    
    ll last=0,now=1;
    for(ll i=0;i<n;i++)
    {
        ll limit = a[i];
        for(ll i=0;i<=k;i++)
            sum[now][i]=0 , dp[now][i]=0;
        for(ll j=0;j<=k;j++)
        {
            if(j<=limit)
                dp[now][j] = sum[last][j];
            else
                dp[now][j] = (sum[last][j]%mod - sum[last][j-limit-1]%mod + mod)%mod;
            sum[now][j]=(sum[now][j-1]+dp[now][j])%mod;    
        }
        /*for(ll i=0;i<=k;i++)
            cout<<sum[0][i]<<" ";
        cout<<"\t";
        for(ll i=0;i<=k;i++)
            cout<<dp[0][i]<<" ";
        line;    
       for(ll i=0;i<=k;i++)
            cout<<sum[1][i]<<" ";
        cout<<"\t";
        for(ll i=0;i<=k;i++)
            cout<<dp[1][i]<<" ";
        line;  
        line;*/
        swap(last,now);
    }
    
    cout<<dp[last][k]; 
   
}

int main() {
    fastio();
    ll t=1;
    //cin>>t;
    while(t--){
        cin>>n>>k;
        for(ll i=0;i<n;i++)
            cin>>a[i];
        solve();
    }
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define mp make_pair
#define pb push_back
void solve(){
	int n;
	double d;
	cin>>n>>d;
	int cnt=0;
	double x,y;
	for (int i = 0; i < n; i++)
	{
		cin>>x>>y;
		if(sqrt(x*x+y*y)<=d)
			cnt++;
	}
	cout<<cnt<<endl;
	
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int T=1;
	//cin>>T;
	while(T--)
		solve();
}



Measured memory_bytes: 3800
def dist(a,b):
    return abs(a[0]-b[0])+abs(a[1]-b[1])

h,w,d=map(int,input().split())
table=[]
cost=[[0 for i in range(w)] for j in range(h)]
dic={}
for i in range(h):
    t=list(map(int,input().split()))
    table.append(t)
    for j in range(w):
        dic[t[j]]=(i,j)

for i in range(1,h*w+1):
    now=i
    a,b=dic[now]
    if cost[a][b]==0:
        while now<=h*w-d:
            now+=d
            y,x=dic[now]
            if cost[y][x]!=0:
                break
            cost[y][x]+=cost[a][b]+dist((a,b),(y,x))
            a,b=y,x

q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    a,b=dic[l]
    c,d=dic[r]
    print(cost[c][d]-cost[a][b])
    

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int n;
vector<vi> g;
set<pii> st;
vi visited, finished;
void dfs(int v, int p) {
    visited.pb(v);
    for (int t : g[v]) {
        if (t == p) continue;
        if (find(all(finished),t) != finished.end()) continue;
        if (find(all(visited),t)!=visited.end() && find(all(finished),t)==finished.end()) {
            st.emplace(v, t);
            st.emplace(t, v);
            repr(i, sz(visited)-1) {
                st.emplace(visited[i], visited[i+1]);
                st.emplace(visited[i+1], visited[i]);
                if (visited[i] == t) break;
            }
            continue;
        }
        dfs(t, v);
    }
    visited.pop_back();
    finished.pb(v);
}

int main(){
    int m;
    cin >> n >> m;
    g = vector<vi>(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].pb(b);
        g[b].pb(a);
    }
    dfs(0, 0);
    int ans = m - sz(st) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
N,M=map(int,input().split())
data=[[] for i in range(N+1)]
for i in range(M):
    A,B=map(int,input().split())
    data[A].append(B)
lst=[]
for i in range(1,N+1):
    flag=[0]*(N+1)
    parent=[0]*(N+1)
    que=[i]
    while que:
        h=[]
        for u in que:
            for v in data[u]:
                if flag[v]==0:
                    flag[v]=1
                    parent[v]=u
                    h.append(v)
        que=h
    if parent[i]==0:
        continue
    lsls=[i]
    zzz=i
    while True:
        zzz=parent[zzz]
        if zzz==i:
            break
        lsls.append(zzz)
    lst.append(lsls)
inf=float("inf")
k=inf
ans=None
for u in lst:
    if k>len(u):
        ans=u
        k=len(u)
if k==inf:
    print(-1)
else:
    print(k)
    for v in ans:
        print(v)

Measured memory_bytes: 53084
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e9;
ll inf = 1e18, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll a[200001], s = 0;
vector<ll> gr[200001];

int main()
{
    fast_io;
    ll n, m, i, j, x, y;
    cin >> n >> m;
    for (i = 1; i <= n; i++) cin >> a[i];
    for (i = 1; i <= m; i++)
    {
        cin >> x >> y;
        gr[x].pb(y);
        gr[y].pb(x);
    }
    for (i = 1; i <= n; i++)
    {
        bool bl = 0;
        for (auto f: gr[i])
        {
            if (a[i] <= a[f]) bl = 1;
            if (bl) break;
        }
        if (!bl) s++;
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 12592
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] a = new int[N];

        for (int i = 0; i < N; i++) {
            a[i] = Integer.parseInt(sc.next());
        }

        int tmp;
        for (int i = 0; i < N-1; i++) {
            for (int j = 0; j < N - i - 1; j++) {
                if ( a[j] < a[j+1] ) {
                    tmp = a[j+1];
                    a[j+1] = a[j];
                    a[j] = tmp;
                }
            }
        }

        int aliceSum = 0;
        int bobSum = 0;
        for (int i = 0; i < N; i++) {
            if (i%2 == 0) {
                aliceSum += a[i];
            } else {
                bobSum += a[i];
            }
        }
        System.out.println(aliceSum - bobSum);
    }
}


Measured memory_bytes: 23764
import sys

N = int(input())
W_list = list(map(int, input().split()))

min_diff = sys.maxsize

pre_val = None
for i in range(len(W_list)):
    diff = abs(sum(W_list[:i]) - sum(W_list[i:]))
    if min_diff > diff:
        min_diff = diff
    pre_val = W_list[i]

print(min_diff)


Measured memory_bytes: 3060
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <bits/stdc++.h>

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

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

int main() {
	#ifdef IZI_KATKA
	freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n = readInt();
    vector <int> a;
    for (int i = 1; i <= n; i++) {
    	a.pb(readInt());
    }
    vector <int> ans;
	for (int i = 1; i <= n; i++) {
		int fnd = 0;
		for (int j = a.size() - 1; j >= 0; j--) {
			if (a[j] == j + 1) {
				fnd = a[j];
				break;
			}
		}
		if (!fnd) {
			cout << "-1";
			return 0;
		}
		ans.pb(fnd);
		a.erase(a.begin() + fnd - 1);
	}
	for (int i = ans.size() - 1; i >= 0; i--) {
		cout << ans[i] << endl;
	}
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    val count = readLine()!!.toInt()

    val list = mutableListOf<String>()

    for (i in 1..count)
        list.add(readLine()!!)

    val success = list.drop(1).fold(list[0] to true) { acc, word ->
        if (!acc.second)
            acc
        else if (list.count { it == word } > 1)
            "" to false
        else
            word to (acc.first.last() == word.first())
    }.second

    println(if (success) "Yes" else "No")
}

Measured memory_bytes: 33652
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int N,M;
int an;
void test(int x){
    if(M/x>=N)an=max(an,x);
}
int main(){
    R(N,M);
    for(int i=1;i*i<=M;i++){
        if(M%i==0){
            test(i);
            test(M/i);
        }
    }
    W(an);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using static Input;
using static Util;
class Program
{
    static int A,B,H,N;
    static void INPUT()
    {
        A = NextInt();
        B = NextInt();
        H = NextInt();
        N = NextInt();
    }

    static void OUT()
    {
        var a = (double)N / 60 * 2 * Math.PI;
        var ax = Math.Cos(a) * A;
        var ay = Math.Sin(a) * A;

        var b = (double)(H * 60 + N) / 720 * 2 * Math.PI;
        var bx = Math.Cos(b) * B;
        var by = Math.Sin(b) * B;


        Console.WriteLine(Math.Pow((ax - bx) * (ax - bx) + (ay - by) * (ay - by), 0.5));
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{
}




Measured memory_bytes: 19020
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer n = scan.nextInt();
        ArrayList<Integer> array = new ArrayList<Integer>();

        for(int i=0;i<n;i++)
            array.add(scan.nextInt());

        int min = array.get(0);
        int count = 0;
        for(int i=0;i<n;i++){
            if(array.get(i) < min){
                min = array.get(i);
                count++;
            }
        }

        System.out.println(count+1);
    }

    static int factorial(int n){
        if(n == 0){
          return 1;
        }
        return n * factorial(n-1);
      }
}


Measured memory_bytes: 93684
def cuntry(N,K,X):
    if N <= K:
        return 0
    XX=[]
    for a in range(1,N):
        XX.append(X[a]-X[a-1])
    XX.sort(reverse=True)
    del XX[0:K-1]
    return sum(XX)
n= int(input())  
for j in range(n):
    N, K = map(int,input().strip().split())
    X = list(map(int,input().strip().split()))
    if N==0:
        break;
    print(cuntry(N,K,X))


Measured memory_bytes: 21060
// in case of multiple test cases and N=1e5 don't intialize arrays as global except for graph vector-array
// always check whether or not you are doing mod of a negative number
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=1e5 + 5;
const int MOD=1e9 + 7;

int32_t main()
{
	IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		int nn;
		cin >> nn;
		char a[nn+5];
		rep(i,1,nn)
			cin >> a[i];
		vi vr; vi vw;
		rep(i,1,nn)
		{
			if(a[i]=='R')
				vr.pb(i);
			else
				vw.pb(i);
		}
		int ans = 0;
		int n = vr.size();
		int m = vw.size();
		int i = n-1;
		int j = 0;
		while(i>=0 && j<=m && n>0 && m>0)
		{
			if(vw[j]<vr[i])
			{
				ans++;
				i--;
				j++;		
			}		
			else
				break;
		}		
		cout << ans;
	}
}

Measured memory_bytes: 5756
n,d = map(int,input().split())
d2 = d*d
xys = []
for i in range(n):
    xys.append(list(map(int,input().split())))
count = 0
for xy in xys:
    if (xy[0]**2+xy[1]**2)<=d2:
        count += 1
print(count)

Measured memory_bytes: 45452
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll N,T; scanf("%lld %lld",&N,&T);
    vector<ll> t(N); rep(i,N) scanf("%lld",&t[i]);

    using P = pair<ll,ll>;
    vector<P> v(N);
    for(int i=0;i<N;i++){
        v[i].fi = t[i];
        if(i) v[i].fi = max(v[i].fi , v[i-1].se);
        v[i].se = t[i] + T;
    }

    ll ans = 0;
    for(int i=0;i<N;i++){
        ans += v[i].se - v[i].fi;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4992
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

int main(){
	int a , b ; 
	cin >> a >> b ; 
	int ans = 0 ; 
	for(int i=a;i<=b;i++){
		int x = i ; 
		vector<int> v ; 
		while(x!=0){
			v.push_back(x%10); x/=10 ; 
		}
		bool ok = true ; 
		for(int i=0;i<(int) v.size()/2;i++){
			if ( v[i] != v[(int)v.size()-1-i] )
				ok = false ; 
		}
		if ( ok ) ans++;
	}
	cout << ans << endl	;
    return 0 ;
}


Measured memory_bytes: 256
/* ex 9_1
   Sagzar1993 */

#include <stdio.h>
#include <stdlib.h>
//スタックに格納するデータの最大数
#define SIZE 1000

//スタックの定義
typedef struct stack{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

//スタックの初期化
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
    if(stk->count >= stk->size){
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else{
        stk->top--;
        *(stk->top) = elem;
        stk->count++;
    }
}

//データの取り出し
char pop(stack *stk){
    char latest;
    if(stk->count <= 0){
        fprintf(stdout, "Error: stack underflow.\n");
        exit(1);
    }
    else{
        latest = *(stk->top);
        stk->top++;
        stk->count--;
        return latest;
    }
}

int main(void){
    stack stk;
    char inputKey[20], *ptr;
    int i;

    //スタックを初期化（ポインタ渡しで関数にわたすこと）
    initialize_stack(&stk);
    
    scanf("%s", inputKey); //キー入力列の入力
    ptr = inputKey; //ポインタに代入

    //\0まで調べる
    while(*ptr){
        if(*ptr != 'B'){
            //0か1ならスタックに文字を追加
            push(&stk, *ptr);
        }else if(stk.count > 0){
            //Bのとき、スタックが空でなければ最後に追加した文字を取り出し
            pop(&stk);
        }
        ptr++; //次の文字へ
    }
    //スタックの古い方から出力
    for(i = 0; i < stk.count; i++){
        printf("%c", stk.data[SIZE - 1 - i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 1644
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

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

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 int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int A, B, C, X; cin >> A >> B >> C >> X;

  int ans = 0;
  for (int i = 0; i <= A; ++i){
    for (int j = 0; j <= B; ++j){
      for (int k = 0; k <= C; ++k){
        if (500 * i + 100 * j + 50 * k == X) ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
using namespace std;
typedef long long int lli;

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if ((((C - 1) / B)) < ((A + (D - 1)) / D))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596