akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int s = in.nextInt();
        int h = s/3600;
        int m = s%3600/60; 
        int S = s%3600%60;
        System.out.println(h + ":" + m + ":" + S);
    }
}

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

typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
  
string N;

int main(){
    cin>>N;
    int flg=0;
    rep(i,0,N.size()){
        char a=N[i];
        //if(a-'0'==7){flg=1;break;}
      	if(a=='7'){flg=1;break;}
    }
    if(flg==1)cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
map<string,int> MM;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>s;
		MM[s]++;
	}
	cin>>M;
	FOR(i,M) {
		cin>>s;
		MM[s]--;
	}
	
	int ret=0;
	FORR(r,MM) ret=max(ret,r.second);
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <stdlib.h>

using namespace std;
char input[100];
int cnt = 0;

int main(void)
{
  scanf("%s", input);
  
  for (char step : input) {
    ++cnt;
    if (step == 'U' || step == 'D')
      continue;
    else if ((cnt & 1)) {// odd
      if (step == 'L') {
        printf("%s\n", "No");
        exit(0);
      }
    }
    else { // even
      if (step == 'R') {
        printf("%s\n", "No");
        exit(0);
      }
	}
  }
  printf("%s\n", "Yes");
  return 0;
}

Measured memory_bytes: 128
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var N = cin.ReadInt;
            var M = cin.ReadInt;
            var a = cin.ReadIntArray(M);

            bool[] canStep = Enumerable.Repeat<bool>(true, N + 1).ToArray();
            for (int i = 0; i < M; i++)
            {
                canStep[a[i]] = false;
            }

            int[] dp = new int[N + 1];

            dp[0] = 1;

            for (int i = 0; i < N; i++)
            {
                for (int j = i + 1; j <= Min(N, i + 2); j++)
                {
                    if(canStep[j])
                    {
                        dp[j] += dp[i];
                        dp[j] %= 1000000007;
                    }
                }
            }

            Console.WriteLine(dp[N]);
            return;

        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 16336
#include<bits/stdc++.h>
using namespace std;
vector<char> ans;
char a[26]={'z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y'};
int main()
{
	long long n;
	cin>>n;
	while(n)
	{
		if(n%26==0)
		{
			n/=26;
			n--;
			ans.push_back('z');
		}
		else
		{
			ans.push_back(a[n%26]);
			n/=26;
		}
	}	
	for(int i=ans.size()-1;i>=0;i--)
		cout<<ans[i];
	return 0;
} 

Measured memory_bytes: 3636
#!/usr/bin/env python3
import itertools
import math
import sys

MAX = 999999


def sieve_of_eratosthenes(max):
    is_prime = [True] * (max + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(math.sqrt(max)) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * i, max + 1, i):
            is_prime[j] = False
    return filter(lambda x: is_prime[x], range(max + 1))


def main():
    p = list(sieve_of_eratosthenes(MAX))
    for l in sys.stdin:
        n = int(l)
        print(len(list(itertools.takewhile(lambda x: x <= n, p))))


if __name__ == '__main__':
    main()

Measured memory_bytes: 18420
class PriorityQueue
  attr_accessor :data, :size

  def initialize(array = [])
    @data = []
    array.each { |a| push(a) }
  end

  def push(element)
    current = @data.size
    while current > 0
      p = parent(current)
      break if @data[p] <= element
      @data[current] = @data[p]
      current = p
    end
    @data[current] = element
  end

  def pop
    ret = @data[0]
    x = @data[-1]
    current = 0
    while have_child?(current)
      a = left_child(current)
      b = right_child(current)
      a = b if b < @data.size - 1 && @data[b] < @data[a]
      break if @data[a] >= x
      @data[current] = @data[a]
      current = a
    end
    @data[current] = x
    @data.pop

    ret
  end

  def size
    @data.size
  end

  def front
    @data[0]
  end

  def empty?
    @data.empty?
  end

  private
  def parent(num)
    (num - 1) / 2
  end

  def left_child(num)
    num * 2 + 1
  end

  def right_child(num)
    num * 2 + 2
  end

  def have_child?(num)
    left_child(num) < @data.size - 1
  end
end


N, M = gets.chomp.split.map(&:to_i)
jobs = []
N.times { jobs.push(gets.chomp.split.map(&:to_i)) }

jobs.sort! { |a, b| b[0] <=> a[0] }

que = PriorityQueue.new

N.times do |i|
  que.push(jobs[i][1])
  que.pop if que.size > M - jobs[i][0] + 1
end

ans = 0
que.size.times do
  a = que.pop
  ans += a
end

puts ans 


Measured memory_bytes: 11368
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define reverse(x) reverse(x.begin(), x.end())
#define sort(x) sort(x.begin(), x.end())
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long,long long>
#define f first
#define s second
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
int main(){
	int n, m;
	cin >> n >> m;
	if(m%2==1||m>n*4||m<n*2){
		cout << "No";
	}else {
		cout << "Yes";
	}
}


Measured memory_bytes: 3596
#include <stdio.h>

int main(int argc, const char * argv[])
{
    
    int n, i = 0;
    long ans = 1;
    
    scanf("%d", &n);
    
    while (n > i) {
        ans *= (n - i);
        i++;
    }
    
    printf("%ld\n", ans);
    
    
    return 0;
}

Measured memory_bytes: 592
<?php
    class Stack {
	public $a;
	public $s;
	public $top;
	public $n;

	public function __construct($a) {
	    $this->a = $a;
	    $this->s = array();
	    $this->top = 0;
	    $this->n = count($a);	
	}
	public function initialize() {
	    $this->top = 0;
	}
	public function isFull($top) {
	    return $top >= $this->n - 1;
	}

	public function isEmpty($top) {
	    return $top == 0;
	}

	 public function push($v) {
	    if (self::isFull($this->top)) {echo "FULL!"; return false;}
	    $this->top++;
	    $this->s[$this->top] = $v;
	}

	 public function pop() {
	    if (self::isEmpty($this->top)) {echo "EMPTY!"; return false;}
	    $this->top--;
	    return $this->s[$this->top + 1]; 
	}
    }

    $a = explode(" ", trim(fgets(STDIN))); 
    $stk = new Stack($a);
    $stk_a = $stk->a;

    for ($i = 0; $i < $stk->n; $i++) {
	$ele = $stk_a[$i];
	if (!ctype_digit($ele)) {
	    $a = $stk->pop();
	    $b = $stk->pop();
	    if ($ele == '+') {
		$stk->push($b + $a);
	    } else if ($ele == '-') {
		$stk->push($b - $a);
	    } else if ($ele == '*') {
		$stk->push($b * $a);
	    }
	} else {
	    $stk->push($ele);
	}
    }

    $result = $stk->s[1];
    echo $result;
?>



Measured memory_bytes: 9412
#include <stdio.h>
int main(void)
{
  char s[10];
  char a[4] = {'A','T','C','G'};
  int i,count=0;
  int max = 0;
  int mmax = 0;
 
  scanf("%s",s);
  
  for(i=0;i<10;i++){
    if(s[i]==a[0] || s[i]==a[1] || s[i]==a[2] || s[i]==a[3]){
    count=count + 1;
    max = count;
    }
    
    else
    count = 0;
    if(max>=mmax){
    mmax=max;
    max=0;
    }
  }
  
  if(mmax>max)
  printf("%d",mmax);
  else
    printf("%d",max);

  return 0;


}

Measured memory_bytes: 128
#include <stdio.h>

int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	if (13 <= a)
		printf("%d", b);
	else if (6 <= a && a <= 12)
		printf("%d", b / 2);
	else
		printf("%d", 0);
			
	return 0;
}

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

#define INF 100100100
#define MOD 1000000007

using namespace std;
using ll = long long;
using ull = unsigned long long ;

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

   double N,T,A;
   cin>>N>>T>>A;
   double MIN = INF;
   int ans;
   for(int i=0;i<N;i++){
      double h;
      cin>>h;
      h = T-(h*0.006);
      if(abs(h-A)<MIN){
         ans=i;
         MIN=abs(h-A);
      }
   }
   cout<<ans+1<<endl;

   return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int x,n;
    cin >> x>>n;
    vector<int> v(n);
    rep(i,n){
        cin >> v[i];
    }
    int ans=-1000;
    for(int i=-105; i<=205; ++i){
        if(abs(x-i) < abs(x-ans)){
            int flag=0;
            rep(j,n){
                if(i==v[j]){
                    flag=1;
                    break;
                }
            }
            if(!flag){
                ans = i;
            }
        }
    }

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


Measured memory_bytes: 3636
#include <stdio.h>                                                                                                      
long long int s[87];
int main(void){
    int n;
    scanf("%d", &n);
    s[0] = 2;
    s[1] = 1;
    for(int i = 2; i <= n; i++){
        s[i] = s[i-1] + s[i-2];
    }   
    printf("%lld",  s[n]);
    return 0;
}

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

using namespace std;

void sol()
{
	string s;
	cin >> s;
	
	bool f=false;
	
	for(int i=0;i<s.size();++i)
	{
		if(s[i]=='7')
		{
			f=true;
			break;
		}
	}
	
	if(f)
	{
		cout << "Yes" << endl;
	}
	
	else
	{
		cout << "No" << endl;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	sol();
}

Measured memory_bytes: 3656
import java.util.Scanner;


public class Main {
    static   Scanner scan = new Scanner(System.in);
 
    public static void main(String[] args) {    
        int n = scan.nextInt();
        int [] array1 = new int[n];
            for (int i = 0; i < n; i++) {
                array1[i] =scan.nextInt();
        }
            for (int i = n-1; i >= 0; i--) {
                System.out.print(array1[i]);
                if (i>0) {
                    System.out.print(" ");
                }
        }System.out.println();
            
    }
}


Measured memory_bytes: 26252
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

ll a[20][20];
ll dp[1LL<<20];

int main(){
    int n;
    cin >> n;
    rep(i,n)rep(j,n) cin >> a[i][j];
    rep(bit,1<<n){
        vector<int> id;
        rep(i,n){
            if(bit>>i&1) id.push_back(i);
        }
        rep(i,id.size()){
            rep(j,i){
                dp[bit] += a[id[i]][id[j]];
            }
        }
    }

    rep(bit,1<<n){
        for(int j=bit;j>0;j=(j-1)&bit){
            dp[bit] = max(dp[bit],dp[j] + dp[bit^j]);
        }
    }

    cout << dp[(1<<n)-1] << endl;
    return 0;
}


Measured memory_bytes: 4116
#!/usr/bin/ruby
# -*- coding: utf-8 -*-

def calcCard(card)
  if card == 'A'
    11
  else
    card
  end
end

play = gets.to_i
play.times do
  hand = gets.split
  hand.push(gets.split).flatten!

  hand.map! {|ch|
    if ch == 'T' || ch == 'J' ||
       ch == 'Q' || ch == 'K'
      10
    elsif ch != 'A'
      ch.to_i
    else
      ch
    end
  }
  # p hand
  if (hand[0] == 10 && hand[1] == 'A') ||
     (hand[0] == 'A' && hand[1] == 10)
    puts "blackjack"
  else
    res = calcCard(hand[0]) + calcCard(hand[1])
    i = 1
    while true
      # p res
      if res <= 16
        i += 1
      elsif res == 17 && hand[0..i].include?("A")
        i += 1
      elsif res <= 21
        puts res
        break
      elsif hand[0..i].include?("A")
        ace = hand[0..i].find_index {|x| x == "A" }
        hand[ace] = 1
      else
        puts "bust"
        break
      end
      res = 0
      hand[0..i].each {|x| res += calcCard(x) }
    end
  end
end

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

long long gcd(long long a,long long b){
	if(a==0 || b==0){
		return max(a,b);
	}
	else if(a%b==0 || b%a==0){
		return min(a,b);
	}
	
	long long q;
	bool pro =true;
	while(pro){
		q=a%b;
		a=b;
		b=q;
		if(a%b==0){
			return q;
			pro=false;
		}
	}
}

int main() {
	ll N,X;
	cin >> N >> X;
	vector <ll> v(N);
	for(ll i=0;i<N;i++){
		cin >> v.at(i);
		v.at(i)-=X;
		v.at(i)=abs(v.at(i));
	}
	ll g=v.at(0);
	for(ll i=0;i<N;i++){
		g=gcd(g,v.at(i));
	}
	cout<<g<<endl;
	
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; string up,lo; cin>>n>>up>>lo;
	int ans=3,i=1; bool p2=false;
	if(!(up.front()==lo.front()))ans=6,p2=true,++i;
	while(i<n){
		if(up.at(i)==lo.at(i)){
			if(!p2)ans=(1L*ans*2)%mod;
			else p2=false;
			++i;
		}
		else{
			if(p2)ans=(1L*ans*3)%mod;
			else ans=(1L*ans*2)%mod,p2=true;
			i+=2;
		}
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H,W;
    cin>>H>>W;
    vector<string> vec(H);
    vector<vector<int>> vec1(H,vector<int>(W));
    vector<vector<int>> vec2(H,vector<int>(W));
    for(int i=0;i<H;i++){
        string S;
        cin>>S;
        vec.at(i)=S;
        int j=0,L=0;
        while(j!=W){
            if(S.at(j)=='#'){
                if(j==0){
                    j++;
                    L=1;
                    continue;
                }
                for(int k=L;k<j;k++){
                    vec1.at(i).at(k)=j-L;
                }
                L=j+1;
                j++;
                continue;
            }
            j++;
            if(j==W){
                for(int k=L;k<j;k++){
                    vec1.at(i).at(k)=j-L;
                }
                break;
            }
        }
        //for(int j=0;j<W;j++){cout<<vec1.at(i).at(j)<<" ";}
        //cout<<endl;
    }
    //cout<<vec.at(0)<<endl;
    //cout<<endl;
    for(int i=0;i<W;i++){
        int j=0,L=0;
        while(j!=H){
            string S=vec.at(j);
            //cout<<j<<" "<<vec.at(j)<<endl;
            if(S.at(i)=='#'){
                if(j==0){
                    j++;
                    L=1;
                    continue;
                }
                for(int k=L;k<j;k++){
                    //cout<<k<<" "<<i<<endl;
                    vec2.at(k).at(i)=j-L;
                }
                L=j+1;
                j++;
                continue;
            }
            j++;
            if(j==H){
                for(int k=L;k<j;k++){
                    vec2.at(k).at(i)=j-L;
                }
                break;
            }
        }
        //for(int j=0;j<H;j++){cout<<vec2.at(j).at(i)<<" ";}
        //cout<<endl;
    }
    int ans=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            ans=max(ans,max(0,vec1.at(i).at(j)+vec2.at(i).at(j)-1));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 38616
object Main {
    def main(args: Array[String]) : Unit = {
        val sc = new java.util.Scanner(System.in)
        val a, b, c, d  = sc.nextInt
        println(calc(a, b, c, d))
    }
    def calc(a: Int, b: Int, c: Int, d: Int) : Int = {
        val ab = (a to b).toSet
        val cd = (c to d).toSet
        (ab & cd).size - 1 max 0
    }
}

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

using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;

u64 K;

u64 modPow(u64 n, u64 k, u64 mod)
{
    if (k == 0) return 1LL % mod;
    u64 r = modPow(n, k >> 1, mod);
    r = r * r % mod;
    if (k & 1) r = r * n % mod;
    return r;
}


int main(int argc, char *argv[])
{
    
 
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    bool found = false;
    u64 num = -1;
    cin >> K;
    for (u64 i = 0; i < K; i++) {
        u64 r = modPow(10, i + 1, 9*K);
        u64 rem = 7 * (r - 1);
        rem %= 9 * K;
        if (!rem) {
            found = true;
            num = i + 1;
            break;
        }
    }
    
    cout << num << endl;
    
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;

string o,q;

int main(){
	cin >> o >> q;
	for(int i=0;i<q.length();i++){
		cout << o[i] << q[i];
	}
	if(o.length()-q.length()){
		cout << o[o.length()-1] << endl;
		return 0;
	}else{
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#define _[2<<17]
n,i;B _,T _,F _;long M,D _,P _,R _;s(u,i,p,I){R[i]=i?s(u,T[i],p),(I=B[i])-p?s(I,F[I],u),D[u]=D[u]*-~D[I]%M:D[u]:++D[u];}S(u,x,p,i,I){for(i=F[u];I=B[i];I-p?S(I,R[i]*x%M+1,u),x=x*-~D[I]%M:0)i=T[i];P[u]=x%M;}main(u,v){for(;~scanf("%d%d",&u,&v);)i++?T[i-1]=F[u],T[i]=F[v],B[F[u]=i-1]=v,B[F[v]=i++]=u:(n=u,M=v);s(1,F[1],i=0);for(S(1,1);i++<n;)printf("%d ",P[i]);}

Measured memory_bytes: 13056
#include<iostream>
using namespace std;
#define MAX 2000000001
struct Node {
	int key = MAX;
	int parent = MAX;
	int left = MAX;
	int right = MAX;
};

Node T[500001];

void search_i(int search) {
	if (T[search].left != MAX) {
		search_i(T[search].left);
	}
	cout << " " << T[search].key;
	if (T[search].right != MAX) {
		search_i(T[search].right);
	}
}

void search_l(int search) {
	cout << " " << T[search].key;
	if (T[search].left != MAX) {
		search_l(T[search].left);
	}
	if (T[search].right != MAX) {
		search_l(T[search].right);
	}
}


void print() {
	search_i(0);
	cout << endl;
	search_l(0);
	cout << endl;
}

void insert(int k) {
	int p = 0;
	while (1) {
		if (T[k].key < T[p].key) {
			if (T[p].left == MAX) {
				T[p].left = k;
				T[k].parent = p;
				return;
			}
			else {
				p = T[p].left;
			}
		}
		else {
			if (T[p].right == MAX) {
				T[p].right = k;
				T[k].parent = p;
				return;
			}
			else {
				p = T[p].right;
			}
		}
	}
}

int main() {
	int n, tmp;
	string com;
	cin >> n;
	cin >> com;
	cin >> tmp;
	T[0].key = tmp;
	for (int i = 1; i < n; i++) {
		cin >> com;
		if (com == "insert") {
			cin >> tmp;
			T[i].key = tmp;
			insert(i);
		} 
		else {
			print();
		}
	}
}


Measured memory_bytes: 10972
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using std::cout;
using ll =long long;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int ab(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  int A,B;
  cin>>A>>B;
  cout<< A*B -A-B+1<<endl;
 

}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
	int N, c[26][100] = {};
	string S[3];
	cin >> N;
	int  ans = N * 3;
	for (int i = 0; i < 3; i++)cin >> S[i];
	for (int i = 0; i < N; i++)
	{
		if (S[1][i] == S[0][i] && S[0][i] == S[2][i])ans -= 3;
		else if (S[1][i] == S[0][i] || S[1][i] == S[2][i] || S[2][i] == S[0][i])ans -= 2;
		else ans--;
	}
	cout << ans;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main{

	static char[][] map;
	static int H;
	static int W;

	public static void main(String[] args) {



		Scanner sc = new Scanner(System.in);			//文字の入力
		int N =sc.nextInt();
		if(N < 1200){
			System.out.println("ABC");

		}else if(N < 2800){
			System.out.println("ARC");

		}else{
			System.out.println("AGC");
		}
	}
}





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

template<class T>
struct SkewHeap{
	struct Node{
		Node *l,*r;
		const T val;
		Node(const T val) : val(val),l(NULL),r(NULL){}
	};
	Node *root;
	SkewHeap() : root(NULL){}
	Node *meld(Node *a,Node *b){
		if(!a) return b;
		if(!b) return a;
		if(a->val < b->val) swap(a,b);
		a->r = meld(a->r,b);
		swap(a->l,a->r);
		return a;
	}
	void push(const T &x){
		root = meld(root,new Node(x));
	}
	void pop(){
		root = meld(root->l,root->r);
	}
	T top() const{
		return root->val;
	}
};

signed main(){
	SkewHeap<int> heap;
	char s[50];
	while(1){
		scanf("%s",s);
		if(!strcmp(s,"end")) break;
		else if(!strcmp(s,"insert")){
			int a;
			scanf("%d",&a);
			heap.push(a);
		}else{
			printf("%d\n",heap.top());
			heap.pop();
		}
	}
}



Measured memory_bytes: 50040
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <cstdlib>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	ll k; cin >> k;
	cout << 50 << endl;
	vector<ll> a(50, 49);
	rep(i, 50)a[i] += k / 50;
	k %= 50;
	rep(i, k)
	{
		rep(j, 50)
		{
			if (i == j)a[j] += 50;
			else --a[j];
		}
	}
	rep(i, 50)cout << a[i] << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    boolean flag=true;
    for(int i=0;i<s.length()/2;i++){
      if(s.charAt(i)!=s.charAt(s.length()-1-i)){
        flag = false;
        break;
      }
    }
    if(flag==true){
      for(int i=0;i<(s.length()-1)/4;i++){
      	if(s.charAt(i)!=s.charAt(s.length()/2-1-i)){
       	 flag = false;
         break;
     	 }
      }
    }
    int n=s.length();
    if(flag==true){
      for(int i=0;i<(n-(n+3)/2)/2;i++){
      	if(s.charAt(i+(n+3)/2-1)!=s.charAt(n-1-i)){
       	 flag = false;
         break;
     	 }
      }
    }
    if(flag == true) System.out.println("Yes");
    else System.out.println("No");
  }
}

Measured memory_bytes: 21844
fs = require('fs');
input = fs.readFileSync('/dev/stdin','utf8');
input = input.split('\n');
N = parseInt(input[0].split(' ')[0],10);
K = parseInt(input[0].split(' ')[1],10);
P = input[1].split(' ');
S = [];
for(i = 0; i < P.length; i++) {
  S.push(parseInt(P[i],10));
}
S.sort(compareFunc);
R = 0;
for(i = 0; i < K; i++) {
  R = R + S[i];
}
console.log(R);
function compareFunc(a, b) {
  return a - b;
}


Measured memory_bytes: 29772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
		

}
int main(){
   double A,B,H,M;
  cin>>A>>B>>H>>M;
  
  H*=30.0;
  H+=(M*1.0)/2;
  M*=6;
  
  double sita;
  if(abs(H-M)<=180){
    sita=abs(H-M)*1.0;
  }
else{
sita=(360-abs(H-M))*1.0;
}

 double pi=4.0*atan(1.0);
   double unit_r=180.0/pi;//ラジアンから弧度法
  double unit= pi / 180.0; 
 
 printf("%0.20lf\n",sqrt(power(A,2)+power(B,2)-2*1.0*A*B*cos(sita*unit)));

}


Measured memory_bytes: 4216
import heapq
q = []
N, M = map(int, input().split())
A = (map(int, input().split()))
for a in A:
    heapq.heappush(q, a)

lst = []   
for i in range(M):
    lst.append(list(map(int, input().split())))
lst = sorted(lst, key = lambda x: -x[1])
for i, j in lst:
    for _ in range(i):
        v = heapq.heappop(q)
        if v < j:
            heapq.heappush(q, j)
        else:
            heapq.heappush(q, v)
            break
print(sum(q))

Measured memory_bytes: 37188
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
 
 
 
 
 
 
 




vector<pair<int,int>> adj[100005];
ll dist[100005];
int n;
void dfs(int node,int par){
     for(auto ch:adj[node]){
          if(ch.fi==par)continue;
          dist[ch.fi]=dist[node]+ch.se;
          dfs(ch.fi,node);
     }
}




int main()
{
    string s;
    cin>>s;
    ll dp[2019]={0};
    dp[s[0]-'0']=1;
    ll res=0;
    for(int i=1;i<s.length();i++){
         int d=s[i]-'0';
         ll tmp[2019]={0};
         tmp[d]=1;
         for(int j=0;j<2019;j++){
              if(dp[j]>0){
                   int rem=(10*j+d)%2019;
                   tmp[rem]+=dp[j];
                   if(rem==0){res+=dp[j];}
              }
         }
         for(int j=0;j<2019;j++)dp[j]=tmp[j];
    }
    cout<<res;

}



































Measured memory_bytes: 6068
//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;  typedef long long ll;
inline int qr(){
	int ret=0,f=0,c=getchar();
	while(!isdigit(c))f|=c==45,c=getchar();
	while(isdigit(c)) ret=ret*10+c-48,c=getchar();
	return f?-ret:ret;
}

int main(){
	int k,a,b;
	cin>>k>>a>>b;
	bool ans=0;
	for(int t=a;t<=b;++t)
		if(t%k==0)
			ans=1;
	puts(ans?"OK":"NG");
	return 0;
}


Measured memory_bytes: 3596
// dile a la jardinera que traigo flores
// corner cases // int vs ll // cin vs scanf
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define N 100050
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int n,k,h[N],dp[N];

void go(){
	dp[0] = 0;
	for(int i = 1; i < n; ++i){
		dp[i] = 1e9;
		for(int j = 1; j <= k and (i-j) >= 0; ++j)
			dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
	}
}

int main(){
	
	fastio;
	cin >> n >> k;
	FER(i,0,n) cin >> h[i];

	go();

	cout << dp[n-1] << endl;

	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5+5;
const int Mx = 1e9+5;
int a[M],dp[M];
int solve(int i){
	//cout << i << " " << dp[i] << endl;
	if(i < 0 )return 0;
	if(dp[i] != Mx)return dp[i];
	if(i == 0){
		return 0;
	}if(i == 1){
		return abs(a[1]-a[0]);
	}
	return dp[i] = min( solve(i-1)+abs(a[i]-a[i-1]),
						solve(i-2)+abs(a[i]-a[i-2]));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		dp[i] = Mx;
	}
	cout << solve(n-1) << '\n';
	return 0;
}

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

int main(){

string a,b,a1,b1;
int c,k,w;
cin>>a>>b;
sort(a.begin(),a.end());
 for (int i = 0; i < b.size(); i++){//字母排序     摘抄 
		for (int j = i + 1; j < b.size(); j++){
			if (b[j] > b[i]){
				char pTem = b[j];
				b[j] = b[i];
				b[i] = pTem;
			}
		}
	}
if(a>b){
cout<<"No";
}
if(a==b){
	cout<<"No";
	
	
}
if(a<b){
		cout<<"Yes";
}
	return 0;
} 

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

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

    int h, m, s;

    h = S / 3600;
    S -= h * 3600;

    m = S / 60;
    S -= m * 60;

    s = S;

    cout << h << ":" << m << ":" << s << endl;

    return 0;
}


Measured memory_bytes: 3092
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solutionC(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solutionA(String[] args) throws Exception{
		String s = nextString();
		pw.println(s.substring(0,3));

	}
	public static void solutionB(String[] args) throws Exception{
		long A = nextLong();
		long V = nextLong();
		long B = nextLong();
		long W = nextLong();
		long T = nextLong();

		long dist=Math.abs(A-B);
		long a = V-W;

		if(A==B||a*T >=dist) {
			pw.println("YES");
		}else {
			pw.println("NO");
		}
	}
	public static void solutionC(String[] args) throws Exception{
		int N=nextInt();
		int K=nextInt();
		int[] A = nextInts();
		int roopEnd=(int)Math.min(K,60);


		for(int k=0;k<roopEnd;k++) {
			int[] tmp = new int[N];
			for(int i=0;i<N;i++) {
				int st = Math.max(0,i-A[i]);
				int end = Math.min(N-1,i+A[i]);
				tmp[st]++;
				if(end+1<N) {
					tmp[end+1]--;
				}
			}
			for(int i=1;i<N;i++) {
				tmp[i]+=tmp[i-1];
			}
			A=tmp;
		}
		print(A);
	}
	public static void solutionD(String[] args) throws Exception{
	}
	public static void solutionE(String[] args) throws Exception{
	}

	public static void print(int[] x) {
		StringBuffer sb = new StringBuffer();
		for(int i=0;i<x.length;i++) {
			sb.append(x[i]);
			sb.append(" ");
		}
		sb.deleteCharAt(sb.length()-1);
		pw.println(sb.toString());
	}
	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



Measured memory_bytes: 64344
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
int dy[4] = {1,0,-1,0},dx[4] = {0,1,0,-1};
typedef pair<ll, ll> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k - 1] = s[k - 1] - ('A' - 'a');
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N, M;
void func()
{
    string a[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string s;
    cin >> s;
    rep(i, 0, 7)
    {
        if (a[i] == s)
        {
            cout << 7 - i << endl;
        }
    }
}
int main()
{
    func();
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	if(s.find("7")!=string::npos) cout << "Yes";
	else cout << "No";
	return 0;
}



Measured memory_bytes: 3636
import java.util.Scanner

import scala.collection.immutable.Stack
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    val in = new Scanner(System.in)
    val v = in.nextInt()
    val graph = (0 until v).map { _ => new ArrayBuffer[Int]() }.toArray
    val e = in.nextInt()
    for (_ <- 0 until e) {
      val s = in.nextInt()
      val t = in.nextInt()
      graph(s).append(t)
    }

    val cmp = StronglyConnectedComponents.decompose(graph)
    val q = in.nextInt()
    for (_ <- 0 until q) {
      val u = in.nextInt()
      val v = in.nextInt()
      if (cmp(u) == cmp(v)) {
        println(1)
      } else {
        println(0)
      }
    }


  }

}

object StronglyConnectedComponents {
  def decompose(graph: IndexedSeq[Seq[Int]]): Array[Int] = {
    val vs = new ArrayBuffer[Int]()
    val V = graph.size
    val cmp = new Array[Int](V)

    val rg = graph.indices.map(_ => new ArrayBuffer[Int]())
    for {
      from <- graph.indices
      to <- graph(from)
    } rg(to).append(from)

    var used = Array.fill[Boolean](V)(false)
    var stack = new Stack[Int]()
    val added = Array.fill[Boolean](V)(false)
    for {
      i <- used.indices
      if !used(i)
    } {
      stack = stack.push(i)
      while (stack.nonEmpty) {
        val v = stack.top
        used(v) = true
        var pushed = false
        for {
          u <- graph(v).reverse
          if !used(u)
        } {
          stack = stack.push(u)
          pushed = true
        }
        if (!pushed) {
          stack = stack.pop
          if (!added(v)) {
            vs.append(v)
            added(v) = true
          }
        }
      }
    }

    used = Array.fill[Boolean](V)(false)
    var k = 0
    for {
      i <- vs.reverse
      if !used(i)
    } {
      stack = stack.push(i)
      used(i) = true
      cmp(i) = k
      while (stack.nonEmpty) {
        val v = stack.top
        var pushed = false
        for {
          u <- rg(v)
          if !used(u)
        } {
          used(u) = true
          cmp(u) = k
          stack = stack.push(u)
          pushed = true
        }
        if (!pushed) {
          stack = stack.pop
        }
      }
      k += 1
    }

    cmp
  }
}

Measured memory_bytes: 232972
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;


int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    ll k;
    cin >> k;
    ll count = a;
    if(a + b >= k) cout << min(a,k) << endl;
    else cout << min(a,k) - (k - (a + b)) << endl;
    return 0;
}

Measured memory_bytes: 3632
n = gets.to_i

arr = gets.split.map(&:to_i)

count = 0

n.times do |i|
  minj = i

  i.upto(n - 1) do |j|
    if arr[j] < arr[minj]
      minj = j
    end
  end

  if minj != i
    arr[i], arr[minj] = arr[minj], arr[i]
    count += 1
  end
end

puts arr.join(' ')
puts count

Measured memory_bytes: 8668
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;

bool solve() {
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (i * j == n)
                return true;
        }
    }
    return false;
}

void input() {
    cin >> n;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << (solve()?"Yes":"No") << endl;
}


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

int main(){
  int n,k;cin>>n>>k;
  int ans =0;
  int h;
  for (int i=0; i<n; i++){
    cin >> h;
    if (h >= k) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

typedef list<pii>::iterator lpiter;

pair<lpiter,lpiter> split(list<pii>& cards,int op1,int op2)
{
	iter(cards) i1=cards.begin();
	iter(cards) i2=i1;
	int sum=0;
	for(;;){
		int num=i2->second-i2->first+1;
		if(sum+num==op1){
			i2++;
			sum+=num;
			break;
		}
		else if(sum+num>op1){
			int over=sum+num-op1;
			pii temp(i2->second-over+1,i2->second);
			i2->second-=over;
			i2++;
			i2=cards.insert(i2,temp);
			sum=op1;
			break;
		}
		else{
			sum+=num;
			i2++;
		}
	}
	iter(cards) i3=i2;
	for(;;){
		int num=i3->second-i3->first+1;
		if(sum+num==op2){
			i3++;
			sum+=num;
			break;
		}
		else if(sum+num>op2){
			int over=sum+num-op2;
			pii temp(i3->second-over+1,i3->second);
			i3->second-=over;
			i3++;
			i3=cards.insert(i3,temp);
			sum=op2;
			break;
		}
		else{
			sum+=num;
			i3++;
		}
	}
	return mp(i2,i3);
}

int main()
{
	for(int n,m,p,q,r;cin>>n>>m>>p>>q>>r,n;){
		vector<pii> op(m);
		rep(i,m)
			cin>>op[i].first>>op[i].second;
		
		list<pii> cards;
		cards.push_back(mp(1,n));
		rep(i,m){
			pair<lpiter,lpiter> temp=split(cards,op[i].first,op[i].second);
			lpiter i2=temp.first,i3=temp.second;
			
			cards.splice(cards.begin(),cards,i2,i3);
			cards.splice(cards.begin(),cards,i3,cards.end());
		}
		
		pair<lpiter,lpiter> temp=split(cards,p-1,q);
		lpiter i2=temp.first,i3=temp.second;
		int res=0;
		for(lpiter i=i2;i!=i3;i++){
			if(i->second<=r)
				res+=i->second-i->first+1;
			else if(i->first<=r)
				res+=r-i->first+1;
		}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1092
#include <bits/stdc++.h>
#define si(n) scanf("%d",&n);
#define pi(n) printf("%d\n",n);
#define pl(n) printf("%lld\n",n);
#define sl(n) scanf("%lld",&n);
#define pd(n) printf("%lf\n",n);
#define ss(s) scanf("%s",s);
#define ps(s) printf("%s\n",s);
#define ll long long int
#define pb push_back
#define maxn 100005
#define sqrtn 317
#define maxm 2e9
#define pii pair<int,int>
#define eps 1e-9
#define mod 1000000007
using namespace std;
int a[maxn];
int b[maxn];
map<int,int> m;
int main()
{
    int n;
    si(n);
    for(int i=0;i<n;i++)
    {
        si(a[i]);
        b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++)
    {
        m[b[i]]=i;
    }
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(i%2==0 && m[a[i]]%2==1 || i%2==1 && m[a[i]]%2==0)
            cnt++;
    }
    pi(cnt/2);
}


Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <math.h>

using namespace std;

int main()
{
	int z = 0, i = 0;
	string s, s1;
	cin >> s;
	if (s == "1" || s == "0") {
		cout << 0 << endl;
	}
	else {
		for (int v = 0; v < s.length(); v++) {
			s1 = s[v];
			if (s1=="0") {
				z++;
			}
			else {
				i++;
			}
		}
		if (z < i) {
			cout << z * 2 << endl;
		}
		else {
			cout << i * 2 << endl;
		}
	}
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();

        if (check(r,g,b)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

    private static boolean check(int r, int g, int b) {
        return (r * 100 + g * 10 + b) % 4 == 0;
    }
}

Measured memory_bytes: 23764
def insertionSort(as)
  puts as.join(' ')
  i = 1
  while i < as.size do
    a = as[i]
    j = i - 1
    while j >= 0 do
      sorted = as[j]
      if sorted > a
        as[j] = a
        as[j+1] = sorted
        j = j - 1
      else
        j = -1
      end
    end
    puts as.join(' ')
    i = i + 1
  end
end

n = STDIN.gets.to_i
as = STDIN.gets.split(' ').map { |x| x.to_i }
insertionSort(as)



Measured memory_bytes: 6892
import math
k=int(input())
ans= 0
for s in range(1,k+1):
    for t in range(1,k+1):
        if math.gcd(s,t) == 1:
            ans=ans+k
        else:
            for u in range(1,k+1):
                ans= ans + math.gcd(math.gcd(s,t),u)
print(ans)

Measured memory_bytes: 9180
import heapq

[n, m] = [int(i) for i in input().split()]
a = [-1 * int(i) for i in input().split()]
heapq.heapify(a)
for i in range(m):
    tmp = heapq.heappop(a)
    heapq.heappush(a, int(tmp / 2))
print(-1 * sum(a))

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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fill(a,v) memset(a,v,sizeof(a))
#define d1(a) cout << a << "\n"
#define d2(a,b) cout << a << " " << b << "\n"
#define d3(a,b,c) cout << a << " " << b << " " << c << "\n"
#define d4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << "\n"
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
	fast;
	int n;
	cin >> n;
	int ans = 0;
	f(i,1,n+1){
		if(i%3 != 0 && i%5 != 0)	ans += i;
	}
	cout << ans;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N; ll Z, W;
ll A[MAX_N];

void solve() {
	cin >> N >> Z >> W;
	rep(i, 0, N) cin >> A[i];
	if(N == 1) {
		cout << abs(A[0] - W) << "\n";
	}
	else {
		cout << max(abs(A[N - 1] - W), abs(A[N - 1] - A[N - 2])) << "\n";
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256