akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc147/tasks/abc147_d
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

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

const MOD: u64 = 1e9 as u64 + 7;

fn main() {
    input! {
        n: usize,
        a: [u64; n]
    };
    let mut total = 0;

    for v in 0..60u64 {
        let mut ones = 0;
        let mut zeros = 0;
        for i in 0..n {
            if (a[i] >> v) & 1 == 1 {
                ones += 1;
            } else {
                zeros += 1;
            }
        }
        let per = (1u64<<v) % MOD;
        total += ones * zeros % MOD * per % MOD;
        total %= MOD;
    }
    println!("{}", total);
}


Measured memory_bytes: 13560
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

x, n = LI()
p = LI()
tmp = 0
while 1:
    if x - tmp not in p:
        print(x-tmp)
        quit()
    elif x + tmp not in p:
        print(x+tmp)
        quit()
    tmp += 1

Measured memory_bytes: 65384
#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;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
    int N; cin>>N;
  if(N==3||N==5||N==7) Out("YES");
  else Out("NO");
}

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

using namespace std;

#define MAX2(a, b) (a > b ? a : b)
#define MIN2(a, b) (a < b ? a : b)

#define MAX3(a, b, c) MAX2(MAX2(a, b) , c)
#define MIN3(a, b, c) MIN2(MIN2(a, b) , c)

int main()
{
	int H, W, max_ = 0;

	scanf("%d", &H);
	scanf("%d", &W);

	vector<vector<int> > c(H, vector<int>(W));

	vector<vector<int> > dp(H, vector<int>(W, 0));

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			scanf("%d", &c[i][j]);

			if (c[i][j] == 0)
			{
				if (i == 0 || j == 0)
				{
					dp[i][j] = 1;
				}

				max_ = 1;
			}
		}
	}

	for (int i = 1; i < H; i++)
	{
		for (int j = 1; j < W; j++)
		{
			if (c[i][j] == 0)
			{
				dp[i][j] = MIN3(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1;

				max_ = MAX2(dp[i][j], max_);
			}
		}
	}

	printf("%d\n", max_ * max_);

	return 0;
}

Measured memory_bytes: 16316
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        for(;;){
                int H,W;
                scanf("%d %d",&H,&W);
                if(H){
                        for(int i=0;i<H;i++){
                                for(int j=0;j<W;j++){
                                        printf("#");
                                }
                                printf("\n");
                        }
                        printf("\n");
                }else{
                        break;
                }
        }
        return 0;
}

Measured memory_bytes: 1152
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

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

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

fn dfs(node: usize, nodes: &Vec<Vec<usize>>, dp: &mut Vec<Option<usize>>) -> usize {
    if let Some(len) = dp[node] {
        return len;
    }

    let mut mx = 0;
    for &next in &nodes[node] {
        mx = max!(mx, dfs(next, nodes, dp)+1);
    }
    dp[node] = Some(mx);
    mx
}

fn solve() {
    let (n,m) = get!(usize, usize);
    let xy = get!(usize, usize; m);

    let mut dp = vec![None; n+1];
    let mut nodes = vec![Vec::new(); n+1];
    for (x,y) in xy {
        nodes[x].push(y);
    }
    let mut mx = 0;
    for i in 1..n+1 {
        mx = max!(mx, dfs(i,&nodes,&mut dp));
    }
    println!("{}", mx);
}


Measured memory_bytes: 20860
A,B,M = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

ans = min(A_list) + min(B_list)
M_list = []
for m in range(M):
  M_list = list(map(int, input().split()))
  _ = A_list[M_list[0]-1] + B_list[M_list[1]-1] - M_list[2]
  ans = min(_,ans)


print(ans)

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

const int N = 100005;

struct Data {
    int x, y, z;
    Data (int x, int y, int z) :
        x(x), y(y), z(z) {}
};

int nx, ny, nz;
long long L[N], R[N];
vector<Data> a;

typedef pair<int, int> ii;

int main() {
    cin >> nx >> ny >> nz;
    for (int i = 0; i < nx + ny + nz; ++i) {
        int x, y, z; cin >> x >> y >> z;
        a.push_back(Data(x, y, z));
    }
    sort(a.begin(), a.end(), [&](Data p, Data q) { return p.x - p.y > q.x - q.y; });
    priority_queue<ii> pq;
    long long sum;
    sum = 0;
    for (int i = 0; i < nx + ny + nz; ++i) {
        if (pq.size() < nx) {
            pq.push(ii(a[i].z - a[i].x, i)), sum += a[i].x;
        } else {
            pq.push(ii(a[i].z - a[i].x, i)), sum += a[i].x;
            int id = pq.top().second; pq.pop();
            sum -= a[id].x, sum += a[id].z;
        }
        L[i] = sum;
    }
    while (pq.size()) pq.pop();
    sum = 0;
    for (int i = nx + ny + nz - 1; i >= 0; --i) {
        if (pq.size() < ny) {
            pq.push(ii(a[i].z - a[i].y, i)), sum += a[i].y;
        } else {
            pq.push(ii(a[i].z - a[i].y, i)), sum += a[i].y;
            int id = pq.top().second; pq.pop();
            sum -= a[id].y, sum += a[id].z;
        }
        R[i] = sum;
    }
    long long res = 0;
    for (int i = nx - 1; i < nx + nz; ++i) {
        res = max(res, L[i] + R[i + 1]);
    }
    cout << res;
}


Measured memory_bytes: 4724
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def main():
    H, N = map(int, input().split())
    A = [int(i) for i in input().split()]
    if sum(A) >= H:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

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

#define ll long long
#define ar array

void solve() {
	 int n,a,b,c=0,c1=0,c2=0;
	 cin>>n>>b;
     cout<<n*b<<endl;

}

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

	int t;
	//cin >> t;
	//while(t--)
		solve();
}


Measured memory_bytes: 3616
//vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n,m,a,b;
  cin >> n >> m >> a >> b;
  vector<int>x(n);
  vector<int>y(m);
  
  rep(i,n) cin >> x.at(i);
  rep(i,m) cin >> y.at(i);
  
  int xma=-250;
  int ymi=+250;
  rep(i,n) xma = max(xma,x.at(i));
  rep(i,m) ymi = min(ymi,y.at(i));
  int flag=0;
  
  if(b-a >= 1){
    for(int i=a+1;i<=b;i++){
      if(xma < i && ymi >=i){
        cout << "No War"<<endl;
        flag =1;
        break;
      }
    }
  }
  if(flag==0) cout<<"War"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

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

    ll ans = 0;

    ll n;
    cin >> n;

    vector<ll> x;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        x.push_back (temp);
    }

    sort(ALL(x));

    ans = 10000000000;
    for (ll i = x[0]; i <= x[n-1]; i++) {
        ll sum = 0;
        for (ll j = 0; j < n; j++) {
            sum += (i - x[j]) * (i - x[j]);
        }
        if (sum < ans) ans = sum;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

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

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll R, ll G) {
  cout << G * 2 - R << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll R;
	ll G;
	scanf("%lld", &R);
	scanf("%lld", &G);
	solve(R, G);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define sz 10002
using namespace std;
int main()
{
    ll int n,x;
    cin>>n;
   
    for(ll int i=n; ;i++)
    {
        x=i;
        int flag=0;
        for(ll int j=2;j<=sqrt(x);j++)
        {
            if(x%j==0)flag=1;
        }
        if(flag==0){cout<<x<<endl;break;}

    }

}



Measured memory_bytes: 256
S = gets.chomp
K = gets.to_i

single = S.chars.slice_when{|a,b|a!=b}.map(&:size)
double = (S+S).chars.slice_when{|a,b|a!=b}.map(&:size)

single_num = single.map{|v|v/2}.inject(:+)
double_num = double.map{|v|v/2}.inject(:+)

if single.size == 1
    puts S.size * K / 2
elsif single.size * 2 == double.size
    puts single_num * K
else
    puts single_num + (double_num - single_num) * (K - 1)
end


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

int main() {
  int N,R;
  cin>>N>>R;
  if(N>=10){
    cout<<R;
  }
  else{
    cout<<R+100*(10-N);
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
 
using namespace std;
int H,W;
int pre[310][310];

char c[310][310];
string a,b;
int dp[310][310];
int dp2[310][310];
int cost(int x,int y){
    if( x == 0 or y == 0 ) return 0;
    if( dp2[y][x] != -1 ) return dp2[y][x];
    int c = 0;
    if( a[H-x] == b[H-y] ) c = 1; 
    return dp2[y][x] = c + cost(x-1,y-1);
}


int dfs(int x,int y){
    if( x == 0 or y == 0 ) return 0;
    if( dp[y][x] != -1 ) return dp[y][x];
    int ans = cost(x,y) + min(dfs(x-1,y),dfs(x,y-1));
    return dp[y][x] = ans;

}
int solve(string a_, string b_){
    a = a_;
    b = b_;
    memset(dp,-1,sizeof(dp));
    memset(dp2,-1,sizeof(dp2));
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    return dfs(H,H);
}

int main(){
    
    cin >> H >> W;
    for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            cin >> c[j][i];
        }
    }
    int sum = 0;
    for(int i = 0 ; i < W-1 ; i++){
        sum += solve(c[i],c[i+1]);
    }
    cout << sum << endl;
}


Measured memory_bytes: 1152
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
typedef long long ll;
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    int a,b;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
//構造体降順
int comp( const void *c1, const void *c2 )
{
  data test1 = *(data *)c1;
  data test2 = *(data *)c2;
  int tmp1 = test1.b;   /* b を基準とする */
  int tmp2 = test2.b;
  return tmp2 - tmp1;
}


int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    int N,D;
    int cnt=0;
    scanf("%d%d",&N,&D);
    int ten[N][D];
    rep(i,N){
        rep(j,D){
            scanf("%d",&ten[i][j]);
        }
    }
    rep(i,N-1){
        for(int j=i+1;j<N;j++){
            int temp=0;
            for(int k=0;k<D;k++){
                temp+=(ten[i][k]-ten[j][k])*(ten[i][k]-ten[j][k]);
            }
            for(int m=1;m<16000;m++){
                if(temp==m*m){
                    cnt++;
                }
            }
        }
    }
    printf("%d",cnt);
}


Measured memory_bytes: 1700
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<math.h>
using namespace std;
long long a[100005];
long long ans[100005];
int main()
{
    memset(a,0,sizeof(a));
    long long n,m,flag=0,k=1;
    a[0]=-5;
    scanf("%lld%lld",&n,&m);
    for(int i=1; i<=m; i++)
    {
        scanf("%lld",&a[i]);
        if(a[i]-a[i-1]==1) flag=1;
    }
    ans[0]=1;
    if(flag) printf("0\n");
    else
    {
        if(a[k]==1)
        {
            ans[k]=0;
            k++;
        }
        else ans[1]=1;
        for(int i=2; i<=n; i++)
        {
            if(i==a[k])
            {
                ans[i]=0;
                k++;
                continue;
            }
            else
            {
                ans[i]=(ans[i-1]+ans[i-2])%1000000007;
            }
        }
        printf("%lld\n",ans[n]);
    }
}


Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main(){
    
    long long N, M;
    cin >> N >> M;

    long long ans;
    if (2 * N > M){
        ans = M / 2;
    }else{
        long long i = (-2 * N + M) / 4;
        ans = N + i;
    }
    
    
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


const ll MOD = (ll)(1e9 + 7);
int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 205;
const int MAX_X = 112345;
ll dp[MAX_N][MAX_X];

int main2() {
  int N = nextInt();
  int X = nextInt();
  vector<int> S(N);
  REP(i, N) S[i] = nextInt();

  // if (N >= 6) return 0;

  sort(ALL(S));
  reverse(ALL(S));

  CLR(dp, 0);
  dp[0][X] = 1;
  for (int i = 0; i < N; i++) {
    for (int x = 0; x <= X; x++) {
      (dp[i+1][x     ] += (N - i - 1) * dp[i][x] % MOD) %= MOD;
      (dp[i+1][x%S[i]] +=               dp[i][x]      ) %= MOD;
    }
  }
  ll ans = 0;
  REP(v, X+1) {
    // cout << dp[N][v] << " ";
    ans += dp[N][v] * v % MOD;
    ans %= MOD;
  }
  // cout << endl;
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 180352
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a, b;
		String op; 
		a = sc.nextInt();
		op = sc.next();
		b = sc.nextInt();
		if(op.equals("+")) System.out.println(a + b);
		else if(op.equals("-")) System.out.println(a - b);
		else System.out.println("error");
	}
}

Measured memory_bytes: 23124
#include<iostream>
using namespace std;
int main(){
    int n,m,a[100][100],b[100],c[100];
    cin >>n >>m;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin >>a[i][j];
    for(int i=0;i<m;i++)
        cin >>b[i];
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
            c[i] += a[i][j]*b[j];
        cout <<c[i]<<endl;
    }
}


Measured memory_bytes: 3160
import java.util.*;
public class Main {
	public static void main(String[] args)
	{
		//変数
		int count=0;
		boolean sw=false;
		//int answer=0;
		//long answer=0;
		double answer=0;
		//String answer="Heisei";
		//List<Integer> h=new ArrayList<Integer>();
		//int af=Integer.MAX_VALUE;
		//int sub=0;
		int max=0;
		int min=Integer.MAX_VALUE;
		//int t[]=new int[(int)Math.pow(10,5)];
		String s="";
		double a=0;
		
		//入力
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		//X=sc.nextDouble();
		//int A[]=new int[N];
		List<Double> x=new ArrayList<Double>();
		List<String> u=new ArrayList<String>();
		for(int i=0;i<N;i++)
		{
			x.add(sc.nextDouble());
			u.add(sc.next());
		}
		//String S=sc.next();
		//for(int i=0;i<N;i++)
		//{
		//	a=x.get(i);
		//	System.out.println(a);
		//}
		
		//処理
		for(int i=0;i<N;i++)
		{
			s=u.get(i);
			//System.out.println(s);
			if(s.equals("JPY"))
			{
				a=x.get(i);
				//System.out.println("JPY");
				answer+=a;
			}else
			{
				a=x.get(i);
				a=a*380000.0;
				//System.out.println("BTC");
				answer+=a;
			}
		}
			
		// 出力
		//System.out.println(Arrays.toString(X));
		//System.out.println(Arrays.deepToString(a));
		//System.out.println(Arrays.toString(A.toArray()));
		System.out.println(answer);
	}
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define FOR(i, c) for (int i = 0; i < c; i++)
#define MOD 1000000007
using namespace std;

int cb(int n, int i) {
  int res = 1;
  for (int j = 0; j < i; j++) {
    res = res*(n-j)/(j+1);
  }
  return res;
}
int main() {
  int n , m;
  cin >> n >> m;
  cout << cb(m, 2) + cb(n, 2) << endl; 
  return 0;
}




Measured memory_bytes: 3624
#!/usr/bin/env python
# coding: utf-8

# In[15]:


N = int(input())
apb = []
b_sum = 0
for i in range(N):
    A,B = map(int, input().split())
    apb += [A+B]
    b_sum += B


# In[20]:


ans = sum(sorted(apb, reverse=True)[::2])-b_sum
print(ans)


# In[ ]:






Measured memory_bytes: 14060
#include <bits/stdc++.h>
using namespace std;
int fact(int n){
	int f=1;
	for(int i=2;i<=n;i++)
	f=f*i;
	return f;
}

int main() {
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	for(int i=0;i<n;i++) cin>>a[i] , c[i]=i+1;
	for(int i=0;i<n;i++) cin>>b[i];
	int p=0,q=0;int k=0;
	for(int i=0;i<n;i++){
int cc=0;
		for(int j=i+1;j<n;j++){
		    if(c[j]>c[i]&&c[j]<a[i])
		    cc++;
		}
		if(c[i]!=a[i])
		cc++;
       
		p+=cc*fact(n-i-1);
// 		p+=(a[i]-c[i]-k)*fact(n-(i+1));
		if(a[i]!=c[i]){
		    k++;
			int m;
			for(int j=0;j<n;j++)
			if(c[j]==a[i]){
				m=j;
				break;
			}
			for(int j=m;j>i;j--)
			c[j]=c[j-1];
		}
		else{
		    k=0;
		}
}

	for(int i=0;i<n;i++)  c[i]=i+1;
	 k=0;
	for(int i=0;i<n;i++){
	    
		int cc=0;
		for(int j=i+1;j<n;j++){
		    if(c[j]>c[i]&&c[j]<b[i])
		    cc++;
		}
		if(c[i]!=b[i])
		cc++;
		
		q+=cc*fact(n-i-1);
 	
		if(b[i]!=c[i]){
		    k++;
			int m;
			for(int j=0;j<n;j++)
			if(c[j]==b[i]){
				m=j;
				break;
			}
			for(int j=m;j>i;j--)
			c[j]=c[j-1];
		}
		else{
		    k=0;
		}
		
	}
	
	cout<<abs(p-q)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N, K;cin >> N >> K;
	string s;cin >> s;
	vector<int> Num;
	int now = 1,cnt = 0;
	for (int i = 0; i < N;i++) {
		if (s[i]==(char)('0'+now)) {cnt++;}
		else {
			Num.push_back(cnt);
			now = 1 - now;
			cnt = 1;
		}
	}
	if (cnt!=0) {Num.push_back(cnt);}
	if (Num.size()%2==0) {Num.push_back(0);}
	int add = 2 * K + 1,ans = 0;
	for (int i = 0; i < Num.size(); i += 2) {
		int tmp = 0,left = i,right = min(i + add,(int)Num.size());
		for (int j = left; j < right; j++) {tmp += Num[j];}
		ans = max(tmp, ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1020
l,r = [int(x) for x in input().split()]

mod = 2019
ans = 2020
for i in range(l, r):
    if i % mod == 0:
        ans = 0
        break
    else:
        for j in range(i+1, r+1):
            if i == j:
                continue
            elif j % mod == 0:
                ans = 0
                break
            else:
                ans = min(ans, (i*j)%mod)
print(ans)

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

int main()
{
    char s[100] = {};
    scanf("%s", s);

    int N = strlen(s);
    int reference = 0;

    while(reference<(N-1)/2)
    {
        if(s[reference]!=s[N-1-reference])
        {
            printf("No");
            return 0;
        }
        if(s[reference]!=s[(N-3)/2-reference])
        {
            printf("No");
            return 0;
        }
        if(s[(N+1)/2+reference]!=s[N-1-reference])
        {
            printf("No");
            return 0;
        }
        reference++;
    }
    printf("Yes");
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <math.h>

int main(){
    int x, h;
    double S;

    for(;;){
        scanf("%d", &x);
        scanf("%d", &h);
        if(x == 0 && h == 0) break;
        double th = sqrt(((double)x/2*(double)x/2)+(h*h));
        S = x * x;
        S += 4 * ((double)x * th / 2);
        printf("%f\n", S);
    }

    return 0;
}

Measured memory_bytes: 1060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define pb push_back
#define fi first
#define se second
#define Mod 1000000007


 
int main(){
    ll i,j;

    ll s[4];
    for(i=0;i<4;i++) s[i]=0;

    for(i=0;i<6;i++){
        ll x;
        cin>>x;

        s[x-1]++;

    }
    for(i=0;i<4;i++){
        if(s[i]>2||s[i]<1){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;


    return 0;
}

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

namespace ABC146F
{
    class Program
    {
        static readonly int MAXIMUM = int.MaxValue / 2;

        private static void Solve2(int n, int m, string s)
        {
            var sarr = s.ToCharArray();
            int current = n;
            int prev = n;
            var path = new List<int>();
            path.Add(current);
            while (current > 0)
            {
                current -= m;
                while (current < 0 || sarr[current] == '1') ++current;
                if (current == prev)
                {
                    Console.WriteLine(-1);
                    return;
                }
                path.Add(current);
                prev = current;
            }

            var arr = path.ToArray();
            var ans = new List<int>();
            for (int i = path.Count - 1; i > 0 ; --i)
            {
                ans.Add(arr[i - 1] - arr[i]);
            }
            var builder = new StringBuilder();
            foreach (var a in ans)
            {
                builder.Append(a);
                builder.Append(" ");
            }
            Console.WriteLine(builder);
        }

        private static void Solve(int n, int m, string s)
        {
            var sarr = s.ToCharArray();
            var nStep = Enumerable.Repeat<int>(MAXIMUM, n + 1).ToArray();
            var from = Enumerable.Repeat<int>(-1, n + 1).ToArray();
            //var nStep = new int[n + 1];
            //var from = new int[n + 1];
            //Array.Fill(nStep, MAXIMUM);
            //Array.Fill(from, -1);
            nStep[0] = 0;
            for (int i = 1; i <= n; ++i)
            {
                if (sarr[i] == '1') continue;
                for (int j = Math.Max(0, i - m); j < i; ++j)
                {
                    if (nStep[j] + 1 <  nStep[i])
                    {
                        nStep[i] = nStep[j] + 1;
                        from[i] = j;
                        //break;
                    }
                }
            }

            if (nStep[n] == MAXIMUM)
            {
                Console.WriteLine(-1);
                return;
            }

            int c = n;
            var ans = new List<string>();
            while (c > 0)
            {
                var step = c - from[c];
                c = from[c];
                ans.Add(step.ToString());
            }

            ans.Reverse();
            var builder = new StringBuilder();
            foreach (var a in ans)
            {
                builder.Append(a);
                builder.Append(" ");
            }
            Console.WriteLine(builder);
        }

        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ');
            var n = Convert.ToInt32(line[0]);
            var m = Convert.ToInt32(line[1]);
            string s = Console.ReadLine();
            Solve2(n, m, s);
        }
    }
}


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

struct node{
	int val,idx;
	node(int val,int idx):val(val),idx(idx){}
	friend bool operator < (node a,node b){
		return a.val < b.val;
	}
};

int n;
int a[200010],b[200010];

int pre(const int i) {return (i+n-1)%n;}
int pot(const int i) {return (i+n+1)%n;}
bool check(const int i){return (b[i] > a[i] && b[i] - a[i] >= b[pre(i)] + b[pot(i)]);}
priority_queue <node> q;

int main()
{
	long long ans = 0;
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < n;i++){
		cin >> b[i];
		if(a[i] > b[i]){
			cout << -1 << endl;
			return 0;
		}
	}
	
	for(int i = 0;i < n;i++) {if(check(i)) q.push(node(b[i],i));}
	
	while(!q.empty()){
		node temp = q.top();q.pop();
		int dis = temp.val - a[temp.idx];
		int dis2 = b[pre(temp.idx)] + b[pot(temp.idx)];
		ans += dis/dis2;
		b[temp.idx] = a[temp.idx] + dis%dis2;
		if(check(pre(temp.idx))) q.push(node(b[pre(temp.idx)],pre(temp.idx)));
		if(check(pot(temp.idx))) q.push(node(b[pot(temp.idx)],pot(temp.idx)));
	}
	
	for(int i = 0;i < n;i++){
		if(a[i] != b[i]){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;


int n,x,m;
int l[10],r[10],s[10];
int lion[7]={};

int ans[6]={-1},ma=-1;


bool ok(){
	rep(i,m){
		if(lion[l[i]]-lion[r[i]+1]!=s[i])return false;
	}
	return true;
}
void dfs(int d){
	if(d==-1){
		if(ok()&&ma<lion[0]){
			ma=lion[0];
			rep(i,n){
				ans[i]=lion[i]-lion[i+1];
			}
		}
		return;
	}
	rep(i,x+1){
		lion[d]=lion[d+1]+i;
		dfs(d-1);
	}
}
int main(){
	cin>>n>>x>>m;
	bool impossible=false;
	rep(i,m){
		cin>>l[i]>>r[i]>>s[i];
		l[i]--;r[i]--;
	}
	dfs(n-1);
	if(ans[0]==-1){
		cout<<-1<<endl;
	}
	else{
		cout<<ans[0];
		rep(i,n-1)cout<<' '<<ans[i+1];
		cout<<endl;
	}
	return 0;
}

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

#if DEBUG && !ONLINE_JUDGE
    #include "header.h"
#else
    #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
    return;
}
lli dp[3001][3001][2];
vi ar;
lli solve(int l, int r, int p) {
    if(r<l) return 0;
    if(dp[l][r][p] != -1) return dp[l][r][p];
    if(p==1) {
        return dp[l][r][p] = max(solve(l,r-1,!p) + ar[r], solve(l+1,r,!p) + ar[l]);
    }
    else return dp[l][r][p] = min(solve(l,r-1,!p) - ar[r], solve(l+1,r,!p) - ar[l]);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    preprocess();
    int n; cin>>n;
    ar.resize(n);
    memset(dp,-1,sizeof dp);
    rep(i,0,n) cin>>ar[i];
    cout<<solve(0,n-1,1)<<endl;
}



Measured memory_bytes: 141184
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;

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



int main(){
    int a, b, k;
    cin >> a >> b >> k;
    int count = 0;
    for(int i = min(a, b); i >= 1; i--){
        if(a % i == 0 && b % i == 0){
            count++;
        }
        if(count == k){
            cout << i << endl;
            break;
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}


template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}

const int MOD = 1000000007;
const int MAX = 210000;
ll fac[MAX];
ll finv[MAX];
ll inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<ll,ll>> factorize(ll n){
  vector<pair<ll,ll>> ret;
  for(ll p = 2 ; p * p <= n; p++){
    if(n % p != 0){
      continue;
    }
    int num = 0;
    while(n % p == 0){
      n = n / p;
      num++;
    }
    ret.emplace_back(make_pair(p,num));
  }
  
  if(n != 1){
    ret.emplace_back(make_pair(n,1));//if prime it self
  }  
  return ret;
}


signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  COMinit();
  int N,M;
  cin >> N >> M;
  vector<pair<ll,ll>> fac_result = factorize(M);
  ll ret = 1;
  for(auto pa : fac_result){
    int num = pa.second;
    ll tmp = COM(num + N - 1, N - 1);
    ret = (ret * tmp) % MOD;
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    if(b-a==c-b) cout<<"YES";
    else
    cout<<"NO";
}
int  main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
    //cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

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

using namespace std;

string s;
int cnt,ans;
int main(){
    cin >> s;
    for(int i=0;i<(int)s.size();i++){
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
            cnt++;
            ans=max(ans,cnt);
        }else{
            cnt=0;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int ai = scanner.nextInt();
            a[i]=ai;
            sum+=ai;
        }
        double d = 1.0*sum/(4*m);
        int c = 0;
        for (int i = 0; i < n; i++) {
            if(a[i]>=d) c++;
        }

        if(c>=m) System.out.println("Yes");
        else System.out.println("No");
    }
}


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

int main(){
    ll a,b,c,d,e,k,l,m,n,o=0,p,q,x,y,z,max1=0,ans;
    string s,t,u;
    cin>>a>>b>>c;
    if (a>=c&&b<=c) {
        cout<<"Yes"<<endl;
    }
   else  if (a<=c&&b>=c) {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
N,H,W = map(int,input().split())
alloy = [list(map(int,input().split())) for i in range(N)]

#print(alloy)

count = 0
for i in range(N):
  if alloy[i][0] >= H and alloy[i][1] >= W:
    count += 1
    continue
else:
  print(count)
  


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;

#define INF (1<<30)

int main(void) {
  int N; cin >> N;
  vector<int> vec(N, 0);
  vector<int> dp(N, INF);

  for (int i = 0; i < N; i++)
    cin >> vec[i];

  for (int i = 0; i < N; i++) {
    *lower_bound(dp.begin(), dp.end(), vec[i]) = vec[i];
  }

  cout << lower_bound(dp.begin(), dp.end(), INF) - dp.begin() << endl;
  return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

// 参考: https://betrue12.hateblo.jp/entry/2019/01/13/030527

int n, q;
int a[100005];
ll Sum[100005], Sum2[100005];

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

    cin >> n >> q;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        Sum[i] = Sum[i - 1] + a[i];
        Sum2[i] = a[i];
        if(i - 2 > 0)   Sum2[i] += Sum2[i - 2];
    }

    for(int i = 0; i < q; ++i){
        int x;
        cin >> x;
        int ng = 0, ok = n;
        while(ok - ng > 1){
            int mid = (ng + ok) / 2;
            if(a[mid] < x){
                ng = mid;
            }
            else{
                int RightCnt = n - mid + 1;
                int LeftCnt = mid - (lower_bound(a, a + n + 1, max(1, 2 * x - a[mid])) - a) + 1;
                (RightCnt > LeftCnt ? ng : ok) = mid;
            }
        }
        ll ans = Sum[n] - Sum[ok - 1];
        int foo = n - (n - ok + 1) * 2;
        if(foo > 0) ans += Sum2[foo];
        cout << ans << '\n';
    }
}

Measured memory_bytes: 3712
/*
  AtCoder Regular Contest 098
  D - Xor Sum 2
*/

#include<iostream>
using namespace std;

int N;
unsigned long long sum = 0;
unsigned long long A[200001];

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

  unsigned long long count = 0;
  int j = 1;
  sum = A[0];
  for (int i = 0; i < N; ++i) {
    while((j < N) && ((sum & A[j]) == 0)) sum ^= A[j++];
    count += j - i;
    sum ^= A[i];
  }

  printf("%llu\n", count);
  return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class A
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var K = int.Parse(Console.ReadLine());
            var X = int.Parse(Console.ReadLine());
            var Y = int.Parse(Console.ReadLine());
            var answer = X * Math.Min(K, N) + Y * Math.Max(0, N - K);
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 27360
#include<stdio.h>
int main(){
  int n, i, j, k, card[4][13];
  char a;
  
  scanf("%d",&n);
  for( i=0; i < 4; i++){
    for( j=0; j < 13; j++){
      card[i][j] = 0;
    }
  }

  for( i = 0; i < n; i++ ){
    scanf(" %c", &a);
    scanf("%d", &k);
    if( a == 'S'){
      card[0][k-1] = 1;
    }else if( a == 'H'){
      card[1][k-1] = 1;
    }else if( a == 'C'){
      card[2][k-1] = 1;
    }else{
      card[3][k-1] = 1;
    }
  }

  for( i = 0; i < 4; i++ ){
    for( j = 0; j < 13; j++ ){
      if( card[i][j] == 0 ){
	if( i == 0 ){
	  printf("S %d\n",j+1);
	}else if( i == 1){
	  printf("H %d\n",j+1);
	}else if( i == 2 ){
	  printf("C %d\n",j+1);
	}else{
	  printf("D %d\n",j+1);
	}
      }
    }
  }

  return 0;
}

Measured memory_bytes: 596
N = int(input())
b = list(map(int, input().split()))
ans = []

for _ in range(N):
    for i in range(len(b)-1, -1, -1):
        if b[i]==i+1:
            ans.append(b[i])
            b = b[:i]+b[i+1:]
            break
    else:
        print(-1)
        exit()

ans.reverse()

for ans_i in ans:
    print(ans_i)

Measured memory_bytes: 38768
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n; cin >> n;
  cout << fixed << setprecision(10);
  
  if(n % 2 == 0) cout << 0.5 << endl;
  else cout << double(n+1)/double(2*n) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define dl double
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define each(i, n) for(auto&& i: n)
#define co(n) cout << fixed << setprecision(n)

int main() {
  st S;
  cin >> S;
  if(S == "Sunny") {
    cout << "Cloudy" << endl;
  }
  else if(S == "Cloudy") {
    cout << "Rainy" << endl;
  }
  else if(S == "Rainy") {
    cout << "Sunny" << endl;
  }
}  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, M;
    vector<double> a;
    cin >> N >> M;
    double tmp;
    double all = 0;
    for(int i = 0; i < N; i++){
        cin >> tmp;
        a.push_back(tmp);
        all += tmp;
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(a[i] >= all /(double)(4 * M)){
            ans++;
        }
    }

    if(ans >= M){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int A[100000 + 10];
int B[100000 + 10];
pi C[100000 + 10];

signed main(void) {
    int N; cin >> N;
    rep(i, N) {
        cin >> A[i] >> B[i];
        C[i] = mp(A[i] + B[i], i);
    }
    sort(C, C+N);
    reverse(C, C+N);

    int ans = 0;
    bool takahashi = true;
    rep(i, N) {
        if (takahashi) {
            ans += A[C[i].se];
            takahashi = false;
        } else {
            ans -= B[C[i].se];
            takahashi = true;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
import qualified Data.Map as M

isP::Int->Bool
isP n 
   |n<2 =False
   |n==2 =True
   |n `mod` 2==0 =False
   |otherwise = try n 3
   where
        try :: Int->Int->Bool
        try m i
           |i*i > m=True
           |m `mod` i==0 =False
           |otherwise=try m (i+2)

f3::Maybe Int->Int
f3 (Just x)=x
f3 Nothing=0

f2::M.Map Int Int->[String]->[Int]
f2 _ [] = []
f2 ms (x:xs) =let (a:b:[])=map read (words x)::[Int]
                  c1=f3 (M.lookup (a-1) ms)
                  c2=f3 (M.lookup (b) ms)
              in c2-c1:f2 ms xs

main =do
      e <- getLine
      es <- getContents 
      let ms=tail $ scanl (\acc x-> acc + if isP x && isP ((x+1) `div` 2) then 1 else 0) 0 [0..100000]
          ms2=zip [0..] ms
          ms3=M.fromList ms2
      mapM_ putStrLn $ map show $ f2 ms3 (lines es)

Measured memory_bytes: 25980