akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
   
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define vi vector<int>
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 1000000007
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long


void solve()
{
    string s;
    cin>>s;
    
    int n=s.size();
    if(s[n-1]=='s')
    {
        cout<<s;
        cout<<"es";
    }
    else 
    {
        cout<<s;
        cout<<"s";
    }
}

int32_t main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    
	int t=1;
//	cin>>t;
	while(t--)solve();
	    
   
}

Measured memory_bytes: 3608
var GET = (function () {function f(s) {return new g(s);}function g(s) {this._s = s.trim().split("\n");}g.prototype.getValue = function (n) {return this._s[n];};g.prototype.getArray = function (n) {return this.stoa(this._s[n]);};g.prototype.slice = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));};g.prototype.sliceArray = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));};g.prototype.stoa = function (s) {return s.split(" ").map(v => this.stox(v));};g.prototype.stox = function (v) {var i = +v;return (i === i) ? i : v;};return f;})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(main());
function main() {
    var N = o.getValue(0);
    if (N % 2 === 1) {
        return (Math.ceil(N / 2)) / N;
    } else {
        return (N / 2) / N;
    }
}

Measured memory_bytes: 21064
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	uint64_t N;
	uint64_t i;
	uint64_t horieyui = UINT64_C(22222222222222222);
	if (scanf("%" SCNu64, &N) != 1) return 1;
	for (i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			uint64_t kugyu = N / i;
			uint64_t score = (i - 1) + (kugyu - 1);
			if (score < horieyui) horieyui = score;
		}
	}
	printf("%" PRId64 "\n", horieyui);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int A, B;
  int answers[3] = {1,2,3};
  cin >> A >> B;
  
  for(int i=0;i<3;i++){
    if(answers[i]!=A && answers[i]!=B) cout << answers[i] << endl;
  }
  
  return 0;
}

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

int main(){
    int N,K,X,Y;
    cin >> N >> K >> X >> Y;

    int ans = 0;

    for(int i = 0; i < N; ++i){
        if(i < K){
            ans += X;
        }
        else{
            ans += Y;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

int main()
{
    int W,a,b;
    cin >> W >> a >> b;
    if(a > b)
    {
        int tmp = b;
        b = a;
        a = tmp;
    }
    cout << (b - a - W > 0 ? b - a - W : 0 )  << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 2e+5+5;

int n;
int p[N];
bool vis[N];
int a[N],k;
int lef[N],rig[N],val[N];
bool bz[N];
bool ext[N];
int m,b[N];

int solveb(){
	if (!m)return 0;
	sort(b+1,b+1+m);
	int m_=1;
	fo(i,2,m)if (b[i]>b[i-1])b[++m_]=b[i];
	m=m_;
	int ans=m;
	fo(i,1,m)
	if (b[i]!=i-1){ans=i-1;break;}
	return ans;
}

void dfs(int x){
	for(int y=lef[x];y;y=rig[y])dfs(y);
	m=0;
	for(int y=lef[x];y;y=rig[y])b[++m]=val[y];
	val[x]=solveb();
}

bool check(int v){
	val[a[1]]=v;
	fo(i,2,k){
		b[m=1]=val[a[i-1]];
		for(int y=lef[a[i]];y;y=rig[y])b[++m]=val[y];
		val[a[i]]=solveb();
	}
	b[m=1]=val[a[k]];
	for(int y=lef[a[1]];y;y=rig[y])b[++m]=val[y];
	int tmp=solveb();
	return tmp==val[a[1]];
}

int main(){
	n=get();
	fo(i,1,n)p[i]=get();
	int x=1;
	for(;!vis[x];x=p[x])vis[x]=1;
	for(;!k||x!=a[1];x=p[x])a[++k]=x;
	fo(i,1,k)bz[a[i]]=1;
	fo(i,1,n)
	if (!bz[i]){
		rig[i]=lef[p[i]];
		lef[p[i]]=i;
	}
	fo(i,1,k)dfs(a[i]);
	if (check(val[a[1]]))return printf("POSSIBLE\n"),0;
	fo(i,0,n)ext[i]=0;
	for(int y=lef[a[1]];y;y=rig[y])ext[val[y]]=1;
	ext[val[a[1]]]=1;
	int key;
	fo(i,0,n)
	if (!ext[i]){key=i;break;}
	if (check(key))return printf("POSSIBLE\n"),0;
	printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 4480
void main(){
	string s = readln().chomp();
	if(s.count('a') == 1 && s.count('b') == 1 && s.count('c') == 1){
		writeln("Yes");
	}else{
		writeln("No");
	}
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
     
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


Measured memory_bytes: 2596
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef long long LL;
const int maxN = 1e5+100;
int N,j;
LL A[maxN],B[maxN],C[maxN],f[maxN],g[maxN];
int main(){
	scanf("%d",&N);
	for (int i=1;i<=N;i++) scanf("%lld",&A[i]);
	for (int i=1;i<=N;i++) scanf("%lld",&B[i]);
	for (int i=1;i<=N;i++) scanf("%lld",&C[i]);
	sort(A+1,A+1+N);
	sort(B+1,B+1+N);
	sort(C+1,C+1+N);
	f[0] = 0;
	j = 1;
	for (int i=1;i<=N;i++){
		while (j<=N && A[j] < B[i]) j++;
		f[i] = f[i-1] + j-1;
	}
	
	g[0] = 0;
	j = 1;
	for (int i=1;i<=N;i++){
		while (j<=N && B[j] < C[i]) j++;
		g[i] = g[i-1] + f[j-1];
	}
	printf("%lld\n",g[N]);
	return 0;
}

Measured memory_bytes: 4096
<?php
  list($n,$k) = explode(" ", trim(fgets(STDIN)));

  $x=[];
  for ($i=0; $i<$n; $i++) {
    list($a,$b) = explode(" ", trim(fgets(STDIN)));
    if(!isset($x[$a])) $x[$a]=0;
    $x[$a]+=$b;
  }
  ksort($x);

  $sum=0;
  foreach($x as $K => $V){
    $sum+=$V;
//    echo $sum." ".$V." ".$K.PHP_EOL;
    if($k <= $sum){
      echo $K;
      exit;
    }
  }

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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int a,b,c,d;
    while(cin >> a >> b >> c >> d)
        cout << min(a,b) + min(c,d) << '\n';
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace B___1_21
{
    class Program
    {
        static void Main(string[] args)
        {
            var a_b = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = a_b[0];
            var b = a_b[1];

            var ab = Math.Sqrt(int.Parse("" + a + b));

            Console.WriteLine(ab == Math.Floor(ab) ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13396
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] cnt = new int[1000];
		for(int i=2;i<=n;i++){
			int a = i, d = 2;
			while(a>1){
				if(a%d==0){
					cnt[d]++;
					a/=d;
				}
				else{
					d++;
				}
			}
		}
		
		long ans = 1;
		for(int i=2;i<cnt.length;i++){
			if(cnt[i]>0){
				ans*=(cnt[i]+1);
				ans%=1000000007;
			}
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

int main() {
  string s; cin >> s;
  ll N = s.size();
  ll a[100001];
  ll ab[100001];
  ll abc[100001];
  ll tot[100001];
  a[0] = 0; ab[0] = 0; abc[0] = 0; tot[0] = 1;
  
  for (ll i = 1; i <= 1e5; i++) {
    if (s[i-1] == 'A') {
      a[i] = (a[i-1]+tot[i-1])%mod;
      ab[i] = ab[i-1];
      abc[i] = abc[i-1];
      tot[i] = tot[i-1];
    }
    if (s[i-1] == 'B') {
      a[i] = a[i-1];
      ab[i] = (a[i-1]+ab[i-1])%mod;
      abc[i] = abc[i-1];
      tot[i] = tot[i-1];
    }
    if (s[i-1] == 'C') {
      a[i] = a[i-1];
      ab[i] = ab[i-1];
      abc[i] = (ab[i-1]+abc[i-1])%mod;
      tot[i] = tot[i-1];
    }
    if (s[i-1] == '?') {
      a[i] = (3*a[i-1]%mod+tot[i-1])%mod;
      ab[i] = (3*ab[i-1]%mod+a[i-1])%mod;
      abc[i] = (3*abc[i-1]%mod+ab[i-1])%mod;
      tot[i] = tot[i-1]*3%mod;
    }
  }
  cout << abc[N] << endl;
}

Measured memory_bytes: 3584
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

map<string, int> f(string s, int& i) {
	map<string, int> m;
	for (;;) {
		map<string, int> _m;
		if (s[i] == '(') {
			i++;
			_m = f(s, i);
		}
		else {
			string t;
			t.push_back(s[i]);
			i++;
			if ('a'<=s[i] && s[i]<='z') {
				t.push_back(s[i]);
				i++;
			}
			_m[t] = 1;
		}
		int z = 0;
		for (; '0'<=s[i] && s[i]<='9'; i++)
			z = z * 10 + (s[i] - '0');
		if (z == 0) z = 1;
		for (auto x: _m) m[x.first] += z * x.second;
		if (s[i] == ')') break;
	}
	i++;
	return m;
}

int main() {
	for (;;) {
		string s; cin >> s;
		if (s == ".") break;
		vector<map<string, int> > vm;
		int l = 0, sign = 1;
		for (;;) {
			int r;
			for (r = l; s[r] != '+' && s[r] != '-' && s[r] != '.'; r++);
			int i = 0;
			map<string, int> m = f(s.substr(l, r - l) + ")", i);
			for (auto& x: m) x.second *= sign;
			vm.push_back(m);
			if (s[r] == '+') l = r + 1;
			if (s[r] == '-') {
				l = r + 2;
				sign = -1;
			}
			if (s[r] == '.') break;
		}
		int M = vm.size();
		vector<string> v;
		for (auto m: vm)
			for (auto x: m)
				v.push_back(x.first);
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());
		int N = v.size();
		vector<vector<ll> > a(N, vector<ll>(M));
		for (int j = 0; j < M; j++)
			for (auto x: vm[j]) {
				int i = lower_bound(v.begin(), v.end(), x.first) - v.begin();
				a[i][j] = x.second;
			}
		int i = 0;
		for (int j = 0; j < M; j++) {
			int k;
			for (k = i; k < N && a[k][j] == 0; k++);
			if (k == N) continue;
			swap(a[i], a[k]);
			for (int k = i + 1; k < N; k++) {
				ll d = gcd(a[i][j], a[k][j]);
				ll x = a[i][j] / d, y = a[k][j] / d;
				for (int _j = j; _j < M; _j++)
					a[k][_j] = x * a[k][_j] - y * a[i][_j];
				d = 0;
				for (int _j = j; _j < M; _j++)
					d = gcd(d, a[k][_j]);
				if (d == 0) continue;
				for (int _j = j; _j < M; _j++)
					a[k][_j] /= d;
			}
			i++;
		}
		vector<int> x(M);
		for (x[M - 1] = 1; ; x[M - 1]++) {
			bool ok = true;
			int i;
			for (i = M - 2; i >= 0; i--) {
				ll sum = 0;
				for (int j = M - 1; j > i; j--)
					sum += a[i][j] * x[j];
				if (sum % a[i][i]) break;
				x[i] = -sum / a[i][i];
				if (x[i] <= 0) break;
			}
			if (i == -1) break;
		}
		for (int j = 0; j < M; j++)
			cout << x[j] << (j + 1 < M ? ' ' : '\n');
	}
}

Measured memory_bytes: 3220
#include<cstdio>
#include<algorithm>
#define N 100010
using namespace std;
 
int n,a[N];
 
int getmin(){
  int mn=1e9;
  for(int i=1;i<=n;i++) mn=min(mn,a[i]);
  return mn;
}
 
int getmax(){
  int mx=0;
  for(int i=1;i<=n;i++) mx=max(mx,a[i]);
  return mx;
}
 
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++) scanf("%d",a+i);
  int mn=getmin(),mx=getmax();
  if(mx-mn>1){
    printf("No\n");
    return 0;
  }
  if(mx==mn){
    if((mx==n-1)||(2*mx<=n)){
      printf("Yes\n");
      return 0;
    }else{
      printf("No\n");
      return 0;
    }
  }
  int s=0;
  for(int i=1;i<=n;i++) if(a[i]==mn) s++;
  if(s>=mx){
    printf("No\n");
    return 0;
  }
  if((mx-s)*2+s>n){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

const ll INF = 1<<30;
const ll LINF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void) {
    string s, t;
    int cnt = 0;
    cin >> s >> t;
    REP(i, s.size()) if (s[i] != t[i]) cnt++;
    cout << cnt << endl;
}

Measured memory_bytes: 3916
import collections
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
 
    
    

    
N = rri()
arr = rrm()
a = arr[0]
for i in range(1, N):
    a^=arr[i]
ans = []
for i in range(N):
    ans.append(str(a^arr[i]))
print(" ".join(ans))
    

Measured memory_bytes: 112884
#include<iostream>
#include<vector>

const long long INF = 1e18;

long long arr[405];
long long dp[405][405];
long long partSum[405];

int main(){
    int n;
    std::cin >> n;
    for(int i = 0; i < n; i++){
        std::cin >> arr[i];
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            dp[i][j] = INF;
        }
        dp[i][i] = 0;
    }

    for(int i = 0; i < n; i++){
        partSum[i+1] = arr[i] + partSum[i];
    }

    for(int i = n-1; i >= 0; i--){
        for(int j = i + 1; j < n; j++){
            for(int k = i; k < j; k++){
                dp[i][j] = std::min(dp[i][j], (dp[i][k] + dp[k+1][j]) + partSum[j+1] - partSum[i]);
            }
        }
    }

    std::cout<<dp[0][n-1];
    return 0;
}

Measured memory_bytes: 1536
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            # 経路圧縮
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def same(self, x, y):
        return self.find(x) == self.find(y)

N,M = map(int,input().split())
p = list(map(int,input().split()))
uf = UnionFind(N)
count = 0

for i in range(M):
    x,y = map(int, input().split())
    uf.union(x-1, y-1)

for i in range(N):
    if uf.same(i, p[i]-1):
        count += 1

print(count)

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

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

    int ans = 0;
    rep(i, n-2) {
        if (s.substr(i, 3) == "ABC") ++ans;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long LL;
LL my_max(LL a,LL b)
{
    return a>b ? a:b;
}
int main()
{
    LL N,M;
    scanf("%lld %lld",&N,&M);
    LL sum=0;
    for(LL i=M+1;i<=N;i++)
    {
        LL a=my_max(0,N%i-M+1);
        LL now=N-N%i;
        now/=i;
        sum+=(i-M)*now;
        sum+=a;
    }
    if(M==0)
        sum-=N;
    printf("%lld\n",sum);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

template <class T> struct FenwickTree {

    vector < T > node;
    FenwickTree (int n) : node(n, 0) {}

    void add(int idx, T val) {
        for (int i = idx; i < node.size(); i |= i + 1) {
            node[i] += val;
        }
    }

    void update(int idx, T val) {
        add(idx, -sum(idx, idx + 1));
        add(idx, val);
    }

    T sum(int idx) {
        T ret = 0;
        for (int i = idx - 1; i >= 0; i = (i & (i + 1)) - 1) {
            ret += node[i];
        }
        return ret;
    }

    T sum(int l, int r) {
        if (l < 0) l = 0;
        if (r < 0) r = 0;
        return sum(r) - sum(l);
    }

};

ll MOD = 998244353LL;

int main ()
{
    ll N,K;
    cin >> N >> K;
    vector<ll> L(K),R(K);
    REP(i,K) cin >> L[i] >> R[i];

    FenwickTree<ll> inst(200010);
    inst.add(1, 1);

    for (ll i = 2; i <= N; i++) {
        REP(j,K) {
            ll b = i - R[j];
            ll e = i - L[j] + 1;
            inst.add(i, inst.sum(b, e));
            inst.update(i, inst.sum(i, i + 1) % MOD);
        }
    }

    cout << inst.sum(N, N + 1) % MOD << endl;

    return 0;
}


Measured memory_bytes: 4844
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

T = S()

revT = reversed(T)

n, d, mods = 0, 1, [1]+[0]*2019

for i in revT:
    n = (n + int(i)*d)%2019
    d = d*10%2019
    mods[n] += 1

sum = 0
for j in mods:
    sum += j*(j-1)//2

print(sum)

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

using namespace std;

int main() {
	int n, x;
	multiset<int> stick;

	scanf("%d", &n);

	while (n--) {
		scanf("%d", &x);

		stick.insert(x);
	}

	long long a = 0, b = 0;

	while ( (a==0 || b==0) && !stick.empty()) {
		int next = *(stick.rbegin());

		stick.erase(stick.find(next));
		if (stick.find(next) != stick.end()) {
			if (!a) 
				a = next;
			else
				b = next;
			stick.erase(stick.find(next));
		}
	}

	printf("%lld\n", a*b);


	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#define ll long long int
using namespace std;
ll stock[90];

int main() {
	ll N, buy_num = 0, st_num = 0, money = 1000;
	cin >> N ;
	for (int i = 0; i < N; i++){
		cin >> stock[i];
	}
	for (int i = 0; i < N; i++){
		if (stock[i+1] > stock[i]){
			st_num += money / stock[i];
			buy_num = money / stock[i];
			money = money - buy_num*stock[i];
		}
		else if (stock[i+1] < stock[i]){
			money += st_num*stock[i];
			st_num = 0;
		}
	}
	if (st_num > 0){
		money += st_num*stock[N-1];
		st_num = 0;
	}

	cout << money << endl;
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    int h, w, n;
    V hw;
    cin >> h >> w >> n;
    REP(i, n)
    {
        int a;
        cin >> a;

        REP(j, a)
        {
            hw.push_back(i + 1);
        }
    }

    int d = 0; //0:-> 1:<-
    REP(i, h)
    {
        REP(j, w)
        {
            if (i % 2 == 0)
                cout << hw[i * w + j];
            else
                cout << hw[(i + 1) * w - 1 - j];

            if (j == w - 1)
                cout << endl;
            else
                cout << " ";
        }
    }

    return 0;
}

Measured memory_bytes: 384
#from sympy import *

def prime(x):
    i = x
    while True:
        f = False
        j = 2
        while i > j:
            if i % j == 0:
                f = True
                break
            j += 1
        if f == False:
            break
        i += 1
    return i


n = int(input())
l = list()
a = 6
i = 0
while i < n:
    a = prime(a+1)
    if a % 5 != 1:
        continue 
    l.append(a)
    i += 1

print(' '.join(map(str, l)))

Measured memory_bytes: 3060
# code-festival-2017-qualaC - Palindromic Matrix
from collections import Counter


def main():
    H, W, *A = open(0).read().split()
    H, W = int(H), int(W)
    single = H & W & 1
    double = (H >> 1 if W & 1 else 0) + (W >> 1 if H & 1 else 0)
    C_mod4 = [i % 4 for i in Counter("".join(A)).values()]
    flg = C_mod4.count(1) + C_mod4.count(3) <= single and C_mod4.count(2) <= double
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3444
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[N];
		int[][] BC = new int[M][2];
		for(int i = 0; i < N; i++)
			A[i] = sc.nextInt();
		Arrays.sort(A);
		for(int i = 0; i < M; i++) {
			BC[i][0] = sc.nextInt();
			BC[i][1] = sc.nextInt();
		}
		Arrays.sort(BC, (x,y) -> y[1]-x[1]);
		int num = 0;
		long ans = 0;
		int s = N-1, t = 0;
		while(true) {
			if(t < M) {					
				if(A[s] >= BC[t][1]) {
					ans += A[s];
					num++;
					s--;				
				}
				else {
					if(num + BC[t][0] <= N) {
						ans += (long)BC[t][1] * BC[t][0];
						num += BC[t][0];
						t++;
					}
					else {
						ans += (long)BC[t][1] * (N - num);
						num = N;
					}
				}
			}
			else {
				ans += A[s];
				num++;
				s--;
			}
			if(num >= N)
				break;
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 99448
import java.util.Scanner; 
  
//Blood Groups 
public class Main{ 
  
    public static void main(String[] args) { 
        Scanner sc = new Scanner(System.in); 
        int[] c = new int[4]; 
        while(sc.hasNext()){ 
            String b = sc.next().split(",")[1]; 
            if(b.equals("A"))c[0]++; 
            else if(b.equals("B"))c[1]++; 
            else if(b.equals("AB"))c[2]++; 
            else c[3]++; 
        } 
        for(int i=0;i<4;i++)System.out.println(c[i]); 
    } 
}

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

using namespace std;

#define MAX_CON 100010

vector<int> adj[MAX_CON];
int colors[MAX_CON][11] = {};

void color(int v, int d, int c)
{
    if(colors[v][d]) return;

    colors[v][d] = c;

    if(d == 0) return;

    color(v, d - 1, c);
    for(auto u : adj[v])
    {
        color(u, d - 1, c);
    }
}

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

    int a, b;
    for(int i = 0; i < m; i++)
    {
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    int q;
    cin >> q;

    int v[q], d[q], c[q];

    for(int i = 0; i < q; i++)
    {
        cin >> v[i] >> d[i] >> c[i];
    }

    for(int i = q - 1; i >= 0; i--)
    {
        color(v[i], d[i], c[i]);
    }

    for(int i = 1; i <= n; i++)
    {
        cout << colors[i][0] << "\n";
    }
    return 0;
}


Measured memory_bytes: 12024
#include<stdio.h>

int main(void){
	int N,i,min=101;
	int s[100];
	int point=0;
	
	scanf("%d",&N);
	
	i=0;
	
	while(i<N){
		scanf("%d",&s[i]);
		if(s[i]%10!=0 && min>s[i]){
			min=s[i];
		}
		i++;
	}       
	
	for(i=0;i<N;i++){
		point+=s[i];
	}
	
	if(point%10!=0){
		printf("%d\n",point);
	}else if(min!=101){
		printf("%d\n",point-min);
	}else{
		printf("0\n");
	}
	
	return 0;
}


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  
  if (abs(a - b) == c || a + b == c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=6005;
int n,dp[N][N],a[N],mx[N],m,ans,zh;
void upd(int x,int y,int v)
{
	dp[x][y]=max(dp[x][y],v);
	dp[y][x]=max(dp[y][x],v);
	mx[x]=max(mx[x],v);
	mx[y]=max(mx[y],v);
	m=max(m,v);
}
vector<tuple<int,int,int>>q;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n*3;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		mx[i]=-1e9;
		for(int j=1;j<=n;j++)
			dp[i][j]=-1e9;
	}	
	upd(a[1],a[2],0);
	for(int i=3;i+3<=n*3;i+=3)
	{
		sort(a+i,a+i+3);
		q.clear();
		if(a[i]==a[i+2])
		{
			zh++;
			continue;
		}
		if(a[i]==a[i+1])
			for(int j=1;j<=n;j++)
				q.emplace_back(j,a[i+2],dp[a[i]][j]+1);
		if(a[i+1]==a[i+2])
			for(int j=1;j<=n;j++)
				q.emplace_back(j,a[i],dp[a[i+1]][j]+1);
		for(int j=i;j<i+3;j++)
		{
			q.emplace_back(j==i?a[i+1]:a[i],j==i+2?a[i+1]:a[i+2],dp[a[j]][a[j]]+1);
			q.emplace_back(j==i?a[i+1]:a[i],j==i+2?a[i+1]:a[i+2],m);
		}
		for(int j=1;j<=n;j++)
			for(int k=i;k<i+3;k++)
				q.emplace_back(j,a[k],mx[j]);
		for(auto &j:q)
		{
			int x,y,v;
			tie(x,y,v)=j;
			upd(x,y,v);
		}
	}
	dp[a[n*3]][a[n*3]]++;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			ans=max(ans,dp[i][j]);
	printf("%d\n",ans+zh);
	return 0;
}

Measured memory_bytes: 27572
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int n,sum=0;
	cin>>n;
	vector<int>a(n),b(n),c(n-1);
	rep(i,n)cin>>a.at(i);
	rep(i,n)a.at(i)--;
	rep(i,n)cin>>b.at(i);
	rep(i,n-1)cin>>c.at(i);
	rep(i,n){
		sum+=b.at(a.at(i));
		if(a.at(i)==n-1||i==n-1)continue;
		if(a.at(i+1)==a.at(i)+1)sum+=c.at(a.at(i));
	}
	dump("test");
	cout<<sum<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int[] pqr = new int[3];
      	for(int i = 0; i < 3; i++){
        	pqr[i] = sc.nextInt();
        }
		Arrays.sort(pqr);
      	System.out.println(pqr[0]+pqr[1]);
    }
}

Measured memory_bytes: 35632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-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;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<vector<int>> a(n,vector<int>(n));
	rep(i,n)rep(j,n) cin>>a[i][j];
	vector<mint> dp(1<<n,0);
	dp[0]=1;
	rep(S,1<<n){
		int cnt=0;
		rep(i,n){
			if(S & (1<<i)) cnt++;
		}
		int now=0;
		if(cnt==n) break;
		rep(j,n){
			if(a[cnt][j]){
				if(!(S & (1<<j))){
					dp[S|(1<<j)]+=dp[S];
				}
			}
		}
	}
	cout<<dp[(1<<n)-1].x<<endl;
}

Measured memory_bytes: 16640
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    int a,b;
    scanf("%d %d",&a,&b);
    if((a+b)%2) printf("IMPOSSIBLE");
    else printf("%d",(a+b)/2);
    return 0;

}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

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

//const MAX:usize = 100006;

fn main() {
    let n:u32 = read();

    for x in 1..10 {
        for y in 1..10 {
            if x*y == n {
                println!("Yes");
                return ();
            }
        }
    }

    println!("No");

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
struct S {
	long index, num;
};

int main(int, char**)
{
	long N;
	cin >> N;
	vector<S> s(N);
	for (long i = 0; i < N; ++i)
	{
		long a;
		cin >> a;
		s[i].index = i;
		s[i].num = a;
	}
	sort(s.begin(), s.end(), [](S l, S r) { return l.num < r.num; });
	for (long i = 0; i < N; ++i)
	{
		cout << s[i].index + 1;
		if (i == N - 1)
		{
			cout << endl;
		}
		else
		{
			cout << " ";
		}
	}
	return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
    int k,s,z;
    cin >>  k >> s;
    int ans = 0;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            z = s-i-j;
            if(z>=0 && z<=k){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
a,b,c,d=map(int,input().split())

if c!=d:
    
    
    sma=min(c,d)
    big=max(c,d)
    
    while sma!=0 :
        cal=big%sma
        big=sma
        sma=cal
    
    euc=big
    ggg=c*d//euc
    
    #print(euc,ggg)
    
    def  cnt(n,ggg,c,d):
        exc=ggg//c + ggg//d
        if c<ggg or d<ggg:
            exc-=1
        ret=exc*(n//ggg)
        #print(ggg,exc,ret)
        remain=n%ggg
        ret+= remain//c + remain//d
        return ret
    
    #print(cnt(b,ggg,c,d))
    #print(cnt(a-1,ggg,c,d))
    
    jog=cnt(b,ggg,c,d)-cnt(a-1,ggg,c,d)
    
    ans=(b-a+1)-jog
    
    print(ans)
    
else:
    jog=(b//c) -((a-1)//c)
    print(b-a+1-jog)    

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

using namespace std;


const int N=200002;

vector<int>g[N];

int main() {
   int n,m;
   cin>>n>>m;
   for(int i=0;i<m;i++) {
      int u,v;
      cin>>u>>v;
      g[u].push_back(v);
      g[v].push_back(u);
   }

   vector<int>v;
   for(int i=0;i<g[1].size();i++) {
      v.push_back(g[1][i]);
   }

   for(int i=0;i<v.size();i++) {
      int node=v[i];
      for(int j=0;j<g[node].size();j++) {
         int nxt=g[node][j];
         if(nxt==n) {
            cout<<"POSSIBLE\n";
            return 0;
         }
      }
   }

   cout<<"IMPOSSIBLE\n";

   return 0;
}


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

typedef unsigned long long ull;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int A,B,K;	cin>>K>>A>>B;
	FOR(i,A,B+1){
		if(i%K==0){
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;

    return 0;
}



Measured memory_bytes: 3648
using System;
using System.Collections;
using System.Collections.Generic;

class Program {
    static void Main (string[] args) {
        long N = long.Parse (Console.ReadLine ());
        string[] strtemp1 = Console.ReadLine ().Split (' ');
        var numarray = new long[100001];
        for (long i = 0; i < N; i++) {
            numarray[long.Parse (strtemp1[i])]++;
        }
        long Q = long.Parse (Console.ReadLine ());
        var Barray = new long[Q];
        var Carray = new long[Q];
        for (long i = 0; i < Q; i++) {
            var tmp = Console.ReadLine ().Split (' ');
            Barray[i] = long.Parse (tmp[0]);
            Carray[i] = long.Parse (tmp[1]);
        }

        long sum = 0;
        for (long i = 0; i < 100001; i++) {
            sum += (long) i * (long) numarray[i];
        }
        for (long i = 0; i < Q; i++) {
            sum -= (long) Barray[i] * (long) numarray[Barray[i]];
            sum += (long) Carray[i] * (long) numarray[Barray[i]];
            numarray[Carray[i]] += numarray[Barray[i]];
            numarray[Barray[i]] = 0;
            Console.WriteLine (sum);
        }
    }
}

//dotnet run --project test

Measured memory_bytes: 44584
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>

using namespace std;

vector<vector<int>> c(3,vector<int>(3));

int main(int argc, const char * argv[]) {

  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> c[i][j];
    }
  }
  
  for(int i = 0; i < 3; i++){
    int m = 999;
    for(int j = 0; j < 3; j++){
      m = min(m, c[i][j]);
    }
    for(int j = 0; j < 3; j++){
      c[i][j] -= m;
    }
  }

  for(int i = 0; i < 3; i++){
    int m = 999;
    for(int j = 0; j < 3; j++){
      m = min(m, c[j][i]);
    }
    for(int j = 0; j < 3; j++){
      c[j][i] -= m;
    }
  }

  int sum = 0;
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      sum += c[i][j];
    }
  }
  if(sum != 0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }

  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[] input = new int [5];
	    for(int i = 0; i < input.length; i++) {
	    	input[i] = sc.nextInt();
	    }
	    int k = sc.nextInt();
	    
	    boolean cantComm = false;
	    for( int i = 0; i < input.length-1; i++) {
	    	for( int j = i; j < input.length; j++ ) {
	    		if( k < (input[j] - input[i]) ) {
	    			cantComm = true;
	    			break;
	    		}
	    	}
	    }
	    
	    if( cantComm ) {
	    	System.out.println(":(");
	    } else {
	    	System.out.println("Yay!");
	    }
		sc.close();
	}
}

Measured memory_bytes: 23124
N=gets.to_i
V=gets.split.map(&:to_i)
odd = V.each_slice(2).map(&:first).group_by(&:itself).map{ |k,v| [k,v.count] }.to_h
even = V.each_slice(2).map(&:last).group_by(&:itself).map{ |k,v| [k,v.count] }.to_h

orank = []
erank = []
odd.sort_by{|_,v|v}.reverse.each { |k,_| orank << k }
even.sort_by{|_,v|v}.reverse.each { |k,_| erank << k }

ans=0
o = orank[0]
e = erank[0]
if orank.size == 1 && erank.size == 1
    ans = o == e ? N/2 : 0
else
    if orank.size == 1
        e = erank[1] if o == e
    elsif erank.size == 1
        o = orank[1] if o == e
    else
        if o == e
            o2 = orank[1]
            e2 = erank[1]
            if odd[o] + even[e2] < odd[o2] + even[e]
                o = o2
            else
                e = e2
            end
        end
    end
    ans = N - odd[o] - even[e]
end

p ans


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

#define ll long long
#define pb push_back

using namespace std;

int main()
{
    ll n, i, j, a, b, k, d;
    string s;
    //set <pair <ll, ll> > s;

    cin >> n >> k;
    bool X[n] ={0};

    while(k--)
    {
        cin >> d;
        while(d--)
        {
            cin >> a;
            X[--a] = 1;
        }
    }



    cout << count(X, X + n, 0) << '\n';

    return 0;
}



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

int main() {
  int D, N;
  cin >> D >> N;
  int ans = 1;
  for (int i = 0; i < D; i++)
    ans *= 100;
  if (N != 100)
    ans *= N;
  else if (N = 100)
    ans *= ++N;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

x, y, a, b, c = map(int, input().split(' '))
p = list(map(int, input().split(' ')))
q = list(map(int, input().split(' ')))
r = list(map(int, input().split(' ')))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

#print(p, q, r)

#print(p[:x])
#print(q[:y])

merge_list = []
merge_list.extend(p[:x])
merge_list.extend(q[:y])
merge_list.extend(r)

merge_list.sort(reverse=True)

# print(merge_list)
print(sum(merge_list[:x + y]))


Measured memory_bytes: 23328
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define frst first
#define sec second
#define fast cin.tie(0) , ios_base :: sync_with_stdio(0)
#define db double
#define mod 1000000007
void online_judge()
{
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}


ll dp[200001];

ll dfs(vector<ll> g[] , ll strt , bool* vis)
{
	vis[strt] = 1;
	ll ans = 1;
	for (auto x : g[strt])
	{
		if (!vis[x]) {
			ans = max(ans , 1 + dfs(g , x , vis));
		}
		else {
			ans = max(ans , 1 + dp[x]);
		}
	}
	///cout << ans << " ";
	return dp[strt] = ans;
}

void go() {
	ll n , m;
	cin >> n >> m;
	vector<ll> g[n + 1];
	for (int i = 0; i < m; ++i)
	{
		ll x , y;
		cin >> x >> y;
		g[x].pb(y);
	}
	bool* vis = new bool[n + 1]();
	memset(dp , 0 , sizeof dp);
	for (int i = 1; i <= n; ++i)
	{
		if (!vis[i]) {
			dfs(g , i , vis);
		}
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i)ans = max(ans , dp[i] - 1);
	cout << ans ;
}


int main() {
	fast;
	///();
	//cout << 2332;
	go();
}

Measured memory_bytes: 10112
def solve(A, BC):
    remain = len(A)
    A = sorted(A, reverse=True)
    A.append(0)
    BC = sorted(((c, b) for b, c in BC), reverse=True)
    BC.append((0, 0))

    aIter = iter(A) 
    bcIter = iter(BC)

    a = next(aIter)
    c, b = next(bcIter)

    result = 0
    while remain > 0:
        if a > c:
            result += a
            remain -= 1
            a = next(aIter)
        elif b < remain:
            result += c * b
            remain -= b
            c, b = next(bcIter)
        else:
            result += c * remain
            break 
    return result

N, M = [int(x) for x in input().split()]
# N, M <= 10 ** 5

A = [int(x) for x in input().split()]
BC = []
for i in range(M):
    bc = tuple(int(x) for x in input().split())
    BC.append(bc)
got = solve(A, BC)
print(got)




Measured memory_bytes: 28872
main = interact $ unlines . map (show' . pablo_squarson) . read' . lines
 where
  read' ("0":_) = []
  read' (m:xs) = map (map read . words) ps : read' xs'
   where (ps,xs') = splitAt (read m - 1) xs
  show' (x,y) = show x ++ " " ++ show y

pablo_squarson ps = pos [(1,1)] ps
 where
  pos acc [] = (maximum fs - minimum fs + 1, maximum ss - minimum ss + 1)
   where (fs,ss) = (map fst acc, map snd acc)
  pos acc ([n,d]:ps') = pos (acc++[(x,y)]) ps'
   where
    (x,y) = add d (acc!!n)
    add d (x,y) = case d of {0->(x-1,y); 1->(x,y+1); 2->(x+1,y); 3->(x,y-1)}

Measured memory_bytes: 6048
int main()
{
    int a,c=0;
    char b[50];
    scanf("%d",&a);getchar();
    for(int i=0;i<a;i++)
    scanf("%c",&b[i]);
    for(int i=0;i<=a;i++)
    {if(b[i]=='A' && b[i+1]=='B' && b[i+2]=='C')

        c++;}
        printf("%d",c);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;

int N;
string words[10], substr[10][10], memo[1 << 10][10];

inline string getMin(const string& lhs, const string& rhs)
{
  if (lhs == "")
    return rhs;
  else if (rhs == "")
    return lhs;

  if (lhs.size() == rhs.size()) {
    if (lhs <= rhs)
      return lhs;
    return rhs;
  }

  if (lhs.size() < rhs.size())
    return lhs;
  else
    return rhs;
}

string solve(int S, int v)
{
  if (memo[S][v] != "")
    return memo[S][v];

  if (S == (1 << N)-1)
    return "";

  string ret = "";
  for (int i = 0; i < N; ++i) {
    if (!(S & (1 << i)))
      ret = getMin(ret, substr[v][i]+solve(S | (1 << i), i));
  }
  return memo[S][v] = ret;
}

int main()
{
  while (cin >> N) {
    if (N == 0)
      break;

    // init
    for (int i = 0; i < (1 << N); ++i) {
      for (int j = 0; j < N; ++j)
	memo[i][j] = "";
    }

    for (int i = 0; i < N; ++i)
      cin >> words[i];

    int S = 0;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
	if (i == j)
	  continue;
	substr[i][j] = words[j];
	if (words[i].find(words[j]) != string::npos) {
	  if (!(S & (1 << i)))
	    S |= 1 << j;
	} else {
	  for (unsigned int k = 0; k < words[i].size(); ++k) {
	    string s = words[i].substr(k);
	    string::size_type index = words[j].find(s);
	    if (index == 0) {
	      substr[i][j] = words[j].substr(s.size());
	      break;
	    }
	  }
	}
      }
    }

    string ans = "";
    for (int i = 0; i < N; ++i) {
      if (!(S & (1 << i)))
	ans = getMin(ans, words[i]+solve(S | (1 << i), i));
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include <iostream>
using namespace std;
#define HOUR 3600
#define MINUTE 60

int S, h, m, s;

int main(){

	
	do {
		cin >> S;
	} while (S < 0 || S>86400);

		h = S / HOUR;
		m = ( S - (HOUR * h) ) / MINUTE;
		s = S - ((HOUR * h) + (MINUTE * m));


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




	return 0;
}

Measured memory_bytes: 1164
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define nmax 100001
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}

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

    if(k>((n-1)*(n-2))/2) {
        cout<<-1<<endl;
        return 0;
    }

    vector<vector<ll>> adj(n+1, vector<ll>());
    ll e = 0;
    for(int i=2;i<=n;i++) {
        adj[1].pb(i);
        e++;
    }

    ll diff = (((n-1)*(n-2))/2)-k;
    int i = 2;
    while(diff) {
        for(int j=i+1;j<=n;j++) {
            adj[i].pb(j);
            e++;
            diff--;
            if(diff==0)
                break;
        }
        i++;
    }

    cout<<e<<endl;
    for(int i=1;i<n;i++) {
        for(int j=0;j<adj[i].size();j++)
            cout<<i<<" "<<adj[i][j]<<endl;
    }


    
    return 0;
}




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

int main() {
	int n,ans=0;
	cin>>n;
	if(n>=500){
		ans+=(n/500)*1000+(n%500)/5*5;
	}
	else{
		ans+=(n/5)*5;
	}
	cout<<ans<<endl;
	return 0;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Integer K = input.nextInt();
        Integer N = input.nextInt();
        Integer A[] = new Integer[N];
        Integer distances[] = new Integer[N];
        Integer sumDistance = 0;
        Integer maxDistance = 0;

        for (int i = 0; i < N; i++) {
            A[i] = input.nextInt();
        }
        Arrays.sort(A);

        for (int i = 0; i < N - 1; i++) {
            distances[i+1] = A[i+1] - A[i];
        }
        distances[0] = (K - A[N-1]) + A[0];

        for (Integer distance : distances) {
            sumDistance += distance;
            maxDistance = Math.max(maxDistance, distance);
        }

        System.out.println(sumDistance - maxDistance);
    }
}

Measured memory_bytes: 96280
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define repl(k,n) for(k=0;k<n;++k)

int main() {
	int N, X, T;
	cin >> N >> X >> T;
	int a;
	if (N % X != 0) {
		a = N / X + 1;
	}
	else {
		a = N / X;
	}
	cout << a * T;
	return 0;
}

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

int main()
{
  long long N,Q;
  string S;
  cin>>N>>Q;
  cin>>S;
  vector<int> cnt(N,0);
  long long tmp=0;
  for(int i=1;i<N;i++){
    if(S[i-1]=='A'&&S[i]=='C'){
      tmp+=1;
    }
    cnt[i]=tmp;
  }
  long long r,l;
  for(int i=0;i<Q;i++){
    cin>>l>>r;
    cout<<cnt[r-1]-cnt[l-1]<<endl;
  }
}


Measured memory_bytes: 1408
from itertools import product

N = str(input())
A = int(N[0])
B = int(N[1])
C = int(N[2])
D = int(N[3])

for bit in product([0,1], repeat = 3):
    if bit[0] == 0:
        E = A + B
        op1 = "+"
    else:
        E = A - B
        op1 = "-"
    
    if bit[1] == 0:
        F = E + C
        op2 = "+"
    else:
        F = E - C
        op2 = "-"

    if bit[2] == 0:
        G = F + D
        op3 = "+"
    else:
        G = F - D
        op3 = "-"

    if G == 7:
        ans = str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D)
        ans = ans + "=7"
        print(ans)
        break

Measured memory_bytes: 8952