akhauriyash/Code-Regression huggingface dataset:
program candidates_of_no_shortest_paths
  implicit none
  integer, parameter :: infty = 1e9
  integer :: n, m, g(100, 100) = infty, i, j, k, x = 0
  integer, dimension(1000) :: a = 0, b = 0, c = 0
  read(*,*) n, m
  do i = 1, n
    g(i, i) = 0
  end do
  do i = 1, m
    read(*,*) a(i), b(i), c(i)
    g(a(i), b(i)) = c(i)
    g(b(i), a(i)) = c(i)
  end do
  do k = 1, n
    do i = 1, n
      do j = 1, n
        g(i, j) = min(g(i, j), g(i, k) + g(k, j))
      end do
    end do
  end do
  do k = 1, m
    do i = 1, n
      do j = 1, n
        if (g(i, a(k)) + c(k) + g(b(k), j) == g(i, j)) goto 100
      end do
    end do
    x = x + 1
  100 end do
  write(*,'(i0)') x
end program candidates_of_no_shortest_paths

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()

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

  int a, b, c;
  cin >> a >> b >> c;

  if(a == b + c) {
    cout << "Yes" << endl;
  } else if(b == a + c) {
    cout << "Yes" << endl;
  } else if(c == a + b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const int INF=100000000;

typedef pair<int,int> pi;
typedef pair<int,pi> P;

struct edge{ int to,cost; };

vector<edge> G[100];

int main()
{
    while(1)
    {
        int n,m,l,k,a,h;
        scanf(" %d %d %d %d %d %d", &n, &m ,&l, &k, &a, &h);
        if(n==0) break;

        rep(i,n) G[i].resize(0);

        //??????????¨?????????????
        int cold[100]={0};
        rep(i,l)
        {
            int t;
            scanf(" %d",&t);
            cold[t]=1;
        }

        //???????§????
        rep(i,k)
        {
            int x,y,z;
            scanf(" %d %d %d", &x, &y, &z);
            //printf("x,y,z=%d, %d, %d\n",x,y,z);
            G[x].pb(edge{y,z});
            G[y].pb(edge{x,z});
        }

        int d[100][101];
        fill(d[0],d[100],INF);
        d[a][m]=0;

        priority_queue<P,vector<P>,greater<P>> que;
        que.push(P(0,pi(a,m)));
        while(!que.empty())
        {
            P p=que.top();
            que.pop();
            int v=p.se.fi;
            int r=p.se.se;
            //printf("%d::v=%d, r=%d\n",p.fi,v,r);
            if(d[v][r]<p.fi) continue;
            rep(i,G[v].size())
            {
                edge e=G[v][i];
                //printf("now V=%d, e.to=%d, e.cost=%d\n",v,e.to,e.cost);
                if(r-e.cost>=0 && d[e.to][r-e.cost]>d[v][r]+e.cost)
                {
                    d[e.to][r-e.cost]=d[v][r]+e.cost;
                    que.push(P(d[e.to][r-e.cost],pi(e.to,r-e.cost)));
                    //printf(" push: %d, (%d,%d)\n",d[e.to][r-e.cost],e.to,r-e.cost);
                    if(cold[e.to])
                    {
                        for(int j=1; r-e.cost+j<=m; ++j)
                        {
                            if(d[e.to][r-e.cost+j]>d[e.to][r-e.cost]+j)
                            {
                                d[e.to][r-e.cost+j]=d[e.to][r-e.cost]+j;
                                que.push(P(d[e.to][r-e.cost+j],pi(e.to,r-e.cost+j)));
                                //printf("push: %d, (%d,%d)\n",d[e.to][r-e.cost+j],e.to,r-e.cost+j);
                            }
                        }
                    }
                }
            }

        }

        int ans=INF;
        rep(i,m+1)
        {
            //printf(" %d: %d\n",i,d[h][i]);
            ans=min(ans,d[h][i]);
        }

        if(ans==INF) printf("Help!\n");
        else printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 3484
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   let ans = xs[0] + xs[1];
   if(ans%2 == 0){
     ans = ans/2;
     console.log(ans);
   }else{
     console.log('IMPOSSIBLE');
   }   
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 21064
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int main()
{
  int k,x;
  cin>>k>>x;
  if(k*500>=x) puts("Yes");
  else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define Amr_Abdelazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define vll vector<ll>
#define vvll vector<vector<ll> >
#define vpll vector<pair<ll,ll> >
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i,n)   for(int i=0;i<n;i++)
#define repp(i,s,n)   for(int i=s;i<=n;i++)
#define print(v) {for(auto i:v)cout<<i<<" ";cout<<"\n";}
#define mkp make_pair
#define clr(ar,v) memset(ar,v,sizeof(ar));
#define TC ll amr_abdelazim;cin>>amr_abdelazim;while(amr_abdelazim--)
#define popcnt(x) __builtin_popcount(x)
#define EPS 1e-9
#define INF 1e17
using namespace std;
const int mod = 1000000007;
const int N = 100000+9;
const double pi = acos(-1);
class cmp{
public:
	bool operator() (pair<ll, pll> &A, pair<ll, pll> &B){
		return A > B;
	}
};
bool by_sec(pll &A, pll &B){
	return A.second < B.second;
}
ld dist(pll p1, pll p2){
	return (ld)sqrt((ld)(p1.first - p2.first)*(p1.first - p2.first) + (ld)(p1.second - p2.second)*(p1.second - p2.second));
}
ll fact[1000009], inv[1000009];
ll fp(ll a, ll b){
	if (b == 0)
		return 1;
	ll ans = fp(a, b / 2);
	ans = (ans * ans) % mod;
	if (b % 2 != 0)
		ans = (ans * (a % mod)) % mod;
	return ans;
}
void FacInv(ll n){
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++)
	{
		fact[i] = ((i%mod) * fact[i - 1] % mod) % mod;
		inv[i] = fp(fact[i], mod - 2);
	}
}
ll ncr(ll n, ll r){
	return (((fact[n] * inv[r]) % mod) * inv[n - r]) % mod;
}

vpll v;
ll n,k;
ll dp[100+9][N];
ll fun(ll i, ll val){
	if (val <= 0)return 0;
	if (i >= n)return 1e15;	
	if (dp[i][val] == -1){

			dp[i][val] = min(fun(i + 1, val), v[i].second + fun(i + 1, val - v[i].first));

	}
	return dp[i][val];
}
int main()
{
	Amr_Abdelazim
	clr(dp, -1);
	cin >> n >> k;
	v.resize(n);
	rep(i, n){
		cin >> v[i].second >> v[i].first;
	}
	for (int i = 100000 + 1; i >= 0; i--){
		ll ans = fun(0, i);
		if (ans <= k)return cout << i, 0;
	}
	return 0;
}


Measured memory_bytes: 88832
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 18;

int n, m, k;

void solve(int test)
{
  cin >> n >> m;
  vector<int> a(m), d(n + 2, 0);
  d[0] = 1;
  for (int i = 0; i < m; ++i) {
    cin >> a[i];
  }
  int p = 0;
  for (int i = 0; i < n; ++i) {
    while (p < m && a[p] < i) ++p;
    if (p < m && i == a[p]) {
      continue;
    }
    d[i + 1] += d[i];
    d[i + 2] += d[i];
    if (d[i + 1] >= mod) {
      d[i + 1] -= mod;
    }
    if (d[i + 2] >= mod) {
      d[i + 2] -= mod;
    }
  }
  cout << d[n] << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
#include <list>
using namespace std;
 
int main()
{
   int n;
   cin>>n;
   long long result=1;
   for(int i=2;i<=n;i++){
     result*=i;
   }
   cout<<result<<endl;
   return 0;
}

Measured memory_bytes: 1156
#include <iostream>
using namespace std;
int IsPrime (int n)
{
    int i;

	if (n < 2){
        return 0;
	}else if (n == 2){
        return 1;
	}
	if (n % 2 == 0){
        return 0;
	}
	for (i = 3; i <= n / i; i += 2){
		if (n % i == 0){
            return 0;
		}
	}
    return 1;
}
int A[55556];
int main(int argc, char* argv[])
{
	int i=0;
	int a=7;
	while (true){
		if (IsPrime(a)){
			if (a%5==1){
				A[i++]=a;
			}
		}
		a++;
		if (i==55556){
			break;
		}
	}
	int N;
	cin>>N;
	for (i=0;i<N-1;i++){
		cout<<A[i]<<" ";
	}
	cout<<A[N-1]<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
// typedef long  l;
typedef pair<int,int> P;
const int INF=10000001;
const double PI=3.141592653589;


int main(){
  int n; cin>>n;
  vector<tuple<ll,ll,ll>> t(n);
  rep(i,n){
    ll x,y,h; cin>>x>>y>>h;
    get<0>(t[i])=h;
    get<1>(t[i])=x;
    get<2>(t[i])=y;
  }

  sort(t.begin(),t.end());
  int cx;
  int cy;
  ll H;

  rep(i,101){
    rep(j,101){
      ll Hh=get<0>(t[n-1])+(ll)abs(get<1>(t[n-1])-i)+(ll)abs(get<2>(t[n-1])-j);
      bool c=1;
      for(int k=n-1;0<=k;k--){
        ll nh=get<0>(t[k])+(ll)abs(get<1>(t[k])-i)+(ll)abs(get<2>(t[k])-j);
        if(get<0>(t[k])>0){
          if(nh!=Hh){
            c=0;
            break;
          }
        }else{
          if(nh<Hh){
            c=0;
            break;
          }
        }
      }
      if(c){
        cx=i;
        cy=j;
        H=Hh;
      }
    }
  }

  cout<<cx<<" "<<cy<<" "<<H<<endl;
  return 0;
}


Measured memory_bytes: 256
#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;

int main(){
	int n,r;cin>>n>>r;
	if (n >= 10){
		cout << r << endl;
	}
	else{
		cout << r + 100 * (10 - n) << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WvNINGS
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int n, w;
ll dp[105][N];
pair<int, int> ar[105];

ll solve(int i, int rem) {
    //cout << i << ' ' << rem << endl;
    if (i > n)return 0;
    if (~dp[i][rem])
        return dp[i][rem];
    ll ans = solve(i + 1, rem);
    if (rem >= ar[i].first) {
        ans = max(ans, solve(i + 1, rem - ar[i].first) + ar[i].second);
    }
    return dp[i][rem] = ans;
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> w;
    for (int i = 1; i <= n; i++) {
        int s, v; cin >> s >> v;
        ar[i] = { s, v };
    }
    memset(dp, -1, sizeof(dp));
    cout << solve(1, w);
    return 0;
}

Measured memory_bytes: 82304
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin>>a>>b;
  for(int i=0;i<a.size()-1;i++)
  	cout<<a[i]<<b[i];
  	cout<<a[a.size()-1];
   if(a.size()-b.size()==0)cout<<b[b.size()-1]<<endl;
  }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int n;
    cin >> n;
    vector<int>p(4);
    vector<int>t(4);
    rep(i,4)cin >> p[i];
    rep(i,4)cin >> t[i];
    int mi = inf;
    vector<int> dp(n+200,inf);
    dp[0] = 0;
    rep(i,4){
        for(int j=t[i];j<=n+100;j++){
            dp[j] = min(dp[j],dp[j-t[i]]+p[i]);
        }
        
    }
    
    for(int i=n;i<=n+101;i++){
        mi = min(mi,dp[i]);
    }
    cout << mi << endl;
    return 0;

}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<long double, long double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    ll k; cin >> k;
    ll x = k;
    k--;
    ll n = sqrt(k);
    int ans = 0;
    vector<int> ar(n+1,0);
    while (k % 2 == 0){
        ar[2]++;
        k /= 2;
    }
    for (int i = 3; i < n+1; i += 2){
        while (k % i == 0){
            ar[i]++;
            k /= i;
        }
        if (k == 1) break;
    }
    int cnt = 1;
    rep(i,n+1){
        cnt *= ar[i]+1;
        //rep(j,ar[i]) cout << i << endl;
    }
    if (k != 1) cnt *= 2;
    ans += cnt-1;
    n = sqrt(x);
    repp(i,n+1,2){
        ll y = x;
        while (y % i == 0){
            y /= i;
        }
        if (y < x && y % i == 1) ans++;
    }
    ans++;
    cout << ans << endl;
}

Measured memory_bytes: 4096
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define ll long long
ll sum[200005];
ll countPairs(ll arr[], ll n)
{
	ll cnt = 0;
    for(ll i =1;i<=n;){
    	ll up=upper_bound(arr+i,arr+n+1,arr[i])-arr;
    	cnt=cnt+(up-i)*(up-i-1)/2;
		if(arr[i]==0)
    		cnt+=(up-i);
    	i = up;
	}
	return cnt;
}
int main(){
	ll n = 0;
	memset(sum,0,sizeof(sum));
	cin>>n;
	for(ll i = 1 ;i <= n;i++){
		ll num = 0;
		cin>>num;
		sum[i] = sum[i-1] + num;
	}
	sort(sum+1 , sum+n+1);
	cout<<countPairs(sum,n);
	return 0;
} 

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

int main() {
	int i, j, n, p[100][2], te;
	char s[100][11], tmp[11];

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%s %d", s[i], &p[i]);
		p[i][1] = i + 1;
	}

	for (i = 1; i < n; i++) {
		for (j = 1; j < n; j++) {
			if (strcmp(s[j - 1], s[j]) > 0) {
				strcpy(tmp, s[j - 1]);
				strcpy(s[j - 1], s[j]);
				strcpy(s[j], tmp);
				te = p[j - 1][0];
				p[j - 1][0] = p[j][0];
				p[j][0] = te;
				te = p[j - 1][1];
				p[j - 1][1] = p[j][1];
				p[j][1] = te;
			}
		}
	}
	
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (strcmp(s[i], s[j]) == 0 && p[i][0] > p[j][0]) {
				strcpy(tmp, s[i]);
				strcpy(s[i], s[j]);
				strcpy(s[j], tmp);
				te = p[i][0];
				p[i][0] = p[j][0];
				p[j][0] = te;
				te = p[i][1];
				p[i][1] = p[j][1];
				p[j][1] = te;
			}
		}
	}

	for (i = 0; i < n; i++) printf("%d\n", p[i][1]);

	return 0;
}

Measured memory_bytes: 128
<?php
fscanf(STDIN, '%d %d %d', $n, $a, $b);
if ($a === 0) {
    $ans = 0;
} else {
    $ans = $a * intval(floor($n / ($a + $b))) + min($a, $n % ($a + $b));
}
echo $ans . PHP_EOL;

Measured memory_bytes: 4728
lis=[int(input())]
for i in range(1000):
    if lis[i]%2==0:
        a=lis[i]//2
        lis.append(a)
        def has_duplicates(x):
            return len(x) != len(set(x))
        if has_duplicates(lis)==True:
            break
    else:
        a=lis[i]*3+1
        lis.append(a)
        def has_duplicates(x):
            return len(x) != len(set(x))
        if has_duplicates(lis)==True:
            break
print(len(lis))

Measured memory_bytes: 9144
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
int q;
char str[maxn];
int a[maxn];
int sum[maxn];
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
	//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
	gg(n);
	gg(q);
	scanf("%s",str);
	rep(i,1,n)
	{
		if(str[i]=='C'&&str[i-1]=='A')
		{
			a[i]=1;
		}
		sum[i]=sum[i-1]+a[i];
	}
	int l,r;
	while(q--)
	{
		gg(l);
		gg(r);
		l--;
		r--;
		int ans=sum[r]-sum[l];
		printf("%d\n",ans);
	}

	
	
	
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 7424
import sys
sys.setrecursionlimit(200000)
from collections import deque
# a-zに正方向と逆辺を張る
def addEdge(g, a, z):
    g[0][a].append(z)
    g[1][z].append(a)

# グラフの初期化
def initGraph(g, edgenum):
    g.append([])  # [0] 正方向のグラフ
    g.append([])  # [1] 逆方向のグラフ
    for _ in range(edgenum):
        g[0].append(deque(list()))
    for _ in range(edgenum):
        g[1].append(deque(list()))

def dfs(g, v, visited, vs):
    # 正方向のDFS
    visited[v] = True
    for i in range(len(g[0][v])):
        if visited[g[0][v][i]] is False:
            dfs(g, g[0][v][i], visited, vs)
    vs.append(v)

def rdfs(g, v, visited, cmp, k):
    # 逆方向のDFS
    # kがcall元に指定される連結成分の通し番号
    visited[v] = True
    cmp[v] = k
    # 指定したノードの逆辺をたどる
    for i in range(len(g[1][v])):
        # print("go? {0}".format(g[1][v][i]))
        # 逆辺の先がrDFSで到達できないときのみ
        if visited[g[1][v][i]] is False:
            # print("yes")
            rdfs(g, g[1][v][i], visited, cmp, k)

def scc(g, cmp):
    vs = []  # 帰りがけのリスト
    visited = [False] * len(g[0])
    cmp.extend([None] * len(g[0]))
    for i in range(len(g[0])):
        if visited[i] is False:
            dfs(g, i, visited, vs)

    visited = [False] * len(g[1])
    k = 0
    # pprint(vs)
    for i in range(len(vs) - 1, -1, -1):
        # print("vited: i={0} vs[i] = {1}".format(i, vs[i]))
        # print(visited)
        if visited[vs[i]] is False:
            # print("rdfs [{0}]".format(i))
            rdfs(g, vs[i], visited, cmp, k)
            k += 1
    # pprint(vs)
    return k

vCount, e = map(int, input().split())

g = []  # グラフ。[0] = 正方向のグラフ。 [1] = 逆方向のグラフ
v = []  # 辺
cmp = []

from pprint import pprint
initGraph(g, edgenum=vCount)
for _ in range(e):
    x, y = map(int, input().split())
    addEdge(g, x, y)

scc(g, cmp)

for _ in range(int(input())):
    x, y = map(int, input().split())
    print(1 if cmp[x] == cmp[y] else 0)



Measured memory_bytes: 31140
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans=10000,n;
    cin >>n;
    ll wei[n+1];
    ll sum=0;
    wei[0]=0;
    for(int i=0;i<n;i++){
        ll a;
        cin >>a;
        wei[i+1]=wei[i]+a;
        sum+=a;
    }
    for(int i=1;i<=n;i++){
        ans=min(ans,abs(abs(sum-wei[i])-wei[i]));
    }

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(i,j,k) for (i=j;i<=k;i++)
using namespace std;
const int N=2e5+5,INF=1e9;
int n,u,v,i,j,lim,bot;
long long ans;
char s[N];
int deep[N*2],key[N*2],far[N]; //µÚiÌõ±ßÖ¸ÏòµÄ×ÓÊ÷µÄ×îÉîÂ·¾¶³¤¶È ÊÇ·ñÓÐ¹Ø¼üµã Àëi×îÔ¶µÄµãµÄ¾àÀë i³ö·¢×îÔ¶µÄº¬ÓÐ¹Ø¼üµãµÄÂ·¾¶³¤¶È(µãÊý) 
int En,size[N],fst[N],nxt[N*2],to[N*2];
void add(int u,int v) {
	En++; nxt[En]=fst[u]; fst[u]=En; to[En]=v;
}
int add(int x)
{
	if (x==INF) return x;
	return x+1;
}
void dfs1(int x,int fa)
{
	int j;
	for (j=fst[x];j;j=nxt[j])
	if (to[j]!=fa)
	{
		dfs1(to[j],x);
		key[j]=size[to[j]];
		far[x]=max(far[to[j]]+1,far[x]);
		size[x]+=size[to[j]];
	}
	if (s[x]=='1') size[x]++;
}
void updata(int dt,int &fs,int &sc)
{
	if (dt>fs) sc=fs,fs=dt;
	else if (dt>sc) sc=dt;
}
int get(int x,int fs,int sc)
{
	if (fs==sc) return fs;
	if (x==fs) return sc;
	return fs;
}
void dfs2(int x,int fa,int abv,int edge)
{
	int j,v,fs=abv+1,sc=0,_abv;
	deep[edge^1]=abv;
	far[x]=max(far[x],abv+1);
	for (j=fst[x];j;j=nxt[j])
	if (to[j]!=fa)
	{
		v=to[j];
		updata(far[v]+1,fs,sc);
	}
	for (j=fst[x];j;j=nxt[j])
	if (to[j]!=fa)
	{
		v=to[j];
		_abv=get(far[v]+1,fs,sc);
		key[j^1]=size[1]-size[v];
		deep[j]=far[v];
		dfs2(v,x,_abv,j);
	}
}
int main()
{
//	freopen("radius.in","r",stdin);
//	freopen("radius.out","w",stdout);
	scanf("%d",&n);
	En=1;
	rep(i,1,n-1)
	{
		scanf("%d%d",&u,&v);
		add(u,v); add(v,u);
	}
	scanf("%s",s+1);
	dfs1(1,1);
	dfs2(1,1,-1,0);

	rep(i,1,n)
	{
		lim=far[i]-1;
		for (j=fst[i];j;j=nxt[j])
			lim=min(lim,deep[j^1]+1);
		if (s[i]=='1') bot=0;
		else {
			bot=INF;
			for (j=fst[i];j;j=nxt[j])
				if (key[j]>0) bot=min(bot,deep[j]+1);
		}
		if (lim>=bot) ans+=lim-bot+1;
	}
	printf("%lld\n",ans+1);
	return 0;
}

Measured memory_bytes: 16128
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>

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

using namespace std;
typedef long long ll;

const ll INF = INT64_MAX;
const int MOD = 1e9 + 7;

int main() {
    int n, W; cin >> n >> W;
    vector<int> w(n), v(n);
    rep(i, n) cin >> w[i] >> v[i];
    vector<vector<ll>> dp(n+1, vector<ll>(W+1, -INF));
    dp[0][0] = 0;
    rep(i, n) rep(j, W+1) {
        if (j + w[i] <= W) dp[i+1][j + w[i]] = max(dp[i+1][j + w[i]], dp[i][j] + v[i]);
        dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
    }

    ll ans = 0;
    rep(j, W+1) ans = max(ans, dp[n][j]);
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T 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;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> mvec(size_t a){return vector<T>(a);}template<class T, class... Ts>auto mvec(size_t a, Ts... ts){return vector<decltype(mvec<T>(ts...))>(a, mvec<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  string S;
  cin >> S;
  ll ans{MOD};
  rep(i, 0, S.size()-2){
    ans = min(ans, abs(stoll(S.substr(i, 3)) - 753));
  }
  cout << ans << rt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+13; 
typedef long long ll;
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	ll ans=-1e18;
	ans=max(ans,1ll*a*d);
	ans=max(ans,1ll*b*c);
	ans=max(ans,1ll*a*c);
	ans=max(ans,1ll*b*d);
	printf("%lld",ans);
 } 

Measured memory_bytes: 3820
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = int.Parse(Console.ReadLine());
            Console.WriteLine(N * N - A);
        }
        
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

string s;
int ta;

signed main() {
	cin >> s;
	if (s[0] != 'A') {
		cout << "WA" << endl;
		ggr
	}
	for (int i = 1; i < s.size(); i++) {
		if (i >= 2 && i < s.size() - 1 && s[i] == 'C')ta++;
		else if (s[i] - 'a' < 0) {
			cout << "WA" << endl;
			ggr
		}
	}
	if (ta != 1)cout << "WA" << endl;
	else cout << "AC" << endl;
	ggr
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;

    if(a1+a2+a3 >= 22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }

    return 0;
}

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

using namespace std;

int main(void) {
	int sx, sy, tx, ty;
	string s;

	cin >> sx >> sy >> tx >> ty;

	for (int i = sx; i < tx; i++) {
		s += 'R';
	}
	for (int i = sy; i < ty; i++) {
		s += 'U';
	}

	for (int i = tx; i > sx; i--) {
		s += 'L';
	}
	for (int i = ty; i > sy; i--) {
		s += 'D';
	}

	s += 'D';
	for (int i = sx; i <= tx; i++) {
		s += 'R';
	}
	for (int i = sy-1; i < ty; i++) {
		s += 'U';
	}
	s += 'L';

	s += 'U';
	for (int i = tx; i >= sx; i--) {
		s += 'L';
	}
	for (int i = ty+1; i > sy; i--) {
		s += 'D';
	}
	s += 'R';

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int sum = 0;
		int max = 0;

		int pre[] = new int[N];

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

			if(max < pre[i]) {

				max = pre[i];
			}
			sum += pre[i];
		}


		sum-= (int)max/2;


		System.out.println(sum);

	}

}


Measured memory_bytes: 23252
n,ans=int(input()),0
for i in range(1,n+1,2):
  divisor=[]
  for j in range(1,int(i**0.5)+1,2):
    if i % j == 0:
      divisor.append(j)
      if j != i // j:
        divisor.append(i//j)
  if len(divisor) == 8:
    ans += 1
print(ans)

Measured memory_bytes: 3188
N = int(input())
A = list(map(int, input().split()))

flag = 0

if 0 in A:
    print(0)
else:
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            flag = 1
            break
    if flag == 0:
        print(ans)
    else:
        print(-1)

Measured memory_bytes: 21648
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
int n;
int H[100005];
int DP[100005];
using namespace std;
int main() {
    cin>>n;
    rep(i,0,n){cin>>H[i+1];}
    H[0]=H[1];
    DP[0]=0;
    DP[1]=0;
    rep(i,2,n+1){
        DP[i]=min(DP[i-1]+abs(H[i]-H[i-1]),DP[i-2]+abs(H[i]-H[i-2]));
    }
    cout<<DP[n]<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    vector<int> h(n);
    rep(i,n)
        cin >> x[i] >> y[i] >> h[i];

    int h_max = 1e9+1000;
    int h_cand = -1;
    rep(i,101)
        rep(j,101)
            rep(k,n)
            {
                if(k==0)
                {
                    h_cand = -1;
                    h_max = 1e9+1000;
                }

                if(h[k] > 0)
                {
                    if(h_cand == -1)
                        h_cand = h[k]+abs(i-x[k])+abs(j-y[k]);
                    else if(h_cand != h[k]+abs(i-x[k])+abs(j-y[k]))
                        break;
                    if(h_cand > h_max)
                        break;              
                }
                else
                {
                    h_max = min(h_max, abs(i-x[k])+abs(j-y[k]));
                    if(h_cand > h_max)
                        break;
                }

                if(k==n-1)
                {
                    if(h_cand > 0)
                        cout << i << " " << j << " " << h_cand << endl;
                    else
                        cout << i << " " << j << " " << h_max << endl;
                    return 0;
                }                    
            }
    return 0;
}

Measured memory_bytes: 256
/**
 * File              : A.cpp
 * Author            : JCHRYS <jchrys@me.com>
 * Date              : 22.12.2019
 * Last Modified Date: 22.12.2019
 * Last Modified By  : JCHRYS <jchrys@me.com>
 */

#include <bits/stdc++.h>
using namespace std;

int main() {
    vector<bool> ans(4, true);
    int a, b;
    cin >> a >> b;
    ans[a] = ans[b] = false;
    for (int i = 1; i <= 3; i++) {
        if (ans[i])
            cout << i;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict, deque
import math

# import copy
# from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 998244353

def solve():
    n = getN()
    nums = getList()
    d = defaultdict(int)
    for num in nums:
        d[num] += 1
    ans = sum(nums)
    # print(d)
    Q = getN()
    for i in range(Q):
        b, c = getList()
        if b in d and d[b] > 0:
            ans -= b * d[b]
            ans += c * d[b]
            d[c] += d[b]
            d[b] = 0

        print(ans)



def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 86056
#include<bits/stdc++.h>
using namespace std;
#define ll      long long int
#define MOD     1000000007
#define pb      push_back
#define mp      make_pair
#define all(v)  (v).begin(),(v).end();
#define T		int t;cin>>t;while(t--)
#define IOS     ios_base::sync_with_stdio(false);cin.tie(NULL);

int main() {




	int n, W;
	cin >> n >> W;

	ll w[n], v[n];

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

	ll dp[n][W + 1] = {0};

	 for (int i = 0 ; i <  n ; i ++) {
	 	for (int j = 0; j <= W ; j++) {
	 		//cout << dp[i][j] << " ";
          dp[i][j] = 0;
	 	}

	 }

	for (int j = 0 ; j <= W ; j ++) {

		if (j >= w[0]) dp[0][j] = v[0];
	
	}

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

		for (int j = 1 ; j <= W ; j++) {

			if (j >= w[i]) {

				dp[i][j] =  max( v[i] + dp[i - 1][j - w[i]] , dp[i - 1][j] );

			}

			else {

				dp[i][j] = dp[i - 1][j];
			}


		}
	}

	cout << dp[n - 1][W] << endl;


}


Measured memory_bytes: 78336
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll A, B, K;
  cin >> A >> B >> K;
  for (auto i = min(A, B); i > 0; i--) {
    if (A % i == 0 && B % i == 0){
      //cout << i << endl;
      K--;
      if (K == 0) {
        cout << i << endl;
        break;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n;
    while(cin>>n){
        ll arr[n+1];
        ll occ[n+1];
        memset(occ,0,sizeof occ);
        for(ll i=1;i<=n;i++){
            cin>>arr[i];
            occ[arr[i]]++;
        }
        long long ans=0;
        for(ll i=1;i<=n;i++){
            ll l=occ[i];
            ans+=((l*(l-1))/2);
        }
        for(ll i=1;i<=n;i++){
            ll val=arr[i];
            ll x=occ[val];
            ll temp=ans;
            temp-=(x*(x-1))/2;
            x--;
            temp+=(x*(x-1))/2;
            cout << temp << endl;
        }
    }
    return 0;
}


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

using namespace std;

class Dice{
public:
    int f[6];

    Dice(){};

    void roll_z(){roll(1,2,4,3);}
    void roll_y(){roll(0,2,5,3);}
    void roll_x(){roll(0,1,5,4);}

    void roll(int a,int b,int c,int d){
        int t = f[a]; f[a] = f[b]; f[b] = f[c]; f[c] = f[d]; f[d] = t;
    }

};

bool chk_dc(Dice dice1, Dice dice2){
    for(int i=0;i<6;i++) if(dice1.f[i] != dice2.f[i]) return false;
    return true; 
}

bool rot_chk(Dice dice1, Dice dice2){
    for(int i=0;i<6;i++){
        for(int j=0;j<4;j++){
            if(chk_dc(dice1,dice2)) return true;
            dice2.roll_z();
        }
        if(i%2 == 0) dice2.roll_x();
        else dice2.roll_y();
    }
    return false;
}

int main(){
    Dice dice_1, dice_2;

    for(int i=0;i<6;i++) cin >> dice_1.f[i];
    for(int i=0;i<6;i++) cin >> dice_2.f[i];
    
    if(rot_chk(dice_1,dice_2)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3092
def main():
    L, R = list(map(int, input().split(' ')))
    if R - L >= 2019:
        # exists numbers which can be divided by 2019.
        print(0)
    else:
        min_value = 2019
        for i in range(L, R):
            for j in range(i + 1, R + 1):
                r = (i * j) % 2019
                if r == 0:
                    print(0)
                    exit(0)
                min_value = min([r, min_value])
        print(min_value)


if __name__ == '__main__':
    main()

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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = 1e18 + 7;


signed main(){
    i64 n, m, l;
    cin >> n >> m >> l;
    vector<vector<pair<i64,i64>>> edges(n);
    for(i64 i = 0; i < m; ++i){
        i64 a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        edges[a].emplace_back(b, c);
        edges[b].emplace_back(a, c);
    }
    i64 q;
    cin >> q;
    auto f = [&](int s){
        vector<pair<i64,i64>> range(n, make_pair(INF, INF));
        range[s] = make_pair(0, 0);
        priority_queue<tuple<i64,i64,i64>, vector<tuple<i64,i64,i64>>, greater<tuple<i64,i64,i64>>> que;
        que.emplace(0, 0, s);
        while(!que.empty()){
            i64 num, val, pos;
            tie(num, val, pos) = que.top();
            que.pop();
            if(range[pos] != make_pair(num, val))
                continue;
            for(auto& p : edges[pos]){
                if(p.second > l)
                    continue;
                bool hoky = (val + p.second > l);
                i64 nex_num = num + hoky;
                i64 nex_val = hoky ? p.second : val + p.second;
                auto nex = make_pair(nex_num, nex_val);
                if(nex < range[p.first]){
                    range[p.first] = nex;
                    que.emplace(nex_num, nex_val, p.first);
                }
            }
        }
        return range;
    };
    vector<vector<pair<i64,i64>>> ranges(n);
    for(int i = 0; i < n; ++i)
        ranges[i] = f(i);
    for(int i = 0; i < q; ++i){
        int s, t;
        cin >> s >> t;
        --s, --t;
        auto ret = ranges[s][t].first;
        cout << (ret >= 1e15 ? -1 : ret) << endl;
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
using namespace std;
using P = pair<int,int>;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

int main() {
    int h,w,cnt=0;
    cin >> h >> w;
    vector<string> field(h);
    rep(i,h) {
        cin >> field[i];
        rep(j,w) {
            if (field[i][j] == '.') cnt++;
        }
    }
    vector<vector<int>> dist(h,vector<int>(w,-1));
    queue<P> q;

    dist[0][0] = 0;
    q.push({0,0});
    while (!q.empty()) {
        int y = q.front().first;
        int x = q.front().second;
        q.pop();

        rep(i,4) {
            int ny = y+dy[i];
            int nx = x+dx[i];
            if (ny < 0 || ny >= h || nx < 0 || nx >= w || field[ny][nx] == '#') continue;
            if (dist[ny][nx] != -1) continue;
            dist[ny][nx] = dist[y][x]+1;
            q.push({ny,nx});
        }
    }

    if (dist[h-1][w-1] == -1) cout << "-1" << endl;
    else cout << cnt-(dist[h-1][w-1]+1) << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
A=[]
B=[]

for i in range(n):
  A.append(input())
for i in range(m):
  B.append(input())
strb=""
for i in range(m):
  strb+=B[i]
z=len(A[0])
x=len(B[0])
for i in range(z-x+1):
  Q=""
  for j in range(n):
    Q+=A[j][i:i+x+1]
  if strb in Q:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
struct UnionFind {
    vector<int> par, siz, f;
    UnionFind(int n) {
        par.resize(n);
        siz.resize(n, 1);
        f.resize(n);
        for (int i = 0; i < n; i++)
            par[i] = i;
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    bool unite(int u, int v) {
        u = find(u), v = find(v);
        if (u == v)
            return false;
        if (siz[u] < siz[v])
            swap(u, v);
        par[v] = u;
        siz[u] += siz[v];
        f[u] |= f[v];
        return true;
    }
    bool same(int u, int v) { return find(u) == find(v); }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, h, w;
    cin >> n >> h >> w;
    vector<pair<ll, P>> v(n);
    for (int i = 0; i < n; i++) {
        int r, c, a;
        cin >> r >> c >> a;
        --r;
        --c;
        v.push_back(make_pair(a, P(r, h + c)));
    }
    sort(all(v));
    reverse(all(v));
    UnionFind uf(h + w);
    ll res = 0;
    for (int i = 0; i < n; i++) {
        if (uf.f[uf.find(v[i].second.first)] &&
            uf.f[uf.find(v[i].second.second)]) {
            continue;
        }
        if (uf.unite(v[i].second.first, v[i].second.second)) {
            res += v[i].first;
        } else if (!uf.f[uf.find(v[i].second.first)]) {
            res += v[i].first;
            uf.f[uf.find(v[i].second.first)] = 1;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 5744
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException{
		Main mainObj = new Main();
		mainObj.solve();
	}
	
	public void solve() throws IOException{
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		int x = fs.nextInt()-1;
		int y = fs.nextInt()-1;
		
		int[] distArr = new int[n];
		
		for(int i = 0; i < n; i++){
			for(int j = i; j < n; j++){
				if(i == j){
					continue;
				}
				int dist = Math.min(j-i, Math.min(Math.abs(x-i)+1+Math.abs(j-y), Math.abs(y-i)+1+Math.abs(x-j)));
				distArr[dist]++;
			}
		}
		
		for(int i = 1; i < n; i++){
			System.out.println(distArr[i]);
		}
	}

	public class FastScanner {
		
		BufferedReader reader;
		private StringTokenizer st;
		
		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		
		public String next() throws IOException {
			if(st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}
		
		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}
		
		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}
		
		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		
		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for(int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}
		
		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for(int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}
		
		public void close() throws IOException {
			reader.close();
		}
	}
}



Measured memory_bytes: 23508
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main{

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt(); 
		
		String[] s = new String[n];
		
		for(int i = 0; i < n; i++) {
			s[i] = stdIn.next();
		}
		
		
		Map<String,Integer> map = new TreeMap<>();
		
		
		
		
		for(int i = 0; i < n; i++) {
			if(!map.containsKey(s[i])) {
				map.put(s[i], 0);
			}
			map.put(s[i], map.get(s[i])+1);
			
		}
		int max = 0;
		
		for(int i = 0; i < n; i++) {
			max = Math.max(max, map.get(s[i]));
		}
		
	
	
		
		
		for(String a: map.keySet()) {
			if(map.get(a)== max) {
				System.out.println(a);
			}
		}
		
		
	}

}


Measured memory_bytes: 84920
#include<bits/stdc++.h>
using namespace std;
    int main(){
        int A, B, C, D, L, R;
            cin >> A >> B >> C >> D;
                L = A + B;
                    R = C + D;
                        if(L > R){
                            cout << "Left" << endl;
                        }else if(L == R){
                            cout << "Balanced" << endl;
                        }else if(L < R){
                            cout << "Right" << endl;
                        }else{}

    return 0;}

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

int main()
{
    int a, b;
    cin >> a >> b;
    for (int i = 0; i <= 1000; i++)
    {
        if ((int)(i * 0.08) == a && (int)(i * 0.1) == b)
        {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  

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

  int maxi = 0;
  for (auto t : a){
    maxi = max(maxi, t.second);
  }
  for(auto t:a){
    if(t.second == maxi){
      cout << t.first << "\n";
    }
  }
  return 0;
}

Measured memory_bytes: 25216
from sys import stdin
N =list(map(int, stdin.readline().strip().split()))[0]
num_list=list(map(int, stdin.readline().strip().split()))
M=list(map(int, stdin.readline().strip().split()))[0]
ans_list=list(map(int, stdin.readline().strip().split()))
n=[]
def calc(i,ans):
    if i==N :
        return ans
    n.append(calc(i+1,ans))
    n.append((calc(i+1,ans+num_list[i])))
    return ans
calc(0,0)
n=list(set(n))
for an in ans_list:
    if an in n:print("yes")
    else:print("no")




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

using namespace std ;

#define N 300007
int n , m , ans ;
int a[N] , num[N] , ton[N] ;

int main()
{
	
	//freopen("a.in" , "r" , stdin ) ;
	//freopen("a.out" , "w" , stdout ) ;
	scanf("%d%d" , &n , &m ) ;
	for(int i = 1 ; i <= n ; i++ ){
		scanf("%d" , &a[i] ) ; ton[a[i]]++ ;
		if( a[i] - ton[a[i]] < 0 ) ans++ ;
		else ans += ( num[ a[i] - ton[a[i]] + 1 ] >= 1 ) , ++num[ a[i] - ton[a[i]] + 1 ]; 
	}
	while( m-- ){
		int x , y ;
		scanf("%d%d" , &x , &y ) ;
		if( a[x] - ton[a[x]] < 0 ) ans-- ;
		else ans -= ( num[a[x] - ton[a[x]] + 1] > 1 ) , --num[ a[x] - ton[a[x]] + 1 ] ;
		--ton[a[x]] , a[x] = y , ++ton[y] ;
		if( y - ton[y] < 0 ) ans++ ;
		else ans += ( num[ y - ton[y] + 1 ] >= 1 ) , ++num[ y - ton[y] + 1 ] ;
		printf("%d\n" , ans ) ;
	}
	
	return 0 ;
}

/*
5 3
1 1 3 4 5
1 2
2 5
5 4
*/

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

using namespace std;
const int N = 10000;
int _w;

int n, a[N];

int main() {
	cin >> n, n *= 2;
	for( int i = 1; i <= n; ++i )
		cin >> a[i];
	sort(a+1, a+n+1);
	int ans = 0;
	for( int i = n-1; i >= 1; i -= 2 )
		ans += a[i];
	printf( "%d\n", ans );
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,m,i,j,a[100][100],b[100],c[100];
    cin>>n>>m;
    for(j = 0;j < n;j++){
        for(i = 0;i<m;i++){
            cin>>a[i][j];
        }
    }
    for(i = 0;i<m;i++){
        cin>>b[i];
    }
    for(j=0;j<n;j++){
        for(i=0;i<m;i++){
            c[j]=c[j]+a[i][j]*b[i];
        }
    }
    for(j=0;j<n;j++){
        cout<<c[j]<<endl;
    }
}




Measured memory_bytes: 3132