akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-9, PI = acos(-1);
const int N = 2e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll INF = 1e18;
using namespace std;

pair<int, int> arr[N];
ll mem[N][N];

ll solve(int l, int r, int idx) { // idx inference variable
	if(r < l) return 0;
	ll& ret = mem[l][r];
	if(~ret)
		return ret;
	ret = 0;
	ret = solve(l + 1, r, idx - 1) + (abs(l - arr[idx].second) * (ll)arr[idx].first);
	ret = max(ret, solve(l, r - 1, idx - 1) + (abs(r - arr[idx].second) * (ll)arr[idx].first));
	return ret;
}

int main() {
	fastIO;
#ifdef LOCAL
//	freopen("input.in", "rt", stdin);
#endif
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> arr[i].first, arr[i].second = i;
	sort(arr + 1, arr + n + 1);
	memset(mem, -1, sizeof mem);
	cout << solve(1, n, n);
	return 0;
}


Measured memory_bytes: 35352
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n, k;
    cin >> n >> k;
    map<int,int> A;
    REP(i,n){
        int tmp;
        cin >>tmp;
        A[tmp]++;
    }
    int ans=0;
    int i=0;
    vector<int> B(0);
    for(auto a:A){
        B.push_back(a.second);
    }
    sort(ALL(B));
    REP(i,A.size()-k)
        ans+=B[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10744
def partition(n, k)
  exec_partition(n, k, 0, [], [])
    .map { |p| p.map { |i| i + 1 } }
end

def exec_partition(n, k, start, prog, acc)
  return [] if n <= k

  if k == 0
    p2 = prog.sort!
    acc.push(p2) unless acc.include?(p2)
    return acc
  end

  (start...(n - 1)).each do |i|
    next if prog.include?(i)
    exec_partition(n, k - 1, start + 1, prog + [i], acc)
  end

  acc
end

def solve(s)
  total = s.to_i
  (1..(s.size - 1)).each do |i|
    parts = partition(s.size, i)
    total = total + parts.reduce(0) do |subtotal, p|
      p2 = ([0] + p).zip(p + [nil])
      nums = p2.map { |head, tail| tail ? s.slice(head...tail).to_i : s.slice(head..-1).to_i }
      subtotal + nums.reduce(0) { |a, e| a + e }
    end
  end
  total
end

s = STDIN.gets.strip!
p solve(s)


Measured memory_bytes: 1916
//BISMILLAH
#include<bits/stdc++.h>
#define ll long long
#define max 100005
using namespace std;
vector<ll> freq(max);
//int DFS(int);

int main()
{
    ll n,flag=0,x,value=0,sum=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        sum+=x;
        freq[x]++;
    }

    int t;
    cin>>t;
    while(t--)
    {
        ll a,b;
        cin>>a>>b;
       sum+=(b-a)*freq[a];
        freq[b]+=freq[a];
        freq[a]=0;

        cout<<sum<<endl;
    }

}



Measured memory_bytes: 3888
import java.util.*;
import java.math.BigInteger;
 
public class Main {
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        
        String s = scan.next();
        String t = scan.next();

        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            if (!s.substring(i, i + 1).equals(t.substring(i, i + 1))) {
                ans++;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 55152
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main()
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    string s;
    cin>>s;
    ll ans=0;
    for (int i = 0; i < s.length(); ++i)
    {
        ans = (ans + (s[i]-'0'))%9;
    }
    if(ans==0){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }

    return 0;
}

Measured memory_bytes: 3780
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 10000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

type A [][]int

func (a A) Len() int           { return len(a) }
func (a A) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a A) Less(i, j int) bool { return a[i][0] < a[j][0] }

func main() {
	nm := strings.Split(readLine(), " ")
	n, _ := strconv.Atoi(nm[0])
	m, _ := strconv.Atoi(nm[1])
	var ab [][]int
	for i := 0; i < n; i++ {
		abstr := strings.Split(readLine(), " ")
		a, _ := strconv.Atoi(abstr[0])
		b, _ := strconv.Atoi(abstr[1])
		ab = append(ab, []int{a, b})
	}
	sort.Sort(A(ab))
	var cost int
	for _, v := range ab {
		if m > v[1] {
			cost += v[0] * v[1]
			m -= v[1]
		} else {
			cost += v[0] * m
			break
		}
	}
	fmt.Println(cost)
}


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

void dfs(int n, int p, vector<int>& dist, vector<vector<int>>& tree) {
    for (int m : tree[n]) {
        if (m == p) {
            continue;
        }

        dist[m] = dist[n] + 1;
        dfs(m, n, dist, tree);
    }
}

int main() {
    int N, u, v;
    cin >> N >> u >> v;
    u--;
    v--;
    vector<vector<int>> tree(N, vector<int>());
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    vector<int> da(N, 1e9), dt(N, 1e9);
    dt[u] = 0;
    dfs(u, -1, dt, tree);
    da[v] = 0;
    dfs(v, -1, da, tree);
    int goal = -1;
    for (int i = 0; i < N; i++) {
        if (dt[i] < da[i]) {
            if (goal == -1) {
                goal = i;
            } else {
                if (da[goal] < da[i]) {
                    goal = i;
                }
            }
        }
    }

    int ans = dt[goal] + ((da[goal] - dt[goal]) - 1);
    cout << ans << endl;
}


Measured memory_bytes: 12928
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
import bisect

def main():
    N, M, K = map(int, input().split())
    A_lsit = list(map(int, input().split()))
    B_lsit = list(map(int, input().split()))

    A_sum_list = [0] + A_lsit[:]
    for i in range(1, N+1):
        A_sum_list[i] = A_sum_list[i-1] + A_lsit[i-1]
    B_sum_list = [0] + B_lsit[:]
    for i in range(1, M+1):
        B_sum_list[i] = B_sum_list[i-1] + B_lsit[i-1]
    #print(A_sum_list)
    #print(B_sum_list)

    max_book_number = 0
    for i in range(N+1):
        if A_sum_list[i] <= K:
            book_number_A = i
            book_number_B = bisect.bisect_right(B_sum_list, K-A_sum_list[i]) - 1
            max_book_number = max(
                max_book_number,
                book_number_A + book_number_B
            )
            #print(book_number_A, book_number_B, book_number_A + book_number_B)
    print(max_book_number)

if __name__ == "__main__":
    main()



Measured memory_bytes: 49096
/* {{{ Definitions */
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <ios>
#include <utility>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
/* }}}------------------------------------------- */
int N, size;
int S[300000];
int now;
queue<int> q;
priority_queue<int> pq;
int c;
int solve(){
	sort(S, S + size, greater<int>());
	if(S[0] == S[1])
		return 1;
	pq.push(N);
	reps(i, size - 1){
		if(pq.empty())
			return 1;
		now = pq.top(); pq.pop();
		if(now != 1){
			pq.push(now - 1);
			q.push(now - 1);
		}
		if(i != size - 1 and S[i] != S[i + 1]){
			while(!q.empty()){
				pq.push(q.front()), q.pop();
			}
		}
	}
	return 0;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	size = 1 << N;
	rep(i, size) {
		cin >> S[i];
	}
	if(solve() == 1)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 1980
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String w = sc.next();
        int count = 0;
        while(true){
        	String t = sc.next();
            if(t.equals("END_OF_TEXT")){
            	break;
            }
            if(t.equalsIgnoreCase(w)){
            	count++;
            }
        }
        System.out.println(count);
    }
}


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

using namespace std;

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n,l;
    cin >> n >> l;
    string a;
    multiset<string> s;
    while(n--){
        cin >> a;
        s.insert(a);
    }
    for(auto i=s.begin();i!=s.end();++i){
        cout << *i;
    }
    return 0;
}


Measured memory_bytes: 3668
#include <iostream>
using i64 = long long;

int main() {
    int n;
    i64 d;
    std::cin >> n >> d;
    int ret = 0;
    while (n--) {
        i64 a, b;
        std::cin >> a >> b;
        if (a * a + b * b <= d * d) ret++;
    }
    std::cout << ret << std::endl;

    return 0;
}


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

using namespace std;

class Point {
public:
	int x;
	int y;
	int h;
	Point(int a, int b, int c) {
		x = a;
		y = b;
		h = c;
	}
};


int main() {
	int i = 0, j, h, N, c;
	int xi, yi, hi;
	cin >> N;
	vector<Point> pts;
	int max_h = 0;//所有坐标中的最大高度
	for (; i < N; ++i) {
		cin >> xi >> yi >> hi;
		if (hi > max_h) 
			max_h = hi;

		Point r(xi, yi, hi);
		pts.push_back(r);
	}
	int flag = 0;
	int c_h;
	for (i = 0; (i <= 100)&&(flag ==0); ++i) { //给定横坐标i
		for (j = 0; (j <= 100)&&(flag ==0); ++j) { //给定纵坐标j
			for (h = max_h; h <= max_h+200; ++h) { //给定高度h
				for (c = 0; c < N; ++c) { //检查每个坐标是否符合给定条件
					c_h = h - abs(pts[c].x - i) - abs(pts[c].y - j);
					if (pts[c].h == c_h)  ++flag;
					else if ((pts[c].h == 0) && c_h < 0)  ++flag;
					else break;
				}
				if (flag != N) flag = 0;
				else break;
			}
		}
	}
	cout << i - 1 << ' ' << j - 1 << ' ' << h;
	return 0;
}

Measured memory_bytes: 3588
import itertools
n,m,x = map(int,input().split())
ca = [list(map(int,input().split())) for i in range(n)]
all_list = list(itertools.product([0,1], repeat=n))
ans_flag = False

final_answer = float("inf")
for i in range(len(all_list)):
  anslist = [0]*(m+1)
  anscost = 0
  flag = True
  for j in range(n):
    if all_list[i][j] == 1:
      anscost += ca[j][0]
      for k in range(1,m+1):
        anslist[k] += ca[j][k]
  # print(anslist)
  for l in range(1,m+1):
    if anslist[l] < x:
      flag = False
  if flag:
    ans_flag = True
    
    final_answer = min(final_answer,anscost)

if ans_flag:
  print(final_answer)
else:
  print("-1")

# for bit in range(2**m):
#   for i in range(n):
#     if (bit >> i) & 1:
#       anscost += ca[i][0]


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

int main() {
  int k,x;
  cin >> k >> x;
  
  int min = x-k+1, max = x+k-1;
  
  for(int i = min; i < max; i++) {
  	cout << i << " " ;
  }
  cout << max << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n;
long a[200010],sum[20010],ans,g=1;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum[i]=sum[i-1]+a[i];
    }
    sort(sum,sum+n+1);
    for(int i=1;i<=n;i++){
        if(sum[i-1]==sum[i]) g++;
        else{
            ans+=g*(g-1)/2;
            g=1;
        }
    }
    ans+=g*(g-1)/2;
    cout<<ans;
}

Measured memory_bytes: 1920
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp;

#[fastout]
fn main() {
  input! {
    k: i32,
    a: i32,
    b: i32,
  }
  if (a..=b).any(|x| x % k == 0) {
    println!("OK");
  } else {
    println!("NG");
  }
}


Measured memory_bytes: 2196
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

#[allow(unused_macros)]
macro_rules! vec_md {
    ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vec_md ! ( $ ( $ dim ) ;* => $ init ) };
    ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vec_md ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] };
    ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] };
}

#[allow(unused_macros)]
macro_rules! chmax {
    ( $ x : expr , $ y : expr ) => { if $ x < $ y { $ x = $ y ; true } else { false } };
}

fn main() {
    input! {
        n: usize, w: usize,
        wv: [(usize, u64); n]
    }

    let mut dp = vec_md![0u64;n+1;w+1];
    for i in 0..n {
        for j in 0..w+1 {
            if j+wv[i].0 <= w {
                chmax!(dp[i+1][j+wv[i].0], dp[i][j] + wv[i].1);
            }
            chmax!(dp[i+1][j], dp[i][j]);
        }
    }

    let mut max = 0u64;
    for j in 0..w+1 {
        chmax!(max, dp[n][j]);
    }
    println!("{}", max);
}

Measured memory_bytes: 106748
#include <iostream>
using namespace std;
int a, b, k;
int main() {
    cin >> a >> b >> k;
    int count = 0;
    int i=a;
    int ans;
    while(true){
        if (a%i==0) {
            if (b%i==0) ++count;
            if (count == k) {
                ans=i;
                break;
            }
        }
        --i;
    }
    cout << ans << endl;
    
}


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

#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define rep(i, n) for(i = 0; i < n; i++)

int main(){
    ll A, B, C, D, a;

    cin >> a;
    A = a / 1000;
    B = a / 100 % 10;
    C = a / 10 % 10;
    D = a % 10;

    for (int i = -1; i < 2; i += 2) {
        for (int j = -1; j < 2; j += 2) {
            for (int k = -1; k < 2; k += 2) {
                if( A + B * i + C * j + D * k == 7){
                    cout << A << ((i == 1) ? '+' : '-');
                    cout << B << ((j == 1) ? '+' : '-');
                    cout << C << ((k == 1) ? '+' : '-');
                    cout << D << "=7\n";
                    return 0;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

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

		int dx = tx - sx;
		int dy = ty - sy;

		String ans = "";

		// 1周目
		// イルカは上に行く
		for (int i = 0; i < dy; i++) {
			System.out.print("U");
		}

		// イルカは右に行く
		for (int i = 0; i < dx; i++) {
			System.out.print("R");
		}

		// イルカは下に行く
		for (int i = 0; i < dy; i++) {
			System.out.print("D");
		}

		// イルカは左に行く
		for (int i = 0; i < dx; i++) {
			System.out.print("L");
		}

		// 2周目
		// イルカは1つ左に行く
		System.out.print("L");

		// イルカは上に行く
		for (int i = 0; i < dy + 1; i++) {
			System.out.print("U");
		}

		// イルカは右に行く
		for (int i = 0; i < dx + 1; i++) {
			System.out.print("R");
		}

		// イルカは1つ下に行く
		System.out.print("D");

		// イルカは1つ右に行く
		System.out.print("R");

		// イルカは下に行く
		for (int i = 0; i < dy + 1; i++) {
			System.out.print("D");
		}

		// イルカは左に行く
		for (int i = 0; i < dx + 1; i++) {
			System.out.print("L");
		}

		// イルカは1つ上に行く
		System.out.println("U");

		sc.close();
	}
}


Measured memory_bytes: 23364
N = int(input())
S = input()
left_w_count = 0
right_e_count = S[1:].count("E")
result = right_e_count
for i in range(1, N):
    if S[i - 1] == "W":
        left_w_count += 1
    if S[i] == "E":
        right_e_count -= 1
    r = left_w_count + right_e_count
    if r < result:
        result = r
print(result)

Measured memory_bytes: 3828
def solve(n,A):
	mod=10**9+7
	s=0
	for _,x in enumerate(A):
		s+=x
	s=s**2
	squared_terms=0
	for _,x in enumerate(A):
		y=x**2
		squared_terms+=y
	ans=(s-squared_terms)//2
	return ans%mod


N=int(input())
A=list(map(int,input().split()))
print(solve(N,A))

Measured memory_bytes: 94148
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  long long a,b,n,c = 0,cnt = 0;
  cin >> n >> a >> b;
  c = n / (a + b);
  cnt = c * a;
  c = n % (a + b);
  if (c >= a){
    cnt += a;
  }
  else{
    cnt += c; 
  }
  cout << cnt << '\n';
  return 0;   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int,int> pa;
#define w1 first
#define w2 second
#define ls (x<<1)
#define rs (x<<1|1)
#define pb push_back
#define mp make_pair
#define mid ((l+r)>>1)
#define SZ(x) ((x).size())
#define All(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=1ll*x*x%p)if(k&1)res=1ll*res*x%p;return res;}
int getgcd(int x,int y){return !x?y:getgcd(y%x,x);}
const int maxn=1e6+5;
int n,k;
int a[maxn];
char str[maxn];
int main(){
	read(n);read(k);
	scanf("%s",str+1);
	rep(i,1,n)a[i]=str[i]-'A';
	rep(i,1,n)if(!(i&1))a[i]^=1;
	rep(i,n+1,2*n)a[i]=!(n&1);
	int pnt=1;
	while(k){
		if(pnt==n+1){
			if((k&1)&&!a[pnt])a[pnt]^=1;
			break;
		}else{
			if(!a[pnt])a[pnt]^=1;
			else pnt++;
		}
		k--;
	}
	rep(i,1,n)
		if(i&1)putchar('A'+a[pnt+i-1]);
		else putchar('A'+(a[pnt+i-1]^1));
	return 0;
}

Measured memory_bytes: 3840
#include <stdio.h>
#include <queue>
using namespace std;

int main()
{
  priority_queue<int> q;
  int n,m; scanf ("%d %d",&n,&m);
  while (n--){
int x; scanf ("%d",&x); q.push(x);
  }
  while (m--){
int x = q.top(); q.pop(); q.push(x/2);
  }
  long long a = 0;
  while (!q.empty()){
a += q.top(); q.pop();
  }
  printf ("%lld\n",a);
return 0;
}

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

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

  int S = 0;
  int a,b,c,d;
  for(int i=0;i<2;i++) {
    cin >> a >> b >> c >> d;
    S = max(S,a+b+c+d);
  }
  cout << S << endl;
}

Measured memory_bytes: 1192
K=int(input())
X,Y=map(int,input().split())

sgn_X,sgn_Y=1,1
if X<0:
  X=-X
  sgn_X=-1
if Y<0:
  Y=-Y
  sgn_Y=-1

if K%2==0 and (X+Y)%2==1:
  print(-1)
else:
  xx,yy=0,0
  vec_list=[]
  while((X-xx)+(Y-yy)>2*K):
    if X-xx>K:
      xx+=K
      vec_list.append((K,0))
    elif Y-yy>K:
      yy+=K
      vec_list.append((0,K))
  #print(xx,yy,vec_list)
  diff_x=X-xx
  diff_y=Y-yy
  
  if diff_x+diff_y==K:
    vec_list.append((diff_x,diff_y))
  else:
    if (diff_x+diff_y)%2==1:
      if diff_x<=K:
        xx+=diff_x
        if K-diff_x<diff_y:
          yy+=K-diff_x
          vec_list.append((diff_x,K-diff_x))
        else:
          yy-=K-diff_x
          vec_list.append((diff_x,-K+diff_x))
      elif diff_y<=K:
        yy+=diff_y
        if K-diff_y<diff_x:
          xx+=K-diff_y
          vec_list.append((K-diff_y,diff_y))
        else:
          xx-=K-diff_y
          vec_list.append((-K+diff_y,diff_y))
      diff_x=X-xx          
      diff_y=Y-yy
      
    buf=2*K-(diff_x+diff_y)  
    if diff_x+buf//2<=K:
      vec_list.append((diff_x+buf//2,K-(diff_x+buf//2)))
      vec_list.append((-buf//2,K-buf//2))
    elif diff_y+buf//2<=K:
      vec_list.append((K-(diff_y+buf//2),diff_y+buf//2))
      vec_list.append((K-buf//2,-buf//2))
    else:
      raise("Error")    

  #print(vec_list)
  print(len(vec_list))
  pos_x,pos_y=0,0
  for x,y in vec_list:
    pos_x+=sgn_X*x
    pos_y+=sgn_Y*y      
    print(pos_x,pos_y)

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

using static Input;
using static Util;
class Program
{
    static string S;
    
    static void INPUT()
    {
        S = NextString();
    }
    static void OUT()
    {
        var len = S.Length;
        var b = true;
        for (var i = 0; i < (len - 1) / 2; i++)
        {
            if (S[i] != S[(len - 1) / 2 - 1 - i])
            {
                b = false;
                break;
            }
        }

        if (S.Substring(0, (len - 1) / 2) != S.Substring((len + 2) / 2))
            b = false;
        Console.WriteLine(b ? "Yes" : "No");
    }
    static void Main(string[] args)
    {
#if DEBUG  
        TESTINPUT();
        //INPUT();

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

    static void TESTINPUT()
    {
        S = "akasaka";
    }

}

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

class Util
{
}




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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

int main() {
    int N, M; cin >> N >> M;
    int64_t sum = 0;
    for (int i = 0; i < M; ++i) {
        int a;
        cin >> a;
        sum += a;
    }
    cout << (N - sum >= 0 ? N - sum : -1) << endl;
}

Measured memory_bytes: 3628
using System;

namespace D
{
    class Program
    {
        public static double ToAngle(double radian)
        {
            return (double)(radian * 180 / Math.PI);
        }

        public static double Solve(double a, double b, double x)
        {
            var theta = a * a * b / 2 < x
                ? Math.Atan(2 / a * (b - x / (a * a)))
                : Math.Atan(a * b * b / (2 * x));
            return ToAngle(theta);            
        }

        static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split(' ');
            double a = Convert.ToDouble(line[0]);
            double b = Convert.ToDouble(line[1]);
            double x = Convert.ToDouble(line[2]);
            Console.WriteLine(Solve(a, b, x));
        }
    }
}


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

C = N-K+1
D = 1
for i in range(1, K+1):
    if N-K+1 < i:
        print(0)
    else:
        ans = (C*D)%(10**9+7)
        print(ans)
    #print(C,D)
    C = C*(N-K-i+1)//(i+1)
    D = D*(K-i)//i


Measured memory_bytes: 42992
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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 = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    int n;
    cin >> n;
    vector<int> h(n+1);
    h[0] = -1;
    rep(i, n) cin >> h[i+1];
    int ans = 0, tmp = 0;
    rep(i, n){
        if(h[n-1-i] >= h[n-i]) tmp++;
        else{
            chmax(ans, tmp);
            tmp = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#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()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

string maze[210];
int d[210][210], dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}, h, w, gx, gy;
int bfs(int sx, int sy) {
	queue<PII> que;
	REP(i, h) REP(j, w) d[i][j] = INF;
	que.push(PII(sx, sy));
	d[sy][sx] = 0;
	while(que.size()) {
		PII p = que.front(); que.pop();
		//cout << p.first << " " << p.second << endl;
		//if(p.first == gx && p.second == gy) break;
		REP(i, 4) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if(0 <= nx && nx < w && 0 <= ny && ny < h && maze[ny][nx] != '#' && d[ny][nx] == INF) {
				que.push(PII(nx, ny));
				d[ny][nx] = d[p.second][p.first] + 1;
			}
		}
	}
	/*REP(i, h) {
		REP(j, w) {
			cout << d[i][j] << " ";
		}
		cout << endl;
	}*/
	return d[gy][gx];
}

signed main(void)
{
	cin >> h >> w;
	REP(i, h) cin >> maze[i];

	int py, px;
	VI sy, sx;
	REP(i, h) REP(j, w) {
		if(maze[i][j] == '@') {py = i; px = j;}
		else if(maze[i][j] == '$') {sy.PB(i); sx.PB(j);}
		else if(maze[i][j] == '%') {gy = i; gx = j;}
	}

	bfs(gx, gy);

	int p = d[py][px];
	int s = INF;
	REP(i, sx.size()) s = min(s, d[sy[i]][sx[i]]);

	//cout << p << " " << s << endl;
	/*REP(i, h) {
		REP(j, w) {
			cout << d[i][j] << " ";
		}
		cout << endl;
	}*/
	if(s <= p) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 3756
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
ll gcd(ll a,ll b){
    ll t;
    if(a<b){
        t=a;
        a=b;
        b=t;
    }
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int main(){
    ll N;
    cin >> N;
    ll A[N];
    ll i;
    for(i=0;i<N;i++){
        cin >> A[i];
    }
    ll ans=1;
    ll L[N],R[N];
    L[0]=A[0];
    R[N-1]=A[N-1];
    for(i=1;i<N;i++){
        L[i]=gcd(L[i-1],A[i]);
        R[N-i-1]=gcd(R[N-i],A[N-i-1]);
    }
    for(i=1;i<N-1;i++){
        ans=max(ans,gcd(L[i-1],R[i+1]));
    }
    ans=max(ans,L[N-2]);
    ans=max(ans,R[1]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 2560
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define REPRi(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    string S;
    cin>>S;
    int num=0;
    REP(i,4){
        if(S[i]=='+'){
            num+=1;
        }else{
            num-=1;
        }
    }
    cout<<num<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define pb push_back
#define clr clear()
#define sz size()
#define FOR(i,a) for(int i=0;i<(int)(a);i++)
using namespace std;
typedef vector<int> vi;


class data{
public:
  int a,s,t;
  bool cut;

  data(int x,int y,int z,bool w){
    a = x;
    s = y;
    t = z;
    cut = w;
  }
  bool operator<(const data &t) const {return a<t.a;}
};

int main(){
  int n,m,s[100000],t[100000],p[100000];
  int use[100000];
  vector<data> d;

  cin >> n >> m;
  for(int i=0;i<n;i++){
    cin >> s[i] >> t[i];
    d.push_back(data(s[i],i,-1,false));
    d.push_back(data(t[i],-1,i,false));
  }
  for(int i=0;i<m;i++){
    cin >> p[i];
    d.push_back(data(p[i],-1,-1,true));
  }

  sort(d.begin(),d.end());

  for(int i=0;i<n;i++)use[i] = -1;

  long long int ans = 0;
  int c[2],cnt = 0;
  c[0] = 0;c[1] = 0;

  for(int i=0;i<(int)d.size();i++){
    if(i)ans += (long long int)(d[i].a - d[i-1].a) * c[cnt%2];
    if(d[i].cut)cnt = 1-cnt;
    if(d[i].s>=0){
      if(s[d[i].s] < t[d[i].s]){
	use[d[i].s] = cnt%2;
	c[cnt%2]++;
      }
    }
    if(d[i].t>=0){
      if(s[d[i].t] < t[d[i].t])c[use[d[i].t]]--;
    }
  }

  for(int i=(int)d.size()-1;i>=0;i--){
    if(i!=(int)d.size()-1)ans += (long long int)(d[i+1].a - d[i].a) * c[cnt%2];
    if(d[i].cut)cnt = 1-cnt;
    if(d[i].s>=0){
      if(s[d[i].s] > t[d[i].s]){
	use[d[i].s] = cnt%2;
	c[cnt%2]++;
      }
    }
    if(d[i].t>=0){
      if(s[d[i].t] > t[d[i].t])c[use[d[i].t]]--;
    }
  }
  cout << ans << endl;
}

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

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"
#include "profile.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define profile(X) LOG_DURATION(X)
#else
#define debug(...) 42
#define profile(...) 42
#endif

using ll = int64_t;
using ld = double;
const ld EPS = 1e-9;
const int MOD = 1e9 + 7;
const ld PI = 3.141592653589793;
const int maxn = 600001;
using cd = complex<double>;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}


signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    profile("all");
    auto solve = [](int _) {
        int n, m;
        cin >> n >> m;
        vector<int> a(n + 1);
        for (int i = 1; i <= n; ++i) {
            cin >> a[i];
        }
        vector<pair<int, int>> seg;
        ll sum = 0;
        for (int i = 1; i < n; ++i) {
            sum += (a[i + 1] - a[i] + m) % m;
            if (a[i + 1] < a[i]) {
                seg.push_back({a[i] - m, a[i + 1]});
                seg.push_back({a[i], a[i + 1] + m});
            } else {
                seg.push_back({a[i], a[i + 1]});
                seg.push_back({a[i] + m, a[i + 1] + m});
            }
        }
        map<int, vector<pair<int, int>>> events;
        for (int i = 0; i < seg.size(); ++i) {
            int x, y;
            tie(x, y) = seg[i];
            events[x + 1].emplace_back(1, i);
            events[y + 1].emplace_back(-1, i);
        }
        ll best = 1e18;
        ll cur = 0;
        for (auto p:seg) {
            cur += p.second - p.first;
        }
        int open_cnt = 0;
        for (int x = -3 * m; x <= 3 * m; ++x) {
            for (auto ev:events[x]) {
                if (ev.first == -1) {
                    --open_cnt;
                    cur += seg[ev.second].second - seg[ev.second].first - 1;
                }
            }
            cur -= open_cnt;
            best = min(best, cur - sum);
            for (auto ev:events[x]) {
                if (ev.first == 1) {
                    ++open_cnt;
                }
            }
        }
        cout<<best;
    };


    fast_io();

    cout.precision(9);
    cout <<
         fixed;
    for (int i = 1; i <= 1; ++i)
        solve(1);


}


Measured memory_bytes: 59528
#include <stdio.h>
#define N 100
 
int main()
{
  int i, j, array[N], n, mini, swap,count = 0;
 
   scanf("%d", &n);
 
   for (i = 0;i < n;i ++)
      scanf("%d", &array[i]);
 
   for (i = 0;i < n - 1;i ++)
   {
      mini = i;
 
      for (j =  i + 1;j < n; j++)
      {
         if ( array[mini] > array[j] )
            mini = j;
      }
      if ( mini != i )
      {
         swap = array[i];
         array[i] = array[mini];
         array[mini] = swap;
	 count ++;
      }
   }
 
  
   for ( i = 0 ; i < n - 1; i++ )
     {
      printf("%d ", array[i]);
     }
  
   printf("%d\n",array[i]);
   printf("%d\n",count);
   return 0;
}

Measured memory_bytes: 600
n=int(input())
a=[0]+list(map(int,input().split()))+[0]
b=[abs(x-y) for x,y in zip(a[:-1],a[1:])]
s=sum(b)

for i in range(n):
    ans=s-b[i]-b[i+1]
    ans+=abs(a[i]-a[i+2])
    print(ans)



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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

ll a[100010];
ll sum[100010];

int main(void){
	int n;
	cin >> n;
	rep(i,n) cin >> a[i];
	
	sort(a,a+n);
	rep(i,n){
		if(i-1>=0) sum[i]=sum[i-1];
		sum[i]+=a[i];
	}

	int ans=1;
	rrep(i,n-1){
		if(a[i+1]<=2LL*sum[i]) 
			ans++;
		else
			break;
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <numeric>
#include <iterator>

#define SIZE 100005
#define MOD 1000000007
#define INF 100000000

using namespace std;

class order {
public:
    int time;
    int id;
    int dst;

    order(int order_time, int order_id, int order_dst) {
        time = order_time;
        id = order_id;
        dst = order_dst;
    }
};

class orders {
public:
    vector<order> orders;
    set<int> order_time;

    void add(order o) {
        orders.push_back(o);
        order_time.insert(o.time);
    }
};


class graph {
public:
    int node_count;
    int edge_count;
    vector<int> vec;

    graph(int a, int b) {
        node_count = a;
        edge_count = b;
    }

};

class AProblemA {
public:
    void solve(std::istream &cin, std::ostream &cout) {
        int v, e;
        cin >> v >> e;
        vector<vector<int>> edges;
        edges.resize(v + 1, vector<int>(v + 1, 0));
        for (int i = 0; i < e; ++i) {
            int v1, v2, d;
            cin >> v1 >> v2 >> d;
            edges[v1][v2] = d;
            edges[v2][v1] = d;
        }

        int t = 0;
        vector<vector<order>> infos(t);
        orders orders;
        cin >> t;
        for (int j = 0; j < t; ++j) {
            int t;
            cin >> t;
            if (t == 0) continue;
            for (int k = 0; k < t; ++k) {
                int id, dst;
                cin >> id >> dst;
                order o(k, id, dst);
                orders.add(o);
            }
        }
        for (int i = 0; i < t; ++i) {
            cout << -1 << endl;
        }
    }
};


int main() {
    AProblemA solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

		lli n;
		cin>>n;

	vector<lli> a(n);

	REP(i,0,n)cin>>a[i];

	REP(i,0,n){
		if(a[i]%2==0){
			if(a[i]%3!=0 && a[i]%5!=0){
				cout<<"DENIED"<<endl;
				return 0;
			}
		}
	}
	cout<<"APPROVED"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;  //これで"std::cout"が"cout"と書ける

//MACRO
typedef long long ll;                  //64bit以上を表現可能な型
#define INF 100000000                  //ほぼ無限
#define itn int                        //タイポ対策
#define ALL(x) (x).begin(), (x).end()  //sort(all(x))などとする
#define SZ(x) ((int)(x).size())        //size()簡略化
//repetition
#define FOR(i, p, b) for (int i = (p); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define repR(i, n) for (int i = n; i >= 0; i--)
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \<< " " << __FILE__ << endl;
template <class T>
bool chMAX(T &a, const T &b) {  //aよりbが大きければaに代入(参照渡し)
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chMIN(T &a, const T &b) {  //aよりbが小さければaに代入//参照渡し
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int ctoi(const char c) {  //CtoI(int) charを渡すとintに変換する、数字以外だと-1を返す
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}

//
//
//

int main() {
    string s;
    cin >> s;
    vector<string> week = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    int result;
    rep(i, 7) {
        if (s == week[i]) {
            result = 7 - i;
            break;
        }
    }

    cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main() {

	long res = 0;
	long N, K; cin >> N >> K;
	long h[100009]; for (int i = 0; i <= N - 1; i++) cin >> h[i];

	sort(h, h + N);

	long dh[100009];
	for (int i = 0; i <= N - K; i++) dh[i] = h[i + K - 1] - h[i];

	sort(dh, dh + N - K + 1);

	res = dh[0];

	cout << res << endl;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

double deg_to_rad(double degree){
    double pi = acos(-1);
    double rad = pi*degree/180;
    return rad;
}

int main() {
    double A,B,H,M;
    cin >> A >> B >> H >> M;
    double Hdeg = H*30 + M/2;
    double Mdeg = M*6;
    double diff = abs(Hdeg-Mdeg);
    double rad = deg_to_rad(diff);
    cout << fixed << setprecision(15);
    cout << (double)sqrt(A*A+B*B-2*A*B*cos(rad)) << endl;
}

Measured memory_bytes: 4144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, node1, node2, ans, leaf, sett;
vector<ll> adjlist[10005];
ll c[10005];
bool visited1[10005];
bool visited2[10005];
ll sets[10005];
void dfs(ll x){
	if (visited1[x]) return;
	visited1[x] = 1;
	if (adjlist[x].size() == 1 && x != 1){
		leaf = x;
		}
	for (auto i:adjlist[x]){
		if (visited1[i])continue;
		//if (adjlist[i].size() == 1 && i != 1){
		//	leaf = i;
		//	cout << leaf << '\n';
		//	}
			dfs(i);
		}
	
	}
void dfs2(ll x){
	if (visited2[x])return;
	visited2[x] = 1;
	sets[x] = c[sett];
	sett -= 1;
	for (auto i:adjlist[x]){
		if (visited2[i])continue;
		//sets[i] = c[sett];
		//sett -= 1;
		dfs2(i);
		}
	
	}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n;
	for (ll i = 0; i < n-1; i++){
		cin >> node1 >> node2;
		adjlist[node1].push_back(node2);
		adjlist[node2].push_back(node1);
		}
	for (ll i = 1; i <= n; i++){
		cin >> c[i];
		}
		sort(c+1, c+n+1);
		for (ll i = 1; i <= n-1; i++){
			ans += c[i];
			}
			cout << ans << '\n';
		dfs(1); //dfs parts buggy
		//cout << leaf << '\n';
		sett = n;
		dfs2(leaf);
		for (ll i = 1; i <= n; i++){
			//if (sets[i] == c[n])continue;
			cout << sets[i] << ' ';
			}
}

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


int main(int argc, const char* argv[]){
    unsigned long long a, b, c;
    cin >> a >> b >> c;
    if(a + b > c){
        cout << "No" << endl;
        return 0;
    }

    unsigned long long ab = a + b;
    unsigned long long left = 4uLL * a * b + 2uLL * c * ab;
    unsigned long long right = c * c + ab * ab;
    if(left < right){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
template <typename Abelian>
struct BIT {
  BIT(int n, const Abelian &UNITY = 0) : n(n), UNITY(UNITY), dat(n, UNITY) {}

  void add(int idx, const Abelian &value) {
    while (idx < n) {
      dat[idx] += value;
      idx |= idx + 1;
    }
  }

  Abelian sum(int idx) {
    Abelian res = UNITY;
    while (idx >= 0) {
      res += dat[idx];
      idx = (idx & (idx + 1)) - 1;
    }
    return res;
  }

  Abelian sum(int left, int right) { return sum(right) - sum(left - 1); }

  Abelian operator[](const int idx) { return sum(idx, idx); }

  int lower_bound(Abelian value) {
    if (value <= UNITY) return 0;
    int res = 0, exponent = 1;
    while (exponent <= n) exponent <<= 1;
    for (int mask = exponent >> 1; mask > 0; mask >>= 1) {
      if (res + mask - 1 < n && dat[res + mask - 1] < value) {
        value -= dat[res + mask - 1];
        res += mask;
      }
    }
    return res;
  }

private:
  int n;
  const Abelian UNITY;
  vector<Abelian> dat;
};

int main() {
  int n, m, q; cin >> n >> m >> q;
  BIT<int> bit(n);
  vector<vector<int> > r(n);
  while (m--) {
    int L, R; cin >> L >> R; --L; --R;
    bit.add(R, 1);
    r[L].emplace_back(R);
  }
  vector<vector<int> > ans(n, vector<int>(n, 0));
  REP(i, n) {
    FOR(j, i, n) ans[i][j] = bit.sum(j);
    for (int e : r[i]) bit.add(e, -1);
  }
  while (q--) {
    int p, q; cin >> p >> q; --p; --q;
    cout << ans[p][q] << '\n';
  }
  return 0;
}


Measured memory_bytes: 3200