akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    vector<long long int> v;
    for(int i = 0; i < 3 * N; i++){
        long long int a;
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end());
    long long int ans = 0;
    for(int i = 3 * N - 2; i > N - 1; i -= 2){
        ans += v[i];
    }
    cout << ans << endl;
    return 0;
}

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

// 数字の各桁の和を返す
int sumDigits (int n) {
    int s;
    while (n > 0) {
        s += n % 10;
        n /= 10;
    }
    return s;
}

// 最大公約数を返す
int gcd (int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

int main () {
  int N, A; cin >> N >> A;
  
  int a = N % 500;
  if (a <= A) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

#define INF 1<<30

vector<long> A;
int count;

void merge(int l,int m,int r){
    int n1 = m - l;
    int n2 = r - m;
    vector<int> L, R;
    for(int i=0;i<n1;i++)
        L.push_back(A[l+i]);
    for(int i=0;i<n2;i++)
        R.push_back(A[m+i]);
    L.push_back(INF);
    R.push_back(INF);
    int i,j;
    i=j=0;
    for(int k=l;k<r;k++){
        count++;
        if(L[i]<=R[j]){
            A[k] = L[i];
            i++;
        }else{
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(int l,int r){
    if(l+1<r){
        int m = (l+r)/2;
        mergeSort(l,m);
        mergeSort(m,r);
        merge( l, m, r);
    }
}
int main(){
    int  n;
    long t;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>t;
        A.push_back(t);
    }
    mergeSort(0,A.size());
    for(int i=0;i<A.size()-1;i++)
        cout<<A[i]<<" ";
    cout<<A[A.size()-1]<<endl;
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 8032
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<algorithm>
using namespace std;
int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
   if(b-a == c-b) printf("YES");
   else printf("NO");
    return 0;
}

Measured memory_bytes: 128
import math
 
x = int(input())
 
ans = 100000000000
for i in range(1, int(math.sqrt(x)) + 1): 
    if x % i == 0:
        tmp = int((i - 1) + (x / i - 1))
        if ans > tmp:
            ans = tmp
 
print(tmp)

Measured memory_bytes: 3060
#include <cmath>
#include <cstdio>
#include<string>
#include <vector>
#include <iostream>
#include<bits/stdc++.h>
#include <algorithm>
#define pb push_back
#define ll long long
#define mk make_pair
#define mod 200000
using namespace std;

ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}

ll lcd(ll a,ll b){
    ll k=gcd(a,b);
    return((a/k)*b);
}


int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)cin>>a[i];
    ll result=a[0];
    for(ll i=1;i<n;i++){
        result=lcd(a[i],result);
    }
    cout<<result<<endl;
}

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


int main(){
	int N;
	int a,b;
	cin>>N;
	if(N==1){
		cout<<"Hello World"<<endl;
	}
	else{
		cin>>a>>b;
		cout<<a+b<<endl;
	}
			
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace __gnu_pbds; 
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
    #define all(a)      (a).begin(),(a).end()
    #define sz(x)       (int)x.size()
    
    #define ff first
    #define ss second
    #define mp make_pair
         
    #define pb push_back
    #define endl "\n"
         
    #define int long long 
    #define double long double
         
    #define bp __builtin_popcountll
    #define inf 1e16
    
    const int N=1e5+5; 
    const int M=1e6+6;
    const int MOD=1e9+7;
    void solve()
    {        
    	int n;
    	cin>>n;
    	int ans=(n/500)*1000;
    	n=n%500;
    	ans+=(n/5)*5;
    	cout<<ans;
    }

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


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

bool good(ll a, ll b, ll c) {
	if (a == b || b == c)
		return false;
	return a + b > c;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<ll> l(n);
	for (int i = 0 ; i < n ; ++i) {
		cin >> l[i];
	}
	sort(l.begin(), l.end());
	int c = 0;
	for (int i = 0 ; i < n ; i++) {
		for (int j = i + 1 ; j < n ; j++) {
			for (int k = j + 1 ; k < n ; k++) {
				c += good(l[i], l[j], l[k]);
			}
		}
	}
	cout << c << "\n";
	

	return 0;
}


Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;

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


int main() {
	long long sum = 0,tmp = 0;
	int n;
	cin >> n;
	for (long long i = 1; i <= n; i++) {
		for (long long j = 1; j <= n; j++) {
			for (long long k = 1; k <= n; k++){
				tmp = gcd(gcd(i, j), k);
				//cout << i << " " << j << " " << k << " " << tmp << endl;
				sum += tmp;
			}
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 3600
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        $(writeln!(stderr(), "{} = {:?}", stringify!($arg), $arg).unwrap());*
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x
    } else {
        gcd(y, x % y)
    }
}

fn main() {
    let (_, X) = read!(usize, i64);
    let Xs = read![[i64]];

    let mut g = 0;
    for x in Xs {
        g = gcd((X - x).abs(), g);
    }
    println!("{}", g)
}


Measured memory_bytes: 8444
package main
import (
  "fmt"
  "strings"
)

func main() {
  var s, res string
  fmt.Scan(&s)
  sa := strings.Split(s, "")
  for _, x := range sa {
    if x == "B" {
      if len(res) > 0 {
        res = res[:len(res)-1]
      }
    } else {
      res = res + x
    }
  }
  fmt.Println(res)
}

Measured memory_bytes: 640
#include<stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
  int x, i, j, t;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ ) {
    if ( A[j] <= x ) {
      i++;
      t = A[j]; A[j] = A[i]; A[i] = t;
    }
  }
  t = A[j]; A[j] = A[i + 1]; A[i + 1] = t;
  return i + 1;
}

int main() {
  int i, q;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);

  q = partition(0, n - 1);

  for ( i = 0; i < n; i++) {
    if ( i ) printf(" ");
    if ( i == q) {
      printf("[%d]", A[i]);
    } else {
      printf("%d", A[i]);
    }
  }

  printf("\n");

  return 0;
}

Measured memory_bytes: 2948
N = int(input())

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

min = 10000000


for t in range(1, N):
    pre = num[:t]
    post = num[t:]

    if pre[-1] == post[0]:
        continue
    else:
        presum = sum(pre)
        postsum = sum(post)
        gap = abs(presum-postsum)
        if gap < min:
            min = gap

print(min)


Measured memory_bytes: 38512
def get_keys_from_value(d_, val_):
    return [k for k, v in d_.items() if v == val_]
import collections

n = int(input())
s = []

for i in range(n):
    s.append(input())
c = collections.Counter(s)

max_val = max(c.values())
ans = sorted(get_keys_from_value(c, max_val))

for i in ans:
    print(i)

Measured memory_bytes: 35576
n = int(input())
lst = [list(map(int,input().split())) for i in range(n)]
B = [lst[i][0] for i in range(n)]
node = [[] for i in range(n)]

def Insertion_Sort(lst,B,n):
    for i in range(1,n):
        v = B[i]
        w = lst[i]
        j = i-1
        while j>=0 and B[j]>v:
            B[j+1]=B[j]
            lst[j+1]=lst[j]
            j-=1
        B[j+1]=v
        lst[j+1]=w
        
def find_root():
    A = []
    for i in range(n):
        A.extend(lst[i][2:])
    for i in range(n):
        if not i in A:
            return i

def make_node(arg_parent,arg_num, arg_depth):
    if arg_num == root:
        type = "root"
    elif lst[arg_num][1] == 0:
        type = "leaf"
    else:
        type = "internal node"
    children_lst = lst[arg_num][2:]
    node[arg_num] = [arg_parent, arg_depth, type, children_lst]
    for i in children_lst:
        make_node(arg_num, i, arg_depth+1)

Insertion_Sort(lst, B, n)
root = find_root()
make_node(-1, root, 0)

for i in range(n):
    parent, depth, type, children_lst = node[i]
    print(f"node {i}: parent = {parent}, depth = {depth}, {type}, {children_lst}")


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

int main() {
	string str;
	cin >> str;
	char cur = 'a';
	for (char c : str) {
		if (c == cur) {
			cout << "Bad" << endl;
			return 0;
		}
		cur = c;
	}
	cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

char arr[1000];

int main()
{
	arr['A'] = 'T';
	arr['T'] = 'A';
	arr['C'] = 'G';
	arr['G'] = 'C';
	char tmp;
	cin >> tmp;
	cout << arr[tmp] << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll md = 1000000007;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
vl pr;

inline ll add(ll a, ll b, ll mod = md) {
    return (a%mod + b%mod + mod) % mod;
}

inline ll mul(ll a, ll b, ll mod = md) {
    return ( (a%mod) * (b%mod) ) % mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	map<string, int> f;
	cin >> n;
	while(n--) {
		string s;
		cin >> s;
		f[s]++;
	}
	cout << "AC x " << f["AC"] << "\n";
	cout << "WA x " << f["WA"] << "\n";
	cout << "TLE x "  << f["TLE"] << "\n";
	cout << "RE x " << f["RE"] << "\n";
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e3+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
double dp[MAXN][MAXN];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>n;
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        double a;
        cin>>a;
        dp[i][0] = dp[i - 1][0]*(1.0 - a);
        for(int j = 1; j <= n; j++){
            dp[i][j] = dp[i - 1][j - 1]*a + dp[i - 1][j]*(1 - a);
        }
    }
    double ans = 0;
    for(int i = n / 2 + 1; i <= n;i++){
        ans += dp[n][i];
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 1LL << 20;
template<class T> inline bool chmin(T& a, T b) {
    if (b < a) {
        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;
}

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
  int N, NW;
  cin >> N >> NW;

  ll w[100];
  ll v[100];
  
  ll dp[101][100001] = {0};

  for(int i = 0; i < N; i++){
    ll w, v;
    cin >> w >> v;
    for(int j = 0; j <= NW; j++){
      dp[i+1][j] = dp[i][j];
      if(0 <= j - w){
        chmax(dp[i+1][j], dp[i][j-w]+v);
      }
    }
  }
  cout << dp[N][NW] << endl; 
}


Measured memory_bytes: 79232
x, n = map(int, input().split())
if (n != 0):
  p = list(map(int, input().split()))
else:
  print(x)
  exit()

kouho = list(range(-200, 200))


for i in range(len(p)):
  if p[i] != x:
    del kouho[kouho.index(p[i])]

kouho_num = kouho.index(x)
right = kouho_num + 1
left = kouho_num - 1

if (x not in p):
  print(x)
elif abs(kouho[right] - kouho[kouho_num]) > abs(kouho[kouho_num] - kouho[left]):
  print(kouho[left])
elif abs(kouho[right] - kouho[kouho_num]) == abs(kouho[kouho_num] - kouho[left]):
  print(kouho[left])
else:
  print(kouho[right])


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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin, (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

int main() {
  int N, M;
  cin >> N >> M;
  int A;
  ll ans = 0;
  multiset<int> s;
  rep(i, N) {
    cin >> A;
    s.insert(A);
  }
  // for (auto i = s.begin(); i != s.end(); i++)
  //   cout << *i << ' ';
  // cout << endl;
  rep(i, M) {
    int temp = *(--s.end());
    s.erase(--s.end());
    s.insert(temp/2);
    // for (auto i = s.begin(); i != s.end(); i++)
    //   cout << *i << ' ';
    // cout << endl;
  }
  for (auto i = s.begin(); i != s.end(); i++) {
    // cout << *i << ' ';
    ans += (ll)*i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4992
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#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 <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
//#define MOD 1000000007
#define MOD 998244353
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    vector<ll> s(N);
    ll sum = 0;
    rep(i, N) {
        cin >> s[i];
        sum += s[i];
    }
    sort(all(s));
    if (sum % 10 == 0)  {
        rep(i, N) {
            if (s[i] % 10 != 0) {
                sum -= s[i];
                break;
            }
            if (i == N-1) {
                sum = 0;
            }
        }
    }
    print(sum);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool prime(int n){
	int cnt=0;
	for(int i=2;i<n;i++){
		if(n%i==0) cnt++;
	}
	if(cnt==0&&n>1) return true;
	else return false;
}
int main(){
	int x;
	cin>>x;
	for(int i=x;i<=1000000;i++){
		if(prime(i)==true){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


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

const int N = 610;
const int mod = 1e9 + 7;

typedef long long LL;

int f[N][N], g[N], G[N], cnt[N][N];

int main() {
    int n, k; scanf("%d%d", &n, &k), n *= 2;
    for (int i = 1; i <= k; i++) {
        int a, b; scanf("%d%d", &a, &b), G[a] = b, G[b] = a;
    }
    for (int i = 1; i <= n; i++)
        for (int j = i; j <= n; j++) 
            cnt[i][j] = cnt[i][j - 1] + !G[j];
    g[0] = 1;
    for (int i = 2; i <= n; i += 2)
        g[i] = (LL)g[i - 2] * (i - 1) % mod;
    for (int i = 1; i <= n; i++)
        for (int j = i; j <= n; j++) {
            bool flag = true;
            for (int k = i; k <= j && flag; k++)
                if (G[k] && (G[k] < i || G[k] > j)) flag = false;
            if (!flag) continue;
            f[i][j] = g[cnt[i][j]];
            for (int k = i; k < j; k++) 
                f[i][j] = (f[i][j] - (LL)f[i][k] * g[cnt[k + 1][j]] % mod + mod) % mod;
        }
    int res = 0;
    for (int i = 1; i <= n; i++)
        for (int j = i; j <= n; j++)
            res = (res + (LL)f[i][j] * g[n - k * 2 - cnt[i][j]]) % mod;
    printf("%d\n", res);
}

Measured memory_bytes: 3072
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, K = MAP()
P = LIST()

check = [0]*(N-K+1)
up_check = [0]*N
for i in range(1, N):
	if P[i] >= P[i-1]:
		up_check[i] = 1

up_check_acc = list(accumulate(up_check))
for i in range(N-K+1):
	if up_check_acc[i+K-1]-up_check_acc[i] == K-1:
		check[i] = 1

q1 = sorted((P[:K]))
q2 = [N]
q3 = sorted([-x for x in P[:K]])
q4 = [N]

ans = N-K+1
for i, p in enumerate(P[K:]):
	heappush(q1, p)
	heappush(q3, -p)
	while q1[0] == q2[0]:
		heappop(q1)
		heappop(q2)

	while q3[0] == q4[0]:
		heappop(q3)
		heappop(q4)

	if q1[0] == P[i] and q3[0] == -p and check[i]*check[i+1] == 0:
		ans -= 1

	heappush(q2, P[i])
	heappush(q4, -P[i])

ans -= max(0, sum(check)-1)
print(ans)

Measured memory_bytes: 53940
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ll long long
#define MOD 1000000007
#define ull unsigned long long int
#define db double
#define fi first
#define se second
#define pb push_back
#define vec vector<ll>
#define pr pair<ll,ll>
#define pq priority_queue<ll,vector<ll>, compare_queue >
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define repn(i,n) for(ll i=0;i<n;i++)
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define GS(s)   string s; getline(cin,s);
#define lll __int128_t
#define endl "\n"
#define Next cout.flush()

struct compare_queue
{
    bool operator()(const pair<ll,pr>& a, const pair<ll,pr>& b)
    {
        return a.fi < b.fi;
    }
};

ll gcd(ll u,ll v)
{
	if(v==0)
	return u;
	
	else
	return gcd(v,u%v);
}

// ll power(ll x,ll y) 
// { 
//     if (y == 0) 
//         return 1; 
//     ll p = power(x, y/2)%MOD; 
//     p = ((p%MOD) * (p%MOD))%MOD; 

//     return (y%2 == 0)? p%MOD : ((x%MOD) * (p%MOD))%MOD; 
// } 

// ll modInverse(int a) 
// { 
//     if(a==1){return 1;}
//     return power(a,MOD-2); 
// } 
  
// // // #define MAX 1000000
// int primes[100009],cnt=0;
// // vector<int> factors[1000009];
// char str[1000009];
// void pre()
// {
//     // calcualting primes
//     int n=100000;
//     for(int i=2; i*i<=n; i++)
//         if(str[i]==0)
//             for(int j=i; j*i<=n; j++)
//                 str[i*j]=1;
//     for(int i=2; i<=n; i++)
//         if(str[i]==0)primes[cnt]=i,cnt++;
// }


// A O(log n) function returning primefactorization 
// by dividing by smallest prime factor at every step 
// vector<ll> getFactorization(ll x) 
// { 
//     vector<ll> ret; 
//     while (x != 1) 
//     { 
//         ret.push_back(spf[x]); 
//         x = x / spf[x]; 
//     } 
//     return ret; 
// } 

// C:\Users\A\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\lambda


void Function(){
string s;
cin >> s;
if(s[s.length()-1]=='s'){s+="es";}
else{s+="s";}
cout << s << endl;

}


int main(){ 
fast;
ll t=1,i=0,j=0,k,h;
 //pre();
// cin >> t;
for(h=1;h<=t;h++){

Function();

}


return 0;

}

Measured memory_bytes: 3640
//
//  main.cpp
//  search_bridges
//
//  Created by ???????????? ???????´???°?????? on 26.06.15.
//  Copyright (c) 2015 company. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

void is_bridge(const std::vector<std::vector<int> > &graph, std::vector<std::pair<int, int> >& bridges, const int v, const int u) {
    //    if (std::count(graph[v].begin(), graph[v].end(), u) == 1) {
    if (v < u) bridges.push_back(std::make_pair(v, u));
    else bridges.push_back(std::make_pair(u, v));
    //    }
}

void DFS(const std::vector<std::vector<int> > &graph, std::vector<bool> &used, std::vector<int> &tin, std::vector<int> &fup,
         std::vector<std::pair<int, int> > &bridges, int timer, int v, int parent = -1) {
    
//    std::copy(graph[v].begin(), graph[v].end(), std::ostream_iterator<size_t>(std::cout, " ")); std::cout << '\n';
    
    used[v] = true;
    tin[v] = fup[v] = timer++;
    for (int i = 0; i < graph[v].size(); ++i) {
        int to = graph[v][i];
        if (to == parent) continue;
        if (used[to]) {
            fup[v] = std::min(fup[v], tin[to]);
        }
        else {
            DFS(graph, used, tin, fup, bridges, timer, to, v);
            fup[v] = std::min(fup[v], fup[to]);
            if (fup[to] > tin[v]) {
                is_bridge(graph, bridges, v, to);
            }
        }
    }
}

int main() {
    int N, M;
    std::cin >> N >> M;
    
    std::vector<std::vector<int> > graph (N);
    for (size_t i = 0; i < M; ++i) {
        int from, to;
        std::cin >> from >> to;
        graph[from].push_back(to);
        graph[to].push_back(from);
    }
    
    std::vector<bool> used (N);
    std::fill(used.begin(), used.end(), false);
    
    std::vector<int> tin (N), fup (N);
    std::vector<std::pair<int, int> > bridges;
    int timer = 0;
    
    for (int i = 0; i < N; ++i) {
        if (!used[i]) {
            DFS(graph, used, tin, fup, bridges, timer, i);
        }
    }
    std::sort(bridges.begin(), bridges.end());
    
    for (auto& edge: bridges) {
        std::cout << edge.first << ' ' << edge.second << '\n';
    }
}

Measured memory_bytes: 3332
($N,$M) =split(" ",<STDIN>);
for($i=0;$i<$M;$i++) {
	($L,$R,$D)=split(" ",<STDIN>);
	$L--;$R--;
	push @L,$L;
	push @R,$R;
	push @D,$D;
	$C{$L}{$R}=$#D;
	$C{$R}{$L}=$#D;
}

$m=0;
while ($m<$M) {
	$M{$m}=1;
	push @M,$m;
	$L=$L[$m];$R=$R[$m];
	push @K,$L;$K{$L}=1;
	push @K,$R;$K{$R}=1;
	$x{$L} = 0;
	$x{$R} = $D[$m];
	
	while ($#K>=0){
		$i=pop(@K);
		foreach $j ( keys %{$C{$i}} ) {
			$n=$C{$i}{$j};
			next if ($M{$n});
			$M{$n}=1;
			push @M,$n;
			if (!exists($K{$j})) {
				push @K,$j;$K{$j}=1;
			}
		}
	}
	$m++;
	for(;$M{$m}!=0;$m++){}
}

for($i=0;$i<=$#M;$i++){
	$m=$M[$i];$L=$L[$m];$R=$R[$m];
	if ( exists($x{$L}) ) {
		if ( exists($x{$R}) ) {
			if ($x{$R} != $x{$L}+$D[$m]) {
				print "No";
				exit;
			}
		} else {
			$x{$R} = $x{$L}+$D[$m];
		}
	} else {
		$x{$L} = $x{$R}-$D[$m];
	}
}


print "Yes";


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

#define fastIO                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
    fastIO;
    int N;
    cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; i++)
    {
        cin >> h[i];
    }
    vector<int> past_one(N, INT_MAX), past_two(N, INT_MAX);
    past_one[0] = past_two[0] = 0;
    for (int i = 1; i < N; i++)
    {
        if (i - 1 >= 0)
            past_one[i] = min(past_one[i - 1], past_two[i - 1]) + abs(h[i] - h[i - 1]);
        if (i - 2 >= 0)
            past_two[i] = min(past_one[i - 2], past_two[i - 2]) + abs(h[i] - h[i - 2]);
    }
    cout << min(past_one[N - 1], past_two[N - 1]);
}

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

int main(){
    int n; cin >> n;
    vector<ll> a(n), b(n), c(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    ll ans = 0;
    for(int i = 0; i < n; i++){
        int d = b[i];
        auto e = upper_bound(c.begin(), c.end(), d);
        auto f = lower_bound(a.begin(), a.end(), d);
        ans += (c.end() - e) * (f - a.begin());
    }
    cout << ans << endl;
}

Measured memory_bytes: 2688
_ = int(input())
A = [ int(i) for i in input().strip().split(' ')]
a = 1
if min(A) == 0:
    print(0)
else:
    for Ai in A:
        a *= Ai
        if a > 10**18:
            print('-1')
            break
    else:
        print(a)


Measured memory_bytes: 21652
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	double a, b;
	cin >> a >> b;
	double c = a / b;
	cout << c << endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;



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

	char a;
	cin >> a;
	if (a == 'A')cout << 'T' << endl;
	if (a == 'T')cout << 'A' << endl;
	if (a == 'G')cout << 'C' << endl;
	if (a == 'C')cout << 'G' << endl;
	return 0;
}

Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N, K=LI()
A=LI()

counts = collections.Counter(A)
counts = counts.values()
counts = sorted(counts, reverse=True)
result = 0
while len(counts) > K:
    result+=counts.pop()
    
print(result)
    

Measured memory_bytes: 35204
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<ii, ii>> vii;


int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    long long a, b;
    cin >> a >> b;
    long long gcd = __gcd(a, b);
    long long ans = 0;
    for (int i = 2; 1LL * i * i <= gcd; ++i) {
        int cnt = 0;
        while (gcd % i == 0) {
            gcd /= i;
            ++cnt;
        }
        if (cnt)
            ++ans;
    }
    if (gcd > 1)
        ++ans;

    cout << ans + 1 << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define REP(i,s,N) for (int i=s;i<(N); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;


int main(){
	string S;
	cin >> S;
	int Q;
	cin >> Q;
	string AA;
	bool rl = false;
	REP(i,0,Q){
		int T;
		cin >> T;
		if(T==1){
			rl = (!rl);
          reverse(AA.begin(),AA.end());
            S = AA + S;
          AA = "";
		}else{
			int F;
			char C;
			cin >> F;
			cin >> C;
			if((F==1&&rl==false)||(F==2&&rl==true)){
				AA.push_back(C);
			}else{
				S.push_back(C);
			}
		}
	}
  reverse(AA.begin(),AA.end());
            S = AA + S;
	if(rl==true) reverse(S.begin(),S.end());
  
    cout << S <<endl;
  
  
	

}

Measured memory_bytes: 1676
# https://beta.atcoder.jp/contests/abc102/tasks/arc100_a

from statistics import median

if __name__ == '__main__':
    # n = 7
    # a = [1, 1, 1, 1, 2, 3, 4]

    n = int(input())
    a = list(map(int, input().split()))

    d = []

    for i, a_i in enumerate(a):
        diff = int(a_i) - (i + 1)
        d.append(diff)

    m = int(round(median(d)))

    ans = 0
    for d_i in d:
        ans += abs(d_i - m)
    print(ans)


Measured memory_bytes: 27244
from sys import stdin
import sys
import math
from functools import reduce

a,b = [int(x) for x in stdin.readline().rstrip().split()]

c = int(b*10)

for i in range(10):
    if a == int(c*0.08):
        print(c)
        sys.exit()
    c = c + 1

print(-1)


Measured memory_bytes: 9572
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
		if (((g * 10) + b) % 4 == 0) {
			System.out.println("YES");
        }
      	else {
          System.out.println("NO");
        }
	}
}

Measured memory_bytes: 20820
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;

	long long r = 0;
	long long g = 0;
	long long b = 0;

	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'R') r++;
		else if (s[i] == 'G') g++;
		else b++;
	}

	long long all = r * g * b;
	long long sub = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (s[i] == s[j]) continue;
			int k = j * 2 - i;
			if (k >= n || s[k] == s[i] || s[k] == s[j]) continue;
			sub++;
		}
	}

	cout << all - sub << endl;

	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int main(void){
    int A, B ,C;
    cin >> A >> B >> C;
    int i;
    int count=0;
    for(i=0;i<C;i++)
    {
        if(B>=A)
        {
            count ++;
            B = B -A;
        }
        
    }
    cout << count << endl;
    
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return (a % 1000000007);
}

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

ll nCr(ll n,ll r){
  if(r == 1) return n;
  else if(r == 0) return 1;
  else return nCr(n-1,r-1)*n/r;
}

int main(){
  ll n,t; cin >> n >> t; ll ans = 1e10;
  
  rep(i,n){
    ll c,td; cin >> c >> td;
    
    if(td <= t){
      ans = min(ans,c);
    }
    
  }
  
  if(ans == 1e10) cout << "TLE" << endl;
  else cout << ans << endl;
  
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    
    public static List<Integer> P;
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        final int S = scanner.nextInt();
        final int W = scanner.nextInt();
        if(S <= W){
            System.out.println("unsafe");
        }else{
            System.out.println("safe");
        }

    }
}

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

class SegmentTree {
    private int _n;
    private int[] _ar;

    public SegmentTree(int n) {
        _n = 1;
        while (_n < n) _n *= 2;

        _ar = new int[_n * 2];
        for (int i = 0; i < 2 * _n - 1; i++) {
            _ar[i] = int.MaxValue;
        }
    }

    // k ?????????????????????(0-indexed)??? a ????????´
    public void Update(int k, int a) {
        // ????????\???
        k += _n - 1;
        _ar[k] = a;
        // ?????????????????´??°
        while (k > 0) {
            k = (k - 1) / 2;
            _ar[k] = Math.Min(_ar[k * 2 + 1], _ar[k * 2 + 2]);
        }
    }

    // [a, b) ???????°????????±???????
    private int Query(int a, int b, int k, int l, int r) {
        // [a, b) ??¨ [l, r) ??????????????????
        if (r <= a || b <= l) return int.MaxValue;

        // [a, b) ??? [l, r) ????????¨???????????§????????°???????????\?????????
        if (a <= l && r <= b) {
            return _ar[k];
        }
        else {
            // ????????§???????????°???2 ????????????????°????
            int vl = Query(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = Query(a, b, k * 2 + 2, (l + r) / 2, r);
            return Math.Min(vl, vr);
        }
    }

    public int Query(int a, int b) {
        return Query(a, b, 0, 0, _n);
    }
}

class Program {
    static string ReadLine() { return Console.ReadLine(); }
    static int ReadInt() { return int.Parse(ReadLine()); }
    static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return ReadLine().Split(); }

    static void Main() {
        var nq = ReadInts();
        int n = nq[0], q = nq[1];

        var segt = new SegmentTree(n);
        for (int i = 0; i < q; i++) {
            var xs = ReadInts();
            int x = xs[1];
            int y = xs[2];
            if (xs[0] == 0) {
                // Console.WriteLine("Update {0} {1}", x, y);
                segt.Update(x, y);
            }
            else {
                // Console.WriteLine("Query {0} {1}", x, y);
                int min = segt.Query(x, y+1);
                Console.WriteLine(min);
            }
        }
    }
}

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

int main() {
  int X, rest;
  cin >> X;
  int c500, c5;
  c500 = X / 500;
  rest = X - c500 * 500;
  c5 = rest / 5;
  cout << c500 * 1000 + c5 * 5 << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input().rstrip()
T = input().rstrip()

l, r = 1, W
if S[-1] == 'L':
    l += 1
if S[-1] == 'R':
    r -= 1
for i in range(N-1)[::-1]:
    if T[i] == 'L':
        r = min(r+1, W)
    if T[i] == 'R':
        l = max(l-1, 1)

    if S[i] == 'L':
        l += 1
    if S[i] == 'R':
        r -= 1
        
    if l > r:
        print('NO')
        exit()

u, d = 1, H
if S[-1] == 'U':
    u += 1
if S[-1] == 'D':
    d -= 1
for i in range(N-1)[::-1]:
    if T[i] == 'U':
        d = min(d+1, H)
    if T[i] == 'D':
        u = max(u-1, 1)

    if S[i] == 'U':
        u += 1
    if S[i] == 'D':
        d -= 1

    if u > d:
        print('NO')
        exit()

if l <= sc <= r and u <= sr <= d:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 45744
using System;
class abc146_a{
  public static void Main(){
    String str = Console.ReadLine();
    int day;
    switch (str){
      case "SUN":
        day = 7;
        break;
      case "MON":
        day = 6;
        break;
      case "TUE":
        day = 5;
        break;
      case "WED":
        day = 4;
        break;
      case "THU":
        day = 3;
        break;
      case "FRI":
        day = 2;
        break;
      case "SAT":
        day = 1;
        break;
      default:
       day = 0;
       break;
    }
    Console.WriteLine(day);
  }
}


Measured memory_bytes: 13152
A, B = gets.split.map(&:to_i)

def calc(n)
  ans = []
  ans[0] = n % 4 == 1 || n % 4 == 2 ? 1 : 0
  for b in 1..39
    ans[b] = (n / 2 ** b).odd? && n.even? ? 1 : 0
  end 
  ans.reverse.join.to_i(2)
end 

if A == 0
  puts calc(B)
else
  puts calc(A - 1) ^ calc(B)
end

Measured memory_bytes: 1788
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      string[] input = Console.ReadLine().Split();
      int x = int.Parse(input[0]);
      int y = int.Parse(input[1]);
      int z = int.Parse(input[2]);
      
      Console.WriteLine( (x-z)/(y+z) );
      
    }
}


Measured memory_bytes: 27468
#include<bits/stdc++.h>
using namespace std;
#define ll long  long 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;

  
int main()
{
	

     ll n,d;
     cin>>n>>d;
     ll c=0;
     while(n--)
     {
      long double x,y;
      cin>>x>>y;

      long double ans=sqrt(x*x+y*y);
      if(ans<=d)
        c++;
     }
     cout<<c;

return 0;
}




Measured memory_bytes: 3756
#include <stdio.h>
int main (){
    long long int N; 
    long long int total=1;
    
    scanf("%lld",&N);
    long long int A[N]; 
    
    for(int i=0;i<N;i++){
        scanf("%lld", &A[i]);
    }
    for(int j=0;j<N;j++){
        if(A[j] == 0){  
            printf("0"); 
            return 0;
        }
    }
    for(int k=0;k<N;k++){
        if(A[k]<=1000000000000000000/total){
            total = total*A[k];
            
        } else {
            printf("-1");
            return 0;
        }
    }
    printf("%lld\n", total);
    
    
return 0;
}

Measured memory_bytes: 2476
#include <bits/stdc++.h>
 
using namespace std;
 
const int maxn = 1 << 15;
 
namespace math {
	const int mod = 998244353;
 
	int sum(int x, int y) {
		return x + y <= mod ? x + y : x + y - mod;
	}
 
	int product(int x, int y) {
		return 1ll * x * y % mod;
	}
 
	int pow_mod(int x, int n) {
		int y = 1;
		while (n) {
			if (n & 1) y = 1ll * y * x % mod;
			x = 1ll * x * x % mod;
			n >>= 1;
		}
		return y;
	}
 
	int fac[maxn], ifac[maxn], r[maxn];
 
	int C(int n, int m) {
		return m >= 0 && n >= m ? 1ll * fac[n] * ifac[m] % mod * ifac[n - m] % mod : 0;
	}
 
	void pre() {
		int n = maxn - 1;
		fac[0] = 1;
		for (int i = 1; i <= n; ++i) {
			fac[i] = 1ll * fac[i - 1] * i % mod;
		}
		ifac[n] = pow_mod(fac[n], mod - 2);
		for (int i = n; i >= 1; --i) {
			ifac[i - 1] = 1ll * ifac[i] * i % mod;
		}
		for (int i = 0; i < maxn; ++i) {
			for (int j = 1; j < maxn; j <<= 1) {
				(r[i] <<= 1) |= ((i & j) ? 1 : 0);
			}
		}
		return;
	}
 
	const int proot = 3;
 
	void dft(int *a, bool rev = 0) {
		for (int i = 0; i < maxn; ++i) {
			if (r[i] < i) {
				swap(a[i], a[r[i]]);
			}
		}
		for (int l = 2; l <= maxn; l <<= 1) {
			int hl = l >> 1, wn = pow_mod(proot, (mod - 1) / l);
			if (rev) {
				wn = pow_mod(wn, mod - 2);
			}
			for (int i = 0; i < maxn; i += l) {
				int w = 1;
				for (int j = i, k = i | hl; j < (i | hl); ++j, ++k) {
					int x = a[j], y = 1ll * a[k] * w % mod;
					a[j] = (x + y) % mod;
					a[k] = (x + mod - y) % mod;
					w = 1ll * w * wn % mod;
				}
			}
		}
		if (rev) {
			int inv = pow_mod(maxn, mod - 2);
			for (int i = 0; i < maxn; ++i) {
				a[i] = 1ll * a[i] * inv % mod;
			}
		}
		return;
	}
}
 
char a[maxn], b[maxn];
int L, n, m;
int dp[maxn], c[maxn];
 
using namespace math;
 
int main() {
	math::pre();
	scanf("%s", a);
	scanf("%s", b);
	L = strlen(a);
	for (int i = 0; i < L; ++i) {
		if (a[i] == '1') {
			if (b[i] == '1') {
				++m;
			}
			else {
				++n;
			}
		}
	}
	dp[0] = 1;
	for (int j = 0; j <= m; ++j) {
		c[j] = ifac[j + 1];
	}
	for (int i = 1; i <= n; i <<= 1) {
		dft(c);
		if (n & i) {
			dft(dp);
			for (int j = 0; j < maxn; ++j) {
				dp[j] = 1ll * dp[j] * c[j] % mod;
			}
			dft(dp, 1);
			for (int j = (maxn >> 1) - 10; j < maxn; ++j) {
				dp[j] = 0;
			}
		}
		for (int j = 0; j < maxn; ++j) {
			c[j] = 1ll * c[j] * c[j] % mod;
		}
		dft(c, 1);
		for (int j = (maxn >> 1) - 10; j < maxn; ++j) {
			c[j] = 0;
		}
	}
	int ans = 0;
	for (int j = 0; j <= m; ++j) {
		ans = sum(ans, product(dp[j], fac[n + m]));
	}
	ans = product(ans, product(fac[n], fac[m]));
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 896
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N = ri()
W = []
for i in range(N):
	a, b = rl()
	W.append((b, a))
W.sort()

t = 0
for b, a in W:
	t += a
	if t > b:
		print('No')
		exit()
print('Yes')


Measured memory_bytes: 92332
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

ll extGCD(ll a, ll b, ll &x, ll &y){
    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }
    ll g = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return g;
}

ll MOD = 1000000007;

vector<ll> mfact(1,1);

ll minv(ll a){
    ll x;ll y;
    extGCD(a, MOD, x, y);
    if(x<0)x+=MOD;
    return x;
}
ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0) res += m;
  return res;
}


ll mpow(ll a,ll b){
    ll res = 1;
    while(b >= 1){
        if(b%2==1)res=(res*a)%MOD;
        b/=2;
        a = (a*a)%MOD;
    }
    return res;
}

ll mfactorial(ll a){
    if(mfact.size()-1 >= a)return mfact[a];
    for(ll i = mfact.size();i<=a;i++){
        mfact.push_back((i * mfact[i-1])%MOD);
    }
    return mfact[a];
}

ll mcomb(ll n, ll r){
    return (((mfactorial(n) * minv(mfactorial(r)))%MOD) * minv(mfactorial(n-r)))%MOD;
}


int main(){
    ll n,k;
    cin>>n>>k;
    ll ans = 1; // 最初の状態（k>=3より常に再現可能）
    for(ll i = min(n-1,k);i > 0;i--){
        ans = (ans + (mcomb(n - 1, i) * mcomb(n,i)) % MOD) % MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,n,a[100001],sum=0;
	cin>>h>>n;
	for(int i=0;i<n;i++){
	cin>>a[n];
	sum+=a[n];
	}
	sum>=h? cout<<"Yes":cout<<"No";
	return 0;
}


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

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

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

int main()
{
	int n,mn,mx;
	while(cin >> n >> mn >> mx and n!=0)
	{
		vector<int> p(n);
		for(int i=0;i<n;i++)
			cin >> p[i];
		sort(p.begin(),p.end());
		//reverse(p.begin(),p.end());
		int ans=0;
		int tmp=0;
		for(int i=1;i<n;i++)
		{
			if(mn<=n-i and n-i<=mx)
			{
				if(tmp<p[i]-p[i-1]) {
					ans=n-i;
					tmp = p[i] - p[i-1];
				}
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3044
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

void process();

int main(){
    LL A,B;    
    int x,y,temp;
    cin >> A >> B;
    if( A > B){
        x = A;
        y = B;
    }else{
        x = B;
        y = A;
    }
    while(x % y != 0){
        temp = x % y;
        x = y;
        y = temp;
    }
    //cout << x;
    //cout << x << endl;
    cout << A * B / y << endl;
    return 0;
}

void process(){
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pci pair<char, int>
#define pic pair<int, char>
#define plvl pair<long long, vector<long long> >
#define pcvc pair<char, vector<char> >


using namespace std;

const int mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	if(b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

template <typename T>
void show1(vector<T> dp) {
	for(auto d : dp) {
		cout << d << " ";
	}
	cout << endl;
}

template <typename T>
void show2(vector<vector<T> > dp) {
	for(auto d : dp) {
		for(auto dd : d) {
			cout << dd << " ";
		}
		cout << endl;
	}
}

void executeCode() {
	for(int i = 1 ; i <= 5 ; i++) {
		int x;
		cin >> x;
		if(x == 0) {
			cout << i << endl;
			return;
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int tt = 1;
	// cin >> tt;
	while(tt--) {
		executeCode();	
	}
	return 0;
}

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

int main() {
    int k,n;
    cin >> n >> k;
    char S[n];
    cin >> S;
    if(S[k-1]=='A'){
    S[k-1]='a';
    }
    if(S[k-1]=='B'){
    S[k-1]='b';
    }
    if(S[k-1]=='C'){
    S[k-1]='c';
    }
    cout << S << endl;   
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
#define per(i,a,b) for(ll i =a ;i >= b;i--)
using namespace std;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
 


int main()
{
	//ifstream cin("input.txt");
	string s;
	cin>>s;
	ll n = s.length();

	int i = 0, cnt = 0;
	int stk = 0, zstk = 0;
	while(i < n - 1)
	{
		if((s[i] == '1' && s[i+1] == '0' )||(s[i] == '0' && s[i+1] == '1'))
		{
			cnt +=1;
			i += 2;
		}
		else if(s[i] == '1' && s[i+1] == '1')
		{
			if(zstk > 0)
			{
				zstk--;
				cnt++;
			}
			else
				stk+=1;
			i++;
		}
		else if(s[i] == '0' && s[i+1] == '0')
		{
			if(stk > 0){
				stk--;
				cnt ++;
			}
			else
				zstk ++;
			i++;
		}
	}
	if(s[i] == '1' && zstk > 0 ||(s[i] == '0' && stk > 0))
		cnt++;

	cout<<cnt * 2;
	
}


Measured memory_bytes: 3752