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

struct Node {
  int key;
  Node *right, *left, *parent;
};
Node *root, *NIL;

Node * find(Node *u, int k) {
  while (u != NIL && k != u->key) {
    if (k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}




void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ) {
    y = x;
    if( z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if ( y == NIL ){
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}
void inorder(Node *u){
  if ( u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u){
  if( u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
	int n, i, x;
  string com;

  scanf("%d", &n);

  for (i = 0; i < n; i++ ) {
    cin >> com;
    if( com[0] == 'f') {
      scanf("%d", &x);
      Node *t = find(root, x);
      if (t != NIL) printf("yes\n");
      else printf("no\n");
    }
    else if (com == "insert") {
      scanf("%d", &x);
      insert(x);
    } else if (com == "print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 22088
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=-mod;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

//関数
//最大公約数
long long gcd(long long m,long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m,long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x,long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//nCr
long long C(long long n, long long r);
//nCr (mod)
long long modC(long long n, long long r) {
    vector<long long> f(n+1),inv(n+1),invf(n+1);
    f[0]=f[1]=1;
    invf[0]=invf[1]=1;
    inv[1]=1;
    for (long long i=2;i<n+1;i++) {
        f[i]=(i*f[i-1])%mod;
        inv[i]=mod-((mod/i)*inv[mod%i])%mod;
        invf[i]=(inv[i]*invf[i-1])%mod;
    }
    long long cmb=f[n]*(invf[r]*invf[n-r]%mod)%mod;
    if (n>=r) return cmb;
    else return 0;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  vl dh={1,0,-1,0};
  vl dw={0,1,0,-1};
  
  lin(H);lin(W);
  ll res=H*W;
  
  char s[H][W];
  rep(i,H){
    rep(j,W){
      cin>>s[i][j];
      if(s[i][j]=='#') res--;
    }
  }
  
  queue<P> Q;
  
  ll d[H][W];
  rep(i,H){
    rep(j,W){
      d[i][j]=-1;
    }
  }
  
  Q.push(P(0,0));
  d[0][0]=0;
  
  while(Q.size()!=0){
    P p=Q.front(); Q.pop();
    
    rep(i,4){
      ll h=p.first+dh[i];
      ll w=p.second+dw[i];
      
      if(h>=0&&h<=H-1&&w>=0&&w<=W-1 &&s[h][w]=='.'&& d[h][w]==-1){
        d[h][w]=d[p.first][p.second]+1;
        Q.push(P(h,w));
      }
    }
  }
  
  //cout<<d[H-1][W-1]<<endl;
  //cout<<d[1][0]<<endl;
  
  if(d[H-1][W-1]==-1){
    cout<<-1;
  }
  else{
    cout<<res-d[H-1][W-1]-1;
  }
}
        



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

#define rep(i, first, to) for(ll i = first; i < to; ++i)

using namespace std;
typedef long long ll;

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

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
 
const ll MOD=1e9+7;
const ll INF=1e18;
 
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};


double cell[110][4];
double dist[110][110]; // お互いの距離

int par[110];//親
int rank2[110];//木の深さ

void init(int n){
  for(int i = 0;i < n;i++){
    par[i] = i;
    rank2[i] = 0;
  }
}

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

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return;
  
  if(rank2[x] < rank2[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(rank2[x] == rank2[y])rank2[x]++;
  }
}

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



int main(){
    int n;
    while(1){
        cin >> n;
        if(n == 0)break;
        init(n);
        for(int i = 0;i < n;i++){
            for(int j = 0;j < 4;j++){
                cin >> cell[i][j];
            }
        }
        for(int i = 0;i < n;i++){
            for(int j = i+1;j < n;j++){
                double xyz = 0.0,rsum = cell[i][3] + cell[j][3];
                for(int k = 0;k < 3;k++){
                    xyz += (cell[i][k]-cell[j][k])*(cell[i][k]-cell[j][k]);
                }
                if(rsum*rsum >= xyz){ // iとjはつながっている
                    unite(i,j);
                }else{
                    dist[i][j] = sqrt(xyz) - rsum;
                    dist[j][i] = sqrt(xyz) - rsum;
                }
            }
        }
        double ans = 0.0;
        while(true){
            int flag = 0;
            int a,b;
            double distmin = 1000000.0;
            for(int i = 0;i < n;i++){
                for(int j = i+1;j < n;j++){
                    if(same(i,j) == false && distmin > dist[i][j]){
                        a = i;
                        b = j;
                        distmin = dist[i][j];
                        flag = 1;
                    }
                }
            }
            if(flag == 0)break;
            unite(a,b);
            ans += distmin;
        }
       // ans += 0.00001;
        //cout << round(ans*1000)/1000  << endl;
        printf("%.3f\n",ans);
    }
}


Measured memory_bytes: 3280
#include<stdio.h>
#include<string.h>
char a[51][51],b[51][51];
int main()
{
	int i,j,k,l,n,m;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
	scanf("%s",&a[i]);
	for(j=0;j<m;j++)
	scanf("%s",&b[j]);
	for(k=0;k<n;k++)
	for(l=0;l<n;l++)
	{
		if(a[k][l]==b[0][0])
		for(i=0;i<m;i++)
		{
			for(j=0;j<m;j++)
			{
				if(a[k+i][l+j]!=b[i][j])
				break;
			}
			if(j!=m)
			break;
			
		}
		if(i==m)
		{
			printf("Yes");
			return 0;
		}
			
	}
	printf("No");
	return 0;
	
}

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

int main(){
	//carryªIChaveªÁÄ¢é
	int carry,have,sum_prize;
	long int mod[8]={100000000,10000000,1000000,100000,10000,1000,100,10};

	while(cin >> carry >> have){
		if(carry == 0 && have == 0) break;

		string number;
		int prize[100],index[100],num[100];

		for(int icarry=0;icarry<carry;icarry++){
			cin >> number >> prize[icarry];
			index[icarry] = number.rfind("*");
			for(int i=0;i<=index[icarry];i++){
				number.replace(number.find("*"),1," ");
			}
			istringstream ss(number);
			ss >> num[icarry];
		}
		int lotnum[1000];
		for(int ihave=0;ihave<have;ihave++){
			cin >> lotnum[ihave];
		}

		sum_prize = 0;
		//numªIÔ,prizeªIàz
		for(int j=0;j<carry;j++){
			for(int k=0;k<have;k++){
				if((lotnum[k]-num[j])%mod[index[j]+1]==0){
						sum_prize += prize[j];
				}
			}
		}
		cout << sum_prize << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 10;

int main()
{
  int r,D,x;
  cin >> r >> D >> x;
  for(int i=0; i<N; i++)
  {
    x = r*x-D;
    cout << x << endl;
  }
  return 0;
}


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  ll N;
  ll left=0;
  ll right=1;
  ll n=1;
  cin>>N;
  while(N<left ||  right<N){
    if(n%2==1){
      left+=pow(-2,n);
    //  cout<<"left="<<left<<endl;

    }
    else right+=pow(-2,n);
    n++;
  }

  n--;
  if(n%2==1) left-=pow(-2,n);
  else right-=pow(-2,n);

  //cout<<n<<" left="<<left<<" right="<<right<<" N="<<N<<endl;
  FORr(i,n,-1){
    if(N<left||right<N) {
      cout<<'1';
      if(i%2==0) left-=pow(-2,i-1);
      else right-=pow(-2,i-1);
      N-=pow(-2,i);
    }
    else {
      cout<<'0';
      if(i%2==0) left-=pow(-2,i-1);
      else right-=pow(-2,i-1);
    }
      //cout<<i<<" left="<<left<<" right="<<right<<" N="<<N<<endl;
  }
  cout<<endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
char mem[114514];
char t[114514];
int a[114514];
signed main(){
	ic(n)
	rep(0,i,n)cin>>a[i];
	sort(a,a+n);
	reverse(a,a+n);
	int j=0;
	int ans=0;
	rep(0,i,n){
		if(a[i]==a[i+1]){
			ans=a[i];
			j=i+2;
			break;
		}
	}
	rep(j,i,n){
		if(a[i]==a[i+1]){
			ans*=a[i];
			break;
		}
		if(i==n-1)ans=0;
	}
	c(ans)
}			


Measured memory_bytes: 1024
# N = int(input())

import numpy as np

A,B,H,M = list(map(int, input().split()))


time = 60*H + M

jishin_deg_perM = 2*np.pi / 720

jishin_coord  = np.array([A * np.cos(jishin_deg_perM*time), A * np.sin(jishin_deg_perM*time)])

funshin_deg_perM =  2*np.pi / 60

funshin_coord  = np.array([B * np.cos(funshin_deg_perM*M), B * np.sin(funshin_deg_perM*M)])

print(np.linalg.norm(jishin_coord-funshin_coord))

Measured memory_bytes: 27272
#include <stdio.h>

int main(int argc,char* argv[]){
  int time;
  int count;
  int amount = 100000;

  scanf("%d",&time);

  for(count = 0;count < time; count++){
    
    amount *= 1.05;
    if(amount % 1000 != 0){
      amount = (amount/1000+1)*1000;
    }
    
  }
  
  printf("%d\n",amount);

  return 0;
  
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <algorithm>
#include <functional>
#include <utility>
#include <tuple>
#include <ctime>
#include <cmath>
#include <fstream>
#include <sstream>
using namespace std;
#define INF 1000000007
#define PB push_back
#define MP make_pair
#define X first
#define Y second

typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef queue<int> QI;
typedef queue<PII> QII;
typedef map<int,int> MII;
typedef map<string,int> MSI;
typedef set<int> SI;
typedef set<PII> SII;
typedef long long ll;

vector<ll> pref;
ll isum(int a, int b);


int main() {
	ios_base::sync_with_stdio(0);
	int N;
	cin >> N;
	pref.PB(0);
	for(int i=1;i<=N;i++)
	{
		ll k; cin >> k;
		pref.PB(pref[i-1]+k);
	}
	int low=0; int mid=1; int high=N-2;
	while((abs(isum(N,high-1)-isum(high-1,mid))<abs(isum(N,high)-isum(high,mid)))&&high-1>mid)
		high--;
	ll best=-1; ll A,B,C,D;
	for(int i=1;i<N;i++)
	{
		//position of mid
		while(abs(isum(low+1,-1)-isum(mid,low+1))<abs(isum(low,-1)-isum(mid,low))&&low<mid-1)
			low++;
		while(abs(isum(N-1,high+1)-isum(high+1,mid))<abs(isum(N-1,high)-isum(high,mid))&&high<N-2)
			high++;
		A=isum(low,-1); B=isum(mid,low); C=isum(high,mid); D=isum(N-1,high);
		ll d=max(max(A,B),max(C,D))-min(min(A,B),min(C,D));
		if(best==-1||best>d)
			best=d;
		mid++;
	}
	cout << best << endl;
return 0;
}

ll isum(int a, int b)
{
	return pref[a+1]-pref[b+1];
}


Measured memory_bytes: 2548
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int maxn = 3e5+10;
const int maxm = 1e6+10;
const int mod = 998244353;

int n;
int val[505][505],dist[505][505];
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};

void bfs(int sx,int sy){
    queue<pair<int,int> >q;
    q.push(make_pair(sx,sy));
    while(!q.empty()){
        int x=q.front().first,y=q.front().second;q.pop();
        for(int i=0;i<4;i++){
            int newx=x+dx[i],newy=y+dy[i];
            if(newx<0||newx>n||newy<0||newy>n)continue;
            if(dist[newx][newy]>dist[x][y]+val[x][y]){
                dist[newx][newy]=dist[x][y]+val[x][y];
                q.push(make_pair(newx,newy));
            }
        }
    }
}

int main(){
    cin>>n;
    FOR(i,1,n)FOR(j,1,n)dist[i][j]=min(min(i-1,j-1),min(n-j,n-i)),val[i][j]=1;
    int ans=0;
    FOR(i,1,n)FOR(j,1,n){
        int P;cin>>P;
        int x=(P+n-1)/n;
        int y=P%n==0?n:P%n;
        val[x][y]--;
        bfs(x,y);
        ans+=dist[x][y];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5572
#include <stdio.h>
int MAX(int a,int b){
    return a>b?a:b;
}
int MIN(int a,int b){
    return a<b?a:b;
}
int main()
{   int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    printf("%d ",MIN(a,b));
    if(a+b>n){
        printf("%d",a+b-n);
    }else{
        printf("0");
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define vl vector<ll>
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define sz size()
#define en end()
#define ro return 0
#define br break
#define con continue;
#define um unordered_map<ll,ll>
#define ms(x) memset(x , 0 , so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define forr(i,a,b) for(ll i=a;i<b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
int main()
{
    ios;
    ll a , b ;
    cin  >> a >> b;
    cout << max(a*b , max(a-b , a+b)) << el ;
    ro ;

}

















Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int n;
    double *v;
    scanf("%d", &n);
    v = malloc(sizeof(double)*n);
    int i;
    for (i = 0; i < n; i++) {
        scanf("%lf", &v[i]);
    }

    int j;
    for (i = 0; i < n; i++) {
        for (j = n-1; j > i; j--) {
            if (v[j] < v[j-1]) {
                double tmp = v[j];
                v[j] = v[j-1];
                v[j-1] = tmp;
            }
        }
    }

    double ans=(v[0]+v[1])/2;
    for (i = 2; i < n; i++) {
        ans = (ans + v[i])/2;
    }

    printf("%f", ans);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define MAX_V 100000
#define INF 1<<29
using namespace std;
struct edge{int to,cap,rev;};
vector<edge>G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}
void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int>q;
  level[s]=0;
  q.push(s);
  while(!q.empty()){
    int v=q.front();q.pop();
    for(int i=0;i<G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[e.to]<0){
        level[e.to]=level[v]+1;
        q.push(e.to);
      }
    }
  }
}
int dfs(int v,int t,int f){
  if(v==t)return f;
  for(int &i=iter[v];i<G[v].size();i++){
    edge &e=G[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s,int t){
  int flow=0;
  while(1){
    bfs(s);
    if(level[t]<0)return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,INF))>0){
      flow+=f;
    }
  }
}
int main(){
  int n,m;
  cin>>n>>m;
  while(m--){
    int a,b,c;
    cin>>a>>b>>c;
    add_edge(a,b,c);
  }
  cout<<max_flow(0,n-1)<<endl;
}

Measured memory_bytes: 6308
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
map<int,int> ma;

int main() {
    while (cin >> N) {
        ma.clear();
        for (int i = 0; i < N; ++i) {
            int a;
            cin >> a;
            ma[a]++;
        }
        int res = 0;
        for (map<int,int>::iterator it = ma.begin(); it != ma.end(); ++it) {
            if (it->second % 2 == 1) ++res;
        }
        cout << res << endl;
    }
}











Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int n,cnt,flag;

int main(void){
    cin >> n;
    vector<int> a(n);

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

    for(int i = 0; i < n; i++){
        if(cnt+1 == a[i]){
            cnt++;
            flag = 1;
        }
    }
	if(flag){
    	cout << n - cnt << endl;
    }else{
      	cout << -1 << endl;
    }
}

Measured memory_bytes: 1024
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1000000007
#define mxval 1e9 + 7
#define grt [](auto x,auto y){return x>y;}
#define pii pair<int,int>
/*********VARIABLE****************/
using namespace std;
int i,j,n,m,k,l,q,t,a,b,sum[3],tot[3],cnt[3];
/*********FUNCTIONS**************/
int powom(int a,int b) {
    int result = 1;
    while (b > 0) {
        if (b & 1)
            result = result * a;
        a = a * a;
        b >>= 1;
    }
    return result;
}
/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int m,d,cnt = 0;
	cin>>m>>d;
	for(int i=1;i<=m;i++){
		for(int l=1;l<=d;l++){
			int j = l;
			int x = j%10;
			j/=10;
			int y = j%10;
			if((x!=1&&y!=1)&&i==(x*y)){
				// cout<<i<<" "<<x<<y<<"\n"; 
				cnt++;
			}
		}
	}
	cout<<cnt;
    return 0;
}
//.........

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

int main() {
    string S, T;
    cin >> S >> T;
    bool can = true;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) can = false;
    }
    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3640
import java.io.*;
import java.util.*;
public class Main{
   
     public static void main(String []args){
       Scanner s=new Scanner(System.in);
       int n=s.nextInt();
       int a[]=new int[n];
       int min=101,max=0;
       for(int i=0;i<n;i++)
       {a[i]=s.nextInt();
       min=Math.min(min,a[i]);
       max=Math.max(max,a[i]);
       }
       int minans=Integer.MAX_VALUE;
       for(int i=min;i<=max;i++)
       {int ca=0;
       for(int j=0;j<n;j++)
       {ca+=(a[j]-i)*(a[j]-i);}
       minans=Math.min(minans,ca);
       }
       System.out.println(minans);
     }}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
ll n,m,a;
int main(){
	ll i;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>a;
		n-=a; 
	}
	if(n<0)
	{
		cout<<-1<<endl;
	}
	else
	{
		cout<<n<<endl;
	}
	return 0;
}

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


const int Nmax=200010;
//#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//#definr REP(i,n) FOR(i,0,n)
//#define dump(x) cout << #x << "=" << (x) << endl;
//#define debug(x) cout << #x << "=" << (x) << "(L" << _LINE_ << ")" << "" << _FILE_ << endl;
//ll a[Nmax];
//int* P = new int[N];

int main() {
	ll N,C,x[Nmax],v[Nmax],S[Nmax]={0},fA[Nmax]={0},fB[Nmax]={0};
	cin >> N >> C;
	x[0]=0;v[0]=0;
  	x[N+1]=C;v[N+1]=0;
	for(int i=1;i <= N;i++){
		cin >> x[i] >> v[i];
		S[i]=S[i-1]+v[i]; //カロリーの累積和
	}
	ll mac1=0,mac2=0,cal,kyori;
  fA[0]=0;fB[N+1]=0;
  	for(int i=1;i <= N;i++){
      fA[i] = S[i] - x[i];
      fB[N-i+1] = (S[N]-S[N-i])-(C-x[N-i+1]);
      fA[i] = max(fA[i],fA[i-1]);
      fB[N-i+1] = max(fB[N-i+1],fB[N-i+2]);
    }
	for(int i=1;i <= N+1;i++){//B→A
			mac1 = max(mac1, fA[i-1]+(S[N]-S[i-1])-2*(C-x[i]));
	}
	for(int i=0;i <= N;i++){//A~B Aを固定
			mac2 = max(mac2, S[i]+fB[i+1]-2*x[i]);
	}
	cout << max(mac1, mac2) << endl;
	return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#include<functional>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.20f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define cotu cout
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b){if(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx;
    int dy = ty - sy;

    for(int i=0;i<dx;i++) cout << "R";
    rep(i,0,dy) cout << "U";
    rep(i,0,dx) cotu << "L";
    rep(i,0,dy) cout << "D";

    cout << "D";
    rep(i,0,dx+1) cout << "R";
    rep(i,0,dy+1) cout << "U";
    cout << "L";
    cout << "U";

    rep(i,0,dx+1) cout << "L";
    rep(i,0,dy+1) cout << "D";
    cout << "R";

    cout << endl;
    return 0; 

}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
const int N = 110 , mz = 1e9+7;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if( b > c ){
        swap(b,c);
    }
    if( a > c ){
        swap(a,c);
    }
    if( a > b ){
        swap(a,b);
    }
    cout<<(c-b)+(b-a)<<endl;
    return 0;
}


Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
var arr=[];
for(var i=0;i<=100001;i++)arr[i]=1;
for(var i=0;i<n;i++){
   var ab=(Arr.shift()).split(" ").map(Number);
   var a=ab[0];
   var b=ab[1];
   for(var j=a;j<=b;j++)arr[j]++;
}
var max=1;
for(var i=2;i<=100001;i++){
   if(arr[i]>=i)max=i;
}
console.log(max-1);

Measured memory_bytes: 36916
import sys
n = int(input())
xyh = [list(map(int, input().split())) for i in range(n)]
xyh.sort(key=lambda x: -x[2])
for cx in range(101):
    for cy in range(101):
        good = True
        h = xyh[0][2]+abs(cx-xyh[0][0])+abs(cy-xyh[0][1])
        for i in range(n):
            if xyh[i][2] != max(h-abs(cx-xyh[i][0])-abs(cy-xyh[i][1]), 0):
                good = False
                break
        if good:
            print(cx, cy, h)
            sys.exit()

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

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

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillDouble(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%lf", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;
const int MAX_V = 100005;

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

  int n, z, w;
  cin >> n >> z >> w;

  vector<long> a(n);
  fillLong(a, n);

  if (n == 1) {
    cout << abs(a[0] - w) << endl;
  } else {
    cout << max(abs(a[n-1] - w), abs(a[n-2]-a[n-1])) << endl;
  }
}


Measured memory_bytes: 256
h, w = [int(i) for i in input().split()]
a = []
answer = []

for i in range(h):
    a.append([int(i) for i in input().split()])
  
for i in range(h):  
    for j in range(w):  
        if a[i][j] % 2 != 0:
            if j != w - 1:
              a[i][j] -= 1
              a[i][j + 1] += 1            
              answer.append([i+1, j+1, i+1, j+2])
            elif i != h - 1:
                  a[i][j] -= 1
                  a[i+1][j] += 1  
                  answer.append([i+1, j+1, i+2, j+1])
    
print(len(answer))
for i in range(len(answer)):
    print(" ".join(map(str, answer[i])))


Measured memory_bytes: 29736
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
# from bisect import *
# from collections import *
# from heapq import *
# import itertools
# import math
# INF = 10**9
# MOD = 10**9+7

a, b = map(int, input().split())
if a >= 10 or b >= 10:
    print(-1)
else:
    print(a*b)


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int rate(int r){
    for(int i=0; i<8; i++){
        if(400 * i <= r && r < 400 * (i+1)) return i;
    }
    return 8;
}

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

    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];

    vector<int> cnt(9);
    for(int i=0; i<N; i++){
        int color = rate(a[i]);
        cnt[color]++;
    }

    int ans = 0;
    for(int i=0; i<8; i++){
        if(cnt[i] > 0) ans++;
    }

    int mn = max(1, ans);
    int mx = ans + cnt[8];
    cout << mn << " " << mx << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    long x;
    long a;
    long b;
    
    scanf("%ld %ld %ld", &x, &a, &b);
    
    if(a >= b){
        printf("delicious");
    }else if(x < b - a){
        printf("dangerous");
    }else if(x >= b - a){
        printf("safe");
    }
    
    
}


Measured memory_bytes: 1688
#include <iostream>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#define MAX_U   10
#define MIN_U   0
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef queue<int> qi;
const int INF=numeric_limits<int>::infinity();
void printa(){cout<<"\n";}
template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
template<class... A>void printa(const A&... rest){printa(rest...);}
void prints(){cout<<" ";}
template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
template<class... A>void prints(const A&... rest){prints(rest...);}
int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
double trapezium(int a,int b,int h){return (a+b)*h/2;}
double triangle(int a,int h){return a*h/2;}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin >>a>>b>>c>>d;
    if(a*b>c*d)printa(a*b);
    else if(c*d>a*b)printa(c*d);
    else if(a*b==c*d)printa(a*b);
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 200001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

int main(){
  ll n,k; cin >> n >> k;
  vl num(n);
  
  rep(i,n) cin >> num[i];
  
  sort(all(num));
  
  ll ans = 0;
  
  rep(i,k){
    ans += num[i];
  }
  
  cout << ans << endl;
  
  
}
                    

Measured memory_bytes: 3692
#include "bits/stdc++.h"
//#include "ext/pb_ds/assoc_container.hpp" 
//#include "ext/pb_ds/tree_policy.hpp" 
using namespace std;
//using namespace __gnu_pbds;
#define ff first
#define ss second
#define ld long double
#define ll long long int
#define ull unsigned ll
#define ins insert
#define pb emplace_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pii pair<int,int> 
#define pll pair<ll , ll>
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define fo(i,a,b) for(i=a; i<b; ++i)
#define foe(i,a,b) for(i=a; i<=b; ++i)
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define per1(i,n) for(i=n;i>=1;i--)
#define mod 1000000007
#define pi 3.141592653589793238460
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0)
//#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif


int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll t, i, j;
    t=1;
    while(t--){
        ll n, k;
        string s;
         cin>>s;
         s = s+"P";
         vi v;
         for(i=0; i<3; i++){
         	ll cnt=0;
         	if(s[i] == 'R'){
         		cnt++;
         		while(s[i+1] == 'R' && i<3){
         			i++;cnt++;
         		}
         		v.pb(cnt);
         	}
         }
         if(sz(v)==0) cout<<0<<'\n';
         else cout<<*max_element(all(v))<<'\n';

    }
    return 0;
}







Measured memory_bytes: 3636
use std::io::BufRead;

pub struct StdinReader<R: BufRead> {
    pub buf_reader: R,
    pub buf: String,
}
impl<R: BufRead> StdinReader<R> {
    pub fn new(r: R) -> Self {
        StdinReader {
            buf_reader: r,
            buf: String::with_capacity(10000),
        }
    }
}

#[macro_export]
macro_rules! input {
    ($reader : expr, $t : ty) => { // one variable
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().parse().unwrap(); 
                reader.buf.clear();
                tmp_var
            },
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty) => { // 2 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0], tmp_var[1])
            }
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty, $t2 : ty) => { // 3 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0], tmp_var[1], tmp_var[2])
            }
        }
    };
    ($reader : expr, $t : ty; $size : expr) => { // Vector
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                tmp_var
            }
        }
    };
}

fn main() {
    let handle = std::io::stdin();
    let mut r = StdinReader::new(handle.lock());

    let (n, w) = input!(r, usize, usize);

    let mut vs: Vec<usize> = Vec::with_capacity(n+1);  
    let mut ws: Vec<usize> = Vec::with_capacity(n+1); 
    vs.push(0);
    ws.push(0);

    for _ in 0..n {
        let (vv, ww) = input!(r, usize, usize);
        vs.push(vv);
        ws.push(ww);
    }
    let mut dp: Vec<Vec<usize>> = vec![vec![0; w+1]; n+1];
    for i in 1..n+1 {
        for j in 0..w+1 {
            if j < ws[i] { dp[i][j] = dp[i-1][j]; }
            else {
                use std::cmp::max;
                dp[i][j] = max(dp[i-1][j-ws[i]] + vs[i], dp[i-1][j]);
            }
        }
    }
    println!("{}", dp[n][w]);
}



Measured memory_bytes: 13112
//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int x;
    cin >> x;
    Yes(x >= 30);
}


Measured memory_bytes: 3632
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n"
#define X first
#define Y second
#define pii pair<int,int>
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)

const int maxn=1e6+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

ll poww(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));}
long long n,arr[100001],k,fact[100001],inv[100001],ans;
ll powww(ll a, ll b){ll rez=1;while(b){if(b%2==1)rez=(rez*a)%mod;a=(a*a)%mod;b/=2;}return rez;}
ll combi(ll a,ll b)
{
    if(a<b)
        return 0;
    ll cp=fact[a];
    cp=(cp*inv[b])%mod;
    cp=(cp*inv[a-b])%mod;
    return cp;
}
int main()
{
    migmig;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
    	cin>>arr[i];
	}
        
    sort(arr+1,arr+n+1);
    
    fact[0]=1;
    inv[0]=powww(1,mod-2);
    for(int i=1;i<=100000;i++)
        {
            fact[i]=(fact[i-1]*i)%mod;
            inv[i]=(powww(fact[i] , mod-2))%mod;
        }
    for(int i=1;i<=n;i++)
    {
        ans=(ans+(combi(i-1,k-1)*arr[i])%mod)%mod;
        ans=(ans-(combi(n-i,k-1)*arr[i])%mod)%mod;
        if(ans<0)
            ans+=mod;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   string s;
   cin >> s;
   for (int i = 0; i < (int)s.size(); i++) {
      if (i % 2 == 0) cout << s[i];
   }
   cout << endl;
   return 0;
}


Measured memory_bytes: 512
#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; cin>>n;
	vector<int> v(n);
	rep(i,n) cin>>v[i];
	int mx=0;
	ll sum=0;
	rep(i,n){
		mx=max(v[i],mx);
		sum+=mx-v[i];
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 4040
# https://qiita.com/snow67675476/items/e87ddb9285e27ea555f8

def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])

  if temp!=1:
    arr.append([temp, 1])

  if arr==[]:
    arr.append([n, 1])

  return arr

def resolve():
  N = int(input())
  prime_factors = factorization(N)
  tri_dict = {
    1 :  1,
    2 :  1,
    3 :  2,
    4 :  2,
    5 :  2,
    6 :  3,
    7 :  3,
    8 :  3,
    9 :  3,
    10 :  4,
    11 :  4,
    12 :  4,
    13 :  4,
    14 :  4,
    15 :  5,
    16 :  5,
    17 :  5,
    18 :  5,
    19 :  5,
    20 :  5,
    21 :  6,
    22 :  6,
    23 :  6,
    24 :  6,
    25 :  6,
    26 :  6,
    27 :  6,
    28 :  7,
    29 :  7,
    30 :  7,
    31 :  7,
    32 :  7,
    33 :  7,
    34 :  7,
    35 :  7,
    36 :  8,
    37 :  8,
    38 :  8,
    39 :  8,
    40 :  8,
    41 :  8,
    42 :  8,
    43 :  8,
    44 :  8,
    45 :  9,
    46 :  9,
    47 :  9,
    48 :  9,
    49 :  9,
    50 :  9,
    51 :  9,
    52 :  9,
    53 :  9,
    54 :  9,
    55 :  9,
    56 :  9,
    57 :  9,
    58 :  9,
    59 :  9
  }
  result = 0

  for prime_factor in prime_factors:
    if prime_factor[0] > 1:
      result += tri_dict[prime_factor[1]]

  print(result)


if __name__ == "__main__":
    resolve()

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

using namespace std; //stdの○○って言わなくていい

class Dice //クラスのメンバの宣言はデフォルトでprivate
{
    int top;    //1
    int front;  //2
    int right;  //3
    int left;   //4
    int back;   //5
    int bottom; //6
public:
    void diceroll(char dir);
    Dice(int top, int front, int right, int left, int back, int bottom);
    void place_front(int q2);
    void if_front(int q1);
    void place_top(int q1);
    int show_right();
};

void Dice ::diceroll(char dir)
{
    while (dir)
    {
        int tmp;
        switch (dir)
        {
        case 'E':
        {
            tmp = top;
            top = left;
            left = bottom;
            bottom = right;
            right = tmp;
            break;
        }
        case 'N':
        {
            tmp = top;
            top = front;
            front = bottom;
            bottom = back;
            back = tmp;
            break;
        }
        case 'S':
        {
            tmp = top;
            top = back;
            back = bottom;
            bottom = front;
            front = tmp;
            break;
        }
        case 'W':
        {
            tmp = top;
            top = right;
            right = bottom;
            bottom = left;
            left = tmp;
            break;
        }
        }
        dir++;
    }
}

Dice ::Dice(int top, int front, int right, int left, int back, int bottom)
{
    this->top = top;
    this->front = front;
    this->right = right;
    this->left = left;
    this->back = back;
    this->bottom = bottom;
}

void Dice ::place_front(int q2)
{
    char direction[] = "NENEN";
    int i = 0;
    while (top != q2)
    {
        diceroll(direction[i]);
        i++;
    }
    diceroll('S');
}

void Dice ::place_top(int q1)
{
    while (top != q1)
    {
        diceroll('W');
    }
}

void Dice ::if_front(int q1)
{
    if (top != q1)
    {
        place_top(q1);
    }
}

int Dice ::show_right()
{
    return right;
}

int main(void)
{
    int q, q1, q2;
    int top, front, right, left, back, bottom;
    cin >> top >> front >> right >> left >> back >> bottom;
    Dice d(top, front, right, left, back, bottom);
    cin >> q;

    for (int i = 0; i < q; i++)
    {
        cin >> q1 >> q2;
        d.place_front(q2);
        d.if_front(q1);
        cout << d.show_right() << endl;
    }
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int num[300001];
  int sosuu[300000];
  int cnt=1;
  for(int i=1;i<=300000;i++){
    if(i%7==1 || i%7==6) num[i]=1;
  }
  sosuu[0]=6;
  for(int i=8;i<=300000;i++){
    if(num[i]==1){
      for(int j=0;j<cnt;j++){
	if(i%sosuu[j]==0) break;
	else if(j==cnt-1 || sosuu[j]>sqrt(i)){
	  sosuu[cnt]=i;
	  cnt++;
	  break;
	}
      }
    }
  }
  while(1){
    cin>>n;
    if(n==1) break;
    cout<<n<<":";
    for(int i=0;i<cnt;i++){
      if(n%sosuu[i]==0) cout<<" "<<sosuu[i];
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 4364
A,B,C,X,Y = map(int,input().split())

ans = A*X+B*Y
for i in range(max(X,Y)+1): #iはABピザの枚数
    a = max(X - i,0)
    b = max(Y - i,0)
    c = 2*i
    sum = A*a + B*b + C*c
    # print(a,b,c,sum)
    if sum < ans:
        ans = sum
print(ans)


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

int len;
char a[200101];
long long num[28];
bool vis[200101];
long long ans;

int main(){
	scanf("%s",a);
	len=strlen(a);
	for(long long i=1;i<=len;++i) ans+=i;
	int x;
	for(int i=0;i<len;++i)
	{
		x=a[i]-'a';
		num[x]++;
	}
	for(long long i=0;i<26;++i)
	  ans-=num[i]*(num[i]-1)/2;
	cout<<ans-len+1;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    int i=0,j=0;
    string s;cin>>s;
    while(true){
        if(s[i]=='A')break;
        i++;
    }
    reverse(s.begin(), s.end());
    while(true){
        if(s[j]=='Z')break;
        j++;
    }
    cout<<s.length()-i-j<<endl;
}

Measured memory_bytes: 640
//shivamkr21
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x;
	cin>>n>>x;
	int ar[n];
	for(int i=0;i<n;i++)
	{
		cin>>ar[i];
		if(i==0)
			continue;
		else
			ar[i]=ar[i]+ar[i-1];
	}
	int p=1;
	for(int i=0;i<n;i++)
	{
		if(ar[i]<=x)
		{
			p++;
		}
		else
		{
			break;
		}
	}
	cout<<p;
	return 0;
}

Measured memory_bytes: 256