akhauriyash/Code-Regression huggingface dataset:
// #include<bits/stdc++.h>
// using namespace std;
 
// const int N = 100, MAXI = 100001, D = 9;
 
// int main() {
//     freopen("output.txt", "r", stdin);
//     freopen("input.txt", "w", stdout);
//     srand(time(nullptr));
//     int tc = 100, flag = 1;
//     cout << tc << "\n";
//     int n = 1;

//     while (tc--)
//     {
    	
//     	int n = rand()%N + 1, m = rand()%N + 1;

//     	int a[n][m];
//     	for(int i=0;i<n;i++)
//     	{
//     		for(int j=0;j<m;j++)
//     		{
//     			int flag = rand()%4;
//     			if(flag==0)
//     				a[i][j] = -1;
//     			else
//     				a[i][j] = rand()%MAXI;
//     		}
//     	}

//     	a[n-1][0] = rand()%MAXI;

//     	cout << n << " " << m << "\n";
//     	for(int i=0;i<n;i++){
//     		for(int j=0;j<m;j++)
//     			cout << a[i][j] << " ";
//     		cout << "\n";
//     	}

//     	cout << "~\n";
//     }
 
//     return 0;
// }
 
 
//  int n, a[N];

// int MEM(int ind, vector<int> &v)
// {
// 	if(ind==n)
// 	{
// 		// o(n)
// 	}

// 	int ans = 0;
// 	if(a[ind]==-1)
// 	{
// 		for(int i=0;i<n;i++)
// 		{
// 			if(i!=ind)
// 			{
// 				v[ind] = i;
// 				ans += MEM(ind+1, v);
// 				if(ans>=mod)
// 					ans %= mod;
// 			}
// 		}
// 	}
// 	else
// 		ans = MEM(ind+1, v);

// 	return ans;

// }
 
 
 
 
 
//---------------------------------------------//
 
 
 
/*
#define int long long 
#define mod (int)(1e9+7)
#define endl '\n'
#define MAXI (int)(3e17+10)
#define N 200005
 */ 
 
 
 
 

//  /* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define MAXI (int)(3e17+10)
#define N 1005




// Driver code to test above functions
int32_t main()
{
    
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
	cout.tie(NULL);

	
	int a, b;
	cin >> a >> b;

	char c;
	cin >> c;

	int d;
	cin >> d;

	b = b*100+ d;

	cout << (a*b)/100;

    return 0;
 
}

Measured memory_bytes: 3660
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll N,T;
ll S;
int main(){
    cin>>N>>T;

    ll X=0;
    ll R=0;
    for(ll i=0;i<N;i++){
    	cin>>S;
    	if(S<R){
    		X=X+T-R+S;
    	}else{
    		X+=T;
    	}
    	R=S+T;
    }

    cout<<X<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int n;
vector<int> a;

int partition(int p, int r){
    int x = a[r];
    int i = p - 1;
    rep(j, p, r){
        if(a[j] <= x){
            i = i + 1;
            swap(a[i], a[j]);
        }
    }
    swap(a[i + 1], a[r]);
    return i + 1;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    a.resize(n);
    rep(i, 0, n) cin >> a[i];
    int idx = partition(0, n - 1);
    rep(i, 0, n){
        if(i != 0) cout << " ";
        if(i == idx) cout << "[" << a[i] << "]";
        else cout << a[i];
    }
    cout << endl;
}

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

row=[]
for i in range(h):
     flag=False
     for j in range(w):
         if(a[i][j]=='#'):
             flag=True
             break
     if flag: row.append(i)
col=[]
for i in range(w):
     flag=False
     for j in range(h):
         if(a[j][i]=='#'):
             flag=True
             break
     if flag: col.append(i)
for i in row:
    s=''
    for j in col:
        s+=a[i][j]
    print(s)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define MOD 1000000007

int H, W;
long long dp[1111][1111];

int main(){
    cin >> H >> W;
    vector<string> a(H);
    for(int i=0; i<H; i++)
        cin >> a[i];

    dp[0][0] = 1;
    for(int i=0; i<H; i++)
        for(int j=0; j<W; j++)
            if(a[i][j] == '.'){
                if(i < H-1 && a[i+1][j] == '.')
                    dp[i+1][j] = (dp[i+1][j]+dp[i][j])%MOD;
                if(j < W-1 && a[i][j+1] == '.')
                    dp[i][j+1] = (dp[i][j+1]+dp[i][j])%MOD;
            }
    cout << dp[H-1][W-1] << endl;

    return 0;
}

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

#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< pii,vector<pii> ,greater< pii >>

using namespace std;


//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*int power(int a,int n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n/2))%mod)%mod;
    return power((a*a)%mod,n/2)%mod;
}*/
//const int md = 998244353;

/*int inverse(int x){

    return power(x,mod-2)%mod;//little fermat....
}*/
const int inf = (int) 1e18;
const int md = (int) 1e9+21;


signed main()
{
    showoff;
    int n,m,tot = 0,sum = 0;
    cin >> n >> m;
    vector<int>v(n+5),cnt(maxn);
    FOR(i,1,n+1)cin >> v[i],sum += v[i];
    sort(v.begin()+1,v.begin()+n+1);
    vector<pii>u;
    FOR(i,1,m+1){
        int b,c;
        cin >> b >> c;
        u.pb({c,b});
    }
    sort(u.begin(),u.end(),greater<pii>());
    int j = 0;
    FOR(i,1,n+1){
        while(j < sz(u) && (u[j].f <= v[i] || u[j].se == 0))++j;
        if(j < sz(u))--u[j].se,sum += u[j].f-v[i];
    }
    cout << sum;
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...

Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n; cin >> n;
    double sol = 0;
    if (n%2==0)
        sol = (n/2.0)/n;
    else
        sol = ((n+1.0)/2.0)/n;

    printf("%.10f", sol);
    return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){

  ll n;
  cin >> n;
  vector<ll> v(n);
  rep(i,n)cin >> v[i];
  vector<ll> cnt(n+1,0);
  rep(i,n){
    if(cnt[v[i]-1] > 0){
      cnt[v[i]] = cnt[v[i]-1]+1;
    }else{
      cnt[v[i]] = 1;
    }
  }
  cout << n-*max_element(ALL(cnt)) << endl;





  return 0;
}

Measured memory_bytes: 3456
from collections import deque
import sys
input = sys.stdin.readline

n = int(input())

def calc_idx(x, y):
    if x > y:
        x, y = y, x
    return x + y*(y-1)//2

# create graphs & calc indegree
n_game = n * (n-1) // 2
edge = [[] for i in range(n_game)]
indegree = [0] * n_game
for i in range(n):
    ai = list(map(int, input().split()))

    for j in range(1, n-1):
        g1 = calc_idx(i, ai[j-1]-1)
        g2 = calc_idx(i, ai[j]-1)
        edge[g1].append(g2)
        indegree[g2] += 1


ans = 0
cand = deque([(i, 1) for i in range(n_game) if indegree[i] == 0])
n_ts = 0
while len(cand) > 0:
    u, day = cand.popleft()
    ans = max(ans, day)
    n_ts += 1
    for v in edge[u]:
        indegree[v] -= 1
        if indegree[v] == 0:
            cand.append((v, day+1))

if n_ts != n_game:
    ans = -1

print(ans)


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

int main() {
    int array_num;
    cin >> array_num;
    long array[array_num];
    long abs_max = 0;
    long abs_max_index = 0;
    long sign;
    for(int i = 0; i < array_num ; i++)
    {
        cin >> array[i];
        if(abs(array[i]) > abs_max)
        {
            abs_max = abs(array[i]);
            abs_max_index = i;
            sign = array[i] / abs(array[i]);
        }
    }

    cout << 2*array_num << endl;            
    for(int i = 0; i < array_num ; i++)
    {
        {
            cout << abs_max_index+1 << " " << i+1 << endl;
        }
    }

    if(sign > 0)
    {
        cout << 1 << " " << 1 << endl;            
        for(int i = 0; i < array_num  - 1; i++)
        {
            cout << i+1 << " " << i+2 << endl;            
        }
    }
    if(sign < 0)
    {
        cout << array_num << " " << array_num << endl;            
        for(int i = array_num; i > 1; i--)
        {
            cout << i << " " << i-1 << endl;            
        }
    }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N,A,B,C,D=map(int,input().split())
S=input().strip()

BLOCK=[0]*N
OPEN=[0]*N

for i in range(1,N):
    if S[i]=="#" and S[i-1]=="#":
        BLOCK[i]=1

for i in range(2,N):
    if S[i]==S[i-1]==S[i-2]==".":
        OPEN[i]=1

RIGHT_A=N-1
for i in range(A,N):
    if BLOCK[i]==1:
        RIGHT_A=i
        break

RIGHT_B=N-1
for i in range(B,N):
    if BLOCK[i]==1:
        RIGHT_B=i
        break

if C<=RIGHT_A+1 and D<=RIGHT_B+1:
    if C<D:
        print("Yes")
        sys.exit()
    if RIGHT_A==RIGHT_B:
        for j in range(B,D+1):
            if OPEN[j]==1:
                print("Yes")
                sys.exit()

        else:
            print("No")
                
    else:
      print("Yes")
else:
    print("No")


Measured memory_bytes: 6392
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

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

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

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    double ans=0;
    int num=n/2;
    ans=num*1.0/n;
    ans=1-ans;
    printf("%0.9lf\n",ans);




    return 0;
}

Measured memory_bytes: 256
function main(input) {
  input=input.trim();
  const n = parseInt(input.split(" ")[0], 10);
  const a = parseInt(input.split(" ")[1], 10);
  const b = parseInt(input.split(" ")[2], 10);

  var ans=[]
  for(var i=1; i<=n; i++){
    var nagasa=String(i).length
    var wa=0
    for(var j=0; j<nagasa; j++){
      wa+=Number(String(i).substr(j,1))
    }
    if(wa>=a&&wa<=b){
      ans.push(i)
    }
  }
  //console.log(ans);
  var sum  = function(arr) {
    var sum = 0;
    for (var i=0,len=arr.length; i<len; ++i) {
        sum += arr[i];
    };
    return sum;
  };
  console.log(sum(ans));
}



main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
	char a[105];
	char b[105];
	scanf("%s %s",a,b);
	int lena = strlen(a);
	int lenb = strlen(b);
	if(lena > lenb) printf("GREATER\n");
	else if(lena < lenb) printf("LESS\n");
	else{
		for(int i = 0; i < lena; i++){
			if(a[i] == b[i] && i == lena-1){
				printf("EQUAL\n");
				break;
			}
			if(a[i] > b[i]){
				printf("GREATER\n");
				break;
			}
			if(a[i] < b[i]){
				printf("LESS\n");
				break;
			}
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=j;i<n;i++)
void insertionsort(int A[],int N){
    rep(i,1,N){
        int v=A[i];int j=i-1;
        while(j>=0&&A[j]>v){
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=v;
        rep(k,0,N-1)cout<<A[k]<<" ";
        cout<<A[N-1]<<endl;
    }
}
int main(){
    int n;cin>>n;
    int A[n];
    rep(i,0,n)cin>>A[i];
    rep(i,0,n-1)cout<<A[i]<<" ";
    cout<<A[n-1]<<endl;
    insertionsort(A,n);
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int n,a[100000],i,p[5001],cnt=0,x,c=0,flg,y;
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&a[i]);
	sort(a,a+n);
	for(i=1;i<=a[n-1];i++){
		if(a[n-1]%i==0) p[c]=i,c++;
	}
	//for(i=0;i<c;i++) printf("%d\n",p[i]);
	y=0; i=0;
	while(1){
		if(i==n) break;
		if(a[i]>p[y]) y++;
		else {
			cnt+=p[y]-a[i];
			i++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


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

int main() {
    string s;
    cin >> s;
    ll res = 0;
    for(ll i=0; i<s.size(); i++){
        res += (int)(s[i]-'0');
    }
    string ans = (res%9 == 0) ? "Yes" : "No" ;
    cout << ans;
}

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

int main(){
  int x,y,z;
  cin >>x >>y >>z;
  int ans = 0;
  for(int i = 1;;i++){
    if(y*i+z*(i+1)>x) break;
    ans = i;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int r, t;
		cin >> r >> t;

		if (r % 100 == 0 && t % 30 == 0)
			cout << 5 * (t / 30) + r / 100 << endl;
		else if (r % 100 == 0)
			cout << 5 * (t / 30) + r / 100 << " "
			<< 5 * (t / 30 + 1) + r / 100 << endl;
		else if (t % 30 == 0)
			cout << 5 * (t / 30) + r / 100 << " "
			<< 5 * (t / 30) + r / 100 + 1 << endl;
		else
			cout << 5 * (t / 30) + r / 100 << " "
			<< 5 * (t / 30) + r / 100 + 1 << " "
			<< 5 * (t / 30 + 1) + r / 100 << " "
			<< 5 * (t / 30 + 1) + r / 100 + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 3124
#include<stdio.h>
#define M 1010

int main(void){
  int i;
  char ch[M];

  scanf("%s",ch);
  for(i=0;ch[i];i++){
    ch[i]-=3;
    if(ch[i]<'A')
      ch[i]+=26;
  }
  printf("%s\n",ch);

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

vector<ll>a;
int main() {
	ll n;
	cin>>n;
	if(n==0){
		cout << 0;
	}
	bool mi=false;
	while(n!=0){
		if(abs(n)%2!=0){
			a.push_back(1);
		}
		else{
			a.push_back(0);
		}
		if(n<0){
			if(abs(n)%2!=0){
				n/=2;
				n*=-1;
				n++;
			}
			else{
				n/=2;
				n*=-1;
			}
		}
		else{
			n/=2;
			n*=-1;
		}
	}
	reverse(a.begin(),a.end());
	for(auto itr=a.begin();itr!=a.end();itr++){
		cout << *itr;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	int n,r;
	cin>>n>>r;
	int ans;
	if(n >=10){
		cout<<r<<endl;
	}
	else{
		ans = 100*(10-n);
	cout<<ans+r<<endl;
	}

	
	return 0;
}

Measured memory_bytes: 888
#include<stdio.h>
int main(){
	int a, b;
	char op;
	while(1){
		scanf("%d %c %d", &a, &op, &b);
		if(op == '?')break;
		else if(op == '+')printf("%d\n", a + b);
		else if(op == '-')printf("%d\n", a - b);
		else if(op == '*')printf("%d\n", a * b);
		else if(op == '/')printf("%d\n", a / b);
	}
	return 0;
}


Measured memory_bytes: 2104
#include<cstdio>
bool a[250000];
int main(void)
{
    int n,k,t,cnt=0,num=0;
    scanf("%d %d" ,&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d" ,&t);
    while(a[n-1]==false){
        for(int i=cnt;i<cnt+k;i++)
            a[i]=true;
        cnt+=k-1;
        num++;
    }
    printf("%d" ,num);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <stdio.h>
#define MAX 2147483647
using namespace std;

int main() {
    int n, q, com, tmp, r_min, r_max;
    cin >> n >> q;
    int a[n];
    for (int i=0; i<n; i++) {
        a[i] = MAX;
    }
    for (int i=0; i<q; i++) {
        scanf("%d", &com);
        if (com == 0) {
            scanf("%d", &tmp);
            scanf("%d", &a[tmp]);
        } else {
            scanf("%d %d", &r_min, &r_max);
            tmp = MAX;
            for (int j=r_min; j<=r_max; j++) {
                if (a[j] < tmp) {
                    tmp = a[j];
                }
            }
            printf("%d\n", tmp);
        }
    }
}


Measured memory_bytes: 3548
l,m = map(int,input().split())
li = list(map(int,input().split()))
y = 0
x = 0
for n in range(l+1):
    if y == m:
            print("Yes")
            exit()
    if x <= (l-1) and li[x] >= ((sum(li))/(4*m)):
        y += 1
        x += 1
    else:
        x += 1
print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(a>=b&&a>=c){
        cout<<a*10+b+c;
    }
    else if(b>=a&&b>=c){
        cout<<b*10+a+c;
    }
        else{
            cout<<c*10+b+a;
        }
}




Measured memory_bytes: 764
import java.util.Scanner;
class Main{
    public static void main(String[] args){
		int H,W;
		Scanner sc=new Scanner(System.in);
		while(true){
			H=sc.nextInt();
			W=sc.nextInt();
			if(H==0&&W==0)break;
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					if((i==0||i==H-1)||(j==0||j==W-1)){
						System.out.print("#");
					}else System.out.print(".");
				}
				System.out.println("");
			}
			System.out.println("");
		}
    }
}



Measured memory_bytes: 31912
n,m = map(int,input().split())

graph = [[] for _ in range(n+1)]

for i in range(m):
  a,b = map(int, input().split())
  graph[a].append(b)
  graph[b].append(a)


dist = [-1] * (n+1)
dist[0] = 0
dist[1] = 0

from collections import deque
d = deque()
d.append(1)

while d:
  v = d.popleft()
  
  for i in graph[v]:
    if dist[i] != -1:
      continue
    dist[i] = v
    d.append(i)
    
ans = dist[2:]
if all(d == -1 for d in dist):
  print('No')
  exit()
print('Yes')
for i in range(len(ans)):
  print(ans[i])

Measured memory_bytes: 34928
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int t = 0;
  for(int i=0;i<50000;i++){
    t = i*1.08;
    if(t == n){
      cout << i << endl;
      return 0;
    }
    }
      cout << ":(" << endl;
}

Measured memory_bytes: 3624
/*---> praveenojha33 <---> 03 September 2019 <--- > 14:09:15 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

int32_t main(){__
	int n;
	cin>>n;
	vi a(n);
	double ans=0.0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(all(a));
	ans=(double)(a[0]+a[1])/2;
	for(int i=2;i<n;i++){
		ans=(double)(ans+a[i])/2;
	}
	cout<<setprecision(15)<<fixed<<ans<<"\n";
return 0;
}

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

int main(){
  
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int S1, S2;
  S1 = A * B;
  S2 = C * D;
  
  cout << max(S1, S2) << endl;
  
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int group(int n) {
    if ((n <= 7 && n % 2 == 1) || (n > 7 && n % 2 == 0)) return 1;
    else return 2;
}

int main () {
    int x, y; cin >> x >> y;
    if (x == 2 || y == 2) cout << "No" << endl;
    else if (group(x) == group(y)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
 int main() {
	 int N, X;
	 cin >> N >> X;
	 int mi = 1 << 30;
	 for (int i = 0; i < N; i++) {
		 int m;
		 cin >> m;
		 mi = min(mi, m);
		 X -= m;
	 }
	 cout << N + X / mi << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int N;
char c;
vector<vector<int>> G(220, vector<int>());

void bfs(int st, vector<int> &dist){
	queue<int> Q;
	Q.push(st);
	dist[st] = 0;
	while(!Q.empty()){
		int f = Q.front();
		Q.pop();
		for(auto t:G[f]){
			if(dist[t] == inf){
				dist[t] = dist[f] + 1;
				Q.push(t);
			}
		}
	}
}

int main(){
	cin >> N;
	rep(i,N)rep(j,N){
		cin >> c;
		if(c == '1')G[i].push_back(j);
	}
	int ans = -1;
	rep(st, N){
		vector<int> dist(N, inf);
		bfs(st, dist);
		int e_ans = -1;
		bool can = true;
		rep(f,N){
			for(auto t:G[f]){
				if(abs(dist[f] - dist[t]) != 1)can = false;
				else e_ans = max({e_ans, dist[f], dist[t]});
			}
		}
		if(can)ans = max(ans, e_ans + 1);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3816
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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;
        InputReader in = new InputReader(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, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();

            int canEatPoisonCookie = Math.min(c, a + b + 1);

            out.println(b + canEatPoisonCookie);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



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

left_length = sum(A[:int(N/2)])
right_length = sum(A[int(N/2):])
if left_length > right_length :
  price = left_length - right_length
  for i in range(int(N/2)-1,0,-1) :
    var = abs(sum(A[:i]) - sum(A[i:]))
    if price > var :
      price = var
    else :
      break
else :
  price = right_length - left_length
  for i in range(int(N/2)+1,N) :
    var = abs(sum(A[i:]) - sum(A[:i]))
    if price > var :
      price = var
    else :
      break

print(price)

Measured memory_bytes: 26220
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll X,Y,A,B,C;
    cin>>X>>Y>>A>>B>>C;
    v p(A),q(B),r(C);
    priority_queue<pair<ll,ll>> que;

    rep(i,0,A){
        cin>>p[i];
        que.push(MP(p[i],0));
    }
    rep(i,0,B){
        cin>>q[i];
        que.push(MP(q[i],1));
    }
    rep(i,0,C){
        cin>>r[i];
        que.push(MP(r[i],2));
    }
    ll n0=0,n1=0,n2=0;
    ll ans = 0;
    while(n0+n1+n2<X+Y){
        if(que.top().second == 0){
            if(n0 >= X){}
            else{
                ans += que.top().first;
                n0++;
            }
            que.pop();
        }
        else if(que.top().second == 1){
            if(n1 >= Y){}
            else{
                ans += que.top().first;
                n1++;
            }
            que.pop();
        }
        else{
            ans += que.top().first;
            n2++;
            que.pop();
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 12396
a= input()
a=a.rstrip().split(" ")
tate = a[0]
yoko = a[1]

e =[]
for i in range(int(tate)):
    b=input()
    e.append(b)
#print(e)
era=0
for j in range(int(tate)):
    
    for k in range(int(yoko)):
        if e[j][k]==".":
            k +=1
        elif e[j][k]=="#":
            if k>1 and k<int(yoko)-1 and j>1 and j<int(tate)-1:
                if e[j-1][k]=="#" or e[j+1][k]=="#" or e[j][k-1]=="#" or e[j][k+1]=="#":
                    k +=1
                else:
                    era = era+1
                    k +=1
            elif k==0 and j>1 and j<int(tate)-1:
                if e[j-1][k]=="#" or e[j+1][k]=="#" or e[j][k+1]=="#":
                    k +=1
                else:
                    era = era+1
                    k +=1
            elif k==int(yoko)-1 and j>1 and j<int(tate)-1:
                if e[j-1][k]=="#" or e[j+1][k]=="#" or e[j][k-1]=="#":
                    k +=1
                else:
                    era = era+1
                    k +=1
            elif j==0 and k>1 and k<int(tate)-1:
                if e[j+1][k]=="#" or e[j][k-1]=="#" or e[j][k+1]=="#":
                    k +=1
                else:
                    era = era+1
                    k +=1
            elif j==int(tate)-1 and k>1 and k<int(yoko)-1:
                if e[j-1][k]=="#" or e[j][k-1]=="#" or e[j][k+1]=="#":
                    k +=1
                else:
                    era = era+1
                    k +=1
if era ==0:
    print("Yes")
elif era >=1:
    print("No")

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

int main(){
    int n;
    cin >> n;
    int t[n],a[n];
    for(int i=0;i<n;i++){
        cin >> t[i] >> a[i];
    }
    long long ans;
    long long N=1;
    long long x=1,y=1;
    for(int i=0;i<n;i++){
        if(i==0) N=1;
        else{
            long long A=(t[i-1]*N+t[i]-1)/t[i];
            long long B=(a[i-1]*N+a[i]-1)/a[i];
            N=max(A,B);
        }
        x=t[i]*N;
        y=a[i]*N;
    }
    cout << x+y << endl;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int s= sc.nextInt();
        int[] f = new int[10000];
        
        f[0] = s;
        
        for(int i=1; i<10000; i++){
            if(f[i-1]%2==0){
                f[i]=f[i-1]/2;
            }else{
                f[i]=3*f[i-1]+1;
            }
            for(int j=0; j<i; j++){
                if(f[i]==f[j]){
                    System.out.println(i+1);
                    return;
                }
            }
        }
        
        
        
	}
}

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

int gcd( int x, int y ) {
	return y ? gcd( y, x%y ) : x;
}

int lcm( int x, int y ) {
	return y / gcd( x, y ) * x;
}

int main() {
	ios_base::sync_with_stdio( false );

	int n;
	cin >> n;

	int result = 1;

	for( int i = 0; i < n; ++i ) {
		int a;
		cin >> a;

		result = lcm( result, a );
	}

	cout << result << endl;
}



Measured memory_bytes: 3132
ld, rd = [0, 0, 0, 0], [0, 0, 0, 0]
while True:
    try:
        l, r = map(float, input().split())
        if l < 0.2:
            ld[3] += 1
        elif l < 0.6:
            ld[2] += 1
        elif l < 1.1:
            ld[1] += 1
        else:
            ld[0] += 1

        if r < 0.2:
            rd[3] += 1
        elif r < 0.6:
            rd[2] += 1
        elif r < 1.1:
            rd[1] += 1
        else:
            rd[0] += 1

    except:
        break

for l, r in zip(ld, rd):
    print(l, r)

Measured memory_bytes: 7376
def main():
    N = int(input())
    cnt = {}
    for c in map(int, input().split()):
        if c not in cnt:
            cnt[c] = 0
        cnt[c] += 1
    ans = 0
    for k in cnt:
        if k <= cnt[k]:
            ans += cnt[k]-k
        else:
            ans += cnt[k]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 65960
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    string ss[4] = {"dream", "dreamer", "erase", "eraser"};
    rep(i, 0, 4) {
        reverse(ss[i].begin(), ss[i].end());
    }
    int cur = 0;
    while (true) {
        rep(i, 0, 4) {
            if (s.substr(cur, ss[i].size()) == ss[i]) {
                cur += ss[i].size();
                break;
            }
            if (i == 3) {
                cout << "NO" << endl;
                return 0;
            }
        }
        if (cur == s.size()) {
            cout << "YES" << endl;
            return 0;
        }

    }
    return 0;
}


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

int main() {
	// your code goes here
	
	
	
	int n;
	cin>>n;
	int a[n] , b[n] , c[n] ;
	
	for(int i=0;i<n;i++)
	{
	    cin>>a[i]>>b[i]>>c[i];
	}
	
	int dp[n][3] ;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
            dp[i][j] = -1 ; 
    }
    
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    
    
    for(int i=1;i<n;i++)
    {
        dp[i][0] = (a[i] + max(dp[i-1][1] , dp[i-1][2]) );
        dp[i][1] = (b[i] + max(dp[i-1][0] , dp[i-1][2]) );
        dp[i][2] = (c[i] + max(dp[i-1][1] , dp[i-1][0]) );
    }
    
    cout<<max(dp[n-1][0] , max(dp[n-1][1] , dp[n-1][2]));
    
    
    
	return 0;
}


Measured memory_bytes: 5944
#include <stdio.h>

int main()
{
  char a[200],b[200];
  long int s,k;
  scanf("%s%s",a,b);
  strcat(a,b);
  k=atoi(a);
  s=(int)sqrt(k);
  if(k%s==0)
  {
      printf("Yes");
  }else{
      printf("No");
  }
 
    return 0;
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int,input().split()))
A += [0]

money = 1000
k = 0
for i in range(N):
    if A[i] <= A[i+1]:
        tmp = money // A[i]
        money -= tmp * A[i]
        k += tmp
    else:
        money += k * A[i]
        k = 0

print(money)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    fio();
    ll a;
    string b;
    cin >> a >> b;
    rep (i, b.size()) {
        if (b[i] == '.') {
            b.erase(b.begin() + i);
            break;
        }
    }
    ll bb = stol(b);
    cout << a * bb / 100 << endl;

}


Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int main(void){
    string split = "####################";
    int n;
    cin >> n;
    int b, f, r, v;
    int a[120];
    for (int i = 0; i < 120; i ++){
        a[i] = 0;
    }
    for (int i = 0; i < n; i ++){
        cin >> b >> f >> r >> v;
        int index = r + (f - 1) * 10 + (b - 1) * 30 - 1;
        a[index] += v;
    }
    for (int i = 1; i <= 120; i ++){
        if(i % 10 == 0){
            printf(" %d\n", a[i - 1]);
            if (i < 120 && i % 30 == 0)
                cout << split << endl;
        }else{
            printf(" %d", a[i - 1]);
        }
    }
    return 0;
}



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

using namespace std;

string solve() {

    int n, y;
    cin >> n >> y;

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            int k = n - i - j;
            if (k < 0) continue;
            int money = 10000 * i + 5000 * j + 1000 * k;
            if (money == y) {
                return to_string(i) + " " + to_string(j) + " " + to_string(k);
            }
        }
    }

    return "-1 -1 -1";
}

int main() {

    cout << solve() << endl;

    return 0;
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

#define N 100010

//1-indexed! 1-indexed!
vl bit(N + 1);
int n;

ll sum(int i) {
	ll s = 0;
	while (i > 0) {
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(int i, ll x) {
	while (i <= n) {
		bit[i] += x;
		i += i & -i;
	}
}

// 1,2,...,nを並び替えた順列をバブルソートで
// 順番通りにするための交換回数
ll bubble(vi p) {
	int n = p.size();
	ll ans = 0;
	for (int j = 0; j < n; j++) {
		ans += (j - sum(p[j]));
		add(p[j], 1);
	}
	return ans;
}

int main() {
	string s;
	cin >> s;
	n = s.size();
	int i, j;
	bit.resize(n + 1);
	vi num(26);
	for (i = 0; i < n; i++) {
		num[s[i] - 'a']++;
	}
	int ki = -1;
	for (i = 0; i < 26; i++) {
		if (num[i] % 2) {
			if (ki == -1) {
				ki = i;
			}
			else {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	vi p(n, -1);
	vi cnt(26);
	vi place(n);
	for (i = 0; i < n; i++) {
		int alpha = s[i] - 'a';
		cnt[alpha]++;
		if (alpha == ki) {
			if (cnt[alpha] <= num[alpha] / 2) {
				place[i] = 0;
			}
			else if (cnt[alpha] == num[alpha] / 2 + 1) {
				place[i] = 1;
			}
			else {
				place[i] = 2;
			}
		}
		else {
			if (cnt[alpha] <= num[alpha] / 2) {
				place[i] = 0;
			}
			else {
				place[i] = 2;
			}
		}
	}
	j = 0;
	for (i = 0; i < n; i++) {
		if (place[i] == 0) {
			p[j++] = i;
		}
		else if (place[i] == 1) {
			p[n / 2] = i;
		}
	}
	vi right(26);
	for (i = 0; i < n; i++) {
		right[s[i] - 'a'] = i;
	}
	for (i = 0; i < n / 2; i++) {
		int alpha = s[p[i]] - 'a';
		p[n - 1 - i] = right[alpha];
		for (j = right[alpha] - 1; j >= 0; j--) {
			if (s[j] - 'a' == alpha) {
				right[alpha] = j;
				break;
			}
		}
	}
	for (i = 0; i < n; i++) {
		p[i]++;
	}
	cout << bubble(p) << endl;
}

Measured memory_bytes: 4340
n, m = map(int, input().split())
xs = [tuple(map(int, input().split())) for _ in range(m)]

union = {x:(x, 0) for x in range(1, n+1)}
def root(n):
    if union[n][0] == n:
        return union[n]
    n1, d1 = union[n]
    n2, d2 = root(n1)
    union[n] = (n2, d2+d1)
    return union[n]

for l, r, d in xs:
    n1, d1 = root(l)
    n2, d2 = root(r)
    if n1 != n2:
        union[n2] = (n1, d + d1 - d2)
    elif d != d2 - d1:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 53108
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
using namespace std;
int mypow(int fa, int fb, int fc) {
	if (fb == 0)return 1;
	if (fb % 2)return mypow(fa, fb - 1, fc)*fa%fc;
	int z = mypow(fa, fb / 2, fc);
	return z * z%fc;
}
int k(int fa) {
	int x = 0;
	while (fa) {
		x++;
		fa /= 10;
	}
	return x;
}
int gcd(int fa, int fb) {
	if (fb == 0)return fa;
	return gcd(fb, fa%fb);
}
int a[50], b[50], c[50], d[50], n, m, q, z[10], ans = 0;
void mutu(int fn, int fm) {
	if (fn == 0) {
		int sum = 0;
		f(i, q) {
			if (z[b[i] - 1] - z[a[i] - 1] == c[i])sum += d[i];
		}
		ans = max(sum, ans);
		return;
	}
	for (int i = fm; i <= m; i++) {
		z[n - fn] = i;
		mutu(fn - 1, i);
	}
	return;
}
signed main() {
	int a, b;
	cin >> a >> b;
	if (a % 2) {
		f(i, b) {
			cout << i + 1 << " " << a - i << endl;
		}
		return 0;
	}
	int i = 0;
	for (; i < a / 4; i++) {
		cout << i + 1 << " " << a - i << endl;
		b--;
		if (b == 0)return 0;
	}
	for (int j = (a - 1) / 4; j >= 1; j--) {
		cout << i + 1 << " " << i + 1 + j * 2 << endl;
		b--;
		if (b == 0)return 0;
		i++;
	}
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int d,n;
    cin>>d>>n;
    int cnt=0;
    if(d==0){
        int cur=1;
        cnt=1;
        while(1){
            if(cnt==n){
                cout<<cur<<endl;
                return 0;
            }
            
            cur+=1;
            if(cur%100!=0)++cnt;
        }
    }
    else if(d==1){
        int cur=100;
        cnt=1;
        while(1){
            if(cnt==n){
                cout<<cur<<endl;
                return 0;
            }
            
            cur+=100;
            if(cur%10000!=0)++cnt;
        }
    }
    else{
        int cur=10000;
        cnt=1;
        while(1){
            if(cnt==n){
                cout<<cur<<endl;
                return 0;
            }
            
            cur+=10000;
            if(cur%1000000!=0)++cnt;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

vector<int> closest_less(const vector<int> &xs) {
    vector<int> res;
    vector<int> stack;
    for (int i = 0; i < xs.size(); ++i) {
        while (not stack.empty() and xs[stack.back()] >= xs[i]) {
            stack.pop_back();
        }
        if (stack.empty()) {
            res.push_back(0);
        } else {
            res.push_back(stack.back());
        }
        stack.push_back(i);
    }
    return res;
}

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

    int h, w;
    cin >> h >> w;
    vector<vector<bool>> board(h, vector<bool>(w));
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) {
            board[i][j] = s[j] == '#';
        }
    }

    vector<vector<bool>> dots(h + 1, vector<bool>(w + 1));
    for (int i = 1; i < h; ++i) {
        for (int j = 1; j < w; ++j) {
            dots[i][j] = board[i - 1][j - 1] != board[i - 1][j] != board[i][j - 1] != board[i][j];
        }
    }

    vector<vector<int>> widths(h + 1, vector<int>(w + 1));
    for (int i = 0; i < h + 1; ++i) {
        int next = w;
        for (int j = w; j >= 0; --j) {
            widths[i][j] = next - j;
            if (dots[i][j]) {
                next = j;
            }
        }
    }

    int ans = 0;
    for (int col = 0; col < w + 1; ++col) {
        vector<int> hist;
        for (int row = 0; row < h + 1; ++row) {
            hist.push_back(widths[row][col]);
        }
        vector<int> l = closest_less(hist);
        reverse(hist.begin(), hist.end());
        vector<int> r = closest_less(hist);
        reverse(hist.begin(), hist.end());
        for (int i = 0; i < h + 1; ++i) {
            int height = hist[i];
            int width = (i - l[i]) + ((h - i) - r[h - i]);
            ans = max(ans, height * width);
        }
    }

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

Measured memory_bytes: 17408
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main() {
  char str[200] ,key[11], end[] = "END_OF_TEXT";
  int c = 0, i;
  scanf("%s", key);
  for(i = 0; i < strlen(key); i++) {
    key[i] = tolower(key[i]);
  }
  while(1) {
    scanf("%s", str); 
    if(strcmp(str,end) == 0) break;
    for(i = 0; i < strlen(key); i++) {
      if(isupper(str[i])) {
        str[i] = tolower(str[i]);
      }
    }
    if(strcmp(str,key) == 0) {
      c++;
    }
  }
  printf("%d\n", c);
  return 0;
}

Measured memory_bytes: 552
#include<stdio.h>

int main(void){

	int h,w;
	int i,j;

	while(scanf("%d %d",&h,&w)!=EOF){

		if(h==0 && w==0)
			break;


		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(i%2==0){
					if(j%2 == 0)
						printf("#");
					else
						printf(".");
				}
				else{
					if(j%2 == 0)
						printf(".");
					else
						printf("#");
				}
			}
			puts("");
		}

		puts("");

	}

	return 0;

}

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

public class Main{
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  int n=sc.nextInt();
	  int[] a=new int[n];
	  boolean f=true;
	  for(int i=0;i<n;i++) {
		  a[i]=sc.nextInt();
		  if(a[i]%2!=0)f=false;
	  }
	  if(f) {
		  Arrays.sort(a);
		  int count=0;
		  while(f) {
			  count++;
			  for(int i=0;i<n;i++) {
				  a[i]/=2;
				  if(a[i]%2!=0)f=false;
			  }
		  }
		  System.out.println(count);
	  }else {
		  System.out.println(0);
	  }

  }
}



Measured memory_bytes: 21844