akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
typedef long long ll;
ll n,N = 1000020,bit[1000010],a[500010],b[500010],c[2][500010],d[2][500010];
ll mod = 1000000007,f[500010],ans = 0;
bool used[500010];
vector<pair<ll,ll>> v;
vector<ll> w;
ll sum(int i){
	ll s = 0;
	while(i>=0){
		s += bit[i];
		i = (i&(i+1)) - 1;
	}
	return s;
}

ll add(int i, int x){
	while(i<=N){
		bit[i] += x;
		i |= i+1;
	}
}

void rev1(){
	int i,j = 0;
	for(i=1;i<=n;i++){
		if(used[i]) b[i] = j;
		j++;
	}
	for(i=(int)v.size()-1;i>=0;i--){
		(ans += f[n - v[i].first]*(sum(b[v[i].second]))) %= mod;
		add(b[v[i].second],1);
	}
	(ans *= (f[w.size()])) %= mod;
}

void rev2(){
	ll i,k = w.size();
	ll inv = (mod + 1)/2;
	for(i=0;i<w.size();i++){
		(ans += f[n - w[i]]*f[k]%mod*(k - 1 - i)%mod*inv) %= mod;
	}
}

void rev3(){
	for(int i=1;i<=n;i++){
		if(a[i]) (ans += (d[0][a[i]]*c[0][i] + d[1][a[i]]*c[1][i]%mod*f[n-i])%mod*f[w.size()-1]%mod) %= mod;
	}
}

int main(){
	ll i,cnt1 = 0,cnt2 = 0,cnt3 = 0,sum = 0;
	cin >> n;
	for(i=1;i<=n;i++) used[i] = false;
	f[0] = 1;
	for(i=1;i<=n;i++){
		cin >> a[i];
		if(a[i]){
			v.push_back({i,a[i]});
			used[a[i]] = true;
		}else{
			w.push_back(i); cnt1++;
		}
		f[i] = f[i-1]*i%mod;
	}
	for(i=1;i<=n;i++){
		if(a[i]){
			c[0][i] = sum;
			c[1][i] = cnt1 - cnt2;
		}else{
			cnt2++; (sum += f[n - i]) %= mod;
		}
	}
	for(i=1;i<=n;i++){
		if(used[i]) d[1][i] = cnt3;
		else cnt3++;
	}
	cnt3 = 0;
	for(i=n;i>=1;i--){
		if(used[i]) d[0][i] = cnt3;
		else cnt3++;
	}
	rev1(); rev2(); rev3();
	(ans += f[w.size()]) %= mod;
	cout << ans << endl;
}

Measured memory_bytes: 43496
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		int X = Integer.parseInt(W.split(" ")[0]);

		int fiveHundredYen = 0;
		int fiveYen = 0;

		fiveHundredYen = X / 500;
		fiveYen = (X - fiveHundredYen * 500) / 5;

		System.out.println(fiveHundredYen * 1000 + fiveYen * 5);

	}

}


Measured memory_bytes: 22356
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

string S;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  const string day[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  cin >> S;
  cin >> S;

  int ans = 0;
  for (int i = 0; i < 7; i++) {
    if (day[i] == S) {
      ans = 7 - (i);
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll Nagaemon1;
void swap(ll i,ll j){
  Nagaemon1=i;
  i=j;
  j=Nagaemon1;
}
int main(){
  ll n,m;
  cin >> n >> m;
  cout << (1900*m+100*(n-m))*pow(2,m) << endl;
}

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

int main() {

	vector<int> v(3);
	int num = 0;

	cin >> v[0] >> v[1] >> v[2];

	while (1) {
		sort(v.begin(), v.end());
		if ((v[0] == v[1]) && (v[1] == v[2])) break;
		else if (v[0] != v[1]) v[0] += 2, ++num;
		else if (v[0] == v[1]) ++v[0], ++v[1], ++num;
	}
	cout << num<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.valueOf(sc.next());

		int v[] = new int[n];
		for (int i = 0; i < v.length; i++) {
			v[i] = Integer.valueOf(sc.next());
		}
		int a = 0;
		for (int i = 0; i < v.length; i++) {
			int c = Integer.valueOf(sc.next());
			if (c < v[i]) {
				a = a + v[i] - c;
			}
		}
		System.out.println(a);
	}

}


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

using namespace std;

long long MOD=1000000007;
long long D[101][100001], S=0, Su=0;
vector <pair<long long, long long>> V;

int main()
{
    int n, k, a;
    cin >> n >> k;
    D[1][0] = 0;
    for (int i = 1; i <= sqrt(n); i++)
    {
        V.push_back({i, 1});
    }
    a = sqrt(n);
    for (int i = ceil(sqrt(n))-1; i >= 1; i--)
    {
        if (i == a && n / a == a)
            continue;
        V.push_back({i, n/i - n/(i+1)});
    }
    for (int i = 1; i <= V.size(); i++)
    {
        D[1][i] = V[i-1].second;
    }
    for (int i = 2; i <= k; i++)
    {
        D[i][0] = 0;
        S = 0;
        for (int y = V.size(); y >= 1; y--)
        {
            S += D[i-1][V.size()-y+1];
            S %= MOD;
            D[i][y] = S*V[y-1].second;
            D[i][y] %= MOD;
            if (i == k)
            {
                Su += D[i][y];
                Su %= MOD;
            }
        }
    }
    cout << Su;
    return 0;
}


Measured memory_bytes: 78580
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
ll pow_mod(ll fi,ll se,ll mod){
  if(se==0){
    return 1;
  }
  if(se%2){
    return pow_mod(fi,se-1,mod)*fi%mod;
  }
  ll t=pow_mod(fi,se/2,mod);
  return t*t%mod;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}

vector<pair<int,int>> Dir={{-1,0},{1,0},{0,1},{0,-1}};
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/


int main(){
  ll n;
  cin>>n;
  vec(a,n);
  rep(i,n){
    cin>>a[i];
    a[i]--;
  }
  ll ans=0;
  rep(i,n){
    if(a[i]==i){
      for(int j=0;;j++){
        if(a[i+j]!=i+j){
          ans+=((j-1)/2+1);
          j--;
          i+=j;
          break;
        }
      }
    }
  }
  op(ans);
  return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            var nxy = Console.ReadLine().Split(' ');
            var n = int.Parse(nxy[0]);
            var x = int.Parse(nxy[1]);
            var y = int.Parse(nxy[2]);
            var count = new int[n - 1];
            for(int i = 1; i < n; i++)
            {
                for(int j = i + 1; j < n + 1; j++)
                {
                    count[Min3(Math.Abs(i - j), Math.Abs(i - x) + 1 + Math.Abs(y - j), Math.Abs(i - y) + 1 + Math.Abs(j - x)) - 1]++;
                }
            }
            foreach(int num in count)
            {
                Console.WriteLine(num);
            }

            Console.ReadKey();
        }

        static public int Min3(int a,int b,int c)
        {
            int min = int.MaxValue;
            min = Math.Min(a, b);
            min = Math.Min(min, c);
            return min;
        }
    }
}

Measured memory_bytes: 13252
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;

template<typename T>bool chkmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool chkmin(T &a,T b){return (a>b)?a=b,1:0;}

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
int n;
char s[1000005];
int sum[1000005];
int dp[1000005];
int nxt[10];
const int mod=1e9+7;
int main () {
#ifndef ONLINE_JUDGE
//file("agc27e");
#endif
    scanf("%s",s+1);
	n=strlen(s+1);
	F(i,1,n)sum[i]=(sum[i-1]+s[i]-'a'+1)%3;
	dp[n]=1;
	bool flag=0;
	F(i,1,n-1)if(s[i]==s[i+1])flag=1;
	if(!flag){
	  puts("1");
	  return 0;
	}
	F(i,0,2)nxt[i]=i==sum[n]?n:n+1;
	f(i,n-1,1){
	  dp[i]=sum[i]==sum[n];
	  F(j,1,2){
	     dp[i]=(dp[i]+dp[nxt[(sum[i]+j)%3]])%mod;
	  }
	  nxt[sum[i]]=i;
	}
    printf("%d\n",(dp[nxt[1]]+dp[nxt[2]])%mod);
    return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define N 110000
const int inf=1e9;
int n,tot,m,cnt,top;
int head[N],nex[N<<1],to[N<<1];
int fa[N][21],deep[N];
int val[N],L[N],R[N],pos[N],a[N],st[N],sig[N];
vector<int>vec[N];
void quit(){puts("No");exit(0);}
void add(int x,int y)
{
	tot++;
	nex[tot]=head[x];head[x]=tot;
	to[tot]=y;
}
void dfs(int x,int y)
{
	fa[x][0]=y;
	for(int i=1;i<=20;i++)
		fa[x][i]=fa[fa[x][i-1]][i-1];
	deep[x]=deep[y]+1;
	pos[x]=++cnt;
	for(int i=head[x];i;i=nex[i])
		if(to[i]!=y)
			dfs(to[i],x);
}
int cmp(int x,int y){return pos[x]<pos[y];}
int lca(int x,int y)
{
	if(deep[x]<deep[y])swap(x,y);
	for(int i=20;i>=0;i--)
		if(deep[fa[x][i]]>=deep[y])x=fa[x][i];
	if(x==y)return x;
	for(int i=20;i>=0;i--)
		if(fa[x][i]!=fa[y][i])
			x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
void dfs1(int x)
{
	L[x]=-inf;R[x]=inf;sig[x]=-1;
	for(int i=0,t,d,v;i<vec[x].size();i++)
	{
		dfs1(t=vec[x][i]);
		d=deep[t]-deep[x];
		v=(R[t]+d)&1;
		L[x]=max(L[x],L[t]-d);
		R[x]=min(R[x],R[t]+d);
		if(sig[x]==-1)sig[x]=v;
		else if(sig[x]!=v)quit();
	}
	if(L[x]>R[x])quit();
	if(val[x]!=val[0])
	{
		if(val[x]<L[x]||val[x]>R[x])quit();
		if(sig[x]!=-1&&(val[x]&1)!=sig[x])quit();
		L[x]=R[x]=val[x];
	}
}
void dfs2(int x)
{
	for(int i=0,t,d,d1;i<vec[x].size();i++)
	{
		t=vec[x][i];
		d=deep[t]-deep[x];
		val[t]=max(L[t],val[x]-d);
		d1=(val[x]+d-val[t])/2;
		int now=val[t],p=t;
		for(int j=1;j<=d1;j++)
			val[fa[p][0]]=val[p]+1,p=fa[p][0];
		for(int j=1;j<d-d1;j++)
			val[fa[p][0]]=val[p]-1,p=fa[p][0];
		dfs2(t);
	}
}
void dfs3(int x,int y)
{
	if(val[x]==val[0])
		val[x]=val[y]+1;
	for(int i=head[x];i;i=nex[i])
		if(to[i]!=y)dfs3(to[i],x);
}
int main()
{
	//freopen("tt.in","r",stdin);
	scanf("%d",&n);
	for(int i=1,x,y;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	memset(val,-0x3f,sizeof(val));
	scanf("%d",&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&a[i]);
		scanf("%d",&val[a[i]]);
	}
	dfs(1,0);
	sort(a+1,a+1+m,cmp);
	st[top=1]=1;
	for(int i=1,t;i<=m;i++)
	{
		while((t=lca(a[i],st[top]))!=st[top])
		{
			if(deep[t]>deep[st[top-1]])
			{
				vec[t].push_back(st[top]);
				st[top]=t;
			}
			else
			{
				vec[st[top-1]].push_back(st[top]);
				top--;
			}
		}
		if(st[top]!=a[i])
			st[++top]=a[i];
	}
	for(int i=top;i>1;i--)
		vec[st[i-1]].push_back(st[i]);
	dfs1(1);
	val[1]=L[1];
	dfs2(1);
	dfs3(1,0);
	puts("Yes");
	for(int i=1;i<=n;i++)
		printf("%d\n",val[i]);
	return 0;
}


Measured memory_bytes: 21760
//2018年  3月 23日 金曜日 03:49:26 JST
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, x;
int ans[MAX_N];

void solve() {
	cin >> N >> x;
	if(x == 2 * N - 1 || x == 1) {
		cout << "No\n"; return;
	}
	cout << "Yes" << "\n";
	if(N == 2) {
		cout << "1\n2\n3\n";
	}
	else {
		set<int> S;
		rep(i, 1, 2 * N) {
			S.insert(i);
		}
		if(x == 2 * N - 2) {
			ans[N - 1] = x;
			ans[N - 2] = x - 1;
			ans[N] = x + 1;
			ans[N + 1] = x - 2;
		}
		else {
			ans[N - 1] = x;
			ans[N - 2] = x + 1;
			ans[N]  = x - 1;
			ans[N + 1] = x + 2;
		}
		for(int i = N - 2; i <= N + 1; i++) {
			S.erase(ans[i]);
		}
		rep(i, 0, 2 * N - 1) {
			if(ans[i] == 0) {
				ans[i] = (*S.begin());
				S.erase(S.begin());
			}
		}
		rep(i, 0, 2 * N - 1) {
			cout << ans[i] << "\n";
		}
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

const int maxn=2e5+10;

int n,m,dep[maxn],cir[maxn];
int tote=1,FIR[maxn],NEXT[maxn],TO[maxn];
bool vis[maxn];

void addedge(int u,int v)
{
	TO[++tote]=v;
	NEXT[tote]=FIR[u];
	FIR[u]=tote;
}

namespace Tree{
	int Ans,c1,c2;

	int dfs(int u,int f)
	{
		int sz=dep[u];
		dep[u]==1?c1++:c2++;
		for (int p=FIR[u];p;p=NEXT[p])
		{
			int v=TO[p];
			if (v==f) continue;
			dep[v]=-dep[u];
			sz+=dfs(v,u);
		}
		Ans+=abs(sz);
		return sz;
	}

	void solve()
	{
		dep[1]=1;
		dfs(1,0);
		if (c1!=c2) puts("-1");
		else printf("%d\n",Ans);
	}
};

namespace OddCircleTree{
	int Ans,c1,c2,del;

	void dfs1(int u,int f)
	{
		dep[u]==1?c1++:c2++;
		for (int p=FIR[u];p;p=NEXT[p])
		{
			int v=TO[p];
			if (v==f) continue;
			if (p==del||(p^1)==del) continue;
			dep[v]=-dep[u];
			dfs1(v,u);
		}
	}

	int dfs2(int u,int f)
	{
		int sz=dep[u];
		for (int p=FIR[u];p;p=NEXT[p])
		{
			int v=TO[p];
			if (v==f) continue;
			if (p==del||(p^1)==del) continue;
			sz+=dfs2(v,u);
		}
		Ans+=abs(sz);
		return sz;
	}

	void solve()
	{
		int u=cir[1];
		for (int p=FIR[u];p;p=NEXT[p])
		{
			int v=TO[p];
			if (v==cir[2]) del=p;
		}
		dep[cir[1]]=1;
		dfs1(cir[1],0);
		if ((c1^c2)&1) puts("-1");
		else
		{
			Ans=abs((c1-c2)/2);
			dep[cir[1]]-=(c1-c2)/2;
			dep[cir[2]]-=(c1-c2)/2;
			dfs2(cir[1],0);
			printf("%d\n",Ans);
		}
	}
}

namespace EvenCircleTree{
	int c1,c2,del;
	int k[maxn],b[maxn],b0[maxn];

	void dfs(int u,int f)
	{
		dep[u]==1?c1++:c2++;
		b[u]=dep[u];
		k[u]+=u==cir[2];
		for (int p=FIR[u];p;p=NEXT[p])
		{
			int v=TO[p];
			if (v==f) continue;
			if (p==del||(p^1)==del) continue;
			dep[v]=-dep[u];
			dfs(v,u);
			b[u]+=b[v];
			k[u]+=k[v];
		}
	}

	void solve()
	{
		int u=cir[1];
		for (int p=FIR[u];p;p=NEXT[p])
		{
			int v=TO[p];
			if (v==cir[2]) del=p;
		}
		dep[cir[1]]=1;
		dfs(cir[1],0);
		if (c1!=c2) puts("-1");
		else
		{
			LL Ans=1e18;
			int i;
			LL K=-cir[0],B=0;
			for (i=1;i<=n;i++)
				if (!k[i]) B+=abs(b[i]);
				else B-=b[i],b0[++b0[0]]=-b[i];
			sort(b0+1,b0+b0[0]+1);
			int p=1;
			for (i=-n;i<=n;i++)
			{
				Ans=min(Ans,K*i+B);
				while (b0[p]==i&&p<=b0[0])
					K+=2,B-=i+i,p++;
			}
			printf("%lld\n",Ans);
		}
	}
}

int findcircle(int u,int f)
{
	vis[u]=1;
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p];
		if (v==f) continue;
		if (vis[v])
		{
			cir[++cir[0]]=u;
			return v;
		}
		int tmp=findcircle(v,u);
		if (tmp)
		{
			cir[++cir[0]]=u;
			if (u==tmp) return 0;
			else return tmp;
		}
	}
	return 0;
}

int main()
{
#ifdef h10
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
	int i,u,v;
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
	}
	if (n!=m)
		Tree::solve();
	else
	{
		findcircle(1,0);
		if (cir[0]&1)
			OddCircleTree::solve();
		else
			EvenCircleTree::solve();
	}
}


Measured memory_bytes: 10240
n, m = map(int, input().split())
a = [int(e) for e in input().split()]

s = sum(a) / (4 * m)
ans = 0
for i in range(n):
    if a[i] >= s:
        ans += 1
    else:
        ans += 0
if ans >= m:
    print("Yes")
else:
    print("No")

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

flag = True
for a in A:
    if a % 2 == 0:
        if a % 3 == 0 or a % 5 == 0:
            continue
        else:
            flag = False

if flag:
    print('APPROVED')
else:
    print('DENIED')


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

struct UnionFind {
    vector<int> r;

    UnionFind(int N) {
        r = vector<int>(N, -1);
    }

    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) {
        return -r[root(x)];
    }
};


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

    //友達集合を作る
    UnionFind UF(N);
    for (int i = 0; i < M; i++)
    {
        int A, B;
        cin >> A >> B;
        A -= 1; B -= 1;
        UF.unite(A, B);
    }

    //最大の友達集合を求める
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans = max(ans, UF.size(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4052
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val r, c = sc.nextInt()
  val in = List.fill(r, c)(sc.nextInt())
  addSumRow(in.map(addSumCol(_))).foreach(e => println(e.mkString(" ")))

  def addSumCol(list: List[Int]) = (list.sum :: list.reverse).reverse

  def addSumRow(lists: List[List[Int]]) = {
    val colSize = lists(0).size
    val sumRow = for (i <- 0 to colSize - 1) yield lists.map(_ (i)).sum
    (sumRow.toList :: lists.reverse).reverse
  }
}

Measured memory_bytes: 59548
#ALDS1_2_D
def insertionSort(A, n, g, cnt):
  for i in range(g, n):
    v = A[i]
    j = i - g
    while j >= 0 and A[j] > v:
      A[j+g] = A[j]
      j = j - g
      cnt += 1
    A[j+g] = v
  return A, cnt

def genG(n):
  G = []
  y = 1
  x = 1
  while y <= n:
    G.append(y)
    y = y + 3**x    
    x += 1
  return G[::-1]
    
n = int(input())
A = []
for ni in range(n):
  A.append(int(input()))
cnt = 0
G = genG(n)
m = len(G)
print(m)
print(" ".join([str(i) for i in G]))
for mi in range(m):
  A, cnt = insertionSort(A, n, G[mi], cnt)
print(cnt)
for ni in range(n):
  print(A[ni])


Measured memory_bytes: 45516
def main
  a, b, c, d = gets.split.map(&:to_i)

  total = b - a + 1

  ac = a - a % c
  bc = b - b % c
  n = bc - ac
  ccnt = n / c
  ccnt += 1 if a % c == 0

  ad = a - a % d
  bd = b - b % d
  m = bd - ad
  dcnt = m / d
  dcnt += 1 if a % d == 0

  lcm = c.lcm(d)
  al = a - a % lcm
  bl = b - b % lcm
  o = bl - al
  cnt = o / lcm
  cnt += 1 if a % lcm == 0

  puts total - ccnt - dcnt + cnt
end

main if $0 == __FILE__


Measured memory_bytes: 1788
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int h = Integer.parseInt(in.next());
            int w = Integer.parseInt(in.next());
            char[][] s = new char[55][55];
            for (int i = 1; i <= h; i++) {
                String tmp = in.next();
                for (int j = 1; j <= w; j++) {
                    s[i][0] = '.';
                    s[i][j] = tmp.charAt(j - 1);
                    s[i][w + 1] = '.';
                }
            }
            int ans = 0;
            for (int i = 1; i <= h; i++) {
                for (int j = 1; j <= w; j++) {
                    if (s[i][j] == '#') {
                        if (s[i][j - 1] != '#' && s[i][j + 1] != '#' && s[i - 1][j] != '#' && s[i + 1][j] != '#') {
                            ans++;
                            break;
                        }
                    }
                }
            }

            // 出力
            if (ans == 0) {
                out.println("Yes");
                return;
            }
            out.println("No");

        }

    }
}



Measured memory_bytes: 23124
#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)

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 n, a, b, c;
vector<int> l(10);
int ans = 1<<30;

void rec(int cur, int sum, int x, int y, int z) {
  if (cur == n) {
    if (x > 0 and y > 0 and z > 0) {
      ans = min(ans, sum + abs(a-x) + abs(b-y) + abs(c-z) - 30);
    }
    return;
  }
  rec(cur+1, sum, x, y, z);
  rec(cur+1, sum+10, x+l[cur], y, z);
  rec(cur+1, sum+10, x, y+l[cur], z);
  rec(cur+1, sum+10, x, y, z+l[cur]);
}

int main() {
  cin>>n>>a>>b>>c;
  rep(i, n) cin>>l[i];
  rec(0, 0, 0, 0, 0);
  print(ans);

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
char a[10][10];
int u;
int n,m;
void dfs(int x,int y){
	a[x][y]='.';
	if(x==n&&y==m) {
		for(int i=1;i<=n;i++) {
			for(int j=1;j<=m;j++) {
				if(a[i][j]=='#')
					return;
			}
		}
		u=1;
		return;
	}
	int o=0;
	if(a[x][y+1]=='#') {
		dfs(x,y+1);
		a[x][y+1]='#';
		o=1;
	}
	if(a[x+1][y]=='#') {
		dfs(x+1,y);
		a[x][y+1]='#';
		o=1;
	}
	if(o==0)
	return;
}
int main() {
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	dfs(1,1);
	if(u==1) {
		cout<<"Possible"<<'\n';
		return 0;
	}
	else {
		cout<<"Impossible"<<'\n';
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MOD = 1000000007;
int a[100005];
long long nn[100005] = {1,1};

int calculate(int x, int n)
{
    if(n==0)
        return 1;
    long long ret = calculate(x, n/2);
    ret = (ret*ret)%MOD;
    if(n%2 == 1)
        ret = (ret*x)%MOD;
    return ret;

}

int cnk(int n, int k)
{
    if(k>n || k<0)
        return 0;
    return (nn[n]*calculate(nn[k], MOD-2)%MOD)*calculate(nn[n-k], MOD-2)%MOD;
}

int f[100005];

int main()
{
    int n;
    cin>>n;
    for(int i=0; i<=n; ++i){
        cin>>a[i];
    }
    for(int i=1; i<=n+1; ++i){
        nn[i] = nn[i-1]*i%MOD;
    }

    int d = -1;
    for(int i=0; i<=n; i++) f[i] = -1;
    for(int i=0; i<=n; i++) {
        if(f[a[i]] >= 0)    d = i-f[a[i]]+1;
        f[a[i]] = i;
    }
    for(int i=1; i<=n+1; ++i){
        cout<<(cnk(n+1, i)-cnk(n+1-d, i-1)+MOD)%MOD<<"\n";
    }

    return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int N, K, ans;
  cin >> N >> K;
  ans=0;
  vector<int> h(N);
  for (int i=0; i<N; i++) {
    cin >> h.at(i);
  }
  for (int j=0; j<N; j++) {
    if (h.at(j)>=K) {
      ans=ans+1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3736
//0:48
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N (1<<18)
class RAQ{
private:
    ll dat[2*N];
    void dfs(int l,int r,int a,int b,int k,ll x){
	if(l<=a&&b<=r){dat[k]+=x;return;}
	if(b<=l||r<=a)return;
	dfs(l,r,a,(a+b)/2,k*2+1,x);
	dfs(l,r,(a+b)/2,b,k*2+2,x);
    }
public:
    void Init(int k){
	lol(i,2*N)dat[i]=0;
	lol(i,N)dat[i+N-1]=(i+1)*k;
    }
    void Add(int l,int r,ll x){
	if(l>r)return;
	dfs(l,r+1,0,N,0,x);
    }
    ll Sum(int i){
	i+=N-1;
	ll res=dat[i];
	while(i>0){
	    i=(i-1)/2;
	    res+=dat[i];
	}
	return res;
    }
};
ll n,q,a[N],b[N],c[N];
int main(){
    cin>>n>>q;
    //lol(i,q)cin>>a[i]>>b[i]>>c[i];
    lol(i,q)scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
    RAQ X,Y;X.Init(1);Y.Init(-1);
    for(int k=q-1;k>=0;k--){
	if(b[k]==1){
	    int l=-1,r=n,m;
	    while(l<r-1){
		m=(l+r)/2;
		if(X.Sum(m)<=a[k])l=m;
		else r=m;
	    }
	    Y.Add(0,l,c[k]*2);
	}
	if(b[k]==2){
	    int l=-1,r=n,m;
	    while(l<r-1){
		m=(l+r)/2;
		if(Y.Sum(m)<-a[k])r=m;
		else l=m;
	    }
	    X.Add(r,n-1,c[k]*2);
	}
    }
    //lol(i,n)cout<<(X.Sum(i)+Y.Sum(i))/2<<endl;
    lol(i,n){
	ll ans=(X.Sum(i)+Y.Sum(i))/2;
	printf("%lld\n",ans);
    }
    return 0;
}



Measured memory_bytes: 16120
#include <iostream>
#include <math.h>
using namespace std;
#define ll long long int 
#define inf std::numeric_limits<double>::infinity()
#define DECI(n) fixed<<showpoint<<setprecision(n)
#define MOD 1000000007LL
#define FOR(i,start,end) for (int i=start;i<end;i++)
#define FORR(i,end,start) for(int i=end-1;i>start;i--)
#define INPUT(arr,n) FOR(i,0,n) cin>>arr[i];
#define INPUT2d(arr,n,k) FOR(i,0,n) FOR(j,0,k) cin>>arr[i][j];
#define SIZE 100005
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))

int main(){
int r;cin>>r;
cout<<3*r*r<<endl;
  
  
  
  
  

return 0;
}








Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H=sc.nextLong();
		long W=sc.nextLong();
		if(H==1||W==1) {
			System.out.println(1);
			System.exit(0);
		}
		if(H*W%2==1) {
			System.out.println(H*W/2+1);
		}else {
			System.out.println(H*W/2);
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int n;
vector<lli> vec;

/*
Resolve o sistema de eq linear
5
3 8 7 5 5

6 16 14 10 10
x1 + x2 = 6
x2 + x3 = 16
x3 + x4 = 14
x4 + x5 = 10
x5 + x1 = 10

6 - 16 + 14 - 10 + 10

*/

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

  cin >> n;
  for(int i=0;i<n;i++){
    lli a;
    cin >> a;
    vec.push_back(a*2);
  }

  lli sum = vec[0];
  lli x1 = 0;

  bool at = false;
  for(int i=1;i<sz(vec);i++){
    if(!at){
      sum -= (vec[i]);
      at = true;
    } else {
      sum += vec[i];
      at = false;
    }
  }

  lli atual = sum/2;
  vector<lli> ans;
  ans.push_back(sum/2);
  for(int i=0;i<sz(vec) - 1;i++){
    ans.push_back(vec[i] - atual);
    atual = vec[i] - atual;
  }

  for(auto i : ans) cout << i << " ";
  cout << endl;

  return 0;
}

Measured memory_bytes: 3060
// 全探索
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>

using namespace std;

const int MAX_N = 20;
const int MAX_N_2 = 100000000;
const int MAX_Q = 200;

// 入力値を保持するバッファ
int input_buffer[MAX_N + 1];
// 組み合わせの管理用バッファ
int comb_buffer[MAX_N + 1];
// 組み合わせから求めた和を格納する配列
int pos = 0;
int add_buffer[MAX_N_2];

void combinations(int n, int r);
void comb_sub(int n, int r, int m);
void add_combination(int m);

int main(void)
{
    int n, q, Q[MAX_Q + 1];

    scanf("%d", &n);

    for(int i = 0; i < n; i++)
    {
        scanf("%d", &input_buffer[i]);
    }

    scanf("%d", &q);

    for(int i = 0; i < q; i++)
    {
        scanf("%d", &Q[i]);
    }

    for(int i = 0; i < n; i++)
    {
        combinations(n, i);
    }

    for(int i = 0; i < q; i++)
    {
        bool judge = false;

        for(int j = 0; j < pos; j++)
        {
            if( add_buffer[j] == Q[i] )
            {
                judge = true;
                break;
            }
        }

        if( judge )
        {
            printf("yes\n");
        }
        else
        {
            printf("no\n");
        }
    }

    return 0;
}

// 組み合わせを生成する関数の入り口
void combinations(int n, int r)
{
	if (r > 0 && r <= MAX_N)
	{
		comb_sub(n, r, 0);
	}
}

// 組み合わせを生成する関数
// n : 選択する数値の範囲 ( 1〜 n )
// r : 選ぶ数値の個数
// m : 選んだ数値の個数
void comb_sub(int n, int r, int m)
{
	if ( r == 0 )
	{
        // r が 0 になったので、組み合わせを一つ生成できた
		add_combination(m);
	}
	else if ( n == r )
	{
		for (int i = r; i > 0; i--)
		{
			// n が r と等しくなったならば、残りの数字 (1 から r まで) を全て選択
			comb_buffer[m++] = i;
		}

		add_combination(m);
	}
	else
	{
		// nを選ばない場合
		// 残りの数字の中から r 個の数字を選びます。
		comb_sub(n - 1, r, m);

		// nを選ぶ場合
		// 数字 n を comb_buffer に追加して、残りの数字の中から r - 1 個を選びます。
		comb_buffer[m] = n;
		comb_sub(n - 1, r - 1, m + 1);
	}

    return;
}

// 入力数値の和を求める
void add_combination(int m)
{
    // 配列の初期化
    add_buffer[pos] = 0;

    for(int i = 0; i < m; i++)
    {
    	// 入力された数列の和を順番に求める
        add_buffer[pos] += input_buffer[comb_buffer[i] - 1];
    }

    // 要素を進める
    pos++;

    return;
}



Measured memory_bytes: 7188
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}

signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	int n;
    cin>>n;
    
    string h="";
    vi v;

    while(n>0)
    {
        
        int x = n%26;
        if(x==0)
        x=26;
        v.pb(x);
       char xt = 'a' + x -1 ;
        n=n/26;
        if(x==26)
        n--;
       

        h+=xt;
         
    }

    reverse(all(v));
    /*for(auto it:v)
    cout<<it<<" ";*/

    reverse(all(h));
    cout<<h;

    

return 0;
}

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

int n, k;
int a[50];

int main() {
	int i, j, l;
	
	cin >> n >> k;
	rep(i, n) cin >> a[i];
	
	vector<int> ans;
	rep(i, k + 1) {
		bool used[50] = {false};
		if (i > 0) used[*ans.rbegin()] = true;
		rep(j, n - 1 + (i == 0)) {
			int maxId = -1;
			rep(l, n) {
				if (used[l] || a[l] <= 0) continue;
				if (maxId == -1 || a[maxId] < a[l]) maxId = l;
			}
			if (maxId == -1) { cout << -1 << endl; return 0; }
			a[maxId]--;
			used[maxId] = true;
			ans.push_back(maxId);
		}
	}
	
	cout << ans.size() << endl;
	rep(i, ans.size()) {
		cout << ans[i] + 1;
		if (i + 1 < ans.size()) cout << " ";
	}
	cout << endl;
	return 0;
}

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

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define eof !cin.eof()
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define ull unsigned long long
#define ll long long
#define ld long double
#define sz(a) a.size()
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define x first
#define y second
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ii pair <int, int>
#define iii pair <int, ii>
#define EPS 1e-10
#define INF 1000000000
#define mod 1000000007
#define reset(a, nilai) memset(a, nilai, sizeof(a))
#define minof min_element
#define maxof max_element
using namespace std;

int n;
bool can(int a, int b, int c) {
	if (b + c > a && a + c > b && a + b > c) {
		return true;
	}
	return false;
}
int ans;
int main () {
	IOS;
	
	cin >> n;
	vector <int> l(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	sort(all(l));
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			for (int k = j + 1; k < n; k++) {
				if (can(l[i], l[j], l[k])) {
					ans++;
				}
			}
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        char[] str = sc.next().toCharArray();
        int[] digits = new int[str.length + 1];
        for (int i = 0; i < str.length; i++) {
            digits[i + 1] = Character.getNumericValue(str[i]);
        }
        int[] residueDP = new int[2019];
        // store number of SUFFIXES with a given residue.
        // We can definitely enumerate all N of those, and we leverage
        // the fact that we can SUBTRACT suffixes in a way that
        // allows us to generate all valid substrings! This will be called
        // the substring from suffix trick!
        residueDP[0] = 1; // we can always build on top of the empty suffix!
        // Now we create a running suffix
        int suffix = 0;
        int shift = 1;
        long ans = 0;
        for (int pos = str.length; pos >= 1; pos--) {
            suffix = (suffix + shift * digits[pos]) % 2019;
            ans += residueDP[suffix]; // build off ALL old ones, subtracting to get 0!
            residueDP[suffix]++; // update it!
            shift = (shift * 10) % 2019;
        }
		System.out.println(ans);
	}
}


Measured memory_bytes: 41504
n=int(input())
a={}
b={}
for i in range(n+1):
    s=str(i)
    msd=s[0]
    lsd=s[len(s)-1]
    if msd=='0':
        continue
    if (msd,lsd) not in a:
        a[(msd,lsd)]=0
    if (msd,lsd) not in b:
        b[(msd,lsd)]=0
    a[(msd,lsd)]+=1
    b[(msd,lsd)]+=1
a_key=a.keys()
ans=0
for key in a_key:
    if key[1]==0:
        continue
    tmp=b.get((key[1],key[0]),0)
    ans+=tmp*a[(key[0],key[1])]
print(ans)

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

using namespace std;


using i64 = long long;

template<typename T>
struct Segtree{
    int n;
    T op;
    vector<T> elm;
    function<T(T, T)> f;

    Segtree(int n, T init, function<T(T, T)> f, T op = T()) :
        n(n),
        op(op),
        elm(2 * n, init),
        f(f)
    {
        for(int i = n - 1; i >= 1; --i)
            elm[i] = f(elm[2 * i], elm[2 * i + 1]);
    }

    Segtree(int n, vector<T> init, function<T(T, T)> f, T op = T()) :
        n(n),
        op(op),
        elm(2 * n),
        f(f)
    {
        for(int i = 0; i < n; ++i)
            elm[i + n] = init[i];
        for(int i = n - 1; i >= 1; --i)
            elm[i] = f(elm[2 * i], elm[2 * i + 1]);
    }

    void set(int x, T val){
        x += n;
        elm[x] = val;
        while(x >>= 1)
            elm[x] = f(elm[2 * x], elm[2 * x + 1]);
    }

    void update(int x, T val){
        x += n;
        elm[x] = f(elm[x], val);
        while(x >>= 1)
            elm[x] = f(elm[2 * x], elm[2 * x + 1]);
    }

    T get(int x, int y) const{
        T l = op, r = op;
        for(x += n, y += n - 1; x <= y; x >>= 1, y >>= 1){
            if(x & 1)
                l = f(l, elm[x++]);
            if(!(y & 1))
                r = f(elm[y--], r);
        }
        return f(l, r);
    }
};


signed main(){
    int n, m;
    string s;
    cin >> n >> m >> s;
    vector<int> nex(n + 1, -1);
    Segtree<pair<int,int>> seg(n + 1, make_pair(int(1e9), int(1e9)), [](auto x, auto y){return min(x, y);},make_pair(int(1e9), int(1e9)) );
    seg.set(n, make_pair(0, n));
    for(int i = n - 1; i >= 0; --i){
        if(s[i] == '1')
            continue;
        auto res = seg.get(1 + i, min(i + 1+m, n + 1));
        seg.set(i, make_pair(res.first + 1, i));
        nex[i] = res.second;
    }
    if(seg.get(0, 1).first >= 1e9){
        cout << -1 << endl;return 0;
    }
    int i = 0;
    vector<int> w;
    while(i != n){
        w.emplace_back(nex[i] - i);
        i = nex[i];
    }
    for(int i = 0; i < w.size(); ++i)
        cout << w[i] << " \n"[i == w.size() - 1];

}


Measured memory_bytes: 3064
import copy
N, M, K = map(int, input().split())

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
      
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(N+1)

not_uf = [set() for _ in range(N+1)]
for _ in range(M):
  a, b = map(int, input().split())
  not_uf[a].add(b)
  not_uf[b].add(a)
  uf.union(a, b)

for _ in range(K):
  c, d = map(int, input().split())
  if uf.same(c, d):
    not_uf[c].add(d)
    not_uf[d].add(c)

for i in range(1, N+1):
  print(uf.size(i)-len(not_uf[i])-1)
  

Measured memory_bytes: 62700
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;

class Main {

	private static final int YEAR = 2004;
	private static final String SUNDAY = "Sunday";
	private static final String MONDAY = "Monday";
	private static final String TUESDAY = "Tuesday";
	private static final String WEDNESDAY = "Wednesday";
	private static final String THURSDAY = "Thursday";
	private static final String FRIDAY = "Friday";
	private static final String SATURDAY = "Saturday";

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			while (sc.hasNextInt()) {
				int month = sc.nextInt();
				int day = sc.nextInt();
				if (month == 0 || day == 0) {
					break;
				}

				System.out.println(getDayOfTheWeek(month, day));

			}
		}
	}

	private static String getDayOfTheWeek(int m, int d) {
		Calendar calendar = new GregorianCalendar(YEAR, m - 1, d);

		String dayOfTheWeek = null;
		switch (calendar.get(Calendar.DAY_OF_WEEK)) {
		case Calendar.SUNDAY:
			dayOfTheWeek = SUNDAY;
			break;
		case Calendar.MONDAY:
			dayOfTheWeek = MONDAY;
			break;
		case Calendar.TUESDAY:
			dayOfTheWeek = TUESDAY;
			break;
		case Calendar.WEDNESDAY:
			dayOfTheWeek = WEDNESDAY;
			break;
		case Calendar.THURSDAY:
			dayOfTheWeek = THURSDAY;
			break;
		case Calendar.FRIDAY:
			dayOfTheWeek = FRIDAY;
			break;
		case Calendar.SATURDAY:
			dayOfTheWeek = SATURDAY;
			break;
		}
		return dayOfTheWeek;
	}
}

Measured memory_bytes: 27144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC154
{
    class Program
    {
        static void Main(string[] args)
        {
            b();
        }

        public static void b()
        {
            string s = Console.ReadLine();
            int a = s.Length;
            for(int i = 0; i < a; i++)
            { Console.Write("x"); }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 11092
//*
// yarn compile template.ts で監視可能
{
  const pattern = {
    yymm: "YYMM",
    mmyy: "MMYY",
    ambiguous: "AMBIGUOUS",
    na: "NA",
  }
  const process = (a: string): string => {
    const firstHalf = parseInt(a.substring(0, 2))
    const latterHalf = parseInt(a.substring(2))

    let isFirstYy = false
    let islatterYy = false

    if (firstHalf === 0 || firstHalf > 12) {
      // firstHalf === yy
      isFirstYy = true
    }
    if (latterHalf === 0 || latterHalf > 12) {
      // latterHalf === yy
      islatterYy = true
    }

    if (isFirstYy && islatterYy) {
      return pattern.na
    }
    if (isFirstYy) {
      return pattern.yymm
    }
    if (islatterYy) {
      return pattern.mmyy
    }
    return pattern.ambiguous
  }

  const Main = (input: string): string => {
    //const n: number = parseInt(input)
    //const a: string[]  = input.split(" ")
    //const aa: string[][]  = input.split("\n").split(" ")
    const res = process(input)
    console.log(res)
    return res
  }
  Main(require("fs").readFileSync("/dev/stdin", "utf8"))
}

// */


Measured memory_bytes: 7372
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            if ((n / 2) + (n % 2) >= k) {
                out.print("YES");
            } else {
                out.print("NO");
            }
        }

    }
}



Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int h,w;
    cin>>h>>w;
    char grid[h][w];
    int path[h][w];
    rep(i,h)rep(j,w)cin>>grid[i][j];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            path[i][j]=0;
        }
    }
    for(int i=0;i<w;i++){
        if(grid[0][i]=='.')path[0][i]=1;
        else break;
    }
    for(int i=0;i<h;i++){
        if(grid[i][0]=='.')path[i][0]=1;
        else break;
    }
    for(int i=1;i<h;i++){
        for(int j=1;j<w;j++){
            if(grid[i][j]=='#')path[i][j]=0;
            else{
                path[i][j]=max(path[i][j],path[i-1][j]+path[i][j-1]);
                path[i][j]%=P;
            }
        }
    }
    cout<<path[h-1][w-1]<<endl;
    /*
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<path[i][j]<<" ";
        }
        cout<<endl;
    }*/


//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;

char ch;
string s;

int main()
{
	ios::sync_with_stdio(false);
	cin>>s;
	int f=0,ans=0;
	for(int i=0;i<s.size();i++){
		if(ch==s[i]){
			i=i+1;
			if(i>=s.size())break;
			ans++;
			ch='0';
		} else {
			ch=s[i];
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0; 
} 

Measured memory_bytes: 720
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vs = vector<string>;
template <typename T>
using ost = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
#define forn(i,n) for(int i=0; i<int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ff first
#define ss second

int main() {
    ios::sync_with_stdio(false);
    int n, c, k;
    cin >> n >> c >> k;
    vpii xs(n);
    for (pii& p:xs) {
        cin >> p.ff;
        p.ss = p.ff + k;
    }
    sort(all(xs));
    int ans=0;
    for (int lo=0, cap=0, i=0; i<n; i++) {
        pii p=xs[i];
        if (cap>0 && lo>=p.ff) cap--;
        else {
            ans++;
            cap=c-1;
            lo=p.ss;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1024
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[10**9]*n
dp[0]=0

for i in range(n):
  a=max(0,i-k)
  for j in range(a,i):
    dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]))
print(dp[-1])

Measured memory_bytes: 52592