akhauriyash/Code-Regression huggingface dataset:
fn :: Int -> Int
fn x
    | even x = x `div` 2
    | otherwise = 3 * x + 1

solve :: [Int] -> Int
solve x
    | next `elem` x = 1 + length x
    | otherwise = solve (x ++ [next])
    where next = fn $ last x

main :: IO ()
main = do
    s <- readLn :: IO Int
    print $ solve [s]

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

#define ll long long int
#define maxn 1000001

vector<int> gph[1000001];
vector<int> rev_gph[1000001];
vector<bool> visited(1000001);
int ans[1000001];
vector<int> toposort;

void dfs(int u){
    visited[u] = true;
    for(vector<int> :: iterator it = gph[u].begin();it!=gph[u].end();++it){
        if(!visited[*it]){
            dfs(*it);
        }
    }
    toposort.push_back(u);
}

int main(){
    int n,m,a,b;
    cin>>n>>m;
    while(m--){
        cin>>a>>b;
        gph[a].push_back(b);
        rev_gph[b].push_back(a);
    }
    for(int i=0;i<=n;i++){
        ans[i] = 0;
        visited[i] = false;
    }
    for(int i=1;i<=n;i++){
        if(!visited[i]){
            dfs(i);
        }
    }
    /*
    for(int i=0;i<toposort.size();i++){
        cout<<toposort[i]<<" ";
    }
    */
    reverse(toposort.begin(),toposort.end());
    for(int i=0;i<toposort.size();i++){
        int val = toposort[i];
        for(int j=0;j<rev_gph[val].size();j++){
            ans[val] = max(ans[val],ans[rev_gph[val][j]]+1);
        }
    }
    int f_ans = INT_MIN;
    for(int i=1;i<=n;i++){
        f_ans = max(f_ans,ans[i]);
    }
    cout<<f_ans<<endl;
}



Measured memory_bytes: 58496
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int n, k;

int main(){
	cin >> n >> k;
	
	if(k == 1) cout << 0 << endl;
	else cout << max(0, n-k) << endl;
	
	return 0;
}

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

int main() {
    int N; cin >> N;
    int light = 1;
    int arr[N];
    int ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }
    for (int i = 0; i < N; i++) {
        if (light == 2) {
            cout << ans << endl;
            return 0;
        }
        light = arr[light - 1];
        ans++;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 4024
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <functional>
#include <stdio.h>
#include <sstream>

using namespace std;

int main()
{
	int n,max,min;
	string str,str2;

	cin>>n;

	for(int i=0;i<n;i++){
		cin>>str;
		str2=str;

		sort(str.begin(),str.end(),greater<int>());
		sort(str2.begin(),str2.end());

		stringstream ss,ss2;
		int min,max;

		ss<<str; ss>>max;
		ss2<<str2; ss2>>min;

		cout<<max-min<<endl;

	}


	return 0;

}

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

int h(int x){
  int n=0;
  while(x){
    n++;
    x/=2;
  }
	return n;
}
  
int main(){  
  int N,K;
  cin>>N>>K;
  int ans=1;
  for(int i=0;i<min(N,h(K));i++){
    ans*=2;
  }
  for(int i=0;i<N-h(K);i++){
    ans+=K;
  }
  cout<<ans<<endl;
}


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

class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var t = Console.ReadLine().Split().Select(int.Parse).ToList();
        var m = int.Parse(Console.ReadLine());

        for (var i = 0; i < m; i++)
        {
            var strs = Console.ReadLine().Split().Select(int.Parse);
            var p = strs.ElementAt(0);
            var x = strs.ElementAt(1);
            var ans = t.Sum() - t[p - 1] + x;
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13396
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	private static double[] getLine(double x1, double y1, double x2, double y2){
		double[] ans = new double[3];
		double mid_x = (x1 + x2) / 2;
		double mid_y = (y1 + y2) / 2;
		ans[0] = y1 - y2;
		ans[1] = x1 - x2;
		ans[2] = - mid_y * (y1 - y2) - mid_x * (x1 - x2);
		return ans;
	}

	public static void main(String[] args){
		List<Double> listX = new ArrayList<Double>();
		List<Double> listY = new ArrayList<Double>();
		List<Double> listR = new ArrayList<Double>();
		double[] pt = new double[6];
		int n = scan.nextInt();
		for(int i = 0; i < n; i++){
			for(int j = 0; j < 6; j++){
				pt[j] = scan.nextDouble();
			}
			double[] l1 = getLine(pt[0], pt[1], pt[2], pt[3]);
			double[] l2 = getLine(pt[0], pt[1], pt[4], pt[5]);

			double x = (l1[0] * l2[2] - l1[2] * l2[0]) / (l1[1] * l2[0] - l1[0] * l2[1]);
			double y;
			if(l1[0] != 0){
				y = (l1[1] * x + l1[2]) / - l1[0];
			} else{
				y = (l2[1] * x + l2[2]) / - l2[0];
			}
			double r = Math.sqrt(Math.pow(x - pt[0], 2) + Math.pow(y - pt[1], 2));

			listX.add(x);
			listY.add(y);
			listR.add(r);
		}

		Iterator<Double> itX = listX.iterator();
		Iterator<Double> itY = listY.iterator();
		Iterator<Double> itR = listR.iterator();
		while(itX.hasNext()){
			double x = itX.next();
			double y = itY.next();
			double r = itR.next();
			System.out.printf("%.3f %.3f %.3f\n", x, y, r);
		}
	}
}

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

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

using namespace std;
//エイリアス
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

//定数
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 1e9 + 7;
const double pi = M_PI;

int main()
{
  char c;
  cin >> c;
  if (isupper(c)) {
    cout << "A" << endl;
  } else {
    cout << "a" << endl;
  }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

llong f(llong l,llong r,llong num){
	return (l+r)*num/2;
}

int main(){
	int n,k;
	cin>>n>>k;
	
	llong ans=0;
	for(int i=k;i<=n+1;++i){
		llong cnt=(f(n-i+1,n,i)-f(0,i-1,i)+1)%MOD;
		//debug(cnt);
		ans=(ans+cnt)%MOD;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
 
#define INF 1234567890
#define ll long long

int N, K;
int A[200201], fen[200201], B[200201];

int Sum(int idx)
{
	int ret = 0;
	while(idx) {ret += fen[idx]; idx &= (idx-1); }
	return ret;
}

void Add(int idx, int val)
{
	while(idx <= 200000) {fen[idx] += val; idx += idx&-idx; }
}

int main()
{
	scanf("%d %d", &N, &K);
	for(int i=1; i<=N; i++)
		scanf("%d", &A[i]);

	while(K--)
	{
		for(int i=1; i<=N; i++)
			B[i] = 1;

		memset(fen, 0, sizeof(fen));
		for(int i=1; i<=N; i++)
		{
			B[i] += (i-1) - Sum(i-1);
			Add(min(200000, A[i]+i), 1);
		}

		memset(fen, 0, sizeof(fen));
		for(int i=N; i>=1; i--)
		{
			B[i] += Sum(i);
			Add(max(1, i-A[i]), 1);
		}

		memcpy(A, B, sizeof(A));

		int die = 1;
		for(int i=1; i<=N; i++)
			if (A[i] != N)
			{
				die = 0;
				break;
			}
		if (die) break;
	}
	for(int i=1; i<=N; i++)
		printf("%d ", A[i]);
	return 0;
}

Measured memory_bytes: 6156
#include <iostream>
#include<stdio.h>
#include<string>
using namespace std;

int main()
{
	int n, q, nk=0,  goukei = 0;
	cin >> n;
	int s[100000], t[50000];
	for (int i = 0; i < n; i++)
	{
		cin >> s[i]; if (s[i] == s[i - 1]) {
			i--;
			n--;
		}
	}
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		cin >> t[i];
	}
	for (int i = 0; i < q; i++)
	{
		int right = n-1, left = 0,count=0;
		while (left < right) {
			nk = right + left + count % 2 * 2;; nk /= 2;
			
			if (s[nk] > t[i]) {
				if (right == nk) { count++; if (count == 2) { break; } }
				else { count = 0; }
				right = nk;
			}
			else if (s[nk] == t[i])
			{
				goukei++;  break;
			}
			else {
				if (left == nk) { count++; if (count == 2) { break; } }
				else { count = 0; }
				left = nk ; 
			}
		}
	}
	cout << goukei+1 << endl;
	return 0;
}

Measured memory_bytes: 3448
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int n, k; cin >> n >> k;
	vector<Int> a(n);
	for(auto &i:a) cin >> i;
	for(Int i=0; i<k; ++i){
		vector<Int> b(n+1);
		for(Int j=0; j<n; ++j){
			b[max(Int(0), j-a[j])]++;
			b[min(n, j+a[j]+1)]--;
		}
		for(Int j=1; j<n; ++j)
			b[j] += b[j-1];
		bool f = true;
		for(Int j=0; j<n; ++j){
			a[j] = b[j];
			if(a[j] < n) f = false;
		}
		if(f) break;
	}
	for(Int i=0; i<n; ++i)
		cout << a[i] << " \n"[i+1==n];
}

Measured memory_bytes: 6368
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a,b,c;
	cin >> a >> b >> c;
	set<int> s;
	s.insert(a),s.insert(b),s.insert(c);
	cout << s.size();
	return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 2019;
const ll INF = (ll) 1e15;

ll modpow(ll n, ll p, ll mod) {
    ll ret = 1;
    ll r = n;
    while (p > 0) {
        if ((p & 1) == 1) {
            ret = ret * r % mod;
        }
        r = r * r % mod;
        p >>= 1;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll N = S.length();
    ll sum = 0;
    ll ans = 0;
    map<ll, ll> m;
    m[0]++;
    REP(i, N) {
        ll p = modpow(10, N - i, MOD);
        sum = (sum * 10LL + S[i] - '0') % MOD;
        ll t = sum * p % MOD;
        ans += m[t];
        m[t]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3760
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    sa = sum(a)
    if sa%(n*(n+1)//2) != 0:
        print("NO")
        exit()
    t = sa//(n*(n+1)//2)
    d = [a[i]-a[i-1] for i in range(n)]
    at = 0
    for i in d:
        if (t-i)%n != 0 or (t-i)//n < 0:
            print("NO")
            exit()
        at += (t-i)//n
    if at == t:
        print("YES")
    else:
        print("NO")

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 92632
N = int(input())
S = input()

C = [0]*3
for i in range(N):
    c = "RGB".index(S[i])
    C[c]+=1

K = 0
for i in range(N-2):
    for j in range(i,N):
        k = 2*j-i
        if k>=N:break
        if len(set([S[i],S[j],S[k]]))==3:
            K+=1
print(C[0]*C[1]*C[2]-K)


Measured memory_bytes: 68488
#include<bits/stdc++.h>
using namespace std;
int main() {
  int H, N;
  cin >> H >> N;
  vector<int> A(N), B(N);
  for(auto i=0; i<N; ++i) cin >> A[i] >> B[i];
  vector<int> memo(H+1);
  function<int(int)> dfs = [&](auto h) {
    if(h <= 0) return 0;
    if(memo[h]) return memo[h];
    int res = 1e9;
    for(auto i=0; i<N; ++i) res = min(res, B[i]+dfs(h-A[i]));
    return memo[h] = res;
  };
  cout << dfs(H) << endl;
}


Measured memory_bytes: 4556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

double a,b,h,m;

int main(void){
	cin>>a>>b>>h>>m;
	cout<<fixed<<setprecision(15)<<sqrt(pow(a*cos((h*60+m)/720*M_PI*2)-b*cos(m/60*M_PI*2),2)+pow(a*sin((h*60+m)/720*M_PI*2)-b*sin(m/60*M_PI*2),2))<<endl;
	return 0;
}

Measured memory_bytes: 4256
#include <stdio.h>

int main(){
  int X,Y,Z;
  scanf("%d %d %d",&X,&Y,&Z);
  int T;
  T=X;
  X=Z;
  Z=Y;
  Y=T;
  printf("%d %d %d\n",X,Y,Z);
  return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
int main() {
    int n,m;
    string w;
      tuple<string,int,int> t;
    vector<tuple<string,int,int>> l;
    cin>>n;
    rep(i,n){
        cin>>w>>m;
        t=make_tuple(w,-m,i+1);
        l.push_back(t);
    }
    sort(all(l));
    rep(i,n){
        cout<< get<2>(l.at(i)) <<endl;
    }


    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = [str(input()) for i in range(N)]
M = int(input())
T = [str(input()) for i in range(M)]

S_set = {s:0 for s in S}
T_set = {t:0 for t in T}
for s in S:
  S_set[s] += 1
for t in T:
  T_set[t] += 1

  
ans = 0
for s in S_set.keys():
  if s in T_set.keys():
    pool = S_set[s] - T_set[s]
  else:
    pool = S_set[s]
  if pool > ans:
    ans = pool
print(ans)

Measured memory_bytes: 3064
from collections import deque

K=int(input())

num_str=[str(i) for i in range(10)]

numbers=deque()
for i in range(1,len(num_str)):
    numbers.append((i,num_str[i]))

times=0
while numbers:
    times+=1
    if times==K:
        break
    else:
        num=numbers.popleft()
        for i in range(3):
            index=num[0]-1+i
            if index>=0 and index<10:
                numbers.append((num[0]-1+i,num[1]+num_str[num[0]-1+i]))


print(numbers.popleft()[1])

Measured memory_bytes: 34588
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	LL n, k;
	while(cin >> n >> k) {
		vector<LL> dp(k+1);
		LL ans = 0;
		REP(x, k) {
			if(x > n) continue;
			if(3*x%k == x) {
				LL cnt = 0;
				if(x == 0) {
					cnt += n/k;
				} else {
					cnt += (n-x)/k + 1;
				}
				ans += cnt * cnt * cnt;
				DEBUG(x); DEBUG(cnt);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,m; cin>>n>>m;
    vector<vector<int>> path(n);
    rep(i,m){
        int u,v; cin>>u>>v;
        u--; v--;
        path[u].push_back(v);
    }
    int s,t,p,P; cin>>s>>t;
    s--; t--;
    vector<int> dis(n,-1);
    vector<vector<int>> visited(2,vector<int>(n,0));
    dis[s]=0;
    queue<int> que;
    que.push(s);
    while(!(que.empty())){
        p=que.front();
        que.pop();
        vector<queue<int>> q(2);
        for(auto to:path[p]){
            if(visited[0][to]) continue;
            visited[0][to]=1;
            q[0].push(to);
        }
        while(!(q[0].empty())){
            P=q[0].front();
            q[0].pop();
            for(auto to:path[P]){
                if(visited[1][to]) continue;
                visited[1][to]=1;
                for(auto TO:path[to]){
                    if(dis[TO]==-1){
                        dis[TO]=dis[p]+1;
                        que.push(TO);
                    }
                }
            }
        }
    }
    cout<<dis[t]<<endl;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<long long> a(3 * n);
  rep(i, 3 * n) cin >> a[i];

  sort(a.begin(), a.end(), greater<long long>());

  long long ans = 0;
  for (int i = 1; i < 2 * n; i += 2) 
    ans += a[i];

  cout << ans << endl;

  return 0;
}


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

namespace ConsoleApplication52
{
    class Program
    {
        static void Main()
        {
            
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] b = new int[a[0]];
            for(int c = 0; c < a[0]; c++)
            {
                b[c] = int.Parse(Console.ReadLine());
            }               
            for(int d = 1; d <= a[1]; d++)
            {
                int e = 0, f = 0;
                for(e=0;e<a[0]-1;e++)
                {
                    if (b[e] % d > (b[e + 1] % d))
                    {
                        f = b[e];b[e] = b[e + 1];b[e+1] = f;
                    }
                }
            }
            foreach (int m in b)
            {
                Console.WriteLine(m);
            }
        }
    }
}

Measured memory_bytes: 9592
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main()
	{
		int N = GetInt();
		int x = GetInt();

		if((x == 1) || (x == 2 * N - 1))
		{
			Console.WriteLine("No");
			return;
		}
		Console.WriteLine("Yes");

		int[] ans = new int[2 * N - 1];
		bool[] used = new bool[2 * N];
		for(int i = -1; i <= 1; i++)
		{
			ans[N - 1 + i] = x + i;
			used[x + i] = true;
		}

		int num = 1;
		for(int i = 0; i < 2 * N - 1; i++)
		{
			if(ans[i] != 0)
				continue;

			while(used[num])
				num++;

			ans[i] = num;
			used[num] = true;
		}

		Console.WriteLine(string.Join("\n", ans.Select(a => a.ToString()).ToArray()));
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


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

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

    int n,k; cin>>n>>k;
    vector<int> p(n);
    for(int i=0; i<n; ++i)
    {
        cin>>p[i];
    }
    sort(begin(p), end(p));
    int ans=0;
    for(int i=0; i<k; ++i)
    {
        ans+=p[i];
    }
    cout << ans << "\n";
}

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


using namespace std;



int main(){
    int N;
    long long mn = 1000000;
    cin >> N;
    vector<int> X(N);
    for(int i = 0; i < N; i++){
        cin >> X.at(i);
    }
    for(int i = 1; i < 100000; i++){
        long long ans = 0;
        for(int j = 0; j < N; j++){
            ans += pow((X.at(j) - i), 2) ;
            
        }
        if(ans < mn) mn = ans;
    }

    cout << mn << endl;
    
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,r[30],ans=1;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
		char c;
		scanf(" %c",&c);
		r[c-'a']++;
	}
	for(int i=0;i<='z'-'a';i++)ans=ans*(r[i]+1LL)%M;
	printf("%lld\n",(ans+M-1)%M);
}


Measured memory_bytes: 256
//
//  main.cpp
//  c
//
//  Created by 13B10694 on 2015/06/01.
//  Copyright (c) 2015????´ 13B10694. All rights reserved.
//

#include <iostream>
#include <vector>
#include<stdio.h>
#include <algorithm>
#include<string.h>
using namespace std;

int now=1;

class team{
    
public:
    int id, pen, sol;
    int wrong[12];
    vector <int> solved;
    team(){
        memset(wrong, 0, sizeof(wrong));
        id=now++;
        pen=0;sol=0;
    }
//    ~team(){
//        solved.clear();
//    }
    
    bool operator < (const team& b) const
    {
        return solved.size()==b.solved.size() ? pen== b.pen ? id<b.id : pen<b.pen : solved.size()>b.solved.size();
    }
};

int main() {
    int t,p,r;
    while(cin>>t>>p>>r,t){
        now=1;
        vector<team> tea(t);

        for(int i=0;i<r;i++){
            int ti, pi, tim;
            string mes;
            cin>>ti>>pi>>tim>>mes;
            ti-=1;
            if(mes=="WRONG"){
                tea[ti].wrong[pi]++;
                continue;
            }
            if(find(tea[ti].solved.begin(),tea[ti].solved.end(),pi)!=tea[ti].solved.end()){
                continue;
            }
            tea[ti].solved.push_back(pi);
            tea[ti].pen += tea[ti].wrong[pi]*1200+tim;
  
        }
        sort(tea.begin(),tea.end());
        for(int i=0;i<t;i++){
            cout<<tea[i].id<<" "<<tea[i].solved.size()<<" "<<tea[i].pen<<endl;
        }
       // tea.clear();
    }
    
    return 0;
}

Measured memory_bytes: 1252
n=int(input())
s=input()
r=0
g=0
b=0
for i in s:
    if i=="R":r+=1
    elif i=="G":g+=1
    elif i=="B":b+=1
ans=r*b*g

for j in range(n):
    for i in range(j):
        k=j+(j-i)
        if k<n:
            
            if s[i]==s[j]: continue
            if s[j]==s[k]: continue
            if s[k]==s[i]: continue
            ans-=1
print(ans)

Measured memory_bytes: 9216
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int K, X;
	cin >> K >> X;

	eFOR(i, X - K + 1, X + K - 1) {
		cout << i;
		if (i != X + K - 1) {
			cout << " ";
		}
		else {
			cout << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		long[] sums = new long[n];
		sums[0] = in.nextLong();
		for(int i=1;i<n;i++) {
			sums[i] = sums[i-1] + in.nextLong();
		}
		long min = Long.MAX_VALUE;
		int left = 0;
		int right = 2;
		for(int i=1;i<=n-2;i++) {
			left = cutLeft(sums,left,i);
			right = cutRight(sums,i,right,n-1);
			long absdif = getAbsoluteDifference(sums[left], sums[i]-sums[left], sums[right]-sums[i], sums[n-1]-sums[right]);
			if(absdif<min) min = absdif;
		}
		System.out.println(min);
	}
	
	public static int cutLeft(long[] sums,int left,int end) {
		long dif = abs(sums[end]-sums[left],sums[left]);
		while(left<end-1) {
			long newDif = abs(sums[end]-sums[left+1],sums[left+1]);
			if(newDif<dif) {
				dif = newDif;
				left++;
			}else {
				break;
			}
		}
		return left;
	}
	
	public static int cutRight(long[] sums,int i,int right,int end) {
		long dif = abs(sums[end]-sums[right],sums[right]-sums[i]);
		while(right<end-1) {
			long newDif = abs(sums[end]-sums[right+1],sums[right+1]-sums[i]);
			if(newDif<dif) {
				dif = newDif;
				right++;
			}else {
				break;
			}
		}
		return right;
	}
	
	public static long abs(long a,long b) {
		if(a>b) return a-b;
		return b-a;
	}
	
	public static long getAbsoluteDifference(long cut1,long cut2,long cut3,long cut4) {
		long min = Math.min(Math.min(cut1, cut2), Math.min(cut3, cut4));
		long max = Math.max(Math.max(cut1, cut2), Math.max(cut3, cut4));
		return max - min;
	}

}


Measured memory_bytes: 80076
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
 
n = ni()
grid = []
 
for _ in range(n):
    s = ns()
    s = s+s
    grid.append(s)
    
for i in range(n):
    grid.append(grid[i])
    
vert = []
hrzn = []
 
for i in range(2*n):
    hrzn.append(grid[i])
    
for j in range(2*n):
    temp = ""
    for i in range(2*n):
        temp += grid[i][j:j+1]
        
    vert.append(temp)
    
    
ans = 0
 
for a in range(n):
    for b in range(1):
        
        ok = True
        for i in range(n-1):
 
            if vert[b+i][a+i:a+n] != hrzn[a+i][b+i:b+n]:
                ok = False
                break
                
        if ok:
            ans += 1
            
print(ans*n)

Measured memory_bytes: 3700
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = unsigned long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
int const mod = 1e9+7;
#define END {cout<<(ans)<<'\n'; return 0;}
#define ALL(vec) vec.begin(),vec.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,s,n) for(int i=s; i<n; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,(n)-1)cout<<a[i]<<' '; cout<<a[(n)-1]<<'\n';
#define prip(p) cout<<(p).first<<' '<<(p).second<<'\n'
template<class T> inline bool cmin(T& a, T b) { if (a > b) { return a = b; } return false; }
template<class T> inline bool cmax(T& a, T b) { if (a < b) { return a = b; } return false; }

int n,m,q,_,x,y;
string s,sb;
bool ok;
char ch;

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

  cin>>n; unordered_map<int,bool>a;
  rep(i,n){cin>>x; a[x]=1;}
  cin>>m; int ans=0;
  rep(i,m){cin>>x; ans+=a[x];}
  END
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
int main() {
int H, W; 
cin >> H >> W; 
char C[123][123] = {'0'}; 
int A[123] = {0}, B[123] = {0}; 
for (int i = 1; i <= H; i++){
  for (int j = 1; j <= W; j++){
cin >> C[i][j]; 
if(C[i][j] == '#') {A[i] ++; 
B[j] ++; 
}
}
}
for (int i = 1; i <= H; i++){
if(A[i] != 0){
for (int j = 1; j <= W; j++){
if(B[j] != 0){
cout << C[i][j]; 
}
}
cout << endl; 
}
}
}


Measured memory_bytes: 256
n=int(input())
xyh=[list(map(int,input().split()))[::-1]for _ in range(n)]
xyh.sort(reverse=1)
for xx in range(101):
  for yy in range(101):
    f=True
    hh=xyh[0][0]+abs(xx-xyh[0][2])+abs(yy-xyh[0][1])
    for h,y,x in xyh[1:]:
      if max(hh-abs(x-xx)-abs(y-yy),0)!=h:f=False
    if f:print(xx,yy,hh);exit()

Measured memory_bytes: 3064
#include <stdio.h>
int main(void)
{
  int a, b;
  int ret;
  ret = scanf("%d %d", &a, &b);

  if( ret < 2)
    return -1;
  else
    if( (a*b)%2 == 0 )
    	printf("%s", "Even");
    else
    	printf("%s", "Odd");
  
  return 0;
}

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


using namespace std;


int main(){
    vector<int> vec(3);

    for(int i=0;i<3;i++){
        cin>>vec[i];
    }

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

    int ans = vec[0]+(vec[1]+10*vec[2]);

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
import Data.List

data YesNo = Yes | No deriving(Show)

necklace :: String -> String
necklace [] = []
necklace (x:xs) = xs ++ [x]

solver :: String -> String -> Int -> Int -> YesNo
solver s p c n
  | c >= n = No
  | otherwise =
    let s' = necklace s
    in
        if p `isPrefixOf` s'
          then Yes
        else
          solver s' p (c+1) n

main :: IO()
main = do
  s <- getLine
  p <- getLine
  print $ solver s p 0 (length s)

Measured memory_bytes: 3996
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}

	sort.Ints(a)
	l := a[len(a)-1]
	r := 0
	min := 10000000000.0
	for _, v := range a {
		if v == l {
			continue
		}
		diff := abs(float64(v) - float64(l)/2)
		if diff < min {
			min = diff
			r = v
		}
	}
	fmt.Printf("%v %v\n", l, r)
}

func factorial(n int) int {
	if n == 1 {
		return 1
	}
	return factorial(n-1) * n
}

func abs(n float64) float64 {
	if n < 0 {
		return -n
	}
	return n
}


Measured memory_bytes: 5504
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    string s;
    cin >> s;
    int n = s.length();

    vector<vector<int>> charPos(26, vector<int>());
    rep(i, n){
        charPos[s[i]-'a'].push_back(i+1);
    }
    rep(i, 26){
        charPos[i].push_back(INF);
    }

    vector<int> pos;
    vector<int> len(n+1);
    for(int i = n; i >= 0; i--){
        int far = 0;

        rep(c, 26){
            int lo = -1;
            int hi = charPos[c].size()-1;

            while(hi - lo > 1){
                int mid = (lo + hi) / 2;
                if(charPos[c][mid] > i){
                    hi = mid;
                }else{
                    lo = mid;
                }
            }

            far = max(far, charPos[c][hi]);
        }

        if(far == INF){
            len[i] = 1;
            continue;
        }

        len[i] = len[far] + 1;
    }

    string ans = "";
    int current = 0;
    rep(i, len[0]){
        rep(c, 26){
            int lo = -1;
            int hi = charPos[c].size()-1;

            while(hi - lo > 1){
                int mid = (lo + hi) / 2;
                if(charPos[c][mid] > current){
                    hi = mid;
                }else{
                    lo = mid;
                }
            }

            if(charPos[c][hi] == INF || len[charPos[c][hi]] + 1 == len[0] - i){
                current = charPos[c][hi];
                ans.push_back('a' + c);
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3964
#include <stdio.h>
#include <string.h>


int main(void) {
    int n, i, c;
    int stk[100001], si, last_color, total;

    while (scanf("%d", &n) == 1 && n) {
        memset(stk + 1, 0, n * sizeof(int));
        scanf("%d", &c);
        si = 1;
        stk[si] = 1;
        last_color = c;
        for (i = 2; i <= n; i++) {
            scanf("%d", &c);
            if (i&1) {
                stk[si += last_color != c]++;
            }
            else {
                if (last_color != c && si > 1) {
                    stk[si-1] += stk[si];
                    stk[si] = 0;
                    si--;
                }
                stk[si]++;
            }
            last_color = c;
        }
        for (i = si - (last_color != 0), total = 0;
             i > 0; i -= 2) {
            total += stk[i];
        }
        printf("%d\n", total);
    }

    return 0;
}

Measured memory_bytes: 996
use std::collections::HashMap;

fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let nm = readn::<usize>(" ");
    let n = nm[0];
    let m = nm[1];

    let mut a = readn::<usize>(" ");
    let mut dict = HashMap::new();
    for &i in a.iter() {
        let count = dict.entry(i).or_insert(0);
        *count += 1;
    }

    for _ in 0..m {
        let bc = readn::<usize>(" ");
        let b = bc[0];
        let c = bc[1];
        let count = dict.entry(c).or_insert(0);
        *count += b;
        a.push(c);
    }

    a.sort_by(|x, y| y.cmp(&x));
    let mut count = 0;
    let mut ans = 0;
    let mut pre = 0;
    for i in 0..a.len() {
        if a[i] == pre {
            continue;
        }
        let num = dict[&a[i]];
        if num + count > n {
            ans += (n - count) * a[i];
            break;
        } else {
            ans += num * a[i];
            count += num;
            pre = a[i];
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 18000
#include<iostream>
using namespace std;
int main(void)
{
    int noth,easu,n,i2,x,y,j1;
    int road[18][18];
    while(1){
        cin>>easu>>noth;
        if(easu==0&&noth==0)break;
        j1=0;
        cin>>n;
        for(int i=1;i<=easu;i++){
            for(int j=1;j<=noth;j++){
                road[i][j]=-1;
            }
        }
        for(int i=0;i<n;i++){
            cin>>x>>y;
            road[x][y]=0;
        }
        for(int i=1;i<=easu;i++){
            i2=0;
            for(int j=1;j<=noth;j++){
                if(i2==1){
                    road[i][j]=0;
                }
                else if(j1==1&&j==1)road[i][j]=0;
                else if(road[i][j]==0&&i==1)i2=1;
                else if(road[i][j]==0&&j==1)j1=1;
                else if(road[i][j]==-1&&(i==1||j==1))road[i][j]=1;
                else if(road[i][j]==-1)road[i][j]=road[i-1][j]+road[i][j-1];
               // cout<<road[i][j]<<" ";
            }
           // cout<<"\n";
        }
        cout<<road[easu][noth]<<"\n";
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	while(cin>>s){
		
	int ft = ((s[0] - '0') * 10) + (s[1]-'0');
	int sd = ((s[2] - '0') * 10) + (s[3]- '0');

	if( (ft>=1 && ft<=12) && (sd>=1&&sd<=12))cout<<"AMBIGUOUS\n";
	else if(ft>=1 && ft<=12)cout<<"MMYY\n";
	else if(sd>=1&&sd<=12)cout<<"YYMM\n";
	else cout<<"NA\n";


	}
}


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

bool ok[101];
int n,k,q,a,ans;
int main(){
	cin>>n>>k;
	for (int i=0;i<k;i++){
		cin>>q;
		for (int j=0;j<q;j++){
			cin>>a;
			ok[a]=true;
		}
	}
	for (int i=1;i<=n;i++) if (ok[i]==false) ans++;
	cout<<ans<<"\n";
}

Measured memory_bytes: 3636
def main():
    INF = float("inf")

    N, M, P, *ABC = map(int, open(0).read().split())

    F = [[] for _ in range(N)]
    B = [[] for _ in range(N)]
    E = [(a - 1, b - 1, P - c) for a, b, c in zip(*[iter(ABC)] * 3)]

    for a, b, c in E:
        F[a].append(b)
        B[b].append(a)

    def reachable(E, a):
        S = {a}
        stack = [a]
        while stack:
            s = stack.pop()
            for v in E[s]:
                if v not in S:
                    stack.append(v)
                    S.add(v)
        return S

    ok = reachable(F, 0) & reachable(B, N - 1)

    E = [(a, b, c) for a, b, c in E if a in ok and b in ok]

    D = [INF] * N
    D[0] = 0

    def bellman_ford(N):
        for _ in range(N):
            update = False
            for a, b, c in E:
                if D[b] > D[a] + c:
                    D[b] = D[a] + c
                    update = True
            if not update:
                return False
        return True

    print(-1 if bellman_ford(N + 1) else max(-D[-1], 0))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5872
N = int(input())
a = []
b = []
for _ in range(N):
    ab = list(map(int, input().split()))
    a.append(ab[0])
    b.append(ab[1])

count = 0
for i in range(N-1, -1, -1):
    if (a[i]+count) % b[i] != 0:
        count += (b[i] - (a[i]+count) % b[i])
print(count)


Measured memory_bytes: 11064
#include<cstdio>
#include<algorithm>
#include<queue>
#include<ctype.h>
#include<cstring>
#include<cmath>
#define maxn 3005
#define ll long long
#define p 1000000007
#define re(i,a,b) for(int i=a;i<=b;i++)
#define _re(i,a,b) for(int i=a;i>=b;i--)
#define for_edge(x) for(int i=head[x];i;i=e[i].nxt)
inline int read()
{
	int ans = 0;
	char c = getchar();
	while(!isdigit(c))
		c = getchar();
	while(isdigit(c))
		ans = ans*10+(c-'0'),
		c =getchar();
	return ans;
}
using namespace std;
inline void mod(int&x)
{
	if(x>=p)
		x-=p;
}
int n,m,dp[maxn][maxn][2];
int main()
{
	n = read() , m =read();
	dp[0][0][1] = 1;
	re(i,1,n)
		dp[0][i][0] = 1;
	re(i,0,m-1)
	{
		re(j,1,n)
			re(w,0,1)
				mod( dp[i+1][j-1][ w||j==1 ] += dp[i][j][w] );
		re(j,1,n)
			re(w,0,1)
				mod( dp[i+1][j][w||j==1] += dp[i][j][w] );
		re(j,0,n-1)
			re(w,0,1)
				mod( dp[i+1][j][w] += dp[i][j][w] );
		re(j,0,n-1)
			re(w,0,1)
				mod( dp[i+1][j+1][w] += dp[i][j][w] );
	}
	int ans = 0;
	re(i,0,n)
		mod( ans += dp[m][i][1]);
	printf("%d\n",ans);
		
}


Measured memory_bytes: 70656
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
/*
using ll = long long;
using P = pair<int, int>;
*/
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dp[101][10001];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, W;
    cin >> n >> W;
    vector<int> v(n), w(n);
    rep(i,n) cin >> v[i] >> w[i];
    int ans = 0;
    rep(i,n){
        rep(j,W+1){
            if(j-w[i] < 0) dp[i+1][j] = dp[i][j];
            else{
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
                chmax(dp[i+1][j], dp[i+1][j-w[i]] + v[i]);
            }
            chmax(ans, dp[i+1][j]);
        }
    }
    std::cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7036
#include<iostream>
#include<cstdio>

using namespace std;


int main(void)
{
	int n = 0;

	while (scanf("%d" , &n) != EOF)
	{
		int ans = 0;
	
		for (int i = 0; i <= 9; i++)
		{
			for (int j = 0; j <= 9; j++)
			{
				for (int k = 0; k <= 9; k++)
				{
					for (int l = 0; l <= 9; l++)
					{
						if (n == i + j + k + l)
						{
							ans++;
						}
					}
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

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

int main() {
  while (true) {
    int n, k;
    cin >> n >> k;
    if (n == 0 && k == 0) return 0;
    
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    
    int sum, max;
    int head = k - 1, tail = 0;
    sum = 0;
    for (int i = tail; i <= head; i++) {
      sum += a[i];
    }
    max = sum;
    
    while (head < n - 1) {
      sum -= a[tail++];
      sum += a[++head];
      if (sum > max) max = sum;
    }
    cout << max << endl;
  }
}

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

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

    int x, y, z;
    cin >> x >> y >> z;
    cout << (x-z)/(y+z) << endl;

    return 0;
}






Measured memory_bytes: 256
a, b, c = map(int,input().split())
A = []
for i in range(1,b+1):
    mod = a*i % b
    if mod in A:break
    A.append(mod)

A.sort()
if len(A) >= 2:
    i = A[1]
else:
    i = 0

if i == 0 and c == 0:
    print('YES')
    exit()
elif i == 0 and c != 0:
    print('NO')
    exit()

if c % i == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9144
#include<stdio.h>

#define MAX 20
int main()
{
  int n,a[MAX],i=0;


  scanf("%d",&n);
  for(;i<n;i++)
    scanf("%d", &a[i]);

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


  printf("%d\n",count);


  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int a,b,t;
	char op[2];
	for(;;){
		scanf("%d%s%d",&a,op,&b);
		t=*op=='+'?a+b:*op=='-'?a-b:*op=='*'?a*b:*op=='/'?a/b:0;
		if(*op=='?')break;
		printf("%d\n",t);
	}
	return 0;
}


Measured memory_bytes: 2044
#include <stdio.h>

void trace(int A[],int N){
    int i;
    for(i=0;i<N;i++){
        if(i>0){
            printf(" ");
        }
        printf("%d",A[i]);
    }
    printf("\n");
}

void insertionSort(int A[], int N){
    int i,j,v;
    for(i=1;i<N;i++){
        v=A[i];
        j=i-1;
        while(j>=0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1]=v;
        trace(A,N);
    }
}

int main(void){
    int N, i;
    int A[100];
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }

    trace(A,N);
    insertionSort(A,N);
    return 0;
}


Measured memory_bytes: 2132
#include<stdio.h>
#include<stdlib.h>
#pragma warning(disable:4996)
#include<string.h>
#include<ctype.h>
int main()
{
	long long n,a[100003];
	long long i,s,count=1,t;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	s=1;
	while(a[s]!=2)
	{
	s=a[s];
	count++;
	if(count==n)break;		
	}
	if(a[s]==2)printf("%lld\n",count);
	else printf("-1\n");
	return 0;
	
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i,N) {
    cin >> A[i];
  }
  sort(rng(A));
  reverse(rng(A));
  ll ans = 0;
  srep(i,1,N) {
    ans += A[i/2];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4060
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>  
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vl vector<ll>
#define N 100005
#define mod 1000000007


 
int main()
{   
    ll n;cin>>n;
    ll a[n+1];
    for(ll i=1;i<n+1;i++)
    cin>>a[i];
    ll pre[n+2]={0};ll suffx[n+2]={0};
    for(ll i=1;i<n+1;i++)
    {
        pre[i]=__gcd(a[i],pre[i-1]);
    }
    for(ll i=n;i>=0;i--)
    {
        suffx[i]=__gcd(suffx[i+1],a[i]);
    }
    ll mx=0;
    for(ll i=1;i<n+1;i++)
    {
        ll x=__gcd(pre[i-1],suffx[i+1]);
        mx=max(mx,x);
    }
    cout<<mx<<"\n";
    return 0;
}

Measured memory_bytes: 5984
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long  a,b,c;
	cin>>a>>b>>c;
	if((c-a-b)<=0)
	{
		cout<<"No\n";
		return 0;
	}
	if(4*a*b < (c-a-b)*(c-a-b))
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
# 後ろから押していく
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int,input().split())
cnt = 0
for i in range(N-1,-1,-1):
    cnt += (B[i]-(A[i]+cnt)%B[i])%B[i]
print(cnt)

Measured memory_bytes: 10868
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int ll
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int> 
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
ll dp[3001][3001];
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll a,b,c,d;
	cin>>a>>b>>c>>d;	
	dp[a][b] = 1;
	repa(i,a,c+1){
		repa(j,b,d+1){
			if(i == a && j == b)continue;
			// cout<<i<<" "<<j<<' ';
			ll temp1 = dp[i-1][j]*j;
			// cout<<temp1<<' ';
			temp1 %= mod;
			ll temp2 = dp[i][j-1]*i;
			temp2 %= mod;
			ll temp = dp[i-1][j-1]*(i-1)*(j-1);
			temp %= mod;
			add(temp1,temp2);
			// cout<<temp1<<" ";
			sub(temp1,temp);
			dp[i][j] = temp1;
			// cout<<temp1<<"\n";
			// dp[i][j] = dp[i-1][j]*j
		}
	}
	cout<<dp[c][d];
	return 0;
}

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

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

    map<int, int> D;
    int di;
    rep(i, N) {
        cin >> di;
        if (D.count(di)) D[di]++;
        else D[di] = 1;
    }

    int M;
    cin >> M;

    string ans = "YES";
    int ti;
    rep(i, M) {
        cin >> ti;
        if (D.count(ti) && D[ti] > 0) D[ti]--;
        else ans = "NO";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9600