akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define int long long

typedef pair<int,int> ii;
typedef pair<int,ii> iii;

int n;
ii c[100001], e[100001];
int p[100001], sz[100001], id[100001];
vector<ii> z[200001];
int f[100001];

int anc(int x)
{
	if (p[x] == x) return x;
	return p[x] = anc(p[x]);	
}

void join(int x,int y,int z)
{
	sz[anc(y)] += sz[anc(x)];
	p[anc(x)] = anc(y);
	id[anc(y)] = z;
}

void dfs(int u,int p,int cur)
{
	if (1 <= u && u <= n)
	{
		f[u] = cur;
		return;
	}	
	for (int i=0;i<z[u].size();i++)
	{
		int val = z[u][i].first;
		int v = z[u][i].second;
		if (v != p)
			dfs(v,u,cur + val);
	}
}

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

	cin >> n;
	for (int i=1;i<=n;i++)
	{
		p[i] = i;
		sz[i] = 1;
	}
	for (int i=1;i<=n-1;i++)
	{
		int u,v,cost;
		cin >> u >> v >> cost;
		c[i] = ii(cost,i);
		e[i] = ii(u,v);
	}	
	sort(c+1,c+1+n-1);
	for (int i=n-1;i>=1;i--)
	{
		int val = c[i].first;
		int u = e[c[i].second].first;
		int v = e[c[i].second].second;
		if (sz[anc(u)] == 1) z[i+n].push_back(ii(val*sz[anc(v)],u));
		else z[i+n].push_back(ii(val*sz[anc(v)],id[anc(u)]+n));
		if (sz[anc(v)] == 1) z[i+n].push_back(ii(val*sz[anc(u)],v));
		else z[i+n].push_back(ii(val*sz[anc(u)],id[anc(v)]+n));
		join(u,v,i);
	}
	dfs(n+1,-1,0);
	for (int i=1;i<=n;i++)
		cout << f[i] << '\n';
}

Measured memory_bytes: 23552
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



const int INF = 1<<29;
int dp[2000][2000];

int main() {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        vector<string> str(n);
        for (int i = 0; i < n; ++i) cin >> str[i];
        
        int res = 0;
        for (int i = 0; i < 2000; ++i) for (int j = 0; j < 2000; ++j) dp[i][j] = 0;
        for (int i = 0; i < n; ++i) {
            if (str[n-1][i] == '.') dp[n-1][i] = 1, res = 1;
            if (str[i][n-1] == '.') dp[i][n-1] = 1, res = 1;
        }
        
        for (int i = n-2; i >= 0; --i) {
            for (int j = n-2; j >= 0; --j) {
                if (str[i][j] != '.') continue;
                dp[i][j] = min(dp[i+1][j], min(dp[i][j+1], dp[i+1][j+1])) + 1;
                chmax(res, dp[i][j]);
                
                //cout << i << ", " << j << " : " << dp[i][j] << endl;
            }
        }
        
        cout << res << endl;
    }
    
    return 0;
}


Measured memory_bytes: 17756
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<62;
const int IINF = 1000000000;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

struct mint {
    ll x;
    mint(ll 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;
    }
    bool operator==(const mint a){
        return (x == a.x);
    }
    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;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// 2項係数を求める
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

//nが非常に大きく、aが小さい場合
mint choose(int n, int a){
    mint x = 1, y = 1;
    rep(i,a){
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}

int main(){

    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    vector<ll> cum(N+1,0);
    rep(i,N){
        cum[i+1] = (cum[i] + A[i]) % MOD;
    }

    mint ans = 0;
    for(int i = 0; i < N; i++){
        ans += (A[i] * (cum[N]-cum[i+1])) % MOD;
    }

    cout << ans << endl;
}


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

int two(int num, int c){
    if(num == 1 | num % 2 == 1) return c;
    return two(num / 2, ++c);
}

int main(){
    int n, a;
    int count = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a % 2 == 0) count += two(a, 0);
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	n, k := io.NextInt(), io.NextInt()
	a := io.NextInts(n)
	for i := k; i < n; i++ {
		if a[i] > a[i-k] {
			io.Println("Yes")
		} else {
			io.Println("No")
		}
	}
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// NextInts returns n integers from stdin
func (io *Io) NextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = io.NextInt()
	}
	return ret
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 14964
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
using namespace std;

#define INF 100000000
typedef pair<string,int> P;

int x,y;
string f;
char c, alph[] = {'R','G','B'};
int ans;
int r,g,b;
map<string,int> memo;
int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};
bool vis[10][10];

void color(string &s,int h,int w, char lu, char nxt){
  s[h*x+w] = nxt;
  for(int i=0;i<4;i++){
    int ty = h+dy[i], tx = w+dx[i];
    if(ty<0 || tx<0 || y<=ty || x<=tx)continue;
    if(s[ty*x + tx] != lu)continue;
    color(s,ty,tx,lu,nxt);
  }
}

int count(string s,int h,int w, char lu){
  if(vis[h][w])return 0;
  vis[h][w] = true;
  int res = 1;
  for(int i=0;i<4;i++){
    int ty = h+dy[i], tx = w+dx[i];
    if(ty<0 || tx<0 || y<=ty || x<=tx)continue;
    if(s[ty*x + tx] != lu)continue;
    res += count(s,ty,tx,lu);
  }
  return res;
}

int rec(string field,int depth){
  if(ans<depth)return INF;
  if(memo.find(field) != memo.end()){
    ans = min(ans,depth+memo[field]);
    return memo[field];
  }

  for(int j=0;j<y;j++)for(int k=0;k<x;k++)vis[j][k] = false;
  int mount = count(field,0,0,field[0]);
  if(mount == y*x){
    ans = min(ans,depth);
    return memo[field] = 0;
  }

  string G[2]; int num[2],cnt=0;
  for(int i=0;i<3;i++){
    G[cnt] = field; 
    if(alph[i] != G[cnt][0]){
      color(G[cnt],0,0,G[cnt][0],alph[i]);
      for(int j=0;j<y;j++)for(int k=0;k<x;k++)vis[j][k] = false;
      num[cnt] = count(G[cnt],0,0,alph[i]);
      cnt++;
    }
    if(cnt>=2)break;
  }

  if(num[0] < num[1]){
    swap(num[0],num[1]);
    swap(G[0],G[1]);
  }

  if(num[0] == y*x){
    ans = min(ans,depth+1);
    return memo[field] = 1;
  }else{
    int tmp = rec(G[0],depth+1);
    if(mount != num[1])tmp = min(tmp,rec(G[1],depth+1));
    ans = min(ans,depth+1+tmp);
    return memo[field] = tmp+1;
  }
}

int main(){
  while(cin >> x >> y,x||y){
    f = "";
    for(int i=0;i<y;i++){
      for(int j=0;j<x;j++){
	cin >> c; f += c;
      }
    }

    memo.clear();
    ans = INF;
    cout << rec(f,0) << endl;
    
  }
}

Measured memory_bytes: 2444
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::time::SystemTime;
#[fastout]

fn calc_score(d: usize, c: &Vec<i64>, s: &Vec<[i64; 27]>, t: &Vec<usize>) -> i64 {
    let mut res = 0;
    let mut last: [usize; 26 + 1] = [0; 26 + 1];
    for day in 1..=d {
        let now_contest = t[day];
        res += s[day][now_contest];
        last[now_contest] = day;
        for contest in 1..=26 {
            res -= c[contest] * (day - last[contest]) as i64;
        }
    }
    res
}

fn get_time(time: SystemTime) -> f64 {
    time.elapsed().unwrap().as_secs_f64()
}

fn main() {
    let time = SystemTime::now();

    // input
    input! {
        d: usize,
        _c: [i64; 26],
        _s: [[i64; 26]; d],
    }

    let mut c = vec![0];
    c.extend(_c.iter());

    let mut s = vec![[0; 26 + 1]; d + 1];
    for day in 1..=d {
        for contest in 1..=26 {
            s[day][contest] = _s[day - 1][contest - 1]
        }
    }

    let mut t = vec![1; d + 1];

    // process
    while get_time(time) < 1.90 {
        for _ in 1..=1000 {
            calc_score(d, &c, &s, &t);
        }
    }

    for i in 1..=d {
        println!("{}", t[i]);
    }
}


Measured memory_bytes: 2408
#include <iostream>
#include <algorithm>
using namespace std;
int N, K, a[100009], b[100009];
long long solve(int x) {
	long long ret = 0;
	for (int i = 0; i < N; i++) {
		if ((x & a[i]) == a[i]) ret += b[i];
	}
	return ret;
}
int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
	long long ret = solve(K);
	for (int i = 0; i < 30; i++) {
		if (K & (1 << i)) {
			int val = (K - (1 << i)) | ((1 << i) - 1);
			ret = max(ret, solve(val));
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define int long long
#define S second
#define F first
#define pb push_back
#define sz size()
using namespace std;
const int N=1e6+7;
const int mod=1e9+7;
int b[N],c[N],dp[2000][2000] ;
int n,x=1,ans,k,w,m ;
char a[2000][2000] ;
vector < int > vec ;
vector < int > pos ;
multiset < int > st ;
main()
{
    cin >> n >> m ;
    dp[1][1]=1 ;
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        {
            cin >> a[i][j] ;
            if (a[i][j]!='#')
                dp[i][j]+=dp[i-1][j]+dp[i][j-1] ;
            dp[i][j]%=mod ;
        }
    cout << dp[n][m] << endl;
}


Measured memory_bytes: 17268
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;


int main(){

string o,e;
cin >> o >> e;
int l = o.size();

for(int i=0;i<l;i++){
    if(i<l-1)cout << o.at(i) << e.at(i);
    else{
    if(o.size()==e.size()) cout << o.at(i) << e.at(i) << endl;
    else cout << o.at(i) <<  endl;
    }
    
}




return 0;

}



Measured memory_bytes: 256
#include<stdio.h>
#include<cmath>
#include<algorithm>
int main(void)
{
	int A, B;
	scanf("%d%d", &A, &B);
	if (A - B * 2 >= 0)
	{
		printf("%d", A - B * 2);
	}
	else
	{
		printf("0");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <iterator>
using namespace std;
int main(void){
    int n,m,p,q;
    set<int> a,b,r;
    cin>>n>>m;
    for(;m--;){
        cin>>p>>q;
        if(p==1)a.insert(q);
        if(q==n)b.insert(p);
    }
    set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(r,r.end()));
    if(r.size()!=0){
        cout<<"POSSIBLE";
    }else{
        cout<<"IMPOSSIBLE";
    }
}


Measured memory_bytes: 9600
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]
#CW = [list(map(int, list(input()))) for _ in range(H)]


X = int(input())

if(X>=30):
  print("Yes")
else:
  print("No")



Measured memory_bytes: 68732
"""
raccoon has no time limit, so will be able to use all his moves once
so just sum up the damage of each move, if greater or equal to H
then he wins
"""


def can_raccoon_win(H, A):
  if sum(A) >= H:
    return "Yes"
  return "No"
  

if __name__ == "__main__":
  H = int(input().split()[0])
  A = map(int, input().split())
  print(can_raccoon_win(H, A))

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

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

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
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")
    };
}

fn main() {
    input!{
        x: i64, y: i64
    }
    let mut z = x;
    let mut count = 0;

    while z <= y {
        count += 1;
        z *= 2;
    }

    println!("{}", count)
}


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

int main() {
    long long x;
    cin >> x;
    long long ans=0;
    ans+=x/11*2;
    if (x%11>6)
    {
        ans+=2;
    }
    else {
        if (x%11) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3584
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 keta(x: usize) -> usize {
   let mut x = x;
   let mut k = 0;
   while x % 2 == 0 {
      x /= 2;
      k += 1;
   }
   k
}

fn main() {
   input! {
      n: usize,
      a: [usize; n]
   }
   let mut ans = 0;
   for &a in a.iter() {
      ans += keta(a);
   }
   println!("{}", ans);
}


Measured memory_bytes: 4352
from itertools import product

N, M = map(int, input().split())


def on_count(p):
    c = 0
    while p > 0:
        if p % 2 == 1:
            c += 1
        p //= 2
    return c


switches = []
for i in range(M):
    k, *sw = map(int, input().split())
    switches.append(sw)
P = list(map(int, input().split()))

total = 0
for pattern in product([0, 1], repeat=N):
    t = 0
    for k, indices in enumerate(switches):
        n_on = 0
        for idx in indices:
            if pattern[idx-1]:
                n_on += 1
        if n_on % 2 == P[k]:
            t += 1
    if t == M:
        total += 1
print(total)


Measured memory_bytes: 9192
// file creato da gio il 2020-03-25 09:50:14.759573

#include <bits/stdc++.h>
#define FAST 

#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif

#define S second
#define F first
#define PB push_back
using namespace std;

int counter(int n){
	return n*(n-1)/2;

}

int main(){
	//freopen("output","w",stdout);
	//freopen("input","r",stdin);
#ifdef FAST
	ios::sync_with_stdio(0);
  	cin.tie(0);
#endif

	int N,M;
	cin >> N >>M;
	cout <<counter(N)+counter(M)<<endl ;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> H){
    RREP(i, N-2) {
        if(H[i]-1 == H[i+1]) {
            H[i]--;
        } else if (H[i] > H[i+1]) {
            cout << NO << endl;
            return;
        }
    }

    cout << YES << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    solve(N, std::move(H));
    return 0;
}


Measured memory_bytes: 1024
/*Shivam Bhalla */
/* f2016941@pilani.bits-pilani.ac.in */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <string>
#include <cmath>
#include <cassert>
#include <bits/stdc++.h>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
long long maxv = 1e9;

int main(){
	int A,B,T;
	cin>>A>>B>>T;
	int total=0;
	for(int i=A;i<=T;i+=A)
		total+=B;
	cout<<total;	

	return 0;
}


Measured memory_bytes: 764
N = int(input())
A = list(map(int, input().split( )))

A_dict = {}
for i, a in enumerate(A):
    A_dict[i+1] = a
A_dict = sorted(A_dict.items(), key=lambda x:x[1])

A_list = []
for i in range(len(A_dict)):
    A_list.append(A_dict[i][0])

print(' '.join(map(str, A_list)))


Measured memory_bytes: 25564
#include <bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(ll i =(l);(i)<(r);(i)++)
const ll MOD=1e9+7;
using namespace std;
int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    rep(num,k,n+2){
        ans+=( ((n+1)*n)/2-((n-num+1)*(n-num))/2-((num-1)*num)/2 )+1;
        ans%=MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

char str[30];
char decripted[30];
bool exists[26];

int main() {
    for (;;) {
        vector<string> answer;

        scanf("%s", str);
        if (str[0] == '#')
            break;

        size_t len = strlen(str);

        for (unsigned S = 0; S < (1 << len); ++S) {
            memset(exists, 0, sizeof(exists));
            bool valid = true;
            for (size_t i = 0; i < len; ++i) {
                if (S & (1 << i)) {
                    // transformed
                    if (str[i] == 'z' || exists[str[i] + 1 - 'a']) {
                        valid = false;
                        break;
                    }
                    decripted[i] = str[i] + 1;
                } else {
                    // as-is
                    if (str[i] != 'a' && !exists[str[i] - 'a']) {
                        valid = false;
                        break;
                    }
                    decripted[i] = str[i];
                }
                exists[decripted[i] - 'a'] = true;
            }
            if (valid) {
                decripted[len] = 0;
                answer.push_back(string(decripted));
            }
        }

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

        cout << answer.size() << endl;
        if (answer.size() <= 10) {
            for (string& s : answer)
                cout << s << endl;
        } else {
            for (size_t i = 0; i < 5; ++i)
                cout << answer[i] << endl;
            for (size_t i = 0; i < 5; ++i)
                cout << answer[answer.size() + i - 5] << endl;
        }
    }
}

Measured memory_bytes: 2352
// In the name of God

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define Size(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
typedef pair<int , int>pii;
const int INF = 1e9 + 10 , MN = 2003, MV = 4000*1000 + 10;

bitset<MV>bt;
int n , sm;

int main(){
	ios_base :: sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	cin >> n;
	bt[0] = 1;
	for(int i=0;i<n;++i){
		int x;cin>>x;
		bt |= bt << x;
		sm += x;
	}
	int ans = 0;
	for(int i=MV-1;i+i>=sm;--i)
		if(bt[i]) ans = i;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))

B = [0]*(N+1)
for l in range(N):
    B[A[l]] += 1
ans = 0
for i in range(N+1):
    ans += int(B[i] * (B[i]-1) / 2)
for k in range(N):
        print(ans - B[A[k]] + 1)

Measured memory_bytes: 26268
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 14:34:06 2020

@author: shinba
"""

n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())

ans = 0

for i in range(k):
    if t[i] == "r":
        ans += p
    elif t[i] == "s":
        ans += r
    else:
        ans += s

for i in range(k,n):
    if t[i] == "r":
        if t[i-k] != "r":
            ans += p
        else:
            t[i] = "d"
    elif t[i] == "s":
        if t[i-k] != "s":
            ans += r
        else:
            t[i] = "d"
    else:
        if t[i-k] != "p":
            ans += s
        else:
            t[i] = "d"

print(ans)
            
    
    

Measured memory_bytes: 4084
## coding: UTF-8
N = int(input())
A = sorted(list(map(int,input().split())))


#print(A)

MAX = 10**6+1000
l = [True] * MAX


count = 0
last = -1
mode = 0
for i in range(len(A)):
    e = A[i]
    if(last == e):
        count -= 1
        last = -1
    if(l[e]):
        count += 1
        for j in range(MAX):
            try:
                l[j*e] = False
            except IndexError:
                break
        last = e

    #print(l)

print(count)


Measured memory_bytes: 114024
#include <stdio.h>
#include <math.h>

using namespace std;


int main(){
	double x1,x2,x3,x4,y1,y2,y3,y4,dist1,dist2,dist3,dist4,dist5,dist6;

	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF){
		dist1 = sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
		dist2 = sqrt((x2-x4)*(x2-x4)+(y2-y4)*(y2-y4));
		dist3 = fabs((y2-y4)*x1+(x4-x2)*y1+y2*(x2-x4)-x2*(y2-y4))/(sqrt((y2-y4)*(y2-y4)+(x4-x2)*(x4-x2)));
		dist4 = fabs((y1-y3)*x2+(x3-x1)*y2+y1*(x1-x3)-x1*(y1-y3))/(sqrt((y1-y3)*(y1-y3)+(x3-x1)*(x3-x1)));
		dist5 = fabs((y2-y4)*x3+(x4-x2)*y3+y2*(x2-x4)-x2*(y2-y4))/(sqrt((y2-y4)*(y2-y4)+(x4-x2)*(x4-x2)));
		dist6 = fabs((y1-y3)*x4+(x3-x1)*y4+y1*(x1-x3)-x1*(y1-y3))/(sqrt((y1-y3)*(y1-y3)+(x3-x1)*(x3-x1)));

		if(dist1 < dist3 || dist2 < dist4 || dist1 < dist5 || dist2 < dist6){
			printf("NO\n");
		}else{
			printf("YES\n");
		}
	}

	return 0;
}

Measured memory_bytes: 2728
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N; cin >> N;
    vec<lint> A_list(N);
    range(i, 0, N) cin >> A_list.at(i);
    unordered_map<lint, lint> count;
    range(i, 0, N) {
        count[i - A_list.at(i)] += 1;
    }
    lint ans = 0;
    range(i, 0, N) {
        ans += count[i + A_list.at(i)];
    }
    cout << ans << "\n";
}

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

int main(){
    int N;
    cin >> N;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    int mxi = max_element(A.begin(), A.end()) - A.begin();
    int mni = min_element(A.begin(), A.end()) - A.begin();
    vector<pair<int, int>> ans;
    if(abs(A[mxi]) > abs(A[mni])){
        for(int i=0; i<N; i++) if(i != mxi) ans.emplace_back(mxi, i);
        for(int i=0; i<N-1; i++) ans.emplace_back(i, i+1);
    }else{
        for(int i=0; i<N; i++) if(i != mni) ans.emplace_back(mni, i);
        for(int i=N-1; i>0; i--) ans.emplace_back(i, i-1);
    }
    cout << ans.size() << endl;
    for(auto& p : ans){
        A[p.second] += A[p.first];
        cout << p.first+1 << " " << p.second+1 << endl;
    }
    for(int64_t a : A) cerr << a << " ";
    cerr << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

class Node:
    __slots__ = ['value', 'parent', 'left', 'right']
    def __init__(self, value: int, parent: 'Node' = None):
        self.value = value
        self.parent = parent
        self.left: Node = None
        self.right: Node = None
    def inParse(self):
        if self.value == None:
            return
        if self.left != None:
            self.left.inParse()
        print(' {}'.format(self.value), end='')
        if self.right != None:
            self.right.inParse()
    def preParse(self):
        if self.value == None:
            return
        print(' {}'.format(self.value), end='')
        if self.left != None:
            self.left.preParse()
        if self.right != None:
            self.right.preParse()

class BinarySearchTree:
    __slots__ = ['root']
    def __init__(self):
        self.root: Node = None
    def insert(self, x: int):
        if self.root == None:
            self.root = Node(x)
            return
        parent, current = None, self.root
        while current:
            parent = current
            if x < current.value:
                current = current.left
            else:
                current = current.right
        if x < parent.value:
            parent.left = Node(x, parent)
        else:
            parent.right = Node(x, parent)
    def find(self, x: int):
        y = self.root
        while y != None and y.value != x:
            if y.value > x:
                y = y.left
            else:
                y = y.right
        return y
    def getMinimum(self, x: Node):
        while x.left != None:
            x = x.left
        return x
    def getSuccer(self, x: Node):
        if x.right != None:
            return self.getMinimum(x.right)
        y = x.parent
        while y != None and x == y.right:
            x = y
            y = y.parent
        return y
    def deleteNode(self, z: Node):
        if z.left == None or z.right == None:
            y = z
        else:
            y = self.getSuccer(z)
        if y.left != None:
            x = y.left
        else:
            x = y.right
        if x != None:
            x.parent = y.parent
        if y.parent == None:
            self.root = x
        elif y.parent.left == y:
            y.parent.left = x
        else:
            y.parent.right = x
        if y != z:
            z.value = y.value
        
def main():
    tree = BinarySearchTree()
    n = int(input())
    for _ in range(n):
        inp = input()
        if inp[0] == 'i':
            com, num = inp.split()
            tree.insert(int(num))
        elif inp[0] == 'f':
            com, num = inp.split()
            if tree.find(int(num)):
                print('yes')
            else:
                print('no')
        elif inp[0] == 'd':
            com, num = inp.split()
            y = tree.find(int(num))
            tree.deleteNode(y)
        else:
            tree.root.inParse()
            print()
            tree.root.preParse()
            print()

if __name__=='__main__': main()


Measured memory_bytes: 47516
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define ull unsigned long long
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
int INF = 1001001001;
const int MOD=1e9+7;

int main()
{
  int n,k;
  in n>>k;
  int64_t ans=k*pow((k-1),(n-1));
  
  cout<<ans<<endl;
}


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

int main(){
    int a[4];
    char c;
    for(int i = 0; i < 4; i++)  cin >> c, a[i] = c-'0';
    string s = "-+";
    for(int i = 0; i < 8; i++){
        int sum = a[0];
        for(int j = 0; j < 3; j++){
            sum += a[j+1] * (2*((i>>j)&1)-1);
        }
        if(sum == 7){
            cout << a[0];
            for(int j = 1; j < 4; j++){
                cout << s[(i>>(j-1))&1] << a[j];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
}

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

typedef long long ll;
#define int ll
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef pair<int,int> pii;
#define pb push_back
#define INF 1000000000
#define mp make_pair
#define MOD 1000000007
#define F first
#define S second
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPD(i,n) for(int i=(n);i>=0;i--)
#define FORD(i,a,b) for(int i=(a);i>=b;i--)
#define all(v) v.begin(),v.end()
#define itr ::iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remin(a,b) (a) = min((a),(b))
#define remax(a,b) (a) = max((a),(b))

signed main() {
	int cnt[5] = {0,0,0,0,0};
	REP(i,3){
		int x,y; cin >> x >> y;
		cnt[x] ++;
		cnt[y] ++;
	}
	int gg1 = 0,gg2 = 0;
	FOR(i,1,5){
		if(cnt[i] == 1) gg1 ++;
		else gg2 ++;
	}
	if(gg1 == 2 and gg2 == 2) cout << "YES\n";
	else cout << "NO\n";
}


Measured memory_bytes: 256
// AtCoder My Practice
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let h = get!(usize);
    let w = get!(usize);
    
    let mut xs = vec![];
    let mut rw = 0;
    let mut cl = 0;
    for r in 0..h {
    	let mut ys = vec![];
    	for c in 0..w {
        	let y = get!();
        	ys.push(y);
        }
    	xs.push(ys);
    }
    
    let mut ans = vec![];
    for r in 0..h {
    	for c in 0..w-1 {
            if xs[r][c] % 2 == 0 {
            	continue;
            }
            xs[r][c+1] += 1;
            ans.push((r, c, r, c + 1));
        }
    }
    for r in 0..h-1 {
    	if xs[r][w-1] % 2 == 0 {
        	continue;
        }
        xs[r+1][w-1] += 1;
        ans.push((r, w-1, r+1, w-1));
    }
    println!("{}", ans.len());
    for &(r, c, y, x) in ans.iter() {
    	println!("{} {} {} {}", r+1, c+1, y+1, x+1);
    }
    
}



Measured memory_bytes: 14836
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    if(n%2==0){
    for(int i=n-1;i>=0;i-=2){
        if(i!=n-1)cout<<' ';
        cout<<a[i];
    }
    for(int i=0;i<n;i+=2)cout<<' '<<a[i];
    cout<<endl;
    }else{
        for(int i=n-1;i>=0;i-=2){
        if(i!=n-1)cout<<' ';
        cout<<a[i];
    }
    for(int i=1;i<n;i+=2)cout<<' '<<a[i];
    cout<<endl;
    }
}


Measured memory_bytes: 2944
n=int(input())
a=list(map(int,input().split()))
f=[True if a[i]==i+1 else False for i in range(n)]
ans=0
for i in range(n-1):
    if f[i] and f[i+1]:
        f[i]=False
        f[i+1]=False
        ans+=1

ans+=sum(f)
print(ans)

Measured memory_bytes: 14008
n=int(input())
MOD=10**9+7 
def isp(i):
    if i<=1:
        return 0 
    return all(i%j for j in range(2,int(i**0.5)+1))
ans=1 
def po(x,n):
    c=0 
    while n//x:
        c+=n//x 
        n//=x 
    return c 
for i in range(2,n+1):
    if isp(i): 
        p=po(i,n)
        ans*=(p+1)
        ans%=MOD 
print(ans)
        

Measured memory_bytes: 38640
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  
  auto red = count(s.cbegin(), s.cend(), 'R');
  auto blue = count(s.cbegin(), s.cend(), 'B');
  
  if(red > blue) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


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

use std::cmp;

fn main() {
    let _ = get!(usize);
    let mut x: i32 = 0;
    let mut max_x: i32 = 0;
    let s = get!(String);
    for c in s.chars().into_iter() {
        match c {
            'I' => { x += 1; },
            'D' => { x -= 1; },
            _ => (),
        };
        max_x = cmp::max(x, max_x);
    }
    println!("{}", max_x);
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<ll,ll> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const ll dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

class union_find{
	private:
	vector<ll> parent,diff;
    ll size;
	public:
    union_find()=default;
    union_find(ll n){ init(n); }

    void init(int n){
		size=n;
		parent.resize(size);
        diff.resize(size);
		for(ll i=0; i<size; ++i){
			parent[i]=i;
            diff[i]=0;
		}
	}

	pii find(int x){
		if(parent[x]==x) return make_pair(x,0);
        pii p=find(parent[x]);
        parent[x]=p.first;
        diff[x]+=p.second;
        return make_pair(parent[x],diff[x]);
	}

	void unite(int x,int y,int w){
		pii a=find(x),b=find(y);
		if(a.first==b.first) return;
        if(diff[y]+w-diff[x]>=0){
            parent[a.first]=b.first;
            diff[a.first]=diff[y]+w-diff[x];
        }else{
            parent[b.first]=a.first;
            diff[b.first]=-diff[y]-w+diff[x];
        }
	}

	bool is_same(int x,int y){
		return find(x).first==find(y).first;
	}

    ll calc_diff(int x,int y){
        auto a=find(x),b=find(y);
        return find(x).second-find(y).second;
    }
};

void solve(int n,int m){
    union_find uf(n);

    rep(i,0,m){
        char ch;
        ll a,b;
        cin >> ch >> a >> b;
        --a;
        --b;
        if(ch=='!'){
            int w;
            cin >> w;
            uf.unite(a,b,w);
        }else{
            if(!uf.is_same(a,b)) cout << "UNKNOWN" << endl;
            else cout << uf.calc_diff(a,b) << endl;
        }
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    while(true){
        ll n,m;
        cin >> n >> m;
        if(!n and !m) break;
        solve(n,m);
    }
    return 0;
}

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


int main() {

double N,M;
cin>>N>>M;

vector<double> a(N);
for(int i=0;i<N;i++) cin>>a[i];

sort(a.begin(),a.end());
reverse(a.begin(),a.end());
double sum=0;
for(int i=0;i<N;i++){
  sum+=a[i];
}
double cnt=0;

double t;

  t=double(sum/4/M);
  for(int i=0;i<M;i++){
    if(a[i]>=t) cnt++;
  }




//cout<<sum<<endl;
//cout<<t<<endl;

if(cnt>=M) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}


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

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;

int gcd(ll a, ll b) {
	if (a < b) swap(a, b);
	while(ll r = (a%b)) {
		a = b;
		b = r;
	}
	return b;
}

int main() {
	speed;
	int n, m;
	cin >> n >> m;
	vector<vector<int>>drink(n,vector<int>(2));
	rep(i, n) {
		cin >> drink[i][0];
		cin >> drink[i][1];
	}
	sort(All(drink));
	ll sum = 0;
	ll ans = 0;
	rep(i, n) {
		ffor(j,1,drink[i][1]+1) {
			ans += drink[i][0];
			sum++;
			if (sum == m)break;
		}
		if (sum == m)break;
	}
	c(ans);
	return 0; 
}



Measured memory_bytes: 5760
N, M = map(int,input().split())
from1 = set()
toN = set()
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        from1.add(b)
    if b == N:
        toN.add(a)
if from1 & toN :
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 19024
N = int(input())
XU = [list(map(str,input().split())) for _ in range(N)]

ans = 0

for i in range(N):
    if XU[i][1] == "JPY":
        ans += float(XU[i][0])
    else:
        ans += 380000*float(XU[i][0])

print(float(ans))

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

#define fi first
#define sd second
#define lson (nd<<1)
#define rson (nd<<11)
#define PB push_back
#define mid (l+r>>1)
#define MP make_pair
#define SZ(x) (int)x.size()

using namespace std;

typedef long long LL;

typedef vector<int> VI;

typedef pair<int,int> PII;

inline int read(){
    int res=0, f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
    return res*f;
}

const int MAXN = 200'005;

const int MOD = 1000000007;

bool check(string s){
    int sz=SZ(s);
    for(int i=0;i<sz/2;++i)if(s[i]!=s[sz-i-1])return false;
    return true;
}

int main(){
    string s;cin>>s;
    int sz=SZ(s);
    int f1=check(s);
    int f2=check(s.substr(0,sz/2));
    int f3=check(s.substr((sz+1)/2,sz/2));

    if(f1&&f2&&f3)cout<<"Yes";
    else cout<<"No";

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) cin >> A[i];
	long long L = 2, R = 2;
	for (int i = N - 1; i >= 0; --i) {
		L = (L + A[i] - 1) / A[i] * A[i];
		R = R / A[i] * A[i] + A[i] - 1;
		if (L > R) break;
	}
	if (L > R) cout << -1 << endl;
	else cout << L << ' ' << R << endl;
	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    vector<ll>v;
    map<ll,ll>mp;
    for(ll i=0;i<n;i++)
        {
            cin>>a[i];
            if(find(v.begin(),v.end(),a[i])==v.end())
                v.push_back(a[i]);
                mp[a[i]]++;
        }
        sort(v.begin(),v.end());
        //reverse(v.begin(),v.end());
        ll cnt=0;
        ll rc=0;
        if(v.size()==1)
            {cout<<"0\n";
        return 0;}
    for(ll i=0;i<v.size()-2;i++)
    {
        for(ll j=i+1;j<v.size()-1;j++)
        {
            for(ll k=j+1;k<v.size();k++)
            {
                if(v[i]+v[j]>v[k])
                    {
                        rc+=(mp[v[i]]*mp[v[j]]*mp[v[k]]);
                    }
                else
                    break;
            }
        }
    }
    cout<<rc<<"\n";
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int k, t;
    cin >> k >> t;
    priority_queue<pair<int, int> > pq;
    rep (i, t) {
        int a;
        cin >> a;
        pq.push(make_pair(a, i));
    }
    int res = 0;
    int prev = -1;
    while (!pq.empty()) {
        int num, id;
        num = pq.top().first, id = pq.top().second;
        pq.pop();
        if (prev != id) {
            prev = id;
            num--;
            if (num > 0) {
                pq.push(make_pair(num, id));
            }
        } else {
            if (!pq.empty()) {
                int x, y;
                x = pq.top().first, y = pq.top().second;
                pq.pop();
                x--;
                if (x > 0) pq.push(make_pair(x, y));
                pq.push(make_pair(num, id));
                prev = y;
            } else {
                res = num;
                break;
            }
        }
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 256