akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
	int a,b;
  cin >> a >> b;
  int sum = 0;
  for(int i = a; i <= b; i++){
    int s = i % 10;
    int t = i / 10000;
    if(s != t){
      continue;
    }
    int u = i / 10 % 10;
    int w = i / 1000 % 10;
    if(u != w){
      continue;
    }
    else{
      sum = sum + 1;
    }
  }
  cout << sum << endl;
}





Measured memory_bytes: 256
#include <stdio.h>

    int main(void){

    int a, b, c, d;

    scanf( "%d", &a);
    scanf( "%d", &b);
    scanf( "%d", &c);

    d = c + b - a;

    if( d < 0 ){

    printf( "0\n");
    }else{

    printf( "%d\n", d);
    }
        return 0;
    }

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

typedef long long ll;

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

  ll n;
  cin >> n;

  ll x = floor(sqrt(n));

  for (ll i = x; i > 0; i--){
    if (n % i == 0){
      cout << i + (n / i) - 2 << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	long X = sc.nextLong();
	long[] x = new long[N];
	long[] a = new long[N];
	long min = 99999999;
	for(int i = 0; i<N; i++) {
	    x[i] = sc.nextLong();
	    a[i] = Math.abs(x[i] - X);
	    if(a[i] < min) min = a[i];

	}
        if(N == 1) {
            System.out.println(Math.abs(x[0]-X));
            return;
        }
	HashSet<Long> set = new HashSet<Long>();
	set.add((long)1);
	for(long i = 2; i<=min; i++){
	    if(min%i == 0) {
		set.add(i);
	    }
	}
	Long[] coArray = set.toArray(new Long[0]);
	Arrays.sort(coArray, Comparator.reverseOrder());
	for(long c: coArray) {
	    long cnt = 0;
	    for(int i = 0; i<N; i++) {
		if(a[i] % c == 0) {
		    cnt++;
		}
	    }
	    if(cnt==N){
		System.out.println(c);
		return;
	    }
	}

    }
}

Measured memory_bytes: 60500
#include <bits/stdc++.h>
#define ll long long 
#define inf 0x3f3f3f3f
using namespace std;
char check(char ch){
	char t;
	if (ch=='q')t='p';
	if (ch=='d')t='b';
	if (ch=='p')t='q';
	if (ch=='b')t='d';
	return t;
}
char s[393939];
signed main(){
	scanf("%s",s+1);
	int len=strlen(s+1);
	for (int i=1;i<=len;++i){
		char ch1=s[i],ch2=s[len-i+1];
		ch2=check(ch2);
		if (ch1!=ch2){puts("No");return 0;}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())

int main() {
    int n;
    cin >> n;
    vector<int> S(n);
    Rep(i, n) {
        cin >> S[i];
    }
    int q;
    cin >> q;
    vector<int> T(q);
    Rep(i, q) {
        cin >> T[i];
    }
    int ans = 0;
    Rep(i, q) {
        int left = 0, right = n;
        while (left <= right) {
            int center = (left + right) / 2;
            if (S[center] == T[i]) {
                ans++;
                break;
            }
            else if (S[center] > T[i]) {
                right = center - 1;
            }
            else {
                left = center + 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3356
H,W,M = map(int, input().split())
L = [[int(l) for l in input().split()] for _ in range(M)]

hlist = [0]*(H+1)
wlist = [0]*(W+1)
for l in L:
    hlist[l[0]] += 1
    wlist[l[1]] += 1

hmax = max(hlist)
wmax = max(wlist)
h = hlist.count(hmax)
w = wlist.count(wmax)
ans = hmax+wmax-1
cnt = 0
for l in L:
    if hlist[l[0]] == hmax and wlist[l[1]] == wmax:
        cnt += 1

if cnt < h*w:
    ans += 1
print(ans)

Measured memory_bytes: 63716
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	int N,W,H;
	int[] row,col;

	public void solve() {
		N = nextInt();
		W = nextInt();
		H = nextInt();
		row = new int[H + 1];
		col = new int[W + 1];

		for(int i = 0;i < N;i++){
			int x = nextInt();
			int y = nextInt();
			int w = nextInt();

			row[Math.max(0,y - w)]++;
			row[Math.min(H, y + w)]--;

			col[Math.max(0, x - w)]++;
			col[Math.min(W, x + w)]--;
		}

		for(int i = 0;i < H;i++){
			row[i + 1] += row[i];
		}

		for(int i = 0;i < W;i++){
			col[i + 1] += col[i];
		}

		boolean okRow = true;
		boolean okCol = true;
		for(int i = 0;i < H;i++){
			if(row[i] <= 0){
				okRow = false;
				break;
			}
		}

		for(int i = 0;i < W;i++){
			if(col[i] <= 0){
				okCol = false;
				break;
			}
		}
		if(okRow || okCol){
			out.println("Yes");
		}else{
			out.println("No");
		}
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 61208
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll perimeter;
    ll houses;
    cin>>perimeter;
    cin>>houses;
    vector<ll >v(houses+1);
    for(int i=0;i<houses;i++)
        cin>>v[i];
    v[houses]=perimeter+v[0];

    ll answer=0;
    ll largest_distance=INT_MIN;
    for(int i=0;i<houses;i++)
    {
        answer+=abs(v[i]-v[i+1]);
        largest_distance=max(largest_distance,abs(v[i]-v[i+1]));
    }

    cout<<answer-largest_distance<<endl;
    return 0;
}


Measured memory_bytes: 1792
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

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

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    int d = sc.nextInt();

    List<int[]> points = new ArrayList<>(n);

    for (int i = 0; i < n; i++) {
      int[] point = new int[d];
      for (int j = 0; j < d; j++) {
        point[j] = sc.nextInt();
      }
      points.add(point);
    }

    int count = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int sqDist = 0;
        int[] p1 = points.get(i);
        int[] p2 = points.get(j);
        for (int k = 0; k < d; k++) {
          sqDist += (p1[k] - p2[k]) * (p1[k] - p2[k]);
        }
        int dist = (int) Math.sqrt(sqDist);
        if (dist * dist == sqDist) count++;
      }
    }

    os.println(count);
  }
}

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

mod = 10**9+7

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

s = 0
s2 = 0
for a in A:
    s2 = (s2 + a*a) % mod
    s = (s + a) % mod

ans = (s*s - s2) * pow(2, mod-2, mod) % mod
print(ans)

Measured memory_bytes: 31468
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

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

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

//拡張ユークリッドの互除法
//ax + by = cとなるようなc=gcd(a,b)をxをペアにして返す
//firstがx,secondがc
template <typename number>
pair<number, number> extended_euclid(number a, number b)
{
    number r0, r1, a0, a1, b0, b1;
    r0 = a; r1 = b;
    a0 = 1; a1 = 0;
    b0 = 0; b1 = 1;
    while (r1>0) {
        number q1 = r0 / r1;
        number r2 = r0 % r1;
        number a2 = a0 - q1 * a1;
        number b2 = b0 - q1 * b1;
        r0 = r1 ; r1 = r2;
        a0 = a1 ; a1 = a2;
        b0 = b1 ; b1 = b2;
    }
    number c = r0;
    a = a0; //x
    b = b0; //y
    return  {a, c};
}

int main()
{
    ll a, b;
    cin >> a >> b;
    p result = extended_euclid(a, b);
    cout << (a * b) / result.second << endl;
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  int a,b;
  cin>>n>>m>>a>>b;
 
  vector<int>X(n);
  vector<int>Y(m);
  for(int i=0;i<n;i++){
    cin>>X.at(i);
  }
  for(int j=0;j<m;j++){
    cin>>Y.at(j);
  }
  sort(X.begin(),X.end());
  sort(Y.begin(),Y.end());
  
  if(X.at(n-1)<Y.at(0) && a <= X.at(n-1) && b > Y.at(0)){
    cout<<"No War"<<endl;
  }
  else{
    cout<<"War"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e6+100;
inline ll quickpow(ll base,ll ind)
{
	ll ans=1;
	while(ind>0)
	{
		if(ind&1)ans=ans*base%MOD;
		ind>>=1;
		base=base*base%MOD;
	}
	return ans;
}
inline ll inv(ll base)
{
	return quickpow(base,MOD-2);
}
ll fac[maxn],invf[maxn];
inline ll C(int n,int m)
{
//	cout<<n<<" "<<m<<" "<<(fac[n]*1ll*invf[m]%MOD*1ll*invf[n-m]%MOD)<<endl;
	return fac[n]*1ll*invf[m]%MOD*1ll*invf[n-m]%MOD;
}
inline void add(ll &a,ll b)
{
	a+=b;
	if(a>=MOD)a-=MOD;
}
int main()
{
	fac[0]=1;
	for(int i=1;i<maxn;i++)fac[i]=fac[i-1]*1ll*i%MOD;
	invf[maxn-1]=inv(fac[maxn-1]);
	for(int i=maxn-2;i>=0;i--)invf[i]=invf[i+1]*1ll*(i+1)%MOD;
	int r1,c1,r2,c2;
	cin>>r1>>c1>>r2>>c2;
	ll ans=0;
	for(int c=c1;c<=c2;c++)
	{
		add(ans,C(r2+c+1,r2));
		add(ans,MOD-C(r1+c,r1-1));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 31488
// 2020-09-20 15:15:19
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
// #include <atcoder/convolution>
// #include <atcoder/dsu>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
// #include <atcoder/math>
#include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/modint>
// #include <atcoder/scc>
// #include <atcoder/segtree>
// #include <atcoder/string>
// #include <atcoder/twosat>
// #include <atcoder/all>
using namespace atcoder;

// clang-format on
void answer() {
  int h, w;
  cin >> h >> w;
  vector<vector<int> > wall(h, vector<int>(w, 0));
  rep(i, h) {
    string s;
    cin >> s;
    rep(j, w) wall[i][j] = (s[j] == '#');
  }
  mf_graph<int> G(h * w + 2);
  int s = h * w, t = s + 1;
  auto id = [&](int i, int j) { return i * w + j; };
  auto ij = [&](int id_) { return P(id_ / w, id_ % w); };
  int di[] = {0, 1, 0, -1};
  int dj[] = {1, 0, -1, 0};
  rep(i, h) rep(j, w) {
    if (wall[i][j]) continue;
    if ((i + j) % 2) {
      G.add_edge(id(i, j), t, 1);
    } else {
      G.add_edge(s, id(i, j), 1);
    }
    if ((i + j) % 2) continue;
    rep(d, 4) {
      int ni = i + di[d];
      int nj = j + dj[d];
      if (ni < 0 || h <= ni || nj < 0 || w <= nj || wall[ni][nj]) continue;
      G.add_edge(id(i, j), id(ni, nj), 1);
    }
  }
  cout << G.flow(s, t) << '\n';
  vector<vector<char> > ans(h, vector<char>(w, '.'));
  rep(i, h) rep(j, w) if (wall[i][j]) ans[i][j] = '#';
  for (auto edge : G.edges()) {
    if (edge.flow == 0) continue;
    int fi = edge.from / w, fj = edge.from % w;
    int ti = edge.to / w, tj = edge.to % w;
    if (id(fi, fj) == s) continue;
    if (id(ti, tj) == t) continue;
    if (fi == ti) {
      if (fj < tj) {
        ans[fi][fj] = '>';
        ans[ti][tj] = '<';
      } else {
        ans[fi][fj] = '<';
        ans[ti][tj] = '>';
      }
    } else {
      if (fi < ti) {
        ans[fi][fj] = 'v';
        ans[ti][tj] = '^';
      } else {
        ans[fi][fj] = '^';
        ans[ti][tj] = 'v';
      }
    }
  }
  for (auto i : ans) {
    for (auto j : i) cout << j;
    cout << '\n';
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 5592
from collections import deque

N = int(input())

S = []



for i in range(N):

    s = input()
    S.append(s)


"""
lis = [float("inf")] * N
lis[0] = 0
q = deque([])

q.append(0)

#print (S,lis)

while len(q) > 0:

    now = q.pop()

    for i in range(N):

        #print (i,now)
        if S[now][i] == "1" and lis[i] > lis[now] + 1:
            lis[i] = lis[now] + 1
            q.append(i)

mind = 0
#print (lis)

for i in lis:
    if lis[mind] < lis[i]:
        mind = i

"""
ans = 0

for mind in range(N):


    lis = [float("inf")] * N
    lis[mind] = 0
    q = deque([])
    q.append(mind)

    #print (q,len(q),lis)

    while len(q) > 0:

        now = q.pop()
        #print (now)
    

        for i in range(N):

            if S[now][i] == "1" and lis[i] > lis[now] + 1:

                lis[i] = lis[now] + 1
                q.append(i)

    ans = max(ans,max(lis))


mind = 0
nlis = [None] * N
nlis[mind] = 0
q = deque([])
q.append(mind)
flag = True

while len(q) > 0:

    now = q.pop()  

    for i in range(N):

        if S[now][i] == "1" and nlis[i] == None:
   
            nlis[i] = nlis[now] ^ 1
            q.append(i)

        elif S[now][i] == "1" and nlis[now] == nlis[i]:
            flag = False
            break

    if not flag:
        break

if flag:
    print (ans + 1)

else:
    print (-1)
        



Measured memory_bytes: 44452
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

n,k = m()

a = l()
dp = [0 for i in range(n)]
ans = [0 for i in range(n)]
for i in range(min(50,k)):
	for j in range(n):
		po = a[j]
		if j - po < 0:
			dp[0] += 1
		else:
			dp[j-po] += 1
		if j + po + 1 <= n-1:
			dp[j+po+1] -= 1
	a[0] = dp[0]
	for j in range(1,n):
		dp[j] += dp[j-1]
		a[j] = dp[j]
	for j in range(n):
		dp[j] = 0

if k <= 50:
	print(jo(a))
	exit()

for j in range(n):
	a[j] += k-51

for j in range(n):
	po = a[j]
	if j - po < 0:
		ans[0] += 1
	else:
		ans[j-po] += 1
	if j + po + 1 <= n-1:
		ans[j+po+1] -= 1
for j in range(1,n):
	ans[j] += ans[j-1]
print(jo(ans))






Measured memory_bytes: 109516
/**/
#include<bits/stdc++.h>
using namespace std;
long long a,b,c;
int main(){
	ios::sync_with_stdio(false);
	cin>>a>>b;
	for(int i=a;i<=b;i++){
		if(i==0){
			cout<<"Zero"<<endl;
			return 0;
		}
		if(i<0){
			c++;
		}
	}
	if(c%2==0){
		cout<<"Positive"<<endl;
	}else{
		cout<<"Negative"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
ans = 0
 
def dfs(s, n):
    global ans

    if s != "" and int(s) > n:
        return
    elif "3" in s and "5" in s and "7" in s:
        ans += 1

    for i in "753":
        dfs(s+i, n)

n = int(input())
dfs("", n)
print (ans)



Measured memory_bytes: 2940
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll x=0,y=0;
  string s;
  set<char> st;
  cin >> s;
  for(char c:s){
    st.insert(c);
  }
  bool can = true,fw,fs,fn,fe;
  fw = st.find('W') != st.end();
  fn = st.find('N') != st.end();
  fs = st.find('S') != st.end();
  fe = st.find('E') != st.end();

  if(fw^fe) can = false;
  if(fn^fs) can = false;
  if(can) cout <<"Yes\n";
  else cout <<"No\n";
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=list(map(int,input().split()))
d=[]
ans=0
for i in range(n):
  d.append([a[i],1])
for i in range(m):
  b,c=map(int,input().split())
  d.append([c,b])
d.sort(reverse=True)
for i in range(n+m):
  if n==0:
    break
  ans+=d[i][0]*min(n,d[i][1])
  n-=min(n,d[i][1])
print(ans)

Measured memory_bytes: 104816
r, c = gets.split.map(&:to_i)

maze = Array.new(r){ Array.new(c) }
queue = []
(0..r-1).each do |rr|
  gets.chomp.each_char.each_with_index { |c, cc|
    if c == '#'
      maze[rr][cc] = 0
      queue << [rr, cc]
    end
  }
end

cnt = nil
until queue.empty?
  qx, qy = queue.shift
  cnt = maze[qx][qy].to_i + 1

  if qx + 1 < r && maze[qx+1][qy].nil?
    maze[qx+1][qy] = cnt
    queue << [qx+1, qy]
  end

  if qx > 0 && maze[qx-1][qy].nil?
    maze[qx-1][qy] = cnt
    queue << [qx-1, qy]
  end

  if qy + 1 < c && maze[qx][qy+1].nil?
    maze[qx][qy+1] = cnt
    queue << [qx, qy+1]
  end

  if qy > 0 && maze[qx][qy-1].nil?
    maze[qx][qy-1] = cnt
    queue << [qx, qy-1]
  end
end

p cnt - 1


Measured memory_bytes: 87292
import java.util.Scanner;
 
public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i < n; ++i) {
            int number = scanner.nextInt();
            if (number % 2 == 0 && ((number % 5 != 0) && (number % 3 != 0))) {
                System.out.println("DENIED");
                return;
            }
        }
        System.out.println("APPROVED");
    }
}

Measured memory_bytes: 23252
import java.util.*;

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

        int K = sc.nextInt();
        int S = sc.nextInt();
        int[] sMinusZ = new int[K + 1];
        for (int i=0; i<=K; i++) {
            sMinusZ[i] = S - i;
        }
        Arrays.sort(sMinusZ);

        int sum = 0;
        for (int i=0; i<=K; i++) {
            for (int j=0; j<=K; j++) {
                if (Arrays.binarySearch(sMinusZ, i+j) >= 0) {
                    sum++;
                }
            }
        }

        System.out.println(sum);
    }
}



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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> V[n];
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        V[a].push_back(b);
        V[b].push_back(a);
    }

    int d[n];
    rep(i,n) d[i] = -1;
    queue<int> Q;
    Q.push(0);

    while(!Q.empty()) {
        int x = Q.front(); Q.pop();
        for (auto ch : V[x]) {
            if (d[ch] == -1) {
                d[ch] = x;
                Q.push(ch);
            }
        }
    }

    cout << "Yes" << endl;
    for (int i=1; i<n; i++) {
        cout << d[i]+1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 10468
import math
n=int(input())
def yakusu(n):
    yaku=[]
    for i in range(1, math.ceil(n**(1/2))+1):
        if n%i==0:
            yaku.append((i, n//i))
    return yaku
yakusu=yakusu(n)
ans=0
for yaku in yakusu:
    if yaku[1]-yaku[0]>=2:
        ans+=(yaku[1]-1)
print(ans)

Measured memory_bytes: 3464
#include <iostream>
#include <string.h>
#include <algorithm>

using namespace std;
int main(void){
    int N,T,A;
    cin>>N>>T>>A;
    int H[N];
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    double tem[N];
    for(int i=0;i<N;i++){
        tem[i]=T-H[i]*0.006;
    }
    double gap;
    double min=100000;
    int ans;
    for(int i=0;i<N;i++){
       if(tem[i]>A) gap=tem[i]-A;
       else gap=A-tem[i];
       if(min>gap) {min=gap; ans=i;} 
    }
    cout<<ans+1;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

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

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <sstream>
#include <utility>
#include <ctime>
#include <cassert>
#include <fstream>
using namespace std;
typedef long long LL;
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 1000000
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';


int main() {

	int r, g, b,k;
	cin>>r>>g>>b;
	cin>>k;

	if(g <= r) {
		while(g <=r) {
			g= g*2; 
			k--;
		}
	
	}

	// cout<<k<<endl;
	// cout<<g <<endl;
	// cout<<b<<endl;
	if(b <=g) {
		while(b <= g) {
			b = b*2;
			k--;
		}
	}

	if(k >=0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3628
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int N,T;
    int[] c,t;
    private void solve() {
        N = nextInt();
        T = nextInt();
        c = new int[N];
        t = new int[N];

        for(int i = 0;i < N;i++) {
            c[i] = nextInt();
            t[i] = nextInt();
        }

        int ans = Integer.MAX_VALUE;
        for(int i = 0;i < N;i++) {
            if (t[i] <= T) {
                ans = Math.min(ans, c[i]);
            }
        }

        if (ans == Integer.MAX_VALUE) {
            out.println("TLE");
            return;
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

long long int answ(long long int x){
  if(x==1) return 1;
  if(x>1) return 2*answ(x/2)+1;
}
int main() {
    long long int n,m;
    cin>>n>>m;
    vector<long long int> a(m);
    rep(i,m) cin>>a[i];
    long long int ans=0;
    rep(i,m) ans+=a[i];
    long long int sum=n-ans;
    if(sum<0) cout<<"-1"<<endl;
    else cout<<sum<<endl;

}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
#define nn 400008
#define ll long long

vector<int> v[nn];
int n,m;int siz[nn];
int tag[nn];ll ans=0;
int sx,sy;

int c0,c1;
void dfs(int x,int p)
{
	tag[x]=-tag[p];
	for(int i=0;i<v[x].size();i++)
	{
		if(v[x][i]!=p and !tag[v[x][i]])
			dfs(v[x][i],x);
		else if(v[x][i]!=p)
			sx=x,sy=v[x][i];
	}
	if(tag[x]<0) c0++;else c1++;
}

int tp[nn];
vector<int> all;int vis[nn];
void solve(int x,int p)
{
	siz[x]=tag[x];vis[x]=1;

	for(int i=0;i<v[x].size();i++)
	{
		if(v[x][i]!=p and !vis[v[x][i]])
		{
			solve(v[x][i],x);
			siz[x]+=siz[v[x][i]],tp[x]+=tp[v[x][i]];
		}
	}

	if(!tp[x]) ans+=abs(siz[x]);
	else if(tp[x]>0) all.push_back(-siz[x]);
	else all.push_back(siz[x]);
}

void sol()
{
	solve(1,0);
	all.push_back(0);sort(all.begin(),all.end());
	int x=all[all.size()/2];
	for(int i=0;i<all.size();i++) 
		ans+=abs(x-all[i]);
		
	printf("%lld\n",ans);
}

#define err {puts("-1");exit(0);}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].push_back(y);v[y].push_back(x);
	}
	tag[0]=1;dfs(1,0);
	if(m==n-1)
	{
		if(c0!=c1) err;sol();
	}
	else
	{
		if(tag[sx]==tag[sy])
		{
			if((c0-c1)%2) err;
			ans=abs(c0-c1)/2;
			tag[sx]+=(c0-c1)/2,tag[sy]+=(c0-c1)/2;
			sol();
		}
		else
		{
			if(c0!=c1) err;
			tp[sx]++,tp[sy]--;
			sol();
		}
	}
	return 0;
}

Measured memory_bytes: 27772
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const ll N = 1e5 + 5, MOD = 1e9+7;

ll a,b;

int main(){

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

    cin>>a>>b;

    if(a>=13)                  cout<<b<<endl;
    else if( a<13 && a>=6 )    cout<<b/2<<endl;
    else                       cout<<0<<endl;

    return 0;
}




Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> x(n), y(m), dx, dy, gx, gy;
    rep(i, 0, n) {
        cin >> x[i];
    }
    rep(i, 0, m) {
        cin >> y[i];
    }
    sort(all(x));
    sort(all(y));

    rep(i, 0, n - 1) {
        dx.push_back((x[i + 1] - x[i])%MOD);
    }
    rep(i, 0, m - 1) {
        dy.push_back((y[i + 1] - y[i])%MOD);
    }

    ll ddx = 1LL*(n - 1);
    ll ddy = 1ll*(m - 1);

    gx.push_back(ddx);
    ddx-=2LL;
    gy.push_back(ddy);
    ddy-=2LL;
    while(ddx > 0){
        gx.push_back((gx[gx.size()-1]+ddx)%MOD);
        ddx-=2LL;
    }
    while(ddy > 0){
        gy.push_back((gy[gy.size()-1]+ddy)%MOD);
        ddy-=2LL;
    }
    if((n - 1) % 2 == 0){
        int si = gx.size();
        for(int i = si-1; i >= 0; i--){
            gx.push_back(gx[i]);
        }
    }else{
        int si = gx.size();
        for(int i = si-2; i >= 0; i--){
            gx.push_back(gx[i]);
        }
    }

    if((m - 1) % 2 == 0){
        int si = gy.size();
        for(int i = si-1; i >= 0; i--){
            gy.push_back(gy[i]);
        }
    }else{
        int si = gy.size();
        for(int i = si-2; i >= 0; i--){
            gy.push_back(gy[i]);
        }
    }

    ll ax = 0LL,ay = 0LL;
    rep(i,0,gx.size()){
        ax = (ax + 1LL * (gx[i] * dx[i]) ) % MOD;
    }
    rep(i,0,gy.size()){
        ay += 1LL * (gy[i] * dy[i]) % MOD;
        ay %= MOD;
    }

    ll ans = (ax * ay) % MOD;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5748
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<algorithm>
using namespace std;

int h[10];
int main()
{
for (int i = 0 ; i < 10; ++i) {
    cin >> h[i];
}
sort(h, h + 10, greater<int>());
cout << h[0] << endl;
cout << h[1] << endl;
cout << h[2] << endl;
}



Measured memory_bytes: 3144
N, K = map(int, input().split())

prob_sum = 0

for i in range(N + 1)[1::]:
    current = i
    prob = 1
    while(True):
        if(K <= current):
            break
        prob = prob * 0.5
        current = current * 2
    prob_sum += prob

print(prob_sum / N)

Measured memory_bytes: 3316
n=int(input())
node=[[1]*n for _ in range(n)]
for i in range(n):
	node[i][i]=0
if n%2==0:
	for i in range(n//2):
		node[i][n-1-i]=0
		node[n-1-i][i]=0
else:
	for i in range(n//2):
		node[i][n-2-i]=0
		node[n-2-i][i]=0
ans=[]
for i in range(n):
	for j in range(i+1,n):
		if node[i][j]==1:
			ans.append((i,j))
print(len(ans))
for x,y in ans:
	print(x+1,y+1)

Measured memory_bytes: 3996
from itertools import product
n,m = map(int,input().split())
l = [list(map(int,input().split()))[1:] for _ in range(m)]
p = list(map(int,input().split()))
s = 0
a = 0
for i in product([0,1],repeat=n):
  for j in l:
    for k in j:
  #    print(i,j,k)
      a += i[k-1]
 #   print(a,p[l.index(j)])
    if a%2!=p[l.index(j)]:
      a =0
      break
    a =0
  else:
    s += 1
print(s)

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll N=in();
	vector<ll> A(N+1);
	A[0] = 0;
	REP(i,N){
		ll v = in<ll>();
		A[i+1] = v+A[i];
	}
	
	ll min_abs = (1LL<<60);
	int left=1,right=3;
	for(int i=2;i<N-1;i++){
		// left
		ll P,Q,R,S;
		ll min_vall = (1LL<<60);
		for(int j=left;j<i;j++){
			ll suml = A[j];
			ll sumr = A[i]-A[j];
			if(abs(sumr-suml)<min_vall){
				min_vall = abs(sumr-suml);
				P = suml;
				Q = sumr;
				left = j;
			}
			else break;
		}
		// right
		ll min_valr = (1LL<<60);
		for(int j=right;j<N;j++){
			ll suml = A[j]-A[i];
			ll sumr = A[N]-A[j];
			if(abs(sumr-suml)<min_valr){
				min_valr = abs(sumr-suml);
				R = suml;
				S = sumr;
				right = j;
			}
			else break;
		}
		ll val = max({P,Q,R,S})-min({P,Q,R,S});
		if(val<min_abs){
			min_abs = val;
		}
	}

 	cout << min_abs << endl;
	return 0;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;


class Main{
	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		String b=br.readLine();
		StringBuilder sb=new StringBuilder(str);
		while(sb.length()<101)sb.append(str);
		str=sb.toString();
		System.out.println(str.contains(b)?"Yes":"No");
	
	
	}}

Measured memory_bytes: 17048
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  string s;cin >> s;
  if(n%2==0 && s.substr(0,n/2) == s.substr(n/2,n/2)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
lines = []
while line = gets
    lines << line.chomp.split(' ')
end

N = lines[0][0].to_i

ans = 0.0
for i in 1..N do
  if lines[i][1] == "JPY" then
    ans += lines[i][0].to_f
  else
    ans += lines[i][0].to_f * 380000.0
  end
end
puts ans

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

int main() {
    int n, idx = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a == idx + 1) {
            idx++;
        }
    }
    cout << (idx != 0 ? n - idx : -1) << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;

int main()
{
	int N, K;
	cin >> N >> K;
	vi P(N);
	for (auto& x : P)
	{
		cin >> x;
		--x;
	}
	vl C(N);
	for (auto& x : C)
		cin >> x;

	vl maxScore(N);
	for (int i = 0; i < N; ++i)
	{
		int pos = i;
		vl score(N+1);
		int j = 0;
		for (; j < N; ++j)
		{
			score[j + 1] = score[j] + C[P[pos]];
			pos = P[pos];
			if (pos == i)
				break;
		}
		int c = K / (j+1);
		int r = K - c * (j+1);
		if (c > 0)
		{
			--c;
			r += (j + 1);
		}


		ll loopScore = score[j+1];
		ll theScore = 0;
		if (loopScore > 0)
		{
			theScore += loopScore * c;
		}
		bool isOk = true;
		if (c == 0 || loopScore < 0)
		{
			isOk = false;
		}
		ll ms = 0;
		for (int k = 0; k < r; ++k)
		{
			ll tmp = score[(k % (j + 1)) + 1] + (k >= (j + 1) ? loopScore : 0);
			if(tmp >= 0LL)
				isOk = true;
			ms = max(ms, tmp);
		}
		theScore += ms;
		if (!isOk)
		{
			theScore = score[1];
		}
		maxScore[i] = theScore;
	}
	sort(maxScore.begin(), maxScore.end());
	cout << maxScore.back() << endl;


	return 0;
}


Measured memory_bytes: 3776
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    int a,b,c=0,d=0,k=0,n,h,w,m,ans=0;
    string s,s2;
    cin >> s; 
    VI alp(26);
    rep(i,s.size()){
        alp[s[i]-'a']++;
    }

    rep(i,26){
        if (alp[i]==0){
            cout << (char)(i + 'a') << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

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

using namespace std;
#define ll long long int
#define rep(i,n) for(i=0;i<(n);i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
typedef pair< ll, ll > lpair;

void solve()
{
    ll n, i;
    cin >> n;

    string s;
    cin >> s;

    ll red = 0;
    for(auto x : s) if(x == 'R') red++;

    ll w = 0;
    for(i = 0; i < red; i++) if(s[i] == 'W') w++;
    
    cout << w << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    ll t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 3772
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>
using namespace std;

#define ll long long

void solve()
{
    ll N, K;
    cin >> N >> K;
    map<ll, ll> mp;
    ll havCount = 0;
    for (ll i = 0; i < K; i++)
    {
        ll d;
        vector<ll> A;
        cin >> d;
        for (ll j = 0; j < d; j++)
        {
            ll a;
            cin >> a;
            if (mp[a] == (ll)NULL)
            {
                havCount++;
                mp[a] = 1;
            }
            else
            {
                mp[a]++;
            }
        }
    }
    cout << N - havCount << endl;

    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

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

        int x = Integer.parseInt(scan.next());
        int y = Integer.parseInt(scan.next());
        int a = Integer.parseInt(scan.next());
        int b = Integer.parseInt(scan.next());
        int c = Integer.parseInt(scan.next());

        int[] p = new int[a];
        for (int i = 0; i < a; i++) {
            p[i] = Integer.parseInt(scan.next());
        }

        int[] q = new int[b];
        for (int i = 0; i < b; i++) {
            q[i] = Integer.parseInt(scan.next());
        }

        int[] r = new int[c];
        for (int i = 0; i < c; i++) {
            r[i] = Integer.parseInt(scan.next());
        }

        scan.close();

        Arrays.sort(p);
        Arrays.sort(q);

        List<Integer> answerList = new ArrayList<Integer>();
        for (int i = 0; i < x; i++) {
            answerList.add(p[a - 1 - i]);
        }
        for (int i = 0; i < y; i++) {
            answerList.add(q[b - 1 - i]);
        }
        for (int ri : r) {
            answerList.add(ri);
        }
        Collections.sort(answerList);

        long answer = 0;
        for (int i = 0; i < x + y; i++) {
            answer += answerList.get(answerList.size() - 1 - i);
        }

        System.out.println(answer);
    }

}


Measured memory_bytes: 63848
#include "bits/stdc++.h"
using namespace std;
#define N 100000
long long n, k, mi, ans = 0, b = 10, c = 9, cnt = 10;
long long ketakeisan(long long aaa){
    long long re = 0;
    while(aaa){
        re += aaa % 10;
        aaa /= 10;
    }
    return re;
}
int main(){
    cin >> k;
    for(int i = 1; i <= k && i <= 9; i++){
        cout << i << endl;
    }
    k -= 9;
    for(long long i = 1 ;; i++){
         if((i * b + c) > ketakeisan(i * b + c) * b){
            i /= 10;
            if(i)
                --i;
            b *= 10;
            c = c * 10 + 9;
        }
        else{
            cout << i * b + c << endl;
            k--;
        }
        if(!k)
            break;
    }
}

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

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long hour,min,sec;
		sec = Long.parseLong(br.readLine());
		sec -= (hour = sec / 60 /60) * 60 * 60;
		sec -= (min = sec / 60) * 60;
		System.out.printf("%d:%d:%d%n", hour, min, sec);
	}
}

Measured memory_bytes: 17100
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
using bll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define PI (acos(-1))
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

signed main() {
	std::chrono::system_clock::time_point starttime, endtime;
	starttime = std::chrono::system_clock::now();

	ll N;
	scanf("%lld", &N);
	vector<vector<ll>> a(N, vector<ll>(N-1, 0));

	rep(i, N) rep(j, N-1) {
		ll t;
		scanf("%lld", &t);
		a[i][j]=t-1;
	}

	ll ans=0;
	vector<ll> index(N,0);
	while(1){
		endtime = std::chrono::system_clock::now();
		double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(endtime - starttime).count();
		if(elapsed>1980){
			p(N*(N-1)/2);
			exit(0);
		}
		map<pair<ll,ll>,ll> m;
		rep(i,N){
			if(index[i]==N-1)continue;
			ll t=i,s=a[i][index[i]];
			if(s>t)swap(s,t);
			m[make_pair(s,t)]++;
		}

		bool gotonext=false;
		for(auto p:m){
			if(p.second!=2)continue;
			gotonext=true;
			index[p.first.first]++;
			index[p.first.second]++;
		}

		if(!gotonext){break;}
		ans++;
	}

	rep(i,N){
		if(index[i]!=N-1){
			p(-1);
			return 0;
		}
	}

	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	string sL = s.substr(0, N), sR = s.substr(N);
	reverse(sR.begin(), sR.end());
	map<pair<string, string>, Int> L, R;
	auto f = [&](string S, map<pair<string, string>, Int>& mp) -> void {
		for (int i = 0; i < (1<<N); ++i) {
			string X = "", Y = "";
			for (int j = 0; j < N; ++j) {
				if ((i>>j) & 1) { X.push_back(S[j]); }
				else { Y.push_back(S[j]); }
			}
			mp[{ X, Y }] += 1;
		}
	};

	f(sL, L);
	f(sR, R);
	Int ans = 0;
	for (auto it = L.begin(); it != L.end(); ++it) {
		auto p = it->first;
		if (!R.count(p)) { continue; }
		ans += it->second * R[p];
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 61004
def main():
    s = input()
    mm1 = False
    mm2 = False

    if 0 < int(s[:2]) < 13:
        mm1 = True
    if 0 < int(s[-2:]) < 13:
        mm2 = True
    
    if mm1 == True and mm2 == True:
        print("AMBIGUOUS")
        return 
    if mm1 == False and mm2 == False:
        print("NA")
        return
    if mm1 == True and mm2 == False:
        print("MMYY")
        return
    if mm1 == False and mm2 == True:
        print("YYMM")
        return
    print("NA")

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (int)n;i++)
#define repb(i,n) for(int i = (int)n;i >= 0;i--)
#define reps(i,m,n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i,m,n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v,n) sort(v,v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
    int a,b,c,mi,mx;
    cin>>a>>b>>c;
    mi=min(min(a,b),c);
    mx=max(max(a,b),c);
    cout<<10*mx+mi+(a+b+c)-mx-mi<<endl;
    return 0;
}


Measured memory_bytes: 256