akhauriyash/Code-Regression huggingface dataset:
N=int(input())
S=list(str(input()))
R=0
G=0
B=0
for i in range(N):
	if S[i]=='R':
		R+=1
	elif S[i]=='G':
		G+=1
	else:
		B+=1
ans=G*B*R
for a in range(N-1):
	for d in range(1,(N-a-1)//2+1):
		if S[a]!=S[a+d] and S[a+d]!=S[a+d*2] and S[a]!=S[a+d*2]:
			ans-=1
print(ans)



Measured memory_bytes: 9236
a, b, k = [int(i) for i in input().split()]
ans = []
if a > b:
    n = a
elif a < b:
    n = b
else:
    n = a

for x in range(1,n+1):
    if b % x == 0:
        if a % x == 0:
            ans.append(x)

print(ans[-k])

Measured memory_bytes: 61888
n=int(input())
l=list(map(int,input().split()))
a=0
b=0
for i in l:
    if i%4==0:
        a+=1
    if i%2==0:
        b+=1
b=b-a
if n<=2*a+1:
    print('Yes')
elif (n-2*a)<=b:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14252
import sys
sys.setrecursionlimit(10**6)

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]

for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M

for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]: # 前のループで求めたjから走査すれば良い（毎回Mから始める必要はない）
        j -= 1
    ans = max(ans, i + j)

print(ans)

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


int main()
{
	int n;
	cin >> n;
	if (64 < n  && n < 91)
		cout << 1 << endl;
	else if (96 < n && n < 123)
		cout << 2 << endl;
	else
		cout << 0 << endl;
}



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

int main() {
	int N,K;
	cin >> N >> K;
	vector<int> p(N);
	for (int i = 0; i < N; i++) {
		cin >> p.at(i);
	}
	
	sort(p.begin(),p.end());
	int ans = 1000000000;
	for (int i = 0; i < N - K + 1; i++) {
		if ((p.at(i + K - 1) - p.at(i)) < ans) {
			ans = p.at(i + K - 1) - p.at(i);
		} 
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct ModInt {
    static constexpr int P = 1000000007;
    ModInt() {}
    ModInt(ll k) : i(k % P) {}
    ModInt operator+(ModInt m) const {
        ModInt r;
        r.i = i + m.i;
        if (r.i >= P) r.i -= P;
        return r;
    }
    ModInt operator-(ModInt m) const {
        ModInt r;
        r.i = i - m.i;
        if (r.i < 0) r.i += P;
        return r;
    }
    ModInt operator*(ModInt m) const {
        ModInt r;
        r.i = (ll)i * m.i % P;
        return r;
    }
    ModInt operator/(ModInt m) const {
        return *this * m.inv();
    }
    ModInt& operator+=(ModInt m) {
        i += m.i;
        if (i >= P) i -= P;
        return *this;
    }
    ModInt& operator-=(ModInt m) {
        i -= m.i;
        if (i < 0) i += P;
        return *this;
    }
    ModInt& operator*=(ModInt m) {
        i = (ll)i * m.i % P;
        return *this;
    }
    ModInt& operator/=(ModInt m) {
        return *this *= m.inv();
    }
    ModInt operator-() const {
        ModInt r;
        r.i = i == 0 ? 0 : P - i;
        return r;
    }
    ModInt pow(ll k) const {
        ModInt r = 1, t = *this;
        for (; k != 0; k /= 2) {
            if (k & 1) r *= t;
            t *= t;
        }
        return r;
    }
    ModInt inv() const {
        return pow(P - 2);
    }
    bool isnan() const {
        return i < 0;
    }
    int i;
};
ostream& operator<<(ostream& os, ModInt m) {
    os << m.i;
    return os;
}

ModInt dp[201][100001];
int s[200];

ModInt f(int n, int x) {
    if (n == 1) return x % s[n - 1];
    if (!dp[n][x].isnan()) return dp[n][x];
    ModInt r = 0;
    r += f(n - 1, x % s[n - 1]);
    r += f(n - 1, x) * (n - 1);
    return dp[n][x] = r;
}

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

    memset(dp, -1, sizeof(dp));

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

    cout << f(n, x) << endl;

    return 0;
}

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

int get_figure_length(unsigned long int n) {
	int figure_length = 0;
	while(n > 0) {
		figure_length++;
		n /= 10;
	}

	return figure_length;
}

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

	int ans = get_figure_length(1E+10);
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0) {
			int figure_length = max(get_figure_length(i), get_figure_length(n / i));
			if (figure_length < ans) {
				ans = figure_length;
			}
		}
	}

	cout << ans << endl;

 	return 0;
 }

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

int main(int argc, const char * argv[]) {
    // insert code here...
    int A, B;
    string op;
    cin >> A >> op >> B;
    
    if (op == "+") cout << A + B << endl;
    if (op == "-") cout << A - B << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-                                                         
import numpy as np

N=int(input())
Vi=np.array(input().split(),dtype=int)
Ci=np.array(input().split(),dtype=int)

Xi=Vi-Ci
Xi_sort=np.sort(Xi)[::-1]
num=np.sum(Xi_sort>=0)

if num == 0:
    XY_max=0
else :
    XY_max=np.sum(Xi_sort[0:num])

print(XY_max)


Measured memory_bytes: 12504
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	int n;
	cin >> n;
	long a[n] , b[n];
	rep(i,0,n)
		cin >> a[i] >> b[i];
	
	long ans = 0;
	rrep(i,n-1,0){
		if( (a[i]+ans) % b[i] ){
			long c = (a[i]+ans) / b[i];	
			ans += b[i] * (c+1) - (a[i]+ans);
		}
	}
	P(ans);
	ret 0;
}

Measured memory_bytes: 1792
// fahadmd16(IIEST Shibpur)

#include<bits/stdc++.h>
#include <algorithm>
using namespace std;

#define ll                          long long
#define pb                          push_back
#define pf                          push_front
#define eb                          emplace_back
#define mp                          make_pair
#define ff                          first
#define ss                          second
#define db                          double
#define pll                         pair<ll, ll>
#define ALL(a)                      (a).begin(),(a).end()
#define endl                        "\n"

#define forn(i, n) for (ll i = 0; i < n; i++)
#define forn1(i, n) for (ll i = 1; i < n; i++)
#define ford(i, n) for (ll i = n - 1; i >= 0; i--)
#define forab(i, a, b) for(ll i = a; i < b; i++)
#define eps 1e-10

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)


#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;


const ll sz = 1e5 + 3;
const ll mod = 1e9 + 7;
const ll mod2 = 1e9;


typedef vector<ll> VL;
typedef vector<pll > VLL;
typedef vector<vector<ll> > VVL;

ll power(ll n, ll k, ll m) {
    ll ans = 1;
    while (k) {
        if (k & 1)ans = (ans * n) % m;
        k /= 2;
        n = (n * n) % m;
    }
    return ans;
}

void solver(ll test) {
    ll n; cin >> n;
    db pi = 2 * acos(0.0);
    cout << fixed << setprecision(5) << 2 * pi*n << endl;

}


int main() {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    IOS;
    ll T = 1; //cin >> T;
    forn1(i, T + 1) {
        clock_t z = clock();
        solver(i);
        debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
    }
    return 0;
}


Measured memory_bytes: 3808
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main{
	
	
	public static void main(String[] args) throws Exception {
		
		Scanner s=new Scanner(System.in);
		
		
		long n=s.nextLong();
		long ans=0;

		for(int i=1;i<=(Math.log(n)/Math.log(2))+1;i++) {
			ans=ans+(long)Math.pow(2, (Math.floor((Math.log(n)/Math.log(2))))+1-i);
			
		}
		System.out.println(ans);
		
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>

using namespace std;

int main() {

    string str,first,last,out;
    int strlength,middle;

    cin >> str;

    strlength = str.length();

    first = str[0];
    middle = strlength - 2;
    last = str[strlength - 1];

    out = first + to_string(middle) + last;

    cout << out << endl;



    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;


int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n,c;
    cin>>n>>c;
    vector<vector<bool>> ch(c+1,vector<bool>(100001,false));
    
    for(int i=0; i<n; i++){
        int x,y,z;
        cin>>x>>y>>z;
        for(int j=x; j<=y; j++){
            ch[z][j]=true;
        }
        
    }
    
    int ans=0;
    for(int i=1; i<=100000; i++){
        int ct=0;
        for(int j=1; j<=c; j++){
            ct+=ch[j][i];
        }
        ans=max(ans,ct);
    }
    
    cout<<ans;
    
   
   
    
    
    return 0;
}

Measured memory_bytes: 640
// abc.cpp :
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define irp(i,n) for(int i=(n);i>=0;i--)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define dw(i,s,e,d) for(int i=(s);i>(e);i-=(d))
#define in(x) cin>>(x)
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
void bye(auto x, int code=0){cout<<(x)<<endl;exit(code);}

void p1(vi v){
  for(auto a: v){ot(a);ot(",");}
}
void p2(vvi &x){
  for(auto v: x){ot("[");p1(v);ot("]\n");}
}

int main(){
	int n;cin>>n;
	map<string,ll> m;
	rp(i,n){
		string s; cin>>s;
		sort(s.begin(),s.end());
		m[s]++;
	}
	ll ans=0;
	for(auto e:m){
		// ote(e.first);
		// ote(e.second);
		if(e.second>1)ans += e.second*(e.second-1)/2;
	}

	ote(ans);
}

Measured memory_bytes: 11136
fun main(args:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val count = (0..n).map { 0 }.toIntArray()
    val ac = (0..n).map { false }.toBooleanArray()

    for(i in (1..m)) {
        val tmp = readLine()!!.split(" ")
        val idx = tmp[0].toInt()
        val isAc = tmp[1] == "AC"
        if(ac[idx]) {
            continue
        }
        if(isAc) {
            ac[idx] = true
        } else {
            count[idx]++
        }
    }
    println("%s %s".format(ac.filter { it }.size, ac.indices.filter { ac[it] }.map { count[it] }.sum()))
}


Measured memory_bytes: 55216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL<<60;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,m,n) for(int i=m;i<n;i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    int N;
    cin >> N;
    if(N%10 == 3){
        cout<<"bon"<<endl;
    }else if((N%10 ==0) || (N%10 == 1) || (N%10 ==6) || N%10 ==(8)){
        cout << "pon"<<endl;
    }else{
        cout<<"hon"<<endl;
    }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define lld long long int 
#define vint vector<int>
#define vlld vector<long long int>
#define vs vector<string>
#define ps push_back
#define pii pair<int,int>
#define vpii vector<pii>
#define vpll vector<pair<long long int , long long int>>
#define forl(i,a,b) for(int i = a ; i <= b ; i++)
#define forln(i,a,b) for(int i = a; i < b ; i++)
#define forb(i,b,a) for(int i = b ; i >= a ; i--)
#define forbn(i,b,a) for(int i = b ; i > a ; i--)
#define mk make_pair
#define le length
#define F first
#define S second
#define B begin
#define E end
#define in insert
#define len(str) lld len = str.length();
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define test()                  lld t; scanf("%d",&t); while(t--)
#define FAST ios_base::sync_with_stdio(false),cin.tie(NULL)

lld power(lld x, lld y) 
{ lld temp; if( y == 0) return 1; temp = power((x%mod), (y%mod)/2); if (y%2 == 0) return ((temp%mod)*(temp%mod))%mod;else return (((x%mod)*(temp%mod))%mod*(temp%mod))%mod;} 

int main()
{ 
    int n;
    
    cin>>n;
     lld arr[n];
     lld mul=1;
    bool f = true;
    for(int i=0;i<n;i++)cin>>arr[i];
    // sort(arr,arr+n);
    for(int i=0;i<n;i++){
        if(arr[i] == 0ll) {f= true;mul =0ll;break;}
        if( mul > 1000000000000000000/arr[i] ){
             
             f= false;
        }
        mul *= arr[i];
        if(mul > 1000000000000000000 || mul <0)f = false;
    }
   if( f== true) cout<<mul<<endl;
   else cout<<"-1\n";
 return 0;   
}

Measured memory_bytes: 4404
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final char[] n = in.next().toCharArray();
        final int k = in.nextInt();
        if (n.length < k) {
            System.out.println(0);
            return;
        }
        System.out.println(sum(n, k, 0));
    }

    private static int sum(char[] n, int count, int index) {
        if (count == 0) {
            return 1;
        }
        if (index >= n.length) {
            return 0;
        }
        final int number = n[index] - '0';
        if (number == 0) {
            return sum(n, count, index + 1);
        }

        int total = 0;
        if (count > 0 && count != n.length - index) {
            int result = combination(n.length - index - 1, count);
            for (int i = 0; i < count; i++) {
                result *= 9;
            }
            total += result;
        }
        if (number > 1) {
            int result = number - 1;
            result *= combination(n.length - index - 1, count - 1);
            for (int i = 0; i < count - 1; i++) {
                result *= 9;
            }
            total += result;
        }
        total += sum(n, count - 1, index + 1);
        return total;
    }

    private static int combination(int n, int k) {
        int top = 1;
        int bottom = 1;
        for (int i = 1; i <= k; i++) {
            bottom *= i;
            top *= n - i + 1;
        }
        return top / bottom;
    }
}


Measured memory_bytes: 23764
n=int(input())
a=list(map(int, input().split()))

l=[0]*9

for i in range(n):
  if a[i]<400:
    l[0]="t"
  elif a[i]<800:
    l[1]="t"
  elif a[i]<1200:
    l[2]="t"
  elif a[i]<1600:
    l[3]="t"
  elif a[i]<2000:
    l[4]="t"
  elif a[i]<2400:
    l[5]="t"
  elif a[i]<2800:
    l[6]="t"
  elif a[i]<3200:
    l[7]="t"
  else:
    l[8]+=1
countt=l.count("t")

if l[8]==0:
  print(countt,countt)
else:
  print(max(countt,1),countt+l[8])

Measured memory_bytes: 3064
import collections

s = list(input())
t = list(input())

c_s = collections.Counter(s)
s_values, s_counts = zip(*c_s.most_common())

c_t = collections.Counter(t)
t_values, t_counts = zip(*c_t.most_common())

if s_counts == t_counts:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 6960
class Switch
   def initialize
	  @cars = []
	  @out =[]
   end
   attr_reader :out
   def input(x)
	  @cars.push(x)
   end
   def output
	  @out.push(@cars[-1])
	  @cars.slice!(-1)
   end
end
s = Switch.new
while line = gets
   num = line.to_i
   if num != 0
	  s.input(num)
   else
	  s.output
   end
end
s.out.each {|each| puts each.to_s }

Measured memory_bytes: 6088
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		
		int k = 0;
		
		do {
			k++;
		}
		while (k * x % 360 != 0);
		
		System.out.println(k);
		
		sc.close();
	}
}




Measured memory_bytes: 27064
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <list>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI  = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

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

    int a, b;
    string op;
    cin >> a >> op >> b;

    if(op == "+"){
        cout << a + b << endl;
    }else{
        cout << a - b << endl;
    }

    return 0;
}


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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, a;
    cin >> x >> a;
    if(x < a) cout << 0 << ln;
    else cout << 10 << ln;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int a,h,w,d,m,y[90001],x[90001],s[90001];

int main() {
	cin >> h >> w >> d;
	REP(i,h) REP(j,w) {
    cin >> a;
    y[a]=i,x[a]=j;
  }
	cin >> m;
  int l[m],r[m];
	REP(i,m) cin >> l[i] >> r[i];

	for (int i=1; i<=h*w-d; i++) {
		s[i+d] = s[i] + abs(x[i+d]-x[i]) + abs(y[i+d]-y[i]);
  }

  REP(i,m) {
		COUT(s[r[i]]-s[l[i]]);
	}

  return 0;
}

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



def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    ans = 0
    count = 1
    for i in A:
        if i == count:
            count += 1

    if count == 1:
        print(-1)
        exit()
    print(N - count + 1)




    


if __name__ == '__main__':
    main()



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

int main() {
  int a,b;
  cin >> a>>b;
  if(b==1) cout << 0 << endl;
  else if(b<=a) cout << 1 << endl;
  else if((b-a)%(a-1)==0){
  cout << (b-a)/(a-1)+1 <<endl;
  }
  else cout << (b-a)/(a-1)+2 <<endl;
}
    
  

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



int main(void) {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;

    long long p[100010] = {0};
    long long q[100010] = {0};
    long long r[100010] = {0};
    for (int i=0; i<A; i++) cin >> p[i];
    for (int i=0; i<B; i++) cin >> q[i];
    for (int i=0; i<C; i++) cin >> r[i];

    sort(p, p+A, greater<>());
    sort(q, q+B, greater<>());
    sort(r, r+C, greater<>());

    long long z[300030] = {0};
    for (int i=0; i<X; i++) {
        z[i] = p[i];
    }
    for (int i=0; i<Y; i++) {
        z[i+X] = q[i];
    }
    for (long long i=0; i<C; i++) {
        z[i+X+Y] = r[i];
    }
    sort(z, z+300030, greater<>());
    long long sum = 0;
    for (long long i=0; i<(X+Y); i++) {
        sum += z[i];
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>

typedef struct{
  char mark;
  int num;
}Card;


int main(){
  Card card1[36], card2[36], temp;
  int i, j, a, b, status = 1, flag, minj, cnt = 0;
  int n;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf(" %c%d", &card1[i].mark, &card1[i].num);
    card2[i] = card1[i];
  }


  flag = 1;

  while(flag){
    flag = 0;

    for(i = n - 1; i > 0; i--){
      if(card1[i].num < card1[i-1].num){
	temp = card1[i];
	card1[i] = card1[i-1];
	card1[i-1] = temp;
	
	cnt++;
	flag = 1;
      }
    }
  }


  for(i = 0; i < n; i++){
    minj = i;

    for(j = i; j < n; j++){
      if(card2[j].num < card2[minj].num){
	minj = j;
      }
    }

    temp = card2[i];
    card2[i] = card2[minj];
    card2[minj] = temp;
    if(i != minj) cnt++;
  }


  for(i = 0; i < n - 1; i++){
    printf("%c%d ", card1[i].mark, card1[i].num);
  }

  printf("%c%d\n", card1[n-1].mark, card1[n-1].num);
  printf("Stable\n");

  for(i = 0; i < n - 1; i++){
    printf("%c%d ", card2[i].mark, card2[i].num);
  }

  printf("%c%d\n", card2[n-1].mark, card2[n-1].num);

  
  for(i = 0; i < n; i++){
    for(j = i+1; j < n; j++){
      for(a = 0; a < n; a++){
	for(b = a+1; b < n; b++){
	  if(card1[i].num == card1[j].num && card2[i].mark == card1[b].mark && card2[i].num == card1[b].num &&
	     card1[j].mark == card2[a].mark && card1[j].num == card2[a].num){
	    status=0;
	  }
	}
      }
    }
  }

  
  if(status == 0) printf("Not stable\n");
  else printf("Stable\n");

  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int INF = 1e9;
const int N = 11;

int main() {
  int M, G[N][N];
  while(cin >>M && M){
    int n = 0;
    REP(i, N) REP(j, N) G[i][j] = (i == j ? 0 : INF);
    REP(i, M){
      int f, t, c; cin >>f >>t >>c;
      n = max(n, max(f, t));
      G[f][t] = G[t][f] = min(G[t][f], c);
    }
    ++n;
    REP(k, n) REP(i, n) REP(j, n) G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
    int index = 0, sum = 0;
    REP(i, n) sum += G[0][i];
    FOR(i, 1, n){
      int _sum = 0;
      REP(j, n) _sum += G[i][j];
      if(_sum < sum){
        index = i;
        sum = _sum;
      }
    }
    cout <<index <<" " <<sum <<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <fstream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()

const int N = 2e6;
const int INF = 1e9 + 123;
const double EPS = 1e-9;

int n, m, x, y;

int main () {
    ios_base :: sync_with_stdio(0);
    cin >> n >> m >> x >> y;
    int mx = x, mn = y;
    for(int i = 1; i <= n; ++i) {
        int a;
        cin >> a;
        mx = max(mx, a);
    }
    for(int j = 1; j <= m; ++j) {
        int a;
        cin >> a;
        mn = min(mn, a);
    }
    if(mn - mx >= 1) cout << "No War\n";
    else cout << "War\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

int mod(int x, int m) {
	return (x%m+m)%m;
}

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n),b(n);
	rep(i,n) std::cin >> a[i];
	rep(i,n) std::cin >> b[i];
	// b -> a
	std::priority_queue<std::pair<int,int> > que;
	rep(i,n) if(a[i]<b[i]) que.emplace(b[i],i);
	int count = 0;
	while(!que.empty()) {
		debug(a,b);
		auto x=que.top();que.pop();
		int xx=x.first;int i=x.second;
		int yy=b[mod(i+1,n)]+b[mod(i-1,n)];
		debug(xx,yy,i);
		if(xx<yy) {
			continue;
		}
		if(b[i]==a[i]) continue;
		if(xx<a[i]) {
			print(-1);
			return 0;
		}
		if(a[i]>yy && (xx-a[i])%yy==0) {
			b[i]=a[i];
			count+=(xx-a[i])/yy;
		} else {
			count+=(xx-1)/yy;
			xx-=((xx-1)/yy)*yy;
			if(xx<a[i]) {
				print(-1);
				return 0;
			}
			b[i]=xx;
			que.emplace(b[i],i);
		}
	}
	rep(i,n) if(a[i]!=b[i]) {
		print(-1);
		return 0;
	}
	print(count);

	return 0;
}


Measured memory_bytes: 9584
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;


public class Main {


    static void solve() {
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int y = scan.nextInt();

        int a = x;
        int b = 0;
        while(a>=0 && b<=x) {
            if(a*2 + b*4 == y) {
                System.out.println("Yes");
                return;
            }
            a--;
            b++;
        }

        System.out.println("No");


//        int x1 = scan.nextInt();
//        int x2 = scan.nextInt();
//        int x3 = scan.nextInt();
//        int x4 = scan.nextInt();
//        int x5 = scan.nextInt();




//        for (int i = 0; i < t; i++) {
//            int n = scan.nextInt();
//
//            scase();
//        }
    }


//    static void solveCase(int t, int x, String s) {
//
//    }

    static void scase() {

    }




    public static void main(String[] args) {
        solve();
        //        Main m = new Main();
        //        Scanner scan = new Scanner(System.in);

        //        long n = scan.nextLong();
        //        long r = scan.nextLong();
        //        List<Long> list = new ArrayList<>();
        ////        int[] arr = new int[n];
        //        for (long i=0;i<n;i++){
        //            list.add(scan.nextLong());
        //        }
//            System.out.println(ch);
        //        solve(n, arr);
        //        scan.close();
    }


//
//    class Counter extends HashMap<Integer, Integer> {
//        public int get(int k) {
//            return containsKey(k) ? super.get(k) : 0;
//        }
//
//        public void add(int k, int v) {
//            put(k, get(k) + v);
//        }
//    }


//    static class TreeNode {
//        int val;
//        TreeNode left;
//        TreeNode right;
//
//        TreeNode(int x) {
//            val = x;
//        }
//    }

    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

}

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

using namespace std;
typedef pair<int, int> P;
const int INF = 1e9;
vector<string> s;
int h, w;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
int bfs() {
  vector<vector<int>> dist(h, vector<int>(w, INF));
  queue<P> q;
  dist[0][0] = 0;
  q.push(P(0, 0));
  
  while (!q.empty()) {
    P cur = q.front(); q.pop();
    int y = cur.first, x = cur.second;
    for (int i = 0; i < 4; ++i) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (ny < 0 || ny >= h|| nx < 0 || nx >= w ||dist[ny][nx] != INF) continue;
      if (s[ny][nx] == '#') continue;
      q.push(P(ny, nx));
      dist[ny][nx] = dist[y][x] + 1;
    }
  }
  return dist[h - 1][w - 1];
}

int main() {
  cin >> h >> w;
  int b_cnt = 0;
  for (int i = 0; i < h; ++i) {
    string t;
    cin >> t;
    s.push_back(t);
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#') b_cnt++;
    }
  }
  
  int c = bfs();
  if (c == INF) {
    puts("-1");
    return 0;
  }
  int ans = h * w - c - b_cnt - 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int N,M[25],i,j;

int dfs(int t[25])
{
	
	int i,j,h,w,m[25]={0},k,c,r,p;
	for(i=r=c=0;t[i]!=0;i++,r++,c++);
	for(i=0;i<c;i++)
	{
		for(h=-1;h<2;h++)
			for(w=0;w<(i%4==3?1:2);w++)
			{
				p=i+4*h+w;
				if(t[p]!=0&&(i!=p)&&(p>=0)&&(p<20)&&t[i]==t[p])
				{
					for(j=k=0;j<20;j++)
					{
						if(j!=i&&j!=p)
							m[k++]=t[j];
					}
					k=dfs(m);
					r=k<r?k:r;
				}
			}
	}
	return r;
}

int main()
{
	for(scanf("%d",&N);N--;)
	{
		for(i=0;i<20;i++)scanf("%d",&M[i]);
		printf("%d\n",dfs(M));
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define ss(x) (int) x.size()
#define FOR(i, n) for(int i = 1; i <= n; ++i)
#define fi first
#define se second
#define cat(x) cout << #x << " = " << x << endl
	
using namespace std;

const int mod = 998244353;

int n;	
int d[100001];
int res = 1, a;

int main() {	
	scanf("%d", &n);
	int maks = 0;	
	for(int i = 1; i <= n; ++i) {
		scanf("%d", &a);
		if(i == 1 && a != 0) {
			printf("0");
			return 0;
		}
		d[a] += 1;
		maks = max(a, maks);
	}
	if(d[0] > 1) {
		printf("0");
		return 0;
	}
	for(int i = 1; i <= maks; ++i) {
		if(d[i - 1] == 0) {
			printf("0");
			return 0;
		}
		for(int j = 1; j <= d[i]; ++j)
			res = (ll) res * d[i - 1] % mod; 
	}
	printf("%d", res);
	
		
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    char c;
    cin >> c;
    switch(c){
        case'a':
        case'e':
        case'i':
        case'o':
        case'u':cout<<"vowel"<<endl;
                break;
        default:cout<<"consonant"<<endl;
                break;

    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

#include <deque>
#include <algorithm>

using namespace std;

#define NMAX 1000

typedef long long i64;

static int n;
static i64 seq[NMAX + 10];
static deque<i64> q;
static int cnt, op[NMAX + 10];

inline void take(int i) {
    op[cnt++] = i;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", seq + i);
        q.push_back(seq[i]);
    }
    while (!q.empty() && q[0] <= 0) {
        take(1);
        q.pop_front();
    }
    while (!q.empty() && q.back() <= 0) {
        take(q.size());
        q.pop_back();
    }

    if (q.empty()) {
        int vi = max_element(seq + 1, seq + n + 1) - seq;
        printf("%lld\n%d\n", seq[vi], n - 1);
        for (int i = n; i > vi; i--)
            printf("%d\n", i);
        for (int i = 1; i < vi; i++)
            puts("1");
        return 0;
    }

    i64 s1 = 0, s2 = 0;
    for (int i = 0; i < q.size(); i += 2)
        s1 += max(0LL, q[i]);
    for (int i = 1; i < q.size(); i += 2)
        s2 += max(0LL, q[i]);

    if (s1 >= s2) {
        for (int i = 2; i < q.size() - 1; i += 2) if (q[i] <= 0) {
            take(i + 1);
            q[i - 1] += q[i + 1];
            q.erase(q.begin() + i);
            q.erase(q.begin() + i);
            i -= 2;
        }
        while (q.size() > 2) {
            take(2);
            i64 v = q[0] + q[2];
            q.pop_front();
            q.pop_front();
            q.pop_front();
            q.push_front(v);
        }
        if (q.size() == 2) {
            take(2);
            q.pop_back();
        }
    } else {
        for (int i = 1; i < q.size() - 1; i += 2) if (q[i] <= 0) {
            take(i + 1);
            q[i - 1] += q[i + 1];
            q.erase(q.begin() + i);
            q.erase(q.begin() + i);
            i -= 2;
        }
        while (q.size() > 3) {
            take(3);
            i64 v = q[1] + q[3], u = q[0];
            q.pop_front();
            q.pop_front();
            q.pop_front();
            q.pop_front();
            q.push_front(v);
            q.push_front(u);
        }
        if (q.size() == 3) {
            take(3);
            q.pop_back();
            take(1);
            q.pop_front();
        }
        if (q.size() == 2) {
            take(1);
            q.pop_front();
        }
    }

    printf("%lld\n%d\n", q[0], cnt);
    for (int i = 0; i < cnt; i++)
        printf("%d\n", op[i]);

    return 0;
}


Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        n: usize,
        a: [usize; n]
    }
    let mut v = vec![0; n];
    for (i, ai) in a.iter().enumerate() {
        v[ai - 1] = i + 1;
    }
    for vi in &v {
        print!("{} ", vi);
    }
    println!("");
}


Measured memory_bytes: 6908
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int D;
  cin>>D;
  vector<int> c(26);
  for(int &i:c)
    cin>>i;
  vector<vector<int>> s(D,vector<int>(26));
  for(vector<int> &v:s)
    for(int &i:v)
      cin>>i;
  vector<int> t(D);
  for(int &i:t)
    cin>>i;
  vector<int> A(26,0);
  int mz=0;
  for(int i=0;i<D;i++){
    A[t[i]-1]=i+1;
    mz+=s[i][t[i]-1];
    for(int j=0;j<26;j++)
      mz-=(i+1-A[j])*c[j];
    cout<<mz<<endl;
  }
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }

int main() {
    int N;
    cin >> N;
    int ans = 1e8;
    auto digit_sum = [](int x) -> int {
        int tmp = 0;
        do {
            tmp += x % 10;
            x /= 10;
        } while(x);
        return tmp;
    };
    for(int a = 1; a <= N - 1; a++) {
        int b = N - a;
        ans = min(ans, digit_sum(a) + digit_sum(b));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define sbits(a) __builtin_popcount(a)
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define gcd __gcd
#define lcm(a, b) ((a * b) / gcd(a, b))
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define nani(x) cerr << #x << " is " << x << endl;
#define ch(x) (x - 'a' + 1)
#define mp make_pair
#define pb push_back
#define loop(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define scan(x, n) loop(i, 0, n) cin >> x[i];
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define print(x, n) loop(i, 0, n) cout << x[i] << " ";
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000001
#define mod 1000000007

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef pair<long, long> pll;
typedef vector<ii> vii;
typedef vector<pll> vll;
typedef um<int, int> umii;
typedef um<char, int> umci;
typedef map<char, int> mci;
typedef map<int, int> mii;

const int N = 101, maxV = 1e5 + 1;
ll W[N], V[N], dp[maxV][N];

int main()
{
    fast;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, w, mval = 0;
    cin >> n >> w;

    for (int i = 1; i <= n; i++) {
        cin >> W[i] >> V[i];
        mval += V[i];
    }

    dp[0][0] = 0;

    for (int i = 1; i <= mval; i++) {
        dp[i][0] = inf;
        int idx = 0;
        for (int j = 1; j <= n; j++) {
            if (V[j] > i)
                continue;
            if (dp[i - V[j]][j])
                continue;
            if (dp[i - V[j]][0] + W[j] > w)
                continue;
            if (dp[i][0] > dp[i - V[j]][0] + W[j]) {
                dp[i][0] = dp[i - V[j]][0] + W[j];
                idx = j;
            }
        }
        if (idx) {
            dp[i][idx] = 1;
            for (int k = 1; k <= n; k++)
                dp[i][k] |= dp[i - V[idx]][k];
        }
    }

    for (int i = mval; i > 0; i--)
        if (dp[i][0] <= w) {
            cout << i;
            break;
        }

    return 0;
}


Measured memory_bytes: 79232
#重みをすべて負の値にして最小化問題に置き換える
N, M = map(int, input().split())
Edges = []
for i in range(M):
    a, b, c = map(int, input().split())
    a, b = a - 1, b - 1
    c = -c
    Edges.append([a, b, c])

dist = [float('inf')] * N
dist[0] = 0

for i in range(N):
    for fr, to, cost in Edges:
        if (dist[fr] != float('inf')) and (dist[to] > dist[fr] + cost):
            dist[to] = dist[fr] + cost
            if (i == N - 1) & (to == N - 1):
                print('inf')
                exit()

print(-dist[-1])


Measured memory_bytes: 3416
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,flag=0;cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++)cin>>a.at(i);
  for(int i=N-1;i>0;i--){
    if(a.at(i)<a.at(i-1)-1){
      flag=1;
      break;
    }
    else if(a.at(i)==a.at(i-1)-1)a.at(i-1)--;
    if(a.at(i-1)<0){
      flag++;
      break;
    }
  }
  if(flag==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  int pos = 0;
  ll sum = 0;
  rep(i, n - 1) {
    sum += a[i];
    if (sum * 2 < a[i + 1]) pos = i + 1;
  }
  cout << n - pos << endl;
}

Measured memory_bytes: 1024
line = gets.split(' ').map(&:to_i)

L = line[0]
R = line[1]
Mod = 2019

min = 2020
flag = false
for i in L..(R-1) do
  for j in i+1..R do
    a = (i * j) % Mod
    if a < min then
      min = a
    end
    if a == 0 then
      flag = true
      break
    end
  end
  if flag then
    break
  end
end
      
print min

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

using namespace std;

typedef long long ll;

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

	int n, k;
	cin >> n >> k;

	string s;
	cin >> s;

	rep(i, n){
		if(i+1 == k){
			cout << (char)(s[i] + 32);
		}else{
			cout << s[i];
		}
	}
	cout << endl;
}


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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,M,R; cin >> N >> M >> R ;
  vi r(R); rep(i,R){cin >> r[i] ; r[i]--; }
  vvl d(N,vl(N,ll(1e8)));
  rep(i,N) d[i][i] = 0;
  rep(i,M){
    int a,b; ll c; cin >> a >> b >> c ;
    a--; b--;
    d[a][b] = d[b][a] = c;
  }
  // rep(i,N) rep(j,N) rep(k,N) d[i][j] = d[j][i] = min(d[i][j],d[i][k]+d[k][j]);
  rep(k,N) rep(i,N) rep(j,N) d[i][j] = d[j][i] = min(d[i][j],d[i][k]+d[k][j]);
  dump(d);
  ll ans = ll(1e8);
  sort(ALL(r));
  do{
    dump(r);
    ll temp = 0;
    rep(i,R-1){
      dump(r[i],r[i+1]);
      temp += d[r[i]][r[i+1]];
    }
    chmin(ans,temp);
  }while(next_permutation(r.begin(),r.end()));
  cout << ans << endl;
  return 0;
}

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


void solve(long long N, long long M, std::vector<long long> A){
    long long sum = 0;
    rep(i,M){
        sum += A[i];
    }
    if(N-sum<0){
        cout << -1 << endl;
    }else {
        cout << N-sum << endl;
    }
}

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


Measured memory_bytes: 3832
import Control.Monad
 
import Data.Ord
import Data.List
import Data.Function
import Data.Maybe
 
import qualified Data.ByteString.Char8 as BS
 
import Debug.Trace
 
tuplify2 :: [a] -> (a, a)
tuplify2 (x:y:_) = (x, y)
tuplify2 _ = undefined
 
readInt = read :: String -> Integer
readIntTuple = tuplify2 . map readInt . words
readIntList = map readInt . words
 
getInt = readInt <$> getLine
getIntList = readIntList <$> getLine
getIntMatrix = map readIntList . lines <$> getContents
getIntTuple = readIntTuple <$> getLine
getIntTuples = map readIntTuple . lines <$> getContents
 
main = do
  [p,q,r] <- getIntList
  print $ (p + q + r - maximum [p,q,r])


Measured memory_bytes: 508
#定義
n, x = input().split()
n = int(n)
x = int(x)
m = []
i_min = 0
gokei = 0
#リストに数値を読み込み
for i in range(n):
  m.append(int(input()))
#一個ずつの合計
for i in range(len(m)):
  gokei = gokei + m[i]
  if m[i_min] > m[i]:
    i_min = i
#残量を出す
x = x - gokei
print(n + int(x/m[i_min]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

priority_queue< ll > lower, higher;
ll loz, hiz;

ll opt;

int main()
{
	int n; scanf("%d", &n);
	int xp = 0, yp = 0;
	for(int i = 1; i<= n; i++)
	{
		int x, y; scanf("%d %d", &x, &y);
		loz -= y-x;
		hiz += yp-xp;
		xp = x; yp = y;
		if(!lower.empty() && x<= lower.top()+loz)
		{
			ll k = lower.top()+loz;
			lower.pop();
			opt += abs(x-k);
			higher.push(-(k-hiz));
			lower.push(x-loz);
			lower.push(x-loz);
		}
		else if(!higher.empty() && x>= -higher.top()+hiz)
		{
			ll k = -higher.top()+hiz;
			higher.pop();
			opt += abs(x-k);
			lower.push(k-loz);
			higher.push(-(x-hiz));
			higher.push(-(x-hiz));
		}
		else
		{
			lower.push(x-loz);
			higher.push(-(x-hiz));
		}
	}
	printf("%lld\n", opt);
}

Measured memory_bytes: 2036
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n;
ll a[200005],rui[200005];

int main(){
	cin >> n;
	repn(i,n) cin >> a[i];
	repn(i,n) rui[i] = rui[i-1] + a[i];
	
	ll ans = 1e18;
	
	for(int i=2;i<=n-2;i++){
		int x = lower_bound(rui+1,rui+n+1,rui[i]/2)-rui;
		int y = lower_bound(rui+1,rui+n+1,rui[i]+(rui[n]-rui[i])/2)-rui;

		for(int a=x-3;a<=x+3;a++){
			for(int b=y-i-3;b<=y-i+3;b++){
				if(1 <= a && a < i && 1 <= b && b < n-i){
					ll p = rui[a];
					ll q = rui[i] - rui[a];
					ll r = rui[i+b] - rui[i];
					ll s = rui[n] - rui[i+b];
					
					ll mx = max(max(p,q),max(r,s));
					ll mn = min(min(p,q),min(r,s));
					ans = min(ans,mx-mn);
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328