akhauriyash/Code-Regression huggingface dataset:
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int n,t;
int ai, bi;
vpi foods;
int dp[3010][6020];

signed main(){
    I(n); I(t);
    REP(i,n){
        I(ai); I(bi);
        foods.eb(ai,bi);
    }
    sort(all(foods));
    int ans = 0;
    REP(i,n) REP(j,t + 3001){
        dp[i+1][j] = dp[i][j];
        if (0 <= j - foods[i].first && j - foods[i].first < t) 
            dp[i+1][j] = max(dp[i+1][j], dp[i][j - foods[i].first] + foods[i].second);
        ans = max(ans, dp[i+1][j] );
    }
    cout << ans << endl;
}

Measured memory_bytes: 141568
x, y = map(int, input().split())
num1 = [1, 3, 5, 7, 8, 10, 12]
num2 = [4, 6, 9, 11]
if x in num1 and y in num1 or x in num2 and y in num2:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define boostIO                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, b, a) for (int i = b; i >= a; i--)
#define sz(v) (int)(v.size())
#define all(v) v.begin(), v.end()
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define trav(a, x) for (auto &a : x)
#define pb push_back
#define fi first
#define se second
#define int long long
#define mod 1000000007
#define rem 998244353
#define maxn 300005
const int INF = 1e18;
typedef pair<int, int> pii;


signed main() {
    boostIO;
    string s, t;
    cin >> s >> t;
    int n = s.length(), m = t.length();
    int ans = 2000;
    for(int i = 0; i + m - 1 < n; i++){
        int mn = 0;
        for(int j = i; j < i + m; j++){
            if(s[j] != t[j - i]){
                mn++;
            }
        }
        ans = min(ans, mn);
    }
    cout << ans << endl;
    return 0;
}
// XD ;;

Measured memory_bytes: 3656
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define Reverse(x) reverse(all(x));
#define Sort(x) sort(all(x));
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    string s;
    cin>>s;
    bool c=false;
    if (s=="keyence"){ 
        c=true;
    }
        rep(i, s.size()) {
        for(lli j=1;i+j<=s.size();j++){
            string sc=s;
            sc.erase(i, j);
            if (sc=="keyence"){ 
                c=true;
                break;
            }
        }
    }
    YES(c);
}

Measured memory_bytes: 3600
fun main() {
    b()
}

fun a() {
    val s = readLine()!!
    fun aa(): Int {
        if (s == "RRR") return 3
        if (s.take(2) == "RR" || s.takeLast(2) == "RR") return 2
        if (s.any { it == 'R' }) return 1
        return 0
    }
    aa().toLong().print()
}

fun b() {
    val N = readLong()
    val L = readLongList().sorted()
    var ans = 0L
    L.forEachIndexed { i, l ->
        L.drop(i + 1).forEachIndexed{ j, m ->
            L.drop(i + j + 2).forEachIndexed { k, n ->
                if (l + m > n) {
                    if (l != m && l != n && m != n) {
                        ans++
                    }
                }
            }
        }
    }
    ans.print()
}

fun readLong() = readLine()!!.toLong()
fun readLongList() = readLine()!!.split(" ").map { it.toLong() }

fun Long.bitEach(action: (Int) -> Unit) {
    (0 until Long.SIZE_BITS).forEach { action(((this shr it) and 1).toInt()) }
}

fun Long.bitFilter(bit: Int) = (0 until Long.SIZE_BITS).filter { ((this shr it) and 1) == 1L }

fun <T1, T2> pairs(first: Iterable<T1>, second: Iterable<T2>) = first.flatMap { t1 -> second.map { t2 -> t1 to t2 } }

fun Long.primeSequence() = sequence<Long> {
    var n = this@primeSequence
    if (n % 2L == 0L) {
        yield(2L)
        n /= 2L
    }
    var i = 3L
    while (n > 0) {
        if (n % i == 0L) {
            yield(i)
            n /= i
        }
        i += 2L
    }
}

fun Long.print() {
    println(this)
}

Measured memory_bytes: 42744
#include <bits/stdc++.h>
using namespace std;
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>=k;i--)
int main(){
    long long ansl=0,ansh=0,n,m,x;
    cin>>n>>m>>x;
    vector <long long> a(n+1,0);
    f(i,0,m){
        long long b;
        cin>>b;
        if(b<x){
            ansl++;
        }
        else if(b>x){
            ansh++;
        }
    }
    cout<<min(ansl,ansh)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<deque>
#include<utility>
#include<map>
#include<set>
using namespace std;

int visit[1000000] = {0},dis[1000000] = {0};
vector<int> v[1000000];

int dfs(int p){
    int max_dis,temp_dis;
    visit[p] = 1;
    max_dis = 1;
    for(int i = 0;i<v[p].size();i++){
        if(visit[v[p][i]] == 1){
            if(dis[v[p][i]] <= 0){
                dis[p] = -1;
                return -1;
            }
            max_dis = max(dis[v[p][i]] + 1,max_dis);
        }
        else{
            dis[v[p][i]] = dfs(v[p][i]);
            if(dis[v[p][i]] == -1){
                dis[p] = -1;
                return -1;
            }
            max_dis=max(max_dis,dis[v[p][i]]+1);
        }
    }
    dis[p] = max_dis;
    return max_dis;
}

int main(){
    int n, input[1000],ans = 0;
    cin >> n;
    //1.2....n,n+1....2n(a>bでa,bのペアがあったら(a-1)*n+b)
    for(int i=1;i<=n;i++){
        for(int j=0;j<n-1;j++){
            cin >> input[j];
            if(j){
                //現在の番号のvectorに前の番号を追加
                v[max(i-1,input[j]-1)*n+min(i,input[j])].push_back(max(i-1,input[j-1]-1)*n+min(i,input[j-1]));
            }
            
        }
    }
    //cout << "finish input" << endl;
    for(int i=1;i<n;i++){
        for(int j=i;j<n;j++){
            if(visit[i+j*n]==0){
                dis[i+j*n] = dfs(i+j*n);
            }
            if(dis[i+j*n] == -1){
                cout << -1 << endl;
                return 0;
            }
            ans = max(ans,dis[i+j*n]);
        }
    }
    cout << ans << endl;
}


/*
int dfs(int p){
    int res1=1,res2=0;
    visit[p]=1;
    for(int i=0;i<v[p].size();i++){
        if(visit[v[p][i]]==1&&dis[v[p][i]]){
            res2=dis[v[p][i]]+1;
            if(res2==0){
                dis[p]=-1;
                return -1;
            }
            res1=max(res1,res2);
        }
        else if(visit[v[p][i]]==1&&!dis[v[p][i]]){
            dis[p]=-1;
            return -1;
        }
        else{
            res2=dfs(v[p][i])+1;
            if(res2==0){
                dis[p]=-1;
                return -1;
            }
            res1=max(res2,res1);
        }
    }
    dis[p]=res1;
    return res1;
}

int main(){
    int n,a[1000],ans=0,flag,f[1001]={};
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        for(int j=0;j<n-1;j++){
            scanf("%d",&a[j]);
            if(j){
                v[max(i-1,a[j]-1)*n+min(i,a[j])-1].push_back(max(i-1,a[j-1]-1)*n+min(i,a[j-1])-1);
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            if(visit[i*n+j]==0){
                dis[i*n+j]=dfs(i*n+j);
            }
            if(dis[i*n+j]==-1){
                printf("-1\n");
                return 0;
            }
            ans=max(ans,dis[i*n+j]);
        }
    }
    printf("%d\n",ans);
}*/


Measured memory_bytes: 47232
n = int(input())
s = [input() for i in range(n)]
for i in range(n):
    s[i] = sorted(s[i])
s.sort()
result = 0
count = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        count += 1
    else:
        result += (count*(count-1))//2
        count = 1
result += count*(count-1)//2
print(result)


Measured memory_bytes: 24664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int N;
long long int A[200005], B[200005];

vector<long long int > VA, VB;

int main(void) {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];

		VA.push_back(A[i]); VB.push_back(B[i]);
	}

	long long int ans = 0;

	if (N % 2 == 0) {

		sort(VA.begin(), VA.end());
		sort(VB.begin(), VB.end());
		long long int a = VA[N / 2 - 1] + VA[N / 2];
		long long int b = VB[N / 2 - 1] + VB[N / 2];
		 ans = b - (a - 1);
	}
	else {
		sort(VA.begin(), VA.end());
		sort(VB.begin(), VB.end());

		long long int a = VA[N / 2];
		long long int b = VB[N / 2];

		ans = b - (a - 1);
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 9364
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let inline gcd x y =
    let zero = LanguagePrimitives.GenericZero
    let rec loop x y = if y = zero then x else loop y (x % y)
    loop (abs x) (abs y)

let factorize n =
    let rec loop acc m i =
        if i * i > n then
            Set.add m acc
        else
            match (m / i, m % i) with
            | (q, 0L) -> loop (Set.add i acc) q i
            | _ -> loop acc m (i + 1L)
    loop Set.empty n 2L
    |> Set.remove 1L

[<EntryPoint>]
let main _ =
    let [a;b] = reads int64
    gcd a b
    |> factorize
    |> Set.count
    |> (+) 1
    |> printfn "%i"
    0

Measured memory_bytes: 14940
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    l, r, d = nm()
    print(r//d - (l-1)//d)
    return

solve()


Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int A, B; cin >> A >> B;

    if(A < B){
        for(int i=0; i<B; i++){
            cout << A;
        }
    }else{
        for(int i=0; i<A; i++){
            cout << B;
        }
    }
    
}

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

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define ld long double
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 2e5 + 10;
const int M = (int) 2e6 + 10;
const int K = (int) 20;
const int INF = (int) 1e9 + 7;
const int mod = (int) 998244353;
const ld EPS = (ld) 1e-9;
const ll LINF = (ll) 1e18;

int n;
int a[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	#ifdef sony
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	srand(time(0));
	cin >> n;
	int mn = INF;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		mn = min(mn, a[i]);
	}	
	for (int i = 1; i <= n; i++) {
		if (a[i] > mn + 1) {
			cout << "No";
			exit(0);
		}
	}
	int cnt_min = 0;
	for (int i = 1; i <= n; i++) {
		if (mn == a[i]) 
			cnt_min++;
	}
	if (cnt_min == n) {
		if (mn == n - 1) {
			cout << "Yes";
			exit(0);
		}
		mn--;
		cnt_min = 0;
	}
	if (cnt_min > mn) {
		cout << "No";
		exit(0);
	}
	int k = n - cnt_min;
	int diff = mn + 1 - cnt_min;
	if (diff >= 0 && k >= diff * 2) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	return 0;	
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    cout << max(0, A-B);

    return 0;
}


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

using namespace std; 


int main(){

string s;
cin>>s;
int i,n;
long b = 0;
long res = 0;
n = s.size();

for(i=0;i<n;i++){
    if(s[i]=='B') b++;
    else res += b;
}

cout<<res;
return 0;
}



Measured memory_bytes: 1336
#include<stdio.h>

int selectionSort(int A[],int N){
  int i,j,temp,count = 0,minj;
  for(i = 0;i < N-1;i++){
    minj = i;
    for(j = i;j < N;j++){
      if(A[j] < A[minj])
	minj = j;
    }
    temp = A[i];
    A[i] = A[minj];
    A[minj] = temp;
    if(i != minj)
      count++;
  }
  return count;
}
  
int main(){
  int A[100],N,i,count;
  scanf("%d",&N);
  for(i = 0;i < N;i++)
    scanf("%d",&A[i]);
    count = selectionSort(A,N);

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

    return 0;
}



Measured memory_bytes: 2100
#include <stdio.h>

int main(void){

  int N,A[100];
  scanf("%d",&N);
  int k;
  for(k=0;k<N;k++) {
    scanf("%d",&A[k]);
  }
  int i,j;
  int count=0;
  for(j=N-1;j>0;j--){
    for(i=0;i<j;i++){
      int v = A[i];
      if(A[i]>A[i+1]){
	A[i]=A[i+1];
	A[i+1]=v;
	count++;
      }
    }
  }
  for(k=0;k<N;k++) {
    printf("%d",A[k]);
    if(k != N-1){
      printf(" ");
    }
  }
  printf("\n");
  printf("%d\n",count);
  return 0;

}


Measured memory_bytes: 1992
#include <iostream>
#include <string>

using namespace std;
int main(void){ 
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  string m;
  for (int i = 0; i < n; i++){
    m.push_back(s[i]);
    m.push_back(t[i]);
  }
  cout << m << endl;

return 0;
}

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

// #define int long long

#define ii pair<int,int>
#define fi first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define all(x) (x).begin(),(x).end()

#define sqr(x) ((x)*(x))

signed main() {
#ifdef _DEBUG
  freopen("in", "r", stdin);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  unsigned long long a, b, c;
  cin >> a >> b >> c;
  long long lla = a, llb = b, llc = c;
  if (llc - lla - llb < 0LL) cout << "No" << '\n';
  else cout << (a * b * 4ULL < sqr(c - a - b) ? "Yes" : "No") << '\n';
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<ll, ll>> vpll;

//mt19937 random(566);
//uniform_int_distribution<ll> distr;
//ll rnd(ll a, ll b) {return a + distr(random) % (b - a + 1);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    int cnt = 0;
    while (n) cnt++, n /= k;
    cout << cnt << "\n";
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)//rep(i,回数){処理}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    ll x, k, d; cin >> x >> k >> d;
    ll ans;
    x = abs(x);//原点からーや＋であっても同じ
    //往復せずに終わる場合
    if (x / d > k) {
        ans = x - d * k;
    }
    //往復する場合
    else {
        ll e = x / d;//往復するまでの回数
        k = k - e;//往復できる回数
        x = x - e * d;//今の座標は？
        if (k % 2 == 1) { ans = abs(x - d); }
        if (k % 2 == 0) { ans = x; }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3608
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>

using namespace std;

int N;
int a[3008];
long long dp[3008][3008];

long long solve(int s, int e) {
    if(s==e) {
        return a[s];
    }
    if(!dp[s][e]) {
        dp[s][e] = 0x8000000000000000ll ^ max(a[s]-solve(s+1, e), a[e]-solve(s, e-1));
    }
    return dp[s][e] ^ 0x8000000000000000ll;
}

int main() {
	scanf("%d", &N);
    for(int n=0; n<N; ++n) {
        scanf("%d", &a[n]);
    }
    printf("%lld\n", solve(0, N-1));
	return 0;
}


Measured memory_bytes: 70144
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int main(){
//	freopen("input.txt","r",stdin);
	LL a,b,c;
	LL cnt=0;
	scanf("%lld%lld%lld",&a,&b,&c);
	while(1){
		if(a&1||b&1||c&1) break;
		if(a==b&&b==c){
			printf("-1\n");
			return 0;
		}
		int aa=a/2,bb=b/2,cc=c/2;
		a=aa+bb;
		b=bb+cc;
		c=cc+aa;
		cnt++;
	}
	printf("%lld\n",cnt);
	return 0;
}

Measured memory_bytes: 256
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = new Date();
  Main();
  var end = new Date() - start;
  
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var N = nextInt();
	var list = nextIntArray();
	var set = new Array(N).fill(0);
	for(var i = N - 1; i >= 0; i--){
		var bai = i + 1;
		var sum = 0;
		for(var j = 1; j * bai <= N; j++){
			var index = j * bai - 1;
			sum += set[index];
		}
		if(sum % 2 != list[i] % 2){
			set[i]++
		}
	}
	var output = [];
	for(var i = 0; i < N; i++){
		if(set[i] == 1){
			output.push(i + 1);
		}
	}
	myout(output.length);
	if(output.length > 0){
		myout(myconv(output, 8));
	}
}


Measured memory_bytes: 48180
from sys import stdin
A,B,m = map(int,stdin.readline().rstrip().split())
a = list(map(int,stdin.readline().rstrip().split()))
b = list(map(int,stdin.readline().rstrip().split()))
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
mina = min(a)
minb = min(b)
goukei = min(a)+min(b)
for i,j,k in li:
    goukei = min(goukei,a[i-1]+b[j-1]-k)
print(goukei)

Measured memory_bytes: 38564
import sys

N, Y = map(int, input().split())

for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        if z < 0:
            continue
        if 10000*x + 5000*y + 1000*z == Y:
            print(x,y,z)
            sys.exit(0)

print(-1,-1,-1)

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

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

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int r;
    cin >> r;
    int ans = 3 * r * r;
    cout << ans << endl;
    return 0;
}


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

const double PI = acos(-1);

void koch(int n, pair<double,double> p1, pair<double,double> p2){
    if( n==0 )
        return;
    pair<double,double> s, t, u;
    double th = PI*60/180;

    s.first = (2.0*p1.first+ 1.0*p2.first)/3.0;
    s.second = (2.0*p1.second + 1.0*p2.second)/3.0;
    t.first = (1.0*p1.first+ 2.0*p2.first)/3.0;
    t.second = (1.0*p1.second + 2.0*p2.second)/3.0;
    u.first = (t.first - s.first)*cos(th) - (t.second-s.second)*sin(th)+s.first;
    u.second = (t.first - s.first)*sin(th) + (t.second-s.second)*cos(th)+s.second;

    koch(n-1,p1,s);
    cout << s.first << ' ' << s.second << endl;
    koch(n-1,s,u);
    cout << u.first << ' ' << u.second << endl;
    koch(n-1,u,t);
    cout << t.first << ' ' << t.second << endl;
    koch(n-1,t,p2);
}


int main()
{
    pair<double,double> a = make_pair(0,0);
    pair<double,double> b = make_pair(100,0);

    int n;
    cin >> n;
    cout << fixed << setprecision(10);
    cout << a.first << ' ' << a.second << endl;
    koch(n, a, b);
    cout << b.first << ' ' << b.second << endl;

    return 0;

}



Measured memory_bytes: 3244
import java.util.Scanner;

public class Main {public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				int N=sc.nextInt();
				int M=sc.nextInt();
				if(N+M==0) break;
				int[] h=new int[N+2];
				int[] w=new int[M+2];
				for(int i=1; i<=N; i++) {
					h[i]=sc.nextInt();
				}
				for(int i=1; i<=M; i++) {
					w[i]=sc.nextInt();
				}
				int[] hnum=new int[1500010];
				int[] wnum=new int[1500010];
				int sum=0;
				for(int i=1; i<=N; i++) {
					sum=0;
					for(int j=i; j<=N; j++) {
						sum+=h[j];
						hnum[sum]++;
					}
				}
				for(int i=1; i<=M; i++) {
					sum=0;
					for(int j=i; j<=M; j++) {
						sum+=w[j];
						wnum[sum]++;
					}
				}
				sum=0;
				for(int i=1; i<=1500000; i++) {
					sum+=hnum[i]*wnum[i];
				}
				System.out.println(sum);
			}
			
		}
	}
}


Measured memory_bytes: 501456
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))

V = [-1 for _ in range(N + 1)]

s = 1

while K != 0:
    if V[s] != -1:
        step = V[s] - K
        K = K % step
        if K != 0:
            V[s] = K
            s = A[s]
            K -= 1
    else:
        V[s] = K
        s = A[s]
        K -= 1

print(s)



Measured memory_bytes: 32376
import std.stdio, std.algorithm;

int a, b, step;

void main(){
	while (readf("%d %d\n", &a, &b), a + b > 0) {
		step = 0;
		if (b > a) swap(a, b);
		while (b != 0) {
			a %= b;
			swap(a, b);
			step++;
		}
		writeln(a, " ", step);
	}
}

Measured memory_bytes: 1000
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    string s;cin>>s;
    int p=700;
    for(int i=0;i<3;i++){
        if(s[i]=='o')p+=100;
    }
    cout<<p<<endl;
}


Measured memory_bytes: 3568
from heapq import heappop,heappush
n,m = map(int,input().split())
edge = [[] for _ in range(n)]
del_edge = []
cnt = 0

for _ in range(m):
    a,b = map(int,input().split())
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)
    del_edge.append((a,b))

def find(s,de):
    visited = [False] * n
    visited[s] = True
    que = []
    for e in edge[s]:
        if s in de and e in de:
            continue
        heappush(que,e)
    while que:
        v = heappop(que)
        if visited[v]:
            continue
        visited[v] = True
        for vtx in edge[v]:
            if v in de and vtx in de:
                continue
            hq = vtx
            heappush(que,hq)
    if False in visited:
        return 1
    else:
        return 0

for i in range(m):
    tmp = del_edge[i]
    cnt += find(0,tmp)

print(cnt)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fori(n) for ( int i = 0; i < (n);i++)
#define forj(n) for ( int j = 0; j < (n);j++)
#define fork(n) for ( int k = 0; k < (n);k++)
#define forghj(n) for ( int ghj = 0; ghj < (n);ghj++)
#define fori1(n) for ( int i = (n)-1; i >= 0;i--)
#define all(vector) (vector).begin(),(vector).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define INF 1e9+7
/*
────────▄──────────────▄
────────▌▒█───────────▄▀▒▌
────────▌▒▒▀▄───────▄▀▒▒▒▐
───────▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐
─────▄▄▀▒▒▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐
───▄▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀██▀▒▌
──▐▒▒▒▄▄▄▒▒▒▒▒▒▒▒▒▒▒▒▒▀▄▒▒▌
──▌▒▒▐▄█▀▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐
─▐▒▒▒▒▒▒▒▒▒▒▒▌██▀▒▒▒▒▒▒▒▒▀▄▌
─▌▒▀▄██▄▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒▒▒▌
_▌▀▐▄█▄█▌▄▒▀▒▒▒▒▒▒░░░░░░▒▒▒▐
▐▒▀▐▀▐▀▒▒▄▄▒▄▒▒▒▒▒░░░░░░▒▒▒▒▌
▐▒▒▒▀▀▄▄▒▒▒▄▒▒▒▒▒▒░░░░░░▒▒▒▐
─▌▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒▒▒░░░░▒▒▒▒▌
─▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
──▀▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▒▒▒▒▌
────▀▄▒▒▒▒▒▒▒▒▒▒▄▄▄▀▒▒▒▒▄▀
───▐▀▒▀▄▄▄▄▄▄▀▀▀▒▒▒▒▒▄▄▀
──▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀▀
*/

int main() {
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    cout << a*b - a - b + 1;
}


Measured memory_bytes: 764
N,K = map(int,input().split())
An = list(map(int,input().split()))

rtn=0
bit_max = 40
for s in range(bit_max, -1, -1):
  target = 1 << s
  numof_hit = len([1 for a in An if a & target != 0])
  
  if target<=K and numof_hit < N-numof_hit:
    numof_hit = N-numof_hit
    K -= target
  
  rtn += target * numof_hit

print(rtn)

Measured memory_bytes: 14700
#include <iostream>

using namespace std;

int main()
{
    int p, q, r;
    cin >> p >> q >> r;

    if (p >= q && p >= r)
    {
        cout << q + r << endl;
    }
    else if (q >= p && q >= r)
    {
        cout << p + r << endl;
    }
    else
    {
        cout << p + q << endl;
    }
    
    return 0;
}

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

int a[5];

bool isStraight(){
	vector<int> n;
	for(int i=0 ; i<5 ; i++){
		n.push_back(a[i]);
	}
	sort( n.begin(), n.end() );
	if( n[0]+1 == n[1] && n[1]+1 == n[2] && n[2]+1 == n[3] && n[3]+1 == n[4]){
		return true;
	}
	if( n[0]==1 && n[1]==10 && n[2]==11 && n[3]==12 && n[4]==13){
		return true;
	}
	return false;
}

string checkCard(){
	int n, count, c[5];
	int c2=0, c3=0, c4=0;

	for(int j=0 ; j<5 ; j++){
		count = 0;
		n = a[j];
		for(int i=0 ; i<5 ; i++){
			if(a[i]==n)count++;
		}
		c[j] = count;
	}
	for(int i=0 ; i<5 ; i++){
		if(c[i]==2)c2++;
		if(c[i]==3)c3++;
		if(c[i]==4)c4++;
	}
	if(c4==4) return "four card";
	else if(c3==3 && c2==2) return "full house";
	else if( isStraight() ) return "straight";
	else if(c3==3) return "three card";
	else if(c2==4) return "two pair";
	else if(c2==2) return "one pair";
	else return "null";
}

int main(){
	string str;
	char s[80];
	while( scanf("%d,%d,%d,%d,%d", &a[0], &a[1], &a[2], &a[3], &a[4] ) != EOF ){
		str = checkCard();
		printf("%s\n",str.c_str());
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define repran(i, a,b) for (int i = a; i<b;i++)
#define all(x) (x).begin(), (x).end()
#define v(T) vector<T>
#define vv(T) vector<v(T)>
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;


int main()
{
    int n;
    cin >> n;
    vll a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll cnt = 0, t = 0;
    rep(i, n) cnt += b[i]-a[i];
    if (cnt < 0) {
        cout << "No" << endl;
        return 0;
    }
    rep(i, n){
        if (a[i] >= b[i]) t += b[i]-a[i];
        else t += (b[i]-a[i])/2;
    }
    if (t >= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long i, k;
    string s;
    cin >> k;
    cin >> s;
    for(i=0;i<k;i++){
        if(i>=s.size()) break;
        cout << s[i] ;
    }
    if(s.size()>k) cout << "...";
    cout <<endl;
    return 0;
}



Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

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

const int MAXN = 100005;

int R, C, N;
vector <pii> row[MAXN];
vector <pii> graph[MAXN];
int r[MAXN], c[MAXN], a[MAXN];
bool bio[MAXN];
ll val[MAXN];
ll mini[MAXN];
int comp[MAXN];

void load() {
	scanf("%d%d%d", &R, &C, &N);
	for (int i = 0; i < N; i++)
		scanf("%d%d%d", r + i, c + i, a + i);
}

ll dfs(int x, ll c, int root) {
	val[x] = c;
	comp[x] = root;
	bio[x] = true;
	ll res = c;
	for (int i = 0; i < graph[x].size(); i++)
		if (!bio[graph[x][i].first])
			res = min(res, dfs(graph[x][i].first, c + graph[x][i].second, root));
	return res;
}

bool solve() {
	for (int i = 0; i < N; i++) 
		row[--r[i]].push_back(pii(--c[i], a[i]));
	
	for (int i = 0; i < R; i++)
		for (int j = 1; j < row[i].size(); j++) {
			graph[row[i][0].first].push_back(pii(row[i][j].first, row[i][j].second - row[i][0].second));
			graph[row[i][j].first].push_back(pii(row[i][0].first, row[i][0].second - row[i][j].second));
		}	
	
	for (int i = 0; i < C; i++) 
		if (!bio[i]) 
			mini[i] = dfs(i, 0, i);
	
	for (int i = 0; i < R; i++)
		for (int j = 1; j < row[i].size(); j++) 
			if (val[row[i][j].first] - val[row[i][0].first] != (ll)(row[i][j].second - row[i][0].second))
				return false;
	
	for (int i = 0; i < N; i++)
		if (a[i] - val[c[i]] + mini[comp[c[i]]] < 0)
			return false;
	
	return true;
}

int main() {
	load();
	puts(solve() ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 14336
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++)
		cin>>v[i];
	int massimo=-1, c=0;
	for(int i=0;i<n;i++){
		if(v[i]>massimo) massimo=v[i], c=1;
		else if(v[i]==massimo) c++;
	}
	int smassimo=0;
	for(int i=0;i<n;i++)
		if(v[i]!=massimo)
			smassimo=max(smassimo,v[i]);
	for(int i=0;i<n;i++){
		if(v[i]==massimo) cout<<(c>1?massimo:smassimo);
		else cout<<massimo;
		cout<<" ";
	}
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define se second
#define fi first
#define endl "\n"
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n,m;
	cin>>m>>n;
	ll arr[n];
	ll x,y,z=0;
	for(int a=0;a<n;a++)
	{
		cin>>arr[a];
		z+=arr[a];
	}
	if(m>=z)
	cout<<m-z;
	else 
	cout<<"-1";
	return 0;
}

Measured memory_bytes: 3684
#include <iostream>

using namespace std;

int main(void) {

	string weathers;
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> weathers;
	cin.ignore();

	char lastWeather = 'S';
	int count=0;
	for(int i=0; i< weathers.length(); i++ ) {
		if(weathers[i]== 'R') {		   
			if(lastWeather == 'R') {
				count++;
			}
			else if(count == 0) {
				count = 1;
			}
		}
		lastWeather = weathers[i];
	}
	
	cout << count;
		
	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll n,m; cin >> n >> m;
	vl a(m),b(m);
	vvl c(m);
	rep(i,m){
		cin >> a[i] >> b[i];
		rep(j,b[i]){
			ll tmp; cin >> tmp; tmp--;
			c[i].push_back(tmp);
		}
	}
	vl dp(1<<n,inf);
	dp[0] = 0;
	rep(bit,1<<n){
		rep(i,m){
			ll mask = bit;
			rep(j,b[i]) mask |= 1<<c[i][j];
			chmin(dp[mask],dp[bit]+a[i]);
		}
	}
	ll ans = dp[(1<<n)-1];
	if(ans==inf) cout << -1 << endl;
	else cout << ans << endl;
}


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

int main() {
  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  if (*max_element(A.begin(),A.end()) <= 0) {
    auto ind = int(max_element(A.begin(), A.end())-A.begin());
    cout << A[ind] << '\n';
    cout << N-1 << '\n';
    for (int i = N-1; i > ind; i--) {
      cout << i+1 << '\n';
    }
    for (int i = 0; i < ind; i++) {
      cout << 0+1 << '\n';
    }
    exit(0);
  }
  long long bestVal = 0;
  vector<int> bestOps;
  for (int z = 0; z < 2; z++) {
    vector<int> curOps;
    long long curVal = 0;
    for (int i = N-1; i >= 0; i--) {
      if ((i&1) == z) {
        if (A[i] < 0) { curOps.push_back(i); if (i==0) curOps.push_back(i); }
        else curVal += A[i];
      } else {
        if (i>0 && A[i-1] < 0) ;
        else curOps.push_back(i);
      }
    }
    if (curVal > bestVal) { bestVal = curVal, bestOps = curOps; }
  }
  assert(bestVal > 0);
  cout << bestVal << '\n';
  cout << bestOps.size() << '\n';
  for (int v : bestOps) cout << v+1 << '\n';
}

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

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size() - t.size() + 1;
    int min = t.size();
    for (int i = 0; i < n; ++i) {
        int count = 0;
        for (int j = 0; j < int(t.size()); ++j) {
            if (t[j] != s[i+j]) {
                count++;
            }
        }
        if (min > count) {
            min = count;
        }
    }
    cout << min << "\n";
    return 0;
}


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

int main(){
    int n,k,q;
    cin>>n>>k>>q;
    vector<int> a(n,0);
    for (int i = 0; i < q; ++i) {
        int t;
        cin>>t;
        --t;
        ++a[t];
    }
    for (int i = 0; i < n; ++i) {
        if(k-(q-a[i])>0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <vector>
#include <stdlib.h>
using namespace std;

typedef enum{INIT, DISCOVERD, FINISHED} mark_e;
typedef struct{
  vector<int> adj; 
  mark_e mark;
} v_t;

void dfs_visit(){
  return;
}

void dfs_visit( vector<v_t>& G_r, const int unode ){
  G_r[unode].mark = DISCOVERD;
  for( int i = 0 ; i != G_r[unode].adj.size() ; i++ ){
    int v = G_r[unode].adj[i];
    if( G_r[v].mark==DISCOVERD){
      printf("1\n");
      exit(0);
    }
    if(G_r[v].mark==INIT){
      dfs_visit(G_r, v);
    }
  }
  G_r[unode].mark = FINISHED;

  return;
}

int main(){
  vector<v_t> G;  // graph : index is each vertex
  int vmax; int emax;

  scanf("%d %d" ,&vmax ,&emax);
  for(int i=0 ; i<vmax ; i++){
    v_t onev;
    onev.mark   = INIT;
    G.push_back(onev);
  }
  for( int cnt=0 ; cnt<emax ; cnt++ ){
    int s, t; // source, target
    scanf("%d %d" ,&s ,&t);
    G[s].adj.push_back(t);
  }

  for(int u=0 ; u<vmax ; u++ ){
    if( G[u].mark == INIT ){
      dfs_visit( G, u ); 
    }
  }
  printf("0\n");

  /* Test vector
  for(int i=0 ; i<vmax ; i++ ){
    printf("%d->" ,i );
    for( int j=0 ; j != G[i].adj.size() ; j++ ){
      printf("%d->" ,G[i].adj[j] );
    }
    printf("\n");
  }
  */

  return 0;
}




Measured memory_bytes: 2740
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

class UF {
private:
    int sz; vector<int> par,nrank;
public:
    UF(){}
    UF(int node_size){ sz = node_size; par.resize(sz),nrank.resize(sz); rep(i,sz){ par[i] = i; nrank[i] = 0; } }
    int find(int x){ if(par[x] == x){ return x; }else{ return par[x] = find(par[x]); } }
    void unite(int x,int y)
    { x = find(x),y = find(y); if(x == y) return;
    	if(nrank[x] < nrank[y]){ par[x] = y; }else{ par[y] = x; if(nrank[x] == nrank[y]) nrank[x]++; } }
    bool same(int x,int y){ return find(x) == find(y); }
};

template<typename T> class Kruskal{
public:
	struct edge{
		int u,v;
		T cost;
		bool operator<(const edge& another) const {
			return cost < another.cost;
		}
	};
	vector<edge> es;
	int V;
    Kruskal(int node_size) : V(node_size){}
	void add_edge(int u,int v,T cost){
		es.push_back((edge){u,v,cost});
	}
	T solve(){
		UF uf(V);
		T res = 0;
		int cnt = 0;
        sort(es.begin(),es.end());
		rep(i,(int)es.size()){
			edge e = es[i];
			if(!uf.same(e.u,e.v)){
				uf.unite(e.u,e.v);
				res += e.cost;
				cnt++;
				if(cnt == V-1){
					break;
				}
			}
		}
		return res;
	}
};

typedef pair<P,int>pi;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
	Kruskal<ll> kr(n);
	vector<pi> u(n),v(n);
	rep(i,n){
		int x,y;
		cin >> x >> y;
		u[i] = pi(P(x,y),i);
		v[i] = pi(P(y,x),i);
	}
	sort(all(u)), sort(all(v));
	rep(i,n-1){
		kr.add_edge(u[i].se,u[i+1].se,min(abs(u[i].fi.fi-u[i+1].fi.fi),abs(u[i].fi.se-u[i+1].fi.se)));
		kr.add_edge(v[i].se,v[i+1].se,min(abs(v[i].fi.fi-v[i+1].fi.fi),abs(v[i].fi.se-v[i+1].fi.se)));
	}
	cout << kr.solve() << "\n";
    return 0;
}


Measured memory_bytes: 8816
#include<bits/stdc++.h>
using namespace std;
#define lld long long int
#define mod 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s,t;
    cin>>s;
    cin>>t;
    lld i,j,k,c=0,r;
    lld z1=s.length();
    lld z2=t.length();
    lld mini=1e18;
    for(i=0;i<=z1-z2;i++)
    {
        k=0;
        r=0;
        for(j=i;j<i+z2;j++)
        {
            if(s[j]!=t[k])
            {
                r++;
            }
            k++;
        }
        mini=min(mini,r);
    }
    cout<<mini;
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
int main(void){
    string s,t;
    cin>>s>>t;
    for(int i=s.size()-t.size();i+1;i--){
        for(int j=0;j<t.size();j++){
            if(s[i+j]!=t[j]&&s[i+j]!='?')break;
            if(j==t.size()-1){
                s.replace(i,t.size(),t);
                replace(s.begin(),s.end(),'?','a');
                cout<<s;
                return 0;
            }
        }
    }
    cout<<"UNRESTORABLE";
    return 0;
}

Measured memory_bytes: 256
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	s = input()
	for i in range(math.ceil(len(s)/2)):
		if(s[i*2]not  in ['R','U','D']):
			print('No')
			exit()
	for i in range(math.floor(len(s)/2)):
		if(s[i*2+1]not  in ['L','U','D']):
			print('No')
			exit()
	print('Yes')


def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()


Measured memory_bytes: 65744
#include <stdio.h>



int main()
{
int a;
int b;


scanf("%d",&a);
scanf("%d",&b);


if (a < b)
{
printf("a < b\n");
}
else if(a > b)
{
printf("a > b\n");
}
else
{
printf("a == b\n");
}



return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

#define int long long

const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

int fact[N];

int add(int a, int b) {
	return (a + b) % MOD;
}

int mul(int a, int b) {
	return (a * b) % MOD;
}

int binpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

int divv(int a, int b) {
	return mul(a, binpow(b, MOD - 2));
}

int getC(int n, int k) {
	return divv(fact[n], mul(fact[n - k], fact[k]));
}

void init() {
	fact[0] = 1;
	for (int i = 1; i < N; i++) {
		fact[i] = mul(i, fact[i - 1]);
	}
}

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

    init();

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto &t : a) {
    	cin >> t;
    }
    sort(a.begin(), a.end());
    int sb = 0;
    for (int i = 0; i + k <= n; i++) {
    	int left = (n - 1 - i);
    	int cnt = getC(left, k - 1);
    	int cur = cnt;
    	cur = mul(cur, a[i]);
    	if (cur < 0) cur += MOD;
    	sb = add(sb, cur);
    }
    int ad = 0;
    for (int i = k - 1; i < n; i++) {
    	int left = i;
    	int cnt = getC(left, k - 1);
    	int cur = cnt;
    	cur = mul(cur, a[i]);
    	if (cur < 0) cur += MOD;
    	ad = add(ad, mul(a[i], getC(left, k - 1)));
    }
    int ans = (ad - sb + MOD) % MOD;
    cout << ans << endl;

}   

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	string s;
	cin >> s;
	int size=s.size();
	if(s[0]!='A'){
		cout << "WA" << endl;
		return 0;
	}
	int c_loc, c_cnt=0;
	for(int i=2; i<size-1; i++){
		if(s[i]=='C'){
			c_loc=i;
			c_cnt++;
		}
	}
	if(c_cnt!=1){
		cout << "WA" << endl;
		return 0;
	}
	for(int i=0; i<size; i++){
		if(i==0 || i==c_loc) continue;
		if(isupper(s[i])){
			cout << "WA" << endl;
			return 0;
		}
	}
	cout << "AC" << endl;
	return 0;
}

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

void DumpArray(int *A, int n)
{
    for (int i = 0; i < n; i++) {
        std::cout << A[i];
        if (i != n - 1) {
            std::cout << " ";
        }
    }
    std::cout << std::endl;
}

void CountingSort(int *A, int *B, int k, int n)
{
    int C[k+1];
    for (int i = 0; i <= k; i++) {
        C[i] = 0;
    }

    for (int j = 0; j < n; j++) {
        C[A[j]]++;
    }

    for (int i = 1; i <= k; i++) {
        C[i] = C[i] + C[i-1];
    }

    for (int j = 0; j < n; j++) {
        B[C[A[j]] - 1] = A[j];
        C[A[j]]--;
    }
}

int main(int argc, char *argv[])
{
    int n;
    int *A = (int *) malloc(sizeof(int) * 2000000);
    int *B = (int *) malloc(sizeof(int) * 2000000);
    scanf("%d", &n);

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

    CountingSort(A, B, 10000, n);
    DumpArray(B, n);

    return 0;
}


Measured memory_bytes: 18856