akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let p: usize = sc.cin();
    let mut cx = vec![1u64, 0];
    for _ in 0..n {
        let a: usize = sc.cin();
        if a % 2 == 0 {
            cx[0] *= 2; cx[1] *= 2;
        } else {
            cx[0] += cx[1]; cx[1] = cx[0];
        }
    }
    put!(cx[p]);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const int inf = ~0u >> 1;
int main() {
    IO;
    ll a;
    string b;
    cin >> a >> b;
    ll ans = 0;
    for (int i = 0; i < 4; ++i) {
        if (i == 0) {
            ans += a * (b[i] - '0') * 100;
        }
        else if (i == 2) {
            ans += a * (b[i] - '0') * 10;
        }
        else if (i == 3)
            ans += a * (b[i] - '0');
        //cout << "i = " << i << " ans = " << ans << endl;
    }
    cout << ans / 100 << endl;
    return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using OS = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ld double
#define ull unsigned long long

const int N = 2e5 + 5;
ll n, a[N], dp[N], pre[N];

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

    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];

    pre[1] = a[1];
    for (int i = 3; i <= n; i += 2) pre[i] += pre[i - 2] + a[i];

    for (int i = 2; i <= n; i++) {
        if (i & 1) {
            dp[i] = max(dp[i - 1], dp[i - 2] + a[i]);
        } else {
            dp[i] = a[i] + dp[i - 2];
            dp[i] = max(dp[i], pre[i - 1]);
        }
    }
    cout << dp[n];

    return 0;
}

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

int main(){
  int N ;
  cin >> N;
  int sum = 0;
  int maxL = 0;
  for(int i = 0; i < N ; i++){
    int L ;
    cin >> L;
    sum += L;
    maxL = max(maxL,L);
  }
  if(maxL < sum - maxL){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
  

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

typedef pair<string,string> pss;
signed main(void) {
    int n,f;
    cin >> n >> f;
    map<pss,int> ma;
    rep(i,n){
        int m;
        cin >> m;
        vs v(m);
        rep(j,m)cin >> v[j];
        rep(j,m)rep(k,j){
            if(v[j] < v[k])ma[pss(v[k],v[j])]++;
            else ma[pss(v[j],v[k])]++;
        }
    }
    vector<pss> ans;
    for(auto x : ma){
        string s = x.first.first;
        string t = x.first.second;
        if(x.second >= f){
            if(s < t)ans.push_back(pss(s,t));
            else ans.push_back(pss(t,s));
        }
    }
    sort(all(ans));
    cout << ans.size() << endl;
    rep(i,ans.size())cout << ans[i].first << " " << ans[i].second << endl;
    
}



Measured memory_bytes: 3620
#include <iostream> 

using namespace std;

int main(int argc, char const *argv[])
{
  int dishes[5];
  int min_dish, min_flag;
  int minites = 0;
  cin >> dishes[0];
  min_dish = dishes[0];
  for(int i=1; i<5;i++){
    cin >> dishes[i];
  }
  for(int i=0;i<5;i++){
    if(dishes[i] % 10 != 0){
      if(dishes[i] % 10 < min_dish % 10){
        min_dish = dishes[i];
        min_flag = i;
      }
    }
  }
  for(int i=0;i<5;i++){
    if(i == min_flag){
      continue;
    }
    if(dishes[i] % 10 == 0){
      minites += dishes[i];
    }else{
      minites += (dishes[i] / 10 + 1) * 10;
    }
  }
  minites += dishes[min_flag];
  cout << minites << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int c[100010];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),m=gi(),a,b;
	for(int i=1;i<=m;++i){
		a=gi(),b=gi();
		if(a>b)std::swap(a,b);
		++c[a],--c[b];
	}
	for(int i=1;i<=n;++i)if((c[i]+=c[i-1])&1)return puts("NO"),0;
	return puts("YES"),0;
}


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

long long comb(int n,int m);//組み合わせ総数の計算
long long shisu(int m2, int n2);
long long h(int m1, int n1);

int main()
{
  int N;
  cin >> N;
  
  int D[N];
  int count[N];
  for(int i=0;i<N; i++){
    count[i]=0;
  }
  
  for(int i=0;i<N; i++){
    cin >> D[i];
    count[D[i]] = count[D[i]] + 1;
  }
  
  long long ans=1;
  
  if(D[0]!=0){//頂点1が自分との距離が0でない
    ans=0;
    cout << ans << endl;
    return 0;
  }else{
    for(int i=1; i<N-1; i++){
      if(D[i]==0){
        ans=0;
        cout << ans << endl;
        return 0;
      }
      if(count[i]==0 && count[i+1]!=0){
        //距離iのものが存在しないのに距離i+1のものが存在する
        ans=0;
        cout << ans << endl;
        return 0;
      }
    }
  }
  //存在するときの個数
  for(int i=2; i<N; i++){
    if(count[i]!=0){

        ans *= shisu(count[i-1],count[i]);
        ans %= 998244353;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


long long shisu(int m2, int n2){
  long long result2=1;
  for(;n2>0;n2--){
    result2  *= m2;
    result2 %= 998244353;
  }
  
  return result2;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<" "
#define rep(i, n) for(int i=0; i<(n); i++)

int digit_sum(int n){
    int ans=0;
    while(1 == 1){
        ans += n%10;
        n/=10;
        if(n==0) break;
    }
    return ans;
}


int main(){
    int n, a, b; cin>> n >> a >> b;
    int ans=0;
    for(int i=1; i<=n; i++){
        int sum=digit_sum(i);
        if(sum >= a && sum <= b) ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
#define inf 1000000007
using namespace std;

int main(void){
    string s;
    cin >> s;
    vector<string> t(int(s.length())+1);
    int count = 1;
    for(int i = 0; i < s.length(); i++){
        t[i]=s[i];
    }
    for(int i = 1; i < s.length(); i++){
        if(t[i]==t[i-1]&&i!=s.length()-1)
            t[i+1]=t[i+1]+t[i];
        if(t[i]==t[i-1]&&i==s.length()-1)
            t[i-2]=t[i-2]+t[i-1];
        if(t[i]!=t[i-1])
            count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 11396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9 + 7;
const int inf = 1e10;

int main() {
	int N,K;
	cin>>N>>K;
	vector<int> h(N);
	rep(i,N)cin>>h[i];
	sort(all(h));
	int ans = inf;
	rep(i,N){
		if(i+K-1<N)ans = min(ans,h[i+K-1]-h[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

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

    int a;
    string s;

    cin >> a >> s;

    if(a < 3200) {
        s = "red";
    }


    cout << s << endl;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

Node root;

void insert(int key);
void inorder(Node );
void preorder(Node );
Node search(Node u,int k);

int main()
{
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if(com[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }
    if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    if(com[0] == 'f'){
      scanf("%d",&x);
      Node t = search(root,x);
      if ( t != NULL ) printf("yes\n");
      else printf("no\n");
    }
  }

  return 0;
}

void insert(int key)
{
  Node x,y,z;
  y = NULL;
  x = root;

  z = malloc(sizeof(struct node));
  z->key = key;
  z->right = NULL;
  z->left = NULL;

  while(x != NULL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NULL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u)
{

  if(u != NULL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}

void preorder(Node u)
{
  if(u != NULL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}

Node search(Node u,int k)
{
  if(u == NULL || k == u->key) return u;
  if(k < u->key) return search(u->left,k);
  else return search(u->right,k);
}



Measured memory_bytes: 20480
#include <bits/stdc++.h>
#define ll long long int
#define pr pair<ll, ll>
#define tp tuple<ll, ll, ll>
using namespace std;
long long int mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll k, n;
    cin >> k >> n;
    ll a[n + 1];
    for (ll i = 0; i < n; i++)
        cin >> a[i];
    if (n == 1)
        cout << 0 << endl;
    else if (n == 2)
        cout << min(a[1] - a[0], k - (a[1] - a[0])) << endl;
    else
    {
        a[n] = k + a[0];
        ll mini = INT_MAX;
        for (ll i = 1; i <= n; i++)
        {
            if (k - (a[i] - a[i - 1]) < mini)
                mini = k - (a[i] - a[i - 1]);
        }
        cout << mini << endl;
    }

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    double per = 0;
    for(int i = 1;i <= n;i++)
    {
        int score = i,count = 0;
        while(score < k)
        {
            score *= 2;
            count++;
        }
        per += 1.0 / n * pow(0.5,count);
    }
    cout << setprecision(15) << per;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {
	public static void main(String[] args){
		new Main().new P1127().run(); 
	}
	class P1127{
		void run(){
			Scanner sc=new Scanner(System.in);
			for(;;){
				int n=sc.nextInt();
				if(n==0)break;
				
				Pos[] p=new Pos[n];
				Queue<Node> q=new PriorityQueue<Node>();
				boolean[] visited=new boolean[n];
				int nvis=0;
				double ans=0;
				
				for(int i=0;i<n;i++){
					double x,y,z,r;
					x=sc.nextDouble();
					y=sc.nextDouble();
					z=sc.nextDouble();
					r=sc.nextDouble();
					p[i]=new Pos(x,y,z,r);
					visited[i]=false;
				}
				
				//Prim
				Node t=new Node(0,0);
				q.offer(t);
				while(nvis<n){
					t=q.poll();
					if(visited[t.node])continue;
					visited[t.node]=true;
					nvis++;
					ans+=t.d;
					for(int i=0;i<n;i++){
						if(!visited[i]){
							q.offer(new Node((p[t.node]).dist(p[i]),i));
						}
					}
				}
				System.out.printf("%.3f\n",ans);
			}
		}
	}
	class Pos{
		double x,y,z,r;
		Pos(double x_,double y_,double z_,double r_){
			this.x=x_;
			this.y=y_;
			this.z=z_;
			this.r=r_;
		}
		double dist(Pos o){
			double ret=Math.sqrt((x-o.x)*(x-o.x)+(y-o.y)*(y-o.y)+(z-o.z)*(z-o.z))-(r+o.r);
			return ret<=0?0:ret;
		}
	}
	class Node implements Comparable<Node>{
		double d;
		int node;
		public int compareTo(Node o){
			if(d<o.d)return -1;
			if(d==o.d)return 0;
			else return 1;
		}
		Node(double d_,int node_){
			this.d=d_;
			this.node=node_;
		}
	}
}

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

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";

int N, M;
vector<int> v[60];

int countPath(int node, vector<int> status) {

    int MAX = 0;
    for (int i = 0; i < N; i++) {
        MAX = max(MAX, status[i]);
    }

    if ( MAX == 0 ) {
        return 1;
    } else {
        int count = 0;
        for (int i = 0; i < v[node].size(); i++) {
            if ( status[v[node][i]] == 0 ) continue;
            vector<int> tempStatus = status;
            tempStatus[v[node][i]] = 0;
            count += countPath(v[node][i], tempStatus);
        }
        return count;
    }
}

int main() {

    cin >> N >> M;

    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    vector<int> status(N, 1);
    status[0] = 0;

    cout << countPath(0, status) << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

    public static void solve(Scanner sc){
        int N = sc.nextInt();
        int Y = sc.nextInt();

        for(int i=0;i<=N;i++){
            for(int j=0;j<=N-i;j++){
                int k = N - i - j;
                if(10000*i + 5000*j + 1000*k == Y){
                    System.out.printf("%d %d %d\n", i,j,k);
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }
}

Measured memory_bytes: 23636
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	long long a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	if(a*b*c % 2 == 0) printf("0\n");
	else {
		long long ans = min(a*b,min(a*c,b*c));
		printf("%lld\n",ans);
	}
}

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

using namespace std;

#define MAXN 2000000

int a[MAXN+5], l[MAXN+5], r[MAXN+5], idx[MAXN+5];

int main()
{
    int n;
    scanf("%d", &n);
    vector<int> v;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        l[i] = i-1, r[i] = i+1;
        idx[a[i]] = i;
        v.push_back(a[i]);
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for (int i = 0; i < n; ++i) {
        int p = idx[v[i]];
        while (a[p] >= v[i]) {
            p = l[p];
            l[idx[v[i]]] = p;
        }
        p = idx[v[i]];
        while (a[p] >= v[i]) {
            p = r[p];
            r[idx[v[i]]] = p;
        }
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += (long long)(r[i]-i)*(long long)(i-l[i])*(long long)a[i];
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 4340
#include <bits/stdc++.h>
#define CYES cout << "Yes" \
                  << "\n"
#define CNO cout << "No" \
                 << "\n"
#define CFS           \
    cin.tie(nullptr); \
    ios::sync_with_stdio(false);
#define CST(x) cout << fixed << setprecision(x)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
const int IINF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const string MM = " ";

bool test(string s) {
    bool flag = true;
    for (int i = 0; i < s.size() / 2; i++) {
        if (s[i] != s[s.size() - i - 1]) {
            flag = false;
            return flag;
        }
    }
    return flag;
}

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    if (test(s) && test(s.substr(0, (n - 1) / 2)) && test(s.substr((n + 3) / 2 - 1, n))) {
        CYES;
    }
    else {
        CNO;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if(a > 9 || b > 9) {
        cout << -1 << endl;
    } else {
        cout << a * b << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
    int A, B;

    cin >> A >> B;

    if ( B == 1 ) {
        cout << 0 << endl;
        return 0;
    }

    B -= A;
    int count = 1;
    while ( 1 ) {
        if ( B <= 0 ) break;
        B -= (A-1);
        count ++;
    }

    cout << count << endl;

    return 0;
}

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

int main() {
   int n;
  cin >> n;
  map<string, int> cnt;
  for (int i = 0; i < n; i++){
    string s ;
    cin >> s;
    cnt[s]++;
  }
  for(string x : {"AC", "WA", "TLE", "RE"}){
    cout << x << " x " << cnt[x] << endl;
  }  
  }


Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;
 
 
int main(){
    int n; cin >> n;
    ll k; cin >> k;
    ll K=k;
    int keta=0;
    string ks="";
    while(K){
        if(K%2==0) ks+='0';
        else ks+='1';
        K/=2;
        keta++;
    }
 
    int  b[41][2];
    rep(i,40)rep(j,2) b[i+1][j]=0;
    rep(i,n){
        ll a; cin >> a;
        rep(j,40){
            if(a%2==0) b[j+1][0]++;
            else b[j+1][1]++;
            a/=2;
        }
    }
    ll dp[41][2];
    if(k!=0){
        dp[keta][0]=b[keta][1]*pow(2,keta-1);
        dp[keta][1]=b[keta][0]*pow(2,keta-1);
        //cout << dp[keta][0] << ' ' << dp[keta][1] << endl;
        for(int j=keta-1; j>0; j--){
            ll ad=(ll)pow(2,j-1);
            if(ks[j-1]=='1'){
                dp[j][0]=max(dp[j+1][0]+max(b[j][0],b[j][1])*ad,dp[j+1][1]+b[j][1]*ad);
                dp[j][1]=dp[j+1][1]+b[j][0]*ad;
            }
            else{
                dp[j][0]=dp[j+1][0]+max(b[j][0],b[j][1])*ad;
                dp[j][1]=dp[j+1][1]+b[j][1]*ad;
            }
        }
    }
    else{
        dp[1][0]=dp[1][1]=0;
    }
    ll ans=0;
    for(int i=40; i>keta; i--){
        ans+=b[i][1]*pow(2,i-1);
    }
    cout << max(dp[1][0],dp[1][1])+ans << endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using llong = long long;
using ldouble = long double;

void fnInput(int& rnWide, int& rnHigh, int& rnx, int& rny)
{
  cin >> rnWide >> rnHigh >> rnx >> rny;
}

void fnRectCutArea(int nWide, int nHigh, int nx, int ny)
{
  llong nRectArea = (llong)nWide * nHigh;
  double nRectCutArea = nRectArea / 2.0;
  cout << nRectCutArea << " ";

  double nCenterx = nWide / 2.0;
  double nCentery = nHigh / 2.0;
  if (nCenterx == nx && nCentery == ny)
    cout << "1" << endl;
  else
    cout << "0" << endl;
}
  
int main()
{
  int nWide, nHigh, nx, ny;

  fnInput(nWide, nHigh, nx, ny);
  fnRectCutArea(nWide, nHigh, nx, ny);

  return 0;
}

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

int main()
{
  int n,m;
  for(;cin>>n>>m,n;)
    {
      m++;
      int time[m][m];
      int money[m][m];
      for(int i=0;i<m;i++)
	for(int j=0;j<m;j++)
	  {
	    if(i==j)
	      {
		time[i][j]=0;
		money[i][j]=0;
	      }
	    else
	      {
		time[i][j]=9999999;
		money[i][j]=9999999;
	      }
	  }
      for(int i=0;i<n;i++)
	{
	int a,b;
	cin>>a>>b;
	cin>>money[a][b]>>time[a][b];
	money[b][a]=money[a][b];
	time[b][a]=time[a][b];
	}
      for(int k=0;k<m;k++)
	for(int i=0;i<m;i++)
	  for(int j=0;j<m;j++)
	    {
	      time[i][j]=min(time[i][j],time[i][k]+time[k][j]);
	      money[i][j]=min(money[i][j],money[i][k]+money[k][j]);
	    }
      int k;
      cin>>k;
      for(int i=0;i<k;i++)
	{
	  int p,q,r;
	  cin>>p>>q>>r;
	  if(r==0)
	    cout<<money[p][q]<<endl;
	  else
	    cout<<time[p][q]<<endl;
	}
    }
}

Measured memory_bytes: 1240
import sys
from collections import *
import heapq
import math
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

dp=[[-1]*n for i in range(2)]
dp[0][-1]=abs(a[-1]-w)
# dp[-1][1]=abs(a[-2]-a[-1])
# print(dp)
for i in range(n-1):
    for j in range(2):
        if j==0:
            tmp=dp[1-j][-1-i:-1][:]
            tmp.append(abs(a[-2-i]-a[-1]))
            dp[j][-2-i]=min(tmp)
        else:
            tmp=dp[1-j][-1-i:-1][:]
            tmp.append(abs(a[-2-i]-a[-1]))
            dp[j][-2-i]=max(tmp)
        # print(i,j,tmp)
print(max(dp[0]))

Measured memory_bytes: 79304
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 500;

int main(void){
    ll N;
    ll c[MAX_N], s[MAX_N], f[MAX_N];
    ll dp[MAX_N][MAX_N];

    cin >> N;
    rep(i, N - 1) cin >> c[i] >> s[i] >> f[i];
    rep(i, N) dp[i][i] = 0;

    rep(i, N - 1){
        dp[i][i] = s[i];
        For(j, i + 1, N){
            if (s[j - 1] <= dp[i][j - 1]){
                if (dp[i][j - 1] % f[j - 1] == 0) dp[i][j] = dp[i][j - 1] + c[j - 1];
                else dp[i][j] = dp[i][j - 1] + f[j - 1] - (dp[i][j - 1] % f[j - 1]) + c[j - 1];
            }else{
                dp[i][j] = s[j - 1] + c[j - 1];
            }
        }
    }

    rep(i, N){
        cout << dp[i][N - 1] << endl;
    }

    return 0;
}

Measured memory_bytes: 2176
//https://atcoder.jp/contests/abc142/tasks/abc142_e
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N,M; cin>>N>>M; //Mがカギ
    struct Key{
        ll value=0;
        ll flag=0;
        void set(ll c){
            flag |= (1<<(c-1)); //1startなので
        }
        bool check(ll c){
            return (flag&(1<<(c-1)));
        }
    };
    vector<Key> keys(M+1);
    FOR(i,1,M+1){
        auto& k = keys.at(i);
        cin>>k.value;
        ll bn; cin>>bn; //開けれる数
        REP(o,bn){
            ll c; cin>>c;
            k.set(c);
        }
    }
    const ll num_box=12;
    //int dp[num_box+1][1<<(num_box+1)]; //どの箱まで?,flag
    vector<vector<ll>> dp(N+1,vector<ll>(1<<(N+1),INT32_MAX));
    dp[0][0]=0;
    FOR(i,1,N+1){
        for(ll pf=0;pf<(1<<N);++pf){
            if (pf&(1<<(i-1))) {
                dp[i][pf]=min(dp[i-1][pf], dp[i][pf]); 
            } else {
                for(auto& k:keys){
                    if (k.check(i)) {
                        ll nf = k.flag | pf;
                        dp[i][nf]=min<ll>(dp[i-1][pf]+k.value, dp[i][nf]);
                    }
                }
            }
        }
    }
    ll ans=dp[N][(1<<N)-1];
    cout<<(ans>=INT32_MAX?-1:ans)<<endl;
    return 0;
}

Measured memory_bytes: 1152
n = int(input())
a = list(map(int,input().split()))

m = 0
for i in a:
    if i < 0:
        m += 1

for i in range(n):
    a[i] = abs(a[i])

ans = 0
for i in range(n):
    ans += a[i]
if m%2 == 0:
    print(ans)
else:
    print(ans-2*min(a))

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

string join(vector<int> v, const char* delim = 0) {
  string s;
  if (!v.empty()) {
    s += to_string(v[0]);
    for (int i = 1, c = v.size(); i < c; ++i) {
      if (delim) s += delim;
      s += to_string(v[i]);
    }
  }
  return s;
}

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }

    bool flag = true;
    int count = 0;
    while (flag) {
        flag = false;
        for (int j = N-1; j >= 1; j--) {
            if (vec[j] < vec[j-1]) {
                count += 1;
                int tmp = vec[j];
                vec[j] = vec[j-1];
                vec[j-1] = tmp;
                flag = true;
            }
        }
    }

    const char* delim_ = " ";
    string answer = join(vec, delim_);
    answer.erase(answer.size() - std::char_traits<char>::length(delim_) + 1);
    answer.erase(0, answer.find_first_not_of(" \n\r\t"));
    cout << answer << endl;
    cout << count << endl;

    return 0;
}


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

int main( )
{
    int n, i, j, k, cnt = 0;
    string s, sub;
    cin >> n >> s;
    for (i = 2; i < n; i++) {
        sub = s.substr(i - 2, 3);
        if (sub == "ABC") {
            cnt++;
        }
    }
    cout << cnt << "\n";
    return 0;
}


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


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;

int lt, lx, ly;

int main () {
    cin >> n;
    For (i, 1, n) {
        int t, x, y;
        cin >> t >> x >> y;
        if (abs(lx - x) + abs(y - ly) > t - lt || (t - lt - abs(lx - x) - abs(y - ly)) % 2) {
            cout << "No";
            exit(0);
        }
        lt = t, lx = x, ly = y;
    }
    
    cout << "Yes";
	return Accepted;
}

// Coded By OB

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

class UnionFind{
    public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> parent;

    //-1で初期化
    //最初はすべてバラバラ
    UnionFind(int N){
        parent = vector<int>(N,-1);
    }

    //Aがどのグループに属しているか(Aの根)を調べる
    int root(int A){
        if(parent[A] < 0) return A;
        return parent[A]=root(parent[A]);
    }

    //自分のいるグループの頂点数を調べる
    int size(int A){
        return -parent[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B) {
    //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        //既にくっついているからくっつけない
        if(A == B) return false; 

        //大きいほう(A)に小さいほう(B)をくっつける
        //大証が逆ならひっくり返す
        if(size(A) < size(B)) swap(A,B);

        //Aのサイズを更新する
        parent[A] += parent[B];
        //Bの親をAに変更する
        parent[B] = A;

        return true;
    }

    //AとBが同じグループならtrueを返す
    bool same(int A, int B){
        return root(A)==root(B);
    } 
};

int main(){
    int n,m;
    cin>>n>>m;
    int p[n];
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    int x,y;
    UnionFind uni(n);
    for(int i=0;i<m;i++){
        cin>>x>>y;
        x--;
        y--;
        uni.connect(x,y);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(uni.same(i,p[i]-1)) ans++;
    }

    cout<<ans;


}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
int main(){
  int n,m,i,j,d[100010];
  char s[110][110];
  scanf("%d %*d",&n);
  for(i=0;i<n;i++){
    scanf("%s",s[i]);
    for(j=i;j&&strcmp(s[i],s[d[j-1]])<0;j--)d[j]=d[j-1];
    d[j]=i;
    //for(j=0;j<=i;j++)printf("%d ",d[j]);printf("\n");
  }
  for(i=0;i<n;i++)printf("%s",s[d[i]]);
  printf("\n");
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main()
{

    int n;
    long long int l[86];
    l[0]=2;l[1]=1;
    scanf("%d", &n);
    int cnt = 2;
    while(cnt<=n){
        l[cnt] = l[cnt-1]+l[cnt-2];
        cnt++;
    }
    printf("%lld\n",l[n]);
    return 0;
}


Measured memory_bytes: 128
<?php
list($t) = ints();
for ($i = 0; $i < $t; ++$i) {
    list($n) = ints();
    $a = ints();
    list($s) = strs();
    $ans[] = solve();
}
echo implode(PHP_EOL, $ans);
function solve()
{
    global $n, $a, $s;
    $base = [];
    for ($i = $n - 1; $i >= 0; --$i) {
        $x = $a[$i];
        foreach ($base as $b) $x = min($x, $x ^ $b);
        if ($x) {
            if ($s[$i] === '0') {
                $base[] = $x;
                rsort($base);
            } else {
                return 1;
            }
        }
    }
    return 0;
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


Measured memory_bytes: 16096
#include <stdio.h>
#include <string.h>
int main(){
  char a[11], b[11], c[11];

  scanf("%s%s%s", a, b, c);

  if(a[strlen(a) - 1] == b[0] && b[strlen(b) - 1] == c[0]){
    printf("YES");
  }else{
    printf("NO");
  }

  printf("\n");
  
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define P pair<int,int>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define re(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n;
    cin>>n;
    int a[n],b[n],c[n-1];
    int kai,mai,ans=0;
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        cin>>b[i];
    }
    rep(i,n-1){
        cin>>c[i];
    }
    mai=a[0];
    ans+=b[a[0]-1];
    
    for(int i=1;i<n;i++){
        kai=a[i];
        mai=a[i-1];
        ans+=b[a[i]-1];
        if(kai-mai==1){
            ans+=c[mai-1];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
s = input()
def pal(s):
  for i in range(len(s) // 2):
    #print(s[i], s[len(s) - i - 1])
    if s[i] != s[len(s) - i - 1]:
      return False
  else:
    return True

if pal(s) and pal(s[:(len(s) - 1) // 2]) and pal(s[(len(s) + 3) // 2 - 1:]):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38384
a,b,k=gets.split.map(&:to_i)
class Integer

  def divisor_list
    return [1] if self == 1
    (1..Math.sqrt(self).to_i).select do |i|
      self%i == 0
    end.map {|e| [e, self/e]}.flatten.uniq.sort
  end

end
p (a.divisor_list & b.divisor_list)[-k]


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

int main(){
  ll a,b ;
  cin >> a >> b ;
  vector<ll> mod ;
  for(ll i=a;i<=b;i++){
    if(i%2019==0){
      cout << 0 << endl ;
      return 0 ;
    }else{
      mod.push_back(i%2019) ;
    }
  }
  vector<ll> ans ;
  for(int i=0;i<mod.size()-1;i++){
    for(int j=i+1;j<mod.size();j++){
      ans.push_back(mod.at(i)*mod.at(j)%2019) ;
    }
  }
  sort(ans.begin(),ans.end()) ;
  cout << ans.at(0) << endl ;
}

Measured memory_bytes: 17532
/*

Author: @karngyan
Team: BlundersPride

*/

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
using namespace std;

using ll = long long;
using ld = long double;
using vll = std::vector< ll >;
using pll = std::pair< ll, ll >;
using vvll = std::vector<vll>;
using vpll = std::vector< pll >;


#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define eb emplace_back
#define rep(i, begin, end) for(__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define max3( a, b, c ) max( a , max(b , c))
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define cntll(a) __builtin_popcountll((a))
#define ff first
#define ss second
#define mk make_pair
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it){}
template<typename T , typename... Args>
void err(istream_iterator<string> it , T a , Args... args)
{
	cerr << *it << " = " << a << endl;
	err(++it , args ... );
}

ll sum(){ return 0; }
template<typename T, typename... Args>
auto sum(T a, Args... args){ return a + sum(args...);}
const ll MOD = 1e9+7;
////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll INF = 1e9+5;
ll n , kk;
vll a;
ll dp[50][50][105];

ll cnt = 0;

ll go(ll i , ll j , ll k){

	if(i >= n or j<0)
		return 0;

	if(k <= 0 or i>j){
		return 0;
	}

	if(i == j){
		return max(0ll , a[i]);
	}

	ll &ans = dp[i][j][k];
	if(ans != -1){
		return ans;
	}



	ll p , q , r = 0, s = 0;
	p = a[i] + go(i+1 , j , k-1);
	q = a[j] + go(i , j-1 , k-1);
	if(k > 1){	
		r = go(i+1 ,j , k-2);
		s = go(i , j-1 , k-2);
	}


	return ans = max(p , max(q , max(r , s)));
}

signed main()
{

	fast;
////////////////////////////////////////////////////////////////////////////////////////////


	cin >> n >> kk;
	cres(a , n);
	memset(dp, -1 , sizeof dp);

	// kk = min(n  ,kk);
	rep(i,0,n){
		cin >> a[i];
	}	

	cout<<go(0 , n-1 , kk)<<endl;

	
	return 0;
}


 	

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

#define ll long long
#define rep(i,N) for(ll i=0; i<N; i++)
const int mx = 2e5;


int main(void){

  ll N;
  cin >> N;
  
  ll ans=0;
  
  for(ll i=1; i<=N; i++){
    if((i%3)==0 || (i%5)==0){
    }else{
      ans += i;
    }
      
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	ld a, b, h, m;
	cin >> a >> b >> h >> m;
	ld dh = (h / 12 + m / 720) * 2 * pi;
	ld dm = m / 30 * pi;
	ld d = dh - dm;
	if (d < 0) d += 2 * pi;
	cout << sqrt(a * a + b * b - 2 * a*b*cos(d)) << '\n';
}

Measured memory_bytes: 4184
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int N,K;
int cum[2][100005];
int zero;

int main(){
  while(scanf("%d%d", &N,&K) && N||K){
    zero = 0;
    memset(cum, 0, sizeof cum);
    for(int i=0;i<K;i++){
      int x; scanf("%d", &x);
      if(x) cum[0][x] = cum[1][x] = 1;
      else zero = 1;
    }

    for(int i=1;i<=N;i++) if(cum[0][i]) cum[0][i] += cum[0][i-1];
    for(int i=N-1;i>=0;i--) if(cum[1][i]) cum[1][i] += cum[1][i+1];

    int res = 0;
    for(int i=0;i<=N;i++) res = max(res, cum[0][i]);
    if(zero){
      for(int i=1;i<=N;i++) if(!cum[0][i]){
	  res = max(res, cum[0][i-1]+cum[1][i+1]+1);
	}
    }
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 1816
n,k=map(int,input().split())
A=[0]*k
mod=10**9+7

def power(a,x): #a**xの計算
    T=[a]
    while 2**(len(T))<mod: #a**1,a**2.a**4,a**8,...を計算しておく
        T.append(T[-1]**2%mod)
    b=bin(x) #xを2進数表記にする
    ans=1
    for i in range(len(b)-2):
        if int(b[-i-1])==1:
            ans=ans*T[i]%mod
    return ans

for i in range(k):
    cnt=power(k//(k-i),n)
    now=(k-i)*2
    while now<=k:
        cnt-=A[now-1]
        now+=k-i
    A[k-i-1]=cnt

ans=0
for i in range(k):
    ans+=(i+1)*A[i]%mod
    ans%=mod
print(ans)

Measured memory_bytes: 69648
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
using namespace std;
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod (int)1e9+7
#define inf (int)1e16
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout<<endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
map<pair<string, int>, int>mp;
int n;
vector<string>v;
set<string>st;
signed main() {
	cin >> n;
	rep(i, n) {
		string s;
		int a;
		cin >> s >> a;
		mp[{s, a}] = i + 1;
		st.insert(s);
	}
	for (auto x: st) {
		v.push_back(x);
	}
	sort(all(v));
	rep(i, v.size()) {
		Rep(j, 100) {
			if (mp[{v[i], j}]) {
				cout << mp[{v[i], j}] << endl;
			}
		}
	}
}

Measured memory_bytes: 640
//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9+7;
const int maxn = 300002;
#define endl '\n'
#define int ll
#define ld long double
#define all(x) (x).begin(),(x).end()

int32_t main()
{ 
  IOS
   
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i = 0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  int ans = 0;
  for(int i = 0;i<k;i++)
    ans+=a[i];
  cout<<ans<<endl;
  
  
  
}

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

int money[4] ={10, 50, 100, 500};

int flag = false;

int main() {
  while (true) {
    int pay;
    cin >> pay;
    if (pay == 0) return 0;

    if (flag) cout << endl;

    int coin[4];
    for (int i = 0; i < 4; i++) {
      cin >> coin[i];
    }

    int sum = 0;
    for (int i = 0; i < 4; i++) {
      sum += coin[i] * money[i];
    }

    int extra[4];
    int spare = sum - pay;
    for (int i = 3; i >= 0; i--) {
      int temp = spare / money[i];
      extra[i] = temp;
      spare -= temp * money[i];
    }

    for (int i = 0; i < 4; i++) {
      coin[i] -= extra[i];
      if (coin[i] < 0) coin[i] = 0;
    }

    for (int i = 0; i < 4; i++) {
      if (coin[i]) {
	cout << money[i] << ' ' << coin[i] << endl;
      }
    }
    flag = true;
  }
}

Measured memory_bytes: 3008
a,b,k=gets.split.map(&:to_i)

k.times {|i|
  if i%2==0
    if a%2==0
    else
      a=a-1
    end
    b=b+a/2
    a=a/2
  else
    if b%2==0
    else
      b=b-1
    end
    a=a+b/2
    b=b/2
  end
}
puts "#{a} #{b}"


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




string _s; int _n; int sa_k;
vector<int> Rank, tmp, sa, lcp;
bool cmp_sa(int i, int j) {
	if (Rank[i] != Rank[j]) return Rank[i]<Rank[j];
	return (i + sa_k <= _n ? Rank[i + sa_k] : -1)<(j + sa_k <= _n ? Rank[j + sa_k] : -1);
}
void construct_sa() {
	for (int i = 0; i <= _n; i++) { sa[i] = i; Rank[i] = i<_n ? _s[i] : -1; }
	for (sa_k = 1; sa_k <= _n; sa_k *= 2) {
		sort(sa.begin(), sa.end(), cmp_sa); tmp[sa[0]] = 0;
		for (int i = 1; i <= _n; i++) tmp[sa[i]] = tmp[sa[i - 1]] + (cmp_sa(sa[i - 1], sa[i]) ? 1 : 0);
		for (int i = 0; i <= _n; i++) Rank[i] = tmp[i];
	}
}
void construct_lcp() {
	for (int i = 0; i <= _n; i++) Rank[sa[i]] = i;
	int h = 0; lcp[0] = 0;
	for (int i = 0; i<_n; i++) {
		int j = sa[Rank[i] - 1]; if (h>0) h--;
		for (; j + h<_n&&i + h<_n; h++) if (_s[j + h] != _s[i + h]) break; lcp[Rank[i] - 1] = h;
	}
}
void init(string s) {
	_s = s;	_n = s.length();
	Rank = vector<int>(_n + 1); tmp = vector<int>(_n + 1);
	sa = vector<int>(_n + 1); lcp = vector<int>(_n + 1);
	construct_sa(); construct_lcp();
}
bool chk(string s) {
	int lo = 0, hi = _n + 1;
	while (lo + 1 != hi) {
		int md = (lo + hi) / 2;
		if (s <= _s.substr(sa[md], s.length())) hi = md;
		else lo = md;
	}
	
	string t = _s.substr(sa[hi], s.length());
	return s == t;
}
//-----------------------------------------------------------------------------------
int N;
string S[101010];
//-----------------------------------------------------------------------------------
#define rrep(i,a,b) for(int i=a;i>=b;i--)
string nxt(string x) {
	int carry = 1;
	rrep(i, x.length() - 1, 0) {
		int n = x[i] - 'a' + carry;
		carry = 0;
		if (26 <= n) {
			n %= 26;
			carry = 1;
		}
		x[i] = 'a' + n;
	}
	if (carry) x = "a" + x;
	return x;
}
//-----------------------------------------------------------------------------------
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	cin >> N; rep(i, 0, N) cin >> S[i];

	string SS = "";
	rep(i, 0, N) SS += "#" + S[i];
	init(SS);

	string ans = "a";
	while (chk(ans)) ans = nxt(ans);
	cout << ans << endl;
}

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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const ll NN = 1e10 + 7;
const int N = 5e5 + 7;
const int M = 11;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

void solve1()
{
    int k;
    cin >> k;
    queue < ll > q;
    for( int i = 1; i <= 9; i++ ){
        q.push(i);
    }
    int ans = 0;
    while( !q.empty() ){
        ll x = q.front();
        ans += 1;
        if( ans == k ){
            cout << x;
            return;
        }
        q.pop();
        if( x % 10 != 0 )q.push( x * 10 + (x % 10 - 1) );
        q.push(10 * x + x % 10);
        if( x % 10 != 9 )q.push(10 * x + x % 10 + 1);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(void) {
  int n, a, b;
  cin >> n >> a >> b;
  string s;
  cin >> s;
  int pass = 0, f = 0;
  string ans = "Yes";
  rep(i, n) {
    if (pass >= a + b) {
      ans = "No";
    } else if (s[i] == 'a') {
      ans = "Yes";
      pass++;
    } else if (s[i] == 'b') {
      if (f < b) {
        ans = "Yes";
        pass++;
        f++;
      } else {
        ans = "No";
      }
    } else {
      ans = "No";
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 896