akhauriyash/Code-Regression huggingface dataset:
n,d = [int(x) for x in input().split()]
x = []
y = []
for i in range(n):
  x1,y1 = [int(x) for x in input().split()]
  x.append(x1)
  y.append(y1)
c = 0
for i in range(n):
  s = x[i] ** 2 + y[i] ** 2
  if s <= d ** 2:
    c += 1
print(c)

Measured memory_bytes: 24988
matches = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
n, m = map(int, input().split())
alist = list(map(int, input().split()))
alist.sort(reverse = True)

dp = [-1 for _ in range(n+1)]
dp[0] = 0
for a in alist:
    match = matches[a]
    for i in range(n - match + 1):
        if dp[i] == -1:
            continue
        dp[i + match] = max(dp[i+match], dp[i] * 10 + a)
        
print(dp[-1])

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

using namespace std;

void solve() {
    string s;
    cin >> s;
    int fi, se;
    fi = (s[0] - '0') * 10 + s[1] -'0';
    se = (s[2] - '0') * 10 + s[3] -'0';
    if (0 < fi && fi <= 12 && 0 < se && se <= 12){
        cout << "AMBIGUOUS" << endl;
    }
    else if (0 < fi && fi <= 12)
    {
        cout << "MMYY" << endl;
    }
    else if (0 < se && se <= 12)
    {
        cout << "YYMM" << endl;
    }
    else
    {
        cout << "NA" << endl;
    }
}

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

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

int main(){
    int N;
    int max = 0;
    int sum = 0;
    int L[100];
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> L[i];
    }
    for(int j=0;j<N;j++){
        if(max < L[j] ){
            max = L[j];
        }
    }
    for(int k=0;k<N;k++){
        sum += L[k];
    }
    sum = sum -max;
    if(max < sum){
        cout << "Yes" << endl;
    }
    if(max >= sum){
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
#define k_p make_pair


int main()
{
    int x;
    while(cin>>x)
    {
        LL ans=0;
        ans+=(x/500)*1000;
        x%=500;
        ans+=(x/5)*5;
        cout<<ans<<endl;


    }
    
    return 0;
}


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

using namespace std;

int frecv[105];

int main(){
    int a,b,c,answer=0;

    cin>>a>>b>>c;

    frecv[a]++;
    answer++;

    if(!frecv[b]){
        frecv[b]++;
        answer++;
    }

    if(!frecv[c]){
        frecv[c]++;
        answer++;
    }

    cout<<answer;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
        string op;
        int a,b;
        while(true){
                cin >> a >> op >> b;
                if(op=="+")
                        cout << a+b<<endl;
                else if(op=="-")
                        cout << a-b << endl;
                else if(op=="/")
                        cout << a/b << endl;
                else if(op=="*")
                        cout << a*b << endl;
                else
                        return 0;
        }
        return 0;
}

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

using namespace std; 
  
const int MAX = 10000001; 
  
// array to store prime factors 
int factor[MAX] = { 0 }; 
  
// function to generate all prime factors 
// of numbers from 1 to 10^6 
void generatePrimeFactors() 
{ 
    factor[1] = 1; 
  
    // Initializes all the positions with their value. 
    for (int i = 2; i < MAX; i++) 
        factor[i] = i; 
  
    // Initializes all multiples of 2 with 2 
    for (int i = 4; i < MAX; i += 2) 
        factor[i] = 2; 
  
    // A modified version of Sieve of Eratosthenes to 
    // store the smallest prime factor that divides 
    // every number. 
    for (int i = 3; i * i < MAX; i++) { 
        // check if it has no prime factor. 
        if (factor[i] == i) { 
            // Initializes of j starting from i*i 
            for (int j = i * i; j < MAX; j += i) { 
                // if it has no prime factor before, then 
                // stores the smallest prime divisor 
                if (factor[j] == j) 
                    factor[j] = i; 
            } 
        } 
    } 
}
// function to calculate number of factors 
int calculateNoOFactors(int n) 
{ 
    if (n == 1) 
        return 1; 
  
    int ans = 1; 
  
    // stores the smallest prime number 
    // that divides n 
    int dup = factor[n]; 
  
    // stores the count of number of times 
    // a prime number divides n. 
    int c = 1; 
  
    // reduces to the next number after prime 
    // factorization of n 
    int j = n / factor[n]; 
  
    // false when prime factorization is done 
    while (j != 1) { 
        // if the same prime number is dividing n, 
        // then we increase the count 
        if (factor[j] == dup) 
            c += 1; 
  
        /* if its a new prime factor that is factorizing n,  
           then we again set c=1 and change dup to the new  
           prime factor, and apply the formula explained  
           above. */
        else { 
            dup = factor[j]; 
            ans = ans * (c + 1); 
            c = 1; 
        } 
  
        // prime factorizes a number 
        j = j / factor[j]; 
    } 
  
    // for the last prime factor 
    ans = ans * (c + 1); 
  
    return ans; 
}

int main() 
{ 
    // generate prime factors of number 
    // upto 10^6 
    generatePrimeFactors(); 
  
   
  int n;
    cin>>n;
    long long sum=0,x;
    for (int i = 1; i <=n; i++) {
        x=calculateNoOFactors(i);
        sum+= x*i;
       
    }
   cout<<sum;
    return 0; 
}


Measured memory_bytes: 42708
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>
#include <iomanip>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	cin >> n;
	
	vector<ll> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	vector< vector<ll> > x(60, vector<ll>(2, 0));
	
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < 60; ++j) {
			if( a[i] & (1LL << j) ) {
				x[j][1]++;
			} else {
				x[j][0]++;
			}	
		}
	}
	
	ll ans = 0;
	ll factor = 1;
	
	for(int i = 0; i < 60; ++i) {
		ans += (x[i][0] * x[i][1]) % MOD_LL * (factor % MOD_LL);
		ans %= MOD_LL;
		factor = (factor * 2) % MOD_LL;
	}
	
	cout << ans << endl;
	
	return 0;
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for(int i = (int)(n); i > 0; --i)
#define all(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rall(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)
#define sz(a) (int)(a).size()
#define mins(a,...) a = min<decltype(a)>({a, ## __VA_ARGS__})
#define maxs(a,...) a = max<decltype(a)>({a, ## __VA_ARGS__})
#define plusMod(a,b) a = (a % mod + b % mod) % mod
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) {
    return os.put(os.widen('\n'));
}
template<typename A, size_t N, typename T>
void fillArray(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}

int n;
ll h[100005];
void solve() {
    cin >> n;

    rep(i, n)
        cin >> h[i];

    ll ans = 0;
    ll res = 0;
    reps(i, n - 1) {
        if (h[i] <= h[i - 1])
            ++res;
        else {
            maxs(ans, res);
            res = 0;
        }
    }

    cout << max(ans, res) << endn;
}


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    solve();

    cout << flush;

    return 0;
}


Measured memory_bytes: 1024
use std::cmp::min;
use std::io::stdin;

fn main() {
    let mut is = String::new();
    stdin().read_line(&mut is).ok();
    let mut itr = is.split_whitespace().map(|e| e.parse::<usize>().unwrap());
    let n: usize = itr.next().unwrap();
    let k: usize = itr.next().unwrap();
    is.clear();
    stdin().read_line(&mut is).ok();
    let mut a = is
        .split_whitespace()
        .map(|e| e.parse::<usize>().unwrap())
        .collect::<Vec<usize>>();

    for _ in 0..k {
        let mut b = vec![0usize; n + 1];
        for i in 0..n {
            let l = i.saturating_sub(a[i]);
            let r = min(i + a[i] + 1, n);
            b[l] = b[l].wrapping_add(1);
            b[r] = b[r].wrapping_add(!0);
        }
        a = vec![0; n];
        for i in 0..n {
            a[i] = a[if i > 0 { i - 1 } else { 0 }].wrapping_add(b[i]);
        }

        if a.iter().all(|e| e == &n) {
            break;
        }
    }

    let mut flg = false;
    for e in a {
        if flg {
            print!(" ");
        }
        print!("{}", e);
        flg = true;
    }
    println!();
}


Measured memory_bytes: 7880
#include<bits/stdc++.h>
#define ll long long
#define all(v) v.begin(),v.end()
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define what(x) cout<<#x<<" is "<<x<<endl;
using namespace std;


template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

ll powmod(ll a,ll b,ll mod) {
    ll res=1;a%=mod;
    //assert(b>=0);
    for(;b;b>>=1){
        if(b&1)res=res*a%mod;a=a*a%mod;
    }
    return res;
}
vector<bool> vis;
vector<set<int>> edges; 

int dfs(int u,int p){
	debug(u,p);
	int cnt=1;
	for(int it:edges[u]){
		if(!vis[it]&&it!=p){
			vis[it]=1;
			cnt+=dfs(it,u);
		
		}
	}
	return cnt;
}



void solve(){
	int n,m;
	cin>>n>>m;
	vis=vector<bool>(n+1,false);
	edges.resize(n+1);
	for(int i=0,x,y;i<m;i++){
		cin>>x>>y;
		edges[x].insert(y);
		edges[y].insert(x);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			vis[i]=1;
			ans=max(ans,dfs(i,-1));
		}
	}
	cout<<ans<<'\n';
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tc=1;
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	#endif
	// cin>>tc;
    while(tc--)solve();
}


Measured memory_bytes: 46868
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		TreeSet<Integer> ts = new TreeSet<Integer>();
		int cnt = 0;
		for(int i = 0 ; i < N ; ++i){
			int pi = sc.nextInt();
			if(!ts.isEmpty()){
				int min = ts.first();
				if(min >= pi){
					++cnt;
				}
			}else{
				++cnt;
			}
			ts.add(pi);
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 100932
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    long[] a = new long[n + 1];
    a[0] = 2;
    a[1] = 1;
    for (int i = 2; i <= n; i++) {
      a[i] = a[i - 1] + a[i - 2];
    }
    System.out.println(a[n]);
  }

}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

template <typename T>
T BinarySearch(T lo, T hi, std::function<bool(T)> pred) {
  while (lo + 1 < hi) {
    T mid = (hi - lo) / 2 + lo;
    if (pred(mid)) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  return lo;
}

using ld = long double;
const ld eps = 0.0000000001;

int main() {
  in(ll, n, k);
  V<ld> a(n);
  rep(i, n) cin >> a[i];
  ld lo = 0, hi = *max_element(all(a));
  rep(iter, 400) {
    ld mid = (hi + lo) / 2;
    ll cuts = 0;
    rep(i, n) cuts += (a[i] / mid) - eps;
    if (cuts <= k) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  out(ll(ceil(lo) + eps));
}

Measured memory_bytes: 6348
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] w = new String[n+1];
        w[0] = "zero";
        for(int i=1; i<=n; i++){
            w[i] = sc.next();
        }
        String ans = "Yes";
        for(int i=1; i<n; i++){
            for(int j=i+1; j<=n; j++){
                if(w[i].equals(w[j])){
                    ans = "No";
                    break;
                }
            }
        }
        for(int i=1; i<n; i++){
            int end = w[i].length()-1;
            if(w[i].charAt(end)!=w[i+1].charAt(0)){
                ans = "No";
                break;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int N; cin >> N;
    vec a(N); readv(a);

    vec suma(N + 2);
    REP(i, N) suma[i + 2] = max(a[i], 0LL) + suma[i];
    int ans = -INF;
    int i1, i2;
    REP(i, N) FOR(j, i, N){
        if((j - i) % 2 != 0) continue;
        int v = suma[j + 2] - suma[i + 2] + a[i];
        if(v > ans){
            ans = v;
            i1 = i;
            i2 = j;
        }
    }
    cout << ans << endl;
    cout << N - 1 - (i2 - i1) / 2 << endl;
    int t = N - 1 - (i2 - i1) / 2;
    REP(i, N - 1 - i2) cout << N - i << endl;
    t -= N - 1 - i2;
    for(int i = i2; i > i1; i -= 2) if(a[i] < 0){
        cout << i + 1 << endl;
        t--;
    }
    REP(i, i1) cout << 1 << endl;
    t -= i1;
    REP(i, t) cout << 2 << endl;
    
    return 0;
}

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

int main() {
    long long A, B;
    cin >> A >> B;
    long long ans = 0;
    for (long long i = A; i <= B; i++) {
        string str = to_string(i);
        string str_rev = str;
        reverse(str_rev.begin(), str_rev.end());
        if (str == str_rev) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

bool isConsistent(int bit, vector<pair<int, int>> remarks) {
    for(auto remark : remarks) {
        int x, y;
        x = remark.first - 1;
        y = remark.second;
        if (y == 1) {
            if ((bit & (1 << x)) == 0) return false;
        } else {
            if ((bit & (1 << x)) != 0) return false;
        }
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    vector<vector<pair<int, int>>> witnesses(N);
    for (int i = 0; i < N; i++) {
      int A;
      cin >> A;
      vector<pair<int, int>> remarks(A);
      for (int j = 0; j < A; j++) {
          int x, y;
          cin >> x >> y;
          remarks[j] = make_pair(x, y);
      }
      witnesses[i] = remarks;
    }

    int maxCount = 0;
    for (int bit = 0; bit < (1 << N); bit++) {
        int count = 0;
        for (int i = 0; i < N; i++) {
            if (bit & (1 << i)) {
                if (isConsistent(bit, witnesses[i])) {
                    count++;
                } else {
                    count = 0;
                    break;
                }
            }
        }
        maxCount = maxCount < count ? count : maxCount;
    }
    cout << maxCount << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
static void ABC115B_ChristmasEveEve()
{
	int N, price, max = 0, sum = 0;

	scanf(" %d", &N);
	for (int i = 0; i < N; i++) {
		scanf(" %d", &price);
		if (max < price) {
			max = price;
		}
		sum += price;
	}
	printf("%d\n", sum - (max / 2));
}

int main()
{
	ABC115B_ChristmasEveEve();

	fflush(stdout);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e18;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    vi A(N);
    rep(i,N) cin >> A[i];
    sort(all(A));
    if(A[0]==0) cout << 0 << endl;
    else {
        int ans=1;
        rep(i,N){
            if(INF/ans<A[i]) {
                cout << -1 << endl;
                return 0;
            }
            ans*=A[i];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3936
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪func•*¨*•.¸¸♪

//•*¨*•.¸¸♪main•*¨*•.¸¸♪

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	n := scanInt()

	ans := 0
	cnt := make([][]int, 10)
	for i := 0; i < 10; i++ {
		cnt[i] = make([]int, 10)
	}

	for i := 1; i < n+1; i++ {
		a := i%10
		if a==0 {
			continue
		}
		b := i
		for b/10!=0 {
			b/=10
		}

		cnt[a][b]++
	}

	for i := 0; i < 10; i++ {
		for j := 0; j < 10; j++ {
			ans += cnt[i][j]*cnt[j][i]
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
int compar(const int *val1,const int *val2){
    if(*val1 < *val2){
        return -1;
    }
    else if(*val1 == *val2){
        return 0;
    }
    else {
        return 1;
    }
}

int compar1(const int *val1,const int *val2){
    if(*val1 > *val2){
        return -1;
    }
    else if(*val1 == *val2){
        return 0;
    }
    else {
        return 1;
    }
}

int p(int i){
    int sum=1;
    while(3-i){
        sum*=10;
        i++;
    }
    return sum;
}

int main(void){
    int n,m,sum,i,linel[4],lines[4],line[4],ans[4]={6,1,7,4},large,small,base,sign;
    char num[5];
    while(1){
        sum=0;
        sign=0;
        large=0;small=0;
        scanf("%s",num);
        n=atoi(num);m=n;
        for(i=0;i<4;i++){
                linel[i]=n/p(i);
                n=n%p(i);
                lines[i]=linel[i];
            }
        if(lines[0] == 0 && lines[1] == 0 && lines[2] == 0 && lines[3] == 0)
            break;
        if(linel[0] == linel[1] && linel[1] == linel[2] && linel[2] == linel[3]){
            sign = 1;
        }
        while(sign != 1){
            large=0;small=0;
            if(lines[0] == 6 && lines[1] == 1 && lines[2] == 7 && lines[3] == 4)
                break;
            qsort(lines,4,sizeof(int),(int (*)(const void *,const void *)) compar);
            qsort(linel,4,sizeof(int),(int (*)(const void *,const void *)) compar1);
            for(i=0;i<4;i++){
                large+=linel[i]*p(i);
                small+=lines[i]*p(i);
            }
            base=large-small;
            for(i=0;i<4;i++){
                lines[i]=base/p(i);
                linel[i]=lines[i];
                base=base%p(i);
            }
            sum++;
        }
        if(sign == 1)
            printf("NA\n");
        else
            printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 572
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <boost/range/algorithm.hpp>
#include <boost/integer/common_factor_rt.hpp>

using namespace std;

int N;
int main() {
    while (cin >> N) {
        int A[N], max_i = 0, max_2nd_i = 0;
        cin >> A[0];
        cin >> A[1];
        if (A[0] < A[1]) {
            max_i = 1;
            max_2nd_i = 0;
        } else {
            max_i = 0;
            max_2nd_i = 1;
        }
        for (int i = 2; i < N; i++) {
            cin >> A[i];
            if (A[max_i] < A[i]) {
                max_2nd_i = max_i;
                max_i = i;
            } else if (A[max_2nd_i] < A[i]) {
                max_2nd_i = i;
            }
        }
        for (int i = 0; i < N; i++) {
            cout << A[(i == max_i) ? max_2nd_i : max_i]  << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<string> S(N);
  rep(i, N) cin >> S[i];

  rep(i, N - 1)
  {
    if (S[i][S[i].size() - 1] != S[i + 1][0])
    {
      cout << "No" << endl;
      return 0;
    }
  }

  std::sort(S.begin(), S.end());
  rep(i, N - 1)
  {
    if (S[i] == S[i + 1])
    {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

int main(){
  
  char b;
  
  cin >> b;
  
  if(b == 'A')
    cout << 'T' << endl;
  
  if(b == 'T')
    cout << 'A' << endl;
  
  if(b == 'C')
    cout << 'G' << endl;
  
  if(b == 'G')
    cout << 'C' << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
        a[i]--;
    }
    vector<int> loc;
    vector<bool> vis(n, false);
    vis[0] = true;
    int s = 0;
    loc.push_back(0);
    int x = 0;
    if(a[0]==0){
        cout << 1 << endl;
        return 0;
    }
    while (1)
    {
        x = a[x];
        if(vis[x]){
            break;
        }
        vis[x] = true;
        loc.push_back(x);
    }
    int l = 0;
    for (int i = 0; i < loc.size(); i++)
    {
        if(loc[i]==x){
            l = i;
            break;
        }
    }
    show(loc);
    if(k<l){
        cout << loc[k]+1 << endl;
        return 0;
    }
    k -= l;
    int c = k % (loc.size() - l);
    //cerr << c << endl;
    vector<int> w;
    for (int i = l; i < loc.size(); i++)
    {
        w.push_back(loc[i]);
    }
    //show(w);
    
    cout << w[c]+1 << endl;

    return 0;
}

Measured memory_bytes: 9424
from collections import deque

def bfs():
    global ans
    while q:
        p = q.popleft()
        for u in v:
            x, y = p[0] + u[0], p[1] + u[1]
            if 0 <= x < h and 0 <= y < w:
                if s[x][y] == -1:
                    s[x][y] = s[p[0]][p[1]] + 1
                    q.append([x, y])
                    ans = max(ans, s[x][y])
    return

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
s = [[-1] * w for _ in range(h)]
v = [[1, 0], [-1, 0], [0, 1], [0, -1]]
q = deque()
ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            s[i][j] = 0
            q.append([i, j])
bfs()
print(ans)

Measured memory_bytes: 176348
// source
// https://atcoder.jp/contests/abc175/submissions/15923583
#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (auto &&e : p)
        cin >> e, --e;
    vector<int64_t> c(n);
    for (auto &&e : c)
        cin >> e;
    // 負のスコアを取る場合があるのでマイナスで初期化
    auto res = numeric_limits<int64_t>::min();
    for (int s = 0; s < n; ++s) {
        // 循環する要素を求める（Pi != i なので自分自身へループしない）
        vector<int64_t> v;
        for (int i = s;; i = p[i]) {
            v.push_back(c[i]);
            if (p[i] == s)
                break;
        }
        // 循環する要素の長さ
        int m = v.size();
        // 循環する要素の合計
        auto sum = accumulate(begin(v), end(v), 0LL);
        int64_t cur = 0;
        for (int r = 1; r <= m; ++r) {
            if (r > k)
                break;
            cur += v[r - 1];
            // 先頭からスコアを加算し、残りの長さに対して何回循環するか数える
            res = max(res, cur + (k - r) / m * max<int64_t>(sum, 0));
        }
    }
    cout << res << '\n';
}


Measured memory_bytes: 3812
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
// g++ hoge.cpp -std=c++17 -I . でコンパイルできる
// -fsanitize=undefinedでオーバーフロー検出
#include <bits/stdc++.h>
#include <atcoder/all>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
using namespace atcoder;
typedef pair<ll,ll> P;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);

    ll a,b,c,d,m,n,k,x,y,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n;
    rep(i,n){
        cout<<"ACL";
    }
    ln;

    //vector<vector<ll>> v(tate,vector<ll> (yoko));
    //vector<ll> v(n);
    //rep(i,n)   cin >> v[i];

    return 0;
}


Measured memory_bytes: 3644
from fractions import gcd

n = int(input())
a = list(map(int,input().split()))
gcd_ans = []

l = [0]*n
r =[0]*n
for i in range(n-1):
  l[i+1] = gcd(l[i],a[i])
  r[i+1] = gcd(r[i],a[n-1-i])
r.reverse()

for i in range(n):
  gcd_ans.append(gcd(l[i],r[i]))

print(max(gcd_ans))
  

  
  
  




Measured memory_bytes: 16116
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}

const ll mod = 998244353;

ll mod_exp(ll a, ll b){
	if(b == 0)
		return 1ll;
	if(b % 2 == 0){
		ll t = mod_exp(a, b / 2) % mod;
		return t * t % mod;
	}
	return a * mod_exp(a, b - 1) % mod;
}		

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n, s;
	cin >> n >> s;

	vector<int> a(n + 1);
	for(int i = 1; i <= n; i++)
		cin >> a[i];

	vector<vector<ll>> dp(n + 2, vector<ll>(s + 5));
	dp[0][0] = mod_exp(2ll, n) % mod;
	ll inv2 = mod_exp(2ll, mod - 2) % mod;


	for(int i = 0; i < n; i++){
		for(int j = 0; j <= s; j++){
			
			//don't add
			dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod;;

			//add
			if(j + a[i + 1] <= s)
				dp[i + 1][j + a[i + 1]] = (dp[i + 1][j + a[i + 1]] + dp[i][j] * inv2 % mod) % mod;	
		}
	}

	cout << dp[n][s] << endl;

	return 0;
}

Measured memory_bytes: 73920
#include <iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		int m,count=n,p[21][21];
		for(int i=0;i<21;++i)for(int j=0;j<21;++j)p[i][j]=0;
		for(int i=0,x,y;i<n;++i){
			cin>>x>>y;
			p[x][y]=1;
		}
		cin>>m;
		for(int i=0,d,cx=10,cy=10;i<m;++i){
			string s;
			cin>>s;
			cin>>d;
			if(s=="N"){
				for(int j=0;j<d;++j){
					++cy;
					if(p[cx][cy]==1){
						count--;
						p[cx][cy]=0;
					}
				}
			}else if(s=="E"){
				for(int j=0;j<d;++j){
					++cx;
					if(p[cx][cy]==1){
						count--;
						p[cx][cy]=0;
					}
				}
			}else if(s=="S"){
				for(int j=0;j<d;++j){
					--cy;
					if(p[cx][cy]==1){
						count--;
						p[cx][cy]=0;
					}
				}
			}else if(s=="W"){
				for(int j=0;j<d;++j){
					--cx;
					if(p[cx][cy]==1){
						count--;
						p[cx][cy]=0;
					}
				}
			}
		}
		if(count==0)cout<<"Yes\n";
		else cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 0
def get_1d(H, h):
    ret = [0] * (H + 1)
    for s in range(h):
        for x, i in enumerate(range(s, H, h)):
            ret[i] = -x
    for x, i in enumerate(range(H, 0, -h)):
        ret[i] = x + 1
    return [x1 - x0 for x0, x1 in zip(ret, ret[1:])]


def solve(H, W, h, w):
    if H % h == 0 and W % w == 0:
        return False
    ans = []
    if H % h > 0:
        col = get_1d(H, h)
        ans.extend([x] * W for x in col)
    else:
        row = get_1d(W, w)
        ans.extend([row] * H)
    return ans


H, W, h, w = map(int, input().split())
ans = solve(H, W, h, w)
if ans == False:
    print('No')
else:
    print('Yes')
    for row in ans:
        print(*row)


Measured memory_bytes: 6484
#!/usr/bin/env python3
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, A: int, B: int, C: int, s: "List[int]"):
    v = [A, B, C]
    ans = []
    for i in range(N):
        l, r = s[i]
        if v[l] + v[r] == 0:
            return None
        if v[r] == 0 or v[l] >= v[r] and i != N - 1 and r in s[i + 1]:
            ans.append(r)
            v[l] -= 1
            v[r] += 1
        else:
            ans.append(l)
            v[l] += 1
            v[r] -= 1
    return ans


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    def s2index(s: "List[str]"):
        return [ord(c)-ord('A') for c in s]

    def index2s(i: int):
        return chr(i + ord('A'))

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    s = [s2index(next(tokens)) for _ in range(N)]  # type: "List[int]"
    ans = solve(N, A, B, C, s)

    if ans == None:
        print(NO)
    else:
        print(YES)
        print("\n".join(list(map(index2s, ans))))


if __name__ == '__main__':
    main()


Measured memory_bytes: 95048
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,string> P;
typedef pair<int,P> PP;
void Main() {
  int n;
  while(R n && n) {
    string ss,tt;
    cin >> ss >> tt;
    map<string,int> m[n+1];
    m[0][ss]=0;
    priority_queue<PP,vector<PP>,greater<PP> > que;
    que.push(PP(0,P(0,ss)));
    while(!que.empty()) {
      PP p=que.top();que.pop();
      string s=p.S.S;
      string t=s;
      int k=p.S.F,cc=p.F;
      int x=s[k]-'0',y=tt[k]-'0';
      if(m[k][s]<cc) continue;
      int z;
      if(y>x) {
        if(abs(y-x)>abs(y-10-x)) z=y-10-x;
        else z=y-x;
      } else {
        if(abs(y-x)>abs(y+10-x)) z=y+10-x;
        else z=y-x;
      }
      REP(j,k,n) {
        s[j]=(char)((s[j]-'0'+10+z)%10+'0');
        int c=cc;
        if(z) c++;
        if(!m[k+1].count(s)||m[k+1][s]>c) {
          m[k+1][s]=c;
          que.push(PP(c,P(k+1,s)));
        }
      }
    }
    pr(m[n][tt]);
  }
}
 
int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


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

int main(){
  string s;
  cin >> s;
  int c = s.size(),cnt=0;
  for(int i=0;i<c-1;i++){
    if(s.at(i+1)!=s.at(i)){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 512
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	string s;
	cin >> s;

	if (s.back() == -1) {
		cout << -1 << "\n";
		return 0;
	}

	vector<int> ans;
	ans.reserve(N);
	for (int i = s.size() - 1; i >= 0; i--) {

		if (i == 0) break;

		for (int j = M; j >= 0; j--) {

			if (j == 0) {
				cout << -1 << "\n";
				return 0;
			}

			if (i - j >= 0 && s[i - j] == '0') {
				DMP(j);
				i -= j - 1;
				ans.emplace_back(j);
				break;
			}

		}
	}

	reverse(ans.begin(), ans.end());

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1104
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 5e2+1;
 
#define ll int
int main(int argc, char const *argv[]){
        ll h, w, ch, cw, dh, dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    string s[h];
    for(int i = 0; i < h; i++)
    {
        cin >> s[i];
    }
    if(s[ch-1][cw-1] == '#')
    {
        cout << -1 << '\n';
        return 0;
    }
    ch--, cw--, dh--, dw--;
    ll dp[h][w];
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
            dp[i][j] = INT_MAX;
    }
    priority_queue<array<ll,3>> q;
    q.push({0,ch, cw});
    dp[ch][cw] = 0;
    ll dx[] = {-2, -1, 0, 1, 2};
    ll dy[] = {-2, -1, 0, 1, 2};
    ll dxx[] = {-1, 1, 0, 0};
    ll dyy[] = {0, 0, -1, 1};
    while(!q.empty())
    {
        int x = q.top()[1], y = q.top()[2], z = -q.top()[0];
        q.pop();
        if(dp[x][y] < z)
            continue;
        for(int i = 0; i < 4; i++)
        {
            if((x + dxx[i] >= 0) && (x + dxx[i] < h) && (y + dyy[i] >= 0) && (y + dyy[i] < w))
            {
                if((s[x + dxx[i]][y + dyy[i]] != '#') && (dp[x + dxx[i]][y + dyy[i]] > dp[x][y]))
                {
                    dp[x+dxx[i]][y+dyy[i]] = dp[x][y];
                    q.push({-dp[x+dxx[i]][y+dyy[i]], x+dxx[i], y+dyy[i]});
                }
            }
        }
        for(int i = 0; i < 5; i++)
        {
            for(int j = 0; j < 5; j++)
            {
                if((x + dx[i] >= 0) && (x + dx[i] < h) && (y + dy[j] >= 0) && (y + dy[j] < w))
                {
                    if((s[x + dx[i]][y + dy[j]] != '#') && (dp[x + dx[i]][y + dy[j]] > dp[x][y] + 1))
                    {
                        dp[x+dx[i]][y+dy[j]] = dp[x][y] + 1;
                        q.push({-dp[x+dx[i]][y+dy[j]], x+dx[i], y+dy[j]});
                    }
                }
            }
        }
    }
    if(dp[dh][dw] == INT_MAX)
        cout << -1 << '\n';
    else
        cout << dp[dh][dw] << '\n';
    return 0;
}

Measured memory_bytes: 9484
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s1, s2, t;
    int n1, n2;
    cin >> s1 >> s2 >> n1 >> n2 >> t;
    if (t==s1) {
        cout << n1-1 << " " << n2 << "\n";
    }
    else {
        cout << n1 << " " << n2-1 << "\n";
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    long long ans = 0;
    while (true) {
        for (int i = 0; i < N; i++) {
            if (A[i] % 2 == 1) {
                cout << ans << endl;
                return 0;
            }
        }
        ans++;
        for (int i = 0; i < N; i++) {
            A[i] /= 2;
        }
    }
    return 0;
}


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

int main(){
  char month[12][2]={"01","02","03","04","05","06","07","08","09","10","11","12"};
  char s[4];
  int i,c1=0,c2=0;
  scanf("%s",s);
  for(i=0;i<12;i++){
    if(strncmp(s,month[i],2)==0)
      c1++;
    if(strncmp(&*(s+2),month[i],2)==0)
      c2++;
  }
  if(c1==1 && c2==1)
    printf("AMBIGUOUS\n");
  else if(c1==1 && c2==0)
    printf("MMYY\n");
  else if(c1==0 && c2==1)
    printf("YYMM\n");
  else
    printf("NA\n");
  return 0;
}

Measured memory_bytes: 128
//TimeLimitExceeded.cpp
#include <iostream>

using namespace std;

int main () {
  int N; int T; 
  cin >> N;
  cin >> T;
 
  int min = 10000;
  int c, t;
  for (int j = 0; j <= N-1; j++) {
    cin >> c >> t;
    if (t <= T){
      if(min > c) {
        min = c;
      }
    }
  }
  if (min > 1000) {
    cout << "TLE" << endl;
  } else {
  cout << min << endl;
  }
  return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  auto b = a;
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  cout << b.size() - (b.size() - a.size() + 1) / 2 * 2 << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;


string s[10000];
int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> s[i];
    }

    int ans = 0;
    int b_start_a_end = 0;
    int b_start = 0;
    int a_end = 0;
    for(int i = 0; i < N; i++){
        if(s[i][0] == 'B'){
                b_start ++;
        }
        if(s[i][s[i].size() - 1] == 'A'){
            a_end ++;
        }
        if(s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A'){
            b_start_a_end ++;
        }
        for(int j = 0; j < s[i].size() - 1; j++){
            if(s[i][j] == 'A' && s[i][j + 1] == 'B'){
                ans ++;
            }
        }
    }
    ans += max(0, b_start_a_end - 1);
    int b_start_not_a_end = b_start - b_start_a_end;
    int a_end_not_b_start = a_end - b_start_a_end;
    if(b_start_a_end > 0){
        if(b_start_not_a_end > 0){
            ans ++;
            b_start_not_a_end--;
        }
        if(a_end_not_b_start > 0){
            ans++;
            a_end_not_b_start--;
        }
    }
    ans += min(b_start_not_a_end, a_end_not_b_start);

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

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int N;
    cin >> N;
    cout << ((N >= 1000) ? "ABD" : "ABC") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int r, c, i, j, n;
    int cells[128][128] = {0};

    scanf("%d %d\n", &r, &c);
    for(i = 0; i < r; i++)
    {
        for(j = 0; j < c; j++)
        {
            scanf("%d", &cells[i][j]);
        }
    }

    for(i = 0; i < r; i++)
    {
        for(j = 0; j < c; j++)
        {
            n = cells[i][j];
            cells[r][j] += n;
            cells[i][c] += n;
            cells[r][c] += n;
        }
    }

    for(i = 0; i <= r; i++)
    {
        for(j = 0; j < c; j++)
        {
            printf("%d ", cells[i][j]);
        }
        printf("%d\n", cells[i][c]);
    }

    return 0;
}

Measured memory_bytes: 672