akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        
        long min = Long.MAX_VALUE;
        for(long i=1;i<=Math.sqrt(n);i++){
            if(n%i==0){
                long length = i + (n/i) -2;
                min = Math.min(length, min);
            }
        }
        System.out.println(min);
    }
    
    private static void sort(int[] d, int left, int right){
        if(left>=right){return;}
        int p = d[(left+right)/2];
        int l=left, r=right;
        int tmp;
        while(l<=r){
            while(d[l]>p){l++;}
            while(d[r]<p){r--;}
            if(l<=r){
                tmp=d[l];
                d[l] = d[r];
                d[r] = tmp;
                l++; r--;
            }
        }
        sort(d, left, r);
        sort(d, l, right);
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(ll i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define size(s) s.size()
using namespace std;
const int N = 100100;
int n;
ll m,v,p;
ll a[N];
ll pref[N];
int main()
{
	cin>>n>>m>>v>>p;
	int ans=0;
	REP(i,n)cin>>a[i];
	sort(a,a+n);
	reverse(a,a+n);
	REP(i,n)
		pref[i+1]=pref[i]+a[i];
	ans=p;
	for(int i=p;i<n;i++){
		if(a[i]+m<a[p-1])break;
		ll cur=v-(n-(i-p+1));
		if(cur<=0){
			ans++;
			continue;
		}
		if(cur*m<=(i-p+1)*(a[i]+m)-(pref[i]-pref[p-1]))
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

using lint = long long;

vector<int> pos[26];

int main() {
#if DEBUG
    freopen("in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s1, s2;
    cin >> s1 >> s2;
    for (int i = 0; i < s1.size(); ++i)
        pos[s1[i] - 'a'].push_back(i);
    for (auto ch : s2) {
        if (pos[ch -'a'].size() == 0) {
            cout << "-1\n";
            return 0;
        }
    }
    lint ans = 0LL; // ans는 문자열의 길이
    for (char ch : s2) {
        auto p = lower_bound(pos[ch - 'a'].begin(), pos[ch - 'a'].end(), ans % s1.size()); // ans % s1.size() 이상의 위치를 탐색
        if (p == pos[ch - 'a'].end()) {
            auto rp = lower_bound(pos[ch - 'a'].begin(), pos[ch - 'a'].end(), 0); // 다시 탐색한다.
            ans = 1LL * ((ans / s1.size()) + 1LL) * s1.size() + *rp + 1;
//            cout << *rp << '\n';
        } else {
            ans = 1LL * (ans / s1.size()) * s1.size();
            ans += 1LL * (*p) + 1; // ans % s1.size() 초과의 위치를  찾아야 하므로 1을 더해준다.
//            cout << *p << '\n';
        }
//        cout << ans << '\n';
    }
    cout << ans << '\n';
}



Measured memory_bytes: 1228
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char a[100000+5];
int alen;
int main()
{
	scanf("%s",a);
	alen=strlen(a);
	for(int i=0;i<alen-1;i++)
		if(a[i]==a[i+1])
		{
			printf("%d %d\n",i+1,i+2);
			return 0;
		}
	for(int i=0;i<alen-2;i++)
		if(a[i]==a[i+1]||a[i]==a[i+2]||a[i+1]==a[i+2])
		{
			printf("%d %d\n",i+1,i+3);
			return 0;
		}
	printf("-1 -1\n");
	return 0;
}


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

#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

#define debug(x) cout << "> " << #x << " = " << x << endl;
#define debug_at(arr, at) cout << "> " << #arr << "[" << at << "] = " << arr[at] << endl;
#define debug_pair(p) cout << "> " << #p << " = (" << p.first << ", " << p.second << ")" << endl;

using namespace std;

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

const int N = 1e5 + 23;
const int INF = 2e9;

int arr[N];
set<int> divs[N];

int n, x;
set<int>::iterator its[N];
void init() {
    fori(i, 0, n) {
        fori(j, 1, sqrt(arr[i]) + 2) { 
            if(arr[i] % j == 0) {
                divs[i].insert(j);
                divs[i].insert(arr[i] / j);
            }
        }
        its[i] = divs[i].begin();
    }
}

int solve() {
    int ans = 1;
    while(its[0] != divs[0].end()) {
        int cur = *its[0];

        for(int i = 0; i < n; i++) {
            if(its[i] == divs[i].end()) {
                return ans;
            }

            if(*its[i] == cur) {
                its[i]++;
            }
            else {
                return ans;
            }
        }
        ans = cur;
    }
    return ans;
}

#define gcd __gcd

int main() {
    ios_base::sync_with_stdio(false);

    cin >> n >> x;

    int ans = 0;
    fori(i, 0, n) {
        cin >> arr[i];
        arr[i] = abs(arr[i] - x);
        ans = gcd(ans, arr[i]);
    }
//    init();
//    cout << solve() << '\n';
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 6144
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long double a=0.0,b=0.0;
    cin>>a>>b;
    lli ans=(lli)floor(a*b);
    cout<<ans<<endl;
}

Measured memory_bytes: 3748
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        StringTokenizer st;
        try {
            int floor;
            double v, maxv, t;
            String line = br.readLine();
            while (line != null) {
                v = 0;
                maxv = Double.parseDouble(line);
                floor = 1;
                for (int i = 1; v <= maxv; i++) {
                    floor = i;
                    v = Math.sqrt((5 * floor - 5) / 4.9) * 9.8;

                }
                System.out.println(floor);
                line = br.readLine();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

Measured memory_bytes: 24188
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
typedef struct{int Parent,Rank;}UnionFind;
static inline int Root(int x,UnionFind *uf)
{
  if(uf[x].Parent==x)return x;
  else return uf[x].Parent=Root(uf[x].Parent,uf);
}
static inline int Unite(int x,int y,UnionFind *uf)
{
  x=Root(x,uf),y=Root(y,uf);
  if(x==y)return 0;
  uf[x].Parent=y;uf[y].Rank+=uf[x].Rank;return 1;
}
static inline int Size(int x,UnionFind *uf){return uf[Root(x,uf)].Rank;}
static inline int Belong(int x,int y,UnionFind *uf){return Root(x,uf)==Root(y,uf);}
int main(void)
{
  int A,B,C,D,N,M,K;
  scanf("%d %d %d",&N,&M,&K);
  int known[N];
  UnionFind uft[N];
  for(int i=0;i<N;i++){known[i]=0;uft[i].Parent=i;uft[i].Rank=1;}
  while(M--)
  {
    scanf("%d %d",&A,&B);
    A--,B--;known[A]++,known[B]++;Unite(A,B,uft);
  }
  while(K--)
  {
    scanf("%d %d",&C,&D);
    C--,D--;if(Belong(C,D,uft))known[C]++,known[D]++;
  }
  for(int i=0;i<N;i++){printf("%d ",Size(i,uft)-known[i]-1);}
  return printf("\n"),0;
}

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

using namespace std;

const int N = 15;

vector <int> g[N];
int n;

int dfs(int u, int mask) {
	if ((1 << n) - 1 == mask) return 1;
	int ans = 0;
	for (int i = 0; i < (int)g[u].size(); i++) {
		int v = g[u][i];
		if (!(mask & (1 << v))) {
			mask |= (1 << v);
			ans += dfs(v, mask);
			mask &= ~(1 << v);                      
		}
	}
	return ans;
}

int main() {
	int m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		int x, y;
		scanf("%d %d", &x, &y);
		g[x - 1].push_back(y - 1);
		g[y - 1].push_back(x - 1);
	}
	int ans = dfs(0, 1);
	printf("%d\n", ans); 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<limits.h>
#define lli long long int
#define MAX 100005
using namespace std;

lli min(lli a, lli b)
{
	return a>b?b:a;
}

int main(void)
{
	lli i,j,n,k,a[MAX],s[MAX],mn;
	cin>>n>>k;
	if(n<=k)
	{
		s[0]=0;
		cin>>a[0];

		for(i=1;i<n;i++)
		{
			cin>>a[i];
			mn = INT_MAX;
			j=0;
			while(i-1-j>=0)
			{
				mn = min(mn, (s[i-1-j] + fabs(a[i] - a[i-1-j])));
				j++;
			}

			s[i]=mn;
		}

		cout<<s[n-1]<<endl;
	}
	else
	{
		s[0]=0;
		cin>>a[0];
		for(i=1;i<=k;i++)
		{
			cin>>a[i];
			mn = INT_MAX;
			j=0;
			while(i-1-j>=0)
			{
				mn = min(mn, (s[i-1-j] + fabs(a[i] - a[i-1-j])));
				j++;
			}

			s[i]=mn;
//			cout<<s[i] ;
		}

		for(i=k+1;i<n;i++)
		{
			cin>>a[i];
			mn = INT_MAX;
			j=0;
			while(j!=k)
			{
				mn = min(mn, (s[i-1-j] + fabs(a[i] - a[i-1-j])));
//				cout<<"j"<<j<<"mn = "<<mn<<endl;
				j++;
			}

			s[i]=mn;
//			cout<<s[i] ;
//			cout<<endl;
		}

		cout<<s[n-1]<<endl;

	}


	return 0;
}


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

namespace A_HEX
{
    class A_HEX
    {
        static void Main(string[] args)
        {
            string[] strIn = Console.ReadLine().Split(' ');

            int intX = 0;
            int intY = 0;

            switch (strIn[0])
            {
                case "A":
                    intX = 10;
                    break;
                case "B":
                    intX = 11;
                    break;
                case "C":
                    intX = 12;
                    break;
                case "D":
                    intX = 13;
                    break;
                case "E":
                    intX = 14;
                    break;
                case "F":
                    intX = 15;
                    break;
            }

            switch (strIn[1])
            {
                case "A":
                    intY = 10;
                    break;
                case "B":
                    intY = 11;
                    break;
                case "C":
                    intY = 12;
                    break;
                case "D":
                    intY = 13;
                    break;
                case "E":
                    intY = 14;
                    break;
                case "F":
                    intY = 15;
                    break;
            }

            if (intX > intY)
            {
                Console.WriteLine(">");
            }
            else if (intX < intY)
            {
                Console.WriteLine("<");
            }
            else if (intX == intY)
            {
                Console.WriteLine("=");
            }



        }
    }
}


Measured memory_bytes: 11092
h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]

ans = 0

for row_bin in range(2**h):
  for col_bin in range(2**w):
    cnt = 0
    for i in range(h):
      for j in range(w):
        if c[i][j] == '#' and ((row_bin >> i) & 1 and (col_bin >> j) & 1):
          cnt += 1
    if cnt == k:
      ans += 1

print(ans)

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  for(int i=1;i<101;i++){
    int as=a*i;
	if(as%b==c){
		cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

// 配列を用意し、インデックス0から順番に入力した値を入れていく
// 逆順に出力していく。

int main() {
	int n;
	int array[100];
	cin >> n;

	for (int i = 0; i < n; ++i) {
		cin >> array[i];
	}
	for (int i = n - 1; i >= 0; --i) {
		cout << array[i];
		if (i != 0) {
			cout << ' ';
		}
		else {
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
loop do
  h, w = gets.split.map(&:to_i)
  break if h==0 and w==0
  f = h.times.map{gets.chomp}
  hseq = Array.new(h){Array.new(w)}
  h.times.map{|y|
    hseq[y][0] = f[y][0]==?. ? 1 : 0
    (1...w).each{|x| hseq[y][x] = f[y][x]==?. ? hseq[y][x-1]+1 : 0}
  }
  ans = 0
  
  (w-1).downto(0){|x|
    h.times{|fy|
      tmp = w
      lim = h-fy
      (h-fy).times{|dy|
        tmp = [tmp, hseq[fy+dy][x]].min
        ans = [ans, tmp*(dy+1)].max
        break if tmp*lim<ans
      }
    }
  }
  p ans
end


Measured memory_bytes: 11392
# https://atcoder.jp/contests/arc097/tasks/arc097_b
# Pについてp_xとp_yでuniteしていくと、スワップできる集合が獲得できる
# 1,2,3...i...Nにできるかだが, iについてp_iとiがスワップできるかはunion-findで探せばよい


import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


class UnionFind:
    def __init__(self, N):
        self.N = N  # ノード数
        # 親ノードをしめす。負は自身が親ということ。
        self.parent = [-1] * N  # idxが各ノードに対応。

    def root(self, A):
        # print(A)
        # ノード番号を受け取って一番上の親ノードの番号を帰す
        if (self.parent[A] < 0):
            return A
        self.parent[A] = self.root(self.parent[A])  # 経由したノードすべての親を上書き
        return self.parent[A]

    def size(self, A):
        # ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。
        return -self.parent[self.root(A)]

    def unite(self, A, B):
        # ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
        # 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
        A = self.root(A)
        B = self.root(B)

        # すでにくっついている場合
        if (A == B):
            return False

        # 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較
        if (self.size(A) < self.size(B)):
            A, B = B, A

        # くっつける
        self.parent[A] += self.parent[B]  # sizeの更新
        self.parent[B] = A  # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる

        return True

    def is_in_same(self, A, B):
        return self.root(A) == self.root(B)


# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right


N, M = read_ints()
P = read_ints()
# P = [p - 1 for p in read_ints()]
uf = UnionFind(N + 1)
for _ in range(M):
    x, y = read_ints()
    uf.unite(P[x - 1], P[y - 1])

ans = 0
for i in range(1, N + 1):
    ans += uf.is_in_same(i, P[i - 1])

print(ans)


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

string s;
int f, l;

void solve();

int main() {
  f = l = -1;
  cin >> s;
  solve();
  cout << f << " " << l << endl;
  return 0;
}

void solve() {
  for(int i = 0; i < 26; ++i) {
    int bf = -1;
    for(int j = 0; j < s.size(); ++j) {
      if(s[j] == 'a' + i) {
        if(bf != -1 && j - bf <= 2) {
          f = bf + 1;
          l = j + 1;
          return;
        }
        bf = j;
      }
    }
  }
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)


def f(a, b):
    return (a, b) if a < b else (b, a)


def dfs(s, p):
    used = {}
    for t in g[s]:
        idx = rev[f(s, t)]
        if ans[idx] > 0:
            used[ans[idx]] = True 
    c = 1
    for t in g[s]:
        idx = rev[f(s, t)]
        if t == p or ans[idx] > 0:
            continue
        while c in used:
            c += 1
        ans[idx] = c
        c += 1
        dfs(t, s)
        

n = int(input())
g = [[] for _ in range(n)]
rev = {}
for i in range(n - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    g[a].append(b)
    g[b].append(a)
    rev[(a, b)] = i
ans = [0] * (n - 1)
dfs(0, -1)
print(max(ans), *ans, sep='\n')


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

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var input2 = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).OrderByDescending(n => n);

            var N = int.Parse(input[0]);
            var K = int.Parse(input[1]);

            Console.Write(input2.Take(K).Sum().ToString());
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;


set<int> s;

int main () {
    ios::sync_with_stdio(false);
    
    int v, n = 3;
    while (n--) {
        cin >> v;
        s.insert(v);
    }
    
    cout << s.size() << endl;
    
    
    
    return 0;
}

Measured memory_bytes: 256
//abc169_a.cpp
//Sun May 31 20:45:55 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	cout << a*b << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> p(m), y(m);
    for (int i = 0; i < m; i++) {
        cin >> p[i] >> y[i];
        p[i]--;
    }
    vector<vector<int>> vals(n);
    for (int i = 0; i < m; i++) vals[p[i]].push_back(y[i]);
    for (int i = 0; i < n; i++){
        sort(vals[i].begin(),vals[i].end());
    }
    for (int i = 0; i < m; i++){   
        int v = p[i];
        printf("%06d",v+1);
        int id = lower_bound(vals[v].begin(),vals[v].end(), y[i]) - vals[v].begin();
        printf("%06d\n",id+1);
    }
}

Measured memory_bytes: 7808
#include <iostream>
#include<string>
#include<math.h>
using namespace std;

int main(){
    int n,m;
    int time=0;
    int bre=1;
    int res[100005];
    string str[100005];
    int num[100005];
    cin>>n>>m;
    for(int i=0; i<n; i++){
        cin>>str[i]>>num[i];
    }
    while(bre){
        bre=0;
    for(int i=0; i<n; i++){
        if(num[i]==-1) continue;
       else if(num[i]<=m){
            time+=num[i];
            res[i]+=time;
            cout<<str[i]<<" "<<res[i]<<endl;
            num[i]=-1;
        }
        else {
            time+=m;
            num[i]=num[i]-m;
            bre=1;
        }
    }
    }
    return 0;
}

Measured memory_bytes: 6704
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int S = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());
        if(W >= S) {
            System.out.println("unsafe");
        }else {
            System.out.println("safe");
        }
    }
}

Measured memory_bytes: 35688
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

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

using namespace std;

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

#define MAX 200010

int V,E1,E2;
vector<int> G[2][MAX];
vector<int> FG[MAX];

class UnionFind {
public:
  vector<int> par;
  UnionFind(int n) {
    par.clear();
    rep(i,n) par.push_back(i);
  }
  int find(int x) {
    if( x == par[x] ) return x;
    return par[x] = find(par[x]);
  }
  void unit(int x,int y) {
    x = find(x), y = find(y);
    if( x != y ) par[x] = y;
  }
  bool same(int x,int y) {
    return find(x) == find(y);
  }
};

bool visited[MAX];
void dfs(int type,UnionFind &uf,int cur) {
  rep(i,(int)G[type][cur].size()) {
    int nex = G[type][cur][i];
    if( visited[nex] ) continue;
    visited[nex] = true;
    uf.unit(cur,nex);
    dfs(type,uf,nex);
  }
}


void compute() {
  UnionFind uf[2] = {UnionFind(V),UnionFind(V)};
  rep(i,2) {
    memset(visited,false,sizeof visited);
    rep(j,V) if( !visited[j] ) {
      visited[j] = true;
      dfs(i,uf[i],j);
    }
  }

  /*
  rep(i,2) {
    puts("");
    cout << i << "-th:" << endl;
    rep(j,V) {
      cout << "(" << j+1 << ": uf-id = " << uf[i].find(j) << ")" << endl;
    }
  }
  */
  map<ii,int> counter;
  rep(i,V) ++counter[ii(uf[0].find(i),uf[1].find(i))];
  rep(i,V) {
    if( i ) printf(" ");
    cout << counter[ii(uf[0].find(i),uf[1].find(i))];
  } puts("");
}

int main() {
  if( 0 ) {
    srand((unsigned int)time(NULL));
    int N = 20;
    int K = 10;
    int L = 10;
    cout << N << " " << K << " " << L << endl;
    set<ii> S;
    while( (int)S.size() < K ) {
      int s = rand() % N + 1;
      int t = rand() % N + 1;
      if( s == t ) continue;
      if( s > t ) swap(s,t);
      S.insert(ii(s,t));
    }
    for(auto v : S) cout << v.first << " " << v.second << endl;
    S.clear();
    while( (int)S.size() < L ) {
      int s = rand() % N + 1;
      int t = rand() % N + 1;
      if( s == t ) continue;
      if( s > t ) swap(s,t);
      S.insert(ii(s,t));
    }
    for(auto v : S) cout << v.first << " " << v.second << endl;
    return 0;
  }
  cin >> V >> E1 >> E2;
  int E[2] = {E1,E2};
  rep(i,2) {
    rep(j,E[i]) {
      int s,t;
      cin >> s >> t;
      --s, --t;
      G[i][s].push_back(t);
      G[i][t].push_back(s);
      FG[s].push_back(t);
      FG[t].push_back(s);
    }
  }
  compute();
  return 0;
}


Measured memory_bytes: 38008
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    int x,y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
//g++ -std=c++11 -Wall -O2 -o main.exe main.cpp
//g++ -std=c++14 -Wall -O2 -o main.exe main.cpp

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <tuple>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>

using namespace std;

#define spc " "
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p_ii;
typedef tuple<int, int, int, int> tup;

ll divc(ll a, ll b){ //割り算(切り上げ)
    return (a + b - 1) / b;
}

//------------------------------------------------------------------------------

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];

    vector<ll> dp(n);
    dp[0] = 0;
    dp[1] = llabs(h[1] - h[0]);

    for(int i = 2; i < n; i++){
        dp[i] += min(dp[i - 2] + llabs(h[i] - h[i - 2]), dp[i - 1] + llabs(h[i] - h[i - 1]));
    }

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

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main(void){
    long long l, r;
    cin >> l >> r;
    r = min(r, l+4038);
    int ans = 2018;
    for(long long i = l; i <= r; i++){
        for(long long j = i+1; j <= r; j++){
            int x = i*j%2019;
            ans = min(ans, x);
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define For(i,l,r)for(res i=(l),_=(r);i<=_;++i)
#define Dor(i,l,r)for(res i=(r),_=(l);i>=_;--i)
#define Sor(i,l,r)for(res i=(l),_=(r);i<_;++i)
#define ll long long
#define fz(a,b)memset(a,b,sizeof a)
#define N 100001
#define M 1000000007
char S[11];
map<string,int>P;
ll w;
int main() {
	int a;
	cin>>a;
	For(i,1,a){
		scanf("%s",S),sort(S,S+10);
		w+=P[S],P[S]++;
	}
	cout<<w;
}


Measured memory_bytes: 11136
n=int(input())
counter=0
l=input().split()
li=[int(i) for i in l]
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            lo=[li[i],li[j],li[k]]
            lo.sort()
            if(lo[0]+lo[1]>lo[2]):
                if(lo[0]!=lo[1] and lo[1]!=lo[2] and lo[2]!=lo[0]):
                    counter+=1
print(counter)


Measured memory_bytes: 68352
#include<stdio.h>
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
int n;
char t[200][200];
  
int main(){
  int d,D;
  int i,j;
  scanf("%d",&d);
    
  for(D=0;D<d;D++){
    if(D>0)printf("\n");
      
    scanf("%d",&n);
      
    for(i=0;i<=n+3;i++){
      for(j=0;j<=n+3;j++){
        if(i==0||j==0||i==n+3||j==n+3)t[i][j]='#';
        else t[i][j]=' ';
      }
    }
      
    int y=n+1,x=2,dir=0,cnt=1;
    while(1){
      while(1){
        t[y][x]='#';
        if(t[y+dy[dir]*2][x+dx[dir]*2]=='#')break;
        cnt++;
        y+=dy[dir];
        x+=dx[dir];
      }
      if(cnt<=1)break;
      dir=(dir+1)%4;
      cnt=0;
    }
      
    for(i=2;i<2+n;i++){
      for(j=2;j<2+n;j++){
        printf("%c",t[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

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

int main()
{
    int n, m;

    cin >> n >> m;

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

    if( n % 2 == 0 )
    {
        cout << 0;
        for( int i = 2; i < n / 2; i++ )
            cout << " " << 0;

        for( int i = n / 2 - 1; i < n; i++ )
            cout << " " << m;
    }
    else
    {
        cout << 0;
        for( int i = 1; i < n / 2; i++ )
            cout << " " << 0;

        for( int i = n / 2; i < n; i++ )
            cout << " " << m;
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 3116
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)

	ans := 0
	for i := 1; i <= n; i++ {
		str := strings.Split(strconv.Itoa(i),"")
		if len(str) % 2 != 0 {
			ans++
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
const ll mod=998244353;
int main()
{
	ll cou;
	scl(cou);
	int count=0;
	ll cc=100;
	while((long long)(cc*1.01)<cou){
		count++;
		cc*=1.01;
	}pf("%d\n",count+1);
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

const int MOD=1e9+7;
int D[100001][201];
bool chk[100001][201];
vector<int> S;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int N, X, t, ans=0;
	cin>>N>>X;
	S.resize(N);
	for(int i=0;i<N;i++) cin>>S[i];
	sort(S.begin(),S.end());
	t=N-(upper_bound(S.begin(),S.end(),X)-S.begin());
	D[X][t]=1;
	for(;X;X--) for(t=200;t>=0;t--) {
		if(D[X][t]==0) continue;
		for(int i=0;i<N && S[i]<=X;i++) {
			int p=upper_bound(S.begin(),S.end(),X)-upper_bound(S.begin(),S.end(),X%S[i])-1;
			D[X%S[i]][t+p]=(D[X%S[i]][t+p]+D[X][t])%MOD;
		}
		if(t) {
			D[X][t-1]=(D[X][t-1]+1LL*t*D[X][t])%MOD;
		}
	}
	for(int i=1;i<S[0];i++) ans=(ans+1LL*i*D[i][0])%MOD;
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 41216
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 1005;
const int mod = 998244353;


int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  ll n;
  cin>>n;
  string ret = "";
  while(n){
    ll tt = n % 26;
    if(tt==0)tt = 26;
    ret += 'a' + tt - 1;
    n = (n-tt)/26;
  }
  reverse(ret.begin(),ret.end());
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N;
	cin >> N;

	vector<pair<long long, long long>> target_info;

	for (int i = 0; i < N; i++)
	{
		long long A, B;
		cin >> A >> B;

		target_info.push_back(make_pair(A, B));
	}

	long long result = 0;

	for (int i = N - 1; i >= 0; i--)
	{
		pair<long long, long long> e = target_info[i];
		
		e.first += result;
		if (e.first % e.second != 0)
		{
			result += e.second - (e.first % e.second);
		}
	}

	cout << result;
	
	return 0;
}


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

int main() {
  string s;
  cin >> s;
  map<char, int> m;
  for (auto e : s) m[e]++;
  bool r = true;
  for (auto e : m) r = r && e.second == 2;
  cout << (r ? "Yes" : "No") << endl;
}


Measured memory_bytes: 764
def countingsort(arr,maximum):
    m = maximum + 100
    count = [0] * (m)
    for a in arr:
        count[a] += 1
    i = 0
    for a in range(m):
        for c in range(count[a]):
            arr[i] = a
            i += 1
    return arr

if __name__ == '__main__':
    N = int(input())
    l = list(map(int, input().split()))

    a = 0
    li = countingsort(l,N)
    for a in range(N-1):
        print(li[a], end=" ")
    print(li[N-1])



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

int main(void)
{
	int a, b;
	cin >> a >> b;
	cout << setprecision(5) << setiosflags(ios::fixed) << a / b << " " << a % b << " " << (double)a / b;
	return 0;
}

Measured memory_bytes: 1244
package main

import (
	"fmt"
)

func main() {
	var a,b int
	fmt.Scan(&a,&b)

	if a == b {
		fmt.Println("Draw")
	} else if a == 1 {
		fmt.Println("Alice")
	} else if b == 1{
		fmt.Println("Bob")
	} else if a > b {
		fmt.Println("Alice")
	} else {
		fmt.Println("Bob")
	}
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RES(a, n) (a).resize(n)
#define VLCIN(a, n) REP(i,n){cin >> a[i];}
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = (ll)pow(10,7);
/****** define constant end ********/
/****** define variable start ******/
ll n, k;
vl p, c;
/******* define variable end *******/

int solve() {
	cin >> n >> k;
	p.resize(n);
	c.resize(n);
	Graph G(n);
	REP(i, n){
		cin >> p[i];
	}
	REP(i, n){
		cin >> c[i];
	}
	REP(i, n){
		Edge e = {p[i]-1, c[p[i]-1]};
		G[i].push_back(e);
	}
	ll ans = -INF;
	REP(i, n){
		ll count = 0;
		ll ncost = 0;
		ll now_ite = i;
		ll ans_tmp = -INF;
		vector<bool> seen(n);
		seen[now_ite] = true;
		while(count < min(n, k)){
			count++;
			ncost += G[now_ite][0].cost;
			now_ite = G[now_ite][0].to;
			if(ncost > ans_tmp){
				ans_tmp = ncost;
			}
			if(seen[now_ite]) break;
			seen[now_ite] = true;
		}
			ll ans_tmp3 = ans_tmp;
			ll ans_tmp2 = ncost * (k / count);
			ll ans_tmp22 = ncost * (k / count - 1);
			ll count2 = count;
			ll count22 = count;
			count = 0;
			ncost = 0;
			ans_tmp = -INF;
			while(count < k % count2){
				count++;
				if(ncost > ans_tmp){
					ans_tmp = ncost;
				}
				ncost += G[now_ite][0].cost;
				now_ite = G[now_ite][0].to;
				if(ncost > ans_tmp){
					ans_tmp = ncost;
				}
			}
			if(ans_tmp > 0){
				ans_tmp2 += ans_tmp;
			}
			count = 0;
			ncost = 0;
			ans_tmp = -INF;
			while(count < k % count22 + count22){
				count++;
				if(ncost > ans_tmp){
					ans_tmp = ncost;
				}
				ncost += G[now_ite][0].cost;
				now_ite = G[now_ite][0].to;
				if(ncost > ans_tmp){
					ans_tmp = ncost;
				}
			}
			if(ans_tmp > 0){
				ans_tmp22 += ans_tmp;
			}
			if(k / count2 - 1 > 0){

				if(ans < max({ans_tmp2, ans_tmp3, ans_tmp22})){
					ans = max({ans_tmp2, ans_tmp3, ans_tmp22});
				}
			}else{

				if(ans < max(ans_tmp2, ans_tmp3)){
					ans = max(ans_tmp2, ans_tmp3);
				}
			}
	}
	cout << ans << endl;
	return 0;
}
int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll x;
    cin >> x;
    for(i = 0;i <= 200;++i){
        for(j = 0;j <= 200;++j){
            ll tmp1 = i*i*i*i*i + j*j*j*j*j;
            ll tmp2 = j*j*j*j*j - i*i*i*i*i;
            if(tmp1 == x){
                cout << j << " " << -i << endl;
                return 0;
            }else if(tmp2 == x){
                cout << j << " " << i << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

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

  int start = 1;
  for(int i=0;i<n;i++) {
    if(a[i] == start) {
      start++;
    }
  }

  if(start == 1) cout << -1 << endl;
  else cout << n - start + 1 << endl;
}

Measured memory_bytes: 1024
import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int N;
    int[] T, C;
    bool input() {
        scanf("%d\n", &N);
        if (N == 0) return false;
        T = new int[N];
        C = new int[N];
        foreach (i; 0 .. N) {
            scanf("%d %d\n", &T[i], &C[i]);
        }
        return true;
    }
    struct Swimmer {
        int time;
        int C;
    }
    struct S {
        int time;
        int which;
        Swimmer s;
    }
    void solve() {
        BinaryHeap!(Array!S, (x, y) => (x.time == y.time ? x.s.time > y.s.time : x.time > y.time)) PQ;
        foreach (i; 0 .. N) {
            PQ.insert(S(0, 0, Swimmer(T[i], C[i])));
        }
        int time0, time1;
        while (!PQ.empty) {
            S event = PQ.front; PQ.removeFront;
            //writeln(event);
            if (event.which == 0) {
                int ntime = max(time0, event.time + event.s.time);
                time0 = ntime;
                PQ.insert(S(ntime, 1, event.s));
            } else {
                int ntime = max(time1, event.time + event.s.time);
                time1 = ntime;
                event.s.C--;
                if (event.s.C == 0) continue;
                PQ.insert(S(ntime, 0, event.s));
            }
        }
        writeln(time1);
    }
    while (input) solve;
}

Measured memory_bytes: 1124
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

inline bool valid(int x, int n) {
    return 0 <= x && x < n;
}

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

template <typename T>
inline T pop(queue<T>& q) {
    T front = q.front();
    q.pop();
    return front;
}

template <typename T>
inline T gcd(T a, T b) {
    for (; b; a %= b, swap(a, b));
    return a; 
}

template <typename T>
tuple<T, T, T> xgcd(T a, T b) {
    if (b == 0) return {1, 0, a};
    T x, y, g;
    tie(x, y, g) = xgcd(b, a%b);
    return {y, x-(a/b)*y, g};
}

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

    int N; cin >> N;
    ll mod = 1e9 + 7;
    vll A(N+1); 
    for (int i = 1; i <= N; i++) cin >> A[i];
    vll psum(N+1);
    for (int i = 1; i <= N; i++) {
        psum[i] = psum[i-1] + A[i];
        psum[i] %= mod;
    }

    ll rst = 0;
    for (int i = 1; i <= N; i++) {
        ll sub = A[i] * ((psum[N] - psum[i] + mod) % mod) % mod;
        rst += sub;
        rst %= mod;
    }

    cout << rst;
}

Measured memory_bytes: 6272
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int A = scanner.nextInt();

    int[] x = new int[N + 1];
    for (int i = 1; i <= N; i++) x[i] = scanner.nextInt();

    long[][][] dp = new long[N + 1][N + 1][2501];
    for (int i = 0; i <= N; i++) dp[i][0][0] = 1;
    for (int i = 1; i <= N; i++) {
      for (int j = 1; j <= i; j++) {
        for (int k = 1; k <= 2500; k++) {
          dp[i][j][k] = dp[i - 1][j][k];
          if (k >= x[i]) dp[i][j][k] += dp[i - 1][j - 1][k - x[i]];
        }
      }
    }

    long count = 0;
    for (int j = 1; j <= N; j++) count += dp[N][j][A * j];
    System.out.println(count);
  }
}


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

int main(){
    int n;
    cin >> n;
    int a[200000];
    if(n%2==0){
        for(int i=0;i<n;i++){
            if(i%2==0)cin>>a[(n+i)/2];
            else cin>>a[(n-i)/2];
        }
    }
    else {
        for(int i=0;i<n;i++){
            if(i%2==0)cin>>a[(n-i)/2];
            else cin>>a[(n+i)/2];
        }
    }
    for(int i=0;i<n;i++)cout<<a[i]<<" "; 
}

Measured memory_bytes: 2944
import scala.io.Source
object Main {
  def binarySearch(arr: Array[Int], value: Int): Int = {
    var i = 0
    var j = arr.length
    var half = (i+j)/2
    while (i < j) {
      if (arr(half) >= value) j = half else i = half+1
      half = (i+j)/2
    }
    i
  }

  def main(args: Array[String]) = {
    val lines = Source.stdin.getLines
    val N = lines.next.toInt
    val A = lines.next.split(" ").map(_.toInt)
    val B = lines.next.split(" ").map(_.toInt)

    var res = 0
    for (i <- (0 to 29).reverse) {
      val (higher, lower) = (1<<(i+1), 1<<i)
      for (j <- 0 until N) {
        A(j) = A(j) % higher
        B(j) = B(j) % higher
      }
      java.util.Arrays.sort(B)
      var loc_sum = 0
      for (k <- 0 until N) {
        if (lower-A(k) >= 0) {
          loc_sum += binarySearch(B, higher-A(k)) 
          loc_sum -= binarySearch(B, lower-A(k))
        } else {
          loc_sum += binarySearch(B, higher-A(k))
          loc_sum += binarySearch(B, higher)
          loc_sum -= binarySearch(B, higher + lower - A(k))
        }
      }
      res += lower*(loc_sum&1)
    }
    println(res)
  }
}


Measured memory_bytes: 95468
import Data.List
import Data.Char
import Data.Maybe
import qualified Data.ByteString.Char8 as BS8
 
main :: IO ()
main = do
    [a, b, c] <- unfoldr (BS8.readInt . BS8.dropWhile isSpace) <$> BS8.getLine

    print $ if (a - b) >= c
        then 0
        else c - (a - b)


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
  ll n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
         cin>>a[i];
    }
    int j=1;
    int ans=0;
    vector<int> v,vis(n+1,0);
    v.pb(1);
    vis[1]=1;
    for(int i=1;i<=n;i++)
    {
         ans=a[j];
         if(vis[ans])
          {
               v.pb(ans);
               break;
          }
         v.pb(ans);
         vis[ans]=1;
         j=a[j];
    }
    int sz=v.size();
    int pp=0;
    for(int i=0;i<v.size();i++)
     {
          if(v[i]!=v[sz-1])
               pp++;
          else
               break;
     }
     v.pp();
     if(k<=pp)
     {
          cout<<v[k]<<e;
     }
     else{
          k-=pp;
          k%=(sz-1-pp);
          cout<<v[pp+k]<<e;
     }

}


Measured memory_bytes: 5808
#include <iostream> 
using namespace std; 
int main() {
  long long n;
  long m; 
  cin >> n >> m; 
  long total = 0; 
  long x; 
  for (long _ = 0; _ < m; _ ++) {
    cin >> x; 
    total += x; 
  }
  if (total > n) 
    cout << -1 << '\n'; 
  else
    cout << n - total << '\n'; 
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>

using namespace std;

unsigned long long int gcd(unsigned long long int a, unsigned long long int b)
{
	if(a % b == 0)
	{
		return(b);
	}
	else
	{
		gcd(b, a % b);
	}
}

unsigned long long int lcm(unsigned long long int a, unsigned long long int b)
{
	return(a * b / gcd(a, b));
}

void solve()
{
	unsigned long long int a[3], m[3];
	while(cin >> a[0] >> m[0] >> a[1] >> m[1] >> a[2] >> m[2], a[0] || m[0] || a[1] || m[1] || a[2] || m[2])
	{
		unsigned long long int count[3] = {0, 0, 0};
		unsigned long long int x[3] = {1, 1, 1};
		for(int i = 0; i < 3; ++i)
		{
			while(true)
			{
				count[i]++;
				x[i] = (x[i] * a[i]) % m[i];
				if(x[i] == 1)
				{
					break;
				}
			}
		}
		sort(count, count + 3);
		unsigned long long int d = lcm(count[1], count[0]);
		unsigned long long int Answer;
		d > count[2] ? Answer = lcm(d, count[2]) : Answer = lcm(count[2], d);
		cout << Answer << endl;
	}
}

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

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

int main() {
	char map[2][3];
	int pair_[] = { 2,1,0 };
	for (int i = 0; i < 2; ++i) {
		for (int i2 = 0; i2 < 3; ++i2) {
			cin >> map[i][i2];
		}
	}
	bool flg = true;
	for (int i = 0; i < 3; ++i) {
		if (map[0][i] != map[1][pair_[i]]) {
			flg = false;
			break;
		}
	}

	if (flg) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }

	return 0;
}


Measured memory_bytes: 256
/** author: __nishad__ **/

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


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a) for(int i=0; i<a;i++)
#define loop2(i,a,b) for(int i=(a);i<=(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    int n, sum=0, i;
    vector<int> v;
    cin>>n;

    for(i=0; i<n; i++){
        int x;
        cin>>x;
        v.push_back(x);
    }

    sort(all(v));

    for(i=0; i<n; i++){
        if(i%2 == 0)
            sum = sum + v[i];
        else
            sum = sum - v[i];
    }

    cout<<abs(sum);



}


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

int main() {
  int N;
  cin >> N;
  string str = to_string(N);
  int ans = 0;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == '2') ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:TYPE();}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:TYPE();}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=105;

int n,m,a[MAXN][MAXN],f[MAXN][MAXN];
char str[MAXN];

int main()
{
	readint(n),readint(m);
	for(int i=1;i<=n;++i)
	{
		scanf("%s",str+1);
		for(int j=1;j<=m;++j)a[i][j]=(str[j]=='#');
	}
	f[1][1]=a[1][1];
	for(int j=2;j<=m;++j)f[1][j]=f[1][j-1]+(a[1][j] && !a[1][j-1]);
	for(int i=2;i<=n;++i)
	{
		f[i][1]=f[i-1][1]+(a[i][1] && !a[i-1][1]);
		for(int j=2;j<=m;++j)
			f[i][j]=min(f[i-1][j]+(a[i][j] && !a[i-1][j]),f[i][j-1]+(a[i][j] && !a[i][j-1]));
	}
	printf("%d\n",f[n][m]);
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int q = n / 100;
  int r = n % 100;
  if(q * 5 >= r){
    cout << 1 << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    vector<int> A(N+1, 0);

    rep(i, N+1) {
        cin >> A[i];
    }

    ll leaf_sum = 0;
    vector<ll> max_leaf(N+1);
    reprev(i, N+1) {
        leaf_sum += A[i];
        max_leaf[i] = leaf_sum;
    }
    /*
    if (A[0] > 0) {
        cout << -1 << endl;
        return 0;
    }
    */
    if (N == 0 && A[0] != 1) {
        cout << -1 << endl;
        return 0;
    }
    if (N != 0 && A[0] > 0) {
        cout << -1 << endl;
        return 0;
    }
    

    ll ans = 1;
    ll cn = 1;
    repr(i, 1, N+1) {
        cn = min(cn*2, max_leaf[i]);
        
        ans += cn;
        cn -= A[i];
        
        if ((i < N) && (cn <= 0)) {
            cout << -1 << endl;
            return 0;
        }
    }
    
    if (cn < 0) {
        cout << -1 << endl;
        return 0;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main()
{
    int k, s;
    cin >> k >> s;
    int count = 0;
    for (int x = 0; x <= k; x++)
    {
        for (int y = 0; y <= k; y++)
        {
            if (s - x - y >= 0 && s - x - y <= k)
                count++;
        }
    }
    cout << count;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
  int n, a, i, j, x;
  int y[8] = {};
  int z = 0;
  int min = 0;
  int max = 0;
 
  scanf("%d", &n);
  for(i = 0; i < n; i++)
  {
    scanf("%d", &a);
    x = a / 400;
    if(x < 8)
    {
      y[x]++;
    }
    else if(x >= 8)
    {
      z++;
    }
  }
  for(j = 0; j < 8; j++)
  {
    if(y[j] > 0)
    {
      min++;
    }
  }
  max = min + z;
  if(min == 0)
  {
    min = 1;
  }
  printf("%d %d", min, max);
  return 0;
}

Measured memory_bytes: 128
import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
    std.typecons, std.math, std.container, std.format;

void main(string[] args)
{
    long n;
    readf("%d\n", &n);

    if (n % 2 == 1)
    {
        writeln(0);
    }
    else
    {
        long count = 0;
        n /= 2;
        for (long i = 5; n / i >= 1; i *= 5)
        {
            count += n / i;
        }
        writeln(count);
    }

}


Measured memory_bytes: 256
#include <stdio.h>
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a < b ? b : a)
#define INF 2e9 
int main(){
int N,i,res = -INF,x,y = INF;
scanf("%d",&N);
for(i = 0 ; i < N ; i++){scanf("%d",&x); res = max(res,x-y); y = min(x,y); } printf("%d\n",res);
return 0;
} 


Measured memory_bytes: 2104