akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
typedef pair<int,int> P;
#define INF 1e9

int a[1005][1005];
int main(){
    int h,w;
    cin>>h>>w;
   // char s[h][w];
    char s;
    for(int i=0;i<h;i++)for(int j=0;j<w;j++)a[i][j]=0;
    int c=0;
    int wh = h*w;
    queue<P> que;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>s;
            if(s=='#'){
                a[i][j]=1;
                que.push(P(i,j));
                wh--;
            }
        }
    }
    //  for(int y = 0 ; y<h;y++){
    //     for(int x=0;x<w;x++){
    //         cout<<a[y][x]<<" ";
    //     }
    //     cout<<endl;
    // }
    int ans = 0;
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};
    int cc = c;
    int r = 0;
    //cout<<"wj:"<<wh<<endl;
    // for(int i=0;i<c;i++){
    //     cout<<"bl:"<<bl[i].first<<" "<<bl[i].second<<endl;
    // }
    while(wh>0){
        while(que.size()){
            P p = que.front();que.pop();
            for(int i=0;i<4;i++){
                int ny = p.first + dy[i], nx = p.second + dx[i];
                if(nx>=0&&nx<w&&ny>=0&&ny<h&&a[ny][nx]==0){
                    que.push(P(ny,nx));
                    a[ny][nx] = a[p.first][p.second] + 1;
                    wh--;
                    ans = max(ans,a[ny][nx]-1);
                }
            }
        }
    }
    // for(int i=0;i<h;i++){
    //     for(int j=0;j<w;j++){
    //         cout<<a[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    cout<<ans<<endl;
}

Measured memory_bytes: 12304
N = int(input())
s = input()
a = [0]*N
for i in range(1,N):
    if s[i]=="E":
        a[0] += 1 
for i in range(1,N):
    a[i] = a[i-1]
    if s[i]=="E":
        a[i] -= 1
    if s[i-1] == "W":
        a[i] += 1
print(min(a))

Measured memory_bytes: 21172
#include<stdio.h>
int n, s[22];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;++i)
        scanf("%d",s+i);
    int acc = 0;
    for(int i=1;i<n-1;++i)
    {
        if(s[i-1] < s[i] && s[i+1] > s[i])
            acc++;
        if(s[i-1] > s[i] && s[i+1] < s[i])
            acc++;
    }
    printf("%d\n",acc);
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define repit(i,a) for(__typeof((a).begin()) i=(a).begin();i!=(a).end();i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

struct node {
    int cst;
    int x, y;
    int dir;
    bool operator<(const node &o) const {
        return cst > o.cst;
    }
};
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};

int w, h;
int f[32][32];
bool inrange(int x, int y) {
    return x >= 0 and y >= 0 and x < w and y < h;
}
int main()
{
    while(cin >> w >> h, w||h) {
        rep(i, h) rep(j, w) cin >> f[j][i];
        vector<int> c(4);
        rep(i, 4) cin >> c[i];

        bool done[32][32][4] = {0};        
        priority_queue<node> pq;
        pq.push((node){0, 0, 0, 1});
        while(pq.size()) {
            int cst = pq.top().cst;
            int x = pq.top().x;
            int y = pq.top().y;
            int dir = pq.top().dir; pq.pop();
            if(done[x][y][dir]) continue;
            done[x][y][dir] = true;

            if(x == w-1 and y == h-1) {
                cout << cst << endl;
                break;
            }
            rep(i, 4) {
                int df = c[i];
                int ndir = (dir + i) % 4;
                if(f[x][y] == i) df = 0;
                int nx = x + dx[ndir];
                int ny = y + dy[ndir];
                if(inrange(nx, ny))
                    pq.push((node){cst+df, nx, ny, ndir});
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1352
require "prime"
class Integer
  def fac
    return 1 if self.zero?
    ary = [*1..self]
    loop do
      return ary[0] if ary.size == 1
      ary = ary.each_slice(2).map{|a| a.size == 2 ? a[0] * a[1] : a[0]}
    end
  end

  def combi(r)
    self.fac / ((r.fac) * ((self - r).fac))
  end
end

n, m = gets.chomp.split.map(&:to_i)
primes = Prime.prime_division(m)

ans = primes.reduce(1) do |sum, prime|
  sum * (prime.last + n - 1).combi(n - 1)
end

puts ans % (10 ** 9 + 7)

Measured memory_bytes: 40124
#include <bits/stdc++.h>
#include<math.h>
typedef long long ll;
using namespace std;
vector<vector<int>>comp;
vector<int>onecycle;
vector<int>clength;
vector<int>v9;
vector<int>v8;
int cycle_start;
int cycle_end;
vector<int>vbip1;
vector<int>vbip2;
#define FIO  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int main()
{
    ll n;
    cin>>n;
    ll a[n][3];
    ll i;
    for(i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    ll dp[n][3];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            dp[i][j]=INT_MIN;
            for(int k=0;k<3;k++)
            {
                if(j!=k)
                {
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
                }
            }
        }
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
}


Measured memory_bytes: 8248
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    LL n;
    cin >> n;
    if(n%2 == 1){
        cout << 0 << endl;
        return 0;
    }

    LL five = 0;
    LL now = 5;
    LL m = n/10;
    while(now <= m){
        five += m/now;
        now *= 5;
    }
    cout << m+five << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int MN=300000+5;
using namespace std;
typedef long long ll;
template<typename T>inline T&IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	return in*=f;
}
int n,V;
int l[20][MN],r[20][MN];
int fr[MN],fl[MN],s[MN];ll x[MN];
void input(){
	IN(n),IN(V);
	for(int i=1;i<=n;++i)IN(x[i]);
	int k;x[0]=LLONG_MIN/10,x[n+1]=LLONG_MAX/10;
	for(k=0;V;++k,V>>=1){
		for(int i=1;i<=n;++i)l[k][i]=x[i]-x[i-1]>V?i:l[k][i-1];
		for(int i=n;i>=1;--i)r[k][i]=x[i+1]-x[i]>V?i:r[k][i+1];
		l[k][0]=1,r[k][n+1]=n;
	}
	for(int i=1;i<=n;++i)l[k][i]=x[i]-x[i-1]>V?i:l[k][i-1];
	for(int i=n;i>=1;--i)r[k][i]=x[i+1]-x[i]>V?i:r[k][i+1];
	l[k][0]=1,r[k][n+1]=n;
	fr[0]=n+1;
	for(int st=1;st<(1<<k);++st){
		fr[st]=n;
		for(int i=0;i<k;++i)if(st>>i&1){
			fl[st]=max(fl[st],r[i+1][fl[st^(1<<i)]+1]);
			fr[st]=min(fr[st],l[i+1][fr[st^(1<<i)]-1]);
		}
	}
	for(int st=0;st<(1<<k);++st){
		int L=l[0][fr[((1<<k)-1)^st]-1],R=r[0][fl[st]+1];
		if(L<=R)s[L]++,s[R+1]--;
	}
	for(int i=1;i<=n;++i){
		s[i]+=s[i-1];
		puts(s[i]?"Possible":"Impossible");
	}
}
int main(){
	input();
	return 0;
}

Measured memory_bytes: 53120
N, x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
 
ans = 0
 
a = a.map do |i|
  if x >= i
    i
  else 
    ans += i - x
    x
  end
end
 
 
(N-1).times do |i|
  
  if a[i] + a[i+1] > x
    t = a[i+1]
    a[i+1] = ( x - a[i] )
    ans += t - a[i+1]
  end
end
 
puts ans

Measured memory_bytes: 9348
#include <iostream>

using namespace std;

int main(int argc, char const* argv[])
{
	int a, b;
	cin >> a >> b;
	if(a + b == 15)cout << "+" << endl;
	else if(a*b == 15)cout << "*" << endl;
	else cout << "x" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  vector<string> days = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string S;
  cin >> S;
  for (int i = 0; i < days.size(); ++i) {
    if (S == days[i]) {
      int ans = 7 - i % 7;
      cout << ans << endl;
    }
  }
  return 0;
}


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

int main(void)
{
    int n;

    scanf("%d",&n);

    switch (n%10)
    {
    case 2:
    case 4:
    case 5:    
    case 7:
    case 9:
        printf("hon");
        break;
    
    case 0:
    case 1:
    case 6:
    case 8:
        printf("pon");
        break;
    
    case 3:
        printf("bon");
        break;

    default:
        break;
    }

    return 0;
}

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

int main(){
  int a,b;
  cin >>a>>b;
  int ans = 0;
  if (a < b) rep(i,b) ans += a * pow(10,i);
  else rep(i,a) ans += b * pow(10,i);
  cout << ans << endl;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const string YES = "Yes";
const string NO = "No";
const ll mod = 1e9+7;


int prime(ll n){
    int is = 1;
    for(int i=2; i*i<=n;i++){
        if (n % i == 0){
            is = 0;
        }
    }
    return is;
}

int main(){
	cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    ll x; cin >> x;
    while(1){
        if (prime(x)) break;
        x++;
    }
    cout << x;
    return 0;
    
}



Measured memory_bytes: 256
a, b, k = map(int, input().split())
for i in range(k):
    if i%2 == 0:
        if a%2:
            a -= 1
        a //= 2
        b += a
    else:
        if b%2:
            b -= 1
        b //= 2
        a += b
print(a,b)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long int li;
typedef unsigned long long int ull;
typedef long double ld;
#define Max 200001
#define mod 1000000007
#define rep(i,a,b) for(i=a;i<=b;i++)
#define rrep(i,a,b) for(i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define mkp make_pair
#define F first
#define S second
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define endl "\n"
void bye()
{
	
	exit(0);
}
signed main()
{
	fast;
	ll t,pro=1,n,m,temp,k,l,r,mid,i,j,x,y,z,rem,ind,ans=0,mx=LONG_LONG_MIN,mn=LONG_LONG_MAX,cnt=0,curr=0,prev,sum=0,flag=0,i1=-1,i2=-1;
	stack<char> ms;
	string s;
	cin>>s;
	for(i=0;i<s.length();i++)
	{
	    if(!ms.empty() && ms.top()=='S' && s[i]=='T')
	    {
	        ms.pop();
	    }
	    else 
	    {
	        ms.push(s[i]);
	    }
	}
	cout<<ms.size();
	return 0;
}

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

using namespace std;

string J(int N) {

	for (int i = 0; i <= 25; i++) {
		for(int j=0;j<=15;j++)
			if (i * 4 + j * 7 == N) { return "Yes"; }
	}

	return "No";
}

int N;

int main(void) {

	cin >> N;

	cout << J(N) << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		String str = input();
		StringBuilder sb = new StringBuilder();
		sb.append(str);

		int q = Integer.parseInt(input());

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

			String[] opreration = input().split(" ");
			int a = Integer.parseInt(opreration[1]);
			int b = Integer.parseInt(opreration[2]);

			if (opreration[0].equals("print")) {

				System.out.println(sb.substring(a, b + 1));

			} else if (opreration[0].equals("reverse")) {

				StringBuilder temp = new StringBuilder(sb.substring(a, b + 1));
				sb.replace(a, b + 1, temp.reverse().toString());

			} else if (opreration[0].equals("replace")) {

				sb.replace(a, b + 1, opreration[3]);

			}
		}

		close();

	}

	public static String input() {

		return scanner.nextLine();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
}

Measured memory_bytes: 28704
n = int(input())
ans = 1
a = list(map(int, input().split(' ')))
for i in range(n):
    if a[i] == 0:
        print(0)
        exit()
for i in range(n):
    ans *= a[i]
    if 1000000000000000000 < ans:
        print(-1)
        exit()
print(ans)


Measured memory_bytes: 21640
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

var numbers = []int{3, 5, 7}
var n int
var digitsLen int

func main() {
	fmt.Scan(&n)
	digitsLen = len(strconv.Itoa(n))

	fmt.Println(dfs(0, 0, 0, 0, 0, 0))
}

var dp = [1000000100]bool{}

func dfs(i, d, sum, n1, n2, n3 int) int {
	// fmt.Println(i)
	if i == digitsLen {
		if len(strconv.Itoa(sum)) >= 3 && n1 >= 1 && n2 >= 1 && n3 >= 1 && !dp[sum] {
			dp[sum] = true
			// fmt.Println(sum)
			return 1
		}
		return 0
	}

	// var count int
	count := dfs(i+1, d, sum, n1, n2, n3)

	if res := sum + numbers[0]*int(math.Pow(10.0, float64(d))); res <= n {
		count += dfs(i+1, d+1, res, n1+1, n2, n3)
	}

	if res := sum + numbers[1]*int(math.Pow(10.0, float64(d))); res <= n {
		count += dfs(i+1, d+1, res, n1, n2+1, n3)
	}

	if res := sum + numbers[2]*int(math.Pow(10.0, float64(d))); res <= n {
		count += dfs(i+1, d+1, res, n1, n2, n3+1)
	}
	return count
}


Measured memory_bytes: 86784
#include <bits/stdc++.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <numeric>
#define load ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ll long long
#define ull unsigned long long
#define fori(i,n) for (int i=0; i<int(n);i++)
#define srt(v) sort(v.begin(), v.end())
#define MOD 1000000007
const int INF = 1e9;
const double PI = 3.14159265358979323846;

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

void solve(){

}

int main(){
	load;
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    fori(i,n){
    	cin>>v[i];
    }
    srt(v);
    int res = 0;
    fori(i,k){
    	res += v[i];
    }
    cout << res<< "\n";
	return 0;



	
}



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

int h, n;
vector<int> b;

int dp[101010][10];

int dfs(int i = 1, int bit = 0) {
  if (i == h) {
    return 0;
  }
  bit |= b[i];

  int &ret = dp[i][bit];
  if (~ret)
    return ret;

  ret = 0;
  if (bit == 0)
    ret = max(ret, dfs(i + 1, 0b111) + 2);
  if ((bit & (0b100)) == 0)
    ret = max(ret, dfs(i + 1, 0b110) + 1);
  if ((bit & (0b010)) == 0)
    ret = max(ret, dfs(i + 1, 0b111) + 1);
  if ((bit & (0b001)) == 0)
    ret = max(ret, dfs(i + 1, 0b011) + 1);
  ret = max(ret, dfs(i + 1, 0));

  return ret;
}

int main() {
  memset(dp, -1, sizeof(dp));
  cin >> h >> n;

  int ei[4] = {0b100, 0b110, 0b011, 0b001};
  b.assign(h + 1, 0);
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    b[y + 1] |= ei[x];
    b[y] |= ei[x];
  }

  cout << dfs() << endl;
}


Measured memory_bytes: 7548
import java.util.Scanner;

public class Main{
 public static void main(String[] args) {
   Scanner kbd =new Scanner(System.in);
   int k=kbd.nextInt();
   int a=kbd.nextInt();
   int b=kbd.nextInt();
   int x=1;
 for(int i=1;i<=1000;i++){
   if(a<=k*i&&k*i<=b){
     System.out.println("OK");
      x=0;
     break;
   }
 }
  if(x==1){System.out.println("NG");
}}
 }


Measured memory_bytes: 35788
n = int(input())
A = list(map(int,input().split()))

FD = [0]*9

for i in range(n):
  if A[i]<3200:
    FD[A[i]//400] += 1
  else:
    FD[8] += 1

count = 0
for j in range(8):
  if FD[j]:
    count += 1

print(max(count,1),count+FD[8])

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<ll> v(n) ,r(n);
    map<ll,ll> mp;
    mp[0]++;
    REP(i,n) {
        cin >> v[i];
        if (i == 0) r[i] = v[i];
        else r[i] = r[i-1] + v[i];
        mp[r[i]]++;
    }

    ll ans = 0;
    REP(i,n) {
        ll x = i == 0 ? 0 : r[i-1];
        //cerr << x << " " << mp[x] << endl;
        mp[x]--;
        ans += mp[x];
    }

    cout << ans << '\n';



    return 0;
}

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

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

use std::cmp::max;

fn main() {
    let a: usize = read();
    let b: usize = read();

    if a % 2 == 0 || b % 2 == 0 {
        println!("Even")
    } else {
        println!("Odd")
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main(){

	int n, tmp, d, e, f, ans=0;
	string s;
	vector< vector<int> > v;
	v.resize(10);

	cin >> n;
	cin >> s;

	for (int i = 0;i < s.size();i++) {
		tmp = s[i] - '0';
		v[tmp].emplace_back(i);
	}

	for (int j = 0;j < 10;j++) v[j].emplace_back(12345678);

	/*for (int j = 0;j < 10;j++) {
		for (int i = 0;i < v[j].size();i++) cout << v[j][i] << " ";
		cout << endl;
	}*/

	for (int a = 0;a < 10;a++) {
		if (v[a].size() < 2) continue;
		for (int b = 0;b < 10;b++) {
			if (v[b].size() < 2) continue;
			for (int c = 0;c < 10;c++) {
				if (v[c].size() < 2) continue;
				//cout << a << " " << b << " " << c << endl;
				d = v[a][0];
				if (d == 12345678) continue;

				vector<int>::iterator itb = upper_bound(v[b].begin(), v[b].end(), d);
				tmp = itb - v[b].begin();
				e = v[b][tmp];
				if (e == 12345678) continue;

				vector<int>::iterator itc = upper_bound(v[c].begin(), v[c].end(), e);
				tmp = itc - v[c].begin();
				f = v[c][tmp];
				if (f == 12345678) continue;

				ans++;
				//cout << d << " " << e << " " << f << endl;
			}
		}
	}

	cout << ans << endl;

}


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


int main() {
	
	int n, k, r, s, p;
	cin >> n >> k >> r >> s >> p;
	string t;
	cin >> t;
	string hand;
	int cnt=0;
	for(int i=0; i<n; i++){
		if(i<k){
			if(t.at(i)=='r'){
				hand += 'p';
				cnt += p;
			}
			else if(t.at(i)=='s'){
				hand += 'r';
				cnt += r;
			}
			else{
				hand += 's';
				cnt += s;
			}
		}
		
		else if(i+k>=n){
			if(t.at(i)=='r' && hand.at(i-k)!='p'){
				hand += 'p';
				cnt += p;
			}
			else if(t.at(i)=='s' && hand.at(i-k)!='r'){
				hand += 'r';
				cnt += r;
			}
			else if(t.at(i)=='p' && hand.at(i-k)!='s'){
				hand += 's';
				cnt += s;
			}
			else hand += '0';
		}
		
		else{
			if(t.at(i)=='r'){
				if(hand.at(i-k)!='p'){
					hand += 'p';
					cnt += p;
				}
				else{
					if(t.at(i+k)=='r') {
						hand += 'r';
					} 
					else hand += 'p';
				}
			}
			
			if(t.at(i)=='s'){
				if(hand.at(i-k)!='r'){
					hand += 'r';
					cnt += r;
				}
				else{
					if(t.at(i+k)=='s') {
						hand += 's';
					} 
					else hand += 'r';
				}
			}
			
			if(t.at(i)=='p'){
				if(hand.at(i-k)!='s'){
					hand += 's';
					cnt += s;
				}
				else{
					if(t.at(i+k)=='p') {
						hand += 'p';
					} 
					else hand += 's';
				}
			}
		
		}
	}
	
	cout << cnt << endl;
	return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define LL long long
#define SZ(X) X.size()
#define pii pair<int,int>
#define ALL(X) X.begin(),X.end()

using namespace std;

LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
LL lcm(LL a, LL b) {return a / gcd(a, b) * b;}
LL powmod(LL a, LL b, LL MOD) {LL ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;}
const int N = 2e5 + 11;
int n,m;
int f[N],q[N];
int main() {
	ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=0;i<(1<<n);i++)f[i]=q[i]=1e9;
    for(int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        int res=0;
        for(int j=1;j<=b;j++){
            int c;cin>>c;
            res|=(1<<c-1);
        }
        f[res]=min(f[res],a);
    }
    for(int i=0;i<(1<<n);i++)q[i]=f[i];
    for(int i=0;i<(1<<n)-1;i++){
        for(int j=0;j<(1<<n);j++){
            q[i|j]=min(q[i]+f[j],q[i|j]);
//            cout<<(i|j)<<' '<<q[i|j]<<endl;
        }
    }
    if(q[(1<<n)-1]==1e9)cout<<-1<<endl;
    else cout<<q[(1<<n)-1];
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        s: chars
    }

    let mut ret = 0;
    for i in 1..n {
        let left  = s[0..i].into_iter().map(|&c| c).collect::<std::collections::HashSet<_>>();
        let right = s[i..] .into_iter().map(|&c| c).collect::<std::collections::HashSet<_>>();
        ret = std::cmp::max(ret, ((&left) & (&right)).len());
    }
    println!("{}", ret);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

#define bit(b, i) (((b) >> (i)) & 1)
#define PC __builtin_popcountll
#define BL(a) (a ? 64 - __builtin_clzll(a) : 0)

// 間に合うのか？
int main() {
	auto a2A = [&](char & c) { c -= 'a'; c += 'A'; };
	auto A2a = [&](char & c) { c -= 'A'; c += 'a'; };
	
	IN(int, n);
	vector<string> v(n);
	RF(s, v) {
		cin >> s;
		reverse(ALL(s));
		RF(c, s) { a2A(c); }
		A2a(s.BA);
	}
	sort(ALL(v));
	RF(s, v) { a2A(s.BA); }
	
	v.PB("@");
	
	vector<int> c(n);
	inc(i, n) {
		int j = 0;
		while(v[i][j] == v[i + 1][j]) { j++; }
		c[i] = j;
	}
	
	vector<vector<int>> b(n);
	inc(i, n) {
		reverse(ALL(v[i]));
		b[i].PB(0);
		inc(j, SI(v[i])) {
			b[i].PB(b[i][j] | (1 << (v[i][j] - 'A')));
		}
		reverse(ALL(v[i]));
		reverse(ALL(b[i]));
	}
	
	LL ans = 0;
	inc(i, n) {
		dec(k, i) {
			int l = SI(v[i]) - 1;
			if(c[k] < l) { break; }
			// if(bit(b[k][l], v[i].BA - 'A') == 1) { OUT(v[i], v[k]); }
			ans += bit(b[k][l], v[i].BA - 'A');
		}
	}
	OUT(ans);
}


Measured memory_bytes: 24064
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#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 all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    sort(all(l));
    int sum = 0;
    rep(i, n) for (int j = i + 1; j < n; ++j) {
        //cが最大辺
        int a = l[i], b = l[j];
        auto itr_csup = lower_bound(all(l), a + b);
        sum += distance((l.begin() + j + 1), itr_csup);
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

const int N = 3e5 + 500;
const ll inf = 1e18;
const int mod = 1e9 + 7;
const int M = 3e6 + 500;


string s;


int main()
{
	speed;
	cin >> s;
	if(s[sz(s)-1] == 's'){
		cout << s << "es";
	}else{
		cout << s << "s";
	}
}


Measured memory_bytes: 3644
N = int(input())
h = list(map(int, input().split()))

dp = [float("inf")] * N
dp[0] = 0
for i in range(N-1):
  dp[i+1] = min(dp[i] + abs(h[i+1]-h[i]), dp[i+1])
  if i + 2 < N:
  	dp[i+2] = min(dp[i] + abs(h[i+2]-h[i]), dp[i+2])

print(dp[-1])

Measured memory_bytes: 13928
import datetime
H1, M1, H2, M2, K = map(int, input().split())
t1 = datetime.datetime(2020, 1, 1, H1, M1)
t2 = datetime.datetime(2020, 1, 1, H2, M2)
print(int((t2 - t1).total_seconds() / 60 - K))

Measured memory_bytes: 9440
#include <iostream>
using namespace std;
int main()
{
   int n,k;
   cin>>n;
   bool flag=false;
   for(int i=0;i<20;i++)
      for(int j=0;j<20;j++)
   {
      if(n == 4*i+7*j)
         flag=true;
   }
   cout<<(flag?"Yes":"No")<<endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int N;

void func(ll now, int judge, ll &cnt){
    if(now > N) return;
    if(judge == 0b111) cnt++;
    func(now * 10 + 3, judge | 0b001, cnt);
    func(now * 10 + 5, judge | 0b010, cnt);
    func(now * 10 + 7, judge | 0b100, cnt);
}
int main() {
    cin >> N;
    ll res = 0;
    func(0, 0, res);
    cout << res << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

N = int(input())
# S = input()
# N, K = map(int, input().split())
A = list(map(int, input().split()))
from collections import Counter

def main():
    cnt = Counter(A).items()
    koho_2 = []
    koho_4 = []
    for k, v in cnt:
        if v >= 4:
            koho_4.append(k)
        if v >= 2:
            koho_2.append(k)
    ans = [0]
    koho_2 = sorted(koho_2)[::-1]
    koho_4 = sorted(koho_4)[::-1]
    if len(koho_2) >= 2:
        ans.append(koho_2[0] * koho_2[1])
    if len(koho_4) >= 1:
        ans.append(koho_4[0] ** 2)
    print(max(ans))

if __name__ == "__main__":
    main()


Measured memory_bytes: 18316
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

ll N;
ll A[201010];
ll cumrev[201010];

int main() {
  //
  cin >> N;
  rep(i, 0, N) { cin >> A[i]; }

  for (int i = N - 1; i >= 0; --i) {
    cumrev[i] = cumrev[i + 1] + A[i];
    cumrev[i] %= MOD;
  }

  ll ans = 0;
  for (int i = 0; i < N - 1; ++i) {
    ans += A[i] * cumrev[i + 1] % MOD;
    ans %= MOD;
  }

  cout << ans;
}



Measured memory_bytes: 6724
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

 
public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
	    String str=reader.readLine();
	    String s1[]=str.split(" ");
	    int a=Integer.parseInt(s1[0]);
	    int b=Integer.parseInt(s1[1]);

	    int count=Integer.parseInt(reader.readLine());
	    int s[]=new int[count];
	    int f[]=new int[count];
	    int tf=0;
	    for(int i=0;i<count;i++){
		String str2=reader.readLine();
		String s2[]=str2.split(" ");
		s[i]=Integer.parseInt(s2[0]);
		f[i]=Integer.parseInt(s2[1]);
	    }

	    for(int i=0;i<count;i++){
		if(s[i]==a||f[i]==b){
		    tf=1;
		    break;
		}else if(s[i]<a&&a<f[i]){
		    tf=1;
		    break;
		}else if(s[i]<b&&b<f[i]){
		    tf=1;
		    break;
		}else if(a<s[i]&&f[i]<b){
		    tf=1;
		    break;
		}else if(s[i]<a&&b<f[i]){
		    tf=1;
		    break;
		}
	    }
	    System.out.println(tf);
	    
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static int gcd (int a, int b){
	return b>0?gcd(b,a%b):a;
    }
    static int lcm (int a, int b) {
	return a*b/gcd(a,b);
    }
}



Measured memory_bytes: 24464
import heapq

N, M=map(int, input().split())
AB=[list(map(int, input().split())) for i in range(N)]
AB=sorted(AB, key=lambda x:x[0])
h=[0]*M
heapq.heapify(h)

out=0
j=0
for i in range(1, M+1):
  while j<N and AB[j][0]<=i:
    heapq.heappush(h, -1*AB[j][1])
    j+=1
    
  out+=-1*heapq.heappop(h)
  
print(out)

Measured memory_bytes: 32548
/*
  バブルソートおよび選択ソートのアルゴリズムを用いて、与えられたN枚のカードをそれらの数字を基準に昇順に整列するプログラム
  また、それぞれのソートが安定な出力をしたか表示する
*/
#include <stdio.h>

typedef struct{
  
  char c;
  int value;
  
}Card;

void swap(Card *, Card *);
int isStable(Card aryA[], Card aryB[], int n);

int main()
{
  Card card[36], output[36];
  int n, i, j, minj;

  scanf("%d", &n);
  for( i = 0; i<n; i++ )
    scanf(" %c%d", &card[i].c, &card[i].value);

  /*cardをoutputにコピー*/
  for( i = 0; i<n; i++ )
    output[i] = card[i];
  /*バブルソートを用いて昇順にソート*/
  for( i = 0; i<n; i++ )
    {
      for( j = n-1; j >= i+1; j-- )
	{
	  if( output[j-1].value > output[j].value )
	      swap(&output[j-1], &output[j]);
	}
    }

  /*バブルソートの結果を出力*/
  for( i = 0; i<n; i++ )
    {
      printf("%c%d", output[i].c, output[i].value);
      if( i != n-1 )
	printf(" ");
    }
  printf("\n");
  if( isStable(card, output, n) == 1 )
    printf("Stable\n");
  else
    printf("Not stable\n");


  /*cardをoutputにコピー*/
  for( i = 0; i<n; i++ )
    output[i] = card[i];
  /*選択ソートを用いて昇順にソート*/
  for( i = 0; i<n; i++ )
    {
      minj = i;

      for( j = i+1; j<n; j++ )
	{
	  if( output[minj].value > output[j].value )
	    minj = j;
	}
      if( minj != i )
	swap(&output[i], &output[minj]);
    }

  /*選択ソートの結果を出力*/
  for( i = 0; i<n; i++ )
    {
      printf("%c%d", output[i].c, output[i].value);
      if( i != n-1 )
	printf(" ");
    }
  printf("\n");
  if( isStable(card, output, n) == 1 )
    printf("Stable\n");
  else
    printf("Not stable\n");

  return 0;
}


/*引数として与えられたCard型構造体 a,b を交換する関数*/
void swap(Card *a, Card *b)
{
  Card tmp;

  tmp = *a;
  *a  = *b;
  *b  = tmp;
}

/*ソートの出力が安定であるか調べる関数 
 戻り値： 安定 １  不安定 ０*/
int isStable(Card in[], Card out[], int n)
{
  int i,j, a, b;

  for( i = 0; i<n-1; i++ )
    {
      for( j = i+1; j<n; j++ )
	{
	  for( a = 0; a<n-1; a++ )
	    {
	      for( b = a+1; b<n; b++ )
		{
		  if( in[i].value == in[j].value &&  in[i].c == out[b].c && in[j].c == out[a].c && in[i].value == out[a].value && in[j].value == out[b].value )
		    return 0;
		}
	    }
	}
    }

  return 1;
}



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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;
	sort(a.begin(), a.end());
	int ai = a[n - 1], aj = a[0];

	long long dis = 1e9;
	for (int i = 1; i < n - 1; i++) {
		if (dis > abs(a[i] * 2 - ai)) {
			dis = abs(a[i] * 2 - ai);
			aj = a[i];
		}
	}
	cout << ai << ' ' << aj << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    ll n;
    cin >> n;
    vector<ll> town(n+1);
    rep(i,n+1)cin >> town.at(i);
    vector<ll> saver(n);
    rep(i,n)cin >> saver.at(i);
    ll monster = 0;
    rep(i,n){//全力で倒して全力で手伝いに行く
        ll now = town[i];
        town[i] = max(0LL,town[i] - saver[i]);
        saver[i] -= now-town[i];
        monster += now - town[i];
        if(saver[i]){
            ll next = town[i+1];
            town[i+1] = max(0LL,town[i+1]-saver[i]);
            monster += next - town[i+1];
        }

    }
    cout << monster << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 1792
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sum_a = sum(A)
sum_b = 0
b_next_ind = 0
ans = 0

# 下からi冊減らす; i=0..N
for i in range(N + 1):
	sum_b_max = K - sum_a
	if sum_b_max >= 0:
		while b_next_ind < M and sum_b + B[b_next_ind] <= sum_b_max:
			sum_b += B[b_next_ind]
			b_next_ind += 1
		ans = max(ans, (N - i) + b_next_ind)
	sum_a -= A[N - 1 - i]

print(ans)


Measured memory_bytes: 40356
#include<cstdio>
#include<list>
#include<algorithm> 
using namespace std;

int main()
{
  int q, x;
  char com[20];

  list<int> v;
  scanf("%d", &q);

  for (int i = 0; i < q; ++i){
    scanf("%s", com);
    if (com[0] == 'i'){
    scanf("%d", &x);
    v.push_front(x);
    }else if(com[6] == 'L'){
      v.pop_back();
    }else if(com[6] == 'F'){
      v.pop_front();
    }else if(com[0] == 'd'){
      scanf("%d",&x);
      for (list<int>::iterator it = v.begin(); it != v.end(); ++it){
        if( *it == x){
          v.erase(it);
          break;
        }
        
      }
    }
  }
  int i=0;
  for( list<int>::iterator it = v.begin(); it != v.end(); it++){
    if (i++)printf(" "); //???????????????????????????????????????????????????????????????????????????if??????????????????????????????
    printf("%d", *it );
  }
  printf("\n");

  return 0;
}

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

int arr[200000]={0,};
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int N;
	cin >>N;
	for (int i=0; i<N; i++){
		cin >>arr[i];
	}
	int count =1;
	int idx=0;
	while(idx < N){
		if (count == arr[idx]){
			count++;
		}
		idx++;
	}
	if (count == 1)
		cout <<-1<<"\n";
	else
		cout << N -(count-1)<<"\n";

	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << ' ' << x << ' ' << y << endl;
    return 0;
}

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

signed main(){
  int A,B,C,ans=0;
  cin>>A>>B>>C;
  if(B+C>A)ans=B+C-A;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int cmpfunc (const void * a, const void * b) {
   return ( *(long long int*)a - *(long long int*)b );
}
int main()
{
    long long int test,n,i,j,sum1,k,m,a,flag=0,count=0,b,c[10]={6,2,5,5,4,5,6,3,7,6},a1[3]={0},b2;
  scanf("%lld%lld",&a,&b);
  for(i=b-a+1;i<b;i++){
      printf("%lld ",i);
  }
  for(i=b;i<b+a;i++){
    printf("%lld ",i);
  }
    return 0;
}




Measured memory_bytes: 128
#include <stdio.h>
#include <ctype.h>
 
int main() {
 
  char ch[1200];
  int i,n;
  n=0;
  char a[1200];
 
  while(1) {
    scanf("%c",&a[n]);
    if(a[n] == '\n') {
      break;
    }
    ch[n] = a[n];
    if('A' <= a[n] && a[n] <= 'Z') {
      ch[n] = a[n] + 32;
    } else if(a[n] >= 'a' && a[n] <= 'z') {
      ch[n] = a[n] - 32;
 
    }
     
    n = n +1;
     
  }
   
  for(i=0; i<n ; i++) {
    printf("%c" ,ch[i]);
  }
  printf("\n"); 
  return 0;
   
}


Measured memory_bytes: 2108
fun main(args: Array<String>) {
  val N = readInt()
  val S = readString()

  val memoL = Array(N) { Array(3) { 0 } }
  val memoR = Array(N) { Array(3) { 0 } }

  var cntR = 0
  var cntG = 0
  var cntB = 0
  for (i in 0 until N) {
    val c = S[i]
    if (c == 'R') cntR++
    if (c == 'G') cntG++
    if (c == 'B') cntB++
    memoL[i][0] = cntR
    memoL[i][1] = cntG
    memoL[i][2] = cntB
  }
  cntR = 0
  cntG = 0
  cntB = 0
  for (i in N - 1 downTo 0) {
    val c = S[i]
    if (c == 'R') cntR++
    if (c == 'G') cntG++
    if (c == 'B') cntB++
    memoR[i][0] = cntR
    memoR[i][1] = cntG
    memoR[i][2] = cntB
  }
//  println(memoL.joinToString { it.joinToString(":") })
//  println(memoR.joinToString { it.joinToString(":") })

  var cnt = 0L
  for (i in 0 until N) {
    val c = S[i]
    if (c == 'R') cnt += memoL[i][1] * memoR[i][2] + memoL[i][2] * memoR[i][1]
    if (c == 'G') cnt += memoL[i][0] * memoR[i][2] + memoL[i][2] * memoR[i][0]
    if (c == 'B') cnt += memoL[i][0] * memoR[i][1] + memoL[i][1] * memoR[i][0]
    for (j in 1..N) {
      val l = S.getOrNull(i - j) ?: break
      val r = S.getOrNull(i + j) ?: break
      if (l != c && c != r && l != r) cnt--
    }
  }
  println(cnt)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLong() = readString().toLong()
fun readLongs() = readStrings().map { it.toLong() }


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int L;
  while(cin >> L){

    double ans = (double)L / 3;
    ans = ans * ans * ans;
    
    puts_all(ans);    
  }

  return 0;
}


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

const int MAXN = 2e5 + 10;

int N, K;
int A[MAXN];

int sum[MAXN];
int n_count = 0;

void do_operation() {
  int cost = 0;
  for (int i = 1; i <= N; ++i) 
    sum[i] = 0;
  for (int i = 1; i <= N; ++i) {
    sum[max(1, i - A[i])]++;
    sum[min(N + 1, i + A[i] + 1)]--;
  }
  n_count = 0;
  for (int i = 1; i <= N; ++i) {
    cost += sum[i];
    A[i] = cost;
    if (cost == N) ++n_count;
  }
}

void solve() {
  for (int i = 1; i <= N; ++i)
    if (A[i] == N)
      n_count += 1;
  for (int k = 1; k <= K; ++k) {
    if (n_count == N) break;
    do_operation();
  }
}

int main() {
  scanf("%d %d", &N, &K);
  for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
  solve();
  for (int i = 1; i <= N; ++i) printf("%d ", A[i]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 5312
// AtCoder Grand Contest 013
// B - Hamiltonish Path

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;


const int MAX_N = 100000;

int N, M;
vector<int> G[MAX_N];
deque<int> path;
bool visited[MAX_N];

int main() {

    int v;
    int a, b;
    bool proceed;

    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    memset(visited, 0, sizeof(visited));
    path.push_back(0);
    visited[0] = true;

    for (int d = 1; d >= -1; d -= 2) {
        proceed = true;
        while (proceed) {
            proceed = false;
            v = (d > 0) ? path.back() : path.front();
            for (int to : G[v]) {
                if (!visited[to]) {
                    visited[to] = true;
                    proceed = true;
                    if (d > 0) {
                        path.push_back(to);
                    } else {
                        path.push_front(to);
                    }
                    break;
                }
            }
        }
    }

    cout << path.size() << endl;
    for (int i = 0; i < (int)path.size(); i++) {
        cout << path[i] + 1 << (i == (int)path.size() - 1 ? '\n' : ' ');
    }

    return 0;

}





Measured memory_bytes: 6784
def sub(strings, listseq):
    for index in listseq:
        strings = strings[index:] + strings[:index]
    return strings



def main():
    while True:
        strings = input()
        if strings == "-": break
        times = int(input())
        list1 = [int(input()) for i in range(times)]
        print(sub(strings, list1))



main()


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std; 
int const N=1e5+10;  
int f[N],vis[N],n,m;   
int find(int x){
	return  x==f[x]? x: f[x]=find(f[x]);  
} 
int main(){
	ios::sync_with_stdio(false); 
	cin.tie(0); 
	cin>>n>>m; 
	for(int i=1;i<=n;i++) 
		f[i]=i; 
	while (m--){ 
		int a,b;
		cin>>a>>b; 
		int fa=find(a); 
		int fb=find(b); 
		f[fa]=fb;  
	} 
	int ans=0; 
	for(int i=1;i<=n;i++){
		int father=find(i);  
		if(!vis[father]){ 
			vis[father]=1;  
			ans++; 
		} 
	}  
	cout<<ans-1<<'\n';   
	return 0; 
} 


Measured memory_bytes: 4436
n = int(input())
cnt = 0
yes = 0
for i in range(n):
    d1, d2 = map(int, input().split())
    if d1==d2:
        cnt += 1
        if cnt==3:
            yes = 1
    else:
        cnt = 0

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


Measured memory_bytes: 9168
#include <iostream>

using namespace std;

int main() {
    int n;
    string s;

    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;

    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> s;
        if(s == "AC")
            ac++;
        if(s == "WA")
            wa++;
        if(s == "TLE")
            tle++;
        if(s == "RE")
            re++;
    }
    cout << "AC x " << ac << "\n";
    cout << "WA x " << wa << "\n";
    cout << "TLE x " << tle << "\n";
    cout << "RE x " << re << "\n";
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>   
using namespace std;   
typedef long long ll;
int main()  
{   
    cin.tie(0); ios::sync_with_stdio(false);  
	//freopen("input.txt", "rt", stdin);
	int h, w; cin >> h >> w;
	
	for (int i = 0; i < h + 2; i++) {
		for (int j = 0; j < w + 2; j++) {
			if (i == 0 || j == 0 || i == h + 1 || j == w + 1)
				cout << "#";
			else {
				char a; cin >> a;
				cout << a;
			}
		}
		cout << "\n";
	}

	return 0;   
}  


Measured memory_bytes: 256
#include <iostream>

using namespace std;
string a;
int main()
{
    cin >> a;
    if (a == "Sunny") {
        cout << "Cloudy";
    } else if (a == "Cloudy") {
        cout << "Rainy";
    } else {
        cout << "Sunny";
    }
    return 0;
}


Measured memory_bytes: 256