akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

void dfs(Vvec<int>& graph, int from, int tmp, int& index, 
    vector<int>& c, vector<int>& d)
{
    d[tmp] = c[index];
    index--;
    for(int& to: graph[tmp]){
        if(to != from) dfs(graph, tmp, to, index, c, d);
    }
}

int main()
{
    int N;
    cin >> N;
    Vvec<int> graph(N);
    for(int i=0; i<N-1; i++){
        int u, v;
        cin >> u >> v; u--; v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    vector<int> c(N), d(N);
    for(int& x: c) cin >> x;
    sort(c.begin(), c.end());

    int index = N-1;
    dfs(graph, -1, 0, index, c, d);

    int score = 0;
    for(int i=0; i<N-1; i++) score += c[i];
    cout << score << endl;
    for(int i=0; i<N; i++) cout << d[i] << " "; cout << endl;
}

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

int main(){
  int n, T;
  cin >> n >> T;
  int ans = 10000000;
  for(int i = 0; i < n; ++i){
    int c, t;
    cin >> c >> t;
    if(t <= T) ans = min(ans, c);
  }
  
  if(ans > 1000) cout << "TLE" << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
S = input()
kisu = ['R', 'U', 'D']
gusu = ['L', 'U', 'D']
flag = True
for i in range(len(S)):
    if i%2==0:
        if S[i] in kisu:
            continue
        else:
            flag = False
    else:
        if S[i] not in gusu:
            flag = False
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD2>;

mint dp[3010][3010][3];
ll a[3010];

int main(){
    int n, s;
    cin >> n >> s;
    rep(i, n) cin >> a[i];

    dp[0][0][0] = 1;

    rep(i, n) {
        rep(j, s + 1){
            dp[i+1][j][0] += dp[i][j][0];
            dp[i+1][j][1] += dp[i][j][0] + dp[i][j][1];
            dp[i+1][j][2] += dp[i][j][0] + dp[i][j][1] + dp[i][j][2];
            if (j + a[i] <= s) {
                dp[i+1][j+a[i]][1] += dp[i][j][0] + dp[i][j][1];
                dp[i+1][j+a[i]][2] += dp[i][j][0] + dp[i][j][1];
            }
        }
    }

    cout << dp[n][s][2] << endl;

    return 0;
}


Measured memory_bytes: 211968
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned long;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    void Solve() {
        while (true) {
            UL H, W; scanf("%d%d", &H, &W);
            if (H == 0) return;
            rep(y, H) {
                rep(x, W) printf("#");
                printf("\n");
            }
            printf("\n");
        }
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}



Measured memory_bytes: 3140
#include <stdio.h>
#include <limits.h>
 
using namespace std;
 
int main(){
    int n,tmp,min=INT_MAX,max=INT_MIN;
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%d",&tmp);
        if(max < tmp-min) max = tmp - min;
        if(min > tmp) min = tmp;
    }
    printf("%d\n",max);
    return 0;
}


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

typedef long long ll;
const ll INF = 1e9;
const ll INFF = 1e18;
const ll MOD = 1e9 + 7;
const ll MAXN = 1e3;
const double EPS = 1e-9;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1 ; i <= 100000 ; i++) {
        double price = 1.0 * i * 1.08;
        if ((int)floor(price) == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(\n";
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long n;
    cin >> n;
    vector<long> vl(n+1);
    for(long i=1; i<=n; i++) {
        cin >> vl[i];
    }
    long cnt=0;
    for (long i=1; i<=n; i++) {
        if (i == vl[vl[i]]) {
            cnt++;
            vl[i] = 0;
        }
    }
    cout << cnt << '\n';
    return 0;
}


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

const ll MOD = 1e9+7;

ll p2(ll r){ // 2のr乗%MODを求める
  if( r == 0 ){ return 1LL;}
  else if( r == 1){ return 2LL;}
  else{
    
    if( r % 2 == 0 ){ 
      return (p2(r/2)*p2(r/2)) %MOD;
    }
    else{
      return ( ((p2((r-1)/2)*p2((r-1)/2)) %MOD )*2)%MOD;
    }
    
  }
}
    
    
                  

int main(){ 
  
  ll N; cin >> N;
  
 
  
  vector<ll> C(N);
  
  for(ll i = 0; i < N; i++){ cin >> C[i];}
  
   if( N == 1){ cout << (2*C[0])%MOD << endl; return 0;} 
  
  sort(C.begin(),C.end());
  
  vector<ll> B(N);
  
  B[0] = (N-1)*p2(N-2);
  B[0] %= MOD;
  B[0] += p2(N-1);
  

  
  for(ll i = 1; i < N; i++){
    B[i] = B[i-1]-p2(N-2);
  
    B[i] = (B[i]+2*MOD)%MOD;
  }
  
  
  
  ll ans = 0;
  
  for(ll i = 0; i < N; i++){
    
    ll res = B[i]*C[i];
    res %= MOD;
    
    ans += res;
    ans %= MOD;
  }
  
  ans *= p2(N);
  
  ans %= MOD;
  
  cout << ans << endl;
  
  return 0;
} 
  

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int a, b; cin >> a >> b;
    int aa = 0;
    int bb = 0;
    repp(i,0,b) {
        aa *= 10;
        aa += a;
    }
    repp(i,0,a) {
        bb *= 10;
        bb += b;
    }
    cout << min(to_string(aa), to_string(bb)) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

const int MOD = (int)(1e9 + 7);

int main()
{
    int n;
    scanf("%d", &n);
    int ans = 1, num = 0;
    for (int i = 0; i < n; i++) {
        int xi;
        scanf("%d", &xi);
        while (xi < 2 * num) {
            ans = ans * 1ll * num % MOD;
            num --;
        }
        if (xi == 2 * num) {
            ans = ans * 1ll * (num + 1) % MOD;
        } else {
            num ++;
        }
    }
    while (num > 0) {
        ans = ans * 1ll * num % MOD;
        num--;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next(), t = sc.next();
        int max = 0;
        for (int i = 1; i <= n; i++) {
            if (s.substring(n-i, n).equals(t.substring(0, i)))
                max = i;
        }
        System.out.println(n*2-max);
    }
}


Measured memory_bytes: 23380
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>

#include <typeinfo>

using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  bool check = false;
  if(a == 5){
    if(b == 5 && c == 7){
      check = true;
    }else if(b == 7 && c == 5){
      check = true;
    }
  }else if(a == 7){
    if(b == 5 && c == 5){
      check = true;
    }
  }

  if(check){
    cout << "YES" << endl;
    return 0;
  }else{
    cout << "NO" << endl;
    return 0;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

int main() {
    ll n,m;cin>>n>>m;
    string s,t;cin>>s>>t;
    ll l = lcm(n,m);
    for(int i = 0;i < n; i++){
        int j = 1.*i/n*m;
        if(j-1.*i/n*m < 0)continue;
        if(j >= t.size())continue;
        // cout << i << " " << 1.*i/n*m << endl;
        if(s[i]!=t[j]){
            cout << -1 << endl;
            return 0;
        }
    }
    // cout << "---" << endl;
    for(int i = 0;i < m; i++){
        int j = 1.*i/m*n;
        if(j-1.*i/m*n<0)continue;
        if(j >= s.size())continue;
        // cout << i << " " << 1.*i/m*n << endl;
        if(t[i]!=s[j]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << l << endl;
}



Measured memory_bytes: 512
class Dice:

    def __init__(self):
        d = map(int, raw_input().split(" "))
        self.c = raw_input()
        self.rows = [d[0], d[4], d[5], d[1]]
        self.cols = [d[0], d[2], d[5], d[3]]

    def __move_next(self, x, y):
        temp = y.pop(0)
        y.append(temp)
        x[0] = y[0]
        x[2] = y[2]

    def __move_prev(self, x, y):
        temp = y.pop(3)
        y.insert(0, temp)
        x[0] = y[0]
        x[2] = y[2]

    def execute(self):
        for i in self.c:
            self.__move(i, self.rows, self.cols)

    def __move(self, com, x, y):
        if com == "N":
            self.__move_prev(y, x)
        elif com == "S":
            self.__move_next(y, x)
        elif com == "E":
            self.__move_prev(x, y)
        elif com == "W":
            self.__move_next(x, y)

    def print_top(self):
        print self.rows[0]

dice = Dice()
dice.execute()
dice.print_top()

Measured memory_bytes: 6484
class Rectangle:
    def __init__(self, len, breadth):
        self.len = a
        self.breadth = b

    def area(self):
        return self.breadth * self.len
    
    def perimeter(self):
        return (self.breadth + self.len) * 2

x = input()
a = int(x.split()[0])
b = int(x.split()[1])
rectangle = Rectangle(a, b)
print(str(rectangle.area() )+ " " +str(rectangle.perimeter()))


Measured memory_bytes: 5596
#include <iostream>

using namespace std;

//?????????????????????????????¢?????´?????????
int BinarySearch(int n, int A[],int T){
	//T?????????dataS?????????????????????????´¢?????????????????????????????°0????????????

	int left=0,right=n,mid;

	while(left<right){
		mid = (left + right)/2;
			if (A[mid] == T)return 1;
			else if (T < A[mid])right = mid;
			else if (T > A[mid])left = mid+1;		
	}

	return 0;

}


int main(){

	int i, j, n, q, cnt= 0;
	int S[100000], T[50000];
	cin >> n;
	for (i = 0; i < n; ++i){
		cin >> S[i];
	}

	cin >> q;
	for (i = 0; i < q; ++i){
		cin >> T[i];
	}

	//????????????????????????
	for (int j = 0; j < q; ++j){

		if (BinarySearch(n, S, T[j]) == 1){
			cnt++;
		}
	}
	cout << cnt << "\n";

	return 0;
}

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

int main(void)
{
    int n;
    string s, t, v;

    cin >> n >> s >> t;
    v = s + t;
    
    for (int i = 0; i < n; i++)
    {
        cout << v[i] << v[n + i];
    }
    
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner (System.in);
	public static void main (String[] args) {
		Main calc = new Main(); 
		long a = sc.nextLong();
		long b = sc.nextLong();
		System.out.println(calc.GCF(a, b));
	}	
	public long GCF(long a, long b) {
	    if (b == 0) return a;
	    else return (GCF (b, a % b));
	}
}

Measured memory_bytes: 26044
/* https://atcoder.jp/contests/abc105/tasks/abc105_c */

#include <iostream>
#include <vector>
#include <cmath>

int main(int argc, char *argv[])
{
  int N;

  std::cin >> N;

  std::string S;

  char one_digit;

  if (N%2)
  {
    N--;
    one_digit = '1';
  }
  else
  {
    one_digit = '0';
  }

  for (int i = 40; i >= 0; i--)
  {
    long num = long(std::pow(-2, i+1));
    long num_term_plus = i/2;
    long num_term_minus = i%2 ? i/2 + 1 : i/2;
    if (i == 0)
    {
      num_term_plus = 0;
      num_term_minus = 0;
    }
    long num_plus = long(4*(1 - std::pow(4, num_term_plus))/(1 - 4));
    long num_minus = long(-2*(1 - std::pow(4, num_term_minus))/(1 - 4));

    if (N <= num + num_plus && N >= num + num_minus)
    {
      S += "1";
      N -= num;
    }
    else
    {
      if (int(S.size()))
      {
        S += "0";
      }
    }
  }

  S += one_digit;

  std::cout << S << std::endl;

  return 0;
}


Measured memory_bytes: 512
#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() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b + c <= 21)
    cout << "win" << endl;
  else
    cout << "bust" << endl;
}


Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<i64>();
    let (a, b, c, k) = (line[0], line[1], line[2], line[3]);

    if k%2 == 1{
        println!("{}", b-a);
    }else{
        println!("{}", a-b);
    }
}


Measured memory_bytes: 4352
using System;
using System.Linq;

namespace AtCoder.ABC121.C
{
    class Program
    {
        static void Rep(long n, Action<long> action) { for (var i = 0; i < n; ++i) { action(i); } }
        static void Rep(long n, long s, Action<long> action) { for (var i = s; i < n; ++i) { action(i); } }

        public static void Main()
        {
            // Solve(2, 5, new Tuple<long, long>[] { new Tuple<long, long>(4, 9), new Tuple<long, long>(2, 4) });
            // Solve(4, 30, new Tuple<long, long>[] {
            //      new Tuple<long, long>(6, 18),
            //      new Tuple<long, long>(2, 5),
            //      new Tuple<long, long>(3, 10),
            //      new Tuple<long, long>(7, 9)
            // });
            // Solve(1, 100000, new Tuple<long, long>[] {
            //      new Tuple<long, long>(1000000000, 100000)
            // });
            // return;

            var str1 = Console.ReadLine().Split(' ');
            var N = long.Parse(str1[0]);
            var M = long.Parse(str1[1]);
            var AB = new Tuple<long, long>[N];
            Rep(N, i =>
            {
                var str2 = Console.ReadLine().Split(' ');
                AB[i] = new Tuple<long, long>(long.Parse(str2[0]), long.Parse(str2[1]));
            });
            Solve(N, M, AB);
        }

        static void Solve(long N, long M, Tuple<long, long>[] AB)
        {
            var ABsorted = AB.OrderBy(t => t.Item1).ToArray();
            long currentNum = 0;
            long currentMoney = 0;
            long currentIndex = 0;
            while (currentNum != M)
            {
                if (ABsorted[currentIndex].Item2 < M - currentNum)
                {
                    currentNum += ABsorted[currentIndex].Item2;
                    currentMoney += ABsorted[currentIndex].Item1 * ABsorted[currentIndex].Item2;
                    ++currentIndex;
                }
                else
                {
                    var diff = M - currentNum;
                    currentNum = M;
                    currentMoney += ABsorted[currentIndex].Item1 * diff;
                }
            }
            Console.WriteLine(currentMoney);
        }
    }
}


Measured memory_bytes: 27588
N = gets.chomp.to_i
A = gets.chomp.split(' ').map(&:to_i)

def combi(n)
  return 0 if n <= 1
  return n * (n - 1) / 2
end

number_counts = Hash.new(0).tap { |h| A.each { |a| h[a] += 1 } }
sums = number_counts.map { |k, v| [k, combi(v)] }.to_h
all_sum = sums.inject(0) { |s, k_v| s += k_v[1] }

A.each do |i|
  sums[i]
  number_counts[i]
  combi(number_counts[i] - 1)
  puts all_sum - sums[i] + combi(number_counts[i] - 1)
end


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

using namespace std;
typedef long long ll;
int n, k;
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    int a = (n + k - 1) / k;
    int b = n/ k;
    cout << a - b << endl;
    return 0;
}


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


int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(N),B(N);
  for(int i = 0; i < N; i++){
    cin >> A[i] >> B[i];
  }

  vector<pair<int,int>> AB(N);
  for(int i = 0; i < N; i++){
    AB[i] = make_pair(A[i],B[i]);
  }
  sort(AB.begin(),AB.end());

  long long ans = 0;
  for(int i = 0; i < N; i++){
    int buy = min(M,AB[i].second);
    ans += (long long)AB[i].first * buy;
    M -= buy;
  }
  cout << ans << endl;

}


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 55, M = 1010, INF = 0x3f3f3f3f;

int n;
int a[N];
vector<PII> res;

int main()
{
	cin >> n;
	
	int maxa = -INF, mina = INF, axi, ini;
	for (int i = 1; i <= n; i ++ )
	{
		cin >> a[i];
		if (a[i] > maxa) maxa = a[i], axi = i;
		if (a[i] < mina) mina = a[i], ini = i;
	}
	
	if (maxa > -mina)
	{
		for (int i = 1; i <= n; i ++ )
			if (i != axi)
				res.PB({axi, i});
		for (int i = 1; i < n; i ++ ) res.PB({i, i + 1});
	}
	else
	{
		for (int i = 1; i <= n; i ++ )
			if (i != ini)
				res.PB({ini, i});
		for (int i = n; i > 1; i -- ) res.PB({i, i - 1});
	}
	
	cout << res.size() << endl;
	for (auto u : res) cout << u.F << ' ' << u.S << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    string S;cin >> S;
    int Q; cin >> Q;
    bool rev=0;
    string A=""; string B="";
    for(int i= 0;i<Q;i++){
        int n; cin >> n;
        if(n == 1)rev=1-rev;
        else {
            int m; char c; cin >> m >> c; m--;
            if(rev==1)m = 1-m;
            if(m) B+=c;
            else A+=c;
        }
    }
    reverse(A.begin(), A.end());
    string ans = A+S+B;
    if(rev) reverse(ans.begin(), ans.end());
    cout << ans << endl;
}



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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int L = A + B;
  int R = C + D;
  
  if ( L == R ) {
    cout << "Balanced" << endl;
  }
  else if ( L > R ) {
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

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

string s;
int main() {
	int i;
	cin >> s;
	for(i=0; s[i]; i++) {
		if(i%2==0 && s[i]=='L' || i%2==1 && s[i]=='R') return puts("No"), 0;
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 256
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
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 INI(...) int __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
#pragma endregion RegionDefs

void solve()
{
    string s, t; cin >> s >> t;
    IN(a, b);
    string u; cin >> u;
    if (s == u) --a;
    else --b;
    cout << a << " " << b << 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: 764
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Abhilash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int arr[] = new int[n];
            boolean b[] = new boolean[n];
            for (int i = 0; i < n; i++) {
                arr[i] = 1;
            }
            b[0] = true;
            for (int i = 0; i < m; i++) {
                int x = in.nextInt() - 1;
                int y = in.nextInt() - 1;
                if (b[x])
                    b[y] = true;
                if (arr[x] == 1 && b[x])
                    b[x] = false;
                arr[x] -= 1;
                arr[y] += 1;
            }
            int ans = 0;
            for (int i = 0; i < n; i++) {
                ans += b[i] ? 1 : 0;
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  int count = 0;
  int a = 1;
  while (true) {
    a = A.at(a - 1);
    count++;
    if (a == 2) {
      break;
    }
    else if (count > N) {
      count = -1;
      break;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 640
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		scan.close();
		int d = a / b;
		int r = a % b;
		BigDecimal da = new BigDecimal(a);
		BigDecimal db = new BigDecimal(b);
		BigDecimal f = da.divide(db, 5, BigDecimal.ROUND_HALF_UP);
		System.out.println(d + " " + r + " " + f);
	}
}

Measured memory_bytes: 17276
n=int(input())

s=input()

s=list(s)

Rcheck=[0]*n

Bcheck=[0]*n

Gcheck=[0]*n

for i in range(n):
    if s[i] == 'R':
        Rcheck[i] += 1
    if s[i] == 'B':
        Bcheck[i] += 1
    if s[i] == 'G':
        Gcheck[i] += 1

for i in range(1,n):
    Rcheck[i] += Rcheck[i-1]
    Bcheck[i] += Bcheck[i-1]
    Gcheck[i] += Gcheck[i-1]

ans = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        #print(ans)
        if s[i] == s[j]:
            continue
        memo = [s[i],s[j]]
        #print(memo)

        if 'R' not in memo:
            ans += Rcheck[-1] - Rcheck[j]
            if 2*(j+1)-(i+1)-1 < n and s[2*(j+1)-(i+1)-1] == 'R':
                ans -= 1
        elif 'B' not in memo:
            ans += Bcheck[-1] - Bcheck[j]
            if 2*(j+1)-(i+1)-1 < n and s[2*(j+1)-(i+1)-1] == 'B':
                ans -= 1
        elif 'G' not in memo:
            ans += Gcheck[-1] - Gcheck[j]
            if 2*(j+1)-(i+1)-1 < n and s[2*(j+1)-(i+1)-1] == 'G':
                ans -= 1

print(ans)


Measured memory_bytes: 68740
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0;
    rep(i,n){
        ll a;
        cin >> a;
        ans += a-1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace std;
map<char,int> mp;
long long arr[6]={0};
int main()
{
    mp['M']=0;
    mp['R']=1;
    mp['A']=2;
    mp['C']=3;
    mp['H']=4;
    int n;
    cin>>n;
    string s;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        if(mp.count(s[0])) arr[mp[s[0]]]++;
    }
    long long sum=0;
    for(int i=0;i<5;i++)
    {
        for(int j=i+1;j<5;j++)
        {
            for(int z=j+1;z<5;z++)
            {
                sum+=arr[i]*arr[j]*arr[z];
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    vector<int> x(3);
    cin >> x[0] >> x[1] >> x[2];
    int oddcnt = (x[0] & 1) + (x[1] & 1) + (x[2] & 1);
    if (oddcnt == 0 || oddcnt == 3) {
        sort(x.begin(), x.end());
        cout << x[2] - (x[0] + x[1]) / 2 << endl;
        return 0;
    }

    if ((x[0] & 1) == (x[1] & 1)) {
        x[0] += 1;
        x[1] += 1;
    } else if ((x[1] & 1) == (x[2] & 1)) {
        x[1] += 1;
        x[2] += 1;
    } else {
        x[2] += 1;
        x[0] += 1;
    }
    sort(x.begin(), x.end());
    cout << x[2] - (x[0] + x[1]) / 2 + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <functional>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <map>

using namespace std;
using ll = long long;

int main()
{
	int n;
	cin >> n;
	ll cnt = 0;
	int odd = 0;

	for (int i = 0; i < n; ++i)
	{
		int a;
		cin >> a;

		cnt += a / 2;

		if (a == 0)
			odd = 0;
		else if (a % 2 != 0)
		{
			odd++;
			if (odd >= 2)
			{
				cnt++;
				odd = 0;
			}
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<17,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,rem;cin>>N>>rem;
        int fi=rem;
        if(N==0&&rem==0) return 0;
        
        vector<int> state(N,0);
        int now=-1;
        
        while(1){
            now++;
            if(now==N) now=0;
            
            if(rem==0){
                rem+=state[now];
                state[now]=0;
            }else{
                state[now]++;
                rem--;
            }
            
            if(state[now]==fi){
                cout<<now<<endl;
                break;
            }
        }
    }
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int n, k; cin >> n >> k;
  vector<bool> use(10, true);
  rep(i,k) {
    int tmp; cin >> tmp;
    use[tmp] = false;
  }

  int ans = n;
  int pow10 = 1;
  while (ans >= pow10) {
    int num = ans/pow10 % 10;
    int i = num;
    while (!use[i%10]) ++i;
    ans += (i-num) * pow10;
    pow10 *= 10;
  }

  int minimum = 0;
  while (!use[minimum]) ++minimum;
  minimum *= 1111;

  while (pow10 != 1) {
    pow10 /= 10;
    if (ans/pow10 != n/pow10) {
      ans = ans/pow10 * pow10 + minimum % pow10;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


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

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

const int M = 1e5;

ll n, m, x;
int ar[M + 5], pos[M + 5];
ll aw[M + 5], pre[M + 5];

void solve() {
  cin >> n >> x >> m;
  ll cur = x;
  int now = 0;
  while(pos[cur] == 0) {
    pos[cur] = ++now;
    ar[now] = cur;
    cur = (cur * cur) % m;
  }
  int st = pos[cur];
  for(int i = st; i <= now; i++) {
    pre[i - st + 1] = pre[i - st] + ar[i];
  }
  for(int i = 1; i < st; i++) {
    aw[i] = aw[i - 1] + ar[i];
  }
  if(n < st) {
    cout << aw[n] << '\n';
    return;
  }
  ll ans = aw[st - 1];
  n -= (st - 1);
  ll mul = (n / (now - st + 1)), sisa = n % (now - st + 1);
  ans += (mul * pre[now - st + 1]) + pre[sisa];
  cout << ans << '\n';
  return;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);

  int TC = 1;
  for(int i = 1; i <= TC; i++) {
    solve();
  }
  
  return 0;
}

Measured memory_bytes: 4516
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll n, m;
	cin >> n >> m;
	if(n % 3 == 0 || m % 3 == 0){
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1e18;
	for(ll i = max(1LL, (n / 2) - 10); i <= min(n - 1, (n / 2) + 10); i++){
		for(ll j = 1; j < m; j++){
			ll a = 1LL * i * j;
			ll b = 1LL * (n - i) * j;
			ll c = 1LL * (m - j) * n;
			ans = min(ans, max({abs(a - b), abs(a - c), abs(b - c)}));
		}
	}
	swap(n, m);
	for(ll i = max(1LL, (n / 2) - 10); i <= min(n - 1, (n / 2) + 10); i++){
		for(ll j = 1; j < m; j++){
			ll a = 1LL * i * j;
			ll b = 1LL * (n - i) * j;
			ll c = 1LL * (m - j) * n;
			ans = min(ans, max({(ll)abs(a - b), (ll)abs(a - c), (ll)abs(b - c)}));
		}
	}
	ans = min(ans, min(m, n));
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
r, g, b, n = [int(num) for num in input().split()]
arr = [r, g, b]
arr.sort()

#総当たり
counter = 0
for c_1 in range(0, n // arr[-1] + 1):
  for c_2 in range(0, n // arr[-2] + 1):
      if n - c_1 * arr[-1] - c_2 * arr[-2] < 0:
        break
      if (n - c_1 * arr[-1] - c_2 * arr[-2]) % arr[-3] == 0:
        counter += 1
print(counter)

Measured memory_bytes: 40556
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

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")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let a:i32 = read();
    let b:i32 = read();
    let c:i32 = read();

    println!("{}",
        if a < c && c < b {"Yes"} 
        else if b < c && c < a {"Yes"}
        else {"No"}
    );
    
}


Measured memory_bytes: 4352
require 'pp'

n = gets.to_i
a_n = gets.split.map(&:to_i)
X = 10 ** 18
ans = 1
if a_n.include?(0)
    puts 0
    exit 0
end

n.times do |i|
    ans *= a_n[i]
    if ans > X
        puts "-1"
        exit 0
    end
end

puts ans


Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
long long f(long long x, long long y){
  return (x == -1 ? -1 : x / y);
}
int main(){
  long long a, b, x; cin >> a >> b >> x;
  cout << f(b, x) - f(a - 1, x) << endl;
}

Measured memory_bytes: 256
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    s = input()
    if (s == "AC"):
        ac += 1
    elif (s == "WA"):
        wa += 1
    elif (s == "TLE"):
        tle += 1
    else:
        re += 1

print("AC x", ac)
print("WA x", wa)
print("TLE x", tle)
print("RE x", re)


Measured memory_bytes: 9196
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	const int mod=1000000007;
	const long o=1;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		Bit bit=new Bit(n*2);
		int[] b=new int[n+1],w=new int[n+1];
		string[] a=new string[n*2];
		int[] r=new int[n*2];
		for(int i = 0;i<n*2;i++) {
			a[i]=sc.S;
			r[i]=int.Parse((a[i].Split())[1]);
			if(a[i][0]=='B'){b[r[i]]=i;}
			else{w[r[i]]=i;}
		}
		long[,,] dp=new long[n+1,n+1,2];
		for(int i = 0;i<=n;i++) {
			bit=new Bit(n*2);
			if(i!=0){
				for(int j = 1;j<i;j++) {bit.Ud(b[j]+1,1);}
				dp[i,0,0]=dp[i-1,0,0]+b[i]-bit.Get(b[i]+1);
				bit.Ud(b[i]+1,1);
			}
			for(int j = 1;j<=n;j++) {
				dp[i,j,0]=dp[i,j-1,0]+w[j]-bit.Get(w[j]+1);
				if(i!=0){dp[i,j,0]=Math.Min(dp[i,j,0],dp[i-1,j,0]+b[i]-dp[i-1,j,1]);}
				if(j!=0){bit.Ud(w[j]+1,1);}
				if(i!=n){dp[i,j,1]=bit.Get(b[i+1]+1);}
			}
			bit.Clear();
		}
		Console.WriteLine("{0}",dp[n,n,0]);
	}
}
public class Bit{
	private int n;
	private long[] bit;
	public Bit(int n){
		this.n=n;
		bit=new long[n+1];
	}
	public void Ud(int a,long p){while(a<=n){bit[a]+=p;a+=a&-a;}}
	public long Get(int n){
		long a=0;
		while(n>0){a+=bit[n];n-=n&-n;}
		return a;
	}
	public long Get2(int n,int m){
		long a=0,b=0;
		while(n>m){a+=bit[n];n-=n&-n;}
		if(n==m){return a;}
		while(n!=m){b+=bit[m];m-=m&-m;}
		return a-b;
	}
	public void Clear(){bit=new long[n+1];}
}

class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 94864
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int[] list = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

        System.out.println(list[k-1]);
    }
}


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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>D( N );
	for( size_t i = 0; i < N; i++ ) {
		cin >> D[i];
		D[i]--;
	}
	int ans = 0;
	for( size_t i = 0; i < N; i++ ) {
		if( D[D[i]] == i ) {
			ans++;
		}
	}
	cout << ans / 2 << endl;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S)
{
    char c = S[0];
    string ans = NO;
    for (int i = 0; i < S.length(); i++)
    {
        if (S[0] != S[i])
        {
            ans = YES;
        }
    }

    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

const int N = 100009;

int n, a[N];
vector<long long> fin, mul, two, trash;

int pop(vector<long long> &a){
    int x = a.back();
    a.pop_back();
    return x;
}

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

    for(int i = 0; i < n; i++)
        if(a[i] % 4 == 0) mul.push_back(a[i]);
        else if(a[i] % 2 == 0) two.push_back(a[i]);
        else trash.push_back(a[i]);

    fin = two;
    while(fin.size() != n){
        if(fin.size() != 0 && mul.size() != 0) fin.push_back(pop(mul));
        if(trash.size() != 0) fin.push_back(pop(trash));
        if(fin.size() == 0 && mul.size() != 0) fin.push_back(pop(mul));
    }

    fprintf(stderr, "%d\n", fin.size());
    for(int i = 0; i < n; i++)
        fprintf(stderr, "%d ", fin[i]);
    fprintf(stderr, "\n");

    if(fin.size() != n){
        printf("No\n");
        return 0;
    }

    for(int i = 0; i < n-1; i++)
        if(fin[i] * fin[i+1] % 4 != 0){
            printf("No\n");
            return 0;
        }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 2932
def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    num=0
    for i in a:
        if i/sum(a) >= 1/(4*m):
            num+=1
    ans='Yes' if num>=m else 'No'
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1000000007;

ll modpow(ll x, ll n){
    ll res = 1, r = x;
    while(n){
        if(n % 2) res = res * r % MOD;
        r = r * r % MOD;
        n /= 2;
    }
    return res;
}

ll p[102];
ll h[102];

P dfs(ll left, ll right, ll height){
    ll lowest = MOD;
    for(int i = left; i < right; i++) lowest = min(lowest, h[i]);
    P d[102];
    ll c = 0;
    ll k = 0;
    ll last = left;
    for(int i = left; i < right; i++){
        if(h[i] == lowest){
            c++;
            if(i != last){
                d[k] = dfs(last, i, lowest);
                k++;
            }
            last = i + 1;
        }
    }
    if(last != right){
        d[k] = dfs(last, right, lowest);
        k++;
    }
    ll dp[102][102];
    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++) dp[i][j] = 0;
    }
    dp[0][0] = 1;
    for(int i = 1; i <= k; i++){
        for(int j = 0; j <= i; j++){
            dp[i][j] = dp[i - 1][j] * d[i - 1].second % MOD;
            if(j) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] * d[i - 1].first % MOD) % MOD;
        }
    }
    P res = P(0, 0);
    for(int j = 0; j <= k; j++){
        res.second = (res.second + dp[k][j] * p[c + j] % MOD) % MOD;
    }
    res.first = dp[k][k] * 2 % MOD;
    res.second = (res.second + MOD - res.first) % MOD;
    res.first = res.first * modpow(2, lowest - height - 1) % MOD;
    return res;
}

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> h[i];
    p[0] = 1;
    for(int i = 1; i <= n; i++) p[i] = p[i - 1] * 2 % MOD;
    P ans = dfs(0, n, 0);
    cout << (ans.first + ans.second) % MOD << endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = int(1e5);
int N, four, two, odd;
ll a[MAX_N];

void solve() {
    if (N == odd + four && odd == four + 1) {
        cout << "Yes" << endl;
        return;
    }
    if (odd > four) {
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
}

int main() {
    cin >> N;
    REP(i, N) {
        cin >> a[i];
        if (a[i] % 4 == 0) four += 1;
        else if (a[i] % 2 == 0) two += 1;
        else odd += 1;
    }
    solve();
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
public class Main{
    static int N, a, b, c;
    static boolean done[][][];
    static double dp[][][];
    static double f(int a, int b, int c){
        if (a==0&&b==0&&c==0) return 0.0;
        if (done[a][b][c]) return dp[a][b][c];
        done[a][b][c] = true;
        dp[a][b][c] = 1.0;
        if (a!=0) dp[a][b][c] += (double)a/(double)(N) * f(a-1, b, c);
        if (b!=0) dp[a][b][c] += (double)b/(double)(N) * f(a+1, b-1, c);
        if (c!=0) dp[a][b][c] += (double)c/(double)(N) * f(a, b+1, c-1);
        dp[a][b][c] /= (1.0 - ((double)(N-a-b-c)/(double)(N)));
        //System.out.println(a + " " + b + " " + c + " "+ dp[a][b][c]);
        return dp[a][b][c];
    }
    public static void main(String[] args) throws IOException{
        N = readInt();
        for (int i = 1; i<=N; i++){
            int x = readInt();
            if (x==1) a++;
            if (x==2) b++;
            if (x==3) c++;
        }
        dp = new double[N+1][N+1][N+1];
        done = new boolean[N+1][N+1][N+1];
        System.out.println(f(a, b, c));
        
    }
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                    st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
    }
    static long readLong() throws IOException {
            return Long.parseLong(next());
    }

    static float readFloat() throws IOException {
            return Float.parseFloat(next());
    }

    static boolean readBool() throws IOException {
            return Boolean.parseBoolean(next());
    }

    static short readShort() throws IOException {
            return Short.parseShort(next());
    }

    static byte readByte() throws IOException {
            return Byte.parseByte(next());
    }

    static int readInt() throws IOException {
            return Integer.parseInt(next());
    }

    static double readDouble() throws IOException {
            return Double.parseDouble(next());
    }

    static char readChar() throws IOException {
            return next().charAt(0);
    }

    static String readLine() throws IOException {
            return br.readLine().trim();
    }

    static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    static void print(Object o) {
            pr.print(o);
    }
}

Measured memory_bytes: 304400
N = int(input())
ans = 0
count = 0
for i in range(2, N+1):
   for j in range(1, i+1):
      if i % j == 0:
         count += 1
   if count == 8 and i % 2 == 1:
      ans += 1
   count = 0

print(ans)

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

int main(){
    int n;
    cin >> n;
    long long ans = 50;
    long long sum,a;
    for (int i = 0; i < n; i++){
        cin >> a;
        sum = 0;
        while (a%2 == 0){
            a /= 2;
            sum++;
        }
        ans = min(ans,sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256