akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <string>
#include <sstream>
#include <iomanip>
#include <functional>
 
using namespace std;
 
 
int main() {
    string a = "CODEFESTIVAL2016";
    string b;
    cin >> b;
    int cnt = 0;
    for(int i=0; i<a.size(); i++)
        if(a[i]!=b[i]) cnt++;
    cout << cnt << endl;
    return 0;
}

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

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    for (int i=A; i<=min(A+K-1, B); i++) cout << i << endl;
    for (int i=max(B-K+1, A+K); i<=B; i++) cout << i << endl;
}

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

int main_()
{
    int N;
    vector<int> Ps;
    cin >> N;
    copy_n(istream_iterator<int>(cin), N, back_inserter(Ps));
    int min_num = numeric_limits<int>::max();
    int count = 0;
    for (auto p : Ps)
    {
        if (min_num > p)
        {
            count++;
            min_num = p;
        }
    }

    cout << count << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 1400
n, q = map(int,input().split())
s = input()
l = []
r = []
for _ in range(q):
    a, b = map(int,input().split())
    l.append(a)
    r.append(b)

acsum = [0]*(n+1)
for i in range(len(s) - 1):
    if s[i:i+2] == "AC":
        acsum[i+2] = acsum[i+1] + 1
    else:
        acsum[i+2] = acsum[i+1]

for le, re in zip(l, r):
    print(acsum[re] - acsum[le])

Measured memory_bytes: 14240
import java.util.*;

public class Main {

    public static void main(String[] args) {
        //
        //Compute c1=new Compute();//計算系
        //変数
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        int answer = 0;
        //String answer="No";
        //StringBuilder answer=new StringBuilder();
        //List<Integer> list = new ArrayList<>();
        //int array[] = new int[];

        //入力
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a=sc.nextInt();
        int b=sc.nextInt();

        int c=a*n;
        answer=Math.min(b,c);


        //出力
        //BigDecimal bd = new BigDecimal(answer);
        //System.out.println(bd.setScale(12,BigDecimal.ROUND_DOWN));
        //System.out.println(String.format("%.0f",answer));
        System.out.println(answer);
    }
}

Measured memory_bytes: 21076
d = 10**9 + 7
n = gets.to_i
a = gets.split.map(&:to_i).sort
if a == n.times.map{|i| n - 1 - (n - i - 1) / 2 * 2}
	puts 2 ** (n / 2) % d
else
	puts 0
end

Measured memory_bytes: 10480
import java.util.Scanner;

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

    if(N == 22){
      System.out.println("Christmas Eve Eve Eve");
    }else if(N == 23){
      System.out.println("Christmas Eve Eve");
    }else if(N == 24){
      System.out.println("Christmas Eve");
    }else if(N == 25){
      System.out.println("Christmas");
    }
}
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main{
	public static long stoneGame(int[] piles) {
		long[][] dp = new long[piles.length + 1][piles.length];

		for (int gap = 0; gap < piles.length; gap++) {
			for (int i = 0, j = i + gap; j < piles.length; j++, i++) {
				if (gap == 0) {
					dp[i][j] = piles[i];
				} else {
					dp[i][j] = Math.max(piles[i] - dp[i + 1][j], piles[j] - dp[i][j - 1]);
				}

			}

		}

		return dp[0][piles.length - 1];
	}

	static long mod = (long) (1e9 + 7);

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int k = scn.nextInt();

		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scn.nextInt();
		}
		long dp[][] = new long[n + 1][k + 1];
		long sum[][] = new long[n + 1][k + 1];
		for (int j = 0; j <= k; j++) {
			sum[0][j] = 1;
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= k; j++) {
				if (j - a[i - 1] > 0) {
					dp[i][j] = (sum[i - 1][j] - sum[i - 1][j - a[i - 1] - 1] + mod) % mod;
				} else {
					dp[i][j] = sum[i - 1][j];
				}
				sum[i][j] = (dp[i][j]) % mod;
				if (j > 0) {
					sum[i][j] = (sum[i][j - 1] + sum[i][j]) % mod;
				}
			}
		}

		System.out.println(dp[n][k] % mod);

	}

}


Measured memory_bytes: 244176
#!/usr/bin/env python3
ans=0
n=int(input())
A=list(map(int,input().split()))
B=[0]*(n+1)
for i in range(n):
    B[A[i]]=i+1
LL=[int(i) for i in range(n+2)]
RR=[int(i) for i in range(n+2)]
for i in range(n,0,-1):
    l=LL[B[i]]
    r=RR[B[i]]
    ans+=(B[i]-l+1)*(r-B[i]+1)*i
    LL[r+1]=l
    RR[l-1]=r
print(ans)


Measured memory_bytes: 88528
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)cin>>a[i];
	ll dp[n][n];
	for(ll i=0;i<n;i++)dp[i][i]=a[i];
	for(ll l=2;l<=n;l++)
	{
		for(ll i=0;i<n-l+1;i++)
		{
			ll j=i+l-1;
			dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
		}
	}
	cout<<dp[0][n-1]<<endl;
	return 0;
}

Measured memory_bytes: 70400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
int H,W,h,w,ans;
int main(){
    cin>>H>>W;
    cin>>h>>w;
    ans = H*W;
    ans -= ((h*W) + (H*w) - h*w);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
////#include <bits/stdc++.h>
//#include <iostream>
//#include <algorithm>
//using namespace std;
//
//long long n,ans;
//int main() {
//    while(cin >> n) {
////          cout << __gcd(n,(long long)2) << endl;
//        if(__gcd((long long)2,n) == 1)
//            cout << (long long)2 * n << endl;
//        else {
//            cout << n << endl;
//
//        }
//    }
//    return 0;
//}
//#include <bits/stdc++.h>
//#include <iostream>
//#include <algorithm>
//using namespace std;
//
////long long n,ans;
//int n,x;
//int main() {
//    while(cin >> n) {
//            int Max = -99;
//            int Min = 2e9;
//            for(int i = 0;i < n;i++){
//                    cin >> x;
//                 Max = max(x,Max);
//                 Min = min(x,Min);
//            }
//            cout << Max - Min << endl;
//    }
//    return 0;
//}




#include <iostream>
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace std;
const int Maxn = 2e5 + 100;
int n,x;
int a[Maxn];
map<int,int>m;
int main() {
    while(cin >> n) {
        m.clear();
        for(int i = 0; i < n; i++)
            cin >> a[i];
        long long  ans = 0;
        int b = 0;
        int q = 1;
        for(int i = 0; i < n; i++) {
            a[i] -= q++;
            m[a[i]]++;
        }
        sort(a,a + n);
        int cnt = 0;
        for(int i = 0; i < n; i++) {
            if(a[i] == 0) continue;
            if(m[a[i]] && m[-a[i]])
                cnt++,m[a[i]]--,m[-a[i]]--;
        }
        int Max = 0;
        int data;
        if(cnt == n) b = 0;
        else {
            b = a[n / 2];
//            for(map<int,int>::iterator it = m.begin(); it != m.end(); it++)  {
////                if(it -> first == 0) continue;
//                if(Max < it -> second) {
//                    Max = it -> second;
//                    data = it -> first;
//                }
            }
//            b = data;
//        }
//        cout << b <<endl;
        for(int i = 0; i < n; i++) {
            ans += abs(a[i] - b);
        }
        cout << ans << endl;
    }
    return 0;
}
 

Measured memory_bytes: 19840
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];
    auto ks = new double[](1001);
    double k = 0;
    foreach (i; 1..1001) {
        k += i;
        ks[i] = k/i;
    }
    double[] ps;
    foreach (p; readln.split.to!(int[])) ps ~= ks[p];
    double p = 0;
    foreach (i; 0..K) p += ps[i];
    auto max_p = p;
    foreach (i; K..N) {
        p = p - ps[i-K] + ps[i];
        max_p = max(max_p, p);
    }
    writefln("%.10f", max_p);
}

Measured memory_bytes: 11304
N,A,B=map(int,input().split())
res = 0

def check(a):
  sumsum = 0
  while a > 0:
    sumsum += a % 10
    a = a // 10
  return sumsum

for i in range(N+1):
  if A<=check(i)<=B:
    res += i
print(res)

Measured memory_bytes: 9100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int div;
		int cnt = 0;

		for(div = a; div <= b; div++) {

			if(c%div == 0){

				cnt++;

			} else {}
		}
		System.out.println(cnt);
		sc.close();
	}

}

Measured memory_bytes: 26292
s=input()
before=""
while len(s):
    if s[0:5]=="dream":
        if s[0:7]=="dreamer":
            before="er"
            s=s[7:]
        else:
            before=""
            s=s[5:]
    elif s[0:5]=="erase":
        if s[0:6]=="eraser":
            before="er"
            s=s[6:]
        else:
            before=""
            s=s[5:]
    elif before=="er":
        if s[0:3]=="ase":
            if s[0:4]=="aser":
                before="er"
                s=s[4:]
            else:
                before=""
                s=s[3:]
        else:
            break
    else:
        break
if len(s):
    print("NO")
else:
    print("YES")

Measured memory_bytes: 3188
#!/usr/bin/env python3

N, W = list(map(int, input().split()))
item_list = []

for _ in range(N):
    w, v = list(map(int, input().split()))
    item_list.append((w, v))

dp_table = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(1, N + 1):
    w, v = item_list[i - 1]
    for j in range(W + 1):
        # 品物iを入れない場合
        before_best_value = dp_table[i - 1][j]
        dp_table[i][j] = before_best_value
        # 品物iを入れる場合
        if j - w < 0:
            continue
        value = dp_table[i - 1][j - w] + v
        best_value = max(before_best_value, value)
        dp_table[i][j] = best_value

ans = max(dp_table[-1])
print(ans)


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 1001001001;

int main(){
	int n, m; cin >> n >> m;
	vl h(n); rep(i,n) cin >> h[i];
	vector<bool> d(n, true);
	rep(i,m){
		int a, b; cin >> a >> b;
		a--; b--;
		if(h[a] <= h[b]) d[a] = false;
		if(h[a] >= h[b]) d[b] = false;
	}
	int ans = 0;
	rep(i,n){
		if(d[i]) ans ++;
	}
	cout <<ans << endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
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);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    unordered_map<string, ll> mp;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        sort(all(s));
        ans += mp[s];
        mp[s]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 10660
#include "bits/stdc++.h"
using namespace std;

const int N = 1e5 + 5;
int dp[N];

int main()
{
        int n;
        scanf("%d", &n);
        for(int i = 0; i < n; i++) {
                int x;
                scanf("%d", &x);
                dp[x]++;
        }

        int mx = 0;

        for(int i = 1; i < N; i++) {
                int temp = dp[i] + dp[i - 1] + dp[i + 1];
                mx = max(temp, mx);
        }
        printf("%d\n", mx);

        return 0;
}


Measured memory_bytes: 640
import sys
def input(): return sys.stdin.readline().rstrip()

from collections import deque

def main():
  S = deque(input())
  N = int(input())

  d = True
  for i in range(N):
    list = input().split()
    if list[0] == '1':
      d = not d
      continue
    if list[1] == '1':
      S.appendleft(list[2]) if d else S.append(list[2])
      continue
    S.append(list[2]) if d else S.appendleft(list[2])
  return ''.join(S) if d else ''.join(S)[::-1]

if __name__ == '__main__':
  print(main())

Measured memory_bytes: 8564
#include <bits/stdc++.h>
#include "atcoder/all"
using namespace std;
using namespace atcoder;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
    { for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
    { os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
    { cerr << " " << H; debug_out(T...); }
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int _max(int a, int b) {return max(a, b);}
int e() {return 0;}

segtree<int, _max, e> seg(330000);

void solve() {
    int n, k;
    cin >> n >> k;
    while(n--) {
        int a;
        cin >> a;
        int l = max(0, a - k);
        int r = min(330000, a + k + 1);
        int m = seg.prod(l, r);
        seg.set(a, m + 1);
    }
    cout << seg.all_prod() << endl;
}

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


Measured memory_bytes: 8376
#include <bits/stdc++.h>
using namespace std;
#define fl(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
#define mx 205
#define inf 2e9
#define nitro ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int main()
{
    nitro ;
    string s,t;
    cin>>s>>t;
    int n,m;
    cin>>n>>m;
    string te;
    cin>>te;
    if(te == s){
        cout<<n-1<<" "<<m<<endl;
    } 
    else{
        cout<<n<<" "<<m-1<<endl;
    }
}


Measured memory_bytes: 256
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////
    int N;
    cin >> N;
    int l,r;
    int S=0;
    for (int i=0;i<N;i++){
        cin >> l>>r;
        S+=r+1-l;
        }
    cout<<S<<endl;
    
    
    
    return 0;
}

Measured memory_bytes: 380
x,n = map(int, input().split())
if n != 0:
    num_list = list(map(int, input().split()))
    max_num = 100
else:
    num_list = []
    max_num = 10
flag = 0
for i in range(0,max_num):
    a = x - i
    b = x + i
    # print(a, b)
    if not(a in num_list):
        print(a)
        flag = 1
        break
    if not(b in num_list):
        print(b)
        flag = 1
        break
    if flag == 1:
        break

Measured memory_bytes: 9160
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int n, x;
	cin >> n >> x;
	vector<int> m(n);
	int rem = x, ans = n, minv = INF;
	rep(i, 0, n) {
		cin >> m[i];
		rem -= m[i];
		minv = min(minv, m[i]);
	}
	ans += rem / minv;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    if n % 2 != 0 {
        println!("No");
        return;
    }
    let s: Vec<char> = it.next().unwrap().chars().collect();
    let m = n / 2;
    if s[..m] == s[m..] {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    run();
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int read( ){
	int x=0,y=1;char ch=' ';
	for(;(ch!='-' && (ch>'9' || ch<'0'));ch=getchar( ));
	if(ch=='-')y=-1,ch=getchar( );
	for(;ch>='0' && ch<='9';ch=getchar( ))x=x*10+ch-48;
	return x*y;
}
const int N=5e3+10;
int n;
char s[N];
unsigned long long f[N],bin[N];
map<unsigned long long,int>mp;
bool chk(int len){
	mp.clear( );
	unsigned long long k;int x,y;
	for(register int i=1;i<=n-len+1;++i){
		x=i;y=i+len-1;
		k=f[y]-f[x-1]*bin[len];
		if(mp[k]){
			if(x>mp[k])return 1;
		}
		else mp[k]=y;
	}
	return 0;
}
signed main( ){
	int x,y,z,k;
	n=read( );
	scanf("%s",s+1);
	for(register int i=1;i<=n;++i)
		f[i]=f[i-1]*131+s[i];
	bin[0]=1;
	for(register int i=1;i<=n;++i)bin[i]=bin[i-1]*131;
	int L=0,R=n;
	while(L<R){
		int mid=(L+R+1)>>1;
		if(chk(mid))L=mid;
		else R=mid-1;
	}
	printf("%d\n",L);
	return 0;
}

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

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]


    n = int(lines[0])

    h = [int(e) for e in lines[1].split(" ")]

    return (n, h)


def solve(n, h):

    if debug:
        log("n=%s" % n)
        log("h=%s" % h)
    
    result = 1
    for i in range(1, n):
        count = 0
        for j in range(i):
            if h[j] <= h[i]:
                count = count + 1
            else:
                break
        if count == i:
            result = result + 1
        

    return result


def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()


Measured memory_bytes: 3064
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll k, a, b, ans = 1;
  scanf("%lld%lld%lld", &k, &a, &b);
  if(a > b - 3) printf("%lld", ans + k);
  else if(k < a) printf("%lld", ans + k);
  else {
    k -= a - 1;
    ans = a;
    ans += (b - a) * (k / 2);
    if(k % 2) ++ans;
    printf("%lld", ans);
  }
  return 0;
}

Measured memory_bytes: 128
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;
ll ans = 0;
string s;

void dfs(int idx, ll sum, string num) {
    if (idx == s.length() - 1) {
        sum += stoull(num);
        ans += sum;
        return;
    }
    dfs(idx + 1, sum + stoull(num), string{s[idx + 1]});
    dfs(idx + 1, sum, num + string{s[idx + 1]});
}


int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        cin >> s;
        dfs(0, 0, string{s[0]});
        cout << ans << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

n = int(input())
p = list(map(int, input().split()))

p_sorted = sorted(p)
swap_pre = []

for i,j in zip(p, p_sorted):
    if i != j and not swap_pre:
        swap_pre += [i,j]
    elif i != j and swap_pre == [j, i]:
        pass
    elif i != j:
        print('NO')
        break
else:
    print('YES')

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n, sum= 0;
    cin>> n;

    int in[n+1], a[n+1], b[n+1];

    for(int i=1; i<=n; i++)
        cin>> in[i];

    for(int i=1; i<=n; i++)
    {
        cin>> a[i];
        sum += a[i];
    }

    for(int i=1; i<n; i++)
        cin>> b[i];

    for(int i=1; i<n; i++)
        {
            if(in [i]+1 == in[i+1])
                sum += b[in[i]];
        }


    cout<< sum << '\n';

    return 0;
}




Measured memory_bytes: 3544
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

typedef long long ll;

int main() {
	int n; cin >> n;
	vector<ll>a(n), s(n + 1, 0);
	for (auto&& x : a)cin >> x;
	map<ll, ll>cnt; cnt[s[0]]++;
	for (int i = 1; i <= n; i++) {
		s[i] = s[i - 1] + a[i - 1];
		cnt[s[i]]++;
	}
	ll ans = 0;
	for (auto&& x : cnt) {
		if (x.second > 1) {
			ans += x.second * (x.second - 1) / 2;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <iomanip>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main(){

//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
    int r,g,b;
    cin >> r >> g >> b;

    string res = "NO";
    int sum = 100 * r + 10 * g + b;
    if(sum % 4 == 0)
    {
        res = "YES";
    }

    cout << res << endl;



    return 0;
}


Measured memory_bytes: 256
<?php
$input = STDIN;

$N = trim(fgets($input));
$line = fgets($input);

print $line;

$seq = explode(' ', trim($line));

for ($i = 1; $i < $N; $i++) {
    $key = $seq[$i];

    $j = $i - 1;
    while ($j >= 0 && $seq[$j] > $key) {
        $seq[$j+1] = $seq[$j];
        $j--;
    }

    $seq[$j+1] = $key;

    print implode(' ', $seq) . "\n";
}


Measured memory_bytes: 9268
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1e+5+5;
int num[maxn];
int main() {
	memset(num,0,sizeof(num));
	int n; cin>>n;
	for(int i=0;i<n;i++) cin>>num[i];
	sort(num,num+n);

	long long sum = 0;
	for(int i=0;i<n;i++) sum+=num[i];

	cout<<num[0]<<" "<<num[n-1]<<" "<<sum<<endl;
	return 0;
}


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

int main(){
  int n,i,kotae=0;
  string s;
  cin>>s;
  n=s.length();
  for(i=0;i<n/2;i++){
    if(s[i]!=s[n-1-i]){
      kotae++;
    }
  }
  cout<<kotae;
}

Measured memory_bytes: 256
import itertools
n,m,q=map(int,input().split())
req=[list(map(int,input().split())) for _ in range(q)]
a=itertools.combinations_with_replacement(range(1,m+1),n)
ans=0
for i in a:
    point=0
    for j in req:
        if i[j[1]-1]-i[j[0]-1]==j[2]:
            point+=j[3]
    ans=max(ans,point)
print(ans)

Measured memory_bytes: 9152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define  fo(i,n) for(ll i=0;i<n;i++)
#define rfo(i,n) for(ll i=n;i>=0;i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define pb push_back
#define deb(x) cout<< #x << " = "<<x<<endl;
#define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
void solve()
{
	string s,t;
	cin>>s>>t;
	ll ans=t.length();
	for(ll i=0;i<=s.length()-t.length();i++)
	{
			ll temp = 0;
			for(ll j=0;j<t.length();j++)
			{
				if(s[i+j] != t[j])
				{
					temp++;
				}
			}
			ans = min(temp,ans);
	}
	cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

long long n,a[10000],ans;

int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=2*n;i++)
	{
		scanf("%lld",&a[i]);
	}
	sort(a+1,a+2*n+1);
	for(int i=1;i<=2*n;i+=2)
	{
		ans+=a[i];
	}
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int N, x;
	cin >> N >> x;
	if (x == 1 || x == 2 * N - 1) {
		cout << "No" << endl;
	}
	else {
		int inc = 0;
		//N-1番目には1 N番目にはx N+1番目には2*N-1 N+2番目にはx-1　それ以外は任意の順番でOK(ここでは昇順に実装)
		cout << "Yes" << endl;
		//x != 2の時
		if (x != 2) {
			for (int i = 1; i <= 2 * N - 1; i++) {
				if (i < N - 1) {
					if ((i + 1 == x - 1) && inc == 0)inc += 2;
					cout << i + inc + 1 << endl;

				}
				else if (i == N - 1)cout << 1 << endl;
				else if (i == N)cout << x << endl;
				else if (i == N + 1)cout << 2 * N - 1 << endl;
				else if (i == N + 2) {
					if (x != 2)cout << x - 1 << endl;
					else cout << i - 3 + inc << endl;
				}
				else {
					if ((i - 3 == x - 1) && inc == 0)inc += 2;
					cout << i - 3 + inc << endl;
				}
			}
		}
		else {
			//x == 2の時
			for (int i = 1; i <= N * 2 - 1; i++) {
				if (i < N - 1)cout << i + 2 << endl;
				else if (i == N - 1)cout << 1 << endl;
				else if (i == N)cout << 2 << endl;
				else if (i == N + 1)cout << 2 * N - 1 << endl;
				else cout << i - 1 << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9;

int n;
const int nx = 1e5+5;
int ac[nx][3];
int dp[3][nx];
int go(int a, int i)
{
	if(i==n) return 0;
	if(dp[a][i] != -1) return dp[a][i];
	int& ans = dp[a][i];
	if(a==0)
	{
		ans=max(ans, go(1, i+1)+ac[i][0]);
		ans=max(ans, go(2, i+1)+ac[i][0]);
	}
	if(a==1)
	{
		ans=max(ans, go(0, i+1)+ac[i][1]);
		ans=max(ans, go(2, i+1)+ac[i][1]);
	}
	if(a==2)
	{
		ans=max(ans, go(0, i+1)+ac[i][2]);
		ans=max(ans, go(1, i+1)+ac[i][2]);
	}
	
	return ans;
	
}
int main()
{
    cin>>n;
    for(int i=0; i<n; i++) cin>>ac[i][0]>>ac[i][1]>>ac[i][2];
    memset(dp, -1, sizeof dp);
    cout<<max(go(0,0), max(go(1,0),go(2,0)))<<"\n";
    return 0;
}

Measured memory_bytes: 7296
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a ; i <= b; ++ i) 
const int N = 25, M = 6e5 + 5, mo = 1e9 + 7 ;
using namespace std ;

int n, m, T, A[N][N], g[N][M], f[2][N][M], nxt[M][N] ;
void upd(int &x, int y) { x = (x + y) % mo ; }
int main() {
	scanf("%d%d%d", &n, &m, &T) ;
	if (n == 1) { puts("1") ; return 0 ; }
	rep(i, 0, m - 1) rep(j, 0, n - 2) A[i][j] = - 1 ;
	for (int x, y, z ; T -- ; ) {
		scanf("%d%d%d", &x, &y, &z) ;
		A[x - 1][y - 1] = z ;
	} 
	int c = 0, st = (1 << (n - 1)) - 1 ;
	rep(i, 0, st) rep(j, 0, n - 2) {
		nxt[i][j] = - 1 ;
		rep(k, j + 1, n - 2) if ((i >> k) & 1) { nxt[i][j] = k ; break ; }
	}
	g[n - 2][0] = 1 ;
	rep(u, 0, m - 1) {
		c ^= 1 ;
		rep(i, 0, n - 1) rep(j, 0, st) f[c][i][j] = 0 ;
		rep(i, 0, st) upd(f[c][0][i], g[n - 2][i]) ;
		rep(i, 0, n - 2) rep(j, 0, st) g[i][j] = 0 ;
		rep(i, 0, n - 2) rep(j, 0, st) {
			upd(f[c][i + 1][j], f[c][i][j]) ;
			if ((j >> i) & 1) continue ;
			if (nxt[j][i] == - 1) upd(g[i][(j & ((1 << i) - 1)) | (1 << i)], f[c][i][j]) ;
				else upd(f[c][i + 1][j ^ (1 << i) ^ (1 << nxt[j][i])], f[c][i][j]) ;
		}
		rep(i, 0, st) upd(g[n - 2][i], f[c][n - 1][i]) ;
		rep(i, 0, n - 3) rep(j, 0, st) upd(g[i + 1][j], g[i][j]), upd(g[i + 1][j ^ (1 << (i + 1))], g[i][j]) ;
		rep(i, 0, st) rep(j, 0, n - 2) if (A[u][j] != - 1 && A[u][j] != ((i >> j) & 1)) g[n - 2][i] = 0 ;
	}
	int ans = 0 ;
	rep(i, 0, st) upd(ans, g[n - 2][i]) ;
	printf("%d\n", ans) ;
	return 0 ;
}

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

int main() {
  int n,k;  
  vector<double> dice;

  cin >> n >> k;
  rep(i,0,n){
    double tmp=0,sum=0;
    cin >> tmp;
    rep(j,1,tmp+1){sum += j;}
    dice.push_back(sum/tmp);
  }
  
  double max=0,tmpmax=0;
  rep(i,0,k){tmpmax += dice[i];}
  max = tmpmax;
  
  rep(i,k,n){
    tmpmax -= dice[i-k];
    tmpmax += dice[i];
    if(tmpmax>max){max=tmpmax;}
  }
  
  cout << fixed << setprecision(12) << max << endl;
    
  return 0;

}

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

using namespace std;

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
      return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

typedef vector<P> G;

#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
int contains(const G& g, const P& p) {
  bool in = false;
  for (int i = 0; i < g.size(); ++i) {
      P a = curr(g,i) - p, b = next(g,i) - p;
      if (imag(a) > imag(b)) swap(a, b);
      if (imag(a) <= 0 && 0 < imag(b))
        if (cross(a, b) < 0) in = !in;
      if (cross(a, b) == 0 && dot(a, b) <= 0) return true;
    }
  return in ? true : false;
}

int main(){
    int n;
    cin >> n;
    for(int q=0; q < n; q++){
        G g(3); P a, b;
        double xp1,yp1,xp2,yp2,xp3,yp3, xk, yk, xs, ys;
        cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
        g[0] = P(xp1, yp1); g[1] = P(xp2, yp2); g[2] = P(xp3, yp3);
        a = P(xk, yk); b = P(xs, ys);
        cout << (contains(g, a) xor contains(g, b) ? "OK" : "NG") << endl;
    }
}

Measured memory_bytes: 1224
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO NとKをうけとる。
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		// TODO NとNの関係性を判定
		if (n % 2 == 1) {
			// TODO Nが奇数のとき
			// TODO ①KがNの商＋１か
			if (k <= n / 2 + 1) {
				// TODO ①がYだったらYESと出力
				System.out.println("YES");
			} else {
				// TODO ①がNだったらNOと出力
				System.out.println("NO");
			}
		} else {
			// TODO Nが偶数のとき
			// TODO ②KがNの商か
			if (k <= n / 2) {
				// TODO ②がYだったらYESと出力
				System.out.println("YES");
			} else {
				// TODO ②がNだったらNOと出力
				System.out.println("NO");
			}
		}
		sc.close();
	}

}


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

vector<int> tsort(const vector<vector<int> > &g) {
	int n = g.size(), k = 0;
	vector<int> ord(n), in(n);
	for(auto &es : g) for(auto &e : es) in[e]++;
	queue<int> q;
	for(int i = 0; i < n; ++i) if(in[i] == 0) q.push(i);
	while(q.size()) {
		int v = q.front(); q.pop(); ord[k++] = v;
		for(auto &e : g[v]) if(--in[e] == 0) q.push(e);
	}
	return *max_element(in.begin(), in.end()) == 0 ? ord : vector<int>();
}

int d[100000];
int deg[100000];
vector<vector<int>> g;
typedef pair<int, int> P;

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

	int n, m;
	cin >> n >> m;

	g = vector<vector<int>>(n);
	for(int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].push_back(b);
		deg[b]++;
	}

	auto res = tsort(g);

	for(int i = 0; i < n; i++) {
		cout << res[i] + 1 << endl;
	}

	queue<int> q;
	q.push(res[0]);
	while(q.size()) {
		int v = q.front();
		q.pop();
		for(auto c : g[v]) {
			deg[c]--;
			if(deg[c] == 0) {
				q.push(c);
				d[c] = d[v] + 1;
			}
		}
	}

	if(*max_element(d, d + n) == n - 1) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}
}

Measured memory_bytes: 3888
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int n, k;
	scanf("%d%d", &n, &k);
	printf("%d\n", (n - 1) * (k - 1));
	
	Please AC;
}


Measured memory_bytes: 256
//#include <climits>
#include <vector>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <math.h>
//#include <sstream>
// #include <string>
using namespace std;

/*
pair<double, double> move(pair<double, double> p, double move_x, double move_y) {
    return make_pair(p.first  - move_x, p.second - move_y);
}

double distance(pair<double, double> p1, pair<double, double> p2) {
    double dx = p1.first  - p2.first;
    double dy = p1.second - p2.second;
    return sqrt(dx * dx + dy * dy);
}
*/

//centerを中心にpをtheta回転する(左回りが正)
pair<double, double> rotate(pair<double, double> center, pair<double, double> p, double theta) {
    double new_x = (p.first  - center.first ) * cos(theta) - (p.second - center.second) * sin(theta) + center.first;
    double new_y = (p.second - center.second) * cos(theta) + (p.first   - center.first) * sin(theta) + center.second;

    return make_pair(new_x, new_y);
}


int n;
vector<pair<double, double>> ans;

void kochCurve(int i, pair<double, double> p1, pair<double, double> p2) {
    //曲線を描き終わったとき
    if(i > n) {
        return;
    }

    //p1とp2の距離を1/3にしたもの
    double dist_x = (p2.first  - p1.first ) / 3;
    double dist_y = (p2.second - p1.second) / 3;

    //左側の座標(p1とp2を3等分する点の左側)
    double left_x = p1.first + dist_x;
    double left_y = p1.second + dist_y;
    pair<double, double> left(left_x, left_y);

    //右側の座標(p1とp2を3等分する点の右側)
    double right_x = left_x + dist_x;
    double right_y = left_y + dist_y;
    pair<double, double> right(right_x, right_y);

    //正三角形の頂点座標
    //    左側の座標を中心に右側の座標を左回転させる(左回転が正。　※座標回転の公式を参照)
    pair<double, double> vertex = rotate(left, right, M_PI/3); 

    //再帰
    kochCurve(i + 1, p1    , left);
    ans.push_back(left);
    
    kochCurve(i + 1, left  , vertex);
    ans.push_back(vertex);
    kochCurve(i + 1, vertex, right);
    
    ans.push_back(right);
    kochCurve(i + 1, right , p2);
}


int main() {
    cin >> n;

    pair<double, double> p1(0  , 0);
    pair<double, double> p2(100, 0);

    ans.push_back(p1);
    kochCurve(1, p1, p2);
    ans.push_back(p2);

    for (int i = 0; i < (int)ans.size(); ++i)
    {
        printf("%.8lf %.8lf\n", ans[i].first, ans[i].second);
    }

    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define INF 1001001001
using namespace std;
int main() {
	string s, t;
	cin >> t >> s;
	int tl = t.size();
	int sl = s.size();
	int ans = INF;
	for (int i = 0; i < tl - sl + 1; i++) {
		int cnt = 0;
		for (int j = 0; j < sl; j++) {
			if (t[j + i] != s[j]) {
				cnt++;
			}
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

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

class CommonIO {
public:
    CommonIO() {
        std::cin.tie(0);
        std::ios::sync_with_stdio(false);
    }
    ~CommonIO() {}

    template <class T>
    void scan(T &v) {
        std::cin >> v;
    }
    template <class T, class... Rest>
    void scan(T &v, Rest&... rest) {
        scan(v);
        scan(rest...);
    }

    template <class T>
    void print(T v) {
        std::cout << v;
    }
    template <class T>
    void print(std::vector<T> &v) {
        if (v.size() == 0) return;
        print(*v.begin());
        for (auto it = ++v.begin(); it != v.end(); ++it) {
            print(' ');
            print(*it);
        }
    }
    template <class T>
    void print(std::vector< std::vector<T> > &grid) {
        if (grid.size() == 0) return;
        print(*grid.begin());
        for (auto it = ++grid.begin(); it != grid.end(); ++it) {
            print('\n');
            print(*it);
        }
    }
    template <class T, class... Rest>
    void print(T v, Rest... rest) {
        print(v);
        print(' ');
        print(rest...);
    }

    template <class T>
    void printl(T v) {
        print(v);
        std::cout << '\n';
    }
    template <class T, class... Rest>
    void printl(T v, Rest... rest) {
        print(v);
        print(' ');
        printl(rest...);
    }
} io;


struct Card {
  int n;
  char s;

  bool operator< (const Card &card) {
    return n < card.n;
  }
};
std::ostream& operator<<(std::ostream& stream, const Card& card) {
  stream << card.s << card.n;
  return stream;
}
bool operator== (const Card &c1, const Card &c2) {
  return c1.n == c2.n && c1.s == c2.s;
}

template <class T>
void BubbleSort(vector<T> &a) {
  int N = a.size();
  REP(i, N) {
    for (int j = N-1; j>=i+1; --j) {
      if (a[j] < a[j-1]) {
         swap(a[j], a[j-1]);
      }
    }
  }
}

template <class T>
void SelectionSort(vector<T> &a) {
  int N = a.size();
  int minj;
  REP(i, N) {
    minj = i;
    FOR(j, i, N) {
      if (a[j] < a[minj]) minj = j;
    }
    if (i != minj) {
      swap(a[i], a[minj]);
    }
  }
}

int main() {
  int n; io.scan(n);
  vector<Card> a(n);
  REP(i, n) io.scan(a[i].s, a[i].n);
  vector<Card> b(a);
  
  BubbleSort(a);
  io.printl(a);
  io.printl("Stable");
  SelectionSort(b);
  io.printl(b);
  io.printl(a == b ? "Stable" : "Not stable");

  return 0;
}



Measured memory_bytes: 3224
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <queue>
#include <random>
#include <map>
#include <set>
#include <boost/multiprecision/cpp_int.hpp>

#pragma warning(disable:4996)

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> home(n);
  for (auto&& v : home) {
    cin >> v;
  }
  sort(home.begin(), home.end());
  cout << home.back() - home.front() << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    int v[n], c[n];
    int i;
    int ans=0;
    for(i=0;i<n;i++){
        scanf("%d",&v[i]);
    }
    for(i=0;i<n;i++){
        scanf("%d",&c[i]);
    }
    for(i=0;i<n;i++){
        if(v[i]-c[i] > 0)
        ans = ans + v[i] - c[i];
    }
    printf("%d",ans);
    return 0;
    
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
 
 string A,B,C;
 cin >> A >> B >> C;

 if(A.at(A.size()-1)==B.at(0) && B.at(B.size()-1)== C.at(0)){
  cout << "YES" << endl;
 }
 else{
  cout << "NO" << endl;
 }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll N; string A, B, C; cin >> N >> A >> B >> C;
    ll c = 0;
    for(int i=0; i<N; i++){
        if(A[i] == B[i]&&B[i] ==C[i]){}
        else if(A[i] == B[i]&&B[i] !=C[i]){c++;}
        else if(A[i] != B[i]&&B[i] ==C[i]){c++;}
        else if(A[i] == C[i]&&B[i] !=C[i]){c++;}
        else{c += 2;}
    }
    cout << c;
}

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

const int MOD = 1000000007;

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> p(M);
  vector<string> S(M);
  for (int i = 0; i < M; i++)
  {
    int a;
    cin >> a >> S[i];
    a--;
    p[i] = a;
  }
  vector<bool> AC(N);
  vector<int> WA(N);
  for (int i = 0; i < N; i++)
  {
    AC[i] = false;
  }
  int ac = 0, wa = 0;
  for (int i = 0; i < M; i++)
  {
    if (!AC[p[i]] && S[i] == "AC")
    {
      ac++;
      AC[p[i]] = true;
    }
    else if (!AC[p[i]] && S[i] == "WA")
    {
      WA[p[i]]++;
    }
  }
  for (int i = 0; i < N; i++)
  {
    if (AC[i])
      wa += WA[i];
  }
  cout << ac << " " << wa << endl;
}


Measured memory_bytes: 6528
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
using namespace std;

int main(){

  int n, l[1000], r[1000], ans=0;

  cin >> n;

  for(int i=0; i<n; i++){
    cin >> l[i] >> r[i];
    ans+=r[i]-l[i]+1;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import { readFileSync } from 'fs'
function main() {
  const input = readFileSync('/dev/stdin', 'utf8')
  const s = input.trim().split('')
  const oddString = 'RUD'
  const evenString = 'LUD'
  let judge = 'Yes'
  for (let i = 0; i < s.length; i++) {
    if ((i + 1) % 2 === 0) {
      if (evenString.match(s[i]) === null) {
        judge = 'No'
        break
      }
    } else {
      if (oddString.match(s[i]) === null) {
        judge = 'No'
        break 
      }     
    }
  }
  console.log(judge)
}
main()

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
//----
ll n, s, ans=-1;
void upd(ll b){
	if(ans==-1)ans=b;
	ans=min(ans, b);
}
ll f(ll b, ll n){
	if(n<b)return n;
	return f(b, n/b)+n%b;
}
int main(){
	cin>>n>>s;
	ll up=sqrt(n)+1;
	rep(i, 2, up+1){
		ll su=0, t=n;
		rep(j, 0, 80){
			su+=t%i;
			t/=i;
		}
		if(su==s)upd(i);
	}
	if(n-s>0)
	rep(p, 1, up+1){
		if((n-s)%p!=0)continue;
		ll b=(n-s)/p+1;
		if(f(b, n)==s)upd(b);
	}
	if(s==n)ans=n+1;
	printf("%lld\n", ans);
	return 0;
}
/*
87654
30
10

87654
138
100

87654
45678
-1

31415926535
1
31415926535

1
31415926535
-1
*/


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  bool fin = false;
  while (!fin) {
    fin = true;
    rep(i, n-1) {
      if (a.at(i) < a.at(i+1)) {
        fin = false;
        int temp = a.at(i);
        a.at(i) = a.at(i+1);
        a.at(i+1) = temp;
      }
    }
  }
  int ans = 0;
  rep(i, n) if (!(i % 2)) ans += a.at(i);
  rep(i, n) if ( (i % 2)) ans -= a.at(i);
  cout << ans << endl;
}


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

int main() {
  bool authenticity = true;
  int N, a, alice = 0, bob = 0;
  
  cin >> N;
  vector<int> nue(N);
  
  for (int i = 0; i < N; i++) cin >> nue.at(i);
  
  while ( authenticity ) {
    authenticity = false;
    for (int i = 0; i < N - 1; i++) {
      a = nue.at(i);
      
      if (nue.at(i) < nue.at(i + 1)) {
        
        nue.at(i) = nue.at(i + 1);
        nue.at(i + 1) = a;
        authenticity = true;
      } 
    }
  }
  
  for (int i = 0; i < N; i += 2) {
    alice += nue.at(i);
    if (i + 1 < N) bob += nue.at(i + 1);
  }
  
  cout << alice - bob << endl;
}


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

int main(void){
  int k, odd, even;
  scanf("%d", &k);
  if(k%2 == 0){
    even = k/2;
    odd = even;
  }
  else {
    even = k/2;
    odd = even + 1;
  }

  printf("%d\n", odd * even);
  
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define se set<ll>
#define vec vector<ll>
#define inf 10000000000000000
bool mark[100005];
vec adj[100005];
ll counter;
vec cnt;
vector<string> forsubs;
ll b;
ll a;
ll ans=0;


void addedge(ll u, ll v,ll w)

	{
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

void dfs(ll node)
	{
		//cout<<node<<endl;
		mark[node]=1;

		for(auto i:adj[node])
		{	
			
			
			if(!mark[i])
				dfs(i);		

		}
	}
	

int main()
{    
 

	#ifdef APNA_IO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
		    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
ll n,m;
cin>>n>>m;
ll u,v,w;

for(ll i=1;i<=m;i++)
{
cin>>u>>v>>w;
addedge(u,v,w);
}



for(ll i=1;i<=n;i++)
{
	if(!mark[i])
	{
		dfs(i);
		ans++;
	}
}

cout<<ans<<endl;

}		





Measured memory_bytes: 8960