akhauriyash/Code-Regression huggingface dataset:
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    int N;
    cin >> N;
    vector<int> x(N);
    vector<int> y(N);
    vector<int> h(N);
    REP(i, N) cin >> x[i] >> y[i] >> h[i];
    REP(cx, 101) REP(cy, 101)
    {
        bool ok = true;
        int ch = -1;
        REP(j, 2) REP(i, N)
        {
            int d = abs(x[i] - cx) + abs(y[i] - cy);

            if (h[i] == 0)
            {
                if (ch < 0)
                {
                    continue;
                }
                else
                {
                    if (d >= ch)
                    {
                        continue;
                    }
                    else
                    {
                        ok = false;
                        break;
                    }
                }
            }

            int pch = h[i] + d;
            if (ch < 0)
            {
                ch = pch;
            }
            else
            {
                if (ch != pch)
                {
                    ok = false;
                    break;
                }
            }
        }
        if (ok)
        {
            cout << cx << " " << cy << " " << ch << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
 
int main(){
    int n;
    int k;
    cin>>n>>k;
    vector<int> x(n);
    rep(i,n) cin>>x[i];
    int ans=0;
    rep(i,n){
        ans += 2*min(x[i],k-x[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int ca[1000010] = { };
int main() {
  int n, s = 0, m = 0;
  cin >> n;
  vector<int> v(n);
  rep(i,n)
    cin >> v[i];
  sort(v.begin(), v.end());
  bool flg = true;
  rep(i,n)
    if (ca[v[i]] == 0) {
      s++;
      m = v[i];
      flg = true;
      for (int j = m; j < 1000010; j += m)
        ca[j] = 1;
    } else if (m == v[i] && flg) {
      s--;
      flg = false;
    }
  cout << s;
  return 0;
}

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

const int N = 2e5 + 5;
typedef long long ll;

int n, a[N], tot, first[N], fa[N], top[N], up[N], d[N];
ll ans[N], cnt[N], s[N];
struct Edge {
	int to, next;
} e[N<<1];

void Dfs2(int u) {
	up[u] = top[a[u]];
	ll out;
	if(up[u]) {
		cnt[up[u]] -= s[u];
		out = cnt[up[u]];
	}
	else { 
	    d[a[u]] -= s[u];
	    out = d[a[u]]; 
	}
	ans[a[u]] += s[u]*(s[u] - 1)/2 + 1 + out*s[u];
	top[a[u]] = u;
	for(int i = first[u]; i; i = e[i].next) {
		int v = e[i].to;
		if(v == fa[u]) continue;
		ans[a[u]] -= s[v]*(s[v] - 1)/2;
		cnt[u] = s[v];
		Dfs2(v);
	}
	top[a[u]] = up[u];
}

void Dfs1(int u, int f) {
	s[u] = 1;
	fa[u] = f;
	for(int i = first[u]; i; i = e[i].next) {
		int v = e[i].to;
		if(v == fa[u]) continue;
		Dfs1(v, u);
		s[u] += s[v];
	}
	cnt[u] = s[u] - 1;
}

void add(int u, int v) { 
	e[++tot] = (Edge) {v, first[u]};
	first[u] = tot;
}

int main() {
	cin>>n;
	for(int i = 1; i <= n; i++)
		cin>>a[i], d[i] = n;
	for(int u, v, i = 1; i < n; i++) {
		cin>>u>>v;
		add(u, v);
		add(v, u);
	}
	Dfs1(1, -1);
    s[0] = n;
    Dfs2(1);
	for(int i = 1; i <= n; i++)
		cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 28436
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		int Q = sc.nextInt();
		
		int[] point = new int[N];
		for(int i = 0; i < N; i++){
			point[i] = K - Q;
		}
		
		for(int i = 0; i < Q; i++){
			point[sc.nextInt() - 1]++;
		}

		for(int i = 0; i < N; i++){
			System.out.println((point[i]>0)?"Yes":"No");
		}
	}
}


Measured memory_bytes: 54424
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}
int main()
{
   ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
int n;
cin>>n;
 ll a[100001];
ll sum=0;
for(int i=0;i<=100000;i++)
{
	a[i]=0;
}
ll l;
for(int i=0;i<n;i++)
{
	cin>>l;
	a[l]++;
	sum=sum+l;
}
int q;
cin>>q;
ll x,y;
while(q--)
{
	cin>>x>>y;
	int p=a[x];
	a[x]=0;
	a[y]=a[y]+p;
	sum=sum-p*x;
	sum=sum+p*y;
	cout<<sum<<endl;
}
}




Measured memory_bytes: 4436
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	int D;
	cin>>D;
	switch(D)
	{
		case 25:cout<<"Christmas"<<endl;break;
		case 24:cout<<"Christmas Eve"<<endl;break;
		case 23:cout<<"Christmas Eve Eve"<<endl;break;
		case 22:cout<<"Christmas Eve Eve Eve"<<endl;break;
	} 
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define D 1000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"

ll gcd(ll a,ll b)
{
    if(a%b==0)
        return b;
    else 
        return gcd(b,a%b);
}

int main() 
{
    FAST;
    ll n,m;
    cin>>n>>m;
    ll a[n];
    ll g=1,l=1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]=a[i]/2;
        if(i==0)
            g=1;
        else
            g=gcd(l,a[i]);
        l=l*a[i];
        l=l/g;
        if(l>m)
        {
            cout<<0;
            return 0;
        }
    }
    for(int i=0;i<n;i++)
        if((l/a[i])%2==0)
        {
            cout<<0;
            return 0;
        }
    ll ans=(m/l)-(m/(2ll*l));
    cout<<ans;
    subt;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
    int N;
    int saidai = 0;
    scanf("%i", &N);
    int H[N];
    for (int i = 0; i < N; i++){
        scanf("%i", &H[i]);
    }
    int j = 0;
    while (j < N - 1){
        int counter = 0;
        while (H[j] >= H[j + 1]){
            if (j == N - 1){
                break;
            }
            counter++;
            j++;
        }
        if (saidai < counter){
            saidai = counter;
        }
        j++;
    }
    printf("%i\n", saidai);
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1000000007;

using namespace std;

long long int GCD(long long int a, long long int b){
	long long int dummy1, dummy2, dummy;
	dummy1 = max(a, b);
	dummy2 = min(a, b);
	while(true){
		dummy = dummy1 % dummy2;
		dummy1 = dummy2;
		dummy2 = dummy;
		if(dummy == 0){
			break;
		}
	}
	return dummy1;
}

int main(){
	
	int T;
	cin >> T;
	
	for(int loop = 0; loop < T; loop++){
		long long int A, B, C, D;
		cin >> A >> B >> C >> D;
		
		if(A < B){
			cout << "No" << endl;
			continue;
		}
		if(A % B > C){
			cout << "No" << endl;
			continue;
		}
		if(D < B){
			cout << "No" << endl;
			continue;
		}
		if(D % B == 0){
			cout << "Yes" << endl;
			continue;
		}
		long long int G = GCD(D % B, B);
		if(B - C <= G){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
	
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int count = 0;
  if(S.at(0) == 'o') count ++;
  if(S.at(1) == 'o') count ++;
  if(S.at(2) == 'o') count ++;
  cout << 700 + count*100 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll x,y;
  cin >> x >> y;
  if(x>y) swap(x,y);
  if(abs(x-y)<=1) pr("Brown");
  else pr("Alice");
}

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

Measured memory_bytes: 256
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cctype>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言

int main() {
  int X, A, B;
  cin >> X >> A >> B;

  if(A >= B) {
    cout << "delicious" << endl;
  }else if(B-A <= X) {
    cout << "safe" << endl;
  }else {
    cout << "dangerous" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n, s = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353

ans = 0
B = [0] * (s+1)
for i in range(n):
    for j in range(s, -1, -1):
        if j-A[i] >= 0:
            B[j] = (B[j] + B[j-A[i]])%mod
    if A[i] < len(B):
        B[A[i]] += i+1
    ans = (ans + B[s])%mod#*(n-i)
    # B[s] = 0
    # print(B)
print(ans)

Measured memory_bytes: 42988
n = int(input())
s = input()

black = []
white = []

cb=0
cw=0
for l in s:
    if l =="#":
        cb+=1
    else:
        cw+=1
    black.append(cb)
    white.append(cw)

if n == 1:
    print(0)
else:
    ans = [white[-1],black[-1]]
    for i in range(n):
        ans.append(black[i-1]+white[-1]-white[i-1])
    print(min(ans))





Measured memory_bytes: 26716
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int sumdigit(int n) {
	int value = 0;
	while (n > 0) {
		value += n % 10;
		n /= 10;
	}
	return value;
}

int main() {
	int n;
	cin >> n;
	if (n%sumdigit(n) == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main()
{
	uint32_t N;
	uint32_t A;
	uint32_t ans;
	map<uint32_t, bool> R, tmpR;
	uint32_t MOD;

	cin >> N;
	for (uint32_t i = 0; i < N; i++)
	{
		cin >> A;
		R[A] = true;
	}

	while (true)
	{
		tmpR[R.begin()->first] = true;
		for (auto itr = R.begin(); itr != R.end(); itr++)
		{
			MOD = itr->first % R.begin()->first;
			if (MOD)
			{
				tmpR[MOD] = true;
			}
		}
		if (tmpR.size() == 1)
		{
			ans = R.begin()->first;
			break;
		}
		R = tmpR;
		tmpR.clear();
	}

	cout << ans << endl;

	return(0);
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
  int h,w;
  cin>>h>>w;
  vector<vector<char>> t(h+2,vector<char> (w+2,'.'));
  for(int i=1;i<h+1;i++){
    for(int j=1;j<=w;j++){
      char a;
      cin>>a;
      t[i][j]=a;
    }
  }
  
  for(int i=1;i<h+1;i++){
    for(int j=1;j<=w;j++){
      if(t[i][j]=='#'){
        int cu=1;
        if(t[i+0][j+1]=='#'){
            cu=0;
        }
        if(t[i+1][j+0]=='#'){
            cu=0;
        }
        if(t[i+0][j-1]=='#'){
            cu=0;
        }
        if(t[i-1][j+0]=='#'){
            cu=0;
        }
        
        if(cu){
          COUT("No");
          return 0;
        }
      }
    }
  }
  COUT("Yes");
}


Measured memory_bytes: 256
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N int

func main() {
	sc.Split(bufio.ScanWords)

	N = nextInt()
	A := make([]int, N+1)
	//B := make([]int, N)
	ans := 0

	for i := 0; i < N+1; i++ {
		A[i] = nextInt()
	}
	for i := 0; i < N; i++ {
		B := nextInt()
		ans += minInt(A[i], B)
		tmp := maxInt(0, A[i]-B)
		B -= minInt(A[i], B)
		A[i] = tmp
		//fmt.Println(ans, A, B)

		if B > 0 {
			ans += minInt(A[i+1], B)
			A[i+1] = maxInt(0, A[i+1]-B)
			//fmt.Println(ans, A, B)
		}

	}

	fmt.Println(ans)
}


Measured memory_bytes: 5832
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int A[3]; rep(i,3) cin >> A[i];
    if(A[0]+A[1]+A[2]>=22) cout << "bust" << endl;
    else cout << "win" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
int pro[1001];

int main(){
	int n, s[1001];
	while(scanf("%d", &n), n){
		double m = 0, t = 0;
		for(int i = 0;i < n;i++){
			scanf("%d", &s[i]);m += s[i];
		}m /= n;
		for(int i = 0;i < n;i++){
			t += pow(s[i] - m, 2);
		}
		printf("%f\n", sqrt(t/n));
	}
	return 0;
}

Measured memory_bytes: 2640
n,m,q = map(int,input().split())
abcd = [[*map(int,input().split())] for _ in range(q)]

def dfs(A=[1]): # A:1 origin
    if n+1 <= len(A):
        return sum(d if A[b]-A[a]==c else 0 for a,b,c,d in abcd)
    A.append(A[-1])
    ret = 0
    while A[-1] <= m:
        ret = max(ret, dfs(A))
        A[-1] += 1
    A.pop()
    return ret

ans = dfs()
print(ans)


Measured memory_bytes: 9136
import java.io.*;
import java.util.*;
 
public class Main {
 
	void submit() {
	    int N = nextInt();
	    
        out.println(N*N*N);
	}

	void preCalc() {
 
	}
 
	void stress() {
 
	}
 
	void test() {
 
	}
 
	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}
 
	static final Random rng = new Random();
 
	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}
 
	public static void main(String[] args) throws IOException {
		new Main();
	}
 
	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
 
	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}
 
	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
 
	int nextInt() {
		return Integer.parseInt(nextToken());
	}
 
	long nextLong() {
		return Long.parseLong(nextToken());
	}
 
	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 21204
import std.stdio, std.conv, std.string, std.algorithm,
       std.math, std.array, std.container, std.typecons;

long mod = 1000000007;
long n;

long solve(long l) {
  long min = l*(l-1)/2;
  long max = n*(n+1)/2 - (n-l+1)*(n-l)/2;
  return max-min+1;
}

void main() {
  long k;
  readf("%d %d\n", &n, &k);
  long res = 0;
  for(long i=k; i<=n+1; i++) {
    res += solve(i) % mod;
    res %= mod;
  }
  writeln(res);
}


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

struct ModInt {
    using M = ModInt;
    long long v;
    ModInt(long long _v = 0) : v(_v % MOD + MOD) { norm(); }
    M &norm() {
        v = (v < MOD) ? v : v - MOD;
        return *this;
    }
    M operator+(const M &x) const { return M(v + x.v); }
    M operator-(const M &x) const { return M(v + MOD - x.v); }
    M operator*(const M &x) const { return M(v * x.v % MOD); }
    M operator/(const M &x) const { return M(v * x.inv().v); }
    M &operator+=(const M &x) { return *this = *this + x; }
    M &operator-=(const M &x) { return *this = *this - x; }
    M &operator*=(const M &x) { return *this = *this * x; }
    M &operator/=(const M &x) { return *this = *this / x; }
    friend istream &operator>>(istream &input, M &x) {
        return input >> x.v, x.norm(), input;
    }
    friend ostream &operator<<(ostream &output, const M &x) {
        return output << x.v;
    }
    M pow(long long n) const {
        M x(v), res(1);
        while (n) {
            if (n & 1)
                res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }
    M inv() const { return this->pow(MOD - 2); }

    static long long MOD;
    static vector<M> fact, finv;
    static void build(int n) {
        fact.assign(n + 1, 1);
        finv.assign(n + 1, 1);
        for (int i = 1; i < n + 1; i++)
            fact[i] = fact[i - 1] * M(i);
        for (int i = 0; i < n + 1; i++)
            finv[i] = fact[i].inv();
    }
    static M comb(int n, int k) {
        if (n < k || k < 0)
            return M(0);
        return fact[n] * finv[n - k] * finv[k];
    }
    static M extgcd(int a, int b, int *x, int *y) {
        M d(a);
        if (b) {
            d = extgcd(b, a % b, y, x);
            *y -= (a / b) * *x;
        } else {
            *x = 1, *y = 0;
        }
        return d;
    }
};
vector<ModInt> ModInt::fact = vector<ModInt>();
vector<ModInt> ModInt::finv = vector<ModInt>();
long long ModInt::MOD = 1e9 + 7;

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> x(n+1), y(m+1);
    for(int i = 1; i <= n; i++) cin >> x[i];
    for(int i = 1; i <= m; i++) cin >> y[i];

    ModInt xlen = 0, ylen = 0;
    for(int i = 1; i <= n; i++) xlen += (i - 1) * x[i] - (n - i) * x[i];
    for(int i = 1; i <= m; i++) ylen += (i - 1) * y[i] - (m - i) * y[i];
    cout << xlen * ylen << endl;
    return 0;
}


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


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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int a, b, ans = 1;
	cin >> a >> b;

	if (b == 1) {
		cout << "0\n";
		return 0;
	}
	while (a + (ans - 1) * (a - 1) < b)
		ans++;
	cout << ans << '\n';
}


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

int main()
{
  uint64_t n, k;
  cin >> n >> k;
  
  if (n > k) n = n % k;
  
  auto ans = min(n, max(n,k)-min(n,k));
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public class Prog
{
    public void run()
    {
        int n = int.Parse(Console.ReadLine());
        int[] S = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int q = int.Parse(Console.ReadLine());
        int[] T = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] Arr = new int[1000000001];
        int ans = 0;
        for(int i = 0; i < n; i++)
        {
            Arr[S[i]] = 1;
        }
        for(int i = 0; i < q; i++)
        {
            ans += Arr[T[i]];
        }
        Console.WriteLine(ans);
    }
    public static void Main()
    {
        var prog = new Prog();
        prog.run();
    }
    /*
    最小公倍数
    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }

    // ユークリッドの互除法 
    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
    */
    //a<=c, b<=d;
}

//Split().Select(int.Parse).ToArray()
//Array.ConvertAll(int.Parse)
//str.IndexOf("Stage",System.StringComparison.CurrentCulture)



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

int main(){
  int N;
  cin >> N;
  vector<char> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  int a1=0;
  int a2=0;
  int a3=0;
  int a4=0;
  int ans=0;
  for(int i=0;i<N;i++){
    if(A[i]=='G'){
      a1=1;
    }
    else if(A[i]=='W'){
      a2=1;
    }
    else if(A[i]=='Y'){
      a3=1;
    }
    else{
      a4=1;
    }
  }
  if(a1!=0){
    ans++;
  }
  if(a2!=0){
    ans++;
  }
  if(a3!=0){
    ans++;
  }
  if(a4!=0){
    ans++;
  }
  if(ans==3){
    cout << "Three" << endl;
  }
  else{
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define PF push_front
#define F first
#define S second
#define endl "\n"
#define pi 3.14159265358979323846264338327950288
#define MOD 1000000
#define INF -100000000000000
#define ordered_set tree<pair< ll int ,ll  int>, null_type,less<pair<ll int, ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds;
int main()
{
    fast;
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif
    ll int l,r,d;
    cin>>l>>r>>d;ll int i,c=0;
    for(i=1;i<=100;i++)
    {
    	if(d*i>=l && d*i<=r)
    		c++;
    }
    cout<<c<<endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <valarray>
#include <array>

using namespace std;

int main() {
	long long h, m = 1, ans = 0;
	cin >> h;
	while (h != 0) {
		h /= 2;
		ans += m;
		m *= 2;
	}
	cout << ans << endl;
}

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

using namespace std;

int a[310][310];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
			a[i][j]--;
		}
	}
	int ng = 0, ok = n;
	while (ok - ng > 1) {
		int mid = (ok + ng) / 2;
		vector<int> can(m, 1);
		vector<int> cur(n, 0);
		bool flag1 = true;
		while (true) {
			vector<int> cnt(m, 0);
			for (int j = 0; j < n; j++) {
				cnt[a[j][cur[j]]]++;
			}
			for (int j = 0; j < m; j++) {
				if (cnt[j] > mid) can[j] = 0;
			}
			bool flag2 = true;
			for (int j = 0; j < n; j++) {
				if (!can[a[j][cur[j]]]) {
					cur[j]++;
					if (cur[j] == m) {
						flag1 = false;
					}
					flag2 = false;
				}
			}
			if (!flag1 || flag2) break;
		}
		bool flag3 = false;
		for (int i = 0; i < m; i++) {
			if (can[i]) {
				flag3 = true;
				break;
			}
		}
		if (flag3) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	int n=s.size();
	ll ans=0;
	int tmp=0;
	REP(i, n){
		if(s[i]=='W'){
			ans+=tmp;
		}
		else{
			++tmp;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 720
#include<iostream>

using namespace std;

int main()
{
  int N;
  cin >> N;
  int A[N];
  for(int i=1;i<N;i++)
  {
    cin >> A[i];
  }
  
  int ANS[N];
  for(int i=0;i<N;i++)
  {
    ANS[i] = 0;
  }
  
  for(int i=1;i<N;i++)
  {
    ANS[A[i]-1]++;
  }

  for(int i=0;i<N;i++)
  {
    cout << ANS[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 5128
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
const int nax=1000*1007;

void nope()
{
	printf("No\n");
	exit(0);
}

int n;
int tab[nax];

vector <pair <int,int> > dos;

vector <int> musz, pot;

vector <int> wyn;

vector <int> zbi[nax];

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
	{
		scanf("%d", &tab[i]);
		dos.push_back({tab[i], i});
	}
	sort(dos.begin(), dos.end());
	for (auto i : dos)
	{
		for (int j=1; j<i.second; j++)
			musz.push_back(i.second);
		for (int j=1; j<=n-i.second; j++)
			pot.push_back(i.second);
	}
	for (int i : pot)
		musz.push_back(i);
	reverse(musz.begin(), musz.end());
	reverse(dos.begin(), dos.end());
	for (int i=1; i<=n*n; i++)
	{
		if (!dos.empty() && dos.back().first<=i)
		{
			wyn.push_back(dos.back().second);
			dos.pop_back();
		}
		else
		{
			wyn.push_back(musz.back());
			musz.pop_back();
		}
	}
	for (int i=0; i<n*n; i++)
		zbi[wyn[i]].push_back(i+1);
	for (int i=1; i<=n; i++)
		if (zbi[i][i-1]!=tab[i])
			nope();
	printf("Yes\n");
	for (int i : wyn)
		printf("%d ", i);
	printf("\n");
	return 0;
}


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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n ;
	int arr[n] ;
	for(int i = 0 ; i < n ; ++i)
		cin>>arr[i] ;
	map<int , int>mp ;
	for(int i = 0 ; i < n ; ++i)
		mp[arr[i]]++ ;
	int ans = 0 ;
	for(int i = 0 ; i < n ; ++i)
	{
		if(mp[arr[i]] >= arr[i])
		{
			ans += mp[arr[i]] - arr[i] ;
			mp[arr[i]] = arr[i] ;
		}
		else
		{
			ans += mp[arr[i]] ;
			mp[arr[i]] = 0 ;
		}
	}
	return cout<<ans<<"\n" , 0 ;
}

Measured memory_bytes: 5120
N, M = map(int, input().split())
A_B = [list(map(int, input().split())) for _ in range(N)]

A_B.sort(key=lambda x: x[0])
count = 0
result = 0
for a, b in A_B:
    if count + b < M:
        count += b
        result += a * b
    else:
        result += a * (M - count)
        break

print(result)

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

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

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

int main(){
    string s, t; cin>>s>>t;
    int n=s.size();

    int f[30][30];
    memset(f, 0, sizeof(f));
    for(int i=0; i<n; i++){
        int a=s[i]-'a', b=t[i]-'a';
        f[a][b]=1;
    }

    for(int i=0; i<26; i++){
        int cnt=0;
        for(int j=0; j<26; j++){
            cnt+=f[i][j];
        }
        if(2<=cnt){
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i=0; i<26; i++){
        int cnt=0;
        for(int j=0; j<26; j++){
            cnt+=f[j][i];
        }
        if(2<=cnt){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

void solve() {
    ll n;
    cin>>n;
    cout<<(n+1)/2;
}

int main()
{
    ll t = 1;
    // cin>>t;
    while(t--) {
        solve();
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,c) memset(a,c,sizeof(a))

#define DEBUG(x) cout<<"#x"<<": "<<x<<endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX/3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};

int main(){
    while(true){
	string s;
	string ans = "";
	getline(cin,s);
	if(s == "END OF INPUT") break;
	s = ' ' + s + ' ';
	REP(i,s.size()){
	    FOR(j,i+1,s.size()){
		if(s[j] == ' ') {
		    ans += to_string(j-i-1);
		    i = j;
		}
	    }
	}
	cout << ans << endl;

    }

    return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
#include <algorithm>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  string W;
  cin>>W;
  
  vector<char> vec(W.size());
  for(int i=0;i<W.size();i++){
    vec[i]=W[i];
  }
  
  vector<int> num(26);
  for(int i=0;i<26;i++){
    num[i]=count(vec.begin(),vec.end(),'a'+i);
  }
  
  bool res=true;
  
  
  for(int i=0;i<26;i++){
    if(num[i]%2!=0){
      res=false;
      break;
    }
  }
  
  if(res){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3616
#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
ll counts(ll s)//sum of the digits of s
{
	if(s == 0)
	{
		return 0;
	}
	return s % 10 + counts(s / 10);
}
ll nxt(ll x,ll y)//ceil(x/y)
{
	return (x + y - 1) / y;
}
int main()
{
	ll K;
	cin>>K;
	ll cur = 2,p = 1;
	while(K)
	{
		ll n = cur * p - 1;
		ll m = ceil((double)cur/10.0) * p * 10 - 1;
		if(n * counts(m) > m * counts(n))
		{
			cur = ceil((double)cur/10.0);
			p *= 10;
		}
		else
		{
			cout<<n<<endl;
			K--;
			cur++;
		}
		// printf("cur = %lld,p = %lld\n",cur,p);
	}
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()
#define mp(a, b) make_pair(a, b)
const int inf = 1 << 28;

struct edge{int to, wt;};

int n, m;
map<int, vector<pair<int, int> > > es;
vector<vector<edge> > g;

bool slimPrim(){
    vector<bool> vis(n);
    auto comp = [](const edge &e, const edge &d){return e.wt < d.wt;};
    priority_queue<edge, vector<edge>, decltype(comp)> q(comp);
    for(q.push((edge){0, 0}); !q.empty();){
        edge e = q.top(); q.pop();
        if(vis[e.to])continue;
        vis[e.to] = true;
        for(auto x: g[e.to])if(!vis[x.to])q.push(x);
    }
    return count(all(vis), false) == 0;
}

int solve(){
    int res = inf;
    for(auto itr1=es.begin(); itr1!=es.end(); ++itr1){
        g.assign(n, vector<edge>());
        for(auto itr2=itr1; itr2!=es.end(); ++itr2){
            if(res <= (*itr2).first - (*itr1).first)break;
            for(auto v: (*itr2).second){
                g[v.first].push_back((edge){v.second, (*itr2).first});
                g[v.second].push_back((edge){v.first, (*itr2).first});
            }
            if(slimPrim())res = (*itr2).first - (*itr1).first;
        }
    }
    return res == inf? -1: res;
}

int main(){
    while(cin >> n >> m, n|m){
        es.clear();
        rep(i, m){
            int a, b, w;
            cin >> a >> b >> w;
            es[w].push_back(mp(a-1, b-1));
        }
        cout << solve() << '\n';
    }
    return 0;
}

Measured memory_bytes: 1668
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
using namespace std;
using ll = long long;

// There are no cycles, so every valid edge decreases the number of components by 1
// For each edge, subtract 1 for each interval it appears in.
// (A,B) appears iff L<=A && B<=R. So L could be any of 1..A and R could be any of B..N
// So (A,B) appears in A*(N-B+1) intervals
//
//
// for L=1..N:
//   for R=L..N:
//     ans += R-L+1-edges(L,R)
//
// 1+2+..+N
// 1+2+..+N-1
//
// the first term is 
//     
// Every edge

// 1+2+...+N
ll S(ll n) {
  return n*(n+1)/2;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for(ll i=1; i<=n; i++) {
    ans += S(i);
  }
  for(ll i=0; i<n-1; i++) {
    ll a,b;
    cin >> a >> b;
    if(a>b) {
      ll tmp = a;
      a = b;
      b = tmp;
    }
    assert(a<=b);
    ans -= a*(n-b+1);
  }
  cout << ans << endl;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define fst first
#define snd second
typedef long long ll;

main(){
  int n; cin >> n;
  ll a;
  map<ll, ll> mp;
  rep(i, n){
    cin >> a;
    mp[a]++;
  }

  ll ss = 0, ls = 0;

  for(auto x : mp){
    if(x.snd >= 4){
      ss = x.fst;
      ls = x.fst;
    }else if(x.snd >= 2){
      ss = ls;
      ls = x.fst;
    }
  }

  cout << ss * ls << endl;
}

Measured memory_bytes: 6528
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello
{

    public static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        int[] num = Array.ConvertAll<string, int>(s, delegate (string value) { return int.Parse(value); });
        Array.Sort(num);
        Console.WriteLine(num[0]+num[1]);
    }
}

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

// ----------- define --------------
#define int long long
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
// ---------------------------------

int get(int a, int b, int x) {
  return b / x - (a - 1) / x;
}

int lcm(int a, int b) {
  return a / __gcd(a, b) * b;
}

void MAIN() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << (b - a + 1) - get(a, b, c) - get(a, b, d) + get(a, b, lcm(c, d)) << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3660
import qualified Data.Array.ST    as S
import qualified Data.Array       as S
import qualified Control.Monad.ST as S
import Control.Monad

import qualified Data.ByteString.Char8 as B
import qualified Data.IntSet as Set
import Data.Maybe
import Data.List

import Data.Array.Unboxed

genPrimes :: Int -> [Int]
genPrimes n = map fst . filter snd . zip [2..] $ S.runST ( do
    isPrime <- S.newArray (2, n) True :: S.ST s (S.STUArray s Int Bool)
    forM_ [2..div n 2] $ \i ->
        S.writeArray isPrime (2*i) False
    forM_ [3,5..n] $ \i -> do
        a <- S.readArray isPrime i
        when a (forM_ [2..div n i] $ \l ->
            S.writeArray isPrime (i*l) False)
    S.elems <$> S.freeze isPrime)

main :: IO ()
main = do
    let m = 100000
    q <- read <$> getLine :: IO Int
    qs <- replicateM q ((\[a,b]->(a,b)) . 
        map (fst . fromJust . B.readInt) . B.words <$> B.getLine) :: IO [(Int,Int)]
    let primes = Set.fromList (genPrimes m)
        isPrime n = n `Set.member` primes
        primeCnt = listArray (0, m) . drop 1 $ scanl (+) 0
                   [if odd i && isPrime i && isPrime ((i+1) `div` 2) then 1 else 0|i<-[0..m]] :: UArray Int Int
    mapM_ (\(l,r) -> print $ primeCnt!r - primeCnt!(l-1)) qs

Measured memory_bytes: 43772
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x=a*b;
    int y=c*d;
    if(x>y) cout<<x<<endl;
    else if(x<y) cout<<y<<endl;
    else if(x==y) cout<<x<<endl;
    
    return 0;
}


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


using namespace std;

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

#define INF 1050000000




int main() {

	int N,D;

	cin >> N>>D;

	double X[10][10];

	rep(i, N) {
		rep(j, D) {
			cin >> X[i][j];
		}
	}


	double sum = 0;

	int ans = 0;

	rep(i, N) {

		

		repr(j, i +1, N) {
			sum = 0;

			rep(k, D) {
				sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);

			}

			

			sum = sqrt(sum);

			

			if (sum == int(sum))ans++;
		}
	}


	cout << ans << endl;




	return 0;
}

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

int main(int argc, char *argv[])
{
	int H,N;
	cin >> H>>N;
	
	vector<int> A(N),B(N);
	vector<int> dp(H+1);

	
	for (int i=0;i<N;i++)
	{
		cin>>A[i]>>B[i];
		//cerr<<i<<":"<<A[i]<<":"<<B[i]<<endl;
	}
	
	dp[0]=0;
	for(int h=1;h<=H;h++)
	{
		int b;
		if (A[0]>h) 
		{
			b=B[0];
		} else {
			b=dp[h-A[0]]+B[0];
		}
		//cerr<<h<<"=0="<<b<<endl;
		for(int i=1;i<N;i++)
		{
			int t;
			if (A[i]>h) 
			{
				t=B[i];
			} else {
				t=dp[h-A[i]]+B[i];
			}
			if (t<b) b=t;
		}
		dp[h]=b;
		//cerr<<h<<":"<< dp[h]<<endl;
	}
	cout<<dp[H]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define elif(a) else if(a)
#define INF INT_MAX
#define F first
#define S second
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
  cout<<n-k+1<<endl;
  return 0;
}



Measured memory_bytes: 256
from itertools import accumulate
n,q = map(int, input().split())
s = input()
b = [0] * len(s)
c = 0
lr = [list(map(int, input().split())) for i in range(q)]
for i,j in enumerate(s):
  if c == 0:
    if j == "A":
      c += 1
  elif c == 1:
    if j == "A":
      continue
    elif j == "C":
      b[i] += 1
      c = 0
    else:
      c = 0
cumsum = list(accumulate(b))
for i in lr:
  print(cumsum[i[1]-1]-cumsum[i[0]-1])
  
  

Measured memory_bytes: 33052
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define INF 1000000007
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2)*pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int jo(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= 2;
	}
	return ans;
}
signed main() {
	int a, b;
	cin >> a >> b;
	if (abs(a - b) >= 2) {
		cout << 0 << endl;
	}
	else if(a==b) {
		int ans = 2;
		loop(i, 1, a + 1) {
			ans *= i;
			ans %= INF;
		}
		loop(i, 1, b + 1) {
			ans *= i;
			ans %= INF;
		}
		cout << ans%INF << endl;
	}
	else {
		int ans = 1;
		loop(i, 1, a + 1) {
			ans *= i;
			ans %= INF;
		}
		loop(i, 1, b + 1) {
			ans *= i;
			ans %= INF;
		}
		cout << ans % INF << endl;
	}
}

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

int main() {
  int A, B, C, D;
  
  cin >> A >> B >> C >> D;
  
  if ( A+B > C+D )
    cout << "Left" << endl;
  else if ( A+B == C+D )
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define LL long double
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }
const int N = 200050;
int n,k,a[N]; LL pre[N],ans;
int main(){
	int i;
	read(n),read(k);
	for (i = 1; i <= n; ++i) read(a[i]),pre[i] = pre[i-1] + (a[i]+1) * 0.5;
	for (i = 1; i <= n-k+1; ++i) ans = max(ans,pre[i+k-1]-pre[i-1]);
	cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4096