akhauriyash/Code-Regression huggingface dataset:
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, q;
    double[] x, y;
    int i, j, countr;
    double x0, y0, ax, ay, bx, by, tmp;

    n = 3;
    x = new double[n + 1];
    y = new double[n + 1];

    for(;sc.hasNext();){
      for(i = 0;i < n;i++){
        x[i] = sc.nextDouble();
        y[i] = sc.nextDouble();
      }
      x[n] = x[0];
      y[n] = y[0];

      x0 = sc.nextDouble();
      y0 = sc.nextDouble();
      countr = 0;

      for(j = 0;j < n;j++){
        if((x[j] - x0) * (y[j + 1] - y0) - (y[j] - y0) * (x[j + 1] - x0) == 0){
          if((x[j] - x0) * (x[j + 1] - x0) <= 0 && (y[j] - y0) * (y[j + 1] - y0) <= 0){
            break;
          }else if(x0 < x[j + 1] && x0 < x[j] && y0 == y[j] && y0 == y[j + 1]){
            if((y[(j - 1 + n) % n] - y0) * (y[(j + 2) % n] - y0) > 0){
              countr++;
            }
          }
        }

        if((y[j] - y0) * (y[j + 1] - y0) <= 0 && y0 != y[j + 1]){
          ax = x[j];
          ay = y[j];
          bx = x[j + 1];
          by = y[j + 1];

          if(ay > by){
            tmp = ay;
            ay = by;
            by = tmp;
            tmp = ax;
            ax = bx;
            bx = tmp;
          }
          if((ax - x0) * (by - y0) - (bx - x0) * (ay - y0) > 0){
            countr++;
            if((y[(j - 1 + n) % n] - y0) * (y[j + 1] - y0) > 0 && y[j] == y0){
              countr++;
            }
          }
        }
      }

      if(j < n){
        System.out.println("NO");
      }else{
        if(countr % 2 == 1){
          System.out.println("YES");
        }else{
          System.out.println("NO");
        }
      }
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 23288
N = gets.to_i
T = gets.strip.split.map(&:to_i)
M = gets.to_i
A = Array.new
P = Array.new
X = Array.new
for i in 0..M-1
P[i],X[i]= gets.split.map(&:to_i)
end

for i in 0..M-1
    A[i] = T.inject(:+)-T[P[i]-1]+X[i]
end

puts A 


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "TASK"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))

const int M=998244353;

int ret;
int cnt[1000010],f[1000010];

int pw(int a,int i){
    int b=1;
    for(;i;i>>=1,a=a*a%M) if(i&1) b=b*a%M;
    return b;
}

main(){
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    forinc(i,1,in) cnt[in]++;
    fordec(i,1e6,1){
        int p=0,t=0,s=0;
        for(int j=i;j<=1e6;j+=i){
            p=(p+t*cnt[j]%M*j)%M;
            t=(t+cnt[j]*j)%M;
            s=(s+f[j])%M;
        }
        f[i]=(p-s+M)%M;
        ret=(ret+f[i]*pw(i,M-2))%M;
        ret=(ret+cnt[i]*(cnt[i]-1)/2%M*i)%M;
    }
    cout<<ret;
}



Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define DB(x)            cout << '>' << #x << ':' << x << endl;
#define DB2(x,y) 	     cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define rep(i,a,b)       for (ll i = a; i < b; i++)
#define repr(i,a,b)      for (ll i = a; i >= b; i--)
#define pb               push_back
#define F                first
#define S                second
#define mp               make_pair
#define MOD              1000000007
#define MAX              1e9
#define MIN              -1e9
#define vec(i)           vector<i>
#define PLL           	 pair<ll,ll>
#define mem(a,v)         memset(a,v,sizeof(a))
#define pf               printf
#define sc               scanf
#define _s               "%s"
#define _d               "%d"
#define _ll              "%lld"
#define _c               "%c"
#define FAST_IO          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define min(a,b)         (a)>(b)?(b):(a)
#define max(a,b)         (a)>(b)?(a):(b)
#define all(c) 		     c.begin(),c.end()
typedef long long ll;
using namespace std;
int main()
{
	ll n;
	cin>>n;
	cout<<n*(n+1)/2;
    return 0;
}

Measured memory_bytes: 256
import math
def keta(n):
    r = 1
    _n = n
    while _n != 0 :
        _n = _n // 10
        if _n > 0:
            r +=1
    return r
n = int(input())
r = keta(n)
for a in range(1, int(math.sqrt(n))+1):
    b = n / a
    if n % a == 0:
        r = min(r, max(keta(a), keta(b)))
print(r)

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

inline ll inl() {
    ll x;
    cin >> x;
    return x;
}

inline string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        ll n = inl();
        vl a(n);
        rep(i, n) cin >> a[i];
        
        cout << *max_element(all(a)) - *min_element(all(a)) << endl;
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
a,b,m = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
yasuiyo = min(al) + min(bl)
ans = []
for i in range(m):
  x,y,c = map(int,input().split())
  ans.append(al[x-1] + bl[y-1] - c)

print(min(min(ans),yasuiyo))

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

const int M = 100000;
int q, d[M + 1], a[M + 1], s[M + 2];

int main() {
	incII(i, 1, M) {
		int j = i;
		while(j <= M) {
			d[j]++;
			j += i;
		}
	}
	
	incII(i, 0, M) {
		if(i % 2 == 1 && d[i] == 2 && d[(i + 1) / 2] == 2) { a[i] = 1; }
	}
	
	incII(i, 1, M + 1) { s[i] = s[i - 1] + a[i - 1]; }
	
	cin >> q;
	inc(i, q) {
		int l, r;
		cin >> l >> r;
		r++;
		
		cout << (s[r] - s[l]) << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,k;
  cin >> n >> k;
  std::vector<int> v(n);
  long double ans=0;
  int flag=0;
  long double tmp =0;
  for(int x=0;x<n;x++){
    if(x+1>=k){
      v[x]=0;
      continue;
    }
    tmp = (long double)k/(x+1);
    v[x]=ceil(log2(tmp));
  }
  for(int i=0;i<n;i++){
    ans+=pow(0.5,v[i]);
  }
  cout << setprecision(20)<<ans/n;
  return 0;
}

Measured memory_bytes: 640
n = int(input())
alst = sorted(list(map(int, input().split())))

ans = 0
for i in range(n):
  for j in range(i + 1, n):
    c = alst[j]
    d = alst[i]
    if j <= n - 3:
      a, b = alst[n - 1], alst[n - 2]
    elif i >= n - 2:
      a, b = alst[n - 3], alst[n - 4]
    elif j == n - 1 and i == n - 3:
      a, b = alst[n - 2], alst[n - 4]
    elif j == n - 2 and i == n - 3:
      a, b = alst[n - 1], alst[n - 4]
    elif j == n - 1 and i == n - 4:
      a, b = alst[n - 2], alst[n - 3]
    elif j == n - 2 and i == n - 4:
      a, b = alst[n - 1], alst[n - 3]
    ans = max(ans, (a + b) / (c - d))
print(ans)


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

 using namespace std;

 int main() {
   int N, K;
   cin >> N >> K;

   vector<int> h(N);
   for (int i = 0; i < N; i++) cin >> h.at(i);

   int ans = 0;

   for (int i = 0; i < N; i++) {
     if (K <= h.at(i)) ans++;
   }

   cout << ans << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
int main (void){
  int n,k,d[100],a,i,j,hito[101],ans;
  //初期化
  a=0;
  ans=0;
  for(i=0;i<101;i++){hito[i]=0;}
  
  //scanf
  scanf("%d%d",&n,&k);
  
  for(i=0;i<k;i++){
    scanf("%d",&d[i]);
    
    for(j=0;j<d[i];j++){
      scanf("%d",&a);
      hito[a]=1;//aが4の時、hito[4]を1にする(1になるとhito[4]はお菓子をもらったことになる)
    }  
  }  
  for(i=1;i<=n;i++){
    if(hito[i]==0){ans++;}}//hito[0からnまで]でお菓子を持ってない人(hito[i]=0の数)を数える
  
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1732
K,A,B=map(int,input().split())
ans = K+1
if (K - (A-1)) %2==0:
  ans=max(ans,((K-(A-1))//2)*(B-A)+A)
else:
  ans=max(ans,((K-(A-1))//2)*(B-A)+A+1)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

struct enem
{
	ll x,h;
};

bool cmp(enem a,enem b)
{
	return a.x<b.x;
}
struct dp
{
	ll del,num;
};


int main()
{
	ll n,d,a;
	cin >> n >> d >> a;
	vector<enem> xh(n);
	rep(i,n)
	{
		ll foo,fooo;
		cin >> foo >> fooo;
		xh[i].x=foo;
		xh[i].h=fooo;
	}
	sort(ALL(xh),cmp);
	queue<dp>Q;
	d = d*2;
	ll ans = 0;
	ll nowdamage = 0;
	for(int i=0;i<n;i++)
	{
		

		
		while(!Q.empty()&&Q.front().del<xh[i].x)
		{
			nowdamage -= Q.front().num*a;
			Q.pop();
		}
		xh[i].h-=nowdamage;
		if(xh[i].h>0)
		{
			dp now;
			now.num = (xh[i].h+a-1)/a;
			now.del = xh[i].x+d;
			//cout<<now.num<<a<<endl;
			nowdamage += now.num*a;
			Q.push(now);
			ans += now.num;
		}
		//cout<<xh[i].h<<";"<<nowdamage<<endl;
		
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4992
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = line[0];
            int B = line[1];
            Console.WriteLine(A <= 8 && B <= 8 ? "Yay!" : ":(");
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,K;
    string S;
    cin >> N >> K >> S;
    int ans = 0;
    for(int i = 0; i < N-1; i++) {
        if(S[i] == S[i+1]) {
            ans++;
        }
    }
    cout << min(N-1,ans+2*K) << endl;
}

Measured memory_bytes: 3692
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<utility>
#include<functional>
#include<cassert>
#include<cmath>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<vint> vvint;
#define PI 3.1415926535;
#define MOD 1000000007;

int main(void) {
	int n,k,ans=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x >= k)ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(R: int, G: int):
    return 2 * G - R


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    R = int(next(tokens))  # type: int
    G = int(next(tokens))  # type: int
    result = solve(R, G)
    if isinstance(result, Iterable):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5372
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define umapi unordered_map<ll, ll>
#define umapc unordered_map<char, int>
#define endl "\n"
using namespace std;

/*
            ॐ
    || Jai Shree Ram ||  
 
 */


void solve()
{
   
    int  a;
    cin >>a;
    cout<< a + a*a + a*a*a;

}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}


Measured memory_bytes: 3676
s = input()

a = 0
l = []

for i in s:
    if a == 0:
        if i == "<":
            a = 1
        else:
            a = -1
    elif ((a > 0) and i == "<"):
        a += 1
    elif ((a < 0) and i == ">"):
        a -= 1
    elif i == "<":
        l.append(a)
        a = 1
    else:
        l.append(a)
        a = -1
l.append(a)

m=[]

for j in l:
    if m:
        if j > 0:
            m.pop()
            for k in range(0, abs(j) + 1, 1):
                m.append(k)
        else:
            b = m.pop()
            if b > abs(j) - 1:
                m.append(b)
                for k in range(abs(j) -1, -1, -1):
                    m.append(k)
            else:
                for k in range(abs(j), -1, -1):
                    m.append(k)
    else:
        if j > 0:
            for k in range(0, abs(j) + 1, 1):
                m.append(k)
        else:
            for k in range(abs(j), -1, -1):
                m.append(k)
            
print(sum(m))

Measured memory_bytes: 24092
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  size_t N, D;
  cin >> N >> D;

  vector<vector<double>> X;
  for (size_t i = 0; i < N; i++) {
    vector<double> x;
    for (size_t j = 0; j < D; j++) {
      double _x;
      cin >> _x;
      x.emplace_back(_x);
    }
    X.emplace_back(x);
  }

  size_t ans = 0;
  for (size_t i = 0; i < N - 1; i++) {
    for (size_t j = 1; j < N; j++) {
      if (i >= j) continue;
      double result = 0;
      for (size_t d = 0; d < D; d++) {
        result += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
      }
      auto sqrt_res = sqrt(result);
      if (sqrt_res == ceil(sqrt_res) && sqrt_res == floor(sqrt_res)) {
        ans ++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] ary = new char[s.length()];
		for (int i = 0; i < s.length(); i++) {
			ary[i] = s.charAt(i);
		}

		int index = s.length();
		char[] dreamer = { 'r', 'e', 'm', 'a', 'e', 'r', 'd' };
		char[] dream = { 'm', 'a', 'e', 'r', 'd', '&', '&' };
		char[] eraser = { 'r', 'e', 's', 'a', 'r', 'e', '&' };
		char[] erase = { 'e', 's', 'a', 'r', 'e', '&', '&' };

		int iDreamer = 0;
		int iDream = 0;
		int iEraser = 0;
		int iErase = 0;

		while (true) {
			if (index == 0) {
				System.out.println("YES");
				break;
			} else if (index < 5) {
				System.out.println("NO");
				break;
			}
			iDreamer = 0;
			iDream = 0;
			iEraser = 0;
			iErase = 0;
			int dex = 0;
			for (int i = index - 1; i >= index - 7 && i >= 0; i--) {
				if (dreamer[dex] == ary[i]) {
					iDreamer++;
				}
				if (dream[dex] == ary[i]) {
					iDream++;
				}
				if (eraser[dex] == ary[i]) {
					iEraser++;
				}
				if (erase[dex] == ary[i]) {
					iErase++;
				}
				dex++;
			}
			if (iDreamer != 7) {
				iDreamer = 0;
			}
			if (iDream != 5) {
				iDream = 0;
			}
			if (iEraser != 6) {
				iEraser = 0;
			}
			if (iErase != 5) {
				iErase = 0;
			}
			int m = Math.max(Math.max(iErase, iEraser), Math.max(iDreamer, iDream));
			if (m == 0) {
				System.out.println("NO");
				break;
			}
			index -= m;

		}
		return;
	}
}

Measured memory_bytes: 26964
# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))

h,w = mp()
ch, cw = mp()
dh,dw = mp()
ch += 1
cw += 1
dh += 1
dw += 1
grid = []
grid.append(["#"]*(w+4))
grid.append(["#"]*(w+4))
ans_grid = []
for i in range(h):
    u = ["#", "#"]
    a = list(input())
    for j in range(w):
        u.append(a[j])
    u.append("#")
    u.append("#")
    grid.append(u)
grid.append(["#"]*(w+4))
grid.append(["#"]*(w+4))

for i in range(h+4):
    ans_grid.append([int(1e6+2)]*(w+4))
# print(grid)
# print(ans_grid)

from collections import deque
def bfs(x,y):
    q = deque([])
    used = set()
    q.append((x,y))
    used.add((x,y))
    ans_grid[x][y] = 0
    while q:
        here = q.popleft()
        move = [(here[0]-1, here[1]),
                (here[0], here[1]-1),
                (here[0], here[1]+1),
                (here[0]+1, here[1])]
        warp = [(here[0]-2, here[1]-2), (here[0]-2, here[1]-1), (here[0]-2, here[1]), (here[0]-2, here[1]+1), (here[0]-2, here[1]+2),
                (here[0]-1, here[1]-2), (here[0]-1, here[1]-1), (here[0]-1, here[1]+1), (here[0]-1, here[1]+2),
                (here[0], here[1]-2), (here[0], here[1]+2),
                (here[0]+1, here[1]-2), (here[0]+1, here[1]-1), (here[0]+1, here[1]+1), (here[0]+1, here[1]+2),
                (here[0]+2, here[1]-2), (here[0]+2, here[1]-1), (here[0]+2, here[1]), (here[0]+2, here[1]+1), (here[0]+2, here[1]+2)]
        for i in range(len(warp)):
            u = warp[i][0]
            v = warp[i][1]
            if grid[u][v] == "." and ans_grid[u][v] > ans_grid[here[0]][here[1]]+1:
                ans_grid[u][v] = min(ans_grid[u][v], ans_grid[here[0]][here[1]]+1)
                q.append((u,v))
        for i in range(len(move)):
            u = move[i][0]
            v = move[i][1]
            if (move[i] not in used or ans_grid[u][v] > ans_grid[here[0]][here[1]]) and grid[u][v] == ".":
                ans_grid[u][v] = min(ans_grid[here[0]][here[1]], ans_grid[u][v])
                q.appendleft((u,v))
                used.add((u,v))

bfs(ch,cw)
ans = ans_grid[dh][dw]
# print(ans_grid)
if ans == int(1e6+2):
    print(-1)
else:
    print(ans)




Measured memory_bytes: 217784
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;

#define NUM 1000
int dp[NUM + 1][NUM + 1];

void calc(string X, string Y){
    for(int i = 0; i <= X.size(); i++){
        for(int j = 0; j <= Y.size(); j++){
            dp[i][j] = 0;
        }
    }

    for(int j = 1; j <= Y.size(); j++){
        for(int i = 1; i <= X.size(); i++){
            if(X[i - 1] == Y[j - 1]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }else{
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    
    printf("%d\n", dp[X.size()][Y.size()]);

}

int main(void){
    int q;
    scanf("%d", &q);

    for(int i = 0; i < q; i++){
        string X;
        string Y;
        cin >> X;
        cin >> Y;
        calc(X, Y);
    }
}




Measured memory_bytes: 7240
/* **************************************************** */
/*                      Author : rakati                 */
/* **************************************************** */
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define RP(i,a,b) for(int i = (a); i < (int)(b); i++)
#define RV(i,a,b) for(int i = (a); i > (int)(b); i--)
#define SHOW(v,d) {RP(i,0,v.size()) cout << v[i] << d;cout << '\n';}
#define ALL(x) x.begin(),x.end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
 
const double EPS = 1e-9;
const double PI = 3.14159265359;
const int INF = 1e9;
 
using ll    = long long;
using ull   = unsigned long long;
using vi    = vector<int>;
using vl    = vector<ll>;
using vb    = vector<bool> ;
using vc    = vector<char>;
using vii   = vector<vi>;
using vll   = vector<vl>;
using pii   = pair<int, int>;
using pll   = pair<ll, ll>;
using vpii  = vector<pii>;
using vpll  = vector<pll>;
 
 
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    int a, b;
    cin >> a >> b;
    char s[a+b+1];
    cin >> s;
    int c = 0;
    for (int i = 0; i < a + b + 1; i++) {
        if (s[i] >= '0' && s[i] <= '9') c++;
    }
    if (c == a + b && s[a] == '-') cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int n;int a[50];
int cul(int i,int m){
  if(m==0) return 1;
  if(i>=n) return 0;
  int res=cul(i+1,m) || cul(i+1,m-a[i]);
  return res;
}


int main(){
  int i,q,m;
  
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&m);
    if(cul(0,m))printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<vector>
using namespace std;
vector<int>G[22];
bool used[22],ok[22];
int n,m;
void f(int u)
{
	used[u]=1;
	for(int i=0;i<G[u].size();i++)
	{
		if(used[G[u][i]])continue;
		f(G[u][i]);
	}
	cout<<u<<endl;
}
main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y;cin>>x>>y;
		G[y].push_back(x);
		ok[x]=1;
	}
	for(int i=1;i<=n;i++)
	{
		if(!ok[i])
		{
			f(i);
			return 0;
		}
	}
}



Measured memory_bytes: 3152
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  string s;
  cin >> s;

  if (s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
ll M = 1e9 + 7;

ll mod(ll a, ll m)
{
    if (a == 0)
        return 0;
    else
        return (a % m + m) % m;
}
int mod(string num, int a)
{

    int res = 0;

    for (int i = 0; i < num.length(); i++)
        res = (res * 10 + (int)num[i] - '0') % a;

    return res;
}
ll f(ll a)
{
    for (ll i = 2; i * i <= a; i++)
        if (a % i == 0)
            return i;
}
int main()
{
    fio;
    ll t, n, q, k, i, m, u, j, p, r, c, a, b, d;
t=1;
    while (t--)
    {
       cin>>n;
       p = n % 10;
       if (p == 2 || p == 4
           || p == 5 || p == 7 || p==9)cout<<"hon";
       else if ( p == 0 || p == 1 || p == 6 || p == 8)cout<<"pon";
       else cout<<"bon";
        }
    return 0;
}

Measured memory_bytes: 3652
# import bisect
# from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    if n < 1000:
        print("ABC")
    else:
        print("ABD")

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
def main():
    N, K = map(int, input().split())
    XY = (tuple(map(int, input().split())) for _ in [0] * N)

    x = [0] * N
    y = [0] * N
    for i, (j, k) in enumerate(XY):
        x[i] = j
        y[i] = k

    ans = float('inf')
    for xi in range(N):
        for xj in range(N):
            if x[xi] >= x[xj]: continue
            for yi in range(N):
                for yj in range(N):
                    if y[yi] >= y[yj]: continue
                    cnt = 0
                    for i in range(N):
                        if x[xi] <= x[i] <= x[xj] and y[yi] <= y[i] <= y[yj]:
                            cnt += 1
                    if cnt >= K:
                        ans = min(ans, (x[xj] - x[xi]) * (y[yj] - y[yi]))

    print(ans)

main()


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



int main ()
{
    int x,y,w,h,r;
    cin >> w >> h >> x >> y >> r;

    if( x+r>w || x-r<0) {cout << "No" << endl; return 0;}
    else if( y+r>h || y-r<0){ cout << "No" << endl;    return 0;}

    else cout << "Yes" << endl;
    
}



Measured memory_bytes: 3112
n,m=map(int,input().split())
somelists=[]

for i in range(m):
    a,b=map(int,input().split())
    somelists.append([i,a,b])

somelists.sort(key=lambda x:(x[1],x[2]))

prefs=1
numbers=0

for x in somelists:
    
    if x[1]==prefs:
        numbers+=1
        
        x.append(numbers)
    if x[1]!=prefs:
        prefs=x[1]
        numbers=1
        x.append(numbers)

somelists.sort(key=lambda x:x[0])
for _ in range(m):
    print(str(somelists[_][1]).zfill(6)+str(somelists[_][3]).zfill(6))


Measured memory_bytes: 35504
#include "bits/stdc++.h"
using namespace std;
int N;
vector<int>to[100005];
vector<int>dist;
bool dfs(int v, int d = 0, int p = -1) {
	dist[v] = d;
	for (int e : to[v]) {
		if (p == e) {
			continue;
		}
		dfs(e,d+1,v);
	}
	return false;
}
vector<int>f(int x) {
	dist = vector<int>(N);
	dfs(x);
	return dist;
}

int main() {
	int u, v;
	cin >> N >> u>> v;
	u--;
	v--;
	for (int n = 0;n<N-1;++n) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	vector<int>DistU =f(u);
	vector<int>DistV =f(v);
	int ans = 0;
	for (int n = 0;n<N;++n) {
		if (DistU[n] < DistV[n]) {
			ans = max(ans, DistV[n]);
		}
	}
	cout << ans -1<<endl;
	return 0;
}

Measured memory_bytes: 13604
N = int(input())
S = input()
# list = [0]
x = 0
ans = 0
# for i in S:
#     if i == 'I':
#         x += 1
#     else:
#         x -= 1
#     list.append(x)
# print(max(list))

for i in S:
    if i == 'I':
        x += 1
    else:
        x -= 1
    ans = max(x, ans)
print(ans)

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main{
    public static void main(String arg[]){
        Scanner sc=new Scanner(System.in);
        int w=sc.nextInt();
        int n=sc.nextInt();
        String[] data=new String[w];
        for(int i=0;i<n;i++)data[i]=sc.next();
        int[] ans=new int[w];
        for(int i=0;i<w;i++)ans[i]=i+1;
        for(int i=0;i<n;i++){
            String[] str=data[i].split(",",0);
            int swap;
            int a=Integer.valueOf(str[0]);
            int b=Integer.valueOf(str[1]);
            swap=ans[a-1];
            ans[a-1]=ans[b-1];
            ans[b-1]=swap;
        }
        for(int i=0;i<w;i++)System.out.println(ans[i]);
        sc.close();
    }
}


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

int main()
{
    int a[3];
    scanf("%d%d%d", &a[0], &a[1], &a[2]);
    int ans = 0x3fffffff;
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            for(int k = 0; k < 3; k++)
            {
                if(i != j && j != k && k != i)
                {
                    ans = std::min(ans,abs(a[i] - a[j]) + std::min( abs(a[j] - a[k]), abs(a[i] - a[k])));
                }
            }
        }
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 384
import collections

def primes(n): #試し割り法で各素因数とその指数を求める
 cnt=collections.defaultdict(int)
 for i in range(2,int(n**0.5)+1):
   if n%i==0:
     while n%i==0:
       cnt[i]+=1
       n//=i
 if n!=1:
   cnt[n]+=1
 return cnt

n=int(input())
cnt=primes(n)
ans=0
for key in cnt.keys():
 val=cnt[key]
 for i in range(100): #各素因数の指数について、k(k+1)//2<=(指数)を満たす最大のkを求める
   if (i*(i+1))//2>val:
     ans+=i-1
     break
print(ans)

Measured memory_bytes: 9720
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;

int main() {
  int n;
  ll sum = 0;
  cin >> n;
  for(int i=1; i<= n; i++) {
    if(i % 3 != 0 && i % 5 != 0) sum+= i;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " : " << p.second << "}";
	return os;
}

template<typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	string A, B, C;
	cin >> A >> B >> C;

	char p = 'a';
	while (true) {
		switch (p)
		{
		case 'a':
			if (A.empty()) {
				cout << 'A' << endl;
				return 0;
			}
			p = A.front();
			A.erase(A.begin());
			break;
		case 'b':
			if (B.empty()) {
				cout << 'B' << endl;
				return 0;
			}
			p = B.front();
			B.erase(B.begin());
			break;
		case 'c':
			if (C.empty()) {
				cout << 'C' << endl;
				return 0;
			}
			p = C.front();
			C.erase(C.begin());
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

ll f(ll a, ll b){
    string s=to_string(a),t=to_string(b);
    ll na=s.size(),nb=t.size();
    return max(na,nb);
}

int main(void)
{
    ll n,ans=INF; cin>>n;
    for(ll i=1; i*i<=n; i++){
        if(n%i==0){
            ll j = n/i;
            ans = min(ans, f(i,j));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
	int m, tibi, deka;
	int data[300];
	int n = 0;
	int sa = -10;
	int basyo = 0;
	while (true) {
		sa = -10;
		basyo = 0;
		cin >> m >> tibi >> deka;
		if (m == 0) break;
		for (int i = 0; i < m; i++) {
			cin >> data[i];
		}
		for (int i = tibi-1; i < deka; i++) {
			if (sa <= abs(data[i] - data[i + 1])) {
				sa = abs(data[i] - data[i + 1]);
				basyo = i+1;
			}
		}
		cout << basyo << endl;
	}
}


/*
#include <iostream>
#include <algorithm>
#include <math.h>

int kiriage(double a) {
	if ((a - (double)(int)a) > 0) {
		return (int)a + 1;
	}
	else {
		return (int)a;
	}
}

using namespace std;

int main() {
	int count = 0;
	int x, y, s;
	int m;
	int z;
	int mm[1001];
	int zz[1001];
	int n;
	int tuyoi = -100;
	while (true) {
		tuyoi = -100;
		cin >> x >> y >> s;
		if (s == 0) break;
		for (double i = 1; i < s/2; i++) {
			m = kiriage((s - i) * (100+y) / (100 + x));
			z = kiriage(((100+y) * i / (100 + x)));
//			cout << m << z << endl;
			if (tuyoi < m+z) {
				tuyoi = m+z;
			}
		}
		cout << tuyoi << endl;
	}
}*/


Measured memory_bytes: 3116
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>

using namespace std;
char ch;
int main()
{
	cin>>ch;
	if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
	cout<<"vowel";
	else
	cout<<"consonant";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
#include <map>
#include <cstring>
#include <cassert>
 
using namespace std;

int main(){

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

    int res=-1;

    for(int ab=0;ab<100;ab++){
        for(int bc=0;bc<100;bc++){
            for(int ac=0;ac<100;ac++){
                int A=a+ab+ac;
                int B=b+ab+bc;
                int C=c+ac+bc;

                int ABC[]={A,B,C};
                sort(ABC,ABC+3);

                if( (ABC[2]-ABC[0])%2==0 && (ABC[2]-ABC[1])%2==0){
                    int cost = ab+bc+ac+(ABC[2]-ABC[0])/2 + (ABC[2]-ABC[1])/2;
                    if(res==-1 || res>cost){
                        res=cost;
                    }
                }
            }
        }
    }

    cout<<res<<endl;

}


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

ll N;
int X[100005];
const ll mod = 1000000007LL;
int main(){
  cin >> N;
  for(int i=0;i<N;i++) cin >> X[i];

  ll res = 1; 
  ll cnt = 0;
  for(int i=0;i<N;i++){
    if( 2*cnt+1 <= X[i] ) 
      cnt++;
    else 
      res = (res*(cnt+1LL))%mod;        
  }
  
  for(ll i=1;i<=cnt;i++)
    res = (res*i)%mod;
  cout << res << endl;
}


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

int main() {
  string S;
  cin >> S;
  S = regex_replace(S, regex("9"), "x");
  S = regex_replace(S, regex("1"), "9");
  S = regex_replace(S, regex("x"), "1");
  cout << S << "\n";
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a-2*b > 0) cout << a-2*b << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define mem(x,y)		(x*)malloc(sizeof(x)*(y))
#define PI 3.14159265358979


int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	int i;
	for(i = 0;i < k;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		if(a > n/2)
		{
			a = n-a+1;
		}
		if(b > n/2)
		{
			b = n-b+1;
		}
		if(a > b)
		{
			printf("%d\n",(b-1)%3+1);
		}
		else 
		{
			printf("%d\n",(a-1)%3+1);
		}
	}
	return 0;
}

Measured memory_bytes: 0
import sys

input=sys.stdin.readline
sys.setrecursionlimit(10**7)

N=int(input())
edge=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)

antena=[]
for i in range(N):
    if len(edge[i])>2:
        antena.append(i)

if not antena:
    print(1)
    exit()

parent=[-1]*N
root=antena[0]

def dfs(v,pv):
    parent[v]=pv
    for i in edge[v]:
        if i!=pv:
            dfs(i,v)

dfs(root,-1)

antena=set(antena)

q=[root]
sub=[]
while q:
    while q:
        x=q.pop()
        if x in antena:
            v=x
            while parent[v] not in antena and parent[v]!=-1:
                antena.add(parent[v])
                v=parent[v]
        for nv in edge[x]:
            if nv!=parent[x]:
                sub.append(nv)

        if not q:
            q=sub
            sub=[]
            break

ans=0
for u in antena:
    if len(edge[u])==1:
        ans+=1
    elif len(edge[u])==2:
        check=0
        for v in edge[u]:
            check+=(v in antena)
        if check==1:
            ans+=1
    else:
        check=0
        for v in edge[u]:
            check+=(v in antena)
        if check>=len(edge[u])-1:
            continue
        else:
            ans+=len(edge[u])-1-check
print(ans)


Measured memory_bytes: 70588
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char *argv[])
{
    double A, B, H, M;
    
    cin >> A >> B >> H >> M;

    double degm = 2.0 * M_PI * M / 60.0;
    double degh = H * (M_PI / 6.0) + (M_PI / 6.0) * M / 60.0;

    double th = abs(degh - degm);
    double d2 = A * A + B * B - 2 * A * B * cos(th);

    printf("%.20lf\n", sqrt(d2));

    return 0;
}

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


int main() {
    
    long long N, K;
    cin >> N >> K;
    
    if (N % K == 0) {
        cout << 0 << endl;
        return 0;
    }
    
    long long ans = N;
    while (N / K != 0) {
        N = N % K;
        ans = N;
    }
    
    long long sum = abs(N - K);
    if (sum < N) {
        cout << sum << endl;
    }else{
        cout << N << endl;
    }  
    
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair

const int maxn = 10;
int c[maxn][maxn];

void solve()
{
    int h, w;
    cin >> h >> w;
    
    int n = 10;
    for(int i = 0; i < n; i++)
    {
        for(int k = 0; k < n; k++)
        {
            cin >> c[i][k];
        }
    }
    
    for(int k = 0; k < n; k++)
    {
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < n; j++)
            {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    
    int res = 0;
    for(int i = 0; i < h; i++)
    {
        for(int k = 0; k < w; k++)
        {
            int x;
            cin >> x;
            if(x == -1)
            {
                continue;
            }
            res += c[x][1];
        }
    }
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    //freopen("file.in", "r", stdin);freopen("file.out", "w", stdout);
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int t = sc.nextInt();

        double x = t+0.5;

        int bisnum = ((int)(x / a) * b);

        System.out.println(bisnum);
    }

}


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

typedef long long ll;

int main() {
    int n, H, A;
    scanf("%d %d", &H, &A);

    n = H / A;
    if (H % A > 0) {
        n++;
    }
    printf("%d\n", n);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int T = sc.nextInt();
        int ans = solve(A, B, T);

        System.out.println(ans);
    }

    private static int solve(int A, int B, int T) {
        int S = B*(T/A);

        return S;
    }
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}

int main(){
    string s;cin >> s;
    ll k; cin >> k;
    ll n = s.size();

    vvvl dp(n+1, vvl(5, vl(2, 0)));
    dp[0][0][0] = 1;
    rep(i,n){
        ll t = s[i] - '0';
        rep(j,4){
            reps(l, 9)dp[i+1][j+1][1] += dp[i][j][1];
            dp[i+1][j][1] += dp[i][j][1];
            reps(l, t-1)dp[i+1][j+1][1] += dp[i][j][0];
            if(t != 0){
                dp[i+1][j+1][0] += dp[i][j][0];
                dp[i+1][j][1] += dp[i][j][0];
            }
            else dp[i+1][j][0] += dp[i][j][0];
        }
        // print(dp[i]);
        // print();
    }

    // print(dp[n]);

    cout << dp[n][k][0] + dp[n][k][1] << endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if(a == 1){
        a = 14;
    }
    if(b == 1){
        b = 14;
    }
    if(a > b){
        cout << "Alice" << endl;
    }else if(a < b){
        cout << "Bob" << endl;
    }else{
        cout << "Draw" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
ID: skipian1
PROB: 
LANG: C++11
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF = 2000000000
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define X first
#define Y second

int main() {
  int n;
  cin >> n;
  string str;
  cin >> str;
  int red = 0;
  int blue = 0;
  for (int i = 0; i < n; i++) {
    if (str.at(i) == 'R') red++;
    else blue++;
  }
  if (red > blue) cout << "Yes" << "\n";
  else cout << "No" << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define int long long
int a[123456], b[123456];
vector<int>v;
signed main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		v.push_back(a[i] - b[i]);
	}
	sort(v.begin(), v.end());
	int f = 0, l = n - 1;
	bool b = 0;
	while (v[f] < 0) {
		if (v[l] < 0 || f == l) {
			cout << "-1\n";
			return 0;
		}
		while (v[f] < 0) {
			if (v[l] < 0 || f == l) {
				cout << "-1\n";
				return 0;
			}
			if (-v[f] >= v[l]) {
				v[f] += v[l];
				v[l] = 0;
				l--;
				b = 0;
			}
			else {
				b = 1;
				v[l] += v[f];
				v[f] = 0;
			}
		}
		f++;
	}
	if (!b)l++;
	cout << f + (n - l) << endl;
}

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

int main(){
	for(int i=0;i<10000;i++){
		int x,y;
		cin>>x>>y;
		if(x==0&&y==0){
		return 0;
		}else if (x>y){
			cout<<y<<" "<<x;
		}else if(y>x){
			cout<<x<<" "<<y;
		}else{
			cout<<x<<" "<<y;
		}
		cout<<endl;
	}
		
	return 0;

}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main()
{
    char a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a==b&&c==d&&a!=c&&a!=d)
    {
        cout<<"Yes";
    }
    else if(a==d&&b==c&&a!=b&&a!=c)
    {
        cout<<"Yes";
    }
    else if(a==c&&b==d&&a!=b&&a!=d)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
 
 
 
    return 0;
}

Measured memory_bytes: 256