akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
#include <stack>
#include <unordered_set>

using namespace std;

int main(){

  int N, K;
  cin >> N >> K;
  vector<pair<int, int>> dt(N);

  int t, d;
  for(int i = 0; i < N; i++){
    cin >> t >> d;
    dt[i] = make_pair(d, t);
  }

  sort(dt.begin(), dt.end(), greater<pair<int, int>>());

  unordered_set<int> used;
  stack<int> replaceStack;

  long long ans = -1;
  long long tempSum = 0;
  long long typeCnt = 0;
  for(int i = 0; i < K; i++){
    auto temp = dt[i];
    if(used.find(temp.second) == used.end()){
      used.insert(temp.second);
      tempSum += temp.first;
      tempSum -= typeCnt * typeCnt;
      typeCnt++;
      tempSum += typeCnt * typeCnt;
    }
    else{
      replaceStack.push(temp.first);
      tempSum += temp.first;
    }
  }

  ans = tempSum;

  for(int i = K; i < N; i++){
    auto temp = dt[i];
    if(used.find(temp.second) == used.end()){
      if(!replaceStack.empty()){
	int replaceScore = replaceStack.top();
	replaceStack.pop();
	used.insert(temp.second);
	tempSum -= replaceScore;
	tempSum += temp.first;
	tempSum -= typeCnt * typeCnt;
	typeCnt++;
	tempSum += typeCnt * typeCnt;
	ans = max(ans, tempSum);
      }
      else{
	break;
      }
    }
    else{
      continue;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4620
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

struct UnionFind {
    vector<ll> par;
    
    //要素nで初期化
    UnionFind(ll n) : par(n, -1) { }
    void init(ll n) { par.assign(n, -1); }
    
    //xが属する集合の根を返す
    ll root(ll x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    //xとyが同じ集合に属しているかを判定
    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    //xが属する集合とyが属する集合をマージ
    bool merge(ll x, ll y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // 計算量が減るよ
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    //xが属する集合のサイズ
    ll size(ll x) {
        return -par[root(x)];
    }
};

struct edge { ll u, v, cost; };
bool comp(const edge& e1, const edge& e2) { return e1.cost < e2.cost;}
edge es[300000];
ll E = 0; // 辺数
ll kruskal(ll V) {
	sort(es, es + E, comp); // edge.costが小さい順にソートする 
	UnionFind uf(V); // Union-Findの初期化
	ll res = 0;
	for (ll i = 0; i < E; i++) {
		edge e = es[i];
		if (!uf.issame(e.u, e.v)) {
			uf.merge(e.u, e.v);
			res += e.cost; 
		}
	}
	return res; 
}




int main(){
	ll n;cin>>n;
	vector<P> a(n);
	vector<P> b(n);
	for(ll i = 0; i < n; i++) {
		ll x,y;cin>>x>>y;
		a[i] = mp(x,i);
		b[i] = mp(y,i);
	}
	sort(ALL(a));
	sort(ALL(b));
	for(ll i = 0; i < n - 1; i++) {
		es[E] = {a[i].sc,a[i + 1].sc,abs(a[i].fs - a[i + 1].fs)};
		E++;
		// es[E] = {a[i + 1].sc,a[i].sc,abs(a[i].fs - a[i + 1].fs)};
		// E++;
		// cost[a[i].sc][a[i + 1].sc] = abs(a[i].fs - a[i + 1].fs);
		// cost[a[i + 1].sc][a[i].sc] = abs(a[i].fs - a[i + 1].fs);
	}
	for(ll i = 0; i < n - 1; i++) {
		es[E] = {b[i].sc,b[i + 1].sc,abs(b[i].fs - b[i + 1].fs)};
		E++;
		// es[E] = {b[i + 1].sc,b[i].sc,abs(b[i].fs - b[i + 1].fs)};
		// E++;
		// cost[b[i].sc][b[i + 1].sc] = min(cost[b[i].sc][b[i + 1].sc],abs(b[i].fs - b[i + 1].fs));
		// cost[b[i + 1].sc][b[i].sc] = min(cost[b[i + 1].sc][b[i].sc],abs(b[i].fs - b[i + 1].fs));
	}

	cout << kruskal(n) << endl; 

	return 0;
}

Measured memory_bytes: 10240
import fractions
A, B = map(int, input().split())
MAX = fractions.gcd(A, B)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
print(len(set(prime_factorize(MAX)))+1)

Measured memory_bytes: 5048
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)



//小文字=大文字+32
int main() {
	int k;
	cin >> k;
	ll ans=1;

	ll tmp = 7;
	if (tmp % k ==0) {
		cout << ans;
		return 0;
	}
	rep(i, 1e7) {
		tmp = tmp * 10 + 7;
		tmp %= k;
			ans++;
			if (tmp == 0) {
				cout << ans;
				return 0;
			}
	}
	cout << -1;
}
	




Measured memory_bytes: 3608
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<random>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> xs(n); cin >> xs;
    int ans = M;
    for(int i = 0; i <= n - k; i++){
        int l = xs[i], r = xs[i + k - 1];
        if(r <= 0){
            ans = min(ans, - l);
        }else if(0 <= l){
            ans = min(ans, r);
        }else{
            ans = min(ans, min(- l * 2 + r, r * 2 - l));
        }
        printde(i, ans);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
        int n,mini,nswap=0;
        int a[100];
        cin>>n;
        for(int i=0;i<n;i++) cin>>a[i];
        for(int i=0;i<n-1;i++){
                mini = i;
                for(int j=i+1;j<n;j++){
                        if(a[j]<a[mini]) {
                                mini = j;
                        }
                }
                if(mini!=i){
                        swap(a[mini],a[i]);
                        nswap++;
                }
        }
        for(int i=0;i<n;i++) {
                cout<<a[i];
                if(i==n-1) cout<<endl;
                else cout<<" ";
        }
        cout<<nswap<<endl;
        return 0;
}


Measured memory_bytes: 3124
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    String sa = String.valueOf(a);
    String sb = String.valueOf(b);
    String sab = sa + sb;
    int iab = Integer.parseInt(sab);
    boolean s = false;
    for (int i = 0; i < 1000; i++) {
      if (i * i == iab) {
        System.out.println("Yes");
        s = true;
        break;
      }
    }
    if (s == false) {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 21844
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    string s;
    cin >> s;
    for(int i = 0; i < 3; i++){
        if(s[i] == '9'){
            cout << '1';
        }
        else
            cout << '9';
    }
    cout << endl;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> V(N), C(N);
    for(int i=0; i<N; ++i) cin >> V[i];
    for(int i=0; i<N; ++i) cin >> C[i];
    int res = 0;
    for(int i=0; i<N; ++i) res += max(0, V[i] - C[i]);
    cout << res << endl; 
}

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

signed main(){
	int N;cin>>N;
	map<string,int> dict;
	vector<string> poll;
	for(int i=0;i<N;i++){
		string S;cin>>S;
		if(dict.count(S))dict[S]++;
		else{
			dict[S]=1;
			poll.push_back(S);
		}

	}
	vector<pair<int,string>> ans(poll.size());
	for(int i=0;i<poll.size();i++){
		ans[i].first=dict[poll[i]];
		ans[i].second=poll[i];
	}
	sort(ans.begin(),ans.end());
	reverse(ans.begin(),ans.end());
	vector<string> A(1);
	A[0]=ans[0].second;
	for(int i=1;i<ans.size();i++){
		if(ans[i].first==ans[i-1].first)A.push_back(ans[i].second);
		else break;
	}
	sort(A.begin(),A.end());
	for(int i=0;i<A.size();i++){
		cout<<A[i]<<endl;
	}

}


Measured memory_bytes: 31600
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

LL f(LL b,LL n){
    if(n<b) return n;
    else return f(b,floor(n/b))+n%b;
}


int main(){
    LL n,s;
    cin >> n >> s;
    if(n<s){
        puts("-1");
        return 0;
    }
    if(n==s){
        cout << n+1 << endl;
        return 0;
    }
    for(LL b=2;b<=sqrt(n);b++){
        if(s==f(b,n)){
            cout << b << endl;
            return 0;
        }
    }
    LL ans=LINF;
    for(LL p=1;p<sqrt(n);p++){
        if((n-s)%p==0&&f((n-s)/p+1,n)==s){
            ans=min((n-s)/p+1,ans);
        }
    }
    if(ans!=LINF){
        cout << ans << endl;
        return 0;
    }
    puts("-1");
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int> vi;

typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define REP(i,l,r) for(int i=l;i>=r;i--)
#define fi first
#define se second
#define eb emplace_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define int ll
const int mod = 1e9+7 ;

int n,m,a,b;
int fft[200001], fft_sz = 1;
int fact(const int& n){
	for(;n > fft_sz; ++fft_sz) fft[fft_sz+1] = (fft[fft_sz]*(fft_sz+1)) % mod;
	return fft[n];
}
int mul (const int& a, const int& b){
	return a * b %mod;
}
int mi(const int& a, const int& b){
	int ans = (a-b) % mod;
	return (ans < 0 ? ans + mod : ans);
}
int binpow(int a, int b){
	int res = 1;
	while(b){
		if (b & 1) res = mul(res,a);
		a = mul(a,a), b >>= 1;
	}
	return res;
}
int divide(const int& a, const int& b){
	assert(b > 0);
	return mul(a,binpow(b,mod-2)); 
}
int c(const int& a, const int& b){
	assert(b >= a);
	return divide(fact(b), mul(fact(a), fact(b-a)));
}
int path0(const int& n, const int& m){
	return c(n-1, n+m-2);
}
int path(const int& r, const int& c, const int& row, const int& col){
	return path0(row-r+1, col-c+1);
}

signed main() {
	fastio ;
	fft[0] = fft[1] = 1LL;
	cin >> n >> m >> a >> b;
	int ans = path0(n,m);
	for(int i = 0, r = n, c = b; i < a; ++i, --r){
		ans = mi(ans, mul(path(1,1 ,r,c), path(r,c+1, n,m)));
	}
	cout << (ans % mod) << endl;
}



Measured memory_bytes: 5164
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n; cin>>n;
  int ans=0;
  int c[100], v[100];
  for(int i=0; i<n; i++){
    cin>>v[i];
  }
  for(int i=0; i<n; i++){
    cin>>c[i];
  }
  for(int i=0; i<n; i++){
    ans+=max(0, v[i]-c[i]);
  }
  cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define llong long long 
typedef struct data{
	int h;
	int w;
	int t;
}data;
int H, W, N;
int HP = 1;
int cost = 0;
int area[1000][1000];
bool cannnot[1000][1000];
bool check[1000][1000];
int nh[4] = {1, 0, -1, 0};
int nw[4] = {0, 1, 0, -1};
pair<int, int> start;
queue<data> q;

void solve(pair<int, int> p){
	data fd;
	fd.h = p.first;
	fd.w = p.second;
	fd.t = 0;

	q.push(fd);

	while(HP <= N){
		data sd = q.front(); q.pop();
		int nowh = sd.h;
		int noww = sd.w;
		if(area[nowh][noww] == HP){
			cost += sd.t;
			while(!q.empty()){
				q.pop();
			}
			HP++;
			data now;
			now.h = sd.h;
			now.w = sd.w;
			now.t = 0;
			q.push(now);
			fill_n(*check, 1000 * 1000, false);
		}else{
			for(int i = 0; i < 4; i++){
				data next;
				next.h = nowh + nh[i];
				next.w = noww + nw[i];
				next.t = sd.t + 1;
				if(next.h < 0 || next.w < 0 || next.h >= H || next.w >= W) continue;
				if(cannnot[next.h][next.w] || check[next.h][next.w]) continue;

				check[next.h][next.w] = true;
				q.push(next);
			}
		}
	}

	return;
}

int main(){
	fill_n(*area, 1000 * 1000, 0);
	fill_n(*check, 1000 * 1000, false);
	fill_n(*cannnot, 1000 * 1000, false);
	cin >> H >> W >> N;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			char in;
			cin >> in;
			if(in == 'S') start = make_pair(i, j);
			if(1 <= (int)in - 48 && (int)in - 48 <= 9) area[i][j] = (int)in - 48;
			if(in == 'X') cannnot[i][j] = true;
		}
	}

	solve(start);
	cout << cost << endl;
	return 0;
}

Measured memory_bytes: 9000
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

const int N=200000+19;
const int Top=1e6+19;

int A[N],val[Top*2];
int n,m,S,sum;

int main(){
	n=IN();
	For(i,1,n) A[i]=IN();
	m=IN();
	S=Top;
	For(i,0,Top) val[S+i]=i;
	For(i,3,n){
		for (int j=1;j<=A[i];j++) val[S-j]=val[S+j];
		S-=A[i];
		sum+=A[i];
	}
	while (m--){
		A[n]=IN();
		if (A[n]>Top){
			printf("%d\n",A[1]-A[2]+A[n]-sum);
		} else{
			printf("%d\n",A[1]-A[2]+val[S+A[n]]);
		}
	}
}

Measured memory_bytes: 10752
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

count = 0
for i in range(q):
    t = T[i]
    left = 0
    right = len(S) - 1
    while left <= right:
        mid = (right + left) // 2
        if S[mid] == t:
            count += 1
            break
        elif S[mid] < t:
            left = mid + 1
        else:
            right = mid - 1
print(count)


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

int N;
int A[20];
int x[20][20];
int y[20][20];

int counter(int x) {
  if (x == 0) return 0;
  return counter(x >> 1) + (x & 1);
}

int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    for (int j = 0; j < A[i]; j++) {
      cin >> x[i][j] >> y[i][j];
    }
  }
  
  int bits;
  bool ok;
  int ans = 0;
  
  for (bits = 0; bits < (1 << N); bits++) {
    ok = true;
    for (int i = 1; i <= N; i++) {
      if ( !((bits >> (i - 1)) & 1) ) continue;
      for (int j = 0; j < A[i]; j++) {
        if ( ((bits >> (x[i][j] - 1)) & 1) ^ y[i][j] ) {ok = false;}
      }
    }
    if (ok) {ans = max(ans, counter(bits));}
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int n,m,i,j,b[120][120],x=0,y=0;
char a;
while(1){
scanf("%d %d\n",&n,&m);
if(n==0 && m==0){
break;
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
b[i][j]=0;
}
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
scanf("%c",&a);
if(a=='>'){
b[i][j]=1;
}
else if(a=='v'){
b[i][j]=2;
}
else if(a=='^'){
b[i][j]=3;
}
else if(a=='<'){
b[i][j]=4;
}
else{
b[i][j]=0;
}
}
scanf("\n");
}
while(1){
if(b[x][y]==0 || b[x][y]==-1){
break;
}
if(b[x][y]==1){
b[x][y]=-1;
y++;
}
else if(b[x][y]==2){
b[x][y]=-1;
x++;
}
else if(b[x][y]==3){
b[x][y]=-1;
x--;
}
else if(b[x][y]==4){
b[x][y]=-1;
y--;
}
}
if(b[x][y]==-1){
printf("LOOP\n");
}
else{
printf("%d %d\n",y,x);
}
x=0,y=0;
}
return 0;
}


Measured memory_bytes: 1932
N, M, Rs = map(int, input().split())
R = list(map(int, input().split()))
D = [[float("inf")] * (N+1) for i in range(N+1)]
for i in range(M):
    a, b, c = map(int, input().split())
    D[a][b] = D[b][a] = c

for k in range(N+1):
    for i in range(N+1):
        for j in range(N+1):
            D[i][j] = min(D[i][j], D[i][k]+D[k][j])


def full(L):
    if len(L) == 1:
        return [L]
    else:
        L2 = []
        for i in range(len(L)):
            L2.extend([[L[i]] + Lc for Lc in full(L[:i] + L[i+1:])])
        return L2


L = full(R)
ans = float("inf")
for l in L:
    a = 0
    for i in range(Rs-1):
        a += D[l[i]][l[i+1]]
    ans = min(ans, a)

print(ans)


Measured memory_bytes: 105816
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

bool Bellman_Ford(int V, int S, vector<pair<pair<int,int>,int>> &edge, vector<int> &dis){
	dis.clear();
	dis.resize(V,INF);
	dis[S] = 0;
	
	for(int i = 0; i < V; i++){
		bool flag = false;
		for(int j = 0; j < edge.size(); j++){
			if(dis[edge[j].first.first] != INF && dis[edge[j].first.second] > dis[edge[j].first.first] + edge[j].second){
				dis[edge[j].first.second] = dis[edge[j].first.first] + edge[j].second;
				flag = true;
				if(i == V-1) return true;
			}
		}
		if(!flag) break;
	}
	
	return false;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, M, P;
	vector<pair<pair<int,int>,int>> edge1, edge2, edge3;
	vector<int> dis1, dis2, dis3;
	int A, B, C;
	
	cin>>N>>M>>P;
	
	for(int i = 0; i < M; i++){
		cin>>A>>B>>C;
		A--, B--;
		// edge3.push_back(make_pair(make_pair(A,B),P-C));
		edge1.push_back(make_pair(make_pair(B,A),P-C));
	}
	
	Bellman_Ford(N,N-1,edge1,dis1);
	// Bellman_Ford(N,0,edge3,dis3);
	
	// for(int i = 0; i < N; i++){
		// cout<<"i = "<<i<<" dis1 = "<<dis1[i]<<endl;
		// cout<<"i = "<<i<<" dis3 = "<<dis3[i]<<endl;
	// }
	for(int i = 0; i < M; i++){
		// cout<<"i = "<<i<<endl;
		// cout<<edge1[i].first.first<<" "<<edge1[i].first.second<<endl;
		// cout<<dis1[edge1[i].first.first]<<" "<<dis1[edge1[i].first.second]<<endl;
		if(dis1[edge1[i].first.first] != INF && dis1[edge1[i].first.second] != INF ){
		   // dis3[edge1[i].first.first] != INF && dis3[edge1[i].first.second] != INF ){
			edge2.push_back(make_pair(make_pair(edge1[i].first.second,edge1[i].first.first),edge1[i].second));
		}
	}
	
	if(Bellman_Ford(N,0,edge2,dis2)) cout<<-1<<endl;
	else cout<<max(0ll,-dis2[N-1])<<endl;
	
	return 0;
}

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

#define pb push_back
#define ss second
#define ff first
#define N 100005
#define ll long long
#define mid(a,b) (a+b)/2
#define pii pair<ll,ll>

using namespace std;

ll mod = 1e9+7;
ll n,k;
ll fc[N],a[N],sum;

ll big(ll a,ll b){
	if(b == 0) return 1;
	ll x = big(a,b / 2);
	if(b % 2) return (((x * x) % mod) * a) % mod;
	return (x * x) % mod;
}

ll norm(ll x){
	if(x < 0) x += mod;
	else if(x >= mod) x -= mod;
	
	return x;
}

ll C(ll n,ll k){
	return (fc[n] * big((fc[n - k] * fc[k]) % mod,mod - 2)) % mod;
}

int main()
{
	scanf("%lld%lld",&n,&k);
	fc[0] = 1;
	for(int i = 1;i <= n;i++)
		fc[i] = (fc[i - 1] * i) % mod;
	for(int i = 1;i <= n;i++) scanf("%lld",&a[i]);
	sort(a + 1,a + n + 1);
	
	for(int i = n;i >= k;i--){
		sum += ((a[i] * C(i - 1,k - 1)) % mod);
		sum %= mod;
	}
	for(int i = 1;i <= n - k + 1;i++){
		sum -= ((a[i] * C(n - i,k - 1)) % mod);
		sum = norm(sum);
	}
	printf("%lld",sum);
}

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

int main() {
	int h, m, s, sum;
	cin >> sum;
	h = sum / 3600;
	m = (sum - (3600 * h)) / 60;
	s = sum % 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>
#include <string.h>

#define MAX 100010

// int ans[MAX] = {};
 
int main() {
    int K, X;

    scanf("%d %d", &K, &X);

    int hidari, migi;

    hidari = X - K;
    migi = X + K;

    if(hidari < -1000000) hidari = -1000000;
    if(migi > 1000000) migi = 1000000;

    int tmp = hidari;
    for(int i = 0;i < migi - hidari - 1;i++) {
        tmp += 1;
        printf("%d ", tmp);
    }

    printf("\n");

    return 0;
}

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

int main()
{
	long long int i,j,k,l,m,n,nd;
	cin>>n;
	nd=n;
	long long int ht=log2(n),sum=0;
	for(i=ht;i>=0;i--)
	{
		sum=sum+(long long int)pow(2,i);
	}
	cout<<sum;
}

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

int main() {
    string S;
    cin >> S;
    int res1 = 0, res2 = 0;

    for(int i=0; i<S.size(); ++i) {
        if(i % 2) {
            if(S[i] == '0') ++res1;
        } else {
            if(S[i] == '1') ++res1;
        }
    }

    for(int i=0; i<S.size(); ++i) {
        if(i % 2) {
            if(S[i] == '1') ++res2;
        } else {
            if(S[i] == '0') ++res2;
        }
    }

    cout << min(res1, res2) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int a[maxn];
int dp[maxn];		//dp[i]:´ÓÆðµãµ½iµÄ×îÐ¡·ÑÓÃ 

int main() {
	int n;cin>>n;
	for(int i = 1;i <= n;i++) cin>>a[i];
	dp[1] = 0;
	dp[2] = abs(a[2] - a[1]);
	for(int i = 3;i <= n;i++) {	
		dp[i] += min(dp[i-1] + abs(a[i] - a[i-1]),dp[i-2] + abs(a[i] - a[i-2]));
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
typedef struct{
  char alf;
  int num;
  int beforei;
}key;
int partition(key *A,int p,int r){
  int i,j,x;
  key kari; 
  x=A[r].num;
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].num<=x){
      i++;
      kari=A[i];
      A[i]=A[j];
      A[j]=kari;      
    }
  } 
  kari=A[i+1];
  A[i+1]=A[r];
  A[r]=kari;   
  return i+1;
}
void quicksort(key *A,int p,int r){
  int q; 
  if(p<r){
    q=partition(A,p,r);
    quicksort(A,p,q-1);
    quicksort(A,q+1,r);
  }  
}
int main(){
  int i,n,j,point=0;
  key A[100000];
 
  scanf("%d%*c",&n);
 
  for(i=0;i<n;i++){
 
    scanf("%c%d%*c",&A[i].alf,&A[i].num);
    A[i].beforei=i;
 
  }
  quicksort(A,0,n-1);
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
     
      if(A[i].num==A[j].num&&A[i].beforei>A[j].beforei){
    printf("Not stable\n");
    point++;
    break;
      }
      if(point==1)break;
    }
    if(point==1)break;
  }
  if(point==0) printf("Stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",A[i].alf,A[i].num);
  }
  return 0; 
}

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

int main() {
    string S; cin >> S;
    sort(S.begin(), S.end());
    if (S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  __int128_t ans = 1;
  rep(i, n) {
    if (a[i] == 0) {
      cout << 0 << '\n';
      return 0;
    }
  }
  rep(i, n) {
    ans *= a[i];
    if (ans > INF) {
      cout << -1 << '\n';
      return 0;
    }
  }
  cout << (ll)ans << '\n';




  
  return 0;
}

Measured memory_bytes: 3992
#include<bits/stdc++.h>
#include<stdio.h>
#define debug(x) cout << '>' << #x << ':' << x << endl;

#define nitro ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
const int INF = 1e9+5;
using namespace std;
using ll = unsigned long long int;
const ll mod = 998244353; 

ll ncr(int n, int r = 2)
{
	ll ans = (n*(n-1))/r;
	return ans;
} 
int main()
{
	

	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	//clock_t time_req;time_req = clock(); 
	int k; cin >> k;
	int a, b;
	cin >> a >> b;
	bool flag = false;
	for(int i = a; i <= b; i++)
	{
		if(i%k==0)
		{
			flag = true;
			break;
		}
	}
	if(flag) cout << "OK" << '\n';
	else cout << "NG" << '\n';


	//time_req = clock()- time_req;cout << "Time Complexity:"<< \n'<<(float)time_req/CLOCKS_PER_SEC << " seconds" << endl; 
	return 0;
 }
  	

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


int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<double>> lab(n,vector<double>(3,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++) cin>>lab[i][j];
    }
    if(m==0){
        cout<<0<<endl;
        return 0;
    }
    double res=0;
    unsigned int comb=(1<<m)-1;
    while(comb<1<<n){
        vector<int> index;
        for(int i=0;i<n;i++){
            if(comb & (1<<i))
                index.push_back(i);

        }
        double sum=0;
        for(int i=0;i<m;i++)
            for(int j=i+1;j<m;j++){
                for(int r=0;r<3;r++){
                    double dis=lab[index[i]][r]-lab[index[j]][r];
                    dis*=dis;
                    sum+=dis;
                }


            }
        res=max(res,sum);
        unsigned int x=comb&-comb,y=comb+x;
        comb=(((comb&~y)/x)>>1)|y;
    }
    cout<<fixed<<setprecision(10);
    cout<<res<<endl;
    return 0;

}

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

int main()
{
  int n, m, s, c;
  cin >> n >> m;
  vector<int> ans(n, 0);
  vector<bool> input(n, false);
  if (n == 1) ans[0] = 0;
  else ans[0] = 1;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    s--;
    if ((input[s] && ans[s] != c) || (s == 0 && c == 0 && n != 1)) {
      cout << -1 << endl;
      return 0;
    }
    input[s] = true;
    ans[s] = c;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,m,cnt,ans=0,k[35]={},a[35][35]={};
  cin >> n >> m;
  map<int,int> mp;
  for(int i=0; i<n; i++) {
    cin >> k[i];
    for(int j=0; j<k[i]; j++) {
      cin >> a[i][j];
      mp[a[i][j]]++;
    }
  }
  for(auto p:mp) {
    if(p.second==n) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long su[100000010] = { 0 };
long sai;
int main()
{
	long n, k;
	long i, j;
	long a;
	while (cin >> n >> k, n != 0 && k != 0)
	{
		for (i = 1; i <= n; i++)
		{
			cin >> a;
			su[i] = su[i - 1] + a;
		}
		sai = 0;
		for (i = k; i <= n; i++)
		{
			if (sai < su[i] - su[i - k])
			{
				sai = su[i] - su[i - k];
			}
		}
		cout << sai << endl;
	}
	return 0;
}

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

int main(){
  string key;
  string st;
  int n;
  int outp = 0;
  cin >> key >> n;
  for(int m = 0;m<n;m++){
    cin >> st;
    st = st + st;
    if(st.find(key) != -1){
      outp += 1;
    }
  }
  cout << outp << endl;
}

Measured memory_bytes: 1212
lines=gets.split(' ')
 
line=[]
 
lines.each do |b|
  line <<b.to_i 
end

 
H1=line[0]
M1=line[1]
H2=line[2]
M2=line[3]
K=line[4]
 
 
sleep=60*H2+M2
wake=60*H1+M1
 
p sleep-wake-K
 
 
 

Measured memory_bytes: 14340
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)


def solve(N: int, A: "List[int]"):
    c=[0] * N
    for i in range(N):
        c[A[i]-1] += 1

    kmax=0
    for i in range(N):
        kmax += c[i] * (c[i]-1) // 2

    #print("#",c, kmax)
    for i in range(N):
        toruc = c[A[i]-1]
        if toruc == 0:
            print(kmax)
        else:
            print(kmax-toruc+1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 30196
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
bool chmin(ll& a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll& a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
typedef string::const_iterator State;
int expression(State& begin);
int factor(State& begin);
// 乗算除算の式をパースして、その評価結果を返す。
int term(State& begin);
// 数字の列をパースして、その数を返す。
int number(State& begin);
int number(State& begin) {
    int ret = 0;

    while (isdigit(*begin)) {
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }

    return ret;
}
int factor(State& begin) {
    if (*begin == '(') {
        begin++; // '('を飛ばす。
        int ret = expression(begin);
        begin++; // ')'を飛ばす。
        return ret;
    }
    else {
        return number(begin);
    }
}
int term(State& begin) {
    int ret = factor(begin);

    for (;;) {
        if (*begin == '*') {
            begin++;
            ret *= factor(begin);
        }
        else if (*begin == '/') {
            begin++;
            ret /= factor(begin);
        }
        else {
            break;
        }
    }

    return ret;
}
int expression(State& begin) {
    int ret = term(begin);

    for (;;) {
        if (*begin == '+') {
            begin++;
            ret += term(begin);
        }
        else if (*begin == '-') {
            begin++;
            ret -= term(begin);
        }
        else{
            break;
        }
        
    }

    return ret;
}
int main() {
	cin>>n;
	rep(i,n){
    string S;
    cin >> S;
    S=S.substr(0,S.length()-1);
    State s=S.begin();
    cout << expression(s) << endl;
	}
}


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

typedef long long ll;
typedef pair<int, int> pii;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

void use_cio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto x : V) os << x << ", ";
  return os << "]";
}

//--------------------------------------------------//

int main() {
  use_cio();
  int n;
  cin >> n;
  vector<int> va(n);
  rep(i, n) cin >> va[i];
  int cnt = 0;
  repp(i, 1, n - 1) if (va[i] > min({va[i - 1], va[i], va[i + 1]}) &&
                        va[i] < max({va[i - 1], va[i], va[i + 1]})) cnt++;
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


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

  int n;
  cin>>n;

  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
  }

  auto q=p;
  rep(i,n-1){
    q[i+1]+=q[i];
  }
  auto qq=q;
  rep(i,n) qq[i]*=2;

  auto r=p;
  reverse(all(r));
  rep(i,n-1){
    r[i+1]+=r[i];
  }
  auto rr=r;
  rep(i,n) rr[i]*=2;

  ll ans=INF;
  for(int i=1;i<=n-3;i++){
    ll x=q[i];
    ll y=r[n-2-i];
    int a=lb(qq,x);
    int c=lb(rr,y);
    chmin(ans,max({q[a],x-q[a],r[c],y-r[c]})-min({q[a],x-q[a],r[c],y-r[c]}));
    if(a>0){
    chmin(ans,max({q[a-1],x-q[a-1],r[c],y-r[c]})-min({q[a-1],x-q[a-1],r[c],y-r[c]}));
    }
    if(c>0){
    chmin(ans,max({q[a],x-q[a],r[c-1],y-r[c-1]})-min({q[a],x-q[a],r[c-1],y-r[c-1]}));
    }
    if(a>0 && c>0){
    chmin(ans,max({q[a-1],x-q[a-1],r[c-1],y-r[c-1]})-min({q[a-1],x-q[a-1],r[c-1],y-r[c-1]}));
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 11128
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int INF = 1<<30;
const ll LINF = 1LL<<61;

int n, m;
vector<vector<int>> G;

int func(int cur, int used)
{
    if(used == (1 << n) - 1)
    {
        return 1;
    }
    int ret = 0;
    for(auto to:G[cur])
    {
        if((used & (1 << to))) continue;
        ret += func(to, used | (1 << to));
    }
    return ret;
}

int main()
{
    cin >> n >> m;
    G.assign(n, vector<int>(0));
    rep(i,m)
    {
        int u, v;
        cin >> u >> v;
        --u; --v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    cout << func(0, 1) << endl;

    return 0;
}

Measured memory_bytes: 3620
N = int(input())

tasks = []
for i in range(N):
    A, B = (int(i) for i in input().split())
    tasks.append((A,B))

tasks = sorted(tasks, key=lambda x:x[1])

tt = 0
flag = False
for tk in tasks:
    tt += tk[0]
    if tt > tk[1]:
        flag = True
        break

if flag:
    print("No")
else:
    print("Yes")

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

using namespace std;

int main()
{
    vector<char> ans;
    char c;

    while (cin >> c) {
        if (c == '0' || c == '1') {
            ans.push_back(c);
        } else if (c == 'B') {
            if (!ans.empty()) {
                ans.pop_back();
            }
        }
    }
    for (auto c : ans) {
        cout << c;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] map = new char[h][w];
        for (int i = 0; i < h; i++) {
            map[i] = sc.next().toCharArray();
        }

        int[][] dd = new int[][]{{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (map[i][j] == '.') continue;

                boolean hasS = false;
                for (int[] d :dd) {
                    int x = i + d[0];
                    int y = j + d[1];
                    if (x >= 0 && x < h && y >= 0 && y< w && map[x][y] == '#') hasS = true;
                }

                if (!hasS) {
                    System.out.println("No");
                    return;
                }
            }
        }

        System.out.println("Yes");

    }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K,A,B,i;
  cin>>K>>A>>B;
  bool ans=false;
  for(i=A;i<B+1;i++){
    if(i%K==0)
      ans=true;
  }
  if(ans)
    cout<<"OK"<<endl;
  else
    cout<<"NG"<<endl;
}
      

Measured memory_bytes: 3596
def calc():
  l, r = map(int,input().split())
  if r - l >= 2019:
    return 0
  ans = 2019
  for i in range(l, r):
    for j in range(i + 1, r + 1):
      n = (i * j) % 2019
      if n == 0:
        return 0
      elif n < ans:
        ans = n
  return ans
 
print(calc())

Measured memory_bytes: 3060
#include <iostream>
     #include <string>
     #include <algorithm>
     using namespace std;
     
     int main() {
     string s;
     string t;
     cin >> s;
     cin >> t;
     sort(s.begin(), s.end());
     sort(t.begin(), t.end(), greater<char>());
     if(s < t) cout << "Yes" << endl;
     else cout << "No" << endl;
     }

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

const int MAXN = 200;
int sum[MAXN];
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vector<pair<int, int>> edges;
	if (N % 2 == 0) {
		for (int i = 1; i <= N; i++) {
			for (int j = i+1; j <= N; j++) {
				if (i + j == N+1) continue;
				edges.emplace_back(i, j);
			}
		}
	} else {
		for (int i = 1; i <= N; i++) {
			for (int j = i+1; j <= N; j++) {
				if (i + j == N) continue;
				edges.emplace_back(i, j);
			}
		}
	}
	for (auto it : edges) {
		int a = it.first, b = it.second;
		assert(a < b);
		sum[a] += b;
		sum[b] += a;
	}
	for (int i = 1; i <= N; i++) {
		assert(sum[i] == sum[1]);
	}
	sort(edges.begin(), edges.end());
	assert(unique(edges.begin(), edges.end()) == edges.end());
	assert(int(edges.size()) >= N-1);
  	cout << edges.size() << '\n';
	for (auto it : edges) {
		int a = it.first, b = it.second;
		cout << a << ' ' << b << '\n';
	}

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
int main(){
    ll a,b;
    cin>>a>>b;
    ll g = gcd(a,b);
    int ans = 1;
    REP(i,2,1000003){
        if(g%i==0){
            ++ans;
            while(g%i==0)g/=i;
        }
    }
    if(g>1)++ans;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
int main() {
    int x[MAX_N] = {}, y[MAX_N] = {};
    int n, q;
    scanf("%d%d", &n,&q);
    ll ans = (ll)(n-2)*(n-2);
    srep(i,2,n){
        x[i] = n;
        y[i] = n;
    }
    int xx = n;
    int yy = n;
    while(q--){
        int t, z;
        scanf("%d%d", &t,&z);
        if(t == 1){
            if(z < xx){
                ans -= yy - 2;
                srep(i,z+1,xx) x[i] = yy;
                xx = z;
            }else{
                ans -= x[z] - 2;
            }
        }else{
            if(z < yy){
                ans -= xx - 2;
                srep(i,z+1,yy) y[i] = xx;
                yy = z;
            }else{
                ans -= y[z] - 2;
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}




Measured memory_bytes: 5424
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;// 1000000007;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL K, N;
	cin >> K >> N;
	LL ans = K;
	LL A0;
	cin >> A0;
	LL prev = A0;
	for (LL n = 1; n < N; n++) {
		LL a;
		cin >> a;
		ans = min(ans, K - (a - prev));
		prev = a;
	}
	ans = min(ans, K - ((K + A0) - prev));
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
#define vv(a,b) vector< vector<int> > v(a,vector<int>(b,0));
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+1;

int main()
{
    ll x,y;
    cin>>x>>y;
    ll ans=0;
    ll now=x;
    while(now<=y)
    {
        now*=2;
        ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int b[9];
int main(){
    for(int i=0;i<9;i++)b[i]=0;
    cin>>n;
    int cont=0;
    for(int i=0;i<n;i++){
        int a;cin>>a;
        if(a<400){
            b[0]=1;
        }else if(a<800){
            b[1]=1;
        }else if(a<1200){
            b[2]=1;
        }else if(a<1600){
            b[3]=1;
        }else if(a<2000){
            b[4]=1;
        }else if(a<2400){
            b[5]=1;
        }else if(a<2800){
            b[6]=1;
        }else if(a<3200){
            b[7]=1;
        }else{
            b[8]++;
        }
    }
    int ans=0;
    for(int i=0;i<8;i++){
        if(b[i]==1)ans++;
    }
    cout<<((ans!=0)?ans:1)<<" "<<ans+b[8]<<endl;
    return 0;
}

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

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

using namespace std;

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

	vector<int>a(100005);

	rep(i, n){
		int b;
		cin >> b;
		if (b-1>=0)
			a[b - 1]++;
		a[b]++;
		a[b + 1]++;
	}

	int ans = 0;
	rep(i, 100005)
		ans = max(a[i], ans);

	cout << ans << endl;

	return 0;
}


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

int main(){
    int x, y;

    while(1){
        scanf("%d %d", &x, &y);
        if(x == 0 && y == 0){
            break;
        }
        if(x > y){
            swap(x, y);
        }
        printf("%d %d\n", x, y);
    }
    
    return 0;
}


Measured memory_bytes: 3180
#include <iostream>
#include<queue>
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int a[110000];
    fill(a,a+n+1,-1);
    a[0]=0;
    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int v=que.front();
        que.pop();
        for(int i=1;v+i<=n;i*=6){
            if(a[v+i]==-1){
                a[v+i]=a[v]+1;
                que.push(v+i);
            }
        }
        for(int i=1;v+i<=n;i*=9){
            if(a[v+i]==-1){
                a[v+i]=a[v]+1;
                que.push(v+i);
            }
        }
    }
    cout<<a[n]<<endl;
    return 0;
}


Measured memory_bytes: 896
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
inf = 10 ** 4 + 1
dp = [inf] * n
dp[0] = 0
for i in range(1,n):
    H = h[i]
    dp[i] = min([dp[j] + abs(h[j] - H) for j in range(max(0, i - k), i)])
print(dp[-1])

Measured memory_bytes: 13928