akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

vector<string> a;

bool cmp(string s, string t) {
    if (s.length() != t.length()) return s.length() < t.length();
    return s < t;
}

void sol(string s) {
    a.push_back(s);
    if (s.length() == 10) return;
    if (s.back() != '0') {
        s += (s.back() - 1);
        sol(s);
        s.pop_back();
    }
    s += (s.back());
    sol(s);
    s.pop_back();
    if (s.back() != '9') {
        s += (s.back() + 1);
        sol(s);
        s.pop_back();
    }
}

int main() {
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << ' ' << a << ' ' << b;
}


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

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		String T = scan.next();
		scan.close();

		int Slength = S.length();
		int Tlength = T.length();

		ArrayList<String> SstrArray = new ArrayList<String>();

		for (int i = 0; i <= (Slength - Tlength); i++) {
			String Sstr = S.substring(i, Tlength + i);
			SstrArray.add(Sstr);
		}


		String[] Tarray = T.split("");
		int count = 0;
		int[] countArray = new int[SstrArray.size()];


		for (int j = 0; j < SstrArray.size(); j++) {
			String[] SstrArray2 = SstrArray.get(j).split("");
			for (int k = 0; k < Tarray.length; k++) {
				if (!(Tarray[k].equals(SstrArray2[k]))) {
					count = count + 1;
				}
			}
			countArray[j] = count;
			count = 0;
		}

		int countMin = countArray[0];
		for(int m = 0; m < countArray.length; m++) {
			if(countMin > countArray[m]) {
				countMin = countArray[m];
			}
		}

		System.out.println(countMin);

	}

}


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

int main() {
  int N, total = 0;
  cin >> N;

  // ここにプログラムを追記
  for (int i = 0; i < N; i++) {
    int st, ed;
    cin >> st >> ed;
    total += (ed - st + 1);
  }
  cout << total << endl;
}


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

const int MAX = 3000005;
const int MOD = 998244353;

long long fac[MAX]; //i!%MOD=fac[i]
long long finv[MAX]; //pow(i!,-1)%MOD=finv[i]
long long inv[MAX]; //pow(i,-1)%MOD=inv[i]

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(int argc, char const *argv[])
{
	COMinit();
	int n,m;
	cin>>n>>m;
	long long ans=COM(3*m+n-1,n-1);
	for (int i = 2*m+1; i <= 3*m; ++i)
	{
		ans-=(long long)n*COM(3*m+n-2-i,n-2)%MOD;
		ans%=MOD;
	}
	for (int i = 0; i < m; ++i)
	{
		ans-=COM(n-1+i,n-1)*COM(n,3*m-2*i)%MOD;
		ans%=MOD;
	}
	ans+=MOD;
	ans%=MOD;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 70656
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int count = 0;
		int ans = 0;
		for(int i=1; i<=N; i+=2){
			count = 0;
			for(int j=1; j<=i; j++){
				if(i%j==0){
					count++;
				}
			}
			if(count==8){
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 35232
import java.lang.Math.sqrt

fun main(args:Array<String>?): Unit {
    val n = readLine()!!.trim().toInt()
    val ratio = DoubleArray(n){readLine()!!.trim().toDouble()}
    println(
            solve(ratio)
    )
}
fun solve(ratio: DoubleArray): Double {
    val sorted = ratio.sorted()
    val minProb = 0.0001
    val sumProb = 0.03
    val sumSqrt = DoubleArray(sorted.size + 1){i -> if (i in sorted.indices) sqrt(sorted[i]) else 0.0}
    var min = Double.MAX_VALUE
    for (i in sumSqrt.lastIndex downTo 1) sumSqrt[i - 1] += sumSqrt[i]
    for (useMinProb in sorted.indices) {
        val restProb = sumProb - minProb * useMinProb
        val sumSqrtFrom = sumSqrt[useMinProb] / restProb
        if ((useMinProb until sorted.size).all{sqrt(sorted[it]) / sumSqrtFrom >= minProb}) {
            val estimated = (0 until useMinProb).map { sorted[it] / minProb }.sum() + (useMinProb until sorted.size).map { sorted[it] * sumSqrtFrom / sqrt(sorted[it])}.sum()
            if (min > estimated){
                min = estimated
            }
        }
    }
    return min * 300
}


Measured memory_bytes: 34896
import sys


def calc(itr):
    dp = [0]
    turn, no_turn, no_visit = 0, 0, 0
    for a in itr:
        b = a % 2
        new_turn = min(turn, no_visit) + (2 if a == 0 else b)
        new_no_turn = min(turn, no_turn, no_visit) + (b ^ 1)
        new_no_visit = no_visit + a
        dp.append(min(new_turn, new_no_turn, new_no_visit))
        turn, no_turn, no_visit = new_turn, new_no_turn, new_no_visit
    return dp


l = int(input())
aaa = list(map(int, sys.stdin))

dp_f = calc(aaa)
dp_b = calc(reversed(aaa))
dp_b.reverse()

print(min(map(sum, zip(dp_f, dp_b))))


Measured memory_bytes: 26844
def main():
    N, K = map(int, input().split())
    *A, = map(int, input().split())

    for _ in range(K):
        B = [0] * (N + 1)
        for i, x in enumerate(A):
            B[max(0, i - x)] += 1
            B[min(N - 1, i + x) + 1] -= 1
        for i in range(N):
            B[i + 1] += B[i]
        B.pop()
        if A == B: break
        A = B
    print(*A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 155868
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
int main(){
	ll n,x;
	cin>>n>>x;
	vi in(n+1);
	rep(i,n)cin>>in[i+1];
	rep(i,n)in[i+1]+=in[i];
	ll out=inf;
	loop(i,1,n+1){
		ll sum=x*(n+i),co=1;
		for(ll j=n;j>=0;j-=i){
			ll t=co*2+1;
			if(co==1)t=5;
			sum+=(in[j]-in[max(0ll,j-i)])*t;
			if(sum>out)break;
			co++;
		}
		cmin(out,sum);
	}
	cout<<out<<endl;
}







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

int main() {
  int r,b,g;
  int num;
  
  cin >> r >> b >> g;
  
  num = r*100 + b*10 + g;
  
  if(num%4==0){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}


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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int a, b, c, d;cin>>a>>b>>c>>d;

    int a1 = a*c;
    int a2 = a*d;
    int a3 = b*c;
    int a4 = b*d;
    int max=a1;
    if(a2>max)max=a2;
    if(a3>max)max=a3;
    if(a4>max)max=a4;
    cout<<max<<endl;


    return 0;
}

Measured memory_bytes: 3640
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}

void func(void)
{
//DEBUG_OUT("----\n");
    string s;
    cin >> s;
    for(uint32 i=0; i<8; i++){
        s.pop_back();
    }
    cout << s << endl;

    return;
}



Measured memory_bytes: 256
S = str(input())

if S[0]==S[1] and S[1]!=S[2] and S[2]==S[3]:
    print("Yes")
elif S[0]!=S[1] and S[1]==S[2] and S[3]==S[0]:
    print("Yes")
elif S[0]==S[2] and S[0]!=S[1] and S[1]==S[3]:
    print("Yes")
else:
    print("No")

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

int main(){
  int N,min_cost=1000000000;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    
  }
  for(int i=-100;i<101;i++){
    int cost=0;
    for(int j=0;j<N;j++){
      int B=A.at(j)-i;
      cost+=pow(B,2);
    }
    min_cost=min(min_cost,cost);
  }
  cout << min_cost << endl;
}  

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ep emplace_back
#define st first
#define sc second

using namespace std;

const ll mod = 998244353;
const int e = 1e6 + 69;
const int base = 311;

// dung igt thay cho gt luc tinh giai thua
// 3
// cach tao hoan vi tu n so : n*(n+1)/2;

ll a[e];
ll b[e];
ll l[e], r[e];

int main()
{
    int n;
    cin >> n;
    ll minn = 1e18;
    ll maxx = 0;
    ll cur;
    l[0] = 0;
    r[n+1] = 0;
    for(ll i=1; i<=n; i++)
    {
        cin >> a[i];
        l[i] = __gcd(l[i-1], a[i]);
    }
    for(int i=n; i>=1; i--)
    {
        r[i] = __gcd(r[i+1], a[i]);
        maxx = max(__gcd(r[i+1], l[i-1]), maxx);
    }
    cout << maxx;
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;
 
const ll INF = 1e18;
const int MOD = 1e9+7;

int n,k;
vi a;

bool valid(int mx) {
 
	ll cnt=0;
 
	for(int i=0; i<n && cnt<=n+k; ++i) {
		cnt+=ceil(a[i]/double(mx));
	}
 
	return cnt<=n+k;
 
}
 
int main() {
	
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
 
	cin>>n>>k;
	int mx=INT_MIN;
	a.resize(n);
	for(int&q : a) cin>>q, mx=max(mx, q);

	int ans=0;
	
	for(int k=mx-1; k>=1; k/=2)
		while(!valid(ans+k))
			ans+=k;
 
	cout<<ans+1<<"\n";
 
	return 0;
}



Measured memory_bytes: 3892
# D - Water Bottle

from math import atan, pi

a, b, x = map(int, input().split())

theta = 0
if a * a * b / 2 < x:
    theta = atan((2 * ((a ** 2) * b - x)) / (a ** 3))
else:
    theta = atan((a * (b ** 2)) / (2 * x))

print(theta * 180 / pi)


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;

    return 0;
}

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

const int N=2e5+20;

int n,a[N];
long long ans;
map <int,int> m;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		ans+=m[a[i]-i];
		m[-a[i]-i]++;
	}

	cout<<ans;
}


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	if(a <= k){
		k -= a;
		a = 0;

		if(k <= b){
			b -= k;
		}
		else{
			b = 0;
		}
	}
	else{
		a -= k;
	}

	cout << a << " " << b;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int n, i, j, k, best, s;
	cin >> n;
	vector<int> a(n);
	for (i = 0; i < n; i++) cin >> a[i];
	s = 0;
	for (auto p : a) {
		s = s + p - 1;
	}
	cout << s << "\n";


	return 0;
}


Measured memory_bytes: 256
import java.awt.geom.Line2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	class P implements Comparable<P> {
		double x, y;

		P(double x_, double y_) {
			x = x_;
			y = y_;
		}

		P add(P p) {
			return new P(x + p.x, y + p.y);
		}

		P sub(P p) {
			return new P(x - p.x, y - p.y);
		}

		P mul(double v) {
			return new P(x * v, y * v);
		}

		P div(double v) {
			return new P(x / v, y / v);
		}

		double dot(P p) {
			return x * p.x + y * p.y;
		}

		double det(P p) {
			return x * p.y - y * p.x;
		}

		double abs2() {
			return x * x + y * y;
		}

		double abs() {
			return Math.sqrt(abs2());
		}

		P norm() {
			return div(abs());
		}

		P rot90() {
			return new P(-y, x);
		}

		P proj(P src, P dst) {
			P p_sd = dst.sub(src).norm();
			return src.add(p_sd.mul(sub(src).dot(p_sd)));
		}

		P reflect(P src, P dst) {
			P middle = proj(src, dst);
			return add(middle.sub(this).mul(2));
		}

		public String toString() {
			return String.format("%f %f", x, y);
		}

		@Override
		public int compareTo(P o) {
			if (Math.abs(x - o.x) > 1e-6)
				return Double.compare(x, o.x);
			else {
				return Double.compare(y, o.y);
			}
		}
	}

	P isLL(P p1, P p2, P q1, P q2) {
		double d = p2.sub(p1).det(q1.sub(q2));
		if (Math.abs(d) < 1e-10)
			return null;
		return p1.add(p2.sub(p1).mul(q1.sub(q2).det(p1.sub(q2)) / d));
	}

	P[] isCC(P c1, double r1, P c2, double r2) {
		ArrayList<P> ret = new ArrayList<>();
		double d = c1.sub(c2).abs();
		if (d < 1e-10)
			return new P[0];
		double cos = (r1 * r1 + d * d - r2 * r2) / (2 * d * r1);
		P midP = c1.add(c2.sub(c1).norm().mul(r1 * cos));
		double h = r1 * Math.sqrt(1 - cos * cos);
		ret.add(midP.add(c2.sub(c1).norm().rot90().mul(h)));
		if (h == 0)
			return new P[] { midP.add(c2.sub(c1).norm().rot90().mul(h)) };
		else {
			return new P[] { midP.add(c2.sub(c1).norm().rot90().mul(h)), midP.add(c2.sub(c1).norm().rot90().mul(-h)) };
		}
	}

	boolean intersect(P p1, P p2, P q1, P q2) {
		return Line2D.linesIntersect(p1.x, p1.y, p2.x, p2.y, q1.x, q1.y, q2.x, q2.y);
	}

	double distSS(P p1, P p2, P q1, P q2) {
		if (intersect(p1, p2, q1, q2))
			return 0;
		double dist = Double.MAX_VALUE;
		for (double d : new double[] { distSP(p1, p2, q1), distSP(p1, p2, q2), distSP(q1, q2, p1),
				distSP(q1, q2, p2) }) {
			dist = Math.min(d, dist);
		}
		return dist;
	}

	double distSP(P p1, P p2, P p) {
		return Line2D.ptSegDist(p1.x, p1.y, p2.x, p2.y, p.x, p.y);
	}

	void run() {

		Scanner sc = new Scanner(System.in);
		P c1 = new P(sc.nextDouble(), sc.nextDouble());
		double r1 = sc.nextDouble();
		P c2 = new P(sc.nextDouble(), sc.nextDouble());
		double r2 = sc.nextDouble();
		P[] ps = isCC(c1, r1, c2, r2);
		Arrays.sort(ps);
		if (ps.length == 1) {
			System.out.println(ps[0].toString() + " " + ps[0].toString());
		} else {
			System.out.println(ps[0].toString() + " " + ps[1].toString());
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

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

int main() {
	int n;
  	cin >> n;
  	vector<int> vec(n);
  	for(auto &i : vec) cin >> i;
  	
  	int mx = 0;
  	for(int i = 0; i < n - 1; i++) {
    	for(int j = i + 1; j < n; j++) {
        	mx = max(mx, abs(vec[i] - vec[j]));
        }
    }
  	cout << mx;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,t,ans="",s1="",s2="";
  int flag=1,f=0,ind;
  vector<int> index;
  cin>>s>>t;
  if(s.size()>=t.size())
  for(int i=0;i<=s.size()-t.size();i++)
  {
     flag=1;
      for(int k=i;k<i+t.size()&&k<s.size();k++)
      {
      //  cout<<s[k]<<"-->"<<t[k-i];
        if(s[k]==t[k-i]||s[k]=='?')
        {
        }
        else
        {
          flag=0;
          break;
        }
        // cout<<i<<" "<<k<<endl;
      }
      if(flag)
      {
        f=1;
        index.push_back(i);
       // break;
      }
     // cout<<"\n"<<endl;
  }
  if(f)
  {
    ind=index[0];
   // cout<<"index"<<ind<<endl;
     for(int i=0;i<ind;i++)
     {
       if(s[i]!='?')
        s1+=s[i];
        else
          s1+='a';
     //   cout<<"#"<<ans<<endl;
     }
     for(int i=ind;i<ind+t.size();i++)
     {
      s1+=t[i-ind];
      //  cout<<">>"<<ans<<endl;
     }
     for(int i=ind+t.size();i<s.size();i++)
     {
      if(s[i]!='?')
        s1+=s[i];
        else
        s1+='a';
      //    cout<<".."<<ans<<endl;
     }
    ind=index[index.size()-1];
  //   cout<<"index"<<ind<<endl;
     for(int i=0;i<ind;i++)
     {
       if(s[i]!='?')
        s2+=s[i];
        else
          s2+='a';
      //  cout<<"#"<<ans<<endl;
     }
     for(int i=ind;i<ind+t.size();i++)
     {
      s2+=t[i-ind];
      //  cout<<">>"<<ans<<endl;
     }
     for(int i=ind+t.size();i<s.size();i++)
     {
      if(s[i]!='?')
        s2+=s[i];
        else
        s2+='a';
        //  cout<<".."<<ans<<endl;
     }
     if(s1<s2)
     ans=s1;
     else
      ans=s2;
  }
  if(!f)
    cout<<"UNRESTORABLE"<<endl;
  else
    cout<<ans<<endl;
  return 0;
}
/*
????cd?
asdacdghj
*/

Measured memory_bytes: 256
import math
N = int(input())
li = []

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

sum = 0
for l1 in li:
  for l2 in li:
    sum += math.sqrt((l1[0]-l2[0]) ** 2 + (l1[1]-l2[1]) ** 2)/N

print(sum)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int min(int a,int b){
    if(a<b) return a;
    else return b;
}


int main(){
    int he[100005],dp[100005];
    int n,k;
    cin >> n >> k;
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++){
        cin >> he[i];
    }
    
    for(int i=n;i>=0;i--){
         int result;
    if(i==n) result=0;
    
    else{
        int x=-1;
        for(int j=i+1;j<=n;j++){
            int a;
            a=abs(he[i]-he[j])+dp[j];
            
            if(x==-1) x=a;
            x=min(x,a);
            if(j-i==k) break;
        }
        result=x;
    }
    dp[i]=result;
    }
    cout << dp[1] << endl;
    
}

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

void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!T;r.popFront;}}

void main()
{
  int[] a; readA(3, a);
  a.sort();
  writeln(a[0] == a[1] ? a[2] : a[0]);
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll N, K;

bool f(ll num, vector<ll> &A, vector<ll> &F) {
    ll remain = K;
    rep(i, N) {
        if (A[i] * F[i] > num) {
            remain -= (A[i] * F[i] - num + F[i] - 1) / F[i];
            if (remain < 0) {
                return false;
            }
        }
    }
    return true;
}

void Main() {
    cin >> N >> K;
    vector<ll> A(N), F(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> F[i];
    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());
    ll ok = INF;
    ll ng = -1;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        if (f(mid, A, F)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3456
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC push_options
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, less<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define MOD 1000000007LL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={-1,1,0,0,1,1,-1,-1};
const vector<lint> dy={0,0,-1,1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[](auto f,auto... args){return f(f,args...);};

int main(){
    lint n;
    cin>>n;
    vec a(n);
    rep(i,n)cin>>a[i];
    lint x=a.back();
    lint i=-1;
    rep(j,n-1){
        if(a[j]<=x){
            i++;
            swap(a[i],a[j]);
        }
    }
    swap(a[i+1],a.back());
    rep(j,n){
        if(j)cout<<" ";
        if(j==i+1)cout<<"[";
        cout<<a[j];
        if(j==i+1)cout<<"]";
    }
    cout<<endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;
 
int main(){
    string s;
    cin>>s;
    sort(ALL(s));
    int d[26]={0};
    rep(i,s.size()) {
        d[(int)(s[i]-97)]++;
    }
    rep(i,26){
        if (d[i]==0) {
            cout<<(char)('a'+i)<<endl;
            return 0;
        }
    }
    cout<<"None"<<endl;
    return 0;
}

Measured memory_bytes: 512
n = gets.to_i
until n == 0
    count = 0
    while n != 1
        if n % 2 == 0
            n /= 2
            count += 1
        elsif n % 2 == 1
            n *= 3
            n += 1
            count += 1
        end
    end
    puts count
    n = gets.to_i
end


Measured memory_bytes: 6852
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct node{
  int key;
  struct node *p;
  struct node *r;
  struct node *l;
} Tree;
Tree *root = NULL;

void insert(int key){
  Tree *z = (Tree*)malloc(sizeof(Tree));
  z -> key = key;
  z -> l = NULL;
  z -> r = NULL;
  Tree *x, *y;
  x = root;
  y = NULL;
  while(x != NULL){
    y = x;
    if(z -> key < x -> key)
      x = x -> l;
    else
      x = x -> r;
  }
  z -> p = y;
  if(y == NULL)
    root = z;
  else if(z -> key < y -> key) 
    y -> l = z;
  else
    y -> r = z;
}
Tree* find(int key){
  Tree *c = root;
  while(c != NULL){
    if(c -> key == key){
      return c;
    }else if(key < c -> key)
      c = c -> l;
    else
      c = c -> r;
  }
  return NULL;
}
Tree* treeMinimum(Tree *x){
  while(x -> l != NULL)
    x = x -> l;
  return x;
}
Tree* treeSuccessor(Tree *x){
  if(x -> r != NULL)
    return treeMinimum(x -> r);
  Tree *y = x -> p;
  while(y != NULL && x == y -> r){
    x = y;
    y = y -> p;
  }
  return y;
}
void delete(Tree *c){
  Tree *x, *y;
  if(c -> l == NULL || c -> r == NULL)
    y = c;
  else
    y = treeSuccessor(c);
  if(y -> l != NULL)
    x = y -> l;
  else
    x = y -> r;

  if(x != NULL)
    x -> p = y -> p;
  
  if(y -> p == NULL)
    root = x;
  else{
    if(y == y -> p -> l)
      y -> p -> l = x;
    else
      y -> p -> r = x;
  }

  if(y != c)
    c -> key = y -> key;
  
  free(y);
}
void printInorder(Tree *u){
  if(u == NULL)
    return;
  printInorder(u -> l);
  printf(" %d", u -> key);
  printInorder(u -> r);
}
void printPreorder(Tree *u){
  if(u == NULL)
    return;
  printf(" %d", u -> key);
  printPreorder(u -> l);
  printPreorder(u -> r);
}

int main(){
  int n, key;
  char line[100];
  char *str_ptr, *key_ptr;

  fgets(line, sizeof(line), stdin);
  sscanf(line, "%d", &n);
  for(int i = 0; i < n; ++i){
    fgets(line, sizeof(line), stdin);
    if(strcmp(line, "print") == 0 || strcmp(line, "print\n") == 0){
      printInorder(root);
      printf("\n");
      printPreorder(root);
      printf("\n");
    }else{
      str_ptr = strtok(line, " ");
      key_ptr = strtok(NULL, " ");
      sscanf(key_ptr, "%d", &key);
      if(strcmp(str_ptr, "insert") == 0)
        insert(key);
      else if(strcmp(str_ptr, "find") == 0){
        if(find(key) != NULL)
          printf("yes\n");
        else
          printf("no\n");
      }
      else if(strcmp(str_ptr, "delete") == 0){
        Tree *c = find(key);
        delete(c);
      }
    }
  }
  return 0;
}



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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    ll n;
    cin >> n;
    vector<ll> sq;
    ll cnt = 1;
    while (cnt * cnt <= n)
    {
        sq.push_back(cnt*cnt);
        cnt++;
    }
    sort(sq.begin(), sq.end());
    cout << sq[sq.size() - 1] << endl;
    return 0;
}

Measured memory_bytes: 640
import scala.io.StdIn._

object Main extends App {

  val s = readLine()
  val t = readLine()
  def solve() = {
    val sLen = s.length
    val tLen = t.length
    val maxMatchCnt = (0 to sLen-tLen).foldLeft(0) { (maxMatchCnt, i) =>
      val tmpMatchCnt = (0 until tLen).foldLeft(0) { (matchCnt, j) =>
        if(s(j+i) == t(j)) matchCnt+1 else matchCnt
      }
      Math.max(tmpMatchCnt, maxMatchCnt)
    }
    tLen - maxMatchCnt
  }

  println(solve())

}



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

struct RUP{
  int n;
  vector<int> dat,laz;
  const int def=INT_MAX;
  RUP(){}
  RUP(int n_){init(n_);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,def);
    laz.clear();
    laz.resize(2*n-1,-1);
  }
  inline void eval(int len,int k){
    if(laz[k]<0) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=laz[k];
      laz[k*2+2]=laz[k];
    }
    dat[k]=laz[k];
    laz[k]=-1;
  }
  int update(int a,int b,int x,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b) return laz[k]=x;
    eval(r-l,k);
    dat[k]=min(update(a,b,x,k*2+1,l,(l+r)/2),
	       update(a,b,x,k*2+2,(l+r)/2,r));
    return dat[k];
  }
  int query(int a,int b,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return def;
    if(a<=l&&r<=b) return dat[k];
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
  void update(int a,int b,int x){
    update(a,b,x,0,0,n);
  }
  int query(int a,int b){
    return query(a,b,0,0,n);
  }
};

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N, Q; cin >> N >> Q;
    vector<T> XST;
    vector<int> vals;
    rep(i, N) {
        int S, T, X; cin >> S >> T >> X;
        XST.pb(make_tuple(X, S, T));
        vals.pb(S-X);
        vals.pb(T-1-X);
    }
    int D[Q];
    rep(i, Q) {
        cin >> D[i];
        vals.pb(D[i]);
    }
    
    sort(vals.begin(), vals.end());
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    map<int, int> idx;
    rep(i, vals.size()) idx[vals[i]] = i;
    
    sort(XST.begin(), XST.end());
    reverse(XST.begin(), XST.end());
    RUP lst(vals.size());
    rep(i, N) {
        int X = get<0>(XST[i]);
        int S = get<1>(XST[i]);
        int T = get<2>(XST[i]);
        lst.update(idx[S-X], idx[T-X-1]+1, X);
    }
    
    rep(i, Q) {
        int res = lst.query(idx[D[i]], idx[D[i]]+1);
        if (res==INT_MAX) printf("%d\n", -1);
        else printf("%lld\n", res);
    }
}

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

typedef long long ll;
const int maxn=900010;
const ll mo=1e9+7;
ll N,M,K;
ll frac[maxn],inv[maxn];
ll ans,sum;

ll powmod(ll a,ll b)
{
	ll ans=1;
	while (b)
	{
		if (b&1)	ans=(ans*a)%mo;
		a=(a*a)%mo;
		b>>=1;
	}
	return ans;
}
ll C(ll a,ll b)
{
	ll ans=frac[a];
	ans=(ans*inv[b])%mo;
	ans=(ans*inv[a-b])%mo;
	return ans;
}
int main()
{
	cin>>N>>M>>K;
	frac[0]=1;
	inv[0]=1;
	for (int i=1;i<=900000;i++)
		frac[i]=(frac[i-1]*i)%mo;
	inv[900000]=powmod(frac[900000],mo-2);
	for (int i=899999;i>=1;i--)
		inv[i]=(inv[i+1]*(i+1))%mo;
	sum=1;
	for (int q=0;q<=M+K;q++)
	{
		ans=(ans+(((sum*C(q+N-1,N-1))%mo)*powmod(3LL,M+K-q))%mo)%mo;
		sum=(sum*2LL)%mo;
		if (q==M+K)
			continue;
		if (q>=M)
			sum=(sum-C(q,M)+mo)%mo;
		if (q>=K)
			sum=(sum-C(q,K)+mo)%mo;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14336
#include <stdio.h>

int n;
int size[100],to[100][100],cost[100][100],dist[100]; 

void tani(int p, int c){
  int i;
  dist[p] = c;
  for(i=0;i<size[p];i++){
    if(dist[to[p][i]] > c+cost[p][i])
      tani(to[p][i], c+cost[p][i]);
  }
}
 
int main(){
  int i, j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    int u;
    scanf("%d",&u);
    scanf("%d",&size[u]);
    for(j=0;j<size[u];j++){
      scanf("%d",&to[u][j]);
      scanf("%d",&cost[u][j]);
    }
  }
  for(i=0;i<n;i++) dist[i] = 100000000;
  tani(0,0);
  for(i=0;i<n;i++){
    printf("%d %d\n", i, dist[i]);
  }
  return 0;
}




Measured memory_bytes: 1956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef DEBUG
	#define D(x...) printf(x);
#else
	#define D(x...)
#endif
ll x[100010], y[100010], n, ans;
bool done[100010];
int main()
{
	scanf("%lld", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%lld%lld", &x[i], &y[i]);
	}
	int s = -100001;
	int e = 100001;
	while (1)
	{
		int m = s + (e-s)/2;
		vector<ll> before, after;
		for (int i = 0; i < n; i++)
		{
			if (y[i] <= m) before.push_back(y[i]);
			if (x[i] >= m) after.push_back(x[i]);
		}
		sort(before.begin(), before.end());
		sort(after.begin(), after.end());
		reverse(after.begin(), after.end());
		ll am = 0;
		ll at = 0;
		if (m <= 0)
		{
		for (int i = 0; i < min(before.size(), after.size()); i++)
		{
			am += abs(before[i]-at);
			at = before[i];
			am += abs(after[i]-at);
			at = after[i];
		}
		if (before.size() > after.size())
		{
			int i = after.size();
			am += abs(before[i]-at);
			at = before[i];
		}
		am += abs(at);
		ans = max(ans, am);
		}
		if (m >= 0)
		{
		am = 0;
		at = 0;
		for (int i = 0; i < min(before.size(), after.size()); i++)
		{
			am += abs(after[i]-at);
			at = after[i];
			am += abs(before[i]-at);
			at = before[i];
		}
		if (after.size() > before.size())
		{
			int i = before.size();
			am += abs(after[i]-at);
			at = after[i];
		}
		am += abs(at);
		ans = max(ans, am);
		}
	//	printf("%d %d\n", s, e);
		if (s == e) break;
		if (before.size() > after.size()) e = m;
		else s = m+1;
	}
	s = -100001;
	e = 100001;
	while (1)
	{
		int m = s + (e-s)/2;
		vector<ll> before, after;
		for (int i = 0; i < n; i++)
		{
			if (y[i] <= m) before.push_back(y[i]);
			if (x[i] >= m) after.push_back(x[i]);
		}
		sort(before.begin(), before.end());
		reverse(before.begin(), before.end());
		sort(after.begin(), after.end());
		reverse(after.begin(), after.end());
		ll am = 0;
		ll at = 0;
		if (m <= 0)
		{
		for (int i = 0; i < min(before.size(), after.size()); i++)
		{
			am += abs(before[i]-at);
			at = before[i];
			am += abs(after[i]-at);
			at = after[i];
		}
		if (before.size() > after.size())
		{
			int i = after.size();
			am += abs(before[i]-at);
			at = before[i];
		}
		am += abs(at);
		ans = max(ans, am);
		}
		if (m >= 0)
		{
		am = 0;
		at = 0;
		for (int i = 0; i < min(before.size(), after.size()); i++)
		{
			am += abs(after[i]-at);
			at = after[i];
			am += abs(before[i]-at);
			at = before[i];
		}
		if (after.size() > before.size())
		{
			int i = before.size();
			am += abs(after[i]-at);
			at = after[i];
		}
		am += abs(at);
		ans = max(ans, am);
		}
	//	printf("%d %d\n", s, e);
		if (s == e) break;
		if (before.size() >= after.size()) e = m;
		else s = m+1;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 3692
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
using ll = long long;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((int)(x).size())
#define MSG(a) cout << #a << " " << a << endl;

int main()
{
    ll t_cookies;
    ll a_cookies;
    ll repeat;
    cin >> t_cookies >> a_cookies >> repeat;

    if (t_cookies <= repeat) {
        repeat -= t_cookies;
        t_cookies = 0;
        if (a_cookies <= repeat) {
            a_cookies = 0;
        } else {
            a_cookies -= repeat;
        }
    } else {
        t_cookies -= repeat;
    }

    cout << t_cookies << " " << a_cookies;

    return 0;
}


Measured memory_bytes: 256
"""
B
"""
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

xyc=[list(map(int,input().split())) for i in range(M)]

ans=float("inf")
for x,y,c in xyc:
    ans=min(ans,a[x-1]+b[y-1]-c)
ans=min(ans,min(a)+min(b))
print(ans)




Measured memory_bytes: 80188
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

struct Prime{
  vector<int> prime; // 2,3,5,7,11...
  vector<bool> is_prime; // 素数=1,合成数=0
  void eratos(int n){
    is_prime.resize(n+1,true);
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= n; i++){
      if(is_prime[i]){
        prime.push_back(i);
        for(int j = i*2; j <= n; j+=i){
          is_prime[j] = false;
        }
      }
    }
  }

  //因数分解
  map<int,int> prime_factor(int n){
    map<int,int> mp; //{約数,個数}
    for(int i = 2; i*i <= n; i++){
      while(n%i == 0){
        mp[i]++;
        n /= i;
      }
    }
    if(n != 1) mp[n] = 1; //n=素数
    return mp;
  }

  //mpから作れる、約数をちょうどn個もつ数の個数
  int factor_cnt(map<int,int> mp,int n){
    vector<int> dp(n+2); //約数がちょうどi個の数の個数
    dp[1] = 1;
    for(auto p : mp) {
      for(int i = n; i > 0; i--) {
        for(int j = p.second; j > 0; j--) {
          dp[ min(n+1,i*(j+1)) ] += dp[i];
        }
      }
    }
    return dp[n];
  }
}prime;

signed main(){

  int n; cin >> n;

  int ans = 0;
  for(auto p : prime.prime_factor(n)){
    for(int i = 1; p.second >= i; i++){
      p.second -= i;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)

int main() {
int a,b;
cin >> a;
cout<< 48-a;
return(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
const int N=105,mod=1e9+7,inv2=(mod+1)/2;
int xx[N],yy[N],x[N],y[N],w[N][N],d[N][N],q[N*N][2];
int H,W,n,m,cnt,ans;

int S2(int n){
	return (ll)n*(n+1)/2%mod;
}

int main(){
	read(H),read(W),read(cnt);
	xx[++n]=1,xx[++n]=H+1,yy[++m]=1,yy[++m]=W+1;
	rep(i,1,cnt){
		read(x[i]),read(y[i]),x[i]++,y[i]++;
		xx[++n]=x[i],xx[++n]=x[i]+1;
		yy[++m]=y[i],yy[++m]=y[i]+1;
	}
	sort(xx+1,xx+n+1),n=unique(xx+1,xx+n+1)-xx-1;
	sort(yy+1,yy+m+1),m=unique(yy+1,yy+m+1)-yy-1;
	rep(i,1,n-1) rep(j,1,m-1){
		w[i][j]=(ll)(xx[i+1]-xx[i])*(yy[j+1]-yy[j])%mod;
	}
	rep(i,1,cnt){
		x[i]=lower_bound(xx+1,xx+n+1,x[i])-xx;
		y[i]=lower_bound(yy+1,yy+m+1,y[i])-yy;
		w[x[i]][y[i]]=0;
	}
	rep(k,1,n-1) if(xx[k+1]-xx[k]>=2){
		int up=0,down=0;
		rep(i,1,n-1) rep(j,1,m-1){
			if(i<k) up=(up+w[i][j])%mod;
			if(i>k) down=(down+w[i][j])%mod;
		}
		ans=(ans+(ll)up*down%mod*(xx[k+1]-xx[k]-1))%mod;
		ans=(ans+(ll)(up+down)*W%mod*S2(xx[k+1]-xx[k]-1))%mod;
		int sum=0;
		rep(i,1,xx[k+1]-xx[k]-1) sum=(sum+(ll)i*(xx[k+1]-xx[k]-i))%mod;
		ans=(ans+(ll)W*W%mod*sum)%mod;
	}
	rep(k,1,m-1) if(yy[k+1]-yy[k]>=2){
		int le=0,ri=0;
		rep(i,1,n-1) rep(j,1,m-1){
			if(j<k) le=(le+w[i][j])%mod;
			if(j>k) ri=(ri+w[i][j])%mod;
		}
		ans=(ans+(ll)le*ri%mod*(yy[k+1]-yy[k]-1))%mod;
		ans=(ans+(ll)(le+ri)*H%mod*S2(yy[k+1]-yy[k]-1))%mod;
		int sum=0;
		rep(i,1,yy[k+1]-yy[k]-1) sum=(sum+(ll)i*(yy[k+1]-yy[k]-i))%mod;
		ans=(ans+(ll)H*H%mod*sum)%mod;
	}
	rep(i,1,n-1) rep(j,1,m-1) if(w[i][j]){
		int r=0;
		memset(d,-1,sizeof d);
		q[++r][0]=i,q[r][1]=j,d[i][j]=0;
		rep(l,1,r){
			int x=q[l][0],y=q[l][1];
			REP(dir,4){
				int xx=x+dx[dir],yy=y+dy[dir];
				if(!w[xx][yy]||d[xx][yy]>=0) continue;
				d[xx][yy]=d[x][y]+1;
				q[++r][0]=xx,q[r][1]=yy;
			}
		}
		rep(x,1,n-1) rep(y,1,m-1) if(w[x][y])
			ans=(ans+(ll)w[i][j]*w[x][y]%mod*d[x][y]%mod*inv2)%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, A, B = map(int, input().split())
    result = 0
    for n in range(N + 1):
        if A <= sum([int(i) for i in list(str(n))]) <= B:
            result += n
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
until (m = $<.gets.to_i).zero?
  result = m.times.map do
    id, *score = $<.gets.split.map(&:to_i)
    th = 0
    
    final_point = 10.times.map do |i|
      if i == 9
        if score[th] == 10 or score[th] + score[th + 1] == 10
          score[th, 3].sum
        else
          score[th, 2].sum
        end
      elsif score[th] == 10
        th += 1
        10 + score[th, 2].sum
      else
        if score[th, 2].sum == 10
          th += 2
          10 + score[th]
        else
          th += 2
          score[th - 2] + score[th - 1]
        end
      end
    end.sum
    
    [id, final_point]
  end.sort {|a, b| (b[1] <=> a[1]).nonzero? || a[0] <=> b[0]}
  puts result.map {|ary| ary.join(" ")}
end


Measured memory_bytes: 6960
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int n,x;
    int ans=0;

    
    while(1){
        cin >> n >> x;
        ans=0;
        if(n== 0 and x==0){
            return 0;
        }
        for (int a = 1; a <= n; a++)
        {
            for (int b = a + 1; b <= n; b++)
            {
                if ( x - a - b > b and x - a - b <= n)
                {
                    ans++;
                }
            }
    }
    cout<<ans<<endl;
}}


Measured memory_bytes: 3100
N = 10000
x = gets.to_i
dp = Array.new(N){ |i| i ** 5 }

dp.each_with_index do |a,i|
  dp.each_with_index do |b,j|
    if a + b == x
      puts [i,-j].join(" ")
      exit
    end

    if a - b == x
      puts [i,j].join(" ")
      exit
    end
  end
end


    

Measured memory_bytes: 14712
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> cnt(n, 0);

  rep(i, k){
    int d; cin >> d;
    rep(j, d){
      int a; cin >> a;
      a--;
      cnt[a]++;
    }
  }

  int ans = 0;
  rep(i, n){
    if(cnt[i] == 0) ans++;
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) (a).begin(),(a).end()

template<typename T1, typename T2> inline void chkmin(T1 & x, const T2 & y) {if (y < x) x = y;}
template<typename T1, typename T2> inline void chkmax(T1 & x, const T2 & y) {if (x < y) x = y;}

#define int ll

struct pt{
	int x, y;
	pt() {}
	pt(int _x, int _y) {
		x = _x, y = _y;
	}
};

bool operator<(const pt & a, const pt & b) {
	return tie(a.x, a.y) < tie(b.x, b.y);
}

int n;
vector<pt> a[4];

int get(char x) {
	if (x == 'U') return 0;
	if (x == 'R') return 1;
	if (x == 'D') return 2;
	if (x == 'L') return 3;
	assert(false);
	return -1;
}

void read() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x, y;
		char t;
		cin >> x >> y >> t;
		a[get(t)].push_back({x, y});
	}
}

const int INF = 1e9 + 228;
int ans = INF;

vector<int> get(vector<pt> a, int t) {
	vector<int> ans;
	for (auto i : a) {
		if (t == 0) {
			ans.push_back(i.x);
		} else {
			ans.push_back(i.y);
		}
	}
	return ans;
}

void solveOneDir(vector<int> a, vector<int> b, int add) {
	sort(all(a));
	sort(all(b));
	for (auto i : a) {
		int pos = lower_bound(all(b), i) - b.begin();
		if (pos == (int)b.size()) continue;
		chkmin(ans, add * (b[pos] - i));
	}
}

const int N = 2e5 + 10;

vector<int> fx[N][4];
vector<int> fy[N][4];

map<int, vector<int>> have[2];

void solvePerpDir(vector<pt> u, vector<pt> r) {
	have[0].clear();
	have[1].clear();
	for (auto [x, y] : u) {
		have[0][x + y].push_back(x);
	}
	for (auto [x, y] : r) {
		have[1][x + y].push_back(x);
	}
	for (auto i : have[1]) {
		if (!have[0].count(i.first)) continue;
		solveOneDir(i.second, have[0][i.first], 10);
	}
}

void make(vector<pt> & a, int t) {
	for (auto &[x, y] : a) {
		if (t == 0) x = -x;
		else if (t == 1) y = -y;
	}
}

void run() {
	for (int i = 0; i < 4; i++) {
		for (auto [x, y] : a[i]) {
			fx[x][i].push_back(y);
			fy[y][i].push_back(x);
		}
	}
	for (int i = 0; i < N; i++) {
		solveOneDir(fx[i][0], fx[i][2], 5);
		solveOneDir(fy[i][1], fy[i][3], 5);
	}
	solvePerpDir(a[0], a[1]);
	make(a[1], 1);
	make(a[2], 1);
	solvePerpDir(a[2], a[1]);
	make(a[0], 0);
	make(a[3], 0);
	solvePerpDir(a[0], a[3]);
	make(a[3], 1);
	make(a[2], 0);
	solvePerpDir(a[2], a[3]);
}

void write() {
	if (ans == INF) {
		cout << "SAFE" << endl;
	} else {
		cout << ans << endl;
	}
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(20), cout.setf(ios::fixed);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 76208
#include<iostream>
#include<array>
#include<algorithm>

using namespace std;

int main(){
    array<int, 10> mountain_height;
    for(int i = 0; i < 10; i++){
        cin >> mountain_height[i];
    }
    sort(begin(mountain_height), end(mountain_height));
    for(int i = 0; i < 3; i++){
        cout << mountain_height[9-i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1172