akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
string s4[4]={"aabc","ddbc","efgg","efhh"};
string s5[5]={"aabcc","d.bee","dffgg","hij..","hij.."};
string s6[6]={"aabc..","ddbc..","ef..gg","efhh..","..ijkk","..ijll"};
string s7[7]={"aa..bcc","d.e.b..","d.e..ff","gghhi..",".j.ki..",".j.k..l","..mmnnl"};
int n;
char ans[1005][1005];
int main(){
    cin >> n;
    if (n<=2){puts("-1");return 0;}
    else if (n==3){
        printf("..a\n..a\nbb.\n");return 0;
    } else {
        for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            ans[i][j]='.';
        for (int _=0;_<n/4-1;_++){
            int r=_*4;
            for (int i=0;i<4;i++)
                for (int j=0;j<4;j++)
                    ans[r+i][r+j]=s4[i][j];
        }
        int r=(n/4-1)*4;
        if (n%4==0){
            for (int i=0;i<4;i++)
                for (int j=0;j<4;j++)
                    ans[r+i][r+j]=s4[i][j];
        } else if (n%4==1){
            for (int i=0;i<5;i++)
                for (int j=0;j<5;j++)
                    ans[r+i][r+j]=s5[i][j];
        } else if (n%4==2){
            for (int i=0;i<6;i++)
                for (int j=0;j<6;j++)
                    ans[r+i][r+j]=s6[i][j];
        } else{
            for (int i=0;i<7;i++)
                for (int j=0;j<7;j++)
                    ans[r+i][r+j]=s7[i][j];
        }
        for (int i=0;i<n;i++){
            for (int j=0;j<n;j++) cout<<ans[i][j];cout<<endl;
        }
    }
}


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

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

typedef int F;
const F INF = 1e9+1e8;

const int N = 11111;
const int M = 111111;

int fst[N], nxt[M], to[M];
F cap[M];
int dis[N], q[N], ptr[N];
int V, E;

void init() {
	memset(fst, -1, sizeof fst);
	V = E = 0;
}
inline int add_node() {
	V++;
	return V-1;
}
inline void add_edge(int u, int v, F c) {
//	cout << u << ' ' << v << ' ' << c << '\n';
	to[E] = v, cap[E] = c, nxt[E] = fst[u], fst[u] = E++;
	to[E] = u, cap[E] = 0, nxt[E] = fst[v], fst[v] = E++;
}
inline bool bfs(int S, int T, int n) {
	memset(dis, -1, sizeof(int) * n);
	int h = 0, t = 0;
	dis[S] = 0, q[t++] = S;
	while (h < t) {
		int u = q[h++];
		for (int e = fst[u]; ~e; e = nxt[e]) if (cap[e] > 0 && dis[to[e]] == -1) {
				dis[to[e]] = dis[u] + 1, q[t++] = to[e];
				if (to[e] == T) return 1;
			}
	}
	return (dis[T] != -1);
}
F dfs(int u, int T, F f) {
	if (u == T) return f;
	for (int &e = ptr[u]; ~e; e = nxt[e]) if (cap[e] > 0 && dis[to[e]] > dis[u]) {
			F ret = dfs(to[e], T, min(f, cap[e]));
			if (ret > 0) {
				cap[e] -= ret, cap[e ^ 1] += ret;
				return ret;
			}
		}
	return 0;
}
F max_flow(int S, int T, int n = V) {
	F ret = 0;
	while (bfs(S, T, n)) {
		memcpy(ptr, fst, sizeof(int) * n);
		for (F cur; (cur = dfs(S, T, INF)) > 0; ret += cur);
	}
	return ret;
}


int a[105], b[105], c[105], d[105];

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i ++) cin >> a[i] >> b[i];
	for(int i = 0; i < n; i ++) cin >> c[i] >> d[i];
	init();
	int S = 0, T = 2 * n + 1;
	for(int i = 0; i < n; i ++) add_edge(S, i + 1, 1);
	for(int i = 0; i < n; i ++) add_edge(i + 1 + n, T, 1);
	for(int i = 0; i < n; i ++){
		for(int j = 0; j < n; j ++){
			if(a[i] < c[j] && b[i] < d[j]) {
//				cout << i << ' ' << j << '\n';
				add_edge(i + 1, n + 1 + j, 1);
			}
		}
	}
	int ans = max_flow(S, T, 2 * n + 5);
	cout << ans << '\n';
}

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

using namespace std;

int main()
{
    cout<<setprecision(10);
    int n;
    cin>>n;

    vector<double>a(n);

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

    double x=0.0;

    for(int i=0;i<n;i++)
    {
        x+=1.0/a[i];
    }
    cout<<fixed<<1.0/x<<endl;

}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
 
using namespace std;
 
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
 
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())
 
#define PB(a) push_back(a)
#define PF(a) pop_front(a)
 
#define MP(a,b) make_pair(a,b)
 
#define FS first
#define SE second
 
#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

//grobal var
//------------------------------------------
LL dp[2000][2000];

int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------
  int N,A,B;
  while(cin >> N >> A >> B){
    int ans = 0;
    cout << min(N*A,B) << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import math

tmp = list(map(int, input().split()))
n = tmp[0]
d = tmp[1]

x = [[0] * d for i in range(n)]
for i in range(n):
  tmp = list(map(int, input().split()))
  for j in range(d):
    x[i][j] = tmp[j]

cnt = 0
for i in range(n):
  for j in range(i+1, n):
    len = 0
    for k in range(d):
      len += (x[i][k] - x[j][k]) ** 2
    len = math.sqrt(len)
#    print('I=' + str(i) + ' J=' + str(j) + ' LEN=' + str(len))
    if len.is_integer():
      cnt += 1

print (cnt)

Measured memory_bytes: 38256
#include<stdio.h>
int G[105][105],d[105],f[105],color[105],n,time=0;
void visit(int u){
    //printf("%d\n",u);
    int i=1;

    color[u]=1;
    d[u]=++time;
    while(G[u][i]!=-1){
        if(color[G[u][i]]==0){
            visit(G[u][i]);
        }
        i++;
    }
    color[u]=2;
    f[u]=++time;
}

int main(){
    int k,i,j,unuse;
    scanf("%d",&n);
    for(i=1; i<=n; i++){
        scanf("%d %d",&unuse,&k);
        for(j=1; j<=k; j++){
            scanf("%d",&G[i][j]);
        }
        G[i][j]=-1;
    }

    for(i=0; i<n; i++){
        color[i]=0;
    }

    for(i=1; i<=n; i++){
        if(color[i]==0){
            visit(i);
        }
    }

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



    return 0;
}


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

int main() {
    string s;
    cin >> s;
    string c="CODEFESTIVAL2016";
    int count=0;
    for(int i=0;i<s.size();i++){
        if(s.at(i)!=c.at(i)) count++;
    }
    cout << count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    string s,t;
    cin >> s >> t;
    int s_size = s.size();
    int t_size = t.size();
    int rui_s[s_size + 1];
    int rui_t[t_size + 1];
    rui_s[0] = 0;
    rui_t[0] = 0;
    REP(i,s_size) rui_s[i+1] = rui_s[i] + int(s[i] == 'A');
    REP(i,t_size) rui_t[i+1] = rui_t[i] + int(t[i] == 'A');

    int q;
    cin >> q;
    REP(i,q){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        a--;
        b--;
        c--;
        d--;
        int anum = rui_s[b+1] - rui_s[a];
        int snum = anum - (b+1- a - anum);
        snum += 3 * s_size;
        anum = rui_t[d+1] - rui_t[c];
        int tnum = anum - (d+1 - c - anum);
        tnum += 3 * t_size;
        if( (snum % 3) == (tnum % 3) ){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }

}

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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) {
        cin >> d.at(i);
    }

    unordered_set<int> mochi;
    for (int i = 0; i < n; i++) {
        mochi.insert(d.at(i));
    }

    cout << mochi.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, k;
    cin >> n >> k;
    ll c0 = n/k;
    ll c1 = (n+k/2)/k;
    ll ans = c0*c0*c0;
    if(k%2==0){
        ans += c1*c1*c1;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int X;
    cin >> X;
    bool c[1001] = {false};
    c[1] = true;
    for (int i = 2; i * i <= X; i++) {
        for (int j = i; j <= X; j *= i) {
            c[j] = true;
        }
    }
    for (int i = X; i >= 1; i--) {
        if (c[i]) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  string N;
  cin >> N;
  int i = 0;
  ll ans = 0;
  while (N[i]){
    ans += N[i] - '0';
    i++;
  }
  if (ans % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int cnt[550][550];
ll sum[110*5][110*5];

int main(){cout<<fixed<<setprecision(10);
		   //O(m+nq)
           int n,m,Q;
           cin>>n>>m>>Q;
           int r,l;
           rep(i,0,m){
             cin>>l>>r;
             
             cnt[l][r]++;
           }
           rep(i,1,n+1){
            rep(j,1,n+1){
              sum[i][j]=sum[i][j-1]+cnt[i][j];
              //cout<<sum[i][j]<<" ";
            }
            // cout<<endl;
           }
           int p,q;
           ll ans;
           rep(i,0,Q){
             cin>>p>>q;
             ans=0;
             rep(j,p,n+1){
              ans+=sum[j][q]; 
               
             }
             cout<<ans<<endl;
           }
}

Measured memory_bytes: 6820
import java.util.Scanner;

public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
		int n = stdIn.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = stdIn.nextInt();
		}

		long stock = 0;
		long money = 1000;
		long yesterdayBoughtStock = 0;
		for(int i=0; i<n; i++){
			stock -= yesterdayBoughtStock;
			money += a[i] * yesterdayBoughtStock;
			if(i+1<n && a[i] < a[i+1]){
				stock += money / a[i];
				yesterdayBoughtStock = money / a[i];
				money -= yesterdayBoughtStock * a[i];
			}else{
				yesterdayBoughtStock = 0;
			}
		}
		System.out.println(money);
    }
}


Measured memory_bytes: 35876
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
	map<int,long> s;
  	long n,k; cin>>n>>k;
  	for(int i=0;i<n;i++){
      int a,b; cin>>a>>b;
      s[a]+=b;
    }
  	long jud=0,ans;
  	for(int i=1;i<=100000;i++){
		jud+=s[i];
      	if(jud>=k){
          ans=i; break;
        }
    }
  	cout<<ans<<endl;
  	return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<vector>
using namespace std;
class ListofTop3Hills{ 
    public:
        void solve(vector<int> m){
            for(int i=0;i<10;i++){ 
                for(int j=m.size()-1;j>0;j--){ 
                    if(m[j-1]<m[j]){ 
                        int tmp=m[j-1];
                        m[j-1]=m[j];
                        m[j]=tmp;
                    }
                }
            }
            for(int i=0;i<3;i++)cout<<m[i]<<endl;
        }
}; 
int main(){
    vector<int> m(10);
    for(int i=0;i<10;i++){ 
        cin>>m[i];
    }
    ListofTop3Hills inst;
    inst.solve(m);
    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>

using namespace std;

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdint.h>

using namespace std;

int32_t main()
{
  int32_t A, B;
  char op;
  cin >> A >> op >> B;

  if(op =='+'){
    cout << A + B << endl;
  } else{
    cout << A - B << endl;
  }

  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()
last_s = "0"
count = 0
A = []
for i, s in enumerate(S):
	if i == 0:
		count += 1
	else:
		if s != last_s:
			A.append(count)
			count = 0
		count += 1
	last_s = s

if count != 0:
	A.append(count)

A.append(0)
A.append(0)

val = 0

if S[0] == "0":
	val = sum(A[:2*K])
	currentMax = val
	old = A[0]
	new = sum(A[2*K:2*K+2])
	val += new - old
	if val > currentMax:
		currentMax = val
	
	for i in range(1, len(A)-2*K, 2):
		old_sum_of_two = sum(A[i:i+2])
		sum_of_two = sum(A[i+2*K+1:i+2*K+3])
		val += sum_of_two - old_sum_of_two
		if val > currentMax:
			currentMax = val
	print(currentMax)
else:
	val = sum(A[:2*K+1])
	currentMax = val
	for i in range(0, len(A)-2*K, 2):
		old_sum_of_two = sum(A[i:i+2])
		sum_of_two = sum(A[i+2*K+1:i+2*K+3])
		val += sum_of_two - old_sum_of_two
		if val > currentMax:
			currentMax = val
	print(currentMax)



Measured memory_bytes: 4596
// In the Name of Allah
// Ya Ali

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define F first
#define S second
#define all( x ) x.begin() , x.end()
#define pb push_back
#define mp make_pair

const int maxn = 510 ;
const int INF = 1e18 ;

int n , p[ maxn*maxn ] , dis[ maxn*maxn ] , rr , ans = 0 ;
vector< int > g[ maxn*maxn ] ;
bool mark[ maxn*maxn ] ;

int ver( int i , int j )
{
   if( i < 1 || i > n || j < 1 || j > n)
     return rr ;
   return ((i-1)*n) + j ;
}

void bfs( int root )
{
  deque< int > qu ;

  qu.pb( root ) ;

  while( qu.size()){

    int v = qu.front();
    qu.pop_front();

    for(auto uu : g[ v ]){
       int u = uu , w = mark[ v ] ;

       if( (dis[ v ] + w) < dis[ u ] ){
         dis[ u ] = dis[ v ]+w ;

         if( w == 0 )
          qu.push_front( u ) ;
         else
          qu.push_back( u ) ;

       }
    }

  }

}

signed main()
{
 ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

 cin >> n ;
 for(int i = 1 ; i <= n*n ; i ++){
   cin >> p[ i ] ;
   dis[ i ] = INF ;
   mark[ i ] = true ;
 }

 rr = (n*n)+1 ;

 dis[ rr ] = 0 ;

 for(int i = 1 ;i <= n ; i ++){
   for(int j = 1 ; j <= n ; j ++){
     int v = ((i-1)*n) + j ;
     int v1 = ver( i-1 , j ) , v2 = ver( i+1 , j ) , v3 = ver( i , j+1 ) , v4 = ver( i , j-1 ) ;
     g[ v ].pb( v1 ) ;
     g[ v1 ].pb( v ) ;
     g[ v ].pb( v2 ) ;
     g[ v2 ].pb( v ) ;
     g[ v ].pb( v3 );
     g[ v3 ].pb( v ) ;
     g[ v ].pb( v4 ) ;
     g[ v4 ].pb( v ) ;
   }
 }

 bfs( rr );

 for(int i = 1 ;i <= n*n ; i ++){
   ans += dis[ p[ i ] ] ;
   mark[ p[ i ] ] = false ;
   bfs( p[ i ] ) ;
 }

 cout << ans ;

    return 0;
}


Measured memory_bytes: 34428
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 998244353
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second1
using namespace std;
lol a,b,c,d;
int i[2000000];
int u[1000000];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,w;
  cin >>a>>b;
  if(a%b==0) cout <<a/b<<'\n';
  else cout <<a/b+1<<'\n';
  return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int a;
  cin >> a;
  cout << (a) + (a * a) + (a * a * a) << endl;
  return 0;
}

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

int main() {
  int N, num;
  int *B;
  cin >> N;
  B = (int*)malloc(sizeof(int) * N);
  for(int i = 0; i < N-1; i++){
  	cin >> num;
    B[num-1]++;
  }
  for(int i = 0; i < N; i++)cout << B[i] << endl;
}


Measured memory_bytes: 4384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  vll v(n);
  REP(i, n) cin >> v.at(i);
  ll ans = 0;
  REP(i, n) {
    ll mini = i;
    rep(j, i, n) {
      if (v.at(j) < v.at(mini)) mini = j;
    }
    swap(v.at(i), v.at(mini));
    if (mini != i) ans++;
  }
  cout << v.at(0);
  rep(i, 1, n) cout << ' ' << v.at(i);
  cout << endl;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
//#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void _main()
{
    COMinit();

    ll N, M, K;
    cin >> N >> M >> K;

    ll ansX = 0;
    for (ll i = 1; i < M; ++i)
    {
        ansX += i * (M - i) * (N * N);
        ansX %= MOD;
    }
    ansX *= COM(N * M - 2, K - 2);
    ansX %= MOD;

    ll ansY = 0;
    for (ll i = 1; i < N; ++i)
    {
        ansY += i * (N - i) * (M * M);
        ansY %= MOD;
    }
    ansY *= COM(N * M - 2, K - 2);
    ansY %= MOD;

    cout << (ansX + ansY) % MOD << endl;
}


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

int main() {
  int A, B, C, X=0;
  cin >> A >> B >> C;
  for  (int i=1; i<100; i++){
    if(A*i%B==C){
      X=1;
      break;
    }
  }
  if(X==1) cout << "YES" << endl;
  else cout << "NO" << endl;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <string>
#include <sstream>
#include <cstring>
#include <cmath>

using namespace std;

#ifdef DEBUG
#define LOG(args) cout << args << "\n"
#define debug(x) x
#else
#define LOG(args)
#define debug(x)
#endif

#define vi vector<int>
#define ii pair<int, int>
#define vii vector< ii >
#define vvi vector< vi >
#define mp make_pair
#define pb push_back
#define ms(x, v) memset(x, v, sizeof(x))
#define all(x) x.begin(), x.end()
#define REP(x, n) for(int x = 0; x < n; x++)
#define REPV(x, v, n) for(int x = v; x < n; x++)
#define REVE(x, n) for(int x = n; x >= 0; x--)

typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	unordered_map<string, int> u;
	string verdicts[] = {"AC", "WA", "TLE", "RE"};
	int N;
	string str;
	cin >> N;
	while(N--)
	{
		cin >> str;
		u[str]++;
	}	
	REP(i, 4)
	{
		cout << verdicts[i] << " x " << u[verdicts[i]] << "\n";
	}
	return 0;
}


Measured memory_bytes: 3480
#include <stdio.h>

int main(){
  int N;
  int A[200000];
  long long int B[200001];
  long long int sum;
  
  scanf("%d",&N);
  for(int i=0;i<N;i++)
    scanf("%d",&A[i]);

  for(int i=1;i<=N;i++)
    B[i] = 0;

  for(int i=0;i<N;i++)
    B[A[i]] += 1;

  sum = 0;
  for(int i=1;i<=N;i++)
    sum += B[i]*(B[i]-1)/2;

  for(int i=0;i<N;i++)
    printf("%lld\n", sum-(B[A[i]]-1) );

  return 0;
}


Measured memory_bytes: 4864
from collections import Counter
w=str(input())
li=Counter(w)
for i in range(len(w)):
    word=w[i]
    if i==len(w)-1:
        if li[word] % 2 == 0:
            print('Yes')
            break
        else:
            print('No')
            break
    if li[word]%2==0:
        continue
    else:
        print('No')
        break

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

int main(void){
    int a, k, t, n, x, y, i, ans=0;
    scanf("%d", &n);
    int v[n], c[n];
    for(i=0; i<n; i++) scanf("%d", &v[i]);
    for(i=0; i<n; i++) scanf("%d", &c[i]);

    for(i=0; i<n; i++){
        if(v[i]-c[i] > 0) ans += v[i]-c[i];
    }
    printf("%d", ans);
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main{

	public static void main(String[] args) throws Exception{
		Scanner stdIn = new Scanner(System.in);
		Long n = stdIn.nextLong();
		Long min = Long.MAX_VALUE;

		for(int i = 1; i <= Math.sqrt(n); i++) {
			if(n%i == 0) {
				long b = n/i; //商
				long c = compare(i,b);
				if(min > c) {
					min = c;
				}
			}

		}
		System.out.println(min);

	}
	static long compare(long a, long b) {  //移動回数の合計を出すメソッド
		long count = 0;
		count += a-1;
		count += b-1;
		return count;
	}


}


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

using namespace std;

int main() {
    long long w, h, x, y;
    int isNotOnly;
    double ans;
    cin >> w >> h >> x >> y;
    ans = double(w) * double(h) / 2;
    if (w == x * 2 && h == y * 2)
        isNotOnly = 1;
    else
        isNotOnly = 0;

    printf("%12lf %d\n", ans, isNotOnly);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int sum(int x)
{
    int tot = 0;
    while(x > 0){tot += x % 10; x /= 10;}
    return tot;
}
int main(){
    int x;
    cin >> x;
    if(x % sum(x) == 0)
        cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main (){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a+b>c+d) cout << "Left" << endl;
    else if (a+b<c+d) cout << "Right" << endl;
    else cout << "Balanced" << endl;
    return 0;
}


Measured memory_bytes: 256
//Name: Pankaj Mandrawal (pankaj_m05)
//Problem: OCD
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define INF LLONG_MAX
#define NINF LLONG_MIN
#define mod 10000000009
#define sz(c) int((c).size())
#define sortall(x) sort(all(x))         
#define PI 3.1415926535897932384626     
#define all(c) (c).begin(), (c).end()
#define clr(x) memset(x, 0, sizeof(x))  
#define MAX32 numeric_limits< int >::max() 
#define MIN32 numeric_limits< int >::min()
#define rall(c) (c).rbegin(), (c).rend()
#define deb(x) cerr << #x << " = " << x << endl
#define forn(i, n) for(int i = 0; i < (int)n; ++i)
#define for1(i, n) for(int i = 1; i <= (int) n; ++i)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = (int)(l); i < (int)(r); ++i)
#define tr(c, it) for(typeof(c).begin() it = c.begin(); it != c.end(); it++)
#define deb2(x, y) cerr << #x << " = " << x << "," << #y << " = " << y << endl

using namespace std;

typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vill;
typedef pair < int, int > pi;
typedef unsigned long long int ull;

ll mypow(ll x, ll y) { 
    if (y == 0) 
        return 1; 
    ll p = mypow(x, y / 2) % mod; 
    p = (p * p) % mod; 
    if (!(y & 1)) 
        return p;
    return (p * x) % mod; 
} 

queue< ll > q;

void precomp() {
	for1(it, 9)
		q.push(it);
}
void plssolve() {
	int k; cin >> k;
	if(k < 10) {
		cout << k << '\n';
		return;
	}
	precomp();
	ll ans = 0;
	while(k--) {
		ans = q.front(); q.pop();
		if(ans % 10)
		   q.push((10 * ans + (ans % 10) - 1));
		q.push((10 * ans + (ans % 10)));
		if(ans % 10 != 9) 
			q.push((10 * ans + (ans % 10) + 1));
	}
	cout << ans << '\n';
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    cout << fixed;
    int t = 1;
    // cin >> t;
    while(t--) {
        plssolve();
    }
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
#include <vector>
#include <string>
#include <limits.h>

int main() {	long long N;
	cin >> N;
	long long n = 0;

	for (int i = 1; i < 1000000; i++) {
		if (N % i == 0) {
			if (N / i - 1 > i) {
				n = n + N / i - 1;
			}
		}
	}
	cout << n;
}

Measured memory_bytes: 384
S=input()
flag=0
for i in range(len(S)):
    if i%2==1:
        if not (S[i]=='L' or S[i]=='U' or S[i]=='D'):
            flag=1
    if i%2==0:
        if not (S[i]=='R' or S[i]=='U' or S[i]=='D'):
            flag=1
if flag==0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    string s,ss;
    int n,ans=0;
    cin>>s>>n;
    for(int i=0;i<n;++i){
        cin>>ss;
        if(ss.find(s)!=string::npos){
            ++ans;continue;
        }
        int sl=ss.size();
        for(int j=sl-s.size()+1;j<sl;++j){
            for(int k=0;k<s.size();++k){
                if(ss[(j+k)%sl]!=s[k]) break;
                if(k==s.size()-1){
                    ++ans;break;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	ll N, K;
	cin >> N >> K;
	map<ll, ll> m;
	rep(i, 0, N) {
		int a, b;
		cin >> a >> b;
		m[a] += b;
	}

	ll sum = 0;
	for(map<ll, ll>:: iterator it = m.begin(); it != m.end(); it++) {
		sum += it->second;
		if(sum >= K) {
			cout << it->first << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

////const long long MOD = 1000000007;
//
void solve(long long N, std::string S){
  vec(a,2*N);
  ll tmp=0;
  rep(i,2*N){
    if(tmp==0){
      if(S[i]=='B'){
        tmp++;
        a[i]=1;
      }else{
        op(0)
        return;
      }
    }else if(tmp%2){
      if(S[i]=='W'){
        tmp++;
        a[i]=1;
      }else{
        tmp--;
        a[i]=0;
      }
    }else if(tmp%2==0){
      if(S[i]=='W'){
        tmp--;
        a[i]=0;
      }else {
        tmp++;
        a[i]=1;
      }
    }
  }
  if(tmp!=0){
    op(0)
    return;
  }
  
  ll cnt=0;
  ll ans=1;
  rep(i,2*N){
    //op(a[i])
    if(a[i]==0){
      ans*=cnt;
      cnt--;
      ans%=MOD;
    }else{
      cnt++;
    }
  }
  repf(i,1,N+1){
    ans*=i;
    ans%=MOD;
  }
  op(ans)
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 2308
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  vector<int> a;

  int n,num;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num;
    a.push_back(num);
  }

  int q,b,e,k;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b;
    cin >> e;
    cin >> k;

    auto itr_s = a.begin();
    auto itr_e = a.begin();

    for (int i=0;i<b;i++){
      itr_s++;
    }
    for (int i=0;i<e;i++){
      itr_e++;
    }

    int ans = count(itr_s, itr_e,k);
    cout << ans << endl;
  }
  return 0;
}



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

queue<int> clear(){
    queue<int> q;
    return q;
}

int main(){
    int H, W; cin >> H >> W;
    int grid[H][W];
    queue<int> QR, QC;
    for(int i = 0; i < H; i++){
        string X; cin >> X;
        for(int j = 0; j < W; j++){
            if(X[j] == '.') { 
                grid[i][j] = 1; 
            }
            else if(X[j] == '#') { 
                grid[i][j] = 0; 
            }
        }
    }
    int cnt = 0;
    int stepR[4] = {1, 0, -1, 0};
    int stepC[4] = {0, 1, 0, -1};
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(grid[i][j] == 0){
                QR.push(i); QC.push(j);
            }
        }
    }
    while(!QR.empty()){
        //各ステップことにgridが全部黒になっていないか確認
        int Qcnt = QR.size();
        cnt++;
        for(int i = 0; i < Qcnt; i++){
            int r = QR.front();
            int c = QC.front();
            QR.pop(); QC.pop();
            for(int j = 0; j < 4; j++){
                int nextR = r + stepR[j];
                int nextC = c + stepC[j];
                if(0 <= nextR && nextR < H && 0 <= nextC && nextC < W){
                    if(grid[nextR][nextC] == 1){
                        grid[nextR][nextC] = 0;
                        QR.push(nextR); QC.push(nextC);
                    }
                }
            }
        }
    }
    cout << cnt-1 << endl;
}

Measured memory_bytes: 12288
numberN = int(input())
seqAi = list(map(int,input().split()))
benefitBi = list(map(int,input().split()))
increaseCi = list(map(int,input().split()))

# print(numberN)
# print(seqAi)
# print(benefitBi)
# print(increaseCi)

totalBenefit = 0
for k,seq in enumerate(seqAi):

    totalBenefit += benefitBi[seq -1]

    if k == 0:
        continue

    if seq == ( seqAi[k -1] +1 ):
        totalBenefit += increaseCi[seq -2]

print(totalBenefit)

Measured memory_bytes: 3064
N,M = (int(a) for a in input().split())
H = list(map(int,input().split()))
ans = [0]*N
for i in range(M) :
    A,B = (int(a) for a in input().split())
    if H[A-1] == H[B-1] :
        ans[A-1] = 1
        ans[B-1] = 1
    elif H[A-1] < H[B-1] :
        ans[A-1] = 1
    else :
        ans[B-1] = 1
print(ans.count(0))
    


Measured memory_bytes: 19996
N,M = list(map(int,input().split()))
sc = [list(map(int,input().split())) for i in range(M)]

import sys

if M == 0:
    if N == 1:
        print(0)
        sys.exit()
 
number = [[i for i in range(10)] for i in range(N)]
number[0].pop(0)

n_count = [0]*N
 
for i in range(M):
    if n_count[sc[i][0]-1] > 0:
        if sc[i][1] != number[sc[i][0]-1][-1]:
            print(-1)
            sys.exit()
    
    number[sc[i][0]-1].append(sc[i][1])
    n_count[sc[i][0]-1] += 1
    
if N != 1 and number[0][-1] == 0:
    print(-1)
    sys.exit()

for i in range(N):
    if n_count[i] > 0:
        print(number[i][-1],end='')
    else:
        print(min(number[i]),end='')

Measured memory_bytes: 3064
use std::io::*;
use std::str::*;
use std::collections::*;

pub fn read_from<T: FromStr, R: Read>(s: &mut R) -> T {
    let s = s.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    if !s.is_empty() {
        if let Ok(s) = s.parse::<T>() {
            s
        } else {
            panic!("faild to parse {}", s);
        }
    } else {
        if cfg!(local) {
            // eprintln!("reached to EOF");
        }
        std::process::exit(0)
    }
}

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    read_from(&mut stdin)
}

fn main() {
    loop {
        let h: usize = read();
        let w: usize = read();
        let g: Vec<Vec<i32>> = (0..h).map(|_| (0..w).map(|_| {
            read()
        }).collect()).collect();

        let mut route = vec![];
        let mut ans = vec![];

        for i in 0..h {
            let js: Vec<_> = if i % 2 == 0 { (0..w).collect() } else { (0..w).rev().collect() };
            for j in js {
                if g[i][j] % 2 == 1 {
                    route.push((i, j));
                    if route.len() >= 2 {
                        for pair in route[..].windows(2) {
                            let (fi, fj) = pair[0];
                            let (ti, tj) = pair[1];
                            ans.push((fi, fj, ti, tj));
                        }
                        route.clear();
                    }
                } else {
                    if !route.is_empty() {
                        route.push((i, j));
                    }
                }
            }
        }

        println!("{}", ans.len());
        for &(fi, fj, ti, tj) in ans.iter() {
            println!("{} {} {} {}", fi+1, fj+1, ti+1, tj+1);
        }
    }
}


Measured memory_bytes: 12788
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
using namespace std;

int k;
int dist[100005];
priority_queue<pair<int,long long> > q;

int main(){
	cin>>k;
	for(int i=0;i<k;i++) dist[i]=1e9+7;
	q.push(make_pair(-1,1));
	while(!q.empty()){
		int s=-q.top().first;
		long long l=q.top().second;
		q.pop();
		if(s<dist[l*10%k]){
			dist[l*10%k]=s;
			q.push(make_pair(-s,l*10%k));
		}
		if(s+1<dist[(l+1)%k]){
			dist[(l+1)%k]=s+1;
			q.push(make_pair(-s-1,(l+1)%k));
		}
	}
	cout<<dist[0]<<endl;
	return 0;
}

Measured memory_bytes: 1784
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    char c;
  
  while(1){
      cin >> a >>c >>b;
      
      if(c=='?') break;
      else if(c=='+') cout << a+b <<endl;
      else if(c=='-') cout << a-b <<endl;
     else if(c=='*')  cout <<a*b <<endl;
     else cout <<a/b <<endl;
}

}


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

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

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

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

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

// --------------------------------------
int n;
int s[20];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) {
    cin >> s[i];
  }

  int ans = 0;
  for(int i = 0; i + 2 < n; i++) {
    if(s[i] < s[i + 1] && s[i + 1] < s[i + 2] || s[i + 1] < s[i] && s[i + 2] < s[i + 1]) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    int N;
    cin>>N;
    vector<ll>vec(N*3);
    for(int i=0;i<N*3;i++)cin>>vec[i];
    
    priority_queue<ll, vector<ll>, greater<ll> >fq;
    vector<ll>front(N*3, 0);
    for(int i=0;i<N;i++){
        fq.push(vec[i]);
        front[N-1]+=vec[i];
    }
    for(int i=N;i<N*2;i++){
        fq.push(vec[i]);
        front[i] = front[i-1] + vec[i] - fq.top();
        fq.pop();
    }

    priority_queue<ll>bq;
    vector<ll>back(N*3, 0);
    for(int i=2*N;i<3*N;i++){
        bq.push(vec[i]);
        back[2*N]+=vec[i];
    }
    for(int i=2*N-1;i>=N;i--){
        bq.push(vec[i]);
        back[i] = back[i+1] + vec[i] - bq.top();
        bq.pop();
    }

    ll ans = front[N-1] - back[N];
    for(int i=N;i<N*2;i++){
        ans = max(ans, front[i] - back[i+1]);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 9588
#include<iostream>
#include<algorithm>
#include<climits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
int n;
char s[310][310];

int main(){
  scan(n);
  rep(i,n){
    rep(j,n){
      scan(s[i][j]);
    }
  }
  int res=0;
  rep(i,n){
    bool f=true;
    rep(j,n-1){
      for(int k=j+1;k<n;k++){
	if(s[(j+i)%n][k%n]!=s[(k+i)%n][j%n]){
	  f=false;
	}
      }
    }
    if(f){
      res+=n;
    }
  }
  prin(res);

  return 0;
}


Measured memory_bytes: 384
abc = sorted(list(map(int,input().split())))
x = abc[0]
y = abc[1]
z = abc[2]
cnt = (z-x)//2 + (z-y)//2
if z == 2*((z-x)//2)+x and z == 2*((z-y)//2)+y:
    print(cnt)
elif z > 2*((z-x)//2)+x and z > 2*((z-y)//2)+y:
    print(cnt + 1)
else:
    print(cnt + 2)

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

int main() {
  int x;
  cin>>x;
  
  vector<bool> p(x+1001,true);
  p[0] = p[1] = false;
  
  for(long long i=3; i<x+1001; i+=2) {
    if(p[i]) {
      for(long long j=i*i; j<x+1001; j+=i)
        p[j] = false;
    }
  }
  
  for(int i=x; i<x+1001; i++) {
    if((i%2 || i==2) && p[i]) {
      cout<<i<<endl;
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
from collections import deque as D 
d = D()
s=input();q=int(input())
ans=0
d.extend(list(s))
for i in range(q):
  k=list(input().split())
  if len(k)==1:
    ans=(ans+1)%2
  else:
    x,y,z=k
    y=(int(y)-1+ans)%2
    d.append(z) if y else d.appendleft(z)
print("".join(list(d)[::(-1)**ans]))

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

int main()
{
    string S;
    cin >> S;
    auto year  = stoi(S.substr(0,4));
    auto month = stoi(S.substr(5,2));
    auto day   = stoi(S.substr(8,2));
    if(year * 12 * 31 + month * 31 + day
    <= 2019 * 12 * 31 +     4 * 31 + 30){
        cout<<"Heisei"<<endl;
    }else{
        cout<<"TBD"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll a,b,x;
    cin>>a>>b>>x;
    ll p=a/x;
    ll q=b/x;
    if(a%x==0)cout<<q-p+1<<endl;
    else cout<<q-p<<endl;
    return 0;
}


Measured memory_bytes: 256
if __name__ == '__main__':
	n,m = map(int,input().split())
	a = []
	b = []
	c = []
	for i in range(n):
		a.append([int(s) for s in input().split()])
		c.append(0)
	for i in range(m):
		b.append(int(input()))
	
	for i in range(n):
		ans = 0
		for k in range(m):
			ans = ans + a[i][k]*b[k]
		c[i] = ans

	for i in range(n):
		print(c[i]) 


Measured memory_bytes: 6016
#include<iostream>
using namespace std;
typedef long long ll;

const ll INF = 1LL << 40;

int main() {
    ll N, S;
    cin >> N >> S;
    if (N == S) {
        cout << N + 1 << endl;
        return 0;
    }
    // 2からsqrt(N)までのbを探索
    for (ll b = 2; b * b <= N; b++) {
        ll ans = 0, tmp = N;
        while (tmp > 0) {
            ans += tmp % b;
            tmp /= b;
        }
        if (ans == S) {
            cout << b << endl;
            return 0;
        }
    }
    // sqrt(N)からNまでのbを探索
    ll min_b = INF;
    for (ll p = 1; p * p <= N; p++) {
        if ((N - S) % p != 0) continue;
        ll b = 1 + (N - S) / p, tmp = N, ans = 0;
        if (b == 0) continue;
        while (tmp > 0) {
            ans += tmp % b;
            tmp /= b;
        }
        if (ans == S) min_b = min(min_b, b);
    }
    if (min_b != INF) cout << min_b << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int,input().split())
A = [int(i) for i in input().split()]
cnt = 0
flag = False
A = sorted(A)[::-1]
for a in A:
  if a >= sum(A)*(1/(4*m)):
    cnt += 1
  if cnt == m:
    flag = True
    break
if flag:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3060
# ABC141-D
import heapq
n, m = [int(x) for x in input().split()]
h = [-int(x) for x in input().split()]
heapq.heapify(h)
for i in range(m):
    x = heapq.heappop(h)
    heapq.heappush(h, -(-x//2))
z = 0
print(-sum(h))

Measured memory_bytes: 72216
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<Pll> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){
  ll r, D, x;
  cin >> r >> D >> x;
  ll X = x;
  rep(i,0,10){
    X = r*X-D;
    print(X);
  }

 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl '\n'

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

bool palin_fun(ll a)
{
    ll arr[10],i=0;
    while(a>0)
    {
        arr[i]=a%10;
        a/=10;
        i++;
    }
    if(arr[0]==arr[4] && arr[1]==arr[3]) return 1;
    else return 0;
}


int main()
{
    ll a,b,cnt=0,i;
    cin>>a>>b;
    for(i=a;i<=b;i++)
    {
        if(palin_fun(i))
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


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

int main() {
  int H, W;
  string s = "";
  cin >> H >> W;
  vector<string> pic(H);
    for (int i = 0; i < H; i++) {
      cin >> pic.at(i);
    }
    for (int j = 0; j < W + 2; j++) {
        s += '#';
    }
    cout << s << endl;
    for (int k = 0; k < H; k++) {
        cout << '#' << pic.at(k) << '#' << endl;
    }
    cout << s << endl;
}

Measured memory_bytes: 256
N,Q=map(int,input().split())
S=list(input())

L=[]

for i in range(1,N):
    if S[i-1]=="A" and S[i]=="C":
        L.append(1)
    else:
        L.append(0)
        
A=[L[0]]
for i in range(1,len(L)):
    A.append(L[i]+A[i-1])
A=[0]+A
#print(A)

for i in range(Q):
    l,r=map(int,input().split())
    print(A[r-1]-A[l-1])
#print(A)
    

Measured memory_bytes: 9496
from operator import mul
from functools import reduce

n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)

cnt = 1
if 0 in a:
    print(0)
    exit()

for i in range(len(a)):
    cnt *= a[i]
    if cnt > 10 ** 18:
        print(-1)
        exit()
print(cnt)


Measured memory_bytes: 83820