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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int

using namespace __gnu_pbds;

typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;


#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
#define mod 1000000007
/* Precode Start Here *\


power of 2 less than or equal to N

ll largest_power(ll N)
{
    //changing all right side bits to 1.
    N = N (N>>1);
    N = N| (N>>2);
    N = N| (N>>4);
    N = N| (N>>8);


//as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
 2.
            return (N+1)>>1;

}


     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);

 ll n,m;
 cin>>n>>m;
 if(n==m)
 {
     cout<<"Yes"<<endl;
 }
 else
 {
     cout<<"No"<<endl;
 }
return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
const int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

	int a,b,c;
	cin >> a >> b >> c;

	if(c-a-b < 0){
		cout << "No" << endl;
		return 0;
	}

	if(4*a*b < (c-a-b)*(c-a-b)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_b
// rm -r -f test;oj dl https://panasonic2020.contest.atcoder.jp/tasks/panasonic2020_c

Measured memory_bytes: 3632
N, M = map(int, input().split())

mod = 1000000007

A = []
for i in range(M):
    A.append(int(input()))
A=set(A)
    
DP = [0]*(N+2)
DP[1] = 1

for i in range(2, N+2):
    if i-1 not in A:
        DP[i] =  DP[i-1]%mod + DP[i-2]%mod

print(DP[N+1]%mod)

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

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

    if (s == "RRR") {
        cout << 3 << endl;
    }
    else if (s == "RRS") {
        cout << 2 << endl;
    }
    else if (s == "SRR") {
        cout << 2 << endl;
    }
    else if (s == "RSR") {
        cout << 1<< endl;
    }
    else if (s == "RSS" || s == "SRS" || s == "SSR") {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    for (int i = 0; i < N; i++)cin >> X[i];
    sort(X.begin(), X.end());

    int ans = -1;

    for (int i = X[0]; i <= X[X.size()-1]; i++) {
        int num = 0;
        for (int j = 0; j < N; j++) {
            num += (X[j] - i) * (X[j] - i);
        }
        if (ans == -1)ans = num;
        else if (ans > num)ans = num;
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
	int n = 5;
	vector<int> arr(5);
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	int k;
	cin >> k;

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

	for (int i = 0; i < n -1; i++)
	{
		for (int j = i + 1;j < n;j++)
		{
			if (arr[j] - arr[i] > k)
			{
				cout << ":(" << endl;
				return 0;
			}
		}
	}

	cout << "Yay!" << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
cum = [[0]*(2*K+1) for i in range(2*K+1)]

def vertex(z):
    if z < K:
        return [(0,z+1),(z+K+1,2*K)]
    else:
        return [(z-K+1,z+1)]

for i in range(N):
    x,y,c = input().split()
    x = int(x)
    y = int(y)
    x %= 2*K
    if c == 'B':
        y %= 2*K
    else:
        y += K
        y %= 2*K

    for d in [0,K]:
        for b,t in vertex((y+d)%(2*K)):
            for l,r in vertex((x+d)%(2*K)):
                cum[b][l] += 1
                cum[t][r] += 1
                cum[b][r] -= 1
                cum[t][l] -= 1

import numpy as np
cum = np.array(cum)
print(np.cumsum(np.cumsum(cum,axis=0),axis=1).max())


Measured memory_bytes: 137632
#include <iostream>

using namespace std;

int main() {

  long n, a, b;

  cin >> n >> a >> b;

  long answer;

  if (a == 0) {
    answer = 0;
  } else {
    answer = a * (n / (a+b));

    if ((n % (a+b)) <= a) {
      answer += (n % (a+b));
    } else {
      answer += a;
    }
  }

  cout << answer;

  return 0;
}


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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int soma( int x ) {
    string s = to_string(x);
    int ans = 0;
    for ( auto l : s ) ans += l - '0';
    return ans;
}



int main() {

    int n, a, b;
    cin >> n >> a >> b;

    int cont = 0;
    for ( int i = 1; i <= n; i++ ) {
        int aux = soma(i);
        if ( aux >= a and aux <= b ) cont += i;
    }

    cout << cont << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;





//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define RALL(x) (x).rbegin(),(x).rend() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define seq vector
#define READLINE(vec,time) for(int indexofvec=0;indexofvec<time;indexofvec++)cin>>vec[indexofvec]
#define VPRINT(vec) for(auto i : vec){cout << i<<" ";}cout<<endl;
#define lambda []
#define clambda [=]
#define reflambda [&]

template<typename A,typename B,class functype>
void select(vector<A>& in,vector<B>& out,functype func){
    out.resize(in.size());

    for(int i =0;i<in.size();i++){
        out[i]=func(in[i]);
    }


}








signed main(){

    int N,Q;
    cin >>N>>Q;
    vector<tuple<ll,int,ll> > ivents(0);
    REP(i,N){
        ll S,T,X;
        cin >>S>>T>>X;
        ivents.push_back(make_tuple(S-X,1,X));
        ivents.push_back(make_tuple(T-X,0,X));
    }
    sort(ALL(ivents));
    ivents.push_back(make_tuple((1<<30),0,0));
    auto st = ivents.begin();
    auto ed = ivents.end();
    ll d,pos;
    set<ll>using_pos;
    int flg;
    REP(i,Q){
        cin >> d;
        while (get<0>(*st)<=d)
        {
           pos = get<2>(*st);
           flg = get<1>(*st);
           if(flg == 1){
               using_pos.insert(pos);
           }else{
               using_pos.erase(pos);
           }
           st++;
        }
        
        if(using_pos.empty()){
            cout << -1 << endl;
        }else{
            cout << *(using_pos.begin()) << endl;

        }


    }





}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  
  map<char, int> cnt;
  for(int i = 0; i < n; i++){
    char now = s.at(i);
    cnt[now]++;
  }
  
  long long ans = 1, mod = pow(10,9) + 7;
  for(auto now : cnt) ans = ans * ++now.second % mod;
  
  ans = (ans + mod -1) % mod;
  cout << ans << endl;
}

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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main()
{
  ll a, b;
  cin >> a >> b;
  if (a > b)
  {
    cout << a-1 << endl;
  }else{
    cout << a << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())

a = list(map(int, input().split()))
a.sort(reverse=True)


from functools import lru_cache
import sys
if n == 2:
    print(max(a))
    sys.exit()


@lru_cache(maxsize=100000)
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


def gcd_list(li):
    if len(li) == 1:
        return li[0]
    g = gcd(li[0], li[1])
    for i in range(2, len(li)):
        g = gcd(g, li[i])
    return g


def gcd_list_2(li):
    g = gcd(li[0], li[1])
    if g == 1:
        return max(gcd_list([li[0]] + li[2:]), gcd_list(li[1:]))
    for i in range(2, n):
        if gcd(g, li[i]) == 1:
            if i == n - 1:
                return gcd_list(li[:i])
            gg = gcd_list(li[i+1:])
            bb = [gcd(li[x], gg) for x in range(i+1)]
            bb.sort()
            return bb[1]
        else:
            g = gcd(g, li[i])
    return g


def max_gcd(a):
    g = gcd_list(a)
    a = [a[i]//g for i in range(n)]
    m = gcd_list_2(a)
    print(g * m)


max_gcd(a)

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

int main() {
    int N; cin >> N;
    string s; cin >> s;
    char t[N];
    for (int k = 0; k < 4; k++){
        if(k>>0&1){
            t[0] = 'S';
        } else {
            t[0] = 'W';
        }
        if(k>>1&1){
            t[1] = 'S';
        } else {
            t[1] = 'W';
        }

        for (int i = 1; i < N-1; i++){
            if(s[i] == 'o' && t[i] == 'S'){
                t[i+1] = t[i-1];
            } else if(s[i] == 'x' && t[i] == 'W'){
                t[i+1] = t[i-1];
            } else {
                if(t[i-1] == 'S'){
                    t[i+1] = 'W';
                } else {
                    t[i+1] = 'S';
                }
            }
        }

        bool ok = true;
        if(s[N-1] == 'o' && t[N-1] == 'S'){
            if(t[N-2] != t[0]){
                ok = false;
            }
        } else if(s[N-1] == 'x' && t[N-1] == 'W'){
            if(t[N-2] != t[0]){
                ok = false;
            }
        } else {
            if(t[N-2] == t[0]){
                ok = false;
            }
        }

        if(s[0] == 'o' && t[0] == 'S'){
            if(t[N-1] != t[1]){
                ok = false;
            }
        } else if(s[0] == 'x' && t[0] == 'W'){
            if(t[N-1] != t[1]){
                ok = false;
            }
        } else {
            if(t[N-1] == t[1]){
                ok = false;
            }
        }

        if(ok){
            rep(i, N){
                cout << t[i];
            }
            cout << endl;
            return 0;
        } else {
            continue;
        }
    }
    cout << -1 << endl;

    return 0;
}

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

int cnt = 0;
ll N;

bool check(ll x)
{
    bool ok = true;
    bool digit_flag[10] = {false};
    while (x > 0)
    {
        int c = x % 10;
        if (c == 3 || c == 5 || c == 7)
        {
            if (!digit_flag[c])
                digit_flag[c] = true;
            x /= 10;
        }
        else
        {
            ok = false;
            break;
        }
    }

    if (digit_flag[3] != true || digit_flag[5] != true || digit_flag[7] != true)
    {
        ok = false;
    }

    return (ok == true);
}

void dfs(ll x)
{
    if (x > N)
        return;

    if (check(x))
        cnt++;

    dfs(x * 10 + 3);
    dfs(x * 10 + 5);
    dfs(x * 10 + 7);
}

int main()
{
    cin >> N;
    dfs(0);
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n, l;
    long int a, max=0;
    scanf("%d", &n);
    l=n;
    
    while(l--){
        scanf("%ld", &a);
        max+=a;
    }
    
    max-=n;
    
    printf("%ld\n", max);
    return 0;
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

bool check_sosu(int a){
  if(a == 0 || a == 1) return false;
  if(a == 2) return true;
  int tmp = pow(a, 0.5) + 2;
  for (int i = 2; i < tmp && i < a; i++) {
    if(a % i == 0) return false;
  }
  return true;

}

int main(){
  int q;
  cin >> q;
  vector<bool> sosu(100100, false);
  vector<int> sosu_num(100100, 0);

  for (int i = 1; i < 100100; i++) {
    sosu[i] = check_sosu(i);
  }
  for (int i = 100099; i >= 3; i--) {
    if(sosu[i] && sosu[(i+1)/2]) sosu[i] = true;
    else sosu[i] = false;
  }
  sosu[0] = false;
  sosu[1] = false;
  sosu[2] = false;
  sosu[3] = true;

  for (int i = 1; i < 100100; i++) {
    if(sosu[i]) sosu_num[i] = sosu_num[i-1]+1;
    else sosu_num[i] = sosu_num[i-1];
  }



  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    // if(l == r) cout << sosu[l] << endl;
    // else if()
    cout << sosu_num[r] - sosu_num[l-1] << endl;
  }



}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
	int N, K, X, Y;
	int pay;
	scanf("%d %d %d %d", &N, &K, &X, &Y);
	if (K < N) {
		pay = K * X + (N - K) * Y;
	}
	else {
		pay = N * X;
	}
	printf("%d", pay);
	return 0;
}

Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;

int Main(int N, VI &d)
{
    int sum = 0;
    REP(i, N-1) REP2(j, i+1, N) sum += d[i]*d[j];
    return sum;
}

int main(void){
    int N;
    cin >> N;
    VI d(N);
    REP(i, N) cin >> d[i];
    cout << Main(N, d) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
 * お遊び
 *
 * @author s-sugimoto
 */
public class Main {

	/**
	 * 隠蔽
	 */
	private Main() {
	}

	/**
	 * main
	 *
	 * @param args 起動引数
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int a = scanner.nextInt();
		if (a > n * n) {
			System.out.println(n * n);
			return;
		}
		System.out.println(n * n - a);
	}

}


Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <map>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int n, m, f;
	string s[10];
	map<pair<string, string>, int> mp;
	vector<pair<string, string> > o;
	
	cin >> n >> f;
	for (int i = 0; i < n; i++) {
		int m;
		cin >> m;
		for (int j = 0; j < m; j++) {
			cin >> s[j];
		}
		
		for (int j = 0; j < m; j++) {
			for (int k = j + 1; k < m; k++) {
				string s1 = s[j];
				string s2 = s[k];
				
				if (s1 > s2) swap(s1, s2);
				
				mp[{s1, s2}]++;
			}
		}
	}
	
	for (auto &x:mp) {
		if (x.second >= f) {
			o.push_back({x.first.first, x.first.second});
		}
	}
	
	cout << o.size() << endl;
	for (int i = 0; i < o.size(); i++) {
		cout << o[i].first << ' ' << o[i].second << endl;
	}
	
	return 0;
}


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

int n,ans;
int a[100100],sum[100100];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum[a[i]]++;
	}
	for (int i=1;i<=100000;i++) ans=max(ans,sum[i-1]+sum[i]+sum[i+1]);
	printf("%d\n",ans);
	return 0;
}

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

    private static void solver(InputReader sc, PrintWriter out) throws Exception {
      int a = sc.nextInt();
     int b = sc.nextInt();
     int c = sc.nextInt();
     int d = sc.nextInt();
     while(true){
        c -= b;
         if(c <= 0){
             out.println("Yes");
            return;
         }
            a -=d;
         if(a <= 0){
             out.println("No");
             return;
         }
        // out.println(a +" "+c);
     }

    }
    private static int gcd(int a, int b){
        if(b==0)
            return a;
        return gcd(b, a%b);
    }
    public static void main(String[] args) throws Exception {
        // long start =  System.nanoTime();
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();


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

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

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int[] readIntArray(int n){
            int arr[] = new int[n];
            for(int i=0;i<n;i++) arr[i] = nextInt();
            return arr;
        }
    }
}
class Pair  implements  Comparable<Pair>{
    int x;
    int y;
    int z;

    Pair(int x, int y, int z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Pair pair = (Pair) o;
        return x == pair.x &&
                y == pair.y;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y, z);
    }

    @Override
    public int compareTo(Pair o) {
        return this.x-o.x;
    }
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
    if (n == 0) return 0;
    if (memo[n] != -1) return memo[n];

    int res = n;

    for (int i = 1; i <= n; i *= 6) res = min(res, rec(n - i) + 1);
    for (int i = 1; i <= n; i *= 9) res = min(res, rec(n - i) + 1);

    return memo[n] = res;
}

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

    rep(i, MAX_N) memo[i] = -1;
    cout << rec(N) << endl;
}

Measured memory_bytes: 3840
import sys
def main():
    a = []
    for line in sys.stdin:
        x = int(line)
        if x == 0:
            break
        else:
            a.append(x)
    for i in range(len(a)):
        print("Case", i + 1, end = "")
        print(":", a[i])   


if __name__ == "__main__":
    main()

Measured memory_bytes: 8344
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
  ll A,B;
  cin >> A >> B;
  cout << A/__gcd(A,B)*B << endl;
}

Measured memory_bytes: 764
#include<iostream>

using namespace std;
using P=pair<int,int>;

const long long MAX=1e18;

int main(){
    long long n;
    cin>>n;
    long long ans=1;
    bool ng=false;
    long long a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0){
            ans=0;
            cout<<ans<<endl;
            return 0;
        }
        if(a[i]<=MAX/ans){
            ans*=a[i];
        }else{
            ans=-1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

const int mod = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> sc(m);
  rep(i, m) {
    int s, c;
    cin >> s >> c;
    s--;
    sc[i] = make_pair(s, c);
  }
  bool ok = true;
  vector<int> ans(n);
  rep(i, m) {
    if (sc[i].first == 0 && n > 1) {
      if (sc[i].second == 0) {
        cout << "-1" << endl;
        return 0;
      }
    }
    rep(j, m) {
      if (sc[i].first == sc[j].first) {
        if (sc[i].second != sc[j].second) {
          cout << "-1" << endl;
          return 0;
        }
      }
    }
    ans[sc[i].first] = sc[i].second;
    if (sc[i].first == 0) {
      ok = false;
    }
  }
  if (ok) {
    ans[0] = 1;
  }
  if(n==1&&m==0){
    cout << 0 << endl;
    return 0;
  }
  rep(i, n) cout << ans[i];
}

Measured memory_bytes: 384
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}


fn main() {
    let line: Vec<u64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let N = line[0] as usize;
    let x = line[1];
    let A: Vec<u64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut memo: Vec<Vec<u64>> = vec![A.clone(); N];

    for i in 1..N {
        for j in 0..N {
            let pos = (i+j)%N;
            memo[i][pos] = cmp::min(memo[i-1][pos], A[j]);
        }
    }



    let mut sum = 0u64;
    for i in 0..N {
        sum += A[i];
    }
    for i in 1..N {
        let mut tmp = x * (i as u64);
        for j in 0..N {
            tmp += memo[i][j];
        }
        sum = cmp::min(sum, tmp);
    }

    println!("{}", sum);
}


Measured memory_bytes: 45436
A,B,K = (int(X) for X in input().split())
Low  = list(range(A,min(B+1,A+K)))
High = list(range(B,max(A-1,B-K),-1)) 
Num  = sorted(set(Low+High))
print('\n'.join(str(X) for X in Num))

Measured memory_bytes: 9172
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;


  ll ans = 0;
  ll mi = 0, ma = 0;
  REP(i, k) {
    mi = (mi + i) % mod;
    ma = (ma + (n - i)) % mod;
  }
  FOR(i, k, n + 2) {
    if(ma < mi) ma = ma + mod;
    ans = (ans + ((ma - mi) + 1)) % mod;
    mi = (mi + i) % mod;
    ma = (ma + (n - i)) % mod;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <stdio.h>
using namespace std;

int top,S[10000];

int stoia(string str){
    int ret;
    stringstream ss;
    ss << str;
    ss >> ret;
    return ret;
}

void push(int x){
    S[++top] = x;
}

int pop(){
    top--;
    
    return S[top+1];
}

int main(void){
    
    int a,b;
    top = 0;
    char s[100];
    
    while(cin >> s){
        if(s[0] == 'a')break;
        
        if(s[0] == '+'){
            a = pop();
            b = pop();
            push(a+b);
        }else if(s[0] == '-'){
            a = pop();
            b = pop();
            push(b-a);
        }else if(s[0] == '*'){
            a = pop();
            b = pop();
            push(a*b);
        }else {
            if(s[1] != '\0'){
                push(stoia(s));
            }
            else
                push(atoi(s));
        }
    }
    
    cout << pop() << endl;
    
    return 0;
}



Measured memory_bytes: 3204
n = int(input())
a, b = map(int, input().split())
ans = [ 0, 0, 0 ]
for p_i in map(int, input().split()):
    if p_i <= a:
        ans[0] += 1
    elif p_i <= b:
        ans[1] += 1
    else:
        ans[2] += 1
print(min(ans))


Measured memory_bytes: 38256
#include<stdio.h>
int main()
{
    long long int N,A,B,a[100005],i,sum=0;
    scanf("%lld%lld%lld",&N,&A,&B);
    for(i=0;i<N;i++)
        scanf("%lld",&a[i]);
    for(i=0;i<N-1;i++)
       {
        if((a[i+1]-a[i])*A<B)
        sum+=(a[i+1]-a[i])*A;
        else
            sum+=B;
       }
       printf("%lld",sum);
}


Measured memory_bytes: 896
s = input()
q = [0]
flag = False
while len(s) > 0:
    if s[0:5] in ['dream','erase'] and flag == False:
        q.append(s[0:5])
        s = s[5:]
        flag = False
    elif s[0:6] == 'eraser':
        q.append(s[0:6])
        s = s[6:]
        flag = False
    elif s[0:7] == 'dreamer':
        q.append(s[0:7])
        s = s[7:]
        flag = False
    elif q[-1] in ['dream','erase']:
        s = q[-1] + s
        q.pop()
        flag = True
    else:
        print('NO')
        exit()

print('YES')


Measured memory_bytes: 4248
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int m = n/2;
    int r = 0;
    for(int i = 1; i <= m; i++) {
        if(n-i == i) {
            continue;
        }
        r++;
    }

    cout << r << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';


///////////////////////////////////////////////////

int main()
{
    int N, X, T;
    io >> N >> X >> T;

    int k = (N+X-1) / X; 
    int ans = k * T;

    io << ans << BR;
}

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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, x) for (int i = 1, _##i = (x); i <= _##i; i++)
#define repr(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repi(i, x) for (auto &i : (x))


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
typedef pair<ll, ll> pll;

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    rep(i, sz(v)) cout << v[i] << ",";
    cout << "]";
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}

template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}

#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N, Q;
struct query {
    int type;
    int pos, tar, val;
};

vector<query> A;

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> N >> Q;
    rep(i, N) {
        int a, b, c; cin >> a >> b >> c;
        A.pb({1, a-c, c, 1});
        A.pb({1, b-c, c, -1});
    }
    rep(i, Q) {
        int t; cin >> t;
        A.pb({2, t, 0, 0});
    }

    sort(A.begin(), A.end(), [](auto a, auto b) {
        if (a.pos != b.pos) return a.pos < b.pos;
        return a.type < b.type;
    });

    multiset<int> m;
    repi(i, A) {
        if (i.type == 1) {
            if (i.val > 0) {
                m.insert(i.tar);
            } else {
                m.erase(m.find(i.tar));
            }
        } else {
            if (sz(m) > 0) cout << *m.begin() << endl;
            else cout << -1 << endl;
        }
    }
}

Measured memory_bytes: 20708
import itertools
import math


def distance(a, b):
    return((a[0] - b[0])**2 + (a[1] - b[1])**2)**0.5


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

    towns = []
    for i in range(n):
        x, y = map(int, input().split())
        towns.append((x, y))

    seq = range(n)
    sum_distance = 0
    for p in itertools.permutations(seq):
        for i in range(n-1):
            sum_distance += distance(towns[p[i]], towns[p[i+1]])
    ans = sum_distance / math.factorial(n)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40560
#include <stdio.h>

int main(void){
  int N, K;
  char S[N];
  int i;
  
  scanf("%d", &N);
  scanf("%d\n", &K);
  
  for(i=0; i<N; i++){
    scanf("%s\n",S);
  }
  
  for(i=0; i<N; i++){
    if(i==K-1&&S[i]=='A'){
      S[i]='a';
    }else if(i==K-1&&S[i]=='B'){
      S[i]='b';
    }else if(i==K-1&&S[i]=='C'){
      S[i]='c';
    }
  }
  
  printf("%s\n", S);
         
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
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;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

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

signed main()
{
   int N, A, B, C, D; cin >> N >> A >> B >> C >> D;
   for (int i = 0; i < N; i++) {
      if (i*C - (N-1-i)*D <= B - A && B - A <= i*D - (N-1-i)*C) {
         cout << "YES" << endl;
         return 0;
      }
   }
   cout << "NO" << endl;

   return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
Ans = [0] * (n + 1)

top = set()
bottom = set()
if s[0] == ">":
    top.add(0)
else:
    bottom.add(0)

for i in range(len(s)-1):
    left = s[i]
    right = s[i+1]
    if left == "<" and right == ">":
        top.add(i+1)
    elif left == ">" and right == "<":
        bottom.add(i+1)

if s[n-1] == ">":
    bottom.add(n)
else:
    top.add(n)

for b in list(bottom):
    counter = 0
    for i in range(b, n+1):
        if i in top:
            break
        else:
            Ans[i] = counter
            counter += 1

    counter = 0
    for i in range(b-1, -1, -1):
        if i in top:
            break
        else:
            Ans[i] = counter + 1
            counter += 1
#print(Ans)

for t in list(top):
    if t == 0:
        Ans[0] = Ans[1] + 1
    if t == n:
        Ans[n] = Ans[n-1] + 1
    else:
        Ans[t] = max(Ans[t-1] + 1, Ans[t+1] + 1)

#print(top)
#print(bottom)
print(sum(Ans))

Measured memory_bytes: 65480
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	string s;
	cin >> s;
	ll cnt = 0;
	for(int i = 0; i < s.size(); i ++)
	{
		cnt += (s[i] == 'W');
	}
	ll k = 0, ans = 0;
	for(int i = 0; i < s.size(); i ++ )
		if(s[i] == 'B')
		{
			ans += (cnt) - i;
			cnt ++;
		}
	cout << ans;





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s[0]==s[1]&&s[1]==s[2])cout<<"Yes"<<endl;
  else if(s[1]==s[2]&&s[2]==s[3])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
def main():
    n,x = map(int,input().split(' '))
    l = list(map(int,input().split(' ')))
    distance = 0
    cnt = 1
    for i in l:
        distance +=i
        if distance <= x:
            cnt += 1
        else:
            break
    print(cnt)
if __name__=='__main__':
    main()


Measured memory_bytes: 2940
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

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

const int L=2e5;
P ps[L];
int main() {
	int H,W,N;
	cin >> H >> W >> N;
	for(int i=0;i<N;i++){
		int x,y;
		cin >> x >> y;
		ps[i]=P(x,y);
	}
	sort(ps,ps+N);
	int d=0;
	for(int i=0;i<N;i++){
		if(ps[i].first-ps[i].second<=d){
			d=max(d,ps[i].first-ps[i].second+1);
		}
		else{
			cout << ps[i].first - 1<< endl;
			return 0;
		}
	}
	cout << H << endl;

	return 0;
}



Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

vector<int> *a;
bool *check;
int *d,*f;

int dfs(int u, int time){
    int i, v;
    check[u] = true;
    d[u] = time;
    time++;
    for(i=0;i<a[u].size();i++){
        v = a[u][i];
        if(!check[v])time = dfs(v,time);
    }
    f[u] = time;
    time++;
    return time;
}

int main(){
    int i, j, n, u, k, v;
    scanf("%d",&n);
    check = (bool *)malloc(sizeof(bool)*(n+1));
    d = (int *)malloc(sizeof(int)*(n+1));
    f = (int *)malloc(sizeof(int)*(n+1));
    for(i=0;i<=n;i++)check[i] = false;
    a = (vector<int> *)malloc(sizeof(vector<int>)*(n+1));

    for(i=1;i<=n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&v);
            a[u].push_back(v);
        }
    }

    int time = 1;
    for(i=1;i<=n;i++){
        if(!check[i])
        time = dfs(i,time);
    }

    for(i=1;i<=n;i++)printf("%d %d %d\n",i,d[i],f[i]);

    return 0;
}



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

A = []

for i in range(Q):
    A.append(int(input()))

tokuten = [K - Q for _ in range(N)]

for a in A:
    atariman = a - 1
    tokuten[atariman] += 1

for ten in tokuten:
    if ten > 0:
        print("Yes")
    else:
        print("No")


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

int main()
{
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    rep(i, n - 1)
    {
        if (a[i] == a[i + 1])
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long int
#define sec ->second
#define fir ->first
#define mapi map<int,int>
#define veci vector<int,int>
#define pb(a) .push_back(a)
#define pob(a) .pop_back(a)
#define fori(a) for(int i=0;i<a;i++)
#define forill(a) for(long long int i=0;i<a;i++)
#define listi list<int>
int main()
{
    ll n;cin>>n;ll sum=0;
    for(ll i=1;i<=n;i++){
        if(i%3!=0&&i%5!=0){
            sum+=i;
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3636
/*input
7
14 14 2 13 56 2 37

*/
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 

using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;cin>>n;
    ll arr[n];
    ll sum=0;
    for(ll i=0;i<n;i++){
    	cin>>arr[i];sum+=arr[i];
    }
    ll maxi = *max_element(arr,arr+n);
    ll mini = *min_element(arr,arr+n);
    ll mid  = sum/n;
    ll ans1  = 0,ans2=0;
    for(ll i=0;i<n;i++){
    	ans1 += pow((arr[i]-mid),2);
    	ans2 += pow((arr[i]-mid-1),2);
    }
    cout<<min(ans1,ans2)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

struct point {
	double x, y;
}; 

struct circle {
	double r;
	point cen;
}cirA, cirB;

double dis(point A, point B) {
	return sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));
}

//判断&#20004;&#22278;的位置&#20851;系
//&#36755;入&#20004;&#22278;的&#22278;心坐&#26631;及半径
//&#36755;出&#20004;&#22278;的位置&#20851;系 
int solve(circle cirA, circle cirB) {
	double disAB = dis(cirA.cen, cirB.cen);
	if (disAB > cirA.r + cirB.r) return 0; //相&#31163;
	if (disAB < max(cirA.r, cirB.r) - min(cirA.r, cirB.r)) {
		if (disAB < cirA.r - cirB.r) return 2; //&#22278;B在&#22278;A内
		else return -2; //&#22278;A在&#22278;B内 
	} 
	return 1; //&#20004;&#22278;相交 
}

int main() {
	int t;
	scanf ("%d", &t);
	while (t--) {
		scanf ("%lf%lf%lf%lf%lf%lf", &cirA.cen.x, &cirA.cen.y, &cirA.r, &cirB.cen.x, &cirB.cen.y, &cirB.r);
		printf ("%d\n", solve(cirA, cirB));
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

ll n, k;

int main() {
    cin >> n >> k;
    vector<ll> A(n, 0);
    for(int i = 0; i < n; ++i) cin >> A.at(i);
    vector<ll> F(n, 0);
    for(int i = 0; i < n; ++i) cin >> F.at(i);
    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());

    ll ng = -1, ok = 1e12;
    while(abs(ok-ng) > 1) {
        ll mid = (ok+ng) / 2;
        bool judge = [&] {
            ll sum = 0;
            for(int i = 0; i < n; ++i) {
                sum += max(0ll, A.at(i) - mid/F.at(i));
            }
            return sum <= k;
        }();
        if(judge) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
#define MAX 2000001
#define VMAX 10000

int C[VMAX];
int n=0;
int k=0;

void countingsort(int A[],int B[],int k){
  for(int i=0;i<=k;i++){
    C[i]=0;
  }
  for(int j=1;j<=n;j++){
    C[A[j]]++;
  }
  for(int i=1;i<=k;i++){
    C[i]=C[i]+C[i-1];
  }
  for(int j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  for(int i=1;i<=n;i++){
    cout<<B[i];
    if(i!=n)cout<<" ";
    
  }
  printf("\n");
}

int main(){
  int A[MAX]={};
  int B[MAX]={};
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>A[i];
    if(k<A[i])k=A[i];
  }
  countingsort(A,B,k);

  
  return 0;
}



Measured memory_bytes: 18736
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	ios::sync_with_stdio(false);
	ll q;
	cin>>q;
	REP(i,q) {
		ll a,b;
		cin>>a>>b;
		ll l=0,r=INF*INF;
		while(r-l>1) {
			__int128 m=(l+r)/2;
			__int128 maxi=0;
			ll medi=m/2;
			for(ll i=-10000; i<10000; i++) {
				ll p=medi+i;
				if(p==a) continue;
				if(p<1||p>m) continue;
				if(p>a) {
					if((m-p)>b) {
						maxi=max(maxi,(__int128)p*(__int128)(m-p+1));
					} else {
						maxi=max(maxi,(__int128)p*(__int128)(m-p));
					}
				} else {
					maxi=max(maxi,(__int128)p*(__int128)(m-p));
				}
			}
			if(maxi<a*b) l=m;
			else r=m;
		}
		cout<<l-2<<endl;
	}
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int a = Integer.parseInt(sc.next());
            String op = sc.next();
            int b = Integer.parseInt(sc.next());
            if (op.equals("?"))
                break;
            else if (op.equals("+"))
                System.out.println(a + b);
            else if (op.equals("-"))
                System.out.println(a - b);
            else if (op.equals("*"))
                System.out.println(a * b);
            else if (op.equals("/"))
                System.out.println(a / b);
        }
    }
}


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

int main(){
	int a,b; scanf("%d%d",&a,&b);
	if(a%3==0||b%3==0||(a+b)%3==0) cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define append push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int x;
  cin >> x;
  if (x == 3 || x == 5 || x == 7) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 3568