akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <time.h>
#define int long long
using namespace std;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int mypow(int x, int y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1)*x;
	else return mypow(x, y / 2)*mypow(x, y / 2);
}
/*ライブラリゾーン！！！！！！！！！！！！！！！*/
signed main(){
	int n, k;
	cin >> n >> k;
	if (k % 2 == 0)cout << mypow(n / k, 3) + mypow((n + k / 2) / k, 3) << endl;
	else cout << mypow(n / k, 3) << endl;
	system("PAUSE");
	return 0;
}


Measured memory_bytes: 504
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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 long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<long long,long long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
 
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

//long long A,B;
bool ok(long long key,long long index){
    if(index > key) return true;
    else if(index <= key) return false;
}
long long binary_search(long long key,long long size){
    //left,right,midはいずれもindex
    long long left = -1,right = size;
    while(right - left > 1){
        long long mid = left + (right-left)/2;
        long long hantei = ok(key,mid);
        if(hantei) right = mid;
        else left = mid;
    }
    if(left == -1)return 0;
    return left;
}

int main() {
    int N;cin >> N;
    int ans = 11451419;
    for(int i = 1;i<N;i++){
        int A = i;
        int B = N-i;
        int digitsum = 0;
        while(A > 0){
            digitsum += A%10;
            A /= 10;
        }
        while(B > 0){
            digitsum += B%10;
            B /= 10;
        }
        ans = min(ans,digitsum);
    }

    cout << ans << endl;
}


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

int main(){
  stack<int> s;
  int num;
  while(cin>>num){
    if(num!=0){
      s.push(num);
    }
    else{
      cout<<s.top()<<endl;
      s.pop();
    }
  }
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  int Q;
  cin >> Q;
  
  int T1count = 0;
  int frontcount = 0;
  int backcount = 0;
  
  deque<char> dq;
  for (int i = 0; i< Q; i++) {
    int T;
    cin >> T;
    
    // T = 1のときの処理 countを増やす
    if (T == 1) {
      T1count++;
    }
    // T = 2のときの処理 F = 1か F= 2，さらにそれぞれ T1countの偶奇で場合わけ
    if (T == 2) {
      int F;
      char C;
      cin >> F >> C;
     // F = 1のときの処理 deque 左にCを入れる 左の数をカウント
      if (F == 1) { 
        if (T1count % 2) {
          dq.push_back(C);
          backcount++;
        } else {
          dq.push_front(C);
          frontcount++;
        }
        
      }
     // F = 2 のときの処理 deque 右にCを入れる 右の数をカウント
      if (F == 2) {
        if (T1count % 2) {
          dq.push_front(C);
          frontcount++;
        } else {
          dq.push_back(C);
          backcount++;
        }
      }
    } 
  }
    
  if (T1count % 2) {
    reverse(S.begin(), S.end());
    reverse(dq.begin(), dq.end());
    for (int i = 0; i < backcount; i++) cout << dq[i];
    for (int i = 0; i < S.size(); i++)  cout << S[i];
    for (int i = backcount; i < dq.size(); i++) cout << dq[i];
    cout << endl;
  } else {
    for (int i = 0; i < frontcount; i++) cout << dq[i];
    for (int i = 0; i < S.size(); i++)  cout << S[i];
    for (int i = frontcount; i < dq.size(); i++) cout << dq[i];
    cout << endl;
    
  }
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n){
        cin>>a[i];
    }
    sort(begin(a), end(a));
    if(a[0]+1<a[n-1]){
        cout << "No" << endl;
        return 0;
    }
    // int cnt = a[0];
    // bool flg = a[0]==a[n-1]&&(a[0]==n-1||n>=2*a[0]) ||
    // cnt<n-1&&a[n-1]==cnt+1&&a[cnt]==cnt+1&&a[cnt-1]==cnt;
    bool flg = a[0]==a[n-1]&&(a[0]==n-1||n>=2*a[0]);
    if(!flg&&a[0]==a[n-1]){
        cout << "No" << endl;
        return 0;
    }else if(a[0]==a[n-1]){
        cout << "Yes" << endl;
        return 0;
    }
    int sm_cnt=0;
    int sm = a[0];
    int cur=0;
    while(cur<n&&a[cur]==sm){
        cur++;sm_cnt++;
    }
    flg |= n-sm_cnt-(a[n-1]-sm_cnt)*2>=0&&sm_cnt<a[n-1];
    cout << (flg ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
deque<int> ans; int tot = 0;
void sol(int x)
{
	if(x == 0) return;
	if(x & 1) sol((x - 1) >> 1LL), ans.push_back(++tot);
	else sol(x - 1), ans.push_front(++tot);
}
signed main()
{
	int n = 0;
	cin >> n;
	sol(n);
	for(int i = 1; i <= tot; i++) ans.push_back(i);
	cout << ans.size() << endl;
	for(auto i:ans) cout << i << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int K = sc.nextInt();
      int a[] = new int[N];
      for (int count = 0; count < N; count++){
  	    a[count] = sc.nextInt();
      }
      for (int count = 0; count < N-K; count++){
        if(a[count] < a[count+K]){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
      }
    }
}

Measured memory_bytes: 60080
s = input()
words = ['maerd', 'remaerd', 'esare', 'resare']
reverse_s = list(reversed(s))
current = 0

while current < len(s):
    diff = 0
    for word in words:
        if "".join(reverse_s[current:current+len(word)]) == word:
            diff = len(word)
            break
    if diff == 0:
        break
    current += diff
if current == len(s):
    print('YES')
else:
    print("NO")


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

void InputSet(std::vector<int> & a) {
	int n;
	cin >> n;
	a.resize(n,0);
	for(int i=0;i<n;++i) {
		cin >> a.at(i);
	}
}

void Printf(std::vector<int> & a) {
	for(int i=0;i<(int)a.size();++i) {
		if (i>0){ 
			cout << " ";
		}
		cout  << a.at(i);
	}
	cout << std::endl;
}

void Merge(std::vector<int> & A, int left, int mid, int right,int & comps)
{
	int n1 = mid - left;
	int n2 = right - mid;
//  create array L[0...n1], R[0...n2]
	static std::vector<int> L,R;
	if (n1+1 > (int)L.size()) L.resize(n1+1);
	if (n2+1 > (int)R.size()) R.resize(n2+1);
	//for (int i = 0; i<n1;++i) {
	//	L[i] = A[left + i];
	//}
	std::copy(A.begin()+left,A.begin()+mid,L.begin());
	//for (int i = 0; i<n2;++i) {
	//	R[i] = A[mid + i];
	//}
	std::copy(A.begin()+mid,A.begin()+right,R.begin());
	const int SENTINEL=(int)(((unsigned int)(-1))>>1);
	L[n1] = SENTINEL;
	R[n2] = SENTINEL;
	int i = 0;
	int j = 0;
	for (int k = left; k<right;++k) {
		++comps;
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i = i + 1;
		} else {
			A[k] = R[j];
			j = j + 1;
		}
	}
}

void MergeSort(std::vector<int> & A, int left, int right,int & comps)
{
	if (left+1 < right) {
		int mid = (left + right)/2;
		MergeSort(A, left, mid,comps);
		MergeSort(A, mid, right,comps);
		Merge(A, left, mid, right,comps);
	}
}

int main(){
	std::vector<int> A;
	::InputSet(A);
	int comps=0;
	MergeSort(A,0,(int)A.size(),comps);
	::Printf(A);
	cout << comps << std::endl;
}

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

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ',') cerr << *sdbg++; cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

const int MAXN = 2E5 + 10;

int a[MAXN];

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	for (int u, v, i = 0; i < m; ++i){
		scanf("%d%d", &u, &v);
		if (u > v)
			swap(u, v);
		if (u == 1)
			a[v] |= 1;
		if (v == n)
			a[u] |= 2;
	}
	puts(find(a + 2, a + n, 3) != a + n ? "POSSIBLE" : "IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 1024
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
//#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

vector<int> xs;
vector<int> ys;
vector<int> x1;
vector<int> y1;
vector<int> x2;
vector<int> y2;
int w;
int h;
int n;
int check[2002][2002];
int toIndex(int v, vector<int> s)
{
	return lower_bound(s.begin(),s.end(),v)-s.begin();
}
void debug()
{
	for(int j=ys.size()-1;j>=0;j--){
		for(int i=0;i<xs.size();i++){
			cout << check[i][j];
		}
		cout << endl;
	}
	cout << endl;
}
void exec()
{
	cin >> w >> h;
	if(w==0&&h==0){
		exit(0);
	}
	memset(check,0,sizeof(check));
	x1.clear();
	x2.clear();
	y1.clear();
	y2.clear();
	xs.clear();
	ys.clear();
	int n;
	cin >> n;
	xs.push_back(0);
	ys.push_back(0);
	for(int i=0;i<n;i++){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		x1.push_back(a);
		y1.push_back(b);
		x2.push_back(c);
		y2.push_back(d);
		xs.push_back(a);
		ys.push_back(b);
		xs.push_back(c);
		ys.push_back(d);
	}
	xs.push_back(w);
	ys.push_back(h);
	sort(xs.begin(),xs.end());
	xs.resize(unique(xs.begin(),xs.end())-xs.begin());
	sort(ys.begin(),ys.end());
	ys.resize(unique(ys.begin(),ys.end())-ys.begin());
	for(int i=0;i<n;i++){
		int a=toIndex(x1[i],xs);
		int b=toIndex(y1[i],ys);
		int c=toIndex(x2[i],xs);
		int d=toIndex(y2[i],ys);
		check[a][b]++;
		check[c][d]++;
		check[a][d]--;
		check[c][b]--;
	}
	xs.pop_back();
	ys.pop_back();
	for(int i=0;i<xs.size();i++){
		for(int j=1;j<ys.size();j++){
			check[i][j]+=check[i][j-1];
		}
	}
	for(int i=1;i<xs.size();i++){
		for(int j=0;j<ys.size();j++){
			check[i][j]+=check[i-1][j];
		}
	}
	//debug();
	//exit(0);
	int ret=0;
	vector<int> nx;
	vector<int> ny;
	int dx[]={-1,0,1,0};
	int dy[]={0,-1,0,1};
	for(int i=0;i<xs.size();i++){
		for(int j=0;j<ys.size();j++){
			if(check[i][j]==0){
				nx.push_back(i);
				ny.push_back(j);
				ret++;
				check[i][j]=1;
				while(nx.size()){
					int x=nx.back();
					int y=ny.back();
					nx.pop_back();
					ny.pop_back();
					for(int k=0;k<4;k++){
						int xx=x+dx[k];
						int yy=y+dy[k];
						if(0<=xx&&xx<xs.size()&&
							0<=yy&&yy<ys.size()&&
							check[xx][yy]==0)
						{
							check[xx][yy]=1;
							nx.push_back(xx);
							ny.push_back(yy);
						}
					}
				}
			}
		}
	}
	cout << ret << endl;
}
int main() {
	while(1)
		exec();
}

Measured memory_bytes: 17348
Blur = [
  [ [0, 0], [-1, 1], [0, 1], [1, 1], [-2, 2], [-1, 2], [0, 2], [1, 2], [2, 2], [-1, 3], [0, 3], [1, 3], [0, 4] ],
  [ [0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [0, 2], [1, 2], [2, 2], ],
  [ [0, 0], [-1, 1], [0, 1], [1, 1], [0, 2] ]
]
Blur_sz = [5, 3, 3]
Blur_c = [[0, 2], [1, 1], [0, 1]]

def solve(fld, x, y, m)
  if m == $n
    if fld.flatten.all?{ |v| v == 0 }
      return true
    else return false
    end
  end

  3.times do |z|
    t = Blur_sz[z]
    10.times do |i|
      10.times do |j|
        if fld[i][j] > 0
          return false if i < y || i == y && j < x
          if ps = ok(j, i, z)
            if ps.all?{ |x, y| fld[y][x] > 0 }
              nfld = fld.map(&:dup)
              ps.each{ |x, y| nfld[y][x] -= 1 }
              $ans[m] = [j + Blur_c[z][0], i + Blur_c[z][1], 3 - z]
              return true if solve(nfld, j, i, m + 1)
            end
          end
        end
      end
    end
  end
  false
end

def ok(x, y, z)
  ret = []
  Blur[z].each do |c, r|
    nx = x + c; ny = y + r
    return false unless 0 <= nx && nx < 10 && 0 <= ny && ny < 10
    ret << [nx, ny]
  end
  ret
end

$n = gets.to_i
$ans = $n.times.map { [] }
fld = 10.times.map { gets.split.map(&:to_i) }
solve(fld, 0, 0, 0)
$ans.each{ |a| puts a.join(' ') }

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  int res=1;
  while(res*2<=n){
    res*=2;
  }
  cout<<res<<endl;

  return 0;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	const int t = static_cast<int>(n / 1.08);
	int answer = -1;
	for(int i = -5; answer < 0 && i <= 5; ++i){
		const int x = (t + i) * 108 / 100;
		if(x == n){ answer = t + i; }
	}
	if(answer < 0){
		cout << ":(" << endl;
	}else{
		cout << answer << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main() {

	long res;
	long A, B, C, K; cin >> A >> B >> C >> K;

	res = (K % 2 == 0) ? A - B : B - A;

	cout << res << endl;
}

Measured memory_bytes: 256
def isPal(s):
    l = 0
    r = len(s) - 1
    while r > l and s[l] == s[r]:
        l += 1
        r -= 1
    return r <= l

s = input()
n = len(s)
if (isPal(s) and isPal(s[:int((n - 1) / 2)]) and isPal(s[int((n + 3) / 2) - 1:])):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#if 1
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define stoi stoll
#else
#define MAX INT_MAX
#define MIN INT_MIN
#endif
#define INF MAX/2
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
const int NIL = -1;
const int MOD = 1000000007;
#define REP(i,n) for (int (i)=0; (i) < (n); ++(i))
#define FOR(i,a,b) for (int (i)=(a); (i) < (b); ++(i))
using namespace std;

int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        int t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int pow(int x, int n) {int res=1; while(n){if(n&1)res*=x;x*=x;n>>=1;} return res;}
int get_gcd(int a, int b) {while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b) {return a * b / get_gcd(a, b);}
bool chmin(int &a, int b) {if(a>b){a=b; return true;} else return false;}
bool chmax(int &a, int b) {if(a<b){a=b; return true;} else return false;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//-------------------------テンプレここまで-------------------------//

char S[20][20];
bool seen[20][20];
int H, W;

typedef struct {
  int y;
  int x;
  int count;
} Node;

int bfs(const int in_y, const int in_x) {
  REP(i,H) {
    REP(j,W) {
      seen[i][j] = false;
    }
  }

  queue<Node> que;
  const Node root = {in_y, in_x, 0};
  seen[in_y][in_x] = true;
  que.push(root);

  int max_count = 0;
  while(que.size() > 0) {
    auto r = que.front(); que.pop();
    chmax(max_count, r.count);

    REP(i,4) {
      const int ny = r.y + dy[i];
      const int nx = r.x + dx[i];

      if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
      if (seen[ny][nx] || S[ny][nx] == '#') continue;

      const Node next = {ny, nx, r.count+1};
      seen[ny][nx] = true;
      que.push(next);
    }
  }

  return max_count;
}

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

  // Input
  cin >> H >> W;

  REP(i,H) {
    REP(j,W) {
      cin >> S[i][j];
    }
  }


  // BFS

  int max_step = 0;
  REP(i,H) {
    REP(j,W) {
      if (S[i][j] == '#') continue;
      chmax(max_step, bfs(i,j));
    }
  }

  cout << max_step << endl;

  return 0;
}


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

int main()
{
	int N, M;
	std::cin >> N >> M;

	std::vector<int> v;
	for ( int i = 1; i * i <= M; i++ )
	{
		if ( M % i != 0 )
		{
			continue;
		}
		else
		{
			v.emplace_back( i );
			v.emplace_back( M / i );
		}
	}

	std::sort( v.begin(), v.end() );

	int d = 1;
	for ( auto &&it : v )
	{
		if ( it > M / N )
		{
			break;
		}

		if ( d < it )
		{
			d = it;
		}
	}

	std::cout << d << std::endl;

	return ( 0 );
}


Measured memory_bytes: 504
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b[] =new int[a];
long e=0;
String c[] =new String[a];
for(int i=1;i<a+1;i++){
b[i-1]=i;
}
for(int i=1;i<a+1;i++){
    c[i-1]=String.valueOf(b[i-1]);
            if(b[i-1]%15==0){
        c[i-1]="FizzBuzz";
    }
    if(b[i-1]%3==0){
        c[i-1]="Fizz";
    }
        if(b[i-1]%5==0){
        c[i-1]="Buzz";
    }

}
for(int i=0;i<a;i++){
    if(c[i]=="FizzBuzz"||c[i]=="Fizz"||c[i]=="Buzz"){
    }else{
        e+=Integer.parseInt(c[i]);
    }
    }
    System.out.println(e);
}
}

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

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

long lcm(long a, long b)
{
  return a / gcd(a, b) * b;
}

int main()
{
  long N, M;
  cin >> N >> M;
  string S, T;
  cin >> S >> T;
  long L = lcm(N, M);
  map<long, char> mp;
  for (long i = 0; i < N; i++)
    mp[i * (L / N)] = S[i];
  for (long i = 0; i < M; i++)
  {
    if (mp.find(i * (L / M)) != mp.end() && mp[i * (L / M)] != T[i])
    {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << L << endl;
  return 0;
}

Measured memory_bytes: 6144
using System;
using static System.Console;
using System.Linq;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
         long[] basedata = ReadLine().Split(' ').Select(long.Parse).ToArray();
         
         long x = basedata[1] <= basedata[2] ? basedata[1] - 1 : basedata[2];
         long ans = basedata[0] * x / basedata[1];
         
         WriteLine(ans);
      }
   }
}

Measured memory_bytes: 28084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}





int main(){

  ll N;
  cin >> N;
  vector<ll> A(N+1,10000000);
  FOR(i,0,N) cin >> A[i+1];


  vector<ll> dp(N+1,0);
  dp[0] = 1000;

  FOR(i,0,N){
    FOR(k,i,N+1){
      FOR(j,k+1,N+1){
        dp[j] = max(dp[j],dp[i]%A[k]+(dp[i]/A[k])*A[j]);
        dp[j] = max(dp[j],dp[j-1]);
      }
    }
  }
  cout << dp[N] << endl;

}



Measured memory_bytes: 3632
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        m: usize,
        p: i64,
        e: [(usize1, usize1, i64); m],
    }
    let mut g = vec![vec![]; n];
    for (a, b, c) in e {
        g[a].push((b, c - p));
    }
    let inf = 1_000_000_000_000_000i64;
    let mut dp = vec![-inf; n];
    dp[0] = 0;
    for _ in 0..n {
        for i in 0..n {
            if dp[i] == -inf {
                continue;
            }
            for &(u, c) in g[i].iter() {
                let d = dp[i] + c;
                if d > dp[u] {
                    dp[u] = d;
                }
            }
        }
    }
    for _ in 0..n {
        for i in 0..n {
            if dp[i] == -inf {
                continue;
            }
            for &(u, c) in g[i].iter() {
                let d = dp[i] + c;
                if d > dp[u] {
                    dp[u] = inf;
                }
            }
        }
    }
    if dp[n - 1] >= inf {
        println!("-1");
    } else {
        println!("{}", std::cmp::max(dp[n - 1], 0));
    }
}

fn main() {
    run();
}


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

#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;

int main() {
  double d, t, s, tmp;
  cin >> d >> t >> s;
  tmp = ceil(d / s);
  if (tmp <= t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3720
import collections
n = int(input())
s = [str(input()) for _ in range(n)]
c = collections.Counter(s)
values, counts = zip(*c.most_common())

ans = [values[0]]
count = counts[0]
for i in range(1,len(c)):
    if counts[i] == count:
        ans.append(values[i])
    else:
        break
ans.sort()
for a in ans:
    print(a)


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

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto 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::pair<int,int> PII;

typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::vector<PII> VPII;

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

std::string S;
int len;

LL calc(int pattern) {
    LL ans = 0;
    LL stack = 0;

    for(int i=0; i<len; ++i) {
        stack *= 10;
        stack += S[i] - '0';
        if( ((pattern >> i) & 0x01) == 0x01 ) {
            ans += stack;
            stack = 0;
        }
    }
    ans += stack;
    return ans;
}

int main() {
    std::cin >> S;

    len = S.length();
    int max = (1 << (len - 1));

    LL sum = 0;
    for(int i=0; i<max; ++i) {
        sum += calc(i);
    }
    std::cout << sum << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if( a == 7 && b == 5 && c == 5 ||
		a == 5 && b == 7 && c == 5 ||
		a == 5 && b == 5 && c == 7)
		cout << "YES";
	else
		cout << "NO";
}

Measured memory_bytes: 256
N=int(input())

a={}
c=0
while N%2==0:
  N//=2
  c+=1
if c!=0:
  a[2]=c

f,c=3,0
while f*f<=N:
  if N%f==0:
    N//=f
    c+=1
    a[f]=c
  else:
    f+=2
    c=0
if N!=1:
  if N in a:
    a[N]+=1
  else:
    a[N]=1

t=0
for v in a.values():
  i=1
  while v>=i:
    t+=1
    v-=i
    i+=1

print(t)


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

int main()
{
  int n;
  cin >> n;
  set<string> st;

  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    st.insert(s);
  }

  cout << st.size() << endl;
}


Measured memory_bytes: 19224
s = gets.chomp
t = gets.chomp
ans_flag = false
ans = []
(0..s.size - t.size).each do|i|
  a = s.slice(i,t.size)
  (0..t.size-1).each do |k|
    if a[k] == t[k] || a[k] == "?"
      ans_flag = true
    else
      ans_flag = false
      break
    end
  end

  if ans_flag
    temp = String.new(s)
    temp[i,t.size] = t
    ans << temp.gsub(/\?/,"a")
  end
end
ans.sort!
puts ans.empty? ? "UNRESTORABLE" : ans[0]

Measured memory_bytes: 1788
import java.util.*;

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

        int a = sc.nextInt(); 
        int b = sc.nextInt(); 
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int k = sc.nextInt();

        if(e-a > k){
            System.out.println(":(");
        }else{
            System.out.println("Yay!");
        }
    }
}

Measured memory_bytes: 22996
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
#mod = 10**9 + 7
mod=998244353
x=220000
fact=[0 for i in range(x)]
invfact=[0 for i in range(x)]
fact[0]=1

def cmod(n,k,mod):
    if n<0 or n<k:
        return 0
    return (fact[n]*invfact[n-k]*invfact[k])%mod
for i in range(1,x):
    fact[i]=(fact[i-1]*i)%mod
#print(fact)
invfact[-1]=pow(fact[-1],mod-2,mod)
#print(invfact)
for j in range(x-1,0,-1):
    #print(j)
    invfact[j-1]=(invfact[j]*(j))%mod
#print(invfact)

n,m,k=MI()
beki=[0 for i in range(n)]
beki[0]=m%mod
for i in range(n-1):
    beki[i+1]=(beki[i]*(m-1))%mod
    
ans=0

for i in range(k+1):
    j=n-i-1
    ans+=(beki[j]*cmod(n-1,i,mod))%mod
    #print(beki[j]*cmod(n-1,i,mod))
print(ans%mod)

Measured memory_bytes: 34596
class Dice:
    def __init__(self, p):
        self.y = [p[0], p[1], p[5], p[4]]
        self.x = [p[0], p[2], p[5], p[3]]
        self.z = [p[1], p[2], p[4], p[3]]
    def roll(self, c):
        if c == 'y':
            self.y.append(self.y.pop(0))
            self.x[0] = self.y[0]
            self.x[2] = self.y[2]
            self.z[0] = self.y[1]
            self.z[2] = self.y[3]
        elif c == 'x':
            self.x.append(self.x.pop(0))
            self.y[0] = self.x[0]
            self.y[2] = self.x[2]
            self.z[1] = self.x[1]
            self.z[3] = self.x[3]
        elif c == 'z':
            self.z.append(self.z.pop(0))
            self.x[1] = self.z[1]
            self.x[3] = self.z[3]
            self.y[1] = self.z[0]
            self.y[3] = self.z[2]
    def num(self, n):
        n = n - 1;
        pos_y = [0, 1, 5, 4]
        pos_x = [0, 2, 5, 3]
        if n in pos_y:
            return self.y[pos_y.index(n)]
        else:
            return self.x[pos_x.index(n)]

p = [ int(n) for n in input().split()]

q = int(input())
qq = []
for i in range(0, q):
    qq.append([int(n) for n in input().split()])


for (a, b) in qq:
    
    dice = Dice(p)

    
    for _ in range(0, 4):
        if dice.num(1) == a:
            break;
        dice.roll('x')
    for _ in range(0, 4):
        if dice.num(1) == a:
            break;
        dice.roll('y')
   
    for _ in range(0, 4):
        if dice.num(2) == b:
            break;
        dice.roll('z')
    print(dice.num(3))


Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll P = 1e9+7;


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

	ll t=1;
	// cin>>t;

	while(t--){
		ll a,b,c,d;
		cin>>a>>b>>c>>d;

		cout<<max( { a*c , a*d , b*c , b*d } )<<"\n";

	}	

	return 0;
}	


Measured memory_bytes: 3644
local mfl, mce, mma = math.floor, math.ceil, math.max

local n, a, b = io.read("*n", "*n", "*n")
local t = {}
local sum = 0
local maxval = 0
for i = 1, n do
  t[i] = io.read("*n")
  sum = sum + t[i]
  maxval = mma(maxval, t[i])
end

local min = mce(sum / (b * (n - 1) + a)) - 1
local max = mce(maxval / b)

local function check(c)
  local rem = c
  for i = 1, n do
    if b * c < t[i] then
      rem = rem - mce( (t[i] - b * c)/ (a - b))
    end
    if rem < 0 then break end
  end
  return 0 <= rem
end

while(1 < max - min) do
  local mid = mfl((min + max) / 2)
  if check(mid) then
    max = mid
  else
    min = mid
  end
end
print(max)


Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {

	public static void main(String[] atgs) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int gcd = 0;
		if (x == y) {
			gcd = x;
		} else {
			gcd = calculation(x, y, gcd);
		}
		System.out.println(gcd);
		sc.close();
	}

	public static int calculation(int x, int y, int gcd) {
		if (x < y) {
			int tmp = x;
			x = y;
			y = tmp;
		}
		x %= y;
		for (int i = x; true; i--) {
			if (x % i == 0 && y % i == 0) {
				gcd = i;
				break;
			}
		}
		return gcd;
	}
}



Measured memory_bytes: 26668
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<complex>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    queue<char> q;
    int n; cin >> n;
    rep(i, n) {
        char a; cin >> a;
        q.push(a);
        if (i) {
            char a = q.front();
            q.pop();
            char b = q.front();
            q.pop();
            if (a == 'T' && b == 'F') q.push('F');
            else q.push('T');
        }
    }
    cout << q.front() << endl;
}





Measured memory_bytes: 3232
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    for i in 1.. {
        if i*(i+1)/2 >= n {
            let mut sum = 0;
            for j in (1..i+1).rev() {
                if sum + j <= n {
                    sum += j;
                    println!("{}", j);
                }
            }
            return;
        }
    }
}


Measured memory_bytes: 8572
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,P[200010];
  cin >> N;
  for(int i = 0; i < N; i++) cin >> P[i];
  int cnt = 0;
  int mini = 98765432;
  for(int i = 0; i < N; i++){
    if(P[i]>mini) cnt--;
    mini = min(mini,P[i]);
    cnt++;
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        int[][] array = new int[n][2];
        for (int i = 0; i < n; i++) {
            array[i][0] = sc.nextInt();
            array[i][1] = sc.nextInt();
        }
        Arrays.sort(array, (a, b) -> Integer.compare(a[0], b[0]));    // foo[][0]で
        
        long cost = 0;
        for (int i = 0; i < n; i++) {
            int price = array[i][0];
            int amount = array[i][1];
            if (k <= amount) {
                cost += (long)price * k;
                System.out.println(cost);
                return;
            } else {
                cost += (long)price * amount;
                k -= amount;
            }
        }
    }
}


Measured memory_bytes: 95224
#include<iostream>
#include<queue>
#include<map>
#include<vector>
using namespace std;

int main() {
    int N, M;
    cin>>N>>M;
    int k;
    int l;
    map<int, vector<int> > man_to_lang;
    map<int, vector<int> > lang_to_man;;
    for(int i=1;i<=N;++i){
        cin>>k;
        for(int j=0;j<k;++j){
            cin>>l;
            lang_to_man[l].push_back(i);
            man_to_lang[i].push_back(l);
        }
    }
    queue<int> que;
    que.push(1);
    int state;
    int nokori = N;
    map<int, int> deta;
    map<int, int> langdeta;
    deta[1]++;
    bool answer = false;
    int ans = N;
    int lang, man;
    while(!que.empty()){
        state = que.front();que.pop();
        ans--;
        if(ans == 0){
            answer = true;
            break;
        }
        for(int i=0;i<man_to_lang[state].size();++i){
            lang = man_to_lang[state][i];
            if(langdeta[lang]>0)continue;
            langdeta[lang]++;
            for(int j=0;j<lang_to_man[lang].size();++j){
                man = lang_to_man[lang][j];
                if(deta[man]>0)continue;
                deta[man]++;
                que.push(man);
            }
        }
    }
    if(answer)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 16632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    string s; cin>>s;
    int n=s.size();
    long long ans=0;
    for(int i=1<<(n-1);i<(1<<n);i++){
        long long num=0;
        for(int j=0;j<n;j++){
            num+=s[j]-'0';
            if(i>>j&1){
                // cout<<num<<endl;
                ans+=num;
                num=0;
            }else{
                num*=10;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

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

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

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

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

	cout << dp[n] << endl;
}

Measured memory_bytes: 1024
N = int(input())
heights = list(map(int, input().strip().split()))

dp = [float("inf") for _ in range(N)]

dp[0] = 0
if N > 1:
    dp[1] = abs(heights[1] - heights[0])


for i in range(2, N):
    dp[i] = min(
        dp[i],
        dp[i - 1] + abs(heights[i] - heights[i - 1]),
        dp[i - 2] + abs(heights[i] - heights[i - 2]),
    )

print(dp[N - 1])


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

int main(void) {
	int N, a = 0, b = 0;
	string S;

	cin >> N >> S ;

	for (int i = 0; i<N; i++) {
		if (S[i] == '(') {
			a++;
		}
		else if (S[i] == ')') {
			if (a>0)
				a = a - 1;
			else
				b++;
		}
	}
	if (b > 0) {
		for (int i = 0; i < b; i++) {
			cout << '(';
		}
	}
	cout << S;
	if (a > 0) {
		for (int i = 0; i < a; i++) {
			cout << ')';
		}
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

	int a=0, b=0, c=0, d=0,n=0,x=0,y=0;

	scanf("%d", &n);

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

		scanf("%d%d%d%d", &a, &b, &c, &d);

		x = a*c + b*d;
		
		if (c>4 && d > 1){ x = 4 * x / 5; }

		if (c < 5){ c = 5; }
		if (d < 2){ d = 2; }
		
		y = a*c + b*d;
		y /= 5;
		y *= 4;
		if (x < y){ printf("%d\n", x); 
		}
		else{
			printf("%d\n", y);
		}
	}
	
	return 0;
}

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

#define INF 1000000007
#define ll long long
#define F first
#define S second
#define pii pair<ll int,ll int>
#define pb push_back
#define ppb pop_back
#define pf push_front
#define	ppf pop_front
#define vi vector<ll int>


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t1=1;
	//cin >> t;
	while(t1--){
		string str;
		cin >> str;
		deque <char> a;
		for(char b : str) a.pb(b);
		int q;
		cin >> q;
		int f;
		char c;
		int t;
		bool flag=true;
		while(q--){
			cin >> t;
			if(t==1) flag = !flag;
			else{
				cin >> f >> c;
				if(f==1){
					if(flag){
						a.pf(c);
					}
					else{
						a.pb(c);
					}
				}
				else{
					if(flag){
						a.pb(c);
					}
					else{
						a.pf(c);
					}
				}
			}
		}
		if(flag){
			for(auto itr=a.begin();itr!=a.end();itr++) cout << *itr;
		}
		else{
			for(auto itr=a.rbegin();itr!=a.rend();itr++) cout << *itr;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 976
/*
  file : /main.comp.cpp
  date : 2015-10-23

 */

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cassert>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef ll int__;
#define rep(i,j) for(int__ i=0;i<(int__)(j);i++)
#define repeat(i,j,k) for(int__ i=(j);i<(int__)(k);i++)
#define all(v) v.begin(),v.end()

#define N_MAX 1130
#define K_MAX 15
int DP[N_MAX][K_MAX];//n k


void init(){
    vector<bool> is_prime(N_MAX,true);
    is_prime[0]=false;
    is_prime[1]=false;
    for(int i=2;i<N_MAX;i++){
        if(not is_prime[i])continue;
        for(int j =i*2;j<N_MAX;j+=i){
            is_prime[j]=false;
        }
    }

    rep(i,N_MAX){
        rep(j,K_MAX){
            DP[i][j]=0;
        }
    }

    // rep(p,N_MAX){
    //     if(is_prime[p])DP[p][1]=1;
    // }
    DP[0][0]=1;
    rep(p,N_MAX){
        if(is_prime[p]){
            for(int k=K_MAX-1;k>=0;k--){
                rep(n,N_MAX){
                    if(n-p>=0 and k-1>=0)DP[n][k] += DP[n-p][k-1];
                    //printf("%lld %d %d\n",n,k,DP[n][k]);
                }
            }
        }


    }
}


bool solve(){
    int n,k;
    cin>>n>>k;
    if(n==0 && k==0)return false;
    cout << DP[n][k] <<endl;    
    return true;
}

int main()
{
    init();

    // rep(n,25){
    //     cout<<n<<"  ";
    //     rep(k,3){
    //         cout <<DP[n][k] <<" ";
    //     }
    //     cout <<endl;
    // }
    
    while(solve());
    return 0;
}

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

#define INFTY INT_MAX
#define MAX 500000

int compCount;

void merge(int* s, int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    int *l, *r;
    l = new int[n1+1];
    r = new int[n2+1];

    for (int i = 0; i < n1; i++)
        l[i] = s[left + i];
    for (int i = 0; i < n2; i++)
        r[i] = s[mid + i];
    
    l[n1] = r[n2] = INFTY;
    int i = 0;
    int j = 0;
    for (int k = left; k < right; k++) {
        if (l[i] <= r[j]) {
            s[k] = l[i];
            i++;
        } else {
            s[k] = r[j];
            j++;
        }
        compCount++;
    }
    delete [] l;
    delete [] r;
}

void mergeSort(int* s, int left, int right)
{
    if (left + 1 >= right) return;
    int mid = (left + right) / 2;
    mergeSort(s, left, mid);
    mergeSort(s, mid, right);
    merge(s, left, mid, right);
}

int main(int, char**)
{
    int n;
    int *s;
    s = new int[MAX];
    compCount = 0;

    cin >> n;
    for (int i = 0; i < n; i++) cin >> s[i];

    mergeSort(s, 0, n);
    for (int i = 0; i < n; i++)
        if (i < n-1) cout << s[i] << " ";
        else cout << s[i] << endl; 
    cout << compCount << endl;
    delete [] s;

    return 0;
}


Measured memory_bytes: 6896
n=int(input())
a=list(map(int,input().split()))
tmp=0
ca=[tmp]
for x in a:
  tmp+=x
  ca.append(tmp)
ans=float('inf')
bidx=0
cidx=1
didx=2
eidx=3

for didx in range(1,n-1):
  p=ca[cidx]-ca[bidx]
  q=ca[didx]-ca[cidx]
  r=ca[eidx]-ca[didx]
  s=ca[-1]-ca[eidx]
  
  np=ca[cidx+1]-ca[bidx]
  nq=ca[didx]-ca[cidx+1]
  while cidx+1<didx and abs(p-q)>abs(np-nq):
    cidx+=1
    p,q=np,nq
    np=ca[cidx+1]-ca[bidx]
    nq=ca[didx]-ca[cidx+1]

  nr=ca[eidx+1]-ca[didx]
  ns=ca[-1]-ca[eidx+1]
  while eidx+1<n and abs(r-s)>abs(nr-ns):
    eidx+=1
    r,s=nr,ns
    nr=ca[eidx+1]-ca[didx]
    ns=ca[-1]-ca[eidx+1]

  ans=min(ans,max(p,q,r,s)-min(p,q,r,s))
print(ans)



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

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  if (s == u) {
    cout << a - 1 << " " << b << endl;
  } else {
    cout << a << " " << b - 1 << endl;
  }
  return 0;
}

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

ll gcd(ll a, ll b){
    ll m,n;
    m=max(a,b);
    n=min(a,b);
    if(m%n==0) return n;
    else return gcd(m%n, n);
}

int main(){
    int n;
    cin >> n;
    ll ans=1;
    for(int i=0; i<n; i++){
        ll t;
        cin >> t;
        ans = (ans/gcd(ans, t))*t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> tree(n, vector<pair<int, int>>());
  rep(i, n-1){
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    tree.at(a).push_back({b, c});
    tree.at(b).push_back({a, c});
  }

  int qe, k;
  cin >> qe >> k;
  k--;
  vector<ll> d(n, -1);
  d.at(k) = 0;
  queue<int> q;
  q.push(k);
  while(!q.empty()){
    auto now = q.front(); q.pop();
    for(auto p : tree.at(now)){
      if(d.at(p.first) != -1) continue;
      d.at(p.first) = d.at(now) + p.second;
      q.push(p.first);
    }
  }
  rep(_q, qe){
    int x, y;
    cin >> x >> y;
    x--; y--;
    ll ans = d.at(x) + d.at(y);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 10700