akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=500*500+100;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int N;
int P[maxn],dis[maxn],fa[maxn];
bool esd[maxn];
deque<int> que;
inline int getfa(int x){return x==fa[x]?x:fa[x]=getfa(fa[x]);}
void bfs()
{
	while(!que.empty())
	{
		int x=que.front();
		que.pop_front();
		if((x%N!=0))
		{
			int p=getfa(x+1);
			if(dis[p]>dis[x]+(!esd[x]))
			{
				dis[p]=dis[x]+(!esd[x]);
				if(esd[x])que.push_front(p);
				else que.push_back(p);
			}
		}
		if((x%N)!=1)
		{
			int p=getfa(x-1);
			if(dis[p]>dis[x]+(!esd[x]))
			{
				dis[p]=dis[x]+(!esd[x]);
				if(esd[x])que.push_front(p);
				else que.push_back(p);
			}
		}
		if(((x-1)/N)>0)
		{
			int p=getfa(x-N);
			if(dis[p]>dis[x]+(!esd[x]))
			{
				dis[p]=dis[x]+(!esd[x]);
				if(esd[x])que.push_front(p);
				else que.push_back(p);
			}
		}
		if((x-1)/N<(N-1))
		{
			int p=getfa(x+N);
			if(dis[p]>dis[x]+(!esd[x]))
			{
				dis[p]=dis[x]+(!esd[x]);
				if(esd[x])que.push_front(p);
				else que.push_back(p);
			}
		}
	}
}
int main()
{
	scanf("%d",&N);
//	N=500;
	for(int i=1;i<=N*N;i++)
	{
		scanf("%d",&P[i]);
	//	P[i]=i;
		fa[i]=i;
	}
//	random_shuffle(P+1,P+1+N*N);
	memset(dis,0x3f,sizeof(dis));
	for(int i=1;i<=N;i++)
	{
		dis[i]=0;
		que.push_back(i);
	}
	for(int i=2;i<=N;i++)
	{
		dis[i*N]=0;
		dis[(i-1)*N+1]=0;
		que.push_back(i*N);
		que.push_back((i-1)*N+1);
	}
	for(int i=2;i<N;i++)
	{
		dis[N*(N-1)+i]=0;
		que.push_back((N*(N-1)+i));
	}
	bfs();
	ll ans=0;
	for(int i=1;i<=N*N;i++)
	{
	//	for(int j=1;j<=N*N;j++)
	//	{
	//		cout<<j<<" "<<dis[j]<<endl;
	//	}system("pause");
	//	cout<<"erased "<<P[i]<<" "<<dis[P[i]]<<endl;
		ans+=dis[P[i]]; 
		int x=P[i];
		esd[x]=1;
		if((x%N!=0))
		{
			int p=getfa(x+1);
			if(dis[p]>dis[x])
			{
				dis[p]=dis[x];
				que.push_back(p);
			}
		//	if(esd)
		}
		if((x%N)!=1)
		{
			int p=getfa(x-1);
			if(dis[p]>dis[x])
			{
				dis[p]=dis[x];
				que.push_back(p);
			}
		}
		if(((x-1)/N)>0)
		{
			int p=getfa(x-N);
			if(dis[p]>dis[x])
			{
				dis[p]=dis[x];
				que.push_back(p);
			}
		}
		if((x-1)/N<(N-1))
		{
			int p=getfa(x+N);
			if(dis[p]>dis[x])
			{
				dis[p]=dis[x];
				que.push_back(p);
			}
		}
		bfs();
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7272
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
static const ll maxLL = (ll)1 << 62;

int main() {
	string s; cin >> s;
	string t; cin >> t;
	set<string> se;

	rep(i, 0, s.size()) {
		bool same = true;
		rep(j, 0, t.size()) {
			if (s[i + j] != '?' && t[j] != s[i + j]) {
				break;
			}
			if (j == t.size() - 1) {
				string p = s;
				rep(k, 0, t.size()) {
					p[i + k] = t[k];
				}
				rep(k, 0, p.size()) {
					if (p[k] == '?') {
						p[k] = 'a';
					}
				}
				se.insert(p);
			}
		}
	}

	if (se.size() >= 1) {
		cout << *se.begin() << endl;
	}
	else {
		cout << "UNRESTORABLE" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ervb
//
//  Created by Kanak Gautam on 21/04/20.
//  Copyright © 2020 Kanak Gautam. All rights reserved.
//
 
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <utility>
#define pb push_back
#define mk make_pair
#define endl "\n"
#define mod 1000000007
using namespace std;
typedef long long int lli;
typedef long double ld;
priority_queue <lli, vector<lli>, greater<lli> > ti;
vector <lli> p[200005],a(300005),b(1000005,0),f(500005,0);
lli vis[200005];
map <pair<lli,lli>,lli> mp;
set<pair<lli, lli> > s;
set<lli> st;
map<lli,lli> np,v;
queue<lli> qy;
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
lli bpow(lli a, lli b) {
    lli res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res%mod;
}
void fact(lli i)
{
    f[0]=1;
    for(lli k=1;k<=i;k++)
    {
        f[k]=(f[k-1]*k)%mod;
    }
}
lli isprime(lli n)
{
    if(n==1)
        return 0;
    for(lli i=2;i<=sqrt(n);i++)
        if(n%i==0)
            return 0;
    return 1;
}
bool cmp(lli i,lli j)
{
    return p[i].size()<p[j].size();
}
lli comb(lli n,lli i)
{
    lli g=f[n]*(bpow(f[i],mod-2))*bpow(f[n-i],mod-2);
    return g%mod;
}
lli permute(lli n, lli i)
{
    lli h=f[n-i];
    lli g=f[n]*(bpow(h,mod-2));
    return g%mod;
}
/*void sieve()
{
    for(lli i=2;i<=5000000;i++)
    {
        if(b[i]==0)
        {
        for(lli j=2;i*j<=5000000;j++)
        {
            b[i*j]=1;
        }
        }
    }
}*/
int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    lli n;cin>>n;
    lli x;
    for(lli i=0;i<n;i++)
    {
        cin>>x;
        for(lli j=2;j<=sqrt(x);j++)
        {
            if(x%j==0)
            {
                b[j]++;
                while(x%j==0)
                {
                    x/=j;
                }
            }
        }
        if(x>1)
        {
            b[x]++;
        }
    }
    lli f=0;
    for(lli i=2;i<1000001;i++)
    {
        if(b[i]>1 && f<1)
        {
            f=1;
        }
        if(b[i]==n)
        {
            f=2;
        }
        //cout<<i<<" "<<b[i]<<endl;
    }
    if(f==2)
    {
        cout<<"not coprime"<<endl;
    }
    if(f==1)
    {
        cout<<"setwise coprime"<<endl;
    }
    if(f==0)
    {
        cout<<"pairwise coprime"<<endl;
    }
}



Measured memory_bytes: 21800
package main

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

func main() {
	N := nextInt()
	M := nextInt()

	ans := min(N, M/2)
	rem := M - ans*2
	if rem > 0 {
		ans += rem / 4
	}

	fmt.Println(ans)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

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

	return i
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	if x < y {
		return x
	}

	return y
}

// ---------- Util.


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

int main(){
  long long N;
  cin>>N;
  long long j=0,k=0,l=0;
  for(long long i=0;i<N;i++){
    long long H;
    cin>>H;
    if(k>=H){
      l++;
    }
    else{
      j=max(j,l);
      l=0;
    }
    k=H;
  }
  cout<<max(j,l)<<endl;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}
#define int ll
void solve(){
	int n, k;
	cin >> n >> k;
	int ans = 0;
	REP(i, n-1) {
		ans += 1 + ans / (k - 1LL);
	}
	cout << ans << endl;
}

#undef int
int main() {
	init();
	solve();
}


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

int main()
{
  int N;
  string S;
  cin >> N >> S;
  
  int x = 0;
  int max_x = 0;

  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'I')
      x++;
    else if(S.at(i) == 'D')
      x--;
    if (x > max_x)
      max_x = x;
  }
  
  cout << max_x << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            ans += a - 1;
        }
        System.out.println(ans);
    }
}

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

int main()
{
	ios::sync_with_stdio(false);
	ll hp, res, sum;
	res = sum = 1;
	cin >> hp;
	while (hp != 1)
	{
		hp >>= 1;
		res <<= 1;
		sum += res;
	}
	cout << sum << '\n';
	return 0;
}

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

typedef long long ll;

const int N = 1e5;

int n;
ll a[N+5];
ll anak[N+5][5];

ll get_total(int x){
	return anak[x][0] + anak[x][1] + anak[x][2];
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	if(n==0){
		if(a[0] == 1) printf("1\n");
		else printf("-1\n");
		return 0;
	}
	ll cur = a[n];
	anak[n][0] = cur;
	for(int i=n-1;i>=0;i--){
		anak[i][2] = cur/2;
		anak[i][1] = cur%2;
		anak[i][0] = a[i];
		cur = get_total(i);
	}
	ll root = get_total(0);
	if(root > 1){
		printf("-1\n");
		return 0;
	}
	bool change = 1;
	while(change){
		change = 0;
		for(int i=n-1;i>=0;i--){
			ll punya1 = anak[i][1];
			ll child2 = anak[i+1][2];
			ll mini = min(punya1,child2);
			if(mini != 0) change = 1;
			anak[i][1] -= mini;
			anak[i][2] += mini;
			anak[i+1][2] -= mini;
			anak[i+1][1] += 2ll*mini;
		}
	}
	ll ans = 0ll;
	for(int i=0;i<=n;i++){
		ans += get_total(i);
	}
	printf("%lld\n",ans);
	return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

const LL MOD = 2019;

void solve(long long L, long long R){
    if(MOD <= R - L) {
        cout << 0 << endl;
        return;
    }

    LL ans = INF;
    REP2(i, L, R+1) {
        REP2(j, i+1, R+1) {
            ans = min(((LL)i * j) % MOD, ans);
        }
    }

    cout << ans << endl;
}

int main(){
    long long L;
    scanf("%lld",&L);
    long long R;
    scanf("%lld",&R);
    solve(L, R);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int h = Integer.parseInt(sc.next());
			int w = Integer.parseInt(sc.next());
			// テーブル
			int[][] square = new int[10][10];
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					square[i][j] = Integer.parseInt(sc.next());
				}
			}
			// 壁
			int[] wall = new int[h * w];
			for (int i = 0; i < h * w; i++) {
				wall[i] = Integer.parseInt(sc.next());
			}
			boolean flag = true;
			while (flag) {
				flag = false;
				for (int i = 0; i < 10; i++) {
					if (i == 1) {
						continue;
					}
					for (int j = 0; j < 10; j++) {
						if (j == 1 || i == j) {
							continue;
						}
						if (square[i][j] + square[j][1] < square[i][1]) {
							square[i][1] = square[i][j] + square[j][1];
							flag = true;
						}
					}
				}
			}
			long ans = 0;
			for (int i = 0; i < h * w; i++) {
				if (wall[i] == -1 || wall[i] == 1) {
					continue;
				}
				ans += square[wall[i]][1];
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 45224
#include <stdio.h>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
  int n, i, j, m, k, g;
  vector< pair< int, int > > v;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    scanf("%d%d", &k, &g);
    pair<int, int> p = make_pair(k, g);
    v.push_back(p);
  }
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    scanf("%d%d", &k, &g);
    pair<int, int> p = make_pair(k, g);
    v.push_back(p);
  }
  sort(v.begin(), v.end());
  vector<pair<int, int>>::iterator it;
  for(it = v.begin(); it != v.end(); ++it) {
    if(it == v.begin()) printf("%d:%02d", (*it).first, (*it).second);
    else if((*it).first != (*(it - 1)).first || (*it).second != (*(it - 1)).second) printf(" %d:%02d", (*it).first, (*it).second);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2768
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define ll long long
#define P pair<int, int>
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve(){
    
}
int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++){
        if(i % 3 != 0 && i % 5 != 0){
            ans += i;
        }
    } 
    cout << ans << endl;
    
    solve();
    return 0;
}



Measured memory_bytes: 3632
# coding: utf-8
# Your code here!
N=int(input())

l=[]

for _ in range(N):
    A,B=map(int,input().split())
    l.append([B,A])

l.sort()

now=0

for i in range(N):
    now+=l[i][1]
    if now>l[i][0]:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 35608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	int n;
	cin >> n;
	int d1 = n % 10;
	n /= 10;
	int d2 = n % 10;
	n /= 10;
	int d3 = n % 10;
	if (d1 == 7 || d2 == 7 || d3 == 7) {
		cout << "Yes\n";
	}
	else
		cout << "No\n";
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()

int main()
{
   int n;
   cin>>n;
   long double arr[n+1];
   forl(i,1,n+1) cin>>arr[i];
   long double dp[n+1][n+1];
//    forl(i,0,n+1)forl(j,0,n+1) dp[i][j]=0;
    dp[0][0]=1;
   forl(j,1,n+1) 
   {
       dp[0][j]=0;
   } 

   forl(i,1,n+1)
   {
       forl(j,0,n+1)
       {

            if(j<=i)
            {
                if(j-1>=0)dp[i][j]=arr[i]*dp[i-1][j-1]+(1-arr[i])*dp[i-1][j]; 
            else dp[i][j]=(1-arr[i])*dp[i-1][j];  
            }
            else dp[i][j]=0;
       }
   }
    long double  sum=0;
   forl(i,n/2+1,n+1) sum+=dp[n][i];
   cout<<setprecision(10)<<fixed<<sum<<endl;

}



Measured memory_bytes: 140928
num, bricks, count, smash = int(input()), [int(x) for x in input().split(" ")], 1, 0
for x in bricks:
    if count == x: count += 1
    else: smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)

Measured memory_bytes: 26012
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i <= (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = long long;


int main() {

	int n, Y;
	cin >> n >> Y;
	
	rep(i, n) {
		rep(j, (n - i)) {
			int x = i * 10000;
			int y = j*5000;
			int z = (n - i - j)*1000;
			if (z < 0) { break; }
			if (x+y+z == Y) {
				cout << i << ' ' << j << ' ' << n-i-j<<endl;
				
				return 0;
			}
			
		}
	}
	
	cout << "-1 -1 -1" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[6];
		for (int i = 0; i < 6; i++) {
			a[i] = sc.nextInt();
		}
		boolean s = true;
		for (int i = 0; i < 6; i++) {
			for (int j = i; j < 6; j++) {
				if (a[5] < Math.abs(a[i] - a[j])) {
					s = false;
					break;
				}
			}
		}
		System.out.println((s) ? "Yay!" : ":(");
	}

}


Measured memory_bytes: 21844
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> a;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        if (i == 0 || x != a.back()) a.push_back(x);
    }
    if (a.size() == 1) { cout << "1000\n"; return 0; }
    long long ans = 1000;
    long long st = 0;
    int i = 0;
    if (a[0] < a[1]) {
        st = ans / a[0];
        ans -= st * a[0];
    }
    for (int i = 1; i < a.size()-1; i++) {
        if (a[i] < a[i+1]) {
            long long k = ans / a[i];
            ans -= a[i] * k;
            st += k;
        } else if (a[i] > a[i+1]) {
            ans += a[i] * st;
            st = 0;
        }
    }
    ans += a.back() * st;
    cout << ans << endl;
}


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

using namespace std;

typedef long long int ll;

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; }

typedef pair<int,int> pair;

int main(){
    int h,a;
    cin >> h >> a;
    int ans=h/a;
    int an=h%a;
    if(an!=0) ans++;



    cout << ans << endl;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;

int main() {
  int n; cin>>n;
  int cnt = 0;
  rep(i,n) {
    int k; cin>>k;
    if (i+1 != k) cnt += 1;
  }
  if (cnt > 2) cout << "NO" << endl;
  else cout << "YES" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  int B;
  cin >> A;
  cin >> B;
  if(A + B > 23){
    cout << A + B - 24 << endl;
  }
  else{
    cout << A + B << endl;
  }
}

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


string s;


int main()
{
    cin >> s;
    int n = s.size();
    for (int i = 0, j = n-1; i < n; i++,j--)
    if (s[i] != s[j])
    {
        cout << "No";
        return 0;
    }


    bool b1 = true, b2 = true;
    for (int i = 0, j = (n-1)/2-1; i < (n-1)/2; i++,j--)
    {
        if (s[i] != s[j])
        {
            b1 = false;
            break;
        }
    }
    for (int i = (n+3)/2 - 1, j = n-1; i < n; i++,j--)
    if (s[i] != s[j])
    {
        b2 = false;
        break;
    }
    if (b1 && b2) cout << "Yes"; else cout << "No";
    return 0;
}


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

int main() {
    string str, ans = "YES";
    cin >> str;
    int n = str.length();
    while(n) {
        if(n >= 5 && str.substr(n - 5) == "dream" || str.substr(n - 5) == "erase") {
            str = str.substr(0, n - 5);
            n -= 5;
        } else if(n >= 6 && str.substr(n - 6) == "eraser") {
            str = str.substr(0, n - 6);
            n -= 6;
        } else if(n >= 7 && str.substr(n - 7) == "dreamer") {
            str = str.substr(0, n - 7);
            n -= 7;
        } else {
            ans = "NO";
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
using namespace std;
#define FOR(i,a) for(int i=0;i<(int)(a);i++)
#define pb push_back
#define clr clear()
#define sz size()
typedef unsigned int ui;

class node{
public:
  int num;
  void set(int n){num = n;}
  bool equal(int a){
    return num == a;
  }
};

class edge{
public:
  node b,e;
  int cost;

  void set(int s,int g,int c){
    b.set(s);
    e.set(g);
    cost = c;
  }
};

class graph{
public:
  vector<node> n;
  vector<edge> e;

  void set(void){
    n.clr;
    e.clr;
  }

  bool Nexist(node a){
    FOR(i,n.sz){
      if(a.num == n[i].num)return true;
    }
    return false;
  }

  int Eexist(int a,int b){
    for(ui i=0;i<e.sz;i++){
      if(e[i].b.equal(a) && e[i].e.equal(b))return i;
      if(e[i].b.equal(b) && e[i].e.equal(a))return i;
    }
    return -1;
  }

  void Nadd(node a){
    if(!n.sz)n.pb(a);
    else if(!Nexist(a)){
      ui i = 0;
      while(n[i].num < a.num && i<n.sz)i++;
      n.insert(n.begin()+i,a);
    }
  }

  void Eadd(edge a){
    if(!e.sz)e.pb(a);
    else{
      ui i = 0;
      while(e[i].cost < a.cost && i<e.sz)i++;
      e.insert(e.begin()+i,a);
    }
    Nadd(a.b);
    Nadd(a.e);
  }

  graph prim(void){
    graph res;

    res.set();

    if(!e.sz)return res;
    else{
      res.Eadd(e[0]);
      res.Nadd(e[0].b);
      res.Nadd(e[0].e);

      while(res.n.sz < n.sz){
	FOR(i,e.sz){
	  if(res.Nexist(e[i].b) && !res.Nexist(e[i].e)){
	    res.Eadd(e[i]);
	    res.Nadd(e[i].e);
	    i = 0;
	  }else if(!res.Nexist(e[i].b) && res.Nexist(e[i].e) ){
	    res.Eadd(e[i]);
	    res.Nadd(e[i].b);
	    i = 0;
	  }
	}
      }
      return res;
    }
  }

  vector<int> warshall_floyd(void){
    vector<int> at;
    int tmp;
    for(ui i=0;i<n.sz;i++){
      for(ui j=0;j<n.sz;j++){
	if(i==j)at.pb(0);
	else{
	  tmp = Eexist(i,j);
	  if(tmp>=0)at.pb(e[tmp].cost);
	  else at.pb(-1);
	}
      }
    }
    for(ui k=0;k<n.sz;k++){
      for(ui i=0;i<n.sz;i++){
	for(ui j=0;j<n.sz;j++){
	  if(at[i*n.sz+k] >= 0 && at[k*n.sz+j] >= 0){
	    if(at[i*n.sz+k] + at[k*n.sz+j] < at[i*n.sz+j] || at[i*n.sz+j]<0){
	      at[i*n.sz+j] = at[i*n.sz+k] + at[k*n.sz+j];
	      at[j*n.sz+i] = at[i*n.sz+k] + at[k*n.sz+j];
	    }
	  }
	}
      }
    }
    return at;
  }
};

int main(){
  int n;
  int a,b,c;
  vector<int> at;
  graph wf;
  edge tmp;
  int cost,max,minn;
  int min;

  while(1){
    cin >> n;
    if(!n)break;

    max = 0;
    wf.set();
    at.clear();
    for(int k=0;k<n;k++){
      cin >> a >> b >> c;
      if(max < a)max = a;
      if(max < b)max = b;
      tmp.set(a,b,c);
      wf.Eadd(tmp);
    }

    at = wf.warshall_floyd();
    
    max++;

    min = 2000000000;
    for(int i=0;i<max;i++){
      cost = 0;
      for(int j=0;j<max;j++)cost += at[i*max+j];
      if(min > cost){
	min = cost;
	minn = i;
      }
    }
    cout << minn << " " << min << endl;
  }
}

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

int n, z, w, a[2000];

int main() {
	cin >> n >> z >> w;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	if (n == 1)
		cout << abs(a[0] - w);
	else
		cout << max(abs(a[n - 1] - w), abs(a[n - 2] - a[n - 1]));
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
bool h(int n)
{
	int a[5];
	int i=0;
	while(n>0)
	{
		a[i]=n%10;
		n/=10;
		i++;
	}
	if(a[0]==a[4]&&a[1]==a[3])
		return true;
	else
		return false;
}
int main()
{
	int a,b;
	cin>>a>>b;
	int ans=0;
	for(int i=a;i<=b;++i)
		if(h(i))
			ans++;
	cout<<ans;
	return 0;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main(void){
   string S;
   cin>>S;
   int ans=0;
   for(int i=0;i<S.size()-1;i++){
      if(S[i]!=S[i+1]) ans++;
   }
   cout<<ans<<endl;
   return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a.at(i);

    sort(a.begin(), a.end());
    rep(i,n-1) {
        if (a.at(i) == a.at(i + 1)) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const int INF = numeric_limits<int>::max();
int main()
{
	string S;
	cin >> S;

	string res;
	REP( i, (int)S.size() )
	{
		if( S[i] == '0' )
		{
			res = res + "0";
		}
		else if( S[i] == '1' )
		{
			res = res + "1";
		}
		else if( S[i] == 'B' )
		{
			if( res.empty() )
			{
				continue;
			}
			res.erase( res.begin() + (int)res.size()-1 );
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,i,j;
	cin>>n;
	ll sum=0;
	for(i=1;i<n;i++){
	    sum+=i;
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

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

  if((a + b == c) || (b + c == a) || (c + a == b)){
    cout << "Yes" << endl;
  } else{
    cout << "No" << endl;
  }
  
  return 0;
}

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

int main(){
    int H,W;
    
    while(1){
        cin >> H >> W;
        if(H==0 and W==0) break;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if((i+j)%2==0) cout<<"#";
                else cout<<".";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
using namespace std;
const int N = 5e5+5;
ll n, m, k, x, y, a, b, t, q, ans, sum;
char c;
string str;
vector< ll >v;
ll A[N],B[N];
main()
{
	ios::sync_with_stdio(0);
	cin>>n>>k;
	if((n+1)/2>=k)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N; cin>>N;
  vector<int> H(N);
  for(int i = 0; i < N; ++i){
    cin>>H[i];
  }
  
  int ans = 0;
  for(int i = 0; i < N; ++i){
    bool is_candidate = true;
    for(int j = 0; j < i; ++j){
      if(H[j] > H[i]){
      is_candidate = false;
      break;
      }
    }
    if(is_candidate){
      ++ans;
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;

int main(){
  int N;
  cin>>N;
  vi A(N);
  rep(i,N)cin>>A[i];
  map<int,int> se;
  rep(i,N){
    se[A[i]]++;
  }
  int cnt=0;
  rep(i,N){
    bool ok=true;
    for(int j=2; j*j<=A[i];j++){
      if(A[i]%j==0){
         if(se.count(A[i]/j) || se.count(j))ok=false;
      }
    }
    if(A[i]!=1){if(se[A[i]] != 1 ||se.count(1) )ok=false;}
    else if(A[i]==1){if( se[A[i]] != 1) ok=false;}
    if(ok)cnt++;  
  }
  cout<<cnt<<endl;
}

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

string v[20];
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
int W,H,x,y;
int cnt;

void search(int y, int x)
{
  int i;
  if(v[y][x]=='#') return;
  cnt++;
  v[y][x] = '#';
  for(i=0;i<4;i++){
    if(x+dx[i]<0||W<=x+dx[i]) continue;
    if(y+dy[i]<0||H<=y+dy[i]) continue;
    if(v[y+dy[i]][x+dx[i]] != '.') continue;
    search(y+dy[i],x+dx[i]);
  }
  return;
}

int main()
{
  int i;
  while(cin>>W>>H,W||H){
    for(i=0;i<H;i++){
      cin>>v[i];
      if(v[i].find("@")!=string::npos){
	x=i;
	y=v[i].find("@");
      }
    }
    cnt=0;
    search(x,y);
    cout<<cnt<<endl;
  }
}

Measured memory_bytes: 0
#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 = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

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

int A, B;

int main() {
  cin >> A >> B;
  cout << (A + B) % 24;
}


Measured memory_bytes: 3596
/*input
*/

// #include<bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <cstdint>
#include <tuple>
#endif
 
using namespace std;
long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
const long long lim = 2e5+10;
typedef long long int lld;
typedef long long ll;

#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define mset(a, v) memset(a, v, sizeof(a))
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }


#define popcount __builtin_popcountll

ll powP(ll x, ll y) {
    ll ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}


ll Array[lim],BArray[lim],dp[lim];

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt 
    freopen("output.txt", "w", stdout);
    #endif

    lld T,i,p,j,l,e,r,b,c,k,q,a,d,w,x,y,u,v,z,t,curr,prev,sum=0,val,countA=0,indicator=0,pos,h,minA,maxA,type,n,m,ans=0,left,right;
    string A,B;
    cin>>a>>b>>c;
    cout<<(c*(a+b))/2<<endl;


    return 0;
}





Measured memory_bytes: 3584
def bg(n,x):##nバーガーのx番目のパティの数
    if n==0:return 1
    l = wid[n-1]
    if x==1:return 0
    if 1<x<=l+1:
        return bg(n-1,x-1)
    if x==l+2:
        return pat[n-1]+1
    if l+2<x<=2*l+2:
        return pat[n-1]+1 + bg(n-1,x-l-2)
    if x==2*l+3 :
        return pat[n]

wid = [1]*51
for i in range(1,51):
    wid[i] = 2*wid[i-1]+3
pat = [1]*51
for i in range(1,51):
    pat[i] = pat[i-1]*2+1
n,x = map(int,input().split())
print(bg(n,x))


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

int h, w, k;

int f(vector<vector<int>> g, int x, int y) {
	g[y][x] = 0;
	
	int ret = 0;
	for (int c = 1; ; c *= 2) {
		rep(j, w) {
			for (int i = h - 1; i > 0; i--) {
				if (g[i][j] == 0) {
					int t = i - 1;
					while (t > 0 && g[t][j] == 0) t--;
					if (g[t][j] != 0) swap(g[i][j], g[t][j]);
				}
			}
		}
		
		bool loop = false;
		rep(i, h) {
			int num = g[i][0];
			int cnt = 1;
			int idx = 0;
			for (int j = 1; j < w; j++) {
				if (g[i][j] == num) cnt++;
				else {
					if (num > 0 && cnt >= k) {
						ret += num * cnt * c;
						rep(k, cnt) g[i][idx + k] = 0;
						loop = true;
					}
					num = g[i][j];
					cnt = 1;
					idx = j;
				}
			}
			
			if (num > 0 && cnt >= k) {
				ret += num * cnt * c;
				rep(k, cnt) g[i][idx + k] = 0;
				loop = true;
			}
		}
		
		if (!loop) break;
	}
	
	return ret;
}

int main() {
	cin >> h >> w >> k;
	
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	
	vector<vector<int>> g(h, vector<int>(w));
	rep(i, h) rep(j, w) g[i][j] = s[i][j] - '0';
	
	int ans = 0;
	rep(i, h) rep(j, w) ans = max(ans, f(g, j, i));
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3608
//Bismillahir-Rahmanir-Rahim
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int llu;
#define f1(i,n) for(i=1;i<=n;i++)
#define f(i,n) for(i=0;i<n;i++)
#define Max 1000009
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
     ll n,k,i,j,r=0,w=0,rn=0,wn=0,op=0;
     cin>>n;
     r=7%n;
     for(i=1;i<=1e6;i++)
     {
         if(r%n==0)
         {
             cout<<i<<endl;
             return 0;
         }
         r=r*10+7;
         r=r%n;
     }
     cout<<-1<<endl;
}














Measured memory_bytes: 3628
import java.util.*;
import java.util.PriorityQueue;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
 
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[N];
        PriorityQueue<Integer> que = new PriorityQueue<>(Collections.reverseOrder());

        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
            que.add(A[i]);
        }
        for(int i=0; i<M; i++){
            int x = que.poll();
            x = x / 2;
            que.add(x);
        }
        long ans = 0;
        for(int i=0; i<N; i++){
            ans += que.poll();
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 64668
import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    var n = 0
    while( {n=readInt;n} != 0 ) {
      val l = new ArrayBuffer[Array[Int]]
      val sum = new Array[Int](n+1)
      for(i<-1 to n) {
        val s = readLine.split(" ").map(_.toInt)
        l += s :+ s.sum
        (0 until n).foreach ( i => sum(i) += s(i) )
      }
      sum(n) = l.toArray.map(e=>e(n)).sum
      println(l.toArray.map(_.map("%5d".format(_)).mkString).mkString("\n"))
      println(sum.map("%5d".format(_)).mkString)
    }
  }
}

Measured memory_bytes: 47856
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    println((1..n).fold(1L) { acc, i -> (acc * i) % 1000000007 })
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 33612
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int W = nextInt();
		int[][] item = new int[N][2];
		long[][] dp = new long[N+1][W+1];
		for(int i=0;i<N;i++){
			item[i][0]=nextInt();
			item[i][1]=nextInt();
			Arrays.fill(dp[i], 0);
		}

		for(int i=0;i<N;i++){
			for(int w=0;w<=W;w++){
				if(w>=item[i][1]){
					dp[i+1][w]=Math.max(dp[i][w-item[i][1]]+item[i][0],dp[i][w]);
				}else{
					dp[i+1][w]=dp[i][w];
				}
			}
		}
		System.out.println(dp[N][W]);
	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 33252
N, M = map(int, input().split())
s = []
c = []
for i in range(M):
    si, ci = map(int, input().split())
    s.append(si-1)
    c.append(ci)

answer = [-1] * N
valid = True
for i in range(M):
    if answer[s[i]] != -1 and answer[s[i]] != c[i]:
        valid = False
        break
    answer[s[i]] = c[i]

if answer[0] == 0 and N != 1:
    valid = False

if valid:
    if N == 1 and answer[0] == -1:
        answer[0] = 0
    elif answer[0] == -1:
        answer[0] = 1
    for i in range(N):
        if answer[i] == -1:
            answer[i] = 0
    print(int(''.join(map(lambda x: str(x), answer))))
else:
    print(-1)

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;
 
/*
struct SegmentTree{
   
  vector<lol> SumV(1000005,0);
  vector<lol> MaxV(1000005,0);
  vector<lol> MinV(1000005,0);
  int N;
   
  void update(int i,int x){
    i += N - 1;
    minv[i] = x;
    maxv[i] = x;
    sumv[i] = x;
    while(i > 0){
      i = (i - 1)/2;
      maxv[i] = max(maxv[i*2+1],maxv[i*2+2]);
      minv[i] = min(minv[i*2+1],minv[i*2+2]);
      sumv[i] = sumv[i*2+1]+sumv[i*2+2];
    }
  }
   
  void add(int i,int x){
    i += N - 1;
    sumv[i] += x;
    maxv[i] += x;
    minv[i] += x;
    while(i > 0){
      i = (i - 1)/2;
      sumv[i] = sumv[i*2+1]+sumv[i*2+2];
      minv[i] = min(minv[i*2+1],minv[i*2+2]);
      maxv[i] = max(maxv[i*2+1],maxv[i*2+2]);
    }
  }
   
  int getmax(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return -INF;
    if(a <= l && r <= b) return maxv[k];
    else{
      int c1 = getmax(a,b,2*k+1,l,(l+r)/2);
      int c2 = getmax(a,b,2*k+2,(l+r)/2,r);
      return max(c1,c2);
    }
  }
   
  int getmin(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return INF;
    if(a <= l && r <= b) return minv[k];
    else{
      int c1 = getmin(a,b,2*k+1,l,(l+r)/2);
      int c2 = getmin(a,b,2*k+2,(l+r)/2,r);
      return min(c1,c2);
    }
  }
   
  int getsum(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return sumv[k];
    else{
      int c1 = getsum(a,b,2*k+1,l,(l+r)/2);
      int c2 = getsum(a,b,2*k+2,(l+r)/2,r);
      return c1+c2;
    }
  }
}
*/
 
//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}
//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  s = s + s;
  rep(i, t.size()){
    bool nasu = true;
    rep(j, t.size()){
      if(s[i + j] != t[j]){
	nasu = false;
      }
    }
    if(nasu){
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

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

typedef struct{
  int x,y;
  int o,st;
  int cost;
}state;

int vis[10][10][1<<10][50];
int in[10][10];

main(){
  int w,h;
  while(cin>>w>>h,w|h){
    memset(vis,0,sizeof(vis));
    rep(i,10)rep(j,10)rep(k,1<<10)rep(l,50)vis[i][j][k][l]=1<<28;
    
    int f,m,o;
    cin>>f>>m>>o;

    rep(i,h)rep(j,w)cin>>in[i][j];

    queue<state> Q;
    state st;
    st.x=0;
    rep(i,w){
      st.y=i;
      st.o=o-1;
      if(st.o<1)continue;
      if(in[0][i]<0){
	st.cost=-in[0][i];
      }else{
	st.o+=in[0][i];
	st.cost=0;
      }
      if(st.o>m)st.o=m;
      st.st=1<<i;
      if(st.cost>f || st.o<1)continue;
      Q.push(st);
    }
    

    while(!Q.empty()){
      st=Q.front();Q.pop();
      int cx=st.x,cy=st.y,cvis=st.st,cc=st.cost,co=st.o;
      if(vis[cx][cy][cvis][co]<=cc)continue;
      vis[cx][cy][cvis][co]=cc;

      rep(i,3){
	int nx=cx+dx[i],ny=cy+dy[i];
	int nc=cc;
	int no=co-1;
	int nvis=cvis;
	if(no<1)continue;
	if(nx<0 || h<=nx || ny<0 || w<=ny)continue;
	if((dx[i]==0 && (nvis>>ny&1)==0) || dx[i]){
	  if(in[nx][ny]<0)nc-=in[nx][ny];
	  else no+=in[nx][ny];
	  if(no>m)no=m;
	}
	if(dx[i]==0)nvis=cvis|1<<ny;
	else nvis=1<<ny;
	if(nc>f)continue;
	if(vis[nx][ny][nvis][no]<=nc)continue;
	st.x=nx,st.y=ny,st.st=nvis,st.cost=nc,st.o=no;
	Q.push(st);
      }
    }
    int ans=f+1;


    rep(i,w)rep(j,1<<w)rep(k,m)ans=min(ans,vis[h-1][i][j][k+1]);

    if(ans==f+1)cout<<"NA"<<endl;
    else cout<<ans<<endl;
  }
}
	   

Measured memory_bytes: 21000
#include <bits/stdc++.h>
using namespace std;
const double PI  = acos(-1.0);
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{

    int X;
    cin >> X;
    cout << 1 + (1999 - X)/200;
    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	long long int x,y;
 	cin >> x>>y;
 	if(x<y/2){
 		long long int a=y-x*2;
 		cout << x+a/4 << endl;
 		return 0;
 	}else{
 		cout << y/2 << endl;
 		return 0;
 	}
 }

Measured memory_bytes: 256