akhauriyash/Code-Regression huggingface dataset:
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>

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

ump mp;

// nCr: v[n][r]
vector<vector<ll>> comb(ll n, ll r) {
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for (int i = 0; i < v.size(); i++) {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (int j = 1; j < v.size(); j++) {
        for (int k = 1; k < j; k++) {
            v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
        }
    }
    return v;
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        int n, a, b;
        cin >> n >> a >> b;
        vector<double> v(n);
        rep(i, n) {
            cin >> v[i];
            mp[v[i]]++;
        }
        sort(v.begin(), v.end(), greater<>());
        cout << fixed << accumulate(v.begin(), v.begin() + a, 0.0) / a << endl;
        if (v[a - 1] == v[a]) {
            if (v[0] == v[a]) {
                ll ans = 0;
                for (int i = a; i <= min(int(mp[v[0]]), b); ++i) {
                    ans += comb(mp[v[0]], i)[mp[v[0]]][i];
                }
                cout << ans << endl;
            } else {
                int s = 0;
                rep(i, a) {
                    if (v[i] == v[a - 1]) break;
                    s++;
                }
                cout << comb(mp[v[a - 1]], a - s)[mp[v[a - 1]]][a - s] << endl;
            }

        } else {
            cout << 1 << endl;
        }


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  cin >> n;
  cout << (n+1)/2 << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll x;
  cin >> x;
  rep(i, 1e5) {
    ll now = i * (i + 1) / 2;
    if(now >= x) {
      cout << i << endl;
      return 0;
    }
  }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  string str;
  cin >> str;
  char kth = str.at(K - 1);
  if (kth == 'A') {
    str.at(K - 1) = 'a';
  } else if (kth == 'B') {
    str.at(K - 1) = 'b';
  } else if (kth == 'C') {
    str.at(K - 1) = 'c';
  }
  cout << str << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max

object Solve {

  private val br = BufferedReader(InputStreamReader(System.`in`))
  private val out = PrintWriter(System.out)

  fun solve() {

    var (n, x, t) = br.readLine()!!.split(' ').map { it.toInt() }

    out.println(t * (n / x + if (n % x == 0) 0 else 1))
    out.flush()
  }
}

fun main(args: Array<String>) {
  Solve.solve()
}

Measured memory_bytes: 36412
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
const double eps = 1e-7;
int N, M, K, Q, T;
priority_queue<int> A, B, C;

int main()
{
	int i, j, x, y, z, a, b, c;
	scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
	vector<int> vec;
	for (i = 1; i <= a; ++i) {
		scanf("%d", &z);
		vec.push_back(z);
	}
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	for (i = 0; i < x; ++i) {
		A.push(-vec[i]);
	}
	vec.clear();
	for (i = 1; i <= b; ++i) {
		scanf("%d", &z);
		vec.push_back(z);
	}
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	for (i = 0; i < y; ++i) {
		B.push(-vec[i]);
	}
	vec.clear();
	for (i = 1; i <= c; ++i) {
		scanf("%d", &z);
		vec.push_back(z);
	}
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	for (i = 0; i < c; ++i) {
		C.push(vec[i]);
	}
	vec.clear();
	while (!C.empty()) {
		int cval = C.top();
		C.pop();
		int aval = -A.top();
		int bval = -B.top();
		if (cval < aval && cval < bval) break;
		if (aval < bval) {
			A.pop();
			A.push(-cval);
		}
		else {
			B.pop();
			B.push(-cval);
		}
	}
	ll sum = 0LL;
	while (!A.empty()) {
		sum += (ll)(-A.top());
		A.pop();
	}
	while (!B.empty()) {
		sum += (ll)(-B.top());
		B.pop();
	}
	printf("%lld", sum);

}

Measured memory_bytes: 2168
use std::io;


/// https://beta.atcoder.jp/contests/abc051/tasks/abc051_b
fn main() {
    let (k, s) = {
        let i = read::<isize>();
        (i[0], i[1])
    };

    let mut ans = 0;
    for i in 0..(k + 1) { for j in 0..(k + 1) {
        let z = s - i - j;
        if 0 <= z && z <= k { ans += 1; }
    }}

    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

int main(){
     long long N,A,B;
    cin >> N >> A>>B;
    long long dis = max(A,B) - min(A,B);
    if(dis%2==0){
        cout<<dis/2<<endl;
    }
    else{
        long long  E =(max(A,B)+min(A,B)-1)/2;
        long long  F =(2*N-max(A,B)-min(A,B)+1)/2;
        cout<<min(E,F)<<endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main { 
    public static void main(String[] args) { 
        try (Scanner sc = new Scanner(System.in)) { 
            while (true) { 
                int n = sc.nextInt(); 
                if (n == 0) { 
                    break; 
                } 
            int[] scores = new int[n]; 
            for (int i = 0; i < scores.length; i++) { 
                scores[i] = sc.nextInt(); 
            } 
            double sum = 0, average = 0, variance = 0, x = 0, xsum = 0; 
            for (int j = 0; j < scores.length; j++) {
                sum+=scores[j];
            }
            average = sum / scores.length;
            for (int k = 0; k < scores.length; k++) {
                x=scores[k]-average;
                xsum+=x*x;
            }
            variance = xsum / scores.length;
            System.out.println(Math.sqrt(variance)); 
            } 
        } 
    } 
}



Measured memory_bytes: 31540
#include<iostream> 
#include<bits/stdc++.h> 
using namespace std; 
int main()
{
   long long  int n,x,t;
    cin>>n>>x>>t;
   if(n%x==0)
     cout<<(n/x)*t;
else 
cout<<(n/x+1)*t;
    return 0;
}

Measured memory_bytes: 3648
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


M, D = MI()
cnt = 0
for m in range(1, M + 1):
    for d in range(1, D + 1):
        d10, d1 = divmod(d, 10)
        if d1 > 1 and d10 > 1 and d1 * d10 == m:
            cnt += 1
print(cnt)

Measured memory_bytes: 38896
n=int(input())
a=sorted([int(input()) for _ in range(n)])

ptr=0
res=0
while ptr<n:
    cc=a[ptr]
    f=0
    while ptr<n and a[ptr]==cc: #出現回数をカウント
        f+=1
        ptr+=1
    res+=f%2 #奇数回の場合インクリメント
print(res)

Measured memory_bytes: 51288
S = input()
ANSlist = []

for i in range(len(S)):
    if S[i] == '0':
        ANSlist.append('0')
    elif S[i] == '1':
        ANSlist.append('1')
    elif S[i] == 'B':
        if len(ANSlist) >=1:
            del ANSlist[-1]

ANS = ''.join(ANSlist)

print(ANS)

Measured memory_bytes: 3064
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);

            if (a < b){
                Console.WriteLine("a < b");
            }
            else if (a > b){
                Console.WriteLine("a > b");
            }
            else if (a == b){
                Console.WriteLine("a == b");
            }
        }
    }
}


Measured memory_bytes: 15880
#include <iostream>
#include <bits/stdc++.h>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>
#include <unistd.h>

using namespace std;

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

long long int INF = 1e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define line cout << "----------" << endl;


ll mod = 1000000007;
ll rui(ll number1,ll number2){

    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){

    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){

    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){

    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

/*
ll fact[800005],rfact[800005];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
	rfact[800000] = rui(fact[800000],mod - 2);
	for(ll i=800000; i>=1; i--){
	   rfact[i-1] = rfact[i] * i;
	   rfact[i-1] %= mod;
	}
	return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q;
ll x[300005],y[300005],z[100005];
char s[500005];
bool ok;


int main(){
	cin >> a >> b;
    num = a - b;
    if(num < 0)num *= -1;
    if(num % 2 == 0){
        p((a+b)/2);
    }else{
        p("IMPOSSIBLE");
    }
	return 0;
}



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



int main()
{
	int n, q;
	int time = 0;
	queue <int> queNum;
	queue <string> queName;
	cin >> n >> q;
	for (int i = 0; i < n; i++)
	{
		int N;
		string name;
		cin >> name;
		cin >> N;
		queName.push(name);
		queNum.push(N);
	}
	while (1)
	{
		int ans = queNum.front() - q;
		if (ans <= 0)
		{
			cout << queName.front() << " " << time+q+ans << endl;
			queNum.pop();
			queName.pop();
		}
		else
		{
			queNum.push(ans);
			queName.push(queName.front());
			queNum.pop();
			queName.pop();
		}

		if (queNum.empty()) break;

		if (ans > 0)ans = 0;
		time += q+ans;
	}
	return 0;
}

Measured memory_bytes: 5608
//	ZapZu's code hohoho
//	#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define dfs_black 1
#define dfs_white -1
#define pr pair
#define vt vector
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef double db;
typedef long long li;
typedef long double ld;

typedef pr<int, int> ii;
typedef pr<ld,ld> dd;

typedef vt<int> vi;
typedef vt<li> vli;
typedef vt<ld> vld;
typedef vt<ii> vii;

typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, char> mic;

typedef set<int> s_i;
typedef set<char> s_c;

const int MOD = 1e9+7;
const li INF = 1e18;
const ld PI = 4*atan((ld)1);
int pf1[200005], pf2[200005];
signed main()
{
//	freopen(".inp", "r", stdin);
//	freopen(".out", "w", stdout);
	string s, t;
	cin>>s>>t;
	for(int i=0; i<s.length(); i++) pf1[i+1] = pf1[i]+(s[i]=='A'? 1: -1);
	for(int i=0; i<t.length(); i++) pf2[i+1] = pf2[i]+(t[i]=='A'? 1: -1);
	int q;
	cin>>q;
	while(q--)
	{
		int a, b, c, d;
		cin>>a>>b>>c>>d;
		int t1 = pf1[b] - pf1[a-1], t2 = pf2[d] - pf2[c-1]; t1%=3; t2%=3;
		while(t1<0) t1+=3; while(t2<0) t2+=3;
		if(t1==t2) cout<<"YES\n";
		else cout<<"NO\n";
	}
}




Measured memory_bytes: 4560
#include <iostream>
 
using namespace std;
 
int main()
{
   char s;
   cin >> s;
 
   if ('A'<=s&&s<='Z')
   {
       cout << "A" << endl;
   }
   else
   {
       cout << "a" << endl;
   }
 
   return 0;
}


Measured memory_bytes: 3600
c1 = list(map(int,input().split()))
c2 = list(map(int,input().split()))
c3 = list(map(int,input().split()))
a = c1[0]+c2[1]+c3[2]
b = c1[1]+c2[2]+c3[0]
c = c1[2]+c2[0]+c3[1]
d = c1[0]+c2[2]+c3[1]
e = c1[1]+c2[0]+c3[2]
f = c1[2]+c2[1]+c3[0]
if a==b==c==d==e==f:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3064
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = read().rstrip().decode()
ans = ''
for ss in s:
    if ss == 'B':
        if ans:
            ans = ans[:-1]
    else:
        ans += ss
print(ans)


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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int getDigit(int x) {
  int res = 0;
  while (x > 0) {
	x /= 10;
	res++;
  }

  return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	cin >> n;
	int res = 0;
	FOR (i, 1, n + 1) {
	  if (getDigit(i) % 2) res++;
	}
	cout << res << endl;
    
    return 0;
}



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

int main(){
    int n,d,x;
    cin >> n >> d >> x;
    int a;
    int cnt = 0;
    for (int i = 0;i < n;i++){
        cin >> a;
        cnt += (d-1)/a + 1;
    }    

    cout << cnt + x << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdio.h>
int main()
{
    char s[200000],temp[2000000];
    int first,last,len,i;
    gets(s);
    len=strlen(s);
    for(i=0; i<len; i++)
    {
        if(s[i]=='A')
        {
            first=i;
            break;
        }
    }
    for(i=len-1; i>=0; i--)
    {
        if(s[i]=='Z')
        {
            last=i;
            break;
        }
    }
    for(i=0; i<=last-first; i++)
    {
        temp[i]=s[first+i];
    }
    printf("%d",strlen(temp));
}



Measured memory_bytes: 1996
import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()
a,b,c,d=map(int,input().split())
def count(start, end, x):
    return (end // x) - (start // x + (1 if start % x else 0)) + 1
print(b-a+1-(count(a,b,c) + count(a,b,d) - count(a,b,c*d//gcd(c,d))))

Measured memory_bytes: 5304
package main

import "fmt"

const max int = 1000000
const mod int = 1000000007

var f [max]int
var rf [max]int

func main() {

	var X, Y int
	fmt.Scan(&X, &Y)
	ComInit()
	for a := 0; a < X+1; a++ {
		b := Y - 2*a
		if a+2*b == X {
			fmt.Println(C(a+b, a))
			return
		}
	}
	fmt.Println(0)
}
func ComInit() {
	f[0], rf[0] = 1, 1
	for i := 1; i < max; i++ {
		f[i] = (f[i-1] * i) % mod
		rf[i] = ModPow(f[i], mod-2, mod)
	}
}
func C(n, k int) int {
	a := f[n]
	b := rf[n-k]
	c := rf[k]

	bc := (b * c) % mod

	return (a * bc) % mod
}
func ModPow(x, n, mod int) int {
	sum := 1
	for n > 0 {
		if (n & 1) == 1 {
			sum = sum * x % mod
		}
		x = x * x % mod
		n = n >> uint(1)
	}
	return sum

}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
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; }


#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

const int INF = 1000000000;
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
int N, M;
Graph G;
vector<long long> D;

void solve() {
    map<int, vector<int>> as;
    for (int i = 0; i < N; ++i) as[D[i]].push_back(i);
    vector<int> color(N, -1);
    vector<int> res(M, INF);
    for (auto it : as) {
        int d = it.first;
        auto vec = it.second;
        for (auto v : vec) {
            if (color[v] != -1) continue;
            for (auto e : G[v]) {
                if (D[e.first] <= d) {
                    res[e.second] = d;
                    if (color[e.first] != -1) color[v] = 1-color[e.first];
                    else color[v] = 1, color[e.first] = 0;
                    break;
                }
            }
            if (color[v] == -1) {
                cout << -1 << endl;
                return;
            }
        }
    }
    for (int v = 0; v < N; ++v) {
        if (color[v] == 1) cout << 'B';
        else cout << 'W';
    }
    cout << endl;
    for (int i = 0; i < M; ++i) cout << res[i] << endl;
}

int main () {
    while (cin >> N >> M) {
        D.resize(N);
        for (int i = 0; i < N; ++i) cin >> D[i];
        G.assign(N, vector<Edge>());
        for (int i = 0; i < M; ++i) {
            int u, v; cin >> u >> v; --u, --v;
            G[u].emplace_back(v, i);
            G[v].emplace_back(u, i);
        }
        solve();
    }
}


Measured memory_bytes: 22400
#include <iostream>
#include <map>

using namespace std;

int y[1501],x[1501];
int main(){
  int N,M;
  while(cin>>N>>M&&(N>0&&M>0)){
    for(int i=1,s=0;i<=N;++i){
      int h;
      cin>>h;
      s += h;
      y[i] = s;
    }
    for(int i=1,s=0;i<=M;++i){
      int w;
      cin>>w;
      s += w;
      x[i] = s;
    }

    map<int,int> hmap,wmap;
    for(int i=0;i<N;++i){
      for(int j=i+1;j<=N;++j){
        hmap[y[j]-y[i]]++;
      }
    }
    for(int i=0;i<M;++i){
      for(int j=i+1;j<=M;++j){
        wmap[x[j]-x[i]]++;
      }
    }

    long num = 0;
    for(const auto &p:hmap){
      num += wmap[p.first]*p.second;
    }
    cout<<num<<endl;
  }
  return 0;
}

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

int moveX(vector<char>& str, int posX, int targetX)
{
    while(posX < targetX)
    {
        posX += 1;
        str.push_back('R');
    }
    while(targetX < posX)
    {
        posX -= 1;
        str.push_back('L');
    } 

    return posX;
}

int moveY(vector<char>& str, int posY, int targetY)
{
    while(posY < targetY)
    {
        posY += 1;
        str.push_back('U');
    }
    while(targetY < posY)
    {
        posY -= 1;
        str.push_back('D');
    }

    return posY;
}

int main() {
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    int posX=sx;
    int posY=sy;
    vector<char> str;

    // step1
    posX = moveX(str, posX, tx);
    posY = moveY(str, posY, ty);
    
    // step2
    posX = moveX(str, posX, sx);
    posY = moveY(str, posY, sy);

    // final step
    if(sx < tx && sy < ty)
    {
        posX -= 1;
        str.push_back('L');
        posY = moveY(str, posY, ty+1);
        posX = moveX(str, posX, tx);
        posY = moveY(str, posY, ty);

        posX += 1;
        str.push_back('R');
        posY = moveY(str, posY, sy-1);
        posX = moveX(str, posX, sx);
        posY = moveY(str, posY, sy);
    }else if(tx < sx && sy < ty)
    {
        posX += 1;
        str.push_back('R');
        posY = moveY(str, posY, ty+1);
        posX = moveX(str, posX, tx);
        posY = moveY(str, posY, ty);       

        posX -= 1;
        str.push_back('L');
        posY = moveY(str, posY, sy-1);
        posX = moveX(str, posX, sx);
        posY = moveY(str, posY, sy);
    }else if(tx < sx && ty < sx)
    {
        posX += 1;
        str.push_back('R');
        posY = moveY(str, posY, ty-1);
        posX = moveX(str, posX, tx);
        posY = moveY(str, posY, ty);

        posX -= 1;
        str.push_back('L');
        posY = moveY(str, posY, sy+1);
        posX = moveX(str, posX, sx);
        posY = moveY(str, posY, sy);   
    }else
    {
        posX -= 1;
        str.push_back('L');
        posY = moveY(str, posY, ty-1);
        posX = moveX(str, posX, tx);
        posY = moveY(str, posY, ty);

        posX += 1;
        str.push_back('R');
        posY = moveY(str, posY, sy+1);
        posX = moveX(str, posX, sx);
        posY = moveY(str, posY, sy);   
    }
    
    for(int i=0; i<str.size(); i++) cout << str[i];
    cout << endl;

    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long int
int n, m, k;
bool possible(int sum)
{
    int dup = m - sum;

    int value = dup / (n - 1);

    if (value == 0) return (sum < 2);

    cout << value << "\n";


    int rem = dup % (n - 1);

    if (rem != 0) rem = 1;
    else
        rem = 0;

    return (abs(sum - value - rem) < 2);

}
void findAns()
{
    int k, x;
    cin >> k >> x;

    if (k * 500 >= x) cout << "Yes";
    else
        cout << "No";
}
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
//     freopen("test.txt", "w", stdout);
//     //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s" << "\n";
// #endif

    FAST;
    ll  t = 1;
    //cin >> t;

    while (t--) findAns();
}


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

int main(){
  string S;
  cin>>S;
int judge=(S.at(0)-'0')*1000+(S.at(1)-'0')*100+(S.at(2)-'0')*10+(S.at(3)-'0');
int judge2=(S.at(5)-'0')*10+(S.at(6)-'0');
  if(judge<2019){
    cout<<"Heisei"<<endl;
  }
  else if(judge==2019){
    if(judge2>=5)cout<<"TBD"<<endl;
    else  cout<<"Heisei"<<endl;  
  }
  else cout<<"TBD"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (int)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>        P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	string S;
	cin >> S;
	
	string ans = "No";
	string cmp = "hi";
	int len = S.size();
	if (IsEven(len)) {
		ans = "Yes";
		REP(i, len / 2) {
			if (!(S[2 * i] == 'h' && S[2 * i + 1] == 'i')) {
				ans = "No";
				break;
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <algorithm>
#include <fstream>
#include <climits>
#define mp make_pair
#define Debug(...) fprintf(stdout, __VA_ARGS__)

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;

const int MAXN = 5e3 + 7;

inline void proc_status() {
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline T read() {
	T res = 0, flag = 1; char in = getchar();
	while(!isdigit(in)) { if(in == '-') flag = -1; in = getchar(); }
	while(isdigit(in)) { res = (res << 1) + (res << 3) + in - '0'; in = getchar(); }
	return res * flag;
}

template<typename T> inline void chkmax(T &a, T b) { if(a < b) a = b; }
template<typename T> inline void chkmin(T &a, T b) { if(a > b) a = b; }

int n, a, b;
int p[MAXN];

inline void init() {
	n = read<int>(); a = read<int>(); b = read<int>();
	for(int i = 1; i <= n; ++i) p[read<int>()] = i;
//	for(int i = 1; i <= n; ++i) cout << p[i] << endl;
}

LL f[MAXN][MAXN];

inline void solve() {
	memset(f, 0x3f, sizeof f);

	f[1][0] = b; f[1][1] = 0;
	for(int i = 2; i <= n; ++i) {
		for(int j = 0; j < i; ++j) {
			if(p[i] < p[j]) {
				chkmin(f[i][j], f[i - 1][j] + a);
			}
			else {
				chkmin(f[i][j], f[i - 1][j] + b);
			}
//			printf("[%d %d] %lld\n", i, j, f[i][j]);
		}
		for(int j = 0; j < i; ++j) {
			if(p[j] < p[i]) chkmin(f[i][i], f[i - 1][j]);
		}
//		printf("[%d %d] %lld\n", i, i, f[i][i]);
//		puts("");
	}
//	cout << endl;
	LL ans = LLONG_MAX;
	for(int i = 0; i <= n; ++i) {
//		cout << f[n][i] << endl;
		chkmin(ans, f[n][i]);
	}
	printf("%lld\n", ans);
}

int main() {

	init();
	solve();

	return 0;
}



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

int N, K;
long long A[100001];
long long T[100001];

int main() {
  cin >> N >> K;
  for (int i=1; i<=N; i++) {
    cin >> A[i];
    T[i] = A[i] + T[i-1];
  }
  long long ans = 0;
  long long h = 0, t = 0;
  for (int i=K+1; i<=N; i++) t += max(A[i], 0LL);
  for (int i=1; i<=N-K+1; i++) {
    ans = max(ans, max(T[i+K-1] - T[i-1], 0LL) + h + t);
    h += max(A[i], 0LL);
    t -= max(A[i+K], 0LL);
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 1792
n,m = map(int,input().split())
num = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
a = list(map(int,input().split()))
a.sort(reverse = True)
dp = [0]+[-1]*(n+1)
for i in range(n):
    for j in a:
        if i+num[j] <=n:
            dp[i+num[j]] = max(dp[i+num[j]],dp[i]+1)
ans = []
match = n
while match > 0:
    for i in a:
        if match-num[i] >= 0 and dp[match-num[i]] == dp[match]-1:
            match -= num[i]
            ans.append(str(i))
            break
print("".join(ans))

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

int main(void)
{
    ll a, b, c;
    cin >> a >> b >> c;

    ll left = 4 * a * b;
    ll right = (c - a - b) * (c - a - b);

    if( (c - a - b) <= 0){
        cout << "No" << endl;
        return 0;
    }

    if(left < right){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

int main() {
  int N;
  cin >> N ;
  
  if(N%10 == 3){
    cout << "bon" << endl;
  }
  
  else if(N%10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8){
    cout << "pon" << endl;
  }
  else{
    cout << "hon" << endl;
  }
}


Measured memory_bytes: 3600
def solve(stu,chk)
	stu.each do |st|
		dist=[]
		chk.each_with_index do |ch,i|
			x=(st[0]-ch[0]).abs
			y=(st[1]-ch[1]).abs
			dist.push([x+y,i])
		end
		dist.sort! do |a,b|
			if a[0]!=b[0]
				a[0]<=>b[0]
			else
				a[1]<=>b[1]
			end
		end
		p dist[0][1]+1
	end
end
if __FILE__==$0
	rl_i=lambda{|str,dl|str.strip.split(dl).map(&:to_i)}
	m,n=rl_i[gets," "]
	stu=[]
	chk=[]
	m.times do |i|
		stu.push(rl_i[gets," "])
	end
	n.times do |i|
		chk.push(rl_i[gets," "])
	end
	solve(stu,chk)
end




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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define w(x)            int x; cin>>x; while(x--)
#define fr(i,a,b)       for(int i = a; i < b; i++)
#define mod				1000000007
void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

vector<vi> multiply(vector<vi> a, vector<vi> b)
{
	int n = a.size();
	vector<vi> res(n, vi(n, 0));
	fr(i, 0, n)
	fr(j, 0, n)
	fr(k, 0, n)
	res[i][j] = (res[i][j] + (a[i][k] * b[k][j]) % mod) % mod;
	return res;
}

vector<vi> power(vector<vi>mat, int exp)
{
	if (exp == 1)
		return mat;
	vector<vi> res = power(mat, exp / 2);
	if (exp & 1)
		return multiply(mat, multiply(res, res));
	else
		return multiply(res, res);
}

void solve()
{
	int n, k;
	cin >> n >> k;

	vector<vi>adj(n, vi(n));
	fr(i, 0, n)
	fr(j, 0, n)
	cin >> adj[i][j];

	vector<vi>ak = power(adj, k);
	int ans = 0;
	fr(i, 0, n)
	fr(j, 0, n)
	ans = (ans + ak[i][j]) % mod;
	cout << ans << endl;
}

int32_t main()
{
	c_p_c();
	solve();
	return 0;
}

Measured memory_bytes: 4896
#include <iostream>
#include <vector>
#include <algorithm>
 
#define ascent(i, a, b) for(int (i) = (a); (i) < (b); (i) ++)

using namespace std;

int main() {
  int n, k;
  vector<int> s;
  int b[100];

  while(true) {
    cin >> n >> k;
    if(!n && !k) break;

    int tmp;
    s.clear();
    ascent(i, 0, k) {
      cin >> tmp;
      s.push_back(tmp);
    }

    ascent(i, 0, 100) {
      b[i] = 0;
    }
    
    ascent(i, 0, n) {
      ascent(j, 0, k) {
	cin >> tmp;
	b[j] += tmp;
      }
    }

    bool flg = true;
    ascent(i, 0, k) {
      if(s[i] < b[i]) {
	flg = false;
	break;
      }
    }

    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

    
  return 0;
}

Measured memory_bytes: 1212
use std::io::Read;
use std::str::SplitWhitespace;
use std::str::FromStr;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse<T> {
    fn parse(&mut self) -> T;
}

impl<'a, T> Parse<T> for SplitWhitespace<'a>
where
    T: FromStr,
{
    fn parse(&mut self) -> T {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n: u64 = iter.parse();
    let k: u64 = iter.parse();

    let mut v: Vec<u64> = Vec::new();
    let base = 2_u32.pow(18) as u64;

    for i in 1..(n + 1) {
        for j in 0..19 {
            let bi = 2_u32.pow(j) as u64;
            if k <= i * bi {
                v.push(base / bi);
                break;
            }
        }
    }

    let total: u64 = v.into_iter().sum();

    println!("{}", (total as f64) / (n * base) as f64);
}

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

int main(){
  int t;
  cin >> t;
  while(t--){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0;i<n;i++)cin >> h[i];
    
    int maxv = 0, minv = 0;
    for(int i=1;i<n;i++){
      maxv = max(maxv, h[i]-h[i-1]);
      minv = min(minv, h[i]-h[i-1]);
    }

    cout << maxv << " " << -minv << endl;
  }
}

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

int main()
{
	long long a[200001];
	long long n;
	long long t;
	cin >> n;
	for (int i = 0;i < n;i++)
	{
		cin >> t;
		a[i] = t - i - 1;
	}
	sort(a, a + n);
	long long b;
	if (n % 2)
		b = a[n / 2];
	else
		b = (a[n / 2 - 1] + a[n / 2]) / 2;
	long long ans=0;
	for (int i = 0;i < n;i++)
	{
		ans += abs(a[i] - b);
	}
	cout << ans << endl;
}

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

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> S(H, vector<char>(W));
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            cin >> S.at(i).at(j);
        }
    }
    int min_cut = 1e9;
    for (int tmp=0; tmp<(1 << H-1); tmp++) {
        bool flag = false;
        int cut = 0;
        bitset<10> yoko(tmp);
        vector<int> block_count(0);
        for (int i=0; i<H-1; i++) {
            if (yoko.test(i)) {
                block_count.emplace_back(0);
                cut++;
            }
        }
        block_count.emplace_back(0);
        for (int j=0; j<W; j++) {
            vector<int> tate_count(block_count.size());
            int block = 0;
            for (int i=0; i<H; i++) {
                if (S.at(i).at(j) == '1') tate_count.at(block)++;
                if (i == H-1) break;
                if (yoko.test(i)) block++;
            }
            for (int i=0; i<block_count.size(); i++) {
                if (block_count.at(i) + tate_count.at(i) > K) {
                    if (j == 0) {
                        flag = true;
                        break;
                    }
                    cut++;
                    block_count = tate_count;
                    break;
                }
                else {
                    block_count.at(i) += tate_count.at(i);
                }
            }
            if (flag) break;
        }
        if (flag) continue;
        min_cut = min(min_cut, cut);
    }
    cout << min_cut << endl;
}

Measured memory_bytes: 768
def match a, b
	(0..a.size-b.size).any?{|y|
		(0..a.size-b.size).any?{|x|
			(0...b.size).all?{|i|
				a[y+i][x...x+b.size]==b[i]
			}
		}
	}
end

n, m = gets.split.map(&:to_i)
a = n.times.map{gets.chomp}
b = m.times.map{gets.chomp}
puts match(a, b) ? "Yes" : "No"

Measured memory_bytes: 3836
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N, A, X;
      cin >> N >> A;
      if (N>=500){
        X = N % 500;
        if (X<=A){
        	cout << "Yes" << endl;
      	}
      	else{
        	cout << "No" << endl;
      	}
      }
     else{
        if (N<=A){
        	cout << "Yes" << endl;
      	}
      	else{
        	cout << "No" << endl;
      	}
     }
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n ;
  cin >> n ;
  vint d(n,-1) ;
  vint seen(n,0) ;
  queue<int> Q ;
  vvint gra(n) ;
  for(int i=0;i<n;i++){
    int a, b;
    cin >> a >> b;
    for(int j=0;j<b;j++){
      int c ;
      cin >> c ;
      gra[a-1].PB(c-1) ;
    }
  }
  
  Q.push(0) ;
  seen[0] = 1 ;
  d[0] = 0 ;
  
  while(!Q.empty()){
    int k = Q.front() ;
    for(int i=0;i<SZ(gra[k]);i++){
      if(seen[gra[k][i]]==0){
        Q.push(gra[k][i]) ;
        seen[gra[k][i]] = 1 ;
        d[gra[k][i]] = d[k] + 1 ;
      }
    }
    Q.pop() ;
  }
  
  for(int i=0;i<n;i++){
    cout << i+1 <<" "<<d[i] <<endl ;
  }
 
  return 0 ;
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010

int main(){
	IOS;
	
	ll n,m;cin>>n>>m;
	string s;cin>>s;
	s[m-1]+=32;
	cout<<s;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
using ll = long long;

ll n, m;

int main() {
    cin>>n>>m;
//    n = 314; m = 1592;
    ll rs = 0;
    if (n > 2 && m > 2) {
        rs = (n - 2) * (m - 2);
    } else if (n == 1 && m > 2) {
        rs = m - 2;
    } else if (n > 2 && m == 1) {
        rs = n - 2;
    } else if (n == 1 && m == 1) {
        rs = 1;
    }
    
    cout << rs << endl;
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s.size()<4){
    cout<<"No";
  }else{
    if(s.at(0)=='Y'&&s.at(1)=='A'&&s.at(2)=='K'&&s.at(3)=='I'){
      cout<<"Yes";
    }else{
      cout<<"No";
    }
  }
}

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








int main(){
  int a,b;scanf("%d%d",&a,&b);
double ret=0;
for(int i=1;i<=a;i++){
double tmp=1.0/a;
int now=i;
while(now<b){
now*=2;
tmp/=2;
}
ret+=tmp;
}
printf("%.12f\n",ret);
}




  

Measured memory_bytes: 256
use proconio::input;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Color {
    Red,
    Blue,
}

fn main() {
    input!(n: usize, ab: [(usize, usize); n], cd: [(usize, usize); n]);
    let mut balls = vec![(0, Color::Red); 2 * n];
    for (a, b) in ab {
        balls[a] = (b, Color::Red);
    }
    for (c, d) in cd {
        balls[c] = (d, Color::Blue);
    }

    let mut ans = 0;
    let mut ckd = vec![false; 2 * n];
    for (y, color) in balls {
        match color {
            Color::Red => {
                ckd[y] = true;
            }
            Color::Blue => {
                if let Some((i, _)) = ckd[0..y]
                    .iter()
                    .copied()
                    .enumerate()
                    .filter(|&(_, b)| b)
                    .last()
                {
                    ckd[i] = false;
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2196
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

void solve()
{
    IN(n);
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }
    sort(all(a));
    sort(all(b));
    if (n % 2 == 0) {
        cout << (b[n/2] + b[n/2-1]) - (a[n/2] + a[n/2-1]) + 1 << endl;
    } else {
        cout << b[(n-1)/2]-a[(n-1)/2]+1 << endl;
    }
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 6364
using System.Collections.Generic;
using static System.Console;

class Program {
	static void Main() {
		var N = NextInt();
		var a = new int[N];
		for (var i = 0; i < N; i++) {
			a[i] = NextInt();
		}
		var j = 1;
		for (var i = 1; i <= N; i++) {
			j = a[j - 1];
			if (j == 2) {
				WriteLine(i);
				return;
			}
		}
		WriteLine(-1);
	}

	static int NextInt() {
		return int.Parse(NextString());
	}

	static string NextString() {
		var result = new List<char>();
		while (true) {
			int next = Read();
			if (next < 0)
				break;
			var nextChar = (char)next;
			if ((nextChar + "").Trim() != "")
				result.Add(nextChar);
			else if (nextChar != '\r')
				break;
		}
		return string.Join("", result);
	}
}


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

using namespace std;
using ll = long long;

int main() {
  string s;
  int q;
  cin >> s >> q;
  int t, f;
  char c;
  bool isrev = false;
  deque<char> deq;
  rep(i, s.size()) { deq.push_back(s[i]); }
  rep(i, q) {
    cin >> t;
    if (t == 1) {
      isrev = !isrev;
    } else {
      cin >> f >> c;
      if (isrev) {
        if (f == 1) {
          deq.push_back(c);
        } else {
          deq.push_front(c);
        }
      } else {
        if (f == 1) {
          deq.push_front(c);
        } else {
          deq.push_back(c);
        }
      }
    }
  }
  if (isrev) {
    while (!deq.empty()) {
      cout << deq.back();
      deq.pop_back();
    }
  } else {
    while (!deq.empty()) {
      cout << deq.front();
      deq.pop_front();
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 4024
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename T>
class segtree {
public:
    //サイズ10^5くらい
    static const int MAX_N = 1 << 17;
    
    int n;
    T dat[2 * MAX_N - 1];
    
    void init(int n_) {
        n = 1;
        while (n < n_) n *= 2;
        for (int i = 0; i < 2 * n - 1; i++) {
            dat[i] = -(1LL<<60);
        }
    }
    
    // k番目(0-indexed)をaに変更
    void update(int k, T a) {
        k += n - 1;
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
    //[a,b)の最小値
    // kは節点の番号、l,rはその節点が[l,r)に対応付いていることを表す
    //外からはquery(a, b, 0, 0, n)として呼ぶ=>このnはseg.n
    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return -(1LL<<60);
        if (a <= l && r <= b)
            return dat[k];
        else {
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return max(vl, vr);
        }
    }
    T query(int a, int b) { return query(a, b, 0, 0, n); }
};

int main(){
    int n;
    ll c;
    cin >> n >> c;
    vector<ll>x(n),v(n);
    rep(i,n){
        scanf("%lld %lld",&x[i],&v[i]);
    }
    ll ans = 0;
    vector<ll>a(n);
    ll temp = 0;
    rep(i,n){
        temp += v[i];
        a[i] = temp -x[i];
        ans = max(a[i],ans);
    }
    segtree<ll> seg;
    segtree<ll>seg2;
    seg2.init(n);
    seg.init(n);
    rep(i,n){
        seg.update(i,a[i]);
    }
    vector<ll>b(n);
    temp = 0;
    rep(i,n){
        temp += v[n-1-i];
        b[i] = temp-(c-x[n-1-i]);
        ans = max(b[i],ans);
        seg2.update(i,b[i]);
    }
    rep(i,n-1){
        ans = max(ans,b[i]-(c-x[n-1-i])+seg.query(0,n-1-i));
        ans = max(ans,a[i]-x[i]+seg2.query(0,n-1-i));
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 7552
using System;

namespace Blue_Balls
{
    class Program
    {
        static void Main(string[] args)
        {
            long N;
            long A;
            long B;

            String input = Console.ReadLine();
            string[] array = input.Split(' ');

            N = long.Parse(array[0]);
            A = long.Parse(array[1]);
            B = long.Parse(array[2]);

            long div = Math.Min((N % (A + B)), A);
            long remainder = (N / (A + B)) * A;

            remainder = remainder + div;
            Console.WriteLine(remainder);
        }
    }
}

Measured memory_bytes: 13140