akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define R register
typedef long long ll;
inline int read(){
	R int x; R bool f; R char c;
	for (f = 0; (c = getchar()) < '0' || c > '9'; f = c == '-');
	for (x = c ^ '0'; (c = getchar()) >= '0' && c <= '9'; x = (x << 1) + (x << 3) + (c ^ '0'));
	return f ? -x : x;
}
#define MN 900005
const int P = 1000000007;
int inv[MN], frac[MN], p3[MN];
inline int mul(int x, int y){return (ll)x * y % P;}
inline int plu(int x, int y){return (x += y) >= P ? x - P : x;}
inline int fpw(int x, int k){
	R int res = 1;
	for (; k; k >>= 1, x = mul(x, x)) 
		if (k & 1) res = mul(res, x);
	return res;
}
inline int C(int n, int m){if (m < 0 || m > n) return 0; return mul(frac[n], mul(inv[m], inv[n-m]));}
int n, m, k, res = 1, ans = 0;
int main(){
	n = read(), m = read(), k = read();
	p3[0] = frac[0] = 1;
	for (R int i = 1; i <= m + k; ++i) p3[i] = mul(p3[i - 1] , 3);
	for (R int i = 1; i <= n + m + k; ++i) frac[i] = mul(frac[i - 1], i);
	inv[n + m + k] = fpw(frac[n + m + k], P - 2);
	for (R int i = n + m + k; i--; ) inv[i] = mul(inv[i + 1], i + 1);
	for (R int i = n; i <= n + m + k; ++i) {
		ans = plu(ans, mul(p3[n + m + k - i], mul(C(i - 1, n - 1), res)));
		res = plu(plu(res, res), plu(plu(-C(i - n, i - n -k), P), plu(-C(i - n, m), P)));
	}
	printf("%d\n", ans); return 0;
}

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

int main(){
	int n;
	cin >> n;
	int ma = 0;
	int mi = 1000000000;
	rep(i,n){
		int a;
		cin >> a;
		ma = max(ma,a);
		mi = min(mi,a);
	}
	int ans = ma - mi;
	cout << ans << endl;
}

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

int main(void){
  int N, n[3];
  cin >> N;
  n[0] = N % 10;
  n[1] = ((N % 100) - n[0]) / 10;
  n[2] = (N - (n[0] + n[1])) / 100;
  if(n[0] == n[2])
    cout << "Yes" << "\n";
  else
    cout << "No" << "\n";
  return 0;
}


Measured memory_bytes: 3540
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[12],d[12],f,g=0,h,i,j,k=0;
	for(i=0;i<12;i++){
		s[i]=0;
		d[i]=0;
	}
	for(i=0;i<12;i++){
		scanf("%d",&a);
		f=0;
		for(j=0;j<k;j++){
			if(a==s[j]){
				f=1;
				d[j]++;
				if(d[j]==4){
					s[j]=0;
					d[j]=0;
					g++;
				}
				break;
			}
		}
		if(f==0){
			s[k]=a;
			d[k]++;
			k++;
		}
	}
	if(g==3) printf("yes\n");
	else printf("no\n");
	return 0;
}

Measured memory_bytes: 2644
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

void stoc(string s, char *cs){
  REP(i, s.length()){
    cs[i] = s[i];
  }
  cs[(int)(s.length())] = '\0';
}

string ctos(char *cs){
  stringstream ss;
  REP(i, strlen(cs)) ss << cs[i];
  return ss.str();
}

int main() {
  set<string> S;
  char cs[256];
  printf("?aa\n"); fflush(stdout);
  S.insert("aa");
  scanf("%s", cs);
  string _s = "aa";
  REP(i, 49){
    string s = ctos(cs);
    //アルファベットの小文字以外が入っている
    REP(i, s.length()) if(!isalpha(s[i]) || s[i] != tolower(s[i])) { cout <<"!OUT" <<endl; return 0; }
    //前回の自分の発言の末尾の文字と一致していない(必ず末尾はa)
    if(s[0] != 'a') { cout <<"!OUT" <<endl; return 0; }
    //既に発言した単語をもう一度繰り返している
    if(S.find(s) != S.end()) { cout <<"!OUT" <<endl; return 0; }

    S.insert(s);
    stringstream ss;
    ss << s[(int)(s.length()) - 1] <<_s <<"a";
    if(_s[1] != 'z') _s[1]++;
    else {_s[0]++; _s[1] = 'a';};
    stoc(ss.str(), cs);
    printf("?%s\n", cs); fflush(stdout);
    scanf("%s", cs);
  }
  return 0;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using namespace std;
int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int a, b, c;
   cin >> a >> b >> c;
   if(a==b+c) {
       cout << "Yes" << endl;
   } else if(b==a+c) {
       cout << "Yes" << endl;
   } else if(c==a+b) {
       cout << "Yes" << endl;
   } else {
       cout << "No" << endl;
   }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		char []c = sc.next().toCharArray();
		
		boolean flag = true;
		
		if(c.length% 2== 1) {
			System.out.println("No");
			return;
		}
		for(int i = 0 ;i < c.length ;i++) {
			if(i % 2 == 1) {
				continue;
			}
			if(c[i] != 'h' || c[i+1] != 'i') {
				flag = false;
				break;
			}
		}
		
		if(flag) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21972
using System;
using System.Collections;
using System.Linq;


namespace How_Many_Islands
{
    class Program
    {
        public static int[] wds = new int[] { -1, -1, -1, 0, 0, 1, 1, 1 };
        public static int[] hds = new int[] { -1, 0, 1, -1, 1, -1, 0, 1 };

        public static void Main(string[] args)
        {
            while (true)
            {
                var wh = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int w = wh[0];
                int h = wh[1];
                if (w == 0 & h == 0) { break; }

                var map = new bool[h + 2, w + 2];
                for (int i = 1; i <= h; i++)
                {
                    var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    for (int j = 1; j <= w; j++)
                    {
                        if (input[j - 1] == 1) { map[i, j] = true; }
                    }
                }

                var count = 0;
                for (int i = 1; i <= h; i++)
                {
                    for (int j = 1; j <= w; j++)
                    {
                        if (map[i, j])
                        {
                            map = DFS(map, i, j);
                            count++;
                        }
                    }
                }
                Console.WriteLine(count);
            }
        }

        static bool[,] DFS(bool[,] map, int y, int x)
        {
            var stk = new Stack();
            stk.Push(new int[] { y, x });
            while (stk.Count > 0)
            {
                var yx = (int[])stk.Pop();
                for (int i = 0; i < wds.Length; i++)
                {
                    int dy = hds[i];
                    int dx = wds[i];
                    if (map[yx[0] + dy, yx[1] + dx])
                    {
                        map[yx[0] + dy, yx[1] + dx] = false;
                        stk.Push(new int[] { yx[0] + dy, yx[1] + dx });
                    }
                }
            }
            return map;
        }
    }
}



Measured memory_bytes: 16408
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
 
using namespace std;
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
	if(a>b)
		return a;
	return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 
 
 
 
int main()
{
	
	ll h;
    cin>>h;
    ll test=0;
    ll cur=1;
    while(h!=1)
    {
        h/=2;
        test+=cur;
        cur*=2;
    }
    test+=cur;
    cout<<test<<endl;
	
	return 0;
}

Measured memory_bytes: 256
p=print
r=range
def a(i,j,k,l=0):p("+<"[l],i,j,k)
def b(i):a(i,i,i+1)
def d(x,i,j):
	for t in r(30):b(p:=j+t-1);a(q:=j+t,n,q);[*map(b,r(q,j+29))];a(j+29,x,i+t,1);b(p);a(q,i+t,q)
p(3933)
a(0,1,n:=97)
a(2,n,n,1)
a(0,n,3)
a(1,n,4)
d(3,5,36)
d(4,36,67)
for t in r(59):a(2,2,2);[(a(5+t-s,36+s,98),a(n,98,99,1),a(2,99,2))for s in r(t+1)if t-30<s<30]

Measured memory_bytes: 9164
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	string t = "AKIHABARA";
	string s;
	cin>>s;
	int N = t.size();
	rep(i,1<<N){
		string a;
		bool ok = 1;
		rep(j,N){
			if((i>>j)&1) a += t[j];
			else if(t[j]!='A') ok = 0;
		}
		if(ok && a==s){
			puts("YES");
			return 0;
		}
	}
	puts("NO");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A,B,C,X,Y,ans;
    cin >> A >> B >> C >> X >> Y; //ABC値段　XY要求
    if (X<Y) {
        if (A*X + B*Y < C*2*X +B*(Y-X)) {
            ans = A*X +B*Y;
        } else if (B*(Y-X) < C*2*(Y-X)) {
            ans = C*2*X +B*(Y-X);
        } else {
            ans = C*2*Y;
        }
    } else {
        if (A*X + B*Y < C*2*Y +A*(X-Y)) {
            ans = A*X +B*Y;
        } else if (A*(X-Y) < C*2*(X-Y)){
            ans = C*2*Y +A*(X-Y);
        } else {
            ans = C*2*X;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let mut i = parse_line::<u64>();
    loop {
        if is_prime(i) {
            println!("{}", i);
            break;
        } else {
            i += 1;
        }
    }
}
fn is_prime(n: u64) -> bool {
    for i in 2..n {
        if i.pow(2) >= n + 2 {
            break;
        }
        if n % i == 0 {
            return false;
        }
        if i * i > n {
            return true;
        }
    }
    true
}

fn parse_line<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
from collections import Counter

N = int(input())
A = [int(n) for n in input().split()]

pairs = sorted([k for k, v in Counter(A).items() if v >= 2] + [k for k,v in Counter(A).items() if v >= 4], reverse = True)

if len(pairs)<2:
  print(0)
else:
  print(pairs[0]*pairs[1])





Measured memory_bytes: 20120
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

// 約数の列挙
/*
 * 2, 4, 8 ... 的な
 */
template<typename T>
set<T> div_count(T x) {
    set<T> st;
    for (long long i = 1; i * i <= x; ++i) {
        if (x % i == 0) {
            st.insert(i);
            st.insert(x/i);
        }
    }
    return st;
}

int main() {
    ll n; cin >> n;
    auto st = div_count(n);
    ll ans = INF;
    for (auto itr : st) {
        //cout << itr + n / itr << endl;
        chmin(ans, itr + n / itr);
    }
    cout << ans - 2<< endl;
}


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

int main() {
	
	int n;
	cin >> n;
	int arr[n][3];
	int dp[n][3];
	for(int i = 0; i < n; ++i)
	{
	    cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
	    dp[i][0] = dp[i][1] = dp[i][2] = INT_MIN;
	}
	dp[0][0] = arr[0][0];
	dp[0][1] = arr[0][1];
	dp[0][2] = arr[0][2];
	
	for(int i = 1; i < n; ++i)
	{
	    dp[i][0] = max(dp[i-1][1] , dp[i-1][2]) + arr[i][0];
	    dp[i][1] = max(dp[i-1][2] , dp[i-1][0]) + arr[i][1];
	    dp[i][2] = max(dp[i-1][1] , dp[i-1][0]) + arr[i][2];
	}
	int ans = dp[n-1][0];
	if(ans < dp[n-1][1])
    {
        ans = dp[n-1][1];   
    }
    if(ans < dp[n-1][2])
        ans = dp[n-1][2];
	cout << ans;
	return 0;
}


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

using namespace std;

template <typename T>
struct Node{
  T value;
  struct Node *next;
  struct Node *prev;
  Node(){
    //????????¶?????????????¬??????????????????????
    prev = next = this;
  }
  Node(T value, Node *prev, Node *next){
    this->value = value;
    this->prev = prev;
    this->next = next;
  }
};

template <typename T>
class DoublyLinkedList {
private:
  Node<T> *head;
  Node<T> *cur;
  void add(T value)
  {
    // ?????¨?????????????????????????¬?????????????????¬????
    // ??????????????¨???????????????????????????????¬????????????????
    Node<T> *node = new Node<T>(value, cur, cur->next);
    cur->next = cur->next->prev = node;
    cur = node;
  }
public:
  DoublyLinkedList(){
      head = cur = new Node<T>();
  }

  void push_front(T value){
    cur = head;
    add(value);
  }

  void push_back(T value){
    cur = head->prev;
    add(value);
  }

  void setCurToFirst(){
    cur = head;
  }

  T next(){
    cur = cur->next;
    return cur->value;
  }

  bool isTail(){
    return cur->next == head;
  }

  void deletenum(int num){
    setCurToFirst();
    while(!isTail()){
      int n = next();
      if (n == num){
        remove_current_node();
        return;
      }
    }
  }

  void deleteFirst(){
    cur = head->next;
    remove_current_node();
  }

  void deleteLast(){
    cur = head->prev;
    remove_current_node();
  }

  void remove_current_node(){
    cur->prev->next = cur->next;
    cur->next->prev = cur->prev;
    delete cur;
    cur = cur->prev;
  }
};

int main(int argc, char const *argv[]) {
  DoublyLinkedList<int> list;
  //??\???
  int count;
  cin >> count;
  string cmd;
  int num;
  for (int i = 0; i < count; i++) {
    cin >> cmd;
    if(cmd == "insert"){
      cin >> num;
      list.push_front(num);
    }else if (cmd == "delete"){
      cin >> num;
      list.deletenum(num);
    }else if (cmd == "deleteFirst"){
      list.deleteFirst();
    }else if (cmd == "deleteLast"){
      list.deleteLast();
    }
  }
  //??????
  list.setCurToFirst();
  while(!list.isTail()){
    int n = list.next();
    cout << n;
    if (list.isTail()){
      cout << endl;
    }else{
      cout << ' ';
    }
  }
  return 0;
}

Measured memory_bytes: 34420
s = gets.strip

words = ['dream', 'dreamer', 'erase', 'eraser']

# 調査文字列が空になるまで
# wordsの要素が見つかるたびに尻から取り除く
until s.empty? do
    reduced = false
    words.map do |w|
        if s[-w.size, w.size] == w
            # s = s[0..-w.size - 1]
            s.slice!(-w.size, w.size)
            reduced = true
            break
        end
    end

    unless reduced
        puts 'NO'
        exit 0
    end
end

puts 'YES'

Measured memory_bytes: 3964
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  long long dp[n + 2];
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for (int i = 2; i < n; i++) {
    dp[i] =
        min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1792
while True:
    n = int(input())
    if n == 0:
        break
    else:
        intlist = []
        minval = 1001
        maxval = -1
        for i in range(n): #calculate max and min values, create list of all values
            a = int(input())
            if a >= maxval:
                maxval = a
            if a <= minval:
                minval = a
            intlist.append(a)
        total = 0
        mincheck = False
        maxcheck = False
        for i in range(len(intlist)): #add numbers together
            if(intlist[i] == minval and mincheck == False): #ignore min value once
                mincheck = True
            elif(intlist[i] == maxval and maxcheck == False): #ignore max value once
                maxcheck = True
            else:
                total += intlist[i]
        print(total//(len(intlist) - 2)) #print avg


Measured memory_bytes: 5600
n = int(input())
cs, ss, fs = [], [], []
for _ in range(n - 1):
    c, s, f = map(int, input().split())
    cs.append(c)
    ss.append(s)
    fs.append(f)

res = []
for i in range(n):
    t = 0
    for j in range(i, n - 1):
        s = ss[j]
        f = fs[j]
        if t < s:
            t = s
        elif t % f > 0:
            t += f - t % f
        t += cs[j]
    res.append(t)
for x in res:
    print(x)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<regex>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int n; cin >> n;
	regex b(R"(>\^(Q=)+~~)");
	rep(i, 0, n) {
		string s; cin >> s;
		int m = 0;
		rep(j, 0, s.size())if (s[j] == '=')m++;
		regex a(">'={" + to_string(m / 2) + "}#={" + to_string(m / 2) + "}~");
		if (regex_match(s, a) && m) { cout << "A" << endl; }
		else if (regex_match(s, b)) { cout << "B" << endl; }
		else cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 3428
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
const int sz=1e5+10,mo=1e9+7;
string s;
int dpA[sz],dpB[sz],dpC[sz],dp[sz];
void solve()
{
    cin>>s;
    const int n=s.size();
    vector<int> dp(4,0);
    dp[0]=1;
    rep(i,n)
    {
        vector<int> ne=dp;
        if(s[i]=='?')
        {
            rep(j,4)
            {
                ne[j]*=3;
                ne[j]%=mo;
            }
        }
        rep(j,3)
        {
            if(s[i]=='A'+j||s[i]=='?')
            {
                ne[j+1]+=dp[j];
                ne[j+1]%=mo;
            }
        }
        dp=move(ne);
    }
    cout<<dp[3]<<endl;

}
main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    solve();
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate nPm
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    string w; cin >> w;
    sort(ALL(w));
    char tmp=w[0]; int cnt = 0;
    rep(i, w.size()) {
        if (w[i] != tmp) {
            tmp = w[i];
            if (cnt%2 != 0) { puts("No"); return 0; }
            cnt = 0;
        }
        cnt += 1;
    }
    if (cnt%2 != 0) { puts("No"); return 0; }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 764
MOD = 1000000007
N = int(input())
A = list(map(int, input().split()))
x = [1, 0, 0]
ans = 3

for i in range(1, N):
    c = x.count(A[i])
    ans *= c
    if c == 0:
        break
    x[x.index(A[i])] += 1

if A[0] != 0:
    ans = 0
print(ans % MOD)

Measured memory_bytes: 52908
import sys
sys.setrecursionlimit(10**9)

TO_K = []
TREE = []

def dfs(parent, distance):
    for i_node in TREE[parent]:
        child, dd = i_node
        if TO_K[child] != -1:
            continue

        next_dt = distance + dd
        TO_K[child] = next_dt
        dfs(child, next_dt)

    return


def main():
    n = int(input())
    abc = [[int(_) for _ in input().split()] for i in range(n-1)]
    q, k = map(int, input().split())
    xy = [[int(_) for _ in input().split()] for i in range(q)]

    global TO_K
    # index '0' is not used.
    TO_K = [-1]*(n+1)

    global TREE
    # index '0' is not used.
    TREE = [[] for _ in range(n+1)]
    for a, b, c in abc:
        TREE[a].append([b, c])
        TREE[b].append([a, c])

    TO_K[k] = 0
    dfs(k, 0)

    for x, y in xy:
        print(TO_K[x]+TO_K[y])
    return


if __name__ == "__main__":
    main()
    sys.exit(0)

Measured memory_bytes: 165824
N = int(input())
S = input()
R = [0]*N
G = [0]*N
B = [0]*N
out = 0
for i in range(N):
    if S[i]=="R":
        R[i]+=1
    if S[i]=="G":
        G[i]+=1
    if S[i]=="B":
        B[i]+=1

SB = sum(B)
for i in range(N):
    for j in range(N):
        X = R[i]
        Y = G[j]
        if (X==1)and(Y==1):
            out += SB
            D = abs(i-j)

            L1 = max(i,j)+D
            if L1<N:
                out += -1*B[L1]
            L2 = min(i,j)-D
            if 0<=L2:
                out += -1*B[L2]
            if D%2==0:
                L3 = min(i,j)+D//2
                out += -1*B[L3]
print(out)

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

long long int c[2003][2003][2] = {};
long long int sum[2003][2003][2] = {};

long long int kansu ( long long int y, long long int x, long long int yy, long long int xx, long long int cc ) {

  return sum[y][x][cc] - sum[y][xx-1][cc] - sum[yy-1][x][cc] + sum[yy-1][xx-1][cc];

}

int main() {

  long long int n, k;
  cin >> n >> k;

  long long int k2 = k * 2;

  for ( long long int i = 0; i < n; i++ ) {

    long long int in_x, in_y;
    char in_c;
    cin >> in_x >> in_y >> in_c;

    if ( in_c == 'W' ) {
      c[ ( in_y % k2 ) + 1 ][ ( in_x % k2 ) + 1 ][0]++;
    }else {
      c[ ( in_y % k2 ) + 1 ][ ( in_x % k2 ) + 1 ][1]++;
    }

  }

  for ( long long int x = 1; x <= k2; x++ ) {
    for ( long long int y = 1; y <= k2; y++ ) {

      //      long long int xx = k2 - x + 1;
      //      long long int yy = k2 - y + 1;

      sum[y][x][0] = c[y][x][0] + sum[y-1][x][0] + sum[y][x-1][0] - sum[y-1][x-1][0];
      sum[y][x][1] = c[y][x][1] + sum[y-1][x][1] + sum[y][x-1][1] - sum[y-1][x-1][1];
      /*
      sum[y][xx][0][1] = c[y][xx][0] + sum[y-1][xx][0][1] + sum[y][xx+1][0][1] - sum[y-1][xx+1][0][1];
      sum[y][xx][1][1] = c[y][xx][1] + sum[y-1][xx][1][1] + sum[y][xx+1][1][1] - sum[y-1][xx+1][1][1];

      sum[yy][xx][0][2] = c[yy][xx][0] + sum[yy+1][xx][0][2] + sum[yy][xx+1][0][2] - sum[yy+1][xx+1][0][2];
      sum[yy][xx][1][2] = c[yy][xx][1] + sum[yy+1][xx][1][2] + sum[yy][xx+1][1][2] - sum[yy+1][xx+1][1][2];

      sum[yy][x][0][3] = c[yy][x][0] + sum[yy+1][x][0][3] + sum[yy][x-1][0][3] - sum[yy+1][x-1][0][3];
      sum[yy][x][1][3] = c[yy][x][1] + sum[yy+1][x][1][3] + sum[yy][x-1][1][3] - sum[yy+1][x-1][1][3];
      */
    }
  }


  long long int ans = 0;

  for ( long long int x = 1; x <= k; x++ ) {
    for ( long long int y = 1; y <= k; y++ ) {
      for ( long long int ccc = 0; ccc < 2; ccc++ ) {

	long long int cc = 1 - ccc;

	ans = max( ans, kansu( y+k, x+k, y+1, x+1, ccc ) + kansu( y, x, 1, 1, ccc ) + kansu( y, k2, 1, x+k+1, ccc ) + kansu( k2, k2, y+k+1, x+k+1, ccc ) + kansu( k2, x, y+k+1, 1, ccc )
		   + kansu( y, x+k, 1, x+1, cc ) + kansu( y+k, k2, y+1, x+k+1, cc ) + kansu( k2, x+k, y+k+1, x+1, cc ) + kansu( y+k, x, y+1, 1, cc ) );

      }
    }
  }

  cout << ans << endl;

  return 0;

}


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

int main(int argc, char const *argv[])
{
	int R;
	cin >> R;
	if(R < 1200)	cout << "ABC" << endl;
	else if(R < 2800)	cout << "ARC" << endl;
	else cout << "AGC" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

vvll edges;
vll c;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    edges.resize(n);
    c.resize(n);
    REP(_, n-1) {
        ll a, b; cin >> a >> b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }
    REP(i, n) cin >> c[i];
    sort(c.begin(), c.end());
    ll start;
    REP(i, n) if (edges[i].size()==1) {start=i; break;}
    vll ans(n, -1);
    ll ci=n-1;
    queue<ll> que; que.push(start);
    while (!que.empty()) {
        ll u = que.front(); que.pop();
        if (ans[u] == -1) {
            ans[u] = c[ci--];
            for (ll v: edges[u]) {
                if (ans[v] == -1) que.push(v);
            }
        }
    }
    cout << accumulate(c.begin(), c.begin()+n-1, 0LL) << '\n';
    REP(i, n) {
        cout << ans[i];
        if (i != n-1) cout << ' ';
    }
    cout << '\n';
    return 0;
}


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


int main() {
    int a[9] = {0};
    rep(i,9) cin >> a[i];
    int cntNone = 0;
    vector<int> indNone;
    vector<int> v;
    set<int> s;
    rep(i,9) s.insert(i+1);
    rep(i,9) {
        if (a[i] == -1) {
            cntNone ++;
            indNone.push_back(i);
        }
        else s.erase(a[i]);
    }
    for (auto i: s) v.push_back(i);
    int ans = 0;
    do
    {
        int b[9];
        rep(i,9) b[i] = a[i];
        rep(i,cntNone) {
            b[indNone[i]] = v[i];
        }
        //rep(i,9) cout << b[i] << ' ';
        //cout << endl;
        int b1 = b[0] + b[2] + b[5];
        int b2 = b[1] + b[4] + (b1 / 10);
        int b3 = b[3] + (b2 / 10);
        if (b1 % 10 != b[8]) continue;
        if (b2 % 10 != b[7]) continue;
        if (b3 % 10 != b[6]) continue;
        ans ++;
    } while (next_permutation( v.begin(), v.end() ) );
    cout << ans << endl;
}


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

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

    string n; cin >> n;
    rep(i,3){
        if(n[i] == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3652
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
int x[18], y[18];
double dist(int i, int j) {
	double dx = x[i] - x[j];
	double dy = y[i] - y[j];
	return pow(dx * dx + dy * dy, 0.5);
}

int main() {
	int n;
	cin >> n;
	
	for (int i = 1; i <= n; i++) {
		cin >> x[i] >> y[i];
	}
	double sum = 0.0;
	vector<int> v(n);
	for (int i = 0; i < n; i++) v[i] = i + 1;
	do {
		for (int i = 0; i < n - 1; i++) sum += dist(v[i], v[i + 1]);
	} while (next_permutation(v.begin(), v.end()));
	int kai = 1;
	for (int i = n; i > 0; i--) {
		kai *= i;
	}
	printf("%12f", sum/kai);
	return 0;
}

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

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            String S = Console.ReadLine();
            int ans = N;

            for(int i=1; i<N; i++)
            {
                if(S[i] == S[i - 1])
                {
                    ans--;
                }
            }

            Console.WriteLine(ans);

        }
    }
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/06/16  Problem: ABC 130 B / Link: http://abc130.contest.atcoder.jp/tasks/abc130_b  ----- */

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N; cin >> N;
	int X; cin >> X;
	vector<int> L(N);
	for (int i = 0; i < N; ++i) {
		cin >> L[i];
	}

	vector<LL>D;
	D.push_back(0);
	FOR(i, 0, N) {
		D.push_back(D.back() + L[i]);
	}
	int ans = 0;
	for (auto it : D) {
		if (it <= X)ans++;
	}
	cout << ans << endl;
	return 0;
}


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

c=0
for i in range(n):
    j=n-1
    while j>0:
        if l[j]<l[j-1]:
            x=l[j]
            l[j]=l[j-1]
            l[j-1]=x
            c+=1
        j-=1
        
print(" ".join(map(str,l)))
print(c)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}
ll ceilll(ll a, ll b) {return (a + b-1) / b;} // if(a%b == 0) (a/b) + 1
ll get_digit(ll a) {ll digit = 0; while(a != 0){a /= 10; digit++;} return digit;} // a != 0
template<typename T> void vecdbg(vector<T>& v){ rep(i, v.size()){cout << v[i] << " ";} br;}
template<typename T> void vecvecdbg(vector<vector<T>>& v){ rep(i, v.size()){rep(j, v[i].size()){cout << v[i][j] << " ";} br;}}

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
// global vector -> 0 initialization

int main() {
    std::cout << std::fixed << std::setprecision(15);
    string s; cin >> s;
    if(s[s.size()-1] == 's'){
        cout << s << "es" << endl;
    }else{
        cout << s << "s" << endl;
    }

}

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
#define MAX 100000

int parent(int i) {return i / 2;}
int left(int i) {return i * 2;}
int right(int i) {return i * 2 + 1;}

int main() {
  int H, A[MAX+1];
  cin >> H;
  for (int i = 1; i <= H; i++) {
    cin >> A[i];
  }

  for (int i = 1; i <= H; i++) {
    cout << "node " << i << ": key = " << A[i] << ", ";
    if (parent(i) > 0) cout << "parent key = " << A[parent(i)] << ", ";
    if (left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
    if (right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3132
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

int main(){
    string s;cin>>s;
    if(s[0] != s[1] || s[1] != s[2])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <cmath>
#include <tuple>
#include <unordered_map>
#include <bitset>
#include <functional>

using namespace std;

#define rep(i,n) for(int i = 0;i < n;i++)
#define all(n)	n.begin(),n.end()
#define each(i,n) for(auto &i : n)
typedef long long ll;

const int INF = 1e9;

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

struct UnionFind {
	vector<int> data;
	vector<int> to;
	UnionFind(int size) : data(size, -1), to(size,-1) {
		rep(i, size)to[i] = i;
	}
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; 
			data[y] = x;
		}
		return x != y;
	}
	void setTo(int x, int to) {
		this->to[root(x)] = to;
	}
	int findTo(int x) {
		return to[root(x)];
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};


signed main() {

	int n, q;
	while (cin >> n >> q && n) {
		struct edge {
			int p, m;
			int count;
			vector<int> t;
		};

		vector<edge> e(n);
		for (int i = 1; i < n;i++) {
			cin >> e[i].p; 
			e[i].p--; 
			e[i].m = -1;
			e[i].count = 0;
			e[e[i].p].t.push_back(i);
		}
		e[0].m = 0; e[0].count = 1;

		vector<int> v(q);
		vector<char> c(q);
		rep(i, q) {
			cin >> c[i] >> v[i]; v[i]--;
			if (c[i] == 'M') {
				e[v[i]].m = v[i];
				e[v[i]].count++;
			}
		}
		function<void(int, int)> dfs = [&](int a, int b) {
			if (e[a].m == -1) {
				e[a].m = b;
			}
			rep(i, e[a].t.size()) {
				dfs(e[a].t[i], e[a].m);
			}
		};
		dfs(0, 0);
		ll ans = 0;
		UnionFind uf(n);

		for (int i = q - 1; i >= 0; i--) {
			int j = v[i];
			if (c[i] == 'M') {
				e[j].count--;
				if (e[j].count == 0) {
					int root = uf.findTo(e[e[j].p].m);
					uf.unionSet(e[j].m, e[e[j].p].m);
					uf.setTo(e[j].m, root);
				}
			}
			else {
				ans += uf.findTo(e[j].m) + 1;
			}
		}

		cout << ans << endl;
	}
	


	return 0;
}

Measured memory_bytes: 15772
#include <iostream>
#include <cstring>
#include <algorithm>
#include <list>
#include <map>
#include <cmath>
#include <string>
#include <cstdio>
#include <vector>
 
using namespace std;

typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '
 
const int MAXN = 2e5+5;

int largest(int a, int b){
	return (a<b)?b:a;
}

int a[MAXN];

int main() {
	int n = 0;
	cin >> n;
	int k;
	for(int i = 0; i < n; ++i){
		cin >> k;
		a[k]++;
	}
	int ans = 0;
	for(int i = 0; i <= 100000; ++i){
		ans = max(ans,a[i]+a[i+1]+a[i+2]);
	}
	cout << ans << endl;


    return 0;
}	

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>

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

inline char tc(){
  static char fl[100],*A=fl,*B=fl;
  return A==B&&(B=(A=fl)+fread(fl,1,100,stdin),A==B)?EOF:*A++;  
}
inline int read(){
  int a=0;static char c;
  while((c=tc())<48||c>57);
  while(c>=48&&c<=57)a=a*10+c-48,c=tc();
  return a;
}
ll h[100010];
int main(){
  ll n=read(),a=read(),b=read(),ans=1e9,c=a-b;
  rep(i,n)h[i]=read();
  ll left=1,right=1e9,mid,cnt=0;
  while (right!=left+1) {
    mid =(right+left)/2;
    cnt=0;
    rep(i,n){
      ll temp=h[i]-b*mid;
      if(temp>0){
        cnt+=ceil(1.0*temp/c);
      }
    }
    if(cnt<mid){
      right=mid;
    }else left=mid;
  }
  cnt=0;
  rep(i,n){
    ll temp=h[i]-b*right;
    if(temp){
      cnt+=ceil(1.0*temp/c);
    }
  }
  ans=min(ans,max(cnt,right));
  cnt=0;
  rep(i,n){
    ll temp=h[i]-b*left;
    if(temp>0){
      cnt+=ceil(1.0*temp/c);
    }
  }
  ans=min(ans,max(cnt,left));
  cout<<ans<<endl;
  return 0;
}

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

const bool num[10][7] =  {{0,1,1,1,1,1,1},
					{0,0,0,0,1,1,0},
					{1,0,1,1,0,1,1},
					{1,0,0,1,1,1,1},
					{1,1,0,0,1,1,0},
					{1,1,0,1,1,0,1},
					{1,1,1,1,1,0,1},
					{0,1,0,0,1,1,1},
					{1,1,1,1,1,1,1},
					{1,1,0,1,1,1,1}};

bool now[7];
bool dif[7];
void init()
{
	for(int i=0;i<7;i++){
		now[i] = 0;
		dif[i] = 0;
	}
}
void show()
{
	for(int i=0;i<7;i++){
		cout << dif[i];
	}
	cout << endl;
}
void solve(int m)
{
	for(int i=0;i<7;i++){
		if(now[i]!=num[m][i]){
			dif[i] = 1;
		}else{
			dif[i] = 0;
		}
		now[i] = num[m][i];
	}
}
int main()
{
	int n;
	while(cin >> n){
		if(n<0)
			break;
		init();
		int m;
		for(int i=0;i<n;i++){
			cin >> m;
			solve(m);
			show();
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int power(int x, int y){
	int i,z;
	 
	 z = 1;
	 
	 for(i = 0; i < y; i++){
	 	z = z * x;
	 }
	 
	 return z;
	 
}
int main (void){
	
	
	int N,K;
	int sum = 0, ans = 0;
		
	scanf("%d", &N);
	scanf("%d", &K);
	
	sum = power(K - 1, N - 1);
	ans = sum * K;
	
	printf("%d\n",ans);
	
	return 0;
}


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

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    if (n%10==3){
        printf("bon\n");
    } else if (n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8){
        printf("pon\n");
    } else {
        printf("hon\n");
    }
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);
ll fac(ll x){if(x==0) return 1;  return x*fac(x-1);}

int main(){
    string s; cin>>s;
    // if(s=="SUN") cout<<7<<endl;
    // else if(s=="MON") cout<<6<<endl;
    // else if(s=="TUE") cout<<5<<endl;
    // else if(s=="WED") cout<<4<<endl;
    // else if(s=="THU") cout<<3<<endl;
    // else if(s=="FRI") cout<<2<<endl;
    // else cout<<1<<endl;

    vector<string> w={"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
    rep(i,w.size()){
        if(w[i]==s) cout<<i+1<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc093/tasks/abc093_b

int main() {
    int A, B, K; cin >> A >> B >> K;
    set<int> st;

    for (int i = A; i < A+K; i++) {
        if (i > B) break;
        st.insert(i);
    }
    for (int i = B; i > B-K; i--) {
        if (i < A) break;
        st.insert(i);
    }
    for (int t : st) {
        cout << t << "\n";
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

bool dp[110000];

int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);

    ll N, K;
    cin >> N >> K;
    vll a(N);
    rep(i,N) cin >> a[i];

    rep(i, K+1) {
        rep(j, N) if(i-a[j] >= 0) dp[i] |= !dp[i-a[j]];
    }

    if(dp[K] == false) cout << "Second" << endl;
    else cout << "First" << endl;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[10000];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    for(int i1=0;i1<n;i1++)
        {
            if(i1<n-1)
            cout<<arr[i1]<<" ";
            else
            cout<<arr[i1];

        }
    cout<<endl;

    for(int i=1;i<n;i++)
    {
       int x=arr[i];int j=i-1;
        while(j>=0 && arr[j]>x)
        {
            arr[j+1]=arr[j];
            j--;


        }
        arr[j+1]=x;
        for(int i1=0;i1<n;i1++)
        {
            if(i1<n-1)
            cout<<arr[i1]<<" ";
            else
                cout<<arr[i1];
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




int N;
#define vacant "Vacant"
#define male "Male"
#define female "Female"
//---------------------------------------------------------------------------------------------------
string a0;
string ask(int i) {
    printf("%d\n", i);
    fflush(stdout);
    string res; cin >> res;
    return res;
}
//---------------------------------------------------------------------------------------------------
void f(int l, int r) {
    int md = (l + r) / 2;

    auto res = ask(md);
    if (res == vacant) return;

    if ((md % 2 == 0 and a0 == res) or (md % 2 == 1 and a0 != res)) f(md + 1, r);
    else f(l, md);
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;

    a0 = ask(0);
    if (a0 == vacant) return;

    f(1, N);
}

Measured memory_bytes: 852
'use strict'

function Main(input) {
  const inputList = input.split('\n');
  const fiveHundread = inputList[0]
  const oneHundread = inputList[1]
  const fifty = inputList[2]
  const sum = Number(inputList[3])
  let count = 0;

  let tmpTotal = 0;

  for (let i=0; i<=fiveHundread; i++) {
    for (let j=0; j<=oneHundread; j++) {
      for (let k=0; k<=fifty; k++) {
        tmpTotal = 500 * i + 100 * j + 50 * k
        if (tmpTotal === sum) {
          count++
        }
      }
    }
  }

  console.log(count)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
n,m=map(int,input().split())
a=list(map(int,input().split()))
sort=sorted(a,reverse=True)
b=sum(a)
count=0

for i in sort:
  if i<b/(4*m):
    break
  else:
    count+=1

if count>=m:
  print('Yes')
else:
  print('No')
  

       

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  bool flag=true;
  bool m=false;
  int b=0;
  int c=0;
  for(int i=0; i<n; i++) {
    for(int j=c; j<n; j++) {
      if(a[j]==i+1) {
       // cout << a[j] << endl;
        b++;
        m=true;
        break;
      }
      if(j-1==n) {
        flag=false;
        break;
      }
      c++;
    }
    if(flag==false) break;
  }
  if(m==false) {
    cout << -1 << endl;
    return 0;
  }
  cout << n-b << endl;
  return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  deque<char>Q;
  string str;
  cin>>str;
  for(char ch:str){
  	Q.push_back(ch);
  }
  int flag=0;
  int n;
  cin>>n;
  while(n--){
  	int t;
    cin>>t;
    if(t==1) flag^=1;
    else{
    	int type;
      	char ch;
      	cin>>type>>ch;
      	if(type==1){
        	if(flag) Q.push_back(ch);
          	else Q.push_front(ch);
        } else {
        	if(flag) Q.push_front(ch);
          	else Q.push_back(ch);
        }
    }
  }
  
  if(flag) reverse(Q.begin(),Q.end());
  while(Q.size()){
  	cout<<Q.front();
    Q.pop_front();
  }
  cout<<endl;
  
  return 0;
}

Measured memory_bytes: 1104