akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
using namespace std;

class unionfind {
public:
  vector<int> v;

  unionfind(int n) {
    v = vector<int>(n, -1);
  }

  int size(int n) {
    return -v[root(n)];
  }

  int parent(int n) {
    return v[n] < 0 ? n : v[n];
  }

  int root(int n) {
    return parent(n) == n ? n : v[n] = root(parent(n));
  }

  int unite(int a, int b) {
    int ra = root(a);
    int rb = root(b);
    if (ra == rb) return size(ra);
    if (size(ra) >= size(rb)) {
      v[ra] += v[rb];
      v[rb] = ra;
      return size(ra);
    } else {
      v[rb] += v[ra];
      v[ra] = rb;
      return size(rb);
    }
  }
};

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

  unionfind uf(n);

  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    uf.unite(x, y);
  }

  set<int> ans;

  for (int i = 0; i < n; i++) {
    ans.insert(uf.root(i));
  }

  cout << ans.size() << endl;
}


Measured memory_bytes: 5376
#include <algorithm>
#include <climits>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

    int ans = B + min(A+B+1, C);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
int main() {
    int cnt = 0;
    int a, b; std::cin >> a >> b;
    for (int i = 1; i <= 12; i++) {
        if (i < a) {
            cnt++;
        } else if (i == a) {
            if (i <= b) {
                cnt++;
            }
        }
    }
    std::cout << cnt << std::endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC096C
{
    class Program
    {
        static void Main(string[] args)
        {
            var HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
            char[,] grid = new char[HW[0] + 2, HW[1] + 2];

            for(int i = 0; i < HW[0]; i++)
            {
                var line = Console.ReadLine();
                for(int j = 0; j < HW[1]; j++)
                {
                    grid[i + 1, j + 1] = line[j];
                }
            }

            bool ans = true;
            int[] dx = { -1, 0, 1, 0 };
            int[] dy = { 0, -1, 0, 1 };
            for (int i = 1; i <= HW[0]; i++)
            {
                for (int j = 1; j <= HW[1]; j++)
                {
                    if (grid[i, j] == '.') continue;

                    if (grid[i + dx[0], j + dy[0]] == '#') continue;
                    if (grid[i + dx[1], j + dy[1]] == '#') continue;
                    if (grid[i + dx[2], j + dy[2]] == '#') continue;
                    if (grid[i + dx[3], j + dy[3]] == '#') continue;

                    ans = false;
                    break;
                }
            }

            if (ans == true) Console.WriteLine("Yes");
            else Console.WriteLine("No");
            Console.ReadKey();
        }
    }
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

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

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, x, m;

	cin >> n >> x;

	vector<ll> v;

	REP(i, n) {
		cin >> m;
		v.push_back(m);
		x -= m;
	}

	sort(v.begin(), v.end());

	ll ans = n;

	ans += x / v[0];

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <deque>
#include <algorithm>

using namespace std;

typedef long long ll;

int main(){
    deque<ll> v;
    ll N,n;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> n;
        auto itr = lower_bound(v.begin(),v.end(),n);
        if(v.begin() == itr){
            v.push_front(n);
            continue;
        }
        *(itr-1) = n;
    }
    cout << v.size() << endl;
    return 0;
}

Measured memory_bytes: 1024
module Main where

import Data.Maybe (fromJust)
import Data.List
import Control.Monad
import qualified Data.ByteString.Char8 as BS

import qualified Data.Vector.Unboxed as VU

bytestr2Int = fst . fromJust . BS.readInt
getInt = bytestr2Int <$> BS.getLine
getIntL_H = map bytestr2Int. BS.words <$> BS.getLine
getIntL_V n = replicate n $ getInt
getInt2D n = replicate n $ getIntL_H

main :: IO ()
main = do
    n <- getInt
    ns <- getIntL_H
    let vecN = VU.fromList $ sort ns
    r <- sum <$> do
        forM [1..(n-2)] $ \i ->
            pure $ btm $ foldl (\acc j -> update acc $ check vecN (vecN VU.! i + vecN VU.! j) (top acc) n 0 ) (i+1,0,0) [0..(i-1)]
    print r


check v thresh x lim r = if lim == x
    then
        (x,r)
    else if v VU.! x < thresh 
        then
            check v thresh (x+1) lim (r+1)
        else
            (x,r)

update :: (Int,Int,Int) -> (Int,Int) -> (Int,Int,Int)
update (_,x,s) (b,y) = (b,x+y,s+x+y)

top (t,_,_) = t
mid (_,m,_) = m
btm (_,_,b) = b


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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int X = sc.nextInt();
		for(int i = Math.max(-1000000, X-K+1); i <= Math.min(1000000, X+K-1); i++)
			System.out.print(i + " ");
		System.out.println();

	}

}


Measured memory_bytes: 21716
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<map>
#include<iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(n,x) for(ll i=0;i<n;i++) cin>>x[i];


int main()
{
	ll n;
	cin >> n;
	vector<ll> a(n + 1);
	vector<ll> b(n);
	rep(n + 1, a);
	rep(n, b);
	ll ans = 0;
	for (ll i = 0; i < n; i++)
	{
		if (a[i] <= b[i])
		{
			ans += a[i];
			b[i] -= a[i];
			if (b[i] <= a[i + 1])
			{
				a[i + 1] -= b[i];
				ans += b[i];
			}
			else
			{
				ans += a[i + 1];
				a[i + 1] = 0;
			}
		}
		else
		{
			ans += b[i];
			b[i] = 0;
		}
	}
	
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 4832
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <string>
#include <map>
#define FOR(i,b,a) for(int i=(b);i<=(a);i++)
#define REP(i,a) for(int i=0;i<(a);i++)
using namespace std;
typedef pair<int,int> pr;
const int INF=1<<30;
int maps[20][20],px[20],py[20];
int ans[20][20],msize[20];
int X,Y,n,b,k,counts=0;
void search(int p){
	if(p==n+1){
		REP(i,20)
			REP(j,20)
				ans[i][j]=maps[i][j];
		counts++;
		return ;
	}

	FOR(i,1,X){
		int x=i,y=msize[p]/i;
		if(x*y==msize[p]){
			FOR(j,max(1,py[p]-y+1),min(Y-y+1,py[p]))
				FOR(k,max(1,px[p]-x+1),min(X-x+1,px[p])){
					bool able=true;
					REP(ii,y)
						REP(jj,x)
							if(maps[ii+j][jj+k]!=p && maps[ii+j][jj+k]!=0)
								able=false;
					if(able){
						REP(ii,y)
							REP(jj,x)
								maps[ii+j][jj+k]=p;
							//	cout << j << k << endl;
						search(p+1);
						REP(ii,y)
							REP(jj,x)
								maps[ii+j][jj+k]=0;
						maps[py[p]][px[p]]=p;
					}
				}
		}
	}
}
int main() {
	while(cin >> X >> Y >>n && X){
	counts=0;
	FOR(i,1,n){
	cin >> b>>k;
	msize[b]=k;
	}
	FOR(i,1,Y)
		FOR(j,1,X){
			cin >> maps[i][j];
			if(maps[i][j]){
				px[maps[i][j]]=j;
				py[maps[i][j]]=i;
			}
			
		}
	search(1);
	if(counts!=1)
		cout << "NA" << endl;
	else
		FOR(i,1,Y){
			FOR(j,1,X)
				if(j==X)
					cout <<ans[i][j];
				else
					cout <<ans[i][j]<<" ";
			cout << endl;
		}
	// your code goes here
	}
	return 0;
}

Measured memory_bytes: 1164
# 整数の入力
n = input()
n = int(n)

# いくつあるかわからないときのスペース区切りの整数の入力
nums = input().split()
nums = list(map(int,nums))

#print(nums)

nums.sort(reverse=True)

#print(nums)

i = 0
Alis = 0
Bob = 0

for i in range(0,n):
    if i % 2 == 0:
        Alis = Alis + nums[i]
    else:
        Bob = Bob + nums[i]

print(Alis-Bob)

#print(Alis)
#print(Bob)


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int numN  = scan.nextInt();

		List<Point> list = new ArrayList<>();

		for (int i = 0; i < numN; i++) {
			int x = scan.nextInt();
			int y = scan.nextInt();
			Point p = new Point(x, y);
			list.add(p);

			if (p.degree < 0) {
				Point p1 = new Point(x, y);
				p1.degree += 360;
				list.add(p1);
			}
		}

		Collections.sort(list);

		List<Double> list2 = new ArrayList<>();

		for (int i = 0; i < numN; i++) {
			double base = list.get(i).degree;
			double x = 0.0;
			double y = 0.0;
			for (Point p: list) {
				if (p.degree >= base && p.degree < base + 180) {
					x += p.x;
					y += p.y;
				}
			}

			double length = Math.sqrt(x * x + y * y);

			list2.add(length);
		}

		for (Point baseP: list) {
			if (baseP.degree >= -90 && baseP.degree < 270) {
			double base = baseP.degree;
			double x = 0.0;
			double y = 0.0;
			for (Point p: list) {
				if (p.degree > base - 90 && p.degree < base + 90) {
					x += p.x;
					y += p.y;
				}
			}

			double length = Math.sqrt(x * x + y * y);

			list2.add(length);
			}
		}

		Collections.sort(list2, Comparator.reverseOrder());
		System.out.println(list2.get(0));
	}
}
class Point implements Comparable<Point>{
	int x;
	int y;
	double degree;

	Point(int x, int y) {
		this.x = x;
		this.y = y;
		this.degree = Math.toDegrees(Math.atan2(y, x));
	}

	public int compareTo(Point p) {

		return Double.compare(this.degree, p.degree);
	}
}

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

typedef long long ll;
const int INF = 1e9 + 7;
const ll LINF = 1LL<<61;

int n;

int main(){
	int n;
	ll x,l;
	cin >> n;
	vector<pair<ll,ll>> a(n);
	for (int i = 0; i < n; i++){
		cin >> x >> l;
		a[i].first = x + l;
		a[i].second = x - l;
	}

	sort(a.begin(),a.end());

	ll ans = 0;
	x = -LINF;

	for(int i = 0; i < n; i++){
		if(x <= a[i].second){
			ans++;
			x = a[i].first;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif
	int n; cin>>n;
	int a[n],sum=0;
	for(int i=0;i<n;i++) {
		cin>>a[i]; sum+=a[i];
	}
	sum=sum/n;
	//cout<<sum<<endl;
	ll ans=0,ans1=0;
	for(int i=0;i<n;i++){
		ans+=(a[i]-sum)*(a[i]-sum);
	}
	sum++;
	for(int i=0;i<n;i++){
		ans1+=(a[i]-sum)*(a[i]-sum);
	}
	ans1=min(ans,ans1);
	cout<<ans1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include <cfenv>
#include <cmath>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){
long long   N;
cin>>N;

vector<long long> B(N);
long long a;
long long sum=0;
for(int i=0;i<N;i++){
    cin>>a;
    B[i]=a-(i+1);
}

sort(B.begin(),B.end());
long long mid;
mid=B[N/2];
/*
if(N%2==0){
    mid=(B[N/2]+B[N/2+1]);
    mid/=2;
}
else{
    mid=B[N/2];
}
*/
long long ans=0;
for(int i=0;i<N;i++){
     ans+=abs(B[i]-mid);
}

cout<<ans<<endl;


 return 0;
}
/*
5
2 2 3 5 5

2

9
1 2 3 4 5 6 7 8 9

0

6
6 5 4 3 2 1

18

7
1 1 1 1 2 3 4

6
*/


Measured memory_bytes: 1792
#include <stdio.h>

int main(){
  int c[3][3],a[3],b[3];
  int flag = 0;
  for(int i = 0; i < 3; ++i) scanf("%d %d %d",&c[i][0],&c[i][1],&c[i][2]);
    //(1,j)check
  b[0] = 0;//a,b解 <-> a+b0,b-b0解
  a[0] = c[0][0];
  b[1] = c[0][1] - a[0];
  b[2] = c[0][2] - a[0];
    //(2,j)check
  a[1] = c[1][0] - b[0];
  if(c[1][1] != a[1] + b[1] || c[1][2] != a[1] + b[2]) flag = 1;
    //(3,j)check
  a[2] = c[2][0] - b[0];
  if(c[2][1] != a[2] + b[1] || c[2][2] != a[2] + b[2]) flag = 1;
  
  if(flag == 0) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 128
N = int(input())
L, R = [0], [0]
for i in range(N):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

L.sort(reverse=True)
R.sort()

ans = 0
tmp = 0
for i in range(N):
    if L[i] - R[i] > 0:
        ans += 2 * (L[i] - R[i])
    else:
        print(ans)
        break


Measured memory_bytes: 58328
import sys
input = sys.stdin.readline
from collections import deque

def main():
    N,A,B,C,D = map(int,input().split())
    if A > B:
        B = A+(A-B)
    ne = (C+D)/2
    wi = (D-C)*(N-1)+1
    use = [A+(2*i+(N+1)%2)*ne for i in range((N-1)//2+1)]
    for num in use:
        u,d = int(num+wi//2-(wi+1)%2/2),int(num-(wi//2-(wi+1)%2/2))
        if d <= B <= u:
            print("YES")
            exit()
            
    print("NO")

if __name__ == "__main__":
    main()


Measured memory_bytes: 11380
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int main() {
    int r, g, b ,n;
    cin >> r >> g >> b >> n;
    // r * i + g * j + b * k == n
    int res = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            int tmp = n - (r * i + g * j);
            if ((tmp  >= 0) && (tmp % b == 0)) {
                //printf("(%d, %d, %d)\n", i, j, tmp / b);
                res++;
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {


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

        int k = sc.nextInt();
        int n = sc.nextInt();

        List<Integer> list = new ArrayList<Integer>();

        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }

        Collections.sort(list);

        List<Integer> list2 = new ArrayList<Integer>();

        for (int i = 0; i < n; i++) {
            if (i == n - 1) {
                list2.add(list.get(0) + k - list.get(i));
            } else {
                list2.add(list.get(i + 1) - list.get(i));
            }
        }

        Collections.sort(list2);

         System.out.println(k - list2.get(n - 1));

        sc.close();
    }

}

Measured memory_bytes: 93152
import numpy as np
N = int(input())
lst = np.array(list(map(int, input().split() )))
for i in range(len(lst)):
    lst[i] = lst[i] - (i +1)
#print("lst:",lst)
b = int(np.median(lst) )  
#print("np.mean(lst):",np.mean(lst))
#print("b:",b)
count = 0
for A in lst:
    count += abs(A -b)
print(count)

Measured memory_bytes: 34220
#include<cstdio>
using namespace std;

int n,ans=0,a[10],b[10];

int solve(int p){
    if(p==n){
        for(int i=0;i<n;i++){
            if(b[i]%2==0){
                return 1;
            }
        }
        return 0;
    }
    int ans=0;
    for(int i=-1;i<=1;i++){
        b[p]=a[p]+i;
        ans+=solve(p+1);
    }
    return ans;
}

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    ans=solve(0);
    printf("%d\n",ans);
}

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

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"--------------------------"<<endl; 
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e18;
#define PI 3.14159265
 
const ll N = 10000005;

ll A[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    rep(i,0,n+1)	A[i]=0;
    rep(i,1,n+1){
    	for(ll j=i;j<=n;j+=i)	A[j]++;
    }
	ll ans=0;
	rep(i,1,n+1){
		ans += (i*A[i]);
	}
	cout<<ans<<endl;
    return 0;
}

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

const W INF = 1LL << 58;

struct edge {
	int to;
	W cost;
};
typedef pair<W, int> P;
typedef vector<vector <edge > > Graph;

void dijkstra(vector<int> st, const Graph& G, vector<W>& d) {
	priority_queue< P, vector<P>, greater<P> > que;
	fill(d.begin(), d.end(), INF);
	for(auto s : st) {
		d[s] = 0;
		que.push(P(0, s));
	}
	while(!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int a[200000];
int b[200000];
int c[200000];

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

	int N, M, R, Q;
	cin >> N >> M >> R >> Q;

	map<int, int> id;
	for(int i = 0; i < M; i++) {
		cin >> a[i] >> b[i] >> c[i];
		id[a[i]] = id[b[i]] = 0;
	}

	int K = 0;
	for(auto v : id) {
		id[v.first] = K++;
	}

	Graph G(K);
	for(int i = 0; i < M; i++) {
		G[id[b[i]]].push_back({ id[a[i]], c[i] });
	}

	vector<W> d[10];
	for(int r = 0; r < R; r++) {
		d[r] = vector<W>(K);
		vector<int> st;
		for(int i = 0; i < M; i++) {
			if(b[i] % R == r) st.push_back(id[b[i]]);
		}
		dijkstra(st, G, d[r]);
	}

	ll sum = 0;
	for(int q = 0; q < Q; q++) {
		int x[2];
		ll z;
		cin >> x[0] >> x[1] >> z;

		ll s = 0;
		for(int r = 0; r < R; r++) {
			bool ok = true;
			ll cost_sum = 0;
			for(int i = 0; i < 2; i++) {
				if(x[i] % R != r) {
					if(!id.count(x[i]) || d[r][id[x[i]]] == INF) ok = false;
					else cost_sum += d[r][id[x[i]]];
				}
			}
			if(ok && z > cost_sum) {
				//cerr << "z - cost_sum : " << z - cost_sum << endl;
				s = max(s, z - cost_sum);
			}
		}
		//cerr << "s : " << s << endl;
		sum += s;
	}
	cout << sum << endl;
}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N;
  cin >> N;
  for (ll i = 1; i < 4000; i++) {
    for (ll j = 1; j < 4000; j++) {
      ll a = N * i * j;
      ll b = 4 * i * j - N * (i + j);
      if (b > 0 && a % b == 0) {
        cout << i << " " << j << " " << a / b << '\n';
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MOD 1000000007
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int 
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//               When something is important enough, you do it even if the odds are not in your favor.

int main(){   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      LI n,m,i;cin>>n>>m;
      std::vector<std::vector<LI> > v(n);
      std::vector<LI> ans(n,-1);
      fo(i,0,m){
        LI x,y;cin>>x>>y;x--;y--;
        v[x].pb(y);v[y].pb(x);
      }
      queue<LI> q;
      q.push(0);
      while(q.size()!=0){
        LI val=q.front();
        q.pop();
        fo(i,0,v[val].size()){
          if(ans[v[val][i]]!=-1) continue;
          ans[v[val][i]]=val+1;
          q.push(v[val][i]);
        }
      }
      cout<<"Yes"<<endl;
      fo(i,1,n) cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 12928
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out=new PrintWriter(outputStream);
            int ans =TaskA.solve(0,in);
            out.println(ans);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() { return Double.parseDouble(next()); }
    }
}
 class TaskA {
    public static int solve(int testNumber, Main.InputReader in) {
        int ans=0;
        String s=in.next();
        if(s.contains("RRR"))
            ans=3;
        else
            if(s.contains("RR"))
                ans=2;
            else
                if(s.contains("R"))
                    ans=1;
                return ans;
    }
}

Measured memory_bytes: 32972
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;

int main(void){
    int n;
    cin >> n;
    vector<int> y(n);
    vector<int> m(n);
    vector<int> d(n);
    vector<int> day(n);
    for(int i = 0; i < n; i++){
        cin >> y[i] >> m[i] >> d[i];
    }

    int base = 20 * 5 + 19 * 5;
    int three_base = 20 * 10;
    int mil = 0;
    for(int i = 1; i <= 999; i++){
        if(i % 3 == 0) mil += three_base;
        else mil += base; 
    }
    mil++;

    //cout << mil << endl;
    
    for(int i = 0; i < n; i++){
        for(int j = 1; j < y[i]; j++){
            if(j % 3 == 0) day[i] += three_base;
            else day[i] += base; 
        }
        for(int k = 1; k < m[i]; k++){
            if(y[i] % 3 == 0){
                day[i] += 20;
            }else{
                if(k % 2 == 0){
                    day[i] += 19;
                }else{
                    day[i] += 20;
                }
            }
        }
        day[i] += d[i];
        cout << mil - day[i] << endl;
    }

}


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

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    long double A, B;
    cin >> A >> B;
    long double C=A*B;
    long int D=0;
    D=C;
    cout << D << endl;
}

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

struct Trie{
   Trie* cp[26]; int cnt[26]={};
   int add(string& s){
      if(s.empty())return 0;
      int c=s.back()-'a'; s.pop_back();
      if(!cp[c])cp[c]=new Trie();
      int x=cp[c]->add(s)|(1<<c);
      rep(i,0,26)if(x>>i&1)cnt[i]++;
      return x;
   }
   Trie* find(string& s){
      if(s.empty())return this;
      int c=s.back()-'a'; s.pop_back();
      return cp[c]->find(s);
   }
};

int main(){
   int n; cin>>n;
   vector<string> s(n);
   rep(i,0,n)cin>>s[i];
   Trie* trie=new Trie();
   rep(i,0,n){
      string tmp=s[i];
      trie->add(tmp);
   }
   ll res=0;
   rep(i,0,n){
      string t=s[i]; t.erase(t.begin());
      Trie* cur=trie->find(t);
      res+=cur->cnt[s[i][0]-'a'];
   }
   cout<<res-n<<endl;
   return 0;
}

Measured memory_bytes: 359404
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

bool dp[30009][4][1009];

int main(void)
{
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    ll ans=INF;
    rep(i,1e5+1){
        ll tmp = 2*c*i + max(0LL, x-i)*a + max(0LL, y-i)*b;
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3528
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

x1, y1, x2, y2 = getNM()
place = [(x1, y1, 0)]
N = getN()
for i in range(N):
    x, y, r = getNM()
    place.append((x, y, r))
place.append((x2, y2, 0))
N += 2
# 地点~円の中心 - 円の半径が被曝する時間　これを元にエッジを貼る
# これを最小化したい
# startからいくつかの円を経由してgoalまで行く時の最小距離

def calc(x1, y1, x2, y2):
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5

def dijkstra(n, start):
    dist = [float('inf')] * n
    pos = [(0, start)]
    heapify(pos)
    dist[start] = 0

    while len(pos):
        cost, u = heappop(pos)

        if dist[u] < cost:
            continue
        # エッジは探索のたびに生成していく
        for i in range(N):
            if i == u:
                continue
            dis = calc(place[u][0], place[u][1], place[i][0], place[i][1])
            opt = max(dis - place[u][2] - place[i][2], 0)
            if dist[u] + opt < dist[i]:
                dist[i] = dist[u] + opt
                heappush(pos, (dist[u] + opt, i))

    return dist

print(dijkstra(N, 0)[-1])

Measured memory_bytes: 127648
WHITE = 0
GRAY = 1
BLACK = 2



$d = []
$f = []



def dfs_visit(u)
	$color[u] = GRAY
	$tt += 1
	$d[u] = $tt

	$n.times do |v|
		next if $m[u][v] == 0
		dfs_visit(v) if $color[v] == WHITE
	end

	$color[u] = BLACK
	$tt += 1
	$f[u] = $tt
end



def dfs()
	$color = Array.new($n, WHITE)
	$tt = 0
	
	$n.times do |u|
		dfs_visit(u) if $color[u] == WHITE
	end

	$n.times do |u|
		printf("%d %d %d\n", u + 1, $d[u], $f[u])	
	end
end



$n = gets.to_i
$m = Array.new($n){ Array.new($n, 0) }

$n.times do
	line = gets.split.map &:to_i
	u, k = line.shift, line.shift
	u -= 1
	k.times do
		v = line.shift
		v -= 1
		$m[u][v] = 1
	end
end

dfs()

Measured memory_bytes: 8852
result = []
while True:
    a, b = map(int, input().split())
    if a == b == 0:
        break
    result.append("\n".join([str(i) for i in range(a, b+1) if i%400 == 0 or i%4 == 0 and i%100]) or "NA")

print("\n\n".join(result))


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

using namespace std;

typedef long long ll;
typedef long double ld;
#define eps 1e-12

int t[105], v[105];

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> t[i];
        t[i] += t[i - 1];
    }
    for(int i = 0; i < n; i++)
        cin >> v[i];
    ld cur = 0;
    ld sol = 0;
    for(int i = 0; i < n; i++)
    {
        ld st = t[i], en = t[i + 1], ans;
        for(int j = 0; j < 70; j++)
        {
            ld mid = (st + en) / 2;
            ld curSpeed = min((ld)v[i], cur + (mid - t[i]));
            bool good = 1;
            for(int k = i + 1; k <= n; k++)
                if(!(curSpeed - (t[k] - mid) <= v[k]))
                    good = 0;
            if(good)
                ans = mid, st = mid;
            else
                en = mid;
        }
        st = t[i], en = ans;
        ld acc, cons, desc = t[i + 1] - ans, ss;
        for(int j = 0; j < 100; j++)
        {
            ld mid = (st + en) / 2;
            ld curSpeed = cur + mid - t[i];
            if(curSpeed <= v[i])
                acc = mid - t[i], cons = ans - mid, ss = curSpeed, st = mid;
            else
                en = mid;
        }
        sol += cur * acc + 0.5 * acc * acc;
        sol += ss * cons;
        sol += ss * (t[i + 1] - ans) + 0.5 * -1 * (t[i + 1] - ans) * (t[i + 1] - ans);
        cur = ss + -1 * (t[i + 1] - ans);
    }
    cout << fixed << setprecision(6) << sol;
}


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


using namespace std;


using ll = long long;


const long long MAX = 200001;


long long fact[MAX];


void calc_fact() {
    fact[0] = fact[1] = 1;
    for (ll i = 2; i <= MAX; i++) {
        fact[i] = (fact[i - 1] * i);
    }
}


ll comb2(ll n) {
    if (n < 2)
        return 0;
    return (n * (n - 1)) / 2;
}


int main(void) {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    calc_fact();

    vector<ll> cnt(N + 1, 0);
    for (ll i = 0; i < N; i++) {
        cnt[A[i]]++;
    }

    ll acc = 0;
    for (ll i = 1; i <= N; i++) {
        acc += comb2(cnt[i]);
    }

    for (ll k = 0; k < N; k++) {
        ll ans = acc - comb2(cnt[A[k]]) + comb2(cnt[A[k]] - 1);
        cout << ans << endl;
    }
}


Measured memory_bytes: 7996
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
   	 static List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
//	 static int mod = 998244353;
	 public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        int H = sc.nextInt();
	        int W = sc.nextInt();
	        int K = sc.nextInt();
	        char[] c=new char[W];
	        int[][] m=new int[H][W];
	        for(int i=0;i<H;i++) {
	        	String S=sc.next();
	        	c=S.toCharArray();
	        	for(int j=0;j<W;j++) {
	        		m[i][j]=(int)c[j]-'0';
	        	}
	        }
	        
	        int cnt=0;
	        int ans=H*W+1;
	        for(int i=0;i<1<<(H-1);i++) {
		        int[][] g=new int[W+5][H+5];
	        	for(int j=0;j<W;j++) {
			        cnt=0;
	        		for(int k=0;k<H;k++) {
	        			g[j][cnt]=g[j][cnt]+m[k][j];
	        			if((i>>k&1)==1)cnt++;
	        		}
	        	}
	        	int[] now = new int[W];
        		boolean tiOK=false;
	        	for(int j=0;j<W;j++) {
	        		boolean isOK=true;
	        		for(int k=0;k<H;k++) {
	        			now[k]=now[k]+g[j][k];
	        			if(now[k]>K)isOK=false;
	        		}
	        		if(isOK==false) {
	        			cnt++;
	        			if(tiOK==false) {
	        				cnt=H*W+5;
	        				continue;
	        			}
	        			j--;
	        			now = new int[W];
	        			tiOK=false;
	        		} else {
	        			tiOK=true;
	        		}
	        	}
	        	ans=Math.min(ans, cnt);
	        }
	        
	        System.out.println(ans);
	        	        	        
	 }
}

Measured memory_bytes: 44088
S=input()
AKI='AKIHABARA'
AKI=list(AKI)
List=[0,4,6,8]
for i in range(1<<4):
  for j in range(4):
    if i&(1<<j):
      AKI[List[j]]='A'
    else:
      AKI[List[j]]=''
    if S==''.join(AKI):
      print('YES')
      exit()
else:
  print('NO')

Measured memory_bytes: 8976
#include<cstdio>
#include<iostream>
using namespace std;
long long a[100005];
int main(void)
{
    long long n,b,sum=0;
    scanf("%lld" ,&n);
    for(long long i=0;i<n+1;i++)
        scanf("%lld" ,&a[i]);
    for(long long i=0;i<n;i++)
    {
        scanf("%lld" ,&b);
        long long t=min(b,a[i]);
        sum+=t;
        b-=t;
        a[i]-=t;
        long long t2=min(b,a[i+1]);
        sum+=t2;
        b-=t2;
        a[i+1]-=t2;
    }
    printf("%lld" ,sum);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
  int n,b,f,r,v,i,j,k;
  cin >> n;
  int a[4][3][10];
  for (i=0;i<4;i++) {
    for (j=0;j<3;j++) {
      for (k=0;k<10;k++) {
        a[i][j][k]=0;
      }
    }
  }

  for (i=0;i<n;i++) {
    cin >> b >> f >> r >> v;
    a[b-1][f-1][r-1]+=v;
  }

  for (i=0;i<4;i++) {
    for (j=0;j<3;j++) {
      for (k=0;k<10;k++) {
        cout << " " << a[i][j][k];
      }
      cout << endl;
    }
    if (i<3) cout << "####################" << endl;
  }

  return 0;
}



Measured memory_bytes: 3072
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

const long long inf = 1e18;

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

	vector<long long> a(m), b(m), c(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;
		b[i]--;
	}

	vector<long long> dist(n, -inf);
	dist[0] = 0;

	vector<long long> scores;
	for (int k = 0; k <= 3000; k++) {
		for (int i = 0; i < m; i++) {
			if (dist[a[i]] == -inf) {
				continue;
			}

			if (dist[b[i]] < dist[a[i]] + c[i]) {
				dist[b[i]] = dist[a[i]] + c[i];
			}
		}

		scores.emplace_back(dist.back());
	}

	if (scores[scores.size() - 1000] == scores.back()) {
		cout << dist.back() << endl;
	} else {
		cout << "inf" << endl;
	}
	return 0;
}


Measured memory_bytes: 384
from bisect import bisect_right

def main():
    N = int(input())


    sixs = [1]
    i = 6
    while i <= N:
        sixs.append(i)
        i *= 6

    nines = [1]
    i = 9
    while i <= N:
        nines.append(i)
        i *= 9

    """
    i円分を6**xxx で、　残りを９**yyyと１*zzzで構成する。これらを全通り試す
    """

    ans = N
    for i in range(N+1):
        cnt = 0
        sum_six = i
        sum_nine = N-i
        while sum_six > 0:
            idx = bisect_right(sixs, sum_six) - 1
            tmp = sum_six // sixs[idx]
            cnt += tmp
            sum_six -= tmp * sixs[idx]

        while sum_nine > 0:
            idx = bisect_right(nines, sum_nine) - 1
            tmp = sum_nine // nines[idx]
            cnt += tmp
            sum_nine -= tmp * nines[idx]

        ans = min(ans, cnt)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define pb push_back
#define sc second
#define fr first
#define mk make_pair
#define ll long long
#define ii pair<int,int>
#define mp make_pair
#define scn(x) scanf("%d",&x)
typedef long long intt;
using namespace std;
int prefx[102][100004];
int dp[102][100004];
int mod=1e9+7;
int main()
{
  int n,k;
  cin>>n>>k;
 prefx[0][k]=1;
 int i,j;
 int a[n+2];
 for(i=1;i<=n;i++)
    cin>>a[i];
 for(i=1;i<=n;i++)
 {
     for(j=0;j<=k;j++)
     {
         if(j==0)
         {
          dp[i][j]+=prefx[i-1][min(j+a[i],k)];
          dp[i][j]%=mod;
         }
        else
        {
          int t=prefx[i-1][min(j+a[i],k)];
             t-=prefx[i-1][j-1];
             t%=mod;
             t+=mod;
             t%=mod;
             dp[i][j]+=t;
             dp[i][j]%=mod;
        }
     }
     prefx[i][0]=dp[i][0];
     for(j=1;j<=k;j++)
       prefx[i][j]=prefx[i][j-1]+dp[i][j],prefx[i][j]%=mod;
 }
 cout<<dp[n][0]<<endl;



    return 0;
}


Measured memory_bytes: 79104
K, N = input().split()
K, N = int(K), int(N)
A = input().split()
for i in range(N):
    A[i] = int(A[i])

A.sort()

x = 0
for i in range(N-1): #Nにi+1を入れるとはみ出るからN-1
    if x < A[i+1] - A[i]:
        x = A[i+1] - A[i]

if x < A[0] + (K - A[N-1]):
    x = A[0] + (K - A[N-1])

print(K - x)


Measured memory_bytes: 18356
from collections import defaultdict, deque
import heapq
v, n = map(int, input().split())
es = [[int(x) for x in input().split()] for _ in range(v+n-1)]

outs = defaultdict(list)
ins = defaultdict(int)
edge_from = [[] for _ in range(v+1)]
edge_to = [[] for _ in range(v+1)]
ans = [-1]*(v+1)
for v1, v2 in es:
    edge_from[v1].append(v2)
    edge_to[v2].append(v1)
    outs[v1].append(v2)
    ins[v2] += 1

q = deque(v1 for v1 in range(v) if ins[v1] == 0)
res = []
while q:
    v1 = q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2] -= 1
        if ins[v2] == 0:
            q.append(v2)
rev = [0]*(v+1)
for i in range(1,v+1):
    rev[res[i]] = i
redge_to = [[] for _ in range(v+1)]
for i in range(1,v+1):
    for j in edge_to[i]:
        ri = rev[i]
        rj = rev[j]
        heapq.heappush(redge_to[ri],-rj)
for ri in range(1,v+1):
    if redge_to[ri]:
        rj = redge_to[ri][0]
        i = res[ri]
        j = res[-rj]
        ans[i] = j
    else:
        i =res[ri]
        ans[i] = 0
for i in ans[1:]:
    print(i)

Measured memory_bytes: 90684
import java.math.*;
import java.io.*;

class Main
{
	public static void main (String[] args) throws Exception
	{
		BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
		String s[]=bu.readLine().split(" ");
		int n=Integer.parseInt(s[0]),m=Integer.parseInt(s[1]),i,sum=0;
		s=bu.readLine().split(" ");
		for(i=0;i<m;i++)
		{
			int k=Integer.parseInt(s[i]);
			sum+=k;
		}
		if(sum>n) System.out.print(-1);
		else System.out.print(n-sum);
	}
}

Measured memory_bytes: 34228
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define SORT(x) sort((x).begin(),(x).end())
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

string s;
int memo[502][502];

bool IsCat(int b,int e){
	int &res=memo[b][e];
	if(res!=0){
		if(res==1) return true;
		else return false;
	}
	if(b==e){
		res=1;
		return true;
	}
	if(!(s[b]=='m'&&s[e-1]=='w')){
		res=2;
		return false;
	}

	REP(i,1,e-1){
		if(s[i]=='e'&&IsCat(b+1,i)&&IsCat(i+1,e-1)){
			res=1;
			return true;
		}
	}

	res=2;
	return false;
}

void Solve(){
	cin >> s;
	if(IsCat(0,s.size())) cout << "Cat";
	else cout << "Rabbit";
	cout << endl;
}

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

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

using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  for(int i=0;i<n;i++){
   cin >>h[i];
  }
  
  sort(h.begin(),h.end());
  
  int res=1000000007;
  
  for(int i=k-1;i<n;i++){
    res=min(res,h[i]-h[i-(k-1)]);
  }
  
 cout << res << endl;
  
  
}

Measured memory_bytes: 640
import Data.List

uniq :: Eq a => [a] -> Bool
uniq a = length a == length (nub a)

siri :: [String] -> Bool
siri s = all (==True) (siri' s)
  where
    siri' :: [String] -> [Bool]
    siri' [] = []
    siri' [_] = []
    siri' (si:sj:sx) = (last si == head sj) : siri' (sj:sx)

main :: IO ()
main = do
    _ <- getLine
    w <- lines <$> getContents :: IO [String]
    putStrLn $ if uniq w && siri w then "Yes" else "No"


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

#define MOD 1000000007
#define f first
#define s second
#define es " "
#define pb push_back
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int main(){
    fastio;
    int n, v[25], resp=0;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    for(int i=1; i<n-1; i++){
        int menor=INF, maior=-1;
        menor=min(v[i], min(v[i-1], v[i+1]));
        maior=max(v[i], max(v[i-1], v[i+1]));
        if(v[i]!=menor && v[i]!=maior){
            resp++;
        }
    }
    cout << resp << endl;
    return 0;
}

Measured memory_bytes: 256
//f
#include <stdio.h>
int main()
{
    int a[3][3]={0};
    
    for(int i=0; i<3; i++)
	{
        for(int j=0; j<3; j++)
		{
            scanf("%d", &a[i][j]);
        }
    }
    
    int n, m;
    scanf("%d",&n);
    
    for(int i=0; i<n; i++)
	{
        scanf("%d",&m);
        for(int j=0; j<3; j++)
		{
            for(int k=0; k<3; k++)
			{
                if(a[j][k]==m)
				{ 
					a[j][k]=0; 
				}
            }
        }
    }
    
    int flag=0;
    for(int i=0; i<3; i++)
	{
        if( a[i][0]==0 && a[i][1]==0 && a[i][2]==0 )
		{ 
			flag=1; 
		}
        if( a[0][i]==0 && a[1][i]==0 && a[2][i]==0 )
		{ 
			flag=1; 
		}
    }
    
    if( a[0][0]==0 && a[1][1]==0 && a[2][2]==0 )
	{ 
	flag=1; 
	}
    if( a[0][2]==0 && a[1][1]==0 && a[2][0]==0 )
	{ 
	flag=1; 
	}
 
    flag ? printf("Yes\n") : printf ("No");
    
    return 0;
}

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

int main() {
  int N,A,B,C,D;
  cin >> N;
  
  A = N/1000;
  B = (N-A*1000)/100;
  C = (N-A*1000-B*100)/10;
  D = N-A*1000-B*100-C*10;
  
  if ((A==B && B==C) || (B==C && C==D)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3576
const main = (input) => {

  let [a, b] = input.trim().split('\n')
  b = b || ''
  
  const [X, N] = a.split(' ').map(v => Number(v))
  const nums = b.split(' ').map(v => Number(v))

  if (N === 0) {
    console.log(X)
    return null
  }

  let smaller = X
  let bigger = X

  while (true) {
    if (nums.indexOf(smaller) === -1) {
      console.log(smaller)
      return null
    } else {
      smaller--
    }

    if (nums.indexOf(bigger) === -1) {
      console.log(bigger)
      return null
    } else {
      bigger++
    }
  }
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

const int MAX_N = 1000000;

int prime[MAX_N];
bool is_prime[MAX_N + 1];

void eratos(int n) {
    int p = 0;
    for (int i = 0; i <= n; ++i) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; ++i) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (int j = 2*i; j <= n; j += i) is_prime[j] = false;
        }
    }
}

int main() {
    eratos(MAX_N);

    int N, P;

    while (cin >> N >> P, (N != -1 and P != -1)) {
        vector<int> t(110);
        int cnt = 0;

        for (int i=N+1; i<MAX_N; ++i) {
            if (is_prime[i]) t[cnt++] = i;
            if (cnt >= 105) break;
        }

        vector<int> tt;

        cnt=0;
        rep(i, 101) {
            for (int j=i; j<=100; ++j) {
                tt.push_back(t[i] + t[j]);
            }
        }

        sort(tt.begin(), tt.end());

        cout << tt[P-1] << endl;

    }

}

Measured memory_bytes: 4484
sa = gets.chomp
sb = gets.chomp
sc = gets.chomp
n = "a"
loop do
  if n == "a"
    if sa == ""
      puts "A"
      exit
    end
    n = sa.slice!(0)
  elsif n == "b"
    if sb == ""
      puts "B"
      exit
    end
    n = sb.slice!(0)
  else
    if sc == ""
      puts "C"
      exit
    end
    n = sc.slice!(0)
  end
end


Measured memory_bytes: 1788
N,Y = map(int,input().split())

x = -1
y = -1
z = -1


for i in range(N+1):
    for j in range(N+1):
        k = N - i - j
        if k < 0 : continue
        if (i*10000+j*5000+k*1000) == Y: 
            x = i
            y = j
            z = k
            print(x,y,z)
            exit(0)
print(x,y,z)

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  ll a,b,c; cin>>a>>b>>c;
  if(4*a*b<(c-a-b)*(c-a-b)&&c-a-b>=0) {cout<<"Yes"<<endl; return 0;}
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(void){
	int n,m,i,j;
	char data[50][2],c;
	scanf("%d",&n);
	while(n!=0){
		for(i=0; i<n; i++){
			scanf(" %c %c ",&data[i][0],&data[i][1]);
		}
		scanf("%d",&m);
		for(i=0; i<m; i++){
			scanf(" %c ",&c);
			for(j=0; j<n; j++){
				if(c==data[j][0]){
					c=data[j][1];
					break;
				}
			}
			printf("%c",c);
		}
		printf("\n");
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 576