akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pll=pair<ll,ll>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vstr=vector<string>;

ll N,M;

void solve() {
    cin >> N >> M;
    vll A(N),B(M),C(M);
    vector<pll> BC(M);
    rep(i,N){
        cin >> A[i];
    }
    sort(ALL(A));
    ll b,c;
    rep(i,M){
        cin >> b >> c;
        BC[i] = mp(b,c);
    }
    sort(BC.begin(),BC.end(),[](auto &left, auto &right){
        return left.second > right.second;
    });
    // rep(i,M){
    //     cout << BC[i].fi << " " << BC[i].sc << endl;
    // }
    ll ans = 0,mi=0;
    rep(i,N){
        if(mi<M && BC[mi].sc>A[i]){
            ans += BC[mi].sc;
            BC[mi].fi--;
        }else{
            ans += A[i];
        }
        if(mi<M && BC[mi].fi == 0) mi++;
    }
    print(ans);
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

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

using namespace std;

main(){
	while(1){
		int x,y;
		cin >> x >> y;
		if (x == 0 && y == 0){
			break;
			}
		else if (x<=y){
			printf("%d %d\n",x,y);
			}
		else if (y<=x){
			printf("%d %d\n",y,x);
	}
}
}


Measured memory_bytes: 3140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		for (String str; (str=br.readLine()) != null; ) {
			String[] data = str.split(",");

			double xa = Double.parseDouble(data[0]);
			double ya = Double.parseDouble(data[1]);

			double xb = Double.parseDouble(data[2]);
			double yb = Double.parseDouble(data[3]);

			double xc = Double.parseDouble(data[4]);
			double yc = Double.parseDouble(data[5]);

			double xd = Double.parseDouble(data[6]);
			double yd = Double.parseDouble(data[7]);
			/*
			 * vector ab : (xb-xa, yb-ya)
			 * vector ac
			 * vector ad
			 * vector bc : (xc-xb, yc-yb)
			 * vector ba
			 * vector bd
			 * vector cd : (xd-xc, yd-yc)
			 * vector ca
			 * vector cb
			 */
			Vector2d a = new Vector2d(xa, ya);
			Vector2d b = new Vector2d(xb, yb);
			Vector2d c = new Vector2d(xc, yc);
			Vector2d d = new Vector2d(xd, yd);
			if ( isSameSide(a, b, c, d)
					&& isSameSide(b, c, d, a)
					&& isSameSide(c, d, a, b) ) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}

	public static class Vector2d {
		private double x;
		private double y;

		public Vector2d(double x, double y) {
			this.x = x;
			this.y = y;
		}
		// vecotr this - v
		public Vector2d minus(Vector2d v) {
			return new Vector2d(this.x - v.x, this.y - v.y);
		}
		// outerProduct this x b
		public double op(Vector2d b) {
			return this.x * b.y  -  this.y * b.x;
		}
	}
	/*
	 * outerProduct
	 * a = (a.x, a.y)
	 * b = (b.x, b.y)
	 */
//	public static double op(Vector2d a, Vector2d b) {
//		return a.x * b.y  -  a.y * b.x;
//	}

	// line ab, point c, point d
	public static boolean isSameSide(
			Vector2d a, Vector2d b, Vector2d c, Vector2d d) {
		Vector2d ab = b.minus(a);
		Vector2d ac = c.minus(a);
		Vector2d ad = d.minus(a);
//		if ( op(ab, ac) > 0 && op(ab, ad) > 0 ) {
		if ( ab.op(ac) > 0 && ab.op(ad) > 0 ) {
			return true;
//		} else if ( op(ab, ac) < 0 && op(ab, ad) < 0 ) {
		} else if ( ab.op(ac) < 0 && ab.op(ad) < 0 ) {
			return true;
		} else {
			return false;
		}
	}

}

Measured memory_bytes: 24100
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int &ai: A) cin >> ai;
  vector<int> B(A);
  sort(B.begin(), B.end());
  for(int &ai: A){
    if(ai==B[N-1]){
      cout << B[N-2] << endl;
    }else{
      cout << B[N-1] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3200
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{
	//auto tokens = split(my_readln());
	string S = my_readln();
	string S2 = "keyence";

	bool ans = false;
	ulong begin;
	ulong si;
	foreach (i, c; S)
	{
		if (c == S2[si])
		{
			++si;
			if (si == S2.length)
			{
				begin = i;
				break;
			}
		}
		else
		{
			begin = i - 1;
			break;
		}
	}
	ulong remain1 = S2.length - si;
	ulong remain2 = S.length - begin - remain1;

	if (S[0..begin+1] ~ S[begin+remain2..$] == S2) ans = true;
	stderr.writeln(S[0..begin+1], " ", S[begin+remain2..$]);
	
	writeln(ans ? "YES" : "NO");
	stdout.flush();
}

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

#define REP(i,n) for(int i = 0;i < n;++i)
#define PB(s) push_back(s)
#define ST(n) sort(n.begin(),n.end())

using namespace std;
typedef long long ll;

int main(){
	int N,M,C;
	cin >> N >> M >> C;
	int ans=0;
	int B[M];
	REP(i,M)cin >> B[i];
	REP(x,N){
		int temp=0;
		REP(i,M){
			int t;
			cin >> t;
			temp+=t*B[i];
		}
		if(temp+C > 0)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
*_, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort.reverse
b = gets.split.map(&:to_i).sort.reverse
c = gets.split.map(&:to_i).sort.reverse
puts a.product(b).map { |x, y| x + y }.sort.reverse[0, k].product(c).map{ |x, y| x + y }.sort.reverse[0, k]

Measured memory_bytes: 287464
N=int(input())
s=input()

if N%2==0:
    s1=s[:int(N/2)]
    s2=s[int(N/2):]
    if s1==s2:
        flg=True
    else:
        flg=False
else:
    flg=False
if flg:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main(void){

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

   int a[2][n];
   for(int i=0;i<n;i++){
       a[0][i] = 1;
   }
   a[1][0] = 1;
   for(int i=1;i<n;i++){
       a[1][i]= 0;
   }

//    for(int i=0;i<2;i++){
//            for(int j=0;j<n;j++){
//                cout<<a[i][j]<<" ";
//            }
//            cout<<endl;
//        }

   for(int i=0;i<m;i++){
       int x, y;
       cin>>x>>y;

       if(a[1][x-1] == 1){
           a[1][y-1] = 1;
       }
       a[0][x-1]--;
       a[0][y-1]++;

       if(a[0][x-1]== 0 && a[1][x-1]==1){
           a[1][x-1]=0;
       }

    //    for(int i=0;i<2;i++){
    //        for(int j=0;j<n;j++){
    //            cout<<a[i][j]<<" ";
    //        }
    //        cout<<endl;
    //    }
   }

    int sum = 0;
   for(int i=0;i<n;i++){
       sum += a[1][i];
   }

   cout<<sum<<endl;
   
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  
  vector<int> sub(N);
  for (int i=0; i<N; i++) {
    sub[i] = A[i];
  }
  sort(sub.begin(), sub.end());
  int f = sub[N-1];
  int s = sub[N-2];
  
  for(int i=0; i<N; i++) {
    if (A[i] != f) {
      cout << f << endl;
    }
    else if (A[i] == f) {
      cout << s << endl;
    }
  }
}

Measured memory_bytes: 3200
import sys

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def nCr(com_n, com_r):
    if com_n < com_r: return 0
    return fac[com_n] * ifac[com_r] % md * ifac[com_n - com_r] % md

def nPr(com_n, com_r):
    if com_n < com_r: return 0
    return fac[com_n] * ifac[com_n - com_r] % md

md = 10 ** 9 + 7
n_max = 500005
fac = [1]
for i in range(1, n_max + 1): fac.append(fac[-1] * i % md)
ifac = [1] * (n_max + 1)
ifac[n_max] = pow(fac[n_max], md - 2, md)
for i in range(n_max - 1, 1, -1): ifac[i] = ifac[i + 1] * (i + 1) % md

def main():
    n,m=MI()
    ans=0
    for i in range(n+1):
        if i&1:ans-=nCr(n,i)*nPr(m,i)*nPr(m-i,n-i)**2
        else:ans+=nCr(n,i)*nPr(m,i)*nPr(m-i,n-i)**2
        ans%=md
    print(ans)

main()

Measured memory_bytes: 108244
#include<iostream>                                        
#include<cmath>                                           
#include<iomanip>                                         
using namespace std;                                      
                                                          
int main(void){                                           
  int a,b;                                                
  double S,L,h;                                           
  int deg;                                                
  double rad;                                             
  double PI = acos(-1);                                   
                                                          
  cin >> a >> b >> deg;                                   
  rad = deg * PI / 180;                                   
                                                          
  S =  a * b * sin(rad) / 2;                              
  L = a + b + sqrt(a*a+b*b-2*a*b*cos(rad));               
  h = 2 * S / a;                                          
                                                          
  cout << fixed << setprecision(6) << S << endl;          
  cout << L << endl << h << endl;                         
                                                          
  return 0;                                               
} 

Measured memory_bytes: 3580
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#define ll long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long

#define INF 999999999

using namespace std;

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

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

    FOR(i, 1, 10)
    {
        FOR(j, 1, 10)
        {
            cout << i << "x" << j << "=" << i * j << "\n";
        }
    }
}


Measured memory_bytes: 3076
import sys
 
N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]

Sum = [0]

sum_ = 0

for i in range(len(S)-1):
  if S[i] == 'A' and S[i+1] == 'C':
    sum_ += 1
  Sum.append(sum_)

for  q in range(Q):
  ans = Sum[lr[q][1]-1]-Sum[lr[q][0]-1]
  print(ans)
  

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

int main() {
    int n;
    string s;
    cin >> n;
    cin >> s;
    if (n % 2 == 1) {
        cout << "No" << endl;
    } else {
        if (s.substr(0, n / 2) == s.substr(n / 2, n / 2)) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 256
N = int(input())
A = sorted(list(map(int, input().split()))) + [0]
 
memo = ['Y'] * (10**6+1)
mx = max(A) + 1 
count = 0
 
for i in range(N):
    if memo[A[i]] == 'N':
        continue
    for j in range(A[i], mx, A[i]):
        memo[j] = 'N'
    if A[i] == A[i+1]:
        continue
    
    count += 1
 
print(count)

Measured memory_bytes: 32172
#include <stdio.h>

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if (a <= b){
		int i;
		for (i = 0;i < b;i++)
			printf("%d",a);
		}else{
			int j;
			for (j = 0;j <a;j++)
			printf("%d",b);
		}
}

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

using namespace std;

#define LL long long
string s;
int x, a, b;

int main() {
	cin >> a >> b;
	cout << a * b << " " << 2 * a + 2 * b << endl;
	return 0;
}


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

typedef enum { false, true } bool;

int main(void)
{
    char S[101], T[101];
    int len;
    int i = 0, j = 0;
    bool flag;
    
    scanf("%s", S);
    scanf("%s", T);
    
    
    len = strlen(S);
    
    
    while(j < len)
    {
        if(S[i] != T[j])
        {
            i = 0;
            flag = false;
        }
        else
        {
            i++;
            flag = true;
        }
        j++;
    }
    
    
    if(flag)
    {
        j = 0;
        
        while(i < len)
        {
            if(S[i] != T[j])
            {
                flag = false;
                break;
            }
            i++;
            j++;
        }
    }
    
    
    if(flag)
        printf("Yes\n");
    else
        printf("No\n");
        

    //system("pause");
    
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
const int nmax=2e5+50;
const int mod=1e9+7;
using namespace std;
int n,i,b[nmax],j,t,cur,ans;
map<int,int>mp1;
int main()
{
       ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n;
    for(i=1;i<=n;i++)
    {
    	cin>>b[i];
    	mp1[b[i]-1]++;
	}
	sort(b+1,b+n+1);
	for(i=n;i>=1;i--){
		
		if(mp1[b[i]-1]<=0)continue;
		mp1[b[i]-1]--;
		for(j=31;j>=0;j--)
		{
			if(b[i]&(1<<j))break;
			cur|=(1<<j);
		}
		t=j,cur=0;
		for(;j>=0;j--)
		{
			if(!(b[i]&(1<<j)))cur|=(1<<j);
		}
		for(j=31;j>=t;j--)
		{
			if(mp1[cur]>0)
			{
				mp1[cur]--;
				mp1[b[i]-1]--;
				ans++;
				break;
			}
			cur^=(1<<j);
		}
		mp1[b[i]-1]++;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 48640
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
const long long int INF=1024*1024*1024*2-1;
const long long int MAX_TREE=1024*1024;
//区間[left,right),valueは値
struct TREE{
	long long int left,right,value;
};
TREE tree[MAX_TREE];
//2^20
//区間は1-indexed

void Segment_Tree_LR_Set(long long int l,long long int r,long long int id){
	tree[id].left=l;
	tree[id].right=r;
	if(id*2<MAX_TREE){Segment_Tree_LR_Set(l, (l+r)/2, id*2);Segment_Tree_LR_Set((l+r)/2, r, id*2+1);}
}

void Segment_Tree_Change_Loop(long long int id)
{
	if(id==0){return;}
	tree[id].value=min(tree[id*2].value,tree[id*2+1].value);
	
	Segment_Tree_Change_Loop(id/2);
}

void Segment_Tree_Change(long long int id,long long int num){
	tree[id+MAX_TREE/2-1].value=num;
	Segment_Tree_Change_Loop((id+MAX_TREE/2-1)/2);
}

long long int Segment_Tree_Check(long long int l,long long int r,long long int id){
		if(tree[id].left>=r||tree[id].right<=l||r<=l){return INF;}
		else if(l==tree[id].left&&r==tree[id].right){return tree[id].value;}
		else {return min(Segment_Tree_Check(l,min(r,tree[2*id].right),2*id),Segment_Tree_Check(max(l,tree[2*id+1].left), r, 2*id+1));}
		
}

int main(){
	long long int n,q,com;
	cin>>n>>q;
	Segment_Tree_LR_Set(1, MAX_TREE/2+1, 1);
	for(int i=1;i<MAX_TREE;i++){
		tree[i].value=INF;
	}
	for(int i=1;i<=q;i++){
		long long int a,b;
		cin>>com>>a>>b;
		if(com==0){Segment_Tree_Change(a+1, b);}
		else{cout<<Segment_Tree_Check(a+1, b+2, 1)<<endl;}
	}
}



Measured memory_bytes: 27676
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String readStr;
    int c = 0;
    while ((readStr = reader.readLine()) != null) {
      int readInt = Integer.parseInt(readStr);
      if (readInt == 0) break;
      System.out.println("Case " + ++c + ": " + readInt);
    }
  }

}

Measured memory_bytes: 27212
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

class ModCalc
{
    LLONG m_mod;
    vector<LLONG> m_fac;
    vector<LLONG> m_ifac;

public:

    ModCalc(const LLONG mod)
    {
        m_mod = mod;
    }

    ModCalc(const int max, const LLONG mod)
    {
        m_mod = mod;
        m_fac = vector<LLONG>(max + 1);
        m_ifac = vector<LLONG>(max + 1);
        m_fac[0] = m_ifac[0] = 1;
        for (int i = 0; i < max; ++i)
        {
            m_fac[i + 1] = m_fac[i] * (i + 1) % mod;    // n! (mod M)
            m_ifac[i + 1] = m_ifac[i] * ModPow(i + 1, mod - 2) % mod;   // k!^(M-2) (mod M)
        }
    }

    const LLONG ModAdd(LLONG a, LLONG b) const
    {
        return (a + b) % m_mod;
    }

    const LLONG ModSubtract(LLONG a, LLONG b) const
    {
        LLONG diff = a - b;
        return diff >= 0 ? diff : diff + m_mod;
    }

    const LLONG ModMulti(LLONG a, LLONG b) const
    {
        LLONG prod = a * b % m_mod;
        return prod >= 0 ? prod : prod + m_mod;
    }

    const LLONG ModDiv(LLONG a, LLONG b) const
    {
        LLONG c = m_mod, u = 1, v = 0;
        while (c)
        {
            LLONG t = b / c;
            b -= t * c; swap(b, c);
            u -= t * v; swap(u, v);
        }
        u %= m_mod;
        if (u < 0) u += m_mod;
        return (a % m_mod) * u % m_mod;
    }

    const LLONG ModPow(LLONG x, LLONG n) const
    {
        LLONG ret = 1;
        while (n != 0)
        {
            if (n & 1) ret = ret * x % m_mod;
            x = x * x % m_mod;
            n = n >> 1;
        }
        return ret;
    }

    const LLONG ModComb(LLONG n, LLONG r) const
    {
        if (n == 0 && r == 0) return 1;
        if (n < r || n < 0) return 0;
        LLONG tmp = m_ifac[n - r] * m_ifac[r] % m_mod;
        return tmp * m_fac[n] % m_mod;
    }
};

int main()
{
    LLONG n, a, b; cin >> n >> a >> b;
    ModCalc mod(MOD);
    // 全ての選び方の合計
    LLONG ans = mod.ModPow(2LL, n);
    ans = mod.ModSubtract(ans, 1LL);
    // ここからnCaとnCbを引く：O(2*10^5)
    LLONG nCa = 1LL, nCb = 1LL;
    for (LLONG k = 1LL; k <= a; ++k)
    {
        nCa = mod.ModMulti(nCa, n - k + 1LL);
        nCa = mod.ModDiv(nCa, k);
    }
    for (LLONG k = 1LL; k <= b; ++k)
    {
        nCb = mod.ModMulti(nCb, n - k + 1LL);
        nCb = mod.ModDiv(nCb, k);
    }
    ans = mod.ModSubtract(ans, nCa);
    ans = mod.ModSubtract(ans, nCb);
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int h, w;
char s[22][22];
int v[22][22];
void dfs(int i, int j, int x)
{
	if (i < 0 || j < 0 || i >= h || j >= w)
		return;
	if (s[i][j] == '#')
		return;
	if (v[i][j] <= x)
		return;
	v[i][j] = x;
	dfs(i - 1, j, x + 1);
	dfs(i + 1, j, x + 1);
	dfs(i, j - 1, x + 1);
	dfs(i, j + 1, x + 1);
	return;
}
int main()
{
	scanf("%d %d", &h, &w);
	int i, j;
	for (i = 0; i < h; i++)
		scanf("%s", s[i]);
	int si, sj, gi, gj;
	int ans = 0;
	for (si = 0; si < h; si++)
	{
		for (sj = 0; sj < w; sj++)
		{
			if (s[si][sj] == '.')
			{
				for (i = 0; i < h; i++)
					for (j = 0; j < w; j++)
						v[i][j] = 1000000009;
				dfs(si, sj, 0);
				for (gi = 0; gi < h; gi++)
					for (gj = 0; gj < w; gj++)
						if (s[gi][gj] == '.')
							if (v[gi][gj] > ans)
								ans = v[gi][gj];
			}
		}

	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main {
  static int count = 0;
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    StringBuilder output = new StringBuilder();
    int n = in.nextInt();
    int[] A = new int[n];
    for (int i = 0; n != 0; i++) {
      A[i] = in.nextInt();
      n--;
    }
    mergeSort(A);
    for (int i = 0; i < A.length; i++) {
      output.append(A[i]);
      if (i != A.length - 1) output.append(" ");
    }
    System.out.println(output.toString());
    System.out.println(Main.count);
  }
  
  static void merge(int[] A, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    int[] L = new int[n1];
    int[] R = new int[n2];
    for (int i = 0; i < n1; i++) { L[i] = A[left + i]; }
    for (int j = 0; j < n2; j++) { R[j] = A[mid +  j]; }
    int i = 0;
    int j = 0;
    for (int k = left; k < right; k++) {
      Main.count++;
      if      (i >= n1)       A[k] = R[j++];
      else if (j >= n2)       A[k] = L[i++];
      else if (L[i] <= R[j])  A[k] = L[i++];
      else                    A[k] = R[j++];
    }
  }
  
  static void mergeSort(int[] A) {
    int left = 0;
    int right = A.length;
    mergeSort(A, left, right);
  }
  
  static void mergeSort(int[] A, int left, int right) {
    if (left + 1 < right) {
      int mid = (left + right)/2;
      mergeSort(A, left, mid);
      mergeSort(A, mid, right);
      merge(A, left, mid, right);
    }
  }
  
}

Measured memory_bytes: 175816
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const long long M = 1e8 ;
int main()
{
     ll i,res=0,j,n;
    cin>>n;
    vector< ll > div(n+1,1);
    for(i=2;i<=n;i++){
        for(j=i;j<=n;j+=i){
            div[j]++;
        }
    }
    for(i=1;i<=n;i++){
        res+=(div[i]*i);
    }
    cout<<res<<endl;
    return 0;
}



Measured memory_bytes: 81400
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300 + 10;
typedef long long ll;
ll ans;
int n;
int d[maxn][maxn];
bool vis[maxn][maxn];
void floyd()
{
	for(int k = 1; k <= n; ++k)
		for(int i = 1; i <= n; ++i)
			for(int j = 1; j <= n; ++j)
				if(i != k && j != k)
				{
					if(d[i][j] == d[i][k] + d[k][j])
						vis[i][j] = 1;
					else if(d[i][j] > d[i][k] + d[k][j])
					{
						puts("-1");
						exit(0);
					}
				}
	for(int i = 1; i <= n; ++i)
		for(int j = i + 1; j <= n; ++j)
			if(!vis[i][j])
				ans += d[i][j];
	printf("%lld\n", ans);
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			scanf("%d", &d[i][j]);
	floyd();
	return 0;
}

Measured memory_bytes: 768
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

n,x,y=map(int,input().split())

fr,to,w=[],[],[]

for i in range(n-1):
  fr.append(i)
  to.append(i+1)
  w.append(1)

fr.append(x-1)
to.append(y-1)
w.append(1)

g=csr_matrix((w, (fr, to)), shape=(n, n))

ans_l=[]

'''for i in range(n):
  d=dijkstra(g,indices=i,directed=False)
  ans_l+=list(d)'''

d=dijkstra(g,directed=False).astype(int)
#print(d)
ans_l=np.bincount(d.ravel(), minlength=n)//2

#print(*ans_l[1], sep='\n')

for i in ans_l[1:]:
  print(i)

Measured memory_bytes: 76520
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* ]]] */

int n, k;
int a[100000];
vector<int> g[100000];
int res;

int dfs(int v){
  int h = 0;
  each(u, g[v]) chmax(h, dfs(u));
  if (a[v] == 0) return 0;
  if (h == k - 1 && a[v] != 0){
    res++;
    return 0;
  }
  return h + 1;
}

int main(){
  cin >> n >> k;
  rep(i, n) cin >> a[i], a[i]--;
  if (a[0] != 0) a[0] = 0, res++;
  rep(i, 1, n) g[a[i]].push_back(i);
  dfs(0);
  cout << res << endl;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  if (a != 1 && b != 1) cout << 1;
  else if (a != 2 && b != 2) cout << 2;
  else cout << 3;
  return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

S,W = LI()

if S <= W:
    print('unsafe')
else:
    print('safe')

Measured memory_bytes: 65612
import sys
input = sys.stdin.readline


class SegmentTree():
    # リストSの部分リストからなる集合を葉とするセグメント木
    def __init__(self, S, n):
        self.size = n
        self.array = [set()] * (2**(self.size + 1) - 1)
        for i, c in enumerate(S):
            self.array[i + 2**self.size - 1] = {c}
        for i in range(2**self.size - 1)[::-1]:
            self.array[i] = self.array[2 * i + 1] | self.array[2 * i + 2]

    def subquery(self, l, r, k, i, j):
        # 区間[i,j)の中で区間[l,r)の文字列の集合を返す
        if j <= l or r <= i:
            return set()
        elif l <= i and j <= r:
            return self.array[k]
        else:
            l_set = self.subquery(l, r, 2 * k + 1, i, (i + j) // 2)
            r_set = self.subquery(l, r, 2 * k + 2, (i + j) // 2, j)
            return l_set | r_set

    def query(self, l, r):
        # [l,r)に含まれる文字の種類数
        return len(self.subquery(l, r, 0, 0, 2**self.size))

    def update(self, i, c):
        # 配列のi番目をcに更新する
        tmp = i + 2**self.size - 1
        self.array[tmp] = {c}
        while tmp > 0:
            tmp = (tmp - 1) // 2
            self.array[tmp] = self.array[2 * tmp + 1] | self.array[2 * tmp + 2]


n = int(input())
S = list(input())
S = [ord(s) for s in S]
segtree = SegmentTree(S, 19)
for _ in range(int(input())):
    t, i, c = input().split()
    if t == '1':
        segtree.update(int(i)-1, ord(c))
    if t == '2':
        print(segtree.query(int(i)-1, int(c)))


Measured memory_bytes: 473736
import math

n,h = map(int,input().split())
s = []
max_a = 0
for i in range(n):
    a,b = map(int,input().split())
    max_a = max(a,max_a)
    s.append((b,a))

if max_a >= h:
    print(1)
    exit()

s.sort(reverse=True)
ans = 10**9
i = 0
while h > 0 and i < n:
    h -= s[i][0]
    c = max(0,math.ceil(h/max_a))
    ans = min(i+c+1,ans)
    i += 1

print(ans)

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

int main() {
  int h, w;
  int dx[] = {0, 0, 1, 1, 1, -1, -1, -1};
  int dy[] = {1, -1, 0, 1, -1, 0, 1, -1};
  cin >> h >> w;
  string map[h];
  rep(i, h) { cin >> map[i]; }
  rep(i, h) {
    rep(j, w) {
      if (map[i][j] == '.') {
        int cn = 0;
        rep(k, 8) {
          int x = i + dx[k];
          int y = j + dy[k];
          if (x >= 0 && x < h && y >= 0 && y < w && map[x][y] == '#') cn++;
        }
        map[i][j] = '0' + cn;
      }
    }
  }
  rep(i, h) { cout << map[i] << endl; }
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };

int main() {
	int d, g;
	cin >> d >> g;
	Vi P(d), C(d);
	rep(i, d)  cin >> P[i] >> C[i];

	
	int ans = INT_MAX;
	//bit全探索
	for (int bit = 0; bit < (1 << d); ++bit)
	{
		int sum = 0;
		int cnt = 0;
		Vi R;
		for (int i = 0; i < d; ++i) {
			if (bit & (1 << i)) { // i が bit に入るかどうか
				sum += (i + 1) * 100 * P[i] + C[i];
				cnt += P[i];
			}
			else {
				R.push_back(i);
			}
		}
		sort(R.begin(), R.end());

		bool f1 = false, f2 = false;;
		while (sum < g) {
			int j = R[R.size() - 1];
			R.pop_back();
			rep(k, P[j] - 1) {
				sum += 100 * (j + 1);
				cnt++;
				//cout << sum << " " << cnt << endl;
				if (sum >= g) {
					f2 = true;
					break;
				}
			}
			if (f2)  break;
			if (sum < g && R.size() == 0) {
				f1 = true;
				break;
			}
		}
		if (f1)  continue;
		ans = min(ans, cnt);
	}
	cout << ans << endl;
}


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

int main() {
	int		a,b,c,r,i,j,k,n,m,x,y,ans = 0;
	string	str;
	
	cin >> n >> r;
	
	
	if (n>=10) {
		ans = r;
	} else {
		ans = r + 100*(10-n);
	}
	cout << ans << endl;


}


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

#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);

    rep(i,n)
    {
        cin >> a[i];
    }

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

    rep(i,n-1)
    {
        if (a[i]==a[i+1])
        {
            cout << "NO" << endl;
            return 0;
        }
        
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<vector>
#define N 101000
#define RG register
#define MOD 998244353
using namespace std;

inline int read(){
    RG int x=0,o=1; RG char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=((x<<3)+(x<<1))+ch-'0',ch=getchar();
    return x*o;
}

int n,val[N];

int main(){
	n=read(); for(RG int i=1;i<=n;++i) val[i]=read();
	sort(val+1,val+1+n);
	int top=1,tail=n-1,L=val[n],R=val[n],l=0,r=0; long long ans=0;
	while(top<=tail){
		int ll,rr;
		if(!l) ll=val[top]; else ll=val[tail];
		if(!r) rr=val[top]; else rr=val[tail];
		if(abs(ll-L)<abs(rr-R)){
			if(!r) ++top; else --tail;
			ans+=abs(rr-R),r^=1,R=rr;
		}else{
			if(!l) ++top; else --tail;
			ans+=abs(ll-L),l^=1,L=ll;
		}
	}   cout<<ans<<endl;
}


Measured memory_bytes: 640
import math

def fac(x):
    if x<=1:
        return 1
    s=1
    for i in range(1,x+1):
        s=s*i
    return s
def com(m,n):
    return fac(m)/(fac(n)*fac(m-n))


temps=input().split()
n=int(temps[0])
m=int(temps[1])
sum=0
for i in range(m,n+2):
    min=int((i-1)*i/2)
    max=int((2*n-i+1)*i/2)
    sum=sum+max-min+1
print(int(sum%(math.pow(10,9)+7)))



Measured memory_bytes: 9448
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(){
	int i,num,tmp;
	char str[81];

	num = 0;
	while(scanf("%s",str) != EOF){
		i = 0;
		while(i < strlen(str)){
			if(isdigit(str[i])){
				tmp = 0;
				while(isdigit(str[i])){
					tmp *= 10;
					tmp += str[i]-'0';
					i++;
				}
				num += tmp;
			}
			i++;
		}
	}

	printf("%d\n",num);

	return 0;
}

Measured memory_bytes: 540
import sys
sys.setrecursionlimit(10 ** 8)
n = int(input())
alp = "abcdefghijklmnopqrstuvwxyz"
permutations = []

def dfs(a, size):
    if len(a) == size:
        global permutations
        permutations.append(a)
        return
    for i in range(1, max(a) + 2):
        dfs(a + [i], size)

dfs([1], n)
for i in permutations:
    print(''.join([alp[j-1] for j in i]))

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

def combination(n,r):
    r=min(r,n-r)
    result=1
    for i in range(n-r+1,n+1):
        result*=i
    for i in range(1,r+1):
        result//=i
    return result

def factorize(n):
    f=[]
    p=2
    cnt=0
    while p**2<=n:
        while n%p==0:
            cnt+=1
            n=n//p
        if cnt!=0:
            f.append([p,cnt])
            cnt=0
        p+=1
    if n!=1:
        f.append([n,1])
    return f

ans=1
mod=10**9+7
f=factorize(m)
for i in range(len(f)):
    k=f[i][1]
    ci=combination(k+n-1,k)%mod
    ans=ans*ci%mod
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <numeric>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <random>



using namespace std;
 

int main()
{
	int n;

	cin >> n;

	vector<int> a(n + 1);
	int count = 0;

	for (int i = 1; i < n + 1; i++)
	{
		cin >> a[i];
	}
	int j = 0;
	for (int i = 1; i < n + 1; i++)
	{
		j = a[i];
		if (i == a[j])
		{
			count++;
		}
	}

	cout << count / 2 << endl;

	return 0;
}

Measured memory_bytes: 640
// Practice 40 hours a day to become Ling Ling
// Code by Nguyen Huu Lam
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long LL;

#define y0 Sword_Art_Online
#define y1 Your_lie_in_April
#define yn Darling_in_the_Franxx
#define tm Plastic_Memories
#define lr Charlotte
#define norm Weathering_with_you
#define left Violet_Evergarden
#define have Date_a_live
#define ends Your_name
#define prev Five_centimeters_per_second
#define hash Silent_voice
#define endl "\n"

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

LL Rand(LL l, LL h){
    return uniform_int_distribution<LL>(l, h)(rng);
}

template <typename T> void read(T &t){
    t = 0; char ch = getchar(); int f = 1;
    while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
    do { (t *= 10) += ch - '0'; ch = getchar(); } while (isdigit(ch)); t *= f;
}

const LL MaxN = 1 + 1e5;

LL n, m, k;

void InOut(){
    #define TASK "ABC"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
}

int main(){
    // InOut();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> k;
    if(k == LL(1e9)){
        for(int i = 0 ; i < m ; ++i) cout << LL(1e9) << " ";
        for(int i = 0 ; i < n - m ; ++i) cout << 1 << " ";
        return 0;
    }
    for(int i = 0 ; i < m ; ++i) cout << k << " ";
    for(int i = 0 ; i < n - m ; ++i) cout << k + 1 << " ";

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i, a, b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

bool check(int n) {
    string s = to_string(n);
    string t(s.rbegin(), s.rend());
    return s == t;
}

void _main() {
    int A, B;
    cin >> A >> B;
    int ans = 0;
    FOR (i, A, B + 1) ans += check(i);
    cout << ans << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("output.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
//
// Created on 2020/08/25.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    int h,w;
    cin>>h>>w;
    vector<vector<int>>dp(10,vector<int>(10,INF));

    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            int mp;
            cin>>mp;
            dp[i][j] = mp;
        }
    }
    map<int,int>mp;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            int number;
            cin>>number;
            mp[number] ++;
        }
    }

    for (int k = 0; k < 10; ++k) {
        for (int i = 0; i < 10; ++i) {
            for (int j = 0; j < 10; ++j) {
                chmin(dp[i][j],dp[i][k] + dp[k][j]);
            }
        }
    }
    int ans = 0;
    for (int l = 0; l < 10; ++l) {
        ans += mp[l] * dp[l][1];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3632
{-# LANGUAGE BangPatterns #-}
import Data.Word
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U

-- Input: s t
-- Output: arr
--   (arr ! i) ! j == length of lcs of (drop i s, drop j t)
lcsTable :: BS.ByteString -> BS.ByteString -> V.Vector (U.Vector Word16)
lcsTable s t = V.scanr' (\ !x !v ->
                           -- for some i (0 <= i < m),
                           --   x = BS.index s i :: Char
                           --   v = arr ! (i+1) :: U.Vector Word16
                           U.scanr (\(!y,!w,!u) !l ->
                                      -- for some j (0 <= j < n)
                                      --   y = BS.index t j :: Char
                                      --   w = (arr ! (i+1)) ! j :: Word16
                                      --   u = (arr ! (i+1)) ! (j+1) :: Word16
                                      --   l = (arr ! i) ! (j+1) :: Word16
                                      if x == y
                                      then u + 1
                                      else max w l
                                   ) 0 (U.zip3 t' (U.init v) (U.tail v))
                        ) (U.replicate (n+1) 0) (V.fromListN m $ BS.unpack s)
  where !m = BS.length s
        !n = BS.length t
        !t' = U.fromListN n (BS.unpack t)

solve :: BS.ByteString -> BS.ByteString -> BS.ByteString
solve s t = let !table = lcsTable s t
                !m = BS.length s
                !n = BS.length t
                recon !i !j | i >= m || j >= n = Nothing
                            | x == y = let !i' = i+1 ; !j' = j+1
                                       in Just (x, (i', j'))
                            | (table V.! (i+1)) U.! j >= (table V.! i) U.! (j+1) = recon (i+1) j
                            | otherwise = recon i (j+1)
                  where x = BS.index s i
                        y = BS.index t j
                (result, _) = BS.unfoldrN (fromIntegral $ (table V.! 0) U.! 0) (\(!i,!j) -> recon i j) (0,0)
            in result

main = do
  s <- BS.getLine
  t <- BS.getLine
  -- BS.length s <= 3000, BS.length t <= 3000, BS.all isAsciiLower s, BS.all isAsciiLower t
  if BS.length s <= BS.length t
    then BS.putStrLn (solve t s)
    else BS.putStrLn (solve s t)


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

int main(){
    int n, v, a[100];
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 1; i < n; i++){
        for(int k = 0; k < n-1; k++) cout << a[k] << ' ';
        cout << a[n-1] << endl;
        v = a[i];
        int j = i - 1;
        while((j >= 0) && (a[j] > v)){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
    }
    for(int k = 0; k < n-1; k++) cout << a[k] << ' ';
    cout << a[n-1] << endl;
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define pb push_back
#define ins insert
#define F first
#define S second
#define var auto
using namespace std;
typedef long long ll;
const int Mod = 924844033;
const int Max = 4010;

ll dp[Max][Max];
ll numofway[Max][Max];
ll fact[Max];
void Solve(vector<int> A , int cntOfElem)
{
    int n = A.size() - 1;//there exists A[i] for every i from 1 to n

    numofway[0][0] = numofway[1][0] = numofway[1][1] = 1;

    for(int a = 2; a < Max; a++)
    {
        numofway[a][0] = 1;
        for(int cnt = 1; cnt <= a; cnt++)
        {
            numofway[a][cnt] = (numofway[a - 1][cnt] + numofway[a - 2][cnt - 1]) % Mod;
        }
    }
    for(int cnt = 0; cnt <= A[n]; cnt++)
    {
        dp[n][cnt] = numofway[A[n]][cnt];
    }
    for(int i = n - 1; i >= 1; i--)
    {
        dp[i][0] = 1;
        for(int cnt = 1; cnt <= cntOfElem; cnt++)
        {
            for(int j = 0; j <= A[i] && j <= cnt; j++)
            {
                dp[i][cnt] += (dp[i + 1][cnt - j] * numofway[A[i]][j]) % Mod;
            }
            dp[i][cnt] %= Mod;
        }
    }
fact[0] = 1;
    for(int i = 1; i < Max; i++)
        fact[i] = (fact[i - 1] * i) % Mod;
    ll ans = 0;
    int sign = 1;
    for(int i = 0; i <= cntOfElem; i++)
    {
        ans = (ans + sign * (dp[1][i] * fact[cntOfElem - i] % Mod) + Mod ) % Mod;
        sign = -sign;
    }

    cout << ans << '\n';;
}

int main()
{
    int n , k;cin >> n >> k;
    int badCnt = 2 * (n - k);
    int mn = badCnt / (2 * k);
    int bgcnt = badCnt % (2 * k);
    vector<int> A;A.pb(0);
    for(int i = 0 ; i < 2 * k ; i++)
        if(i < bgcnt)
            A.pb(mn + 1);
        else
            A.pb(mn);
    Solve(A , n);
}

Measured memory_bytes: 159784
import numpy as np
N,M,C = list(map(int,input().split(' ')))
B = np.array(list(map(int,input().split(' '))))
#print(B)
A = []
for i in range(N):
  A.append(list(map(int,input().split(' '))))
ans = 0
#print(A)

for i in range(N):
  A_ = np.array(A[i])
#  print((A_))
  test = (np.dot(B,A_))+ C
#  print('test',test)
  if (test) >0:
    ans+=1

print(ans)    


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

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

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main()
{
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((abs(b-a) <= d && abs(c-b) <= d) || abs(c-a) <= d)
  {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256