akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const int INF = 1e9;

int main() {
  int s, w;
  cin >> s >> w;
  if (w >= s) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
}


Measured memory_bytes: 3636
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,x;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	x=a*1+b*5+c*10+d*50+e*100+f*500;
	if(x>=1000) printf("%d\n",1);	
	else printf("%d\n",0);
	return 0 ;
}


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

int main() {
  int N;
  int64_t Li, Li1, Li2;
  Li  = 0;
  Li1 = 1;
  Li2 = 2;
  cin >> N;
  
  if (N == 1){
  	cout << 1 << endl;
  }
  else{
   for (int i = 2; i <=N; i++){
  		Li = Li1 + Li2;
     	Li2 = Li1;
     	Li1 = Li;     	
  	}
    cout << Li << endl;
  }
}

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

signed main(){
    ll k,a,b;
    cin >> k >> a >> b;
    ll t = (k - (a - 1)) / 2;
    cout << max(k + 1, k - t * 2 + 1 + t * (b - a)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	int a, b;
	cin >> a >> b;
	cout << a * b - a - b + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * @author yoshizaki
 * EDCP A
 */
public class Main {

    
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        // 休日の数
        int vacation = scanner.nextInt();
        // 幸福度の配列
        long[][] happy = new long[110000][3];
        // DP用配列
        long[][] dp = new long[110000][3];
        for(int i = 0; i < vacation; i++) {
            for(int j = 0; j < 3; j++) {
                happy[i][j] = scanner.nextInt();
            }
        }
        
        for (int i = 0; i < vacation; i++) {
            for (int j =0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    if(j == k) continue;
                    if(dp[i + 1][k] < dp[i][j]+happy[i][k]) dp[i + 1][k] = dp[i][j]+happy[i][k];
                }
            }
        }
        long answer = 0;
        for(int i = 0; i < 3; i++) {
            if(answer < dp[vacation][i]) answer = dp[vacation][i];
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 104828
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const double PI = acos(-1.0);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int c[4];
int d[4];

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    rep(_,10000000) {
        int N; cin >> N;
        if (!N) break;
        rep(i,4) cin >> c[i];
        int p = 10*c[0] + 50*c[1] + 100*c[2] + 500*c[3] - N;
        d[3] = p / 500;
        p %= 500;
        d[2] = p / 100;
        p %= 100;
        d[1] = p / 50;
        p %= 50;
        d[0] = p / 10;
        if (_) cout << ln;
        if (max(0,c[0] - d[0])) cout << "10 " << c[0] - d[0] << ln;
        if (max(0,c[1] - d[1])) cout << "50 " << c[1] - d[1] << ln;
        if (max(0,c[2] - d[2])) cout << "100 " << c[2] - d[2] << ln;
        if (max(0,c[3] - d[3])) cout << "500 " << c[3] - d[3] << ln;
    }
}


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

using namespace std;

int main(void)
{
	int r,g,b;

	cin >> r >> g >> b;

	int x = 100*r+10*g+b;

	if(x%4==0)
	{
		cout << "YES" << '\n';
	}
	else
	{
		cout << "NO" << '\n';
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define rep(i,n,f) for (int i = n; i < f; i++)
#define rap(i,n,f) for (int i = n; i > f; i--)
#define inf 1e9+9
 
using namespace std;
 
const int maxn = 3e4 + 10;
double ans,a[maxn],dp[2999][2999];
int n;

int main(){
	cout<<setprecision(15)<<fixed;
	cin >> n;
	rep(i,0,n){
		cin >> a[i];
	}
	rep(i,0,n+1){
		rep(j,0,n+1){
			if(i == j and i == 0){
				dp[i][j] = 1;
			}
			if(j > i){
				dp[i][j] = 0;
			}
			if(i != 0 and j == 0){
				dp[i][j] = dp[i-1][j] * (1-a[i-1]);
			}
			if(i >= j and i != 0 and j != 0){
				dp[i][j] = (dp[i-1][j-1] * a[i-1]) + (dp[i-1][j] * (1-a[i-1]));
			}
		}
	}
	int f = n/2 + 1;
	rep(i , 0 , n-f+1){
		ans += dp[n][f+i];
	}
	cout << ans << endl;
}



Measured memory_bytes: 70528
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<climits>
#include<cfloat>
#include<cstdio>
#define curr(P, i) P[(i) % P.size()]
#define next(P, i) P[(i+1) % P.size()]
#define prev(P, i) P[(i+P.size()-1) % P.size()]

using namespace std;

struct point{ double x, y; };

double areaPol(vector<point> t){
  double area=0;
  for(int i=0;i<t.size();i++){
    area+=(curr(t,i).x-next(t,i).x)*(curr(t,i).y+next(t,i).y);
  }
  return abs(area)/2.0;
}

int main(void){
  int n,turn=1;
  point p;
  vector<point>t;

  while(cin >> n,n){
    t.clear();
    for(int i=0;i<n;i++){
      cin >> p.x >> p.y;
      t.push_back(p);
    }
    printf("%d %.1f\n",turn++,areaPol(t));
  }

  return 0;
}

Measured memory_bytes: 1264
N, Y = map(int, input().split())
 
for x in range(N + 1):
    for y in range(N + 1- x):
        z=N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print(x,y,z)
            exit()
print('-1 -1 -1')

Measured memory_bytes: 9144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
int main() {
  int n;
  cin >> n;
  int zero = 0;
  map<pair<ll,ll>,P> mp;
  rep(i,n) {
    ll x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) {
      zero++;
      continue;
    }
    ll g = gcd(x,y);
    x /= g;
    y /= g;
    if (y < 0) x = -x, y = -y;
    if (y == 0 && x < 0) x = -x, y = -y;
    bool rot90 = (x <= 0);
    if (rot90) {
      ll tmp = x;
      x = y; y = -tmp;
    }
    if (rot90) mp[{x,y}].first++;
    else mp[{x,y}].second++;
  }
 
  mint ans = 1;
  for (auto p : mp) {
    int s = p.second.first;
    int t = p.second.second;
    mint now = 1;
    now += mint(2).pow(s) - 1;
    now += mint(2).pow(t) - 1;
    ans *= now;
  }
  ans -= 1;
 
  ans += zero;
  cout << ans << endl;
  return 0;
}

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

long long f(long long n);

long long a, b, x;
int main() {
    cin >> a >> b >> x;
    
    cout << f(b) - f(a - 1) << endl;
}

long long f(long long n) {
    if(n == -1) return 0;
    
    return n / x + 1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    //解は[l,r)に存在する
    int l = -1, r, N;
    //各席の状況
    map<int, int> mp;
    cin >> N;
    while(true){
        int n;
        if(l == -1) n = 0;
        else n = (l+r)/2;
        cout << n << endl;
        string s;
        cin >> s;
        if(s == "Vacant") break;
        elif(s == "Male") mp[n] = 0;
        else mp[n] = 1;
        if(l == -1) l = 0, r = N;
        else{
            if(((n-l)&1)^mp[l]^mp[n]) r = n;
            else l = n;
        }
    }
}

Measured memory_bytes: 852
input = readlines()

total = input.shift().chomp.to_i

list = input.shift().chomp.split("\s").map{|x| x.to_i}

res = nil

list.sort().each do |l|
  if res.nil?
    res = l
    next
  end
  res *= l
  if res > 10**18
    puts '-1'
    exit()
  end
end

puts res

Measured memory_bytes: 23192
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

int main()
{
    int x;
    cin>>x;
    if(x>=400 and x<=599) cout<<8<<endl;
    if(x>=600 and x<=799) cout<<7<<endl;
    if(x>=800 and x<=999) cout<<6<<endl;
    if(x>=1000 and x<=1199) cout<<5<<endl;
    if(x>=1200 and x<=1399) cout<<4<<endl;
    if(x>=1400 and x<=1599) cout<<3<<endl;
    if(x>=1600 and x<=1799) cout<<2<<endl;
    if(x>=1800 and x<=1999) cout<<1<<endl;
    return 0;
}


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

int main(){
    int n,ans;
    string x;
    cin>>n;
    vector<string> s(n);
    vector<int> t(n);
    rep(i,n){
        cin>>s[i]>>t[i];
    }
    cin>>x;
    bool b= false;
    rep(i,n){
        if(s[i]==x){
            b= true;
            continue;
        }
        if(b){
            ans+=t[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System.Linq;
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        var science = new List<int>();
        for (int i = 0; i < 4; i++)
              science.Add( int.Parse(Console.ReadLine().Trim()));
        var gh1 = int.Parse(Console.ReadLine().Trim());
        var gh2 = int.Parse(Console.ReadLine().Trim());
        var ans = science.OrderBy(x => x).Skip(1).Sum() + Math.Max(gh1, gh2);
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 9996
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int power(int x, unsigned int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 
int mx[1000005];
int fr[1000005];
int mod=1e9+7;
signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
//  #ifndef ONLINE_JUDGE
//     freopen ("INPUT.txt" , "r" , stdin);
//     freopen ("OUTPUT.txt" , "w" , stdout);
//  #endif

// -------------------------------------Code starts here---------------------------------------------------------------------     

   int n,m;
   cin>>n>>m;
   string str1="",str2="";
   for(int i=0;i<n;i++)
   {
      str1+=to_string(m);
   }

   for(int i=0;i<m;i++)
   {
      str2+=to_string(n);
   }
   cout<<min(str1,str2);

// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int gcd( int m, int n ){

	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;

	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}

int main(void){
    int w,h,c;
    cin >> w >> h >> c;
    int a = gcd(w, h);
    int count = (w/a)*(h/a);
    cout << count * c << endl;
    return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;


#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll fact(ll n){
	
    ll res = 1; 
    for (ll i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
  
int nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 


ll ston(string s) 
{ 
    stringstream geek(s); 
    ll x = 0; 
    geek >> x; 
    
  
    return x; 
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[0] < v2[0]; 
} 

 ll digit(ll n)
 {
 	ll t=0;
 	while(n>0)
 	{
 		t++;
 		n/=10; 	}
 		return t;
 }

void solve()
{
	ll k;
	cin>>k;
	string s;
	cin>>s;
	if(s.sz<=k)
	{
		cout<<s;
		return;
	}
	for(ll i=0;i<k;i++)
		cout<<s[i];
	if(s.sz>k)
		cout<<"...";
	return;
}

int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3676
import Control.Monad.Trans.State
 
main = do
  n <- readLn
  print $ lucas n
 
lucas :: Int -> Int
lucas n = evalState (step n) (2, 1)
 
step :: Int -> State (Int, Int) Int
step 0 = do
  (x, y) <-  get
  return x
step 1 = do
  (x, y) <- get
  return y
step n = do
  (x, y) <- get
  put (y, x+y)
  step $ n - 1

Measured memory_bytes: 508
/*{{{*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;
typedef pair<int, int> PP;
typedef long long LL;
#define pb push_back
#define fr first
#define sc second
#define bitcnt __builtin_popcount
#define all(x) x.begin(), x.end()
inline LL ri() {LL x; scanf("%lld", &x); return x;}
#define rep2(i, n, ...) for (int i = 0; i < (n); i ++) 
#define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --)
#define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --)
#define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__)
template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} 
template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} 
/*}}}*/


int lis(vector<int>& v) {
  vector<int> p;
  for (int i = 0; i < v.size(); i ++) {
    if (p.size() == 0 || p.back() < v[i]) {
      p.pb(v[i]);
    } else {
      auto it = lower_bound(p.begin(), p.end(), v[i]);
      *it = v[i];
    }
  }
  return p.size();
}

vector<PP> p;
const double arc = 10 * acos(-1) / 2;
int main() {
  LL x1, y1, x2, y2, n;
  cin >> x1 >> y1 >> x2 >> y2 >> n;
  rep(i, n) {
    int tx, ty; cin >> tx >> ty;
    p.pb(PP(tx, ty));
  }
  if (x1 > x2) {
    rep(i, n) p[i].fr *= -1;
    x1 *= -1;
    x2 *= -1;
    //swap(x1, 2);
  }
  if (y1 > y2) {
    rep(i, n) p[i].sc *= -1;
    y1 *= -1;
    y2 *= -1;
    //swap(x1, x2);
  }
  sort(p.begin(), p.end());
  if (y1 == y2) {
    swap(x1, y1);
    swap(x2, y2);
    rep(i, n) swap(p[i].fr, p[i].sc);
  }
  //rep(i, n) cout << p[i].fr << ' ' << p[i].sc << endl;
  if (x1 == x2) {
    rep(i, n) if (p[i].sc >= y1 && p[i].sc <= y2 && p[i].fr == x1) {
      cout << setprecision(20) << fixed<<(y2 - y1) * 100.0 + 2 * arc - 20; return 0;
    }
  }
  vector<int> nv;
  rep(i, n) if (x1 <= p[i].fr && p[i].fr <= x2 && y1 <= p[i].sc && p[i].sc <= y2) {
    nv.pb(p[i].sc);
  }
  int k = lis(nv);
  double res =  (x2 - x1 + y2 - y1) * 100.0 -  (20 - arc) * k;
  if (k > min(x2 - x1, y2 - y1)) res += arc;
  cout << setprecision(20) << fixed<< res << endl;
  return 0;
}


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

namespace Contest20191031
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);

            if(a > 0 && a< 10 && b >0 && b < 10)
            {
                Console.WriteLine(a * b);
            }
            else
            {
                Console.WriteLine(-1);
            }

        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
#define N 100
int main(){
  int i;
  int j;
  int n;
  int count=0;
  int tmp;
  int A[N];
  scanf("%d",&n);
  for( i=0; i<n; i++ ){
    scanf("%d",&A[i]);
  }
  for( i=0; i<n; i++ ){
    for( j=n-1; j>=i+1; j-- ){
      if( A[j]<A[j-1]){
	tmp=A[j];
	A[j]=A[j-1];
	A[j-1]=tmp;
	count++;
      }
    }
  }
  for( i=0; i<n; i++ ){
    printf("%d", A[i]);
    if( i<n-1 ) printf(" ");
  }
  printf("\n%d\n",count); 
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#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__) << "] "
using ll = long long;
#define ar array 

void test_case() {
	ll h , w;
	cin >> h >> w;
	ll INF = static_cast<ll>((h+1)*w);
	vector<ll> A(h,0);
	vector<ll> B(h,0);
	for(int i = 0 ; i < h ; i++)
		cin >> A[i] >> B[i];
	
	map<ll,ll> M;
	multiset<ll> V;
	for(int i = 1 ; i <= w ; i++){
		M.insert({i,0});
		V.insert(0);
	}
	for(int i = 0 ; i < h ; i++){
		ll bp1 = INF;
		if(M.count(B[i]+1)==1) {
			bp1 = M[B[i]+1];
			V.erase(V.find(M[B[i]+1]));
		}
		while(true){
			auto it = M.lower_bound(A[i]);
			if(it != M.end() && it->first <= B[i]){
				bp1 = min(bp1,it->second+(B[i]+1-it->first));
				V.erase(V.find(it->second));
				M.erase(it);
			}
			else{
				break;
			}
		}
		if(bp1 < INF && B[i]+1 <= w){
			M[B[i]+1] = bp1;
			V.insert(bp1);
		}
		if(V.empty()){
			cout<<-1<<"\n";
		}
		else{
			cout<<((*V.begin())+i+1)<<"\n";
		}
	}
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T = 1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
}

// map of current possible positions -> how long to get there
// starts as {1:0 , 2:0 , ... , w:0}
// when we get a new wall segment A ... B
// anything in A ... B has to move to right to B + 1;
// So erase everything in A ... B and set B+1 to whichever one
// is cheapest (after moving right).
// Erasing is expensive , but everything can only get erase
// once , and there are only W+H things
// to erase (W things we start with, and each row adds up to 
// one more thing at B+1).
// So the amortized (average) time should be OK.
// At each row, the score is the minimum of the values , which 
// can store in a , multiset.


Measured memory_bytes: 28232
#/*
    AUTHOR:shivam51
    IIESTS
*/
  #include<bits/stdc++.h>
  using namespace std;
  //
  #define add accumulate
  #define ll long long int
  #define ff first
  #define ss second
  #define pb push_back
  #define mp make_pair
  #define vll vector<ll>
  #define lb lower_bound
  #define ub upper_bound
  #define pll pair<ll,ll>
  #define vpll vector<pll>
  #define all(v) v.begin(), v.end()
  #define rep(i,k,n) for(int i=k;i<n;i++)
  #define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
  const ll mod=1e9+7;
  const ll MAX=1e6+1;
  //
  //	
    	ll  solve(){
  		string str;
  		cin>>str;
  		rep(i,1,str.length())
  			if(str[i]==str[i-1])
  				return cout<<"Bad",0 ;
  		cout<<"Good";
  	}
	int main(){ 
		hs;
		ll t;
		// cin>>t;
		t=1;
		while(t--)
			solve();
    return 0; 
} 

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
vector<string>split(string s, char c = ' ') {
	vector<string>vec;
	string h = "";
	for (int i = 0; i < s.size();) {
		int j = i;
		while (j < s.size() && s[j] != ' ') {
			h += s[j++];
		}
		if (h.size() > 0) vec.push_back(h);
		h = "";
		i = j + 1;
	}
	return vec;
}
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
signed main(){
	int a[4] = { 0,0,0,0 };
	for (int i = 0; i < 6; i++) {
		a[read() - 1]++;
	}
	if (a[0] >= 3 || a[1] >= 3 || a[2] >= 3 || a[3] >= 3) {
		cout << "NO\n";
	}
	else {
		cout << "YES\n";
	}
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[][]A = new int[N][];
		for(var i=0;i<N;i++){
			A[i] = new int[2];
		}
		for(var i=0;i<N;i++){
			string[] str = Console.ReadLine().Split();
			A[i][0] = int.Parse(str[0]);
			A[i][1] = int.Parse(str[1]);
		}
		Array.Sort(A,(x,y)=>x[0]-y[0]);
		int ans = 0;
		if(N%2==1){
			int a1 = A[N/2][0];
			Array.Sort(A,(x,y)=>x[1]-y[1]);
			int a2 = A[N/2][1];
			ans = a2-a1+1;
		} else {
			int a1 = A[N/2-1][0];
			int a2 = A[N/2][0];
			Array.Sort(A,(x,y)=>x[1]-y[1]);
			int b1 = A[N/2-1][1];
			int b2 = A[N/2][1];
			ans = b1+b2-(a2+a1)+1;
		}
		Console.WriteLine(ans);
	}
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int l = 0, r = 1e9;
    while(abs(l - r) > 1) {
        int mid = (l + r) / 2;
        int cnt = 0;
        for(int i = 0; i < n; i++) cnt += (a[i] - 1) / mid;
        if(cnt <= k) r = mid;
        else l = mid;
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 4016
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import sys
# import numpy as np
# from scipy.special import comb

INF = 100100100


def main():
    N = int(input())

    memo = [INF] * (N + 100)
    memo[0] = 0

    for i in range(0, N + 1):
        six = 0
        nine = 0
        while i + 9**nine <= N:
            memo[i + 9**nine] = min(memo[i + 9**nine], memo[i] + 1)
            nine += 1
        while i + 6**six <= N:
            memo[i + 6**six] = min(memo[i + 6**six], memo[i] + 1)
            six += 1

    print(memo[N])


if __name__ == '__main__':
    main()


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

namespace lec10A
{
    class Program
    {
        static int [] fibo_arr = new int[45];

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            fibo_arr[0] = 1;
            fibo_arr[1] = 1;

            for (int i = 2; i < 45; i++)
            {
                fibo_arr[i] = 0;
            }

            int ans = Fibonacci(n);

            Console.WriteLine("{0}",ans);

            Console.ReadLine();
        }

        static int Fibonacci(int m)
        {
            if (fibo_arr[m] != 0)
            {
                return fibo_arr[m];
            }
            else
            {
                fibo_arr[m] = Fibonacci(m - 1) + Fibonacci(m - 2);
            }
            return fibo_arr[m];
            
        } 
    }
}



Measured memory_bytes: 17732
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}
	sort.Ints(a)
	b := make([]int, 1000001)
	prev := -1
	for i := 0; i < len(a); i++ {
		if a[i] == prev {
			b[a[i]] = 1
			continue
		}
		prev = a[i]
		for j := a[i] * 2; j < 1000001; j += a[i] {
			b[j] = 1
		}
	}
	ans := 0
	for i := 0; i < len(a); i++ {
		if b[a[i]] != 1 {
			ans++
		}
	}
	out(ans)
}


Measured memory_bytes: 13188
/*
 * b.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 1000000;
const int MAX_M = 10000;

typedef long long ll;

const ll BS0 = 2549;
const ll BS1 = 4283;
const ll MOD0 = 1000000007;
const ll MOD1 = 1000000009;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

/* subroutines */

ll rh(string &s, int m, ll bs, ll mod) {
  ll h = 0;
  for (int i = 0; i < m; i++)
    h = (h * bs + s[i]) % mod;
  return h;
}

ll powmod(ll a, int b, ll mod) {
  ll pm = 1;
  while (b > 0) {
    if (b & 1) pm = (pm * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return pm;
}

/* main */

int main() {
  string s, p;
  cin >> s >> p;

  int n = s.size(), m = p.size();

  ll ph0 = rh(p, m, BS0, MOD0);
  ll ph1 = rh(p, m, BS1, MOD1);
  //printf("%lld %lld\n", ph0, ph1);

  ll e0 = powmod(BS0, m, MOD0);
  ll e1 = powmod(BS1, m, MOD1);
  
  ll sh0 = rh(s, m, BS0, MOD0);
  ll sh1 = rh(s, m, BS1, MOD1);

  for (int i = 0; i <= n - m; i++) {
    if (sh0 == ph0 && sh1 == ph1) printf("%d\n", i);

    sh0 = (sh0 * BS0 % MOD0 + s[i + m] - s[i] * e0 % MOD0 + MOD0) % MOD0;
    sh1 = (sh1 * BS1 % MOD1 + s[i + m] - s[i] * e1 % MOD1 + MOD1) % MOD1;
  }
  return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>

#define INF 10e10
#define REP(i,n) for(int i=0; i<n; i++)
#define REP_R(i,n,m) for(int i=m; i<n; i++)
#define MAX 100

using namespace std;

typedef long long ll;

ll N;

int count_digits (ll n) {
  int count = 0;

  while (n > 0) {
    n /= 10;
    count++;
  }

  return count;
}

int main() {
  cin >> N;

  ll ans = 100;

  for (ll i = 1LL; i * i <= N; i++) {

    ll quo;
    if (N % i) continue;
    quo = N / i;

    ll digit;

    digit = max(count_digits(quo), count_digits(i));

    if (digit < ans) ans = digit;
  }

  printf("%lld\n", ans);

}


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

int main(){
  int n;
  char s1[100], s2[100];
  int t = 0, h = 0;
  scanf("%d", &n);
  for(;n > 0; n--){
    scanf("%s %s", s1, s2);
    if ( strcmp(s1, s2) == 0 ) {t++;h++;}
    else if ( strcmp(s1, s2) > 0 ) t += 3;
    else if ( strcmp(s1, s2) < 0 ) h += 3;
    else {}
  }
  printf("%d %d\n", t, h);
  return 0;
}


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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/c.in", "r", stdin);
//  freopen("../IO/c.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


void solve(std::istream &in, std::ostream &out) {
  int64_t sum = 0;
  int k;
  in >> k;
  for (int i = 1; i <= k; ++i) {
    for (int j = 1; j <= k; ++j) {
      for (int c = 1; c <= k; ++c) {
        sum += __gcd(i, __gcd(j, c));
      }
    }
  }
  out << sum << '\n';
}

Measured memory_bytes: 3640
def test():
    s = input()
    t = input()
    dict1,dict2 = {},{}
    for i,j in zip(s,t):
        if i in dict1:
            if dict1[i] != j:
                print("No")
                return
        else:
            dict1[i] = j
        if j in dict2:
            if dict2[j] != i:
                print("No")
                return
        else:
            dict2[j] = i
    print("Yes")


if __name__ == "__main__":
    test()


Measured memory_bytes: 3632
//Radhe Radhe
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include<boost/math/common_factor.hpp>
#include <ext/numeric>
using namespace __gnu_cxx;
using namespace std;
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define array(a,n) int a[n]; for(int i=0;i<n;i++) cin>>a[i];
#define loop(i,a,b,x) for(int i=a;i<b;i+=x)
const int MOD = 1000000007;
//const int N = 10001;
const int N = 1e5 + 10;
//const int N = (2 * (1e5)) + 2;


int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
   
    int t = 1;
    //cin >> t;
    while (t--) {
        int h, w;
        cin >> h >> w;
        vector< string > a(h);
        vector< vector<int> > dp(h + 1, vector<int> (w + 1, 0));
        for (int i = 0; i < h; i++)
            cin >> a[i];

        dp[1][1] = 1;
        for (int i = 1; i <= h; i++)
        {
            for (int j = 1; j <= w; j++)
            {
                if (a[i - 1][j - 1] == '.')
                    dp[i][j] = max(dp[i][j], dp[i - 1][j] + dp[i][j - 1]) % MOD;
                else
                    dp[i][j] = 0; 
            }
        }

        cout << dp[h][w] << endl;
    }
    return 0;

}






Measured memory_bytes: 12516
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main(){
  ll a,b,c,d,e,f;
  cin>>a>>b>>c>>d;
  f = c - a;
  e = d - b;
  cout<<c-e<<" "<<d+f<<" "<<a-e<<" "<<b+f<<"\n";
  return 0;
}

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 N = sc.nextInt();
        long K = sc.nextLong();
        int A[] = new int[N+1];
        for(int n=1; n<=N; n++) {
            A[n] = sc.nextInt();
        }

        int mymap[] = new int[N+1];
        boolean visited[] = new boolean[N+1];
        int now = 1;
        int count = 0;
        int maxIndex = -1;
        mymap[count] = now;
        visited[now] = true;
        while(true) {
            int next = A[now];
            if(visited[next]) {
                // todo
                // ++count 回目にnextにループする
                // 持つべきマイマップのサイズは ++count
                maxIndex = ++count;
                mymap[maxIndex] = next;
                break;
            } else {
                mymap[++count] = next;
                visited[next] = true;
                now = next;
            }
        }
        // search loop start
        int loopStart = -1;
        for(int i=0; i<=maxIndex; i++) {
            if(mymap[i]==mymap[maxIndex]) {
                loopStart = i;
                break;
            }
        }
        int loopSize = maxIndex - loopStart;
//        System.out.println(String.format("maxIndex: %d, loopStart:%d, loopSize;%d", maxIndex, loopStart, loopSize));
        if(maxIndex>=K) {
            System.out.println(mymap[(int) K]);
        } else {
            long amari = (K - maxIndex) % loopSize;
            int amari_i = (int)amari;
            System.out.println(mymap[loopStart + amari_i]);
        }
    }
}


Measured memory_bytes: 60044
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    int a[n], dp[n+1];
    for(int i = 0; i<n;i++) cin >> a[i];

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

    cout << dp[n-1] << endl;

    
    return 0;

}



Measured memory_bytes: 4360
h, w, d = map(int, input().split())

p = [[] for _ in range(h * w)]

for i in range(h):
    temp = list(map(int, input().split()))
    for j in range(w):
        p[temp[j] - 1] = [i, j]

q = int(input())
a = [[int(x) - 1 for x in input().split()] for _ in range(q)]

s = [0 for _ in range(h * w)]
for i in range(d, h * w):
    s[i] = s[i - d] + abs(p[i][0] - p[i - d][0]) + abs(p[i][1] - p[i - d][1])

for i in range(q):
    print(s[a[i][1]] - s[a[i][0]])


Measured memory_bytes: 35232
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        int a = Integer.valueOf(arr01[0]);
        int b = Integer.valueOf(arr01[1]);

        //        System.out.println(a);
        //        System.out.println(b);

        System.out.println(a - b * 2 > 0 ? a - b * 2 : 0);

    }

}

Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int n,m,x;
  cin>>n>>m>>x;
  vector<int> a(n+1);
  for(int i=0;i<m;i++){
    int b;
    cin>>b;
    a[b]++;
  }
  int c=x;
  int cost0=0;
  while(c!=0){
    c--;
    cost0+=a[c];
  }
  int d=x;
  int costn=0;
  while(d!=n){
    d++;
    costn+=a[d];
  }
  cout<<min(cost0,costn)<<endl;
}

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

//ABC 083 B
int main()
{
	int n,a,b,x=0;
	cin>>n>>a>>b;
	for(int i=1; i<=n; i++){
		int t=i,s=0;
		while(t!=0){
			s+=t%10;
			t=t/10;
		}
		if(s>=a && s<=b){
			x+=i;
		}
	}
	cout<<x<<endl;
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
string = "No"
for i in range(1, n+1):
        for j in range(1, n+1):
            if n % (4 * i + 7 * j) == 0:
                string = "Yes"
                break
            elif n % (4 * i) == 0:
                string = "Yes"
                break
            elif n % (7 * j) == 0:
                string = "Yes"
                break

print(string)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);    
    int n;
    cin>>n;
    int a[n];
    int ans=-1;
    int s=1;
    for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]==s){
        s++;
    }
    }
    if(s>1){
        ans=n-s+1;
    }
    cout<<ans;

    
}

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

int main()
{
	int N;
	char S[4][54];
	scanf("%d", &N);
	scanf("%s", &(S[1][1]));
	scanf("%s", &(S[2][1]));
	
	int i, k, situ[54] = {};
	for (i = 1, k = 0; i <= N; i++) {
		if (S[1][i] == S[2][i]) situ[k++] = 1;
		else {
			situ[k++] = 2;
			i++;
		}
	}
	
	long long ans = (situ[0] == 1)? 3: 6;
	for (i = 1; i < k; i++) {
		if (situ[i-1] == 1) ans = ans * 2 % 1000000007;
		else if (situ[i] == 2) ans = ans * 3 % 1000000007; 
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  int n,x,y,z, cnt;
  char str[50];
  scanf("%d", &n);
  for (int nl = 1; nl <= n; nl++){
    cnt = 0;
    for (int x = 1; x < n; x++){
      int y;
      for (y = 1; y < n; y++){
        int xy = x*x+y*y+x*y;
        if (xy >= nl) break;
        int nlnew = nl - xy;
        int z;
        for (z = 1; z < n; z++){
//        int cal = (x*(x+y))+(y*(y+z))+(z*(z+x));
          int calz = z*(x+y+z);
//        sprintf(str,"x[%d]y[%d]z[%d]:%d", x,y,z,cal);
//        cout << str << endl;
          if (calz == nlnew) cnt++;
          if (calz >= nlnew) break;
        } //z
        if (z == 1) break;
      } //y
      if (y == 1) break;
    } //x
    cout << cnt << endl;
  }
  return 0;
}

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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30
#define N 1024

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int par[N], rank[N];

void init(int n){
  rep(i, n){
    par[i] = i;
    rank[i] = 0;
  }
}

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

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y) return;

  if(rank[x] < rank[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(rank[x] == rank[y]) rank[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

int V, d;
int f[N];
int main(){
  f[0] = 1; f[1] = 2;
  REP(i, 2, N) f[i] = (f[i-1] + f[i-2])%1001;

  while(~scanf("%d%d", &V, &d)){
    init(V+1);
    REP(i, 1, V+1){
      REP(j, i+1, V+1){
	if(abs(f[j]-f[i]) < d) unite(i, j);
      }
    }
  int res = 0;
  REP(i, 1, V+1) if(par[i] ==  i) res++;
  printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 1200
#include <vector>
#include <set>
#include <cstdio>
using namespace std;
int main(){
	int N,L;
	scanf("%d%d",&N,&L);
	vector<int>v(N);
	for(int i=0;i<N;i++)scanf("%d",&v[i]);
	multiset<int>se;
	for(int i=0;i<L-1;i++)se.insert(v[i]);
	for(int i=L-1;i<N;i++){
		se.insert(v[i]);
		printf(i<N-1?"%d ":"%d\n",*se.begin());
		se.erase(se.find(v[i-L+1]));
	}
}

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

int main(){
	int N, d_i, ans;
	vector<int> d;
	cin >> N;
	for(int i = 0; i < N; ++i){
		cin >> d_i;
		d.push_back(d_i);
	}
	sort(d.begin(), d.end());
	ans = d[N/2] - d[N/2 - 1];
	cout << ans << endl;
}

Measured memory_bytes: 892
use strict;
use warnings;
use feature 'say';
use Data::Dumper;

chomp(my $line  = <STDIN>);
my ($x, $n) = split / /, $line;

if($n == 0) {
  say $x;
  exit;
}

chomp(my $line2 = <STDIN>);
my @nums = sort { $a <=> $b } (split/ /, $line2);

my %exist_hash = ();
map { $exist_hash{$_}++ } @nums;

my @all = ();
my $i = -100;
while( $i <= 200) {
  push(@all, $i);
  $i++;
}

my @not_exist = ();
for (@all) {
  if(! exists($exist_hash{$_}) ) {
    push(@not_exist, $_);
  }
}

my $min_diff = 100;
my $answer = '';


for my $num ( sort { $b <=> $a } @not_exist) {
  my $diff = $x - $num;

  if( $answer eq '') {
    $answer = $num;
    next;
  }

  if ( abs($diff) <= $min_diff) {
    if ($answer = 0 || $num < $answer ) {
      $answer = $num;
    }
    $min_diff = abs($diff);
  }
}

say $answer;



Measured memory_bytes: 6496
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    string s; cin >> s;
    int ans = 110;
    int f = 1;
    for(int i = 1; i < s.size(); i++) if(s[0] != s[i]) f = 0;
    if(f) {
        cout << 0 << endl;
        return 0;
    }

    for(char c = 'a'; c <= 'z'; c++) {
        string s1 = s;
        int flg = true;
        int cnt = 0;
        while(flg) {
            flg = false;
            for(int i = 0; i < s.size() - cnt - 1; i++) {
                if(s1[i] == c || s1[i + 1] == c) s1[i] = c;
                else flg = true;
            }
            cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
using ll = long long;


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

int main(){
	int n;
	string s;
	cin >> n >> s;
	int a=0,b=0;
	for(int i=0;i<n;i++) if(s[i] == 'R') a++;
	int ans = max(a,b);
	for(int i=0;i<n;i++){
		if(s[i] == 'R') a--;
		else b++;
		int now = max(a,b);
		ans = min(ans,now);
	}
	cout << ans << endl;
}


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

#define int long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int N = 2e5 + 5;
const int inf = 1e16 + 2;

int n , m , x;
struct save {
    int c , arr[20];
};

void solve(int z) {
    
    cin >> n >> m >> x;
    vector<save> brr(n);
    for(int i = 0 ; i < n ; i ++) {
        cin >> brr[i].c;
        for(int j = 0 ; j < m ; j ++) cin >> brr[i].arr[j];
    }
    int pw = pow(2 , n);
    int mn = INT_MAX;
    for(int i = 0 ; i < pw ; i ++) {
        int y = i;
        int ch[m] , k = 0;
        memset(ch , 0  , sizeof ch);
        for(int j = 0 ; j < n ; j ++) {
            int t = y % 2;
            if(t) {
                k += brr[j].c;
                for(int h = 0 ; h < m ; h ++){
                    ch[h] += brr[j].arr[h];
                }
            }
            y /= 2;
        }
        int tr = 1;
        for(int j = 0 ; j < m ; j ++) {
            if(ch[j] < x) tr = 0;
        }
        if(tr == 1) mn = min(mn , k);
    }
    if(mn == INT_MAX) {
        cout << -1;
        return ;
    }
    cout << mn << '\n';
}

/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int x = 1;
    while(testcase --) {
        solve(x ++);
    }
    
    return 0;
}
 



Measured memory_bytes: 4068