akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        List<Integer> list = new ArrayList<>(n);
        int m = 200, M = -200;
        for(int i = 0; i < n; ++i) {
            int t = Integer.parseInt(sc.next());
            list.add(t);
            m = Math.min(m, t);
            M = Math.max(M, t);
        }
        
        int ans = Integer.MAX_VALUE;
        for(int num = m; num <= M; ++num) {
            int cost = 0;
            for(int i = 0; i < n; ++i) {
                int changed = list.get(i);
                cost += (changed - num) * (changed - num);
            }
            ans = Math.min(ans, cost);
        }
        System.out.println(ans);
    }
}


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

char S[8] = "keyence";

int main(int argc, char const *argv[]) {
	char str[101];
	int i, j;
	int len;

	scanf("%s", &str);

	for (len = 0; str[len]; len++) ;

	char* tmp;
	if ((tmp = strstr(str, S)) != NULL) {
		if (tmp == str) {
			printf("YES\n");
			return 0;
		}

		if (tmp[7] == '\0') {
			printf("YES\n");
			return 0;
		}

		printf("NO\n");
		return 1;
	} else {

		for (i = 0; i < len; i++) {
			if (str[i] != S[i]) {
				break;
			}
		}

		for (j = len-1; i < j; j--) {
			if (str[j] != S[7-(len-j)]) {
				break;
			}
		}

		// printf("%d %d %d\n", i, j,len);

		if (i + (len-j-1) == 7) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}

	}

	return 0;
}


Measured memory_bytes: 128
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e14 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main() {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n, d, ans; cin >> n >> d >> ans;

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

    for(long long i = 0; i < n; i++) {
        long long cnt = 0, day = 1;
        while(day <= d) {
            cnt++;
            day += a[i];
        }
        ans += cnt;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 3660
program main
	implicit none
    character(10)::s
    read(*,*)s
    if(len_trim(s)<=3)then
    	write(*,*)'No'
    else
    	if(s(1:4)=='YAKI')then
        	write(*,*)'Yes'
        else
        	write(*,*)'No'
        end if
    end if
    stop
    
end program main

Measured memory_bytes: 2820
long max(a,b)long a,b;{return a<b?b:a;}
int n;
long dat[1<<19],lazy[1<<19];
init(n_)
{
	n=1;
	while(n<n_)n<<=1;
}
eval(i,l,r)
{
	if(lazy[i])
	{
		dat[i]+=lazy[i];
		if(r-l>1)
		{
			lazy[2*i+1]+=lazy[i];
			lazy[2*i+2]+=lazy[i];
		}
		lazy[i]=0;
	}
}
update(a,b,x,k,l,r)long x;
{
	eval(k,l,r);
	if(b<=l||r<=a)return 0;
	else if(a<=l&&r<=b)
	{
		lazy[k]+=x;
		eval(k,l,r);
	}
	else
	{
		update(a,b,x,2*k+1,l,(l+r)/2);
		update(a,b,x,2*k+2,(l+r)/2,r);
		dat[k]=max(dat[2*k+1],dat[2*k+2]);
	}
}
long query(a,b,k,l,r)
{
	eval(k,l,r);
	if(b<=l||r<=a)return 0;
	else if(a<=l&&r<=b)return dat[k];
	else return max(
		query(a,b,2*k+1,l,(l+r)/2),
		query(a,b,2*k+2,(l+r)/2,r)
	);
}
int N,m;
L[1<<18],R[1<<18],A[1<<18];
first[1<<18],next[1<<18];
main()
{
	scanf("%d%d",&N,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",L+i,R+i,A+i);
	}
	for(int i=1;i<=m;i++)
	{
		next[i]=first[R[i]];
		first[R[i]]=i;
	}
	init(N+1);
	//lazysegtree dp(n+1);
	for(int i=1;i<=N;i++)
	{
		update(i,i+1,query(0,i,0,0,n),0,0,n);
		int p=first[i];
		for(;p!=0;)
		{
			update(L[p],i+1,1L*A[p],0,0,n);
			//printf("%d %d %d\n",L[p],R[p],A[p]);
			p=next[p];
		}
		//puts("");
	}
	printf("%ld",query(0,N+1,0,0,n));
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
ll MOD = 1000000007;
ll INF = 214748364700000000;
double EPS = 1e-12;
double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
   double N;cin >> N;
   vector<double> A(N);
   double sum = 0,av = 0;
   rep(i,N){
       cin >> A[i];
       sum += A[i];
   }
   av = sum / N;
   vector<pair<double,ll>> D(N);
   rep(i,N){
       D[i].first = abs(A[i] - av);
       D[i].second = i;
   }
   sort(ALL(D));
   cout << D[0].second << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	
	int s1,h,m,s2;
	scanf("%d",&s1);
	h = (int)(s1/3600);
	m = (int)((s1%3600)/60);
	s2 = s1-3600*h-m*60;
	printf("%d:%d:%d\n",h,m,s2);
	return 0;
}

Measured memory_bytes: 592
N,K=map(int,input().split())
l=[list(map(int,input().split()))for i in range(N)]
l.sort(key=lambda x: x[0])
ans=0
for i in l:
    if K==0:
        break
    K-=min(K,i[1])
    ans=i[0]
print(ans)

Measured memory_bytes: 28564
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
    int a, b;
    cin >> a >> b;
    if (a == b)
        cout << "Draw\n";
    else if (a == 1 || b != 1 && a > b)
        cout << "Alice\n";
    else
        cout << "Bob\n";

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds; 
using ll = long long int;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order() - 0 indexing
// order_of_key() - number of elements strictly smaller
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
//---------------------------------------GL HF------------------------------------------------------
// -------------------------------------ManavJ07----------------------------------------------------
signed main()
{
	fastio();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	int t=1;
	//cin>>t;
	while(t--)
	{
		ll N;
		cin>>N;
		string s;
		cin>>s;
		ll R=0,W=0;
		for(ll i=0;i<N;i++){
			if(s[i]=='R')
				R++;
			else
				W++;
		}
		ll r=0,w=0;
		ll ans=R;
		for(ll i=1;i<=N;i++){
			if(s[i-1]=='R'){
				r++;
				R--;
			}
			else{
				w++;
				W--;
			}
			ll k=min(w,R);
			ans=min(ans,k+max(w-k,R-k));
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3744
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x) - 1 * 100);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>

using namespace std;
int n, m;



int main(void) {
	ll H, W;
	cin >> H >> W;
	ll dif = 10000000005;
	ll choco[3];
	if (H % 3 == 0 || W % 3 == 3) dif = 0;
	else dif = min(H, W);
	rep(h, H) {
		choco[0] = h*W;
		choco[1] = (H - h)*(W / 2);
		choco[2] = (H - h) * (W - W / 2);
		sort(choco, choco + 3);
		dif = min(choco[2] - choco[0], dif);
	}
	rep(w, W) {
		choco[0] = H*w;
		choco[1] = (W - w)*(H / 2);
		choco[2] = (W - w) * (H - H / 2);
		sort(choco, choco + 3);
		dif = min(choco[2] - choco[0], dif);
	}
	cout << dif << endl;
	return 0;
}

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

using namespace std;

const long long MOD = 1000000007;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);

    int sx, sy, tx, ty;

    cin >> sx >> sy >> tx >> ty;

    for(int i = 0; i < tx - sx; ++i)
        cout << "R";
    for(int i = 0; i < ty - sy; ++i)
        cout << "U";
    for(int i = 0; i < tx - sx; ++i)
        cout << "L";
    for(int i = 0; i < ty - sy; ++i)
        cout << "D";

    cout << "L";

    for(int i = 0; i <= ty - sy; ++i)
        cout << "U";
    for(int i = 0; i <= tx - sx; ++i)
        cout << "R";

    cout << "DR";

    for(int i = 0; i <= ty - sy; ++i)
        cout << "D";
    for(int i = 0; i <= tx - sx; ++i)
        cout << "L";

    cout << "U";

    return 0;
}


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

const int MAX_L = 301;

int T[MAX_L][MAX_L];
pair<int, int> prev[MAX_L][MAX_L];

string LCS(const string &s, const string &t) {
  for(int i = 1; i <= s.size(); ++i) {
    for(int j = 1; j <= t.size(); ++j) {
      int tmp = T[i-1][j-1];
      if(s[i-1] == t[j-1]) ++tmp;
      T[i][j] = max(max(T[i-1][j], T[i][j-1]), tmp);
      if(T[i][j] == T[i-1][j]) {
	prev[i][j] = make_pair(i-1, j);
      } else if(T[i][j] == T[i][j-1]) {
	prev[i][j] = make_pair(i, j-1);
      } else if(T[i][j] == tmp) {
	prev[i][j] = make_pair(i-1, j-1);
      }
    }
  }

  string res = "";
  pair<int, int> p(s.size(), t.size());
  int size = T[s.size()][t.size()];
  while(size) {
    p = prev[p.first][p.second];
    if(size != T[p.first][p.second]) {
      size = T[p.first][p.second];
      res += s[p.first];
    }
  }
  reverse(res.begin(), res.end());
  return res;
}


int main() {
  T[0][0] = 0;
  for(int i = 0; i < MAX_L; ++i) T[i][0] = T[0][i] = 0;

  string str;
  while(getline(cin, str) && str != "#END") {
    string ans = "";
    for(int i = 1; i < str.size(); ++i) {
      string s = str.substr(0, i);
      string t = str.substr(i);
      string res = LCS(s, t);
      if(res.size() > ans.size()) ans = res;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1960
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>

int rank[100005];
int par[100005];

void Init(){
  for (int i=0; i<100005; i++){
    par[i] = i;
    rank[i] = 1;
  }
  return;
}

int GetRoot(int x){
  if (par[x]==x){
    return x;
  } else {
    return GetRoot(par[x]);
  }
}

bool IsSameGroup(int x, int y){
  //printf("root of %d = %d\n",x,GetRoot(x));
  //printf("root of %d = %d\n",y,GetRoot(y));
  if (GetRoot(x) == GetRoot(y)){
    return true;
  } else {
    return false;
  }
}

int GetSize(int x){
  return rank[GetRoot(x)];
}

void Union(int x, int y){
  if (IsSameGroup(x, y)){
    return;
  } else {
    int rootX = GetRoot(x);
    int rootY = GetRoot(y);
    //printf("rootX=%d, rootY=%d\n",rootX, rootY);
    if (rank[rootX]>rank[rootY]){
      par[rootY] = rootX;
      rank[rootX] += rank[rootY];
    } else {
      par[rootX] = rootY;
      rank[rootY] += rank[rootX];
    }
  }
}

int main(){
  int N, M;
  scanf("%d",&N);
  scanf("%d",&M);
  std::vector<int > A(M), B(M);
  for (int i=0; i<M; i++){
    scanf("%d",&A[i]);
    scanf("%d",&B[i]);
  }
  long long ans = (long long)N*(N-1)/2;
  std::stack<long long > stack;
  stack.push(ans);
  Init();
  for (int i=M-1; i>0; i--){
    if (!IsSameGroup(A[i], B[i])){
      ans -= GetSize(A[i])*GetSize(B[i]);
      //printf("GetSize(%d)=%d, GetSize(%d)=%d\n",A[i],GetSize(A[i]),B[i],GetSize(B[i]));
      Union(A[i], B[i]);
    }
    stack.push(ans);
  }
  while(stack.size()){
    printf("%lld\n", stack.top());
    stack.pop();
  }
  return 0;
}


Measured memory_bytes: 3568
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
constexpr ll INF = 1e18;

vector<vector<int>> tree;
vector<int> visited;
vector<int> v;

ll bfs(int i) {
    ll c = 0;
    queue<int> que;
    que.push(i);
    while (!que.empty()) {
        int f = que.front();
        que.pop();
        if (visited[f] == 1) continue;
        visited[f] = 1;
        c++;
        for (auto&& n : tree[f]) {
            if (visited[n]) continue;
            que.push(n);
        }
    }
    return c;
}

int main(void) {
    ll N, M;
    cin >> N >> M;

    tree = vector<vector<int>>(N, vector<int>());
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    for (int i = 0; i < N; i++) {
        sort(all(tree[i]));
        tree[i].erase(unique(all(tree[i])), tree[i].end());
    }

    visited = vector<int>(N, 0);

    ll cmax = 0;
    for (int i = 0; i < N; i++) {
        ll c;
        if (visited[i] == 0) {
            c = bfs(i);
        }
        cmax = max(c, cmax);
    }
    cout << cmax << endl;

    return 0;
}



Measured memory_bytes: 15060
def read_input():
    n, l = map(int, input().split())

    slist = []
    for i in range(n):
        slist.append(input().strip())

    return n, l, slist

if __name__ == '__main__':
    n, l, slist = read_input()

    slist.sort()
    print(''.join(slist))

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

using namespace std;

int main() {
    string str;
    cin >> str;
    int ans = 0;
    for(size_t i = 1; i<str.size(); ++i) if( str[i] != str[i-1] )
        ++ans;
    printf("%d\n", ans);
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int W, H;
  cin >> H >> W;
  cout << string(W+2,'#') << endl;
  REP(y,H){
	string s;
	cin >> s;
	cout << "#" << s << "#" << endl;
  }
  cout << string(W+2,'#') << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import Counter


def inverse_lookup(d: dict, x):
    for k, v in d.items():

        if v == x:
            return k

    # if x is not found
    return None


def num_of_nth_often(lst, nth):
    counter = Counter(lst)
    counted_list = sorted(list(counter.values()), reverse=True)

    if len(counted_list) < nth:
        return 0, None

    else:
        return counted_list[nth - 1], inverse_lookup(counter, counted_list[nth - 1])

n = int(input())
v = list(map(int, input().split()))

v_even = []
v_odd = []

for i in range(n):
    if i % 2 == 0:
        v_even.append(v[i])
    else:
        v_odd.append(v[i])

e1 = num_of_nth_often(v_even, 1)
e2 = num_of_nth_often(v_even, 2)
o1 = num_of_nth_often(v_odd, 1)
o2 = num_of_nth_often(v_odd, 2)

if e1[1] != o1[1]:
    rewrite_num = len(v_even) - e1[0] + len(v_odd) - o1[0]
    print(rewrite_num)
else:
    rewrite_num1 = len(v_even) - e1[0] + len(v_odd) - o2[0]
    rewrite_num2 = len(v_even) - e2[0] + len(v_odd) - o1[0]
    print(min(rewrite_num1, rewrite_num2))


Measured memory_bytes: 21344
#include <iostream>
#include<stdio.h>
#include<math.h>
#define ll long long
using namespace std;

int main()
{
    ll l,d,a,b,c,e,x,y,z1,z2,z3,z4,z;
    scanf("%lld%lld",&l,&d);
    a = l/3;
    b = l/3 +1;
    c = d/2;
    e = d-c;
    x = a*d>(l-a)*e?a*d:(l-a)*e;
    y = a*d<(l-a)*c?a*d:(l-a)*c;
    z1 = x-y;
    x = b*d>(l-b)*e?b*d:(l-b)*e;
    y = b*d<(l-b)*c?b*d:(l-b)*c;
    z1 = z1<x-y?z1:x-y;
    a = d/3;
    b = d/3 +1;
    c = l/2;
    e = l-c;
    x = a*l>(d-a)*e?a*l:(d-a)*e;
    y = a*l<(d-a)*c?a*l:(d-a)*c;
    z2 = x-y;
    x = b*l>(d-b)*e?b*l:(d-b)*e;
    y = b*l<(d-b)*c?b*l:(d-b)*c;
    z2 = z2<x-y?z2:x-y;
    a = d/3;
    b = d/3+1;
    c = (d-a)/2;
    e = (d-b)/2;
    x = a>d-a-c?a:d-a-c;
    y = a<c?a:c;
    z3 = x-y;
    x = b>d-b-e?b:d-b-e;
    y = b<e?b:e;
    z3 = (z3<x-y?z3:x-y)*l;
    a = l/3;
    b = l/3+1;
    c = (l-a)/2;
    e = (l-b)/2;
    x = a>l-a-c?a:l-a-c;
    y = a<c?a:c;
    z4 = x-y;
    x = b>l-b-e?b:l-b-e;
    y = b<e?b:e;
    z4 = (z4<x-y?z4:x-y)*d;
    if(z1<z2) z = z1;
    else z = z2;
    if(z3<z) z = z3;
    if(z4<z) z = z4;
    printf("%lld",z);
    return 0;
}


Measured memory_bytes: 256
//TwoSwitches.cpp (B)
#include <iostream>
using namespace std;

int main(){
  int A,B,C,D,Ans;
  cin >> A >> B >> C >> D;
  if(A <= C && D <= B) Ans = D - C;
  else if(A <= C && C <= B) Ans = B - C;
  else if(A <= D && D <= B) Ans = D - A;
  else if(C <= A && B <= D) Ans = B - A;
  else Ans = 0;
  printf("%d\n", Ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
 
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using ll = long long;
using ld = long double;
 
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
const int L = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = (1LL << 61);
 
int h, n, x, s;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    cin >> h >> n;
    while (n--) {
        cin >> x;
        s += x;
    }
    
    cout << (s >= h ? "Yes" : "No");
 
    return 0;
}
 
/// ACTUAL CODE STARTS HERE:
/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <list>
#include <map>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
#define rep(i,n) for(register int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f;
const int dx[]={0,1,-1,0},dy[]={1,0,0,-1};
//const int MOD=998244353;
//const int N=2e5+10;

inline int read(){
	int ww=1,xx=0;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-') ww=-ww;ch=getchar();}
	while(isdigit(ch)){xx=(xx<<1)+(xx<<3)+(ch^48);ch=getchar();}
	return ww*xx;
}

string s,t;
int ans;

signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>s>>t;
	if(s[0]==t[0]) ans++;
	if(s[1]==t[1]) ans++;
	if(s[2]==t[2]) ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <cmath>
using namespace std;


int main(){
  string s;
  cin >> s;
  int64_t numArray[s.length()];
  int64_t sNum;
  int64_t length = s.length();
  int64_t pl, pr;
  int64_t sum = 0;
  int64_t p;
  for(int64_t i = 0; i <length ; i++){
    sNum = (int64_t)(s[i]-'0');
    //cout << i << endl;
    for(int64_t j = 0; j < length-i; j++){
      
      pl = i  >=0 ? i : 0;
      pr = length -(i+j + 2) >= 0 ? length -(i+j + 2) : 0;
      int64_t add = sNum*pow(10, j)*pow(2, pl + pr);
      sum += add;
      //cout << sNum*pow(10, j) << " " << pl << " " << pr << " " << pl + pr<< " " << add <<endl;
    }
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
const int N=500005;
int n,l[N],r[N],x,y;
vector<pair<int,int> >A;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x,&y);
		A.push_back(make_pair(x,y));
	}
	sort(A.begin(),A.end());
	int ans=0;
	r[n-1]=A[n-1].se;l[0]=A[0].se;
	for (int i=1;i<n;i++)l[i]=min(l[i-1],A[i].se);
	for (int i=n-2;i>=0;i--)r[i]=min(r[i+1],A[i].se);
	for (int i=1;i<n;i++){
		int Z=i==1?1e9:l[i-2],X=A[i-1].se,Y=r[i];
		ans=max(ans,max(0,min(X,Z)-A[i-1].fi+1)+max(0,Y-A[n-1].fi+1));
		ans=max(ans,max(0,X-A[i-1].fi+1)+max(0,min(Y,Z)-A[n-1].fi+1));
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

void	calc_par(const Graph &graph, vector<int> &par_vec, int u)
{
	for (int v : graph.at(u)) {
		if (v == par_vec.at(u))
			continue;
		par_vec.at(v) = u;
		calc_par(graph, par_vec, v);
	}
}

void	add_cnt(const Graph &graph, const vector<int> &par_vec,
			vector<int> &cnt_vec, int u, const vector<int> &Q_vec)
{
	cnt_vec.at(u) += Q_vec.at(u);
	for (int v : graph.at(u)) {
		if (v == par_vec.at(u))
			continue;
		cnt_vec.at(v) += cnt_vec.at(u);
		add_cnt(graph, par_vec, cnt_vec, v, Q_vec);
	}
}

int	main()
{
	int	N, Q;
	cin >> N >> Q;
	int	a, b;
	Graph	graph(N);
	for (int i = 0; i < N - 1; ++i) {
		cin >> a >> b;
		--a; --b;
		graph.at(a).push_back(b);
		graph.at(b).push_back(a);
	}
	vector<int>	par_vec(N, -1);
	calc_par(graph, par_vec, 0);
	int	p, x;
	vector<int>	Q_vec(N, 0);
	vector<int>	cnt_vec(N, 0);
	for (int i = 0; i < Q; ++i) {
		cin >> p >> x;
		--p;
		Q_vec.at(p) += x;
	}
	add_cnt(graph, par_vec, cnt_vec, 0, Q_vec);
	for (int i = 0; i < N - 1; ++i)
		cout << cnt_vec.at(i) << " ";
	cout << cnt_vec.at(N - 1) << endl;
}


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

int main(){
int n;
int count=0;
cin>>n;
rep(i,n){
if(i<100000&&i>=10000){
count++;
}else if(i<10000&&i>=1000){

}else if(i<1000&&i>=100){
    count++;
}else if(i<100&&i>=10){
    
}else if(i<10){
    count++;
}

}
cout<<count;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>

using namespace std;

int main() {
	int K;
	string S;
	cin >> K >> S;

	if (S.size() <= K) {
		cout << S;
	} else {
		cout << S.substr(0, K) + "...";
	}
	cin >> K;
	return 0;
}

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

#define endl "\n"
#define si(a) scanf("%d ",&a);
#define si2(a,b) scanf("%d %d ",&a,&b);
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sll(a) scanf("%lld ",&a);
#define sll2(a,b) scanf("%lld%lld",&a,&b)
#define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define sf(a) scanf("%f ",&a);
#define sd(a) scanf("%lf ",&a);
#define sc(a) scanf("%c ",&a);
#define ss(a) scanf("%s ",a);
#define sf2(a,b) scanf("%f %f ",&a,&b);
#define sd2(a,b) scanf("%lf %lf ",&a,&b);
#define mp(a,b) make_pair(a,b)
#define pb(x) push_back(x)
#define all(a) a.begin(),a.end()
#define forn(i,n) for(int i=0;i<n;i++)
#define forq(i,q,n) for(int i=q;i<n;i++)
#define form(i,n) for(int i=n;i>=0;i--)
#define forp(i,q,n) for(int i=q;i>=n;i--)
#define fi first
#define se second
#define INF 1000000010
#define MOD 1000000007
#define MAXN
#define LL long long int


using namespace std;

string s;

void init(){
	cin >> s;
	int l = s.size();
	//printf("%d\n", l);
	int L = l - 2;
	printf("%c", s[0]);
	printf("%d", L);
	printf("%c\n", s[l - 1]);
}

int main(){
	#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	init();
	return 0;
}


Measured memory_bytes: 256
inf = 1000000007

def check(roar,i):
    if roar[i]!='m':return inf
    i+=1
    if roar[i]=='e':i+=1
    else :
        j = check(roar,i)
        if j==inf:return inf
        i = j+1
    if roar[i]=='w':i+=1
    else :
        j = check(roar,i)
        if j==inf:return inf
        i = j+1
    return i



def main():
    roar = input()
    if check(roar,0)==len(roar):print ('Cat')
    else                       :print ('Rabbit')


if __name__ == '__main__':
    main()




Measured memory_bytes: 5580
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
string s;
ll dp[100005][15];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> s;
  int l = s.length();

  dp[0][0] = 1;

  REP(i, l) {
    int c;
    if(s[i] == '?') c = -1;
    else c = s[i] - '0';

    REP(j, 10) {
      if(c != -1 && c != j) continue;
      REP(k, 13) {
        dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
      }
    }
    REP(j, 13) dp[i + 1][j] = dp[i + 1][j] % mod;
  }

  cout << dp[l][5] << endl;
}


Measured memory_bytes: 12240
#include <iostream>
#include <queue>

#define MAX_W 1000
#define MAX_H 1000
#define MAX_N 1000
#define INF -1

typedef std::pair<int, int> P;

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

int w, h, n;
int sx, sy, gx[MAX_N], gy[MAX_N];
char field[MAX_W][MAX_H];

int solve(int _sx, int _sy, int _gx, int _gy);

int main(){
    std::cin >> h >> w >> n;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            std::cin >> field[j][i];
            if(field[j][i] == 'S')
                sx = j, sy = i;
            
            else if(field[j][i] >= '0' && field[j][i] <= '9')
                gx[field[j][i] - '0'] = j, gy[field[j][i] - '0'] = i;
        }
    }
    
    int ans = 0;
    
    for(int i = 0; i < n; ++i){
        if(i == 0)
            ans += solve(sx, sy, gx[i + 1], gy[i + 1]);
        else
            ans += solve(gx[i], gy[i], gx[i + 1], gy[i + 1]);
    }
    
    std::cout << ans << std::endl;
    
    return 0;
}

int solve(int _sx, int _sy, int _gx, int _gy){
    int dis[MAX_W][MAX_H];
    std::queue<P> que;
    que.push(P(_sx, _sy));
    
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j)
            dis[j][i] = INF;
    }
    
    dis[_sx][_sy] = 0;
    
    while(que.size()){
        P p = que.front();
        que.pop();
        
        if(p.first == _gx && p.second == _gy)
            break;
        
        for(int i = 0; i < 4; ++i){
            int nx = p.first + dx[i], ny = p.second + dy[i];
            
            if(nx >= 0 && ny >= 0 && nx < w && ny < h && field[nx][ny] != 'X' && dis[nx][ny] == INF){
                que.push(P(nx, ny));
                dis[nx][ny] = dis[p.first][p.second] + 1;
            }
        }
    }
    
    return dis[_gx][_gy];
}

Measured memory_bytes: 6104
#include <atcoder/twosat>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

int main() {
    int N, D;
    scanf("%d %d", &N, &D);
    vector<ll> X(N), Y(N);
    for (int i = 0; i < N; i++) scanf("%lld %lld", &X[i], &Y[i]);
    atcoder::two_sat ts(N);
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            if (abs(X[i]-X[j]) < D) ts.add_clause(i, false, j, false);
            if (abs(X[i]-Y[j]) < D) ts.add_clause(i, false, j, true);
            if (abs(Y[i]-X[j]) < D) ts.add_clause(i, true, j, false);
            if (abs(Y[i]-Y[j]) < D) ts.add_clause(i, true, j, true);
        }
    }
    if (ts.satisfiable()) {
        printf("Yes\n");
        vector<bool> answer = ts.answer();
        for (int i = 0; i < N; i++) {
            printf("%lld\n", (answer[i] ? X[i] : Y[i]));
        }
    }else{
        printf("No\n");
    }
}


Measured memory_bytes: 3872
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;



int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    rep(i,n) {
        cout << s[i] << t[i];
    }
    cout << endl;

    return 0;
}


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

const ll MOD = 1000000007;

ll mod_add(ll a, ll b){
    return ((a % MOD) + (b % MOD)) % MOD;
}

ll mod_sub(ll a, ll b){
    return ((a + MOD) - b) % MOD;
}
 
ll mod_mul(ll a, ll b){
    return ((a % MOD) * (b % MOD)) % MOD;
}

ll mod_pow(ll x, ll r){
    if (r == 0) return 1;

    else if (r == 1) return x % MOD;

    else if (r % 2 == 0){
        ll t = mod_pow(x, r/2) % MOD;
        return mod_mul(t, t);
    }

    else{
        ll t = mod_pow(x, r/2) % MOD;
        ll k = mod_mul(t, t);
        return ((k % MOD) * (x % MOD)) % MOD;
    }
}

ll mod_div(ll a, ll b){
    return mod_mul(a, mod_pow(b, MOD - 2));
}

ll mod_fac(ll n){
    ll ret = 1;
    for(ll i = 1; i <= n; ++i){
        ret = (ret*i) % MOD;
    }
    return ret;
}

ll mod_comb(ll n, ll k){
    ll numerator = 1;
    for(ll i = 0; i < k; ++i){
        numerator = numerator*(n-i) % MOD;
    }
    ll denominator = mod_fac(k);
    return mod_div(numerator, denominator);
}

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

    ll n;
    cin >> n;

    if(n==1){
        cout << 0 << endl;
        return 0;
    }
    if(n==2){
        cout << 2 << endl;
        return 0;
    }

    cout << mod_add(mod_sub(mod_pow(10, n), mod_mul(mod_pow(9, n), 2)), mod_pow(8, n)) << endl;

    return 0;
}

Measured memory_bytes: 3652
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var x = long.Parse(input.ReadLine());

        var dic = new Dictionary<long, long>();
        long ra=0;
        long rb=0;

        long z = 6000;

        for(long i=-z; i<z; i++) {
            var a = i;
            var a5 = (long)Math.Pow(a, 5);

            dic.Add(a5, a);
            var b5 = a5 - x;

            if (dic.ContainsKey(b5)) {
                ra = a;
                rb = dic[b5];
                break;
            }
        }

        return ra + " " + rb;
    }

    //static long Pow(long x, long n) {
    //    long ans = 1;
    //    while (n > 0) {
    //        if (n % 2 == 1) {
    //            ans = ans * x;
    //        }
    //        x = x * x;
    //        n /= 2;
    //    }
    //    return ans;
    //}
}


Measured memory_bytes: 28620
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3,typename T4> inline void print4(T1 a, T2 b, T3 c, T4 d){
	cout << a << " " << b << " " << c << " " << d << endl;
}
const int mod = 1e9 + 7;

int main(){
	ll n,k; cin >> n >> k;
	if(n<=k){
		cout << min(n,k-n) << endl;
	}else{
		ll ans = n;
		n -= n / k * k;
		chmin(ans,min(n,k-n));
		cout << ans << endl;
	}
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n; cin >> n;
    V<int> p(n), q(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 0; i < n; i++) cin >> q[i];

    V<int> nums(n);
    iota(ALL(nums), 1);
    sort(ALL(nums));
    int cnt = 0;
    int a = 0, b = 0;
    do {
        int pc = 0, qc = 0;
        for(int i = 0; i < n; i++){
            if(p[i] == nums[i]) pc++;
            if(q[i] == nums[i]) qc++;
        }
        if(pc == n) a = cnt;
        if(qc == n) b = cnt;
        cnt++;
    } while(next_permutation(nums.begin(), nums.end()));

    a++;
    b++;
    cout << abs(a - b) << endl;


    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<sstream>
#include<string>

using namespace std;

string IntToString(int n){
  stringstream ss;
  ss << n;
  return ss.str();
}

bool Check(int n){
  const string str = IntToString(n);
  for(int i=0, j=str.size()-1; i < j; ++i, --j){
    if(str[i] != str[j]) return false;
  }
  return true;
}

int GetMax(int n){
  while(1){
    if(Check(n)) return n;
    ++n;
  }
}

int GetMin(int n){
  while(1){
    if(Check(n)) return n;
    --n;
  }
}

int main(){
  int n, max, min;
  cin >> n;

  max = GetMax(n);
  min = GetMin(n);

  if(n-min <= max-n) cout << min << endl;
  else cout << max << endl;

  return 0;
}

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

#define FasterIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main(){
    FasterIO;

    string n;

    while(cin>>n){
        int cnt = 0;

        if(n[0]=='2')
            cnt++;
        if(n[1]=='2')
            cnt++;
        if(n[2]=='2')
            cnt++;
        if(n[3]=='2')
            cnt++;

        cout<<cnt<<endl;
    }

    return 0;
}



Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))

ans = [a[0]]

for i in range(1, n):
    t = [0,0,0]
    for j in range(3):
        t[j] = max([ans[i-1][k] + a[i][j] if k != j else 0 for k in range(3)])
    ans.append(t)
    #print(ans)
print(max(ans[n-1]))

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

int main()
{
    //freopen("output.txt","w",stdout);

    ll n,k;
   // cout<<7%4;
    cin>>n>>k;
    if(k==1)
    {
        cout<<0<<endl;
        return 0;
    }

    ll ans=min(k-(n%k),n%k);
    cout<<ans<<endl;
}



Measured memory_bytes: 384
import java.io.*;
import  java.util.*;

import static java.lang.System.in;

class Main{
    public static void main(String[] args)throws IOException{
        //Scanner sc = new Scanner(System.in);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String[] buf;
        buf = reader.readLine().split(" ");
        int H = Integer.parseInt(buf[0]), W = Integer.parseInt(buf[1]), D = Integer.parseInt(buf[2]);
        TreeMap<Integer,int[]> tm = new TreeMap<>();
        for(int i=1;i<=H;i++){
            buf = reader.readLine().split(" ");
            for(int j=0;j<W;j++){
                int[] now = new int[]{i,j+1};
                int key = Integer.parseInt(buf[j]);
                tm.put(key,now);
            }
        }
        ArrayList<Integer>[] dic = new ArrayList[D]; // to record prefix sum
        for(int i=0;i<D;i++) dic[i]=new ArrayList<>();
        int[][] rec = new int[D][];
        while(tm.size()>0){
            int key = tm.firstKey();
            int[] now = tm.get(key);
            tm.remove(key);
            int j=key%D;
            if(dic[j].size()==0){
                dic[j].add(0);
                rec[j] = now;
            }else{
                int last = dic[j].get(dic[j].size()-1);
                int cur = Math.abs(rec[j][0]-now[0])+Math.abs(rec[j][1]-now[1]);
                dic[j].add(last+cur);
                rec[j] = now;
            }
        }
        PrintWriter out = new PrintWriter((System.out));
        buf = reader.readLine().split(" ");
        int q = Integer.parseInt(buf[0]);
        for(int i=0;i<q;i++){
            buf = reader.readLine().split(" ");
            int L = Integer.parseInt(buf[0]), R = Integer.parseInt(buf[1]);
            if(R==L){
                out.println(0);
                continue;
            }
            int key = L%D;
            out.println(dic[key].get((R-1)/D)-dic[key].get((L-1)/D));
        }
        out.flush();
    }
}


Measured memory_bytes: 70636
LARGE = 10 ** 9 + 7

def prime_factorize_dict(N):
    d = dict()
    for n in range(1, N + 1):
        while not n & 1:
            d[2] = d.get(2, 0) + 1
            n >>= 1
        f = 3
        while f * f <= n:
            if not n % f:
                d[f] = d.get(f, 0) + 1
                n //= f
            else:
                f += 2
        if n != 1:
            d[n] = d.get(n, 0) + 1
    return d

N = int(input())
total = 1
for p in prime_factorize_dict(N).values():
    total *= (p + 1)

print(total % LARGE)


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

int main() {
	int n, k; cin >> n >> k;
	string s; cin >> s;

	int ret = 0;
	for (int i = 1; i < n; i++)if (s[i] == s[i - 1]) {
		ret++;
	}
	cout << min(ret + 2 * k, n - 1) << endl;

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9 + 7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};



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


  vector<int>v;
  vector<int>p(1000010); 

  for(int i=2;i*i<=1000009;i++)
  {
     if(!p[i])
     {
       for(int j=i*i;j<=1000009;j+=i)
       {
         p[j]=1;
       }
     }
  }

  v.push_back(2);

  for(int i=3;i<=1000009;i+=2)
  {
    if(!p[i])
    {
      v.push_back(i);
    }
  }

  int x;
  cin>>x;
  int k=lower_bound(v.begin(),v.end(),x)-v.begin();
  cout<<v[k]<<"\n";

}

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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define pb push_back

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

#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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

const int MOD = 1000000007;

const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

using Graph = vector<vector<int>>;

Graph G;

vector<bool> seen;
void dfs(const Graph &G, int v)
{
    seen[v] = true;

    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        dfs(G, next_v);
    }
}

int main()
{
    ll n;
    cin >> n;
    ll a[110000][3];
    rep(i, 0, n) rep(j, 0, 3) cin >> a[i][j];

    ll dp[110000][3];

    rep(i, 0, n)
    {
        rep(j, 0, 3)
        {
            rep(k, 0, 3)
            {
                if (j == k)
                {
                    continue;
                }
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    ll res = 0;
    rep(i, 0, 3)
    {
        chmax(res, dp[n][i]);
    }
    cout << res << endl;
}

Measured memory_bytes: 5248
# AtCoder
from collections import defaultdict
N = int(input())
lst = [int(i) for i in input().split()]

d = defaultdict(int)
for i, v in enumerate(lst, start=1):
    d[i] = v

d2 = sorted(d.items(), key=lambda x: x[1])

ans = []
for k, v in d2:
    ans.append(k)
print(*ans)


Measured memory_bytes: 27356
import itertools

N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]

ans = float('inf')
for Lp in itertools.permutations(L):
    Lac = tuple(itertools.accumulate(([0] + list(Lp))))
    for a in range(1, N - 1):
        for b in range(a + 1, N):
            for c in range(b + 1, N + 1):
                A_MP = 10 * (a - 1) + abs(Lac[a] - Lac[0] - A)
                B_MP = 10 * (b - a - 1) + abs(Lac[b] - Lac[a] - B)
                C_MP = 10 * (c - b - 1) + abs(Lac[c] - Lac[b] - C)
                ans = min(ans, A_MP + B_MP + C_MP)
print(ans)


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

#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX_N 110

int n,time,head,tail;
int *queue;
int *dist;
int *color;
int **matrix;

void enqueue(int);
int dequeue(void);
void bfs(void);

int main(){
  int i,j,u,k,v;

  scanf("%d",&n);

  queue = malloc(MAX_N * sizeof(int));
  color = malloc(n * sizeof(int));
  dist = malloc(n * sizeof(int));

  matrix = malloc(n * sizeof(int *));
  for(i = 0 ; i < n ; i++){
    matrix[i] = malloc(n * sizeof(int));
 }
 for(i = 0 ; i < n ; i++){
   dist[i] = -1;
 }
 for(i = 0 ; i < n ; i++){
   for(j = 0 ; j < n ; j++){
     matrix[i][j] = 0;
   }
 }

 for(i = 0 ; i < n ; i++){
    scanf("%d",&u); u--;
    scanf("%d",&k);
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v); v--;
      matrix[u][v] = 1;
    }
  }

  bfs();
  for(i = 0 ; i < n ; i++){
    printf("%d %d\n",i+1,dist[i]);
  }

  for(i = 0 ; i < n ; i++){
    free(matrix[i]);
  }
  free(matrix);
  free(queue);
  free(dist);
  free(color);
  return 0;
}

void bfs(){
  int u,i;

  head = tail = 0;
  color[0] = GRAY;
  dist[0] = 0;
  enqueue(0);

  while(head != tail){
    u = dequeue();
    for(i = 0 ; i < n ; i++){
      if(matrix[u][i] == 1 && color[i] == WHITE){
        color[i] = GRAY;
        dist[i] = dist[u] + 1;
        enqueue(i);
      }
    }
    color[u] = BLACK;
  }
}

void enqueue(int q){
  queue[tail%MAX_N] = q;
  tail++;
}

int dequeue(){
  int v = queue[head%MAX_N];
  head++;
  return v;
}

Measured memory_bytes: 636
#include<iostream>
#define INF 99999999
using namespace std;
int h,w,t[30][30],u[30][30][4],v[30][30][4];
int ny,nx,nz,y,x,z,mini;
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
int cost[4];

void input();
void init();
int compute();
int check(int,int);
int co(int);
int main(){
  while(1){
    cin>>w>>h;
    if(w==0&&h==0)break;
    input();
    init();
    cout<<compute()<<endl; 
  }
  return 0;
}
void input(){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>t[i][j];
    }
  }  
}
void init(){
  for(int i=0;i<30;i++){
    for(int j=0;j<30;j++){
      for(int k=0;k<4;k++){
	u[i][j][k]=INF;
	v[i][j][k]=0;
      }
    }
  }
  for(int i=0;i<4;i++)cin>>cost[i];
}

int compute(){
  u[0][0][1]=0;
  while(1){
    mini=INF;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	for(int k=0;k<4;k++){
	  if(u[i][j][k]<mini&&v[i][j][k]==0){
	    mini=u[i][j][k];
	    y=i;x=j;z=k;
	  }
	}//k
      }//j
    }//i
    
    //cout<<y<<' '<<x<<' '<<z<<' '<<u[y][x][z]<<endl;
    //cout<<u[1][7][2]<<endl;
    if(mini==INF)break;
    v[y][x][z]=1;

    for(int i=0;i<4;i++){
      nz=(z+i)%4;
      nx=x+dx[nz];
      ny=y+dy[nz];
      if(!check(ny,nx))continue;
      if(u[ny][nx][nz]>u[y][x][z]+cost[i]){
	u[ny][nx][nz]=u[y][x][z]+cost[i];
      }
    }
    
    if(t[y][x]==4){
    }else{
      nz=(z+t[y][x])%4;
      nx=x+dx[nz];
      ny=y+dy[nz];
      if(!check(ny,nx))continue;
      if(u[ny][nx][nz]>u[y][x][z]){
	//cout<<u[y][x][z]<<endl;
	u[ny][nx][nz]=u[y][x][z];
      }
    }
  }
  mini=INF;
  for(int i=0;i<4;i++){
    if(mini>u[h-1][w-1][i]){
      mini=u[h-1][w-1][i];
    }
  }
  /*
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int k=0;k<4;k++){
	if(u[i][j][k]!=INF){
	  cout<<i<<' '<<j<<' '<<k<<endl;
	  cout<<u[i][j][k]<<endl;
	}
      }//k
    }//j
  }//i
  */

  return mini;
}
int check(int y,int x){
  if(0<=y&&y<h&&0<=x&&x<w)return 1;
  else return 0;
}

Measured memory_bytes: 1192