akhauriyash/Code-Regression huggingface dataset:
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n,l=NM()
a=[0]+L()
for i in range(1,n):
    if a[i]+a[i+1]>=l:
        print("Possible")
        for j in range(1,i):
            print(j)
        for j in range(n-1,i-1,-1):
            print(j)
        break
else:
    print("Impossible")

Measured memory_bytes: 14068
//default
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
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 int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  int N;
  cin >> N;
  rep(i,N){
    int A;
    cin >> A;
    if(A%2==0){
      if(A%3==0 || A%5==0);
      else{
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;

namespace AtCoder {
	class Program {
		public static void Main(string[] args) {
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

			long[] input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			long output;
			if (input.Any(x => x == 1)) {
				output = 1;
			} else {
				output = (long)Math.Ceiling(input[0] * input[1] / 2.0);
			}
			Console.WriteLine(output);

			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 13396
#include<iostream>
using namespace std;main(){int a,b,c;char o;while(cin>>a>>o>>b){if(o=='+')c=a+b;if(o=='-')c=a-b;if(o=='*')c=a*b;if(o=='/')c=a/b;if(o=='?')break;cout<<c<<endl;}}

Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>

using namespace std;

typedef struct {
	int x, y;
} POINT;

bool operator< (const POINT& a, const POINT& b)
{
	if (a.x == b.x){
		return (a.y < b.y);
	}
	return (a.x < b.x);
}

int main(void)
{
	POINT pat[200];
	POINT all[1000];
	int allcnt, patcnt;
	int i, j;
	
	while (1){
		scanf("%d", &patcnt);
		
		if (patcnt == 0){
			break;
		}
		
		for (int i = 0; i < patcnt; i++){
			scanf("%d%d", &pat[i].x, &pat[i].y);
		}
		
		scanf("%d", &allcnt);
		for (int i = 0; i < allcnt; i++){
			scanf("%d%d", &all[i].x, &all[i].y);
		}
		
		sort(pat, pat + patcnt);
		sort(all, all + allcnt);
		
		for (i = 0; i + patcnt - 1 < allcnt; i++){
			int k;
			k = 0;
			for (j = 0; j < patcnt; j++){
				for (int l = 0; l < allcnt; l++){
					if (pat[j].x - pat[0].x == all[l].x - all[i].x && pat[j].y - pat[0].y == all[l].y - all[i].y){
						k++;
						break;
					}
				}
			}
			if (k == patcnt){
				break;
			}
		}
		
		printf("%d %d\n", all[i].x - pat[0].x, all[i].y - pat[0].y);
		
	}
	
	return (0);
}

Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define szt size_t
using ll = long long;
using namespace std;
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 T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}

int H,W;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> H >> W;
  vector<vector<int>> d(H,vector<int>(W,0));
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      cin >> d[i][j];
    }
  }
  vector<tuple<szt,szt,szt,szt>> ret;
  for(szt i = 0 ; i < H; i++){
    for(szt j= 0 ; j < W; j++){
      if(d[i][j] % 2 == 0){
        continue;
      }
      if(i == H-1 && j == W-1){
        continue;
      }
      szt ni = i;
      szt nj = j;
      if(j+1 == W){
        ni++;
      }
      else{
        nj++;
      }
      ret.emplace_back(i+1,j+1,ni+1,nj+1);
      d[i][j]--;
      d[ni][nj]++;
    }
  }

  cout << ret.size() << endl;
  for(auto i : ret){
    szt A,B,C,D;
    tie(A,B,C,D) = i;
    cout << A << " " << B << " " << C << " "<< D << endl;
  }

  return 0;
}


Measured memory_bytes: 7408
#include <bits/stdc++.h>
using namespace std;
 
#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, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 2e5+5;

int main(int argc, char** argv) {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(max(a*c, b*c), max(a*d, b*d)) << "\n";
	return 0;
}


Measured memory_bytes: 3632
N = int(input())
vS = []
for _ in range(N):
    vS.append(input())

mP = dict()
for i in range(N):
    s = "".join(sorted(list(vS[i])))
    if s in mP.keys():
        mP[s] += 1
    else:
        mP[s] = 1

count = 0
vC = []
for key in mP:
    if (mP[key] < 2):
        continue
    vC.append(mP[key])
    count += 1

res = 0
for x in vC:
    res += x * (x-1) // 2

print(res)


Measured memory_bytes: 24980
n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = [0] * n
for i in range(n - 1):
    for j in range(i, n):
        dist = min(j-i, abs(x-i) + abs(y-j) + 1)
        ans[dist] += 1

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

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
int a,b;
bool Main(){
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 256
if __name__ == "__main__":
  a, b, c, d = [int(a) for a in input().split()]
  # x = max(a, b)
  # y = max(c, d)
  # if (x < 0 and y < 0 ) or (x >= 0 and y >= 0):
  #   pass
  # elif x > 0 and y <= 0:
  #   x = min(a, b)
  # elif y > 0 and x <= 0:
  #   y = min(c, d)
  # ret = x * y
  print(max(a*c, a*d, b*c, b*d))


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

int main() {

    long long int n, l;
    cin >> n >> l;

    vector< long long int > v;

    for ( long long int i = 0; i < n; i++ ) {
        long long int in;
        cin >> in;
        v.push_back( in );
    }

    long double x = 0;
    long double y = 0;
    long long int cnt = 0;
    long double kk = M_PI / l;
    long double vcos[3010] = {};
    long double vsin[3010] = {};
    for ( long long int i = n - 1; i > 0; i-- ) {
        vcos[i] = vcos[i+1] + cosl( kk * v[i] );
        vsin[i] = vsin[i+1] + sinl( kk * v[i] );
    }

    for ( long long int a = 0; a < n; a++ ) {
        long double ax = cosl( 2.00L * M_PI * v[a] / l );
        long double ay = sinl( 2.00L * M_PI * v[a] / l );
        for ( long long int b = a + 1; b < n; b++ ) {
            long double bx = cosl( 2.00L * M_PI * v[b] / l );
            long double by = sinl( 2.00L * M_PI * v[b] / l );

            long double px = cosl( 2.00L * M_PI * (v[a]+v[b])/2 / l );
            long double py = sinl( 2.00L * M_PI * (v[a]+v[b])/2 / l );
            long long int cc = n - (b+1);
            cnt += cc;
            x += px * cc;
            y += py * cc;
            long double d = sqrtl( ( ax - px ) * ( ax - px ) + ( ay - py ) * ( ay - py ) );
            long double vv = 0.50L * (v[a]+v[b]+l);
            x += cosl( kk * vv ) * vcos[b+1] * d;
            x -= sinl( kk * vv ) * vsin[b+1] * d;
            y += sinl( kk * vv ) * vcos[b+1] * d;
            y += cosl( kk * vv ) * vsin[b+1] * d;
        }
    }

    cout << fixed << setprecision(15) << x / cnt << " " << y / cnt << endl;

    return 0;

}


Measured memory_bytes: 640
#include<stdio.h>

int main(void){
  int n;
  scanf("%d",&n);
  for(int a=1;a<=9;a++)
  for(int b=1;b<=9;b++)
  {
    if(a*b==n)
    {
    puts("Yes");
    return 0;
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <bitset>
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";}
template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";}
template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<ll,ll>;
const ll M = 998244353;

int main() {
  int n; cin>>n;
  P p[n]; for(int i=0;i<n;i++) {
    cin>>p[i].first>>p[i].second;
  }
  sort(p,p+n);
  ll l1=p[(n-1)/2].first,l2=p[n/2].first;
  sort(p,p+n,[](P x, P y){if (x.second==y.second) return x.first>y.first; return x.second>y.second;});
  ll r1=p[(n-1)/2].second,r2=p[n/2].second;
  if (n%2) {
    cout<<r1-l1+1<<endl;
  } else {
    //cout<<l1<<" "<<l2<<" "<<r1<<" "<<r2<<endl;
    ll l=l1+l2, r=r1+r2;
    cout<<r-l+1<<endl;
  }
}

Measured memory_bytes: 6764
#include<stdio.h>
#include<string.h>
#define QSIZE 100000

typedef struct list{
  char name[100];
  int t;
}LIST;
LIST queue[QSIZE];
  
int head,tail,n;
LIST dequeue(void);
void enqueue(LIST);

int main(){
  int time = 0;
  int i,q,num;
  LIST data;

  head=1;
  scanf("%d %d",&n,&q);
  tail=n+1;
  
  for(i=1;i<=n;i++){
    scanf("%s", queue[i].name);
    scanf("%d",&queue[i].t);
  }

  while(head!=tail){
    data =dequeue();
    if(q<data.t){
      num=q;
    }
    else{
      num=data.t;
    }
    data.t -= num;
    time += num;
    if(data.t>0){
      enqueue(data);
    }
     else{
       printf("%s %d\n",data.name,time);
     }
    }
}

void enqueue(LIST num){
  int next = (tail+1)%QSIZE;
  queue[tail] = num;
  tail =next;
}

LIST dequeue(void){
 LIST val;
  val = queue[head];
  head =(head+1)%QSIZE;
  return val;
}



Measured memory_bytes: 12884
n=int(input())
a=[int(input()) for i in range(n)]
count=0

if a[0]!=0: count=-1
else:
    for i in range(n-1):
        if a[i]+1==a[i+1]:
            count+=1
        elif a[i]+1<a[i+1]:
            count=-1
            break
        else:
            count+=a[i+1]
print(count)

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

int main() {
  int counter = 0;
  int number;
  cin >> number;
  vector<int> data(number);
  for (int i=0; i<number; i++) {
    cin >> data[i];
  }
  for (int i=1; i<number-1; i++) {
    if (data[i-1] < data[i] && data[i] < data[i+1]) {
      counter++;
    } else if (data[i+1] < data[i] && data[i] < data[i-1]) {
      counter++;
    }
  }
  cout << counter;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define int long long int 
#define F first
#define S second
#define boost ios_base::sync_with_stdio(false),cin.tie(NULL);
const int MOD = 998244353;
//#include <ext/pb_ds/assoc_container.hpp> // Common file 
//#include <ext/pb_ds/tree_policy.hpp>  
//using namespace __gnu_pbds; 
//stringstream ss; string temp; ss<<str(original string) ss>>temp;


int32_t main()
{	
  	
  	int n,d; cin>>n>>d;
  	int a[n][d];
  	for(int i=0;i<n;i++)
  	{
  		for(int j=0;j<d;j++)
  		{
  			cin>>a[i][j];
  		}
  	}
  	int ans = 0;

  	for(int i=0;i<n;i++)
  	{
  		for(int j=i+1;j<n;j++)
  		{
  			int sum = 0;
  			for(int k=0;k<d;k++)
  			{
  				sum = sum + (a[i][k] - a[j][k])*(a[i][k] - a[j][k]);
  			}

  			int sqr = sqrt(sum);

  			if(sqr*sqr == sum)
  			{
  				ans++;
  			}
  		}
  	}
  	cout<<ans<<endl;
	return 0;
} 


Measured memory_bytes: 256
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}
 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;
}

const ll N=1e7+1;

ll sp[N];

void sieve(){
  for(int i=1;i<=N;i++)sp[i]=1;

    for(ll i=1;i<=N;i++){
      for(ll j=2*i;j<=N;j+=i){
        sp[j]++;
      
    }
}

}
/*
//ll fac[N],inv[N];

ll p=1e9+7;

void fill(){
  fac[0]=inv[0]=1;

  for(int i=1;i<N;i++){
    fac[i]=fac[i-1]*i%p;
  }
}

*/

int main()
{ 

  IOS;

sieve();


ll n;cin>>n;


//cout<<sp[10000000]<<endl;


ll x=0;

for(ll i=1;i<=n;i++){

 ll d=sp[i]*i;
 x+=d;
}

cout<<x<<endl;

//cout<<sp[n]<<endl;


return 0;
 
}



Measured memory_bytes: 81776
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

class dice{
public:
	int d[6];
	void set(int n, int x){
		d[n] = x;
	}
	int get(int n){
		return d[n];
	}
	void rotate(char c){
		int tmp;
		switch (c){
		case 'W':
			tmp = d[3];
			d[3] = d[0];
			d[0] = d[2];
			d[2] = d[5];
			d[5] = tmp;
			break;
		case 'E':
			tmp = d[5];
			d[5] = d[2];
			d[2] = d[0];
			d[0] = d[3];
			d[3] = tmp;
			break;
		case 'N':
			tmp = d[0];
			d[0] = d[1];
			d[1] = d[5];
			d[5] = d[4];
			d[4] = tmp;
			break;
		case 'S':
			tmp = d[4];
			d[4] = d[5];
			d[5] = d[1];
			d[1] = d[0];
			d[0] = tmp;
			break;
		}
	}
	void espin(){
		rotate('S');
		rotate('E');
		rotate('N');
	}
	bool operator ==(dice e){
		bool flag;
		string s = "SESESE";
		for (int i = 0; i < 6; i++){
			e.rotate(s[i]);
			if (d[0] == e.get(0)){
				for (int j = 0; j < 4; j++){
					flag = true;
					for (int k = 1; k < 6; k++){
						if (d[k] != e.get(k)) flag = false;
					}
					if (flag) return true;
					e.espin();
				}
			}
			if (i == 5) return false;
		}
	}
};

int main(){
	int tmp;
	dice d, c, e;
	for (int i = 0; i < 6; i++){
		cin >> tmp;
		d.set(i, tmp);
	}
	for (int i = 0; i < 6; i++){
		cin >> tmp;
		c.set(i, tmp);
	}
	if (d == c) cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 3208
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main(){
  string n;
  cin >> n;
  string a[3];
  a[0] = "Sunny";a[1] = "Cloudy";a[2] = "Rainy";
  for(int i = 0; i < 3; i++){
    if(a[i] == n){
      cout << a[(i+1)%3]<< endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
const int maxn = 2e6+5;
const int mod = 1e9+7;
using namespace std;

ll a[maxn];

void solve() {
	ll n, k, cur=1, tmp; cin >> n >> k;
	rep(i,0,n) cin >> a[i];
	rep(i,0,k) cur += a[i];
	rep(i,k,n) {
		tmp = cur;
		cur -= a[i-k];
		cur += a[i];
		if (cur > tmp) cout << "Yes\n";
		else cout << "No\n";
	}
}

int main(int argc, char * argv[]) 
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin);
	//freopen("C:/Users/Fish_Brother/Desktop/out", "w", stdout);
#endif

	//int t; cin >> t; while(t--)
	solve();

    return 0;
}

Measured memory_bytes: 5076
def show(a):
    ans=""
    for c in a:
        if c==a[-1]:
            ans+=str(c)
        else:    
            ans+=str(c)+" "
    print(ans)

def insertionsort(a,n):
    show(a)
    for i in range(1,n):
        v=a[i]
        j=i-1
        while j>=0 and a[j]>v:
            a[j+1]=a[j]
            j-=1
        a[j+1]=v
        show(a)

n=int(input())
line=list(map(int,input().split()))
insertionsort(line,n)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int>P;
 
int main() {
  ll a,R,G,B,count;
  R=0,G=0,B=0,count=0;
  cin>>a;
  string s;
  cin>>s;
 vector<ll>r(a);
  vector<ll>g(a);
  vector<ll>b(a);
  if(a<4){
    cout<<0<<endl;
  }
  else{
  for(ll i=0;i<a;i++){
    if(s.at(i)=='R'){
      R++;
    }
    else if(s.at(i)=='G'){
      G++;
    }
    else{
      B++;
    }
    r.at(i)=R,g.at(i)=G,b.at(i)=B;
  }
   for(ll i=0;i<a-3;i++){
    for(ll j=i+1;j<a-1;j++){
      if(s.at(i)==s.at(j)){
        continue;
      }
      if(s.at(i)!='R'&&s.at(j)!='R'){
        count+=r.at(a-1)-r.at(j);
        if(2*j-i<a){
        if(s.at(2*j-i)=='R'){
          count--;
        }
        }
      }
      else if(s.at(i)!='G'&&s.at(j)!='G'){
        count+=g.at(a-1)-g.at(j);
        if(2*j-i<a){
         if(s.at(2*j-i)=='G'){
          count--;
        }
        }
      }
     else  if(s.at(i)!='B'&&s.at(j)!='B'){
        count+=b.at(a-1)-b.at(j);
       if(2*j-i<a){
       if(s.at(2*j-i)=='B'){
          count--;
        }
      }  
     }
      }
    }
  cout<<count<<endl;
  }
  }
 

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

using namespace std;

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

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef vector<int> vi;


int n, d;

ll ds(const vi &a, const vi &b)
{
    ll ans = 0;
    forn(i, d)
    {
        ans+=(a[i]-b[i])*(a[i]-b[i]);
    }
    return sqrt(ans);
}

ll ds2(const vi &a, const vi &b)
{
    ll ans = 0;
    forn(i, d)
    {
        ans+=(a[i]-b[i])*(a[i]-b[i]);
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> d;
    int ans = 0;

    vector<vi> a(n, vi(d));
    forn(i, n)
    {
        forn(j, d) cin >> a[i][j];
    }
    forn(i, n)
    {
        forab(j, i+1, n)
        {
            ll x = ds(a[i], a[j]), y = ds2(a[i], a[j]);
            ans+=(x*x==y);
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
bool used[100100] = {};
vector<int> adj[100100];

void dfs(int i) {
    used[i] = true;
    for (int j : adj[i]) if (!used[j]) dfs(j);
}

int main() {
    int n, m; cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int x, y, z; cin >> x >> y >> z;
        x--; y--; adj[x].push_back(y); adj[y].push_back(x);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (!used[i]) { dfs(i); ans++; }
    }
    cout << ans << endl;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
const int MQ=200000*2;
const int MN=200000;
int N,Q;
int its[MQ],a[MQ],b[MQ];
int nouse[MQ];
bool e[MQ];
typedef pair<ll,int> P;	//cost,id
priority_queue<P,vector<P>,greater<P> > que;

struct unionfind{
	int par[MN];
	void init(int N){rep(i,N) par[i]=i;}
	int find(int x){
		if(par[x]==x) return x;
		return par[x]=find(par[x]);
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	void unite(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return;
		par[y]=x;
	}
}UF;

void iter(int id){
		a[id]++;
		if(a[id]==N) a[id]=0;
		b[id]++;
		if(b[id]==N) b[id]=0;
}
int main(){
	cin>>N>>Q;
	UF.init(N);
	rep(i,Q){
		ll c;
		cin>>a[i]>>b[i]>>c;
		a[i+Q]=(a[i]+1)%N;
		b[i+Q]=b[i];
		que.push(P(c,i));
		que.push(P(c+1,i+Q));
	}
	int tm=0;
	ll ans=0;
	while(tm!=N-1){
		P p=que.top();que.pop();
		int id=p.sc;
		ll c=p.fs;
		if(UF.same(a[id],b[id])){
//			printf("no use id=%d    %d,%d\n",id,a[id],b[id]);
			nouse[id]++;
			iter(id);
//			if(que.size()<=10||nouse[id]<=10) que.push(P(c+2,id));
			continue;
		}else{
			UF.unite(a[id],b[id]);
			tm++;
//			printf("unite id=%d   %d,%d\n",id,a[id],b[id]);
			ans+=c;
			iter(id);
			que.push(P(c+2,id));
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 12136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <map>

typedef long long ll;
using namespace std;

int main() {
    
    int n;
    cin >> n;
    
    map<int, int> m;
    vector<int> a(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]]++;
    }
    
    sort(a.begin(), a.end(), greater<int>());
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (!m[a[i]]) continue;
        m[a[i]]--;
        for (int d = 31; d--;) {
            
            int e = 1 << d;
            if (a[i] >= e) continue;
            
            if (m[e - a[i]]) {
                m[e - a[i]]--;
                ans++;
            }
            
        }
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 29824
import sys
input=sys.stdin.readline
import numpy as np
from scipy.sparse.csgraph import shortest_path


h,w=map(int,input().split())
c=[list(map(int,input().split())) for i in range(10)]
a=[list(map(int,input().split())) for i in range(h)]

graph = np.zeros((10,10))
for i in range(10):
    for j in range(10):
        graph[i,j] = c[i][j]
dist = shortest_path(graph,directed=True).astype(int)

#print(dist)
res=0
for i in range(h):
    #print(a[i])
    for j in range(w):
        if a[i][j]==-1:continue
        res+=dist[a[i][j]][1]
        #print(dist[a[i][j]][1])
print(res)

Measured memory_bytes: 14068
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1LL << 60;
constexpr int INF = 1000000007;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}

double dp[3010][3010];
int main(){
  int N;
  cin >> N;
  vector<double> p(N);
  for(int i=0; i<N; i++){
    cin >> p[i];
  }
  dp[0][0] = 1.0;
  for(int i=0; i<N; i++){
    for(int j=0; j<=i; j++){
      dp[i+1][j+1] += dp[i][j] * p[i];
      dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
    }
  }
  double res=0.0;
  for(int i=(N+1)/2; i<=N; i++){
    res += dp[N][i];
  }
  cout << fixed << setprecision(10) <<  res << endl;
  return 0;
}


Measured memory_bytes: 69120
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let read_ints () = read_line () |> split_on_char ' ' |>  List.map int_of_string

let dfs vs n =
  let d = Array.make n (-1) in
  let rec doit i j =
    d.(i) <- j;
    List.iter (fun v -> if d.(v) = (-1) then doit v j) vs.(i) in
  Array.iteri (fun i e -> if e = (-1) then doit i i) d;
  d

let solve n m =
  let g = Array.make n [] in
  for _ = 0 to m - 1 do
    match read_ints () with
    | [s; t] ->
      g.(s) <- t :: g.(s);
      g.(t) <- s :: g.(t);
    | _ -> assert false
  done;
  let v = dfs g n in
  let q = read_int () in
  for _ = 0 to q - 1 do
    match read_ints () with
    | [s; t] -> Printf.printf (if v.(s) = v.(t) then "yes\n" else "no\n")
    | _ -> assert false
  done

let () =
  match read_ints () with
  | [n;m] -> solve n m
  | _ -> assert false

Measured memory_bytes: 19172
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=a-1;i>=b;i--)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.14159265358979323
#define sz(a) (int)((a).size())
#define len(a) (int)(a.length())
#define FOR(i,j,k,l) for(ll i=j;i<k;i+=l)
#define CC(x) cout<<x<<endl


void Fast_IO() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   #ifndef ONLINE_JUDGE
   freopen("input.in","r",stdin);
   freopen("output.out","w",stdout); 
   #endif
} 

int main(){
   //Fast_IO();
      ll n,val;
      cin>>n;
      if(n%1000!=0) val = n/1000+1;
      else val=n/1000;
      cout<<val*1000-n<<endl;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

vector<ll> divisors(ll n) {
    vector<ll> v;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            v.push_back(i);
            if (i * i != n) {
                v.push_back(n / i);
            }
        }
    }
    return v;
}

void solve() {
    int n;
    cin >> n;
    vi a(n);
    vvl d(n, vl());
    vi s(1001001);
    REP(i, n) {
        cin >> a[i];
        s[a[i]]++;
        d[i] = divisors(a[i]);
    }
    int ans = 0;
    REP(i, n) {
        bool ok = true;
        for (auto e : d[i]) {
            if (s[e] > 1 or (s[e] == 1 and e != a[i])) {
                ok = false;
                break;
            }
        }
        if (ok) ans++;
        // cout << i << ": " << ans << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 115444
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323

//int calc1(float a,float b,float c,float d,float e,float f,float *x,float *y);
//void quick(int *,long long,long long);
//int comp(char *a,char *b);

int main(){
	
	char a[100];
	char b[100];
	char c;
	int i,j,k,n;

	n=100;
	i=0;
	j=0;
	while(scanf("%c",&c)!=EOF){
		if(c=='\n'){
			j--;
			if(j==2)
				for(k=0;k<=25;k++)
					if((b[0]+k-'t')%26==0&&(b[1]+k-'h')%26==0&&(b[2]+k-'e')%26==0)
						n=26-k;
			if(j==3)
				for(k=0;k<=25;k++)
					if((b[0]+k-'t')%26==0&&(b[1]+k-'h')%26==0&&(b[2]+k-'i')%26==0&&(b[3]+k-'s')%26==0)
						n=26-k;
			if(j==3)
				for(k=0;k<=25;k++)
					if((b[0]+k-'t')%26==0&&(b[1]+k-'h')%26==0&&(b[2]+k-'a')%26==0&&(b[3]+k-'t')%26==0)
						n=26-k;
			if(n==100)
				printf("error");
			for(j=0;j<i;j++){
				if(a[j]>='a'&&a[j]<='z'){
					a[j]-=n;
					if(a[j]<'a')
						a[j]+=26;
				}
					printf("%c",a[j]);
			}
			printf("\n");
			n=100;
			i=0;
			j=0;
		}else{
			a[i]=c;
			i++;
			if(c>='a'&&c<='z'){
				b[j]=c;
				j++;
				if(j>10)
					j=0;
			}else{
				j--;
				if(j==2)
					for(k=0;k<=25;k++)
						if((b[0]+k-'t')%26==0&&(b[1]+k-'h')%26==0&&(b[2]+k-'e')%26==0)
							n=26-k;
				if(j==3)
					for(k=0;k<=25;k++)
						if((b[0]+k-'t')%26==0&&(b[1]+k-'h')%26==0&&(b[2]+k-'i')%26==0&&(b[3]+k-'s')%26==0)
							n=26-k;
				if(j==3)
					for(k=0;k<=25;k++)
						if((b[0]+k-'t')%26==0&&(b[1]+k-'h')%26==0&&(b[2]+k-'a')%26==0&&(b[3]+k-'t')%26==0)
							n=26-k;
				/*
				if(j==2&&( (b[0]-'t')-(b[1]-'h')+52 )%26==0&&( (b[0]-'t')-(b[2]-'e')+52 )%26==0)
					n=b[0]-'t';
				if(j==3&&( (b[0]-'t')-(b[1]-'h')+52 )%26==0&&( (b[0]-'t')-(b[2]-'i')+52 )%26==0&&( (b[0]-'t')-(b[3]-'s')+52 )%26==0)
					n=b[0]-'t';
				if(j==3&&( (b[0]-'t')-(b[1]-'h')+52 )%26==0&&( (b[0]-'t')-(b[2]-'a')+52 )%26==0&&( (b[0]-'t')-(b[3]-'t')+52 )%26==0)
					n=b[0]-'t';
				*/
				j=0;
			}
		}
	}
	//for(i=0;i<=1000000000;i++);
	return 0;
}

Measured memory_bytes: 524
# n a b
n, a, b = gets.split
n = n.to_i
a = a.to_i
b = b.to_i

def some_sums(n)
  sum = 0
  n_str = n.to_s
  n_str.length.times do |i|
    sum += n_str[i].to_i
  end
  return sum
end

sums = 0
n.times do |i|
  sum = some_sums(i+1)
  if sum >= a && sum <= b
    sums += i+1
  end
end

puts sums


Measured memory_bytes: 14300
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
#define LL long long
#define NUM 1000000007

using namespace std;

int main() {
    vector<int> v(3);
    for (size_t i = 0; i < 3; i++)
    {
        cin >> v[i];
    }
    int mini = 0;
    auto itr = min_element(v.begin(), v.end());
    mini = *itr;
    v.erase(itr);
    auto itrr = min_element(v.begin(), v.end());
    mini += *itrr;
    cout << mini << endl;

}

Measured memory_bytes: 256
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))


N = INT()


# DP = [1] * (N+1)

# ans = 1
# for i in range(2, N+1):
#     for j in range(i, N+1):
#         if j % i == 0:
#             DP[j] += 1
#     ans += i*DP[j]
# print(ans)

ans = 0
for i in range(1, N+1):
    tmp = (N//i)
    ans += tmp * (tmp+1) // 2 * i
print(ans)

Measured memory_bytes: 63340
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(void)
{
    int a[4], b[4], hit, blow;
    
    while(cin >> a[0] >> a[1] >> a[2] >> a[3])
    {
        cin >> b[0] >> b[1] >> b[2] >> b[3];
        
        hit = blow = 0;
        rep(i,4)
        {
            if(a[i] == b[i]) hit++;
            else{
                rep(j,4){
                    if(a[i] == b[j]){
                        blow++;
                        break;
                    }
                }
            }
        }
        cout << hit << " " << blow << endl;
    }

    return 0;
}

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

namespace abc168_v{
    class Program{
        static void Main(string[] args){
            // A B H M
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var tickLengthHour = input[0];
            var tickLengthMinite = input[1];
            var hour = input[2];
            var minite = input[3];

            var clockKakudo = (double)360.0;
            var clockMinite = (double)60.0;
            var clockHour = (double)12.0;

            double tickMiniteKakudo =  clockKakudo / clockMinite * minite;
            double t1 = clockKakudo / clockMinite / clockHour * minite;
            double t2 = clockKakudo / clockHour * hour;
            double tickHourKakudo = t1 + t2;

            double SankakuKakudo;

            if(tickMiniteKakudo > tickHourKakudo){
                var k1 = tickMiniteKakudo - tickHourKakudo;
                if(k1 > 180) {
                    SankakuKakudo = calcKakudo(tickHourKakudo) + calcKakudo(tickMiniteKakudo);
                }else{
                    SankakuKakudo = k1;
                }
            }else{
                var k1 = tickHourKakudo - tickMiniteKakudo;
                if(k1 > 180) {
                    SankakuKakudo = calcKakudo(tickHourKakudo) + calcKakudo(tickMiniteKakudo);
                }else{
                    SankakuKakudo = k1;
                }
            }
            // System.Console.WriteLine("時針長さ: {0} / 分針長さ: {1} / 時針-分針間角度: {2}", tickLengthHour, tickLengthMinite, SankakuKakudo);

            System.Console.WriteLine(YogenTeiri(tickLengthHour, tickLengthMinite, (double)SankakuKakudo));
        }
        public static double YogenTeiri(double A, double B, double cosC){
            double rad = Math.PI * cosC / 180.0;
            // Cについて解く
            // 余弦定理からc^2 = a^2 + b^2 -2ab cosCなので
            var result = Math.Pow(A, 2) + Math.Pow(B, 2) - 2 * A * B * Math.Cos(rad);
            result = Math.Abs(result);
            return Math.Sqrt(result);          
        }

        public static double calcKakudo(double k){
            if(k > 180){
                return (double)360 - k;
            }else{
                return k;
            }
        }
    }
}


Measured memory_bytes: 28684
#include<stdio.h>
int main()
{
	int w,h,x,y,r;
	scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
	if(0<=(x-r) && (x+r)<=w && (y+r)<=h && 0<=(y-r)){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 584
import java.util.Scanner;

public class Main {
	
	public static void main(String args[]){
		Scanner scanner=new Scanner(System.in)	;
		int x=scanner.nextInt();
		int y=scanner.nextInt();
		if(x<y){
			System.out.println("a < b");
		}else if(x>y){
			System.out.println("a > b");
		}else{
			System.out.println("a == b");
		}
		
		scanner.close();
	}

}

Measured memory_bytes: 17320
from collections import defaultdict
n = int(input())

def makeFreqTuple(s):
    freq = [0] * 26
    for c in s:
        freq[ord(c)-ord("a")] += 1
    return tuple(freq)

def C(n, k):
    numera = 1
    for i in range(n, n-k, -1):
        numera *= i
    denomi = 1
    for i in range(k, 1, -1):
        denomi *= i
    return numera // denomi

dic = defaultdict(int)
for i in range(n):
    s = input()
    t = makeFreqTuple(s)
    dic[t] += 1

ans = 0
for k, v in dic.items():
    ans += C(v, 2)
print (ans)

Measured memory_bytes: 41088
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> v(n);
  bool flag = false;
  rep(i, n){
    cin >> v[i];
    if(v[i] == 0) flag = true;
  }
  cpp_int res = 1;
  // print(v);

  rep(i, n){
    res *= v[i];
    if(res > cpp_int(1000000000000000000)){
      res = -1;
      break;
    }
  }
  if(flag) cout << 0 << endl;
  else cout << res <<endl;
}


Measured memory_bytes: 3996
import java.util.Scanner;
import java.util.Arrays;
import java.lang.Integer;
import java.lang.Math;

class Main {
  public static void main (String[] args) {
    	Scanner scanner = new Scanner(System.in);
		String tokens[] = scanner.nextLine().split(" ");
        int n = Integer.parseInt(tokens[0]);
        int m = Integer.parseInt(tokens[1]);
        int min = Math.min(n,m);
        int max = Math.max(n,m);
        for(int i = 0; i < max; i++) {
        	System.out.print(min);
        }
        
  }
}


Measured memory_bytes: 23124
/* おまじない　*/
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
    cout<<fixed;
}

int main(){
    init();
    ll N;cin>>N;
    vector<ll>L(2*N);
    for(int i=0;i<2*N;i++){
        cin>>L[i];
    }

    sort(L.begin(),L.end());
    ll ans=0;
    for(int i=0;i<N;i++){
        ans+=L[2*i];
    }

    cout<<ans<<endl;
}


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

/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

const int mxN = 100;
string g[100];
int dist[100][100];
int dx[4] = {1,-1,0,0},dy[4] = {0,0,1,-1};

int H,W;

void bfs() {
	for(int i = 0;i < H;i++) for(int j = 0;j < W;j++) dist[i][j] = INT_MAX;
	dist[0][0] = 1;
	queue<pair<int,int> > q;
	q.push({0,0});
	while(!q.empty()) {
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		for(int k = 0;k < 4;k++) {
			int tx = x + dx[k];
			int ty = y + dy[k];
			if(min(tx,ty) < 0 || tx >= H || ty >= W || g[tx][ty] == '#') continue;
			if(dist[tx][ty] <= dist[x][y] + 1) continue;
			dist[tx][ty] = dist[x][y] + 1;
			q.push({tx,ty});
		}
	}
}

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

	int b = 0;
	cin>>H>>W;
	for(int i = 0;i < H;i++) cin>>g[i], b += count(g[i].begin(),g[i].end(),'#');
	bfs();
	H--,W--;
	if(dist[H][W] >= INT_MAX) cout<<"-1\n";
	else cout<<(H * W) + H + W + 1 - b - dist[H][W]<<'\n';
	return 0;
}


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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

/*constants*/
#define MAXN                         100005
#define PI                           3.14159265358979323846

/*debug*/
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>void __f(const char* name, Arg1&& arg1){ std::cout << name << " : " << arg1 << '\n';}
    template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll i,j,n,m,k,cnt=0,ans=0,t=1;
	cin>>n;
	ll a[n];
	rep(i,0,n) cin>>a[i];
	multiset<ll> s;
	rep(i,0,n) s.insert(a[i]);
	rep(i,0,n){
		s.erase(s.find(a[i]));
		cout<<(*s.rbegin())<<endl;
		s.insert(a[i]);
	}	
	
	return 0;
}

Measured memory_bytes: 13376
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
bool ch(char c){if(c=='A'||c=='T'||c=='G'||c=='C')return 0;else return 1;}
int main()
{
	string s;
	cin>>s;
	int n=s.size(),m=0;
	for(int i=0;i<n;i++)for(int j=i;j<n;j++)
	{
		int f=0;
		for(int k=i;k<=j;k++)
		{
			if(ch(s[k]))f=1;
		}
		if(f==0)m=max(m,j-i+1);
	}
	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int price = 0;
        for(int i=1;i<=50000;i++){
            if((int)(i*1.08)==N){
                price = i;
            }
        }
        if(price>0){
            System.out.println(price);
        }else{
            System.out.println(":(");
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
//map<pair<long long int,long long int>,long long int>mapa;
//pair<ll,ll>v[200005];
ll sum[200005];
//priority_queue<ll>pq;
class Myfirst{
private:
    string *name;       ll *age;
    public:
        ll gcd(ll a ,ll b)
        {   if(b==0) return a;  a%=b;   return gcd(b,a);    }
        ll exte_gcd(ll a,ll b,ll& x,ll& y)
        {
            if(b==0)
            {   x=1; y=0;   return a;   }
            ll x1,y1;             ll d=exte_gcd(b,a%b,x1,y1);
            x=y1;                 y=x1-y1*(a/b);  return d;
        }
        ll powe(ll d,ll s)
        {
            if(s==1) return d;      else if(s==0) return 1;
            else
            {   ll u,v=d;            for(u=1;u<s;u++)    d=d*v;
                return d;
            }
        }
        ll count_divisors(ll b)
        {
                ll i,count=0,n=1;
                for(i=2;i*i<=b;i++)
                {
                    count=0;
                    if(b%i==0)
                    {
                        while(b%i==0)
                        {
                            b=b/i;      count++;
                        }
                        n=n*(count+1);
                    }
                }
                if(b>1) n=2*n;
            return n;
        }
        ll bigmod(ll a,ll b, ll mod)
        {
            if(b==0)
                return 1;
            ll x=bigmod(a,b/2,mod);         x=(x*x)%mod;
            if(b%2) x=(x*a)%mod;
                return x;
        }
        ll phi(ll n)
        {
            double result=n;
            for (ll p=2;p*p<=n;++p){
                if (n%p==0){
                    while(n%p==0)       n/=p;
                    result*=(1.0-(1.0/(double)p));
                }
            }
            if(n>1)
                result*=(1.0-(1.0/(double)n));
            return (ll)result;
        }

        void solve()
        {
            ll n,i,mx=0,j,x,ans=0,s=0;
            cin>>n;
            ll a[n+5];
            for(i=1;i<=n;i++) cin>>a[i];
            mx=a[1];
            for(i=2;i<=n;i++)
            {
                mx=max(a[i],mx);
                ans+=mx-a[i];
                a[i]=mx;
            }
            cout<<ans<<endl;



        }



};
int main()
{
    Myfirst *prg = new Myfirst();
    prg->solve();
}



Measured memory_bytes: 5168
A,B,C,D = map(int,input().split())

Alice = []
for i in range(A,B):
  Alice.append(i)

Bob = []
for s in range(C,D):
  Bob.append(s)

count = 0  
B = B - A

for i in range(B):
  if Alice[i] in Bob:
    count += 1
print(count)

Measured memory_bytes: 9132
/*
    NEVER GIVE UP!
    THE EXPERT IN ANYTHING WAS ONCE A BEGINNER
*/
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

void solve()
{
    ll n,m,s=0;    
    cin >> n >> m;
    vll a(n);
    bool is=true;

    f(i,0,n-1)
    {
        cin >> a[i];
        s+=a[i];
    }

    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());

    // s/=(4*m);

    f(i,0,m-1)
    {
        if(a[i]*4*m < s)
            is=false;
    }

    if(is)
        cout << "Yes" <<endl;
    else
        cout << "No" <<endl;
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <queue>

struct edge{
    int to, cost;
};

using namespace std;

typedef pair<int, int> P;

vector<edge> G[100000];
int dist[100000];
bool used[100000];

void dijkstra(int v){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(1, v));
    while(!que.empty()){
        P top = que.top();
        que.pop();
        int u = top.second;
        int d = top.first;
        //cout << u << ' ' << d << endl;
        if(used[u]) continue;
        dist[u] = d;
        used[u] = true;
        for(int i = 0; i < G[u].size(); i++){
            if(!used[G[u][i].to]){
                que.push(P(d+G[u][i].cost, G[u][i].to));
                //cout << G[u][i].to << ' ' <<  d+G[u][i].cost << endl;
            }
        }
    }
}

int main(){
    int N;
    cin >> N;
    for(int i = 1; i < N; i++){
        G[i].push_back(edge{(i+1)%N, 1});
        G[i].push_back(edge{(i*10)%N, 0});
    }
    dijkstra(1);
    cout << dist[0] << endl;
}

Measured memory_bytes: 6904
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(o) (o).begin(), (o).end()
using namespace std;
typedef int_fast64_t ll;

size_t i, j;
ll N, K, S = 0;
ll cnt, buff, tmp;
ll A[500], B[500];
ll x, y;
vector<ll> cand;

inline bool solve(ll m) {
    for(i = 0; i < N; i++) B[i] = A[i] % m;
    sort(B, B + N);
    cnt = 0, buff = 0, tmp;
    for(i = 0, j = N - 1; i <= j; i++) {
        if(B[i] == 0 || B[i] == m) continue;
        buff = B[i];
        cnt += B[i];
        B[i] = 0;
        while(buff && j >= i) {
            if(B[j] == 0 || B[j] == m) {
                j--;
                continue;
            }
            tmp = m - B[j];
            if(tmp > buff) {
                B[j] += buff;
                break;
            } else {
                buff -= tmp;
                j--;
            }
        }
    } 
    return cnt <= K;
}

int main() {
    scanf("%lld %lld", &N, &K);
    REP(i, N) {
        scanf("%lld", A + i);
        S += A[i];
    }
    x = 1, y;
    while(x * x <= S) {
        if(S % x == 0) {
            y = S / x;
            if(solve(y)) {
                printf("%lld\n", y);
                return 0;
            }
            cand.push_back(x);
        }
        x++;
    }
    reverse(ALL(cand));
    for(auto& c : cand) if(solve(c)) {
        printf("%lld\n", c);
        break;
    }
	return 0;
}

Measured memory_bytes: 256