akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 998244353;

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

    ll n, d;
    cin >> n >> d;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    REP(i, n) a[i] = (a[i]-1)%(d+1);    

    ll g = 0;
    REP(i, n) g ^= a[i];
    if(g != 0) cout << "First" << endl;
    else cout << "Second" << endl;

    return 0;
}



Measured memory_bytes: 4804
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        List<List<Integer>> s = new ArrayList<>(M);
        for(int i = 0; i < M; i++) {
            int k = sc.nextInt();
            List<Integer> l  = new ArrayList<>();
            for(int j = 0; j < k; j++) {
                l.add(sc.nextInt() - 1);
            }
            s.add(l);
        }
        List<Integer> p = new ArrayList<>();
        for(int i = 0; i < M; i++) {
            p.add(sc.nextInt());
        }

        long res = 0;
        for(int bit = 0; bit < (1 << N); bit++) {
            boolean ok = true;
            for(int i = 0; i < M; i++) {
                int count = 0;
                for(int t : s.get(i)) {
                    if(((bit >> t) & 1) == 1) count++;
                }
                if(count % 2 != p.get(i)) {
                    ok = false;
                    break;
                }
            }
            if(ok) res++;
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 36140
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int n;
	string s;
	cin >> n >> s;
	set<int> st[26];
	for (int i = 0; i < n; i++) {
		st[int(s[i] - 'a')].insert(i + 1);
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int que;
		cin >> que;
		if (que == 1) {
			int j;
			char c;
			cin >> j >> c;
			st[int(s[j - 1] - 'a')].erase(j);
			s[j - 1] = c;
			st[(int(c - 'a'))].insert(j);
		}
		else {
			int l, r;
			int co = 0;
			cin >> l >> r;
			for (int k = 0; k < 26; k++) {
				auto o = st[k].set::lower_bound(l);
				if (o != st[k].end() && *o <= r) {
					co++;
				}
			}
			cout << co << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 24196
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
    int x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
    return x*f;
}
inline ll readll(){
    ll x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
    return x*f;
}
const int maxn=2e3+10,inf=0x3f3f3f3f;
int Begin[maxn],Next[maxn<<1],to[maxn<<1],e;
char s[maxn];
int sz[maxn],sum[maxn];
inline void add_edge(int x,int y){
	to[++e]=y;
	Next[e]=Begin[x];
	Begin[x]=e;
}
void dfs_init(int x,int ff){
	sum[x]=sz[x]=0;
	for(int i=Begin[x];i;i=Next[i]) if(to[i]!=ff){
		dfs_init(to[i],x);
		sz[x]+=sz[to[i]];
		sum[x]+=sum[to[i]];
	}
	sum[x]+=sz[x];
	sz[x]+=s[x]-'0';
}
bool dfs(int x,int ff,int Nw){
	int Max=0,ss=0;
	for(int i=Begin[x];i;i=Next[i]) if(to[i]!=ff){
		sum[to[i]]+=sz[to[i]];
		chkmax(Max,sum[to[i]]),ss+=sum[to[i]];
	}
	if(Nw>ss/2) return 0;
	ss-=Max;
	if(Nw<=ss) return 1;
	for(int i=Begin[x];i;i=Next[i]) if(to[i]!=ff && sum[to[i]]==Max) return dfs(to[i],x,Nw-ss);
	return 0;
}
int main(){
	int ans=inf;
	int n=read();
	scanf("%s",s+1);
	REP(i,1,n-1){
		int x=read(),y=read();
		add_edge(x,y),add_edge(y,x);
	}
	REP(i,1,n){
		dfs_init(i,0);
		if(sum[i]&1) continue;
		if(!dfs(i,0,sum[i]/2)) continue;
		chkmin(ans,sum[i]/2);
	}
	printf("%d\n",ans==inf?-1:ans);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

#include <atcoder/math>
using namespace atcoder;

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

    int n, m, a, b;

    int t;
    cin >> t;
    while(t--) {
        cin >> n >> m >> a >> b;
        cout << floor_sum(n, m, a, b) << "\n";
    }

    return 0;
}

Measured memory_bytes: 3620
t_score = 0
h_score = 0

gets.to_i.times{
    x = gets.split
    if x[0] == x[1] then
        t_score += 1
        h_score += 1
        
    elsif x[0] == x.sort[0] then
        h_score += 3
    else
        t_score += 3
    end
}
puts [t_score, h_score].join(" ")


Measured memory_bytes: 6864
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;

int main() {
    int n, x, t;
    cin >> n >> x >> t;
    int k;
    if (n % x == 0) {
        k = n / x;
    } else {
        k = (n / x) + 1;
    }
    cout << t * k << endl;
    
    return 0;
}


Measured memory_bytes: 3632
a,b=map(int,input().split())
a,b=a-1,b-1
l=[300000,200000,100000]
if a<3 and b<3:
  if a==0 and b==0:
    print(400000+l[a]+l[b])
  else:
    print(l[a]+l[b])
else:
  if a<3:
    print(l[a])
  elif b<3:
    print(l[b])
  else:
    print(0)
  # print("HELLO")

Measured memory_bytes: 3064
#include <iostream>
#include<bits/stdc++.h>
#define rep(k,i,n) for(long i=k;i<n;++i)
using namespace std;
int main(void){
    // Your code here!
    string s,t;
    cin>>s>>t;
    int c=0;
    rep(0,i,3)if(s.substr(i,1)==t.substr(i,1))++c;
    cout<<c<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  char s[h+2][w+2];
  int t[h+2][w+2];
  for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++){
      t[i][j]=0;
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin >> s[i][j];
      if(s[i][j]=='#'){
        t[i][j]=9;
        t[i][j-1]++;
        t[i][j+1]++;
        t[i-1][j-1]++;
        t[i-1][j]++;
        t[i-1][j+1]++;
        t[i+1][j-1]++;
        t[i+1][j]++;
        t[i+1][j+1]++;
      }
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(t[i][j]<=8)cout << t[i][j];
      else cout << '#';
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<limits.h>
#define SENTINEL INT_MAX 
using namespace std;
typedef long long ll;
ll counter=0;
void Merge(long long S[],int left,int mid,int right){
  int n1 = mid-left;
  int n2 = right-mid;
  ll L[n1+1];
  ll R[n2+1];
  
  for(int i=0;i<n1;i++){
    L[i] = S[left+i];
  }
  for(int i=0;i<n2;i++){
    R[i]=S[mid+i];
  }
  L[n1]=R[n2]=SENTINEL;
  int i=0;
  int j=0;
  for(int k=left;k<right;k++){
    if(L[i]<=R[j]){
      S[k]=L[i];
      i=i+1;
      counter++;
    }
    else{
      S[k]=R[j];
      j=j+1;
      counter++;
    }
  }
}
  
void Merge_Sort(long long S[],int left,int right){
   
  if(left+1<right){
    int mid = (left+right)/2;
    Merge_Sort(S,left,mid);
    Merge_Sort(S,mid,right);
    Merge(S,left,mid,right);
  }
}
  
  
  
int main(){
  int n;
  ll S[600000];
  
  cin >> n;
    for(int i=0;i<n;i++){
      cin >> S[i];
    }
  
    Merge_Sort(S,0,n);
  
    for(int i=0;i<n;i++){
      cout << S[i];
      if(i != n-1)cout << " ";
    }
    cout << endl;
    cout << counter << endl;
  
  return 0;
}


Measured memory_bytes: 10892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl 	"\n"

typedef vector< ll > 	vi;
typedef vector< vi > 	vvi;
typedef pair< ll,ll > 	ii;
#define pb 		push_back
#define all(c) 		(c).begin(),(c).end()
#define tr(c,i) 	for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) 	((c).find(x) != (c).end())

#define MOD 	1000000007
#define INF 	(int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))

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

	ll n, k;
	cin>>n>>k;
	ll dig = (ll)(floor( log(n) /  
                         log(k)) + 1);  
	cout<<dig;
	
	return 0;
}

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

int main() {
  int n;
  int count =0;
  cin >> n;
  
  string s;
  cin >> s;
  for(int i=0; i<n-2;i++){
    if(s.substr(i,3) =="ABC")
      count++;
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define uint unsigned int


using namespace std;

const int MOD = 998244353;

inline int lgput(int a, int b) {
	int ans = 1;
	while(b > 0) {
		if(b & 1) ans = (1LL * ans * a) % MOD;
		b >>= 1;
		a = (1LL * a * a) % MOD;
	}
	return ans;
}

inline void solve(vector<int> &sum, vector<vector<int>> &g, int n) {
	vector<int> grundy(n + 1, 0);
	for(int i = n; i >= 1; i--) {
		set<int> vals;
		for(auto it : g[i]) {
			if(it > i) {
				vals.insert(grundy[it]);
			}
		}
		int j = 0;
		while(vals.find(j) != vals.end()) {
			j++;
		}
		grundy[i] = j;
	}
	sum.resize(*max_element(grundy.begin(), grundy.end()) + 1);
	for(int i = 1; i <= n; i++) {
		sum[grundy[i]] = (sum[grundy[i]] + lgput(10, 18 * i)) % MOD;
	}
}

int main() {
#ifdef HOME
    ifstream cin("A.in");
    ofstream cout("A.out");
#endif
    int n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

   	// dp0[x][y][z] =  0 (poti sa-l iei pe x, y, z)
   	//			    != 0 (nu poti sa-l iei)	
   	// dp0[x][y][z] = grundy(x) ^ grundy(y) ^ grundy(z)
    // grundy(x) <= sqrt(M)

    cin >> n;
    vector<vector<int>> sum(3);
    for(int t = 0; t < 3; t++) {
    	int m; cin >> m;
    	vector<vector<int>> g(n + 1);
    	while(m--) {
    		int x, y; cin >> x >> y;
    		g[x].push_back(y);
    		g[y].push_back(x);
    	}
    	solve(sum[t], g, n);
    }
    int ans = 0;
    for(int a = 0; a < (int)sum[0].size(); a++) {
    	for(int b = 0; b < (int)sum[1].size(); b++) {
    		int c = (a ^ b);
    		if(c < (int)sum[2].size()) {
    			ans = (ans + 1LL * sum[0][a] * (1LL * sum[1][b] * sum[2][c] % MOD)) % MOD;
    		}
    	}
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 5840
# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(10000000)

#const
dxdy=((1,0),(0,1))
# my functions here!
def pin(type=int):
    return map(type,input().rstrip().split())

def resolve():
    N,K=pin()
    x=N%K
    print(min(K-x,x))
"""         
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じ,るの忘れてるだろ
"""
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """7 4"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2 6"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """1000000000000000000 1"""
        output = """0"""
        self.assertIO(input, output)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 6464
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var a = ("1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51").Replace(" ", string.Empty).Split(',');
            var K = Console.ReadLine().ToInt();
            Console.WriteLine(a[K - 1]);
            Console.ReadLine();
        }
    }
}

public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }
}



Measured memory_bytes: 11092
def judge(x):
  if x==4 or x==6 or x==9 or x==11:
    y = 'a'
  elif x==2:
    y = 'b'
  else:
    y = 'c'
  return y
 
a,b = map(int,input().split())
if judge(a) == judge(b) :
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
n,t = map(int, input().split())
Task=[]
for i in range(n):
    nm,le= map(str, input().split())
    Task.append([nm,le])
T=0
while n >0:
    k = Task.pop(0)
    k[1]=int(k[1])
    if k[1] > t:
        k[1]=k[1]-t
        T=T+t
        Task.append(k)
        n = len(Task)
    else:
        T=T+k[1]
        k[1]=T
        print(' '.join(map(str, k)))
        n = len(Task)

Measured memory_bytes: 15572
#include<stdio.h>
#include<string.h>
int main(void){
  char s[4], a[]="AAA", b[]="BBB";
  int i;
  scanf("%s",s);
  if(strcmp(s,a)==0 ||strcmp(s,b)==0){
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(f) (f).begin(),(f).end()
#define allr(f) (f).rbegin(),(f).rend()
const int mod = 1e9+7, A = 1e5+5;
int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n, m;
  cin >> n >> m;
  cout << (m >= n? "Yes":"No");
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

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

#####BitCount#####
def bit_count(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#############
# Main Code #
#############

N = inputI()
H = inputIL()

b = 0
c = 0
for h in H:
  if h>= b:
    b= h
    c +=1
    
print(c)

Measured memory_bytes: 64876
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int n, q; cin >> n >> q;
    vector<char> s(n+1);
    repr(i, 1, n+1) cin >> s[i];
    vector<char> t(q), d(q);
    rep(i, q) cin >> t[i] >> d[i];

    int ans = n;

    int ok = 0, ng = n+1;
    auto check = [&](auto x) -> int {
        // 0:left 1:stay 2:right
        if (x==0) return 0;
        else if (x==n+1) return 2;
        rep(i, q) {
            if (t[i] == s[x]) {
                if (d[i] == 'L') x--;
                else x++;
            }
            if (x==0) return 0;
            else if (x==n+1) return 2;
        }
        return 1;
    };
    while(ng-ok > 1) {
        int mid = (ok+ng) / 2;
        (check(mid) == 0? ok:ng) = mid;
    }
    ans -= ok;

    ok = n+1, ng = 0;
    while(ok-ng > 1) {
        int mid = (ok+ng) / 2;
        (check(mid) == 2? ok:ng) = mid;
    }
    ans -= (n+1) - ok;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 896
#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> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
//long long ccw(const Point& A, const Point& B, const Point& C) {
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	vector<string> v;
	int n; cin >> n;
	rep(i, n) {
		string tmp; cin >> tmp;
		sort(tmp.begin(), tmp.end());
		v.push_back(tmp);
	}
	sort(v.begin(), v.end());
	ll ans = 0;
	ll cnt = 1;
	rep(i, (int)v.size()) {
		if (i == 0)continue;
		if (v[i] == v[i - 1]) {
			cnt += 1;
		}
		else {
			ans += cnt * (cnt - 1) / 2;
			cnt = 1;
		}
	}

	ans += cnt * (cnt - 1) / 2;
	cout << ans << '\n';

}


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

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

    vector<double> p(N);
    for (int i = 0; i < N; i++)
    {
        cin >> p.at(i);
    }

    ll sum = 0;
    for (int i = 0; i < K; i++)
    {
        sum += p.at(i);
    }
    ll sum_max = sum;
    for (int i = K; i < N; i++)
    {
        sum = sum - p.at(i - K) + p.at(i);
        sum_max = max(sum, sum_max);
    }
    cout << fixed << setprecision(10);
    cout << 0.5 * (sum_max + K) << endl;
}

Measured memory_bytes: 1792
#include <iostream> 
#include <vector> 
using namespace std; 
int main(){ 
   int N; 
   cin>>N; 
   vector<int> A(N); 
   for(int i=0;i<N;i++) cin>>A[i];

   vector<int> stu(N); 
   for(int i=0;i<N;i++) 
     stu[A[i]-1]=i+1; 
   for(int i=0;i<N;i++) 
     cout<<stu[i]<<endl; 
}


Measured memory_bytes: 1664
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);
	static String A = "1100000011";
	static String B = "10000000100000001";
	static String C = "1111";
	static String D = "1000000110000001";
	static String E = "11000000011";
	static String F = "100000001100000001";
	static String G = "110000011";
	static String[] blocks = {A, B, C, D, E, F, G};
	static String[] dic = {"A", "B", "C", "D", "E", "F", "G"};

	public static void main(String[] args){

		while(scan.hasNext()){
			StringBuffer sb = new StringBuffer();
			for(int i = 0; i < 8; i++){
				sb.append(scan.next());
			}
			System.out.printf("%s\n", dic[solve(sb.toString())]);
		}
	}

	public static int solve(String str){
		for(int i = 0; i < 8 * 8; i++){
			for(int j = 0; j < 7; j++){
				if(8 * 8 < i + blocks[j].length()){
					continue;
				}
				String s = str.substring(i, i + blocks[j].length());
				if(s.equals(blocks[j])){
					return j;
				}
			}
		}
		return -1;
	}
}

Measured memory_bytes: 28388
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int N;
int t[100001],x[100001],y[100001];
int main(){
  cin >> N;
  for(int i=1;i<=N;i++)cin >> t[i] >> x[i] >> y[i];
  for(int i=1;i<=N;i++){
    int tt=t[i]-t[i-1];
    int d=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
    if(tt<d || tt%2!=d%2){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

template<typename T>
struct BinaryIndexedTree{
    vector<T> data;
    int sz;

    BinaryIndexedTree(int n){
        sz = n + 2;
        data.assign(sz, 0);
    }

    void add(int i, T x){
        ++i;
        while(i < sz){
            data[i] += x;
            i += i & -i;
        }
    }

    // [0, i] の区間和
    T sum(int i){
        T res = 0;
        ++i;
        while(i > 0){
            res += data[i];
            i -= i & -i;
        }
        return res;
    }

    // [l, r) の区間和
    T sum(int l, int r){
        return sum(r - 1) - sum(l - 1);
    }

    // val 以上を満たす 0-indexed の位置を返す
    int lower_bound(T val){
        // if(val <= 0)    return -1;
        int res = 0;
        int n = 1;
        while(n < sz)   n <<= 1;
        for(int k = n >> 1; k > 0; k >>= 1){
            if(res + k < sz && data[res + k] < val){
                val -= data[res + k];
                res += k;
            }
        }
        return res;     // 1-indexed であれば、res + 1 を返す
    }
};

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

    string s;
    int k;
    cin >> s >> k;
    int n = s.length();
    vector<vector<int>> pos(26);
    vector<int> c(26, 0);
    for(int i = 0; i < n; ++i)  pos[s[i] - 'a'].emplace_back(i);
    BinaryIndexedTree<int> bit(n);
    string ans = "";
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < 26; ++j){
            if(c[j] == (int)pos[j].size())  continue;
            int p = pos[j][c[j]];
            int v = p - bit.sum(p);
            if(k >= v){
                k -= v;
                ans += ('a' + j);
                ++c[j];
                bit.add(p, 1);
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5196
#include<stdio.h>
#include<stdlib.h>
int main()
{
  char s[6];
  scanf("%s",s);
  if(strcmp(s,"Sunny")==0)
  {
    printf("Cloudy\n");
    return 0;
  }
  else if(strcmp(s,"Cloudy")==0)
  {
    printf("Rainy\n");
    return 0;
  }
  else
  {
    printf("Sunny\n");
    return 0;
  }
  
  return 0;
}

Measured memory_bytes: 128
n = int(input())
p = list(map(int, input().split()))
count = 0

for i in range(1,n-1):
  if p[i] > min(p[i-1],p[i+1]) and p[i] < max(p[i-1],p[i+1]):
    count += 1
    
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i = 0; i < N; i++){
    cin >> H.at(i);
  }
  bool flag = false;
  bool ans = true;
  for(int i = 1; i < N; i++){
    if(H.at(i)+1 < H.at(i-1)){
      ans = false;
      break;
    }else if(H.at(i) + 1 == H.at(i-1)){
      if(flag){
	ans = false;
	break;
      }else{
	flag = true;
      }
    }else if(H.at(i) > H.at(i-1)){
      flag  = false;
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define in(type,a) type a;cin >> a

using ll = long long;
int main() {
    in(string, s);
    if ((s[0]==s[1])||(s[1]==s[2])||(s[2]==s[3])) {
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;
ll mod=1000000007;

int main()
{
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    
    ll ans=0;
    for(int i=0; i<N; i++){
        ll cnt1=0, cnt2=0;
        for(int j=0; j<N; j++){
            if(i<j && A[i]>A[j]) cnt1++;
            if(A[i]>A[j]) cnt2++;
        }
        ll tmp=K*(K-1)/2%mod;
        ans=ans+cnt1*K%mod+cnt2*tmp%mod;
        ans%=mod;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    ll n, a, b;
    scanf("%lld%lld%lld", &n, &a, &b);
    if (a > b) {
        printf("0\n");
        return;
    }
    if (n == 1 && a != b) {
        printf("0\n");
        return;
    }
    ll ans = (b*n - (b - a)) - (a*n + (b - a)) + 1;
    printf("%lld\n", ans);
    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 1664
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = [0] *(10**5+1)
    total = 0
    for a in map(int, readline().split()):
        total += a
        A[a] += 1


    Q = int(readline())
    for _ in range(Q):
        b, c = map(int, readline().split())
        total += A[b]*(c-b)
        print(total)
        A[c] += A[b]
        A[b] = 0


if __name__ == '__main__':
    main()


Measured memory_bytes: 15772
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



string tostr(char s[], int a, int n) {
    string res = "";
    for (int i = a; i < a+n; ++i) {
        if (s[i] != 0) res += s[i];
    }
    return res;
}




int n;

string solve(string str) {
	for (int i = 1; i < 26; ++i) {
		if (i % 2 == 0) continue;
		if (i % 13 == 0) continue;
		for (int j = 0; j < 26; ++j) {
			string next = "";
			for (int k = 0; k < str.size(); ++k) {
				if (str[k] == ' ') next += " ";
				else {
					int is = str[k] - 'a';
					int in = (is * i + j) % 26;
					char cn = 'a' + in;
					next += cn;
				}
			}

			bool con = false;
			for (int k = 0; k < next.size()-3; ++k) {
				string sub = next.substr(k, 4);
				if (sub == "this" || sub == "that") {
					con = true;
					break;
				}
			}
			if (con) {
				return next;
			}
		}
	}
	return str;
}



int main() {
	cin >> n; cin.ignore();
	string str;
	for (int i = 0; i < n; ++i) {
		getline(cin, str);
		//str = "y eazqyp pnop pngtg ye obmpngt xmybp mr lygw";
        cout << solve(str) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1220
n,m,x=map(int,input().split())
a=[[0]*(m+1)]*n
for i in range(n):
    a[i]=list(map(int,input().split()))
b=[0]*(m+1)
flag=True
ans=-1
for i in range(2**n):
    flag=True
    b=[0]*(m+1)
    for j in range(n):
        if(i>>j & 1):
            for y in range(m+1):
                b[y]=b[y]+a[j][y]
    for y in range(1,m+1):
        if(b[y]<x):
            flag=False
            break
    if(flag):
        if ans<0 or b[0]<ans:
            ans=b[0]
print(ans)

Measured memory_bytes: 9244
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        try (final Scanner scanner = new Scanner(System.in)) {

            final int m = scanner.nextInt();
            final int n = scanner.nextInt();

            final List<List<Integer>> table = new LinkedList<>();
            final List<Integer> pr = new LinkedList<>();

            for (int i = 0; i < m; i++) {
                table.add(new LinkedList<>());
                pr.add(0);
            }

            for (int i = 0; i < n; i++) {
                int x = scanner.nextInt();
                int y = scanner.nextInt();
                x--;
                y--;
                table.get(x).add(y);
                pr.set(y, pr.get(y) + 1);
            }

            for (int i = 0; i < m; i++) {
                for (int j = 0; j < m; j++) {
                    if (pr.get(j) == 0) {
                        System.out.println("" + (j + 1));

                        for (Integer succ : table.get(j)) {
                            pr.set(succ, pr.get(succ) - 1);
                        }

                        pr.set(j, pr.get(j) - 1);
                    }
                }
            }

        }

    }

}



Measured memory_bytes: 26348
#include <bits/stdc++.h>
using namespace std;
int n,k;
string s;
int main(){
    cin>>n>>s>>k;
    char z = s[k-1];
    for(int i=0;i<n;i++){
        if(s[i] == z) continue;
        s[i] = '*';
    }
    cout<<s<<endl;
}   

Measured memory_bytes: 256
N, K = map(int, input().split())
p = list(map(int, input().split()))
# pのうち、小さい方から順にK個足していく
# pを小さい順に並べる
newlist = sorted(p)
# print(newlist)
# K個足していく
ans = 0
for i in range(K):
  # print(newlist[i])
  ans += newlist[i]
print(ans)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n,k;

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

  cin>>n>>k;
  cout<<(n-k+1)<<endl;

  return 0;
}


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

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

  int N;
  cin >> N;
  vector<int> cnt(N + 1, 0);
  for (int i = N; i >= 1; i--) {
    for (int j = i; j <= N; j += i) {
      cnt[j] += 1;
    }
  }
  lint ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += 1ll * i * cnt[i];
  }
  cout << ans << "\n";
  return 0;  
}


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

char changeChar(char c){
    if('a' <= c && c <= 'z'){
        return c - 0x20;
    }
    else if('A' <= c && c <= 'Z'){
        return c + 0x20;
    }
    return c;
}

int main(){

    string s;
    getline(cin, s);

    for(int i = 0; i < s.length(); ++i){
        s[i] = changeChar(s[i]);
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include <random>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,q;
    string s;
    cin>>n>>s>>q;
    ll k[100];
    rep(Q,q){
        ll k;
        cin>>k;
        ll ans=0;
        ll d=0,m=0,c=0,dm=0;
        rep(i,n){
            if(s[i]=='C'){
                ans+=dm;
            }
            else if(s[i]=='D'){
                d++;
            }
            else if(s[i]=='M'){
                m++;
                dm+=d;
            }
            if(i>=k-1){
                if(s[i-k+1]=='D'){
                    dm-=m;
                    d--;
                }
                else if(s[i-k+1]=='M'){
                    m--;
                }
            }
        }
        cout<<ans<<endl;
    }    
    return 0;
}


Measured memory_bytes: 1948
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}*/
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 
 












int main()
{
     ll n;
     cin>>n;
     ll res=0LL;
     if(n>=3)res+=n-1;
     for(ll i=2;i<=sqrt(n);i++)
     {
          if(n%i==0)
          {
               ll t=i-1;
               ll q=n/t,rem=n%t;
               if(q==rem){res+=t;}
               if(i*i!=n)
               {
                    t=n/i;t=t-1;
                    q=n/t;rem=n%t;
                    if(q==rem){res+=t;
                    }
               }
          }
               
     }
     cout<<res;
     
}







 
 

















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

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 INF = 1LL << 60;

int n;
int a[110];

int bubbleSort(int a[], int n)
{
  int cnt = 0;
  REPR(i, n-1, 1){
    rep(j, i){
      if(a[n-2-j] > a[n-1-j]){
        swap(a[n-2-j], a[n-1-j]);
        cnt++;
      }
    }
  }
  return cnt;
}


int main(){
  cin >> n;
  rep(i, n) cin >> a[i];
  
  int ans = bubbleSort(a, n);

  rep(i, n){
    if(i>0) cout << " ";
    cout << a[i];
  }
  cout << endl;
  cout << ans << endl;

  return 0;
}




Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
using ll = long long;
int main(){ 
    ll a,b;
    cin>>a>>b;
    
    
    if(a==1&&b==1){
        cout<<1000000;
    }else if(a==1&&b==2){
        cout<<500000;
    }else if(a==1&&b==3){
        cout<<400000;
    }else if(a==2&&b==1){
        cout<<500000;
    }else if(a==3&&b==1){
        cout<<400000;
    }else if(a==2&&b==2){
        cout<<400000;
    }else if(a==2&&b==3){
        cout<<300000;
    }else if(a==3&&b==2){
        cout<<300000;
    }else if(a==3&&b==3){
        cout<<200000;
    }else if(a==1){
        cout<<300000;
    }else if(a==2){
        cout<<200000;
    }else if(a==3){
        cout<<100000;
    }else if(b==1){
        cout<<300000;
    }else if(b==2){
        cout<<200000;
    }else if(b==3){
        cout<<100000;
    }else{
        cout<<0;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
template <class T>
int upb(V<T> &v, const T &x) { return upper_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
//////////////////////////////////////////////INSERT ABOVE HERE
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    V<int> a(n);
    read(a);
    for (int i = k; i < n; i++) {
        if (a[i] > a[i - k]) {
            cout << "Yes" << newl;
        } else {
            cout << "No" << newl;
        }
    }
}

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

void solve(){
    string s;
    cin >> s;
    string ans = "";
    for(char i:s) {
        if(i != 'B')
            ans += i;
        else if(ans.size())
            ans.pop_back();
    }
    cout <<  ans << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t =1;
    while(t--)
        solve();
    return 0;
}



Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void){
  int n;
  vector<int>num;

  while(cin >> n,~n){
    if(n==0){
      cout << 0 << endl;
      continue;
    }
    for(int i=0;n>0;i++){
      num.push_back(n%4);
      n/=4;
    }
    for(int i=num.size()-1;i>=0;i--)
      cout << num[i];
    cout << endl;
    num.clear();
  }

  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main(void){
    int a[3], w, i, j;
    scanf("%d %d %d", &a[0], &a[1], &a[2]);
    for(i = 0; i < 2; i++){
        for(j = i+1; j < 3; j++){
            if(a[i] > a[j]){
                w = a[i];
                a[i] = a[j];
                a[j] = w;
            }
        }
    }
    printf("%d %d %d\n", a[0], a[1], a[2]);
    return 0;
}


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

int main(){
  int N;
  int a=0;
  cin >> N;
  vector<int> p(N);
  vector<int> n(N);
  for(int i=0;i<N;i++){
    cin >> p.at(i);
    if(p.at(i)-i != 1){
      a++;
    }
  }
  if(a==0 || a==2){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

int main(void) {
	int num, i, ans = 0;
	string s;
	cin >> s;
	num = s.size();
	for (i = 0; i < num / 2; i++) {
		if (s[i] != s[num - i - 1])
			ans++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
    ll k,a,b;
    cin>>k>>a>>b;
    ll ans=0;
    if(b<=a+2) ans+=k+1;
    else{
        if(k<=a-1) ans+=k+1;
        else{
            ans+=a;k-=(a-1);
            ans+=(k/2)*(b-a);
            if(k%2) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int div(int n)
{
	int cnt = 0;
	while (n % 100 == 0) {
		n /= 100;
		cnt++;
	}
	return cnt;
}

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

	int nb = 0;
	int i = 0;
	while (nb < N) {
		i++;
		if (div(i) == D) {
			nb++;
		}
	}

	cout << i << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;

#define MOD 998244353


ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}
  
  

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(ll i = 0; i<n; i++){
        cin>>a[i];
    }
    
    for(ll i = 0; i<n; i++){
        if(a[i]%2 == 0){
            if(a[i]%6 == 0 || a[i]%10 == 0){
                continue;
            }
            else cout<<"DENIED"<<endl;
            return 0;
        }
    }
    cout<<"APPROVED"<<endl;
    return 0;
}
    
    



Measured memory_bytes: 256