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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

#define MOD 1000000007
#define INF 1001001001

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int main(int, char**)
{
    int n, m;
    cin >> n >> m;

    vector< pair<int, P> > line[2];
    vector<int> grid[2];

    int idx, s, e, k;
    rep(i,2) {
        k = i ? m : n;
        rep(j,k) {
            if (i) { cin >> idx >> s >> e; }
            else { cin >> s >> e >> idx; }
            grid[i].push_back(idx);
            line[i].emplace_back(idx, P(s, e));
        }
    }
    int sz[2];
    rep(i,2) {
        grid[i].push_back(0);
        sort(grid[i].begin(), grid[i].end());
        grid[i].erase( unique(grid[i].begin(), grid[i].end()), grid[i].end());
        sz[i] = grid[i].size();
    }
    vector< vector<int> > area(sz[0]*2, vector<int>(sz[1]*2, 0));

    rep(i,2) {
        for (auto l : line[i]) {
            auto itr = lower_bound(grid[i].begin(), grid[i].end(), l.first);
            int li = distance(grid[i].begin(), itr);
            itr = lower_bound(grid[!i].begin(), grid[!i].end(), l.second.first);
            int d1 = distance(grid[!i].begin(), itr);
            itr = lower_bound(grid[!i].begin(), grid[!i].end(), l.second.second+1);
            int d2 = distance(grid[!i].begin(), itr);
            rep(j,(d2-d1)*2-1) {
                int idx1 = li*2;
                int idx2 = d1*2+j;
                if (i) swap(idx1, idx2);
                area[idx1][idx2] = 1;
            }
        }
    }
    int st[2];
    rep(i,2) {
        auto itr = lower_bound(grid[i].begin(), grid[i].end(), 0);
        st[i] = distance(grid[i].begin(), itr) * 2;
    }
    ll ans = 0;
    queue<P> q;
    q.emplace(st[0],st[1]);
    while (!q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        if (area[x][y]) continue;
        if (x == 0 || y == 0 || x >= (sz[0]-1)*2 || y >= (sz[1]-1)*2) {
            cout << "INF" << endl;
            return 0;
        }
        if (x % 2 && y % 2) {
            ll v = grid[0][x/2+1] - grid[0][x/2];
            ll h = grid[1][y/2+1] - grid[1][y/2];
            ans += v * h; 
        }
        rep(i,4) {
            int nx = x;
            int ny = y;
            int dir = (i % 2) ? 1 : -1;
            if (i / 2) nx += dir;
            else ny += dir;
            if (!area[nx][ny]) q.emplace(nx,ny);
        }
        area[x][y] = 1;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	string s;
	cin>>s;
	if(s[0]=='S'){
		cout<<"Cloudy"<<'\n';
	}
	if(s[0]=='C'){
		cout<<"Rainy"<<'\n';
	}
	if(s[0]=='R'){
		cout<<"Sunny"<<'\n';
	}
	return 0;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	var ans int
	divisors := make([]int, N+1)
	// 1はすべての約数なのでどこかで足す
	wg := new(sync.WaitGroup)
	wg.Add(1)
	go func() {
		for i := 2; i <= N; i++ {
			for j := 1; i*j <= N; j++ {
				// fmt.Println(i * j)
				divisors[i*j]++
				ans += i * j
			}
		}
		wg.Done()
	}()
	// fmt.Println(divisors)
	wg.Wait()
	// for i := 1; i <= N; i++ {
	// 	for j := 1; j*j <= i; j++ {
	// 		if i%j == 0 {
	// 			ans++
	// 			if i/j != i {
	// 				ans++
	// 			}
	// 		}
	// 	}
	// }
	ans += N * (N + 1) / 2
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 82532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) {
        if (a[i] <= b[i]) continue;
        int d = a[i] - b[i];
        rep(ii, n) {
            int dd = (b[ii] - a[ii]) / 2;
            if (dd <= 0) continue;
            if (d <= dd) {
                a[ii] += 2 * d;
                b[i] += d;
                d = 0;
                break;
            }
            a[ii] += 2 * dd;
            b[i] += dd;
            d -= dd;
        }
    }
    rep(i, n) {
        if (a[i] > b[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

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

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        ArrayList<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {
            mylist.add(strinput);
            strinput = reader.readLine();
        }

        String arr01[] = mylist.get(0).split(" ");

        int a = Integer.valueOf(arr01[0]);
        int b = Integer.valueOf(arr01[1]);
        int c = Integer.valueOf(arr01[2]);
        int k = Integer.valueOf(arr01[3]);

        if (a >= k) {
            System.out.println(k);
        } else if (a + b >= k) {
            System.out.println(a);
        } else {
            int nokori = k - (a + b);
            System.out.println(a - Math.min(c, nokori));

        }

    }

}


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

using namespace std;

int getPoint(int n,int k,vector<int> &v){
  int res = 0;
  for(int i = 0 ; i < n ; i++){
    if(i+k > n) break;
    int mul = 1;
    for(int j = i ; j < i+k ; j++){
      mul *= v[j];
    }
    res = max(res,mul);
  }
  return res;
}

int main(){
  int n,k;
  while(true){
    cin >> n >> k;
    if(n == 0 && k == 0) break;
    vector<int> v(n);
    for(int i = 0 ; i < n ; i++){
      cin >> v[i];
    }
    int Cb = getPoint(n,k,v),Ca = 0;
    for(int i = 0 ; i < n ; i++){
      for(int j = i+1 ; j < n ; j++){
	swap(v[i],v[j]);
	Ca = max(Ca,getPoint(n,k,v));
	swap(v[i],v[j]);
      }
    }
    if(Ca-Cb < 0){
      cout << "NO GAME" << endl;
    }else{
      cout << Ca-Cb << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1196
x,n=map(int,input().split())
if n!=0:
 s=set(list(map(int,input().split())))
else:
 s=[]
diff=10**18
ans=10**18
for i in range(-10000,10000):
 if i in s:
   continue
 else:
   if abs(x-i)<diff:
     ans=i
     diff=abs(x-i)
print(ans)

Measured memory_bytes: 64984
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (declare (inline read-byte)
           #-swank (sb-kernel:ansi-stream in))
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (read-byte in nil 0))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setq minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
	 (let* ((byte (%read-byte)))
	   (if (<= 48 byte 57)
	       (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))
	       (return (if minus (- result) result))))))))

(defun main ()
  (let* ((a-num (read-fixnum))
	 (b-num (read-fixnum))
	 (m-num (read-fixnum))
	 (a-price (make-array a-num))
	 (b-price (make-array b-num))
	 (price 200000))
    (dotimes (n a-num)
      (setf (aref a-price n) (read-fixnum)))
    (dotimes (n b-num)
      (setf (aref b-price n) (read-fixnum)))
    (dotimes (i m-num)
      (let* ((a-disc-idx (read-fixnum))
	     (b-disc-idx (read-fixnum))
	     (disc-price (read-fixnum))
	     (result (- (+ (aref a-price (1- a-disc-idx)) (aref b-price (1- b-disc-idx))) disc-price)))
	(if (< result price) 
	    (setq price result))))
    (setq a-price (sort a-price #'<))
    (setq b-price (sort b-price #'<))
    (if (< (+ (aref a-price 0) (aref b-price 0)) price)
	(setq price (+ (aref a-price 0) (aref b-price 0))))
    (format t "~a~%" price)))

(main)


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

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int k;
	cin >> k;
	vector < bool > seen(k, 0);
	int cur = 7;
	for (int i = 1; i <= k; ++i) {
		int t = cur % k;
		if (seen[t]) {
			cout << "-1\n";
			return 0;
		}
		else {
			seen[t] = 1;
			if (t == 0) {
				cout << i << '\n';
				return 0;
			}
			cur = 10 * t + 7;
		}
	}
}


Measured memory_bytes: 3768
c0=list(map(int,input().split(' ')))
c1=list(map(int,input().split(' ')))
c2=list(map(int,input().split(' ')))
f=0
if (c0[0]-c1[0]) != (c0[1] - c1[1]) or (c0[0]-c1[0]) != (c0[2]-c1[2]):
    f=1
if (c0[0]-c2[0]) != (c0[1] - c2[1]) or (c0[0]-c2[0]) != (c0[2]-c2[2]):
    f=1
if (c0[0]-c0[1]) != (c1[0] - c1[1]) or (c0[0]-c0[1]) != (c2[0]-c2[1]):
    f=1
if (c0[2]-c0[1]) != (c1[2] - c1[1]) or (c0[2]-c0[1]) != (c2[2]-c2[1]):
    f=1
if f == 1:
    print('No')
else:
    print('Yes')

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

int main() {
	int n, m;
	cin >> n >> m;
	int cnt[m] = {};
	int k[n];
	for (int i = 0; i < n; i++) {
		cin >> k[i];
		int a[k[i]];
		for (int j = 0; j < k[i]; j++) {
			cin >> a[j];
			cnt[a[j] - 1]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < m; i++) {
		if (cnt[i] == n) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

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

const int MAXN = 62;
typedef pair<int, int> pp;

int main()
{
    int n, p[MAXN];
    while(cin >> n && n)
    {
        int start, stop;
        REP(n) cin >> p[i];
        p[n] = -1;
        vector<pp> page;
        start = p[0], stop = p[0];
        bool second = false;
        for(int i=1; i<n;i++)
        {
            if(p[i] - 1 == stop){ stop = p[i];continue;}

            page.push_back(pp(start, stop));
            start = stop = p[i];
        }
        page.push_back(pp(start, stop));

        REP(page.size())
        {
            if(second) cout << " " ;

            if(page[i].first == page[i].second) cout << page[i].first;
            else cout << page[i].first << "-" << page[i].second ;
            second = true;
        }
        cout << endl;
        

    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

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

    int ans  = 1;
    int temp = a;
    if(b == 1){
        cout << 0 << endl;
        return 0;
    }
    if(a >= b){
        cout << 1 << endl;
        return 0;
    }
    while(b > temp){
        temp = a+(temp-1);
        ++ans;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long int ll;

int main(){
	set<char> s;
	string st;
	cin >> st;
	int n = st.length();
	for(int i = 0;i < n;i++)s.insert(st[i]);
	cout << (s.size() == 2 ? "Yes" : "No");
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.OptionalInt;
import java.util.Scanner;

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

		int n = sc.nextInt();
		int m = sc.nextInt();

		double rtm = Math.sqrt(m);

		List<Integer> list = new ArrayList<Integer>();

		for (int i = 1; i <= rtm; i++) {

			if (m % i == 0) {
				list.add(i);
				list.add(m / i);
			}
		}

		Collections.sort(list);

		OptionalInt ans = list.stream()
				.mapToInt(Integer::intValue)
				.filter(i -> i <= m / n)
				.max();

		System.out.println(ans.getAsInt());
	}
}

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

using namespace std;
const int maxn = 1e5 + 5;
int f[maxn][4], a[maxn][3], n;

int dp(int i, int pre)
{
    if (i > n) return 0;
    if (f[i][pre] != -1) return f[i][pre]; 
    for(int j=0; j<3; ++j) if (j != pre) 
        f[i][pre] = max(f[i][pre], dp(i + 1, j) + a[i][j]);
    return f[i][pre];
}

int main()
{
    #ifdef NTMA 
        freopen("abc.inp", "r", stdin);
    #endif
    memset(f, 255, sizeof(f));
    cin >> n;
    for(int i=1; i<=n; ++i) cin >> a[i][0] >> a[i][1] >> a[i][2];
    cout << dp(1, 3) << endl;
}

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

ll kagen(ll min, ll x){
  if(min < 2){
    return 0;
  }
  return (min-1) / x;
}

ll zyogen(ll max, ll x){
  return max / x;
}

int main(){
  ll a, b, x;
  cin >> a >> b >> x;
  if(a == 0){
    cout << zyogen(b, x) -kagen(a, x) + 1 << endl;
  }else{
    cout << zyogen(b, x) -kagen(a, x) << endl;
  }

}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	fmt.Printf("%d\n", resolve(parseProblem(os.Stdin)))
}

func parseProblem(r io.Reader) (n int, a, b []int) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines

	n = scanInt(sc)
	return n, scanIntSlice(sc, n), scanIntSlice(sc, n)
}

func scanIntSlice(sc *bufio.Scanner, n int) (s []int) {
	for i := 0; i < n; i++ {
		s = append(s, scanInt(sc)-1)
	}
	return s
}

func resolve(n int, a, b []int) int {
	numA, numB := -1, -1
	i := 0
	for l := range permutations(n) {
		if match(l, a) {
			numA = i
		}
		if match(l, b) {
			numB = i
		}
		if numA > -1 && numB > -1 {
			break
		}
		i++
	}
	return abs(numA - numB)
}

func abs(v int) int {
	if v < 0 {
		return -v
	}
	return v
}

func match(a, b []int) bool {
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func permutations(l int) chan []int {
	ch := make(chan []int)
	go func() {
		dfsPermutations(0, make([]bool, l), []int{}, func(perm []int) bool {
			p := make([]int, len(perm))
			copy(p, perm)
			ch <- p
			return false
		})
		close(ch)
	}()
	return ch
}

func dfsPermutations(pos int, used []bool, perm []int, atLeaf func(perm []int) (halt bool)) (halt bool) {
	l := len(used)
	if pos == l {
		if atLeaf(perm) {
			return true
		}
	}

	for i := 0; i < l; i++ {
		if used[i] {
			continue
		}
		used[i] = true
		if dfsPermutations(pos+1, used, append(perm, i), atLeaf) {
			return true
		}
		used[i] = false
	}
	return false
}


Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<string>


using namespace std;

int main(void)
{
	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
	{
		cout << "vowel" << endl;
	}
	else
	{
		cout << "consonant" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

switches = []

for i in range(m):
    array = list(map(int, input().split()))
    switches.append(array[1:])

checker = list(map(int, input().split()))

bit_size = 2 ** n

ans = 0

for i in range(bit_size):
    num = format(i, 'b').zfill(n)
    flag = True
    for j in range(m):
        a = 0
        for k in range(n):
            if num[k] == '1' and k+1 in switches[j]:
                a += 1
        if a % 2 == checker[j]:
            continue
        else:
            flag = False
            break
    if flag is True:
        ans += 1

print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;
using pis = std::pair<int, std::string>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
namespace mp = boost::multiprecision;

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

	int a, b, q;
	cin >> a >> b >> q;
	ll* s = new ll[a + 1];
	ll* t = new ll[b + 1];
	ll* x = new ll[q];
	rep(i, a) cin >> s[i];
	rep(i, b) cin >> t[i];
	rep(i, q) cin >> x[i];
	sort(s, s + a);
	sort(t, t + b);
	s[a] = INF;
	t[b] = INF;

	rep(i, q) {
		int si = lower_bound(s, s + a, x[i]) - s;
		int ti = lower_bound(t, t + b, x[i]) - t;

		ll ans = max(abs(s[si] - x[i]), abs(t[ti] - x[i]));

		if (si != 0) ans = min(ans, abs(x[i] - s[si - 1]) + abs(t[ti] - x[i]) + min(abs(x[i] - s[si - 1]), abs(t[ti] - x[i])));
		if (ti != 0) ans = min(ans, abs(x[i] - t[ti - 1]) + abs(s[si] - x[i]) + min(abs(x[i] - t[ti - 1]), abs(s[si] - x[i])));
		if (si != 0 && ti != 0) ans = min(ans, max(abs(x[i] - s[si - 1]), abs(x[i] - t[ti - 1])));

		cout << ans << "\n";
	}

	return 0;
}


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

// 2つの数の最小公倍数を求める問題

int main() {
	int64_t a, b;
    cin >> a >> b;
    // 公約数の配列
    vector<int> common_div;

    for (int i = 2; i <= min(a,b); i++) {
        while (a % i == 0 && b % i == 0) {
            a /= i;
            b /= i;
            common_div.push_back(i);
        }
    }

    int64_t answer = a * b;

    for (int x : common_div) {
        answer *= x;
    }

    cout << answer << endl;
}

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

const int mod = 998244353;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    mint choose(int n, int a){
        mint x = 1 ,y = 1;
        for(int i=0; i<a; ++i){
            x *= n-i;
            y *= i+1;
        }
        return x / y;
    }
    friend istream& operator>>(istream& is, mint& m){
        is >> m.x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

mint fact[200010];

mint choose2(int n, int a){
    return fact[n]/(fact[n-a]*fact[a]);
}

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    mint ans=0;

    //階乗を前計算
    fact[0]=1;
    for(int i=1; i<200010; ++i){
        fact[i]=fact[i-1]*i;
    }

    for(int i=0; i<=k; ++i){
        ans+=choose2(n-1,i)*(mint)m*mint(m-1).pow(n-i-1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5220
// Problem : A - Not
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
const long long int  modu=1e9+7;
#define endl '\n'
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define inp(x)  for(auto &t:x) cin>>t;
#define itr     vector<int>::iterator
#define debug(a) cout << #a << "=" << a << ' '<<endl;
#define out(x)  for(auto &t:x) cout<<t<<" "; cout<<endl;
#define ff first
#define ss second
#define pb push_back
#define initialize(a,v)  for(int i=0;i<a.size();++i) a[i]=v;
#define all(x) x.begin(),x.end()
#define mpt(mp) for(auto it=mp.begin();it!=mp.end();it++)
#define trav(x) for(int i=0;i<(int)x.size();++i)
#define mkp(a,b) make_pair(a,b)
#define sz(x)  (int)x.size()

int noofdig(int N)
{
	return floor(log10(N))+1;
}


ll f(ll a)
{

return 0;

}



void pre()
{

}

ll expo(ll a,ll b)
{
	ll res=1;
	a%=modu;
	while(b>0)
	{
		if(b&1)
		res=((res%modu)*(a%modu))%modu;
		a=((a%modu)*(a%modu))%modu;
		b>>=1;
	}
	return (res)%modu;
}





void solve()
{
	unsigned ll n;
	cin>>n;
	
	cout<<(unsigned ll)(expo(10,n)%modu-(2*(expo(9,n)))%modu+(expo(8,n)) + 2*modu)%modu<<endl;

}



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

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


Measured memory_bytes: 3676
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        a: [i32; 4],
    }
    let s = a.iter().fold(0, |s, a| s + *a);
    let mut ans = std::i32::MAX;
    for i in 0..4 {
        for j in 0..i {
            let x = a[i] + a[j];
            ans = std::cmp::min(ans, ((s - x) - x).abs());
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}



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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int n, m;
  while(cin >> n >> m){
    int ans = n * (n - 1) / 2 + m * (m - 1) / 2;

    puts_all(ans);
  }


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vi vector<int>
#define vb vector<bool>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
using namespace std;
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
void show(ll x){cout<<x<<" ";}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define mkp make_pair
//#define d double
void solve(){
	int n,m;
	cin>>n>>m;
	vl dp(1<<n,inf);
	vi cost(m);
	vvi keys(m);
	set<int> st;
	for(int i=0;i<m;i++){
		int a,b,x;
		cin>>a>>b;
		cost[i]=a;
		for(int j=0;j<b;j++) cin>>x,keys[i].pb(x-1),st.insert(x-1);
	}
	if(st.size()!=n){
		cout<<"-1"<<endl;
		return ;
	}
	dp[0]=0;
	for(int mask=0;mask<(1<<n);mask++){
		for(int i=0;i<m;i++){
			int msk=mask;
			for(int j=0;j<keys[i].size();j++){
				//dp[mask|(1<<keys[i][j])]=min(dp[mask|(1<<keys[i][j])],dp[mask]+cost[i]);
				msk|=(1<<keys[i][j]);
			}
			dp[msk]=min(dp[msk],dp[mask]+cost[i]);
		}
	}
	int target=(1<<n)-1;
	cout<<dp[target];
}
int32_t main(){
FIO;
int t=1;
//cin>>t;
while(t--){
	solve();
}
}

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

int main(){
  long k;  cin >> k;
  long sevens = 7, ans = 1;
  if(k%2==0 || k%5==0){
    cout << "-1" << endl;
    return 0;
  }
  while(sevens % k){
    sevens = (sevens*10%k + 7) % k;
    ans++;
  }

  cout << ans << endl;
  
  return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inN(A) cin>>n;for(i=0;i<n;++i)cin>>A[i];
#define rep(i,a,b) for(i=a;i<b;++i)
#define repn for(i=0;i<n;++i)
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define sd second
#define ft first
#define vi vector<int>
#define vpii vector<pair<int,int> >
#define abs(a) (a>=0?a:-a)
#define TC //int T;cin>>T;while(T--)
#define n_max 200001
#define mod 1000000007

vi G[n_max];

int main() {
    int a,b,p,i,j,l,n;
    TC
    {
    	cin>>n;
    	rep(i,0,n-1){cin>>j>>b;if(j>b)swap(j,b);G[b].pb(j);}
    	ll ans=1,k=1;
    	rep(i,2,n+1)
    	{
    		sort(G[i].begin(),G[i].end());
    		for(j=G[i].size()-1,l=1,a=i;j>=0;--j)
    		{
    			k+=(ll)(a-G[i][j])*l--;
    			a=G[i][j];
    		}
    		k+=(ll)a*l;
    		ans+=k;
    	}
    	cout<<ans;
    }
}



Measured memory_bytes: 14564
#include<cstdio>
#include<cmath>
#include<math.h> 
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
double t,tang,pans,ans,pi=3.141592654;
int a,b,x,v;
int main()
{
	scanf("%d%d%d",&a,&b,&x);
	v=a*a*b;
	if(x>v/2)
	{
		t=(double)(2*v-2*x)/(a*a);
		tang=(double)t/a;
		pans=atan(tang);
		ans=(double)pans*180/pi;
	}
	else if(x<v/2)
	{
		t=(double)2*x/(a*b);
		tang=(double)b/t;
		pans=atan(tang);
		ans=(double)pans*180/pi;
	}
	else
		ans=45.000000;
	printf("%.7f\n",ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long m = 0;
        long[] array = new long[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextLong();
            if (m < array[i]) {
                m = array[i];
            }
        }
        long ans = 1;
        for (int i = 0; i < n; i++) {
            ans = lcm(ans, array[i]);
        }
        if (ans < m) {
            ans = m;
        }
        System.out.println(ans);
    }
    
    public static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }
    public static long lcm(long a, long b) {
        return a/gcd(a,b)*b;
    }
}


Measured memory_bytes: 23636
n=int(input())
a=[]
cnt=0
ans=""
s=0
if n>=6:
    for j in range(2,30001):
        if j%6==0 or j%6==2 or j%6==3 or j%6==4:
            a.append(j)
            cnt+=1
            s+=j
            if cnt==n:
                if s%6==0:
                    for i in range(n-1):
                        ans+=str(a[i])+" "
                    ans+=str(a[-1])
                    print(ans)
                elif s%6==2:
                    a[4]=30000
                    for i in range(n-1):
                        ans+=str(a[i])+" "
                    ans+=str(a[-1])
                    print(ans)
                elif s%6==3:
                    a[5]=30000
                    for i in range(n-1):
                        ans+=str(a[i])+" "
                    ans+=str(a[-1])
                    print(ans)
                else:
                    a[5]=29998
                    for i in range(n-1):
                        ans+=str(a[i])+" "
                    ans+=str(a[-1])
                    print(ans)
elif n==3:
    print(str(2)+" "+str(5)+" "+str(63))
elif n==4:
    print(str(2)+" "+str(5)+" "+str(20)+" "+str(63))
else:
    print(str(2)+" "+str(5)+" "+str(20)+" "+str(30)+" "+str(63))

Measured memory_bytes: 4180
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int total = pow(3, n);
  int total2 = 1;

  for (int i = 0; i < n; i++) {
    if (a[i] % 2 == 0) {
      total2 *= 2;
    }
  }
  // cout << total2 << endl;
  cout << total - total2 << endl;
}


Measured memory_bytes: 640
#include<cstdio>
using namespace std;
int main()
{
	int a,b,x,cnt;
	scanf("%d %d",&a,&b);
	cnt=0;
	x=1;
	while(1){
		if(x>=b)	break;
		x+=a-1;
		cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
  static final long INF = Long.MAX_VALUE / 2;
  static long h, w;

  static final boolean DEBUG = true;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    h = sc.nextInt();
    w = sc.nextInt();

    if(h % 3 == 0 || w % 3 == 0){
      System.out.println(0);
      return;
    }

    long min = INF;
    for(long i = 1; i < w; i++){
      long s1 = h * i;
      long s2 = h * ((w - i) / 2);
      long s3 = h * w - (s1 + s2);
      min = Math.min(min, 
          Math.max(s1, Math.max(s2, s3)) - Math.min(s1, Math.min(s2, s3)));
    }
    for(long i = 1; i < h; i++){
      long s1 = w * i;
      long s2 = w * ((h - i) / 2);
      long s3 = h * w - (s1 + s2);
      min = Math.min(min, 
          Math.max(s1, Math.max(s2, s3)) - Math.min(s1, Math.min(s2, s3)));
    }
    for(long i = 1; i < w; i++){
      long s1 = h * i;
      long s2 = (h / 2) * (w - i);
      long s3 = h * w - (s1 + s2);
      min = Math.min(min, 
          Math.max(s1, Math.max(s2, s3)) - Math.min(s1, Math.min(s2, s3)));
    }
    for(long i = 1; i < h; i++){
      long s1 = w * i;
      long s2 = (w / 2) * (h - i);
      long s3 = h * w - (s1 + s2);
      min = Math.min(min, 
          Math.max(s1, Math.max(s2, s3)) - Math.min(s1, Math.min(s2, s3)));
    }

    System.out.println(min);
  }
}


Measured memory_bytes: 23892
#include <iostream>
using namespace std;
int main(void){
    int a, b;
    cin >> a;
    cin >> b;
    
    if (a > b)
        cout << "a > b" << endl;
    else if (a < b)
        cout << "a < b" << endl;
    else
        cout << "a == b" << endl;
}

Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	char pos1, pos2, c;
	int cup[] = {1,0,0};
	while(cin >> pos1 >> c >> pos2){
		swap(cup[pos1-'A'], cup[pos2-'A']);
	}
	for(int i = 0 ; i <3; i++){
		if(cup[i]){
			cout << (char)(i+'A') << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 1132
using System;
using System.Linq;
class aoj
{
    static void Main()
    {
        int[] c = new int[8];
        c[0] = 1;c[1] = 2;c[2] = 1;c[3] = 2;c[4] = 1;c[5] = 4;c[6] = 1;c[7] = 4;
        while (true)
        {
            string a = Console.ReadLine();
            if (String.IsNullOrEmpty(a)) break;
            int[] b = a.Split(' ').Select(int.Parse).ToArray();
            int[] f = new int[3];
            f[0] = 1000000000;
            for (int i = 0; i < 8; i++)
            {
                int e = 0;
                char[] h = new char[8];
                for (int j = 0; j < 8; j++)
                {
                    int d = j + i;
                    if (d >= 8)
                        d -= 8;
                    int g = b[j] - c[d];
                    if (g < 0)
                        g = 0;
                    e += g;
                    h[j] = (char)(c[d] + '0');
                }
                if (f[0] > e)
                {
                    f[0] = e;
                    f[1] = i;
                    string k = new string(h);
                    f[2] = int.Parse(k);
                }
                if (f[0] == e)
                {
                    string k = new string(h);
                    int l = int.Parse(k);
                    if (f[2] > l)
                    {
                        f[1] = i;
                        f[2] = l;
                    }
                }
            }
            int m = f[1];
            for (int i = 0; i < 8; i++)
            {
                int n = m + i;
                if (n >= 8)
                    n -= 8;
                if (i == 0)
                    Console.Write(c[n]);
                else
                    Console.Write(" " + c[n]);
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<P> XL(N);
    rep(i, N) cin >> XL[i].first >> XL[i].second;
    sort(all(XL));

    int ans = 1;
    int l = XL[0].first - XL[0].second;
    int r = XL[0].first + XL[0].second;

    repd(i, 1, N) {
        int nl = XL[i].first - XL[i].second;
        int nr = XL[i].first + XL[i].second;
        if (r > nl) {
            if (r > nr) {
                r = nr;
            }
        }
        else {
            r = nr;
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
n=int(input())
c=list(input())
all_r=c.count('R')
l_w=0
l_r=0
ans=0
for i in range(n):
  if l_w==all_r-l_r:
      ans=l_w
      break
  if c[i]=='W':
    l_w+=1
  else:
    l_r+=1
print(ans)


Measured memory_bytes: 73280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
using tii = tuple<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
//#define INF (ll)1E9
#define INF INT_MAX
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

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

//constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

struct segtree {
	int N = 1;
	vi val;
	segtree(int n) {
		while (N < n) N *= 2;
		val = vi(2*N);
		for (int i = 0; i < 2 * N;i++) {
			val[i] = INF;
		}
	}
	void replace(int k, int a) {
		k += N;
		val[k] = a;
		while (k > 0) {
			k =  k / 2;
			val[k] = min(val[k * 2],val[k * 2 + 1]);
		}
	}
	int minim(int a, int b) { return minim(a, b, 1, 0, N); }
	int minim(int a, int b, int k,int l, int r) {
		if (r <= a || b <= l) return INF;
		if (a <= l && r <= b) return val[k];
		int m = (l + r) / 2;
		return min(minim(a, b, k * 2, l, m), minim(a, b, k * 2 + 1, m, r));
	}
};

int main(void) {
	int n, q;
	int a, b, c;
	cin >> n >> q;
	segtree st(n);
	rep(i, q) {
		cin >> a >> b >> c;
		if (a == 0) {
			st.replace(b, c);
		}
		else cout << st.minim(b, c+1)<<endl;
	}
	///cout << endl;
	//rep(i, st.val.size())cout <<i<<"  "<< st.val[i] << endl;
}




Measured memory_bytes: 3876
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("ride.in");ofstream coutt("ride.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 

int n,m;
int fr[100005];
int dp[100005];

signed main(){
    FASTER;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int x;cin>>x;
        fr[x]=1;
    }
    dp[0]=1;
    dp[1]=1-fr[1];
    for(int i=2;i<=n;i++){
        if(!fr[i])dp[i]=(dp[i-1]+dp[i-2])%MOD;
    }
    cout<<dp[n];
}

Measured memory_bytes: 5196
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
using namespace std;
int main(){
  int k,n;
  cin >> k >> n;
  vector<long long> a(n);
  for(int i=0; i<n; ++i){
    cin >>a[i];
  }
  sort(a.begin(),a.end());
  long long dis=a[n-1]-a[0];
  for(int i=1; i<n; i++){
    if(k+a[i-1]-a[i]<dis){
      dis=k+a[i-1]-a[i];
    }
  }
  cout << dis << endl;
}


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

int main(void){
  int N;
  cin >> N;
  
  vector<pair< pair<string, int>, int>> rList;
  vector<int> rList_num;
  string tmpS;
  int tmpInt;
  for(int i=0; i<N; i++){
    cin >> tmpS >> tmpInt;
    rList.emplace_back(make_pair(make_pair(tmpS, 100-tmpInt), i+1));
  }
  
  sort(rList.begin(), rList.end());
  
  for(int i=0; i<N; i++){
//    cout << rList[i].first.first << 100-rList[i].first.second << rList[i].second << endl;
    cout << rList[i].second << endl;
  }
 
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            if (map.containsKey(num)) {
                int tmp = map.get(num);
                tmp++;
                map.put(num, tmp);
            } else {
                map.put(num, 1);
            }
        }
        int count = 0;
        for (int key : map.keySet()) {
            int tmp = map.get(key);
            if (tmp < key) {
                count += tmp;
            } else {
                count += tmp - key;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 60640
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int sum = 0;
		for(int i=0;i<3;i++) {
			sum += nextInt();
		}

		if(sum > 21) {
			out.println("bust");
		}else{
			out.println("win");
		}

	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}
}

Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include<map>
#include<string>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<typeinfo>
#include<queue>
using namespace std;
int gcd(int a,int b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
int main() {
	long long int A, B, C, D;
	cin >> A >> B >> C >> D;
	long long int C_num, D_num,CD_num;
	int GCD_CD;
	if (C > D)GCD_CD = gcd(C, D);
	else GCD_CD = gcd(D,C);
	if(A%C==0)C_num = (B / C) - (A / C) + 1;
	else C_num = (B / C )- (A / C);
	if (A % D == 0)D_num =( B / D) - (A / D) + 1;
	else D_num = (B / D) -( A / D);
	if(A%(C*D/GCD_CD)==0)CD_num = (B / (C*D/GCD_CD))-(A/(C*D/GCD_CD)) + 1;
	else CD_num = (B / (C * D/GCD_CD)) - (A / (C * D/GCD_CD));
	cout << B - A + 1 - C_num - D_num + CD_num<<endl;
}
		

Measured memory_bytes: 256