akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  string S[H];
  for(int i=0;i<H;i++) cin>>S[i];
  int A[H+2][W+2]={0};
  for(int h=1;h<H+1;h++){
    for(int w=1;w<W+1;w++){
      if(S[h-1][w-1]=='#'){
        A[h-1][w-1]++, A[h-1][w]++, A[h-1][w+1]++;
        A[h][w-1]++, A[h][w]=-10, A[h][w+1]++;
        A[h+1][w-1]++, A[h+1][w]++, A[h+1][w+1]++;
      }
    }
  }
  for(int h=1;h<H+1;h++){
    for(int w=1;w<W+1;w++){
      if(A[h][w]<0) cout<<"#";
      else cout<<A[h][w];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){


	int d,n;
	cin>>d>>n;
	
	if(d<=8 && n<=8){
	cout<<"Yay!"<<endl;
	}else if(d*2>n || n*2>d){
		cout<<":("<<endl;
	}
	
	
return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);

int main () {
  int n = in();
  vi a(n);
  vi b(n);
  vi c(n-1);
  rep(i,n) {
    cin >> a[i];
    a[i]--;
  }
  rep(i,n) cin >> b[i];
  rep(i,n-1) cin >> c[i];
  
  int ans = 0;
  rep(i,n) {
    ans += b[a[i]];
    if (i > 0 && a[i] == a[i-1] + 1) ans += c[a[i-1]];
  }

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

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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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

const int N = 2e5 + 5;

int n, L[N], R[N], A[N];
ll SEG[N << 2], LAZY[N << 2], DP[N]; 
vector<int> QL[N], QR[N];

void Apply(int id, ll x) { SEG[id] += x, LAZY[id] += x; }
void Shift(int id) {
	if (LAZY[id] == 0) return;
	Apply(id << 1, LAZY[id]);
	Apply(id << 1 | 1, LAZY[id]);
	LAZY[id] = 0;
}
void Update(int l, int r, ll x, int id = 1, int s = 0, int e = n + 1) {
	if (l >= e || s >= r) { return; }
	if (l <= s && e <= r) { Apply(id, x); return; }
	Shift(id);
	int md = (s + e) >> 1;
	Update(l, r, x, id << 1, s, md);
	Update(l, r, x, id << 1 | 1, md, e);
	SEG[id] = max(SEG[id << 1], SEG[id << 1 | 1]);
}
ll Get(int l, int r, int id = 1, int s = 0, int e = n + 1) {
	if (l >= e || s >= r) return 0;
	if (l <= s && e <= r) return SEG[id];
	Shift(id);
	int md = (s + e) >> 1;
	return max(Get(l, r, id << 1, s, md), Get(l, r, id << 1 | 1, md, e));
}

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int m; cin >> n >> m;
	for (int i = 0; i < m; i++) cin >> L[i] >> R[i] >> A[i], QL[L[i]].push_back(i), QR[R[i]].push_back(i);
	ll open = 0;
	for (int i = 1; i <= n; i++) {
		for (int j : QL[i]) open += A[j];
		DP[i] = open + Get(0, i);
		Update(i, i + 1, DP[i] - open);
		for (int j : QR[i]) Update(L[j], i + 1, A[j]), open -= A[j];
	}
	ll mx = 0;
	for (int i = 1; i <= n; i++) mx = max(mx, DP[i]);
	cout << mx << endl;

	return 0;
}


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

#define FILE_IN freopen("kotlin.in", "r", stdin);
#define FILE_OUT freopen("kotlin.out", "w", stdout);

#define fr(i,n) for(int i=0;i<n;i++)
#define frr(i,a,b) for(int i =a;i<=b;i++)
// for(auto it : g[i].nb)

typedef long long ll;

#define pb push_back

#define fi first
#define se second
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const long double PI = acos(-1.0l);
const ll MOD = 1e9+7;

//LLONG_MAX
//-DBL_MAX
//__builtin_popcountll(ll x) - __builtin_popcount(int x)

bool debug = 1;
#define printa(a) cout << #a << " = " << (a) << endl
#define prin(a) if(debug) cout << #a << " = " << (a) << endl
#define soprin(a) if(debug) cout << (a)
#define ppal(a)  if(debug) cout << #a << endl
#define prinsep if(debug) cout << "------" << endl
#define cendl if(debug) cout << endl
#define prinpar(p) if(debug) cout << #p << ".fi=" << (p).fi << " " << #p << ".se=" << (p).se << endl
#define print(tup) if(debug) cout << #tup << " = {" << get(tup,0) << ", " << get(tup,1) << ", " << get(tup,2) << "}\n"
#define prinv(v) if(debug){ cout << #v << ":" << endl; for(auto it = (v).begin(); it!=(v).end();it++){ cout << *it << " ";} cout << endl;}

const int N = -1;

map<int,int> mp;

int main(){
	//FILE_IN FILE_OUT
	
	int n;
	cin >> n;
	
	frr(num,2,n){
		int aux = num;
		frr(divi,2,num){
			while(aux%divi==0){
				mp[divi]++;
				aux/=divi;
			}
	}
	}
	
	ll ans = 1;
	
	for(auto &it : mp){
		ans = (ans*(it.se+1))%MOD;
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    int v;
    for(int i=0; i<n; i++)cin>>a[i];
    for(int i=0; i<n; i++){
        cout<<a[i];
        if(i!=n-1)cout<<' ';
    }
    cout<<endl;
    
    for(int i=1; i<n; i++){
        v=a[i];
        int j=i-1;
        for(; j>=0 && v<a[j]; j--){
            a[j+1]=a[j];
           
        }
        a[j+1]=v;
        for(int i=0; i<n; i++){
            cout<<a[i];
            if(i!=n-1)cout<<' ';
        }
        cout<<endl;
    }
}



Measured memory_bytes: 3092
#include <iostream>
#include <complex>
#include <vector>
#include <string>
using namespace std;

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

int main(){
	int n, m, xi, yi, a;
	char c, f[256];
	f['N'] = 0;
	f['S'] = 1;
	f['E'] = 2;
	f['W'] = 3;
	
	while( cin >> n , n ){
		vector< complex<int> > vc;
		char field[21][21] = {0};
		int x = 10;
		int y = 10;
		
		for(int i=0 ; i < n ; i++ ){
			cin >> xi >> yi;
			field[yi][xi] = 1;
		}
		cin >> m;
		for(int i=0 ; i < m ; i++ ){
			cin >> c >> a;
			for( ; a-- ; ){
				x += dx[ f[c] ];
				y += dy[ f[c] ];
				if( field[y][x] == 1 ){
					n--;
					field[y][x] = 0;
				}
			}
		}
		cout << ( ( n == 0 )? "Yes" : "No" ) << endl;
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#define MAX (3)
int main(void) {                    /*3回スキャンして、5が2つ、7が1つの時YES*/
    int array[2];
    int i;
    int a = 0;
    int b = 0;

    for (i = 0; i < MAX; i++) {     /*MAX=3*/
        scanf("%d", &array[i]);     /*配列の時はアンパサンドを付ける*/

        switch (array[i]) {
        case 5:
            a++;
            break;
        case 7:
            b++;
            break;
        default:
            break;
        }
    }

    if ((a == 2) && (b == 1)) {
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }
}

Measured memory_bytes: 128
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	vector<vector<int>> tb(n);
	vector<int> p(m);
	vector<int> y(m);
	for (int i = 0; i < m; i++) {
		int a,b; cin >> a >> b;
		a--; b--;
		p[i] = a;
		y[i] = b;

		tb[a].push_back(b);
	}

	for (int i = 0; i < n; i++) {
		sort(tb[i].begin(), tb[i].end());
	}

	for (int i = 0; i < m; i++) {
		cout << setfill('0') << setw(6) << p[i]+1;
		auto itr = lower_bound(tb[p[i]].begin(), tb[p[i]].end(), y[i]);

		int rank = itr - tb[p[i]].begin()+1;

		cout << setfill('0') << setw(6) << rank << endl;
	}

}

Measured memory_bytes: 7808
#include "bits/stdc++.h"
#define REP(i, m, n) for(long long i = m; i < n; ++i)
#define CO(n) cout << n << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

string S,T,U;
int A,B;

int main()
{
    ios::sync_with_stdio(false);
    cin >> S >> T >> A >> B >> U;
    if (U == S){
        cout << A-1 << ' ' << B << endl;
    }
    else {
        cout << A << ' ' << B-1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<iterator>
#include<algorithm>
#include<cstring>
#include<set>
#include<cstdlib>
#include<cmath>
using namespace std;
int main()
{
	string s;
	long long int i, j, k, m, n;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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

using namespace std;

#define ll long long;

const int N=1e6+5;

vector<int> v;

int n,ans,tc,q,m,a[N],k;

char s1[N],s2[N];

int main(){
    scanf("%s%s",s1,s2);
    for(int i=0;s1[i];i++)
        ans+=s1[i]==s2[i];
    printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define Rep(i,x) for(int i=head[x];i+1;i=nxt[i])
#define rep2(i,a,b) for(int i=(a);i<(b);i++)
#define ff first
#define ss second
using namespace std;
const int N=100005;
const long long inf=1e15;
typedef long long ll;
//------------------------------------------head---------------------------------------------------//
ll a[N];
int op[N];
ll f[N][2];
inline void Updmax(ll &x,ll y){x=(x<=y)?y:x;}
int main()
{
	int m=0;//ll tot=0;
	ll tot=0,ans=0,pos=0,ma=0;
	int n;scanf("%d",&n);scanf("%d",&a[1]);rep(i,2,n)
	{
		char s[4];int x;scanf("%s%d",s+1,&x);
		op[i-1]=(s[1]=='+');a[i]=x;
	}
	ans=a[1];
	rep(i,1,n-1){if(op[i])ans+=a[i+1];else ans-=a[i+1];}
	//printf("%lld\n",ans);
	per(i,n-1,1)
	{
		if(op[i]==1) tot+=2ll*a[i+1];
		else
		{
			ma=max(ma,ans+pos-tot);
			pos+=2ll*a[i+1];
			tot=0;
		}
	}
	printf("%lld\n",max(ans,ma));
	return 0;
	// 0 min
	// 1 max
	//n=m;//f[1][0][1]=f[1][0][0]=a[1];
	/*rep(i,0,n)rep(j,0,1)f[i][j]=-inf;f[1][0]=a[1];
	//rep(i,1,n)printf("%d ",a[i]);
	op[0]=-1;
	op[n]=1;a[++n]=0;
	rep(i,1,n-1)
	{
		if(op[i]==1)
		{
			//printf("Case owo:%d\n",i);
			Updmax(f[i+1][0],f[i][0]-a[i+1]);
			Updmax(f[i+1][1],f[i][0]-a[i+1]);
			Updmax(f[i+1][1],f[i][1]+a[i+1]);
			Updmax(f[i+1][0],f[i][1]+a[i+1]);
			
		}
		else
		{
			Updmax(f[i+2][0],f[i][0]+(a[i+1]-a[i+2]));
			Updmax(f[i+2][1],f[i][0]+(a[i+1]-a[i+2]));
			Updmax(f[i+2][1],f[i][1]-(a[i+1]-a[i+2]));
			Updmax(f[i+2][0],f[i][1]-(a[i+1]-a[i+2]));
		}
	}*/
	//printf("%lld\n",max(f[n][0],f[n][1]));
	return 0;
}

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

int main(){
	int n,k,cnt=0;
	cin>>n>>k;
	int x;
	for(int i=0; i<n; i++){
		cin>>x;
		if((k+1)/2>x)cnt+=(x*2);
		else cnt+=((k-x)*2);
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int mod=998244353;
const int MAXN=10005;
int pow_mod(int a,int b)
{
	int ret=1;
	for(;b;b>>=1,a=1LL*a*a%mod)if(b&1)ret=1LL*ret*a%mod;
	return ret;
}
int pre[2*MAXN],inv[2*MAXN];
int C(int n,int m){return 1LL*pre[n]*inv[m]%mod*inv[n-m]%mod;}
int a[MAXN],b[MAXN],c[MAXN],ln1,ln2,ln3;
char ch1[MAXN],ch2[MAXN];
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int f[MAXN][MAXN];
int main()
{
	pre[0]=1;for(int i=1;i<2*MAXN;i++)pre[i]=1LL*pre[i-1]*i%mod;
	inv[2*MAXN-1]=pow_mod(pre[2*MAXN-1],mod-2);
	for(int i=2*MAXN-2;i>=0;i--)inv[i]=1LL*inv[i+1]*(i+1)%mod;
	scanf("%s",ch1+1);scanf("%s",ch2+1);int len=strlen(ch1+1);
	int ln1=0,ln2=0,ln3=0;
	for(int i=1;i<=len;i++)if(ch1[i]=='1'||ch2[i]=='1')
	{
		if(ch1[i]=='1'&&ch2[i]=='1')++ln1;
		else if(ch1[i]=='1')++ln2;
		else ++ln3;
	}
	f[0][0]=1;
	for(int j=1;j<=ln2;j++)f[0][j]=1LL*f[0][j-1]*(ln2-j+1)%mod*(ln2-j+1)%mod;
	for(int i=1;i<=ln1;i++)for(int j=1;j<=ln2;j++)
		f[i][j]=(1LL*f[i-1][j]*(ln1-i+1)*j%mod+1LL*f[i][j-1]*(ln2-j+1)%mod*(ln2-j+1)%mod)%mod;
	int ans=0;
	for(int i=0;i<=ln1;i++)
		ad(ans,1LL*f[i][ln2]*pre[ln1-i]%mod*pre[ln1-i]%mod*C(ln1-i+(ln2+i),ln2+i)%mod);
	pr2(ans);
	return 0;
}

Measured memory_bytes: 389632
#include<bits/stdc++.h>
#define INF 1000000009
#define INFL 1000000000000000018
#define mod 10007
#define pb push_back
#define MAXN 505
#define ff first
#define sf second.first
#define ss second.second
using namespace std;
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef vector<int> VE;
typedef map<int, int> MAP;
char fid[200][200];
int h, w, cnt;
bool  a[200], b[200], flag;
signed main()
{
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> fid[i][j];
            if(fid[i][j] == '.'){
                cnt++;
            }
        }
        if(cnt == w){
            a[i] = true;
        }
        cnt = 0;
    }
    cnt = 0;
    for(int i = 0; i < w; i++){
        for(int j = 0; j < h; j++){
            if(fid[j][i] == '.'){
                cnt++;
            }
        }
        if(cnt == h){
            b[i] = true;
        }
        cnt = 0;
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(!a[i] && !b[j]){
                cout << fid[i][j];
                flag = true;
            }
        }
        if(flag)cout << endl;
        flag = false;
    }

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

/**
 * 增税
 */
public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int a = sc.nextInt();
        int b = sc.nextInt();

        int ans = -1;
        for (int i =0; i< 10009; i++){
            if((int) (i * 0.08) == a ){
                if((int) (i * 0.1) == b ){
                    ans = i;
                    break;
                }
            }
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 23764
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let s: Vec<char> = read::<String>().chars().collect();
    let t: Vec<char> = read::<String>().chars().collect();
    let mut ret: Vec<String> = Vec::new();

    for i in 0..(s.len()) {
        if s.len() - i < t.len() {
            continue;
        }
        let mut is_valid = true;
        for j in 0..(t.len()) {
            if s[i + j] != t[j] && s[i + j] != '?' {
                is_valid = false;
                break;
            }
        }

        if !is_valid {
            continue;
        }
        ret.push((0..(s.len())).map(|j| if i <= j && j < t.len() + i { t[j - i] } else if s[j] == '?'{ 'a' } else { s[j] }).collect());
    }
    ret.sort();

    if ret.len() == 0 {
        println!("UNRESTORABLE");
    } else {
        println!("{}", ret[0]);
    }
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> Type igcd(Type x,Type y){if(x==0||y==0)return (x>y)?x:y;return (y%x)?igcd(y%x,x):x;}
template<class Type> Type ilcm(Type x,Type y){return x/igcd(x,y)*y;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

struct UnionFind{
	std::vector<int> par;//xの親はpar[x]. もしx自身が親ならpar[x]<0で,-par[x]がその集合のサイズ.
	int cnt;			 //Number of group.
	
	UnionFind(int n):par(n,-1),cnt(n){}//Constructor.
	
	void reset(int n){par.assign(n,-1),cnt=n;}
	int root(int x){return (par[x]<0)?x:par[x]=root(par[x]);}//Recrusion.
	int size(int x){return -par[root(x)];}
	bool same(int x,int y){return root(x)==root(y);}
	bool unite(int x,int y){
		x=root(x), y=root(y);
		if(x==y) return false;//Do nothing.
		if(size(x)<size(y)) std::swap(x,y);//Merge technique.
		par[x]+=par[y];
		par[y]=x;
		cnt--;
		return true;
	}
};

int main(){
	int n;
	cin>>n;
	
	vi x(n),y(n);
	REP(i,n) cin>>x[i]>>y[i];
	
	vector<pii> px(n),py(n);
	REP(i,n) px[i]=pii(x[i],i);
	REP(i,n) py[i]=pii(y[i],i);
	sort(ALL(px));
	sort(ALL(py));
	
	priority_queue<tuple<int,int,int>,vector<tuple<int,int,int> >,greater<tuple<int,int,int> > > que;//tuple(cost,a,b)
	REP(i,n-1) que.push(make_tuple(px[i+1].first-px[i].first,px[i].second,px[i+1].second));
	REP(i,n-1) que.push(make_tuple(py[i+1].first-py[i].first,py[i].second,py[i+1].second));
	
	UnionFind uf(n);
	llong sum=0;
	while(!que.empty()){
		tuple<int,int,int> tmp=que.top();
		que.pop();
		
		if(uf.same(get<1>(tmp),get<2>(tmp))){}
		else{
			uf.unite(get<1>(tmp),get<2>(tmp));
			sum+=get<0>(tmp);
		}
	}
	
	cout<<sum<<endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int S=0, T=0;
  
  for (int i=0; i<N; i++)
    cin >> a.at(i);
  
  for (int i=0; i<31; i++) {
    for (int j=0; j<N; j++) {
      if (a.at(j)%2==0) {
        a.at(j)=a.at(j)/2;
        T++;
        if (T%N==0)
          S++;
      }
      else
        break;
    }
  }
  cout << S << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
r,s,p = map(int,input().split())
l = input()
ans =0
for i in range(k):
    #print(i)
    if l[i] =="r":
        ans += p
    elif l[i] =="s":
        ans += r
    elif l[i] =="p":
        ans += s
        
        
daida=[]
for o in range(len(l)):
    daida.append(l[o])
for j in range(k,n):
    if l[j]== l[j-k]:
        jj=["r","s","p"]
        jj.remove(l[j])
        if l[j] == daida[j-k]:
            daida[j]=jj[0]
            continue
        else:
            if l[j] =="r":
                ans += p
            elif l[j] =="s":
                ans += r
            elif l[j] =="p":
                ans += s
            continue
            
    else:
        if l[j] =="r":
            ans += p
        elif l[j] =="s":
            ans += r
        elif l[j] =="p":
            ans += s
print(ans)
        



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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

string s;
string s1="abcdefgqrstvwxz";

bool is_left(char c){
	rep(i,s1.length()){
		if(c==s1[i])return true;
	}
	return false;
}

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>s;
		if(s[0]=='#')break;
		int flag=-1;
		int res=0;
		rep(i,s.length()){
			if((flag==0&&is_left(s[i]))||(flag==1&&!is_left(s[i]))){
				flag=1-flag;
				res++;
			}else if(flag==-1){
				if(is_left(s[i]))flag=1;
				else flag=0;
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 3132
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>

using namespace std;

int main(){
	int n;
	cin>>n;
	double EPS=0.000000001;
	vector<pair<int64_t,int64_t> > points;
	points.reserve(n);
	for(int64_t i=0;i<n;i++){
		int64_t x,y;
		cin>>x>>y;
		points.push_back(make_pair(x,y));
	}
	double total=0;
	for(int i=0;i<n;i++){
		double min_num;
		double max_num;
		bool isFirst=true;
		bool noans=false;
		for(int j=0;j<n;j++){
			if(i==j){
				continue;
			}
			double xdiff=points[j].first-points[i].first;
			double ydiff=points[j].second-points[i].second;
			double min_angle=atan2(xdiff,-1*ydiff);
			double max_angle=min_angle+M_PI;
			//cout<<"i1="<<i<<"i2="<<j<<"min_angle="<<min_angle<<"max_angle="<<max_angle<<endl;
			if(isFirst){
				min_num=min_angle;
				max_num=max_angle;
				isFirst=false;
			}else{
				double temp_min=max(min_angle,min_num);
				double temp_max=min(max_angle,max_num);
				if((temp_max-temp_min)<EPS){
					temp_min=max(min_angle,min_num+2*M_PI)-2*M_PI;
					temp_max=min(max_angle,max_num+2*M_PI)-2*M_PI;
					if((temp_max-temp_min)<EPS){
						temp_min=max(min_angle+2*M_PI,min_num)-2*M_PI;
						temp_max=min(max_angle+2*M_PI,max_num)-2*M_PI;
						if((temp_max-temp_min)<EPS){
							noans=true;
							break;
						}
					}
				}
				min_num=temp_min;
				max_num=temp_max;
			}

		}
		if(noans){
			cout<<0<<endl;
		}else{
			double p=0;
			if(max_num>=min_num){
				p=(max_num-min_num)/(2*M_PI);
			}else{
				p=(2*M_PI+max_num-min_num)/(2*M_PI);
			}
			total+=p;
			cout<<fixed<<setprecision(10)<<p<<endl;
		}
	}
	return 0;

}

Measured memory_bytes: 256
#![allow(unused_imports)]
#[macro_use]
mod reader {
    // mod calc;

    // use calc::*;


    #![allow(dead_code)]
    use std;
    macro_rules! read_line((  ) => {
                           {
                           let mut input = String :: new (  ) ; std :: io ::
                           stdin (  ) . read_line ( & mut input ) . unwrap (
                           ) ; input } } ;);
    pub fn read_to_vec<T: std::str::FromStr>() -> Vec<T> {
        read_line!().split_whitespace().map(|e|
                                                e.parse().ok().unwrap()).collect()
    }
    pub fn read_trim() -> String { read_line!().trim().to_owned() }
}
#[macro_use]
mod misc {
    #![allow(dead_code)]
    use std;
    #[macro_export]
    macro_rules! bind_from_vec((
                               $ ( $ variable : ident ) , + = $ vector : expr
                               ) => {
                               let mut v = $ vector . clone (  ) . into_iter (
                                ) ; $ (
                               let $ variable = v . next (  ) . unwrap (  ) ;
                               ) + } ;);
}
use reader::*;
use misc::*;
fn main() {
    bind_from_vec!(_n , k = read_to_vec :: < usize > (  ));
    let input = read_trim();
    let former = &input[..k - 1];
    let mid = &input[k - 1..k].to_lowercase();
    let latter = &input[k..];
    println!("{}{}{}" , former , mid , latter);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

//cout << fixed << setprecision(10);

int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll lms=c*d/euclidean_gcd(c,d);

    ll ans=0;
    ans=(b-a)+1-b/c-b/d+b/lms+(a-1)/c+(a-1)/d-(a-1)/lms;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import statistics

N = int(input())
A = list(map(int, input().split()))
B = []
li = []
for i in range(N):
  B.append(A[i] - (i+1))
b = int(statistics.median(B))
for i in range(N):
  li.append(abs(A[i] - (b+i+1)))
print(sum(li))

Measured memory_bytes: 29648
use std::io::*;
const MOD: usize = 1_000_000_007;

fn inv(mut x: usize) -> usize {
    let mut res = 1;
    let mut e = MOD - 2;
    while e > 0 {
        if e & 1 == 1 {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        e >>= 1;
    }
    res
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    // 区間がn-1個。
    let mut fac = vec![0; n + 1];
    fac[0] = 1;
    fac[1] = 1;
    for i in 2..n {
        fac[i] = fac[i - 1] * i % MOD;
    }

    let mut b = Vec::new();
    for i in 0..n - 1 {
        b.push(a[i + 1] - a[i]);
    }

    let mut ans = 0;
    let mut now = 0;
    for i in 0..n - 1 {
        now = (now + inv(i + 1)) % MOD;
        ans = (ans + now * b[i] % MOD) % MOD;
    }
    println!("{}", ans * fac[n - 1] % MOD);
}


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


int main()
{
	string s;
	string p;
	cin>>s;
	cin>>p;
	for(int i = 0; i < s.length(); i++){
		for(int j = 0; j < p.length(); j++){
			if(s[ (i + j) % s.length()] == p[j]){
				if(j==(p.length() -1)){
				cout<<"Yes"<<endl;
				return 0;
			}
			}else{
				break;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3164
n,m,x = map(int, input().split())

price_list = []
skillup = []
for i in range(n):
    book = list(map(int,input().split()))
    price_list.append(book[0])
    skill = []
    for j in range(m):
        skill.append(book[j+1])
    skillup.append(skill)

min_price = 10**10
for i in range(2**n):
    price = 0
    skill = [0] * m
    index = 0

    bits = "0" * (n - (len(bin(i))-2)) + str(bin(i))[2:len(bin(i))] 

    for bit in bits:
        if bit == "1":
            price += price_list[index]
            for s in range(m):
                skill[s] += skillup[index][s]
        index+=1
    check = [0] * m
    for s in range(m):
        if skill[s] >= x:
            check[s] = 1
    passed = 1
    for s in range(m):
        if check[s] == 0:
            passed = 0
    if passed:
        if price < min_price:
            min_price = price

if min_price == 10**10:
    print(-1)
else:
    print(min_price)


Measured memory_bytes: 9148
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
using namespace std;

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

//変数
int N,M;
vector<string> s,t;

//解法
void solve() {
	int ans = 0;
	rep(i, N) {

		int sum = 0;
		rep(j, N) {
			if (s[i] == s[j]) sum++;
		}
		rep(j, M) {
			if (s[i] == t[j]) sum--;
		}

		ans = max(ans, sum);

	}
	cout << ans;

	return;
}

int main() {
	//入力
	cin >> N;
	s.resize(N);
	rep(i, N) cin >> s[i];
	cin >> M;
	t.resize(M);
	rep(i, M) cin >> t[i];
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import heapq
import bisect
import copy
import math
from collections import defaultdict

def warshall_floyd(d, N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i * N +j] = min(d[i * N +j], d[i * N + k] + d[k * N + j])
    return d

MOD = 10**9 + 7

def cone(n):
    if n == 0:
        return 0
    else:
        return n

def ctwo(n):
    if n <= 1:
        return 0
    else:
        return(n * (n-1)) // 2

def ketaall(keta, m):
    if m == 0:
        return 1
    if m == 1:
        return keta * 9
    else:
        return ctwo(keta) * 81


def main():
    n = getN()
    n = str(n)
    keta = len(n) - 1
    m = getN()
    if m == 1:
        res = 0
        print(int(int(n[0]) + 9 * keta))
        return

    res = (int(n[0]) - 1)*  ketaall(keta, m -1)
    # print(res, n[0], n, keta)
    for k in range(int(keta)):
        res += 9 * ketaall(k, m-1)
        # print(res)

    m -= 1
    # print("====================")
    for s in n[1:]:
        if s == "0":
            pass
        else:
            res += ketaall(keta - 1, m)
            # print(res)
            res += (int(s) - 1) * ketaall(keta-1, m-1)
            # print(res)
            m -= 1

        keta -= 1
        # print(res, m)
        if m == 0:
            res += 1
            break

    print(res)


if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

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

int main()
{
    ll N;
    cin >> N;
    ll crack = 0;
    ll index = 0;
    bool count(false);
    for (int i = 0; i < N; ++i)
    {
        ll temp;
        cin >> temp;

        if (temp == 1)
        {
            if (count)
            {
                crack = i;
                index = 2;
            }
            else
            {
                count = true;
                index = 2;
            }
        }
        else if (temp != index)
        {
            ++crack;
        }
        else
        {
            ++index;
        }
    }
    if (crack == N)
    {
        crack = -1;
    }
    cout << crack << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
const int inf = 1e9;

int G[15][maxn];
int pre[15][maxn];
int check[15];
int cnt[15];

int n, m, k;

int solve(int x){
	memset(check, 0, sizeof check);
	int ans = 0;
	cnt[++x] = n;
	for(int i = 1 ; i <= m ; i++){
		bool ok = 1;
		for(int j = 1 ; j <= x ; j++){
			if(pre[cnt[j]][i] - pre[cnt[j - 1]][i] > k)return inf;
			if(check[j] + pre[cnt[j]][i] - pre[cnt[j - 1]][i] > k)ok = 0;
		}
		for(int j = 1 ; j <= x ; j++){
			if(ok)check[j] += pre[cnt[j]][i] - pre[cnt[j - 1]][i];
			else check[j] = pre[cnt[j]][i] - pre[cnt[j - 1]][i];
		}
		if(!ok)ans++;
	}
	return ans;
}

int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i = 1 ; i <= n ; i++)
		for(int j = 1 ; j <= m ; j++)
			scanf("%1d",&G[i][j]);
	for(int i = 1 ; i <= m ; i++)
		for(int j = 1 ; j <= n ; j++)
			pre[j][i] = pre[j - 1][i] + G[j][i];


	int ans = inf;
	int now, p, j;
	for(int i = 0 ; i < (1 << 9) ; i++){
		now = i; p = 0; j = 0;
		while(now){
			j++;
			if(now & 1)cnt[++p] = j;
			now >>= 1;
		}
		ans = min(ans, p + solve(p));
	}
	printf("%d\n",ans);
}

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

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

  int n, m;
  cin >> n >> m;

  int h[n];
  for (int i = 0; i < n; ++i) cin >> h[i];

  int mx[n];
  memset(mx, 0, sizeof(mx));

  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;

    mx[a] = max(mx[a], h[b]);
    mx[b] = max(mx[b], h[a]);
  }

  int ans = 0;

  for (int i = 0; i < n; ++i) if (h[i] > mx[i]) ++ans;

  cout << ans << '\n';

  return (0);
}


Measured memory_bytes: 4412
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n,x,y = [int(i) for i in readline().split()]

ans = [0] * n

for a in range(1, n+1):
    for b in range(a+1, n+1):
        d = b - a
        d2 = abs(x-a) + abs(y-b) + 1
        d = d if d < d2 else d2
        ans[d] += 1

for i in range(1, n):
    print(ans[i])

Measured memory_bytes: 3444
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static int getInt(){
		return Integer.parseInt(s.next());
	}
	static IntStream REPS(int r){
		return IntStream.range(0,r);
	}
	static IntStream REPS(int l,int r){
		return IntStream.rangeClosed(l,r);
	}
	static IntStream INTS(int l){
		return REPS(l).map(i->getInt());
	}
	public static void main(String[] __){
		int n=s.nextInt();
		int[] color=new int[9];
		for(int i=0;i<n;i++){
			int latte=getInt();
			if(latte<400)
				color[0]++;
			else if(latte<800)
				color[1]++;
			else if(latte<1200)
				color[2]++;
			else if(latte<1600)
				color[3]++;
			else if(latte<2000)
				color[4]++;
			else if(latte<2400)
				color[5]++;
			else if(latte<2800)
				color[6]++;
			else if(latte<3200)
				color[7]++;
			else
				color[8]++;
		}
		
		
		long v=Arrays.stream(color).limit(8).filter(i->i>0).count();
		System.out.printf("%d %d\n",
				Math.max(1,v),
				Math.max(1,v+color[8])
				);
	}
}


Measured memory_bytes: 27092
N = int(input())
nums = []

for i in range(4):
    tmp = N % 10
    nums.append(tmp)
    N = N // 10

nums = nums[::-1]

for i in range(8):
    ans = nums[0]
    
    judge = []
    
    for j in range(3):
        bitts = (i >> j) & 1
        if (bitts):
            ans += nums[j + 1]
            judge.append('+')
            
        else:
            ans -= nums[j + 1]
            judge.append('-')
    
    if (ans == 7):
        siki = ''
        
        for i in range(3):
            siki += str(nums[i])
            siki += judge[i]
        
        siki += (str(nums[3]) + '=7')
        
        print(siki)
        break

Measured memory_bytes: 9224
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long
map<char, int> m;
signed main() {
    int a,b,c,k;
    cin >> a >> b>>c >>k;
    if(k%2==0) cout << a-b << endl;
    else cout << b-a << endl;
  return 0;
}



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

#define int long long int

main()
{
    int n, a, b;
    std::cin >> n >> a >> b;

    if (n < a + b - 1 || n > a * b * 1LL)
    {
        std::cout << -1;
    }
    else
    {
        for (int i = a - 1; i >= 0; --i)
        {
            std::cout << n - i << " ";
        }

        n -= a;
        int temp = b;
        --b;
        for (int i = 1; i < temp; ++i)
        {
            int cur = n - b + 1;
            cur = std::min(cur, a);

            for (int j = cur - 1; j >= 0; --j)
            {
                std::cout << n - j << " ";
            }

            n -= cur;
            --b;
        }
    }
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; i++)
 
using ll = long long;
 
 
bool solve() {
    int N, M, C, S, G;
    int x[10001], y[10001], d[10001], c[10001];
    vector<int> com[20];
 
    cin >> N >> M >> C >> S >> G;
    S--; G--;
 
    if (N == 0) return false;
 
    for(int i=0; i<M; i++) {
        scanf("%d%d%d%d", x+i, y+i, d+i, c+i);
        x[i]--; y[i]--; c[i]--;
        com[c[i]].push_back(i);
    }
 
    int p[30];
    int q1[30][51], q2[30][51];
    int cost[30][20010] = {};
 
    for(int i=0; i<C; i++) {
        scanf("%d", p+i);
    }
 
    for(int i=0; i<C; i++) {
        q1[i][0] = 0;
        q1[i][p[i]] = 1e9;
        for(int j=1; j<p[i]; j++) {
            scanf("%d", q1[i] + j);
        }
        for(int j=0; j<p[i]; j++) {
            scanf("%d", q2[i] + j);
        }
     
        int t = 0, s = 0;
        cost[i][0] = 0;
 
        for (int j=0; j<20001; j++) {
            if(q1[i][t] == j) {
                s = q2[i][t];
                t++;
            }
 
            cost[i][j+1] = cost[i][j] + s;
        }
    }
 
    ll Dist[101][101];
 
    for(int i=0; i<N; i++) {
        for(int j=0; j<N; j++) {
            Dist[i][j] = 1e17 * (i != j);
        }
    }
 
    for(int r=0; r<C; r++) {
        int dist[101][101];
 
        for(int i=0; i<N; i++)
            for(int j=0;j<N;j++)
                dist[i][j] = (i != j) * 1e9;
         
        for(int i : com[r])
            dist[x[i]][y[i]] = dist[y[i]][x[i]] = min(dist[x[i]][y[i]], d[i]);
 
        for(int k=0; k<N; k++) {
            for (int i=0; i<N; i++) {
                for(int j=0; j<N; j++) {
                    dist[i][j] = min(dist[i][k] + dist[k][j], dist[i][j]);
                }
            }
        }
 
        for(int i=0; i<N; i++) {
            for(int j=0;j<N; j++) {
                if(dist[i][j] < 1e8) {
                    Dist[i][j] = min(Dist[i][j], (ll)cost[r][dist[i][j]]);
                }
            }
        }
    }
 
    for(int k=0; k<N; k++) {
        for(int i=0; i<N; i++) {
            for(int j=0; j<N; j++) {
                Dist[i][j] = min(Dist[i][j], Dist[i][k] + Dist[k][j]);
            }
        }
    }
 
    if (Dist[S][G] > 1e16)
        Dist[S][G] = -1;
 
    printf("%lld\n", Dist[S][G]);
    return true;
}
 
int main(){
    int t;
    while(solve());
    return 0;
}


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

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

const int INF = 1e9;

int n, m;
int a[1005], b[1005], c[1005][20];
vector<int> dp(5000, INF);

void solve() {
    dp[0] = 0;
    for (int i = 0; i < m; i++) {
        int now = 0;
        for (int j = 0; j < b[i]; j++) {
            now |= (1<<(c[i][j]-1));
        }
        for (int bits = 0; bits < (1<<n); bits++) {
            chmin(dp[bits | now], dp[bits] + a[i]);
        }
    }
    if (dp[(1<<n)-1] == INF) dp[(1<<n)-1] = -1;
    cout << dp[(1<<n)-1] << endl;
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        for (int j = 0; j < b[i]; j++) cin >> c[i][j];
    }
    solve();
}

Measured memory_bytes: 384
import java.util.Scanner;

class Main
{
	public static void main(String[] args)
	{
		Scanner stdIn=new Scanner(System.in);
		int w=stdIn.nextInt();
		int h=stdIn.nextInt();
		int x=stdIn.nextInt();
		int y=stdIn.nextInt();
		int r=stdIn.nextInt();

		if((x-r>=0) && (y-r>=0) && (x+r<=w) && (y+r<=h)){
                  System.out.println("Yes");
                 }
		
		 else{
                     System.out.println("No");
                     }
		
        }
}

Measured memory_bytes: 26240
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        int[] X = new int[N];
        for (int i = 0; i < N; i++) {
            X[i] = sc.nextInt();
        }

        int minCost = Integer.MAX_VALUE;
        for (int p = 0; p <= 100; p++) {

            int cost = 0;
            for (int i = 0; i < N; i++) {
                cost += (X[i] - p) * (X[i] - p);
            }

            minCost = Math.min(cost, minCost);
        }

        System.out.println(minCost);
    }
}


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

namespace AtCoder
{
    class Program
    { 
        static void Main(string[] args)
        {
            //[summary]B - Digital Gifts
            int n = int.Parse(Console.ReadLine());
            double sum = 0;

            for(int i = 0; i < n; i++)
            {
                sum += GetOtoshidama();
            }

            Console.WriteLine(sum);
        }

        static double GetOtoshidama()
        {
            string s = Console.ReadLine();
            var array = s.Split(' ');

            if (array[1] == "JPY")
            {
                return double.Parse(array[0]);
            }
            else
            {
                return double.Parse(array[0]) * 380000;
            }
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 1e12;
int BitCount(int64_t x) {
	x = (x & 0x5555555555555555) + (x >>  1 & 0x5555555555555555);
	x = (x & 0x3333333333333333) + (x >>  2 & 0x3333333333333333);
	x = (x & 0x0f0f0f0f0f0f0f0f) + (x >>  4 & 0x0f0f0f0f0f0f0f0f);
	x = (x & 0x00ff00ff00ff00ff) + (x >>  8 & 0x00ff00ff00ff00ff);
	x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff);
	x = (x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff);
	return (int)(x);
}
int main() {
	int N;
	cin >> N;
	int64_t F[1000];
	int64_t P[100][100];
	for(int i = 0; i < N; i++) {
		int64_t t;
		F[i] = 0;
		for(int j = 0; j < 10; j++) {
			cin >> t;
			F[i] |= t << j;
		}
	}
	for(int i = 0; i < N; i++) {
		for(int j = 0; j <= 10; j++) {
			cin >> P[i][j];
		}
	}
	int64_t ans = -INF;
	for(int i = 1; i < 1024; i++) {
		int64_t prof = 0;
		if(BitCount(i) == 0) continue;
		for(int j = 0; j < N; j++) {
			prof += P[j][BitCount(i & F[j])];
		}
		ans = max(prof, ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
import sys
def f(y,m,d):
    res = (y-1)//3*200+(y-1-(y-1)//3)*195
    if y%3 == 0:
        res += (m-1)*20+d
    else:
        res += (m-1)//2*19+(m-1-(m-1)//2)*20+d
    return res
    
M = 196471
n  = int(sys.stdin.readline())
for i in range(n):
    y,m,d = [int(x) for x in sys.stdin.readline().split()]
    print(M-f(y,m,d))



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

using namespace std;

int main(){
	int card[4][13] = { 0 },
		num,
		ans,
		n;
	string mark;

	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> mark >> num;

		//for (int i1 = 0; i < n; i++){
			if (mark == "S"){
				card[0][num - 1] = num;
			}

			if (mark == "H"){
				card[1][num - 1] = num;
			}

			if (mark == "C"){
				card[2][num - 1] = num;
			}

			if (mark == "D"){
				card[3][num - 1] = num;
			}

		//}

	}

	for (int i2 = 0; i2 < 13; i2++){
		if (0 == card[0][i2]){
			cout << "S " << i2 + 1 << endl;
		}
	}

	for (int i2 = 0; i2 < 13; i2++){
		if (0 == card[1][i2]){
			cout << "H " << i2 + 1 << endl;
		}
	}

	for (int i2 = 0; i2 < 13; i2++){
		if (0 == card[2][i2]){
			cout << "C " << i2 + 1 << endl;
		}
	}

	for (int i2 = 0; i2 < 13; i2++){
		if (0 == card[3][i2]){
			cout << "D " << i2 + 1 << endl;
		}
	}

	cin >> ans;

}


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

int main() {
    ios_base::sync_with_stdio(false);	
    cin.tie(0);	
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int x = (a + d - 1) / d;
	int y = (c + b - 1) / b;
	if (x >= y) cout << "Yes" << "\n";
	else cout << "No" << "\n";
	return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    double a = 3.1415926535897979323;
    double r;
    cin >> r;
    printf("%.10lf" ,r * a * 2);
}


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

class Main {
  public static void main(String[] args) {
    int N;
    Scanner sc = new Scanner(System.in);

    N = sc.nextInt();

    for (int i = 0; i < N; i++) {
      int a,b,c;

      a = sc.nextInt();
      b = sc.nextInt();
      c = sc.nextInt();

      if (a+b > c && a+c > b && b+c > a) {
        if (a*a+b*b == c*c || a*a+c*c==b*b || b*b+c*c==a*a) {
          System.out.println("YES");
        } else {
          System.out.println("NO");
        }
      } else {
        System.out.println("NO");
      }
    }
  }
}

Measured memory_bytes: 33048
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int nums[10];
  for(int i=0;i<10;i++){
    cin>>nums[i];
  }
  sort(nums,nums+10,greater<int>());
  for(int i=0;i<3;i++)
    cout<<nums[i]<<endl;
  return 0;
}

Measured memory_bytes: 1176