akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,1,-1,-1};
const int INF = 1e8;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> Pii;
typedef pair<int,vi > P;
typedef unsigned long long ll;
string stage[128];
int main(){
	int H,W;
	cin >> H >> W;
	rep(i,H){
		int bef = -1;
		cin >> stage[i];
		rep(j,W){
			if(stage[i][j] == 'c'){
				printf("0");
				bef = j;
			}
			else{
				if(bef == -1){
					printf("-1");
				}
				else{
					printf("%d",j-bef);
				}
			}
			printf("%c",j == W-1?'\n':' ');
		}
	}
	return 0;
}

Measured memory_bytes: 1224
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int N=sc.nextInt();
		String S=sc.next();
		int len[][]=new int[N+1][N+1];
		//System.out.println(len[0][0]);
		int ans=0;
		for(int i=N-1;i>=0;i--) {
			for(int j=i-1;j>=0;j--) {
				if(S.charAt(i)==S.charAt(j)) {
					len[i][j]=len[i+1][j+1]+1;
				}
				ans=Math.max(ans, Math.min(len[i][j],i-j ));
			}
		}
		/*for(int i=0;i<N;i++) {
			for(int j=0;j<N;j++) {
				System.out.print(len[i][j]+",");
			}
			System.out.println();
		}*/
		System.out.println(ans);

	}
}


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

int func(int x){
  if(x%100 != 0) return 0;
  return func(x/100)+1;
}

int main(void){
  int D, N;
  cin >> D >> N;
  int cnt = 0;
  for(int x=1;;x++){
    if(func(x) == D){
      cnt++;
      if(N == cnt){
        cout << x << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

vector<LL> d(13,0);
vector<bool> frag(24,false);

LL solve(){
    LL ans = 24;
    for(LL i = 0; i < 24; i++){
        for(LL j = i+1; j < 24; j++){
            if(frag[j] && frag[i]){
                ans = min(ans,min(j-i,24-(j-i)));
            }
        }
    }
    return ans;
}

LL dfs(LL ind){

    if(ind == 13){
        return solve();
    }

    if(d[ind] == 0){
        return dfs(ind+1);
    }else if(d[ind] == 1){
        frag[ind] = true;
        LL ret1 = dfs(ind+1);
        frag[ind] = false; 
        frag[24-ind] = true;
        LL ret2 = dfs(ind+1);
        frag[24-ind] = false;
        return max(ret1,ret2);
    }else{
        frag[ind] = true;
        frag[24-ind] = true;
        LL ret = dfs(ind+1);
        frag[ind] = false;
        frag[24-ind] = false;
        return ret;
    }
}

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

    LL n;
    cin >> n;

    d[0]++;

    for(int i = 0; i < n; i++){
        LL x;
        cin >> x;
        d[x]++;
    }
    for(int i = 0; i < 13; i++){
        if(i == 0 && d[i] >= 2){
            cout << 0 << endl;
            return 0;
        }
        if(d[i] >= 3){
            cout << 0 << endl;
            return 0;
        }
    }

    frag[0] = true;

    cout << dfs(1) << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#define FREE 0
#define NOT_FREE 1
#define N 8
#define M 15
 
int r, c, R[N], C[N], P[M], D[M];
 
int putQueen(int i){
 
  int j;
 
  if(i == N){
    return 0;
  }  
   
  if(R[i] == -1){ 
    for(j = 0 ; j < N ; j++){
      if(C[j] == NOT_FREE || P[i+j] == NOT_FREE || D[i-j+N-1] == NOT_FREE){
	continue;
      }
    
      R[i] = j;
      C[j] = P[i+j] = D[i-j+N-1] = NOT_FREE;
      if(putQueen(i+1) == 0){
	return 0;
      }
      R[i] = -1;
      C[j] = P[i+j] = D[i-j+N-1] = FREE;
    }
    return 1;
  }
  else{
    if(putQueen(i+1) == 0){
      return 0;
    }
    return 1;
  }
 
}
 
int main(){
 
  int i, j, k;
 
  for(i = 0 ; i < N ; i++){
    R[i] = -1;
  }
   
  scanf("%d", &k);
  for(i = 0 ; i < k ; i++){
    scanf("%d%d", &r, &c);
    R[r] = c;
    C[c] = NOT_FREE;
    P[r+c] = NOT_FREE;
    D[r-c+N-1] = NOT_FREE;
  }
 
  putQueen(0);
 
  for(i = 0 ; i < N ; i++){
    for(j = 0 ; j < N ; j++){
      if(R[i] == j){
	printf("Q");
      }
      else{
	printf(".");
      }
    }
    printf("\n");
  }
   
  return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
long long n,ans,dp[2020][2020];
pair<long long,long long>p[2020];
bool cmp(pair<long long,long long>a,pair<long long,long long>b)
{
	if(a.first!=b.first)
	{
		return a.first>b.first;
	}
	return a.second<b.second;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		long long a;
		cin>>a;
		p[i]=make_pair(a,i);
	}
	sort(p+1,p+n+1,cmp);
	for(int i=1;i<=n;i++)
	{
		for(int l=1;l<=n;l++)
		{
			int r=n-(i-l);
			if(r>n)
			{
				continue;
			}
			dp[l+1][r]=max(dp[l+1][r],dp[l][r]+p[i].first*abs(p[i].second-l));
			dp[l][r-1]=max(dp[l][r-1],dp[l][r]+p[i].first*abs(p[i].second-r));
		}
	}
	for(int i=1;i<=n+1;i++)
	{
		ans=max(ans,dp[i][i-1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 26316
import math
K = int(input())

ret = 0
for i in range(1,K+1):
    ret += i

    for j in range(1,i):
        ret += 3 * math.gcd(j, i)

    for j in range(1,i):
        for k in range(1,i):
            tmp = math.gcd(i,j)
            ret += 3*math.gcd(tmp,k)

print(ret)

Measured memory_bytes: 67468
#include<iostream>

#define SWAP(a,b) {int tmp = a;a = b;b = tmp;}

using namespace std;

int main(){
    int n;
    cin >> n;
    int A[n];
    int ans = 0;
    for(int i=0;i<n;i++)cin >> A[i];
    for(int i=0;i<n;i++){
        int minj = i;
        for(int j=i;j<n;j++){
            if(A[j]<A[minj])minj=j;
        }
        if(i!=minj){SWAP(A[i],A[minj]);ans++;}
    }
    cout << A[0];
    for(int i=1;i<n;i++)cout << " " << A[i];
    cout << endl;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main(){
    ll N, A, B;
    cin >> N >> A >> B;
 
    if((B - A) % 2 == 0){
        cout << (B - A) / 2 << endl;
    }else{
        cout << min(A, (N - B + 1)) +  (B - A - 1) / 2 << endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

using namespace std;

int main() {

	SINT32 N = 0;
	SINT32 M = 0;
	SINT32 cnt = 0;

	cin >> N;
	cin >> M;

	vector<pair<int,int>> DATA(M);
	vector<SINT32> SHIMA(N);
	
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA[i].second;
		cin >> DATA[i].first;
	}
	for (SINT32 i = 0; i < N; i++) {
		SHIMA[i] = 1;
	}

	sort(DATA.begin(),DATA.end());

	for (SINT32 i = 0; i < M; i++) {
		if (SHIMA[DATA[i].first-1] == SHIMA[DATA[i].second-1]) {
			cnt++;
			for (SINT32 j = DATA[i].first-1; j < N; j++) {
				SHIMA[j]++;
			}
/*
			for (SINT32 j = 0; j < N; j++) {
				cout << SHIMA[j] << " ";
			}
			cout << endl;
*/
		}
	}


	cout << cnt << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;

	rep(m,n){
		if(-d*m + c*(n-1-m) <= b-a && b-a <= d*(n-1-m) - c*m){
			cout << "YES" << endl;
			return 0;
		}
	}

	cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
using namespace  std;

struct StCst
{
  int m_nNo;
  int m_nSeq;
  bool m_bDone;

  static bool AsdNo(const StCst &cnroLeft, const StCst &cnroRight) 
  { return cnroLeft.m_nNo < cnroRight.m_nNo; }
};

void fnInput(int &rnMaxSiz, vector<StCst> &rvoSort)
{
  int nCnt = 0;
  cin >> rnMaxSiz;

  rvoSort.resize(rnMaxSiz);
  for (int i = 0; i < rnMaxSiz; i++)
  {
    cin >> rvoSort[i].m_nNo;
    rvoSort[i].m_nSeq = nCnt++;
  }
}

void fnMinCostSort(vector<StCst> &rvoSort, int &rnSwpCnt)
{
  sort(begin(rvoSort), end(rvoSort), StCst::AsdNo);
  int nMinNo = rvoSort[0].m_nNo;

  int nCost;
  for (int i = 0; i < rvoSort.size(); i++)
  {
    if (rvoSort[i].m_bDone)  continue;

    int nTotal = rvoSort[i].m_nNo;
    int nCurSize = 1;
    int nCurMin = rvoSort[i].m_nNo; 
    rvoSort[i].m_bDone = true;

    int j = rvoSort[i].m_nSeq;
    while  (rvoSort[j].m_nNo != rvoSort[i].m_nNo)
    {
      nTotal += rvoSort[j].m_nNo;
      nCurSize++;
      nCurMin = min(nCurMin, rvoSort[j].m_nNo);
      rvoSort[j].m_bDone = true;
      j = rvoSort[j].m_nSeq;
    }

    if (nCurSize == 1)
        nCost = 0;
    else
      if (nMinNo == nCurMin)
        nCost = nTotal + (nCurSize - 2) * nCurMin;
      else
        nCost = min(nTotal + (nCurSize - 2) * nCurMin, 
                    nTotal + nCurMin + (nCurSize + 1) * nMinNo);
    rnSwpCnt += nCost;
  }
}

void fnResult(int nSwpCnt)
{
  cout << nSwpCnt << endl;
}

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

  int nMaxSiz;
  vector<StCst> voSort;

  fnInput(nMaxSiz, voSort);

  int nSwpCnt = 0;
  fnMinCostSort(voSort, nSwpCnt);

  fnResult(nSwpCnt);
  return 0;
}

Measured memory_bytes: 1228
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n,m,a,b,c;
	string str;
	cout << fixed << setprecision(10);
	cin>>n>>a>>b;
	cout<<min(n*a,b);


	cout<<endl;
} 


Measured memory_bytes: 256
#define scanf_s scanf
#include <string>
#include <stdio.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
using namespace std;

#define MAX 25
//#define MAX_ 1000

int cou = 0;

struct binarytree
{
	int id;
	binarytree *pp;
	binarytree *brather;
	binarytree *pchleft, *pchright;
};
void de_hi_1(int N, binarytree *p) {
	if (N >= 0) {
		if (p->id != -1) {
			printf(" %d", p->id);
			de_hi_1(N - 1, p->pchleft);
			de_hi_1(N - 1, p->pchright);
		}
	}
}
void de_hi_2(int N, binarytree *p) {
	if (N >= 0) {
		if (p->id != -1) {
			de_hi_2(N - 1, p->pchleft);
			printf(" %d", p->id);
			de_hi_2(N - 1, p->pchright);
		}
	}
}
void de_hi_3(int N, binarytree *p) {
	if (N >= 0) {
		if (p->id != -1) {
			de_hi_3(N - 1, p->pchleft);
			de_hi_3(N - 1, p->pchright);
			printf(" %d", p->id);
		}
	}
}
int main(void)
{
	int n, xid, xl, xr;
	binarytree node[MAX], first, nvalue;
	first.id = -1; nvalue.id = -1; nvalue.brather = &nvalue;
	bool node_b[MAX + 1] = { false };
	scanf_s("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf_s("%d %d %d", &xid, &xl, &xr);
		node[xid].id = xid;
		if (xl == -1) node[xid].pchleft = &nvalue;
		else { node[xid].pchleft = &node[xl]; }
		if (xr == -1) node[xid].pchright = &nvalue;
		else { node[xid].pchright = &node[xr]; }

		if (node_b[xid] == false) { node[xid].pp = &first; node[xid].brather = &nvalue; }

		node[xl].pp = &node[xid]; node[xr].pp = &node[xid];
		node_b[xl] = true; node_b[xr] = true;

		if (xl != -1 && xr != -1) { node[xl].brather = &node[xr]; node[xr].brather = &node[xl]; }
		else {
			if (xl != -1 && xr == -1) { node[xl].brather = &nvalue; }
			if (xl == -1 && xr != -1) { node[xr].brather = &nvalue; }
		}
	}
	for (int i = 0; i < n; ++i) {
		if (node_b[i] == false) {
			printf("Preorder\n");
			de_hi_1(n - 1, &node[i]);
			printf("\nInorder\n");
			de_hi_2(n - 1, &node[i]);
			printf("\nPostorder\n");
			de_hi_3(n - 1, &node[i]);
			printf("\n");
			break;
		}
	}
}

Measured memory_bytes: 3220
#include<stdio.h>
 
int solve(int, int);
 
int n, A[2000];
 
int main(){
   
  int q, Q[2000], i;
   
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &A[i]);
   
  scanf("%d", &q);
  for(i = 0; i < q; i++)
    scanf("%d", &Q[i]);
 
 
  for(i = 0; i < q; i++){
    if(solve(0, Q[i]) == 1)   printf("yes\n");
    else                      printf("no\n");
  }
 
  return 0;
}
 
int solve(int i, int m){
  int res;
 
  if(m == 0)    return 1;
  if(i >= n)    return 0;
   
  res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  //printf("i + 1 = %d, m = %d res = %d\n", i + 1, m, res);
 
  return res;
}

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

int main()
{
  int h, n,a,as=0;
  cin >> h >> n;
  
  REP(i,n){
    cin >> a;
    as += a;
  }

  if(h<=as){
    cout << "Yes" << "\n";
  }else{
    cout << "No" << "\n";
  }

  return 0;
}


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



int sc1(){int x; scanf("%d",&x); return x;}

long long sc2(){long long x;scanf("%lld",&x);return x;}



#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  Int              sc1()
#define  LL               sc2()
#define  For(n)           for(int i=0;i<n;i++)
#define  Forj(n)          for(int j=0;j<n;j++)
#define  Fork(n)          for(int k=0;k<n;k++)
#define  For1(n)          for(int i=1;i<=n;i++)
#define  ll               long long
#define  vi               std::vector<int>
#define  vll              std::vector<ll>
#define  qui              qu
#define  pb               push_back
#define  mpsi             std::map<string, int>
#define  MAX              100007








int main()
{	
	
	//freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int x=Int,a=Int;

    if(x<a) printf("0\n");
    else printf("10\n");
    
    return 0;
}




Measured memory_bytes: 384
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define elif(a) else if(a)
#define INF INT_MAX
#define F first
#define S second
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int maxi=0,n,data[11],ans[11]={};
  cin>>n;
  FOR(i,n){
    cin>>data[i];
    if(data[i]>data[maxi]) maxi=i;
    if(i!=0) ans[i]+=ans[i-1];
    ans[i]+=data[i];
  }
  if(ans[n-1]-2*data[maxi]>0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}



Measured memory_bytes: 256
/*  ex5_4
    pptenshi  */

#include<stdio.h>
#define SIZE 11

int main(void) {
    char string[SIZE];  // S
    char *p_str;        // pointer of string
    int tmp_len = 0,    // temp 
        max_len = 0;    // max length of ACGT

    // input
    scanf("%s", string);


    // calculate
    p_str = string;
    while (*p_str != '\0') {
        switch (*p_str) {
        // if ACGT
        case 'A': case 'C': case 'G': case 'T': 
            tmp_len++;
            break;
        
        // if not AGCT
        default:
            // max_length = max(max_length, length)
            max_len = max_len < tmp_len 
                ? tmp_len 
                : max_len;
            tmp_len = 0;
            break;
        }
        
        p_str++;
    }
    max_len = max_len < tmp_len
        ? tmp_len
        : max_len;


    //output
    printf("%d\n", max_len);

    return 0;
}

Measured memory_bytes: 1728
//Accepted
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
	static StringBuilder sb=new StringBuilder();
	public static void main(String[] args) {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String work[]=new String[2];
		int n;
		int m;

		
		//入力
		try {
			//sample=Integer.parseInt(br.readLine());
			//nとmの入力
			work=br.readLine().split("\\s+");
			n=Integer.parseInt(work[0]);
			m=Integer.parseInt(work[1]);

			int[][] A=new int[n][m];
			int[] b=new int[m];
			
			//Aの入力
			String work2[]=new String[m];
			for(int x=0; x<n; x++) {
				work2=br.readLine().split("\\s+");
				for(int y=0; y<m; y++) {
					A[x][y]=Integer.parseInt(work2[y]);
				}
			}

			//bの入力
			for(int i=0; i<m; i++) {
				b[i]=Integer.parseInt(br.readLine());
			}
			
			//計算処理
			for(int x=0; x<n; x++) {
				int sum=0;
				for(int y=0; y<m; y++) {
					sum += A[x][y]*b[y];
				}
				sb.append(sum);
				sb.append(String.format("%n", ""));
			}

		}catch(Exception e) {
			e.printStackTrace();
		}
		
		//出力
		System.out.print(sb);
	}
	
}


Measured memory_bytes: 31136
// AOJ 2132: Left Hand Rule
// 2017.12.13 bal4u@uu

#include <stdio.h>
#include <string.h>

char h[101][101], v[101][101];
char mk[101][101][4];
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};

char buf[40], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	p++;
	return n;
}

int main()  
{  
	int W, H, N, x, y, i, x1, y1, x2, y2, x3, y3, d, ans;  

    while (fgets(p=buf, 30, stdin) && *p != '0') {
		W = getint(), H = getint(), N = getint();

		memset(h, 0, sizeof(h));
		memset(v, 0, sizeof(v));
		for (x = 0; x < W; x++) v[x][0] = v[x][H] = 1;
		for (y = 0; y < H; y++) h[0][y] = h[W][y] = 1;

		for (i = 0; i < N; i++) {
			fgets(p=buf, 30, stdin);
			x1 = getint(), y1 = getint(), x2 = getint(), y2 = getint();
			if (x1 == x2) {
				if (y1 > y2) y = y1, y1 = y2, y2 = y;
				for (y = y1; y < y2; y++) h[x1][y] = 1;
            } else {
				if (x1 > x2) x = x1, x1 = x2, x2 = x;
				for (x = x1; x < x2; x++) v[x][y1] = 1;
            }  
        }

		fgets(p=buf, 40, stdin);
		x1 = getint(), y1 = getint(), x2 = getint(), y2 = getint();
		x3 = getint(), y3 = getint();
		x = x1; if (x2 < x) x = x2;
		y = y1; if (y2 < y) y = y2;
		if (x1 == x2) { if (x1 == 0) d = 2; else x--, d = 0; }
		else          { if (y1 == 0) d = 1; else y--, d = 3; }

		memset(mk, 0, sizeof(mk));
		ans = 1;
		while (1) {
			if (x == x3 && y == y3) break;

			if (mk[x][y][d]) { ans = -1; break; }
			mk[x][y][d] = 1;

			d += 3; if (d >= 4) d -= 4;
			for (i = 0; i < 4; i++) {
				x2 = x + mv[d][0], y2 = y + mv[d][1];
                if (x2 >= 0 && x2 < W && y2 >= 0 && y2 < H) {
					if (d == 0 && !h[x  ][y] || d == 1 && !v[x][y+1] ||
						d == 2 && !h[x+1][y] || d == 3 && !v[x][y  ]) {	x = x2, y = y2; break; }
				}
                if (++d == 4) d = 0;
            }
            ans++;
        }
        if (ans < 0) puts("Impossible");
		else printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long bio[(1<<18)], n[20][20];
long long g(int m)
{
	vector <int> v;
	for(int i = 0; i < 17; i++)
	{
		if((m&(1<<i))) 
		{
		    v.push_back(i);
		}
	}
	long long z = 0;
	for (int i = 0; i < v.size(); ++i)
	{
		for (int j = i+1; j < v.size(); ++j)
		{
			z += n[v[i]][v[j]];
		}
	}
	return z;
}
 
long long f(int m)
{
	if(m == 0) 
	{
	    return 0;
	}
	if(bio[m] != (long long)(-1e18)) 
	{
        return bio[m];
    }
	bio[m] = g(m);
	for(int i = (m-1)&m; i > 0; i = (i-1)&m)
	{
		bio[m] = max(bio[m] , f(i) + f(m^i));
	}
	return bio[m];
}
 
int main()
{
	int b;
	cin >> b;
	for(int i = 0; i < b; i++)
	{
		for(int j = 0; j < b; j++)
		{
			cin >> n[i][j];
		}
	}
	for (int i = 0; i < (1<<18); i++)
	{
		bio[i] = -1e18;
	}
	cout << f((1<<b)-1) << endl;
	return 0;
}



Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const int N = 1e5;
int a[N+5];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int n, a, b;

    cin >> n >> a >> b;

    cout << min(n*a, b);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <vector>
#include<math.h>
#include <map>
#include <functional>
#include <queue>
#include <string>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
using namespace std;
int cnt[200200];
int main(){
	string s; cin >>s;
	int n=s.size();
	ll ans=0;
	for(int i=0;i<200200;i++){
		cnt[i]=0;
	}
	for(int i=0;i<n-2;i++){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
			ans+=cnt[i]+1;
			cnt[i+2]+=cnt[i];
			s[i]='C'; s[i+2]='A';
		}
		else if(s[i]=='A'){
			cnt[i+1]=cnt[i]+1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1412
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}
//--main function
int main(){
	int n,m,s,sum=0;
	cin>>n>>m;
	vi v(m);
	REP(i,0,m-1){
		cin>>v[i];
	}
	REP(i,0,m-1)sum=sum+v[i];
	if(n-sum<0)cout<<-1;
	else cout<<n-sum;
	return 0;

//   TimeTaken();
}


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

int main(int argc, char const *argv[]) {

    for (int i = 0; i < 10; i++) {
        char cards[201], tmp[201];
        scanf("%s", cards);
        int len = strlen(cards);

        if (strcmp(cards , "-") == 0) {
            break;
        }

        int m;
        scanf("%d", &m);

        for (int j = 0; j < m; j++) {
            int h;
            scanf("%d", &h);

            strcpy(tmp, &cards[h]);
            strncat(tmp, cards, h);
            tmp[len] = '\0';

            strcpy(cards, tmp);

        }

        puts(cards);
    }
    return 0;
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;
int N, A, B;
int main() {
    std::cin >> N >> A >> B;
    std::cout << std::min(A*N, B) << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;

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

double dp[3010][3010];

int main(){
    int n; cin>>n;
    vector<double> p(n);
    for(int i=0; i<n; i++) cin>>p[i];

    dp[0][0]=1;
    for(int i=0; i<n; i++){
        for(int j=0; j<=i; j++){
            dp[i+1][j]+=dp[i][j]*(1-p[i]);
            dp[i+1][j+1]+=dp[i][j]*p[i];
        }
    }
    
    double ans=0;
    for(int i=0; i<=n; i++){
        if(i>n/2) ans+=dp[n][i];
    }
    cout << fixed << setprecision(12) << ans << endl;
}

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

int main() {

  int a, b;
  int ave;
  
  cin >> a >> b;
  
  if((a + b) % 2 != 0) {
    ave = ((a + b) / 2) + 1;
  } else {
    ave = (a + b) / 2;
  }
  cout << ave << endl;
  
  return 0;
}


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

#define ll long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

#define Debug(x) cout<<(#x)<<" >> "<<(x)<<endl

using namespace std;

ll fastpow(ll angka,ll pangkat,ll MOD){
	ll res=1;
	while(pangkat){
		if(pangkat&1) res=(res*angka)%MOD;
		angka=(angka*angka)%MOD;
		pangkat=pangkat>>1;
	}
	return res;
}

ll fastpow(ll angka,ll pangkat){
	ll res=1;
	while(pangkat){
		if(pangkat&1) res=(res*angka);
		angka=(angka*angka);
		pangkat=pangkat>>1;
	}
	return res;
}

ll gcd(ll angka1,ll angka2){
	while(angka2){
		swap(angka1,angka2);
		angka2=angka2%angka1;
	}
	return angka1;
}

ll lcm(ll angka1,ll angka2){
	return (angka1/gcd(angka1,angka2))*angka2;
}

const ll mod=1e9+7;

vector<ll>dp(2005,-1);

ll Solve(ll val){
	if(val==0) return 1;
	if(val<3) return 0;
	
	if(dp[val]!=-1) return dp[val];
	
	ll ret=0;
	for(ll i=3;i<=val;i++){
		ret+=Solve(val-i);
		ret=ret%mod;
	}
	
	return dp[val]=ret;
}

void solve(){
	
	ll s;
	cin>>s;
	
	cout<<Solve(s)<<endl;
	
}

int main(){
	
	fastio();

//	freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

	int t=1;
//	cin>>t;
	
	for(int tt=0;tt<t;tt++){
//		cout<<"Case "<<tt+1<<":\n";solve();
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3676
#include <stdio.h>
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

 int main(){
	 while( true ) {
		int studentNum = 0;
		cin >> studentNum;

		if ( studentNum == 0 ) {
			break;
		}

		vector<int> point(studentNum, 0);
		int sum = 0;
		for ( int i = 0; i < studentNum; i++ ) {
			cin >> point[i];
			sum += point[i];

		}

		// calculate average
		double average = (double)sum / (double)studentNum;
			
		// calculate variance
		double variance = 0;
		for( int i = 0; i < studentNum; i++ ) {
			double deviation	=	point[i]	- average;
			variance			+=	deviation	* deviation;

		}
		variance = variance / studentNum;
			
		// calculate standardDeviation
		double stdDeviation = sqrt(variance );

		printf( "%F\n", stdDeviation );

	 }
}

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

int main(){
    string s,t;
    cin>>s>>t;
    int ans=100000;
    int tmp=0;
    for(int i=0;i<=(s.size()-t.size());i++){
        string sub = s.substr(i, t.size());
        //cout<<sub<<endl;
        tmp=0;
        rep(j, t.size()){
            if(sub[j]!=t[j]) tmp++;
            //cout<<tmp<<endl;
        }
        ans = min(ans, tmp);
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
}

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

int main()
{
    int N, X;
    cin >> N >> X;
    int L[N];
    rep(i, N) cin >> L[i];

    int ans = 1;
    int d = 0;
    for (int i = 0; i < N; i++) {
        d = d + L[i];
        if (d > X) {
            break;
        }
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
#include <math.h>
#include <vector>
//#include <string>
typedef long long LL;
using namespace std;
struct city{
    int p;
    int y;
    
    city(int input_p, int input_y){
        p = input_p;
        y = input_y;
    }
};

int main(){
    int n;
    int m;
    int p_tmp;
    int y_tmp;
    vector<city> citys;
    cin >> n >> m;
    vector<vector <int>> pref(n);
    for(int i=0; i<m; i++){
        cin >> p_tmp >> y_tmp;
        p_tmp--;
        y_tmp--;
        citys.push_back(city(p_tmp, y_tmp));
        pref[p_tmp].push_back(y_tmp);
    }

    for(int i=0; i<n; i++){
        if(pref[i].size()!=0){
            sort(pref[i].begin(), pref[i].end());
        }
    }

    for(int i=0; i<m; i++){
        auto city_position = lower_bound(pref[citys[i].p].begin(), pref[citys[i].p].end(), citys[i].y);
        int city_index = distance(pref[citys[i].p].begin(), city_position);
        city_index++;
        int city_pref = citys[i].p+1;
        LL ans = (LL)city_pref*1000000+(LL)city_index;
        cout.fill('0');
        cout << setw(12) << ans << endl;
    }
}

Measured memory_bytes: 7796
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<" : "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
template<class Type> void line(const Type &a){int cnt=0;for(auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}
template<class Type> void dline(const Type &a){int cnt=0;for(auto &elem:a){if(cnt++)cerr<<' ';cerr<<elem;}cerr<<endl;}

int main(){
	int r;
	cin>>r;
	
	debug(r);//test.
	
	cout<<r*r<<endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())

if k % 2 == 1:
    L = [i for i in range(k, n+1, k)]
    num = len(L)
    print(num**3)
else:
    L1 = [i for i in range(k, n+1, k)]
    L2 = [i for i in range(k//2, n+1, k)]
    num1 = len(L1)
    num2 = len(L2)
    print(num1**3 + num2**3)

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

int main() {
  int N;
  cin >> N;
  
  vector<int> p(N);
  for(int i=0; i<N ;i++){
    cin >> p.at(i);
  }
  
  int ans = 0;
  for(int i=0; i<N-1 ;i++){
    if(p.at(i)==i+1){
      p.at(i+1) = i+1;
      ans ++;
    }
  }
  
  if(p.at(N-1)==N){
    ans ++;
  }
  
  
  cout << ans << endl;
  
  

}

Measured memory_bytes: 3788
import java.util.Map.Entry;
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++) a[i] = sc.nextInt();
		int[] b = new int[N];
		for(int i = 0; i < N; i++) b[i] = sc.nextInt();
		
		long sum = 0;
		for(int i = 0; i < N; i++){
			if(a[i] < b[i]){
				long diff = 1L * b[i] - a[i];
				if(diff >= 2){
					if(diff % 2 == 0) sum -= (1L * b[i] - a[i]);
					else sum -= (1L * b[i] - a[i] - 1);
				}
			}else if(a[i] > b[i]){
				sum += (1L * a[i] - b[i]) * 2;
			}
		}
		if(sum <= 0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int a, b; cin >> a >> b;
	if (a <= 8 && b <= 8) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  vector<string> v(3);
  cin >> v[0] >> v[1] >> v[2];
  char cur = 'a', ans = 'a';
  while (true) {
    if (cur == 'a') {
      if (v[0].size() == 0) {
        ans = 'A';
        break;
      }
      cur = v[0][0];
      v[0].erase(v[0].begin());
    } else if (cur == 'b') {
      if (v[1].size() == 0) {
        ans = 'B';
        break;
      }
      cur = v[1][0];
      v[1].erase(v[1].begin());
    } else {
      if (v[2].size() == 0) {
        ans = 'C';
        break;
      }
      cur = v[2][0];
      v[2].erase(v[2].begin());
    }
  }
  cout << ans << endl;
}

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

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

    if (a > 0 && b > 0) cout << "Positive" << endl;
    else if (a <= 0 && b >= 0) cout << "Zero" << endl;
    else {
        if ((b - a) % 2 == 0) cout << "Negative" << endl;
        else cout << "Positive" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
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;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<int> p(n);
   rep(i, 0, n) cin >> p[i];
   int ans = 0;
   rep(i, 0, n - 2) {
      if (p[i] < p[i + 1] && p[i + 1] < p[i + 2]) {
         ans++;
      }
      if (p[i] > p[i + 1] && p[i + 1] > p[i + 2]) {
         ans++;
      }
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

vector<ll> vec;

ll ans[111111];
ll cnt[111111];
ll P[111111];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll N; int n;
	cin>>N>>n;
	vec.pb(N);
	for(int i=0;i<n;i++)
	{
		ll x; cin>>x;
		while(!vec.empty()&&vec.back()>=x)
		{
			vec.pop_back();
		}
		vec.pb(x);
	}
	n=vec.size();
	cnt[n-1] = 1;
	for(int i=n-1;i>=0;i--)
	{
		ll coeff=cnt[i];
		ll cur=vec[i];
		if(i==0)
		{
			for(int j=0;j<cur;j++) ans[j]+=coeff;
			break;
		}
		while(cur>=vec[0])
		{
			int lb=lower_bound(vec.begin(),vec.end(),cur)-vec.begin();
			lb--;
			if(lb<0) break;
			ll quo = cur/vec[lb]; ll rem = cur%vec[lb];
			//assert(quo>=1);
			cnt[lb]+=quo*coeff;
			//assert(rem*2<=cur);
			cur=rem;
		}
		if(cur>0) P[cur-1]+=coeff;
	}
	for(int i=N-2;i>=0;i--)
	{
		P[i]+=P[i+1];
	}
	for(int i=0;i<N;i++) ans[i]+=P[i];
	for(int i=0;i<N;i++)
	{
		cout<<ans[i]<<'\n';
	}
}


Measured memory_bytes: 4980
local n,m=io.read("n","n")
local a={}
local b={}
local visited={}
local graph={}
for i=1,n do
    graph[i]={}
    for j=1,n do
        graph[i][j]=false
    end
end

local function dfs(x)
    visited[x]=true
    for y=1,n do
        if graph[x][y]==false then
            goto continue
        end
        if visited[y]==true then
            goto continue
        end
        dfs(y)
        ::continue::
    end
end

for i=1,m do
    local x,y=io.read("n","n")
    a[i]=x
    b[i]=y
    graph[x][y]=true
    graph[y][x]=true
end

local counter=0
for i=1,m do
    graph[a[i]][b[i]]=false
    graph[b[i]][a[i]]=false
    for j=1,n do
        visited[j]=false
    end
    dfs(1)
    local bridge=false
    for j=1,n do
        if visited[j]==false then
            bridge=true
        end
    end
    if bridge==true then
        counter=counter+1
    end
    graph[a[i]][b[i]]=true
    graph[b[i]][a[i]]=true
end
print(counter)

Measured memory_bytes: 2732
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	string S;
	cin >> S;
	int ans = 1000;
	for (int i = 0; i < (int)S.size() - 2; i++) {
		int num = (S[i] - '0') * 100 + (S[i + 1] - '0') * 10 + S[i + 2] - '0';
		int diff = abs(num - 753);
		ans = min(ans, diff);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INF 1000000000000 //10^12

int main(){
    ll k,n;
    vector<ll> A;
    cin >> k >> n;
    REP(i,n){
        ll temp;
        cin >> temp;
        A.push_back(temp);
    }

    ll max=0;
    REP(i,n-1){
        ll temp;
        temp =abs(A[i] -A[i+1]);
      //  cout <<temp << endl;
        if(max < temp){
            max = temp;
        }
    }
    if(max < *A.begin() + (k - *(A.end()-1)))
        max =*A.begin() + (k - *(A.end()-1));
    //cout << max <<endl;
    cout << k - max <<endl;
}

Measured memory_bytes: 2420
#include <iostream>
using namespace std;
int main(void){
    int A,B,C,X,i,j,k,ans;
    ans=0;
    cin >> A >> B >> C >> X;
    for(i=0;i<=A;i++){
        for(j=0;j<=B;j++){
            for(k=0;k<=C;k++){
                if((500*i+100*j+50*k)==X){
                    ans++;
                }
            }
        }
    }
    cout << ans; 
    
    return 0;
}


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

using namespace std;

const long long INF = 1e18;

int main() {
	long long x;
	scanf("%lld", &x);
	
	long long res = INF;
	
	for (int i = 1; i <= sqrt(x); i++) {
		if (x % i == 0) res = min(res, x / i + i - 2);
	}
	
	printf("%lld\n", res);
}


Measured memory_bytes: 256
/* ----------------------- reclone_rk --------------------------------------------*/ 
#include<bits/stdc++.h>
using namespace std;
#define int long long int
const int mod=1e9+7;

#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define prq priority_queue<int>
#define prqp priority_queue<pair<int,int>>
#define vtr vector<int>
#define INF INT_MAX
#define NINF INT_MIN
#define endl "\n"
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define pvtr vector<pair<int,int>>
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)

int gcd(int a, int b){ if(a == 0) return b; return gcd(b%a, a);}
int MOD(int n){ return ((n%mod)+mod)%mod;}
int power(int a,int b){ if(b==0)return 1LL;int s=power(a,b/2LL);s*=s;s%=mod;if(b&1LL)return (s*a)%mod;return s;}
int inv(int a){return power(a,mod-2);}
int nCr(int n,int r){if(r>n)return 0LL;if(n-r<r)r=n-r;int ans=1;for(int i=0;i<r;i++){ans*=(n-i);ans=MOD(ans);ans*=inv(i+1);ans=MOD(ans);}return ans;}

const double pi = 3.14159265358979323846;
signed main()
{   
    int a, b;
    cin>>a>>b;
    cout<<a*b<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int main(){
  double x1,y1,x2,y2,nijou,ans=0.0;
  int i;
  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
  nijou=pow((x1-x2),2) + pow((y1-y2),2);
  for(i=0;i<=5;i++){
    while(1){
      if(pow(ans+pow(10,-i),2) <=nijou){
        ans+=pow(10,-i);
      }
      else break;
    }
  }
  printf("%lf\n",ans);
  return 0;
}

Measured memory_bytes: 696
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
s = S()
if s == 'SUN':
    print(7)
elif s == 'MON':
    print(6)
elif s == 'TUE':
    print(5)
elif s == 'WED':
    print(4)
elif s == 'THU':
    print(3)
elif s == 'FRI':
    print(2)
elif s == 'SAT':
    print(1)

Measured memory_bytes: 3896
n=int(input())
li=list(map(int,input().split()))	
cnt=0
num=1
p=0
for i in range(n):
  if li[i] == num:
    cnt += i-p
    p=i+1
    num += 1
  if i == n-1:
    cnt += n - p
if num==1:
  cnt=-1
print(cnt)

Measured memory_bytes: 26268
n = int(input())
a = list(map(int,input().split()))
color = [0,0,0,0,0,0,0,0,0]
cmin = 0
cmax = 0

for i in range(n) :
    if a[i] < 400 :
        color[0] += 1
    elif a[i] < 800 :
        color[1] += 1
    elif a[i] < 1200 :
        color[2] += 1
    elif a[i] < 1600 : 
        color[3] += 1
    elif a[i] < 2000 :
        color[4] += 1
    elif a[i] < 2400 :
        color[5] += 1
    elif a[i] < 2800 :
        color[6] += 1
    elif a[i] < 3200 :
        color[7] += 1
    else :
        color[8] += 1
        
for i in range(8) :
    if color[i] > 0 :
        cmin  += 1

if cmin == 0 :
    cmin = 1
    cmax = color[8]
else :
    cmax = cmin + color[8]

print (cmin, cmax)

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

int main()
{
    double n, m, sum = 0;
    int count = 0;
    cin >> n >> m;
    vector<double> a(n);

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    sum = sum / (4 * m);
    for (int i = 0; i < n; i++)
    {
        if (a[i] >= sum)
            count++;
    }

    if (count >= m)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn.readInt
  import scala.io.StdIn.readLine
  import scala.math.floor
    var n = readInt
    var num = readLine.split(" ").map(_.toInt).toIndexedSeq
  
  	def heiho(arr:IndexedSeq[Int]):Int = {
    return floor((arr.sum.toDouble / arr.length.toDouble) + 0.5).toInt
    }
  
    def nolmsum(x:Int,arr:IndexedSeq[Int]):Int = {
  	return arr.map(a =>(a - x) * (a - x)).sum
  }
    println(nolmsum(heiho(num),num).toString);
}

Measured memory_bytes: 55024