akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using  namespace std;
int main(){
    long long n, ans=0, num=0;
    string s;
    cin >> n;
    map<string, long long> S;
    for(int i=0;i<n;i++){
        cin >> s;
        sort(s.begin(),s.end());
        S[s]++;
    }
    for(auto itr=S.begin();itr!=S.end();itr++){
        num = 0;
        for(int i=itr->second-1;i>0;i--){
            num += i;
        }
        ans += num;
    }
    cout << ans << endl;
 
}


Measured memory_bytes: 11136
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
}

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func main() {
	n := readInt()
	d := make(map[int]int)
	for i := 0; i < n; i++ {
		d[readInt()]++
	}
	fmt.Println(len(d))
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>

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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<ll> as(N, 0);
    vector<ll> bs(N, 0);
    rep(i, N){
        cin >> as[i] >> bs[i];
    }
    ll ans = 0;

    for(int i = N - 1; i >= 0; i --){
        ll tmp = ans;
        ans += (as[i] + bs[i] - 1 + ans) / bs[i] * bs[i];
        ans -= as[i] + tmp;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000000000001
#define pi acosl(-1)
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
void solve()
{
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        ans+=((n-1)/i);
    }
    cout<<ans;
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    time_taken_start
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
    time_taken_end
}

Measured memory_bytes: 3648
n = int(input())
graph = list(map(int, input().split()))
pre = 1000000
ans = 0
cnt = -1
for i in graph:
  if i <= pre:
    cnt += 1
    pre = i
  else:
    ans = max(ans, cnt)
    cnt = 0
    pre = i
ans = max(ans, cnt)
print(ans)

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

#define task "D"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define db1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define db2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define db3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, n) { cerr << #A << " = "; rep(_, 1, n) cerr << A[_] << ' '; cerr << '\n'; }
#define SZ(x) ((int)(x).size())
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 2e5 + 1;
int n, k;
ld a[N], sum, res;
int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n >> k;
	rep(i, 1, n)
	{
	    int x;
	    cin >> x;
	    a[i] = (x + 1.0) / 2.0;
	}
	rep(i, 1, k) sum += a[i];
	res = sum;
	rep(i, k + 1, n)
	{
	    sum -= a[i - k] - a[i];
	    res = max(res, sum);
	}
	cout << fixed << setprecision(10) << res;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int a[3][3];
    map<int,int> m;
    rep(i,3){
        rep(j,3){
            cin>>a[i][j];
        }
    }
    int n;
    cin>>n;
    int b[n];
    rep(i,n){
        cin>>b[i];
        m[b[i]]++;
    }
    if(m[a[0][0]] && m[a[0][1]] && m[a[0][2]]) cout<<"Yes"<<endl;
    else if(m[a[1][0]] && m[a[1][1]] && m[a[1][2]]) cout<<"Yes"<<endl;
    else if(m[a[2][0]] && m[a[2][1]] && m[a[2][2]]) cout<<"Yes"<<endl;
    else if(m[a[0][0]] && m[a[1][0]] && m[a[2][0]]) cout<<"Yes"<<endl;
    else if(m[a[0][1]] && m[a[1][1]] && m[a[2][1]]) cout<<"Yes"<<endl;
    else if(m[a[0][2]] && m[a[1][2]] && m[a[2][2]]) cout<<"Yes"<<endl;
    else if(m[a[0][0]] && m[a[1][1]] && m[a[2][2]]) cout<<"Yes"<<endl;
    else if(m[a[2][0]] && m[a[1][1]] && m[a[2][0]]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();

        int a = scanner.nextInt();
        int b = scanner.nextInt();
        if(a>9||b>9) {
        	System.out.println("-1");
        }else {
        	System.out.println(a*b);
        }
    }

    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 21332
import java.util.Scanner;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        long n = sc.nextInt(), m = sc.nextInt();

        if (n > 2 && m > 2) {
            System.out.println(n * m - 2 * n - 2 * m + 4);
        } else if (n >= 2 && m == 2 || n == 2 && m >= 2) {
            System.out.println(0);
        } else if (n == 1 && m >= 2) {
            System.out.println(m - 2);
        } else if (n >= 2 && m == 1) {
            System.out.println(n - 2);
        } else if (n == 1 && m == 1) {
            System.out.println(1);
        } else {
            System.out.println("A");
        }
    }
}

Measured memory_bytes: 23892
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll a, b;
string str;

int main(){
	cin >> a >> b;
	if((a+b)%2 == 0){cout << (a+b)/2 << endl;}
	else{cout << "IMPOSSIBLE" << endl;}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n,M[N][N],color[N],d[N],f[N],time;
void visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++time;
  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(color[v]==WHITE) visit(v);
  }
  color[u]=BLACK;
  f[u]=++time;
}
void dfs(void){
  int u;
  for(u=0;u<n;u++) color[u]=WHITE;
  time=0;
  for(u=0;u<n;u++){
    if(color[u]==WHITE) visit(u);
  }
  for(u=0;u<n;u++) printf("%d %d %d\n",u+1,d[u],f[u]);
}
int main(){
  int i,j,k,u,v;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  return 0;
}

Measured memory_bytes: 636
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

int g[100001], h[100000];

int dfs(int x) {
  if (g[x] == x) {
    return x;
  } else {
    g[x] = dfs(g[x]);
  }
}

int main() {
  int n, m, a, b, ans = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    g[i] = 1;
    cin >> h[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    if (h[a] <= h[b]) {
      g[a] = 0;
    }
    if (h[a] >= h[b]) {
      g[b] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    ans += g[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4404
import sys

point=list(map(int,input().split()))
if point[0]==0 and point[1]==0:
    print("1")
    sys.exit()
fiblist=[0,1,1]
maxpoint=[0,0]
minpoint=[0,0]
i=2
while True:
    if i%4==2 or i%4==3:
        maxpoint[i%2]+=fiblist[2]
    else:
        minpoint[i%2]-=fiblist[2]
    if minpoint[0]<=point[0] and maxpoint[0]>=point[0] and minpoint[1]<=point[1] and maxpoint[1]>=point[1]:
        print((i-1)%3+1)
        break
    fiblist[0]=fiblist[1]
    fiblist[1]=fiblist[2]
    fiblist[2]=fiblist[0]+fiblist[1]
    i+=1


Measured memory_bytes: 5604
#include <stdio.h>
int main(void){
  int a,b,c;
  scanf("%d %d %d", &a, &b, &c);
  if(a < b&&b<c)
	{
		printf("Yes\n");
	}
  else
	{
		printf("No\n");
	}
  return 0;
  }

Measured memory_bytes: 580
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin >> a >> b;
	if(a < b){
		cout << "a < b" << endl;
	}
	else if(a > b){
		cout << "a > b" << endl;
	}
	else{
		cout << "a == b" << endl;
	}
	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef vector<vector<int> > vvi;
#define clr(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mkp make_pair
#define forn(i, n) for(int i=0; i<(int)n; ++i)

const int inf = (int)1e6+5;
const int nax = (int)3e5+5;

void compute(){
    int n; cin>>n;
    double x;
    string s;
    double res = 0.0;
    forn(i, n){
        cin>>x>>s;
        if(s == "BTC"){
            res += x*(380000.0);
            continue;
        }
        res += x;
    }
    cout<<res<<"\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //    int t;
    //    cin>>t;
    //    while(t--)
    compute();
    return 0;
}


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

int gcd(int x, int y)
{
	return y ? gcd(y, x % y) : x;
}

string str;

bool check(long long n) {
	return (n & (n - 1)) == 0;
}

void hawawa()
{
	int a, b, x;
	cin >> a >> b >> x;
	if (a <= x && x <= a + b) {
		cout << "YES\n";
	}
	else {
		cout << "NO\n";
	}
}

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll dp[2010][2010];

int main(void){
    ll a,b;
    cin>>a>>b;
    if(a%2==0){
        if(b%2==1){
            ll num = b-a+1;
            num = num/2;
            cout<<(num%2)<<endl;
        }
        else{
            ll num = b-a;
            num = num/2;
            cout<<((num%2)^b)<<endl;
        }
    }
    else{
        if(b%2==1){
            ll num = b-a;
            num = num/2;
            cout<<((num%2)^a)<<endl;
        }
        else{
            ll num = (b-1)-(a+1)+1;
            num = num/2;
            cout<<((num%2)^a^b)<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	int N, M;
	cin >> N >> M;
	vector<tuple<int,int,int,int>>A(M);
	rep(i, M) {
		cin >> get<0>(A[i]) >> get<1>(A[i]);
	}
	rep(i, M) {
		get<2>(A[i]) = i;
	}
	sort(A);
	int cnt = 0;
	get<3>(A[0]) = 0;
	cnt++;
	for (int i = 1; i < M; i++) {
		if (get<0>(A[i]) != get<0>(A[i - 1])) {
			cnt=0;
		}
		get<3>(A[i]) += cnt;
		cnt++;
	}
	rep(i, M) {
		get<3>(A[i])++;
	}
	rep(i, M) {
		get<1>(A[i]) = get<0>(A[i]);
	}
	rep(i, M) {
		get<0>(A[i]) = get<2>(A[i]);
	}
	sort(A);
	rep(i, M) {
		cout <<setfill('0')<< right << setw(6) << get<1>(A[i])<< setfill('0') << right << setw(6) << get<3>(A[i]) << endl;
	}
}


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

#define pow2(a) ((a)*(a));

int main(){
    int n, d;
    cin >> n >> d;

    int x[20][20];

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

    int ans = 0;
    for(int i = 0;i < n;i++){
        for(int j = i+1;j < n;j++){
            int sum = 0;

            for(int k = 0;k < d;k++){
                sum += pow2(x[i][k]-x[j][k]);
            }

            int k;
            for(k = 0;k*k < sum;k++);

            if(k*k == sum) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
ll n,ans;
int main() {
//	freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++)
		if (i%3!=0&&i%5!=0) ans+=i;
	printf("%lld\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 3764
a = []
while True:
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        break
    a.append([x, y])


for i in range(len(a)):
    sho = a[i][1] // 2
    mod = a[i][1] % 2
    for j in range(a[i][0]):
        if (j % 2) == 0:
            print("#."*sho + "#"*mod)
        else:
            print(".#" * sho + "." * mod)
    print("")



Measured memory_bytes: 5628
using System;
using System.Collections.Generic;
using System.Collections;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace _1_A
//{
class Program
{
    static void Main(string[] args)
    {
        ArrayList array = new ArrayList();
        int i;
        string x = Console.ReadLine();
        int z = int.Parse(x);
        for (i = 0; i < 10000; i++)
        {
            if (z != 0)
            {
                array.Add(z);
                x = Console.ReadLine();
                z = int.Parse(x);
            }
            else
                break;
        }

        int k = 1;

        foreach (object obj in array)
        {
            Console.WriteLine("Case" + " " + k + ":" + " " +  obj.ToString());
            k++;
        }

        //Console.Read();
    }
}
//}

Measured memory_bytes: 9848
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/
#define rep(i,l,r) for(int i=l;i<=r;i++)
const double EPS=1E-8;

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


int main(){
    int a,b;cin>>a>>b;
    char m[105][105];
    rep(i,1,100)rep(j,1,100)m[i][j]='.';
    cout<<"100 100"<<endl;
    if(a==1){
        int s=52,t=2;
        while(b--){
            m[s][t]='#';
            
            t+=2;
            if(t>100){
                t-=100;
                s+=2;
            }
        }
        rep(i,1,100){
            rep(j,1,100){
                cout<<m[i][j];
            }
            cout<<endl;
        }
        
        return 0;
        
    }
    a--;
    int syou=a/50,amari=a%50;
    rep(i,1,syou){
        rep(j,1,100){
            if(j%2==0)m[i*2-1][j]='#';
        }
        rep(j,1,100){
            m[i*2][j]='#';
        }
    }
    
    rep(j,1,amari*2){
        if(j%2==0)m[2*syou+1][j]='#';
        m[2*syou+2][j]='#';
    }
    
    b--;
    int s=52,t=2;
    while(b--){
        m[s][t]='#';
        
        t+=2;
        if(t>100){
            t-=100;
            s+=2;
        }
    }
    rep(i,1,100){
        rep(j,1,100){
            cout<<m[i][j];
        }
        cout<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int n, m, c, i, j, k, x, y, ans;
char s[8][8];
int main(){
	scanf("%d%d%d", &n, &m, &c);
	for(i=1; i<=n; i++){
		scanf("%s", &s[i][1]);
	}
	for(x=0; x<(1<<n); x++){
		for(y=0; y<(1<<m); y++){
			for(k=0, i=1; i<=n; i++){
				if(1<<i-1 & x) continue;
				for(j=1; j<=m; j++){
					if(1<<j-1 & y) continue;
					if(s[i][j] == '#') k++;
				}
			}
			if(c == k) ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  int a, b, h;
  cin >> a >> b >> h;
  cout << (a + b) * h / 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long LL;
using namespace std;

 int main() {

     int N;
     cin >> N;

     vector<int> A(N), B(N), C(N);
     for (int i = 0; i < N; i++) cin >> A[i];
     for (int i = 0; i < N; i++) cin >> B[i];
     for (int i = 0; i < N; i++) cin >> C[i];
     sort(A.begin(), A.end());
     sort(B.begin(), B.end());
     sort(C.begin(), C.end());

     LL ans = 0;

     for (int i = 0; i < N; i++) {
         LL pre = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
         LL over = C.end() - upper_bound(C.begin(), C.end(), B[i]);
         ans += pre * over;
     }


     cout << ans;

     return 0;
 }


Measured memory_bytes: 1408
n, q = gets.chomp.split.map(&:to_i)

que = []
while str = gets
  name, time = str.chomp.split
  time = time.to_i
  que.push name: name, time: time
end

past_time = 0
while !que.empty?
  process = que.shift

  if process[:time] <= q
    past_time += process[:time]
    puts "#{process[:name]} #{past_time}"
  else
    past_time += q
    process[:time] -= q
    que.push process
  end
end

Measured memory_bytes: 25480
#include <iostream>
#include<bits/stdc++.h>
#include<cmath>
#include <algorithm> 
#include<map>
#include<string>
#include<unordered_map>
#include <set>
#include <unordered_set>

using namespace std;

const long long N = (1e4 + 7);

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long n, x,t;
	cin >> n>>x>>t;
	vector<long long>arr;
	long long ans = 0;
	if (n%x == 0) {
		ans = n / x;
	}
	else {
		ans = (n / x) + 1;
	}
	ans = ans * t;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3608
#define ll     long long int
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    ll a,b,c;
     cin>>a>>b>>c;
     ll temp1=a;
     ll temp2=b;
     ll temp3=c;
      a=temp3;
      b=temp1;
      c=temp2;
      cout<<a<<" "<<b<<" "<<c <<endl;


    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException err){
			err.printStackTrace();
		}
	}
	
	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		List<String> Ans = new ArrayList<String>();
		String line = in.readLine();
		
		int size = Integer.parseInt(line);
		for(int n=0; n<size; n++){
			line = in.readLine();
			while(line.contains("Hoshino")){
				line = line.replace("Hoshino", "Hoshina");
			}
			Ans.add(line);
		}
		
		for(int n=0; n<Ans.size(); n++){
			System.out.println(Ans.get(n));
		}
		
	}
}

Measured memory_bytes: 9340
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <list>
#define rep(i,n) for(int i=0; i<n; ++i)
using namespace std;

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


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	if(a==1)a+=13;
	if(b==1)b+=13;
	if(a>b)cout << "Alice" << endl;
	else if(a<b) cout << "Bob" << endl;
	else cout << "Draw" << endl;
	return 0;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep1(i, n) for(ll i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  ll x;
  cin >> x;
  vector<pair<ll,pair<ll,ll>>> st(0);
  rep(i,120){
    for(ll j = -120;j<120;j++){
      ll tmp = (ll)pow(i,5)-(ll)pow(j,5);
      if(tmp>0){
        auto pair1 = make_pair(i,j);
        auto pair2 = make_pair(tmp,pair1);
        st.push_back(pair2);
      }
    }
  }
  for(auto p : st){
    if(p.first == x){
      cout << p.second.first << " " << p.second.second << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 4752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int n;
ll t;
string s;
map<char, int> freq;

int main() {
    cin >> n >> s;
    for(int i = 0; i < s.size(); i++) {
        freq[s[i]]++;
    }
    t = 1;
    for(int i = 'a'; i <= 'z'; i++) {
        t *= (freq[i] + 1);
        t %= mod;
    }
    cout << (t - 1 + mod) % mod << endl;
}

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

//union_find begin
#define MAX 5000000
struct node{  int parent,size; };
node tree[MAX];
void init(){
  for(int i=0;i<MAX;i++){
    tree[i].parent=i;
    tree[i].size=1;    
  }
}
/*
int find(int x){ 
  if(tree[x].parent==x)return x;
  tree[x].parent = find( tree[x].parent );
  return tree[x].parent;
}
*/
int st[MAX],cnt;
int find(int x){
  cnt=0;
  while(tree[x].parent!=x){    
    st[cnt++]=x;
    x=tree[x].parent;
  }
  while(cnt>0){
    cnt--;
    tree[st[cnt]].parent=x;
  }
  return x;
}

int count(int x){
  x=find(x);
  return tree[x].size;
}

bool same(int x,int y){
  return ( find(x) == find(y) );
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;  
  if(count(x)>count(y))swap(x,y);
  tree[x].parent=y;
  tree[y].size+=tree[x].size;
}
// union find end

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

int W,H,N,target;
char t[1005][1005];

int change(int i,int j){
  return i*W+j;
}

int solve(){
  cin>>N;
  for(int ans=1;ans<=N;ans++){
    int i,j;
    cin>>j>>i;
    if(t[i][j]=='.')continue;
    t[i][j]='.';
    for(int k=0;k<4;k++){
      int ni=i+dy[k];
      int nj=j+dx[k];
      if(ni<0 || nj<0 || H<=ni || W<=nj)continue;
      if(t[ni][nj]=='#')continue;
      unite( change(i,j) , change(ni,nj) );
    }
    if(same(target,0))return ans;
  }
  return -1;
}

int main(){
  init();
  cin>>W>>H;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>t[i][j];
      if(t[i][j]=='t')target=change(i,j);
    }
  }  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(t[i][j]=='#')continue;
      for(int k=0;k<4;k++){
        int ni=i+dy[k];
        int nj=j+dx[k];
        if(ni<0 || nj<0 || H<=ni || W<=nj)continue;
        if(t[ni][nj]=='#')continue;
        unite( change(i,j) , change(ni,nj) );
      }
    }
  }
  if( same( target , 0 ) ){
    cout<<"0"<<endl;
  }else{
    cout<<solve()<<endl;
  }  
  return 0;
}

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

import sys
n = int(input())
word = input()
res = 0
num_r = 0

for charactor in word:
    if charactor == 'R':
        num_r += 1

num_w = 0
for i in range(num_r):
    if word[i] == 'W':
        num_w += 1

print(num_w)


Measured memory_bytes: 9428
import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

private func gcd(_ a: Int, _ b: Int) -> Int {
    var (a, b) = a <= b ? (a, b) : (b, a)
    while b != 0 {
        (a, b) = (b, a % b)
    }
    return a
}

func main() {
    // 考察過程
    // 0~maxまでの数字を全て作ることが不可能な条件を探る
    // k > max なら不可能
    // 1を作り出すことができれば全部の数字を作れる？
    // 1を作り出すことができないのはどういう状況か
    // 全ての数のgcdが1より上
    // gcd(A)の倍数 に k がいればOKかも。
    // gcdが1かどうか関係なく k % gcd(A) == 0ならOK?

    let nk = readWords { Int($0)! }
    let n = nk[0]
    let k = nk[1]
    let A = readWords { Int($0)! }

    guard k <= A.max()! else {
        print("IMPOSSIBLE")
        return
    }

    var g = A[0]
    for i in 1..<n {
        g = gcd(g, A[i])
    }

    if k % g == 0 {
        print("POSSIBLE")
    } else {
        print("IMPOSSIBLE")
    }

}


main()

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

typedef long long int lli;
int main() {
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(&A[0], &A[N]);
    lli minCost = LONG_MAX;
    for(int i = A[0]; i < A[N - 1]; i++) {
        lli cost = 0;
        for(int j = 0; j < N; j++) {
            cost += (lli) pow(A[j] - i, 2);
        }
        if(cost < minCost) minCost = cost;
    }
    if(minCost == LONG_MAX) {
        minCost = 0;
    }
    cout << minCost;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;
  cin >> s;
  vector<int> a(2);
  a[0]=-1;
  a[1]=s;
  int an;
  bool loop=true;
  for(int i=2;loop;i++){
    if(a[i-1]%2==0)a.push_back(a[i-1]/2);
    else a.push_back(3*a[i-1]+1);
    for(int j=1;j<i;j++){
      if(a[i]==a[j]){
        loop=false;
        an=i;
        break;
      }
    }
  }
  cout << an << endl;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int n,m;cin>>n>>m;
	priority_queue<double>que;
	ll cnt=0;
	rep(i,n){
		int a;scanf("%d",&a);
		cnt+=a;
		que.push(a);
	}
	int ans=0;
	rep(T,m){
		double d=que.top();que.pop();
		cnt-=floor(d);
		d/=2;
		ans++;
		cnt+=floor(d);
		que.push(d);
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 1400
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class CSugarWater {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    double ma = 0;
    int ma_g = 100 * A, ma_sugar = 0;

    for (int a = 0; a <= 30; a++){
        for (int b = 0; b <= 30; b++){
            int water = 100 * a * A + 100 * b * B;
            for (int c = 0; c * C <= water; c++){
                int t = (E * water - 100 * c * C) / (100 * D);
                int s = (F - water - c * C) / D;
                int d = min(t, s);
                int sugar = c * C + d * D;
                int g = water + sugar;
                if (d < 0)
                    continue;
                if (g == 0)
                    continue;
                if (g > F)
                    continue;
                double percent = double(100 * sugar) / g;
                if (sugar * (100 + E) > E * g)
                    continue;
                if (ma < percent){
                    ma = percent;
                    ma_g = g;
                    ma_sugar = sugar;
                }
            }
        }
    }

    cout << ma_g << " " << ma_sugar << endl;
}
};

int main() {
	CSugarWater solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

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

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

class Node:
    def __init__(self, h):
        self.high = h
        self.ne_max = 0

    def set_ne(self, h):
        self.ne_max = max(self.ne_max, h)

    def isg(self):
        return 1 * (self.high > self.ne_max)

def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    nodes = [Node(h) for h in H]

    for ai, bi in zip(A,B):
        nodes[ai-1].set_ne(nodes[bi-1].high)
        nodes[bi-1].set_ne(nodes[ai-1].high)

    print(sum([n.isg() for n in nodes]))

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, H, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 94096
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/
int main(){
  ll N; cin >>N;
  vector<char> ans;
  while(N>0){
    N--;
    ll c = N%26;
    N++;
    ans.push_back(c+'a');
    N-=c;
    N/=26;
    if(N==0) break;
  } 
  reverse(All(ans));
  for(char x:ans){
    cout << x;
  } 
  cout << "\n";
}

Measured memory_bytes: 3632
# include <bits/stdc++.h>
using namespace std;
#define P 1000000007
int n;
char s1[100], s2[100];
int main(){
    scanf("%d%s%s",&n,s1,s2);
    long long ans=s1[0]==s2[0]?3:6;
    for(int i=1; i<n; ++i){
        if(s1[i-1]==s2[i-1]) ans=ans*2%P;
        if(s1[i]!=s2[i]&&s1[i-1]!=s2[i-1]&&s1[i]!=s1[i-1]&&s2[i]!=s2[i-1]) ans=ans*3%P;
    }
    printf("%lld",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

int N, K;

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

  int T = 2*K;
  vector<vector<int>> C(T, vector<int>(T, 0));

  rep(i,N) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    if(c == 'W') x += K;
    C[y%T][x%T]++;
  }

  vector<vector<int>> SC(T+1, vector<int>(T+1, 0));
  rep(i,T) rep(j,T) {
    SC[i+1][j+1] = C[i][j] + SC[i+1][j] + SC[i][j+1] - SC[i][j];
  }

  // [x0, x1) x [y0, y1)
  auto rangeSum = [&](int y0, int y1, int x0, int x1) {
    return SC[y1][x1] - SC[y0][x1] - SC[y1][x0] + SC[y0][x0];
  };

  int ans = 0;
  rep(i,T) rep(j,T) {
    int x1 = (j+K) % T, x2 = j;
    if(x1 > x2)swap(x1, x2);
    int y1 = (i+K) % T, y2 = i;
    if(y1 > y2)swap(y1, y2);

    int b = rangeSum(0, y1, 0, x1)
      + rangeSum(0, y1, x2, T)
      + rangeSum(y1, y2, x1, x2)
      + rangeSum(y2, T, 0, x1)
      + rangeSum(y2, T, x2, T);

    ans = max(ans, max(b, N - b));
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;


int main ()
{
  prep();
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cur = 1;
  if (s[0] != 'B'){
      cout << 0;
      return 0;
  }
  long long res = 1;
  bool endnow = false;
  for (int i=1; i<2*n; i++){
      if (cur == n*2-i){
          endnow = true;
      }
      
      if (s[i] == 'B'){
          if (cur%2 == 1){
              res *= cur;
              res %= mod;
              cur--;
          }else{
              // increase or decrease
              if (endnow){
                  cout << 0;
                  return 0;
              }else{
                  cur++;
              }
          }
      }else{
          if (cur%2 == 1){
              if (endnow){
                  cout << 0;
                  return 0;
              }else{
                  cur++;
              }
          }else{
              res *= cur;
              res %= mod;
              cur--;
          }
      }
      //cout << cur << endl;
  }
  if (cur != 0){
      cout << 0;
      return 0;
  }
  for (int i=2; i<=n; i++){
      res *= i;
      res %= mod;
  }
  cout << res;
  return 0; 
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
ll n,dp[44][(1<<20)+5];
ll x,y,z;
ll rec(ll i,ll msk)
{
	if(i>n)
	{
		if((msk&(1<<z))&&(msk&(1<<(z+y)))&&(msk&(1<<(x+y+z))))
			return 1;
		return 0;
	}
	if(dp[i][msk]!=-1)
		return dp[i][msk];
	ll an=0;
	if((msk&(1<<z))&&(msk&(1<<(z+y)))&&(msk&(1<<(x+y+z))))
	{
		an=1;
		for(int h=i;h<=n;h++)
			an=(an*10)%MOD;
		return dp[i][msk]=an;
	}
	bitset<19>b(msk),x;
	b.set(0);
	for(int h=1;h<=10;h++)
	{
		x=((b<<h));
		an=(an+rec(i+1,x.to_ulong()))%MOD;
	}
	return dp[i][msk]=an;
}
int main()
{
	SPEED;
	memset(dp,-1,sizeof dp);
	cin>>n>>x>>y>>z;
	cout<<rec(1,0)<<endl;
	return 0;
}

Measured memory_bytes: 360704
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string.h>
using namespace std;

int main(){
	int n;
	char c[9],h[9],l[9];
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%s",c);
		strcpy(h,c);
		strcpy(l,c);
		sort(h,h+8,greater<char>());
		sort(l,l+8);
		int ans = atoi(h) - atoi(l);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 2644
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

template<class T> struct UF{
    vector<T> par,sz;

    UF(T n){
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i]=i;
            sz[i]=1;
        }
    }

    T find(T x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }

    bool unit(T x,T y){
        x=find(x);
        y=find(y);
        if(x==y) return false;
        if(sz[x]>sz[y]){
            par[y]=x;
            sz[x]+=sz[y];
        }
        else{
            par[x]=y;
            sz[y]+=sz[x];
        }
        return true;
    }

    bool same(T x,T y){return find(x)==find(y);}
};

struct edge{
    ll dm,cd,ct;
    edge(ll a,ll b,ll c){
        dm=a;cd=b;ct=c;
    }
    bool operator<(const edge& right) const{
        return ct<right.ct;
    }
};

ll kk(vector<edge>& edges,ll n){
    sort(edges.begin(),edges.end());
    ll cnt=0,ans=0;
    UF<ll> uf(n);
    for(auto it=edges.begin();cnt<n-1;it++){
        edge e=*it;
        if(uf.same(e.dm,e.cd)) continue;
        uf.unit(e.dm,e.cd);
        ans+=e.ct;
        cnt++;
    }
    return ans;
}

class EConnectingCities {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        using P=pair<ll,ll>;
        ll n,d;
        in>>n>>d;
        vector<int> a(n);
        for(auto& i:a) in>>i;
        priority_queue<P,vector<P>,greater<P>> pq;
        vector<edge> es;
        fr(i,n){
            while(!pq.empty()){
                int j=pq.top().second;
                if(a[j]>a[i]) pq.pop();
                else{
                    es.emplace_back(j,i,a[i]+a[j]+d*(i-j));
                    break;
                }
            }
            pq.emplace(a[i]-d*i,i);
        }
        while(!pq.empty()) pq.pop();
        ifr(i,n){
            while(!pq.empty()){
                int j=pq.top().second;
                if(a[j]>a[i]) pq.pop();
                else{
                    es.emplace_back(j,i,a[i]+a[j]+d*(j-i));
                    break;
                }
            }
            pq.emplace(a[i]+d*i,i);
        }
        out<<kk(es,n)<<endl;
    }
};

int main() {
    EConnectingCities solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

int main(){
        string s;
        cin >> s;
        if(s[1] == s[2]) {
                if(s[0] == s[1] || s[2] == s[3]) {
                        cout << "Yes" << endl;
                }else{
                        cout << "No" <<endl;
                }
        }else{
                cout << "No" <<endl;
        }
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort( ALL(v) )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main()
{
    int h;
    int n;
    cin>>h>>n;
    int a[n];
    for(int i = 0 ; i<n ; i++)scanf("%d", a+i);

    sort(a , a+n);

    for(int i = 0 ; i<n ; i++)
    {
        h-=a[i];
        if(h<=0)
           {
               cout<<"Yes"<<endl;
               return 0;
           }
    }
    cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
using namespace std;

struct Point{
  double x,y;
  Point(){}
  Point(double x,double y) :x(x),y(y){}
  Point operator + (Point p) {return Point(x+p.x,y+p.y);}
  Point operator - (Point p) {return Point(x-p.x,y-p.y);}
  Point operator * (double k) {return Point(x*k,y*k);}
  Point operator / (double k) {return Point(x/k,y/k);}
  double norm(){return x*x+y*y;}
  double abs(){return sqrt(norm());}

  bool operator < (const Point &p) const{
    return x!=p.x ? x < p.x : y < p.y;
  }

  bool operator == (const Point &p) const{
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};
typedef Point Vector;
typedef vector<Point> Polygon;

double norm(Vector a){
  return a.x*a.x+a.y*a.y;
}
double abs(Vector a){
  return sqrt(norm(a));
}
double dot(Vector a,Vector b){
  return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b){
  return a.x*b.y-a.y*b.x;
}
double dp[20][20][20000];
const double PI = 3.1415926535;
int main(){
  int n,i,j,k,ans=0;cin>>n;
  double r,arc;cin>>r>>arc;
  arc=PI/180.0*arc;
  Polygon g;g.resize(n);
  for(i=0;i<n;i++) cin>>g[i].x>>g[i].y;
  double e[n][n][n],inf=1<<28;
  fill(e[0][0],e[0][0]+n*n*n,inf);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      for(k=0;k<n;k++){
	if(i==j||j==k||k==i) continue;
	Vector a=g[j]-g[i],b=g[k]-g[j];
	if(fabs(acos(dot(a,b)/(abs(a)*abs(b))))<=arc)
	  e[i][j][k]=abs(g[k]-g[j]);
      }
    }
  }
  for(k=1;k<n;k++) e[0][0][k]=abs(g[k]-g[0]);
  
  fill(dp[0][0],dp[0][0]+20*20*20000,inf);
  typedef pair<int,int> P;
  typedef pair<int,P> PP;
  typedef pair<double,PP> PPP;
  priority_queue<PPP,vector<PPP>,greater<PPP> > q;
  q.push(PPP(0.0,PP(0,P(0,n))));
  while(!q.empty()){
    PPP ppp=q.top();q.pop();
    double d=ppp.first,z;
    PP pp=ppp.second;
    k=pp.first;
    P p=pp.second;
    if(d>r) continue;
    ans=max(ans,k);
    if(p.second==n){
      for(i=0;i<n;i++){
	z=inf;
	for(j=0;j<n;j++) z=min(z,e[j][0][i]);
	q.push(PPP(d+z,PP(k+1,P(i,p.first))));
      }
    }else{
      if(dp[p.first][p.second][k]<=d) continue;	
      dp[p.first][p.second][k]=d;
      for(i=0;i<n;i++)
	if(dp[i][p.first][k+1]>d+e[p.second][p.first][i])
	  q.push(PPP(d+e[p.second][p.first][i],PP(k+1,P(i,p.first))));
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 64656
fun main(args: Array<String>) {
    val N = nextInt()
    val S = next()
    val L = IntArray(N + 1)
    val R = IntArray(N + 1)
    for (n in 0 until N) {
        L[n + 1] = L[n] + (if (S[n] == 'E') 1 else 0)
    }
    for (n in (0 until N).reversed()) {
        R[n] = R[n + 1] + (if(S[N - n - 1] == 'W') 1 else 0)
    }
    var ans = Int.MAX_VALUE
    for (n in 0 until N) {
        ans = Math.min(ans, (L[N] - L[n + 1]) + (R[N - n] - R[N]))
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }


Measured memory_bytes: 39500
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i <= n / 4; i++) {
    for (int j = 0; j <= n / 7; j++) {
      if (4 * i + 7 * j == n) {
        cout << "Yes" << endl;
        exit(0);
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 384
import numpy as np
n, k = map(int, input().split())
hs = []
for i in range(n):
    hs.append(int(input()))

if list(np.diff(hs)) == list(np.zeros(n-1, dtype=int)):
    print('0')
else:
    sorted_hs = np.sort(hs)
    try:
        print(min([min(np.diff(sorted_hs[i::k-1])) for i in range(k) if not len(sorted_hs[i::k-1]) == 1]))
    except:
        print('0')

Measured memory_bytes: 23772
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

int main() {
	int n;
	cin >> n;
	
	int ans = 0;
	while (n--) {
		int l, r;
		scanf("%d %d", &l, &r);
		ans += r - l + 1;
	}
	cout << ans << endl;
	return 0;
}

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

#define int long long
#define sz(x) (int)(x.size())

const int N = 3003;
int n;
double p[N], ans = 0;
vector<vector<double> > dp(N, vector<double> (N, -1));

double solve(int i, int h){
    if(dp[i][h] != -1){
        return dp[i][h];
    }
    if(h > i){
        return dp[i][h] = 0;
    }
    if(i == 1){
        return dp[i][h] = (h ? p[1] : 1 - p[1]);
    }
    return dp[i][h] = p[i] * solve(i - 1, h - 1) + (1 - p[i]) * solve(i - 1, h);
}

signed main(){
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 1;i <= n; i++) {
        cin >> p[i];
    }
    for(int h = (n + 1) / 2 ;h <= n; h++){
        ans += solve(n, h);
    }
    cout << setprecision(9) << fixed << ans << "\n";
}

Measured memory_bytes: 71040