akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    int t = 0, u = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'a'){
            if(t + u < a + b){
                t++;
                cout << "Yes" << endl;
            }
            else cout << "No" << endl;
        }
        else if(s[i] == 'b'){
            if(u < b && t + u < a + b){
                u++;
                cout << "Yes" << endl;
            }
            else cout << "No" << endl;
        }
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 896
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string N;
    cin >> N;
    int ans = 0;
    for(int i = 0; i < 4; i++){
        if(N[i] == '2'){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))//数组(结构体)清零 
#define ll long long
int A(int a,int b){if(a<b||a<1||b<0)return 0;int k=1;while(b--){k*=a--;}return k;}//数学中的Aab,传递ab,返回Cab//类型为int//如果不符合条件则返回0 
int C(int a,int b){if(a<b||a<1||b<0)return 0;b=min(a-b,b);int k=A(a,b),t=1;while(--b)k/=++t;return k;}//数学中的Cab,传递ab,返回Cab//类型为int//如果不符合条件则返回0 
int HW(char*HWa,int HWl,int HWr){if(HWr<HWl)swap(HWl,HWr);for(int i=0;i<(HWr-HWl)/2+1;i++)if(HWa[HWl+i]!=HWa[HWr-i])return 0;return 1;}//传递字符串名,判断区间l r,如果是回文字符串就返回1,否则返回0 
int SS(int a){if(a>4&&((a-1)%6)&&((a+1)%6))return 0;for(int i=2;i<=sqrt(a);i++)if(a%i==0)return 0;return 1;}//判断一个数是不是质数，是1 否0；请确保a>1; 
/*记得如果改int为long long,就把printf与scanf中相应的%d也改成%lld*/
int main()
{
	int a;
	cin>>a;
	int b=a/500;
	int c=a-b*500;
	c=c/5;
	cout<<1000*b+c*5;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

const ll N_MAX = 1e12;
const ll N_MAX_SQ = 1e6;

bool isPrime[N_MAX_SQ + 1];

ll gcd(ll x, ll y){
    if(x % y == 0){
        return y;
    }
    return gcd(y, x % y);
}

bool HasLargePrime(ll x, vector<ll>& primes){
    if(x == 1) return false;
    for(auto p: primes){
        while(x % p == 0){
            x /= p;
        }
    }
    return x != 1;
}

vector<ll> Primes(){
    for(int i = 0; i <= N_MAX_SQ; i++){
        isPrime[i] = true;
    }
    vector<ll> primes;
    for(int i = 2; i <= N_MAX_SQ; i++){
        if(isPrime[i]){
            for(int j = 2*i;j<= N_MAX_SQ; j += i){
                isPrime[j] = false;
            }
            primes.push_back(i);
        }        
    }
    return primes;
}

int main(){
    ll a, b;
    cin >> a >> b;
    vector<ll> primes = Primes();
    ll count = 1;
    for(auto p: primes){
        if(a % p == 0 && b % p == 0){
            count++;
        }
    }
    if(HasLargePrime(gcd(a, b), primes)) count++;
    cout << count << endl;
}

Measured memory_bytes: 2424
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
ll n,m,q;
ll l[505][505];
int main(void){
    cin>>n>>m>>q;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        l[b][a]++;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            l[i][j]+=l[i][j-1];
        }
    }
    for(;q>0;q--){
        int a,b,ans=0;
        cin>>a>>b;
        for(int i=b;i>=1;i--){
            ans+=l[i][n]-l[i][a-1];
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 2944
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    d = dict()
    for i in range(1, n + 1):
        d[i] = input_int_list()[::-1]
    day = 0
    candi = set(range(1, n + 1))
    rest = (n * (n - 1)) // 2
    while rest:
        played = set()
        for a in candi:
            if d[a] and d[d[a][-1]][-1] and a == d[d[a][-1]][-1]:
                played.add(a)
                played.add(d[a][-1])

        if not played:
            break

        candi.clear()

        rest -= len(played) // 2
        for a in played:
            candi.add(a)
            d[a].pop()
            if d[a]:
                candi.add(d[a][-1])
        day += 1

    if rest == 0:
        print(day)
    else:
        print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 90928
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

import sys
sys.setrecursionlimit(4100000)
input = sys.stdin.readline

N = Int()
mod = 1000000007
ans = 1
import math

from collections import defaultdict
XX = defaultdict(list)
YY = defaultdict(list)

zeros = 0

for i in range(N):
    A,B = Ints()
    if A!=0 and B!=0:
        GCD = math.gcd(A,B)
        A //=GCD
        B //=GCD
        if A<0 and B<0:
            A *= -1
            B *= -1
        elif A>0 and B<0:
            A *= -1
            B *= -1
        XX[(A,B)].append(i)
        
        B *= -1
        if A<0 and B<0:
            A *= -1
            B *= -1
        elif A<0 and B>0:
            A *= -1
            B *= -1
        YY[(B,A)].append(i)
        
    elif A==0 and B!=0:
        XX[(0,1)].append(i)
        YY[(1,0)].append(i)
    elif A!=0 and B==0:
        XX[(1,0)].append(i)
        YY[(0,1)].append(i)
    else:
        zeros += 1


D = {}

for key in XX:
    if not key in D:
        l = len(XX[key])
        m = len(YY[key])
        ans *= (pow(2,l,mod)+pow(2,m,mod)-1)
        ans %= mod
        D[key] = 1
        
        a,b = key
        if a==0 and b==1:
            D[(1,0)] = 1
        elif a==1 and b==0:
            D[(0,1)] = 1
        else:
            b *= -1
            if a < 0:
                b*=-1
                a*=-1
            D[(b,a)] = 1
    
ans -= 1
ans += zeros
ans %= mod
print(ans)

Measured memory_bytes: 224356
//lover~ crazy~
#include<bits/stdc++.h>
using namespace std;
int n,k;
int main() {
    cin>>n>>k;
	if(n%k==0)cout<<0; 
	else cout<<1;
	return 0;
}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            for(int i; (i = int.Parse(Console.ReadLine())) != 0;) {
                var d = new Dictionary<string, int>();
                while(i-- > 0) {
                    Array.ForEach(Console.ReadLine().Split(), q => d[q] = 1 + (d.ContainsKey(q) ? d[q] : 0));
                }
                var k = Console.ReadLine()[0];
                var c = d.Where(q => q.Key[0] == k).OrderByDescending(q => q.Value).ThenBy(q => q.Key).Select(q => q.Key).Take(5).ToArray();
                Console.WriteLine(c.Length == 0 ? "NA" : String.Join(" ", c));
            }
        }
    }
}

Measured memory_bytes: 7280
#include <bits/stdc++.h>
#define mem(a,b) memset(a, b, sizeof(a))
#define INF 0x3f3f3f3f
#define rep(a, b) for(int i=a;i<b;i++)

using namespace std;

typedef long long ll;

const int maxn = 1e5 + 5;

int main()
{
    int n;
    string a;
    cin >> n;
    cin >> a;
    int l = a.size();
    char s[l];
    int m = 0;
    for(int i=0;i<l;i++)
    {
        a[i] = ((a[i] - 'A' + n % 26) % 26 + 'A');
    }
    for(int i=0;i<l;i++)
        cout << a[i];
}


Measured memory_bytes: 256
import numpy as np
MOD = 10 ** 9 + 7
N, K = map(int, input().split())
gcds = np.zeros((K + 1,), dtype=np.int64)
for n in range(K, 0, -1):
    gcds[n] = (pow(K // n, N, MOD) - gcds[np.arange(1, K // n + 1, dtype=np.int64) * n].sum()) % MOD
print(gcds @ np.arange(K + 1) % MOD)


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

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int
main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  int m[2];
  for (int i = 0; i < N; ++i)
  {
    int a;
    cin >> a;
    A[i] = a;
    if (i < 2)
    {
      m[i] = a;
    }
    else if (m[1] < a)
    {
      m[1] = a;
    }
    if (i != 0 && m[0] < m[1])
    {
      int tem = m[0];
      m[0] = m[1];
      m[1] = tem;
    }
  }
  for (int i = 0; i < N; ++i)
  {
    cout << (A[i] == m[0] ? m[1] : m[0]) << endl;
  }
  return 0;
}


Measured memory_bytes: 2432
H,W,K = map(int,input().split())
C = []
for _ in range(H):
    C.append(input())
res = 0
for i in range(2**W):
    for j in range(2**H):
        tmp = 0
        for h in range(H):
            for w in range(W):
                if bin(i)[2:].zfill(W)[w] == '0' and bin(j)[2:].zfill(H)[h] == '0' and C[h][w] == '#':
                    tmp += 1
        if tmp == K:
            res += 1

print(res)

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

count = 1
next = a[0]
flg = 0

while True:
  if next == 2:
    break
  if count == n:
    flg = 1
    break
  
  count += 1
  next = a[next-1]

if flg == 1:
  print(-1)
else:
  print(count)

Measured memory_bytes: 7084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;


int main(){
    ll s;   cin >> s;
    vector<ll> a(6, 0);
    a.at(2) = 1;
    a.at(3) = 1e+9;

    
    a.at(5) = (a.at(3)-s%a.at(3))%a.at(3);
    a.at(4) = (s+a.at(5))/a.at(3);
    
    for(auto x: a) cout << x << ' ';
    cout << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program
{
    static int n;
    static long[] a;
    static Dictionary<long, int> paper; // 紙

    static void Main()
    {
        /* 入力を受け取る */
        n = int.Parse(Console.ReadLine());
        a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = long.Parse(Console.ReadLine());
        /* シミュレート */
        paper = new Dictionary<long, int>();
        foreach (var ai in a)
        {
            if (!paper.ContainsKey(ai)) // 紙に書いたことがなければ
                paper.Add(ai, 1); // 1個書く
            else // 過去に書いたことがあるとき
            {
                if (paper[ai] == 1) // 紙に1個書いてあれば
                    paper[ai]--; // 0個に
                else // 紙に1個も書いてなければ
                    paper[ai]++; // 1個に
            }
        }
        /* 答えを計算し出力 */
        long ans = 0;
        foreach (var x in paper)
            ans += x.Value;
        Console.WriteLine(ans);
    }
}

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


int main() {
    unsigned int numOfHinaArare;
    std::cin >> numOfHinaArare;
    
    std::string bagOfHinaArare;
    char hinaArare;
    for(unsigned int i = 0U; i < numOfHinaArare; ++i) {
        std::cin >> hinaArare;
        bagOfHinaArare += hinaArare;
    }
    
    bool isYellowExist = false;
    for(char collerOfHinaArare : bagOfHinaArare) {
        if(collerOfHinaArare == 'Y') {
            isYellowExist = true;
            break;
        }
    }
    
    if(isYellowExist) {
        std::cout << "Four" << std::endl;
    } else {
        std::cout << "Three" << std::endl;
    }    
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>

using namespace std;

int n;
int m;

long h[100010];

int a[100010];
int b[100010];

bool g[100010];

int main() {

  cin >> n >> m;
  for(int i=0 ; i<n ; i++)
    cin >> h[i];
  for(int i=0 ; i<m ; i++){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  /*
  for(int i=0 ; i<m ; i++){
    cout << a[i] << ' '<<b[i]<<endl;
  }
  */

  for(int i=0 ; i<n ; i++)
    g[i]=true;

  for(int i=0 ; i<m ; i++){
    if(h[a[i]] >= h[b[i]])
      g[b[i]]=false;
    if(h[a[i]] <= h[b[i]])
      g[a[i]]=false;
  }

  long sum=0;
  for(int i=0 ; i<n ; i++){
    if(g[i])
      sum++;
  }
  cout << sum << endl;
  
  
  return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#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)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
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);


int h, w;
int a[500][500];

void solve() {
    int ans = 0;
    vector<pair<int, int>> from, to;
    rep(i, h) {
        rep(j, w) {
            if (i == h - 1 && j == w - 1) {
                goto LABEL;
            }

            if (i % 2 == 0) {
                if (j == w - 1) {
                    if (a[i][j] % 2 != 0) {
                        a[i][j]--, a[i + 1][j]++;
                        ans++;
                        from.emplace_back(make_pair(i, j));
                        to.emplace_back(make_pair(i + 1, j));
                    }
                } else {
                    if (a[i][j] % 2 != 0) {
                        a[i][j]--, a[i][j + 1]++;
                        ans++;
                        from.emplace_back(make_pair(i, j));
                        to.emplace_back(make_pair(i, j + 1));
                    }
                }
            } else {
                int rev = w - 1 - j;
                if (rev == 0) {
                    if (a[i][rev] % 2 != 0) {
                        a[i][rev]--, a[i + 1][rev]++;
                        ans++;
                        from.emplace_back(make_pair(i, rev));
                        to.emplace_back(make_pair(i + 1, rev));
                    }
                } else {
                    if (a[i][rev] % 2 != 0) {
                        a[i][rev]--, a[i][rev - 1]++;
                        ans++;
                        from.emplace_back(make_pair(i, rev));
                        to.emplace_back(make_pair(i, rev - 1));
                    }
                };
            }
        }
    }
    LABEL:;
    cout << ans << endl;
    rep(i, from.size()) printf("%d %d %d %d\n", from[i].first + 1, from[i].second + 1,
                               to[i].first + 1,
                               to[i].second + 1);
}

int main() {
    cin >> h >> w;
    rep(i, h) rep(j, w) cin >> a[i][j];
    solve();
    return 0;
}

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

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    char b;
    cin >> b;

    if(b == 'A') cout << 'T';
    if(b == 'T') cout << 'A';
    if(b == 'G') cout << 'C';
    if(b == 'C') cout << 'G';
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let it = stdin.lock().bytes().map(|c| c.unwrap() as char);
    let (fs, ft) = (|c: &char| c.is_whitespace(), |c: &char| !c.is_whitespace());
    let token = it.skip_while(fs).take_while(ft).collect::<String>();
    token.parse().ok().unwrap()
}
#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    f(std::io::BufWriter::new(out.lock()));
}
#[allow(unused_macros)]
macro_rules! debug {
    ($($var:expr),*) => { #[cfg(debug_assertions)] {
        $({ match &$var { v => eprint!("{}={:?} ", stringify!($var), v) } })*
        eprintln!();
    }};
}

fn main() {
    let n: usize = input();
    let a: Vec<i32> = (0..1 << n).map(|_| input()).collect();

    let mut dp = vec![(0, 0); 1 << n];
    for i in 0..1 << n {
        dp[i] = (a[i], 0);
    }

    let max2 = |a: (i32, i32), b: (i32, i32)| {
        let mut v = [a.0, a.1, b.0, b.1];
        v.sort();
        (v[2], v[3])
    };

    for i in 0..n {
        for j in 0..1 << n {
            let b = j | (1 << i);
            if b != j {
                dp[b] = max2(dp[b], dp[j]);
            }
        }
    }
    debug!(dp);

    let mut ans = vec![0; 1 << n];
    for i in 1..1 << n {
        ans[i] = std::cmp::max(ans[i - 1], dp[i].0 + dp[i].1);
    }
    with_stdout_lock(|mut w| {
        for i in 1..1 << n {
            writeln!(w, "{}", ans[i]).unwrap();
        }
    });
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    ll N, L; cin >> N >> L;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    ll cur = -1;
    rep(i, N-1){
        if(a[i]+a[i+1] >= L){
            cur = i;
        }
    }
    if(cur == -1){
        cout << "Impossible" << endl;
    }else{
        cout << "Possible" << endl;
        rep(i, cur){
            cout << i+1 << endl;
        }
        rep(i, N-cur-1){
            cout << N-i-1 << endl;
        }
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 8200
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = read();

    // ありうるパターンを全て列挙する
    let patterns = [
        "AKIHABARA",
        "KIHABARA",
        "AKIHBARA",
        "KIHBARA",
        "AKIHABRA",
        "KIHABRA",
        "AKIHBRA",
        "KIHBRA",
        "AKIHABAR",
        "KIHABAR",
        "AKIHBAR",
        "KIHBAR",
        "AKIHABR",
        "KIHABR",
        "AKIHBR",
        "KIHBR",
    ];

    let ans = if patterns.iter().any(|x| *x == s) {
        "YES"
    } else {
        "NO"
    };

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>
#include <unordered_set>

int main() {
    std::string str;
    std::cin >> str;
    
    for (std::size_t i = 0; i < str.size(); ++i) {
        if (i % 2 == 0) {
            if (str[i] == 'R' || str[i] == 'U' || str[i] == 'D') {
                continue;
            } else {
                std::cout << "No\n";
                return 0;
            }
        } else {
            if (str[i] == 'L' || str[i] == 'U' || str[i] == 'D') {
                continue;
            } else {
                std::cout << "No\n";
                return 0;
            }
        }    
    }

    std::cout << "Yes\n";

    return 0;
}


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

int main(void) {
  int n, A=0, B=0;
  scanf("%d", &n);

  for (int i=0; i<n; i++) {
    char a[101], b[101];
    scanf("%s %s", a, b);

    if (strcmp(a, b)>0) A+=3;
    else if (strcmp(a, b)<0) B+=3;
    else A++, B++;
  }

  printf("%d %d\n", A, B);
  return 0;
}


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

int main() {
  int64_t N;
  cin >> N;
  int64_t power = 1LL;
  for (int64_t i = 1LL; i <= N; i++) {
    power *= i;
    power %= 1000000007LL;
  }
  cout << power << endl;
}
    

Measured memory_bytes: 256
/*Author : Krishna*/

#include<iostream>
#include<unordered_map>
#include<queue>
#include<vector>
#include <cmath>
#include <stack>
#include <unordered_set>
#include <algorithm>
/* 97 to 122*/
using namespace std;

void solve()
{
    string S,T;
    cin>>S>>T;
    int ans =(int) T.size();
    for(int start =0;start<=S.size()-T.size();start++)
    {
        int diff=0;
        for(int i=0;i<T.size();i++)
        {
            if(T[i]!=S[start+i])
            {
                diff++;
            }
        }
        ans = min(ans,diff);
    }
    cout<<ans;

    
    
}
int main()
{
    int t;
    t=1;
    while(t--)
    {
        solve();
    }
}




Measured memory_bytes: 3556
def main():
    n, a, b = map(int, input().split())

    if (b - a) % 2 == 0:
        ans = (b - a) // 2
    else:
        ans = min(n - b, a - 1) + 1 + (b - a - 1) // 2
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61356
#include <iostream>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>

#define rep(i,n)	for(int i = 0;i < n;i++)
#define rep2(i,n)	for(int i = 1;i <= n;i++)
#define each(i,x)	for(auto & i : x)

using namespace std;

int cnt(int y,int m,int d)
{
	y--;m--;d--;
	int c = y * 39 * 5;
	c += (y/3)*5;
	c += m * 20;
	if((y+1)%3 != 0)
	c -= (m/2);
	c += d;
	return c;
}

int main()
{
	int mill = cnt(1000,1,1);
	int n;
	cin >> n;
	rep(i,n)
	{
		int y,m,d;
		cin >> y >> m >> d;
		cout << mill - cnt(y,m,d) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;

void solve()
{
	int n,m;
	cin>>n>>m;
	int a[n],c=0,sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]>=(sum)/(double)(4*m))
			c++;
	}
	if(c>=m)
		cout<<"Yes";
	else
		cout<<"No";
}
 
int main()
{
    NFS
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		solve();
 	}
    return 0;
}

Measured memory_bytes: 256
#!/bin/sh

while true;
do
        read k
        read a b

        if [ -z "$k" ]; then
                break
        fi

        result=`seq $a $b | awk -v num=$k '($1%num==0){print $1}' | wc -l`

        if [ $result -eq 0 ]; then
                echo "NG"
        else
                echo "OK"
        fi

done

Measured memory_bytes: 4196
#include <stdio.h>

int main(){
  int flag=1,i,j,N,cnt=0;

  //scanf N
  scanf("%d",&N);

  //making array
  int A[N];

  //complete array
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  //bubbling 
  i=0;
  while(flag){
    flag = 0;
    for(j=N-1;j>i;j--){
      if(A[j]<A[j-1]){
        int swap = A[j];
        A[j] = A[j-1];
        A[j-1] = swap;
        cnt++; //count
        flag = 1; //to be continue
      }
    }
    i++;
  }

  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
  } 
  printf("%d\n",A[i]);
  printf("%d\n",cnt);


  return 0;
}

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

void selectionSort(int A[],int N){
	int cnt=0;
	for(int i=0;i<N;++i){
		int minv=A[i];
		int p=i;
		for(int j=i+1;j<N;++j){
			if(minv>A[j]){
				minv=A[j];
				p=j;
			}
		}
		if(p!=i){
			swap(A[i],A[p]);
			cnt++;
		}
	}
	for(int i=0;i<N;++i) {
		if(i==0) printf("%d",A[i]);
		else printf(" %d",A[i]);
	}
	puts("");
	printf("%d\n",cnt);
}

int main(){
	int N;scanf("%d",&N);
	int A[100];
	for(int i=0;i<N;++i) scanf("%d",&A[i]);
	selectionSort(A,N);
}



Measured memory_bytes: 2764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;
template<typename T> void cmax(T &a, T b) {a = max(a, b);}
template<typename T> void cmin(T &a, T b) {a = min(a, b);}

signed main(){
  int n,m,d;
  cin>>n>>m>>d;
  double ans=0;
  if(d==0)ans=(double)(m-1)/n;
  else ans=(double)(m-1)*2*(n-d)/(n*n);
  printf("%.8lf\n",ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int X,Y; cin>>X>>Y;
  if(0<=X){
    if(0<Y){
      if(X<Y){
        cout<<Y-X<<endl;
      }
      else{
        cout<<X-Y+2<<endl;
      }
    }
    else{
      cout<<abs(abs(X)-abs(Y))+1<<endl;
    }
  }
  else{
    if(0<Y){
      cout<<abs(abs(X)-abs(Y))+1<<endl;
    }
    else{
      if(X<Y){
        cout<<Y-X<<endl;
      }
      else{
        cout<<X-Y+2<<endl;
      }
    }
  }
  }





Measured memory_bytes: 256
N,K=map(int,input().split())
D=list(map(int,input().split()))
def func(N):
    l=[]
    while(N!=0):
        l.append(N%10)
        N//=10
    return l
for n in range(N,10**6+1):
    l=func(n)
    T=True
    for i in l:
        if i in D:
            T=False
            break
    if T:
        print(n)
        quit()


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

using namespace std;

int main()
{
  int n, f, m;
  cin >> n >> f;
  map<string, int> counter_dict;
  
  for(int i=0; i<n; i++){
    cin >> m;
    vector<string> vec = vector<string>(m);
    for(int j=0; j<m; j++){
      cin >> vec[j];
    }
    sort(vec.begin(), vec.end());

    string str;
    for(int j=0; j<m;j++) {
      for(int k=j+1; k<m; k++) {
	str = vec[j]+" "+vec[k];
	if(counter_dict.find(str) != counter_dict.end()) {
	  counter_dict[str]++;;
	} else {
	  counter_dict[str]=1;
	}
      }
    }
  }
  vector<string> results;
  for(map<string, int>::iterator it=counter_dict.begin(); it != counter_dict.end(); it++) {
    if(it->second >= f) {
      results.push_back(it->first);
    }
  }
  sort(results.begin(), results.end());
  cout << results.size() << endl;
  for(int i=0; i<results.size(); i++){
    cout << results[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,k,arr[150],j=2;
    cin>>a>>b>>k;
    if(a>b)
        swap(a,b);
    arr[1]=1;
    for(int i=2; i<=a; i++)
    {
        if(a%i==0&&b%i==0)
        {
            arr[j]=i;
            //cout<<arr[j]<<" ";
            j++;
        }
    }
    j--;
    //sort(arr,arr+j,greater<int>());
    cout<<arr[j-k+1]<<endl;
    return 0;
}


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

mod = 10 ** 9 + 7
MAX = 2 * 10 ** 5

fact = [1] * (MAX + 1)
for i in range(1, MAX + 1):
    fact[i] = (fact[i-1] * i) % mod

inv = [1] * (MAX + 1)
for i in range(2, MAX + 1):
    inv[i] = inv[mod % i] * (mod - mod // i) % mod

ans = pow(2, n, mod) - 1


def comb(k):
    ret = 1
    for i in range(1, k + 1):
        ret *= n - i + 1
        ret %= mod
        ret *= inv[i]
        ret %= mod

    return ret


ans -= comb(a)
ans -= comb(b)
ans %= mod
print(ans)


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

int main()
{
 long long n, d;
 cin >> n;
 long long a[n+2],b[n+2];
 d=0;
 a[0]=0;
 b[0]=0;
 b[n+1]=0;
 for(int i=1;i<n+2;i++) cin >> a[i];
 for(int i=1;i<n+1;i++) cin >> b[i];
 for(int i=1;i<n+2;i++){
    int e,f;
 	e=min(a[i],b[i-1]);
    a[i]-=e;
    b[i-1]-=e;
    d+=e;
    f=min(a[i],b[i]);
    a[i]-=f;
    b[i]-=f;
    d+=f;
 }
 cout << d;
  return 0;
}

Measured memory_bytes: 1792
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, h, m float64
	fmt.Scan(&a, &b, &h, &m)
	hDeg := h*30 + m*0.5
	mDeg := m * 6
	ang := math.Abs(hDeg - mDeg)
	fmt.Println(math.Sqrt(a*a + b*b - 2*a*b*math.Cos(ang * math.Pi / 180)))
}


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

int N, A, B;

int main() {
    cin >> N >> A >> B;
    cout << min(N * A, B) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main()
{
    std::string S;
    std::cin >> S;

    std::string ans = "AC";

    if (S[0] != 'A') ans = "WA";
    auto f = S.find('C');
    if (f == std::string::npos) ans = "WA";
    auto f2 = S.find('C', f+1);
    if (f2 != std::string::npos) ans = "WA";
    if (f < 2 || f == S.length()-1) ans = "WA";
    int up = 0;
    for(int i = 0; i < S.length(); i++) {
        if (S[i] >= 'A' && S[i] <= 'Z') up++;
    }
    if (up != 2) ans = "WA";

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
<?php
  
  fscanf(STDIN,"%s",$S);
$count01 = 0;
$count10 = 0;
for($i=0;$i<strlen($S);$i++){
  if($i%2==0 && $S[$i] != 0){
    $count01++;
  }
  
  if($i%2!=0 && $S[$i] != 1){
    $count01++;
  }
  
  if($i%2==0 && $S[$i] != 1){
    $count10++;
  }
  
  if($i%2!=0 && $S[$i] != 0){
    $count10++;
  }
}


echo min($count01,$count10)."\n";

Measured memory_bytes: 4604
unittest
{
	assert( [ "29", "20", "7", "35", "120" ].parse.expand.solve == 215 );
	assert( [ "101", "86", "119", "108", "57" ].parse.expand.solve == 481 );
	assert( [ "123", "123", "123", "123", "123" ].parse.expand.solve == 643 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto ds = new long[ 5 ];
	foreach( ref d; ds )
	{
		d = input.front.to!( long );
		input.popFront;
	}
	return tuple( ds );
}

auto solve( long[] ds )
{
	auto rs = ds.map!( ( a ) => ( a % 10 == 0 ) ? 10L : a % 10 ).array;
	zip( rs, ds ).sort;
	foreach( ref d; ds[ 1 .. $ ] )
	{
		d = ( d + 9 ) / 10 * 10;
	}
	return ds.sum;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

int main() {
  int N, M;
  string S, T;
  cin >> N >> M >> S >> T;
  ll x = lcm(N, M);
  int sp = 0, tp = 0, sn = lcm(x/N, x/M)/(x/N), tn = lcm(x/N, x/M)/(x/M);
  while(sp < N && tp < M) {
    if(S[sp] != T[tp]) {
      cout << -1 << endl;
      return 0;
    } else {
      sp += sn;
      tp += tn;
    }
  }
  cout << x << endl;
  return 0;
}

Measured memory_bytes: 512
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]

def main():
    k = II()
    if k%2==0:
        print((k//2)**2)
    else:
        print(((k+1)//2)*(k//2))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
use std::io::*;
use std::str::FromStr;
use std::cmp::{max};
use std::cell::RefCell;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut dp = Vec::with_capacity(n + 1);
    for i in 0..(n + 1) {
        dp.push(Vec::with_capacity(64));
        for _ in 0..64 {
            dp[i].push(0);
        }
    }
    println!("{}", rec(n, 63, &mut dp));
}

fn rec(n: usize, i: usize, dp: &mut Vec<Vec<u64>>) -> u64 {
    if dp[n][i] != 0 {
        return dp[n][i];
    } else if n == 0 {
        dp[n][i] = 1;
        return dp[n][i];
    }
    let mut ret = 0;
    for c in 0..4 {
        if ng((i << 2) + c) {
            continue;
        }
        let new_i = ((i << 2) + c) & 63;
        ret = add_mod(rec(n - 1, new_i, dp), ret);
    }
    dp[n][i] = ret;
    ret
}

// A C G T
// CGA
// ACG
// AG?C
fn ng(n: usize)  -> bool {
    let up = n >> 2;
    let down = n & 63;
    let pos1 = n & 243;
    let pos2 = n & 207;
    up == 6 || down == 6 || up == 33 || down == 33 || up == 9 || down == 9 || pos1 == 33 || pos2 == 9
}

const MOD: u64 = 1000000007;

fn add_mod(a: u64, b: u64) -> u64 {
    (a + b) % MOD
}

fn sub_mod(a: u64, b: u64) -> u64 {
    (a + MOD - b) % MOD
}

fn mul_mod(a: u64, b: u64) -> u64 {
    (a * b) % MOD
}

fn pow_mod(base: u64, exp: u64) -> u64 {
    if exp == 0 {
        1
    } else if exp == 1 {
        base
    } else {
        let prev = pow_mod(base, exp / 2);
        let tmp = if exp % 2 == 0 { 1 } else { base };
        mul_mod(mul_mod(prev, prev), tmp)
    }
}

fn div_mod(a: u64, b: u64) -> u64 {
    mul_mod(a, pow_mod(b, MOD - 2))
}

fn combination_mod(n: u64, k: u64) -> u64 {
    let mut ret = 1;
    for i in 0..k {
        let mul = if i < n { n - i } else { 0 };
        ret = div_mod(mul_mod(ret, mul), i + 1);
    }
    ret
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N;
set<string> st;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  for (int i = 0; i < N; i++) {
    string si;
    cin >> si;
    st.insert(si);
  }

  int ans = st.size();
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 15644
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<string>
#include<bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

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 (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    string s, t; cin >> s >> t;
    int a, b; cin >> a >> b;
    string u;
    cin >> u;
    if (u == s) a--;
    else if (u == t) b--;
    cout << a << " " << b << endl;
    return 0;
}

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

int main(){
  int N,m=1;
  cin>>N;
  int A[N];
  for(int i=1;i<N+1;i++)
    cin >>A[i];
  pair <int,int> p[N+1];
  for(int i=1;i<N+1;i++)
    p[i]=make_pair(A[i],i);
  
  sort(p+1,p+N+1);

  for(int i=1;i<N+1;i++)
    cout<<p[i].second<<" ";
  







  return 0;
}


Measured memory_bytes: 2048
function ismine(a, j, i, w, h)
  if i < 1 || j < 1 || i > h || j > w
    return 0
  elseif a[j,i] == "#"
    return 1
  else
    return 0
  end
end

function ms(a, j, i, w, h)
  count = 0
  count += ismine(a, j-1, i-1, w, h)+ismine(a, j, i-1, w, h)+ismine(a, j+1, i-1, w, h)+ismine(a, j-1, i, w, h)+ismine(a, j+1, i, w, h)+ismine(a, j-1, i+1, w, h)+ismine(a, j, i+1, w, h)+ismine(a, j+1, i+1, w, h)
  return count
end

function main()
  h, w = parse.(split(readline()))
  a = Array{String}(w,h)
  for i in 1:h
    a[:,i] = split(chomp(readline()), "")
  end
  for i in 1:h
    for j in 1:w
      if a[j,i] == "."
    	a[j,i] = string(ms(a,j,i,w,h))
      end
    end
  end
  for i in 1:h
  	for j in 1:w
      print(a[j,i])
    end
    println()
  end
end

main()

Measured memory_bytes: 127064
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

const int max_n = 100000+10;
int N,M;
int S,T;
vector<pair<int,int> > G[max_n][3]; //node, state
int visited[max_n][3];

int solve(void) {
    for(int i = 0;i < max_n;i++) {
        for(int j = 0;j < 3;j++) {
            visited[i][j] = -1;
        }
    }

    queue<pair<int, pair<int,int> > > Q;
    Q.push({S,{0, 0}}); //node, next_node, distance
    while(!Q.empty()) {
        auto u = Q.front();Q.pop();
        if(visited[u.first][u.second.first] != -1)
            continue;
        visited[u.first][u.second.first] = u.second.second;

        for(auto v: G[u.first][u.second.first]) {
            Q.push({v.first,{v.second, u.second.second+1}});
        }
    }

    return visited[T][0] == -1 ? -1 : visited[T][0]/3;
}

int main(void) {
    cin>>N>>M;

    for(int i = 0;i < M;i++) {
        int u,v;
        cin>>u>>v;
        G[u][0].push_back({v, 1});
        G[u][1].push_back({v, 2});
        G[u][2].push_back({v, 0});
    }

    cin>>S>>T;
    cout<<solve()<<endl;

    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<int, ll>;

constexpr char newl = '\n';
constexpr int MAXL = 100000;

array<ll, MAXL + 1> dp;
vector<P> cand = {{0, 0}};

void solve(int cur, int depth, int n, const vector<int>& v, const vector<int>& w, const vector< vector<int> >& qs, const vector<int>& L, vector<ll>& ans) {
    if (depth < 9) {
        array<ll, MAXL + 1> tmp_dp = dp;
        for (int i = MAXL; i >= w[cur]; i--) {
            dp[i] = max(dp[i], dp[i - w[cur]] + v[cur]);
        }

        for (int i : qs[cur]) {
            ans[i] = dp[L[i]];
        }

        if (2 * cur + 1 < n) solve(2 * cur + 1, depth + 1,  n, v, w, qs, L, ans);
        if (2 * cur + 2 < n) solve(2 * cur + 2, depth + 1, n, v, w, qs, L, ans);
        dp = move(tmp_dp);
    } else {
        int hoge = 1 << (depth - 9);
        for (int i = 0; i < hoge; i++) {
            cand.emplace_back(cand[i].first + w[cur], cand[i].second + v[cur]);
        }

        for (P& p : cand) {
            for (int j : qs[cur]) {
                if (p.first > L[j]) continue;
                ans[j] = max(ans[j], dp[L[j] - p.first] + p.second);
            }
        }

        if (2 * cur + 1 < n) solve(2 * cur + 1, depth + 1,  n, v, w, qs, L, ans);
        if (2 * cur + 2 < n) solve(2 * cur + 2, depth + 1, n, v, w, qs, L, ans);
        
        for (int i = 0; i < hoge; i++) {
            cand.pop_back();
        }
    }
}

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

    int n;
    cin >> n;

    vector<int> v(n), w(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i] >> w[i];
    }

    int q;
    cin >> q;

    vector<int> L(q);
    vector< vector<int> > qs(n);
    for (int i = 0; i < q; i++) {
        int u;
        cin >> u >> L[i];
        --u;

        qs[u].push_back(i);
    }

    vector<ll> ans(q, 0);
    solve(0, 0, n, v, w, qs, L, ans);

    for (int i = 0; i < q; i++) {
        cout << ans[i] << newl;
    }
    return 0;
}

Measured memory_bytes: 23452
package main

import "fmt"

func main() {
	var x1,x2,x3,x4,x5 int
	fmt.Scan(&x1,&x2,&x3,&x4,&x5)

	if x1 == 0 {
		fmt.Println(1)
	}
	if x2 == 0 {
		fmt.Println(2)
	}
	if x3 == 0 {
		fmt.Println(3)
	}
	if x4 == 0 {
		fmt.Println(4)
	}
	if x5 == 0 {
		fmt.Println(5)
	}
}



Measured memory_bytes: 1816
import math
pi=math.pi
def calcAngle(h,m): 
    if (h == 12): 
        h = 0
    if (m == 60): 
        m = 0
    hour_angle = 0.5 * (h * 60 + m) 
    minute_angle = 6 * m 
    angle = abs(hour_angle - minute_angle) 
    angle = min(360 - angle, angle) 
    return angle
A,B,H,M=map(int,input().split())
angle=calcAngle(H,M)
t= A*A + B*B - 2*A*B*math.cos(((math.pi)/180)*(angle))
print("{0:.15f}".format(t**0.5))

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

const int MAX = 2510000;
const int mod = 998244353;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    COMinit();
    ll n,m;
    cin>>n>>m;
    ll ans = COM(3*m+n-1,n-1);
    // cerr << ans << endl;
    for(int k=2*m+1;k<=3*m;k++){
        ll ret = n*COM(3*m-k+n-2,n-2);
        ret %= mod;
        // cerr << k << " " << ret << endl;
        ans += mod - ret;
        ans %= mod;
    }
    int x = 1;
    for(int i=m+1;i<=n;i++){
        ll ret = COM(n,i);
        if((m*3-i)%2)continue;
        ll p = 3*m-i;
        p /= 2;
        ret *= COM(n+p-1,n-1);
        ret %= mod;
        ans += mod - ret;
        ans %= mod;
    }
    ans %= mod;
    cout << ans << endl;
    
}

Measured memory_bytes: 59136
#include <bits/stdc++.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()
 
#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream &os, vector<T> V){
  os<<"[";for(auto vv:V)os<<vv<<",";return os<<"]";
} 

template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}


#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
 
#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue
 
#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb fflush(stdout)
 
const int max_n = 1e5 + 5;
 



int main() {
	make(n);
	makev(v, n);
	sort(all(v));
	if (v[n-1]-v[0] > 1) {
		printf("No\n");
		return 0;
	}
	if (v[0] == v[n-1]) {
		if (v[0] == n-1) {
			printf("Yes\n");
			return 0;
		}
		if (v[0] > n/2) printf("No\n");
		else printf("Yes\n");
		return 0;
	} else {
		int unik = 0;
		FOR(i,0,n) if (v[i]==v[0]) unik++;
		int rest = n - unik;
		if (rest == 1) {
			printf("No\n");
			return 0;
		}
		int maxi = unik + rest/2;
		int mini = unik + 1;
		if (v[n-1] >= mini && v[n-1] <= maxi) {
			printf("Yes\n");
		} else {
			printf("No\n");
		}
		return 0;
	}
}


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

int main(){
	long long i,h,w,p,a,b,res,ans=0;
	vector<pair<long long, int>> r;
	cin >> h >> w;
	for(i=0;i<h;i++){
		cin >> p;
		r.push_back(make_pair(p,0));
	}
	for(i=0;i<w;i++){
		cin >> p;
		r.push_back(make_pair(p,1));
	}
	sort(r.begin(),r.end());
	b = h+1;
	a = w+1;
	res = a*b-1;
	i = 0;
	while(res>0){
		if(r[i].second==0){
			ans += (r[i].first)*a;
			res -= a;
			b--;
		}else{
			ans += (r[i].first)*b;
			res -= b;
			a--;
		}
		i++;
	}
	cout << ans << endl;
}
		
		

Measured memory_bytes: 6384
#include <iostream>
#include <algorithm>

int main()
{
  int k, n, a[200010];
  std::cin >> k >> n;
  
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
  }
  
  int max = 0;
  for (int i = 1; i < n; ++i) 
  {
    if (a[i] - a[i-1] > max)
      max = a[i] - a[i-1];
  }
  
  if (k+a[0] - a[n-1] > max)
    max = k+a[0] - a[n-1];
  
  std::cout << k-max;
}

Measured memory_bytes: 4436
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b

signed main(){
	int n; cin>>n;
	int a=0,b=0;
	rep(i,1,n+1){
		if(i%2==0)b++;
		else a++;
	}
	cout<<a*b<<endl;
	
	return 0;
}

Measured memory_bytes: 3592