akhauriyash/Code-Regression huggingface dataset:
//...Bismillahir Rahmanir Rahim...
// Code by    Asad Bin Saber

#include <bits/stdc++.h>

using namespace std;

// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

// constants...
const double PI = acos(-1);
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18+5;

// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

// chess moves...
// int dx[] = {+0, +0, -1, +1}; ///Up-down, Left-Right
// int dy[] = {+1, -1, +0, +0};
// int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
// int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1};
// int dx[] = {-2, -2, -1, -1,  1,  1,  2,  2}; ///Knight's Move
// int dy[] = {-1,  1, -2,  2, -2,  2, -1,  1};

// structs...
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

// functions...
ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll lcm(ll a, ll b)
{
    return (a/gcd(a, b)*b);
}
ll comb(ll a, ll b)
{
    ll x = max(a-b, b), ans=1;

    for(ll K=a, L=1; K>=x+1; K--, L++){
        ans *= K;
        ans /= L;
    }

    return ans;
}


void task()
{
    //code here...
    
    string s;
    int n;
    
    cin >> n >> s;
    
    vector<int> ara(n);
    if(s[n-1]=='R') ara[n-1]++;
    for(int K=n-2; K>=0; K--){
		if(s[K]=='R') ara[K] = ara[K+1] + 1;
		else ara[K] = ara[K+1];
	}
    
    int mid=0, ans=0;
    
    for(int K=0; K<n; K++){
		if(ara[K]<=ans+mid){
			ans += mid;
			break;
		}
		
		if(s[K]=='W') mid++;
		else if(s[K]=='R'){
			ans += mid;
			mid = 0;
		}
	}
	
	cout << ans << "\n";
}


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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    task();

    return 0;
}


Measured memory_bytes: 4400
#![allow(unused_imports)]

use std::{cmp, fmt};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, StdinLock, Write};
use std::ops::{Add, Div, Mul, Sub};
use std::str::{self, FromStr};

fn solve(_: u32, a: u32, b: u32) -> &'static str {
    if (b - a) % 2 == 0 {
        "Alice"
    } else {
        "Borys"
    }
}

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes(), 1024);
    println!("{}", solve(sc.next(), sc.next(), sc.next()));
}

struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>, capacity: usize) -> Self {
        Scanner {
            buf: Vec::with_capacity(capacity),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        let buf = &mut self.buf;
        buf.clear();
        self.bytes
            .by_ref()
            .map(Result::unwrap)
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
            .foreach(|c| buf.push(c));
        str::from_utf8(&buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<T1: FromStr, T2: FromStr>(&mut self, n: usize) -> Vec<(T1, T2)>
    where
        <T1 as FromStr>::Err: fmt::Debug,
        <T2 as FromStr>::Err: fmt::Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<T1: FromStr, T2: FromStr, T3: FromStr>(&mut self, n: usize) -> Vec<(T1, T2, T3)>
    where
        <T1 as FromStr>::Err: fmt::Debug,
        <T2 as FromStr>::Err: fmt::Debug,
        <T3 as FromStr>::Err: fmt::Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: fmt::Debug,
    {
        (0..m).map(|_| self.vec(n)).collect()
    }

    fn strings_as_mat<T, F: FnMut(u8) -> T>(&mut self, h: usize, mut f: F) -> Vec<Vec<T>> {
        (0..h)
            .map(|_| {
                self.bytes
                    .by_ref()
                    .map(Result::unwrap)
                    .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
                    .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
                    .map(&mut f)
                    .collect()
            })
            .collect()
    }
}

trait Foreach {
    type Item;
    fn foreach<F: FnMut(Self::Item)>(self, f: F);
}

impl<T, I: Iterator<Item = T>> Foreach for I {
    type Item = T;

    fn foreach<F: FnMut(T)>(self, mut f: F) {
        self.fold((), move |(), x| f(x));
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 2005

struct Edge{
	Edge(int arg_to,int arg_value){
		to = arg_to;
		value = arg_value;
	}
	int to,value;
};

ll N,M;
int in_num[SIZE];
ll fact[3*SIZE],inverse_fact[3*SIZE];
ll dp[SIZE][3*SIZE];
ll head[SIZE],tail[SIZE];
vector<Edge> G[SIZE];


ll extgcd(ll a,ll b,ll &x,ll &y){
	ll d = a;
	if(b != 0){
		d = extgcd(b,a%b,y,x);
		y -= (a/b)*x;
	}else{
		x = 1;
		y = 0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}


void func(){

	for(int i = 0; i < SIZE; i++){

		G[i].clear();
		in_num[i] = 0;
	}

	int from,to,value;

	for(int loop = 0; loop < M; loop++){

		scanf("%d %d %d",&from,&to,&value);
		from--;
		to--;

		G[from].push_back(Edge(to,value));

		in_num[to]++;
	}

	for(int i = 0; i < N; i++){
		for(int k = 0; k <= 3*N; k++){
			dp[i][k] = 0;
		}
	}

	dp[0][0] = 1;

	queue<int> Q;
	for(int i = 0; i < N; i++){
		if(in_num[i] == 0){
			Q.push(i);
		}
	}

	while(!Q.empty()){

		int node_id = Q.front();
		Q.pop();

		for(int i = 1; i <= 3*N; i++){

			dp[node_id][i] += dp[node_id][i-1];
			dp[node_id][i] %= MOD;

		}

		for(int i = 0; i <= 3*N-1; i++){
			if(dp[node_id][i] == 0)continue;

			for(int k = 0; k < G[node_id].size();k++){

				if(i+G[node_id][k].value > 3*N)continue;

				dp[G[node_id][k].to][i+G[node_id][k].value] += dp[node_id][i];
				dp[G[node_id][k].to][i+G[node_id][k].value] %= MOD;
			}
		}

		for(int k = 0; k < G[node_id].size(); k++){

			in_num[G[node_id][k].to]--;
			if(in_num[G[node_id][k].to] == 0){

				Q.push(G[node_id][k].to);
			}
		}
	}

	int num_query;
	scanf("%d",&num_query);

	int last_node;
	ll total;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d %lld",&last_node,&total);
		last_node--;

		if(total <= 3*N){

			printf("%lld\n",dp[last_node][total]);
			continue;
		}

		head[0] = 1;
		for(int i = 1; i <= N; i++){

			head[i] = head[i-1]*((total-2*N)-i+1);
			head[i] %= MOD;
		}

		tail[N] = 1;
		for(int i = N-1; i >= 0; i--){

			tail[i] = tail[i+1]*((total-2*N)-i-1);
			tail[i] %= MOD;
		}

		ll ans = 0;

		for(int i = 2*N; i <= 3*N; i++){

			ll tmp = dp[last_node][i];

			tmp *= head[i-2*N];
			tmp %= MOD;

			tmp *= tail[i-2*N];
			tmp %= MOD;

			ll denominator = (inverse_fact[i-2*N]*inverse_fact[3*N-i])%MOD;
			if((3*N-i)%2 == 1){

				denominator *= (-1+MOD);
				denominator %= MOD;
			}

			tmp *= denominator;
			tmp %= MOD;

			ans += tmp;
			ans %= MOD;
		}

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

int main(){

	fact[0] = 1;
	for(ll i = 1; i <= 6000; i++){
		fact[i] = i*fact[i-1];
		fact[i] %= MOD;
	}

	inverse_fact[6000] = mod_inverse(fact[6000],MOD);
	for(ll i = 6000; i >= 1; i--){

		inverse_fact[i-1] = inverse_fact[i]*i;
		inverse_fact[i-1]%= MOD;
	}

	while(true){

		scanf("%lld %lld",&N,&M);
		if(N == 0 && M == 0)break;

		func();
	}

	return 0;
}




Measured memory_bytes: 97556
#include<bits/stdc++.h>
#define lowbit(i) ((i)&(-(i)))
#define lson(i) ((i)<<1)
#define rson(i) ((i)<<1|1)
#define fi first
#define se second
#define MP(x,y) make_pair((x),(y))
using namespace std;

typedef long long ll;typedef unsigned long long ul;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef vector<string> vss;
typedef vector<int> vii;typedef vector<pii> vpi;
typedef queue<int> qii;typedef queue<pii> qpi;

const int inf=0x3f3f3f3f;
const int maxn=100007;

int n,k,a[maxn],res,mn=inf;
vii v;

int main()
{
// 	freopen("","r",stdin);
// 	freopen("","w",stdout);
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
//		if(a[i]<mn){
//			mn=a[i];
//			v.clear();
//			v.push_back(i);
//		}
//		else if(a[i]==mn) v.push_back(i);
	}
//	double div=(k-1);
//	res+=ceil((v[0]-1)/div);
//	res+=ceil((n-v[v.size()-1])/div);
//	for(int i=1;i<v.size();i++){
//		res+=ceil((v[i]-v[i-1])/div);
//	}
	res=ceil((n-1)/(double(k-1)));
	printf("%d\n",res);
	return 0;
}



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

using namespace std;
#define ll long long int

int main()
{
   ll t;
   t = 1;	
   //cin t;
   while(t--){
       ll n;
       cin >> n;
       ll count = 0;
       ll ans =0;
       while(n % 2 == 0 && n > 1)
       {
           n /=2 ;
           count ++;
       }      
       ans += (ll) (-1 + sqrt(1 + 8 * count)) / 2;
       for(ll i = 3 ; i * i <=n ; i +=2)
       {
           count =0;
           while(n % i == 0 && n > 1)
           {
               n/=i;
               count ++;
           }
           ans += (ll) (-1 + sqrt(1 + 8 * count)) / 2;
       } 
       if(n > 1)
       ans ++;

       cout << ans << endl;
   }
}


Measured memory_bytes: 3668
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a;
    int b;
    int c;
    int k;
    cin >>a>>b>>c>>k;
    
    int max=0;
    
    if(k<=a){
    max += k;
    k=0;
    }else if(k>a){
        max +=a;
        k -=a;
    }
    
    if(k>=b){
        k-=b;
    }
    if(k>0){
    max -=k;
    }
    cout<<max;
    
}

Measured memory_bytes: 3648
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve() 
{
	//happy coding

	ll n;
	ll sum = 0;
	cin>>n;
	ll a[n];
	map<ll,ll>m;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		sum += a[i];
		m[a[i]]++;
	}

	ll q;
	cin>>q;
	while(q--){
		ll a,b;
		cin>>a>>b;
		if(m[a]){
			ll x = m[a];
			sum -= (a*m[a]);
			m[a] = 0;
			m[b] += x;
			sum+= (b*x);
		}
		cout<<sum<<endl;
	}


	
	return 0;
}
int main(){
	int test = 1;
  	//scanf("%d", &test);
  	while (test--)solve();return 0;
}

Measured memory_bytes: 10020
#include <stdio.h>

int main(void){
    int n,i,m;
    scanf("%d",&n);
    m=100000;
    for(i=0;i<n;i++){
        m=m+m*5/100;
        if(m%1000!=0) m=m+1000-(m%1000);
    }
    printf("%d\n",m);
    
    return 0;
}


Measured memory_bytes: 2104
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;


ll fact[200001];

ll extgcd(ll a,ll b,ll& x,ll& y){
	ll d=a;
	if(b!=0){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}else{
		x=1;
		y=0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
	ll x,y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}

ll mod_fact(ll n,ll p,ll& e){
	e=0;
	if(n==0)return 1;
	ll res=mod_fact(n/p,p,e);
	e+=n/p;
	if(n/p%2!=0)return res*(p-fact[n%p])%p;
	return res*fact[n%p]%p;
}

ll mod_comb(ll n,ll k,ll p){
	if(n<0 || k<0 || n<k)return 0;
	ll e1,e2,e3;
	ll a1=mod_fact(n,p,e1),a2=mod_fact(k,p,e2),a3=mod_fact(n-k,p,e3);
	if(e1>e2+e3)return 0;
	return a1*mod_inverse(a2*a3%p,p)%p;
}

int h,w,a,b;

int main(void){
	scanf("%d%d%d%d",&h,&w,&a,&b);
	fact[0]=1;
	for(ll i=1;i<=200000;i++){
		fact[i]=fact[i-1]*i%MOD;
	}
	ll res=0;
	ll join=0;
	for(int i=0;i<h-a;i++){
		ll cnt=((mod_comb(b+i,b,MOD)-join+MOD)%MOD)*mod_comb(h+w-2-(b+i),w-b-1,MOD)%MOD;
		join=mod_comb(b+i,b,MOD);
		res=(res+cnt)%MOD;
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> pl;
const int INF=100000001;

int main(){

  int n,a,b,ans; cin>>n>>a>>b;
  if(a*n>b)
  ans=b;
  else
  ans=a*n;

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;
int main(){
vector<ll> vec(3);
rep(i,3) cin >> vec[i];
sort(vec.begin(),vec.end());
ll ans;
if(vec[0] % 2 == 0|| vec[1] % 2 == 0 || vec[2] % 2 == 0) ans = 0;
else ans = vec[0] * vec[1];
cout << ans << endl;;
}

Measured memory_bytes: 256
L, R = gets.chomp.split.map(&:to_i)

# p L.upto(R).to_a
# p L.upto(R).map { |i| i % 2019 }

def solve
  if (R - L) > 2019
    p 0
    return
  end

  mods = []
  L.upto(R).each do |i|
    mod = i % 2019
    mods << mod
  end

  # p [L, R]
  # p mods

  min = 2019 * 2019 + 1
  0.upto(mods.size - 1).each do |i|
    (i + 1).upto(mods.size - 1).each do |j|
      k = (mods[i] * mods[j]) % 2019
      if (k < min)
        min = k
      end
    end
  end
  
  p min
end

solve

Measured memory_bytes: 1916
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		int a2 = a + W;
		int b2 = b + W;
		if(a <= b && b <= a2 || a <= b2 && b2 <= a2) {
			System.out.println(0);
		}else if(a > b2) {
			System.out.println(a - b2);
		}else if(a2 < b) {
			System.out.println(b - a2);
		}
	}
}

Measured memory_bytes: 22740
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int [] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		for(int i = n - 1; i >= 0; i--) {
			System.out.printf("%d", a[i]);
			if(i > 0)	System.out.printf(" ");
		}
		System.out.printf("\n");
	}
}



Measured memory_bytes: 26228
import sys

def print_arr(arr):
	for i in range(len(arr)):
		sys.stdout.write(str(arr[i]))
		if i != len(arr) - 1:
			sys.stdout.write(' ')
	print()
	
def bubble_sort(arr):
	cnt = 0
	n = len(arr)
	for i in range(n):
		for j in range(n - 1, i, -1):
			if arr[j - 1] > arr[j]:
				temp = arr[j - 1]
				arr[j - 1] = arr[j]
				arr[j] = temp
				cnt += 1
	return cnt	
	
n = int(input())
arr = list(map(int, input().split()))

cnt = bubble_sort(arr)
print_arr(arr)
print(cnt)


Measured memory_bytes: 5612
#include<iostream>                                        
using namespace  std;                                     
                                                          
int main(){                                               
  int n;                                                  
  int b,f,r,v;                                            
  int i;                                                  
  int house[4][3][10] = {};                               
                                                          
  cin >> n;                                               
                                                          
  for(i=0;i<n;i++){                                       
    cin >> b >> f >> r >> v;                              
    house[b-1][f-1][r-1] += v;                            
  }                                                       
                                                          
  for(int k=0;k<4;k++){                                   
    for(n=0;n<20;n++){                                    
      if(k>0)                                             
      cout << "#";                                        
    }                                                     
    if(k>0)                                               
    cout << endl;                                         
    for(int l=0;l<3;l++){                                 
      for(int m=0;m<10;m++){                              
        cout << " " << house[k][l][m];                    
      }                                                   
      cout << endl;                                       
    }                                                     
  }                                                       
                                                          
  return 0;                                               
                                                          
} 

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


int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string s,t;
  map<char, vector<int> > mp;
  cin>>s>>t;

  for(int i=0;i<s.size();i++){
    char c = s[i];
    mp[c].push_back(i);
  }

  for(int i=0;i<t.size();i++){
    char c = t[i];
    if(mp.count(c)==0){
      cout<<-1<<endl;
      return 0;
    }
  }

  vector<int>::iterator it;
  ll res=0;
  int s_p=0;

  for(int i=0;i<t.size();i++){
    char c = t[i];
    it = lower_bound(mp[c].begin(), mp[c].end(), s_p);
    if(it == mp[c].end()){
      res += s.size() - s_p;
      s_p = 0;
      res += mp[c][0] - s_p + 1;
      s_p = mp[c][0] + 1;
    } else {
      res += *it - s_p + 1;
      s_p = *it + 1;
    }
  }

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 1228
#include<iostream>
#include<algorithm>
using namespace std;
int n,num[600001];
int s[600001];
int tot=0;
void hb(int s1,int e1,int s2,int e2){
	int w=s1,t=s1;
	while(s1<=e1&&s2<=e2){
		if(num[s1]<num[s2]) s[w++]=num[s1++];
		else s[w++]=num[s2++];
		tot++;
	}
	if(s1<=e1){
		for(s1;s1<=e1;s1++){
			s[w++]=num[s1];
			tot++;
		}
	}
	else{
		for(s2;s2<=e2;s2++){
			s[w++]=num[s2];
			tot++;
		}
	}
	for(int i=t;i<=e2;i++){
		num[i]=s[i];
		s[i]=0;
	}
}
void gb(int l,int r){
	if(l==r) return;
	int mid=(l+r)/2;
	gb(l,mid);
	gb(mid+1,r);
	hb(l,mid,mid+1,r);
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++) cin>>num[i];
	gb(0,n-1);
	for(int i=0;i<n-1;i++) cout<<num[i]<<" ";
	cout<<num[n-1]<<"\n";
	cout<<tot<<"\n";
	return 0;
}

Measured memory_bytes: 7024
#include<stdio.h>
int main(){
 int d[10]={0};
 int i,j,t;
 for(i=0;i<10;i++){
 scanf("%d",&d[i]);
  for(j=i;j;j--){
   if(d[j-1]<d[j]){
     t=d[j-1];
     d[j-1]=d[j];
     d[j]=t;
   }
  }
 }
 printf("%d\n%d\n%d\n",d[0],d[1],d[2]);
 return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 100001
#define int ll
string str;
bool pos[maxn];

		
			
bool ok(int k){
	mem(pos,0);
	
	bool pos1 = 1, pos0 = 1;
	
	FOR(i,k-1,str.size() - k){
		pos[i] = 1;
	}
	
	FOR(i,0,str.size()-1){
		if (i >= k || i + 1 <= str.size() - k) pos[i] = 1;
		
		if (str[i] == '1') pos1 = pos1 && pos[i];
		else pos0 = pos0 && pos[i];
	}
	
	return pos1||pos0;
	
	
}
int32_t main(){
	fast;
	
	cin>>str;
	int N = str.size();
	bool one = 1,zr = 1;
	
	aFOR(i,str){
		if (i == '1') zr = 0;
		else one = 0;
	}
	
	if (zr || one){
		cout<<str.size();
		return 0;
	}
	
	
	int l = 0, r = str.size()+1;
	
	while (l+1<r){
		int mid = (l+r)/2;
		

		
		if (ok(mid)) l = mid;
		else r = mid;
	}
	
	cout<<max((ll)1,l);
	
}



Measured memory_bytes: 592
#include<iostream>
#include <string>
#include <stdio.h>
using namespace std;

int main()
{
    //　数値の定義
    int R; //半径
    cin >> R;

    // 操作
    double pi = 3.14159276;

    double result = 2 * R * pi;
    
    
    //判定
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3232
n, m = [int(i) for i in input().split()]
sc = list(set([tuple(map(int, input().split())) for _ in range(m)]))

s = list('x'*n)
for i in range(len(sc)):
    if s[sc[i][0]-1] != 'x':
        print("-1")
        exit()
    s[sc[i][0]-1] = str(sc[i][1])

if n > 1 and s[0] == 'x':
    s[0] = '1'

ans = int("".join(s).replace('x', '0'))
print(ans if len(str(ans)) == n else -1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 10007; // 1e9+7
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)

#define FOREACH(x,a) for(auto&& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_ll.hpp>
// using namespace boost::multiprecision; // cpp_ll

#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>

#define pb(a) push_back(a)
#define mp make_pair

signed main(){
    LCIN(n, p);
    ll t = sqrt(p);
    M m;
    FOR(i, 2, t + 100){
        while(p % i == 0){
            ++m[i];
            p /= i;
        }
    }
    if(p != 1)
        ++m[p];
    ll ans = 1;
    FOREACH(xx,m){
        ll c = xx.second / n;
        REP(i,c)
            ans *= xx.first;
    }
    COUT(ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
/* -- template -- */

struct UnionFind {
    vector<int> par;
    vector<ll> siz;
    UnionFind(int N) : par(N), siz(N, 1LL) {
        for(int i = 0; i < N; ++i) {
            par[i] = i;
        }
    }
    int root(int x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        siz[ry] += siz[rx];
        par[rx] = ry;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    ll size(int x) {
        return siz[root(x)];
    }
};
int main() {
    int N, M; cin >> N >> M;
    int p[N]; rep(i, N) cin >> p[i], --p[i];
    UnionFind tree(N);
    rep(i, M){
        int x, y; cin >> x >> y;
        --x, --y;
        tree.unite(x, y);
    }
    int ans = 0;
    rep(i, N) {
        if(tree.same(p[i], i))++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
/*Priness's Marriage*/
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> p;

int main(void){
  int ok=0;
  while(ok==0){
  int n,m;
  cin >> n >> m;
  if(n==0 && m==0)return 0;
  pair<int,int> p[n];
  for(int i=0;i<n;i++){
    cin >> p[i].second >> p[i].first;
  }//firtst = danger second = walk
  sort(p,p+n);
  reverse(p,p+n);
  int num=0;
  for(int i=0;i<n;i++){
    if(m>=0){
      if(m>=p[i].second){
        m-=p[i].second;
        p[i].second=0;
      }else{
        p[i].second-=m;
        m=0;
        num+=p[i].second*p[i].first;
      }
    }else{
      num+=p[i].second*p[i].first;
    }
  }
  cout << num << endl;
  }
  return 0;
}

Measured memory_bytes: 3160
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        n:usize,
        k:usize,
    }
    let modulo:usize = 1_000_000_007;
    let mut fact:Vec<usize> = vec![0;n+1];
    let mut inv:Vec<usize> = vec![0;n+1];
    let mut fact_inv:Vec<usize> = vec![0;n+1];
    fact[0] = 1;
    fact[1] = 1;
    for i in 2..n+1 {
        fact[i] = fact[i-1] * i % modulo;
    }
    inv[0] = 1;
    inv[1] = 1;
    for i in 2..n+1 {
        inv[i] = (modulo - modulo/i) * inv[modulo%i] % modulo;
    }
    fact_inv[0] =1;
    fact_inv[1] =1;
    for i in 2..n+1 {
        fact_inv[i] = fact_inv[i-1] * inv[i] % modulo;
    }
    let mut ans:usize =0 ;
    for i in 1..k+1 {
        // println!("i ? {}", i);
        ans = 0;
        if n-k>=i-1 && k>=i {
            ans = fact[n-k+1] * fact[k-1] % modulo * fact_inv[1+n-k-i]%modulo * fact_inv[i] %modulo * fact_inv[k-i] %modulo * fact_inv[i-1] %modulo;
        }
        println!("{}", ans);
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,start,end) for(int i=start; i<=end; i++)
#define repd(i,start,end) for(int i=start; i>=end; i--)
#define all(x) x.begin(),x.end()

void solve() {
	ll n,x,t;
	cin >> n >> x >> t;

	if(n%x==0)
		cout << (n/x)*t << endl;
	else
		cout << (n/x + 1)*t << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	//cin >> t;
	while(t--) {
		solve();
	}
}

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

struct Node{
  int s;
  struct Node *ri;
  struct Node *le;
  struct Node *oya;
};

struct Node *root, *NIL;

void Inorder(struct Node *);
void Preorder(struct Node *);

void Insert(int a){
struct  Node *p = root;
struct  Node *q = NIL;
struct  Node *r;

 r = (struct Node *)malloc(sizeof(struct Node));
 r -> s = a;
 r -> le = NIL;
 r -> ri = NIL;


 while(p != NIL){
   q = p;
   if(r->s < p->s){
     p = p -> le;
   }
   else{
     p = p -> ri;
   }
 }

 r -> oya = q;
  if(q == NIL){
    root = r;
  }
  else{
    if(r->s < q->s){
      q -> le = r;
    }

    else{
      q -> ri = r;
    }
  }
}




int main(){
  int str1 = 0;
  int str2 = 0;
  int i,n,val;
  char c1[10], c2[10]="insert", c3[10]="print";

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    scanf("%s",c1);
    if(strcmp(c1,c2) == 0) str1 = 1;
    if(strcmp(c1,c3) == 0) str2 = 1;

    if(str1 == 1){
      scanf("%d",&val);
      Insert(val);
      str1 = 0;
    }
    else if(str2 == 1){
      str2 = 0;
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }
  }

  return 0;
}



void Inorder(struct Node *x){
  if(x == NIL) return;
  Inorder(x -> le);
  printf(" %d",x -> s);
  Inorder(x -> ri);
}


void Preorder(struct Node *x){
  if(x == NIL) return;
  printf(" %d",x -> s);
  Preorder(x -> le);
  Preorder(x -> ri);
}



Measured memory_bytes: 25180
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

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

    VI p(n);
    rep(i,n) cin>>p[i];

    int cnt=0;
    rep(i,n){
        if(p[i]!=i+1) cnt++;
    }
    if(cnt<=2) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int a, b;
    cin >> a >> b;
    int g = __gcd(a, b);
    int c = 0;
    for (int i = 2; i <= sqrt(g); i++) {
        if (g % i == 0) {
            c++;
            while (g % i == 0) {
                g /= i;
            }
        }
    }
    if (g >= 2) c++;
    cout << c + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int max = -1000000005, a[200000], small, tmp, n, i;
  scanf("%d", &n);
  scanf("%d", &a[0]);
  small = a[0];

  for (i = 1; i < n; i++)  {
    scanf("%d", &a[i]);
    if (a[i] - small > max)  {
      max = a[i] - small;
    }
    if (a[i] < small) {
      small = a[i];
    }
  }
  printf("%d\n", max);

  return 0;
}

Measured memory_bytes: 1376
#include<bits/stdc++.h>
using namespace std;
void dfs(vector<int> adj[], bool visited[], int start, int n){
	stack<int> s;
	visited[start]=true;
	s.push(start);
	while(!s.empty()){
		int temp=s.top();
		s.pop();
		vector<int>::iterator i;
		for(i=adj[temp].begin();i!=adj[temp].end();i++){
			if(!visited[*i]){
				s.push(*i);
				visited[*i]=true;
			}
		}
	}
}
int main(){
	int n,m;
	cin>>n>>m;
	vector<int> adj[n+1];
	bool visited[n+1];
	for(int i=0;i<=n;i++){
		visited[i]=false;
	}
	int x,y,z;
	while(m--){
		cin>>x>>y>>z;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	int cc=0;
	for(int i=1;i<=n;i++){
		if(!visited[i]){
			dfs(adj, visited, i, n);
			cc++;
		}
	}
	cout<<cc;
	return 0;
}

Measured memory_bytes: 6648
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
bool ng[364];
int a[364][364];
int num[364];
int main()
{
	memset(ng,false,sizeof(ng));
	int n,m,out=364;
	cin>>n>>m;
	rep(i,n) rep(j,m){
		cin>>a[i][j];a[i][j]--;
	}
	rep(i,m){
		memset(num,0,sizeof(num));
		rep(j,n){
			rep(k,m){
				if(!ng[a[j][k]]){
					num[a[j][k]]++;
					break;
				}
			}
		}
		int mai=-1;
		rep(j,m){
			if(mai<0 || num[mai]<num[j]) mai=j;
		}
		//cout<<mai<<' '<<num[mai]<<endl;
		out=min(out,num[mai]);ng[mai]=true;
	}
	cout<<out<<endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>

int main() {

    int a, b, c;

    scanf("%d %d %d", &a, &b, &c);

    int a1, a2, a3;

    if (a >= b && b >= c) {
        a1 = a;
        a2 = b;
        a3 = c;
    }
    if (a >= c && c >= b) {
        a1 = a;
        a2 = c;
        a3 = b;
    }

    if (b >= c && c >= a) {
        a1 = b;
        a2 = c;
        a3 = a;

    }

    if (b >= a && a >= c) {
        a1 = b;
        a2 = a;
        a3 = c;

    }

    if (c >= a && a >= b) {
        a1 = c;
        a2 = a;
        a3 = b;

    }

    if (c >= b && b >= a) {
        a1 = c;
        a2 = b;
        a3 = a;

    }

    printf("%d",a1*10+a2+a3);


    return 0;

}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
const long long MAX = 1000000000000001;

int main(){
  string alph = "abcdefghijklmnopqrstuvwxyz";
  vector<long long> namesum;
  namesum.push_back(0);
  int i = 0;
  while (namesum.at(i) < MAX) {
    namesum.push_back(namesum.at(i) * 26 + 26);
    i++;
  }
  
  long long N; cin >> N;
  for (int k = 0; k < namesum.size(); k++){
    if (namesum.at(k) < N && N <= namesum.at(k+1)){
      N = N-namesum.at(k)-1;
      string ans;
      for (int i = 0; i < k+1; i++){
        ans = ans + alph.at(N % 26);
        N = N/26;
      }
      reverse(ans.begin(),ans.end());
  	  cout << ans << endl;
      break;
    }
  } 
}

Measured memory_bytes: 3588
io = STDIN
n,m=io.gets.split.map(&:to_i)
ar=m.times.map{io.gets.split.map(&:to_i)}
def check(ar,n)
  str=" "*n
  ar.each do |s,c|
    if n==1 && s==1 && str[0] == " " && c==0
      str[s-1]="0"
    elsif s==1 && c==0 && n != 1
      return "-1"
    elsif str[s-1] == " " ||
      str[s-1]==c.to_s
      str[s-1]=c.to_s
    else
      return "-1"
    end
  end
  if str[0]==" "
    if n==1
      str[0]="0"
    else
      str[0]="1"
    end
  end
  str.gsub(" ","0")
end
puts check(ar,n)


Measured memory_bytes: 1788
N = int(input())
A_s = list(map(int, input().split()))
A_s = list(map(lambda x:(x[1],x[0]+1), enumerate(A_s)))
A_s = sorted(A_s, key=lambda x:x[0])
print(" ".join(list(map(lambda x:str(x[1]), A_s))))

Measured memory_bytes: 94352
#include <iostream>

using namespace std;

const int max_num = (1e5 + 5), max_answer = 1e9;
long long int dp[max_num];

int get_num() {
    int input;
    cin >> input;

    return input;
}

int main() {
    int num_of_stones = get_num(), height_of_stone[num_of_stones], jump = get_num();
    for (int i = 0; i < num_of_stones; i++) {
        height_of_stone[i] = get_num();
    }

    dp[1] = abs(height_of_stone[1] - height_of_stone[0]);
    for (int i = 2; i < num_of_stones; i++) {
        dp[i] = max_answer;
        for (int j = max(i - jump, 0); j < i; j++) {
            long long int answer = (dp[j] + abs(height_of_stone[i] - height_of_stone[j]));
            if (answer < dp[i]) {
                dp[i] = answer;
            }
        }
    }

    cout << dp[num_of_stones - 1];
}

Measured memory_bytes: 4340
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
cnt=0
for i in range(n):
    x,y=map(int,input().split())
    if x==y:
        cnt+=1
    else:
        cnt=0
    if cnt>=3:
        print("Yes")
        break
else:
    print("No")


Measured memory_bytes: 77232
n,m = map(int, input().split())
al = [True]*(n+1)
for _ in range(m):
    a = int(input())
    al[a] = False

MOD = 10**9+7
dp = [0]*(n+1)
dp[0] = 1
for i in range(n):
    if i+1 <= n and al[i+1]:
        dp[i+1] += dp[i]
        dp[i+1]%=MOD
    if i+2 <= n and al[i+2]:
        dp[i+2] += dp[i]
        dp[i+2]%=MOD

print(dp[n])


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  int n;
  cin>>n;
  vector<pll> a(n);
  cin>>a;

  vector<pll> sect(n);
  rep(i,n){
    sect[i] = {a[i].first-a[i].second,a[i].first+a[i].second};
  }
  sort(sect.begin(),sect.end(),[](auto a,auto b){return a.second<b.second;});

  ll ans = 0;
  ll now = -INF;
  rep(i,n){
    if(now<=sect[i].first){
      now = sect[i].second;
      ans++;
    }
  }
  cout<<(ans)<<endl;


}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X,Y;
  cin >> X >> Y;
  
  bool turukame = false;
  for(int i=0;i<=X;i++){
    int j = X-i;
    if(4*i+2*j == Y){
      turukame = true;
    }
  }
  
  if(turukame){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3484
import java.util.*;
import java.lang.*;

public class Main{

    public static void solve(long a , long b,long c , long d){//healt , str
        while(a > 0 && c > 0){
            c -= b;
            if(c <= 0){
                System.out.println("Yes");
                return;
            }
            a -= d;
        }

        if(c == 0){
                System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }

    public static void gora(){
        Scanner scn = new Scanner(System.in);

        // long test = scn.nextLong();

        long a = scn.nextLong();

        long b = scn.nextLong();


        long c = scn.nextLong();

        long d = scn.nextLong();
        // long arr[] = new long[n];

        // for(int i = 0 ; i < arr.length ; i++){
        //     arr[i] = scn.nextLong();
        // }

        solve(a,b,c,d );
    }

    public static void main(String args[]){
        gora();
    }
}




Measured memory_bytes: 35784
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <math.h>
#include <list>
#include <algorithm>

using namespace std;

int power(int x, int n) {
	if( n == 0 ) return 1;
	if( x == 0 ) return 0;
	if( n == 1 ) return x;
	
	if( n % 2 == 1 ) {
		int y = power(x, (n - 1)/2);
		return x*y*y;
	} else {
		int y = power(x, n/2);
		return y*y;
	}
}

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	while( 1 ) {
		stringstream a_0;
		int a,L;
		cin >> a >> L;
		if( a == 0 && L == 0 ) break;
		a_0 << a;
		vector<int> v;
		v.push_back(a);

		while(1) {
			vector<char> ch[2];
			//頭を埋める
			int l = a_0.str().length();
			int p = atoi(a_0.str().c_str());
			a_0.clear();
			a_0.str("");
			a_0 << p*power(10,L - l);

			int k = atoi(a_0.str().c_str());

			int ans[3] = {-1,0,0};
			for(int i = 0; i < v.size() - 1; i++) {
				if( v.at(v.size()-1) == v.at(i) ) {
					ans[0] = i;
					ans[1] = v.at(v.size()-1);
					ans[2] = v.size() - i - 1;
				}
			}
			if(ans[0] != -1) {
				cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
				break;
			}

			//桁を取得
			for(int i = 0; i < a_0.str().length(); i++)
				ch[0].push_back(a_0.str().at(i));
			
			sort( ch[0].begin(), ch[0].end() );

			for(int i = a_0.str().length() - 1; i >= 0; i--)
				ch[1].push_back(ch[0].at(i));

			string s[2];
			for(int i = 0; i < a_0.str().length(); i++) {
				s[0] += ch[0].at(i);
				s[1] += ch[1].at(i);
			}

			int d = atoi(s[1].c_str()) - atoi(s[0].c_str());
			//cout << s[0] << " " << s[1] << endl;
			a_0.clear();
			a_0.str("");
			a_0 << d;
			//cout << d << endl;

			v.push_back(d);

		}
	}

	//while(1){}
	return 0;
}

Measured memory_bytes: 1264
#include <iostream>

int main()
{
	int x, y;
	scanf("%d %d", &x, &y);
	if(4 * x < y) printf("No\n");
	else if(y < 2 * x) printf("No\n");
	else if(y % 2 == 1) printf("No\n");
	else
	{
		printf("Yes\n");
	}	
	return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n,m;
    cin >> n >>m;
    int k = m/n;
    int r = m%n;
    while(r%k !=0){
        k--;
        r +=n;
        n += r/k;
        r = r%k;
    }
    cout << k;
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <limits>

using namespace std;

int main()
{
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	int ans = numeric_limits<int>::max();
	for (int n_AB = 0; n_AB / 2 <= max(X, Y); n_AB += 2) {
		int n_A = max(0, X - n_AB / 2);
		int n_B = max(0, Y - n_AB / 2);
		int total = n_A * A + n_B * B + n_AB * C;
		ans = min(ans, total);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;   
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll a=0,t=0,c=0,d=0,n,min=100000000000,k,ans=0;
    string s,s2;
    cin >> n >> t >> a;
    rep(i,n){
        cin >> d;
        c = t*1000 - d*(0.006*1000) - a*1000;
        int temp = abs(c);
        if(min>temp){
            ans = i;
            min = temp;
        }
    }
    cout << ans+1 <<endl;
    return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ll)(1e9)+7)
 
ll pmod(ll n, ll p){
	ll m=n%mod;
	if(p==0) return 1;
	ll rtn=pmod((m*m)%mod, p/2)%mod;
	if(p%2==1) rtn=rtn*m%mod;
	return rtn;
}

int main(){ 
	int n;
	cin >> n;
	ll a[n];
	for(int i=0; i<n; i++) cin >> a[i];
 
	map<int, int> cnt;
	for(int i=0; i<n; i++){
		ll t=a[i];
		for(int j=2; j*j<=a[i]; j++){
			int q=0;
			while(t%j==0){
				t/=j;
				q++;
			}
			cnt[j]=max(cnt[j], q);
		}
		if(t>1) cnt[t]=max(cnt[t], 1);
	}
 
	ll l=1;
	for(int i=2; i<(int)(1e6); i++){
		l=l*pmod(i, cnt[i])%mod;
	}
	ll s=0;
	for(int i=0; i<n; i++){
		s=(s+pmod(a[i], mod-2))%mod;
	}
	cout << l*s%mod << endl;
	return 0;
}

Measured memory_bytes: 49280
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<tuple>
#include<utility>

using namespace std;


int main() {

	int n;
	cin >> n;

	vector <pair<pair<string, int>,int>> t(n);

	for (int i = 0; i < n; i++) {
		string s;
		int p;
		cin >> s >> p;

		t[i] = make_pair(make_pair(s,-p),i+1);
	}

	sort(t.begin(), t.end());

	for (int i = 0; i < n; i++) {
		
		cout << t[i].second << endl;
	}
	
	return 0;
}




Measured memory_bytes: 256