akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#define llint long long

using namespace std;

string s;
vector<string> vec;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	string t;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'A') t += s[i];
		else if(i+1 < s.size() && s[i] == 'B' && s[i+1] == 'C') t += s[i], i++;
		else{
			vec.push_back(t);
			t = "";
		}
	}
	vec.push_back(t);
	
	llint ans = 0, cnt = 0;
	for(int i = 0; i < vec.size(); i++){
		s = vec[i], cnt = 0;
		for(int j = 0; j < s.size(); j++){
			if(s[j] == 'A') cnt++;
			else ans += cnt;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 5388
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
double d(double a,double b){
    return (a-b)*(a-b);
}
int main(){
    int n,m;
    double a[20],b[20],c[20];
    double fld[20][20];
    cin>>n>>m;
    REP(i,n)cin>>a[i]>>b[i]>>c[i];
    REP(i,n)REP(j,n){
        fld[i][j]=d(a[i],a[j])+d(b[i],b[j])+d(c[i],c[j]);
    }
    //REP(i,n){REP(j,n)cout<<fld[i][j]<<" ";cout<<endl;}
    //cout<<fld[0][2]<<endl;
    double ans=0;
    REP(i,1<<n){
        int cnt=0;
        vector<int>V;
        REP(j,n)if(i>>j&1){
            cnt++;
            V.push_back(j);
        }
        if(cnt!=m)continue;
        //REP(j,m)cout<<V[j]<<" ";cout<<endl;
        double res=0;
        REP(j,m){
            for(int k=j+1;k<m;k++){
                res+=fld[V[j]][V[k]];
            }
        }
        ans=max(ans,res);
    }
    printf("%.10f\n",ans);
}

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

int main()
{
	ios::sync_with_stdio(false);

	string s;
	cin >> s;
	int n = s.size();
	int res = n;
	for (int x=0; x<26; x++)
	{
		int ans = 0, cnt = 0;
		for (int i=0; i<n; i++)
		{
			if (x != s[i] - 'a')
				cnt++;
			else ans = max(ans, cnt), cnt = 0;
		}
		ans = max(ans, cnt);
		res = min(res, ans);
	}
	cout << res << "\n";

	return 0;
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t h, n;
  std::cin >> h >> n;

  std::vector<std::pair<int64_t, int64_t>> ab(n);
  std::cin >> ab;
  std::vector<int64_t> c(h + 1, 1000000000);

  for (const auto &pair : ab) {
    for (int64_t i = 0; i <= std::min(h, pair.first); i++) {
      c[i] = std::min(c[i], pair.second);
    }
  }
  c[0] = 0;

  for (int64_t i = 0; i < h; i++) {
    for (const auto &pair : ab) {
      if (i + pair.first <= h) {
        c[i + pair.first] = std::min(c[i + pair.first], c[i] + pair.second);
      }
    }
  }

  std::cout << c[h] << std::endl;

  return 0;
}

Measured memory_bytes: 384
n=int(input())
B=list(map(int,input().split()))
A=[]
for i in range(n-1,-1,-1):
  for j in range(i,-1,-1):
    if B[j]==j+1:
      A.append(j+1)
      del B[j]
      break
if len(A)==n:
  for a in A[::-1]:print(a)
else:
  print(-1)

Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  int m;
  cin >> n >> m;
  priority_queue<int> p;
  vector<vector<int>> f(m);
  for(int i=0;i < n;i++){
    int g,h;
    cin >> g >> h;
    if(g<=m){f.at(g-1).push_back(h);}
  }
  int ans = 0;
  for(int i=0;i < m;i++){
    for(int j=0;j < f.at(i).size();j++){
      p.push(f.at(i).at(j));
    }
    if(p.size() != 0){ans += p.top();
    p.pop();}
  }
  cout << ans << endl;
  }

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

ST = []
for _ in range(N):
    x, l = map(int, input().split())
    ST.append((x-l, x+l))

ST.sort(key=lambda x: x[1])

ans = 0
cur = -1e9
for i in range(N):
    s, t = ST[i]
    if cur <= s:
        ans += 1
        cur = t
print(ans)


Measured memory_bytes: 23808
#include <stdio.h>

int main(void){
  int input;
  int flag = 0;
  scanf("%d",&input);
  if (input / 10 == 0){flag=1;goto end;}
  for(int div1=2;div1<10;div1++){
    for (int div2=div1;div2<10;div2++){
      if (div1*div2==input){
        flag = 1;
        goto end;
      }
    }
  }
end:
  if (flag == 1){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}
        

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int N;
    cin >> N;
    vector<lli> A(N);
    REP (i, 0, N) cin >> A[i];
    lli ans = 0;
    bool run = true;
    while (run) {
        run = false;
        lli sum = 0;
        REP (i, 0, N) {
            sum += A[i] / N;
        }
        REP (i, 0, N) {
            A[i] = A[i] - A[i] / N * (N + 1) + sum;
            if (A[i] >= N)  run = true;
        }
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    ll n,k;
    cin>>n>>k;
    if(k==1)cout<<0<<endl;
    else cout<<n-k<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include <vector>
using namespace std;
int n, k;
int lnum, rnum;
int calc( int l, int r )
{
	return ( lnum - l + k - 2 ) / ( k - 1 ) + ( rnum - r + k - 2 ) / ( k - 1);
}
int main( )
{
	cin >> n >> k;
	int pos = 0;
	for( int i = 1; i <= n; ++ i )
	{
		int t;
		cin >> t;
		if( t == 1 )
			pos = i;
	}
	int ans = 300000;
	lnum = pos - 1, rnum = n - pos;
	int l = min( lnum, k - 1 );
	while( l >= 0 )
	{
		int r = k - l - 1;
		ans = min( ans, calc( l, r ) );
		l --; r ++;
	}
	cout << ans + 1 << endl;
}

Measured memory_bytes: 256
# include<iostream>
# include<algorithm>
# include<cstring>
using namespace std;
 
 
int main ()
{
    int A,B,C,K;
    cin>>A>>B>>C>>K;
    
    if(K<=A+B)
    {
    	cout<<min(K,A)<<endl;
    	return 0;
	}
	else 
	{
		cout<<A-(K-A-B)<<endl;
		return 0; 
	}

    
    
    
	
	
 } 

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
		ll N,A,B;
	cin >> N>>A>>B;
	vecl(H);
	fx(N) {
		vecpl(H);
	}
	A -= B;
	ll left = 0, right = 2000000000;
	ll mid;
	while(right-left>1) {
		mid = (left + right ) / 2;
		ll k = mid;
		fy(N) {
			if (H[y] >mid*B) {
						ll tmp = (H[y] - mid * B);
				//k -= (tmp + A - 1) / A;
				k -= (tmp + A - 1) / A;
			/*	if ((H[y]-mid*B)%A==0) {
					k -= ((H[y] - mid * B) + A - 1) / A;
					//doublece((H[y] - mid * B) / A, ((H[y] - mid * B) + A - 1) / A)
				}
				else {
					k -= ((H[y] - mid * B) + A - 1) / A;
					//doublece((H[y] - mid * B) / A + 1, ((H[y] - mid * B) + A - 1) / A)
				}*/
			}
		}

		if (k >= 0) {
			right = mid;
		}
		else {
			left = mid;
		}
	}
	//doublece(left,right)
	ce(right)
	

    return 0;
}



Measured memory_bytes: 1400
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N;
vector<int> h;
int dp[100001];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  h.resize(N + 1, 0);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  fill(dp, dp + 100001, INF);

  dp[0] = 0;
  for (int i = 0; i < (N - 2); i++) {
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
  }
  dp[N - 1] = min(dp[N - 1], dp[N - 2] + abs(h[N - 2] - h[N - 1]));

  cout << dp[N - 1] << endl;
  return 0;
}

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

int main(){
    int n, q, fish[1000001] = {};
    cin >> n >> q;
    priority_queue<pair<int,int>> pq;
    
    int a, v;
    for(int i = 0; i < q; i++){
        cin >> a >> v;
        fish[a] += v;
        pq.push({fish[a], -a});
        
        while(!pq.empty()){
            pair<int,int> p = pq.top();
            if(p.first == fish[-p.second]){
                cout << -p.second << " " << p.first << endl;
                break;
            }
            pq.pop();
        }
        
    }
    
    return 0;
}



Measured memory_bytes: 7816
M=998244353
N,*A=open(0)
d=[1]+[0]*7**6
e=[1]+[0]*7**6
z=1
s=0
for a in A:
	a=int(a);s+=a;i=s;z*=3
	while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1
i=s
while i*2>=s:z=(z-d[i]*3)%M;i-=1
z+=~s%2*e[s//2]*3
print(z%M)

Measured memory_bytes: 143948
n,m=map(int,input().split())
A=[[] for j in range(n)]
b=[[0]*1 for i in range(m)]

for i in range(n):
    A[i] = list(map(int,input().split()))
for i in range(m):
    b[i] = int(input())

for row in range(n):
    tmp=0
    for col in range(m):
        tmp +=A[row][col]*b[col]
    print("%d"%(tmp))



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

int vector_min(vector<int> A){
    sort(A.begin(), A.end());//mainの中でsortしなければAの順序は変わらない
    int minvector = A[0];
    return minvector;
}

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> S(M), C(M);
    for (int i=0; i<M; i++){
        cin >> S.at(i) >> C.at(i);
    }
    
    vector<int> ans(1,-1);

    if(N == 1){
        for (int i=0; i<10; i++){
            int ok = 0;
            for (int j=0; j<M; j++){
                if(C.at(j) != i){
                    ok++;
                }
            }
            if(ok == 0){
                ans.push_back(i);
            }
        }     
    }
  
    if (N == 2){
        for(int i=10; i<100; i++){
            int i_10 = i/10;
            int i_1 = i % 10;
            int ok=0;
            for(int j=0; j<M; j++){
                if(S.at(j) == 1){
                    if (i_10 != C.at(j)){
                        ok++;
                    }
                }
                if(S.at(j) == 2){
                    if (i_1 != C.at(j)){
                        ok++;
                    }
                }
            }
            if(ok == 0){
                ans.push_back(i);
            }
        }
    }

    if(N == 3){
        for(int i=100; i<1000; i++){
            int i_100 = i/100;
            int i_10 = (i-100*i_100)/10;
            int i_1 = i%10;
            int ok = 0;
            for(int j=0; j<M; j++){
                if (S.at(j) == 1){
                    if(i_100 != C.at(j)){
                        ok++;
                    }
                }
                if(S.at(j) == 2){
                    if (i_10 != C.at(j)){
                        ok++;
                    }
                }
                if(S.at(j) == 3){
                    if(i_1 != C.at(j)){
                        ok++;
                    }
                }
            }
            if (ok==0){
                ans.push_back(i);
            }
        }
    }
    if (ans.size() == 1){
        cout << -1 << endl;
    }
    else{
        ans.at(0)=1000;
        cout << vector_min(ans) << endl;
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;
typedef vector<vl> v2;
typedef vector<v2> v3;
typedef vector<v3> v4;


const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

ll n;
vl h;
ll cnt;
ll ans;

int main(){
  cin >> n;
  h = vl(n);
  for(ll i = 0;i < n;i++) cin >> h.at(i);
  for(ll i = 1;i < n;i++){
    if(h.at(i) <= h.at(i-1)) cnt++;
    else cnt = 0;
    ans = max(ans,cnt);
  }
  cout << ans << endl;

}


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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int n, m;
    while(cin>>n>>m, n) {
        vector<pair<int,int> > nd;
        rep(i,n) {
            int d, p;
            cin >> d >> p;
            nd.push_back(make_pair(p,d));
        }
        sort(ALL(nd));
        reverse(ALL(nd));

        int ans = 0;
        for(int i=0; i<nd.size(); ++i) {
            if (m>=nd[i].second) {
                m -= nd[i].second;
            }
            else {
                ans += (nd[i].second - m) * nd[i].first;
                m = 0;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3160
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<utility>

#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define PII pair<int,int>
#define LL long long
#define L(x) (x<<1)
#define R(x) ((x<<1)+1)
#define lb(x) (x&(-x))
#define maxn 200000

using namespace std;

inline void GetN(int &num)
{
    char in=getchar();
    while(in<'0'||in>'9') in=getchar();
    num=in-'0';
    while(in=getchar(),in>='0'&&in<='9') num*=10,num+=in-'0';
}

inline void GetS(char *s)
{
	memset(s,0,sizeof(s));
	char in=getchar();
	while((in<'A'||in>'Z')&&(in<'a'||in>'z')) in=getchar();
	int len=0;
	s[len]=in;
	while(in=getchar(),(in>='A'&&in<='Z')||(in>='a'&&in<='z')) s[++len]=in;
}

int a[maxn];

int src(int x,int y,int item)
{
	int l=x,r=y,mid;
	while(r-l>1)
	{
		mid=(l+r)>>1;
		if(a[mid]>item)
		{
			r=mid-1;
		}
		else
		{
			l=mid;
		}
	}
	return a[r]>item?l:r;
}

int n,c,k,tmp,ans;

int main()
{
	int i;
	GetN(n);
	GetN(c);
	GetN(k);
	for(i=1;i<=n;i++)
	{
		GetN(a[i]);
	}
	sort(a+1,a+1+n);
	for(i=1;i<=n; )
	{
		tmp=src(i,n,a[i]+k);
		ans++;
		if(i+c-1<=tmp) i=i+c; else i=tmp+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
L=[list(map(int,input().split())) for i in range(M)]
x=[]
y=[]
c=[]
for i in range(M):
    x.append(L[i][0])
    y.append(L[i][1])
    c.append(L[i][2])
La=min(a)
Lb=min(b)
ans=La+Lb
for i in range(M):
    X=x[i]-1
    Y=y[i]-1
    han=a[X]+b[Y]-c[i]
    ans=min(han,ans)
print(ans)

Measured memory_bytes: 42408
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
int N;
int main() {
	cin>>N;

	int ans=0;
	for(int i=1;i<N+1;i++){
		ans+=i;
	}

	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 256
/*********** Template Starts Here ***********/

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

#define MAX 500
#define ll long long
#define ull unsigned long long
#define ___   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define f(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = b; i >= a; i--)
#define debug(x) cout << #x << " " << x << endl;
#define in(x) cin>>x;
#define out(x) cout<<x;
#define gap cout<<" ";
#define nl cout<<endl;
#define cs(x) cout<<"Case "<<x<<": ";
/*********** Template Ends Here ***********/

/** ################################## Code starts here ################################### **/

int main()
{
    ___
    int x,y,z;
    in(x) in(y) in(z)
    if(x==y&&y==z)
        cout<<"No";
    else if(x==y||y==z||z==x)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

/** ################################## Happy Coding ################################### **/


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
int N,flag=0;
  cin>>N;
int A[N];
  for(int i=0;i<N;i++)
  {
    cin>>A[i];
  }
  for(int i=0;i<N;i++)
  {
    if(A[i]%2==0)
    {
      if(A[i]%3==0 || A[i]%5==0)
        continue;
      else
        flag=1;
    }
  }
 if(flag==1)
   printf("DENIED");
 else
   printf("APPROVED");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
typedef long long ll;
typedef long double ld;
 
#define X first
#define Y second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define deb(x) cerr << #x << " " << x << '\n';
#define fo(i, n) for(int i = 0; i < n; i++)
#define Fo(i, k, n) for(int i = k; k < n ? i < n : i > n; k < n ? i++ : i--)

#define int ll
 
const int maxn = 1e5 + 7;
const int mod = 1e9 + 7;
using namespace std;

// vector<vector<int> > g(maxn);
// vector<int> used(maxn);
 
void pudge(){ 
    int x, y;
    cin >> x >> y;
    for(int i = 0; i <= x; i++){
        if (2 * i + 4 * (x - i) == y){
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
}
 
// #define PUDGE
// #define TIME

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

#ifdef PUDGE
    freopen("input.txt", "r", stdin);
    // freopen("pudge.out", "w", stdout);
#endif

#ifdef TIME
    auto start = chrono::steady_clock::now();
#endif
    
    // int q; cin >> q; while(q--)
    pudge();

#ifdef TIME
    auto end = chrono::steady_clock::now();
    auto diff = end - start;
    cout << chrono::duration <double, milli> (diff).count() << " ms\n";
#endif

    return 0;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <vector>
#include<iterator>
#include<utility>
#include<math.h>
#include <cmath>
#include<algorithm>


using namespace std;

typedef long long ll; // %lld
typedef vector<int> vi;
typedef pair<int, int> pi;

#define mod (pow(10,9)+7);
#define PB push_back
#define POB pop_back
#define MP make_pair
#define itri std::vector<int>::iterator
#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)


void showpq( vector <ll> gq)
{
	vector <ll> g = gq;
	reverse(g.begin(), g.end());
	while (!g.empty())
	{
		cout << g.back() << " ";
		g.pop_back();
	}
	cout << '\n';
}

bool isPrime(ll n)
{
	// Corner cases
	if (n <= 1)  return false;
	if (n <= 3)  return true;

	// This is checked so that we can skip
	// middle five numbers in below loop
	if (n % 2 == 0 || n % 3 == 0) return false;

	for (ll i = 5; i * i <= n; i = i + 6)
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	return true;
}

// Function to return the smallest
// prime number greater than N
int nextPrime(ll N)
{

	// Base case
	if (N <= 1)
		return 2;

	ll prime = N;
	bool found = false;

	// Loop continuously until isPrime returns
	// true for a number greater than n
	while (!found) {
		prime++;

		if (isPrime(prime))
			found = true;
	}

	return prime;
}


int main()
{
#ifndef ONLINE_JUDGE
	freopen("inno.in", "r", stdin);
	freopen("ottu.txt", "w", stdout);
#endif


	ll n, pri, c = 1, m, cnt = 0, p;
	cin >>  n;
	vector<ll> promo;

	pri = 2;
	p = pow(pri, c);

	if (isPrime(n))
	{
		cnt = 1;
	}
	else
	{
		while (pri <= n)
		{
			if (n % p == 0)
			{
				promo.PB(p);
				n = (n / p) ;
				cnt += 1;
				if (isPrime(n))
				{
					if (count(promo.begin(), promo.end(), n) == 0)
					{
						cnt += 1;
					}
					break;
				}
				c += 1;
				p = pow(pri, c);
				continue;
			}
			else
			{
				pri = nextPrime(pri);
				c = 1;
				p = pow(pri, c);
			}
		}
	}

	cout <<  cnt  << endl;


	return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main() {
  ll N,D,X,sum,day;
  cin>>N>>D>>X;
  vector<ll> A(N);
  rep0(i,N){cin>>A[i];}
  rep0(i,N){
      day=1;
      ll k=1;
      while(day<=D){
          sum++;
          day=k*A[i]+1;
          k++;
      }
  }
  cout<<sum+X<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n" 
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll a,b,c,d,f=0;
  cin>>a>>b>>c>>d;
  while(1)
  {
  	if(f)
  	{
  		a-=d;
  		if(a<=0)
  		{
  			No;
  			return 0;
  		}
  		f=0;
  	}
  	else
  	{
  		c-=b;
  		if(c<=0)
  		{
  			Yes;
  			return 0;
  		}
  		f=1;
  	}
  }
}

Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>
using namespace std;
int x,y,z;
int v[9];
int ive[101];
int bor[101];
double dp[101][5201];
int main(void){
	while(1){
		memset(v,0,sizeof(v));
		memset(bor,0,sizeof(bor));
		memset(ive,0,sizeof(ive));
		memset(dp,0,sizeof(dp));
		cin >> x >> y >> z;
		if(x==0 && y==0 && z==0)break;
		for(int i=0;i<x;i++)cin >> v[i];
		for(int i=0;i<z;i++){
			int n,e,a;
			cin >> n >> e >> a;
			ive[n]=e;
			bor[n]=a;
		}
		double ck=1.0/x;
		dp[0][0]=1;
		for(int i=0;i<y;i++){
			for(int j=0;j<=5000;j++){
				for(int k=0;k<x;k++){
					int next=i+v[k];
					if(next>y)next=y;
					if(ive[next]==0){
						dp[next][j]+=dp[i][j]*ck;
					}
					if(ive[next]==1){
						int nextp=next+bor[next];
						if(nextp>y)nextp=y;
						dp[nextp][j]+=dp[i][j]*ck;
					}
					if(ive[next]==2){
						dp[next][j+bor[next]]+=dp[i][j]*ck;
					}
					if(ive[next]==3){
						dp[next][max(0,j-bor[next])]+=dp[i][j]*ck;
					}
				}
			}
		}
		double ans=0;
		for(int i=0;i<=5000;i++){
			ans+=i*dp[y][i];
		}
		cout << (int)ans << endl;
	}
    return 0;
}

Measured memory_bytes: 5272
#include <iostream>

using namespace std;

int main() {

	int n, m, e, j;

	while(cin >> n) {
		if(n==0)
			break;
		while(n>0) {
			cin >> m >> e >> j;
			if((m==100||e==100||j==100)||(double)((m+e)/2)>=90||(double)((m+e+j)/3)>=80)
				cout << "A" << endl;
			else if((double)((m+e+j)/3)>=70||((double)((m+e+j)/3)>=50&&(m>=80||e>=80)))
				cout << "B" << endl;
			else
				cout << "C" << endl;
			n--;
		}
	}

	return 0;

}

Measured memory_bytes: 0
n = int(input())
s = input()
l = 0
r = 0
L = [0]
R = [0]
for i in range(n):
  if s[i] == 'W':
    l += 1
  L += [l]
for i in range(n):
  if s[-1-i] == 'E':
    r += 1
  R += [r]
C = []
for i in range(n+1):
  C += [L[i]+R[-1-i]]
print(min(C))

Measured memory_bytes: 29980
n,m,k=map(int,input().split())
ab=[list(map(int,input().split()))for i in range(m)]
cd=[list(map(int,input().split()))for i in range(k)]
class UnionFind():
    def __init__(self,n):
        self.n=[-1]*n
        self.r=[0]*n
    def Find_Root(self,x):
        if self.n[x]<0:
            return x
        else:
            self.n[x]=self.Find_Root(self.n[x])
            return self.n[x]
    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)
        if x==y:
            return
        elif self.r[x]>self.r[y]:
            self.n[x]+=self.n[y]
            self.n[y]=x
        else:
            self.n[y]+=self.n[x]
            self.n[x]=y
            if self.r[x]==self.r[y]:
                self.r[y]+=1
    def Root_Same(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)
    def Count(self,x):
        return -self.n[self.Find_Root(x)]
u=UnionFind(n)
for a,b in ab:
    u.Unite(a-1,b-1)
ans=[u.Count(i)-1 for i in range(n)]
for a,b in ab:
    if u.Root_Same(a-1,b-1):
        ans[a-1]-=1
        ans[b-1]-=1
for c,d in cd:
    if u.Root_Same(c-1,d-1):
        ans[c-1]-=1
        ans[d-1]-=1
print(*ans)

Measured memory_bytes: 124504
// ProblemURL : https://atcoder.jp/contests/abc084/tasks/abc084_d
// ---------------------------------------------
package main

import "fmt"

func isOdd(n int) bool { return n%2 != 0 }

func sieveOfEratosthenes(n int) []bool {
	res := make([]bool, n+1)
	res[0], res[1] = true, true
	for i := 2; i*i <= n; i++ {
		if res[i] == false {
			for j := i * i; j <= n; j += i {
				res[j] = true
			}
		}
	}
	return res
}

func main() {
	var q int
	fmt.Scan(&q)

	maxR := int(1e5)
	isNotPrime := sieveOfEratosthenes(maxR + 1)

	is2017Like := make([]bool, maxR+1)
	for i := 0; i < maxR+1; i++ {
		if isOdd(i) && !isNotPrime[i] && !isNotPrime[(i+1)/2] {
			is2017Like[i] = true
		} else {
			is2017Like[i] = false
		}
	}

	count2017Like := make([]int, maxR+1)
	for i := 1; i < maxR+1; i++ {
		count2017Like[i] += count2017Like[i-1]
		if is2017Like[i-1] {
			count2017Like[i]++
		}
	}

	for i := 0; i < q; i++ {
		var l, r int
		fmt.Scan(&l, &r)
		fmt.Println(count2017Like[r+1] - count2017Like[l])
	}
}


Measured memory_bytes: 7940
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[100000], f[100000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i], a[i]--;

    int k = 0, sol = 0;
    while (!f[k] && k != 1)
        f[k] = 1, k = a[k], sol++;

    if (k != 1)
        cout << -1;
    else
        cout << sol;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) ((a) - 1) / (b) + 1
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int H, A;
signed main() {
    cin >> H >> A;
    cout << cdiv(H, A) << endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

bool memo[30];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    
    rep(i,s.size()){
        int c=s[i]-'a';
        memo[c]=1;
    }
    
    int idx=-1;
    rep(i,26){
        if(memo[i]==0){
            idx=i;
            break;
        }
    }
    
    if(idx==-1){
        rrep(i,25){
            char c=s[i];
            for(;c++<='z';){
                idx=s.find(c);
                if(i<idx){
                    s=s.substr(0,i+1);
                    s[i]=c;
                    cout1(s)
                    return 0;
                }
            }
        }
        cout1(-1)
    }else{
        s+='a'+idx;
        cout1(s)
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
int index_compress(int n, pair<int, int> p)
{
	return (p.fi-1)*n + p.se;
}
bool isCyclicUtil(int v, bool visited[], bool *recStack, vector<vector<int>> &adj) 
{ 
    if(visited[v] == false) 
    { 
        visited[v] = true; 
        recStack[v] = true; 
        for(auto i = adj[v].begin(); i != adj[v].end(); ++i) 
        { 
            if ( !visited[*i] && isCyclicUtil(*i, visited, recStack, adj) ) 
                return true; 
            else if (recStack[*i]) 
                return true; 
        } 
  
    } 
    recStack[v] = false;   
    return false; 
} 
bool isCyclic(int V, vector<vector<int>> &adj) 
{ 
    bool *visited = new bool[V]; 
    bool *recStack = new bool[V]; 
    for(int i = 0; i < V; i++) 
    { 
        visited[i] = false; 
        recStack[i] = false; 
    } 
    
    for(int i = 0; i < V; i++) 
        if (isCyclicUtil(i, visited, recStack,adj)) 
            return true; 
  
    return false; 
}
int longest_path(vector<vector<int>> &adj, int n)
{
	int indegree[n] = {0};
	int l_path[n] = {0};
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < adj[i].size(); ++j)
		{
			indegree[adj[i][j]]++;
		}
	}
	queue<int> q;
	for (int i = 0; i < n; ++i)
	{
		if (indegree[i]==0)
		{
			q.push(i);
		}
	}
	while(!q.empty())
	{
		int u  = q.front();
		q.pop();
		for (int i = 0; i < adj[u].size(); ++i)
		{
			indegree[adj[u][i]]--;
			l_path[adj[u][i]] = max(l_path[adj[u][i]],l_path[u]+1);
			if (indegree[adj[u][i]] == 0)
			{
				q.push(adj[u][i]);
			}

		}
	}
	int answer = INT_MIN;
	for (int i = 0; i < n; ++i)
	{
		answer = max(answer, l_path[i]);
	}
	return answer;
}
int main()
{
	SPEED
	int n, temp;
	cin >> n;
	vector<vector<int>> adj((n*n) + n);
	for (int i = 1; i <= n; ++i)
	{
		cin >> temp;
		pair<int,int> prev = mp(min(i,temp),max(i,temp));
		for (int j = 2; j <= n-1; ++j)
		{
			cin >> temp;
			pair<int, int> next = mp(min(i,temp),max(i,temp));
			adj[index_compress(n,prev)].pb(index_compress(n,next));
			prev = next;
		}

	}
	if (isCyclic((n*n)+n, adj))
	{
		cout << -1;
	}
	else
	{
		cout << longest_path(adj,(n*n)+n) + 1;
	}
	return 0;
}

Measured memory_bytes: 51200
# -*- coding: utf-8 -*-
from fractions import Fraction
from collections import Counter
import math

import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def fract(a, b):
    if a == 0 and b == 0:
        return (0, 0)
    if b == 0:
        return (1, 0)
    f = Fraction(a, b)
    a = f.numerator
    b = f.denominator
    return a, b


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, AB):
    adb = Counter()
    for a, b in AB:
        k = fract(a, b)
        adb[k] += 1
    M = Mod(1000000007)
    ans = 1
    done = {(0, 0)}
    for k, v in adb.items():
        if k in done:
            continue
        a, b = k
        kk = fract(-b, a)
        done.add(k)
        done.add(kk)

        n = adb[kk]
        t = M.sub(M.pow(2, v) + M.pow(2, n), 1)
        ans = M.mul(ans, t)
    ans = M.add(ans, adb[(0, 0)])
    return M.sub(ans, 1)


def main():
    N = read_int()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 172840
X = input()

n = len(X)

S_cnt = 0
cnt = 0

for i in range(n):
    if X[i]=='S':
        S_cnt += 1
    elif (X[i]=='T') and(S_cnt>0):
        cnt += 1
        S_cnt -= 1
print(n-cnt*2)

Measured memory_bytes: 67184
N = int(input())
List = [2,7,17,37,47,67,97,107,127,137,\
        157,167,197,227,257,277,307,317,337,347,\
        367,397,457,467,487,547,557,577,587,607,\
        617,647,677,727,757,787,797,827,857,877,\
        887,907,937,947,967,977,997,1087,1097,1117,\
        1187,1217,1237,1277,1307]
for i in range(N):
  print(List[i],end=" ")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long int
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define Sort(v) sort(v.begin(), v.end())
#define For(m) for (auto it = m.begin(); it != m.end(); it++)
#define mod 1000000007
#define PI 3.14159265358979323846
using namespace std;

int main()
{
  ll a,b;
  cin >> a >> b;
  if(b%a==0)
  {
      cout << a+b;
  }
  else
  cout << b-a;
  return 0;
}


Measured memory_bytes: 256
def d_bouquet(MOD=10**9 + 7):
    from functools import reduce
    N, A, B = [int(i) for i in input().split()]

    def comb(m, r):
        numerator = reduce(lambda x, y: x * y % MOD, range(m, m - r, -1))
        denominator = reduce(lambda x, y: x * y % MOD, range(1, r + 1))
        return (numerator * pow(denominator, MOD - 2, MOD)) % MOD

    return (pow(2, N, MOD) - 1 - (comb(N, A) + comb(N, B))) % MOD

print(d_bouquet())

Measured memory_bytes: 3572
#include <stdio.h>

int main(void){
int a;
int b;


scanf("%d%d",&a,&b);

if(a==1){
a=14;
}
if(b==1){
b=14;
}

if(a>b){
printf("Alice");
}else if(a==b){
printf("Draw");
}else{
printf("Bob");
}
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

int A[205][205];

int d[10][10];

int main()
{
	int H, W;
	cin >> H >> W;
	REP(i, 10)
	{
		REP(j, 10)
		{
			cin >> d[i][j];
		}
	}
	REP(h, H)
	{
		REP(w, W)
		{
			cin >> A[h][w];
		}
	}
	//! ワーシャルフロイドで全点間最短距離
	REP(k, 10)
	{
		REP(j, 10)
		{
			REP(i, 10)
			{
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}

	ll ans = 0;
	REP(h, H)
	{
		REP(w, W)
		{
			if (A[h][w] == -1)continue;
			ans += d[A[h][w]][1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;




int main(void) {

    int N; cin>>N;
    vector<double> X(N); vector<double> Y(N);
    for (int i = 0; i < N; ++i) {
        cin>>X[i]; cin>>Y[i];
    }
    double a; int cnt=0;
    for (int i = 0; i < N-1; ++i) {
        for (int j = i+1; j < N; ++j) {
            a += sqrt(pow(X[i]-X[j],2)+pow(Y[i]-Y[j],2));
            cnt++;
        }
    }
    a /= cnt;
    a *= (N-1);
    printf("%.6lf", a);
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int resolve(int N, int h[]) {
  ll c[N];
  c[0] = 0;
  c[1] = abs(h[1] - h[0]);
  for (int i=1; i+1 < N; i++) {
    c[i+1] = min(c[i-1]+ abs(h[i+1]-h[i-1]), c[i] + abs(h[i+1] - h[i]));
  }
  return c[N-1];
}

int main() {
  int N;
  cin >> N;
  int heights[N];
  for (int i = 0; i < N; i++) {
    cin >> heights[i];
  }
  cout << resolve(N, heights) << endl;
  return 0;
}

Measured memory_bytes: 4556
# coding: utf-8
# Your code here!

MAX = 1000000
#エラトステネスの篩を用いて素数リストを予め作成する
s = [1] * MAX
## まずは全ての数が素数か不明ということにしておく
## s[2]以降をfor文で1に変換するより、s[0]s[1]を0とする方が繰り返しを使わずに済む
s[0] = 0
s[1] = 0

start = 2
while True:
    ## はじめにpmbを0で初期化しておかないと、pmb==0という条件に入ることはない
    pmb = 0
    for i in range(start, MAX):
        if s[i] == 1: #素数か否か不明な数の中で最小値を探す
            pmb = i
            break #見つかったらループを抜ける
    #print("リストsの中身", s)
   
    if pmb == 0:
        break #素数が見つからなかった
   
    #篩にかける
    for i in range(pmb ** 2, MAX, pmb):
        s[i] = 0  #素数でない要素を０にする

    start += 1

    #素数一覧をを表示
   #  for i in range(2, MAX):
   #     if s[i] == 1:
   #        print(i)

while True:
    try:
        n = int(input())
        
        c = 0
        for i in range(2, n + 1):
            if s[i] == 1:
                c += 1
        print(c)

    except EOFError:
        break
    ## tryできたときに行いたい処理はtryのインデント内に書く
      #  c = 0
      #  for i in range(2, n + 1):
      #       if s[i] == 1:
      #           c += 1
      #  print(c)



Measured memory_bytes: 13172
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/exawizards2019/editorial.pdf
・二分探索
"""

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,Q=MAP()
S=input()
TD=[input().split() for i in range(Q)]

# ある位置にいるゴーレムを動かして、左端から外に出ないか判定する
def calc1(m):
    if m==-1:
        return False
    if m==N:
        return True
    idx=m
    s=S[idx]
    for i in range(Q):
        t,d=TD[i]
        if t==s:
            if d=='L':
                idx-=1
            elif d=='R':
                idx+=1
        if idx<0:
            return False
        if idx>=N:
            return True
        s=S[idx]
    return True

# ある位置にいるゴーレムを動かして、右端から外に出ないか判定する
def calc2(m):
    if m==-1:
        return True
    if m==N:
        return False
    idx=m
    s=S[idx]
    for i in range(Q):
        t,d=TD[i]
        if t==s:
            if d=='L':
                idx-=1
            elif d=='R':
                idx+=1
        if idx>=N:
            return False
        if idx<0:
            return True
        s=S[idx]
    return True

low=-1
hi=N
while low+1<hi:
    mid=(hi+low)//2
    if calc1(mid):
        hi=mid
    else:
        low=mid
# 左端にたどり着かない(生き残る)ゴーレムのうち、初期位置が最も左のもの
lowest=hi

low=-1
hi=N
while low+1<hi:
    mid=(hi+low)//2
    if calc2(mid):
        low=mid
    else:
        hi=mid
# 右端にたどり着かない(生き残る)ゴーレムのうち、初期位置が最も右のもの
highest=low

print(max(highest-lowest+1, 0))


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int comb(int n, int k) {
    if (n < k) return 0;
    if (k == 0) return 1;
    if (k == 1) return n;
    if (k == 2) return n * (n - 1) / 2;
    if (k == 3) return n * (n - 1) * (n - 2) / 6;
}

int main() {
    string n;
    int k;
    cin >> n;
    cin >> k;
    int a = (int) n.size();
    int d0 = n[0] - '0';
    int d1 = n[1] - '0';
    int d2 = n[2] - '0';

    if(a < k){
        cout << 0 << endl;
        return 0;
    }
    int res;
    if (k == 1) {
        res = comb(a - 1, 1) * 9;
        res += d0;
    }
    if (k == 2) {
        res = comb(a - 1, 2) * 81;
        res += comb(a - 1, 1) * 9 * (d0 - 1);
        for (int i = 1; i < a; ++i) {
            if(n[i] != '0'){
                int di = n[i] - '0';
                res += comb(a - (i + 1), 1) * 9;
                res += di;
                break;
            }
        }
    }
    if (k == 3) {
        res = comb(a - 1, 3) * 729;
        res += comb(a - 1, 2) * 81 * (d0 - 1);
        int i;
        for (i = 1; i < a; ++i) {
            if(n[i] != '0'){
                int di = n[i] - '0';
                res += comb(a - (i + 1), 2) * 81;
                res += comb(a - (i + 1), 1) * 9 * (di - 1);
                break;
            }
        }
        for (int j = i + 1; j < a; ++j) {
            if(n[j] != '0'){
                int dj = n[j] - '0';
                res += comb(a - (j + 1), 1) * 9;
                res += dj;
                break;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))

l = 0
r = 0
ans = 0
while l < N and r < N:
    tmp = L[l]
    while r < N and L[r] <= tmp:
        tmp = L[r]
        r += 1
    ans = max(ans, r-l)
    if r != N:
        l = r
print(ans-1)


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

typedef long long ll;

int N;
ll H;
ll A[100010],B[100010];

int main()
{
    scanf("%d%lld",&N,&H);
    for(int i = 0; i < N; i++)
    {
        scanf("%lld%lld",A + i,B + i);
    }

    sort(A,A + N);
    sort(B,B + N);
    reverse(B,B + N);
    ll ans = 1001001001;
    ll sum = 0;
    for(int i = 0; i < N; i++)
    {
        sum += B[i];
        ans = min(ans,(max(H - sum,0LL) + A[N - 1] - 1) / A[N - 1] + i + 1);
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long test=1;
// 	cin>>test;	
	while(test--)
	{
	    long a,b=0,c=0,k,i,n,j,temp,mini,maxi,ans,q,sum,x,y;
	    string s;cin>>s;
	    long arr[129]={0};
	    for(i=0;i<s.length();i++)
	    {
	        arr[int(s[i])]++;
	    }
	    
	    for(i=50;i<126;i++)
	    {
	        if(arr[i]%2)
	        {
	            cout<<"No";
	            return 0;
	        }
	    }
	    cout<<"Yes";
	
	
    }
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=100005;
int a[maxn];
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
    }
    sort(a+1,a+n+1,cmp);
    a[0]=a[1];
    a[n+1]=0;
    int ans=0;
    while(a[ans+2]>=ans+2){
        ans++;
    }
    //printf("%d\n",ans);
    int x=a[ans+1]-ans;
    int y=ans;
    while(a[y]>=ans+1)
        y++;
    y=y-ans-1;
    //printf("%d %d\n",x,y);
    if(x%2==0||y%2==0){
        puts("First");
    }
    else{
        puts("Second");
    }
    return 0;
}


Measured memory_bytes: 640