akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <bitset>
#include <tuple>
#include <stack>
#include <utility>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> x(N);
    for(int i=0; i<N; i++) cin >> x[i];
    int ans = 0;
    for(int i=0; i<N; i++){
        ans += 2*min(x[i], K-x[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

s = input()

for si in s[0::2]:
  if si not in ["R", "U", "D"]:
    print("No")
    sys.exit(0)

for si in s[1::2]:
  if si not in ["L", "U", "D"]:
    print("No")
    sys.exit(0)

print("Yes")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <set>

class Dictionary {

public:
    void insert(std::string word) {
        strList.insert(word);
    }

    void find(std::string word) {
        auto elemItr = strList.find(word);
        if (elemItr == strList.cend()) {
            std::cout << "no";
        } else {
            std::cout << "yes";
        }
        std::cout << std::endl;
    }

private:
    std::set<std::string> strList;

};

void useDictionary(Dictionary &dictionary, std::string command, std::string word) {
    if (command == "insert") {
        dictionary.insert(word);
    } else if (command == "find") {
        dictionary.find(word);
    }
}

int main () {

    std::size_t n;
    std::cin >> n;

    Dictionary dictionary;
    while (n--) {
        std::string command, word;
        std::cin >> command >> word;
        useDictionary(dictionary, command, word);
    }

    return 0;

}

Measured memory_bytes: 32048
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX(a,b) (a > b) ? a : b
#define MIN(a,b) (a < b) ? a : b
const int inf = 1000000000; // 10^9

int main(){
   char s[100000];scanf("%s",s);
   for(int i = 0;i < strlen(s);i+=2)printf("%c",s[i]);
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a=1,n,k,i;
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++){
  if(a*2>a+k)a+=k;
  else a*=2;
  }
  printf("%d",a);
  return 0;

}

Measured memory_bytes: 128
// 1027
#include <stdio.h>

int main()
{
    int i, n, a, sum;

    while (1) {
        scanf("%d", &n);
        if (n == 0)
            break;
        sum = 0;
        for (i = 0; i < (n - 1) * n / 2; i++) {
            scanf("%d", &a);
            sum += a;
        }
        printf("%d\n", sum / (n - 1));
    }
    return 0;
}

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

int main(){
    int A, B;
    cin >> A >> B;

    int cnt = 0;
    for(int i=A; i<B+1; i++){
        if( (i/10000 == i%10) && ((i-(i/10000)*10000)/1000 == (i/10)%10) ){
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

int take() {
    int n;
    scanf("%d",&n);
    return n;

}
double ttake() {
    double n;
    scanf("%lf",&n);
    return n;
}
ll takes() {
    ll n;
    scanf("%lld",&n);
    return n;

}
#define M 3001
#define Int take()
#define Dnt ttake()
#define LL takes()

#define fr(n) for(int i=1;i<=n;i++)
#define rfr(n) for(int i=n;i>=1;i--)
int cas;
#define print printf("Case %d:",++cas)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mk  make_pair
#define fill(x,v) memset(x,v,sizeof x)
using namespace std;

bool approximatelyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool essentiallyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyGreaterThan(float a, float b, float epsilon) {
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyLessThan(float a, float b, float epsilon) {
    return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
//////////////////////////////////////////


int main(){
    int n=Int,a=Int,b=Int;
    printf("%d\n",min(n*a,b));

    return 0;
}


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

using namespace std;

int check(string A, int left, int right){
    int flag = 1;
    for (int i=left; i<right; i++){
        if (A[i] != A[right-1-i]) flag = 0;
    }
    return flag;
}

int main(){
    string A;
    int n;
    cin >> A;
    n = (int)(A.length());
    if (check(A, 0, n) && check(A, 0, (n-1)/2) && check(A, (n+3)/2, n)) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline

flagset = ['not increase', 'flat', 'not decrease']

def main():
    N = int(readline())
    A = list(map(int, readline().split()))

    cnt = 0
    A0 = A[0]
    flag = flagset[1]
    for i in range(N-1):
        Ai = A[i]
        Ai1 = A[i+1]
        if flag == 'flat':
            if Ai < Ai1:
                flag = 'not decrease'
            elif Ai > Ai1:
                flag = 'not increase'
            elif Ai == Ai1:
                flag = 'flat'
            else:
                cnt += 1
        elif flag == 'not decrease':
            if Ai <= Ai1:
                continue
            else:
                flag = 'flat'
                cnt += 1
        else:
            if Ai >= Ai1:
                continue
            else:
                flag = 'flat'
                cnt += 1
    cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14168
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm> // sort
#include <math.h>

#define DEBUG 0

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll mod = 1000000007;
static const ll INF = 1000000000000000000LL;
                    //999999997000000003
                    //1000000000000000000

using namespace std;

//2-1-4-7-5
//  |
//  3-6

//これが想像できていない
//1-2-3-7
//  |
//  5-6-4

//d[0][N-1]の距離をはかる(閉路がないため、一通り)
//先行の方が先に使える
//あまりの数

int main(){
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;

    vector <vector <int>> G(N);

    REP(i,N-1)
    {
        int a, b;
        cin >> a >> b;
        --a;--b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    //0からの最短経路と最短経路でNを使用するか
    vector <int> d(N, N + 100);
    vector <int> prev(N);
    vector <int> guard(N);

    d[0] = 0;

    //0からN-1を経由して到達できる箇所を調べる
    queue <int> que;
    que.push(0);
    int from, to;
    while(!que.empty())
    {
        from = que.front();
        que.pop();

        for(int i = 0; i < G[from].size(); ++i)
        {
            to = G[from][i];
            if(d[from] + 1 < d[to])
            {
                d[to] = d[from] + 1;
                prev[to] = from;
                que.push(to);
            }
        }
    }

    //snukeは Nから1に向かって、(d[N-1] - 1) / 2回移動できる
    int pos = N-1;
    guard[pos] = 1;
    guard[0] = 1;
    REP(i, (d[N-1] - 1) / 2)
    {
        pos = prev[pos];
        guard[pos] = 1;
    }

    int fen = 0;
    que.push(0);
    while(!que.empty())
    {
        from = que.front();
        que.pop();

        for(int i = 0; i < G[from].size(); ++i)
        {
            to = G[from][i];
            if(guard[to] == 1)continue;
            guard[to] = 1;
            ++fen;
            que.push(to);
        }
    }

    //fen 塗れるマス N - 2 - fen 
    string res;
    //奇数個の場合
    if( fen > N - 2 - fen)
    {   
        res = "Fennec";
    }
    else
    {
        res = "Snuke";
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <cmath>

using namespace std;

int main() {
    size_t n, k;
    cin >> n >> k;
    vector<size_t> h(n, 0);
    for (size_t i = 0; i < n; ++i)
        cin >> h[i];
    size_t c = 0;
    if (k < n) {
        sort(begin(h), end(h), greater<size_t>());
        auto b = begin(h) + k;
        auto e = end(h);
        for (; b != e; ++b)
            c += *b;
    }
    cout << c << endl;
    return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long int ll;

int N;
int P[200005];
int ans;

int main(){
    cin>>N;
    for(int i=0;i<N;++i)cin>>P[i];
    int mi=P[0];
    for(int i=1;i<N;++i){
        if(mi>=P[i])ans++;
        mi=min(mi,P[i]);
    }
    cout<<ans+1<<endl;
}

Measured memory_bytes: 1024
n = int(input())
xs = [(i, int(v)) for i, v in enumerate(input().split())]

tmp = sorted(xs, key=lambda x: x[1])

a = tmp[n // 2 - 1][1]
b = tmp[n // 2][1]

ans = [0]*n

for i,v in tmp[:n//2]:
    ans[i] = b
    
for i, v in tmp[n//2:]:
    ans[i] = a

for i in ans:
    print(i)


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int a, b;
  cin >> a >> b;
  cout << max({a+b, a-b, a*b});
}

int main()
{
  fastio;
  solve();

  return 0;
}


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

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	string s;
	cin >> s;
	int c = 0;
	for(int i = 0; i < 16; ++i){
		c += s[i] != "CODEFESTIVAL2016"[i];
	}
	cout << c << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


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

int main(){
  
  int i,j,r,c;
  int num[101][101]={} ;
  
  cin >>r >>c;
  
  for(i=0;i<r;i++)for(j=0;j<c;j++)cin >>num[i][j];
  
  for(i=0;i<r;i++){
    
    for(j=0;j<c;j++){
      num[i][c] += num[i][j];
    }

  }	
  
  for(i=0;i<c;i++){
    
    for(j=0;j<r;j++){
      
      num[r][i] += num[j][i] ;
    }
    num[r][c] += num[r][i];
  }
  
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      
      cout<<num[i][j] <<" " ;
    }
    cout<<num[i][c] <<"\n" ;
  }
  for(i=0;i<c;i++){
    
    cout <<num[r][i] <<" " ; 
  }
  cout<<num[r][c];
  cout <<"\n" ;

  return 0;
}

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

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

int main(){
	int N;
	cin >> N;
	unsigned long int cnt=0;
	
	repn(i,N){
		if(i%3!=0 && i%5!=0)cnt+=i	;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}

int main() {
  ll N;
  cin >> N;
  map<ll, ll> mp;
  FOR(i, 1, N + 1) {
    auto primes = prime_factor(i);
    for (auto x : primes) {
      mp[x.first] += x.second;
    }
  }

  map<ll, ll> cnt;
  for (auto x : mp) {
    ll tmp = x.second;
    if (tmp >= 74) {
      cnt[75]++;
    }
    if (tmp >= 24) {
      cnt[25]++;
    }
    if (tmp >= 14) {
      cnt[15]++;
    }
    if (tmp >= 4) {
      cnt[5]++;
    }
    if (tmp >= 2) {
      cnt[3]++;
    }
  }

  ll ans = 0;
  ans += cnt[75];
  ans += cnt[25] * (cnt[3] - 1);
  ans += cnt[15] * (cnt[5] - 1);
  ans += (cnt[3] - 2) * cnt[5] * (cnt[5] - 1) / 2;
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll h;cin>>h;
    ll exp=1;
    while(h){
        ans+=exp;
        h/=2;
        exp*=2;
    }
    cout<<ans<<endl;    
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a < b)
            System.out.println("a < b");
        if (a > b)
            System.out.println("a > b");
        if (a == b)
            System.out.println("a == b");

        sc.close();
    }
}


Measured memory_bytes: 26136
use std::io::stdin;

fn main() {
    let mut n = String::new();
    stdin().read_line(&mut n).unwrap();
    let mut hs = String::new();
    stdin().read_line(&mut hs).unwrap();

    let hs: Vec<usize> = hs.trim().split_whitespace().flat_map(str::parse).collect();
    let mut max_h = hs[0];
    let mut result = 1;
    for h in hs.into_iter().skip(1) {
        if max_h <= h {
            result += 1;
            max_h = h;
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;cin>>s;int m=0;
    for(int i=0;i<s.length()-1;i++)
        if(s[i]!=s[i+1])m++;
        //cout<<m<<endl;
    if(m==3)cout<<"Good";else cout<<"Bad";
}


Measured memory_bytes: 256
nums = input()
n = 4


def calc(i, f, sum):
    if i == n-1:
        if sum == 7:
            print(f+'=7')
            exit()

    else:
        calc(i+1, f + '-' + nums[i+1], sum - int(nums[i+1]))
        calc(i+1, f + '+' + nums[i+1], sum + int(nums[i+1]))


calc(0, nums[0], int(nums[0]))


Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int n;
    cin >> n;
    int res = 800 * n - 200 *( n / 15);
    cout << res << ln;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int x[10000] ,i = 1,j ;
	scanf("%d",&x);
	while(x[i-1] != 0){
		scanf("%d",&x[i]);
		i++;
	}
	for(j = 1 ;j < i ;j++){
	printf("Case %d: %d\n",j,x[j-1]);
	}
	return 0;
}

Measured memory_bytes: 640
N, Q = map(int, input().split())
s = '#' + input() + '#'
#room[0], [1~N], [N+1]と考える
#文字を取り出すとき:[1~N]
T = [] #Title[0～Q-1]
D = [] #Direction[0～Q-1] R:1, L:-1で表現
for t, d in [input().split() for _ in range(Q)]:
  T.append(t)
  D.append(-1 if d=='L' else 1)

#そのゴーレムがどちらかの端にたどり着けるかの関数
#True, Falseを返す
def canReachEnd(iL, dir):
  #iLは初期マス(1~N), dirは方向(L:-1, R:1)
  
  #nowL:今いるマスの位置
  nowL = iL
  #nowt:今いるマスに書いてある文字
  nowt = s[iL]
  for t, d in zip(T, D):
    if t == nowt:
      #左に動いても右に動いてもdを足せばok
      #端に落ちたら文字が'#'なので気にしない
      nowL += d
      nowt = s[nowL]
      
  if dir == 1 and nowL == N+1:
    return True
  elif dir == -1 and nowL == 0:
    return True
  else: return False
#たどり着けるかの関数終わり

#ここから二分探索で2つの「境目」を探す

#(1)「iは左に辿り着くがi+1は辿り着かない」iを探す
#何も辿り着かない場合はi=0とする？
#全部辿り着く場合はi=Nとする？
#leftとrightが隣接したときのleftを答えとする？
##すると、ありえるleftの範囲は0~N
left = 0
right = N+1
while right > left+1:
  check = (left+right)//2
  
  if canReachEnd(check, -1):left = check
  else: right = check
#答えを代入
leftborder = left


#(2)「jは右に辿り着くがj-1は辿り着かない」jを探す
#何も辿り着かない場合はj=N+1とする？
#全部辿り着く場合はj=1とする？
#leftとrightが隣接したときのrightを答えとする？
##すると、ありえるrightの範囲はleftborder+1~N+1
left = leftborder #(1)で左に辿り着くと分かった部分は省く
right = N+1
while right > left+1:
  check = (left+right)//2
  
  if canReachEnd(check, 1):right = check
  else: left = check
#答えを代入
rightborder = right

#二分探索終わり

#lbには左に辿り着く限界,rbには右に辿り着く限界が格納
#1~lbまでは全部左端に落ちる lb==0なら0
#rb~Nまでは全部右端に落ちる rb==N+1なら0

dropcnt = 0
dropcnt += leftborder
dropcnt += (N-(rightborder-1))
print(N-dropcnt)

Measured memory_bytes: 42588
n = gets.to_i
a = gets.split.map(&:to_i).sort
sums = Array.new(n+1,0)
ans = 1
for i in 0..n-1
    sums[i+1] = sums[i]+a[i]
end
(n-1).downto(0) do |i|
    if sums[i]*2 >= a[i]
        ans = n-i+1 if ans < n-i+1
    else
        break
    end
end
puts ans

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

 
int main(){
  int x, y;
  cin >> x >> y;
  int ans = x + y/2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
#define ll long long
#define     f           first
#define     s           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<long long,long long>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)

vector<ll> adj[N];
bool visited[N];
int main()
{
    string s;
    cin>>s;
    ll n=s.size();
    if(s[n-1]=='s')
        s+="es";
    else
        s+="s";
cout<<s<<endl;
 //getch();
    return 0;
}

Measured memory_bytes: 8316
#include <iostream>
#include <unordered_map>

using namespace std;

int main() {
    int n;
    string name;

    unordered_map<string, int> count;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> name;
        count[name] += 1;
    }

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> name;
        count[name] -= 1;
    }

    int max_count = 0;
    for (pair<string, int> pair: count) {
        max_count = max(pair.second, max_count);
    }

    cout << max_count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

const int INF = 1 << 30;

int main() {
	int A, B;
	string str;
	int cnt = 0;

	cin >> A >> B;
	cin >> str;

	for (int i = 0; i < str.length(); i++) {
		if (str[i] == '-')cnt++;
	}

	if (cnt < 2 && str.length() == A + B + 1 && str[A] == '-')cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
int main() {
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int a;
	cin>>a;
	if(a==7 || a==5 || a==3)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
    return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

const int MAXN = 20000010;

vl fact(MAXN);
vl rfact(MAXN);

ll mod_pow(ll x, ll p, ll M = MOD) {
	ll a = 1;
	while (p) {
		if (p % 2)
			a = a*x%M;
		x = x*x%M;
		p /= 2;
	}
	return a;
}

ll mod_inverse(ll a, ll M = MOD) {
	return mod_pow(a, M - 2, M);
}

void set_fact(ll n, ll M = MOD) {
	fact[0] = fact[1] = rfact[0] = rfact[1] = 1;
	for (ll i = 2; i <= n; i++) {
		fact[i] = i * fact[i - 1] % M;
		//rfact[i] = mod_inverse(fact[i], M);
	}
}

//http://drken1215.hatenablog.com/entry/2018/06/08/210000
//nが大きくfactが計算できないときのほかの計算方法について書いてある
ll nCr(ll n, ll r, ll M = MOD) {
  if (r > n) return 0;
  ll ret = fact[n];
  ret = (ret*rfact[r]) % M;
  ret = (ret*rfact[n - r]) % M;
  return ret;
}



int main() {
  set_fact(20000005);
  //set_fact(20005);
  ll h, w, k;
  cin >> h >> w >> k;
  ll n = fact[h + w] * mod_inverse(fact[h + w - k]) % MOD;
  ll ans = 0;
  ll inv = mod_inverse((h+w) * (h + w - 1) % MOD);
  ans += k * n % MOD;
  for (ll t = 1; t <= k; t++) {
    (ans += (k - t + 1) * n % MOD) %= MOD;
    (ans += 2 * (t - 1) % MOD * (k - t + 1) % MOD * inv % MOD * h % MOD * w % MOD * n % MOD) %= MOD;
  }
  ans %= MOD;
  cout << ans << endl;
}
  
  


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

long long Combination(int n, int r)
{
  if (n < 0 || r < 0 || r > n) return 0; //不正な引数

  if (n - r < r) r = n - r;
  if (r == 0)    return 1;
  if (r == 1)    return n;

  vector<int> numerator(r);
  vector<int> denominator(r);

  for (int k = 0; k < r; k++)
  {
    numerator[k] = n - r + k + 1;
    denominator[k] = k + 1;
  }

  for (int p = 2; p <= r; p++)
  {
    int pivot = denominator[p - 1];
    if (pivot > 1)
    {
      int offset = (n - r) % p;
      for (int k = p - 1; k < r; k += p)
      {
        numerator[k - offset] /= pivot;
        denominator[k] /= pivot;
      }
    }
  }

  long long result = 1;
  for (int k = 0; k < r; k++)
  {
    if (numerator[k] > 1)
      result *= numerator[k];
  }

  return result;
}

int main(){
  int N;
  scanf("%d",&N);
  string si;
  unordered_map<string,int> s(N);
  for (int i = 0; i < N; i++){
    cin >> si;
    sort(si.begin(), si.end());
    auto it1 = s.find(si);
    if (it1 == s.end()){
      s.emplace(si,0);
    }
    else{
      s[si]++;
    }
  }
  long long sum = 0;
  for (auto i : s){
    sum += Combination(i.second+1, 2);
  }

  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 10496
#pragma GCC optimize (2)
#include<bits/stdc++.h>
using namespace std;
int arr[100005];
int main()
{
	int a,b,c,k;
	int t=0;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	while(a>=b)
	{
		b=b*2;
		t++;
	}
	while(b>=c)
	{
		c=c*2;
		t++;
	}
	if(t>k)
	printf("No\n");
	else
	printf("Yes\n");
}

Measured memory_bytes: 3760
import numpy as np
N, S = map(int, input().split())
A = np.array(list(map(int, input().split())))
P = 998244353
table = np.zeros((N, S+1), dtype=int)
table[0, 0] = 2
if A[0] <= S:
  table[0, A[0]] = 1
for i in range(1, N):
  Ai = A[i]
  table[i] += 2*table[i-1]
  if Ai <= S:
    table[i][Ai:] += table[i-1][:S-Ai+1]
  table[i] = table[i]%P
print(table[N-1][S])




Measured memory_bytes: 97460
n = int(input())
a = list(map(int, input().split()))
a.append(99999)
dp = [0] * (n+1)
dp[0] = 0

for i in range(n):
    # print(dp)
    if (i > 0):
        dp[i+1] = min(dp[i] + abs(a[i]-a[i+1]),
                      dp[i-1] + abs(a[i-1]-a[i+1]) )
    else:
        dp[i+1] = dp[i] + abs(a[i]-a[i+1])

print(dp[n-1])


Measured memory_bytes: 13976
#include <iostream>
#include <vector>
#include <limits>

int merge(std::vector<int> & list, int left, int mid, int right) {
    constexpr int MAX = std::numeric_limits<int>::max();

    std::vector<int> l_list, r_list;
    l_list.reserve(mid - left + 1);
    for (int i = left; i < mid; ++i) {
        l_list.emplace_back(list.at(i));
    }
    l_list.emplace_back(MAX);
    l_list.reserve(right - mid + 1);
    for (int i = mid; i < right; ++i) {
        r_list.emplace_back(list.at(i));
    }
    r_list.emplace_back(MAX);

    int left_id = 0;
    int right_id = 0;
    int count = 0;
    for (int i = left; i < right; ++i) {
        ++count;
        if (l_list.at(left_id) <= r_list.at(right_id)) {
            list.at(i) = l_list.at(left_id);
            ++left_id;
        } else {
            list.at(i) = r_list.at(right_id);
            ++right_id;
        }
    }
    return count;
}

int mergeSort(std::vector<int> & list, int left, int right) {
    if (left + 1 < right) {
        int count = 0;
        const int mid = (left + right) / 2;
        count += mergeSort(list, left, mid);
        count += mergeSort(list, mid, right);
        count += merge(list, left, mid, right);
        return count;
    }
    return 0;
}

int main() {

    int n;
    std::cin >> n;

    std::vector<int> S;
    S.reserve(n);
    while (n--) {
        int t;
        std::cin >> t;
        S.emplace_back(t);
    }

    int count = mergeSort(S, 0, S.size());

    std::cout << S.front();
    const auto endItr = S.cend();
    for (auto itr = S.cbegin() + 1; itr != endItr; ++itr) {
        std::cout << " " << *itr;
    }
    std::cout << std::endl;
    std::cout << count << std::endl;

    return 0;

}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> picture(H);
  for (int i = 0; i < H; i++) cin >> picture[i];
  for (int i = 0; i < W+2; i++) cout << '#';
  cout << endl;
  for (int i = 0; i < H; i++) cout << '#' << picture[i] << '#' << endl;
  for (int i = 0; i < W+2; i++) cout << '#';
  cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const int INF=1e7;

LL cx[100001],cy[100001];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    LL x[n],y[m];
    for(int i=0;i<n;i++) cin >> x[i];
    for(int i=0;i<m;i++) cin >> y[i];
    sort(x,x+n);
    sort(y,y+m);
    for(LL i=1;i<=100000;i++){
        cx[i]=i*(n-i)%mod;
        cy[i]=i*(m-i)%mod;
    }
    LL sx=0,sy=0;
    for(int i=0;i<n-1;i++){
        sx+=(x[i+1]-x[i])%mod*cx[i+1]%mod;

        sx%=mod;
    }
    for(int i=0;i<m-1;i++){
        sy+=(y[i+1]-y[i])%mod*cy[i+1]%mod;
        sy%=mod;
    }
    cout << sx*sy%mod << endl;
    return 0;
}

Measured memory_bytes: 3456
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		int p[] = new int[N];

		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
		}
		Arrays.sort(p);

		int cnt1 = 0;
		int cnt2 = 0;
		int cnt3 = 0;

		int s1 = 0;
		int s2 = 0;
		int s3 = 0;

		for (int i = 0; i < N; i++) {
			if (p[i] <= A) {
				cnt1++;
			} else {
				s1 = i;
				break;
			}
		}
		if(cnt1 == 0) {
			System.out.println(0);
			return;
		}
		for (int i = s1; i < N; i++) {
			if (p[i] <= B) {
				cnt2++;
			} else {
				cnt3++;
			}
		}
		if(cnt2 == 0 || cnt3 ==0) {
			System.out.println(0);
			return;
		}

		int ans = Math.min(cnt1, cnt2);
		ans = Math.min(ans, cnt3);
		System.out.println(ans);

	}
}


Measured memory_bytes: 21844
from bisect import bisect_left, bisect, insort

def main():
    n = int(input())
    a = list(map(int, input().split()))
    h_plus_i = [ai+i for i, ai in enumerate(a, 1)]
    h_minus_i = [ai-i for i, ai in enumerate(a, 1)]
    s_h_plus_i = list(sorted(h_plus_i))
    s_h_minus_i = list(sorted(h_minus_i))
    ans = 0
    for hpi, hmi in zip(h_plus_i, h_minus_i):
        i1 = bisect_left(s_h_minus_i, -hpi)
        i2 = bisect_left(s_h_plus_i, -hmi)
        if (i1 < n and s_h_minus_i[i1] == -hpi):
            ans += bisect_left(s_h_minus_i, -hpi+1)-i1
        if (i2 < n and s_h_plus_i[i2] == -hmi):
            ans += bisect_left(s_h_plus_i, -hmi+1)-i2
            
    print(ans//2)

if __name__ == "__main__":
    main()


Measured memory_bytes: 37256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int c = s.nextInt();
		int k = s.nextInt();
		int ans = 0, count = 0;
		int curr = Integer.MIN_VALUE;
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = s.nextInt();
		}
		Arrays.sort(arr);
		for (int i = 0; i < n; i++) {
			if (curr + k < arr[i] || count >= c) {
				curr = arr[i];
				count = 1;
				ans++;
			}
			else{
				count++;
			}
			
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 50848
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
using pii = pair<i32, i32>;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
using vpii = vector<pii>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;
using vvf80 = vector<vf80>;

template<typename T, typename S> bool amax(T &x, S y) { if (x < y) { x = y; return 1; } return 0; }
template<typename T, typename S> bool amin(T &x, S y) { if (y < x) { x = y; return 1; } return 0; }

char board[110][110];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cerr << fixed << setprecision(16);
  int A, B;
  cin >> A >> B;
  rep(i, 100) rep(j, 100) {
    if (i < 50)
      board[i][j] = '#';
    else
      board[i][j] = '.';
  }
  rep(i, A - 1) {
    int y = ((i * 2) / 100) * 2;
    int x = (i * 2) % 100;
    board[y][x] = '.';
  }
  rep(i, B - 1) {
    int y = 99 - ((i * 2) / 100) * 2;
    int x = (i * 2) % 100;
    board[y][x] = '#';
  }
  cout << 100 << " " << 100 << endl;
  rep(i, 100) {
    rep(j, 100) {
      if (j == 100 - 1) {
        cout << board[i][j] << endl;
      } else {
        cout << board[i][j];
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 1e3+10;
const int M = 2e4+10;
/*=================================================================================*/

struct node {
   int w, v, s;
}a[N];
ll n, dp[M], ans;

bool cmp(node a, node b) {
   return a.w+a.s < b.w+b.s;
}

int main() {
   cin>>n;
   for1(i, n) scanf("%d %d %d", &a[i].w, &a[i].s, &a[i].v);
   sort(a+1, a+1+n, cmp);

   for1(i, n) for(int j = M-10; j >= a[i].w; --j) {
      if(a[i].s + a[i].w >= j) dp[j] = max(dp[j], dp[j-a[i].w] + a[i].v);
   }

   for1(i, M) ans = max(ans, dp[i]);
   cout<<ans<<endl;
}

Measured memory_bytes: 3808
#include<stdio.h>
#include<stdlib.h>
#define MAX 1000000
#define NIL -1

struct Node{
  int parent;
  int left;
  int right;
};
struct Node A[MAX];
int n,B[MAX],C[MAX];

int getSibling(int s){
  if(A[s].parent==NIL)return NIL;
  if(A[A[s].parent].left!=s&&A[A[s].parent].left!=NIL)return A[A[s].parent].left;
  if(A[A[s].parent].right!=s&&A[A[s].parent].right!=NIL)return A[A[s].parent].right;
 return NIL;
}
 
int setHeight(int x){
  int h1=0,h2=0;
  if(A[x].left!=NIL) h1=setHeight(A[x].left)+1;
  if(A[x].right!=NIL) h2=setHeight(A[x].right)+1;
  return C[x]=(h1>h2?h1:h2);
}
 

 void setDepth(int x,int y){
  if(x==NIL)return;
  B[x]=y;
  setDepth(A[x].left,y+1);
  setDepth(A[x].right,y+1);
}
 
void print(int x){
  int i,c;
  printf("node %d: ",x);
  printf("parent = %d, ",A[x].parent);
  printf("sibling = %d, ",getSibling(x));
  
  int deg=0;
  if(A[x].left!=NIL)deg++;
  if(A[x].right!=NIL)deg++;
  
  printf("degree = %d, ",deg);
  printf("depth = %d, ",B[x]);
  printf("height = %d, ",C[x]);
 
  if(A[x].parent==NIL)printf("root\n");
  else if(A[x].left==NIL&&A[x].right==NIL) printf("leaf\n");
  else  printf("internal node\n");
}
 
int main(){
 
  int x,y,z,root=0,i;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    A[i].parent=NIL;
  }
 
  for(i=0;i<n;i++){
     scanf("%d",&x);
     scanf("%d",&y);
     scanf("%d",&z);
     A[x].left=y;
     A[x].right=z;
     if(y!=NIL)A[y].parent=x;
     if(z!=NIL)A[z].parent=x;
  }
  for(i=0;i<n;i++){
    if(A[i].parent==NIL)root=i;
  }
 
  setDepth(root,0);
  setHeight(root);
  for(i=0;i<n;i++)print(i);
 
  return 0;
}



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


int* mallocint(int si)
{
    return (int*) malloc(si * sizeof(int));
}

int* inputint(int n)
{
    int *ans = mallocint(n);
    for( int i = 0; i < n; i++ ) cin >> ans[i];
    return ans;
}

int main()
{
    int n;

    cin >> n;
    int *a = inputint(n + 1);

    long long *rl = new long long[n + 1];
    long long *lr = new long long[n + 1];


    lr[n] = a[n];
    for( int i = n - 1; i >= 0; i-- )
    {
        lr[i] = lr[ i + 1 ] + a[i];
    }

    long long ans = 1;
    long long pre = 1;
    for( int i = 1; i <= n; i++ )
    {
        pre = min(lr[i], (pre - a[i - 1]) * 2 );
        if( pre <= 0 )
        {
            cout << -1;
            return 0;
        }
        ans += pre;
    }
    if( pre != a[n] ) ans = -1;
    cout << ans;
   return 0;    
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int X; cin >> X;
    vector<int> table(1010,0);
    table[1] = 1;
    FOR(i,2,X){
        int num = i;
        while(num*i<=X){
            num *= i;
            table[num] = 1;
        }
    }

    REPR(i,X){
        if(table[i] == 1){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3568
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)

left = 1
right = A[0]
while int(left) != int(right):
    mid = (left + right) / 2
    k = sum(int(a / mid) if mid < a else 0 for a in A)
    if k <= K:
        if right == mid:
            break
        right = mid
    else:
        if left == mid:
            break
        left = mid
print(math.ceil(left))

Measured memory_bytes: 31036
import java.util.Scanner;

public class Main {
	public static void main(String [] args){
		Scanner scan = new Scanner(System.in);
		
		while(true){
			
			int a = scan.nextInt();
			char op = scan.next().charAt(0);
			int b = scan.nextInt();
			
			if(op == '?'){
				break;
			}
			if(op == '+'){
				System.out.println(a+b);
			}
			if(op == '-'){
				System.out.println(a-b);
			}
			if(op == '*'){
				System.out.println(a*b);
			}
			if(op == '/'){
				System.out.println(a/b);
			}
		}
	}
}

Measured memory_bytes: 18032
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;
ll gcd(ll a, ll b){if(b==0) return a; return gcd(b, a%b);}


const int INF=1001001001;

bool func(ll x){
    bool san=false;
    bool nana=false;
    bool go=false;
    while(x>0){
        ll n=x%10;
        if(n==3) san=true;
        if(n==5) go=true;
        if(n==7) nana=true;
        x/=10;
    }
    return san&&go&&nana;
}

int main(){
    fast_io

   ll n;
   cin>>n;

   stack<ll> stk;
   stk.push(0);
   int ans=0;
   while(!stk.empty()){
       ll x=stk.top(); stk.pop();
       if(x*10+3<=n) stk.push(x*10+3);
       if(10*x+5<=n) stk.push(x*10+5);
       if(x*10+7<=n) stk.push(x*10+7);
       if(func(x)){
           ans++;
       }
   }

   cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>

#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;

ll factorial_mod(ll n, ll m) {

  ll num = 1 % m;

  for(int i = n; i >= 1; i--){
    num = (num * i) % m;
  }
  
  return num;
}

ll pow_mod(ll a, ll n, ll m) {

  ll res = 1;

  while (n > 0) {
    if (n & 1) res = (res * a) % m;
    a = (a * a) % m;
    n = n >> 1;
  }

  return res;

}


int main() {

  // -----------------------------
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  // input
  int X, Y;
  cin >> X >> Y;

  
  // -----------------------------

  // Knightの飛べない点
  if ( (X+Y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }

  // y = 2x より上, あるいはy = x/2 より下の領域にも飛べない
  if ( Y > 2 * X || Y < X/2) {
    cout << 0 << endl;
    return 0;
  }
  

  ll m = 1000000000 + 7;
  
  // レイヤ番号（目標点が存在するレイヤ深さ）
  ll n;
  n =  ( (X + Y) / 3 );

  // そのレイヤの端点の座標
  ll eu_x = n;
  ll eu_y = n * 2;
  
  // k（目標点がレイヤの内部のどの位置か）
  ll k = abs(eu_x - X);
  
  // calc n C k
  //cout << "n = " << n << endl;
  //cout << "k = " << k << endl;
  
  ll res, num;
  res = factorial_mod(n, m);

  for (ll i = n - k; i >= 1 ; i--) {
    num = pow_mod(i, m-2, m);
    res = (res * num) % m;
  }
  
  for (ll i = k; i >= 1 ; i--) {
    num = pow_mod(i, m-2, m);
    res = (res * num) % m;
  }
    
    
  cout << res << endl;
  
}


Measured memory_bytes: 256
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
	BufferedReader br =
	    new BufferedReader(new InputStreamReader(System.in));
	String buf;
	int n;
	while(true){
	    int comb=0;
	    if((buf=br.readLine())==null)break;
	    if(buf.length()==0)break;
	    n=Integer.parseInt(buf);
	
	    for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
		    for(int k=0;k<10;k++){
			for(int l=0;l<10;l++){
			    if((i+j+k+l)==n)comb++;
			}
		    }
		}
	    }
	    System.out.println(comb);
	}
    }
}

Measured memory_bytes: 9488
# 水が側面（量が多い）と底面（少ない）の場合分けをする
# (ab - 1/2*a*atanθ) = x
import math

a, b, x = map(int, input().split())
S = x/a # 水を平面にする
radian = 0
if S >= a*b/2:
  h = (a*b-S) * 2/a
  radian = math.atan2(h, a)
else:
  w = S*2/b
  radian = math.atan2(b, w)
deg = radian/(2*math.pi)*360
print(deg)


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

using namespace std;
using ll = long long int;

int main() {
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    int len = s.size();
    for (int i = 0; i < len; i++) {
        if (s[i] != t[i]) {
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3920
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, A = Z(), ZZ()

    if N == 0 and A[0] == 1:
        print(1)
        return

    if A[0] != 0:
        print(-1)
        return

    v = [[1, 1] for _ in range(N+1)]

    for i in range(N):
        x = v[i][1] - A[i]
        if x < 0:
            print(-1)
            return
        v[i+1][1] = 2 * x
    if v[N][0] > A[N] or A[N] > v[N][1]:
        print(-1)
        return
    v[N] = [A[N], A[N]]
    for i in range(N):
        x = (v[N-i][0]+1)//2 + A[N-i-1]
        y = v[N-i][1] + A[N-i-1]
        v[N-i-1][0] = max(v[N-i-1][0], x)
        v[N-i-1][1] = min(v[N-i-1][1], y)
        if v[N-i-1][0] > v[N-i-1][1]:
            print(-1)
            return
    v[0] = [1, 1]
    output = 0
    for i in range(N+1): output += v[i][1]
    print(output)

    return

if __name__ == '__main__':
    main()


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

int main() {
  LL n, m, d;
  cin >> n >> m >> d;

  double ans;
  if (d == 0) ans = (double)(m - 1) / n;
  else ans = (double)(2 * (n - d) * (m - 1)) / n / n;

  cout << setprecision(15) << ans << endl;
}

Measured memory_bytes: 256
macro_rules! scan_sub {
    ( $itr:ident, $t:ty ) => {
        let mut buf = String::new();
        let $itr = {
            while buf.trim().len() == 0 {
                buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
            }
            buf.split_whitespace().map(|n| n.parse::<$t>().unwrap())
        };
    };
}

macro_rules! scan {
    ( $x:ident; Vec<$t:ty> ) => {
        scan_sub!(itr, $t);
        let $x = itr.collect::<Vec<_>>();
    };
    ( $( $x:ident ),*; $t:ty ) => {
        scan_sub!(itr, $t);
        let mut itr = itr;
        $(
            let $x = itr.next().unwrap();
        )*
    };
}

use std::collections::BinaryHeap;

const INF: usize = 1000000000;

fn main() {
    scan!(n, m; usize);
    let mut routes = vec![vec![]; n];
    for _ in 0..m {
        scan!(a, b; usize);
        let a = a - 1;
        let b = b - 1;
        routes[a].push(b);
        routes[b].push(a);
    }

    let mut res = vec![None; n];
    let mut d = vec![INF; n];
    let mut heap = BinaryHeap::new();
    let mut used = vec![false; n];

    heap.push((0, 0, 0));
    res[0] = Some(0);
    d[0] = 0;

    while let Some(t) = heap.pop() {
        if used[t.1] { continue; }
        if (d[t.1] as i64) < t.0 { continue; }
        used[t.1] = true;
        res[t.1] = Some(t.2);

        for &r in routes[t.1].iter() {
            if d[r] <= d[t.1] + 1 { continue; }
            d[r] = d[t.1] + 1;
            heap.push((-(d[r] as i64), r, t.1));
        }
    }

    if res.iter().all(|i| i.is_some()) {
        println!("Yes");
        for r in &res[1..] {
            println!("{}", r.unwrap() + 1);
        }
    } else {
        println!("No");
    }
}


Measured memory_bytes: 14904
const input = require("fs").readFileSync("/dev/stdin", "utf8")
const lines = input.split('\n')
let N = lines[0] - 0
let A = lines[1].split(' ').map(Number)

const mod = 1000000007

const sum = [0]
for (let i = 0; i < N; i++)  {
    sum[i + 1] = (sum[i] + A[i]) % mod
}

function mul (a, b) {
    return ((a >> 16) * b % mod * 65536 + (a & 65535) * b) % mod
}

let ans = 0
for (let i = 1; i < sum.length - 1; i++) {
    ans += mul(sum[i], A[i])
}
console.log(ans % mod)


Measured memory_bytes: 56580
#include <algorithm>
#include <cstring>
#include <cstdio>
using ll = long long;
constexpr int MOD = 1e9 + 7;
int nxt[3005][3005], arr[3005], lst[3005];
int dp[3005][2][2][3005], qx[3005], qy[3005], pw[3005];
int calc(int p, int x, int y)
{
	if (p == -1)
		return arr[x] > arr[y];
	int t = std::max(nxt[p][x], nxt[p][y]), coef = pw[p - t];
	p = t;
	if (p == -1)
		return (arr[x] > arr[y]) * coef;
	bool a = qx[p] == x || qy[p] == x, b = qx[p] == y || qy[p] == y;
	int &res = dp[p][a][a ? (x == qx[p]) : (y == qx[p])][b ? x : y];
	if (~res)
		return res;
	res = calc(p - 1, x, y);
	if (a && b)
		res += calc(p - 1, y, x);
	else if (a)
		res += calc(p - 1, qx[p] ^ qy[p] ^ x, y);
	else if (b)
		res += calc(p - 1, x, qx[p] ^ qy[p] ^ y);
	else
		throw "GG";
	return res = (ll)res * coef % MOD;
}
int main()
{
	// freopen("AGC030-D.in", "r", stdin);
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d", arr + i);
	memset(lst, -1, sizeof(lst));
	for (int i = 0; i < m; i++)
	{
		scanf("%d%d", qx + i, qy + i);
		qx[i]--;
		qy[i]--;
		lst[qx[i]] = lst[qy[i]] = i;
		memcpy(nxt[i], lst, sizeof(lst));
	}
	pw[0] = 1;
	for (int i = 1; i <= m; i++)
		pw[i] = pw[i - 1] * 2 % MOD;
	memset(dp, -1, sizeof(dp));
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
			(ans += calc(m - 1, i, j)) %= MOD;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 176896
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int v[maxn],w[maxn],n,q;
int dp[529][100005],ans = 0;
vector<int> g;
void dfs(int &ans,int val,int weight,int limit,int pos,int fa) {
	if (weight > limit) return;
	if (pos == g.size()) {
		//printf("*****%d %d %d\n",val,limit - weight,dp[fa][limit - weight]);
		ans = max(ans,val + dp[fa][limit - weight]);
		return ;
	}
	dfs(ans,val + v[g[pos]],weight + w[g[pos]],limit,pos + 1,fa);
	dfs(ans,val,weight,limit,pos + 1,fa);
}
int main() {
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) {
		scanf("%d%d",&v[i],&w[i]);
	}
	int N = sqrt(n), T = 100000;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= T; j++) {
			dp[i][j] = dp[i / 2][j];
			if (j >= w[i])
				dp[i][j] = max(dp[i][j],dp[i / 2][j - w[i]] + v[i]);
		}
	} 
	scanf("%d",&q);
	while (q--) {
		int v, L;
		scanf("%d%d",&v,&L);
		if (v <= N) printf("%d\n",dp[v][L]);
		else {
			ans = 0;
			g.clear();
			while (v > N) {
				g.push_back(v);
				v /= 2;
			}
			//printf("****%d %d\n",g.size(),v);
			dfs(ans,0,0,L,0,v);
			printf("%d\n",ans);
		}
	}
	return 0;
}

Measured memory_bytes: 205428
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a =sc.nextInt();
    if (a==3 || a==5 || a==7){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21844