akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct obj{
    ll l,r,t;
    bool operator <(const obj &b)const{
        return t<b.t;
    }
    obj(ll nl,ll nr,ll nt){
        l=nl,r=nr,t=nt;
    }
};
vector<obj> a;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,q;cin>>n>>q;
    for(ll i=0;i<n;i++){
        ll l,r,t;cin>>l>>r>>t;
        a.push_back(obj(l-t,r-t,t));
    }
    sort(a.begin(),a.end());
    set<ll> st;
    unordered_map<ll,ll> rev;
    ll ans[q];memset(ans,-1,sizeof(ans));
    for(ll i=0;i<q;i++){
        ll x;cin>>x;
        st.insert(x);
        rev[x]=i;
    }
    for(auto &ele:a){
        ll l=ele.l,r=ele.r,t=ele.t;
        while(!st.empty()){
            auto it = st.lower_bound(l);
            if(it==st.end() || (*it)>=r )break;
            ans[rev[*it]]=t;
            st.erase(it);
        }
    }
    for(ll i=0;i<q;i++)cout<<ans[i]<<"\n";
}


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

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

    std::string s;
    std::cin >> s;

    std::vector<int> vec(1, 0);
    int x = 0;
    for(int i = 0; i < n; ++i){
        if('I' == s.at(i)){
            ++x;
        }else{
            --x;
        }

        vec.push_back(x);
    }

    std::cout << *std::max_element(vec.begin(), vec.end()) << std::endl;

    return 0;
}


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

#define ll long long
using namespace std;
const int maxn = 100000 + 5;
ll n;
ll s[maxn];

int main() {
    ll C, K;
    scanf("%lld%lld%lld", &n, &C, &K);
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", &s[i]);
    }
    sort(s + 1, s + 1 + n);
    ll t = 0, tmp = 0, ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (tmp < C && t == 0) {
            tmp=1;
            t = s[i];
        } else if (tmp < C && t + K >= s[i]) {
            tmp++;
        } else {
            ans++;
            tmp = 1;
            t = s[i];
        }
    }
    ans++;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
int main(){
  std::string s[3];
  long long k,a[3]={};
  std::cin>>s[0]>>k;
  for(size_t i=0;i<2;++i) s[i+1]=s[i]+s[0];
  for(size_t i=0;i<3;++i) for(size_t j=0;j<s[i].length()-1;++j) if(s[i][j]==s[i][j+1]) ++a[i],++j;
  std::cout<<(k&1?a[0]:a[1])+(k-1)/2*(a[2]-a[0])<<std::endl;
}


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

int main()
{
  
  int n;
   int sum = 0;
  //std::vector<int> vec;
  cin>>n;
 
  
 
  for(int i =0;i<n;i++)
  {
    int temp;std::cin>> temp;
     
   sum += temp-1;
  }
    
  cout<<sum;
 
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] iArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long N = iArray[0];
            long A = iArray[1];
            long B = iArray[2];
            
            Console.WriteLine((N / (A + B))*A + Math.Min(A, N % (A + B)));
        }
    }
}

//文字列の入力
//string s = Console.ReadLine();
//整数の入力
//long n = long.Parse(Console.ReadLine());
//文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');
//整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

//Console.WriteLine();
//Console.ReadKey();

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

int fairfield(int y, int m, int d){
  if(m == 1 || m == 2){
    y = y--;
    m = m + 12;
  }

  return 365 * y + y / 4 - y / 100 + y / 400 + 306 * (m + 1) / 10 + d - 428;
}

int main(){
  int y1, m1, d1, y2, m2, d2;

  while(cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2){
    if(y1 == -1) break;
    cout << fairfield(y2, m2, d2) - fairfield(y1, m1, d1) << endl;
  }
}

Measured memory_bytes: 1160
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <set>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cstring>
using namespace std;


int main()
{
	int a, b;
	cin >> a >> b;
	cout << max(max(a + b, a - b), a*b);
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	p := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&p[i])
	}

	count := 0
	for i := 1; i < n-1; i++ {
		if p[i-1] < p[i] && p[i] < p[i+1] {
			count++
		}
		if p[i-1] > p[i] && p[i] > p[i+1] {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <map>

using namespace std;

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

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

    int mm = 2e9;
    for (int i=-100;i<=100;i++){
        int cost = 0;
        for (int j=0;j<n;j++){
            cost+=(i-a[j])*(i-a[j]);
        }

        mm=  min(mm, cost);
    }

    cout<<mm<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
c = list(input())

def solve_fixed(p):
    w_cnt = 0
    r_cnt = 0

    for i in range(p):
        if(c[i] == "W"):
            w_cnt += 1
    
    for j in range(p,n):
        if(c[j] == "R"):
            r_cnt += 1
    
    return (w_cnt,r_cnt)

ans = 10**9
w_cnt,r_cnt = solve_fixed(0)

tmp = max(w_cnt,r_cnt)
ans = min(ans,tmp)
for i in range(n):
    
    if(c[i] == "W"):
        w_cnt += 1
    else:
        r_cnt -= 1

    tmp = max(w_cnt,r_cnt)
    ans = min(ans,tmp)
    

print(ans)

Measured memory_bytes: 10736
f = Array.new(2){ Array.new(4001, 0) }
f[0][0] = 1
4.times do |j|
  f[1].fill(0)
  (0..1000*j).each do |i|
    (0..1000).each do |k|
      f[1][i+k] += f[0][i]
    end
  end
  f.rotate!
end
while gets
  p f[0][$_.to_i]
end

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

int main ()
{
    int a,b,c,d,x,y;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a>c) x=a;
    else x=c;
    if(b>d) y=d;
    else y=b;
    if(x>y) printf("0");
    else printf("%d",y-x);
    return 0;
    }

Measured memory_bytes: 1676
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let n = it.next().unwrap().parse::<usize>().unwrap();
    let m = it.next().unwrap().parse::<usize>().unwrap();
    let mut cnt = vec![0; n];
    for _ in 0..2*m {
        cnt[it.next().unwrap().parse::<usize>().unwrap() - 1] += 1;
    }
    println!("{}", if cnt.iter().all(|x| x%2 == 0) { "YES" } else { "NO" });
}


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


int main(){
  int n,x,i;
  cin >> n >> x;
  vector<int> a(n);
  for(i=0;i<n;++i){
    cin >> a[i];
  }
  int ans=0;
  int id=0;
  sort(a.begin(),a.end());
  for(i=0;i<n;++i){
    if(a[i]<=x){
      x=x-a[i];
      ans++;
      id=i;
    }else{
      i=n;
    }
  }
  if(id==n-1 && x>0){
    ans--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      ps: [f64; n],
    }
    let half = n/2 + 1;
    let mut dp = vec![vec![0f64; n+1]; n+1];
    dp[0][0] = 1.0;
    for i in 0..n {
        for j in 0..n+1 {
            dp[i+1][min(half, j+1)] += dp[i][j] * ps[i];
            dp[i+1][j] += dp[i][j] * (1.0-ps[i]);
        }
    }
    // debug!(half, ps);
    // for i in 0..n {
    //     debug!(i, dp[i]);
    // }
    println!("{}", dp[n][half]);
}


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

int main() {
	int a,b;
  	cin>>a>>b;
  
  if(a<=5){
  	cout<<0<<endl;
  }
  
  else if(a>=6&&a<=12){
  	cout<<b/2<<endl;
  }
  
  else {
  	cout<<b<<endl;
  }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a;
    string s;
    cin>>a>>s;
    if(a<3200){
        cout<<"red\n";
        return 0;
    }
    else{
        cout<<s<<endl;
        return 0;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  vector<int> jun(N);
  int tmp;
  for(int i = 0; i < N; i++){
    cin >> tmp;
    jun[tmp-1] = i;
  }

  for(int i = 0; i < N; i++){
    cout << (jun[i] + 1) << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n" 
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
ll a[200009];
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll n;
  cin>>n;
  ll i=0;
  while(i<n)
    cin>>a[i++];
  sort(a,a+n);
  ll j=n-1,sum=0,k=n-1;
  bool f=0;
  while(k--)
  {
    sum+=a[j];
    if(f==0)
      j--;
    f=1-f;
  }
  deb(sum)
}

Measured memory_bytes: 5204
<?php
  list($w) = explode(" ", trim(fgets(STDIN)));

  $n = strlen($w);
  for ($i=0; $i<$n; $i++) {
    if(!isset($a[$w[$i]])) $a[$w[$i]] = 0;
    $a[$w[$i]]++;
  }

  foreach($a as $A){
    if($A % 2 !== 0){
      echo "No";
      exit;
    }
  }
  echo "Yes";

Measured memory_bytes: 16340
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

int n;

int head(int k){
  while(k>=10) k/=10;
  return k;
}

int tail(int k){
  return (k%10);
}


ll calc(int i,int j){
  ll c=0;
  for(int k=1;k<=n;k++){
    if(head(k)==i&&tail(k)==j) c++;
  }
  return c;
}

int main(){
  int i,j;
  cin>>n;
  ll ans=0;
  for(i=1;i<=9;i++){
    for(j=1;j<=9;j++){
      ans+=calc(i,j)*calc(j,i);
    }
  }
  cout<<ans<<endl;


  return 0;
}


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

int main() {
    int n, a;
    cin >> n >> a;
    vector<int>p, m;
    int ave_cnt = 0;
    rep(i,n) {
        int x;
        cin >> x;
        int d = x - a;
        if (d > 0) p.push_back(d);
        if (d < 0) m.push_back(-d);
        if (d == 0) ave_cnt++;
    }
    int64_t pdp[n+10][50*50+10];
    memset(pdp, 0, sizeof(pdp));
    pdp[0][0] = 1;
    rep(i,p.size()) {
        for (int j = 0; j <= 50*50; j++) {
            pdp[i+1][j] += pdp[i][j];
            if (j >= p[i]) pdp[i+1][j] += pdp[i][j-p[i]];
        }
    }
    int64_t mdp[n+10][50*50+10];
    memset(mdp, 0, sizeof(mdp));
    mdp[0][0] = 1;
    rep(i,m.size()) {
        for (int j = 0; j <= 50*50; j++) {
            mdp[i+1][j] += mdp[i][j];
            if (j >= m[i]) mdp[i+1][j] += mdp[i][j-m[i]];
        }
    }
    int64_t ans = 0;
    for (int i = 1; i <= 50*50; i++) {
        /*
        if (pdp[p.size()][i] != 0 ||  mdp[m.size()][i] != 0) {
            printf("%d  %ld  %ld\n", i, pdp[p.size()][i], mdp[m.size()][i]);
        }
        */
        ans += pdp[p.size()][i] * mdp[m.size()][i];
    }
    ans *= pow(2, ave_cnt);
    ans += pow(2, ave_cnt) - 1;
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple

const int N = 1e6 + 10;
const int INF = 0x3f3f3f3f;

int n;
int m;
vector<int> g[N];
int d[N][3];

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	while (m--) {
		int v;
		int u;
		cin >> v >> u;
		--v;
		--u;
		g[v].push_back(u);
	}
	queue<int> q;
	fill_n(d[0], 3 * N, INF);
	int s;
	int t;
	cin >> s >> t;
	--s;
	--t;
	d[s][0] = 0;
	q.push(s);
	while (q.size()) {
		int v = q.front();
		q.pop();
		for (int u : g[v]) {
			if (d[u][1] > d[v][0]) {
				d[u][1] = d[v][0];
				q.push(u);
			}
			if (d[u][2] > d[v][1]) {
				d[u][2] = d[v][1];
				q.push(u);
			}
			if (d[u][0] > d[v][2] + 1) {
				d[u][0] = d[v][2] + 1;
				q.push(u);
			}
		}
	}
	int ans = d[t][0];
	if (ans < INF) {
		cout << ans << "\n";
	} else {
		cout << "-1\n";
	}
	return 0;
}


Measured memory_bytes: 50304
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def IS():
    return input().split()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a
 
show_flg=False
show_flg=True
 
ans=0

h,w=LI()
t=[]
for i in range(h):
    s=input()
    if s=='.'*w:
        continue
    t+=[s]

u=[[0]*len(t) for i in range(w)]
for i in range(len(t)):
    for j in range(w):
        u[j][i]=t[i][j]

ans=[]
for x in u:
    if x.count('#')==0:
        0
    else:
        ans+=[x]

ANS=[[0]*len(ans) for i in range(len(ans[0]))]
for i in range(len(ans)):
    for j in range(len(ans[0])):
        ANS[j][i]=ans[i][j]
for i in ANS:
    print(''.join(i))




Measured memory_bytes: 41068
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>
#include<sstream>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cout << '\n';}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << '[' << *it << " = " << a << "]  ";
    err(++it, args...);
}

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<lli, lli> tii;
typedef tuple<lli, lli, lli> tiii;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;


void solve(){
	lli x; cin>>x;
	lli h=0;
	h+=(x/500)*1000;
	x%=500;
	h+=(x/5)*5;
	cout<<h;
}

int main(){
	fast_io
	int tc=1;
	//cin>>tc;
	while(tc--){solve();}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        int n = Integer.parseInt(f.readLine());
        int[] ar = new int[n];
        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        for (int i = 0; i < n; i++) ar[i] = Integer.parseInt(tokenizer.nextToken());

        long needed = 0;
        int maxSoFar = ar[0];
        for (int i = 1; i < n; i++) {
            if (ar[i] < maxSoFar) needed += maxSoFar - ar[i];
            maxSoFar = Math.max(maxSoFar, ar[i]);
        }

        out.println(needed);

        out.close();
    }
}

Measured memory_bytes: 55204
#include <iostream>
#include <cstdlib>
#include <list>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int main(void)
{
    int N, Q;
    cin >> N >> Q;

    string s;
    cin >> s;

    int n[100000];
    int count = 0;
    for (int i = 0; i < N; )
    {
        if (s[i] == 'A')
        {
            if (s[i+1] == 'C')
            {
                n[i] = count;
                n[i+1] = count+1;
                ++count;
                i+=2;
            }
            else
            {
                n[i] = count;
                ++i;
            }
        }
        else
        {
            n[i] = count;
            ++i;
        }
        
    }

    // for (int i = 0; i < s.length(); ++i)
    // {
    //     cout << n[i] << ",";
    // }
    // cout <<endl;

    for (int i = 0; i < Q; ++i)
    {
        int l, r;
        cin >> l >> r;

        cout << n[r-1] - n[l-1] << endl;
    }

    
        
    return 0;
}

Measured memory_bytes: 1472
n = int(input().rstrip())
f1 = n % 10

r = 'bon'
if f1 in [2, 4, 5, 7, 9]:
	r = 'hon'
elif f1 in [0, 1, 6, 8]:
	r = 'pon'
else:
	# f1 is 3
	pass

print(r)


Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  short int N,sum=1;
  cin >> N;
  vector<short int> d(N);
  short int i;
  for(i=0;i<N;++i)
    cin >> d.at(i);
  sort(d.begin(), d.end(), greater<int>());
  for(i=0;i<N;++i){
    if(i<(N-1))
      if(d.at(i)>d.at(i+1))
        ++sum;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3596
N=int(input())
s=str(N)
l=len(s)
if l==1:
    print(N)
elif l==2:
    print(9)
elif l==3:
    print(9+(N-99))
elif l==4:
    print(9+900)
elif l==5:
    print(9+900+(N-9999))
elif l==6:
    print(9+900+90000)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
 
#define M 1046527
 
string H[M];
 
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}
 
long int getKey(string str){
  long int sum = 0, p = 1;
  for (int i = 0; i < str.size(); i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
 
int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }
int ha(int key, int i){ return (h1(key)+i*h2(key))%M;}
 
int find(string str){
  long int key, h;
  key = getKey(str);
  for (int i = 0;; i++){
    h = ha(key, i);
    if( H[h] == str ) return 1;
    else if ( H[h] == "0" ) return 0;
  }
  return 0;
}
 
int insert(string str){
  long int key, h;
  key = getKey(str);
  for (int i = 0; ; i++ ){
    h = ha(key, i);
    if( H[h] == str) return 1;
    else if ( H[h] == "0" ){
      H[h] = str;
      return 0;
    }
  }
  return 0;
}
 
 
int main(){
  int n, h;
  string str, com;
  for (int i = 0; i < M; i++ ) H[i] = "0";
  cin >> n;
  for (int i = 0; i < n; i++ ){
    cin >> com >> str;
 
    if ( com[0] == 'i' ){
      insert(str);
    } else {
      if (find(str) ){
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 70484
import java.util.Collections;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		int N;
		TreeSet<Integer> mochi = new TreeSet<Integer>(Collections.reverseOrder());
		Scanner scan = new Scanner(System.in);
		N = scan.nextInt();

		for(int i = 0; i < N; i++) {
			mochi.add(scan.nextInt());
		}
		System.out.println(mochi.size());
		scan.close();
	}
}


Measured memory_bytes: 22868
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    ll N;
    cin >> N;

    for(ll h = 1; h <= 3500; h++){
        for(ll n = 1; n <= 3500; n++){
            ll up = N * h * n;
            ll down = 4 * h * n - N * n - N * h;
            if(down != 0){
                if(up % down == 0 && up / down >= 1){
                    cout <<  h << " " << n << " " << up / down << endl;
                    return 0;
                }
            }
        }
    }
    


}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int x = n/100;
	int y = n%10;
	if(x == y) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
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;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

   string s;
   cin>>s;
   s[3] ='8';

   cout<<s<<endl;


   
}

Measured memory_bytes: 3616
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NT = Sarray();
            var N = NT[0];
            var T = NT[1];
            var ti = Sarray();
            var ans = 0L;
            for (var i = 0; i < N-1; ++i)
            {
                ans += Min(ti[i + 1] - ti[i], T);
            }
            ans += T;
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 30880
#include <algorithm>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int N, T;
    cin >> N >> T;

    int curt = 0;
    int tot = 0;
    int until = 0;

    for (int i = 0; i < N; ++i) {
        int t;
        cin >> t;

        if (until < t) {
            tot += until - curt;
        } else {
            tot += t - curt;
        }
        curt = t;
        until = t + T;
    }

    tot += until - curt;
    cout << tot << endl;
    return 0;
}


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};



int main(){
    // Failed to predict input format
    int memo[30];
    REP(i, 30) memo[i] = 0;

    int N,M;
    cin >> N >> M;
    REP(i, N){
        int K;
        cin >> K;
        REP(j, K){
            int tmp;
            cin >> tmp;
            memo[tmp-1]++;
        }
    }

    int ans = 0;
    REP(i, M){
        ans += (memo[i] == N);
    }

    cout << ans << endl; 
    return 0;
}


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

AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))

AB.sort(key=lambda x: x[1],reverse=True)

time = AB[0][1]
for i in range(1,N):
    if time-AB[i-1][0] < AB[i][1]:
        time = time-AB[i-1][0]
    else:
        time = AB[i][1]

time = time - AB[N-1][0]

if time < 0:
    print("No")
else:
    print("Yes")

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

int main(){
    string sa,sb,sc;
    cin >> sa >> sb >>sc;
    int a=0,b=0,c=0;
    char now = 'a';
    while(1){
        if(now=='a'){if(a+1>sa.size()){cout<<'A'<<endl;break;}now=sa[a];a++;}
        if(now=='b'){if(b+1>sb.size()){cout<<'B'<<endl;break;}now=sb[b];b++;}
        if(now=='c'){if(c+1>sc.size()){cout<<'C'<<endl;break;}now=sc[c];c++;}
    }
    return 0;
}

Measured memory_bytes: 256
#include <climits>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,m;
    cin>>n>>m;
    int a[n];
    for (size_t i = 0; i < n; i++) {
      cin>>a[i];
    }
    sort(a,a+n);
    ll sum=0;
    for (size_t i = 0; i < n; i++) {
      sum+=a[i];
      if(sum==m){cout<<i+1<<endl;return 0;}
      if(sum>m){
        cout<<i<<endl;return 0;
      }
    }
    cout<<n-1<<endl;
    return 0;
}


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

int main()
{
        int n;
        cin >> n;
        vector<int> a(n);
        for (int i = 0; i < n; ++i) {
                cin >> a[i];
        }
        bool plus = false;
        long long ans1 = 0;
        long long sum = 0;
        for (int i = 0; i < n; ++i) {
                sum += a[i];
                if (plus == false) {
                        if (sum >= 0) {
                                ans1 += (abs(sum)+1);
                                sum = -1;
                        }
                        plus = true;
                }
                else {
                        if (sum <= 0) {
                                ans1 += (abs(sum)+1);
                                sum = 1;
                        }
                        plus = false;
                }
        }
        if (sum == 0) ans1++;

        plus = true;
        long long ans2 = 0;
        sum = 0;
        for (int i = 0; i < n; ++i) {
                sum += a[i];
                if (plus == false) {
                        if (sum >= 0) {
                                ans2 += (abs(sum)+1);
                                sum = -1;
                        }
                        plus = true;
                }
                else {
                        if (sum <= 0) {
                                ans2 += (abs(sum)+1);
                                sum = 1;
                        }
                        plus = false;
                }
        }
        if (sum == 0) ans2++;
        long long ans = (ans1 < ans2) ? ans1 : ans2;
        cout << ans << endl;

}


Measured memory_bytes: 640
#解説O(1)解法
a,b = map(int,input().split())
if a > 0:
  a -= 1
def f(x):
  if x%4 == 1:
    return 1
  if x%4 == 3:
    return 0
  if x%4 == 0:
    return x
  if x%4 == 2:
    return x+1
print(f(a)^f(b))

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

int main()
{
  int n,inp,b,c;
  long long sum=0;
  cin>>n;
  int mp[1'00'001] {0};
  for(int i =0 ; i< n; i++)
  {
    cin>>inp;
    mp[inp]++;
    sum = sum + inp;

  }
  int q;
  cin>>q;
  for (int i =0; i<q; i++)
  {
    cin>>b>>c;
    sum += (c-b) * mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    cout<<sum<<endl;

  }
  return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long result = 0;
  for (i = 0; i < n; i++) {
    result += a[i] - 1;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
using vi = vector<int>;

string str;
string stra;
int id = 0;

void pt(vector<int> v){
  for(int r=0;r<v.size();r++){
    cout << v[r];
  }
  cout << endl;
}

vi number(){
  vi res;
  for (;'0'<=stra[id]&&stra[id]<='9'; id++) {
    res.push_back(stra[id] - '0');
  }
  reverse(res.begin(),res.end());
  return res;
}
int solve(){
  stra = str;
  for (int i = 9; i >= 0; i--) {
    id = 0;
    for (int j = 0; j <(int)str.size(); j++) {
      if (str[j] == 'X') {
        stra[j] = i + '0';
      }
    }
    vi a = number();
    if (stra[id] == '+' ) {
      id++;
    }
    vi b = number();
    
    //a.resize(max(b.size() + 1,a.size()+1),0);
  /*  
    a.push_back(0);
    while(a.size()<=b.size()){
      a.push_back(0);
    }
    
    for (int j = 0; j < (int)b.size(); j++) {
      a[j] += b[j];
      if (a[j]>=10) {
        a[j] -= 10;
        a[j+1]++;
      }
    }
    // for (int j = b.size(); j < (int)(a.size()-1); j++) {
    //   if (a[j] >= 10) {
    //     a[j] -= 10;
    //     a[j+1]++;
    //   }
    // }
    for(int j=0;j<(int)a.size();j++){
      if(a[j]>=10){
        a[j]-=10;
        a[j+1]++;
      }
    }
    
    while(a[a.size()-1]==0){
      a.pop_back();
    }*/
    
    //pt(a);
    int j;
    int k=0;
    int l=0;
    vi ab;
    for(j=0;j<int(a.size())&&j<int(b.size());j++){
      k=0;
      if(a[j]+b[j]+l>=10){
        k++;
        ab.push_back(a[j]+b[j]+l-10);
      }
      else{
        ab.push_back(a[j]+b[j]+l);
      }
      l=k;
    }
    for(;j<int(a.size());j++){
      k=0;
      if(a[j]+l>=10){
        k++;
        ab.push_back(a[j]+l-10);
      }
      else{
        ab.push_back(a[j]+l);
      }
      l=k;
    }
    for(;j<int(b.size());j++){
      k=0;
      if(b[j]+l>=10){
        k++;
        ab.push_back(b[j]+l-10);
      }
      else{
        ab.push_back(b[j]+l);
      }
      l=k;
    }
    if(l>0){
      ab.push_back(l);
    }
    a=ab;
    ///////
    if (stra[id] == '=') {
      id++;
    }

    vi c = number();
    if (a.size() != c.size()) {
      continue;
    }
    int flag = 0;
    for (int j = 0; j < (int)a.size(); j++) {
      if (a[j] == c[j]) {
        flag++;
      }
    }
    if (flag ==(int)a.size()) {
      return i;
    }

  }
  return -1;
}
int main(){
  cin >> str;
  while(str.size()){
  int ans = solve();
  if (ans >= 0) {
    cout << ans << endl;
  } else {
    cout << "NA" << endl;
  }
  str="";
  cin >> str;
}
  return 0;
}



Measured memory_bytes: 3048
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int Maxn = 100000 + 100;
int A[Maxn];
int diff[Maxn];
int N;
int main()
{
	scanf("%d", &N);
	LL Sum = 0, Cnt = 0;
	for (int i = 1; i <= N; ++i)
		scanf("%d", &A[i]), Sum += A[i], Cnt += i;
	if (Sum % Cnt)
	{
		puts("NO");
		return 0;
	}
	for (int i = 1; i < N; ++i)
		diff[i] = A[i + 1] - A[i];
	diff[N] = A[1] - A[N];
	Cnt = Sum / Cnt;
	for (int i = 1; i <= N; ++i)
	{
		if (Cnt == diff[i]) continue;
		int Now = Cnt - diff[i];
		if (Now < 0 || Now % N)
		{
			puts("NO");
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define N (100009)
using namespace std;

int n,l,q,a,b,ans,x[N],f[N][21];

int main()
{
	cin>>n;
	for (int i=1; i<=n; ++i) cin>>x[i];
	cin>>l>>q;
	for (int i=1; i<=n; ++i)
	{
		int pos=upper_bound(x+1,x+n+1,x[i]+l)-x;
		f[i][0]=pos-1;
	}
	for (int i=1; i<=20; ++i)
		for (int j=1; j<=n; ++j)
			f[j][i]=f[f[j][i-1]][i-1];
	for (int i=1; i<=q; ++i)
	{
		cin>>a>>b; ans=0;
		if (a>b) swap(a,b);
		for (int i=20; i>=0; --i)
			if (f[a][i]<b) a=f[a][i], ans+=1<<i;
		ans++;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 9472
N, K = map(int, input().split())
TD = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: -x[1])
q = []
ans = 0
s = set()
for i in range(K):
    ans += TD[i][1]
    if TD[i][0] in s:
        q.append(TD[i][1])
    s.add(TD[i][0])
ans += len(s) ** 2
k1 = K
ans1 = ans
while k1 < N and q:
    if TD[k1][0] not in s:
        ans1 = ans1 + TD[k1][1] - q.pop() - len(s) ** 2 + (len(s) + 1) ** 2
        ans = max(ans, ans1)
        s.add(TD[k1][0])
    k1 += 1
print(ans)


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

int main() {
  int N;
  cin >> N;
  
  if (N/100-N/1000*10 != N/10-N/100*10){
       cout << "No" << endl;}
  else if ((N/1000 == N/100-N/1000*10) || (N/10-N/100*10 == N-N/10*10)){
     cout << "Yes" << endl;}
  else{
    cout << "No" << endl;}
  
}


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

#define REP(i,n) for(decltype(n) i=0; i<(n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define st first
#define nd second
#define pb push_back

typedef pair<int,int> pii;
typedef vector<int> vi;

struct ed {
    int v,rev;
    bool removed;
};

bool connected(int n, vector<vector<ed>> g){
    queue<int> Q;
    vector<bool> visited(n+1,false);
    visited[1] = true;
    Q.push(1);
    int cnt = 1;
    while(!Q.empty()){
        int v = Q.front();
        Q.pop();
        for(ed& e : g[v]){
            if(e.removed || visited[e.v]) continue;
            visited[e.v] = true;
            ++cnt;
            Q.push(e.v);
        }
    }
    return cnt == n;
}

void solve(){
    int n,m,a,b;
    cin>>n>>m;
    vector<vector<ed>> g(n+1);
    vector<pii> edge;
    REP(_,m){
        cin>>a>>b;
        g[a].pb({b,-1,false});
        g[b].pb({a,(int)g[a].size()-1,false});
        g[a].back().rev = g[b].size()-1;
        edge.pb({a,(int)g[a].size()-1});
    }
    int ans = 0;
    for(const auto& p : edge){
        ed& e1 = g[p.first][p.second];
        ed& e2 = g[e1.v][e1.rev];
        e1.removed = e2.removed = true;
        if(!connected(n,g)) ++ans;
        e1.removed = e2.removed = false;
    }
    cout<<ans<<'\n';
}

int main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a,b,k,c,i;
    scanf("%d%d%d",&a,&b,&k);
    if(a<=b)
    {
        c=0;
        for(i=a;i>=1;i--)
        {
            if(a%i==0&&b%i==0)
            {
                c++;
                if(c==k)
                {
                    printf("%d",i);
                    break;
                }
            }
        }
    }
    else
    {
        c=0;
        for(i=b;i>=1;i--)
        {
            if(a%i==0&&b%i==0)
            {
                c++;
                if(c==k)
                {
                    printf("%d",i);
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <ctime>
#include <climits>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <cstdlib>

using namespace std;
long int pow107 = (int)pow(10, 9) + 7;
int ilimit = INT_MAX;
long int llimit = LONG_MAX;

bool comp(pair<int, string> a, pair<int, string> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

int Func2(int n,int m){
    long int s2 = 1,
        r = 1;


    for(int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % pow107;
    }

    return s2;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//階乗factorial
//コンビネーションFunc2

int main(){
    int n,max = -1,r;
    cin >> n;
    for(int i = 1;i <= n; ++i){
        int c = 0,ii = i;
        while(ii % 2 == 0){
            c++;
            ii /= 2;
        }
        if(max < c){
            max = c;
            r = i;
        }
    }
    cout << r << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(a: int, b: int, c: int):
    print(sum([a, b, c])-max(a, b, c))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    solve(a, b, c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1]; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1]; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb(x) push_back(x)
#define vi vector <int>
#define pi pair <int, int>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int l, r;
	cin >> l >> r;
	if (r - l >= 2019) {cout << 0; return 0;}
	
	l %= 2019;
	r %= 2019;
	if (l <= r)
	{
		int ans = 2019;
		FOR (i, l, r)
			FOR (j, i + 1, r)
				ans = min(ans, i * j % 2019);
		cout << ans;
	}
	
	else cout << 0;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var num = Console.ReadLine();
        if ((num[0] == num[1] && num[1] == num[2] && num[0] == num[2]) || (num[1] == num[2] && num[2] == num[3] && num[3] == num[1])) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 13140
#include <iostream>
int cnt[55];
int main(){
  int n,m;
  std::cin >> n >> m;
int len = 0;  
for(int i = 1; i <= n; i++){
std::cin >> len;
while(len--){
  int tmp;
std::cin >> tmp;
cnt[tmp]++;
}
  }
int count = 0;
for(int i = 1; i <= m; i++) if (cnt[i] == n) count++;
std::cout << count ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int N, M;
int mp[8][8]={0};
bool visited[8]={false};

int dfs(int n, int d){
  if(d==N-1) return 1;
  int ret = 0;
  rep(i,N){
    if(mp[n][i] && visited[i]==false){
      visited[i]=true;
      ret +=dfs(i, d+1);
      visited[i]=false;
    }
  }
  return ret;
}

int main()
{
  int res=0;
  cin >> N >> M;

  rep(i,M) {
    int a,b;
    cin >> a >> b;
    a--;b--;
    mp[a][b]=1;
    mp[b][a]=1;
  }

  visited[0]=true;
  res = dfs(0,0);

  cout << res << endl;
}


Measured memory_bytes: 256
#line 2 "/home/toof/working/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 3 "/home/toof/working/library/union_find.hpp"

struct UnionFind {
  struct Node {
    ll parent;
    ll size;
  };
  vector<Node> tree;

  UnionFind(ll size) : tree(size) {
    rep(i, size) {
      tree[i].parent = i;
      tree[i].size = 1;
    }
  }

  ll find(ll x) {
    while (tree[x].parent != x) {
      ll p = tree[x].parent;
      tree[x].parent = tree[p].parent;
      x = p;
    }
    return x;
  }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (tree[x].size < tree[y].size) swap(x, y);
    tree[y].parent = x;
    tree[x].size += tree[y].size;
  }

  bool same(ll x, ll y) {
    return find(x) == find(y);
  }
};
#line 3 "d.cpp"

int main() {
  ll n, m;
  cin >> n >> m;

  UnionFind uf(n+1);
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    uf.unite(a, b);
  }

  ll maxi = 0;
  rep(i, n) {
    cmax(maxi, uf.tree[i+1].size);
  }
  cout << maxi << el;
}


Measured memory_bytes: 6372
#include <bits/stdc++.h>
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
#define all(x) (x).begin(), (x).end()
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
ll now = 1e9;
inline bool check(ll x)
{
    cout << "? " << x << endl;
    char res;
    cin >> res;
    return res == 'Y';
}
int main()
{
    if(check(now)) while(now > 1 && check(now - 1)) now /= 10;
    else
    {
        while(!check(now /= 10));
        ll l = now, r = now * 10;
        while(r - l > 1)
        {
            ll mid = (l + r) / 2;
            if(check(mid * 10)) r = mid;
            else l = mid;
        }
        now = r;
    }
    cout<<"! "<<now<<endl;
    return 0;
}


Measured memory_bytes: 596
judge::Int->Int->Bool
judge a n | n == 1 = True
          | a == 1 = False
          | n `mod` a == 0 = n `div` a < 10
          | otherwise = judge (a-1) n

main = do
  n <- readLn
  putStrLn $ if judge 9 n then "Yes" else "No"

Measured memory_bytes: 508