akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#define INF 100000000
#define _INF -100000000
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> P;

static const int N = 1e5 + 5;

ll h, w, n;
vector<P> black(N);
vector<ll> ans(10, 0);

bool in_range(ll a, ll b) {
	if (1 <= a&&a <= h - 2 && 1 <= b&&b <= w - 2) return true;
	else return false;
}

void solve() {
	map<P, ll> mp;
	Loop(i, n) {
		ll a = black[i].first, b = black[i].second;
		for (ll dx = -2;dx <= 0;dx++) {
			for (ll dy = -2;dy <= 0;dy++) {
				if (in_range(a + dx, b + dy)) mp[{a + dx, b + dy}]++;
			}
		}
	}
	for (auto itr = mp.begin();itr != mp.end();itr++) {
		ans[itr->second]++;
	}
	ll cnt = 0;
	for (int i = 1;i < 10;i++) {
		cnt += ans[i];
	}
	ans[0] = (h - 2)*(w - 2) - cnt;
	Loop(i, 10) {
		cout << ans[i] << endl;
	}
}


int main() {
	cin >> h >> w >> n;
	Loop(i, n) {
		cin >> black[i].first >> black[i].second;
	}
	solve();
	return 0;
}

Measured memory_bytes: 58112
#include <iostream>
#include <algorithm>
using namespace std;
long long a,b;
int main(){
	cin>>a>>b;
	if (a==b) cout << a;
	else if (a+1==b) cout << (a^b);
	else if ((a&1)&&!(b&1)) cout << ((a^b)^((b-a-1>>1)%2==1?1:0));
	else if ((a&1)) cout << ((a)^((b-a>>1)%2==1?1:0));
	else if (!(b&1)) cout << ((b)^((b-a>>1)%2==1?1:0));
	else cout << ((b-a+1>>1)%2==1?1:0);
	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <numeric>
using namespace std;

long long combi(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}

long long gcd(int a, int b){
  if (a%b == 0){
    return(b);
  }
  else{
    return(gcd(b, a%b));
  }
}

int main(){    
  long long N,K,d,b;
  cin >> N >> K;
  long long A[N+1]={},count=0;
  A[0]=1;
  
  for(int i=0;i<K;i++){
    cin >> d;
    for(int j=0;j<d;j++){
      cin >> b;
      A[b]++;
    }
  }

  for(int i=1;i<=N;i++){
    if(A[i] == 0){
      count++;
    }
  }
  
  cout << count  << endl;

}
 

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

typedef pair<int, ll> P;
#define fs first
#define sc second

int main() {
    string s;
    cin >> s;
    int N = s.size();

    ll ans = 0;
    vector<ll> cnt(2019, 0);

    for(int i = 0; i < N; i++) {
        int num = s[i] - '0';

        vector<ll> tmp(2019, 0);
        for(int j = 0; j < 2019; j++) {
            if(cnt[j] != 0) {
                if((j * 10 + num) % 2019 == 0) ans += cnt[j];
                tmp[(j * 10 + num) % 2019] += cnt[j];
            }
        }

        tmp[num] += 1;

        cnt = tmp;
    }

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


Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <queue>
using namespace std;

int main(){
    int a,b;cin >> a >> b;
    int ans = 0;

    for(int i = a; i <= b; ++i){
        string s = to_string(i);
        if(s[0] == s[s.size()-1] && s[1] == s[s.size()-2]) ans++;
    }

    cout << ans << endl;

    return EXIT_SUCCESS;
}


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

int main() {
	double d1=0, d2=0, d3=0, di=0, temp;
	vector<double> v1, v2;
	int n;
	cin >> n;
	v1.resize(n);
	v2.resize(n);
	for(int i=0; i<n; ++i) {
		cin >> v1[i];
	}
	for(int i=0; i<n; ++i) {
		cin >> v2[i];
	}
	for(int i=0; i<n; ++i) {
		temp=abs(v1[i]-v2[i]);
		d1+=temp;
		d2+=temp*temp;
		d3+=temp*temp*temp;
		di=(di>temp?di:temp);
	}
	cout << fixed << setprecision(6);
	cout << d1 << endl;
	cout << pow(d2,1.0/2.0) << endl;
	cout << pow(d3,1.0/3.0) << endl;
	cout << di << endl;

	return 0;
}

Measured memory_bytes: 3400
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main(void)
{
  int N,i,odd = 0,even = 0,ans;
  char s[1000],a1[5],a2[5],a3[5],a4[5],a5[5],a6[5],a7[5],a8[5],a9[5],a10[5];

  int A[20];

  scanf("%d\n",&N);
  fgets(s,1000,stdin);
  sscanf(s,"%s %s %s %s %s %s %s %s %s %s",a1,a2,a3,a4,a5,a6,a7,a8,a9,a10);

  A[0] = 0;
  A[1] = atoi(a1);
  A[2] = atoi(a2);
  A[3] = atoi(a3);
  A[4] = atoi(a4);
  A[5] = atoi(a5);
  A[6] = atoi(a6);
  A[7] = atoi(a7);
  A[8] = atoi(a8);
  A[9] = atoi(a9);
  A[10] = atoi(a10);
 for(i = 1;i < N + 1;i++)
    {
      if(A[i]%2 == 1)
        odd = odd + 1;
      else
        even = even + 1;
     
      ans = pow(3,N) - pow(2,even);
    }

  //  printf("odd = %d even = %d",odd,even);
  //printf("%d\n",pow(3,N) - pow(2,even));
  printf("%d\n",ans);
  //printf("%s %s %s",a1,a2,a3);
  //  for(i = 1;i < N + 1;i++)
  // printf("A[%d] = %d\n",i,A[i]);


  return 0;
}




Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;

int a, b;
int main()
{
	while( ~scanf("%d%d", &a, &b) )	{
		double x = (a + b)/2.0;
		int n = (a + b)/2;
		if(n - x == 0)
			printf("%d\n", n);
		else
			printf("%d\n", n + 1);
		}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long hxtype;
typedef pair<int,int>pii;
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
const int N=155;
map<pii,int>dp[N][N][N];int p;
inline void add(int &a){if(a>=p)a-=p;}
int main(){
	int m,n,k,i,j,t,J,T,d;
	map<pii,int>::iterator it1,it2;
	scanf("%d%d%d",&n,&k,&p);
	if(k&1){
		m=n+1;
		dp[0][0][0][mp(m,m)]=1;
		rep(i,1,n)rep(j,0,n)rep(t,0,n){
			it1=dp[i-1][j][t].begin();
			it2=dp[i-1][j][t].end  ();
			for(;it1!=it2;++it1){
				J=(*it1).fi.fi;
				T=(*it1).fi.se;
				d=(*it1)   .se;
//				printf("sol (%d,%d,%d,%d,%d) %d\n",i-1,j,t,J,T,d);
				if(i&1){
//					printf("add (%d,%d,%d,%d,%d)\n",i,0,t,m,T);
					add(dp[i][0][t][mp(m,T)]+=d);
					if((t<<1)>k)cmin(T,i-(j<<1)+k);
//					if(i!=J)printf("add (%d,%d,%d,%d,%d)\n",i,j+1,t,J,T);
					if(i!=J)add(dp[i][j+1][t  ][mp(J,T)]+=d);
				}else{
//					printf("add (%d,%d,%d,%d,%d)\n",i,j,0,J,m);
					add(dp[i][j][0][mp(J,m)]+=d);
					if((j<<1)>k)cmin(J,i-(t<<1)+k);
//					if(i!=T)printf("add (%d,%d,%d,%d,%d)\n",i,j,t+1,J,T);
					if(i!=T)add(dp[i][j  ][t+1][mp(J,T)]+=d);
				}
			}
		}
		T=0;
		rep(j,0,n)rep(t,0,n){
			it1=dp[n][j][t].begin();
			it2=dp[n][j][t].end  ();
			for(;it1!=it2;++it1)add(T+=(*it1).se);
		}
		printf("%d",T);
	}else{
		k>>=1;
		static int dp[N][N];
		dp[0][0]=1;
		REP(i,0,n)rep(j,0,k){
			add(dp[i+1][  0]+=dp[i][j]);
			if(j!=k)
			add(dp[i+1][j+1]+=dp[i][j]);
		}
		t=n-(j=n>>1);
		J=T=0;
		rep(i,0,k)add(J+=dp[j][i]);
		rep(i,0,k)add(T+=dp[t][i]);
		printf("%lld",((ll)J)*T%p);
	}
	return 0;
}

Measured memory_bytes: 228352
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const double pi=acos(-1);

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> A(n);
    for(int i=0;i<n;i++) cin >> A[i];
    int ans=1;
    int num=n-k;
    ans+=num/(k-1);
    if(num%(k-1)!=0) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const int maxn=2e5+5;
int n,a[maxn];
ll ans,sum[maxn];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	for(int i=1;i<n;i++){
		ans=(ans+((sum[n]-sum[i])%mod)*a[i])%mod;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 5548
a,b = map(int,input().split())
ans = 0
if b-a <= 8:
  for i in range(a,b+1):
    ans^=i
  print(ans)
  exit()

stop = a - (a%8) + 8
start = b - (b%8)
for i in range(a,stop):
  ans ^= i
for i in range(start,b+1):
  ans ^= i
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef vector<int> vi;
typedef pair<int,vi> P;
int my[2],op[2],fr[5];
bool use[52];
int g(string s){
	int x,y;
	if(s[0]=='S') x=0;
	if(s[0]=='D') x=1;
	if(s[0]=='H') x=2;
	if(s[0]=='C') x=3;
	if(s[1]=='A') y=1;
	if(s[1]=='K') y=13;
	if(s[1]=='Q') y=12;
	if(s[1]=='J') y=11;
	if(s[1]=='T') y=10;
	if(isdigit(s[1])) y=s[1]-'0';
	use[x*13+y-1]=true;
	return x*13+y-1;
}
bool awinb(P a,P b){
	if(a.fs!=b.fs) return a.fs<b.fs;
	rep(i,a.sc.size()){
		if(a.sc[i]!=b.sc[i]) return a.sc[i]>b.sc[i];
	}
	return false;
}
P value(vi x){
	vector<int> s,n;
	rep(i,5){
		s.pb(x[i]/13),n.pb(x[i]%13+1);
		if(n[i]==1) n[i]=14;
	}
	bool ssame=true;
	rep1(i,4) if(s[0]!=s[i]) ssame=false;
	if(ssame){
		sort(all(n));
		if(n==vi{2,3,4,5,14}) return P(1,vi{1});
		bool st=true;
		rep(i,5) if(n[i]-n[0]!=i) st=false;
		if(st) return P(1,vi{n[0]});
		return P(4,vi{n[4],n[3],n[2],n[1],n[0]});
	}else{
		sort(all(n));
		if(n[0]==n[3]) return P(2,vi{n[0],n[4]});
		if(n[1]==n[4]) return P(2,vi{n[1],n[0]});
		if(n[0]==n[2]&&n[3]==n[4]) return P(3,vi{n[0],n[3]});
		if(n[2]==n[4]&&n[0]==n[1]) return P(3,vi{n[2],n[0]});
		if(n==vi{2,3,4,5,14}) return P(5,vi{1});
		bool st=true;
		rep(i,5) if(n[i]-n[0]!=i) st=false;
		if(st) return P(5,vi{n[0]});
		if(n[0]==n[2]) return P(6,vi{n[0],n[4],n[3]});
		if(n[1]==n[3]) return P(6,vi{n[1],n[4],n[0]});
		if(n[2]==n[4]) return P(6,vi{n[2],n[1],n[0]});
		if(n[0]==n[1]&&n[2]==n[3]) return P(7,vi{n[2],n[0],n[4]});
		if(n[0]==n[1]&&n[3]==n[4]) return P(7,vi{n[3],n[0],n[2]});
		if(n[1]==n[2]&&n[3]==n[4]) return P(7,vi{n[3],n[1],n[0]});
		if(n[0]==n[1]) return P(8,vi{n[0],n[4],n[3],n[2]});
		if(n[1]==n[2]) return P(8,vi{n[1],n[4],n[3],n[0]});
		if(n[2]==n[3]) return P(8,vi{n[2],n[4],n[1],n[0]});
		if(n[3]==n[4]) return P(8,vi{n[3],n[2],n[1],n[0]});
		return P(9,vi{n[4],n[3],n[2],n[1],n[0]});
	}
}
P good(vi x){
	P ss=P(1000,vi{});
	rep(i,7) rep(j,i){
		vi a;
		rep(k,7){
			if(k==i||k==j) continue;
			a.pb(x[k]);
		}
		P p=value(a);
		if(awinb(p,ss)) ss=p;
	}
	return ss;
}
bool canwin(vi a,vi b){
	P xp=good(a);
	P yp=good(b);
	return awinb(xp,yp);
}
int main(){
	while(true){
		string s;
		cin>>s;
		if(s[0]=='#') break;
		rep(i,52) use[i]=0;
		my[0]=g(s);
		cin>>s;
		my[1]=g(s);
		rep(i,2){
			cin>>s;
			op[i]=g(s);
		}
		rep(i,3){
			cin>>s;
			fr[i+2]=g(s);
		}
		int cnt=0,win=0;
		for(fr[0]=0;fr[0]<52;fr[0]++){
			if(use[fr[0]]) continue;
			for(fr[1]=0;fr[1]<fr[0];fr[1]++){
				if(use[fr[1]]) continue;
				cnt++;
				vi a,b;
				rep(i,2) a.pb(my[i]);
				rep(i,2) b.pb(op[i]);
				rep(i,5){
					a.pb(fr[i]);
					b.pb(fr[i]);
				}
				if(canwin(a,b)) win++;
			}
		}
		printf("%.12f\n",(double)win/cnt);
	}
}

Measured memory_bytes: 1252
#include <iostream>
using namespace std;
int A, B, C, D;
int main(void) {
	cin >> A >> B >> C >> D;
	int l = A + B;
	int r = C + D;
	if (l < r) {
		cout << "Right";
	}
	else if (r < l) {
		cout << "Left";
	}
	else {
		cout << "Balanced";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>

using namespace std;

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

	int minR = R[0];
	int maxv = INT_MIN;
	for(int i = 1; i < n; i++){
		maxv = max(maxv, R[i] - minR);
		minR = min(minR, R[i]);
	}
	cout << maxv << endl;

	return 0;
}

Measured memory_bytes: 1940
#include <string>
#include<queue>
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<map>
#include<tuple>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> t3;
typedef tuple<int,int,int,int> t4;

const int MX = 205;

int main()
{
	int N;
	scanf("%d", &N);
	map<int,int> L;
	for(int i = 1; i <= N; i++){
		int a;
		scanf("%d", &a);
		L[a] += 1;
	}
	ll a = 0, b = 0;
	for(auto it = L.rbegin(); it != L.rend(); ++it){
		while( it->second >= 2 ){
			if( a == 0 ) a = it->first;
			else if( b == 0 ) b = it->first;
			else return !printf("%lld\n", a*b);
			it->second -= 2;
		}
	}
	printf("%lld\n", a*b);
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
void solve(){
    string s;
    cin >> s;
    int n = s.size();
    char a = 'a';
    char z = 'z';
    bool test;
    for(char i = a; i <= z; i++){
        test = false;
        for(int j = 0; j < n; j++){
            if(s.at(j) == i)
            test = true;
        }
        if(test == false){
            cout << i << endl;
            break;
        }
    }
    if(test){
        cout << "None" << endl;
    }
}
int main(){
    solve();
    return 0;
}


Measured memory_bytes: 512
class Main{
    public static void main(String[] args){
       for (int i = 0; i < 9 * 9; i++) {
			int a = i / 9 + 1;
			int b = i % 9 + 1;

			System.out.println(a + "x" + b + "=" + a * b);

		}


    }
}

Measured memory_bytes: 23936
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef		vector<ll>      vll;
#define		pb              push_back
#define         O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		PB              pop_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)



int main()
{
    ll x;
    string s;
    cin>>x>>s;
    ll cnt=0;

    for(int i=0;i<x-2;i++)
    {
        if((s[i]=='A')&&(s[i+1]=='B')&&(s[i+2]=='C')) cnt++;

    }

    cout<<cnt<<nn;








    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,b[100001],x,y;
bool a[100001];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>b[i];
		a[i]=true;
	}
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		if(b[x]<=b[y]) a[x]=false;
		if(b[y]<=b[x]) a[y]=false;
	}
	x=0;
	for(int i=1;i<=n;i++)
		if(a[i]) x++;
	cout<<x;
	return 0;
}

Measured memory_bytes: 4068
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)( m ); i < (unsigned int)( n ); i++ )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

VI shuffle( VI vec, int p, int c )
{
	VI res( vec.begin() + p, vec.begin() + p + c );
	vec.erase( vec.begin() + p, vec.begin() + p + c );
	res.insert( res.end(), ALL( vec ) );
	
	return res;
}

int main()
{	
	while ( true )
	{
		int n, r;
		cin >> n >> r;

		if ( !( n | r ) )
		{
			break;
		}

		VI res( n );
		REP( i, 0, n )
		{
			res[i] = n - i;
		}

		REP( i, 0, r )
		{
			int p, c;
			cin >> p >> c;

			res = shuffle( res, p - 1, c );
		}

		cout << res[0] << endl;
	}

	return 0;
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i];}cerr << endl;}

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




const int nmax = 100;
int open[nmax][10];
int p[nmax][11];


int main(){

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

    fill_n(*open, nmax*10, 0);
    fill_n(*p, nmax*11, 0);

    ll ans = LLONG_MIN;

    int n;
    cin >> n;

    rep(i, n){
        rep(j, 10){
            cin >> open[i][j];
        }
    }

    rep(i, n){
        rep(j, 11){
            cin >> p[i][j];
        }
    }

    for(int patt = 1; patt < (1 << 10); ++patt){

        ll tmpsales = 0;

        rep(shop, n){
            ll dup = 0;

            rep(i, 10){
                if((patt >> i & 1) and open[shop][i])
                    ++dup;
            }

            tmpsales += p[shop][dup];
        }

        ans = max(ans, tmpsales);
    }


    ppp(ans);
    return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;




signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll a,b,c; cin>>a>>b>>c;
  if(b-a==c-b) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
main = interact $ unlines . map (show . sum_of_integers . map read . words) . init . lines
sum_of_integers [n,s] = count n s [0,1,2,3,4,5,6,7,8,9]
 where
  count 0 0 _ = 1
  count 0 _ _ = 0
  count _ _ [] = 0
  count n' s' (x:xs) = count (n'-1) (s'-x) xs + count n' s' xs

Measured memory_bytes: 4124
from itertools import permutations


def solve():
    N = int(input())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    
    a, b = -1, -1
    cnt = 0
    for nums in permutations(range(1, N + 1), N):
        nums = list(nums)
        if nums == P:
            a = cnt
        if nums == Q:
            b = cnt
        cnt += 1
    print(abs(a - b))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3188
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 23 21:04:33 2020

@author: naoki
"""

N = int(input()) # input the row A length "N" 
A = list(map(int,input().split())) # input the row of A 
Q = int(input()) # input the number of trying operation 
BC = [list(map(int,input().split())) for i in range(Q)]
S = 0
num = [0 for i in range(100001)] 
for i in A:
    S += i # Sum of all conponents of the row "A"
    num[i]+=1 

for B,C in BC:
    S = S + (C - B) * num[B]
    num[C] += num[B]
    num[B] = 0 
    print(S)



Measured memory_bytes: 33028
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
typedef long long ll;
const int MYINF = 1e9+7;


void printA(const int *A, int N) {
	int i;
	char *sp = "";
	for (i = 0; i < N; i++) {
		printf("%s%d", sp, A[i]);
		sp = " ";
	}
	putchar('\n');
}

void insersion_sort(int *A, int N, void (*fn)(const int *, int)) {
	int i, j, key;
	if (fn != NULL) fn(A, N);
	for (i = 1; i < N; i++) {
		key = A[i];
		for (j = i - 1; j >= 0 && A[j] > key; j--) {
			A[j + 1] = A[j];
		}
		A[j + 1] = key;
		if (fn != NULL) fn(A, N);
	}
}

int main(int argc, char **argv)
{
	int N;
	int A[128];
	int i;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	insersion_sort(A, N, printA);

	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++) // ex)REP(i,10) i=0~i=9
#define REPR(i, n) for(int i = n;i >= 0;i--) // ex)REPR(i,10) i=10~i=0
#define FOR(i, m, n) for(int i = m;i < n;i++) //ex)FOR(i,3,10) i=3~i=9
#define FORR(i, m, n) for(int i = m;i >= n;i--) 
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end()); //
#define llong long long //64bitに拡張
#define pb(a) push_back(a)　
#define INF 999999999 //大きな値
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//座標上を探索
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
int answer,a,b;
char c;
scanf("%d %c %d",&a,&c,&b);
switch(c) {
   case '+' : printf("%d\n",answer = a + b) ;break;
   case '-' : printf("%d\n",answer = a - b); ;break;
}
return 0;
}


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

int N;
vector<int> p(100);

int num(int m) {
    int ind = lower_bound(p.begin(), p.end(), m-1) - p.begin();
    return p.size() - ind;
}

int main() {
    cin >> N;
    for (int i = 1; i <= N; i++) {
        int cur = i;
        for (int j = 2; j < i+1; j++) {
            while(cur%j == 0) {
                p[j]++;
                cur /= j;
            }
        }
    }
    sort(p.begin(), p.end());

    cout << num(75) + num(25) * (num(3)-1) + num(15) * (num(5) - 1) + num(5) * (num(5) - 1) * (num(3) - 2) / 2 << endl;

}

Measured memory_bytes: 256
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int r,d,x;

int main()
{
	cin>>r>>d>>x;
	rep(i,10)
	{
		x=r*x-d;
		cout<<x<<endl;
	}
	rt0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[5];
int main(){
	scanf("%s",a);
	for(int i=0;i<=2;i++){
		if(a[i]=='9')
			printf("1");
		else
			printf("9");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((int64_t *)a) < *((int64_t *)b) ? -1 : 1;
}

int compare_f2(const void *a, const void *b) {
	return *((uint64_t *)a) > *((uint64_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

	for (uint64_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	size_t a, b, h;

	scanf("%zu\n%zu\n%zu", &a, &b, &h);

	printf("%zu\n", (a + b) * h / 2);

	return 0;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    int ans = c - (a - b);
    if (ans < 0) {
        cout << 0 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

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

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

    FOR(i, 1, 10) {
        li criteria = i * 111;
        if (N <= criteria) {
            cout << criteria;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = (1..(n + 1)).map({|i| read::<i64>() - (i as i64)}).collect();

    a.sort();
    let x = a[n / 2];
    let ans: i64 = a.iter().map({|y| (x - y).abs()}).sum();

    println!("{}", ans);
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define int long long int 
#define mp make_pair
#define pb push_back

int check(int i)
{
     
     set <int> s;
     
     while(i)
     {
          int r=i%10;
          s.insert(r);
          i/=10;
     }
     
     if(s.size()==1)
     return 1;
     else 
     return 0;
     
}


int32_t main()
{
    
    int n;
    cin>>n;
    
    for(int i=n;i<=999;i++)
    {
         if(check(i))
         {
              cout<<i;
              return 0;
         }
    }
    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

ll n,x;
vl a;

int main(){
	cin>>n>>x;
	a=vl(n);
	for(int i=0;i<n;i++) cin>>a[i];
	ll ans=0;
	for(int i=1;i<n;i++){
		if(a[i]+a[i-1]>x){
			ans+=(ll)a[i]+a[i-1]-x;
			a[i]-=a[i]-x+a[i-1];
			if(a[i]<0) a[i]=0;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;
using ll = long long;

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

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

    map<string, int> mp;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        mp[s]++;
    }

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;


    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>

int main(){

  int n,i,j=0,x,min;
  int r[200000];

  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&r[i]);
    if(i==0)min=r[i];
    if(i==1)x=r[i]-min;
    if(i>0){
      if(r[i]-min>x) x=r[i]-min;
      if(r[i]<min)min=r[i];
  }
  }
  printf("%d\n",x);
}
    



Measured memory_bytes: 2576
/* Filename: ARC083D.java
 * Author: Mushiyo
 */

import java.util.Scanner;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
		final int INF = Integer.MAX_VALUE;
		Scanner input = new Scanner(System.in);

		while (input.hasNext()) {
			int N = input.nextInt();
			long[][] shortestPath = new long[N][N];

			for (int u = 0; u < shortestPath.length; ++u) {
				for (int v = 0; v < shortestPath[u].length; ++v) {
					shortestPath[u][v] = input.nextInt();
				}
			}

			long[][] graph = new long[N][N];
			for (int u = 0; u < graph.length; ++u) {
				graph[u][u] = 0;
				for (int v = u + 1; v < graph[u].length; ++v) {
					graph[u][v] = INF;
					graph[v][u] = INF;
				}
			}

			for (int u = 0; u < shortestPath.length; ++u) {
				for (int v = 0; v < shortestPath[u].length; ++v) {
					boolean hasMid = false;
					for (int mid = 0; mid < shortestPath.length; ++mid) {
						if (shortestPath[u][mid] + shortestPath[mid][v] == shortestPath[u][v]) {
							if (mid != u && mid != v) {
								hasMid = true;
							}
						}
					}

					if (hasMid == false) {
						graph[u][v] = shortestPath[u][v];
						graph[v][u] = shortestPath[u][v];
					}
				}
			}

			long[][] Floyd_Warshall = new long[N][N];
			for (int i = 0; i < Floyd_Warshall.length; ++i) {
				System.arraycopy(graph[i], 0, Floyd_Warshall[i], 0, graph.length);
			}

			for (int mid = 0; mid < Floyd_Warshall.length; ++mid) {
				for (int u = 0; u < Floyd_Warshall.length; ++u) {
					for (int v = 0; v < Floyd_Warshall[u].length; ++v) {
						Floyd_Warshall[u][v] = Math.min(Floyd_Warshall[u][v],
								Floyd_Warshall[u][mid] + Floyd_Warshall[mid][v]);
					}
				}
			}

			boolean isExist = true;
			for (int i = 0; i < shortestPath.length; ++i) {
				if (Arrays.equals(shortestPath[i], Floyd_Warshall[i]) == false) {
					isExist = false;
					break;
				}
			}

			if (isExist) {
				long pathLen = 0;
				for (int u = 0; u < graph.length; ++u) {
					for (int v = u + 1; v < graph[u].length; ++v) {
						if (graph[u][v] != INF) {
							pathLen += graph[u][v];
						}
					}
				}

				System.out.println(pathLen);
			} else {
				System.out.println(-1);
			}
		}
	}

}


Measured memory_bytes: 52172
from math import atan2
from collections import defaultdict, deque
def cross(a, b, c):
    return (b[0]-a[0])*(c[1]-a[1]) - (b[1]-a[1])*(c[0]-a[0])
def convex_hull(ps):
    qs = []
    n = len(ps)
    for p in ps:
        while len(qs)>1 and cross(qs[-1], qs[-2], p) > 0:
            qs.pop()
        qs.append(p)
    t = len(qs)
    for i in range(n-2, -1, -1):
        p = ps[i]
        while len(qs)>t and cross(qs[-1], qs[-2], p) > 0:
            qs.pop()
        qs.append(p)
    return qs
def outer_check(R, S):
    cur = 0
    for e in S:
        if cur < len(R) and e == R[cur]:
            cur += 1
    return cur == len(R)
while 1:
    C, W = map(int, input().split())
    if C == W == 0:
        break
    G0 = [[] for i in range(C)]
    P = [list(map(int, input().split())) for i in range(C)]
    P0 = [P[i] + [i] for i in range(C)]
    P0.sort()
    Q0 = convex_hull(P0)
    R = list(map(lambda x: x[2], Q0))[:-1]
    k = R.index(min(R))
    R = R[k:] + R[:k]

    for i in range(W):
        s, t = map(int, input().split()); s -= 1; t -= 1
        G0[s].append(t)
        G0[t].append(s)
    for i in range(C):
        x0, y0 = P[i]
        G0[i].sort(key = lambda p: atan2(P[p][1] - y0, P[p][0] - x0))
    E = defaultdict(list)
    cur = 0
    for v in range(C):
        for b, v0 in enumerate(G0[v]):
            prv = v
            st = [v]
            while 1:
                g = G0[v0]
                c = (g.index(prv)+1) % len(g)
                if v0 == v and c == b:
                    break
                st.append(v0)
                prv = v0; v0 = g[c]

            if min(st) == v and not outer_check(R, st):
                for i in range(len(st)):
                    p = st[i-1]; q = st[i]
                    if not p < q:
                        p, q = q, p
                    E[p, q].append(cur)
                cur += 1
    G = [[] for i in range(cur+1)]
    for es in E.values():
        if len(es) == 2:
            a, b = es
        else:
            a = es[0]; b = cur
        G[a].append(b)
        G[b].append(a)
    D = [-1]*(cur+1)
    D[cur] = 0
    que = deque([cur])
    while que:
        v = que.popleft()
        d = D[v]
        for w in G[v]:
            if D[w] != -1:
                continue
            D[w] = d+1
            que.append(w)
    print(max(D))



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

using namespace std;

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

    int num = stoi(S);

    int prev = num / 100;
    int next = num % 100;

    if((prev > 0 && prev <= 12) && (next > 0 && next <= 12)) {
        cout << "AMBIGUOUS" << endl;
    } else if(prev > 0 && prev <= 12) {
        cout << "MMYY" << endl;
    } else if(next > 0 && next <= 12) {
        cout << "YYMM" << endl;
    } else {
        cout << "NA" << endl;
    }
}


Measured memory_bytes: 256
use proconio::input;
use std:: char::*;

fn main() {
  input! {
    mut n: u64
  }

  let mut ans: Vec<char> = Vec::new();

  loop {
    n -= 1;
    let c = (n%26) as u32;
    n += 1;
    ans.push(from_u32(c + ('a' as u32)).unwrap());
    n -= c as u64;
    n /= 26;
    if n==0 {break;}
  }

  ans.reverse();

  for x in ans {
    print!("{}", x);
  }
  println!();

  //println!("Hello, AtCoder!");
}


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


int main(){
    string S;
    cin >> S;
    if((S.at(0)== 'A' && S.at(1)== 'A' &&S.at(2)== 'A')||(S.at(0)== 'B' && S.at(1)== 'B' &&S.at(2)== 'B')){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    
    

    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int N;
long long A[20001];
long long B[20001];
int main(){
	cin>>N;
	REP(i,N){
	    A[i]=i*20000+1;
	    B[i]=(N-1-i)*20000+1;
	}
	REP(i,N){
	    int p;
	    cin>>p;
	    B[p-1]+=i;
	}
	REP(i,N){
           cout<<A[i];
           if(i!=N-1){
              cout<<" ";
           }else{
              cout<<endl;
           }
        }
        REP(i,N){
           cout<<B[i];
           if(i!=N-1){
              cout<<" ";
           }else{
              cout<<endl;
           }
        }
	return(0);
}

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

void bubbleSort(int *,int);
int main(){
    int i,n;
    int *array;
    
    scanf("%d",&n);
    array=(int *)malloc(n*sizeof(int));
    for(i=0;i<n;i++){
       scanf("%d",&array[i]);
    }
    bubbleSort(array,n);
return 0;
}

void bubbleSort(int *array,int n){
    int i,j,temp;
    int flag;
    int count=0;
    
    while(1){
        flag=0;
       for(i=n-1;i>0;i--){
        if(array[i]<array[i-1]){
          temp=array[i];
          array[i]=array[i-1];
          array[i-1]=temp;
          
          count++;
          flag=1;
        }
       }
       if(flag==0) break;
    }
    for(j=0;j<n-1;j++){
        printf("%d ",array[j]);
    }
    printf("%d",array[n-1]);
    printf("\n");
    printf("%d\n",count);
}



Measured memory_bytes: 2144
#include <stdio.h>
#include <math.h>
#include <string.h>
#define rad M_PI/3
#define N 500001

int S[N]={0};
int L[N/2]={0};
int R[N/2]={0};
long count =0;

void Merge(int A[],int left,int mid,int right){
    int n1,n2;
    int i,j,k;
    n1=mid-left;
    n2=right-mid;
    for(i=0;i<n1;++i){
        L[i]=A[left+i];
    }
    for(i=0;i<n2;++i){
        R[i]=A[mid+i];
    }
    L[n1]=1000000010;
    R[n2]=1000000010;
    i=j=0;
    for(k=left;k<right;++k){
        if(L[i]<=R[j]){
            A[k]=L[i];
            ++i;
    }else{
        A[k]=R[j];
        ++j;
        count+=(n1-i);
    }
    }
    return;
}
void MergeSort(int A[], int left, int right) {
    int mid;
    if (left + 1 < right) {
        mid = (left + right) / 2;
        MergeSort(A, left, mid);
        MergeSort(A, mid, right);
        Merge(A, left, mid, right);
    }
    return;
}

int main()
{
  int n, i;
 
    scanf("%d", &n);
 
    for (i = 0; i < n; ++i) {
        scanf("%d", &S[i]);
    }
    MergeSort(S, 0, n);
    printf("%ld\n", count);
     
    return 0;
  return 0;
}


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

int change(string s1){
    int num;
    string str = s1;
    stringstream s(str);
    s >> num;
    return num;
}

int main(){
    int n,a;
    vector<int> v,tmp;
    
    cin >> n;
    rep(i,n){
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());

    if(n >= 4) n = 4;
    rep(i,n){
        tmp.push_back(v[i]);
    }
    
    vector<string> vec;
    for(int i = 0 ; i < tmp.size() ; i++){
        for(int j = 0 ; j < tmp.size() ; j++){
            if(i == j) continue;
            stringstream s;
            s << tmp[i];
            s << tmp[j];
            vec.push_back(s.str());
        }
    }
    
    vector<int> ans;
    for(int i = 0 ; i < vec.size() ; i++){
        ans.push_back(change(vec[i]));
    }
    sort(ans.begin(),ans.end());
    
    cout << ans[2] << endl;
    
    return 0;
}

Measured memory_bytes: 1312
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();
		if (A == 1 && B == 2) {
			System.out.println(3);
		} else if (A == 2 && B == 1) {
			System.out.println(3);
		} else if (A == 2 && B == 3) {
			System.out.println(1);
		} else if (A == 3 && B == 2) {
			System.out.println(1);
		} else if (A == 1 && B == 3) {
			System.out.println(2);
		} else if (A == 3 && B == 1) {
			System.out.println(2);
		}
	}

}


Measured memory_bytes: 23124
n = int(input())
if n < 3:
    print(n)
    exit()

primes = [2]

import math
for i in range(3, n+1):
    k = int(math.sqrt(i))
    flag = True
    for p in primes:
        if p > k:
            break
        if  i%p == 0:
            flag = False
            break
    if flag:
        primes.append(i)

ans = 1
for p in primes:
    k = n
    cnt = 0
    while k:
        k = k//p
        cnt += k
    # print(p, cnt)
    ans *= cnt + 1
ans = ans % (10**9 + 7)
print(ans)


Measured memory_bytes: 3064
A, B = tuple(int(num) for num in input().split())
S = input()

s_list = list(S)
  
for i, s in enumerate(s_list):
  if i == A:
    if s_list[A] != '-':
      print('No')
      break
  else:
    try:
      s = int(s)
    except:
      print('No')
      break
else:
  print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

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

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

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#define M 101

using namespace std;

int main(){
	int A, B;
	cin >> A >> B;
	for (int i = 0; i<1e5; i++){
		if (floor((double) i*0.08) == A && floor((double) i*0.1) == B){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}
			
		


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

int main() {
    string s;
    cin>>s;
    int counter = 0;
    if(s[0]=='o') ++counter;
    if(s[1]=='o') ++counter;
    if(s[2]=='o') ++counter;
    cout << 700+100*counter << endl;
}


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

#define endl '\n'
#define sz(x) ((int)(x.size()))

string s[55];
long long C[55];

long long dist[55][22][55][22];

bool pal(string s) {
	for(int i=0; i<sz(s); i++) if(s[i] != s[sz(s)-1-i]) return 0;
	return 1;
}

bool pal(string x, string y) {
	for(int i=0; i<min(sz(x), sz(y)); i++) {
		if(x[i] != y[sz(y)-1-i]) return 0;
	}
	return 1;
}

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

	int n;
	cin >> n;
	for(int i=0; i<n; i++) cin >> s[i] >> C[i];
	long long ans = 1e18;
	memset(dist, 127, sizeof dist);
	priority_queue < pair < long long, vector <int> > > pq;
	for(int i=0; i<n; i++) {
		for(int j=0; j<n; j++) {
			if(i == j) {
				if(pal(s[i])) ans = min(ans, C[i]);
			}
			if(pal(s[i], s[j])) {
				if(sz(s[i]) > sz(s[j])) {
					dist[i][sz(s[i])-sz(s[j])][j][0] = C[i]+C[j];
					pq.push({-C[i]-C[j], {i, sz(s[i])-sz(s[j]), j, 0}});
				}
				else if(sz(s[i]) < sz(s[j])) {
					dist[i][0][j][sz(s[j])-sz(s[i])] = C[i]+C[j];
					pq.push({-C[i]-C[j], {i, 0, j, sz(s[j])-sz(s[i])}});
				}
				else {
					ans = min(ans, C[i]+C[j]);
				}
			}
		}
	}
	while(sz(pq)) {
		auto e = pq.top();
		pq.pop();
		long long D = -e.first;
		auto state = e.second;
		if(state[1] + state[3] == 0) {
			ans = min(ans, D);
			continue;
		}
		int i = state[0];
		int j = state[2];
		if(dist[i][state[1]][j][state[3]] < D) continue;
		if(state[3] == 0) {
			if(pal(s[i].substr(sz(s[i])-state[1]))) {
				ans = min(ans, D);
			}
			else {
				for(int jj=0; jj<n; jj++) {
					bool flag = 1;
					for(int k = sz(s[i])-state[1], t = sz(s[jj])-1; k < sz(s[i]) && t >= 0; k++, t--) {
						if(s[i][k] != s[jj][t]) {
							flag = 0;
							break;
						}
					}
					if(flag) {
						vector <int> nx;
						if(state[1] >= sz(s[jj])) {
							nx = {i, state[1]-sz(s[jj]), jj, 0};
						}
						else {
							nx = {i, 0, jj, sz(s[jj])-state[1]};
						}
						if(D + C[jj] < dist[nx[0]][nx[1]][nx[2]][nx[3]]) {
							dist[nx[0]][nx[1]][nx[2]][nx[3]] = D + C[jj];
							pq.push({-dist[nx[0]][nx[1]][nx[2]][nx[3]], nx});
						}
					}
				}
			}
		}
		else {
			if(pal(s[j].substr(0, state[3]))) {
				ans = min(ans, D);
			}
			else {
				for(int ii=0; ii<n; ii++) {
					bool flag = 1;
					for(int k = state[3]-1, t = 0; k >= 0 && t < sz(s[ii]); k--, t++) {
						if(s[j][k] != s[ii][t]) {
							flag = 0;
							break;
						}
					}
					if(flag) {
						vector <int> nx;
						if(state[3] >= sz(s[ii])) {
							nx = {ii, 0, j, state[3]-sz(s[ii])};
						}
						else {
							nx = {ii, sz(s[ii])-state[3], j, 0};
						}
						if(D + C[ii] < dist[nx[0]][nx[1]][nx[2]][nx[3]]) {
							dist[nx[0]][nx[1]][nx[2]][nx[3]] = D + C[ii];
							pq.push({-dist[nx[0]][nx[1]][nx[2]][nx[3]], nx});
						}
					}
				}
			}
		}
	}
	if(ans > 5e17) cout << -1 << endl;
	else cout << ans << endl;

	return 0;
}

Measured memory_bytes: 15092
N,M=map(int,input().split());e=[[9e9]*N for _ in range(N)];g=[[0]*N for _ in range(N)]
for _ in range(M):a,b,c=map(int,input().split());e[a-1][b-1]=e[b-1][a-1]=c
for i in range(N):
 for j in range(N):
  for k in range(N):
   if e[j][k]>e[j][i]+e[i][k]:
    e[j][k]=e[j][i]+e[i][k];g[j][k]=1
print((sum(sum(l)for l in g)+2*M-N*N)//2)

Measured memory_bytes: 3512
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>

using namespace std;
using ll = long long int;



int main(void){
  
  ll n;
  cin>>n;

  vector<int> b(n-1);
  vector<int> a(n);

  for(int i=0;i<n-1;i++){
    int x;
    cin>>x;
    b[i] = x;
  }

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

  for(int i=0;i<n-1;i++){
    a[i] = min(b[i], a[i]);
    a[i+1] = min(b[i], a[i+1]);
  }

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


  return 0;
}

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

int main(){
    int n;
    int i,j,k;
    // int build[4][3][10]={{{}}};
    int build[4][3][10]{0};
    cin >> n;
    int b,f,r,v;
    for(i=0;i<n;i++){
        cin >> b >> f >> r >> v;
        build[b-1][f-1][r-1]+=v;
    }
    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
	            cout << " ";
	            cout << build[i][j][k];
            }
            cout << endl;
        }
        if(i<3)cout << "####################" << endl;
    }
    return 0;
}


Measured memory_bytes: 3088