akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	string s;
	while(cin>>N>>M) {
		ll ans=min(N, M/2);
		ans+=(M-min(N, M/2)*2)/4;
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
L=int(input())
A=[int(input()) for _ in range(L)]
dp=[0 for _ in range(5)]

for i in range(1,L+1):
    a=A[i-1]
    back = a%2 if a>0 else 2
    through = (a+1)%2

    dp[4] = min(dp[0:5]) + a
    dp[3] = min(dp[0:4]) + back
    dp[2] = min(dp[0:3]) + through
    dp[1] = min(dp[0:2]) + back
    dp[0]=dp[0]+a

print(min(dp))

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

int main() {
  int N = 0, M= 0, x= 0, ans= 0;
  cin >> N;
  vector<string> blue(N);

  for(int i = 0; i < N; i++){
    cin >> blue.at(i);
  }
  cin >> M;
  vector<string> red(M);
  for(int i = 0; i < M; i++){
    cin >> red.at(i);
  }
  
  for(int i = 0; i < N; i++){
    x = 0;
    for(int j = 0; j < N; j++){   
      if(blue.at(i) == blue.at(j)){
        x++;
      }
    }
    for(int j = 0; j < M; j++){
      if(blue.at(i) == red.at(j)){
        x--;
      }
    }
    if(x > ans){
      ans = x;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		
		if (Y%2!=0)
		{System.out.println("No");}
	else if ((Y>4*X)||(Y<2*X))
		{System.out.println("No");}
	else{System.out.println("Yes");}

	
	}
}

Measured memory_bytes: 35824
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC121
{
    class D
    {
        static void Main(string[] args)
        {
            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long A = input[0]; long B = input[1];

            Console.WriteLine(F(B) ^ F(A - 1));
        }

        static long F(long x)
        {
            switch (x % 4)
            {
                case 0: return x;
                case 1: return 1;
                case 2: return x + 1;
                case 3: return 0;
                default: return 0;
            }
        }

    }
}


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

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

void insertion_sort(int* a, int n) {
  int v, j;
  for(int i=1; i < n; i++) {
    rep(i, n) {
      cout << a[i];
      if(i != n-1) cout << " ";
    }
    cout << endl;
    v = a[i];
    j = i - 1;
    while(j >= 0 && a[j] > v) {
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
  }
  rep(i, n) {
    cout << a[i];
    if(i != n-1) cout << " ";
  }
  cout << endl;
}

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

  int A[n];
  rep(i, n) cin >> A[i];

  insertion_sort(A, n);
}



Measured memory_bytes: 3080
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			while(n--!=0)
			{
				var s = Console.ReadLine();
				var min = int.Parse(new string(s.OrderBy(c => c).ToArray()));
				var max = int.Parse(new string(s.OrderByDescending(c => c).ToArray()));
				Console.WriteLine(max - min);
			}
		}
	}
}

Measured memory_bytes: 6352
let iota ?(start=0) ?(step=1) cnt =
  let rec doit i acc =
    if i <= 0 then acc
    else doit (i - 1) (start + step*(i - 1) :: acc)
  in doit cnt []

let place_p x qs =
  let rec doit i = function
    | [] -> true
    | y :: _ when x = y + i || x = y - i -> false
    | _ :: ys -> doit (i + 1) ys
  in doit 1 qs

let killer_queen_p rc qs =
  let rec doit i = function
    | ([], _) -> true
    | (((r,_)::_ as rc), _::ys) when r <> i -> doit (i + 1) (rc, ys)
    | ((_,c)::xs, y::ys) when c = y -> doit (i + 1) (xs, ys)
    | _ -> false
  in doit 0 (rc, qs)

let print qs =
  let rec print_row i q =
    if i = 8 then print_newline ()
    else (print_string (if i = q then "Q" else "."); print_row (i + 1) q)
  in List.iter (fun q -> print_row 0 q) qs

let solve rc =
  let rec doit qs = function
    | [] -> if killer_queen_p rc qs then print qs
    | xs -> List.iter (fun x -> if place_p x qs then doit (x :: qs) (List.filter (fun e -> e <> x) xs)) xs
  in doit [] (iota 8)

let () =
  let k = read_int () in
  let rec read i acc =
    if i = k then List.sort (fun a b -> fst a - fst b) acc
    else read (i + 1) (Scanf.scanf "%d %d\n" (fun r c -> (r, c)) :: acc)
  in solve (read 0 [])

Measured memory_bytes: 3100
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

llong solve(int n, int coin){
  if(coin == 1 || n == 0) return 1;

  llong res = 0;
  int c = coin * coin;
  for(int i = 0; n - i * c >= 0; ++i){
    res += solve(n - i * c, coin-1);
  }
  return res;
}

int main(){

  while(true){
    int n;
    cin >> n;
    if(n == 0) break;

    cout << solve(n, 17) << endl;
  }
  return 0;
}




Measured memory_bytes: 3088
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int d = sc.nextInt();
			if(a==0 && b==0 && d==0) break;
			
			int t;
			boolean flag = false;
			if(a<b){
				t = a;
				a = b;
				b = t;
				flag = true;
			}
			
			int ansx = Integer.MAX_VALUE;
			int ansy = Integer.MAX_VALUE;
			int sum = Integer.MAX_VALUE;
			
			for(int i=d/a;i>=0;i--){
				t = d-i*a;
				if(t%b==0){
					ansx = i;
					ansy = t/b;
					sum = ansx+ansy;
					break;
				} 
			}
			
			for(int i=0;;i++){
				t = d+i*a;
				if(i+t/b>sum) break;
				if(t%b==0){
					ansx = i;
					ansy = t/b;
					sum = ansx+ansy;
					break;
				}
			}
			
			for(int i=d/a;;i++){
				t = -d+i*a;
				if(i+Math.abs(t)/b>=sum) break;
				if(t%b==0){
					ansx = i;
					ansy = t/b;
					sum = ansx+ansy;
					break;
				}
			}
			
			if(flag==false) System.out.println(ansx + " " + ansy);
			else System.out.println(ansy + " " + ansx);
		}	
	}	
}

Measured memory_bytes: 21252
#include <stdio.h>
#include <stdlib.h>
#define INFTY 1000000001

void mergeSort(int *,int,int);
void merge(int *,int,int,int);
int c=0;

int main()
{
  int *S,n,i;

  scanf("%d",&n);
  
  S = (int *)malloc(n * sizeof(int));

  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  
  mergeSort(S,0,n);

  for(i=0;i<n;i++){
    printf("%d",S[i]);
    if(i<n-1) printf(" ");
    else{
      printf("\n");
      printf("%d\n",c);
    }
  }

  free(S);

  return 0;
}

void mergeSort(int *S,int left,int right)
{
  int mid;
  
  if(left+1<right){
    mid = (left+right)/2;
    mergeSort(S,left,mid);
    mergeSort(S,mid,right);
    merge(S,left,mid,right);
  }
}

void merge(int *S,int left,int mid,int right)
{
  int n1,n2,k,i,j,*L,*R;
  n1 = mid-left;
  n2 = right-mid;

  L = (int *)malloc((n1+1) * sizeof(int));
  R = (int *)malloc((n2+1) * sizeof(int));
  
  for(i=0;i<n1;i++){
    L[i] = S[left+i];
  }

  for(i=0;i<n2;i++){
    R[i] = S[mid+i];
  }

  L[n1] = INFTY;
  R[n2] = INFTY;
  i=0,j=0;

  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      S[k] = L[i];
      i++;
    }
    else{
      S[k] = R[j];
      j++;
    }
    c++;
  }

  free(L);
  free(R);
}

    
  



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

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try{
	    String st;
	    while((st=sc.readLine())!=null){
		char[] c = st.toCharArray();
		int i=0;
		while(i<c.length){
		    if(c[i]=='@'){
			int n = c[i+1]-'0';
			for(int j=1; j<n; j++)
			    System.out.print(c[i+2]);
			i+=2;
		    }
		    else{
			System.out.print(c[i]);
			i++;
		    }
		}
		System.out.println();
	    }
    	}catch (Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 9352
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int n,m;
int miti[52][52];
int dk[52];
stack<int> s;
int ans=0;

int  dfs(int v,bool visited[8]){
   
    bool av=true;
    rep(i,n){
        if(visited[i]==false){av=false;}
    }
    
    if(av){return 1;}
    int ret=0;
    for(int i=0;i<n;i++){
        
        if(miti[v][i]==false)continue;
        if(visited[i]==true)continue;
        visited[i]=true;
        ret+=dfs(i,visited);
        visited[i]=false;
        
        
        
    }
    return ret;
    
    
   
}


int main(){
  
    cin>>n>>m;
    
    
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        miti[a-1][b-1]=1;
        miti[b-1][a-1]=1;
    }
    bool visited[8];
    rep(i,8){visited[i]=false;}
    visited[0]=true;
    cout<<dfs(0,visited)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (){
	int r;
	cin >> r;
	if(r < 1200){
		cout << "ABC" << endl;
	}else if(r < 2800){
		cout << "ARC" << endl;
	}else{
		cout << "AGC" << endl;
	}
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}
const ll mod = 1e9 + 7;

ll fact(ll n){
    if(n == 1) return 1;
    else return n * fact(n-1) % mod;
}

int main(){
    ll N, M; cin >> N >> M;
    if(abs(N - M) > 1){
        cout << 0 << endstr; return 0;
    }
    else if(N - M == 1 || M - N == 1){
        ll ret = (fact(N) * fact(M)) % mod;
        cout << ret << endstr; return 0;
    }
    else{
        ll ret = (2 * fact(N) * fact(M)) % mod;
        cout << ret << endstr;
    }
    
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int main(){
   int n,l;
   cin>>n>>l;
   deque<pint> deq;
   int a[n];
   rep(i,n)cin>>a[i];
   rep(i,n){
       while(!deq.empty()&&a[i]<=deq.back().first)
            deq.pop_back();
        deq.push_back({a[i],i});
        if(i>=l-1){
           cout<<deq.front().first;
           if(i==n-1)cout<<endl;
           else cout<<" ";
           if(deq.front().second==i-l+1)deq.pop_front();
       }
   }
   return 0;
}


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

int main(){
	int n,k,ans=0;
	cin>>n>>k;
	rep(i,77)if(i*9%11==k&&i%7>1){
	    ans+=floor(((n-1)*7.0-i)/77.0)-(i<7?1:0)+1;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int a;
    cin >> a;

    cout << a + a * a + a * a * a << "\n";

    return 0;
}



Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		while(h!=0){
			for(int i=0; i<h ;i++) {
				for(int j=0;j<w;j++) {
					System.out.print("#");
				}
				System.out.print("\n");
			}
			h = sc.nextInt();
			w = sc.nextInt();
			System.out.println();
		}
	}
}



Measured memory_bytes: 37656
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define SUM(x) accumulate(ALL(x));
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};


int k=0,n=0, m=0, l=0,a=0, b=0, c=0, d=0,e=0,ans=0,ans2=0,x=0,y=0;
string s,t,S;
signed main() {
    cin >> n;
    for(int i=1;i<=9;i++)for(int j=1;j<=9;j++){
        if(i*j==n){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
  return 0;
}


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

using namespace std;

const int mod = 2011;

typedef long long int64;

int expr(int, int, int);

inline int64 modPow(int64 x, int64 n)
{
  if(n == 0) return (1);
  int64 ret = modPow(x, n / 2);
  (ret *= ret) %= mod;
  if(n & 1) (ret *= x) %= mod;
  return (ret);
}

inline int64 modInv(int64 a)
{
  return (modPow(a, mod - 2));
}

int N, idx, width;
string S[20];

int LatteMalta(int top, int bottom)
{
  while(idx < width) {
    for(int i = top; i < bottom; i++) {
      if(S[i][idx] != '.') return (i);
    }
    ++idx;
  }
  return (-1);
}

int primary(int base, int top, int bottom)
{
  if(S[base][idx] == '(') {
    idx += 2;
    auto get = expr(base, top, bottom);
    idx += 2;
    return (get);
  } else {
    return (S[base][idx++] - '0');
  }
}

int powexpr(int base, int top, int bottom)
{
  int ret = primary(base, top, bottom);
  if(top <= base - 1 && idx < width && isdigit(S[base - 1][idx])) {
    return (modPow(ret, S[base - 1][idx++] - '0'));
  } else {
    return (ret);
  }
}

int factor(int base, int top, int bottom)
{
  if(S[base][idx] == '-' && S[base][idx + 1] == '.') {
    idx += 2;
    return ((mod - factor(base, top, bottom)) % mod);
  } else if(S[base][idx] == '-') {
    int latte = idx;
    auto ue = expr(LatteMalta(top, base), top, base);
    idx = latte;
    auto sita = expr(LatteMalta(base + 1, bottom), base + 1, bottom);
    idx = latte;
    while(idx < width && S[base][idx] == '-') ++idx;
    return (ue * modInv(sita) % mod);
  } else {
    return (powexpr(base, top, bottom));
  }
}

int term(int base, int top, int bottom)
{
  int ret = factor(base, top, bottom);
  while(idx + 2 < width && S[base][idx] == '.' && S[base][idx + 1] == '*') {
    idx += 3;
    (ret *= factor(base, top, bottom)) %= mod;
  }
  return (ret);
}

int expr(int base, int top, int bottom)
{
  int ret = term(base, top, bottom);
  while(idx + 2 < width && S[base][idx] == '.' && (S[base][idx + 1] == '+' || S[base][idx + 1] == '-')) {
    char operation = S[base][idx + 1];
    idx += 3;
    auto get = term(base, top, bottom);
    if(operation == '+') (ret += get) %= mod;
    else (ret += mod - get) %= mod;
  }
  return (ret);
}

int main()
{
  while(cin >> N, N) {
    for(int i = 0; i < N; i++) cin >> S[i];
    idx = 0;
    width = (int) S[0].size();
    cout << expr(LatteMalta(0, N), 0, N) << endl;
  }

}

Measured memory_bytes: 3056
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll N, H;
    cin >> N >> H;
    VLL a(N), b(N);
    rep(i,N){
        cin >> a[i] >> b[i]; 
    }
    ll maxi=0;
    sort(all(a));
    reverse(all(a));
    maxi=a[0];
    ll sum=0;
    ll count=0;
    sort(all(b));
    reverse(all(b));
    rep(i,N){
        if(b[i]>maxi){
            sum+=b[i];
            count++;
            if(sum>=H){
                cout << count << endl;
                return 0;
            }
        }
    }
    H-=sum;
    ll ans=0;
    if(H%a[0]==0){
        ans=H/a[0];
    }
    else{
        ans=H/a[0]+1;
    }
    cout << ans+count << endl;
}

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

int main(){
  int N,W;
  string S;

  cin >> N >> W;
  
  for(int i=0;i<W+2;i++)
    cout << '#';
  
  cout <<endl;
  
  for(int i=0;i<N;i++){
    cin >> S;
    cout << '#'+S+'#' <<endl;
  }
  
  for(int i=0;i<W+2;i++)
    cout << '#';
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
ma = lambda : map(int,input().split())
ni = lambda : int(input())
n,m,x = ma()
A =list(ma())
c1 = 0
c2 = 0
for a in A:
    if a>x:c1+=1
    else:c2+=1
print(min(c1,c2))


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


int divi(int x, int y){
  while (x != 0 && y != 0 && x != y) {
    if (x > y) {
      x = x % y;
      //error check...
      //cout << "x is "<< x << "  y is " << y << endl;
    }else if (y > x) {
      y = y % x;
      //error check
      //cout << "x is "<< x << "  y is " << y << endl;
    }
  }
  //error check
  //cout << "x is "<< x << "  y is " << y << endl;
  switch (x) {
    case 0:return y;
    default:return x;
  }
}

int main() {
  int x,y,tmp;
  cin >> x >> y;
  tmp = divi(x,y);
  cout << tmp << endl;
  return 0;
}



Measured memory_bytes: 3068
#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 n;
vector<int> x(10), y(10);
double dist(int i, int j){
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx*dx + dy*dy, 0.5);
}

int main(){
    cin >> n;
    rep(i, n) cin >> x[i] >> y[i];
    vector<int> d(n);
    rep(i, n) d[i] = i;
    double ans = 0.0;
    int cnt = 0;
    do{
        rep(i,n-1){
            ans += dist(d[i], d[i+1]);
        }
        cnt++;
    }while(next_permutation(d.begin(), d.end()));
    cout << fixed<<setprecision(7)<< ans / cnt << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
 
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed<<setprecision(14)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const lol MOD=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k,r;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >>n;
  map<int,int> ma;
  lol ans=0;
  for(int i=0;i<n;i++){
    int a;cin>>a;
    ma[a]++;
    ans+=a;
  }
  cin >>k;
  for(int i=0;i<k;i++){
    int b,c;
    cin >>b>>c;
    int tmp=c-b;
    tmp*=ma[b];
    ans+=tmp;
    ma[c]+=ma[b];
    ma[b]=0;
    cout <<ans<<'\n';
  }
  return (0);
}

Measured memory_bytes: 8084
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

int main() {
  ll x;
  while (cin >> x) {
    int result = 0;
    int r = 0;
    REP(i,x+1) {
      r += i;
      if (r >= x) { result = i; break; }
    }
    cout << result << endl;
  }
}


Measured memory_bytes: 256
from  math import log,floor
n=int(input())

if n==0:
  print(0)
  exit(0)

if n%2==1:
  print(0)
  exit(0)

f=floor(log(n,5))
ans=0
for i in range(f):
  t=n//(5**(f-i))
  ans+=t//2
print(ans)



Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	N := nextInt()
	m := make(map[int]struct{})

	for i := 0; i < N; i++ {
		m[nextInt()] = struct{}{}
	}

	fmt.Println(len(m))
}

Measured memory_bytes: 640
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))

A = [(A[i], i) for i in range(N)]
A_sort = sorted(A,reverse = True)

dp = [-float('inf')]*(N+1)
dp[0] = 0

for i in range(N):
    dp_new = [-float('inf')]*(N+1)
    pi = A_sort[i][1]  #もともといた場所
    for l in range(i+1): 
        r = i - l   #右を選んだ回数
        dp_new[l+1] = max(dp_new[l+1],dp[l] + A_sort[i][0] * (pi-l)) 
        dp_new[l] = max(dp_new[l],dp[l] + A_sort[i][0] * ((N-r-1)-pi))
    dp = dp_new
print(max(dp))

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

int main(){
	int N;
	int i=0;
	int hyp=0,cat=0;
	int x=0;
	
	cin >> N;
	int side[N][3];
	
	while(i<N){
		cin >> side[i][0] >> side[i][1] >> side[i][2];
		if(1<=side[i][0] && side[i][0]<= 1000){
			if(1<=side[i][1] && side[i][1]<= 1000){
				if(1<=side[i][2] && side[i][2]<= 1000)
					i++;
			}
		}
	}
	
	for(int j=0; j<i; j++){
		for(int k=0; k<3; k++){
			x = side[j][k]*side[j][k];
			if(hyp <= x){
				cat += hyp;
				hyp = x;
			}
			else
				cat += x;
		}
		if(hyp == cat)
			cout << "YES\n";
		else
			cout << "NO\n";
		hyp=0;
		cat=0;
	}
	
	return 0;
}

Measured memory_bytes: 1128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String ans = "No";

		//入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if((a<=c && c<=b) || (b<=c && c<=a)) {
			ans = "Yes";
		}

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 21972
#include "bits/stdc++.h"
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin>>s;
  if(s=="ARC")
  cout<<"ABC";
  else cout<<"ARC";
  
  
     
  return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int N,i,j,k,c,a,A[10000000],R[3]={9999999999,9999999999,9999999999};

int cmp(int *a,int *b){return *a>*b;}

int main()
{
	scanf("%d",&N);
	for(i=0;i<N;i++)scanf("%d",&A[i]);

	for(i=0;i<N;i++)
		for(j=0;j<N;j++)
		{
			if(i!=j)
			{
				for(k=10;A[j]%k!=A[j];k*=10);
				a=A[i]*k+A[j];
				for(k=0;k<3;k++)
					if(R[k]>a)a^=R[k]^=a^=R[k];
			}
		}
	printf("%d\n",R[2]);
	return 0;
}

Measured memory_bytes: 624
import itertools
 
N = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

# print(p)
count = 1
for i in itertools.permutations([i+1 for i in range(N)]):
    if list(i) == p:
        a = count
    if list(i) == q:
        b = count
    count += 1

print( abs(a-b) )

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

#define int long long

signed main(){
    int n, a, b;
    cin >> n >> a >> b;

    if(a > b){
        cout << 0 << endl;
        return 0;
    }

    if(a == b){
        cout << 1 << endl;
        return 0;
    }

    if(n == 1){
        cout << 0 << endl;
        return 0;
    }

    cout << (b*(n-1)+a)-(a*(n-1)+b)+1 << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (31 - __builtin_clz(x))
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 19;

long long f(int n, vector <pair <int, int> > T)
{
	sort(ALL(T));
	reverse(ALL(T));
	set <int> S;
	FOR(i, 0, n)
		S.insert(i);
	long long ret = 0;
	for (auto [dx, i] : T)
	{
		auto it = S.lower_bound(i);
		if (it != S.begin())
			S.erase(prev(it)), ret += dx;
	}
	return ret;
}

void solve()
{
	int n;
	scanf ("%d", &n);
	vector <pair <int, int> > front, back;
	long long res = 0;
	FOR(i, 0, n)
	{
		int k, l, r;
		scanf("%d%d%d", &k, &l, &r);
		
		if (k == n)
		{
			res += l;
			continue;
		}
		res += min(l, r);
		
		if (l > r)
			front.pb({l - r, k});
		if (r > l)
			back.pb({r - l, n - k});
	}
	
	res += f(n, front);
	res += f(n, back);
	printf("%lld\n", res);
}

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


Measured memory_bytes: 14880
#include <iostream>
using namespace std;
int main()
{
    int d,e,c;
    int a[5];
    d=1^2^3^4^5;
    for(int i=0;i<5;i++)
    {
        cin>>a[i];
    }
    e=a[0]^a[1]^a[2]^a[3]^a[4];
    c=d^e;
    cout<<c;
return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int,Int> pii;
typedef pair<Int,double> pid;
typedef pair<double,double> pdd;
typedef pair<Int,pii> pip;
typedef pair<double,Int> pdp;
#define A first
#define B second
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define Itype(a) typeof(a.begin()) 
#define REP(i,a,b) for(int i = (a);i <= (b);i++)
#define FORO(i,n) REP(i,0,(int)n-1)
#define FORI(i,n) REP(i,1,(int)n)
#define FORIT(i,t) for(Itype(t) i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a,_b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define abs(x) (x < 0 ? -x : x) 
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
template<typename T>void getMin(T &a,T b) { if(a > b) a = b; }
template<typename T>void getMax(T &a,T b) { if(a < b) a = b; }
const int MOD = 1000000007;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a[5], k;
    FORO(i, 5) cin >> a[i];
    cin >> k;
    bool flg = false;
    FORO(i, 5) {
        FORO(j, 5) {
            if(abs(a[i] - a[j]) > k) flg = true;
        }
    }
    cout << (flg ? ":(" : "Yay!") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static int getInt(){
		return Integer.parseInt(s.next());
	}
	static IntStream REPS(int r){
		return IntStream.range(0,r);
	}
	static IntStream REPS(int l,int r){
		return IntStream.rangeClosed(l,r);
	}
	static IntStream INTS(int l){
		return REPS(l).map(i->getInt());
	}
	public static void main(String[]__){
		int[] in=INTS(getInt()).sorted().toArray();
		
		System.out.println(in[in.length-1]-in[0]);
	}
}


Measured memory_bytes: 27348
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll a[225816],af[225816],ab[225816];

int main(void){
	int n,i;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	for(i=1; i<n; ++i){
		af[i] = max(af[i-1],a[i-1]);
	}
	for(i=(n-1); i>0; --i){
		ab[i-1] = max(ab[i],a[i]);
	}
	for(i=0; i<n; ++i){
		cout << max(af[i],ab[i]) << endl;
	}
	return 0;
}


Measured memory_bytes: 6528
import java.io.InputStream;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static long mod = 1000000007;

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    long ans = BigInteger.valueOf(2).modPow(
      BigInteger.valueOf(n), BigInteger.valueOf(mod)
    ).longValue();
    ModInt m = new ModInt(ans, mod);
    m = m.minus(1);
    m = m.minus(combination(n, a));
    m = m.minus(combination(n, b));
    pw.println(
      m.x
    );
  }

  static long combination(int n, int a) {
    long x = 1;
    long y = 1;
    for (int i = 0; i < a; i++) {
      x *= n - i;
      x %= mod;
      y *= i + 1;
      y %= mod;
    }
    return new ModInt(x, mod).divide(new ModInt(y, mod)).x;
  }

  static class ModInt {

    private final long mod;
    private long x;

    ModInt(long x, long mod) {
      this.x = x;
      this.mod = mod;
    }

    ModInt(ModInt m) {
      this.x = m.x;
      this.mod = m.mod;
    }

    ModInt minus(long m) {
      ModInt n = new ModInt(this);
      if ((n.x += (mod - m)) >= mod) {
        n.x -= mod;
      }
      return n;
    }

    ModInt multiplicity(long m) {
      ModInt n = new ModInt(this);
      n.x *= m;
      n.x %= mod;
      return n;
    }

    ModInt pow(long p) {
      if (p == 0) {
        return new ModInt(1, mod);
      }
      ModInt a = pow(p >> 1);
      a = a.multiplicity(a.x);
      if ((p & 1) == 1) {
        a = a.multiplicity(x);
      }
      return a;
    }

    ModInt inv() {
      return pow(mod - 2);
    }

    ModInt divide(ModInt d) {
      ModInt n = new ModInt(this);
      n = n.multiplicity(d.inv().x);
      return n;
    }
  }
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 n,k;
    cin >> n >> k;
    vector<int32> cnt(40, 0);
    REP(i,n){
        int64 a;
        cin >> a;
        REP(j,40){
            cnt[j] += (a >> j & 1);
        }
    }
    // ostream_iterator<int32> out_it(cout, " ");
    // copy(ALL(cnt), out_it);
    // cout << endl;
    vector<int64> dp(41, 0);    //dp[i] := i bit目までkと同じ時のそこまでのf
    FORR(d,39,0){
        if((k) >> d & 1){
            dp[d] = dp[d+1] + (1ll << d) * (n - cnt[d]);
        }else{
            dp[d] = dp[d+1] + (1ll << d) * cnt[d];
        }
    }
    int64 ans = dp[0];
    REP(i,41){
        if(((k >> i) & 1) == 0)continue;
        int64 f = dp[i+1];
        f += (1ll << i) * cnt[i];
        REP(j,i){
            f += (1ll << j) * max(cnt[j], n - cnt[j]);
        }
        // cout << f << " ";
        ans = max(ans, f);
    }
    // cout << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <array>
#include <stdlib.h>

#define INT_MAX 2000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)

using namespace std;

int i, j, k;

int main() {
	int n;
	int l[1000], r[1000];
	cin >> n;
	rep(i, 0, n) {
		cin >> l[i] >> r[i];
	}
	int ans = 0;
	rep(i, 0, n) {
		ans = ans + r[i] - l[i]+1;
	}
	cout << ans << endl;
	return 0;
}

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

int X;
int main(){
	scanf("%d", &X);
	
	long long r = X / 500 * 1000;
	X -= X / 500 * 500;
	r += X / 5 * 5;
	printf("%lld\n", r);
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int count = 0;
		int sum = 1;
		while(b > sum) {
			sum += a - 1;
			count++;
		}
		
		System.out.println(count);

	}

}


	

Measured memory_bytes: 25172
#include <cmath>
#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
#include <iomanip>
using namespace std;

int main()
{
    int n, min, max;
    long long sum;

    cin >> n;

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

    min = a[0];
    max = a[0];
    for (int i = 0; i < n; i++)
    {
        if (a[i] < min)
        {
            min = a[i];
        }
        if (a[i] > max)
        {
            max = a[i];
        }
        sum += a[i];
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 3240
import java.util.Scanner;

public class Main {
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int a = stdIn.nextInt() +1;
        int ans = 0;

        for (int i = 1; i <a; i++) {
            for (int j = 1; j <a; j++) {
                for (int k = 1; k <a ; k++) {
 //                   System.out.println(i+""+j+""+k);
                    ans += gcd(gcd(i,j),k) ;
                }
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 35752
#include <iostream>
#include<bits/stdc++.h>
#define rep(k,i,n) for(long i=k;i<n;++i)
using namespace std;
long N,K;
long happy_count(string *s){
    long c=0;
    rep(0,i,N){
        if((i==0&&s[i]=="L") || (i==N-1 && s[i]=="R")){
            ++c;
        }else{
            if(s[i]=="L"){
                if(s[i-1]=="R")++c;
            }else if(s[i]=="R"){
                if(s[i+1]=="L")++c;
            }
        }
    }
    return c;
}
int main(void){
    // Your code here!
    cin>>N>>K;
    string S,s[N];
    cin>>S;
    rep(0,i,N)s[i]=S.substr(i,1);
    long c=happy_count(s);
    rep(0,i,K){
        c-=2;
        if(c<=0){
            c=1;
            break;
        }
    }
    long ans=N-c;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5760
L=list(map(int,input()))
n=len(L)
def power(a,n):
    x=1
    L=list(format(n,'b'))
    l=len(L)
    for i in range(l):
        if int(L[l-i-1])==1:        
            x=(x*a)%(10**9+7)
        a=(a*a)%(10**9+7)
    return x
X=power(3,n-1)%(10**9+7)
count=1
for i in range(1,n):
    if L[i]==1:
        k=n-i-1
        count+=1
        X+=(power(3,k)%(10**9+7))*(power(2,count-1)%(10**9+7))
X+=power(2,count)%(10**9+7)
print(X%(10**9+7))


Measured memory_bytes: 46044
from collections import defaultdict
import sys
sdin = sys.stdin.readline

N, K = map(int, sdin().split())
AB = []
for _ in range(N):
    AB.append(tuple(map(int, sdin().split())))
    
    
dic = defaultdict(int)

# 辞書に追加していく
for a,b in AB:
    dic[a] += b
    
# キーの昇順リストつくる
key_list = list(dic.keys())
key_list.sort()

# resが0になるまで引いていく
res = K
i = 0
while res > 0:
    res -= dic[key_list[i]]
    ans = key_list[i]
    i += 1
    
print(ans)

Measured memory_bytes: 22944
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	long long int a,s,d,f,g,h,z,x;
	int i,j;
	scanf("%lld",&a);
	d=a;
	f=0;
	for(i=2;i<=100000000;i++){
		if(i>a/i)
			break;
		if(a%i==0){
			d=i;
			f=a/i;
		}
	}
	g=1;
	h=1;
	for(i=1;i<10;i++){
		if(d>9){
			d=d/10;
			g++;
		}
		if(f>9){
			f=f/10;
			h++;
		}
	}
	z=g;
	if(h>g)
		z=h;
	printf("%lld\n",z);
	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		long H[] = new long[N];
		for(int i = 0 ; i < N ; ++i){
			H[i] = sc.nextLong();			
		}
		Arrays.sort(H);
		long S = 0;
		for(int i = 0 ; i < Math.max(0, N - K) ; ++i){
			S += H[i];
		}
		System.out.println(S);
	}
}


Measured memory_bytes: 90128
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
long long dp[3001][3001],a[3001][3001];
long long n,m;
int main(){
cin>>n>>m;
for(int k=1;k<=n;k++)
for(int i=1;i<=m;i++){
   char ch;
   cin>>ch;
   if(ch=='.')
    a[k][i]=1;
}
dp[1][1]=1;
for(int k=1;k<=n;k++)
for(int i=1;i<=m;i++){
        if(a[k][i]==0)
        continue;
   if(a[k][i-1]==1)
    dp[k][i]+=dp[k][i-1];
   if(a[k-1][i]==1)
    dp[k][i]+=dp[k-1][i];
    dp[k][i]%=mod;
}
cout<<dp[n][m];
return 0;
}


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

using namespace std;

int main() {
    int n, v[20], c[20];

    cin >> n;
    for (int i=0; i<n; i++) cin >> v[i];
    for (int i=0; i<n; i++) cin >> c[i];

    int ans = 0;
    for (int i=0; i<n; i++) {
        if (v[i] > c[i]) ans += v[i] - c[i];
    }

    cout << ans << endl;

    return 0;
}

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

struct node{
  int key;
  struct node *prev;
  struct node *next;
};

  typedef struct node * Node;
  void make_node(void);
  void insert(int);
  void delete(int);
  void list(void);

  Node head;

  int main(){
    
    int  i;
    int  n;
    int  key;
    char order[15];
    Node x;
    
    make_node();
   
    scanf("%d",&n);
    for(i=0;i<n;i++){
    scanf("%s",order);
    if(strcmp(order,"insert")==0){
    scanf("%d",&key);
    insert(key);
    }
    else if(strcmp(order,"delete")==0){
    scanf("%d",&key);
    delete(key);
    }
   
    else if(strcmp(order,"deleteFirst")==0){
    x = head->next;
    x->prev->next = x->next;
    x->next->prev = x->prev;
    free(x);
    }
 
    else if(strcmp(order,"deleteLast")==0){
    x = head->prev;
    x->prev->next = x->next;
    x->next->prev = x->prev;
    free(x);
    }
   }
   list();
   return 0;
}
    void make_node(void){
    head = malloc(sizeof(struct node));
    head->next = head;
    head->prev = head;
    }

    void insert(int key){
   
    Node x;
   
    x = malloc(sizeof(struct node));
   
    x->next = head->next;
    head->next->prev = x;
    head->next = x;
    x->prev = head;
   
    x->key = key;
    }
    void delete(int key){
    Node x;
    for(x=head->next;x!=head;x=x->next){
    if(x->key == key){
    x->prev->next = x->next;
    x->next->prev = x->prev;
    free(x);
    break;
     }
    }
   }
void list(void){
   Node x;
   for(x=head->next;x!=head->prev;x=x->next){
   printf("%d ",x->key);
     }
   printf("%d",x->key);
   printf("\n");
}

Measured memory_bytes: 31788
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;

public class Main {
	static int n;
	static List<List<Integer>> list;
	static int[] dv;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		n = Integer.parseInt(sa[0]);
		int u = Integer.parseInt(sa[1]) - 1;
		int v = Integer.parseInt(sa[2]) - 1;
		list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < n - 1; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			list.get(a).add(b);
			list.get(b).add(a);
		}
		br.close();

		dv = new int[n];
		dfs(v, -1);

		int[] du = new int[n];
		Arrays.fill(du, -1);
		Queue<Integer> que = new ArrayDeque<>();
		que.add(u);
		du[u] = 0;
		while (!que.isEmpty()) {
			int x = que.poll();
			for (int i : list.get(x)) {
				if (du[i] == -1 && du[x] + 1 < dv[i]) {
					que.add(i);
					du[i] = du[x] + 1;
				}
			}
		}

		int max = -1;
		for (int i = 0; i < n; i++) {
			if (du[i] >= 0) {
				max = Math.max(max, dv[i]);
			}
		}
		System.out.println(max - 1);
	}

	static void dfs(int x, int p) {
		for (int i : list.get(x)) {
			if (i != p) {
				dv[i] = dv[x] + 1;
				dfs(i, x);
			}
		}
	}
}


Measured memory_bytes: 62152