akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

public class MazeMaster
{
  public class Step
  {
    public int h;
    public int w;
    public int stp;
    public bool flg;
  }
  
   static void Main(string[] args) 
   {
     var b = Console.ReadLine().Split(' ');
     int H = int.Parse(b[0]);
     int W = int.Parse(b[1]);
     bool[,] pos  = new bool[H,W];
     
     
     for(int i=0;i<H;i++)
     {
       string p = Console.ReadLine();
        for(int j=0;j<W;j++)
        {
        	pos[i,j] = p.Substring(j,1) == "."?false:true;
        }
     }
     
     int maxStep=0;
     
     for (int i = 0; i < H; i++)
     {
     	for (int j = 0; j < W; j++)
         {
         	//BFS
             List<Step> bfs = new List<Step>();
             bfs.Add(new Step() { h = i, w = j, stp = 0, flg = false });
             if (pos[i, j]) { continue; }
             while (1 <= bfs.Where(x => x.flg == false).Count())
             {
             	var l = bfs.Where(x => x.flg == false);
                 Step s =  l.First();
                 if (s.h + 1 < H && !pos[s.h + 1, s.w] && !bfs.Exists(x=> x.h == s.h+1 && x.w == s.w)) { bfs.Add(new Step() { h = s.h+1, w = s.w, stp = s.stp+1, flg = false }); }
                 if (s.h - 1 >= 0 && !pos[s.h - 1, s.w] && !bfs.Exists(x => x.h == s.h - 1 && x.w == s.w)) { bfs.Add(new Step() { h = s.h - 1, w = s.w, stp = s.stp + 1, flg = false }); }
                 if (s.w + 1 < W && !pos[s.h , s.w + 1] && !bfs.Exists(x => x.h == s.h  && x.w == s.w + 1)) { bfs.Add(new Step() { h = s.h , w = s.w + 1, stp = s.stp + 1, flg = false }); }
                 if (s.w - 1 >= 0 && !pos[s.h , s.w - 1] && !bfs.Exists(x => x.h == s.h  && x.w == s.w - 1)) { bfs.Add(new Step() { h = s.h , w = s.w - 1, stp = s.stp + 1, flg = false }); }
                 s.flg = true;
             }
			if (maxStep < bfs.Max(x => x.stp) ){maxStep = bfs.Max(x => x.stp);}
          }
     }
     Console.WriteLine(maxStep);
   }
}

Measured memory_bytes: 17904
use proconio::input;

const MOD: u64 = 1_000_000_000 + 7;

fn pow(a: u64, b: u64) -> u64 {
    if b == 0 {
        1
    } else if b % 2 == 1 {
        a * pow(a, b - 1) % MOD
    } else {
        let r = pow(a, b / 2);
        r * r % MOD
    }
}

fn main() {
    input! {
        n: u64,
        k: usize,
    }

    let mut v = vec![0; k+1];
    let mut res: u64 = 0;

    for i in (1..=k).rev() {
        v[i] = pow((k / i) as u64, n);
        let mut j = i * 2;
        while j <= k {
            v[i] = (v[i] + MOD - v[j]) % MOD;
            j += i;
        }
        res += v[i] * i as u64 % MOD;
        res %= MOD;
    }

    println!("{}", res)
}


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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  vector<int> v(n), c(n);
  rep(i, n) { cin >> v[i]; }
  rep(i, n) { cin >> c[i]; }
  rep(i, n) {
    if (v[i] > c[i]) {
      ans += v[i] - c[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    while (true) {
        int n;
        int m;
        cin >> n >> m;
        if (n == 0 && m == 0) {
            break;
        }

        unordered_map<int, int> wip;
        using Range = tuple<int, int, int>;
        vector<Range> v;
        int r;
        cin >> r;
        for (int i = 0; i < r; ++i) {
            int t;
            int n_;
            int m_;
            int s;
            cin >> t >> n_ >> m_ >> s;
            if (s == 1) {
                wip[n_] = t;
            }
            else {
                v.push_back(make_tuple(m_, wip[n_], t));
                wip.erase(n_);
            }
        }
        int q;
        cin >> q;
        for (int i = 0; i < q; ++i) {
            int t_s;
            int t_e;
            int m_;
            cin >> t_s >> t_e >> m_;
            auto merge = [](const Range& a, const Range& b) {
                int am, as, ae;
                int bm, bs, be;
                tie(am, as, ae) = a;
                tie(bm, bs, be) = b;
                int max_ = max(as, bs);
                int min_ = min(ae, be);
                if (max_ <= min_) {
                    return make_pair(true, make_tuple(am, min(as, bs), max(ae, be)));
                }
                return make_pair(false, Range{});
            };
            vector<Range> cv;
            copy_if(begin(v), end(v), back_inserter(cv),
                    [m_](const Range& a) { return get<0>(a) == m_; });
            vector<Range> curr = cv;
            vector<Range> prev = cv;
            while (true) {
                prev = curr;
                curr = {};
                bool merged{false};
                for (int j = 0; j < static_cast<int>(prev.size()) - 1; ++j) {
                    auto a = merge(prev[j], prev[j + 1]);
                    if (a.first) {
                        curr.push_back(a.second);
                        curr.insert(end(curr), begin(prev) + j + 2, end(prev));
                        merged = true;
                        break;
                    }
                    curr.push_back(prev[j]);
                }
                if (!merged) {
                    break;
                }
            }
            // ??????????????????????????£???????????§?¨???????????????????prev?????¨??????????´?????????????????????§??????
            // curr????????????????´??????\??£??????????????????prev?????¨??????
            cv = prev;
            cv.erase(unique(begin(cv), end(cv)), end(cv));
            int c{0};
            for (auto&& j : cv) {
                int beg = max(t_s, get<1>(j));
                int en = min(t_e, get<2>(j));
                if (en - beg > 0) {
                    c += en - beg;
                }
            }
            cout << c << endl;
        }
    }
}

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

int main() {
    int n, m, c; cin >> n >> m >> c;
    vector<int> b(m);
    for(int i = 0; i < m; ++i) {
        cin >> b[i];
    }
    vector<vector<int>> a(n, vector<int>(m));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }

    int ans = 0;
    for(int i = 0; i < n; ++i) {
        int sum = c;
        for(int j = 0; j < m; ++j) {
            sum += a[i][j] * b[j];
        }
        ans += sum > 0;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<i64> a(n);
    for (int i = 0; i < n; i++) std::cin >> a[i];
    std::sort(a.begin(), a.end());
    std::vector<std::pair<i64, int>> v;
    for (int i = 0; i < m; i++) {
        i64 b, c;
        std::cin >> b >> c;
        v.emplace_back(c, b);
    }
    std::sort(v.begin(), v.end(), std::greater<>());
    auto it = a.begin();
    for (int i = 0; it != a.end() && i < m; i++) {
        for (int j = 0; it != a.end() && j < v[i].second; j++) {
            if (*it < v[i].first) {
                *it = v[i].first;
                it++;
            } else break;
        }
    }
    std::cout << std::accumulate(a.begin(), a.end(), 0ll) << std::endl;

    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int M=pow(10,9)+7;
int main() {
	
	int n,m;
	cin>>n>>m;
	vector<string> A(n);
	for(int i=0;i<n;i++)cin>>A[i];
	vector<vector<ll>> dp(n,vector<ll>(m,0));
	dp[0][0]=1;
	
	for(int i=1;i<m;i++)dp[0][i]=(A[0][i]=='.')?dp[0][i-1]:0;
	for(int i=1;i<n;i++)dp[i][0]=(A[i][0]=='.')?dp[i-1][0]:0;
	
	for(int i=1;i<n;i++)
	for(int j=1;j<m;j++)
	{
		dp[i][j]=(A[i][j]=='#')?0:(dp[i-1][j]+dp[i][j-1])%M;
		
	}
	cout<<dp[n-1][m-1]<<endl;
	
	
}

Measured memory_bytes: 13008
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//
// #include <immintrin.h>
// #include <emmintrin.h>

#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#define vi vector<int>
#define vpii vector<pii>
#define pii pair<int, int >
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define LL long long
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define all(x) (x).begin(), (x).end()
#define aal(x,n) (x+1), (x+1+n)
#define sz(x) ((int)(x).size())
#define mod(x) ((x)%MOD)
#define eb emplace_back
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define ppt(x) __builtin_popcount(x)
using namespace std;
const int INF=0x3f3f3f3f,N=1e6+5,MOD=1e9+7;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;
template<typename T>
inline int getplc(T x,int y) { return (x>>y)&1; }
template<typename T>
T square(T x) {return x*x;}
LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
  LL res=1;
  for(;b;b>>=1,a=a*a%_MOD){
    if(b&1)res=res*a%_MOD;
  }
  return res;
}
template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) { return max(a, Smax(args...)); }
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) { return min(a, Smin(args...)); }
template <typename T>
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); errl(_it, args); }
void errl(istream_iterator<string> it) {}
template<typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  errl(++it, args...);
}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr<<endl;}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << "=" << a << " # ";
  err(++it, args...);
}


int a[N];
void Solve() {
  int n, mx = INT_MIN;
  LL ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mx = max(a[i], mx);
    ans += mx - a[i];
  }
  cout << ans << endl;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
//  freopen("o1.txt","w",stdout);
#endif
  ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
  Solve();
  return 0;
}


Measured memory_bytes: 4452
#prag\
ma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;

int p[100001],a[100001];

inline int find(int x){
	if(x!=p[x]) p[x]=find(p[x]);
	return p[x];
}

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;++i) cin>>a[i],p[i]=i;
	for(int i=1;i<=m;++i){
		int u,v;
		cin>>u>>v;
		int x=find(u),y=find(v);
		if(x!=y) p[y]=x;
	}
	int s=0;
	for(int i=1;i<=n;++i){
		if(a[i]==i||find(i)==find(a[i])) ++s;
	}
	cout<<s;
}

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

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans=0;
    int i,r=0,w=0,k=0;
    for(i=0;i<n;i++)
    {
        if(s[i]=='R')
        r++;
        else
        w++;
    }
    vector<char> temp(n);
    for(i=0;i<r;i++)
    temp[k++]='R';
    for(i=0;i<w;i++)
    temp[k++]='W';
    for(i=0;i<n;i++)
    {
        if(s[i]!=temp[i])
        ans++;
    }
    cout<<ans/2;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  string strA,strB;
  for(int i = 0; i < b; i++){
    strA += to_string(a);
  }
  for(int i = 0; i < a; i++){
    strB += to_string(b);
  }
  if(strA<strB) cout << strA;
  else cout << strB;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

int main() 
{
	int N;
	cin >> N;
	vector<int> vs(N);
	for(int i = 0; i < N; i++) {
		cin >> vs[i];
	}
	int ans = -101;
	int min_cost = 1000000000;
	for(int i = -100; i <= 100; i++) {
		int cost = 0;
		for(int v : vs) {
			cost += (v - i) * (v - i);
		}
		if(min_cost > cost) {
			min_cost = cost;
			ans = i;
		}
	}
	cout << min_cost << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<complex>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

#define MAX 1010

int main(){
  P p(1.0, 0.0);
  P r(0.0,-1.0);

  P ans[MAX];

  REP(i, MAX){
    P dir = -p;
    ans[i] = p;
    dir *= r;
    dir /= abs(dir);
    p += dir;
  }

  int n;
  while(scanf("%d",&n), n+1)
    printf("%.2f\n%.2f\n", ans[n-1].real(), ans[n-1].imag());

  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };
bool valid_pos(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }



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

	int n, s;
	while (cin >> n >> s, n)
	{
		int r[21234];
		for (int i = 0; i < n; ++i)
			cin >> r[i];
		sort(r, r + n);

		int res = 0;
		for (int i = 0; i < n; ++i)
			res += (r + n) - upper_bound(r + (i + 1), r + n, s - r[i]);
		cout << res << endl;
	}
}

Measured memory_bytes: 0
import sys

N = int(input())
coord = [tuple(map(int, input().split())) for _ in range(N)]
parity = (coord[0][0] + coord[0][1]) % 2
flag = False
for c in coord[1:]:
    if (c[0] + c[1]) % 2 != parity:
        flag = True
        break
if flag:
    print(-1)
    sys.exit()
D = [2**(31-i) for i in range(32)]
if parity == 0:
    D.append(1)
print(len(D))
print(*D, sep=' ')
for c in coord:
    w = ''
    pos = [0, 0]
    for d in D:
        dif = [c[0] - pos[0], c[1] - pos[1]]
        cands = [(abs(dif[0] - d) + abs(dif[1]), 'R'), (abs(dif[0] + d) + abs(dif[1]), 'L'), (abs(dif[0]) + abs(dif[1] - d), 'U'), (abs(dif[0]) + abs(dif[1] + d), 'D')]
        select = min(cands)
        w += select[1]
        if select[1] == 'R':
            pos[0] += d
        elif select[1] == 'L':
            pos[0] -= d
        elif select[1] == 'U':
            pos[1] += d
        else:
            pos[1] -= d
    print(w)

Measured memory_bytes: 3188
from collections import Counter

def main():
    N = int(input())
    *A, = map(int, input().split())
    C = Counter(A)

    MAX = 1000005
    T = [0]*MAX

    ans = 0
    for a in C.keys():
        if T[a]:
            continue
        else:
            for i in range(2*a, MAX, a):
                T[i] = 1

    ans = 0
    for a, n in C.items():
        if n == 1 and T[a] == 0:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 134584
#include <iostream>

using namespace std;

bool func ( int n )
{
  while ( n > 0 ) {
    if ( n % 10 == 9 ) return true;
    n /= 10;
  }

  return false;
}

int main()
{
  int n;

  cin >> n;

  if ( func(n) ) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	int k;
	cin>>a>>b>>c;
	cin>>k;
	if(b>a && c>b)
		cout<<"Yes\n";
	else
	{
		if(b<=a)
		{
			while(b<=a && k>0)
			{
				b=b*2;
				k--;
			}
		}
		if(c<=b)
		{
			while(c<=b && k>0)
			{
				c=c*2;
				k--;
			}
		}
		if(b>a && c>b)
			cout<<"Yes\n";
		else
			cout<<"No\n";
	}

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ull unsigned long long
#define db double
#define vi vector<ll>
#define vvi vector<vector<int> >
#define vvii vector<vector<pii> >
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl "\n"
#define pii pair<ll,ll>
#define piii pair<ll,pair<ll,ll> >
#define mem(a,b) memset(a , b , sizeof a ) ; 
#define pb push_back
#define pf push_front
#define F first 
#define S second 
#define mp make_pair
#define all(v) v.begin(),v.end()

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}



#define deb1(a) cout<<#a<<"=*"<<a<<endl;
#define deb2(a) cout<<#a<<"=@"<<a<<endl;
#define deb3(a) cout<<#a<<"=#"<<a<<endl;
#define deb4(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;
#define deb5(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


ll mod=1000000007;
ll vis[212345]={0};
vvi v(212345);
ll d[212345]={0};


ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}


//extended euclidean algorithm( x is inverse of a wrt b onlt if gcd!=1)
ll gcd(ll a,ll b,ll &x,ll &y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1,y1;
	ll d=gcd(b,a%b,x1,y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;

}


int main()
{
speed
string n;
cin>>n;

ll c=0;
rep(i,0,n.size())
{
	c+=(n[i]-'0');
}
if(c%9) cout<<"No\n";
else cout<<"Yes\n";
}



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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()

#define uint8_t unsigned char
#define uint16_t unsigned short
#define uint32_t unsigned int
#define uint64_t unsigned long long

#define int8_t signed char
#define int16_t signed short
#define int32_t signed int
#define int64_t signed long long



using namespace std;
// #define PI 3.14159265358979323846
// cout << fixed << setprecision(20);
int main(int argc, char const* argv[])
{
    int n = 0;
    vector<uint64_t> ai;
    cin >> n;
    uint64_t i;
    while (cin >> i) {
        ai.push_back(i);
    }
    uint64_t total = 0;
    uint64_t before_box = 0;
    for (auto it = ai.begin(); it + 1< ai.end();) {
        
        uint64_t before_length = *it + before_box;
        it++;
        uint64_t next_length = *it;
        
       // cout << (int64_t)next_length - (int64_t)before_length << endl;
        if ( (int64_t)next_length -  (int64_t)before_length >= 0) {
            before_box = 0;
        }
        else {
            before_box =  (int64_t)before_length -  (int64_t)next_length;
        }
        total += before_box;

    }
    cout << total  << endl;
    return 0;
}










Measured memory_bytes: 5344
import Data.Char(isSpace)
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as C

main = do
    n <- readLn
    as <- U.unfoldrN n (C.readInt . C.dropWhile isSpace) <$> C.getLine
    let left = U.scanl' gcd 0 as
    let right = U.scanr' gcd 0 as
    let res = U.zipWith gcd left (U.tail right)
    print $ U.maximum res

Measured memory_bytes: 4732
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
priority_queue<pair<int, int>> qu;
int de[100010];
int main()
{
	memset(de, -1, sizeof(de));
	int n;
	scanf("%d", &n);
	qu.push({ -1,1 });
	while (qu.size())
	{
		int cst = -qu.top().first;
		int curr = qu.top().second;
		qu.pop();
		if (de[curr] != -1)continue;
		de[curr] = cst;
		if (de[(curr + 1)%n] == -1)
			qu.push({ -cst-1,(curr + 1)%n });
		if (de[(curr*10) % n] == -1)
			qu.push({ -cst,(curr*10) % n });
	}
	printf("%d", de[0]);
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>

using namespace std;

// N以下の自然数が素数であるかどうかのリストを返す
void sieve_eratosthenes(int N, vector<bool> &arr){
    fill(arr.begin(), arr.end(), true);
    arr[0] = false;
    arr[1] = false;

    
    for (int i = 2; i <= floor(sqrt(N)); i++){
        // エラトステネスの篩
        if (arr[i]){
            for (int j = 2*i; j <= N+1; j += i){
                arr[j] = false;
            }
        }
    }
}

int main(){
    int Nmax = 100000;
    vector<bool> arr(Nmax+1);
    vector<int> sum_list(Nmax+1, 0);
    
    sieve_eratosthenes(Nmax, arr);

    for (int i = 2; i < Nmax+1; i++){
        if (arr[i] && arr[(i+1)/2]){
            sum_list[i] = sum_list[i-1]+1;
            //cout << i << "\n";
        }
        else{
            sum_list[i] = sum_list[i-1];
        }
    }

    int Q, l, r;
    cin >> Q;

    for (int i = 0; i < Q; i++){
        cin >> l >> r;
        cout << sum_list[r] - sum_list[l-1] << "\n";
    }

    return 0;
}

Measured memory_bytes: 1024
A, B, C = list(map(int,input().split()))
K = int(input())

ans = 'No'
while K >= 0:
    if A < B:
        break
    B *= 2
    K -= 1

while K >= 0:
    if B < C:
        ans = 'Yes'
        break
    C *= 2
    K -= 1

print(ans)

Measured memory_bytes: 9048
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define push push_back
const int N = 1e5 + 7;
int n;
vector <int> g[N];
vector <int> path, cur;
bool inp[N];
void dfs(int u, int p) {
    cur.push_back(u);
    if (u == n) path = cur;
    for (int v : g[u]) {
        if (v != p) {
            dfs(v, u);
        }   
    }
    cur.pop_back(); 
}   
int jfs(int u, int p) {
    int ans = 1;
    for (int v : g[u]) {
        if (v != p && !inp[v]) ans += jfs(v, u);
    }   
    return ans;
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        int u, v; cin >> u >> v; g[u].push(v); g[v].push(u);
    }   
    dfs(1, 1);
    for (int e : path) inp[e] = 1;
    int m = (path.size() + 1) >> 1;
    int f = 0, s = 0;
    for (int i = 0; i < m; ++i) {
        f += jfs(path[i], path[i]);
    }   
    for (int i = m; i < (int)path.size(); ++i) {
        s += jfs(path[i], path[i]);
    }   
    if (f > s) cout << "Fennec\n";
    else cout << "Snuke\n";
}   

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

int main()
{
	int n;
	cin>>n;
	
	int a[n+20],i,maxv=0,total;
	
	for(i=1;i<=n;i++)
	{
	    cin>>a[i];
	}
	for(i=1;i<=n;i++)
	{
		if(a[i]>=maxv)
		{
			total++;
			maxv=a[i];
		}
	}
	cout<<total<<endl;
	return 0;
}

Measured memory_bytes: 256
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 2e9;
 
typedef long long ll;
typedef long double ld;

ll ans = 0, s;
ll dp[2001];

ll find(ll curr)
{
	if(curr == 0)
		return 1;
	if(curr < 0)
		return 0;
	ll &ans = dp[curr];
	if(ans != -1)
		return ans;
	ans = 0;
	for(int i = 3; i <= s; i++)
	{
		ans = (ans + find(curr - i)) % MOD;
	}
	return ans;
}
void test_case()
{
	cin >> s;
	memset(dp, -1, sizeof(dp));
	cout << find(s) << '\n';
	
}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long x;
	cin>>x;
	__int128 n = 100;
	long long t = 0;
	while(n<x){
		n=n*101;
		n=n/100;
		t++;
	}
	cout<<t;
}

Measured memory_bytes: 3580
#Between Two Integers
def ABC_61_A():
    x,y = map(int, input().split())
    list1 = [1,3,5,7,8,10,12]
    list2 = [4,6,9,11]
    
    if (list1.count(x) == 1 and list1.count(y) == 1) or (list2.count(x) == 1 and list2.count(y) == 1) :
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':

    ABC_61_A()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int64 n, m; cin >> n >> m;
	int64 ans = 1 + (n == m);
	if (max(n, m) - min(n, m) > 1) {
		cout << 0 << endl;
		return;
	}
	for (int i = n; i >= 1; --i) {
		ans = (ans * i) % MOD;
	}
	for (int i = m; i >= 1; --i) {
		ans = (ans * i) % MOD;
	}
	cout << ans << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    str s;
    cin >> s;
    bool a = false, b = false, c = false;
    rep(i, 3) {
        if(s[i] == 'a') {
            a = true;
        }
        if(s[i] == 'b') {
            b = true;
        }
        if(s[i] == 'c') {
            c = true;
        }
    }
    if (a && b && c) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>

const long long MOD = 1e9+7;
const double PI=acos(-1);

using namespace std;

long long GCD(long long a,long long b){
	long long x=max(a,b);
	long long y=min(a,b);
	
	if(x%y==0){
		return y;
	}else{
		return GCD(y,x%y);
	}
}

int main(){
	int n;
	cin >> n;
	vector<long long> A(n);
	
	for(int i=0;i<n;i++){
		cin >> A[i];
	}
	
	long long ans=A[0];
	for(int i=1;i<n;i++){
		ans=GCD(A[i],ans);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, K;
  cin >> N >> K;
  vector<bool>su(110, false);
  for (int i = 0; i < K; i ++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j ++) {
      int a;
      cin >> a;
      su[a] = true;
    }
  }
  int ans = 0;
  for (int i = 1; i <= N; i ++) {
    if (!su[i]) ans ++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
N=int(input())
s =[input() for i in range(N)]

M=int(input())
t =[input() for i in range(M)]

sset=list(set(s))
tset=list(set(t))

Nset=len(sset)
ans=0
for i in range(Nset):
  if s.count(sset[i])-t.count(sset[i])>ans:
    ans=s.count(sset[i])-t.count(sset[i])
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int d[105];
ll ans;
int main(void){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans+=d[i]*d[j];
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
s = input()
n = len(s)

end = ""

for i in range(n):
    if i % 2 == 0:
        end += "0"
    else:
        end += "1"

cnt = 0

for i in range(n):
    if s[i] == end[i]:
        cnt += 1

print(min(cnt, n-cnt))

Measured memory_bytes: 3188
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
 
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e9+7;
 
int main()
{
    ll h,w;
    cin >> h >> w;
    if(h==1 || w==1){
        cout << 1 << endl;
        return 0;
    }
    cout << (h*w+1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))




int main(){
	vector <string>res;
	while(1){
		int H,W;
		cin>>H>>W;
		if(H==0&&W==0)break;
		char c[102][102];
		REP(i,H)REP(j,W)cin>>c[i][j];
		int tx=0,ty=0;
		int x=0,y=0;
		vector<PII>pi;
		set<PII>sp;
		int cnt=0;
		bool ch=true;
		while(c[y][x]!='.'){
			sp.insert(MP(x,y));
			if(c[y][x]=='>'){
				tx=1;ty=0;
			}else if(c[y][x]=='v'){
				tx=0;ty=1;
			}else if(c[y][x]=='<'){
				tx=-1;ty=0;
			}else if(c[y][x]=='^'){
				tx=0;ty=-1;
			}
			x+=tx;y+=ty;
			if(sp.find(MP(x,y))!=sp.end()){
				ch=false;
				break;
			}
		}
		if(ch){
			res.PB(toString(x)+' '+toString(y));
		}else{
			res.PB("LOOP");
		}
	}
	REP(i,SZ(res))cout<<res[i]<<endl;
}

Measured memory_bytes: 1260
import fileinput

def main(arg_list):
    if(len(arg_list) == 3 and arg_list.count('5')==2 and arg_list.count('7') == 1):
        print("YES")
        return 
    print("NO")

if __name__ == "__main__":
    for line in fileinput.input():
        main(line.rstrip("\n\r").split(" "))

Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;
const int MAXSIZE = 500001 + 2;
struct Node {
	int data;
	Node  *parent, *left, *right;
};
Node *Root, *NIL;
void Insert(int key) {
	Node *y = NIL;
	Node *x = Root;
	Node *z;

	z = (Node*)malloc(sizeof(Node));
	z->data = key;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL) {
		y = x;
		if (z->data < x->data) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}
	z->parent = y;
	if (y == NIL) {
		Root = z;
	}
	else {
		if (z->data < y->data) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
}
void Inorder(Node *u) {
	if (u == NIL) return;
	Inorder(u->left);
	printf(" %d", u->data);
	Inorder(u->right);
}
void Preorder(Node* u) {
	if (u == NIL) return;
	printf(" %d", u->data);
	Preorder(u->left);
	Preorder(u->right);
}
int main() {
	string str1;
	int  num_node;
	int value;
	cin >> num_node;
	for (int i = 0; i < num_node; i++) {
		cin >> str1;
		if (str1 == "insert") {
			cin >> value;
			Insert(value);
		}
		else if(str1 == "print"){
			Inorder(Root);
			printf("\n");
			Preorder(Root);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 26620
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int t;
		t = A[0]; A[0] = A[1]; A[1] = t;
		t = A[0]; A[0] = A[2]; A[2] = t;
		Console.WriteLine(String.Join(" ",A));
		
		
	}
	int[] A; 
	public Sol(){
		A = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

X = 0
D = 0

def loop():
    i=1
    a = int(input())
    while True:
        if i*a+1 <= D:
            yield 1
        else:
            break
        i += 1

def readlines():
    global X, D
    N = int(input())
    D, X = map(int, input().split())
    for _ in range(N):
        yield 1+sum(loop())

def main():
    return sum(readlines()) + X
	
if __name__ == "__main__":
    print(main())

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;

int parent[N], Size[N];

int findParent(int x) {
  if (x == parent[x]) return x;
  return parent[x] = findParent(parent[x]);
}

void unionize(int a, int b) {
  a = findParent(a);
  b = findParent(b);
  if (a != b) {
    if (Size[a] < Size[b]) swap(a, b);
    parent[a] = b;
    Size[b] += Size[a];
  }
}

void solve() {
  int n, m; scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    parent[i] = i;
    Size[i] = 1;
  }
  for (int x, y, z, i = 0; i < m; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    unionize(--x, --y);
  }
  set<int> s;
  for (int i = 0; i < n; ++i) s.insert(findParent(i));
  printf("%d", s.size());
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 9184
from operator import itemgetter

N = int(input())
table = [[int(i) for i in input().split()] for _ in range(N)]
table.sort(key=itemgetter(1))
limit = 0

for i in table:
    limit += i[0]
    if i[1] < limit:
        print("No")
        exit()

print("Yes")


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

typedef long long ll;

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

  int C[N], S[N], F[N];
  for (int i = 0; i < N - 1; i++) {
    cin >> C[i] >> S[i] >> F[i];
  }

  // i 駅から N 駅までの最短時間をそれぞれ出力する
  for (int i = 0; i < N; i++) {
    int time = 0;
    for (int j = i; j < N - 1; j++) {
      if (time < S[j]) {
        // 始発まで待つ
        time = S[j];
      } else {
        // F[j] おきに発車する電車を待つ
        if (time % F[j] != 0) {
          time = time + F[j] - time % F[j];
        }  // else は待つ必要がない
      }
      time += C[j];
    }
    cout << time << endl;
  }
}

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

int c[300010];
int a[300010];

int main(){
	int n, q;
	cin >> n >> q;



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

	for(int i = 1;i <= 300000;i++){
		a[i] = max(a[i-1], a[i]);
	}

	while(q--){
		int x;
		cin >> x;
		int ans = 0;
		for(int i = x-1;i <= 300000;i+=x){
			ans = max(ans, a[i] % x);
		}
		ans = max(ans, a[300000] % x);
		cout << ans << endl;
	}

	return 0;
}


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

import sys
import math

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    s = lines[0]

    return (s,)


def solve(s,):


    n = len(s)
    m = n // 2

    cnt = 0
    for i in range(m):
        if s[i] != s[-(i+1)]:
            cnt = cnt + 1
    
    return  cnt


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

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

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

    int h, w;
    cin >> h >> w;

    vector<string> str(h);
    REP(i, h) cin >> str[i];

    vector<vector<int> > m(h, vector<int>(w, -1));
    REP(i, h) REP(j, w)
        if (str[i][j] == '.') m[i][j] = 0;

    REP(i, h) REP(j, w) {
        if (str[i][j] == '#') {
            for (int x = -1; x <= 1; x++) {
                if (i + x >= 0 && i + x < h) {
                    for (int y = -1; y <= 1; y++) {
                        if (j + y >= 0 && j + y < w) {
                            if (str[i + x][j + y] == '#') continue ;
                            else m[i + x][j + y]++;
                        }
                    }
                }
            }
        }
    }

    REP(i, h) {
        REP(j , w) {
            if (m[i][j] == -1) cout << '#';
            else cout << m[i][j];
        }
        cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec_raw<>() -> Vec<String> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.to_string()).collect::<Vec<String>>().clone()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    let mut v2 = Vec::new();
    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let v = s.trim().split_whitespace()
            .map(|e| e.parse().ok().unwrap()).collect();
        v2.push(v);
    }
    v2
}

/*fn get_score(r: usize,c:usize,n: usize,map: &Vec<Vec<usize>>) -> usize {
    let current = map[r][c].clone();
    match r {
        0 => if c < n - 1 { current + map[r + 1][c + 1] } else { current }
        1 => if c > 0 { current + map[r - 1][c - 1]} else {current}
        _ => panic!()
    }
}*/

fn get_result(return_point: usize,n: usize,map: &Vec<Vec<usize>>) -> usize{

    let mut r = 0;
    let mut c = 0;
    let mut flag = false;
    let mut result = map[r][c];

    for i in 0..n {
        if c == return_point && !flag {
            r = 1;
            flag = true;
            result += map[r][c]
        } else {
            c += 1;
            result += map[r][c]
        }
    }
    result
}

fn solve_a(){

    /*let mut str1 = read_vec_raw()[0].clone();
    let str2 = read_vec_raw()[0].clone();
    str1.push_str(&str2);*/

    let vec1 : Vec<Vec<usize>> = read_vec2(1);
    let n : usize = vec1[0][0].clone();
    let m : usize = vec1[0][1].clone();
    let mut vec2 : Vec<Vec<usize>> = read_vec2(m);
    vec2.sort();


    /*let mut graph = vec![vec![0;n];n];

    for v in vec2.iter() {
        let diff = v[1] - v[0];
        if diff == 1  {
            graph[v[0] - 1][v[1] - 1] = v[2];
            graph[v[1] - 1][v[0] - 1] = v[2];
        } else {

        }
    }*/

    println!("{:?}",vec2);

}

fn max(a: usize,b:usize) -> usize {
    if a > b {
        a
    } else {
        b
    }
}

fn min(a: usize,b:usize) -> usize {
    if a > b {
        b
    } else {
        a
    }
}

fn diff(a: usize,b: usize) -> usize {
    max(a,b) - min(a,b)
}

fn solve_c() {
    let grid: Vec<Vec<i32>> = read_vec2(3);
    let mut f = true;

    for i in 0..3 {
        for j in 0..3 {
            for k in 0..3 {
                for l in 0..3 {
                    if grid[i][k] + grid[j][l] != grid[i][l] + grid[j][k] {
                        f = false;
                    }
                }
            }
        }
    }
    if f {
        println!("Yes");
    } else {
        println!("No");
    }

}

fn main (){

    solve_c();
}

Measured memory_bytes: 4352
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
l_max=1
r_min=n
for i in range(m):
    l_now=l[i][0]
    r_now=l[i][1]
    if l_now>l_max:
        l_max=l_now
    if r_now<r_min:
        r_min=r_now
    
print(max(r_min-l_max+1,0))

Measured memory_bytes: 27332
#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
double dp[N][N];
double p[N];
int n;

int main() {
    cin >>  n;
    for(int i = 1; i <= n; i ++) {
        cin >> p[i];
    }
    dp[0][0] = 1;
    for(int i = 1; i <= n; i ++){
        for(int j = 0; j <= i; j ++) {
            if(j == 0) {
                dp[i][j] = (1-p[i]) * dp[i-1][j];
            } else {
                dp[i][j] = (1-p[i]) * dp[i-1][j] + p[i]*dp[i-1][j-1];
            }
        }
    }
    double res = 0;
    for(int i = (n/2) + 1; i <= n; i ++) {
        res += dp[n][i];
    }
    cout <<setprecision(12) << fixed << res << endl;
    return 0;
}

Measured memory_bytes: 69120
from fractions import gcd
a, b, c, d = map(int, input().split())
ac = abs(a - c)
bd = abs(b - d)
if ac == bd:
  ans = ac
elif ac == 0 or bd == 0:
  ans = 0
else:
  ans = ac + bd - gcd(ac, bd)

print(ans)

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

#define INF INT_MAX/2
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

   int N;
   cin>>N;
   int Min = INF;
   vector<int>sum(100001,0);
   for(int i=0;i<=100000;i++){
      int n = i;
      for(int j=0;j<6;j++){
         sum[i] += n%10;
         n /= 10;
      }
   }
   for(int i=1;i<N;i++){
      int a = i;
      int b = N-i;
      Min = min(sum[a]+sum[b],Min);
   }
   cout<<Min<<endl;
   return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
 
 
#define ll long long

#define start long long t;cin>>t;while(t--)
#define in(x) cin >> x
#define in2(x, y) cin >> x >> y
#define in3(x, y, z) cin >> x >> y >> z
#define in4(x, y, z, o) cin >> x >> y >> z >> o
#define biggestFactor (n)      for (ll j = 2; j <= sqrt(n); j++){if (n % j == 0){cout << n / j << "\n";break;}}
                               //First find smallest factor and then divide that factor and the answer itself is biggest factor
                          
using namespace std;


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
   string s;
   cin >>s;
   ll sum = 0;
   for (ll i = 0; i < s.length(); i++)
   {
       sum += s[i] - '0';
   }
   if (sum % 9 == 0)
   {cout << "Yes" << "\n";
   }
   else
   {
       cout << "No" << "\n";
   }
    	return 0;
}

Measured memory_bytes: 3732
module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.List
import           Data.Array
import           Data.Char

main = do
  n   <- (read :: String -> Int) <$> getLine
  arr <- map (read :: String -> Int) . words <$> getLine
  print $ calcCost arr


calcCost :: [Int] -> Int
calcCost arr = let (_, plus, _) = foldl update (0, 0, True) arr
                   (_, minus, _) = foldl update (0, 0, False) arr
               in min plus minus

update :: (Int, Int, Bool) -> Int -> (Int, Int, Bool)
update (s, c, b) v =
  let next = calcNext s b
  in  if next * v > 0 && abs v > abs next
        then (s + v, c,  not b)
        else (s + next, c + abs (next - v), not b)

calcNext :: Int -> Bool -> Int
calcNext a b = if b then 1 - a else -1 - a



Measured memory_bytes: 39292
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 404 , P = 1e9 + 7;
int n , c , a[N] , b[N] , f[N] , g[N];
int pw[N][N];

int main(){
  cin >> n >> c;
  rep(i,0,n) cin >> a[i];
  rep(i,0,n) cin >> b[i];
  rep(i,0,N) rep(j,0,N)
    pw[i][j]=j?ll(pw[i][j-1])*i%P:1;
  rep(i,1,N) rep(j,0,N)
    (pw[i][j]+=pw[i-1][j])%=P;
  f[0] = 1;
  rep(i,0,n) {
    rep(i,0,c+1) g[i] = 0;
    rep(j,0,c+1) if(f[j]) {
      rep(k,0,c+1) {
        if(j+k>c) break;
        g[j+k]+=ll(f[j])*(((pw[b[i]][k]-pw[a[i]-1][k])%P+P)%P)%P;
        if(g[j+k]>=P) g[j+k]-=P;
      }
    }
    rep(i,0,c+1) f[i] = g[i];
  }
  cout << f[c] << endl;
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> x(3, vector<int>(n));
    rep(i,n){
        cin >> x[0][i] >> x[1][i] >> x[2][i];
    }

    vector<vector<int>> dp(3, vector<int>(n,0));
    dp[0][0] = x[0][0];
    dp[1][0] = x[1][0];
    dp[2][0] = x[2][0];
    rep(i,n){
        if ( i == 0 ) {
            continue;
        }
        rep(j,3){
            rep(k,3){
                if (j!=k) {
                    dp[j][i] = max( dp[j][i],dp[k][i-1]+x[j][i] );
                }
            }
        }
    }
    int ans = max( dp[0][n-1], dp[1][n-1] );
    ans = max ( ans, dp[2][n-1] );
    cout << ans << endl;
}


Measured memory_bytes: 2940