akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> init(n,0);
    vector<vector<int> > adj(n, init);

    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        for(int j = 0; j < n; j++){
            adj[i][j] = s[j] - '0';
        }
    }

    int sol = -1;

    for(int st = 0; st < n; st++ ){
        vector<vector<int> > V;
        vector<int> given(n, -1);

        vector<int> first = {st};
        V.push_back(first);
        given[st] = 0;

        while(true){
            vector<int> neu;
            for(v : V.back()){
                for(int i = 0; i < n; i++){
                    if(adj[v][i] == 1 && given[i] == -1){
                        given[i] = V.size();
                        neu.push_back(i);
                    }
                }
            }
            if(neu.empty()){
                break;
            }
            else{
                V.push_back(neu);
            }
        }
        bool ok = true;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(adj[i][j] == 1){
                    if(abs(given[i]-given[j]) != 1){
                        ok = false;
                        break;
                    }
                }
            }
        }

        if(ok)
            sol = max(sol, (int)(V.size()));
    }

    cout << sol << endl;

    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	int m=0;
	int i=0;
	while(m<n)
	{
		i++;
		m+=i;
	}
	int a=m-n;
	int b=i;
	for(i=1;i<=b;i++)
		if(i!=a)
			printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <ctime>
#define ESP 1e-10
using namespace std;
int main() {
	bool flag = false;
	time_t c1;
	while (true) {
		int H, W; cin >> H >> W;
		if (!flag) { c1 = clock(); flag = true; }
		if (H == 0 && W == 0) break;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W;j++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	time_t c2;
	while (true) {
		c2 = clock();
		if (c2 - c1 > 5000) break;
	}
}

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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;

const ll modval = pow(10,9) + 7;

template <typename T>
vector<T> getValues(int num){
    vector<T> values(num);
    for(int i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

int main(){
    int N;
    cin >> N;
    auto inputs = getValues<ll>(N);
    ll sumOfStep = 0;
    ll front = inputs.at(0);
    for(int i=1;i<N;i++){
      ll target = inputs.at(i);
      int step = 0;
      if(front>target){
        step = front -target;
        sumOfStep += step;
      }
      front = step + inputs.at(i);
    }
    printl(sumOfStep);
}


Measured memory_bytes: 4848
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    int n; cin >> n;
    int a[100010]; rep(i,0,n) {cin >> a[i]; a[i]--; }
    bool check[100010];
    memset(check, false, sizeof(check));

    int ans = 0;
    rep(i,0,n) {
        if(check[i]) continue;
        if(a[a[i]] == i) {
            check[i] = true;
            check[a[i]] = true;
            ans++;
        }
        else check[i] = true;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int N;
    cin >> N;
    int d[N];
    rep(i, N) cin >> d[i];

    int sum = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            sum += d[i] * d[j];
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
k = int(input())

memo = [[-1 for _ in range(k+1)] for _ in range(k+1)]


def gcd(a, b):
    if -1 != memo[a][b]:
        return memo[a][b]
    r = a % b
    if r == 0:
        memo[a][b] = b
        return b
    else:
        ans = gcd(b, r)
        memo[a][b] = ans
        return ans


def gcd_m(a, b, c):
    lst = sorted([a, b, c], reverse=True)
    return gcd(gcd(lst[0], lst[1]), lst[2])


ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd_m(a, b, c)
print(ans)


Measured memory_bytes: 69232
function Main(input) {
    input = input.split("\n");
    var input1 = input[0].split(" ");
    var H = parseInt(input1[0]);
    var W = parseInt(input1[1]);

    var input2 = input[1].split(" ");
    var h = parseInt(input2[0]);
    var w = parseInt(input2[1]);

    var b = h * W + w * H - h * w;
    // console.log("b:" + b);
    var ans = H * W - b;
    console.log(ans)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "YES"
#define FALSE__ "NO"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

int K;
priority_queue<pair<int, pair<int, int> > > q;
//                 cost        s    t
vector<int> cost;
vector<bool> f;
const int INF = INT_MAX;

void init()
{
	cin >> K;
	cost.RS(K, INF);
}


void solve()
{
	cost[1] = 1;
	q.push(MP(-1, MP(1, 10 % K)));
	q.push(MP(-2, MP(1, 2 % K)));
	while (!q.empty()) {
		auto x = q.top();
		q.pop();
		int s = x.second.first;
		int t = x.second.second;
		int c = -x.first;
		if (cost[t] != INF) continue;
		cost[t] = c;
		q.push(MP(-c, MP(t, t * 10 % K)));
		q.push(MP(-c-1, MP(t, (t + 1) % K)));
	}
	cout << cost[0] << endl;
}





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

int FindSumOfDigit(int n){
    int sum = 0;
    while(n>0){
        sum += n%10;
        n/=10;
    }
    return sum;
}

int main(){
    int N, A, B;
    int total = 0;;
    cin >> N >> A >> B;
    for(int i = 1; i <= N; i++){
        int sum = FindSumOfDigit(i);
        if(sum >= A && sum<=B){
            total +=i;
        }
    }
    cout << total << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split().Select(long.Parse).ToArray();

            var set1 = new HashSet<string>();
            for (int i = 0; i < N; i++)
            {
                set1.Add(input[i].ToString());
            }

            Console.WriteLine(N == set1.Count ? "YES" : "NO");
        }
    }
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

const ll BINF = 0x3f3f3f3f3f3f3f3f;
const int N = 55, S = 25;
ll f[N][S][3];
bool vis[N][S][3];

int main() {
    int n; cin >> n;
    vll c(n);
    vector <string> s(n);
    FOR(i, 0, n - 1)
        cin >> s[i] >> c[i];
    
    function <ll(int, int, int)> dfs = [&] (int x, int y, bool z) -> ll {
        if (y == sz(s[x])) return 0;
        ll &u = f[x][y][z]; bool &v = vis[x][y][z];
        if (v) return u;
        v = 1, u = BINF;
        bool palin = 1;
        if (!z) {
            for (int l = y, r = sz(s[x]) - 1; l < r; l++, r--)
                if (s[x][l] != s[x][r]) palin = 0;
        }
        else {
            for (int l = y, r = 0; l > r; l--, r++)
                if (s[x][l] != s[x][r]) palin = 0;
        }
        if (palin) return v = 0;
        FOR(i, 0, n - 1) {
            if (!z) {
                bool hv = 1;
                if (sz(s[i]) <= sz(s[x]) - y) {
                    int j = y;
                    for (int k = sz(s[i]) - 1; k >= 0; j++, k--)
                        if (s[i][k] != s[x][j]) hv = 0;
                    if (hv) u = min(u, c[i] + dfs(x, j, z));
                }
                else  {
                    int k = sz(s[i]) - 1;
                    for (int j = y; j < sz(s[x]); j++, k--)
                        if (s[i][k] != s[x][j]) hv = 0;
                    if (hv) u = min(u, c[i] + dfs(i, k, !z));
                }
            }
            else {
                bool hv = 1;
                if (sz(s[i]) < y + 1) {
                    int j = y;
                    for (int k = 0; k < sz(s[i]); j--, k++)
                        if (s[i][k] != s[x][j]) hv = 0;
                    if (hv) u = min(u, c[i] + dfs(x, j, z));
                }
                else  {
                    int k = 0;
                    for (int j = y; j >= 0; j--, k++)
                        if (s[i][k] != s[x][j]) hv = 0;
                    if (hv) u = min(u, c[i] + dfs(i, k, !z));
                }
            }
        }
        return u;
    };

    ll ans = BINF;
    FOR(i, 0, n - 1)
        ans = min(ans, c[i] + dfs(i, 0, 0));
    if (ans < BINF) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 3680
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		var line0 = Console.ReadLine().Split(new char[]{' '}).Select(c => Int32.Parse(c)).ToArray();
		var n = line0[0];
		var k = line0[1];
		var org = Console.ReadLine().Split(new char[]{' '}).Select(c => Int32.Parse(c)).ToArray();
		var ans = Enumerable.Repeat(0, n).ToArray();
			var diff = true;
		for (var i = 0; (i < k) && diff; i++)
		{
			diff = false;
			for (var j = 0; j < n; j++)
			{
				var xl = j - org[j];
				ans[(xl > -1) ? xl : 0]++;
				var xr = j + org[j] + 1;
				if (xr < n)
				{
					ans[xr]--;
				}
			}
			var acc = 0;
			for (var j = 0; j < n; j++)
			{
				acc += ans[j];
				if (org[j] != acc)
				{
					diff = true;
				}
				org[j] = acc;
			}
			ans = Enumerable.Repeat(0, n).ToArray();
		}
		Console.WriteLine(string.Join(" ", org));
	}
}


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

long long ans, n;
 
int main() {
    string s;
    cin >> n >> s;
    for (int i = 0; i < (1 << n); i++) {
        string lr, lb;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j))
                lr += s[j];
            else
                lb += s[j];
        }
 	//cerr << lr << " " << lb << "\n";
        long long dp[40][20];
        memset(dp, 0, sizeof dp);
        dp[n * 2][0] = 1;
        for (int j = n * 2 - 1; j >= n; j--) {
            for (int k = 0; k <= (int)lr.size(); k++) {
                dp[j][k] += (k > 0) * dp[j + 1][k - 1] * (s[j] == lr[k - 1]);
                dp[j][k] += dp[j + 1][k] * (s[j] == lb[(n * 2 - j) - k - 1]);
            }
        }        
		ans += dp[n][(int)lr.size()];
    }
    cout << ans;
    return 0;
}

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

int main() {
    ll N, M; cin >> N >> M;
    ll min_id = 0;
    ll max_id = 10000000;
    for (int i = 0; i < M; i++){
        ll L, R; cin >> L >> R;
        if(min_id < L) min_id = L;
        if(R < max_id) max_id = R;
    }
    if(max_id < min_id){
        cout << 0 << endl;
    }
    else cout << max_id - min_id + 1 << endl;
}

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

int dfs(string s, string query, int K)
{
    if (K == 0)
    {
        return 0;
    }
    query += "a";
    for (int i = 0; i < 26; i++)
    {
        if (s.find(query) != string::npos)
        {
            if (K > 0)
            {
                K--;
                if (K == 0)
                {
                    cout << query << endl;
                }
                else
                {
                    K = dfs(s, query, K);
                }
            }
        }
        query.back()++;
    }
    return K;
}

int main()
{
    string s;
    int K;
    cin >> s;
    cin >> K;
    dfs(s, "", K);
}


Measured memory_bytes: 256
#include <stdio.h>


int f(int);

int main(){
  int n;

  scanf("%d",&n);

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

  return 0;
}

int f(int n){
  int f[45],i;
  
  f[0]=f[1]=1;
  for(i=2;i<=n;i++){
  f[i]=f[i-1]+f[i-2];
  
  }

  return f[n];
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
int main(){

  long long int N;
  cin >> N;
  long long int ans = 1;
  for(int i = 1;i < N;i++){
    if(i * i <= N)ans = i * i;
    else break;
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
// x^y≡x^(y%(p-1))mod p
// but there is a condition that x needs to be coprime to p
///assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set; */
typedef long long int ll;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
#define  pb push_back
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define tests() int test_cases ; cin >> test_cases ; while(test_cases--)
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define MAXN 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define sp " "
#define MS(x,y) fill_n(*x, sizeof x / sizeof **x, y);
#define mem(x,y) memset(x,y,sizeof(x));
#define INF 1000000000000000000
#define IO                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define debug(x) cerr << (#x) << " is " << (x) << endl;

#ifndef ONLINE_JUDGE
#define cerr if(true)cerr
#endif

template<int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
static_assert(D >= 1, "Vector dimension must be greater than zero!");
template<typename... Args>
	Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
	}
};
template<typename T>
struct Vec<1, T> : public vector<T> {
	Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {
	}
};

ll power(ll x, ll y,ll p)
{
    ll res = 1;     // Initialize result
    x = x % p;
    if (y==0)return 1;
    if(x==0)return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;  // Change x to x^2
    }
    return res;
}
int gcd(int a, int b) { if (a == 0)return b;return gcd(b % a, a);}

ll modinv(ll a,ll p){return power(a,p-2,p);}


void solve(){
    ll n,k;
    cin>>n>>k;
    Vec<1,ll> h(n+1);
    f(i,0,n){
        cin>>h[i+1];
    }
    Vec<1,ll> dp(n+1,INF);
    dp[1] = 0;
    fo(i,1,n){
        fo(j,1,k){
            if (i+j<=n)
            {
                dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]));
            }
        }
    }
    cout<<dp[n]<<endl;
    return ;
}
int main()

{
    IO;
    int T=1;
	// cin >> T;
	f(c,0,T){
		solve();
	}
    return 0;
}// make_pair make_tuple  tuple<int,int,int> continue resize insert count size else true isValid second first false erase


Measured memory_bytes: 1792
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;

int main()
{
	int a,b,c,d;
	while(~scanf("%d %d %d %d",&a,&b,&c,&d))
	{
		if(a+b<c+d)
			cout<<"Right"<<endl;
		else if(a+b>c+d)
			cout<<"Left"<<endl;
		else
			cout<<"Balanced"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
def insertionSort(a, n, g)
  g.upto(n-1) do |i|
    v = a[i]
    j = i - g
    while 0 <= j && v < a[j]
      a[j+g] = a[j]
      j = j - g
      $cnt += 1
    end
    a[j+g] = v
  end
end

def shellSort(a, n)
  h = 1
  while h < n / 3
    h = 3 * h + 1
    $g.unshift(h)
  end
  $m = $g.size

  0.upto($m-1) do |i|
    insertionSort(a, n, $g[i])
  end
end

$cnt = 0
$m = 0
$g = [1]

a = []
(n = gets.to_i).times do
  a << gets.to_i
end

shellSort(a, n)

puts $m
puts $g * ' '
puts $cnt
puts a * "\n"

Measured memory_bytes: 26004
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

int main()
{
    int h, w; cin >> h >> w;
    vector<string> b(h);
    for (int i = 0; i < h; i++) {
        cin >> b[i];
    }

    const char* ans = "Yes";
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            bool found = false;
            if (b[i][j] == '.') continue;
            if (i > 0) if (b[i-1][j] == '#') found = true;
            if (i < h-1) if (b[i+1][j] == '#') found = true;
            if (j > 0) if (b[i][j-1] == '#') found = true;
            if (j < w-1) if (b[i][j+1] == '#') found = true;
            if (!found)
                ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}

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

ll a,b,c,d;
cin>>a>>b>>c>>d;
//ll x=(b-a)+1;
//b--;
a--;
ll ans=0;
ans=b/c;
ans-=a/c;
ans+=b/d;
ans-=a/d;
//cout<<ans<<endl;
ll gc=__gcd(c,d);
c/=gc;
c*=d;
//cout<<c<<endl;
ll x=b/c;
x-=a/c;
//cout<<x<<endl;
ans-=x;
//cout<<ans<<endl;
//c*=d;
//cout<<c<<endl;
//ans-=(cv);
cout<<(b-a)-ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807;
const ll half_inf = 0x3f3f3f3f;
const ll inf = 0x7fffffff;
const ll mod = 1e9 + 7;
const ll maxn = 200005;
int main(){  
	cin.tie(0);
    ios::sync_with_stdio(false);
	ll a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	if(4*a*b<(c-a-b)*(c-a-b)&&(c-a-b)>0) printf("Yes");
	else printf("No");
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
int main(){
    ll h, w;
    cin >> h >> w;
    vector<string> grid(h);
    for (ll i = 0; i < h; i++) cin >> grid[i];
    ll dp[h + 1][w + 1];
    for (ll i = 0; i < h+1;i++){
        for (ll j = 0; j < w + 1;j++){
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;
    for (ll i = 0; i < h;i++){
        for (ll j = 0; j < w;j++){
            if (grid[i][j] == '#') dp[i][j] = 0;
            else if(i>0 and j>0)
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
			else if(i>0)
                dp[i][j] = dp[i - 1][j];
			else if(j>0)
                dp[i][j] = dp[i][j - 1];
            dp[i][j] %= MOD;
        }
    }
    cout << dp[h - 1][w - 1] << endl;
}

Measured memory_bytes: 13304
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,m;
    cin>>n>>m;
    vector<ll>adj[n];
    for(int i=0;i<m;i++)
    {
       ll x,y;
       cin>>x>>y;
       x--,y--;
       adj[x].pb(y);
       adj[y].pb(x);
    }
    for(int i=0;i<n;i++)
    {
      cout<<adj[i].size()<<endl;
    }
}
return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#include<complex>
#define EPS 1e-10
using namespace std;
typedef long long llong;
bool f(pair<int, double>a, pair<int, double>b) {
	return a.second < b.second;
}
int main() {
	vector<pair<int, double> >v(24);
	for (int i = 0; i < 24; i++) {
		cin >> v[i].first >> v[i].second;
	}
	//cout << endl << endl;
	//cout << setprecision(4);
	sort(v.begin(), v.begin() + 8, f);
	cout << v[0].first << " " << v[0].second << endl;
	cout << v[1].first << " " << v[1].second << endl;

	sort(v.begin() + 8, v.begin() + 8 + 8, f);
	cout << v[8].first << " " << v[8].second << endl;
	cout << v[9].first << " " << v[9].second << endl;

	sort(v.begin() + 8 + 8, v.end(), f);
	cout << v[16].first << " " << v[16].second << endl;
	cout << v[17].first << " " << v[17].second << endl;

	v.erase(v.begin() + 8 + 8, v.begin() + 8 + 8 + 2);
	v.erase(v.begin() + 8, v.begin() + 8 + 2);
	v.erase(v.begin(), v.begin() + 2);

	sort(v.begin(), v.end(), f);
	cout << v[0].first << " " << v[0].second << endl;
	cout << v[1].first << " " << v[1].second << endl;

	return 0;
}

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

int main()
{
  ios::sync_with_stdio(false);
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    int A = 0, B = 0;
    for (int i = 0; i < n; ++i) {
      int c1, c2;
      cin >> c1 >> c2;
      if (c1 > c2) {
	A += (c1+c2);
      } else if (c1 < c2) {
	B += (c1+c2);
      } else {
	A += c1;
	B += c2;
      }
    }
    cout << A << " " << B << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define N 100005
using namespace std;
int bb[N],ct,*x[N];
bool cmp(int *a,int *b)
{
	return (*a) < (*b);
}
void pppd(int *a,int sz)
{
	for(int i = 1; i <= sz; i ++) x[i] = &a[i];
	ct = 0;
	sort(x + 1, x + sz + 1, cmp);
	bb[1] = ++ ct;
	for(int i = 2; i <= sz; i ++) bb[i] = *x[i] == *x[i-1] ? bb[i - 1]:++ ct;
	for(int i = 1; i <= sz; i ++) *x[i] = bb[i];
}

int n;
int fa[N];
int find(int x)
{
	return fa[x] == x? x:fa[x] = find(fa[x]);
}
void union1(int x, int y)
{
	if(find(x) == find(y)) return;
	fa[find(x)] = find(y);
}

int a[N],b[N];
int c[N],d[N],m;
int main()
{
	scanf("%d",&n);
	int ta = 0, tb = 0;
	for(int i = 1; i <= n; i ++) scanf("%d", &a[i]), ta ^= a[i];
	for(int i = 1; i <= n; i ++) scanf("%d", &b[i]), tb ^= b[i];
	n ++;
	a[n] = ta;
	b[n] = tb;
	for(int i = 1; i <= n; i ++)
		if(a[i] != b[i])
			c[++ m] = a[i], d[m] = b[i];
	int fl1 = 0, fl2 = 0;
	if(a[n] == b[n]) fl1 = 1;
	for(int i = 1; i <= m; i ++)
		if(c[i] == a[n]) fl2 = 1;
	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);
	for(int i = 1; i <= n; i ++)
		if(a[i] != b[i])
			return puts("-1"), 0;

	int ans = 0;
	if(fl1 == 1 && fl2 == 1) ans --;
	if(fl1 == 0) ans -= 2;
	ans += m;

	pppd(c,m);
	pppd(d,m);
	for(int i = 1; i <= m; i ++) fa[i] = i;
	for(int i = 1; i <= m; i ++) union1(c[i], d[i]);
	for(int i = 1; i <= ct; i ++) if(find(i) == i) ans ++;

	cout << ans << endl;
	return 0;
}


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

// ll minCost(ll i,ll n,ll h[]){
//     if(i==n-1){
//         return 0;
//     }
//     if(i==n-2){
//         return abs(h[i]-h[i+1]);
//     }
//     ll c1=abs(h[i]-h[i+1])+minCost(i+1,n,h);
//     ll c2=abs(h[i]-h[i+2])+minCost(i+2,n,h);
//     return min(c1,c2);
// }

int main() {
    ll n;
    cin>>n;
    ll h[n];
    for(ll i=0;i<n;i++){
        cin>>h[i];
    }
    //cout<<minCost(0,n,h);
    ll dp[n];
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    for(ll i=2;i<n;i++){
        dp[i]=min((abs(h[i]-h[i-1])+dp[i-1]),(abs(h[i]-h[i-2])+dp[i-2]));
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 5144
#include <bits/stdc++.h>
//#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
//#include <string.h>
#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
using namespace std;
const LL MOD=1e9+7;
int main()
{
	int n,ans=1e9;
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int a=i,b=n-i,sum=0;
		while(a>0)
		{
			sum+=a%10;
			a/=10;
		}
		while(b>0)
		{
			sum+=b%10;
			b/=10;
		}
		ans=min(ans,sum);
	}
	cout<<ans;
  rt0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MOD 1000000007
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
ll dp[1001][1001];
ll fact[1001];
ll ppow(ll a) {
	ll b=MOD-2;
	ll res = 1;
	while (b) {
		if (b & 1)res = (res*a) % MOD;
		a = (a*a) % MOD;
		b >>= 1;
	}
	return res;
}
ll comb(ll a, ll b) {
	return (((fact[a] * ppow(fact[a - b])) % MOD)*ppow(fact[b])) % MOD;
}
int main() {
	fact[0] = 1;
	int n, a, b, c, d; scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
	for (int i = 1; i <= n; i++)fact[i] = (fact[i - 1] * i) % MOD;
	rep(i, n)dp[i][0] = 1;
	for (int i = a - 1; i < b; i++) {
		for (int j = 0; j <= n; j++) {
			if (j)(dp[i + 1][j] += dp[i][j]) %= MOD;
			if (j - c*(i + 1) < 0)continue;
			ll y = 1, t = n - j;
			rep(p, c - 1) {
				(y *= comb(t + i + 1, t)) %= MOD;
				t += i + 1;
			}
			for (int k = c; j - k*(i + 1) >= 0 && k <= d; k++) {
				(y *= comb(t + i + 1, t)) %= MOD;
				ll o = y;
				(o *= ppow(fact[k])) %= MOD;
				(dp[i + 1][j] += dp[i][j - k*(i + 1)] * o) %= MOD;
				t += i + 1;
			}
		}
	}
	printf("%lld\n",dp[b][n]);
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N, K; cin >> N >> K;
  vector<int> cs(N, 1);
  while (K--)
    {int d; cin >> d;
    for (int i = 0; i < d; ++i)
      {int A; cin >> A;
      cs[A - 1] = 0;}}
  cout << accumulate(cs.begin(), cs.end(), 0) << endl;}

Measured memory_bytes: 3572
#include<stdio.h>
int main(){
  int a[4][3][10]={0},i,j,k,f,s,n;
  scanf("%d\n",&n);
  
  for(f=0;f<n;f++){
    scanf(" %d%d%d%d", &k,&i,&j,&s);
    a[k-1][i-1][j-1]+=s;
  }
  
  for(k=0;k<4;k++){
    for(i=0;i<3;i++){
      for(j=0;j<10;j++){
	if(s<10 || 0<=s)printf(" %d",a[k][i][j]);
      }
      printf("\n");
    }
    if(k!=3)printf("####################\n");
  }
  
  return 0;
}

Measured memory_bytes: 612
import sys
sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))

N = int(input())
x = []
y = []
for i in range(N):
    xy = inpl()
    x.append(xy[0])
    y.append(xy[1])
ans2 = 10**12
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            a = 2*(x[j]-x[i])
            c = 2*(x[k]-x[j])
            b = 2*(y[j]-y[i])
            d = 2*(y[k]-y[j])
            P = x[j]**2 - x[i]**2 + y[j]**2 - y[i]**2
            Q = x[k]**2 - x[j]**2 + y[k]**2 - y[j]**2

            det = a*d - b*c
            if det == 0:
                continue
            Cx = (d*P - b*Q)/det
            Cy = (a*Q - c*P)/det
            r2 = (Cx-x[i])**2 + (Cy-y[i])**2
            for p in range(N):
                if p in (i,j,k):
                    continue
                if (Cx-x[p])**2 + (Cy-y[p])**2 > r2:
                    break
            else:
                if r2 < ans2:
                    ans2 = r2

for i in range(N-1):
    for j in range(i+1,N):
        Cx = (x[i] + x[j])/2
        Cy = (y[i] + y[j])/2
        r2 = ((x[i]-x[j])**2 + (y[i]-y[j])**2)/4
        for p in range(N):
            if p in (i,j):
                continue
            if (Cx-x[p])**2 + (Cy-y[p])**2 > r2:
                break
        else:
            if r2 < ans2:
                ans2 = r2

print(ans2**0.5)

Measured memory_bytes: 52332
#include<iostream>
using namespace std;
int main(){
long x[5],h[4],i,j;
while(cin>>x[0]){
if(x[0]==0)break;
for(i=1;i<=3;i++)h[i]=0;
h[x[0]]++;
for(i=1;i<5;i++){cin>>x[i];h[x[i]]++;}
for(j=0,i=1;i<=3;i++)if(h[i]==0)j++;
if(j==2||j==0){
for(i=0;i<5;i++)cout<<"3"<<endl;
}else{
for(i=1;i<=3;i++)if(h[i]==0)break;
if(i==1){
for(i=0;i<5;i++)cout<<x[i]-1<<endl;
}else if(i==2){
for(i=0;i<5;i++)cout<<(x[i]+1)%3<<endl;
}else if(i==3){
for(i=0;i<5;i++)cout<<x[i]<<endl;
}
}
}
return 0;
}

Measured memory_bytes: 1160
x,n = map(int,input().split())
if n == 0:
    print(x)
    quit()
a = list(map(int,input().split()))

k = 0
while(True):
    if not x-k in a:
        print(x-k)
        quit()
    if not x+k in a:
        print(x+k)
        quit()
    k += 1

Measured memory_bytes: 8960
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

struct Info{
	Info(int arg_to,int arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	bool operator<(const struct Info &arg) const{
			return cost > arg.cost;
	};
	int to,cost;
};


int main(){

	int V,E,start;
	scanf("%d %d %d",&V,&E,&start);

	int *min_cost = new int[V];
	for(int i = 0; i < V; i++)min_cost[i] = BIG_NUM;

	vector<Info> Edges[V];

	min_cost[start] = 0;

	int from,to,cost;
	for(int i = 0; i < E; i++){
		scanf("%d %d %d",&from,&to,&cost);
		Edges[from].push_back(Info(to,cost));
	}

	priority_queue<Info> Q;

	for(int i = 0; i < Edges[start].size(); i++){
		if(min_cost[Edges[start][i].to] > Edges[start][i].cost){
			min_cost[Edges[start][i].to] = Edges[start][i].cost;
			Q.push(Info(Edges[start][i].to, Edges[start][i].cost));
		}
	}

	int min_index;

	while(!Q.empty()){
		if(Q.top().cost > min_cost[Q.top().to]){
			Q.pop();
		}else{
			min_index = Q.top().to;
			Q.pop();
		}

		for(int i = 0; i < Edges[min_index].size(); i++){
			if(min_cost[Edges[min_index][i].to] > min_cost[min_index] + Edges[min_index][i].cost){
				min_cost[Edges[min_index][i].to] = min_cost[min_index] + Edges[min_index][i].cost;
				Q.push(Info(Edges[min_index][i].to,min_cost[Edges[min_index][i].to]));
			}
		}
	}

	for(int i = 0; i < V; i++){
		if(min_cost[i] == BIG_NUM)printf("INF\n");
		else{
			printf("%d\n",min_cost[i]);
		}
	}


	return 0;
}

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

using namespace std;

void add(vector<int> &x, int a, int n) {
  int mul = 1; 
  for (int i = 1; i < 100; ++i) {
    mul *= a;
    if (mul <= n) x.push_back(mul);
    else break;
  }
}

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

  int n;
  cin >> n;

  vector<int> actions;
  add(actions, 6, n);
  add(actions, 9, n);
  sort(actions.begin(), actions.end());

  vector<int> dp(n+1);
  for (int i = 0; i < 6; ++i) dp[i] = i;

  for (int i = 6; i <= n; ++i) {
    int sol = 1e9;
    for (auto &a : actions) {
      if (i < a) break;
      sol = min(sol, dp[i-a]);
    }
    dp[i] = 1 + sol;
  }
  cout << dp[n] << endl;

  return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    int n, w;
    int sw[102];
    cin>>n;
    rep(i, n){
        cin>>w;
        if(i==0) sw[i]=w;
        else sw[i]=sw[i-1]+w;
    }
    int Minim=1000000;
    rep(i, n) Minim=min(Minim, abs(sw[n-1]-2*sw[i]));
    cout<<Minim<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
int main(void){
	int a,b,c,d;cin>>a>>b>>c>>d;
	cout<<((a+b==c+d)?"Balanced":((a+b>c+d)?"Left":"Right"))<<endl;
}

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

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

    //good luck kittu!
    int h, n; cin>>h>>n;
    vector<int> a(n), cost(n);
    for(int i = 0; i<n; i++) cin>>a[i]>>cost[i];

    //dp[i] = min cost needed to break i health
    vector<int> dp(h+1, 1000000007);
    dp[0] = 0;
    for(int i = 0; i<n; i++){
        for(int j = 0; j<=h; j++){
            dp[min(h, j+a[i])] = min(dp[min(h, j+a[i])], dp[j]+cost[i]);
        }
    }
    cout<<dp[h]<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int kabuka[85];
  int n;
  cin >> n;
  REP(i, n) { cin >> kabuka[i]; }

  ll money = 1000;
  ll kabu = 0;
  REP(i, n - 1) {
    if (kabuka[i] < kabuka[i + 1]) {
      kabu = (money / kabuka[i]);
      money += (kabu * (kabuka[i + 1] - kabuka[i]));
    }
  }
  cout << money << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}


int main(){
    int N;
    cin >> N;
    vector<int> h(N);
    rep(i, N)cin >> h[i];
    vector<ll> dp(N, INF);
    dp[0] = 0;
    for(int i = 1; i < N; i++){
        if(i == 1){
            dp[1] = dp[0] + abs(h[i] - h[i - 1]);
        }else{
            dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
            dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
        }
    }
    cout << dp[N - 1] << endl;

}



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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

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

  int ans = 0;
  for(int i = 0; i < n; i++){
    int res = 0;
    int j = i;
    while(j+1 < n && h[j] >= h[j+1]){
      j++;
      res++;
    }
    ans = max(ans,res);
    i = j;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <cstring>
#include <cassert>
#include <functional>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <queue>
#include <utility>

using namespace std;

#define MH 1000
int H, W, N;
string F[MH];

void input() {
    cin >> H >> W >> N;
    for (int i = 0; i < H; i++) {
        cin >> F[i];
    }
}

struct P {
    int y, x, t;
    P(int y, int x, int t = 0) : y(y), x(x), t(t) {}
};
P pos(char x) {
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (F[i][j] == x) return P(i, j);
        }
    }
    assert(0);
}

int bfs(char from, char to) {
    P init = pos(from);
    queue<P> Q; Q.push(init);
    static const int dy[] = {0, 1, 0, -1},
                     dx[] = {1, 0, -1, 0};
    bool used[H][W]; memset(used, 0, sizeof(used));
    while (!Q.empty()) {
        P cur = Q.front(); Q.pop();
        int y = cur.y,
            x = cur.x;
        if (F[y][x] == to) return cur.t;
        for (int i = 0; i < 4; i++) {
            int ny = y + dy[i],
                nx = x + dx[i];
            if (ny < 0 || ny >= H) continue;
            if (nx < 0 || nx >= W) continue;
            if (used[ny][nx]) continue;
            used[ny][nx] = true;
            if (F[ny][nx] != 'X') {
                Q.push(P(ny, nx, cur.t + 1));
            }
        }
    }
    assert(0);
}

void solve() {
    char N1 = N + '0';
    int ans = bfs('S', '1');
    for (char n = '1'; n < N1; n++) {
        ans += bfs(n, n +1);
    }
    cout << ans << endl;
}

int main() {
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3248
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

r = inp()
print(3*r*r)


Measured memory_bytes: 4204
#include<bits/stdc++.h>
#define lint long long int
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define fill(a,x) fill(a.begin(),a.end(),x)
#define eb(data) emplace_back(data)
#define pb(data) emplace_back(data)
#define mp make_pair
#define ALNUM 26
#define vint vector<int>
#define vlint vector<lint>
#define F first
#define S second
#define ALL(data) data.begin(),data.end()
#define GEts(s) getline(cin,s);
#define UNIQUE(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())

using namespace std;
template<typename Rast>inline void out(Rast rast){cout<<rast<<"\n";return;}
template<typename Rast>inline void in(Rast& rast){cin>>rast;return;}
template<typename T>istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename First, typename... Rest>void in(First& first, Rest&... rest){cin >> first;in(rest...);return;}
template<typename First, typename... Rest>void out(First first, Rest... rest){cout << first<<" ";out(rest...);return;}
template<typename T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<typename T1,typename T2>bool chmax(T1& a,T2 b){if(a<b){a=b;return true;}else{return false;}}
template<typename T1,typename T2>bool chmin(T1& a,T2 b){if(a>b){a=b;return true;}else{return false;}}
template<typename T>T lcm(T a, T b){return a * b / gcd(a, b);}
static const double pi = 3.141592653589793;
int modpow(int a,int n,int p){if (n==0)return 1%p; if(n==1)return a%p;if(n%2==1)return (a*modpow(a,n-1,p))%p;lint t=modpow(a,n/2,p);return (t*t)%p;}//a^n%p
lint MOD=pow(10,9)+7;
//lint MOD=998244353;
lint inf=pow(2,50);
int intinf=pow(2,30);
/**int dirx[]={1,0};int diry[]={0,1};//*///右、下
/**int dirx[]={0,1,0,-1};int diry[]={-1,0,1,0};//*///四方位
/**int dirx[]={-1,0,1,1,1,0,-1,-1};int diry[]={-1,-1,-1,0,1,1,1,0};//*///八方位


class unionfind{
public:
	vector<int> table;
	void init(int size){
		table.resize(size);
		rep(i,size)table[i]=i;
	};
	int root(int index){
		if(table[index]==index)return index;
		else{
			int hoge=root(table[index]);
			table[index]=hoge;
			return hoge;
		}
	};
	bool same(int x,int y){
		return(root(x)==root(y));
	};
	int marge(int x,int y){
		int yroot=root(y);
		int xroot=root(x);
		if(xroot==yroot)return 0;
		table[yroot]=xroot;
		return 0;
	}
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);cout<<std::fixed<<std::setprecision(19);
	int n,m;
	in(n,m);
	unionfind uni;
	uni.init(n);
	rep(i,m){
		int a,b;
		in(a,b);
		uni.marge(a-1,b-1);
	}
	map<int,int> ma;
	rep(i,n)ma[uni.root(i)]=0;
	out(ma.size()-1);
	return 0;
}


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

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define setIO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define trav(e, x) for (auto &e : x)
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define int long long
using namespace std;
using ii = pair<int, int>;

signed main() {
    FAST_IO;
    //setIO("input.txt", "output.txt");

    int n, d;
    cin >> n >> d;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        if ((d * d) >= (x * x) + (y * y)) cnt++;
    }
    cout << cnt;
}


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

const int INF = 2e9;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int ans = INF;
    rep(i,n) cin >> a[i];
    for(int i = -100;i <= 100;i++){
        int sum = 0;
        rep(j,n){
            sum += (a[j] - i)*(a[j] - i);
        }
        ans = min(ans,sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <math.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;
  string s;
  cin >> s;
  string ans = "Yes";
  if(s.at(a) != '-') ans = "No";
  else {
    for(int i = 0; i < a; i++) {
      if(s.at(i) == '-') ans = "No";
    }
    for(int i = a + 1; i < a + b + 1; i++) {
      if(s.at(i) == '-') ans = "No";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int64_t N,K;
  cin>>N>>K;
  vector<int64_t>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  for(int64_t i=K;i<N;i++){
    if(A[i-K]<A[i]){
      cout<<"Yes"<<endl;
    }
    else{cout<<"No"<<endl;}
  }
  return 0;
}

Measured memory_bytes: 4832
#include <iostream>
#include <cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
#define NIL -1
const int MOD = 1e9+7;
const int INF = 1 << 29;
int h,w;
int c[10][10];
int a[201][201];
int G[10][10];
int main(){

    cin>>h>>w;
    rep(i,10)rep(j,10)cin>>c[i][j];
    rep(i,h)rep(j,w)cin>>a[i][j];
    rep(i,10)rep(j,10){
        G[i][j]=c[i][j];
    }
    rep(k,10)rep(i,10)rep(j,10){
        G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
    }
    int ans=0;
    rep(i,h)rep(j,w){
        if(a[i][j]!=-1 &&a[i][j]!=1){
            ans+=G[a[i][j]][1];
        }
    }
    cout<<ans<<endl;
    return 0;
    }

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <numeric>
#include <functional>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<long long> a(N);
	for (auto& x : a) {
		cin >> x;
	}

	vector<long long> ans(N);

	long long T = accumulate(a.begin(), a.end(), 0LL, bit_xor<>{});
	for (int i = 0; i < N; ++i) {
		ans[i] = T ^ a[i];
	}

	for (auto x : ans) {
		cout << x << " ";
	}
	cout << endl;
}


Measured memory_bytes: 6408
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int k = sc.nextInt();
	int q = sc.nextInt();
	int[] score = new int[n];
	for (int i=0; i<q; i++) {
	    score[sc.nextInt()-1]++;
	}
	for (int i=0; i<n; i++) {
	    if (k - (q - score[i]) <= 0)
		System.out.println("No");
	    else {
		System.out.println("Yes");
	    }
	}
    }
}


Measured memory_bytes: 60040
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int Max = 0;
  Max = max(a,max(b,c));
  int count = Max;
  for(int i = 0; i < k; i++){
    count = count * 2;
  }
  int ans = 0;
  ans = a + b + c + count - Max;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256