akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
main()
{
 long long int i, k, sum = 0;
  long long int n;
  cin >> n >> k;
  vector<long long int>ans;
  long long int a[n];
  for(i=0;i<n;i++)
  cin >> a[i];
  i = 0;
  unordered_map<long long int, long long int>m;
  while(1)
  {
  	
	  i= a[i]-1;
	  
	  if(m[i] != 0)
	  {
	  m[i]++;
      break;
	  }
	  m[i]++;
      
	  ans.push_back(i);
  	
  }
  vector<long long int >ans1;
  bool ima = false;
 for(i=0;i<ans.size();i++)
 {
 	 
 	if(m[ans[i]] == 1 && ima == false)
 	k--;
 	if(k==0)
 	{
 		cout << ans[i]+1 ;
 		return 0;
	 }
	 if(m[ans[i]] == 2)
	 {
	 	ima = true;
	 }
	 if(ima == true)
	 ans1.push_back(ans[i]);
 }
 
 
 
 
 
  long long int x = k%ans1.size();
if(x == 0)
x = ans1.size();
  cout << ans1[x-1]+1 << endl;
    	return 0;
}
 /*
 6 1
6 5 2 5 3 2
  */

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

int main (){
   int h,w,n,flag=0;
   int ans,total=0;
   scanf("%d\n%d\n%d\n",&h,&w,&n);
   if(w < h)flag=1;

   if(flag == 1){
      for(int i = 1;i <= w;i++){
         total += h;
         if(total >= n){
            printf("%d\n",i);
            break;
         }
      }
   }else{
      for(int i = 1;i <= h;i++){
         total += w;
         if(total >= n){
            printf("%d\n",i);
            break;
         }
      }
   }
}

Measured memory_bytes: 128
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main(){
    string A, B, C;
    string ans;
    cin >> A >> B >> C;
    int sizeA = A.size(), sizeB = B.size(), sizeC = C.size();
    if (A[sizeA - 1] == B[0] && B[sizeB - 1] == C[0]) ans = "YES";
    else ans = "NO";
    cout << ans << endl;
}


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

#define PI acos(-1)
#define pb push_back
#define int long long int
#define pi pair<int, int>
#define fir first
#define sec second
#define MAXN 200001
#define MAXL 20
#define mod 1000000007

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int ans = 0, at = 0;
  for (int i = 0; i < s.size(); i++)
  {
    if (s[i] == 'R')
      at++;
    else
      at = 0;
    ans = max(ans, at);
  }
  cout << ans << endl;
}

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

int main(){
  int n,a;
  cin>>n;
  int cnt=0;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a%2)cnt++;
  }
  if(cnt%2)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  return 0;
}


Measured memory_bytes: 384
s=list(input())
s=list(map(int,s))
t=10*s[0]+s[1]
k=10*s[2]+s[3]
if 1<=t<=12:
  if 1<=k<=12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
elif 1<=k<=12:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3060
# 隣り合う長さの最大値をKから引く
circ_length, n_house = map(int, input().split())
places = sorted(list(map(int, input().split())))

delta_places = []
for i in range(n_house):
  if i == 0:
    d = circ_length - places[-1] + places[0]
  else:
    d = places[i] - places[i-1]
  delta_places.append(d)

result = circ_length - max(delta_places)

print(result)


Measured memory_bytes: 26060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(~scanf("%d",&n)){
      int flag=0;
     for (int i=1;i<=9;i++){
        for (int j=1;j<=9;j++){
            if (n==i*j)flag=1;
        }
     }
     if (flag)printf("Yes\n");
     else printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
 
const int MAX = 200001;
 
int main(){
    int N;
    pair<int,int> x[MAX];
 
    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> x[i].second >> x[i].first;
    }
 
    sort(x,x + N);
 
    int sum = 0;
    int lim = 0;
 
    for(int i = 0;i < N;i++){
        sum += x[i].second;
        lim = x[i].first;
        
        if(lim < sum){
            cout << "No" << endl;
            return 0;
        }
    }
 
    cout << "Yes" << endl;
 
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(ll i = 0; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define TEN(x) ((ll)1e##x)

template <class COST>
void warshall_floyd(vector<vector<COST>> &cost) { // cost[n][n]
	int n = cost.size();
	REP(k, n) REP(i, n) REP(j, n) cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
}

pair<ll, ll> dp[33][33][33][33];
int main() {
#ifdef _WIN32
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0); // cin??¨cout?????£????????????
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	while (true) {
		ll h, w, s; cin >> h >> w >> s;
		if (h == 0) break;
		vvl table(w, vl(h));
		REP(i, h) REP(j, w) cin >> table[j][i]; // table[x][y];

		{
			ll sum = 0; REP(i, h) REP(j, w) sum += table[j][i];
			s = sum - s;
		}

		fill((pair<ll,ll>*)begin(dp), (pair<ll,ll>*)end(dp), pair<ll,ll>{0, -1});
		function<pair<ll,ll>(int, int, int, int)> dfs = [&](int x1, int y1, int x2, int y2) {
			if (dp[x1][y1][x2][y2].second != -1) return dp[x1][y1][x2][y2];
			ll sum = 0;
			FOR(x, x1, x2) FOR(y, y1, y2) sum += table[x][y];
			if (sum < s) return dp[x1][y1][x2][y2] = pair<ll, ll>(0, sum);

			pair<ll, ll> ans = { 1,  sum };
			FOR(x, x1 + 1, x2) {
				auto result_1 = dfs(x1, y1, x, y2);
				auto result_2 = dfs(x, y1, x2, y2);
				if (result_1.first == 0 || result_2.first == 0) continue;
				auto result = make_pair(result_1.first + result_2.first, min(result_1.second, result_2.second));
				if (result.first > ans.first || (result.first == ans.first && result.second > ans.second)) {
					ans = result;
				}
			}
			FOR(y, y1 + 1, y2) {
				auto result_1 = dfs(x1, y1, x2, y);
				auto result_2 = dfs(x1, y, x2, y2);
				if (result_1.first == 0 || result_2.first == 0) continue;
				auto result = make_pair(result_1.first + result_2.first, min(result_1.second, result_2.second));
				if (result.first > ans.first || (result.first == ans.first && result.second > ans.second)) {
					ans = result;
				}
			}
			return dp[x1][y1][x2][y2] = ans;
		};
		auto ans = dfs(0, 0, w, h);
		cout << ans.first << " " << ans.second - s << endl;
	}
	return 0;
}

Measured memory_bytes: 21640
#include<stdio.h>
#include<limits.h>
int MIN(int a, int b){return a>b?b:a;}

int main(void){
    int n;
    scanf("%d", &n);
    char s[n+1];
    scanf("%s", s);

    int e[n+1];
    int w[n+1];

    for(int i = 0; i < n+1; i++){e[i] = 0; w[i] = 0;}
    for(int i = 0; i < n; i++){
        if(s[i] == 'E'){e[i+1] = e[i] + 1; w[i+1] = w[i];}
        else{w[i+1] = w[i] + 1; e[i+1] = e[i];}
    }
    int en = e[n];
    int wn = w[n];
    int min = INT_MAX;
    /*for(int i = 0; i < n; i++){
        min = MIN(min, w[i]+en-e[i]);
    }*/
    /*for(int i = 0; i < n+1; i++){printf("e:%d w:%d\n", e[i], w[i]);}
    return 0;*/
    int ans;
    //ここめっちゃこんがらがった（コンガラガッタっていう都市ありそう）
    for(int i = 0; i < n; i++){
        //自分より左にいて左向き＋自分より右にいて右向き
        if(s[i] == 'W'){
            //自分より左にいて左向き＋自分より右にいて右向き
            ans = w[i+1]-1 + (en-e[i+1]);
        }else{
            ans = en-e[i+1] + w[i+1];
        }
        //printf("i:%d ans:%d\n", i, ans);
        min = MIN(min, ans);
    }

    printf("%d\n", min);
    return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)

int main(){
	int n;
	cin >>n;
	vector<int>p(n);
	rep(i,n)
		cin >>p[i];
	sort(p.rbegin(),p.rend());
	int sum=p[0]/2;
	rep(i,p.size()-1){
		sum+=p[i+1];
	}
	cout <<sum<<endl;

}

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

#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define T() int tt; cin >> tt; rep1(qq,1,tt)
#define rep(i,start,lim) for(int i=start;i<lim;i++)
#define rep1(i,start,lim) for(int i=start; i<=lim; ++i)
#define repd(i,start,lim) for(int i=start;i>=lim;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define br cout<<"\n"
#define MOD (998244353LL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define eps (1e-6)
#define what_is(x) cerr << #x << " is " << x << "\n";
#define int long long int
#define infll 9e18
#define inf 1e12

#define lnode (2 * node + 1)
#define rnode (2 * node + 2)

using namespace std;

typedef pair<int, int> pii;

const int N = 2e5 + 5;

int l;

int32_t main()
{

	FIO
	cout << fixed << setprecision(6);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	cin >> l;
	double mid = (1.0 * l) / 3.0;
  double res = mid * mid * mid;
  cout << res << '\n';
  
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  string s;
  cin>>s;
  int ans = 0;
  char now = s[0];
  rep(i,s.size()) {
    if(s[i] != now) {
      ans++;
      now = s[i];
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define inf (int)1e18+7
const int nmax = (int) 1e6 + 10;


int n;
int a[nmax], b[nmax], c[nmax];
int H[nmax][4];               

#define aa 1
#define bb 2
#define cc 3    
                     
signed main() {

    ios_base :: sync_with_stdio(false);
    cin.tie(0);         

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

    H[1][aa] = a[1];
    H[1][bb] = b[1];
    H[1][cc] = c[1];

    for (int i = 2; i <= n; i ++) {
        H[i][aa] = max(H[i - 1][bb] + a[i], H[i - 1][cc] + a[i]);
        H[i][bb] = max(H[i - 1][aa] + b[i], H[i - 1][cc] + b[i]);
        H[i][cc] = max(H[i - 1][aa] + c[i], H[i - 1][bb] + c[i]);
    }

    cout << max(H[n][aa], max(H[n][bb], H[n][cc])) << endl;
                                                           

    return 0;
}

Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;
#define ALL(a)  (a).begin(),(a).end()
using namespace std;

int main(){
    int n, r;
    cin >> n >> r;

    if(n >= 10){
        cout << r << endl;
    }else{
        cout << r + (100 * (10-n)) << endl;
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(obj) (obj).begin(), (obj).end()

int main(){
    int n,k;
    cin >> n >> k;
    int ret = 0;
    if(n==0){
        cout << 1 << endl;
        return 0;
    }
    while(n>0){
        n /= k;
        ret++;
    }
    cout << ret << endl;
}


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

using namespace std;

typedef long long lint;

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

    int rez = 1;
    for(int i = 1; i <= 60; i ++)
    {
        lint p2 = 1LL << i;
        if(a <= b / p2)
            rez = i + 1;
    }

    cout << rez << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
 

int main()
{
    int X, A, B;
  cin >> X >> A >> B;
  cout << (X - A) % B << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;



signed main(){
	int n;
	cin>>n;
	int bit=1<<n;
	vector<int>s(bit);
	rep(i,bit)cin>>s[i];
	sort(s.begin(),s.end());
	vector<int>a;
	a.pb(s.back());
	s.back()=-1;//使用済みのものは-1に
	rep(i,n){
		vector<int>p=a;//pはi秒で生成するスライムの親しか含まない
		sort(p.begin(),p.end());//大きいものから貪欲に
		int id=bit-1;
		while(p.size()>0&&id>=0){
			if(s[id]==-1){
				--id;//過去にやった操作はカット
				continue;
			}
			if(s[id]<p.back()){//大きいものから貪欲に使う
				a.pb(s[id]);//集合そのものに含む
				p.pop_back();//i秒での役目を終える
				s[id]=-1;//使用したので
			}
			--id;//親より大きくてもs全体を見たいので進める
		}
		if(p.size()>0){//全ての親を使わないといけないので残っているということは失敗
			cout<<"No\n";
			return 0;
		}

	}
	cout<<"Yes\n";
	return 0;
}

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

using namespace std;

typedef long long ll;

string s;
ll totsum = 0;

string vecstr(vector<string>& v) {
	string ret = "";
	for (const string& s : v) ret += s;
	return ret;
}

long eval(vector<string>& operations) {
	//cout << vecstr(operations) << '\n';
	string expression = "";
	for (int i = 0; i < operations.size(); i++) {
		expression += s[i];
		expression += operations[i];
	}
	expression += s[s.length() - 1];

	long ret = 0;
	
	stringstream ss(expression);
	long num;
	while (ss >> num) {
	    ret += num;
	}

	return ret;
}

void search(vector<string> operations, int i, int n) {
	if (i == n) {
		totsum += eval(operations);
	} else {
		operations.push_back("");
		search(operations, i + 1, n);
		operations.pop_back();
		operations.push_back(" ");
		search(operations, i + 1, n);
		operations.pop_back();
	}
}

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

	char expression[s.length() * 2 - 1];
	for (int i = 0; i < s.length() - 1; i++) {
		expression[i * 2] = s[i];
		expression[i * 2 + 1] = ' ';
	}

	expression[s.length() * 2 - 2] = s[s.length() - 1];

	vector<string> operations;
	search(operations, 0, s.length() - 1);

	cout << totsum << endl;
    return 0;
}


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

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"

void solve()
{
    ll n;
    cin>>n;
    string s="";
    while(n){
        --n;
        s+='a'+n%26;
        n/=26; 
    }
    reverse(s.begin(),s.end());
    cout<<s;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int l1=s1.length(),l2=s2.length();
    int dp[l1+1][l2+1];
    for(int i=0;i<l1+1;i++)
    {
        for(int j=0;j<l2+1;j++)
        {
            if(i==0||j==0)
                dp[i][j]=0;
            else
            {
                if(s1[i-1]==s2[j-1])
                    dp[i][j]=dp[i-1][j-1]+1;
                else
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    int i=l1,j=l2;
    char a[dp[l1][l2]];
    int x=0;
    while(i>0&&j>0)
    {
        if(s1[i-1]==s2[j-1])
        {
            a[x++]=s1[i-1];
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
            i--;
        else if(dp[i-1][j]<=dp[i][j-1])
            j--;
    }
    for(int i=x-1;i>=0;i--)
        cout<<a[i];
}

Measured memory_bytes: 35456
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int N;
	cin >> N;

	int digit = N / 100;

	if (N <= digit * 111)
	{
		cout << digit * 111 << endl;
	}
	else
	{
		cout << (digit + 1) * 111 << endl;
	}

	return 0;
}


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

int main()
{   long long n;
    scanf("%lld",&n);
    if(n%2==0){
    printf("%lld",n/2-1);
    }else{
        printf("%lld",n/2);
    }
    return 0;
}


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

int a,b;

int main() {
    cin >> a >> b;
    int sum = a + b;
  
  	if (sum % 2 == 0) {
      cout << (a + b) / 2;
    } else {
      cout << "IMPOSSIBLE"; 
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N_MAX 2000005
#define k 10005


int A[N_MAX];
int B[N_MAX];
int C[k];
int n;

int main()
{
  int i, j;
  
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &A[i]);
  }

  for(i=0; i<k; i++){
    C[i] = 0;
  }
  
  for(j=0; j<=n; j++){
    C[A[j]]++;
  }
  
  for(i=0; i<k; i++){
    if(i==0)
      continue;
    C[i] =C[i] +  C[i-1];
    // printf("C[%d] = %d\n", i, C[i]);
  }
  
  for(j=n-1; j>=0; j--){
    B[C[A[j]]-1] = A[j];
    //    printf("B[%d] = %d\n",C[A[j]], B[C[A[j]]]);
    C[A[j]]--;
  }



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

  return 0;
}

Measured memory_bytes: 16268
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int k = stdIn.nextInt();
		int[] a = new int[n];
		int t = n / (k-1);
		int r = n % (k-1);
		int s;
		s = (n == k) ? 1 : ((r == 0 || r == 1) ? t : t + 1);
		if (k == 2)
			s = n - 1;
		System.out.println(s);
	}
}

Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>
#include <list>
#include <string>
#include <limits.h>
#include <set>
using namespace std;
#define ll long long int


/*int main(){
	int N;
	cin>>N;
	int i,j,k;
	vector<pair<long long int,long long int>> v(N);
	for(i=0;i<N;i++){
		long long int x,y;
		cin>>x>>y;
		v[i]=make_pair(x,y);
	}

	long long int res=0;
	res+=(v[0].first+v[0].second);
	for(i=1;i<N;i++){
		if(v[i].first<v[i-1].first||v[i].second<v[i-1].second){
			long long int a=v[i-1].first/v[i].first;
			long long int b=v[i-1].second/v[i].second;
			if(v[i-1].first%v[i].first!=0&&v[i-1].first>v[i].first) a++;
			if(v[i-1].second%v[i].second!=0&&v[i-1].second>v[i].second) b++;
			a=max(a,b);
			v[i].first*=a;
			v[i].second*=a;
		}
	}
	res=v.back().first+v.back().second;
	cout<<res<<endl;
	return 0;
}*/

vector<vector<int>> memo;
int N;
string str;

/*int solve(int idx,int pNum){
	if(idx>=N) return 0;
	if(memo[idx][pNum]!=INT_MIN) return memo[idx][pNum];
	
	if(idx-pNum>pNum){
		int b=solve(idx+1,pNum+1);
		if(str[idx]=='g') memo[idx][pNum]=max(memo[idx][pNum],b+1);
		else memo[idx][pNum]=max(memo[idx][pNum],b);
	}
	else{
		int a=solve(idx+1,pNum);
		if(str[idx]=='g') memo[idx][pNum]=max(memo[idx][pNum],a);
		else memo[idx][pNum]=max(memo[idx][pNum],a-1);
	}
	return memo[idx][pNum];
}

int main(){
	
	cin>>str;
	N=str.size();
	
	int res=0;
	memo.resize(N,vector<int>(N/2+2,INT_MIN));
	res=solve(0,0);
	cout<<res<<endl;
	return 0;
}*/

int main(){
	cin>>str;
	N=str.size();
	int i,j,k;
	int w=0,l=0;
	for(i=0;i<N;i++){
		if(i%2==0){ //'g'
			if(str[i]=='p') l++;
		}
		else{
			if(str[i]=='g') w++;
		}
	}
	cout<<w-l<<endl;
	return 0;
}





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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

const int N=110000;
typedef long long LL;
const LL mod=998244353;

int d[N];
int pp[N];
int maxx;
int n;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&d[i]);
		pp[d[i]]++;
		maxx=max(maxx,d[i]);
	}
	for (int i=0;i<=maxx;i++)
		if (!pp[i])
		{
			printf("0\n");
			return 0;
		}
	if (pp[0]>1||d[1]!=0)
	{
		printf("0\n");
		return 0;
	}
	LL ans=1;
	for (int i=2;i<=n;i++)
		ans=ans*(LL)pp[d[i]-1]%mod;
	cout<<ans<<endl;
	return 0;
}

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


int main(){
    int a[5];
    for(int i=0; i<5; i++){
        cin >> a[i];
    }
    for(int i=0; i<5; i++){
        if(a[i] == 0) cout << i+1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3636
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

LL gcd(LL a, LL b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    string S;
    cin >> S;
    int L=S.length();
    string T,R,ans,E;
    string D;
    int last=1;
    int L_ini=0;
    for(int i=0;i<L-1;++i){
        R+=S[i];
        T=D;
        L_ini=R.length();
        for(int i=0;i<L_ini/2;++i){
            T+=R[i];
        }
        if(R==T+T){
            ans=R;
        }
        T=D;
    }
    int fir=ans.length();
    last=max(last,fir);
    cout << last;
    }

Measured memory_bytes: 256
class Object
	def is_true?
		self === true
	end
end

def main(one, two)
	arr = two.split.map(&:to_i)
	tes = arr.map.with_index do |v, index|
		next false if index - 1 < 0
		next false if arr.size <= index + 1
		next false if v < arr[index - 1] and v < arr[index + 1]
		next false if v > arr[index - 1] and v > arr[index + 1]
		true
	end

	puts tes.count(&:is_true?)
end

main(gets.strip, gets.strip)


Measured memory_bytes: 1788
N,M = [int(i) for i in input().split()]
nes = ['0'] * M
for i in range(M) :
    li = input().split()
    nes[i] = li
sum_ac = 0
sum_wa = 0
l = [0] * (N+1)
for i in range(N+1) :
    l[i] = True
r = [0] * (N+1)
rr = [0] * (N+1)
for i in range(M) :
    if nes[i][1] == "AC" :
        if l[int(nes[i][0])] :
            sum_ac+=1
            r[int(nes[i][0])]+=1
            l[int(nes[i][0])] = False
    if nes[i][1] == "WA" :
        if l[int(nes[i][0])] :
            sum_wa +=1
            rr[int(nes[i][0])] += 1
for i in range(1,N+1) :
    if r[i] == 0 :
        sum_wa -= rr[i]
print(sum_ac,sum_wa)

Measured memory_bytes: 70480
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(b+c<=a) cout << 0 << endl;
    else cout << c-(a-b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <math.h>
#include <list>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX_N 1005
#define MAX_M 100

int N;
int B[MAX_N];

int main()
{
    int A[5], k;
    rep(i, 5) cin >> A[i];
    cin >> k;
    if (k < A[4] - A[0])
        cout << ":(" << endl;
    else
        cout << "Yay!" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>

using namespace std;
typedef long long ll;

array<array<array<ll, 101>, 101>, 301> dp;

int main()
{
  int n, w;
  cin >> n >> w;

  vector<ll> ws(n);
  vector<ll> vs(n);
  for(int i = 0; i < n; i++)
  {
	cin >> ws[i] >> vs[i];
  }
  const ll init = ws[0];
  for(int i = 0; i < n; i++)
  {
	ws[i] -= init;
  }
  
  for(auto &vv : dp)
  {
	for(auto &v : vv)
	{
	  fill(v.begin(), v.end(), 0);
	}
  }
  
  ll sumW = 0;
  for(int i = 1; i <= n; i++)
  {
	sumW += ws[i-1];
	for(int j = 1; j <= i; j++)
	{
	  for(int k = 0; k <= sumW; k++)
	  {
		dp[i][j][k] = dp[i-1][j][k];
	  }
	  for(int k = ws[i-1]; k <= sumW; k++)
	  {
		if(k + j * init <= w)
		{
		  dp[i][j][k] = max(dp[i][j][k], dp[i-1][j-1][k-ws[i-1]] + vs[i-1]);
		}
	  }
	}
  }
  
  ll ans = 0;
  for(int i = 0; i <= sumW; i++)
  {
	for(int j = 1; j <= n; j++)
	{
	  ans = max(ans, dp[n][j][i]);
	}
  }
	 
  cout << ans << endl;
}


Measured memory_bytes: 24192
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();

        f("a", "abcdefghij", "a", n);

    }

    static void f(String s, String canUse, String used, int n) {
        if (s.length() == n) {
            System.out.println(s);
            return;
        }

        int i = 0;
        for (i = 0; i < used.length(); i++) {
            String newS = s + used.charAt(i);
            f(newS, canUse, used, n);
        }
        String newS = s + canUse.charAt(i);
        f(newS, canUse, used + canUse.charAt(i), n);

        return;
    }
}


Measured memory_bytes: 72052
#include<iostream>
#include<string>
#include<math.h>
using namespace std;


struct Dice{
    int f[6];
    void roll(char temp){
        switch (temp)
      {
        int temp_1;
        case 'S':
          temp_1 = f[4];
          f[4] = f[5];
          f[5] = f[1];
          f[1] = f[0];
          f[0] = temp_1;
          break;
        case 'N':
            temp_1 = f[1];
            f[1] = f[5];
            f[5] = f[4];
            f[4] = f[0];
            f[0] = temp_1;
            break;
        case 'W':
            temp_1 = f[2];
            f[2] = f[5];
            f[5] = f[3];
            f[3] = f[0];
            f[0] = temp_1;
            break;
        case 'E':
            temp_1 = f[2];
            f[2] = f[0];
            f[0] = f[3];
            f[3] = f[5];
            f[5] = temp_1;
            break;
        case 'R':
            temp_1=f[1];
            f[1]=f[2];
            f[2]=f[4];
            f[4]=f[3];
            f[3]=temp_1;
            break;
      
        default:
            break;
      }
    }
    int top(){
        return f[0];
    }
    int right(){
        return f[2];
    }
    int left(){
        return f[3];
    }
    int front(){
        return f[1];
    }
};

int main(){
  Dice d;
  for(int i = 0;i<6;i++){
      cin>>d.f[i];
  }
  int n;
  cin>>n;
  while(n--){
    int a,b;
    cin >> a >> b;
    if(d.left()==a) d.roll('E');
    if(d.right()==a) d.roll('W');
    while(d.top()!=a) d.roll('N');
    while(d.front()!=b) d.roll('R');
    cout << d.right() << endl;
  }
  return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  
  int ans = 1e9;
  for (int i = -100; i <= 100; i++) {
    int sum = 0;
    for (int j = 0; j < N; j++) sum += (A[j]-i)*(A[j]-i);
    ans = min(ans,sum);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
'use strict'
function main(input) {
  const tmp = input.split('\n');
  const NK = tmp[0].split(' ').map((elem) => parseInt(elem, 10));
  const N = NK[0];
  const K = NK[1];
  const h = tmp[1].split(' ').map((elem) => parseInt(elem, 10));

  let dp = new Array(N);
  dp.fill(Infinity);
  dp[0] = 0;
  for (let i = 1; i < N; i++) {
    for (let k = 1; k <= K; k++) {
      if (i >= k) {
        dp[i] = Math.min(dp[i], dp[i - k] + Math.abs(h[i] - h[i - k]));
      }
    }
  }

  console.log(dp[N - 1]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 27732
#include <bits/stdc++.h>
using namespace std;
#define hyperspeed ios::sync_with_stdio(false);cin.tie(NULL);
#define ll long long  
#define ull unsigned long long
#define ui unsigned int
#define li long int
#define uli unsigned long int
#define pb push_back
#define ld long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vli vector<li>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pi pair<int,int>
#define FOR(i,s,n) for(auto i=s;i<n;++i)
#define FORN(i,s,n) for(auto i=s;i<=n;++i)
#define FORR(i,s,n) for(auto i=s;i>=n;--i)
#define FORE(i,a) for(auto i : a)
#define mp make_pair
const int MOD = 1e9+7;

void solve() {
    ll h;
    ll n;
    ll sum = 0;
    cin >> h >> n;
    FOR(i,0,n) {
        ll x;
        cin >> x;
        sum+=x;
    }
    if(sum>=h) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
}

int32_t main()
{
    hyperspeed
    int test=1;
    // cin >> test;
    while(test--) {
        solve();
    }
    return 0;
}

//--n1m5


Measured memory_bytes: 3632
package main

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

func main() {
	sc := NewScanner()
	S := sc.NextLine()
	fmt.Println(S[:4] + " " + S[4:])

}

Measured memory_bytes: 640
import sys

input = sys.stdin.readline


def main():
    h, w = map(int, input().split())
    # 蛮兵
    painted = [['#'] * (w + 2)]
    painted += [['#'] + list(input().rstrip()) + ['#'] for _ in range(h)]
    painted.append(['#'] * (w + 2))
    que = []

    for y in range(1, h + 1):
        for x in range(1, w + 1):
            if painted[y][x] == '#':
                painted[y][x] = 0
                que.append((y, x))
    while que:
        qq = []
        for y, x in que:
            if painted[y - 1][x] == '.':
                painted[y - 1][x] = painted[y][x] + 1
                qq.append((y - 1, x))
            if painted[y + 1][x] == '.':
                painted[y + 1][x] = painted[y][x] + 1
                qq.append((y + 1, x))
            if painted[y][x + 1] == '.':
                painted[y][x + 1] = painted[y][x] + 1
                qq.append((y, x + 1))
            if painted[y][x - 1] == '.':
                painted[y][x - 1] = painted[y][x] + 1
                qq.append((y, x - 1))
        que = qq

    print(painted[y][x])


if __name__ == '__main__':
    main()


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

using namespace std;
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	map<string, int> memo;
	for(int i=0; i<n; i++){
		string s;
		cin >> s;

		memo[s] += 1;
	}

	int maxv = 0;
	for(auto x:memo){
		int v = x.second;
		if(v > maxv) maxv = v;
	}
	for(auto it = memo.begin(); it != memo.end(); it++){
		if(it->second == maxv){
			cout << it->first << endl;
		}
	}
	return 0;
}

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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.1415926535897932384626

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, no = -1;
LL c[100005];

vector<int> v[100005];

LL sum, maxi;

void gg(){
	printf("NO\n");
	exit(0);
}

void dfs(int id, int pv){
	if(v[id].size() == 1){
		//is leaf
		return;
	}
	
	for(auto to: v[id]){
		if(to == pv) continue;
		dfs(to, id);
	}
	
	sum = maxi = 0;
	
	for(auto to: v[id]){
		if(to == pv) continue;
		sum += c[to];
		maxi = max(maxi, c[to]);
	}
	
	LL pair_up = sum - c[id];
	LL alone = c[id] - pair_up;
	
	if(pair_up < 0 || alone < 0) gg();
	//can make that many pairs?
	
	LL max_pair;
	if(maxi + maxi > sum) max_pair = sum - maxi;
	else max_pair = sum / 2;
	
	if(max_pair < pair_up) gg();
	
	
//	printf("id = %d, pair %lld alone %lld\n", id, pair_up, alone);
	
	c[id] = alone;
	return;
}
	

int main(){
	scanf("%d", &n);
	FI(i, 1, n) scanf("%lld", &c[i]);
	FI(i, 2, n){
		int a, b;
		scanf("%d %d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	FI(i, 1, n) if(v[i].size() > 1 && no == -1) no = i;
	
	if(no == -1){
		assert(n == 2);
		if(c[1] == c[2]) printf("YES\n");
		else printf("NO\n");
		return 0;
	}
	
	dfs(no, -1);
	if(c[no] != 0) gg();
	
	printf("YES\n");
	return 0;
}


Measured memory_bytes: 13184
// Vicfred
// https://atcoder.jp/contests/abc128/tasks/abc128_b
// implementation
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

struct restaurant {
    string name;
    int score;
    int index;

    int opCmp(restaurant rhs) const {
        if(name == rhs.name)
            return rhs.score - score;
        return cmp(name, rhs.name);
    }
}

void main() {
    const int n = readln.chomp.to!int;
    restaurant[] restaurants;

    for(int i = 1; i <= n; i++) {
        string name;
        int score;
        readf("%s %s\n", &name, &score);
        restaurant r = restaurant(name, score, i);
        restaurants ~= r;
    }

    restaurants.sort;

    foreach(r; restaurants)
        r.index.writeln;
}



Measured memory_bytes: 3196
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] inputArgs = getInputArgs(br);
		if (Integer.parseInt(inputArgs[0]) > Integer.parseInt(inputArgs[1])) {
			System.out.println("a > b");
			return;
		}
		if (Integer.parseInt(inputArgs[0]) < Integer.parseInt(inputArgs[1])) {
			System.out.println("a < b");
			return;
		}
		System.out.println("a == b");
		return;
	}

	private static String[] getInputArgs(BufferedReader br) throws IOException {
		String line = br.readLine();
		String[] splitLine = line.split("\\s");
		return splitLine;
	}
}

Measured memory_bytes: 16888
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

int n;
ll a[100005];

int main(){
	scanf("%d ", &n);
	FORI(0, n) {
		scanf("%lld ", &a[i]);
	}
	sort(a, a + n);
	vector<ll> ans;
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] == a[i - 1]) {
			ans.push_back(a[i]);
			i--;
		}
		if (ans.size() == 2)
			break;
	}
	if (ans.size() < 2)
		cout << "0" << endl;
	else
		cout << ans[0] * ans[1] << endl;
	return 0;
}


Measured memory_bytes: 1024
import java.util.HashMap;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    HashMap<Integer, Integer> freq = new HashMap<>();
    for (int i = 0; i < N; i++) {
      int a = scanner.nextInt();
      freq.put(a, freq.getOrDefault(a, 0) + 1);
    }

    int count = 0;
    int numEven = 0;
    for (int f : freq.values()) {
      if (f % 2 == 0) {
        numEven++;
        count += f / 2 - 1;
      } else {
        count += f / 2;
      }
    }
    count += (numEven + 1) / 2;
    System.out.println(N - count * 2);
  }
}


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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i=0;i<N;i++) {
		cin >> A[i];
	}

	long long ans = 0LL;
	for (int i=0;i<N-1;i++) {
		if (A[i] > A[i+1]) {
			ans += A[i]-A[i+1];
			A[i+1] = A[i];
		}
	}
	cout << ans << endl;
}

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

int main() {

    int N;
    cin >> N;
    vector<int> X(N);
    int sum = 0;
    rep(i, N) {
        cin >> X[i];
        sum += X[i];
    }

    int ans_a = 0;
    int ans_b = 0;

    int m_a = floor(sum * 1.0 / N);
    int m_b = ceil(sum * 1.0 / N);

    rep(i, N) {
        ans_a += pow(X[i] - m_a, 2);
        ans_b += pow(X[i] - m_b, 2);
    }

    cout << min(ans_a, ans_b) << endl;

    return 0;
}


Measured memory_bytes: 256
/* Atcoder abc158a
 * See tasks at: https://atcoder.jp/contests/abc158/tasks/abc158_a
 */
#include <iostream>
#include <vector>
#include <algorithm>

#define until(symbol, max) for (int symbol = 0; (symbol) < (max); (symbol)++)

using namespace std;
using ll = long long;
int main()
{
    string s;
    cin >> s;

    if (s == "AAA"s || s == "BBB"s)
    {
        cout << "No";
    }
    else
    {
        cout << "Yes";
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
    
    public class Main{
        public static void main(String[] args){
            Scanner scan = new Scanner(System.in);
            int h = scan.nextInt();
            int w = scan.nextInt();
            String[] readS = new String[h];
            for(int i = 0; i < h; i++) readS[i] = scan.next();
            char[][] s = new char[h][w];
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++) s[i][j] = readS[i].charAt(j);
            }
            for(int i = 0; i < h; i++){
                for(int j = 0; j < w; j++){
                    if(s[i][j] == '#'){
                        try{
                        if(s[i - 1][j] != '#' && s[i][j + 1] != '#' && s[i + 1][j] != '#' && s[i][j - 1] != '#'){
                            System.out.println("No");
                            return;
                        }
                        }catch(Exception e){
                            
                        }
                    }
                }
            }
            System.out.println("Yes");
            scan.close();
        }
    }

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

int main() {
	long long x;
	cin >> x;

	long long ans = x / 11 * 2;
	x %= 11;
	if (x > 6) ans += 2;
	else if (x > 0) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 764
(defun app ()
    (let ((a (read))
        (b (read))
        (c (read))
        (ans "No"))
        (if (equal a b)
            (if (not (equal b c))
                (setq ans "Yes"))
            (progn (if (equal b c)
                (setq ans "Yes"))
            (if (equal a c)
                (setq ans "Yes")))
        )
    (format t "~A~%" ans)
    )
)
(app)

Measured memory_bytes: 23572
import java.util.*;

public class Main {
  public static void main(final String[] args) throws Exception {
    final Scanner scanner = new Scanner(System.in);
    try {
      int n = scanner.nextInt();
      int k = scanner.nextInt();
      int ans = k;
      for (int i = 1; i < n; i++) {
        ans *= k - 1;
      }
      System.out.println(ans);
    } finally {
      scanner.close();
    }
  }
}


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

#define Array_MAX 10000

void countingSort(short *A,short *B,int n){
  int i,j;
  int C[Array_MAX+1];

  for(i=0;i<=Array_MAX;i++)
    C[i] = 0;
  for(j=1;j<=n;j++)
    C[A[j]]++;
  for(i=1;i<=Array_MAX;i++)
    C[i] = C[i] + C[i-1];
  for(j=n;j>=1;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}

int main(){
  unsigned short *A, *B;
  int n,i;

  scanf("%d",&n);
  
  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=1;i<=n;i++)
    scanf("%hd",&A[i]);
  
  countingSort(A,B,n);

  for(i=1;i<n;i++)
    printf("%hd ",B[i]);
  printf("%hd\n",B[n]);
  
  free(A);
  free(B);
  return 0;
}
    
  

Measured memory_bytes: 8408
package main

import (
	"fmt"
)

func main() {

	var line, row int

	fmt.Scan(&line, &row)

	var table [][]int

	for i := 0; i < line+1; i++ {
		table = append(table, make([]int, row+1))
	}

	for i := 0; i < line; i++ {
		for j := 0; j < row; j++ {
			fmt.Scan(&table[i][j])
			table[i][row] += table[i][j]
			table[line][j] += table[i][j]
			table[line][row] += table[i][j]
		}
	}

	for i := 0; i <= line; i++ {
		for j := 0; j <= row; j++ {
			if j != 0 {
				fmt.Print(" ")
			}
			fmt.Print(table[i][j])
		}
		fmt.Println()
	}
}



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

typedef long long int ll;

vector <ll> input;
int main()
{
	ll i,j,k,l,m,n,x,y,z;

	cin >> n >> m;

	l = 0;
	for(i=0;i<n;i++)
	{
		cin >> k;
		input.push_back(k);
		l += k;
	}

	j = (l)/(4*m);

	if(l%(4*m) != 0)
	{
		j++;
	}
	// j = (l)/(4*m);

	sort(input.rbegin(),input.rend());

	l = 0;

	for(i=0;i<n;i++)
	{
		if(input[i] >= j)
			l++;
		else
			break;

	}

	if(l>=m)
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}


}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
signed main(){
    int n;
    cin >> n;
    long long x, sv = 0, sp = 0, sz = 0, min1 = 0, min2 = 0, min3 = 0, min4 = 0;
    for(int i = 1; i <= n; i++){
        cin >> x;
        sv+=x; sp+=x%2; sz+=!x;
        min4 = min(min4,
            (min3 = min(min3,
                (min2 = min(min2,
                    (min1 = min(min1,
                        sv-sp-2*sz
                    )) + 2*sz+2*sp-i
                )) - 2*sz-2*sp+i
            )) - sv+sp+2*sz
        );
    }
    cout << min4 + sv << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long int 
#define pb push_back
#define mp make_pair
#define pq priority_queue<int> 
#define pqs priority_queue<int,vector<int>, greater<int>>
#define setbits(x) __builtin_popcountll(x)  // no of ones in setbit
#define zrobits(x) __builtin_ctzll(x)       //101000 here 3..no of 0 aftrer 1sr right one 
#define mod 1000000007
#define inf 1e18
#define prDouble(x)  cout<<fixed<<setprecision(10)<<x     // ans upto 5 decimal place 
#define mk(ar,n,type) type *arr=new type[n];
#define w(x) int x;cin>>x;while(x--)
  
#define mod 1000000007


int  fn(int arr[],int k , int n)
{

	int dp[n+2][k+2] ;
	for(int j=0 ; j<=k; j++)
	{
		// if(i<=arr[1])
		// dp[1][i]=1; 
		// else
		// 	dp[i][i]=0 ; 
		dp[1][j]=(j>arr[1]) ? 0 : 1 ; 
	}

	for(int i=2; i<=n; i++)
	{
		for(int j=0 ; j<=k; j++)
		{
			if(j==0)
			{
				dp[i][j]=dp[i-1][j] ; 
			}
			else
				dp[i][j]=(mod+dp[i][j-1]+dp[i-1][j]- ((j-1-arr[i]>=0)? dp[i-1][j-1-arr[i]] : 0))%mod ; 
		}
	}

	return dp[n][k] ; 

	// 

	
}




int32_t main()
{
	int n, k; 
	cin>>n>>k; 
	int arr[n+10]; 
	for(int i=1 ; i<=n; i++)
	{
		cin>>arr[i] ;  
	}
	// memset(dp, -1, sizeof(dp)) ; 

	int c= fn(arr,k, n); 
	cout<<c; 
}

Measured memory_bytes: 78464