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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  string S; cin >> S;
  if(S[2] == S[3] && S[4] == S[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int k, n;
	cin >> k >> n;
	if (500*k >= n)
		cout << "Yes\n";
	else
		cout << "No\n";

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

signed main() {
	int n;
	cin >> n;
	int a[n];
	rep (i, n) cin >> a[i];
	rep (i, n) rep (j, n) {
		if (i != j && abs(a[i] - a[j]) % (n - 1) == 0) {
			cout << a[i] << " " << a[j] << endl;
			return 0;
		}
	}
	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}

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


Measured memory_bytes: 3580
#include <bits/stdc++.h>
typedef long long ll; 
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define sc(n) scanf("%d", &n) 
using namespace std;

int n, k;

void solve() {
    cin >> n >> k;
    int additional = ((n-1)*(n-2))/2-k;
    if (additional < 0) {
        cout << -1;
        return;
    }
    cout << n-1+additional << '\n';
    fo(i, n-1) printf("%d %d\n", n, i+1);
    int start = 1;
    int end = 2;
    while (additional--) {
        printf("%d %d\n", start, end);
        end++;
        if (end == n) {
            start++;
            end = start+1;
        }
    }

}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PRECISION(x) cout << fixed << setprecision(x); 
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(i,n) for (int i = 0; i < n; ++i)
#define DO(X) while(X--)
#define DRI(X) int (X); cin >> X
#define DRII(X, Y) int X, Y; cin >> X >> Y
#define DRIII(X, Y, Z) int X, Y, Z; cin >> X >> Y >> Z
#define read(X) for(int &ele : (X)) cin >> ele
#define readI(X) for(int idx = 1; idx < SZ((X)); ++idx) cin >> (X)[idx]
#define debug(x) cerr << '>' << #x << ':' << x << endl
#define MP make_pair
#define PB push_back
#define F first
#define S second

using namespace std;
typedef long long LL;
const int INF = 1<<29;
inline int in() { int x; cin >> x; return x; }
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }

int main(){
	FAST_IO 
	DRI(num);
	auto is_prime = [](int curNum){
		if(curNum <= 1) return false;
		for(int checkNum = 2; checkNum * checkNum <= curNum; ++checkNum){
			if(curNum % checkNum == 0) return false;
		}
		return true;
	};
	while(!is_prime(num)) num++;
	cout << num << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll h, w, k;
	cin >> h >> w >> k;
	vector<string> ck(h);
	for (ll i = 0; i < h; i++) cin >> ck[i];

	vector<vll> ans(h, vll(w, 0));
	ll cnt = 1;
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			if (ck[i][j] == '#') {
				ans[i][j] = cnt;
				ll x = j - 1;
				while (x >= 0 && ans[i][x] == 0 && ck[i][x] == '.') {
					ans[i][x] = cnt;
					x--;
				}
				x = j + 1;
				while (x < w && ans[i][x] == 0 && ck[i][x] == '.') {
					ans[i][x] = cnt;
					x++;
				}
				cnt++;
			}
		}
	}

	for (ll i = 0; i < h - 1; i++) {
		ll x = i;
		while (x < h - 1 && ans[x][0] > 0 && ans[x + 1][0] == 0) {
			ans[x + 1] = ans[x];
			x++;
		}
		i = x;
	}

	for (ll i = h - 1; i > 0; i--) {
		ll x = i;
		while (x > 0 && ans[x][0] > 0 && ans[x - 1][0] == 0) {
			ans[x - 1] = ans[x];
			x--;
		}
		i = x;
	}

	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w - 1; j++) cout << ans[i][j] << " ";
		cout << ans[i][w - 1] << endl;
	}
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <numeric>
using namespace std;

int main(){
    int N;
    cin >> N;
    
    if(N % 2 == 0){
        cout << N << endl;
    }else{
        cout << N * 2 << endl;
     }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    string s;
    int a,b;
    cin >> a >> b;
    cout << max(0LL,a - b*2) << endl;
}


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

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> n;
	cout << n * 800 - (n / 15 * 200);
	
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  char a; cin >> a;
  if (isupper(a)) {
    cout << "A" << endl;
  } else {
    cout << "a" << endl;
  }
}

Measured memory_bytes: 3620
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

/**
 * pushpush
 */
public class Main {

    public static void main(String[] args) {
        int n;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        Deque<Long> dq = new ArrayDeque<Long>();
        for (int i = 0; i < n; i++) {
            long a = sc.nextLong();

            if (i % 2 == 0) {
                dq.addLast(a);
            } else {
                dq.addFirst(a);
            }
        }

        if (n % 2 == 0) {
            while (!dq.isEmpty()) {
                System.out.print(dq.poll() + " ");
            }
            System.out.println();
        } else {
            while (!dq.isEmpty()) {
                System.out.print(dq.pollLast() + " ");
            }
            System.out.println();
        }
        sc.close();
    }
}

Measured memory_bytes: 97028
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_E main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif

void z_algorithm(vi& pre, string s) {
    int N = s.size();
    //vi pre(N);
    pre = vi(N);
    
    pre[0] = N;
    int i = 1, j = 0;
    while (i < N) {
        while (i + j < N && s[j] == s[i + j]) j++;
        pre[i] = j;

        if (j == 0) {
            i++;
            continue;
        }

        int k = 1;
        while (i + k < N && k + pre[k] < j) {
            pre[i + k] = pre[k];
            k++;
        }
        i += k;
        j -= k;
    }
}

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

    int N; cin >> N;
    string S; cin >> S;

    int ans = 0;
    for (int l = 0; l < N; l++) {
        vi pre;
        z_algorithm(pre, S.substr(l));

        for(int r=1; r<pre.size(); r++) {            
            ans = max(ans, min(r, pre[r]));
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
#define PI 3.141592
using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	vector<vector<int>> r(h, vector<int>(w));
	vector<vector<int>> l(h, vector<int>(w));
	vector<vector<int>> u(h, vector<int>(w));
	vector<vector<int>> d(h, vector<int>(w));
	vector<vector<bool>> wb(h, vector<bool>(w));
	int max = 0;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char tmp;
			cin >> tmp;
			wb[i][j] = (tmp == '#' ? false : true);
		}
	}

	for (int i = 0; i < h; i++) {
		l[i][0] = (wb[i][0] ? 1 : 0);
		r[i][w - 1] = (wb[i][w - 1] ? 1 : 0);
		for (int j = 1; j < w; j++) {
			l[i][j] = (wb[i][j] ? l[i][j - 1] + 1 : 0);
			r[i][w - j - 1] = (wb[i][w - j - 1] ? r[i][w - j] + 1 : 0);
		}
	}

	for (int i = 0; i < w; i++) {
		d[0][i] = (wb[0][i] ? 1 : 0);
		u[h - 1][i] = (wb[h - 1][i] ? 1 : 0);
		for (int j = 1; j < h; j++) {
			d[j][i] = (wb[j][i] ? d[j - 1][i] + 1 : 0);
			u[h - j - 1][i] = (wb[h - j - 1][i] ? u[h - j][i] + 1 : 0);
		}
	}


	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int tmp = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3;
			if (max < tmp) {
				max = tmp;
			}
			//printf("(%d,%d,%d,%d) ", l[i][j], r[i][j], u[i][j], d[i][j]);
		}
	}

	printf("%d", max);

	return 0;
}

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

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

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

    // start
    vector<int> x = {0, 0, 0}, y = {1, 1, 1};
    rep(i, 3)
    {
        char s;
        cin >> s;
        if (s == 'a')
            x.at(0)++;
        if (s == 'b')
            x.at(1)++;
        if (s == 'c')
            x.at(2)++;
    }
    cout << (x == y ? "Yes" : "No") << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<cmath>
#include <string>

 int main (){

	 int a, b, c, d;
	 int ans = 0;

	 std::cin >> a >> b >> c >> d;

	 if (a > b) {
		 ans += b;
	 }
	 else {
		 ans += a;
	 }
	 if (c > d) {
		 ans += d;
	 }
	 else {
		 ans += c;
	 }

	 std::cout << ans << std::endl;

	 return 0;
}

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

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

Measured memory_bytes: 1792
n,m=map(int,input().split())
a = [int(input()) for i in range(m)]
broken = set(a)
dp=[0]*(n+1)
mod = 10**9 + 7

for i in range(n,-1,-1):
  if i in broken:
    continue
  elif i==n or i==n-1:
    dp[i]=1
  else:
    dp[i]=dp[i+1]+dp[i+2]
    dp[i]%=mod
print(dp[0])

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

int main() {
  int Q; cin >> Q;
  vector<int> l(Q),r(Q),ans(Q);
  for (int i = 0; i < Q; i++) cin >> l[i] >> r[i]; 
  vector<int> prime = {2,3};
  
  for (int i = 4; i <= 100000; i++) {
    bool can = true; 
    for (int j = 2; j*j <= i; j++) {
      if (i % j == 0) can = false;
    }
    if (can) prime.push_back(i);
  }
  
  vector<int> like2017(0);
  
  for (int i = 0; i < prime.size(); i++) {
    if (prime[i] % 2 != 0) {
      int k = (prime[i] + 1) / 2;
      for (int j = 0; j < prime.size(); j++) {
        if (k == prime[j]) like2017.push_back(prime[i]);
      }
    }
  }
  
  for (int i = 0; i < Q; i++) {
    int ll = lower_bound(like2017.begin(),like2017.end(),l[i]) - like2017.begin();
    int rr = upper_bound(like2017.begin(),like2017.end(),r[i]) - like2017.begin();
    ans[i] = rr - ll;
  }
  
   for (int i = 0; i < Q; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 1920
from collections import deque

n = int(input())
AA = [deque(list(map(int, input().split()))) for _ in range(n)]

graph = [[] for _ in range(n * n)]


def calc(i, j):
    if j > i:
        i, j = j, i
    return i * n + j


to = [0] * (n * n)
for i in range(n):
    for j in range(n - 2):
        u = calc(i, AA[i][j] - 1)
        v = calc(i, AA[i][j + 1] - 1)
        graph[u].append(v)
        to[v] += 1
start = []
for i in range(n * n):
    if to[i] == 0:
        start.append(i)


def topological_sort(edge_num, graph, start, to):
    topo = []
    cnt = 0
    stack = deque(start)
    while stack:
        v = stack.popleft()
        topo.append(v)
        cnt += 1
        for u in graph[v]:
            to[u] -= 1
            if to[u] == 0:
                stack.append(u)
    return topo, cnt


topo, cnt = topological_sort(n * n, graph, start, to)
if cnt != n * n:
    print(-1)
    exit()
day = [1] * (n * n)
for i in topo:
    for j in graph[i]:
        day[j] = day[i] + 1
print(max(day))


Measured memory_bytes: 197948
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

const int mod = 1e9 + 7;
const int rev2 = (mod + 1) / 2;

const int maxn = 500500;
vector<int> zeros;
int p[maxn];
bool used[maxn];
ll fact[maxn];

struct Fw {
    int t[maxn];

    void put(int pos, int delta) {
        for (int i = pos; i < maxn; i |= i + 1) {
            t[i] += delta;
            t[i] %= mod;
        }
    }

    ll get(int r) {
        ll res = 0;
        for (int i = r - 1; i >= 0; i = (i & (i + 1)) - 1) {
            res += t[i];
            res %= mod;
        }
        return res;
    }

} fw;

int main() {
    #ifdef LOCAL
    assert(freopen("e.in", "r", stdin));
    #else
    #endif
    int n;
    cin >> n;
    int k = 0;
    forn (i, n) {
        cin >> p[i];
        --p[i];
        if (p[i] == -1)
            ++k;
        else
            used[p[i]] = true;
    }
    forn (i, n)
        if (!used[i])
            zeros.push_back(i);
    ll coef = 0;

    fact[0] = 1;
    for (int i = 1; i < maxn; ++i) {
        fact[i] = (fact[i - 1] * ll(i)) % mod;
    }

    ll res = fact[k];
    ll zc = 0;
    for (int pos = n - 1; pos >= 0; --pos) {
        ll X = fact[n - pos - 1];
        if (p[pos] == -1) {
            ll A = coef;
            A %= mod;
            A *= fact[k - 1];
            A %= mod;
            ll B = zc * fact[k];
            B %= mod;
            B *= rev2;
            B %= mod;

            //cerr << (A + B) * X << '\n';

            res += (A + B) * X;
            res %= mod;

            ++zc;
        } else {
            int bd = lower_bound(zeros.begin(), zeros.end(), p[pos]) - zeros.begin();
            coef += k - bd;
            coef %= mod;

            ll A = fw.get(p[pos]) * fact[k];
            A %= mod;
            ll B = zc * bd;
            B %= mod;
            B *= fact[k - 1];
            B %= mod;

            //cerr << (A + B) * X << '\n';

            res += (A + B) * X;
            res %= mod;

            fw.put(p[pos], 1);
        }
    }
    cout << res << '\n';
}


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

int main() {
    string s;
    cin >> s;
    int s_size = s.size();
    if (s_size%2 == 1) s.pop_back();
    s.erase(s.end()-2, s.end());
    while (true) {
        int count = 0;
        s_size = s.size();
        for (int i = 0; i < s_size/2; i++) {
            if (s[i] == s[i+s_size/2]) count++;
        }
        if (count == s_size/2) {
            cout << s_size << endl;
            return 0;
        }
        s.erase(s.end()-2, s.end());
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    string S, T;
    cin >> S >> T;
    bool flag = true;
    map<char,char> ma, rma;
    rep(i,S.length()){
        char s = S[i];
        char t = T[i];
        if(ma.count(s)){
            if(ma[s] != t) flag = false;
        }
        if(rma.count(t)){
            if(rma[t] != s) flag = false;
        }
        ma[s] = t;
        rma[t] = s;
    }
    if (flag) puts("Yes");
    else puts("No");
    return 0;
} 

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int counter(int x){
    if(!x)return 0;
    return counter(x>>1)+(x&1);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    int M=in();
    vector<int> L(M);
    vector<int> R(M);
    REP(i,M){
        int l;int r;
        cin>>l>>r;
        L[i]=l;R[i]=r;
    }
    int max_l;int min_r;
    max_l=*max_element(all(L));
    min_r=*min_element(all(R));
    int ans;
    ans=min_r-max_l+1;
    ans=max(ans,0);
    print(ans);
    return 0;
}

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

int main(){
    bool A=1;
    while (A){
        int x,y;
        cin >> x >> y;
        if (x==0 && y==0) {A=0;}
        else {cout << min(x,y) << " " << max(x,y) << endl;}
    }
}


Measured memory_bytes: 3088
require 'matrix'

def power(n, k)
  x = 1
  r = n
  while k > 0
    x *= r if k & 1 == 1
    r *= r
    # x %= MOD
    # r %= MOD
    k >>= 1
  end
  x
end

m1 = Matrix[
  [1, -1],
  [0,  1]
]
m2 = Matrix[
  [1, 0],
  [1, 1]
]

n = gets.to_i
v = Vector[*gets.split.map(&:to_i)]
x = power(m2 * m1, n / 2) * v
x = m1 * x if n.odd?
puts x.to_a * ' '


Measured memory_bytes: 7136
#include <stdio.h>
#include <stdlib.h>


// I/O
int get_int() {
    int n = 0;
    int c = getchar_unlocked();
    if(c == 45) {
        c = getchar_unlocked();
        while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
        return -n;
    } else if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
    return n;
}
int get_str(char *str) {
    int c;
    while((c = getchar_unlocked()) > 32) *str++ = (char)c;
    *str = 0;
    return c;
}
void put_int(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    if(n < 0) n = -n, putchar_unlocked('-');
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
//


// Binary Search Tree
typedef struct Node {
    int key;
    struct Node *left, *right;
} Node;
typedef struct BST {
    Node *root;
    size_t size;
} BST;
void bst_init(BST *BST) {
    BST->root = NULL;
    BST->size = 0;
}
void bst_insert(BST *BST, int key) {
    Node *new_node = malloc(sizeof(Node));
    new_node->key = key;
    new_node->left = NULL;
    new_node->right = NULL;
    Node *tmp;
    Node *root = BST->root;
    while(root != NULL) {
        tmp = root;
        if(key < root->key) root = root->left;
        else root = root->right;
    }
    if(BST->size == 0) BST->root = new_node;
    else if(key < tmp->key) tmp->left = new_node;
    else tmp->right = new_node;
    BST->size++;
}
void bst_inorder(Node *root) {
    if(root == NULL) return;
    bst_inorder(root->left);
    putchar_unlocked(' '), put_int(root->key);
    bst_inorder(root->right);
}
void bst_preorder(Node *root) {
    if(root == NULL) return;
    putchar_unlocked(' '), put_int(root->key);
    bst_preorder(root->left);
    bst_preorder(root->right);
}
//


int main(int argc, char **argv) {
    BST BST;
    bst_init(&BST);
    int m = get_int();
    char c[8];
    for(int i = 0; i < m; ++i) {
        get_str(c);
        if(*c == 'i') {
            int key = get_int();
            bst_insert(&BST, key);
        } else {
            bst_inorder(BST.root);
            putchar_unlocked('\n');
            bst_preorder(BST.root);
            putchar_unlocked('\n');
        }
    }
    return 0;
}



Measured memory_bytes: 17156
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x, y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x, y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
#define T ll tt; cin>>tt; while(tt--)
using namespace std;
ll mode=pow(10,9)+7;
bool cmp(pair<long double ,int > x, pair<long double , int> y){ return x.F<y.F && x.S<y.S; }
const ll maxn=1e4+10;
ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }
int main(){ 
    
//    #ifndef ONLINE_JUDGE
//  		freopen("input.txt", "r", stdin);
//    #endif
    
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll h,n;
    cin>>h>>n;
    ll sum=0;
    for (int i=0;i<n;i++){
    	ll x;
    	cin>>x;
    	sum+=x;
    	
	}
    if (sum>=h) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
N = gets.to_i

dp = Array.new(N+1, 0)
(1..N).each do |i|
    cand = dp[i-1] + 1
    n = 6
    while n <= i
        c = dp[i-n] + 1
        cand = c if cand > c
        n *= 6
    end
    n = 9
    while n <= i
        c = dp[i-n] + 1
        cand = c if cand > c
        n *= 9
    end
    dp[i] = cand
end
puts dp[N]

Measured memory_bytes: 2556
#include<iostream>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>//min,max,swap,rand,reverse,sort,lower_bound
#include<functional>
#include<vector>
#include<list>
#include<map>
#include<tuple>
#include<cmath>//abs, sin, cos
#include<bitset>
using namespace std;

int main()
{
	char S[200010], T[200010];
	string copy;
	int count = 0;
	cin >> S;
	cin >> T;
	copy = S;
	for (int i = 0; i < copy.size(); i++) {
		if (S[i] != T[i]) {
			count++;
			S[i] = T[i];
		}
	}

	cout << count << endl;
	return 0;
}

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

using namespace std;

int main(void) {
  
  int A, B, H, M;
  cin >> A >> B >> H >> M;

  // 針の単位時間あたりの角度
  double HdegPh = 30.0;
  double HdegPm = 30 / 60.0; // 0.5
  double MdegPm = 6.0;

  // 針の角度
  double Hdeg = HdegPh * H + HdegPm * M;
  double Mdeg = MdegPm * M;
  
  double diff;
  if (Hdeg >= Mdeg) diff = Hdeg - Mdeg; else diff = Mdeg - Hdeg;
  if (diff > 180) diff = 360 - diff;

  double ans2 = A*A + B*B - 2*A*B*cos(diff * 2 * M_PI / 360.0);
  double ans = sqrt(ans2);

  printf("%.16f\n", ans);
}


Measured memory_bytes: 4224
N, M = [int(n) for n in input().split()]
left, right = 1, N

for _ in range(M):
    L, R = [int(n) for n in input().split()]
    if left < L:
        left = L
    if R < right:
        right = R

if left <= right:
    print(right - left + 1)
else:
    print(0)


Measured memory_bytes: 3060
/*
    Author:    DreamCat4er
    Created:   29.08.2020 15:52:18
*/
#include <bits/stdc++.h>
using namespace std;

void solve() {
    long long d, t, s;
    cin >> d >> t >> s;
    
    if (d <= t * s) cout << "Yes\n";
        else cout << "No\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
                
    #ifdef _LOCAL
        int t;
        cin >> t;
        for (int _t = 0; _t < t; ++_t) {
            cout << "Case " << _t << " :\n";
            solve();
            cout << "\n";
        }
    #else
        solve();
    #endif // _LOCAL

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

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

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }


int main() {
  int n, m; cin>>n>>m;
  vector<long long> h(n);
  rep(i, n) cin>>h[i];
  vector<vector<int>> g(n);
  rep(i, m) {
    int a, b; cin>>a>>b;
    --a; --b;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  int ans = 0;
  rep(i, n) {
    bool ok = true;
    for (auto x: g[i]) {
      if (h[x] >= h[i]) ok = false;
    }
    if (ok) ++ans;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 9204
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        boolean[] a = new boolean[x+1];
        a[1] = true;
        for(int i = 2; i < x; i++) {
            int t = i * i;
            while(t <= x) {
                a[t] = true;
                t *= i;
            }
        }
        int ans = x;
        while(!a[ans]) ans--;
        System.out.println(ans);
    }
}

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

int main() {
    int n,i,a=0,b=0;
    cin>>n;
    string s;
    cin>>s;
    for(i=0;i<n;i++)
    {
        if(s[i]=='R')
        a++;
        else
        b++;
    }
    if(a>b)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    }

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int h,w;
	char a[100][100];
	cin>>h>>w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<h+2;i++){
		for(int j=0;j<w+2;j++){
			if(i==0||i==h+1||j==0||j==w+1)cout<<'#';
			else cout<<a[i-1][j-1];
		}
		cout<<endl;
	}
	getchar();
	getchar();
	return 0;
}


Measured memory_bytes: 256
package main

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

const (
	maxBufsize = 1000000
)

func inputs(lines int) []string {
	var strSlice []string

	rdr := bufio.NewReaderSize(os.Stdin, maxBufsize)

	for i := 0; i < lines; i++ {

		line := ReadLine(rdr)
		strSlice = append(strSlice, line)

	}

	return strSlice
}

// ReadLine is to read long line
func ReadLine(rdr *bufio.Reader) string {
	buf := make([]byte, 0, maxBufsize)
	for {
		l, p, e := rdr.ReadLine()

		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}

	return string(buf)
}

func gcd2(a, b int) int {
	if b == 0 {
		return a
	}

	return gcd2(b, a%b)
}

func gcd3(a, b, c int) int {
	buf := []int{a, b, c}

	sort.Ints(buf)

	g2 := gcd2(buf[2], buf[1])

	if buf[0] == g2 {
		return g2
	}

	if buf[0] < g2 {
		return gcd2(g2, buf[0])
	} else {
		return gcd2(buf[0], g2)
	}
}

func main() {
	line1 := inputs(1)

	k, _ := strconv.Atoi(line1[0])

	sum := 0
	for a := 1; a <= k; a++ {
		for b := 1; b <= k; b++ {
			for c := 1; c <= k; c++ {
				sum += gcd3(a, b, c)
			}
		}
	}

	fmt.Println(sum)

	return
}


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

int main() {
    long long N;
    cin >> N;
    string S; cin >> S;
    long long W = 0, B = 0;
    for (long long i = 0; i < N; i++) {
        if (S.at(i) == '.') W++;
    }
    long long ans = W;
    for (long long i = 0; i < N; i++) {
        if (S.at(i) == '#') B++;
        else if (S.at(i) == '.') W--;
        long long num = B + W;
        if (ans > num) ans = num;
    }
    cout << ans << endl;
}

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

const double EPS=1e-10;
const double PI=acos(-1.0);
inline int sgn(double x)
{
	return (x>EPS)-(x<-EPS);
}

int main()
{
	int a,b,h,m;
	scanf("%d%d%d%d",&a,&b,&h,&m);
	// c^2=a^2+b^2-2*cos(A,B)*a*b;
	double A=(h/12.+m/12./60.)*2.0*PI;
	double B=(m/60.)*2.0*PI;
	if(h==0&&m==0) printf("%d\n",abs(a-b));
	else
	{
		double C=cos(A-B);
		//cout<<C<<endl;
		if(sgn(C-1)==0) printf("%.13f\n",fabs(a+b));
		else printf("%.13f\n",sqrt((double)a*a+(double)b*b-2.0*C*a*b));
	}
	return 0;
}

Measured memory_bytes: 4172
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//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(); }

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

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

	ll X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;

	vector<pair<ll, ll>> apples;
	apples.reserve(A + B + C);
	ll apple;
	for (ll i = 0; i < A; ++i) {
		cin >> apple;
		apples.emplace_back(apple, 0);
	}
	for (ll i = 0; i < B; ++i) {
		cin >> apple;
		apples.emplace_back(apple, 1);
	}
	for (ll i = 0; i < C; ++i) {
		cin >> apple;
		apples.emplace_back(apple, 2);
	}

	sort(apples.begin(), apples.end(), greater<pair<ll, ll>>());

	ll i = 0;
	ll res = 0;
	ll ps_count = 0, qs_count = 0;
	for (; i < X + Y; ++i) {
		if (apples[i].second == 0) {
			++ps_count;
			if (ps_count > X) continue;
		}
		else if (apples[i].second == 1) {
			++qs_count;
			if (qs_count > Y) continue;
		}
		res += apples[i].first;
	}
	for (; ps_count > X; ++i) {
		if (apples[i].second == 0) continue;
		res += apples[i].first;
		--ps_count;
	}
	for (; qs_count > Y; ++i) {
		if (apples[i].second == 1) continue;
		res += apples[i].first;
		--qs_count;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 4992
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <queue>
using namespace std;

int main(){
  int N, ans = 0, count = 0 ;
  cin >> N ;
  for(int i=1;i<N;i++){
    count = N / i ;
    ans += count ;
    if((N%i) == 0) ans-- ;
  }
  cout << ans << endl ;
  return 0 ;
}

Measured memory_bytes: 3640
_n, p = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

cases = a.each_with_object({ odd: 0, even: 1 }) do |aa, hash|
  if aa.even?
    hash[:odd] *= 2
    hash[:even] *= 2
  else
    hash[:odd] = hash[:even] = hash[:odd] + hash[:even]
  end
end
puts p.zero? ? cases[:even] : cases[:odd]

Measured memory_bytes: 3836
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const ld EPS = 1e-6;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const char nl = '\n';

template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> void ckmin(T& a, T b) { a = min(a, b); }
template <class T> void ckmax(T& a, T b) { a = max(a, b); }

// (Integer/Long).bitCount(x)
int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << h; if (sizeof...(t)) cerr << ", "; DBG(t...); }

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
void setIO(string s = "") {
	unsyncIO();
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
}

// Binary Exponentiation
ll pow(ll b, ll e, ll m = 0LL, ll ans = 1LL) { while (e) { if (e & 1LL) { ans *= b; if (m) ans %= m; } b *= b, e >>= 1LL; if (m) b %= m; } return ans; }



void solve(int tcn) {
	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	F0R(i, n) cin >> a[i];
	FOR(i, k, n)
		cout << (a[i] > a[i-k] ? "Yes" : "No") << nl;
}

int main() {
    setIO();

    int t = 1; //cin >> t;
	for (int i = 1; i <= t; ++i) {
		//cout << "Case #" << i << ": ";
		solve(i);
	}
	return 0;
}

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

const int N = 100000 + 7;

pair <int, int> get(int a) {
    //while(a % 10 == 0) a /= 10;
    int last = a % 10;
    while(a >= 10) a /= 10;
    int first = a;
    return {first, last};
}

int d[10][10];

int32_t main() {
  int n; cin >> n;
  long long ans = 0, cnt = 0;
  for(int i = 1; i <= n; i++) {
    pair <int, int> a = get(i);
    d[a.first][a.second]++;
   // cout << a.first << " " << a.second << endl;
  }
  for(int i = 1; i <= n; i++) {
     pair <int, int> a = get(i);
     ans += d[a.second][a.first];
  }

  cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define L long long
#define pb push_back
using namespace std;
int n,a[100010],b[100010],x[200010],p,q;
map<int,int> h;
vector<int> w[200010],A;
bool u[200010];
inline int dfs(int i)
{
	int j,k=0;
	u[i]=1;
	for(j=0;j<w[i].size();j++)
	  {
	   if(!u[w[i][j]])
	     k+=dfs(w[i][j]);
	   if(w[i][j]!=i)
	     k++;
	  }
	return k;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k=0,l;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	  scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
	  scanf("%d",&b[i]);
	for(i=1;i<=n;i++)
	  {
	   k^=a[i];
	   if(!h[a[i]])
	     h[a[i]]=++p;
	   a[i]=h[a[i]];
	   if(!h[b[i]])
	     h[b[i]]=++p;
	   b[i]=h[b[i]];
	   w[a[i]].pb(b[i]);
	   x[a[i]]++;
	   x[b[i]]--;
	  }
	if(!h[k])
	  h[k]=++p;
	k=h[k];
	for(i=1,j=0;i<=p;i++)
	  if(x[i]>0)
	    j+=x[i];
	if(j>1 || j==1 && x[k]!=-1)
	  {
	   printf("-1\n");
	   return 0;
	  }
	q=-1;
	if(j==1)
	  {
	   for(i=1;i<=p;i++)
	     if(x[i]==1)
	       j=i;
	   w[k].pb(j);
	   q--;
	  }
	for(i=1;i<=p;i++)
	  if(!u[i])
	    {
	     l=dfs(i);
	     if(l)
	       q+=l+1;
	     else if(i==k)
	       q++;
		}
	printf("%d\n",q);
	return 0;
}


Measured memory_bytes: 18560
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    ll n; cin >>n;
    vector<ll> c(n); vector<ll> s(n); vector<ll> f(n);
    FOR(i,1,n)  cin >> c[i] >> s[i] >> f[i];

    vector<int> bs(100100);
    for (ll i = 0; i < 100100; i++) {
        bs[i] = i;
    }

    vector<int> res(n);
    for (ll i = 1; i < n; i++) {

        ll ans = 0;

        for (ll j = i; j < n; j++) {

            if (ans < s[j]) {

                ans = s[j];

            } else if (ans % f[j] != 0) {

                ll ok = bs.size();
                ll ng = -1;
                while (abs(ok - ng) > 1) {
                    ll m = (ok+ng)/2;
                    if (s[j] + bs[m]*f[j] >= ans) {
                        ok = m;
                    } else {
                        ng = m;
                    } 
                }
                ans = s[j] + bs[ok]*f[j];
                
            }
            ans += c[j];

        }
        res[i-1] = ans;
    }

    for (int i = 0; i < n; i++) {
        cout << res[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))


def solve(isPosi,N,A):
    ans = 0
    sm = 0
   
    for a in A:
        if isPosi:
            sm += a
            if sm >= 0:
                ans += abs(-1-sm)
                sm = -1
            isPosi = False
        
        else:
            sm += a
            if sm <= 0:
                ans += abs(1-sm)
                sm = 1
            isPosi = True
        
    return ans

ans_p = solve(True,N,A)
ans_n = solve(False,N,A)

print(min(ans_p,ans_n))

Measured memory_bytes: 14340
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define ll long long
const ll INF = 1<<29;
const ll MOD = 1e9+7;

ll dp[100010][13];

int main(){
    string s; cin >> s;
    reverse(s.begin(),s.end());
    rep(i,100010) rep(j,13) dp[i][j] = 0;
    dp[0][0] = 1;
    ll rec = 1;
    rep(i,s.size()){
        rep(j,13){
            char x = s[i];
            if(x=='?'){
                rep(k,10){
                    ll y = (k*(rec%13))%13;
                    dp[i+1][(j+y)%13] += dp[i][j];
                    dp[i+1][(j+y)%13]%=MOD;
                }
            }
            else{
                ll y = ((x-'0')*(rec%13))%13;
                dp[i+1][(j+y)%13] += dp[i][j];
                dp[i+1][(j+y)%13]%=MOD;
            }
        }
        rec*=10;
        rec%=13;
    }
    cout << dp[s.size()][5] << endl;
}

Measured memory_bytes: 10624
import java.util.Stack;
import java.util.Scanner;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static long res = 0;
    public static int[] ary;
    public static void main(String[] args) throws Exception {
        Stack<Integer> stack = new Stack<>();
        while (sc.hasNext()) {
            int n = sc.nextInt();
            if (n == 0) {
                System.out.println(stack.pop());
            } else {
                stack.push(n);
            }
        }
    }
}

Measured memory_bytes: 25812
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

ll a,b, v, w, t;

int main()
{
  ll pdiff, vdiff;

  cin >> a >> v;
  cin >> b >> w;
  cin >> t;

  if (a==b) {
    printf("YES\n");
    return 0;
  }
  pdiff = (a>b)?(a-b):(b-a);
  if (v>w) {
    vdiff = v-w;
    if (vdiff * t >= pdiff) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  } else {
    printf("NO\n");
  }

  return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, N)cin >> L[i];
    sort(L.begin(), L.end());

    ll res = 0;
    rep(r, N)rep(l, r) {
        int vl = L[r] - L[l];
        int vr = L[r] + L[l];
        int idxl = upper_bound(L.begin(), L.end(), vl) - L.begin();
        int idxr = lower_bound(L.begin(), L.end(), vr) - L.begin() - 1;
        if (idxl > idxr)continue;
        int tres = idxr - idxl + 1;
        if (vl < L[l] && L[l] < vr)tres--;
        if (vl < L[r] && L[r] < vr)tres--;
        res += tres;
    }
    cout << res / 3 << endl;
    return 0;
}


Measured memory_bytes: 256
n=gets.to_i

def calc_(n,x)
  t = x
  t *= x while t <= n
  t /= x
  t
end

def solve_(n)
  return (n/6+n%6) if n < 9
  n9 = calc_(n,9)
  n6 = calc_(n,6)

  i = n / n9

  ret = 100_000
  0.upto(i) do |j|
    m = n
    m -= n9 * j
    k = m / n6
    m = m % n6
    count = solve_(m) + j + k
    ret = count if count < ret
  end
  ret
end

p solve_(n)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef pair<string,int> psi;
typedef pair<psi,int> psii;
int N;
vector<psii> res;
bool sortrule(const psii &p1, const psii &p2)
{
  if(p1.first.first==p2.first.first)
    {
      return p1.first.second>p2.first.second;
    }
  else
    {
      return p1.first<p2.first;
    }
}
int main(int argc,char const* argv[])
{
  cin >> N;
  for(int i=0;i<N;i++)
    {
      string s;
      int p;
      cin >> s >> p;
      res.push_back(psii(psi(s,p),i+1));
    }
  sort(res.begin(),res.end(),sortrule);
  for(int i=0;i<N;i++)
    {
      cout << res[i].second << endl;
    }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int ans = 0;
    if (A >= K) {
        ans = K;
    } else if (B >= K - A) {
        ans = A;
    } else {
        ans = A - (K - A - B);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616