akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int M, K;
  cin >> M >> K;
  int N = 1 << M;
  if (M == 1) {
    if (K != 0) {
      cout << -1 << endl;
    } else {
      cout << "0 0 1 1" << endl;
    }
    return 0;
  }
  if (K >= N){
    cout << -1 << endl;
    return 0;
  }
  if (K == 0) {
    cout << "0 0";
    for (int i=1; i<N; i++) {
      cout << ' ' << i << ' ' << i;
    }
    cout << endl;
    return 0;
  }
  set<int> s;
  for (int i=0; i<M; i++) {
    int d = 1 << i;
    if (K & d) s.insert(d);
  }
  cout << 0;
  for (auto it = s.begin(); it != s.end(); ++it) {
    cout << ' ' << *it;
  }
  cout << ' ' << 0;
  if (s.size() > 1) {
    cout << ' ' << K;
    for (auto it = s.rbegin(); it != s.rend(); ++it) {
      cout << ' ' << *it;
    }
    s.insert(K);
  }
  for (int i=1; i<N; i++) {
    if (s.find(i) == s.end()) {
      cout << ' ' << i;
    }
  }
  cout << ' ' << K;
  for (int i=N-1; i>=1; i--) {
    if (s.find(i) == s.end()) {
      cout << ' ' << i;
    }
  }
  cout << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;
import java.util.Stack;

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

    Stack<Integer> main = new Stack<>();

    while(scan.hasNext()) {
      String inputString = scan.next();
      char[] input = inputString.toCharArray();
      if(input[0]>='0'&&input[0]<='9') {
        main.push(Integer.parseInt(inputString));
      }else {
        if(input[0]=='+') {
          main.push(main.pop()+main.pop());
        }else if(input[0]=='-') {
          main.push(-main.pop()+main.pop());
        }else {
          main.push(main.pop()*main.pop());
        }
      }
    }
    System.out.println(main.pop());
  }
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, c, k, b=1, tc=0, tk;
  cin >> n >> c >> k;
  vecll t(n);
  forll(i, 0, n)
	cin >> t[i];
  sort(t.begin(), t.end());
  tk = t[0];
  forll(i, 0, n){
	if (tc == c || t[i] - tk > k){
	  b++;
	  tc = 1;
	  tk = t[i];
	  continue;
	}
	tc++;
  }
  cout << b << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,K,R,S,P;
    string T;
    cin >> N >> K >> R >> S >> P;
    cin >> T;
    
    vector<char> G[114514];
    REP(i,T.size()){
        G[i%K].push_back(T[i]);
    }
    int Ans=0;
    /*REP(i,K){
        REP(j,G[i].size()){
            cout << G[i][j];
        }cout << endl;
    }*/
    REP(i,K){
        REP(j,G[i].size()){
            if(j==0 || G[i][j]!=G[i][j-1]){
                if(G[i][j]=='r'){
                    Ans+=P;
                }else if(G[i][j]=='s'){
                    Ans+=R;
                }else{
                    Ans+=S;
                }
            }else{
                G[i][j]='x';
            }
        }
    }
    cout << Ans << endl;
    return 0;
}



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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    long long a;
    double b;
    cin >> a >> b;
    long long c = 100*b + 0.0001;
    long long ans = a*c/100;
    cout << ans << endl;
}



Measured memory_bytes: 3740
# AOJ 0565
# JOI 2010/2011 yo-t1

p = 2000
j = 2000
3.times do
  d = gets.chomp.to_i
  p = d if d < p
end
2.times do
  d = gets.chomp.to_i
  j = d if d < j
end
puts p+j-50

Measured memory_bytes: 6088
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
int main(){
	int inp, arr[11];   
	REP(i,3) cin >> inp, ++arr[inp];
	if(arr[7]==1 and arr[5]==2) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int a, b;
    cin >> a >> b;

    string x = "";
    rep(i, b) {
        x += '0' + a;
    }

    string y = "";
    rep(i, a) {
        y += '0' + b;
    }

    if(x < y) {
        cout << x << endl;
    } else {
        cout << y << endl;
    }

    return 0;
}


Measured memory_bytes: 3576
from collections import deque
import copy
H,W=map(int,input().split())

inf=1000000000
field=[]
for i in range(H):
  row=list(input())
  for j in range(len(row)):
    if row[j]=='#':row[j]=-1
    else:row[j]=inf
  field.append(row)
ans=inf

def isIn(x,y):
  if x<0 or x>=W:return False
  if y<0 or y>=H:return False
  return True
vector=[[0,1],[0,-1],[1,0],[-1,0]]
ans=0
for i in range(H):
  for j in range(W):
    if field[i][j]==-1:continue
    l=deque([[j,i]])
    f=copy.deepcopy(field)
    f[i][j]=0
    tmp=0
    #print('--start--')
    while l:
      x,y=l.popleft()
      #print(x,y)
      #i,jを訪問
      for v in vector:
        if not isIn(x+v[1],y+v[0]):continue
        if f[y+v[0]][x+v[1]]<=tmp:continue
        f[y+v[0]][x+v[1]]=f[y][x]+1
        l.append([x+v[1],y+v[0]])
        tmp=max(f[y+v[0]][x+v[1]],tmp)
    ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 9624
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        Integer[] inputs = readInput();
        System.out.println(xCubic(inputs[0]));
    }

    public static int xCubic(int x) {
        return x * x * x;
    }

    public static Integer[] readInput() {
        List<Integer> l = new ArrayList<Integer>();
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            l.add(sc.nextInt());
        }
        return l.toArray(new Integer[l.size()]);
    }
}

Measured memory_bytes: 26128
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
priority_queue<pii, vector<pii>, greater<pii>> pq;

int main(){
    int N;cin>>N;
    for(int i=0;i<N;i++) {
        int x, y;
        cin>>x>>y;
        pq.push(make_pair(y, x));
    }
    int c = 1;
    pii p = pq.top();pq.pop();
    int t = p.first;
    while(!pq.empty()){
        pii p = pq.top();pq.pop();
        if(t<p.second) c++,t = p.first;
    }cout<<c<<endl;
}


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
int main(){
  int xx[4]={-1,1,0,0};
  int yy[4]={0,0,-1,1};
  int h,w;cin>>h>>w;
  string s[h];
  for(int i=0;i<h;i++) cin>>s[i];
  int cnt=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='.') cnt++;
    }
  }
  bool bo[h][w];
  int c[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      c[i][j]=100000000;
      bo[i][j]=false;
    }
  }
  c[0][0]=0;
  queue<int>qx;
  queue<int>qy;
  queue<int>qn;
  qx.push(0);qy.push(0);qn.push(0);
  bo[0][0]=true;
  while(qx.size()>0){
    int x=qx.front();
    int y=qy.front();
    int n=qn.front();
    qx.pop();qy.pop();qn.pop();
    for(int i=0;i<4;i++){
      int fy=y+yy[i];int fx=x+xx[i];
      if(bo[fy][fx])continue;
      
    if(fy>=h||fy<0||fx>=w||fx<0) continue;
    if(s[fy][fx]=='#')continue;
    if(fx==w-1&&fy==h-1){
      cout<<cnt-n-2<<endl;
      
      return 0;
    }
      bo[fy][fx]=true;
    qx.push(fx);qy.push(fy);qn.push(n+1);
    }
  }
  
  cout<<-1<<endl;
  
  
}
    




Measured memory_bytes: 256
import java.io.*;
public class Main
{
  public static void main(String args[]) throws IOException
  {
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      
      int i,N,A,B,sum=0,c,copy;
      
      //System.out.println();
      
      String s[]=br.readLine().trim().split(" ");
      
      N=Integer.parseInt(s[0]);
      A=Integer.parseInt(s[1]);
      B=Integer.parseInt(s[2]);
      
      for(i=1;i<=N;i++)
      {
          copy=i;
          c=0;
          while(copy>0)
          {
              c+=copy%10;
              copy/=10;
          }
          
          if(c>=A&&c<=B)
          sum+=i;
      }
      System.out.println(sum);
    }
}

Measured memory_bytes: 21332
#include <vector>
#include <cstdio>
#include <cmath>
#include <string>
#include <iostream>
using namespace std;

string st(char c, int n)
{
	string ans;
	for (int i = 0; i < n; ++i) {
		ans += c;
	}
	return ans;
}

int main(void)
{
	int x, y, s, t;

	cin >> x >> y >> s >> t;

	string str;

	str += st ('R', s - x);
	str += st('U', t - y);
	str += st('L', s - x);
	str += st('D', t - y + 1);
	str += st('R', s - x + 1);
	str += st('U', t - y + 1);
	str += 'L';
	str += 'U';
	str += st('L', s - x + 1);
	str += st('D', t - y + 1);
	str += 'R';

	cout << str << endl;

	return 0;
}

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

#define endl '\n'

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

    int a, b;
    cin >> a >> b;
    int res = (a + b) / 2 + ((a + b) % 2 == 0 ? 0 : 1);
    cout << res;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        boolean check = true;
        if (N >= 2) {
            while (N > 0) {
                ans++;
                N = N / 2;
            }
        } else {
            check = false;
        }
        if (check == false) {
            System.out.println(N);
        } else {
            System.out.println((int)Math.pow(2,(ans - 1)));
        }
    }

}

Measured memory_bytes: 21844
#![allow(unused_mut, non_snake_case, unused_imports, dead_code)]

use std::iter;
use std::cmp::{max, min, Ordering};
use std::mem::swap;
use std::collections::{HashMap, BTreeMap, HashSet, BTreeSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut 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)*}};}
//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)*}};}
//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, 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")};}
// 低速 EOF不要
macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

// 非常時
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

fn main() {
    input!(AB:i32,BC:i32,CA:i32);
    println!("{}",AB*BC/2);
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main(){
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	if (x-r>=0&&y-r>=0&&x+r<=w&&y+r<=h )
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}













}
	




Measured memory_bytes: 3112
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define MAX 200

void push(int);
int pop1(void);

int top = 1;
int s[MAX];

int main(){
  int x,a,b;
  char stack[MAX];

  while(1){
    if(scanf("%s", stack) == EOF) break;
    if ( stack[0] == '+' )
      {
        a= pop1();
        b= pop1();
        push(b+a);
      }
    else if ( stack[0] == '-' )
      {
        a=pop1();
        b=pop1();
        push(b-a);
      }
    else if ( stack[0] == '*' )
      {
        a=pop1();
        b=pop1();
        push(b*a);
      }
    else
      {
        x = atoi(stack);
        push(x);
      }
  }
  printf("%d\n",pop1());
  return 0;
  }

  void push(int x)
  {
    if(top >= MAX - 1)
      {
        printf("Overflow!\n");
        exit(1);
      }
    top++;
    s[top] = x;
  }

  int pop1(void)
  {
    if(top == 0)
      {
        printf("Underflow!\n");
        exit(1);
      }
    return s[top--];
  }



Measured memory_bytes: 2108
import collections

N = int(input())
v = list(map(int,input().rstrip().split()))
list_odd = v[0::2]
list_even = v[1::2]

odd_count = collections.Counter(list_odd).most_common()
even_count = collections.Counter(list_even).most_common()

if len(odd_count) == 1 and len(even_count) == 1:
    if odd_count[0][0] == even_count[0][0]:
        print(N//2)
    else:
        print(0)
elif odd_count[0][0] != even_count[0][0]:
    print(N-odd_count[0][1]-even_count[0][1])
elif len(odd_count) == 1:
    print(N//2-even_count[1][1])
elif len(even_count) == 1:
    print(N//2-odd_count[1][1])
else:
    print(min(N-odd_count[0][1]-even_count[1][1], N-even_count[0][1]-odd_count[1][1]))

Measured memory_bytes: 21084
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		boolean good = true;
		for(int i=0;i<3;i++) {
			if(s.charAt(i)==s.charAt(i+1)) {
				good = false;
				break;
			}
		}
		System.out.println(good?"Good":"Bad");
		in.close();
	}

}


Measured memory_bytes: 23636
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] str = sc.nextLine().split(" ");
        int a = Integer.parseInt(str[0]);
        int b = Integer.parseInt(str[1]);
        
        if (a <= b) {
        	System.out.println(a);
        } else if (a > b) {
        	System.out.println(a - 1);
        }
    }
    
}

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

n1 = 8*N+1
a = int(n1**0.5)

if N==1:
    print("Yes")
    print(2)
    print(1, 1)
    print(1, 1)
elif N>=3 and n1==a**2:
    n = (-3+a)//2
    if (-3+a)%2:
        print("No")
    else:
        d = [[0]*(n+1) for _ in range(n+2)]
        d[0][0] = 1
        d[0][1] = 2
        d[1][0] = 2
        d[1][1] = 3
        d[2][0] = 3
        d[2][1] = 1
        for i in range(1, n):
            v = 4+((i-1)*(i+4)//2)
            c = 2+i

            for j in range(c):
                d[c][j] = v+j
                d[j][c-1] = v+j

        print("Yes")
        print(n+2)
        for i in range(n+2):
            print(n+1, *d[i], sep=" ")
else:
    print("No")

Measured memory_bytes: 12376
n=int(input())
c=list(map(int, input().split()))
ans = 0

for i in range(n-1):
    if c[i] == i+1 :
        c[i],c[i+1]= c[i+1],c[i]
        ans += 1
if c[n-1] == n:
    ans += 1
print(ans)

Measured memory_bytes: 20640
#include <iostream>
#include <algorithm>
#include <vector>

int v[55]={11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,
			1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381};

int main(){
	int n;
	std::cin>>n;
	for(int x=0;x<n;x++){
		std::cout<<v[x]<<" ";
	}
	std::cout<<std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fatafat                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define int long long
#define MOD ((long long)(1e9) + 7)
#define excl(i, a, b) for (int i = a; i < b; i++)
#define incl(i, a, b) for (int i = a; i <= b; i++)
#define mp(a, b) make_pair(a, b)
#define ff first
#define ss second
#define PII pair<int, int>

using namespace std;

int binexp(int a, int b) {
  if (b) {
    if (b % 2)
      return a * binexp(a * a, b / 2);
    return binexp(a * a, b / 2);
  }
  return 1;
}

int modexp(int a, int b, int m) {
  if (b) {
    if (b % 2)
      return (a * modexp((a * a) % m, b / 2, m)) % m;
    return modexp((a * a) % m, b / 2, m);
  }
  return 1;
}

int mygcd(int a, int b) {
  if (b == 0)
    return a;
  return mygcd(b, a % b);
}

int euclidgcd, euclidx, euclidy;

void exteuclid(int a, int b) {
  if (b == 0) {
    euclidgcd = a;
    euclidx = 1;
    euclidy = 0;
  } else {
    exteuclid(b, a % b);
    int temp = euclidx;
    euclidx = euclidy;
    euclidy = temp - euclidy * (a / b);
  }
}

int modinv(int a, int m) {
  exteuclid(a, m);
  return (euclidx % m + m) % m;
}

int pmodinv(int a, int m) { return modexp(a, m - 2, m); }

bool checkprime(int a) {
  for (int i = 2; i * i <= a; i++)
    if (a % i == 0)
      return false;
  return true;
}

vector<bool> seive(int n) {
  vector<bool> ret(n + 1, true);
  ret[0] = ret[1] = false;
  for (int i = 2; i * i <= n; i++)
    if (ret[i])
      for (int j = i * i; j <= n; j += i)
        ret[j] = false;
  return ret;
}

vector<bool> seivelims(int l, int r) {
  vector<bool> ret(r - l + 1, true);
  for (int i = 2; i * i <= r; i++) {
    for (int j = max(i * i, ((l + i - 1) / i) * i); j <= r; j += i) {
      ret[j - l] = false;
    }
  }
  return ret;
}

vector<int> rootnfact(int n) {
  vector<int> ret;
  for (long i = 2; i * i <= n; i++)
    while (n % i == 0) {
      ret.push_back(i);
      n /= i;
    }
  if (n != 1)
    ret.push_back(n);
  return ret;
}

vector<int> prelognfact(int n) {
  vector<int> minprime(n + 1, 0);
  minprime[0] = minprime[1] = 0;
  for (int i = 2; i * i <= n; i++) {
    if (minprime[i] == 0) {
      for (int j = i * i; j <= n; j += i) {
        if (minprime[j] == 0)
          minprime[j] = i;
      }
    }
  }
  for (int i = 2; i <= n; i++)
    if (minprime[i] == 0)
      minprime[i] = i;
  return minprime;
}

vector<int> lognfact(int n, vector<int> minprime) {
  vector<int> ret;
  while (n != 1) {
    ret.push_back(minprime[n]);
    n /= minprime[n];
  }
  return ret;
}

int temp, temp1, temp2;

signed main() 
{ 
    fatafat; 
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int max=-1,cnt=0;
    for(int i=0;i<n;i++)
    {
        if(max<=arr[i])
        {
            max=arr[i];
            cnt++;
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<random>
#include<numeric>
#include<string>
#include<cstring>
typedef long long ll;
typedef long double ld;
using namespace std;
ll dx[] = { 0,0,1,-1 };
ll dy[] = { 1,-1,0,0 };

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll D, N;
	cin >> D >> N;
  	if(D==0&&N<100)
		cout<<N<<endl;
  	else if(D==0&&N==100)
      cout<<101<<endl;
  	else if(D==1&&N<100)
      cout<<100*N<<endl;
  	else if(D==1&&N==100)
      cout<<10100<<endl;
  	else if(D==2&&N<100)
      cout<<N*10000<<endl;
  	else 
  	cout<<1010000<<endl;
}


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

using namespace std;

int main(int argc, char const *argv[]) {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  int length = S.length();

  vector<int> m(0);
  if (S[0] == '0') {
    m.push_back(0);
  }

  int count = 1;
  for (int i = 1; i < length; i++) {
    if (S[i] != S[i - 1]) {
      m.push_back(count);
      count++;
    } else {
      count++;
    }

    if (i == length - 1) {
      m.push_back(count);
    }
  }

  if (S[length - 1] == '0') {
    m.push_back(m[m.size() - 1]);
  }

  int M = m.size();

  int max = 0;
  for (int i = 0; i <= M - 2 * K - 1; i += 2) {
    if (max < m[i + 2 * K] - m[i - 1]) {
      max = m[i + 2 * K] - m[i - 1];
    }
  }

  if (M <= 2 * K + 1) {
    max = length;
  }

  cout << max << "\n";
  return 0;
}


Measured memory_bytes: 1020
x, n = map(int, input().split())
p = list(map(int, input().split()))
if x not in p:
    print(x)
else:
    for i in range(1, n+1):
        if x-i not in p:
            print(x-i)
            break;
        if x+i not in p:
            print(x+i)
            break;

Measured memory_bytes: 9116
#include<iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main() {
  int A, B, T;
  cin >> A >> B >> T;
  cout << (int)(((float)T + 0.5f) / (float)A) * B  << endl;
}

Measured memory_bytes: 256
#include<set>
#include<queue>
#include<cstdio>

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

using namespace std;

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

struct data{
	int S;
	int x,y;
	bool operator<(const data &D)const{
		if(S!=D.S) return S<D.S;
		if(x!=D.x) return x<D.x;
		return y<D.y;
	}
};

int n;

data next_state(int S,int x,int y){
	S|=1<<y*n+x;
	int T=0;
	rep(i,n) rep(j,n) {
		int cnt=0;
		rep(k,8){
			int yy=i+dy[k],xx=j+dx[k];
			if(0<=yy && yy<n && 0<=xx && xx<n && S&(1<<yy*n+xx)) cnt++;
		}
		if(S&(1<<i*n+j)){
			if(cnt==2 || cnt==3) T|=1<<i*n+j;
		}
		else{
			if(cnt==3) T|=1<<i*n+j;
		}
	}
	T&=~(1<<y*n+x);
	return (data){T,x,y};
}

int main(){
	for(;scanf("%d",&n),n;){
		data ini={};
		rep(i,n){
			char s[6]; scanf("%s",s);
			rep(j,n){
				if(s[j]=='#') ini.S|=1<<(i*n+j);
				if(s[j]=='@') ini.x=j, ini.y=i;
			}
		}

		int ans=-1;
		set<data> Vis;
		queue< pair<int,data> > Q; Q.push(make_pair(0,ini));
		while(!Q.empty()){
			int t=Q.front().first;
			data D=Q.front().second; Q.pop();

			if(t>15) break;

			if(Vis.count(D)>0) continue;
			Vis.insert(D);

			if(D.S==0){ ans=t; break; }

			rep(k,8){
				int yy=D.y+dy[k],xx=D.x+dx[k];
				if(0<=yy && yy<n && 0<=xx && xx<n && (D.S&(1<<yy*n+xx))==0){
					Q.push(make_pair(t+1,next_state(D.S,xx,yy)));
				}
			}
		}

		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, a) for(i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
using namespace std;
int main() {
    int a;
    cin >> a;
    cout << (a - 1) / 2 + 1;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a,b,c,lec=0,loz=0;
	for(;;){
		if(scanf("%d,%d,%d",&a,&b,&c) == EOF){break;}
		if(a*a+b*b == c*c){lec++;}
		else if(a == b){loz++;}
	}
	printf("%d\n%d\n",lec,loz);
	return 0;
}

Measured memory_bytes: 596
fun judge(n: Int): Int {
	var result = 0
	var j = n
	for (i in 1 .. n.toString().length) {
		result += j % 10
		j /= 10
	}
	return result
}

fun main(args: Array<String>) {
	val (N, A, B) = readLine()!!.split(" ").map(String::toInt)
	var ans = 0

	for (i in 1 .. N) {
		if (judge(i) in A .. B) {
			ans += i
		}
	}
	println(ans)
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define MOD 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

pair<long double, long double> hoge(long double x1, long double y1, long double x2, long double y2)
{
    long double b = (x2 * y1 - x1 * y2) / (x2 - x1);
    long double a = (y1 - b) / x1;
    return make_pair(a, b);
}

int main()
{
    int n;
    cin>>n;
    cout<<180*(n-2)<<endl;
    return 0;
}


Measured memory_bytes: 256
/*
░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░
░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░
░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░
░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░
░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░
░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░
░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░
░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░
░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░
░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░
░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░
░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░
░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██
░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█
░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀
░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░
░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░
█▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░
█░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
const ll mod = 1000000007;
const ll nmax=100010;
int n;
bool a[200002];
bitset<200002> b;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n;
    for(int i=1; i<=n; i++) cin>>a[i];
    for(int i=n; i>=1; i--){
		if(2*i>n) b[i]=a[i];
		else{
			int ctrl=0;
			for(int cur=2*i; cur<=n; cur+=i) ctrl+=b[cur];
			ctrl%=2;
			b[i]=(a[i]-ctrl+2)%2;
		}
	}
	cout<<b.count()<<"\n";
	for(int i=1; i<=n; i++) if(b[i]) cout<<i<<" ";
}


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


bool cmp(pair< int, int> &a, pair< int, int> &b) {
    return a.second * b.first > a.first * b.second;
}

int main() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;


    vector< int> water, sugar;
    for (int i = 0; ; i++) {
        if (i * a > f) break;
        for (int j = 0; ; ++j) {
            if (i == 0 and j == 0) continue;
            if (i * a + b * j > f) break;
            water.emplace_back(i * a * 100 + b * j * 100);
        }
    }

    for (int i = 0; ; i++) {
        if (i * c > f) break;
        for (int j = 0; ; ++j) {
            if (i * c + d * j > f) break;
            sugar.emplace_back(i * c + d * j);
        }
    }

    sort(begin(water), end(water));
    sort(begin(sugar), end(sugar));
    water.erase(unique(water.begin(), water.end()), water.end());
    sugar.erase(unique(sugar.begin(), sugar.end()), sugar.end());

    vector< pair< int, int> > Vp;

    for (int x : water) {
        int sugar_limit = min(f - x, e * x / 100);
        auto it = upper_bound(sugar.begin(), sugar.end(), sugar_limit);
        if (it != sugar.begin()) {
            it--;
            Vp.emplace_back(x + (*it), *it);
        }
    }

    sort(Vp.begin(), Vp.end(), cmp);
    cout << Vp[0].first << ' ' << Vp[0].second << endl;
}

Measured memory_bytes: 2804
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

//つねに10億7などの剰余をとる構造体
//参考: https://www.youtube.com/watch?v=L8grWxBlIZ4&t=9858
//参考: https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an
int mod  = MODA;
struct modint {
	ll x;
	modint (ll x):x(x%mod){}
	modint& operator+=(const modint a){
		(x += a.x ) %= mod;
		return *this;
	}
	modint& operator-=(const modint a){
		(x -= a.x ) %= mod;
		if (x < 0) x += mod;
		return *this;
	}
	modint& operator*=(const modint a){
		(x *= a.x ) %= mod;
		return *this;
	}
	modint& operator/=(modint a){ //除算のみO(log mod)なので注意。割る数が小さいならnCrのinvを使うこと
		ll exp = mod - 2;
		while(exp > 0){ 
			if(exp & 1) *this *= a.x;
			a *= a.x;
			exp >>= 1;
		}
		return *this;
	}
	modint operator+(const modint a) const{
		modint res(*this);
		return res+=a;
	}
	modint operator-(const modint a) const{
		modint res(*this);
		return res-=a;
	}
	modint operator*(const modint a) const{
		modint res(*this);
		return res*=a;
	}
	modint operator/(const modint a) const{
		modint res(*this);
		return res/=a;
	}
};
modint modpow(modint x, ll n){
	modint res=1;
	while(n > 0){
		if(n & 1) res = res * x.x;
		x = x * x;
		n >>= 1;
	}
	return res;
}


//さらにnCrのために、x!とその逆元を配列で持つ
const int NMAX = 500000; // 10^7くらいまではいけそう
ll fact[NMAX], finv[NMAX], inv[NMAX];

void ncr_init(){ //はじめにinitすること
	fact[0] = fact[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i = 2; i < NMAX; i++){
		fact[i] = fact[i-1] * i % MODA;
		inv[i] = MODA - inv[MODA%i] * (MODA / i) % MODA;
		finv[i] = finv[i-1]* inv[i] % MODA;
	}
}
ll ncr(int n, int r){
	if(n<r) return 0;
	if(n<0 || r<0) return 0;
	return fact[n] * (finv[n-r] * finv[r] % MODA) % MODA;
}
//
ll sigpr[NMAX];
void sig_init(){
	sigpr[0] = sigpr[1] = 1;
	for(int i = 2; i < NMAX; i++){
		sigpr[i] = (sigpr[i-1] + inv[i]) % MODA;
	}
}

int main() {
	modint ans = 0;
	ll tmp;
	int n; cin >> n;
	vector<ll> x(n);
	cin >> x;
	ncr_init();
	sig_init();
	REP(i, n-1) ans += (x[i+1] - x[i]) * sigpr[i+1];
	ans *= fact[n-1];
	cout << ans.x << endl;
}

Measured memory_bytes: 19544
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;



int main() {
    
    ll n;
    cin>>n;
    string ans;
    ll B=1;
    int keta=1;
    for(int i=1;;i++){
        if(B+pow(26,i)<=n){
            B+=pow(26,i);
            keta++;
        } else break;
    }
    n-=B;
    while(n>0){
        ans+=char(n%26+'a');
        n/=26;
    }
    while(ans.size()<keta)ans+='a';
    reverse(all(ans));
    // rep(i,ans.size()){
    //     if(ans[i]=='a')ans[i]='z';
    //     else ans[i]--;
    // }
    fin(ans);
}


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

//wierd debugging stuff
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << "\n" ; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//end of weird debugging stuff
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
 
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define fo(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define foe(i,x) for(auto& i: x)
#define ar array
#define pb push_back
#define vt vector
#define F first
#define S second

template<class T> bool umin(T& a,const T& b){return b<a?a=b,1:0;}
template<class T> bool umax(T& a,const T& b){return b>a?a=b,1:0;}

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {cin>>x;}
void read(double& d) {string t;read(t);	d=stod(t);}
void read(long double& d) {	string t;read(t);d=stold(t);}
template<class H, class... T> void read(H& h, T&... t) {read(h);read(t...);}
template<class A> void read(vt<A>& x) {	foe(a, x)read(a);}
int nxt(){int a;read(a);return a;}   // iota(all(v),0); genrate(all(v),nxt);

// no change 
const ll MOD = 1e9+7;  
int mx = 1e6+1;
void Titan(){
	int a,b;
	read(a,b);
	cout << (a+b)%24;
}

	

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T = 1;
	//cin >> T;		//cmt if one test case
    fo(T){
		//cout << "Case #" << i+1 << ": " ;
		Titan();
	}
}
/*///////////////////////////////////////////////////////////
Important Notes : 
* check long long 
* check base cases
* do not loose Hope
* if case fails on 2nd test case maybe some cases are missing check them
* do not sit idle
* try to do it using pen/paper.
*/


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


int f(int x, int y, int z){
    return pow(x, 2) + pow(y, 2) + pow(z, 2) + x*y + y*z + z*x;
}

void dfs(int i, const int size, const int range_start, const int range_end)
{
    if (i == size) {
        vector<int> k;
        for(int i = 0; i < buf.size(); ++i){
            k.push_back(buf[i]);
        }
        nums.push_back(k);
    }
    else{
        for(int j = range_start; j <= range_end; ++j){
            buf[i] = j;
            dfs(i + 1, size, range_start, range_end);
        }
    }
}

int main(void)
{
    int n; cin >> n;
    int size = 3;
    int range_start = 1;
    int range_end = 100;
    buf.resize(size);
    dfs(0, size, range_start, range_end);
    vector<int> cnt(n);
    for (auto vi: nums){
        int x = vi[0], y = vi[1], z = vi[2];
        int out = f(x, y, z);
        if (out <= n) cnt[out-1] ++;
    }
    for (auto c:cnt) cout << c << endl;
    return 0;
}

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

int main() {
    int n,m,l;
    cin>>n>>m>>l;
    long long A[n][m],B[m][l],result[n][l];
    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++){
        for(int j=0;j<l;j++){
            cin>>B[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            result[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            for(int k=0;k<m;k++){
                result[i][j]+=A[i][k]*B[k][j];
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            if(j) cout<<" ";
            cout<<result[i][j];
        }
        cout<<endl;
    }
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=k;i<n;i++)
	{
		if(a[i]>a[i-k])
			cout<<"Yes\n";
		else
			cout<<"No\n";
	}
    return 0;
}

Measured memory_bytes: 4440
from bisect import bisect_left
from time import time
t0 = time()
def xorshift(seed=123456789):  # 31 bit xorshift
    y = seed
    def randint():
        nonlocal y
        y ^= (y & 0xffffff) << 7
        y ^= y >> 12
        return y# % (b-a+1) + a
    return randint
randint = xorshift()
D = int(input())
C = list(map(int, input().split()))  # 低下
S = [list(map(int, input().split())) for _ in range(D)]
Last = [-1] * 26
def calc_pena(day):
    res = 0
    for l, c in zip(Last, C):
        res += (day-l)*c
    return res
T2 = [[-1] for _ in range(26)]

def change(day, contest):
    diff = 0
    contest_old = T[day]
    T[day] = contest
    idx = bisect_left(T2[contest_old], day)
    #assert day in T2[contest_old]
    diff -= C[contest_old] * (T2[contest_old][idx+1] - day) * (day - T2[contest_old][idx-1])
    del T2[contest_old][idx]
    idx = bisect_left(T2[contest], day)
    diff += C[contest] * (T2[contest][idx] - day) * (day - T2[contest][idx-1])
    T2[contest].insert(idx, day)
    diff += S[day][contest] - S[day][contest_old]
    return diff
Check = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 9999]
idx_Check = 0
def check():
    global idx_Check, ans
    if Check[idx_Check] < time()-t0:
        idx_Check += 1
        print(ans, Check[idx_Check-1])

T = []
ans = 0
for day, s in enumerate(S):
    best_gain = -999999
    best_gain_contest = None
    pena = 0
    for cont, (l, c, s_) in enumerate(zip(Last, C, s)):
        p = (day-l)*c
        pena += p
        if best_gain < s_ + p:
            best_gain = s_ + p
            best_gain_contest = cont
    T.append(best_gain_contest)
    Last[best_gain_contest] = day
    ans += best_gain - pena
# print(T)
# print(ans)
# ans = 0
# Last = [-1] * 26
# for i, (s, t) in enumerate(zip(S, T)):
#     Last[t] = i
#     ans += s[t]
#     ans -= calc_pena(i)
#     T2[t].append(i)
for i, t in enumerate(T):
    T2[t].append(i)
for i in range(26):
    T2[i].append(D)  # 番兵

#from math import exp
#def prob(gain, remain_time):
#    return exp(-gain / remain_time)

t_now = time()-t0
while t_now < 1.9:
    r = randint()
    day = r % D
    r //= D
    contest = r % 26
    contest_old = T[day]
    ch = change(day, contest)
    r2 = randint()
    if ch >= 0 \
        or (t_now < 1.7 and -ch < r2&0x1ff) \
        or (t_now < 1.5 and -ch < r2&0x3ff) \
        or (t_now < 1.2 and -ch < r2&0xfff):
        ans += ch
        #print(ans, time()-t0)
        #check()
    else:
        change(day, contest_old)
    t_now = time()-t0
#print(ans)
print("\n".join(str(a+1) for a in T))


Measured memory_bytes: 85496
//_nebula_
#include<bits/stdc++.h>
using namespace std;
#define int long  long
#define double long double
int t;
const int M=1e9+7;
int factt(int n)
{
    int ans=1;
    for(int i=1;i<=n;i++)
    {
        ans*=i;
        ans=ans%M;
    }
    return ans;
}
int max(int a,int b,int c)
{
    return max(a,max(b,c));
}
int min(int a,int b,int c)
{
    return min(a,min(b,c));
}
int fspow(int x,int y)
{
    int ans;
    if(y==0) return 1;
    ans=fspow(x, y/2);
    if(y%2==0) return (ans*ans)%M;
    return (x*((ans*ans)%M))%M;;
}
int gcd(int x,int y)
{
    if(x<y) swap(x,y);
    if(y==0) return x;
    return gcd(x%y,y);
}
int p2(int x)
{
    int ans=0;
    while(x>=1)
    {
        ans++;
        x/=2;
    }
    return ans;
}
int v=0;
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    t=1;
    // freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //  cin>>t;
    // int tmp=t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n];
        int sum=0;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            sum+=a[i];
        }
        int ans=0;
        for(int i=0;i<n;i++)
        {
            sum-=a[i];
            ans=(ans+(a[i]%M)*(sum%M))%M;
        }
        cout<<ans<<"\n";
    }
}


Measured memory_bytes: 5208
#include<bits/stdc++.h>
#define M 300005 
#define LL long long
using namespace std;
int A[M],B[M],C[M],sz[M],fa[M];
int P=1e9+7,n;
vector<int>edge[M];
LL F[M],dp[M],pre;
int fast(int x,int n){
	LL res=1,a=x;
	while(n){
		if(n&1)res=res*a%P;
		a=a*a%P;
		n>>=1;
	}
	return res;
}
void dfs(int x,int f){
	sz[x]=1;fa[x]=f;
	for(int i=0;i<edge[x].size();i++){
		int y=edge[x][i];
		if(y==f)continue;
		dfs(y,x);
		sz[x]+=sz[y];//儿子的数量  
	}
} 
void rdfs(int x,int f,LL pre){ 
	 //pre记录x的祖先节点在把x变成根是的前缀积 
	for(int i=0;i<edge[x].size();i++){
		int y=edge[x][i];
		if(y==f)continue; 
		//y变成根之后，y在原树的所有祖先节点的 子树大小都发生变化 
		LL p=pre*sz[x]%P*fast(n-sz[y],P-2)%P; 
		LL tmp=p*sz[y]%P*fast(n,P-2)%P; 
		dp[y]=dp[1]*tmp%P; 
		rdfs(y,x,p); 
	}
}
int main(){
	int a,b;
	cin>>n;
	F[0]=1;
	for(int i=1;i<=n;i++)F[i]=F[i-1]*i%P;
	for(int i=1;i<n;i++){
		scanf("%d %d",&a,&b);
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	dfs(1,0);
	dp[1]=F[n];
	for(int i=1;i<=n;i++)dp[1]=dp[1]*fast(sz[i],P-2)%P; 
	rdfs(1,0,1);
	for(int i=1;i<=n;i++)printf("%lld\n",dp[i]);
	return 0; 
} 

Measured memory_bytes: 23028
from collections import defaultdict
from heapq import heapify, heappop, heappush
from sys import stdin

def main():
    N, M = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in [0] * N]

    ab = defaultdict(list)
    for a, b in AB:
        ab[a].append(b)

    ans = 0
    reward = []
    for i in range(1, M + 1):
        if ab[i]:
            for n in ab[i]:
                heappush(reward, n * -1)
        if reward:
            ans += heappop(reward) * -1
    print(ans)

input = lambda: stdin.readline()
main()


Measured memory_bytes: 38584
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 1000000007;
const int MAX = 1000010;
Int fac[MAX], sumfac[MAX], dp[MAX];
int main() {
    int N, H, D; cin >> N >> H >> D;
    fac[0] = 1;
    for (int i = 1; i <= N; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        sumfac[i] = (sumfac[i - 1] + fac[i]) % MOD;
    }
    dp[0 + 1] = (dp[0 + 1] + fac[N]) % MOD;
    dp[0 + D + 1] = (dp[0 + D + 1] + MOD - fac[N]) % MOD;
    for (int i = 1; i < H; i++) {
        Int t = dp[i] * sumfac[N] % MOD;
        dp[i + 1] = (dp[i + 1] + t) % MOD;
        int idx = min(H + 1, i + D + 1);
        dp[idx] = (dp[idx] + MOD - t) % MOD;
        dp[i + 1] = (dp[i] + dp[i + 1]) % MOD;
    }
    cout << dp[H] << '\n';
    return 0;
}


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

typedef long long ll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
typedef pair<ll,ll> pll;

const ll N = 200001;
const ll MOD = 1000000007;
const ll INF = LLONG_MAX;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl
#define space ' '
#define nl '\n'

#define COUT(v) for(auto it:v)cout<<it<<space;cout<<nl;
#define CIN(v) for(auto &it:v)cin>>it;

int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int t=1,cs=0;
    //cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        if(s[2]==s[3]&&s[4]==s[5])
            cout<<"Yes"<<nl;
        else
            cout<<"No"<<nl;
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static long naive_solve(long A, long B, long N) {
		long answer = Long.MIN_VALUE;
		
		for(int x = 1; x <= N; x++) {
			final long upper = (A * x) / B;
			final long lower = A * (x / B);
			
			answer = Math.max(answer, upper - lower);
		}
		
		return answer;
	}
	
	public static long smart_solve(long A, long B, long N) {
		final long x = Math.min(N, B - 1);
		final long upper = (A * x) / B;
		final long lower = A * (x / B);
		
		return upper - lower;
	}
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final long A = sc.nextLong();
			final long B = sc.nextLong();
			final long N = sc.nextLong();
			
			/*
			for(int i = 0; i < 1000; i++) {
				final long a = (long)(1 + Math.random() * 1000l);
				final long b = (long)(1 + Math.random() * 1000l);
				final long n = (long)(1 + Math.random() * 1000l);
				
				if(naive_solve(a, b, n) != smart_solve(a, b, n)) {
					System.out.println("ng");
				}
			}
			*/
			
			System.out.println(smart_solve(A, B, N));
			
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 32748