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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

bool prime[100000 + 1];

void era(int n) {
	rep (i, 0, 100000 + 1)
		prime[i] = true;

	for (int i = 2; i * i < n; i++) {
		if (prime[i]) {
			for (int j = i * 2; j < 100000 + 1; j += i) {
				prime[j] = false;
			}
		}
	}
}

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

	vector<int> a;
	era(100000 + 1);
	rep (i, 3, 100000 + 1) { // 2 is even
		if (prime[i])
			a.push_back(i);
	}

	int q;
	cin >> q;
	rep (i, 0, q) {
		int l, r;
		cin >> l >> r;

		int res = 0;
		auto lb = lower_bound(a.begin(), a.end(), l);
		auto ub = upper_bound(a.begin(), a.end(), r);
		for (auto it = lb; it != ub; it++) {
			if (prime[(*it + 1) / 2])
				res++;
		}
		cout << res << endl;
	}

	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;
int main(void)
{
   int n, m;
   char a[55][55];
   char b[55][55];

   cin >> n >> m;

   if (n < m) {
       cout << "No" << endl;
       return 0;
   }

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

   for (int i = 0; i < m; i++) {
       for (int j = 0; j < m; j++) {
           cin >> b[i][j];
       }
   }

   for (int i = 0; i < n; i++) {
       for (int j = 0; j < n; j++) {
           if (i+m-1 >= n || j+m-1 >= n) {
               continue;
           }
           bool flag = true;
           for (int k = 0; k < m; k++) {
               for (int l = 0; l < m; l++) {
                   if (a[k+i][l+j] != b[k][l]) {
                       flag = false;
                   }
               }
           }
           if (flag) {
               cout << "Yes" << endl;
               return 0;
           }
       }
   }

   cout << "No" << endl;

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef long long ll;

int main() {
	string a, b;
	cin >> a >> b;
	if (a.size() > b.size())cout << "GREATER" << endl;
	else if (a.size() < b.size())cout << "LESS";
	else {
		if (a > b)cout << "GREATER" << endl;
		else if (a < b)cout << "LESS" << endl;
		else cout << "EQUAL" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    ll N; cin >> N;
    ll ans = 0;
    for (ll i = 1; i+1 < N/i; i++) {
        if (N % i == 0) {
            ans += N/i - 1;
        }
    }
    cout << ans << endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

ll facs[200200];

// x^n in mod
ll modpow(ll x, ll n, ll mod){
  if(n==0) return 1;

  if(n%2==0){
    return modpow(x*x%mod, n/2, mod) % mod;
  }else{
    return x * modpow(x, (n-1), mod) % mod;
  }
}

// n! in mod
ll fac(ll n){
  return facs[n];
}

// nCr in mod
ll comb(ll n, ll r){
  if(n<0 || n<r || r<0)return 0;
  ll fn = fac(n);
  ll fr = fac(r);
  ll fn_r = fac(n-r);
  
  ll d = (modpow(fr, MOD-2, MOD) * modpow(fn_r, MOD-2, MOD)) % MOD;
  ll u = fn%MOD;
  
  ll result = u * d % MOD;
 
  return result;
}

int main(){
  ll n,k;cin>>n>>k;
  facs[0]=1;
  rep(i, n+10)facs[i+1] = (facs[i]*(i+1))%MOD;
  if(k>n)k=n;

  ll result=0;
  rep1(i, min(n-1,k)){
    ll tmp = comb(n ,i);
    tmp *= comb(n-1, i);
    tmp %= MOD;

    result += tmp;
    result %= MOD;
  }

  cout<<result+1%MOD;

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	for (int i = 0; i < (int) 1e7; i++) {
		if ((a & 1) || (b & 1) || (c & 1)) {
			cout << i << "\n";
			return 0;
		}
		int x = (b + c) / 2;
		int y = (a + c) / 2;
		int z = (a + b) / 2;
		a = x;
		b = y;
		c = z;
	}
	cout << -1 << "\n";
	return 0;
}

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

public class Main {
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (a <= 0 && 0 <= b) {
			out.println("Zero");
		} else if (0 < a) {
			out.println("Positive");
		} else {
			if ((b - a) % 2 == 1) {
				out.println("Positive");
			} else {
				out.println("Negative");
			}
		}
		
		out.flush();
	}
	
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	
	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	
	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}
	
	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}
	
	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}
	
	public int nextInt() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

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

int main(){
	int h,w; cin>>h>>w;
	vector<vector<string>> v(h, vector<string>(w));
	rep(i,h){
		rep(j,w){
			cin>>v[i][j];
		}
	}
	int r,c;
	rep(i,h){
		rep(j,w){
			if(v[i][j]=="snuke"){
				r=i;
				c=j;
			}
		}
	}
	vector<char> a(26);
	rep(i,26) a[i]='A'+i;
	cout<<a[c]<<r+1<<endl;
}

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

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

int main()
{
    string S;
    cin >> S;
    string S_tmp = S;
    int N = S.length();
    reverse(S_tmp.begin(), S_tmp.end());
    if(S != S_tmp){
        cout << "No" << endl;
        return 0;
    }
    S_tmp = "";
    for (int i = 0; i < (N - 1) / 2;i++){
        S_tmp += S.at(i);
    }
    string S_tmp2 = S_tmp;
    reverse(S_tmp2.begin(), S_tmp2.end());
    if(S_tmp != S_tmp2){
        cout << "No" << endl;
        return 0;
    }
    S_tmp = "";
    for (int i = ((N + 3) / 2) - 1; i < N;i++){
        S_tmp += S.at(i);
    }
    S_tmp2 = S_tmp;
    reverse(S_tmp2.begin(), S_tmp2.end());
        if(S_tmp != S_tmp2){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
//ProblemD

//#define USE_STDIO
//#define USE_LOG
//#define FILE_ERR

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#ifndef debug
#define debug(...)
#endif // !LOG

//include
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>

using namespace std;

//for
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forbe(i, begin, end) for(decltype(begin) i = (begin); i != (end); ++i)
#define forbes(i, begin, end, step) for(decltype(begin) i = (begin); i != (end); i += (step))

//int
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;

//pair
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
#define fi first
#define se second

//vector
template <typename Value>
static inline void fillv(Value& x, const Value& val) { x = val; }
template <typename Vector, typename Value>
static inline void fillv(Vector& v, const Value& val) { for (auto& x : v) fillv(x, val); }

static inline void Solve();

int main(int argc, char* argv[]) {
#ifdef REDIRECT_STDIO
	REDIRECT_STDIO;
#endif // REDIRECT_STDIO

	Solve();
	return 0;
}

ll sum(ll n) {
	ll ans = 0;
	while (n) {
		ans += n % 10;
		n /= 10;
	}
	return ans;
}

//ProblemD
void Solve() {
	int k;
	cin >> k;

	ll mul = 1;
	ll j = 1;

	vector<ll> res;
	while (int(res.size()) < k) {
		ll n = (j + 1) * mul - 1;
		if (j % 10 != 9 && n > mul * sum(n)) {
			mul *= 10;
			j = j / 10;
		}
		else {
			res.push_back(n);
			j += 1;
		}
	}

	for (int i = 0; i < k; i++) {
		cout << res[i] << endl;
	}
}


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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll N;
  cin >> N;
  vec<ll> H(N);
  REP(i, N) cin >> H[i];

  REP(i, N) {
    if (i - 1 < 0 || H[i - 1] < H[i]) {
      H[i]--;
    }
  }
  cout << (is_sorted(ALL(H)) ? "Yes" : "No") << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

	ll n;
	cin >> n;

	map<ll, ll> mp;
	ll sm = 0;
	rep(i, n){
		ll a;
		cin >> a;

		if(mp.count(a) == 0) mp[a] = 0;
		mp[a]++;
		sm += a;
	}

	int q;
	cin >> q;

	rep(i, q){
		ll b, c;
		cin >> b >> c;

		ll t = mp[b];
		sm += (c - b) * t;

		cout << sm << "\n";
		
		mp[b] = 0;
		if(mp.count(c) == 0) mp[c] = 0;
		mp[c] += t;
	}

}


Measured memory_bytes: 9420
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define ctoi(x) (x - '0')
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

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

int n, ans;
vi v(200010);
unordered_map<int, int> M;

int main() {
	fastio;
	cin >> n;
	FOR(i, n) {
		cin >> v[i + 1];
		M[v[i + 1]]++;
	}
	for (int i = 1; i <= n; i++) {
		int flag = 1;
		for (ll j = 1; j * j <= v[i]; j++) {
			if (v[i] % j == 0) {
				//v[i]/j, j
				if (j == v[i] && M[j] >= 2 || j != v[i] && M[j] >= 1 || v[i]/j == v[i] && M[v[i]/j] >= 2 || v[i]/j != v[i] && M[v[i]/j] >= 1) {
					flag = 0;
					break;
				}
			}
		}
		if (flag) ans++;
	}
	cout << ans;
}

Measured memory_bytes: 32536
#encoding:utf-8 No.0047 2014.10.6
cups = {"A"=>"ball","B"=>nil,"C"=>nil}
change = []

while gets
  change.push $_.chomp.split(/,/)
end

change.length.times do |i|
  cups[change[i][0]],cups[change[i][1]] = cups[change[i][1]],cups[change[i][0]]
end

cups.each{|key,value|
  puts key if value == "ball"
}

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

const int oo = 1e9;

int n, m, x;
int Sum[15], c[15], a[15][15];

int GetBit(int num, int pos)
{
    return (num >> pos) & 1;
}

int test(int k)
{
    memset(Sum, 0, sizeof(Sum));
    int Res = 0;
    for (int i = 0; i < n; i++)
    {
        if (GetBit(k, i))
        {
            Res += c[i];
            for (int j = 0; j < m; j++)
            {
                Sum[j] += a[i][j];
            }
        }
    }
    bool flag = *min_element(Sum, Sum + m) >= x;
    return (flag ? Res : oo);
}

int main()
{
    cin >>n>>m>>x;
    rep(i,0,n-1)
    {
        cin >> c[i];
        rep(j,0,m-1)
        {
            cin >> a[i][j];
        }
    }
    int p2n = (1 << n), ans = oo;
    for (int i = 0; i < p2n; i++)
    {
        ans = min(ans, test(i));
    }
    cout << (ans == oo ? -1 : ans);
    return 0;
}


Measured memory_bytes: 3636
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		String S = scan.next();
		scan.close();
		String []a = S.split("");
		//Arrays.sort(a);
		ArrayList<String> list1 = new ArrayList<String>();
		//list1.add(a[0]);
		int max = 0;
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			check(list1, a[i]);
			cnt = 0;
			for(int j = 0; j < list1.size(); j++) {
				String t = list1.get(j);
				for(int l = i + 1; l < N; l++) {
					if(t.equals(a[l])) {
						cnt ++;
						if(max < cnt) {
							max = cnt;
						}
						break;
					}
				}
			}
			//System.out.println(i + " listsize " + list1.size() + " max " + max);
		}
		//System.out.println("listsize" + list1.size());
		System.out.println(max);
	}
	public static void check(ArrayList<String> list, String a) {
		for(int i = 0; i < list.size(); i++) {
			if(a.equals(list.get(i))) {
				return;
			}
		}
		list.add(a);

	}

}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a;
  bool flag=1;
  cin>>n;
  while(cin>>a){
    if(a%2==0&&a%3!=0&&a%5!=0){
        flag=0;
    }
  }
  puts(flag?"APPROVED":"DENIED");
}

Measured memory_bytes: 256
import queue

n, m = map(int, input().split())
maze = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    maze[a-1].append(b-1)
    maze[b-1].append(a-1)

ans = [-1 for _ in range(n)]
ans[0] = 0
q = queue.Queue()
q.put(0)
while not q.empty():
    start = q.get()
    for end in maze[start]:
        if ans[end] == -1:
            q.put(end)
            ans[end] = start

if -1 in ans[1:]:
    print('No')
else:
    print('Yes')
    for i in range(1,n):
        print(ans[i]+1)


Measured memory_bytes: 35004
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)3e3+5;
const int Q = 301;
const int logN = 19;

void solve() {
    int n;
    cin>>n;
    set<string> s;
    string t;
    while(n--) {
        cin>>t;
        s.insert(t);
    }
    cout<<s.size();
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 19264
#include <stdio.h>


int main(){
	
	int h,w,n,bigsize,ans;
	scanf("%d",&h);
	scanf("%d",&w);
	scanf("%d",&n);
	
	/*　大きい値を調べる　*/
	if(h>=w){
		bigsize=h;
	}
	else{
		bigsize=w;
	}
	/*　答えをだす　*/
	if(n%bigsize==0){
		ans=n/bigsize;
	}
	else{
		ans=n/bigsize+1;
	}
	
	printf("%d",ans);
}


Measured memory_bytes: 128
#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[3], b[3];
	rep(i,0,3) cin >> a[i] >> b[i];

	bool map[4][4] = {};
	rep(i,0,3) {
		map[a[i]-1][b[i]-1] = true;
		map[b[i]-1][a[i]-1] = true;
	}

	bool used[4] = {};
	used[0] = true;
	rep(i,0,4) {
		if (map[0][i] && !used[i]) {
			used[i] = true;
			rep(j,0,4) {
				if (map[i][j] && !used[j]) {
					used[j] = true;
					rep(k,0,4) {
						if (map[j][k] && !used[k]) {
							cout << "YES" << endl;
							return 0;
						}
					}
				}
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long a, b;
    cin >> a >> b;
    bool f = true;
    for (int i = max(a, b); i <= 10000; i++)
    {
        if (floor(i * 0.08) == a && floor(i * 0.1) == b)
        {
            cout << i;
            f = false;
            break;
        }
    }
    if (f)
        cout << -1;
    return 0;
}

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


int main (void)
{ 
  long long int ans,h,w,x,y;
  
  
  cin>>w>>h>>x>>y;
  ans=h*w/2;
  cout<<ans;
  if(h*w%2==1){cout<<".5";}
  cout<<" ";
 // cout<<w<<" "<<2*x<<" "<<h<<" "<<2*y;
  
  if((w==2*x) && (h==2*y))
  { 
    cout<<"1"<<endl;
    return 0;
  }
  cout<<"0"<<endl;
  return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int N,a[105],sum,m,ans,b;
int main(){
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d",a+i);
        sum+=a[i];
    }
    m=sum/N;
    for(int i=0;i<N;i++)
        ans+=(a[i]-m)*(a[i]-m);
    for(int i=0;i<N;i++)
        b+=(a[i]-m-1)*(a[i]-m-1);
    ans=min(ans,b);
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int x, a, b;
    cin >> x >> a >> b;
    char ans = 'A';
    if (abs(x-b)<abs(x-a)) {
        ans++;
    }
    
    cout << ans << endl;
    return 0;
}


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

int n,s[100+10][100+10];

int biggest(int n){
    int M=-10000-10;
    for(int p=0;p<n;p++){
        for(int q=0;q<n;q++){
            if(s[p][q]>M) M=s[p][q];
            
            for(int r=0;r<p;r++) if(s[p][q]-s[r][q]>M) M=s[p][q]-s[r][q];
            for(int t=0;t<q;t++) if(s[p][q]-s[p][t]>M) M=s[p][q]-s[p][t];
            
            for(int r=0;r<p;r++){
                for(int t=0;t<q;t++){
                    if(s[p][q]-s[r][q]-s[p][t]+s[r][t]>M) M=s[p][q]-s[r][q]-s[p][t]+s[r][t];
                }
            }
        }
    }
    return M;
}

int main(){
    cin >> n;
    int a[100+10][100+10];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++) cin >> a[i][j];
    }
    
//    for(int i=0;i<n;i++){
//        for(int j=0;j<n;j++){
//            cout << a[i][j] << " ";
//        }
//        cout << endl;
//    }

    
    s[0][0]=a[0][0];
    for(int i=1;i<n;i++) s[i][0]=s[i-1][0]+a[i][0];
    for(int j=1;j<n;j++) s[0][j]=s[0][j-1]+a[0][j];
    
    for(int i=1;i<n;i++){
        for(int j=1;j<n;j++) s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];
    }
    
//    for(int i=0;i<n;i++){
//        for(int j=0;j<n;j++){
//            cout << s[i][j] << " ";
//        }
//        cout << endl;
//    }

    
    cout << biggest(n) << endl;
}

Measured memory_bytes: 3220
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int n;
int a[100000];

signed main() {
	int i, j;
	
	cin >> n;
	for (i = 0; i < n; i++) { cin >> a[i]; }

	int ans = 0;
	
	for (i = 0; i < n; ) {
		int x = a[i];
		for (j = i + 1; j < n; j++) {
			if (x != a[j]) {
				break;
			}
		}
		if (j == n) { ans++; break; }
		int y = a[j];
		
		if (x < y) {
			for (j = i + 1; j < n; j++) {
				if (a[j - 1] > a[j]) {
					break;
				}
			}
		}
		else {
			for (j = i + 1; j < n; j++) {
				if (a[j - 1] < a[j]) {
					break;
				}
			}
		}
		i = j;
		ans++;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){

	int n;
	int fish[20] = { 0 };
	int ans1 = -1;
	int ans2;
	int num;

	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> num;
		cin >> fish[num - 1];
	}

	for (int i = 0; i < n; i++){
		if (fish[i] > ans1){
			ans2 = 0;
			ans1 = fish[i];
			ans2 = i + 1;
		}
	}

	cout << ans2 << " " << ans1 << endl;

	return 0;
}

Measured memory_bytes: 3108
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;

#define ran 202202

int n, m;
vector<int> e[ran];
bool v[ran];
int ans, ans_id;

void dfs(int cur, int dep) {
	v[cur] = true;
	if(dep>ans) {
		ans = dep;
		ans_id = cur;
	}
	
	for(int i=0;i<(int)e[cur].size();i++) {
		int nxt = e[cur][i];
		if(!v[nxt]) dfs(nxt, dep+1);
	}
}

int main() {
	scanf("%d", &n);
	for(int i=1;i<n;i++) {
		int x, y; scanf("%d%d", &x, &y);
		e[x].push_back(y); e[y].push_back(x);
	}
	
	ans = -1;
	memset(v, false, sizeof v);
	dfs(1, 0);
	
	ans = -1;
	memset(v, false, sizeof v);
	dfs(ans_id, 0);
	
	if(n==1) puts("First");
	else puts((ans+1)%3==2 ? "Second" : "First");
	
	return 0;
}

Measured memory_bytes: 20736
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define endl "\n"
const int N=5+1e5;
using namespace std;
ll a[N],n;
ll memo[N][2];
ll solve(int index,int s)
{
    ll &ret=memo[index][s];
    if(ret!=-1)
        return ret;
    if(index>=n-1)
      return ret=0;
    else
    {
        return ret=min(solve(index+1,0)+abs(index+1<n?(a[index+1]-a[index]):1e15),solve(index+2,0)+abs(index+2<n?(a[index+2]-a[index]):1e15));
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n;
    for(int i=0;i<n;++i)
        cin>>a[i];
        memset(memo,-1,sizeof memo);
        cout<<min(solve(0,0),solve(0,1));

}


Measured memory_bytes: 5760
import sys
input=sys.stdin.readline
h,w,d=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
x=[0]*(h*w+1)
y=[0]*(h*w+1)
for i in range(1,h+1):
    for j in range(1,w+1):
        x[a[i-1][j-1]]=i
        y[a[i-1][j-1]]=j
dp=[0]*(h*w+1)
for i in range(d+1,h*w+1):
    dp[i]=dp[i-d]+abs(x[i]-x[i-d])+abs(y[i]-y[i-d])

q=int(input())
for _ in range(q):
    l,r=map(int,input().split())
    print(dp[r]-dp[l])


Measured memory_bytes: 55132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  int ans = 0;
  while (N != 0) {
    ans++;
    N /= K;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/**********************************************************************
   File hoge.cpp
   Author  harunaya
   Date   2020-03-04(Wed)
   note
**********************************************************************/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
//#define PI(acos(-1))
using namespace std;
typedef long long ll;

int main() {
  int n, k; cin >> n >> k;
  string s; cin >> s;
  if (s.at(k-1) == 'A' ) {
    s.at(k-1) = 'a';
  }
  else if (s.at(k-1) == 'B' ) {
    s.at(k-1) = 'b';
  }
  else if (s.at(k-1) == 'C' ){
    s.at(k-1) = 'c';
  }

  cout << s << endl;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  LL n,k;
  cin >> n >> k;
  LL l=-1,r=LINF,mid;
  while(r-l>1){
    mid=(l+r)/2;
    LL tmp=mid;
    rep(i,n-1){
      if(tmp==0){
        l=mid;
        goto next;
      }
      if(tmp%k==0) tmp--;
      tmp-=tmp/k+1;
    }
    r=mid;
    next:;
  }
  cout << r << endl;
  return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  int r, g, b, n;
  cin >> r >> g >> b >> n;
  lol ans = 0;
  rep(i, n + 1){
    rep(j, n + 1){
      lol nasu = r * i + g * j;
      if(nasu <= n && (n - nasu) % b == 0){
	//cout << i << " " << j << '\n';
	ans ++;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> l(N);
    for(int i=0; i<N; i++){
        cin >> l.at(i);
    }

    ll sum=0;

    for(int i=0; i<N; i++){
        for(int j=i; j<N; j++){
            for(int k=j; k<N; k++){
                if(l.at(i)!=l.at(j) && l.at(j)!=l.at(k) && l.at(k)!=l.at(i) && l.at(i)+l.at(j) > l.at(k) && abs(l.at(i)-l.at(j)) < l.at(k)){
                    sum++;
                }
            }
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 3644
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    string A, B, C;
    scan(A, B, C);
    bool b = A[$ - 1] == B[0] && B[$ - 1] == C[0];
    writeln(b ? "YES" : "NO");
}


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

int chk (int v) {
  int ans = 0;
  while (v > 0) {
    ans++;
    v /= 10;
  }
  return ans;
}

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, tot = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if ((chk(i) & 1) == 1) {
      tot++;
    }
  }
  cout << tot << '\n';
  return 0;
}

Measured memory_bytes: 256
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_ll.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <iomanip>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_ll;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

struct s_t{
  ll l,r,c;
};

bool asc(s_t left,s_t right) {
  return left.l != right.l ? left.l < right.l : (left.c != right.c ? left.c < right.c : left.r < right.r);
}

// 区間更新、区間最小の遅延セグメントツリー
struct RMQRUQ {
  ll n;
  vector<ll> dat, lazy;

  RMQRUQ(){}
  RMQRUQ(ll n_) {
    n = 1; while(n < n_) n *= 2;
    dat.assign(n*2, LLONG_MAX);
    lazy.assign(n*2, LLONG_MAX);
  }

  void eval(ll len, ll k) {
    if(lazy[k] == LLONG_MAX) return;
    if(k*2+1 < n*2-1) {
      lazy[2*k+1] = min(lazy[k],lazy[2*k+1]);
      lazy[2*k+2] = min(lazy[k],lazy[2*k+2]);
    }
    dat[k] = min(dat[k],lazy[k]);
    lazy[k] = LLONG_MAX;
  }

  // [a, b)
  ll update(ll a, ll b, ll x, ll k, ll l, ll r) {
    eval(r-l, k);
    if(b <= l || r <= a) return dat[k];
    if(a <= l && r <= b) {
      lazy[k] = min(lazy[k],x);
      return lazy[k];
    }
    return dat[k] = min({dat[k],update(a, b, x, 2*k+1, l, (l+r)/2), update(a, b, x, 2*k+2, (l+r)/2, r)});
  }
  ll update(ll a, ll b, ll x) { return update(a, b, x, 0, 0, n); }

  // [a, b)
  ll query(ll a, ll b, ll k, ll l, ll r) {
    eval(r-l, k);
    if(b <= l || r <= a) return LLONG_MAX;
    if(a <= l && r <= b) return dat[k];
    ll vl = query(a, b, 2*k+1, l, (l+r)/2);
    ll vr = query(a, b, 2*k+2, (l+r)/2, r);
    return min(vl, vr);
  }
  ll query(ll a, ll b) { return query(a, b, 0, 0, n); }
};

int main(){
  ll n,m,ans=0;
  ll f=0;
  cin>>n>>m;
  s_t z;
  vector<s_t>v;
  for(ll i=0;i<m;i++){
    cin>>z.l>>z.r>>z.c;
    z.l--;
    z.r--;
    v.push_back(z);
  }
  sort(v.begin(),v.end(),asc);
  if(v[0].l!=0){
    cout<<-1<<endl;
    return 0;
  }
  RMQRUQ s(n);
  s.update(0,1,0);
  s.update(v[0].l+1,v[0].r+1,v[0].c);
  for(ll i=1;i<m;i++){
    ll x=s.query(v[i].l,v[i].r+1);
    if(x==LLONG_MAX) f=1;
    s.update(v[i].l,v[i].r+1,x+v[i].c);
  }
  ans=s.query(n-1,n);
  if(f==0&&ans!=LLONG_MAX)cout<<ans<<endl;
  else cout<<-1<<endl;
}


Measured memory_bytes: 7536
#include <iostream>
#include <vector>
#include <list>
#include <utility>
using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    vector<list<int> > lst(n);

    for(int i = 0; i < q; i++) {
        int p;
        cin >> p;
        if(p == 0) {
            int t, x;
            cin >> t >> x;
            lst[t].push_back(x);
        }
        else if(p == 1) {
            int t;
            cin >> t;
            list<int>::iterator itr = lst[t].begin();
            if(itr != lst[t].end()){
                cout << *itr;
            }
            while(++itr != lst[t].end()){
                cout << " " << *itr;
                //itr++;
            }
           
            cout << endl;   
        }
        else {
            int s, t;
            cin >> s >> t;
            /*
            if(lst[s].size() == 0){
                continue;
            }
            */
            lst[t].splice(lst[t].end(), lst[s]);
            //lst[s].clear();
        }
    }

}


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

using namespace std;

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N+ 1);
    for(int i = 1; i <= N; i++)
    {
        cin >> A[i];
    }
    vector<int> vec(N + 1,0);
    vector<int> ans;
    for(int j = N ; j >= 1; j--)
    {
        //vec[j]
        ll res = 0;
        for(int k = 2; j * k <= N; k++)
        {
            res += vec[ j * k];
            res %= 2;
        }
        if( A[j] != res)
        {
            vec[j] = 1;
            ans.push_back(j);
        }
        else
        {
            vec[j] = 0;
        }
    }

    //reverse(ans.begin(),ans.end());

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

    for(int i = 0; i < (int) ans.size(); i++)
    {
        cout << ans[i] << " " ;
    }
    return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
#define rep2(i,start,end) for(ll i = start; i < end; i++)
#define dwn(i,n) for(int i = n; i >= 0; i--)
#define dwn2(i,start,end) for(ll i = start; i >= end; i--)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f;
const ll Mode = 1e9 + 7;

int main(){
	int n,m;
	cin>>n;
	string s;
	cin>>s;
	if(n < 3200){
		cout<<"red"<<endl;
	}else{
		cout<<s<<endl;
	}
	return 0;
}

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

using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (auto &a : v){
        cin >> a;
    }       
    sort(v.begin() , v.end());
    int ans =0;
    for (int i  =0 ; i < k; ans += v[i++]);
    cout << ans << '\n';
    return 0;
}

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

main(){
  int n,s;
  while(true){
    scanf("%d%d",&n,&s);
    if (n==0)break;
    int r[101]={0};
    for(int i=0;i<n;i++){
      int tmp;scanf("%d",&tmp);r[tmp]++;
    }
    int ans = 0;
    for(int i=0;i<101;i++){
      if (i+i > s && r[i])ans += (r[i]*(r[i]-1))/2;
      for(int j=i+1;j<101;j++){
	if (i+j > s)ans += r[i]*r[j];
      }
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 0
L,R=map(int,input().split())
a=[]
if R-L>=2019:
	print(0)
else:
	for i in range(L,R+1):
		for j in range(i+1,R+1):
			a.append(((i%2019)*(j%2019))%2019)
 
	print(min(a))

Measured memory_bytes: 107276
//BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define N 10000010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
int n,d[N],t[N];
int vis[N],prime[N],tot;
ll ans;
inline void prepare(int Maxn)
{
	d[1]=1;
	for(register int i=2;i<=Maxn;i++)
	{
		if(!vis[i]){prime[++tot]=i;d[i]=2;t[i]=2;}
		for(register int j=1;j<=tot&&1LL*prime[j]*i<=Maxn;j++)
		{
			vis[i*prime[j]]=1;
			if(i%prime[j]){d[i*prime[j]]=d[i]*d[prime[j]];t[i*prime[j]]=2;}
			else {d[i*prime[j]]=d[i]/(t[i])*(t[i]+1);t[i*prime[j]]=t[i]+1;}
		}
	}
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	prepare(n);
	for(register int i=1;i<=n;i++)ans+=1LL*i*d[i];
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 123548
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

from collections import deque
sys.setrecursionlimit(10**6)

N, M = mi()
x = li2(M)

adj = [[] for i in range(N)]
for i in range(M):
    x[i][0] -= 1
    x[i][1] -= 1
    adj[x[i][0]].append(x[i][1])

flag = [0]*N
ans = deque([])

def dfs(x):
    if flag[x]:
        return None
    else:
        flag[x] = 1
        for a in adj[x]:
            dfs(a)
        global ans
        ans.appendleft(x)

for i in range(N):
    dfs(i)

dp = [0]*N
for a in ans:
    for b in adj[a]:
        dp[b] = max(dp[b], dp[a] + 1)

print(max(dp))

Measured memory_bytes: 140680
import heapq

N, M = map(int, input().split())
S = ["" for m in range(M)]

D = {}
for m in range(M):
    P, Y = map(int, input().split())
    listP = D.setdefault(P, [])
    heapq.heappush(listP, (Y, m))

for p, l in D.items():
    for i in range(len(l)):
        y, m = heapq.heappop(l)
        S[m] = format(p, "06") + format(i + 1, "06")

for s in S:
    print(s)


Measured memory_bytes: 38288
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
void vout(vl V) {
	for (ll i = 0; i < (ll)V.size(); i++) cout << V[i] << " ";
	cout << endl;
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color; vll path; vl A; vl dp; vl Ans;
int main(){
	cin >> H >> W;
	vector<string> A(H);
	for (i = 0; i < H; i++) {
		cin >> A[i];
	}
	vl validH(H);
	vl validW(W);
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (A[i][j] == '#') {
				validH[i] = 1; validW[j] = 1;
			}
		}
	}
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (validH[i] && validW[j]) {
				cout << A[i][j];
			}
		}
		if(validH[i]) cout << endl;
	}
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, q);
  multiset<ll> lo, hi;
  ll lo_sum = 0, hi_sum = 0;
  optional<ll> mid;
  ll bs = 0;
  while (q--) {
    in(int, t);
    if (t == 1) {
      in(ll, a, b);
      bs += b;
      if (!mid) {
        mid = a;
      } else if (a <= *mid) {
        lo.insert(a);
        lo_sum += *mid - a;
        while (lo.size() > hi.size()) {
          ll change = *mid - *lo.rbegin();

          hi.insert(*mid);
          hi_sum += change * hi.size();

          mid = *lo.rbegin();

          lo_sum -= change * lo.size();
          lo.erase(lo.find(*lo.rbegin()));
        }
      } else {
        hi.insert(a);
        hi_sum += a - *mid;
        while (lo.size() + 1 < hi.size()) {
          ll change = *hi.begin() - *mid;

          lo.insert(*mid);
          lo_sum += change * lo.size();

          mid = *hi.begin();

          hi_sum -= change * hi.size();
          hi.erase(hi.begin());
        }
      }
      dbg(lo.size(), hi.size());
      assert(lo.size() == hi.size() || lo.size() + 1 == hi.size());
      // dbg(*mid, lo_sum, hi_sum, lo.size(), hi.size());
    } else {
      out(*mid, lo_sum + hi_sum + bs);
    }
  }
}


Measured memory_bytes: 12948
import itertools

n = int(input())
p = [tuple(map(int, input().split())) for n_ in range(n)]
routes = [i for i in itertools.permutations(range(0,n), n)]

distances = 0
for route in routes:
    for i in range(len(route)-1):
        distances += ((p[route[i]][0] - p[route[i+1]][0])**2 + (p[route[i]][1] - p[route[i+1]][1])**2) ** 0.5

print(distances / len(routes))

Measured memory_bytes: 13964
#include <iostream>

using namespace std;

long long n, m;

int main()
{
	cin >> n >> m;
	for (long long i = m / n; i >= 1; i--)
	{
		if (m % i == 0)
		{
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()
s = input()
t = input()

if s == t:
	print(N)
	exit()

for i in range(1, N):
	if s[i:] == t[:-i]:
		print(N+i)
		break
else:
	print(2*N)

Measured memory_bytes: 5200
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n; cin >> n;
    if(n >= 30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 3632
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const inputs = input.trim().split('\n');
const n = Number(inputs.shift());
const adj = inputs.map((s) => s.split(' ').map(Number));

class Node {
  constructor(id) {
    this.id = id;
    this.children = [];
  }
  getDepth() {
    return this.parent ? this.parent.getDepth() + 1 : 0;
  }
  add(node) {
    node.parent = this;
    this.children.push(node);
  }
  getType() {
    if (this.getDepth() === 0) {
      return 'root';
    }
    return this.children.length ? 'internal node' : 'leaf';
  }
  toString() {
    return 'node ' + this.id + ': ' + [
      'parent = ' + (this.parent ? this.parent.id : -1),
      'depth = ' + this.getDepth(),
      this.getType(),
      '[' + this.children.map(node => node.id).join(', ') + ']',
    ].join(', ');
  }
}

class Tree {
  constructor() {
    this.map = new Map();
  }
  getNode(id) {
    if (!this.map.has(id)) {
      this.map.set(id, new Node(id));
    }
    return this.map.get(id);
  }
  print() {
    for (let i = 0; i < this.map.size; i++) {
      const node = this.map.get(i);
      console.log(node.toString());
    }
  }
}

const tree = new Tree();
adj.forEach(([id, k, ...ck]) => {
  const parent = tree.getNode(id);
  ck.forEach(c => {
    const node = tree.getNode(c);
    parent.add(node);
  });
});

tree.print();



Measured memory_bytes: 107780
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;

int main()
{
	int N, m6, m9;
	cin >> N;

	int ans = N;

	vector<int> v6, v9;

	v6.push_back(1);
	v9.push_back(1);

	int count = 6;
	while (count <= N) {
		v6.push_back(count);
		count *= 6;
	}

	count = 9;
	while (count <= N) {
		v9.push_back(count);
		count *= 9;
	}

	/*
	int  n = N;
	for (int i = v.size()-1; i >= 0; i--) {
		while (v[i] <= n) {
			n -= v[i];
			ans++;
		}
	}
	
	for (int i = 0; i < v.size(); i++) {
		cout << v[i] << endl;
	}*/

	for (int i = 0; i <= N/6; i++) {
		int count = 0;

		int res = 6*i;
		while(res != 0) {
			count += res%6;
			res = res/6;
		}

		res = N - 6*i;
		while (res != 0) {
			count += res % 9;
			res = res / 9;
		}
/*
		if (m6+m9>11) {
			count -= 10;
		}
		else if (m6 + m9>5) {
			count -= 5;
		}
*/
		if (ans > count) ans = count;
	}

	cout << ans;

	char qq;
	cin >> qq;
	return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> num(n);
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        --a[i];
        num[a[i]] = i+1;
    }
    
    sort(a.begin(), a.end());
    
    for(int i = 0; i < n; ++i) cout << num[i] << ' ';
    cout << endl;
}


Measured memory_bytes: 1664