akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

void bfs(ll n, vector<vll> &children, ll start, vll &cnt) {
  queue<ll> task;
  task.push(start);

  vector<ll> visit(n, 0);
  visit[start] = 1;

  ll depth = 0;

  while (task.size() > 0) {
    ll sz = task.size();
    for (int i = 0; i < sz; i++) {
      for (int j = 0; j < children[task.front()].size(); j++) {
        if (visit[children[task.front()][j]] == 0) {
          cnt[children[task.front()][j]] += cnt[task.front()];
          task.push(children[task.front()][j]);
          visit[children[task.front()][j]] = 1;
        }
      }
      task.pop();
    }
    depth++;
  }
  return;
}

int main() {
  ll n, q;
  cin >> n >> q;
  vector<ll> a(n - 1), b(n - 1), p(q), x(q), cnt(n, 0);
  for (ll i = 0; i < n - 1; i++) cin >> a.at(i) >> b.at(i);
  for (ll i = 0; i < q; i++) cin >> p.at(i) >> x.at(i);
  for (ll i = 0; i < q; i++) cnt.at(p.at(i) - 1) += x.at(i);
  vector<vector<ll>> children(n);
  for (int i = 0; i < n - 1; i++) {
    children.at(a.at(i) - 1).push_back(b.at(i) - 1);
    children.at(b.at(i) - 1).push_back(a.at(i) - 1);
  }
  bfs(n, children, 0, cnt);
  for (ll i = 0; i < n - 1; i++) cout << cnt.at(i) << " ";
  cout << cnt.at(n - 1) << endl;
}

Measured memory_bytes: 24148
use std::cmp::max;
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($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;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = scan!(usize);
    let vs = scan!(usize, usize;n);

    let (mut a, mut t) = vs[0];
    for &(x, y) in vs.iter().skip(1) {
        let k = max((a + x - 1) / x, (t + y - 1) / y);
        a = k * x;
        t = k * y;
    }
    println!("{}", a + t);
}


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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni(), m = in.ni();
        int[][] py = new int[m][2];
        Year[] year = new Year[n];
        for (int i = 0; i < n; i++) year[i] = new Year();
        for (int i = 0; i < m; i++) {
            int p = in.ni()-1,  y = in.ni();
            py[i][0] = p;
            py[i][1] = y;
            year[p].add(y);
        }
        for (Year a: year) Collections.sort(a);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < m; i++) {
            int l = -1, r = year[py[i][0]].size(), mid = 0;
            while(true){
                mid = (l+r)/2;
                if(year[py[i][0]].get(mid)==py[i][1]) break;
                else if(year[py[i][0]].get(mid)<py[i][1]) l = mid;
                else r = mid;
            }
            sb.append(String.format("%06d", py[i][0]+1));
            sb.append(String.format("%06d", mid+1));
            sb.append('\n');
        }
        out.println(sb);
    }
    public static class Year extends ArrayList<Integer>{}

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 116816
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		String t = sc.next();
		int x = s.length();
		int y = t.length();
		int[][] dp = new int[x + 10][y + 10];

		for (int i = 0; i < x; i++) {
			for (int j = 0; j < y; j++) {
				if (s.charAt(i) == t.charAt(j)) {
					dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i][j] + 1);
				}
				dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i + 1][j]);
				dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i][j + 1]);
			}
		}

//		for(int i=0; i<=x; i++) {
//			for (int j=0; j<=y; j++) {
//				System.out.print(dp[i][j]+"\t");
//			}
//			System.out.println();
//		}

		String ans = "";

		while (x > 0 && y > 0) {
			if (dp[x][y] == dp[x - 1][y]) {
				x--;
			} else if (dp[x][y] == dp[x][y - 1]) {
				y--;
			} else {
				ans = s.charAt(x - 1) + ans;
				x--;
				y--;
			}
		}

		System.out.println(ans);
		sc.close();
	}
}

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

int main()
{
   long long n,a[100000],i,d=1,kq=0;
   cin>>n;
   for(i=1;i<=n;i++)
   {
   		cin>>a[i];
  	}
    sort(a+1,a+1+n);
    for (i=2;i<=n+1;i++)
    {
    	if (a[i]==a[i-1])
    	{
    		d++;
		}
		else
		{
			if (d>a[i-1])
			{
				kq+=d-a[i-1];
			}
			else if (d<a[i-1])
			{
				kq+=d;
			}
			d=1;
		}
	}
	cout<<kq;
}

Measured memory_bytes: 1024
/**
 *    author:  tourist
 *    created: 03.02.2018 17:21:41       
**/
#include <bits/stdc++.h>

using namespace std;

string query(int x) {
  cout << x << endl;
  fflush(stdout);
  string res;
  cin >> res;
  if (res == "Vacant") {
    exit(0);
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  int i = 0;
  int j = n - 1;
  string x = query(0);
  string y = query(n - 1);
  while (true) {
    int k = (i + j) >> 1;
    string z = query(k);
    if ((z == x) != (i % 2 == k % 2)) {
      j = k;
      y = z;
    } else {
      i = k;
      x = z;
    }
  }
  return 0;
}


Measured memory_bytes: 852
#include<stdio.h>
#include<set>
using namespace std;
struct pr{
	int l,r;
	pr(int a=0,int b=0){
		if(a>b)swap(a,b);
		l=a;
		r=b;
	}
};
bool operator<(pr a,pr b){return a.l==b.l?a.r<b.r:a.l<b.l;}
set<pr>s;
set<int>g[100010];
int fa[100010];
int get(int x){
	return fa[x]==x?x:(fa[x]=get(fa[x]));
}
void add(int x,int y){
	set<int>::iterator it=g[x].find(y);
	if(it==g[x].end())
		g[x].insert(y);
	else{
		g[x].erase(it);
		s.insert(pr(x,y));
	}
}
int main(){
	int n,m,i,x,y;
	scanf("%d",&n);
	for(i=1;i<=2*n-2;i++){
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	for(i=1;i<=n;i++)fa[i]=i;
	m=0;
	while(!s.empty()){
		set<pr>::iterator it=s.begin();
		x=get(it->l);
		y=get(it->r);
		s.erase(it);
		if(g[x].size()>g[y].size())swap(x,y);
		fa[x]=y;
		for(int i:g[x]){
			g[i].erase(x);
			add(i,y);
			add(y,i);
		}
		g[x].clear();
		m++;
	}
	puts(m==n-1?"YES":"NO");
}

Measured memory_bytes: 24064
#include <iostream>
using namespace std;
typedef long long ll;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    COMinit();
    int n,k;cin>>n>>k;
    if(k>=n-1){
        cout << COM(2*n-1, n-1) << endl;
    }
    else{
        ll ans=0;
        for(int i=0;i<k+1;i++){
            ll a=COM(n,i);
            ll b=COM(n-1,i);
            ll c=a*b%MOD;
            ans+=c;   
        }
        cout<<ans%MOD<<endl;
    }
}

Measured memory_bytes: 12160
// Author: getharshkumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, c = 0;
    cin >> n;
    for (ll i = 1; i <= n; i++)
        c += !(ll(log10(i)) % 2);
    cout << c;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
int main()
{
  int a, b, h, m;
  const double pi = 3.14159265358979;
  double th;
  double l;
  std::cin >> a >> b >> h >> m;
  th = (30 * h - 5.5 * m) * pi / 180.0;
  l = std::sqrt(a * a + b * b - 2 * a * b * std::cos(th));
  std::cout << std::fixed << std::setprecision(15) << l << std::endl;
  return 0;
}

Measured memory_bytes: 4244
import java.util.*

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val L = readLine()!!.split(" ").map {it.toInt()}.sorted()

    var res = 0L

    for (i in L.indices) for (j in i + 1 until L.size) {
        val l = Math.abs(L[i] - L[j])
        val u = L[i] + L[j]

        val a = Math.max(upperBound(L, l), j + 1)
        val b = lowerBound(L, u)

        if (b < a) {
            continue
        }

        res += (b - a)

        if (i in a until b) {
            res -= 1L
        }
        if (j in a until b) {
            res -= 1L
        }
    }

    println(res)
}

//private fun lowerBound(list: List<Int>, v: Int): Int {
//    if (list.last() < v) {
//        return list.size
//    }
//
//    var l = -1
//    var u = list.size - 1
//
//    while (u - l > 1) {
//        val c = (u + l) / 2
//        if (list[c] >= v) {
//            u = c
//        } else {
//            l = c
//        }
//    }
//
//    return u
//}

private fun lowerBound(a: List<Int>, v: Int): Int {
    var l = -1
    var u = a.size

    while (u - l > 1) {
        val c = (l + u) / 2

        if (a[c] >= v) {
            u = c
        } else {
            l = c
        }
    }

    return u
}

private fun upperBound(list: List<Int>, v: Int): Int {
    var l = 0
    var u = list.size

    while (u - l > 1) {
        val c = (u + l) / 2
        if (list[c] > v) {
            u = c
        } else {
            l = c
        }
    }

    return u
}


Measured memory_bytes: 40972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        while(true){
            String str[] = br.readLine().split(" ");
            int H = Integer.parseInt(str[0]);
            int W = Integer.parseInt(str[1]);
            if(H==0 && W==0) break;
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if((i+j)%2==0){
                        sb.append("#");
                    }else{
                        sb.append(".");
                    }
                }
                sb.append("\n");
            }
            sb.append("\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 25456
#!/usr/bin/ruby

def divide_2_num( n )
    res = 0
    while (n % 2 == 0)
        res += 1
        n = n / 2
    end
    res
end

n = gets.chomp.to_i
input = gets.chomp.split(" ")

res = nil
input.each do |a|
    da = divide_2_num(a.to_i)
    if res.nil? or res > da
        res = da
    end 
end
puts res


Measured memory_bytes: 14300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

//mainの外で宣言
ll a[100010][3];
ll dp[100010][3];

int main() {
    //入力
    //mainの内で宣言
    //ll a[100010][3];
    //ll dp[100010][3];
    ll N; 
    cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    //遷移
    for (ll i = 0;i<N;i++) {
        for (ll j = 0;j<3;j++) {
            for (ll k = 0;k<3;k++) {
                if (j==k) continue;
                chmax(dp[i+1][k],dp[i][j] + a[i][k]);
            }
        }
    }
    ll ans = max(dp[N][0],dp[N][1]); //dp[i] はi日目なので注意,
    ans = max(ans,dp[N][2]);         //N日目はN-1でなく、dp[N]なので注意
    cout << ans << endl;
}

Measured memory_bytes: 4992
/*
Author: Babin Dutta
*/
 
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define inf 1e18
#define mm 998244353
 
ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

const int N = 1e7+1;

int a[N];

void sieve(){
	for(int i=1;i<=N;i++){
		for(int j=i;j<=N;j+=i) a[j]++;
	}
}

void solve(){
    sieve();
    ll n; cin>>n;
    ll ans = 0ll;
    for(ll i=1;i<=n;i++){
    	ans += (1ll * a[i] * i);
	}
	cout<<ans<<endl;
}
 
int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

Measured memory_bytes: 42704
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.*
import kotlin.system.exitProcess

@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out

const val _BUFFER_SIZE = 1 shl 16
@JvmField val _buffer = ByteArray(_BUFFER_SIZE)
@JvmField var _bufferPt = 0
@JvmField var _bytesRead = 0

tailrec fun readChar(): Char {
    if(_bufferPt == _bytesRead) {
        _bufferPt = 0
        _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)
    }
    return if(_bytesRead < 0) Char.MIN_VALUE
    else {
        val c = _buffer[_bufferPt++].toChar()
        if (c == '\r') readChar()
        else c
    }
}

fun readLine(): String? {
    var c = readChar()
    return if(c == Char.MIN_VALUE) null
    else buildString {
        while(true) {
            when(c) {
                '\n', Char.MIN_VALUE -> return@buildString
                else -> {
                    append(c)
                    c = readChar()
                }
            }
        }
    }
}
fun readLn() = readLine()!!

fun read() = buildString {
    var c = readChar()
    while(c <= ' ') {
        if(c == Char.MIN_VALUE) return@buildString
        c = readChar()
    }
    do {
        append(c)
        c = readChar()
    } while(c > ' ')
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readLines(n: Int) = List(n) { readLn() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }


fun main() {
    val n = readInt()
    val s = readLine()!!

    val r = mutableListOf<Int>()
    val w = mutableListOf<Int>()

    val rCount = s.count { it == 'R' }
    val wCount = n - rCount

    var rWrong = 0
    var wWrong = 0

    for (i in 0 until rCount) {
        if (s[i] == 'W') {
            wWrong++
        }
    }

    for (i in rCount until n) {
        if (s[i] == 'R') {
            rWrong++
        }
    }

    println(min(wWrong, rWrong))


}

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

int main() {
long long x,y,z;
cin >> x >> y >> z;
int ans=0;
for(int i=1;i<50000;i++){
    long long dist=y*i+z*(i+1);
    if(dist<=x)ans=i;
}
cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll n;
	ll a[100001];

	cin>>n;

	rep(i,n){
		cin>>a[i];
	}
	sort(a,a+n);
	ll total=0;
	ll x=1;
	for(ll i=1; i<n; i++){
		if(a[i-1]!=a[i]){
			if(x>=a[i-1]){
				total+=x-a[i-1];
			}else if(x<a[i-1]){
				total+=x;
			}
			x=1;
		}else{
			x++;
		}
	}
	if(x>a[n-1]){
		total+=x-a[n-1];
	}else if(x<a[n-1]){
		total+=x;
	}
	cout<<total<<endl;
	return 0;
}


Measured memory_bytes: 1024
// 

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

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

using namespace std;

int main(){
  int n;
  vector<int> v;
  long long sum = 0;
  long long ans = 0;

  cin >> n;
  for(int i = 0; i < n; i++){
    int work;
    cin >> work;
    v.push_back(work);
  }
  // sum = v[0];

  int r = 0;
  for(int l = 0; l < n; l++){
    while(r < n){
      if((sum ^ v[r]) != (sum + v[r])) break;
      // cout << "L:" << l << " R:" << r << endl;
      sum += v[r];
      r++;
    }
    ans += r - l;
    sum -= v[l];
/*    if(r != l) sum -= v[l];
    else r++;*/
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1400
import java.util.Scanner;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        String hoge = sc.next();
        if(hoge.equals("Sunny")){
            System.out.println("Cloudy");
        }else if(hoge.equals("Cloudy")){
            System.out.println("Rainy");
        }else{
            System.out.println("Sunny");
        }
    }     
}

Measured memory_bytes: 21716
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
    #define lb lower_bound 
    #define ub upper_bound
    #define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define vi vector<int> 
	#define vvi vector<vi>
    #define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
    #define all(c) (c).begin(),(c).end()
    #define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
    
	const int N =1e6;
    
     int mod= 1e9+7;
     
     int dx[4]={0,0,+1,-1};
     int dy[4]={+1,-1,0,0};
   
     void solve(){
         int n,k;
         cin>>n>>k;
         
         vi v(n,0);
         
         int sum=0;
         
        rep(i,0,n)
         cin>>v[i];
       
           int tt=k*(k-1)/2;
           tt%=mod;
           
       rep(i,0,n){
           rep(j,0,n){
               
               if(v[i]<=v[j]) continue;
                              
               sum+=tt;
               sum%=mod;
                              
               if(i<j){
                 sum+=k;
                 sum%=mod;
               }
           }
       }
       
       cout<<sum<<endl;  
     }
   
   
   
   
      int32_t main() {
	    cool;
	    int t=1;
        //cin>>t;
	    while(t--)
	       solve();
	       
	       
	       return 0;	   
	   }


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,t,n,money[4],seki[4]={6000,4000,3000,2000};
	for(i=0;i<4;i++){
		scanf("%d %d",&t,&n);
		money[i] = seki[t-1] * n;
	}
	for(i=0;i<4;i++)
		printf("%d\n",money[i]);
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<list>
#include<algorithm>
#include <ctype.h>
#include<deque>
using namespace std;
using ll = long long int;

string s;
int n, pos = 0;

int cnt(char c) {
	int ret = 0;
	for (int i = pos; i < n; i++) {
		if (c == s[i]) {
			ret++;
			pos++;
		}
		else
			break;
	}
	return ret;
}

int main(void) {
	cin >> s;
	n = s.size();

	for (int i = 0; i < n; i++) {
		int r = cnt('R');
		int l = cnt('L');
		for (int j = 1; j < r; j++)
			cout << "0 ";
		int tmp1 = (r + l) / 2;
		int tmp2 = tmp1;
		if ((r + l) % 2 == 1) {
			if (r > l) {
				if (r % 2 == 0)
					tmp2++;
				else
					tmp1++;
			}
			else {
				if (l % 2 == 0)
					tmp1++;
				else
					tmp2++;
			}
		}
		cout << tmp1 << " ";
		cout << tmp2 << " ";
		for (int j = 1; j < l; j++)
			cout << "0 ";
		i = pos - 1;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>

using namespace std;

int N;
int A[110000];

int main () {
	scanf ("%d", &N);
	for (int i = 0; i < N; i++) scanf ("%d", &A[i]);
	int ans = 1, pos = A[1] - A[0];
	for (int i = 2; i < N; i++) {
		if (pos == 0) pos = A[i] - A[i - 1];
		if (1LL * pos * (A[i] - A[i - 1]) < 0) {
			ans++;
			pos = 0;
		}
	}
	printf ("%d\n", ans);
}



Measured memory_bytes: 512
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::HashMap;

fn main() {
    let s: String = read();
    let mut map: HashMap<char, bool> = HashMap::new();
    let sc: Vec<char> = s.chars().collect();
    for i in sc {
        if map.contains_key(&i) {
            println!("no");
            return
        } else {
            map.insert(i, true);
        }
    }
    println!("yes");
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
long long p[100005],re[100005];
main()
{
    int t;
    long long pp;
    scanf("%d%lld",&t,&pp);
    for(int i = 1;i <= t;i++)
    {
        scanf("%lld",&p[i]);
    }
    vector<int>v;
    for(int i = 1;i <= t;i++)
    {
        if(p[i]+p[i-1]>=pp)
        {
            for(int j = 1;i-j >= 1;j++)
            v.push_back(i-j);
            for(int j = i;j < t;j++)
            v.push_back(j);
        }
        else if(p[i]+p[i+1]>=pp)
        {
            for(int j = i;j < t;j++)
            v.push_back(j);
            for(int j = 1;i-j >= 1;j++)
            v.push_back(i-j);
        }
        if(v.size()!=0)
        {
            printf("Possible\n");
            for(int j = v.size()-1;j >= 0;j--)
            {
                printf("%d\n",v[j]);
            }
            return 0;
        }
    }
    printf("Impossible");
}


Measured memory_bytes: 2168
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  int N, K, max = 0;
  cin >> N >> K;
  int l[N+1];
  for(int i=0; i<N; ++i)
    cin >> l[i];

  sort(l, l+N, greater<int>());

  for(int i=0; i<K; ++i) {
    max += l[i];
  }

  cout << max << endl;

  return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let a: u32 = read();
    let b: u32 = read();

    let sum = a + b;
    let ans = (sum + 1) / 2 ;
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int x = sc.nextInt();
		System.out.println(a+b>=x && a<=x ? "YES" : "NO");
	}
}

Measured memory_bytes: 21716
n_str = input()
n_int = int(n_str)
n_list = list(map(int,list(n_str)))

def get_max_num():
    digits = len(n_list)
    if digits == 1:
        return n_list[0]
    else:
        # 1桁下げて全ての桁9にする場合を考える
        max_cnt = 0
        for i in range(digits-1):
            max_cnt += 10**i*9
        # 1桁下げて全て9にしたものに、頭に1~9をつけていきNを超えたらbreak
        for i in range(1,10):
            cnt = max_cnt + 10**(digits-1)
            if cnt <= n_int:
                max_cnt = cnt
            else:
                return max_cnt
        #nが全桁9の時、上だと何も返さないので、もう一度returnしてあげる
        return max_cnt

max_num = get_max_num()
max_num_list = list(map(int,list(str(max_num))))
print(sum(max_num_list))

Measured memory_bytes: 38256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

int cnt = 0;
string S, T;

void solve(){
	rep(i, 3){
    	if(S[i] == T[i]) cnt++;
    }
    cout << cnt << endl;
}

int main(){
    cin >> S >> T;

    solve();
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;
  cin >>n>>k;
  ll quotient = n/k;

  cout << min(n - k * quotient, -(n-k*(quotient+1))) << endl;

  return 0;
}


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

int main() {
  int n,k;
  cin >> n >> k;
  bitset<100> flag;
  rep(i,k){
    int d;
    cin >> d;
    rep(j,d){
     int a;
     cin >> a;
     flag.set(a-1,1);
    }
  }
  int result=0;
  rep(i,n)if(!flag.test(i))result++;
  cout << result << endl;
}

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


#define NUM 10005

struct Edge{
	Edge(int arg_from,int arg_to,int arg_cost){
		from = arg_from;
		to = arg_to;
		cost = arg_cost;
	}
	bool operator<(const struct Edge &arg) const{
		return cost > arg.cost;
	}
	int from,to,cost;
};

struct Data{
	Data(int arg_cost){
		cost = arg_cost;
	}
	bool operator<(const struct Data &arg) const{
		return cost > arg.cost;
	}
	int cost;
};

int V,E;
int num_base,num_destroy;
int height[NUM],boss[NUM],base_count[NUM];
int case_num;
vector<Edge> G;
priority_queue<Data> Q;

int get_boss(int id){
	if(id == boss[id])return id;
	else{
		return boss[id] = get_boss(boss[id]);
	}
}

bool is_same_group(int x,int y){
	return get_boss(x) == get_boss(y);
}

void unite(int x,int y){

	int x_boss_id = get_boss(x);
	int y_boss_id = get_boss(y);

	if(x_boss_id == y_boss_id)return;

	if(height[x_boss_id] < height[y_boss_id]){

		base_count[y_boss_id] += base_count[x_boss_id];
		boss[x_boss_id] = y_boss_id;

	}else{

		base_count[x_boss_id] += base_count[y_boss_id];
		boss[y_boss_id] = x_boss_id;
		if(height[x_boss_id] == y_boss_id)height[x_boss_id]++;
	}
}

void init(){

	for(int i = 0; i < V; i++){
		boss[i] = i;
		height[i] = 0;
		base_count[i] = 0;
	}
}

void func(){

	G.clear();
	while(!Q.empty())Q.pop();
	init();

	int from,to,cost;

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

		scanf("%d %d %d",&from,&to,&cost);
		from--;
		to--;
		G.push_back(Edge(from,to,cost));
	}

	int tmp;

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

		scanf("%d",&tmp);
		tmp--;
		base_count[tmp] = 1;
	}

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

	int num_A,num_B;

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

		if(is_same_group(G[i].from,G[i].to))continue;

		num_A = base_count[get_boss(G[i].from)];
		num_B = base_count[get_boss(G[i].to)];

		if(num_A >= 1 && num_B >= 1){
			Q.push(G[i].cost);
			continue;
		}

		unite(G[i].from,G[i].to);
	}

	int count = 0,ans = 0;

	while(count < num_destroy){

		ans += Q.top().cost;
		Q.pop();
		count++;
	}

	printf("Case %d: %d\n",case_num,ans);

	case_num++;
}

int main(){

	case_num = 1;

	while(true){
		scanf("%d %d %d",&V,&num_base,&num_destroy);
		if(V == 0 && num_base == 0 && num_destroy == 0)break;
		E = V-1;

		func();
	}

	return 0;
}



Measured memory_bytes: 3476
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back


PI park[10][2]; //goTime,carNo;
int m,n,inpark;//ÔãÌAÔÌAÔêàÌÔÌ

queue<PI> Q;//waitTime,carNo;


//o­·éÔÌÔðÔ·B
int left(int time){
  
  rep(i,m){
    if(park[i][0].first<=time && park[i][0].first>0){
      PI ret=park[i][0];
      park[i][0]=park[i][1];//ãiÌÔðº°éB
      park[i][1]=mp(0,0);
      inpark--;
      return ret.second;
    }
  }
  //o­·éÔªÈ¯êÎ-1
  return -1;
}

//ÔðâßéB
void stop(int cometime,int wait,int no){
  int mini=-1,mint,maxi=-1,maxt;

  //·ÅÉÔÅ êÎL[ÉüêéÄ^[
  if(inpark>=2*m){
    Q.push(mp(wait,no));
    return;
  }
  
  inpark++;
  
  //êiÚªó¢Ä¢êÎ»±ÉüêÄ^[
  rep(i,m){
    if(park[i][0].first==0){
      park[i][0]=mp(cometime+wait,no);
      return;
    }
  }

  //oÉªß¢êiÚðIèB
  rep(i,m){
    if(park[i][1].first)continue;
    if((park[i][0].first<mint || mini==-1) && cometime+wait<=park[i][0].first){
      mint=park[i][0].first;
      mini=i;
    }
    if((park[i][0].first>maxt  || maxi==-1) && cometime+wait>=park[i][0].first){
      maxt=park[i][0].first;
      maxi=i;
    }
  }


  //oÉªüêéÔæèx¢àÌª êÎA»êðãiÉµÄAºiÉüÉB
  if(mini!=-1){
    park[mini][1]=park[mini][0];
    park[mini][0]=mp(cometime+wait,no);
  }else{//»¤ÅÈ¯êÎãiÉÈéÔÌÒ@ÔªêÔZ¢Æ±ëÉüÉ
    park[maxi][1]=park[maxi][0];
    park[maxi][0]=mp(cometime+wait,no);
  }
}


int main(){
  while(cin>>m>>n){
    if(m==0 && n==0)break;
    int time=0,out=0,f=0;//»ÝAoÉµ½ÔA\¦µ½©Ç¤©
    inpark=0;//»ÝÌÔ

    //Ôãú»
    rep(i,10)rep(j,2)park[i][j]=mp(0,0);


    //oÉµ½ÔªüÁÄ­éÔæè­È¢Ô[v
    while(out<n){
      ++time;


      //»ÝÉoÉ·éÔª êÎ»êð\¦B
      while(true){
        int carno=left(time);
        if(carno==-1)break;
        else{
          if(f)cout<<" ";
          cout<<carno;
          f=1;
          ++out;
        }
      }
      
      //ÔÅÈ­AÒ@Ôª éÈçÎ»êðüÉB
      while(!Q.empty() && inpark<2*m){
        int wait=Q.front().first,no=Q.front().second;
        Q.pop();
        stop(time,wait,no);
      }

      //»ÝÉ½Ôª êÎüÉB
      if(time%10==0 && time<=10*n){
        int wait;
        cin>>wait;
        stop(time,wait,time/10);
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
bool ispal(string s, int st, int en)
{
    for(int i = st; i <= en; i++)
        if(s[i]!=s[en-i]) return false;
    return true;
}

int main()
{
 	int bingo[3][3];
 	for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++)
            cin >>bingo[i][j];
    int n;
    cin >> n;
    while(n--)
    {
        int a;
        cin >> a;
        for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++)
        {
            if(bingo[i][j]==a)
            {
                bingo[i][j]=-1;
                break;
            }
        }
    }
    if(bingo[0][0]==-1 and bingo[1][0]==-1 and bingo[2][0]==-1) cout << "Yes\n";
    else if(bingo[0][0]==-1 and bingo[0][1]==-1 and bingo[0][2]==-1) cout << "Yes\n";
    else if(bingo[0][0]==-1 and bingo[1][1]==-1 and bingo[2][2]==-1) cout << "Yes\n";
    else if(bingo[1][0]==-1 and bingo[1][1]==-1 and bingo[1][2]==-1) cout << "Yes\n";
    else if(bingo[2][0]==-1 and bingo[2][1]==-1 and bingo[2][2]==-1) cout << "Yes\n";
    else if(bingo[0][1]==-1 and bingo[1][1]==-1 and bingo[2][1]==-1) cout << "Yes\n";
    else if(bingo[0][2]==-1 and bingo[1][2]==-1 and bingo[2][2]==-1) cout << "Yes\n";
    else if(bingo[0][2]==-1 and bingo[1][1]==-1 and bingo[2][0]==-1) cout << "Yes\n";
    else            cout << "No\n";
}


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

using namespace std;

int main(){
        int a, b, c, d;
        cin>>a>>b>>c>>d;
        int res=min(b, d)-max(a, c);
        if(res>=0)
                cout<<res<<endl;
        else
                cout<<0<<endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
constexpr int N = 1e7 + 10;

ll f[N];

int main() {
	int n; cin >> n;
	for (int i = 1; i <= n; i++)
		for (int j = i; j <= n; j += i)
			++f[j];
	ll ans = 0;
	for (int i = 1; i <= n; i++)
		ans += i * f[i];
	cout << ans << "\n";
}

Measured memory_bytes: 81724
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	string res;
	int a = 0;
	while (abs(N) > 0) {
		if (N % 2 != 0) {
			if (a % 2 == 0) {
				N--;
			}
			else {
				N++;
			}
			res.push_back('1');
		}
		else {
			res.push_back('0');
		}
		N /= 2;
		//N = -N;
		a++;
	}
	/*reverse(res.begin(), res.end());
	while ((int)res.size() > 1 && res.back() == '0') {
		res.pop_back();
	}*/
	reverse(res.begin(), res.end());
	if (res.size() == 0)res.push_back('0');
	cout << res << endl;
}

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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
//ここから書き始める

int main()
{
	cout <<setprecision(10);
	ll n ;
	ll time[5];
	cin >> n;
	rep(i,5)cin >> time[i];

	ll m = INF;
	ll where = 10;
	rep(i,5){
		if(time[i] < m){
			m = time[i];
			where = i;
		}
	}
	ll ans = 4 + ( n + (m-1) ) / m ;
	cout << ans << endl;


	
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int a, b;
  cin >> a >> b;
  vector<int>v;
  v.push_back(a+b);
  v.push_back(a-b);
  v.push_back(a*b);
  cout << *max_element(v.begin(), v.end());
  return 0;
}


Measured memory_bytes: 256
f=lambda:map(int,input().split())
n,m=f()
lt=[]
ll=[[] for _ in range(n)]
for _ in range(m):
  a,b=f()
  a-=1;b-=1
  lt+=[(a,b)]
  ll[a].append(b)
  ll[b].append(a)
def dfs(x):
  if lv[x]>0: return
  lv[x]=1
  for i in range(n):
    if x in ll[i]: dfs(i)
c=0
for a,b in lt:
  ll[a].remove(b)
  ll[b].remove(a)
  lv=[0]*n
  dfs(0)
  if sum(lv)<n: c+=1
  ll[a].append(b)
  ll[b].append(a)
print(c)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstdlib>
#include <stack>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000009
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
typedef long long ll;

using namespace std;

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


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

int main()
{
  int N,X,T;
  cin >> N >> X >>T;
  int result = 0;
  while(N > 0)
  {
    result += T;
    N -= X;
  }
  
  cout << result;
  return 0;
}

Measured memory_bytes: 3628
def solve
  a, b, c, d = gets.split.map!(&:to_i)
  flag = true
  while a > 0 || c > 0 do
    if flag == true
      c -= b
      flag = false
    else
      a -= d
      flag = true
    end
  end

  if flag == true
    print "Yes"
  else
    print "No"
  end
end
solve


Measured memory_bytes: 14352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll);
ll mod_fact(ll, ll);
ll mod_inv(ll, ll);
//

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> pe(n + 1);
    for(int i = 0; i < k; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int cur;
            cin >> cur;
            pe[cur]++;
        }
    }
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        if(!pe[i]) cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>

using namespace std;

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

    long long res = 0;
    for (int i = 0, j = 0; i < n; i++) {
        int a;
        cin >> a;
        res += max(j - a, 0);
        j = max(j, a);
    }

    cout << res << endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string.h>

using namespace std;

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)

const int N=(int)1e5+7;
const long long inf = (long long)1e16 + 7;

int main(){
    int n,a[1111];
    cin>>n;
    forn(i,n) cin>>a[i];
    sort(a,a+n);
    cout<<a[n-1]-a[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <cstdio>
using namespace std;

struct NODE{
	int to;
	int bit;
	double cost;
	NODE(int to, double cost) : to(to) , cost(cost) {}
	NODE(int to, double cost,int bit) : to(to) , cost(cost) , bit(bit) {}
	NODE(){}
};
bool operator < (const NODE &a,const NODE &b){
	return a.cost > b.cost;
}
int main(){
	int t,n,m,s,g;
	while(cin >> t >> n >> m >> s >> g&& t){
		s--;g--;
		int info[10];
		vector<NODE> v[31];
		for(int i = 0 ; i < t ; i++) cin >> info[i];
		for(int i = 0 ; i < m ; i++){
			int x,y,z;
			cin >> x >> y >> z;
			x--,y--;
			v[x].push_back(NODE(y,z));
			v[y].push_back(NODE(x,z));
		}
		bool used[31][1<<8] = {0};
		priority_queue<NODE> Q;
		Q.push(NODE(s,0,0));
		while(Q.size()){
			NODE q = Q.top(); Q.pop();
			if(used[q.to][q.bit]) continue;
			else used[q.to][q.bit] = true;
			if(q.to == g){
				printf("%.8f",q.cost);
				cout << endl;
				goto exit;
			}
			for(int i = 0 ; i < v[q.to].size() ; i++)
				for(int j = 0 ; j < t ; j++){
					if(q.bit>>j&1)continue;
					Q.push(NODE(v[q.to][i].to, q.cost + v[q.to][i].cost / info[j] , q.bit|(1<<j) ) );
				}
		}
		cout << "Impossible" << endl;
		exit:;
	}
}

Measured memory_bytes: 7996
#include<stdio.h>
int main(void){
	int n;
	int m;
	int i;
	int h,flg,tmp;
	int a[100100];
	long sum=0;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	a[0]%=m;
	for(i=1;i<n;i++){
		a[i]=(a[i]+a[i-1])%m;
	}
	h=n;flg=0;
	while(h>1||flg){
		if(h>1) h=h/1.3;
		flg=0;
		for(i=0;i<n-h;i++){
			if(a[i]>a[i+h]){
				tmp=a[i];
				a[i]=a[i+h];
				a[i+h]=tmp;
				flg=1;
			}
		}
	}
	int ok=0,ng=n,mid;
	for(i=0;i<n;i++){
		ok=0;ng=n;
		while(ng-ok>1){
			mid=(ok+ng)>>1;
			if(a[i]>=a[mid]){
				ok=mid;
			}else{
				ng=mid;
			}
		}
		sum+=(ok-i);
		if(a[i]==0) sum++;
	}
	printf("%ld\n",sum);
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define MAX_N 103
#define MAX_V 10
#define MAX_M 101
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define pro "はいプロ　世界一○○が上手　○○界のtourist　○○時代の終焉を告げる者　実質○○　○○するために生まれてきた男"

signed main(){
	int X, Y, count = 0, ni = 1;
	
	cin>>X>>Y;
	
	for(;;){
		if(ni*X>Y) break;
		count++;
		ni *= 2;
	}
	cout<<count<<endl;
	
	return 0;
}

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


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

char s[MAXN], t[MAXN];

void solve(){
	int n;
	scanf("%d%s%s", &n, &s[0], &t[0]);
	REPN(i, 0, n){
		int fl = 0;
		REP(j, 0, n - i){
			if (t[j] != s[i + j]){
				fl = 1;
			}
		}
		if (!fl){
			printf("%d\n", n + i);
			return;
		}
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
cout<<"ABC"+to_string(n)<<endl;
//system("pause");
return 0;
}

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

int main() {
  int N,K;
  cin >> N >> K ;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  
  unordered_map<int,int> num;
  for(int i=0;i<N;i++){
    if(num.count(A.at(i))){
      num.at(A.at(i))++;
    }else{
      num[A.at(i)] = 1;
    }
  }
  vector<int> ballnum;
  for(auto p : num){
    int value = p.second;
    ballnum.push_back(value);
  }
  sort(ballnum.begin(), ballnum.end());
  int res = 0;
  for(int i=0;i<max((int)num.size()-K, 0);i++){
    res += ballnum.at(i);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 11080
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main(){

    int N;
    cin >> N;
    vector<int> v(N);
    for(int i = 0; i < N; i++) cin >> v.at(i);

    priority_queue<double, vector<double>, std::greater<int>> pq;
    for(int i = 0; i < N; i++) pq.push(v.at(i));

    while(pq.size() != 1){
        double x = pq.top(); pq.pop();
        double y = pq.top(); pq.pop();
        pq.push((x + y) / 2.);
    }

    cout << pq.top() << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int ans,n,s;
int memo[1050][1000][10];
int rec(int bit,int x,int d){
  int res=0;
  if(memo[bit][x][d]!=-1) return memo[bit][x][d];
  if(d==n){
    if(x==s) return 1;
    return 0;
  }
  if(x>s) return 0;
  for(int i=0;i<10;i++){
    if(bit>>i&1) continue;
    res+=rec(bit+(1<<i),x+i*(d+1),d+1);
  }
  return memo[bit][x][d]=res;;
}
int main(){
  while(cin>>n>>s){
    fill(memo[0][0],memo[1049][999],-1);
    cout << rec(0,0,0) << endl;
  }
  return 0;
}

Measured memory_bytes: 42176