akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  vector<int> A(N);
  REP(i, N) {
    cin >> A[i];
    A[i]--;
  }

  int ans = 0;
  REP(i, N) {
    if (A[A[i]] == i) ans++;
  }
  cout << ans / 2 << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    int A,P;cin>>A>>P;
    cout<<(A*3+P)/2<<endl;
}

Measured memory_bytes: 256
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys

k = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
if len(s) <= k:
    print(s)
else:
    print(s[:k]+'...')


Measured memory_bytes: 72744
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int K = in.nextInt();
            int X = in.nextInt();

            StringBuilder res = new StringBuilder();
            for (int x = X - K + 1; x <= X + K - 1; x++) {
                res.append(x).append(" ");
            }

            System.out.println(res.toString().trim());
        }
    }
}


Measured memory_bytes: 27092
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
ll M=1e9+7;
ll BM(ll a,ll b)
{
    ll k=1;
    while(b!=0)
    {
        if(b%2==1)
        {
            k=(k*a)%M;
        }
        a=(a*a)%M;
        b/=2;
    }
    return k;
}
ll MI(ll a)
{
    return (BM(a,M-2)+M)%M;
}
int main()
{
    ft
    ll i,n,a,b,x,y,s=1;
    cin>>a>>b;
    x=(2*a-b)/3;
    y=(2*b-a)/3;
    if((a+b)%3!=0 || x<0 || y<0)
    {
        cout<<"0\n";
        return 0;
    }
    n=x+y;
    for(i=1;i<=n;i++)
    {
        s=(s*i)%M;
    }
    for(i=1;i<=x;i++)
    {
        s=(s*MI(i))%M;
    }
    for(i=1;i<=y;i++)
    {
        s=(s*MI(i))%M;
    }
    cout<<s<<"\n";
    return 0;
}

Measured memory_bytes: 3684
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
    int N, M;
    cin >> N >> M;
    vector<P> v;
    for(int i = 0; i < N; i++){
        P p;
        cin >> p.first >> p.second;
        v.push_back(p);
    }
    for(int i = 0; i < M; i++){
        P p;
        cin >> p.first >> p.second;
        p.second *= -1;
        v.push_back(p);
    }
    sort(v.begin(), v.end());
    priority_queue<long long int> que;
    for(int i = v.size() - 1; i >= 0; i--){
        if(v[i].second < 0){
            while(que.size() >= -v[i].second){
                que.pop();
            }
        }else{
            que.push(-v[i].second);
        }
    }
    long long int ans = 0;
    while(!que.empty()){
        ans -= que.top();
        que.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7020
#include<iostream>
#include<string>
#include<algorithm>
#include <cctype>

using namespace std;

int main()
{
	string s1,s2,s3;
	cin >> s1 >> s2 >>s3 ; 

	transform(s1.begin(), s1.end(), s1.begin(), ::toupper);
	transform(s2.begin(), s2.end(), s2.begin(), ::toupper);
	transform(s3.begin(), s3.end(), s3.begin(), ::toupper);

	cout << s1[0]<< s2[0] << s3[0] << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1LL<<59)

signed main(){
    int n,a,b;
    cin>>n>>a>>b;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    
    int ans = 0;
    
    rep(i,n-1){
        ans+=min( (v[i+1]-v[i])*a, b );
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

bool ask(int t) {
        cout << t << endl;
        string s;
        cin >> s;
        if (s[0] == 'V') exit(0);
        return s[0] == 'F';
}

int main() {
        int n;
        scanf("%d", &n);
        bool a = ask(0);
        bool b = a;
        int lb = 1, ub = n - 1;
        for (;;) {
                if (lb >= ub) {
                        ask(lb);
                        ask(ub);
                }
                int mid = (lb + ub) / 2;
                bool t = ask(mid);
                if (((mid - lb) % 2 == 0) != (a != t)) ub = mid - 1, b = t;
                else lb = mid + 1, a = t;
        }
        return 0;
}



Measured memory_bytes: 852
<?php
	$n = trim(fgets(STDIN));

	for ($i = 1; $i <= $n; $i++) {
		$x = $i;
		if ($x % 3 == 0) {
			print " $i";
			continue;
		}

		while ($x) {
			if ($x % 10 == 3) {
				print " $i";
				break;
			}

			$x /= 10;
		}
	}

	print "\n";

Measured memory_bytes: 6568
#include<iostream>
#include <string>
#include <cstdlib> //絶対値利用のため
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)

//const int INF = INT_MAX / 2;

int main() {
	int a,b,t;
	cin >> a >> b >> t;
	cout << (t/a)*b << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  
  cin >> a >> b;
  
  if((a + b) % 2){
  	c = (a + b + 1) / 2;
  }else{
    c = (a + b) / 2;
  }
  
  cout << c << endl;
}

Measured memory_bytes: 256
s = input()

# 圧縮した文字列 t に対して len(t) - 1 が答え

from itertools import groupby

groups = []
uniquekeys = []
for k, g in groupby(s):
    groups.append(list(g))
    uniquekeys.append(k)

# print(groups)
# print(uniquekeys)

print(len(uniquekeys) - 1)

Measured memory_bytes: 60252
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};
const int W = 1;
const int B = 2;
int w, h;
vector<vector<int> > label;

void dfs(int x, int y, int who) {
	label[y][x] |= who;
	for(int i = 0; i < 4; ++i) {
		const int nx = x + dx[i], ny = y + dy[i];
		if(nx < 0 || ny < 0 || nx >= w || ny >= h)
			continue;

		if(!(label[ny][nx] & who))
			dfs(nx, ny, who);
	}
}

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

	while(cin >> w >> h, w) {
		vector<string> field(h);
		for(int i = 0; i < h; ++i)
			cin >> field[i];

		label.clear();
		label.resize(h, vector<int>(w, 0));
		for(int i = 0; i < h; ++i)
			for(int j = 0; j < w; ++j)
				if(field[i][j] != '.')
					label[i][j] = (W | B);

		for(int i = 0; i < h; ++i)
			for(int j = 0; j < w; ++j)
				if(field[i][j] == 'W')
					dfs(j, i, W);
				else if(field[i][j] == 'B')
					dfs(j, i, B);

		int num_b = 0, num_w = 0;
		for(int i = 0; i < h; ++i)
			for(int j = 0; j < w; ++j)
				if(label[i][j] == W)
					++num_w;
				else if(label[i][j] == B)
					++num_b;
					
		cout << num_b << " " << num_w << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1312
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
#include <bits/stdc++.h>
#include <regex> //正規表現
using namespace std;
#define _GLIBCXX_DEBUG /GCC環境下で[]による配列要素参照のエラーを出す
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  string e;
  int ans=0;
  rep(i,10){
    //cout<<i<<" ";
    rep(j,10){
      //cout<<j<<" ";
      rep(k,10){
        //cout<<k<<endl;
        e=s;
        if(e.find(to_string(i))==string::npos){
          goto SKIPi;
        }else{//cout<<e<<" "<<e.find(to_string(k))<<endl;
          e=e.substr(e.find(to_string(i))+1);
          //cout<<e<<endl;
        }
        if(e.find(to_string(j))==string::npos){
          goto SKIPj;
        }else{//cout<<e<<" "<<e.find(to_string(j))<<endl;
          e=e.substr(e.find(to_string(j))+1);
         // cout<<e<<endl;
        }
        if(e.find(to_string(k))==string::npos){
          continue;
        }else{//cout<<e<<" "<<e.find(to_string(i))<<endl;
        //cout<<100*i+10*j+k<<endl;
        //cout<<e<<endl;
          ans+=1;
        }
      }
      SKIPj:;
    }
    SKIPi:;
  }
  cout<<ans<<endl;
}

  

Measured memory_bytes: 3820
# -*- coding: utf-8 -*-
import math
a = int(input())


ans = a/1.08

if int(math.floor(ans)*1.08) == a:
    ans = math.floor(ans)
elif int(math.ceil(ans)*1.08) == a:
    ans = math.ceil(ans)
else:
    ans = ":("

print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
int f(int m[],int c,int n){
  int t=0;
  if(n-c==0)
    return 1;
  if(m[n-c-1])
    return m[n-c-1];
  if(n-c>2)
    t+=f(m,c+3,n);
  if(n-c>1)
    t+=f(m,c+2,n);
  if(n-c>0)
    t+=f(m,c+1,n);
  m[n-c-1]=t;
  return t;
}
int main(){
  int n,m[30];
  memset(m,0,sizeof(m));
  for(;;){
    scanf("%d",&n);
    if(n==0)
      break;
    printf("%d\n",((f(m,0,n)+9)/10+364)/365);
  }
  return 0;
}
  

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define N 200100
using namespace std;
int n,m,ans;
int cs[N],qz[N],a[N];
int tot[N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		cs[a[i]]++;
	}
	for(int i=1;i<=n;i++){
		qz[i+1]--;
		qz[max(i-cs[i]+1,1)]++;
	}
	int fla=0;
	for(int i=1;i<=n;i++){
		fla+=qz[i];
		tot[i]=fla;
		if(!tot[i]) ans++;
	}
	while(m--){
		int l,r,bas;
		scanf("%d%d",&l,&r);
		bas=a[l];
		if(bas-cs[bas]+1>0){
			if(tot[bas-cs[bas]+1]==1) ans++;
			tot[bas-cs[bas]+1]--;
		}
		cs[bas]--;
		if(r-cs[r]>0){
			if(tot[r-cs[r]]==0) ans--;
			tot[r-cs[r]]++;
		}
		cs[r]++;
		a[l]=r;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int r; cin>>r;
    cout<<fixed<<setprecision(4);
    cout<<r*2*3.14159265<<endl;
}


Measured memory_bytes: 3784
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int N;
vector<int> H;

int main() {
	cin >> N;
	H.resize(N);
	for (int n = 0; n < N; n++)cin >> H[n];
	H[0]--;
	for (int n = 1; n < N; n++) {
		if (H[n - 1] < H[n])H[n]--;
		else if (H[n - 1] == H[n])continue;
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec_1(N);
  vec_1.at(1) = N + 1;
  vector<int> vec_2(N);
  for(int i = 1; i < N; i++) {
    cin >> vec_1.at(i);
    vec_2.at(vec_1.at(i) - 1)++;
  }
  for(int i = 0; i < N; i++) {
    cout << vec_2.at(i) << endl;
  }
}

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

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

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  ll N;

  cin >> N;

  ll ans = INF;
  for(ll i = 1; i * i <= N; i++){
    if(N%i!=0)continue;
    ans = min(ans, i + (N/i) - 2);
  }

  cout << ans << endl;
}




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

using namespace std;

int main() {
  int n, p;
  cin >> n >> p;
  int odds = 0;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    if (tmp % 2 == 1) {
      odds++;
    }
  }

  int evens = n - odds;

  if (p == 1 && odds == 0 || p == 0 && evens == 0 && odds == 1 ) {
    cout << 0 << endl;
    return 0;
  }

  long long ans = 1;

  for(int i = 0; i < n-1; i++){
    ans *= 2;
  }
  
  if(odds == 0){
    ans *= 2;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;

signed main() {
	int n;
	int a[100];
	int i, j;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i];
	
	int best = 1145141919;
	for (i = -200; i <= 200; i++) {
		int cst = 0;
		for (j = 0; j < n; j++) {
			cst += (a[j] - i) * (a[j] - i);
		}
		if (cst < best) {
			best = cst;
		}
	}
	cout << best << endl;
	return 0;
}

Measured memory_bytes: 256
#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 <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,x) for(int i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

int main() {
    ll N;
    cin >> N;
    vector<ll> ans(N);
    vector<ll> num(N);
    rep(i, N)cin >> num[i];
    if (N % 2 == 0) {
        rep(i, N) {
            if (i % 2 == 0) {
                ans[N / 2 + i / 2] = num[i];
            }
            else ans[N / 2 - 1 - i / 2] = num[i];
        }
    }
    else {
        rep(i, N) {
            if (i % 2 == 0) {
                ans[N / 2 - i / 2] = num[i];//3 1 2 3  3 1 2
            }
            else ans[N / 2 + 1 + i / 2] = num[i];
        }
    }
    rep(i, N)cout << ans[i] << " ";
    cout << endl;
}

Measured memory_bytes: 5248
#include <iostream>
using namespace std;
//ITP2の9番台はPythonで実装したら負けだという気がしたのでc++で書きます。

int main(void){
  int n,m;
  cin>>n;
  long A[n];
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  cin>>m;
  long B[m];
  for(int i=0;i<m;i++){
    cin>>B[i];
  }
  int i=0;
  int j=0;
  while(i<n and j<m){

    if(A[i]<B[j]){
      i++;
    }
    else if(A[i]>B[j]){
      j++;
    }
    else{
      cout<<A[i]<<endl;
      i++;
      j++;
    }

  }

  return 0;
}



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

int main() {
    int N, K, C;
    cin >> N >> K >> C;
    string S; cin >> S;
    auto solve = [&]() {
        vector<int> W(N);
        int n = 0, t = 1;
        rep(i, N) {
            if(n == 0 && S[i] == 'o') W[i] = t++, n = C;
            else if(n) n--;
            if(t == K + 1) break;
        }
        return W;
    };
    auto L = solve();
    reverse(S.begin(), S.end());
    auto R = solve();
    reverse(R.begin(), R.end());
    rep(i, N) {
        if(L[i] == K - R[i] + 1 && L[i]) cout << i + 1 << '\n';
    }
    return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        g[--a].emplace_back(--b);
        g[b].emplace_back(a);
    }
    vector<int> d(n, INF);
    vector<int> par(n, -1);
    d[0] = 0;
    queue<int> que;
    que.push(0);
    while(que.size()) {
        int v = que.front();
        que.pop();
        for(const auto &u : g[v]) {
            if(d[u] == INF) {
                d[u] = d[v] + 1;
                par[u] = v;
                que.push(u);
            }
        }
    }
    print("Yes");
    for(int i = 1; i < n; i++) {
        print(par[i] + 1);
    }
}

Measured memory_bytes: 10712
import java.util.Scanner;

//AtCoder Beginner Contest 145
//B	Echo
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String S = sc.next();
		sc.close();

		if (N % 2 == 1) {
			System.out.println("No");
			return;
		}

		for (int i = 0; i < (N / 2); i++) {
			if (S.charAt(i) != S.charAt((N / 2) + i)) {
				System.out.println("No");
				return;
			}
		}

		System.out.println("Yes");
	}
}


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

A = list(map(int,input().split()))

c = 1
M = [] #（葉でない）子ノードの数の最大値
INF = 10**16
for a in A:
    c -= a
    M.append(c)
    c *= 2

    c = min(INF, c)
    
if c < 0:
    print(-1)
else:
    cnt = A[-1]
    num = A[-1]
    for a,m in zip(reversed(A[:-1]),reversed(M[:-1])):
        n = min(num, m)
        cnt += n+a
        num = n+a
    print(cnt)

Measured memory_bytes: 678304
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

using ll = long long;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

#define mp make_pair
#define mt make_tuple

/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<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.first << "," << p.second << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
inline T sq(T a) { return a * a; }

template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

ll pcnt(ll b) {
    return __builtin_popcountll(b);
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

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

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        if (abs(sum - a[i] * N) < abs(sum - a[ans] * N)) {
            ans = i;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
 
static const double EPS = 1e-8;

static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int H,W;
char stage[20][20];
string ghost;
bool visited[20][20][20][20][10];
int gTime = 0;
int rx,ry;

class State {
public:
  int _sx,_sy,_gx,_gy,_time;
  State(int sx,int sy,int gx,int gy,int time) : 
    _sx(sx),_sy(sy),_gx(gx),_gy(gy),_time(time) {}
  bool operator<(const State &s) const {
    return _time < s._time;
  }
  bool operator>(const State &s) const {
    return _time > s._time;
  }
};

void bfs(int sx,int sy,int gx,int gy){
  State init(sx,sy,gx,gy,0);
  
  priority_queue<State,vector<State>,greater<State> > que;
  que.push(init);

  while(!que.empty()){
    State s = que.top();
    que.pop();

    int pattern_i = s._time % ghost.size();
    if(ghost[pattern_i] == '5'){
      //nothing to do
    }
    else if(ghost[pattern_i] == '8' && s._gy - 1 >= 0){
      s._gy--;
    }
    else if(ghost[pattern_i] == '6' && s._gx + 1 < W){
      s._gx++;
    }
    else if(ghost[pattern_i] == '4' && s._gx - 1 >= 0){
      s._gx--;
    }
    else if(ghost[pattern_i] == '2' && s._gy + 1 < H){
      s._gy++;
    }

    if(!visited[s._sx][s._sy][s._gx][s._gy][pattern_i]){
      visited[s._sx][s._sy][s._gx][s._gy][pattern_i] = true;
      if(s._sx == s._gx && s._sy == s._gy && gTime > s._time){
        gTime = s._time;
        rx = s._gx;
        ry = s._gy;
        return;
      }
      que.push(State(sx,sy,s._gx,s._gy,s._time+1));
    }
    for(int i = 0; i < 4; i++){
      int dx = tx[i] + s._sx;
      int dy = ty[i] + s._sy;
      if(dx < 0 || dx >= W || dy < 0 || dy >= H) continue;
         if(stage[dy][dx] == '#') continue;
         if(visited[dx][dy][s._gx][s._gy][pattern_i]) continue;
         
         visited[dx][dy][s._gx][s._gy][pattern_i] = true;
         if(dx == s._gx && dy == s._gy && gTime > s._time){
           gTime = s._time;
           rx = s._gx;
           ry = s._gy;
           return;
         }
         que.push(State(dx,dy,s._gx,s._gy,s._time+1));
    }
  }
}

int main(){
  while(~scanf("%d %d",&H,&W)){
    if(H == 0 && W == 0) break;

    int sx,sy,gx,gy;
    memset(visited,false,sizeof(visited));
    gTime = INF;

    for(int y = 0; y < H; y++){
      char line[32];
      scanf("%s",line);
      for(int x = 0; x < W; x++){
        stage[y][x] = line[x];
        if(stage[y][x] == 'A'){
          sx = x;
          sy = y;
        }
        if(stage[y][x] == 'B'){
          gx = x;
          gy = y;
        }
      }
    }
    cin >> ghost;
    rx = -1;
    ry = -1;
    bfs(sx,sy,gx,gy);
    
    if(gTime == INF){
      printf("impossible\n");
    }
    else{
      printf("%d %d %d\n",gTime + 1,ry,rx);
    }
  }
}

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

vector<int> v;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    v.push_back(c);
  }
  std::sort(v.begin(), v.end());
    
  long double prev = (v[0] + v[1]) / 2.0;
  long double res = prev;
  // cout << res << endl;
  for (int i = 2; i < n; i++) {
    // cout << "prev: " << prev << "a: " << v[i] << endl;
    prev = (prev + v[i]) / 2.0;
    // cout << "update prev: " << prev << endl;
    // res += prev;
    // cout << "res: " << res << endl;
// 
  }
  cout << prev << endl;
  return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var S = new List<long>();
            for (var i = 0; i < N; ++i)
                S.Add(Sarray()[0]);
            var ans = S.Sum();
            if (ans % 10 == 0)
            {
                S.Sort();
                foreach (var s in S)
                {
                    if (s % 10 != 0)
                    {
                        WriteLine(ans - s);
                        return;
                    }
                }
                WriteLine(0);
            }
            else
                WriteLine(ans);
            //Out.Flush();
        }
    }
}

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



int main()
{
    char a[102];  scanf("%s", a);
    char b[102];  scanf("%s", b);
    int na;
    int nb;
    int i;

    for(i = 0; a[i]; i++){
        ;
    }
    na = i;
    for(i = 0; b[i]; i++){
        ;
    }
    nb = i;

    if(na > nb){
        printf("GREATER\n");
    }
    else{
        if(na < nb){
            printf("LESS\n");
        }
        else{
            if(strcmp(a, b) > 0){
                printf("GREATER\n");
            }
            else{
                if(strcmp(a, b) < 0){
                    printf("LESS\n");
                }
                else{
                    printf("EQUAL\n");
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"

	"strconv"
)

func solve(in io.Reader, out io.Writer) error {
	sc := bufio.NewScanner(in)
	sc.Split(bufio.ScanWords)
	_, m, x := nextInt(sc), nextInt(sc), nextInt(sc)

	a := make([]int, m)
	lc, rc := 0, 0
	for i := 0; i < m; i++ {
		a[i] = nextInt(sc)

		if a[i] < x {
			lc++
		} else {
			rc++
		}
	}

	if lc < rc {
		fmt.Fprintln(out, lc)
	} else {
		fmt.Fprintln(out, rc)
	}

	return nil
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	err := solve(os.Stdin, os.Stdout)
	if err != nil {
		log.Fatal(err)
	}
}


Measured memory_bytes: 640
#include <stdio.h>
int main(){
  char c = getchar();
  long long int ans = 0;
  int a_num = 0;
  int ab = 0;
  while(c){
    if(c == 'A'){
      a_num++;
      if(ab){
        ab = 0;
        a_num = 1;
      }
    }else if(c == 'B'){
      if(ab){
        ab = 0;
        a_num = 0;
      }else if(a_num){
        ab = 1;
      }else{
        a_num = 0;
      }
    }else if(c == 'C'){
      if(ab){
        ans += a_num;
        ab = 0;
      }else{
        a_num = 0;
      }
    }else{
      break;
    }
    c = getchar();
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 128
n, m = gets.split.map(&:to_i)

islands = Hash.new { |h, k| h[k] = [] }

m.times do
  a, b = gets.split.map(&:to_i)

  islands[a] << b
  islands[b] << a
end

islands[1].each do |mid|
  if islands[mid].include? n
    puts 'POSSIBLE'
    exit
  end
end
puts 'IMPOSSIBLE'


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

using namespace std;

typedef long long ll;


ll largemod(ll m,string s)
{
    ll mod=0;

    for(int i=0; i<s.size(); i++)
    {
        mod = (mod*10 + s[i]-'0')%m;
    }
    return mod;


}

int main(void)
{

  string a,b;
  cin>>a>>b;
  int ans=0;
  for(int i=0;i<a.size();i++)
  {
      if(a[i]!=b[i])
      {
          ans++;
      }
  }
  cout<<ans<<endl;



}


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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    sort(A.begin(), A.end());
   
    bool ans = true;
    REP(i, N-1) {
        if (A[i] == A[i+1]) {
            ans = false;
            break;
        }
    }
    
    if (ans) print("YES");
    else print("NO");
}

signed main() {
    solve();
}


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

#define MAX 2000000000

typedef struct node{
  
  struct node *next;

  struct node *prev;

  unsigned int key;

}*NodePointer;

NodePointer head, last;

NodePointer make_1node(int, NodePointer);

NodePointer search(int);

void insert(int);

void delete(int);

void deleteFirst();

void deleteLast();

int main(){

  int i, n, key;

  char com[15];

  NodePointer node;

  last = make_1node(0, NULL);

  head = make_1node(0, last);

  scanf("%d", &n);

  if(MAX < n)
    exit(8);

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

    scanf("%s", com);

    if(strlen(com) == 6){

      scanf("%d", &key);

      if(com[0] == 'i')
	insert(key);
      else
	delete(key);      

    }

    else if(com[6] == 'F')
      deleteFirst();

    else
      deleteLast();

  }

  for(node = head->next; node != last; node = node->next){

    if(node->next == last)
      printf("%d\n", node->key);

    else
      printf("%d ", node->key);

  }

  return 0;

}


NodePointer make_1node(int x, NodePointer node){

  NodePointer newnode;

  newnode = (NodePointer)malloc(sizeof(struct node));

  newnode->key = x;

  newnode->next = node;

  return newnode;

}

NodePointer search(int x){

  NodePointer node;

  node = head->next;

  while((node != head) && (node->key != x)){

    if(node == last){

      node = NULL;

      break;

    }

    node = node->next;

  }

  return node;

}

void insert(int x){

  NodePointer node;

  node = (struct node *)malloc(sizeof(struct node));

  node->key = x;

  node->next = head->next;

  head->next->prev = node;

  head->next = node;

  node->prev = head;

}

void delete(int x){

  NodePointer deletenode;

  deletenode = search(x);

  if(deletenode != NULL){

    deletenode->prev->next = deletenode->next;

    deletenode->next->prev = deletenode->prev;

  }

}

void deleteFirst(){

  head->next->next->prev = head->next->prev;

  head->next = head->next->next;

}

void deleteLast(){

  last->prev->prev->next = last->prev->next;

  last->prev = last->prev->prev;

}

Measured memory_bytes: 34972
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

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

		while(true){
			final int N = sc.nextInt();
			
			if(N == 0){
				break;
			}
			
			System.gc();
			
			int[] own = new int[N];
			//int[] ene = new int[N];
			ArrayList<Integer> ene = new ArrayList<Integer>();
			
			for(int i = 0; i < N; i++){
				own[i] = -sc.nextInt();
			}
			Arrays.sort(own);
			for(int i = 0; i < N; i++){
				own[i] = -own[i];
			}
			
			
			for(int i = 0; i < N; i++){
				ene.add(sc.nextInt());
			}
			Collections.sort(ene);
			/*
			for(int i = 0; i < N; i++){
				ene[i] = -ene[i];
			}
			*/
			/*
			int[] sum = new int[N];
			for(int i = 0; i < N; i++){
				sum[i] = own[i] > ene[i] ? 1 : 0;
			}
			for(int i = 1; i < N; i++){
				sum[i] += sum[i - 1];
			}
			*/
			
			//System.out.println(Arrays.toString(sum));
			
			
			boolean flag = false;
			int win_count = 0;
			for(int K = 1; K < N; K++){
				final int must = K / 2 + 1;
				final int own_num = own[K - 1];
				
				int pos = Collections.binarySearch(ene, own_num);
				
				if(pos < 0){
					pos = -(pos + 1);
				}
				
				if(pos >= ene.size()){
					win_count++;
				}else if(own_num > ene.get(pos)){
					win_count++;
				}
				
				if(win_count >= must){
					flag = true;
					System.out.println(K);
					break;
				}
				
				if(ene.size() > pos){
					ene.remove(pos);
				}else{
					ene.remove(0);
				}
			}
			
			if(!flag){
				System.out.println("NA");
			}
			
		}
		
		sc.close();
	}
}

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

using namespace std;
#define N 200010
#define ll long long
#define ld long double

struct line
{
    ll a=0,b;
}st[4000010+2];

ll vall(line u,ll x)
{
    return u.a*x+u.b;
}

ll h[N],dp[N],C;
int n;

void update(int id,int l,int r,line high)
{
    if(l>r)return;
    line low=st[id];
    if(vall(high,l)>vall(low,l))swap(high,low);
    if(l==r)
    {
        st[id]=high;
        return;
    }
    if(vall(high,r)<vall(low,r))
    {
        st[id]=high;
        return;
    }
    int mid=(l+r)/2;
    if (vall(high,mid)<vall(low,mid))
    {
        st[id]=high;
        update(id*2+1,mid+1,r,low);
    }else
    {
        st[id]=low;
        update(id*2,l,mid,high);
    }
}

ll query(int id,int l,int r,int x)
{
    //cout<<l<<" "<<r<<" "<<x<<" "<<endl;
    if(r<l||(r<x||l>x))return 1e18;
    if(l==r)return vall(st[id],x);
    int mid=(l+r)/2;
    if(x<=mid)return min(vall(st[id],x),query(id*2,l,mid,x));
        else return min(vall(st[id],x),query(id*2+1,mid+1,r,x));
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cin>>n>>C;
    for(int i=1;i<=n;i++)cin>>h[i];
    dp[1]=0;
    update(1,1,1e6,{-2*h[1],dp[1]+h[1]*h[1]});
    //cout<<"CC\n";
    for(int i=2;i<=n;i++)
    {
        ll u=query(1,1,1e6,h[i]);
        dp[i]=u+h[i]*h[i]+C;
        update(1,1,1e6,{-2*h[i],dp[i]+h[i]*h[i]});
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 69248
// This code writed by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
using namespace std;
template <class t> inline void rd(t &s)
{
	s=0;
	reg char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return;
}
double a[1001];
signed main(void)
{
	int n;cin>>n;
	double ans=0.0;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	for(int i=1;i<=n;++i)
		ans+=1.0/a[i];
	cout<<1.0/ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>

int bubbleSort(int A[], int N) {
	int sw = 0;
	bool flag = 1;
	for(int i = 0; flag; i++){
		flag = 0;
		for(int j = N-1; j >= i+1; j--){
			if(A[j] < A[j-1]){
				std::swap(A[j], A[j-1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main() {
	int A[100], N, sw;
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		std::cin >> A[i];
	}
	sw = bubbleSort(A, N);

	for(int i = 0; i < N; i++) {
		if(i) std::cout << " ";
		std::cout << A[i];
	}
	std::cout << std::endl;
	std::cout << sw << std::endl;

	return 0;
}


Measured memory_bytes: 3108
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <set>
#include <string>
#include <unordered_map>

using namespace std;

const double PI = 3.14159265358979323846;

int main() {
  int n;

  cin >> n;

  cout << 2 * PI * n << endl;

  return 0;
}

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

typedef long long ll;

string S;
ll N;
vector<vector<ll>> Dp;
const ll B = 13;
const ll MOD = 1e9 + 7;

int main() {
  cin >> S;
  N = S.size();
  Dp.resize(N + 1);
  for (auto &dp : Dp) dp.resize(B);
  Dp[0][0] = 1;
  for (ll i = 0; i < N; ++i) {
    for (ll k = 0; k < B; ++k) {
      for (ll d = 0; d < 10; ++d) {
        if (S[i] == '0' + d || S[i] == '?') {
          (Dp[i + 1][(k * 10 + d) % B] += Dp[i][k]) %= MOD;
        }
      }
    }
  }
  cout << Dp[N][5] << endl;
  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ac(n), pena(n);
  rep(i, m) {
    int p;
    string s;
    cin >> p >> s;
    --p;
    if (ac[p]) continue;
    if (s == "AC") {
      ac[p] = 1;
    } else {
      pena[p]++;
    }
  }
  int AC = 0, PENA = 0;
  rep(i, n) {
    AC += ac[i];
    if (ac[i]) PENA += pena[i];
  }
  printf("%d %d\n", AC, PENA);
  return 0;
}


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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 912345678;

int n, i;
int main()
{
    cin >> n >> i;
    cout << n - i + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    string s;

    cin >> s;

    ll n = 0;

    ll t = 1;

    for (int i = s.size() - 1; i >= 0; i--)
    {
        if (s[i] == '/')
            continue;

        n += t * (s[i] - '0');

        t *= 10;
    }

    if (n <= 20190430)
        cout << "Heisei" << endl;
    else
        cout << "TBD" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int r;
    cin >> r;
    double ans;
    ans = r*2*3.1415926535;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3756
import math
import sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from heapq import heapify, heappop, heappush
from itertools import chain, combinations, permutations, product
from typing import List, Dict

# import numpy as np

sys.setrecursionlimit(10**6 + 1)
input = sys.stdin.readline
write = sys.stdout.write


def read_item(cls=int):
    return cls(input())


def read_n_item(cls=int) -> list:
    return [cls(s) for s in input().split()]


def list2d(row, col, init_val=0) -> List[list]:
    return [[init_val] * col for _ in range(row)]


def nCr_factory(limit, mod):
    """ return a combinatorial number operator with upper bound """

    fact = [1] * (limit + 1)
    for i in range(1, len(fact)):
        fact[i] = i * fact[i-1] % mod

    ifact = [1] * (limit + 1)
    ifact[-1] = pow(fact[-1], mod-2, mod)

    for i in range(1, len(fact)-1)[::-1]:
        ifact[i] = ifact[i+1] * (i+1) % mod

    def calc(n, i):
        """ combinatorial number with modulo """
        if i < 0 or i > n:
            return 0
        return fact[n] * ifact[i] % mod * ifact[n-i] % mod
    return calc


# MOD = 10**9 + 7
MOD = 998244353

nCr = nCr_factory(2*10**5, MOD)

N, M, K = read_n_item()
dp = [0] * (N+1)
dp[0], dp[1] = 1, M

for i in range(2, N+1):
    dp[i] = dp[i-1] * (M-1) % MOD

ans = 0
for i in range(K+1):
    remain = N - i
    ans += dp[remain] * nCr(N-1, i)
    ans %= MOD
print(ans)



Measured memory_bytes: 33780
#include "bits/stdc++.h"

using namespace std;

int dp[1024][1024];
char s1[1024], s2[1024];

void solve()
{
	scanf("%s\n%s\n", s1, s2);
	int l1 = strlen(s1), l2 = strlen(s2);
	for (int i = 0; i <= l1; i++)
		for (int j = 0; j<= l2; j++)
	{
		//0番目の文字は便宜上空文字とする
		if (i == 0)
		{
			dp[i][j] = j;
			continue;
		}
		if (j == 0)
		{
			dp[i][j] = i;
			continue;
		}
		else
		{
			dp[i][j] = INT_MAX;
		}
		//i文字目とj文字目が一致していれば置換不要
		dp[i][j] = min(dp[i-1][j-1]+(s1[i-1] != s2[j-1]), dp[i][j]);
		//挿入
		dp[i][j] = min(dp[i][j-1]+1, dp[i][j]);
		//削除
		dp[i][j] = min(dp[i-1][j]+1, dp[i][j]);
	}

	printf("%d\n", dp[l1][l2]);
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



Measured memory_bytes: 7236
s = input()
q = int(input())
cnt = 0
front = []
back = []
for i in range(q):
    t = input()
    if t[0] == "1":
        cnt += 1
        cnt %= 2
    else:
        _, f, c = t.split()
        f = int(f)
        x = f+cnt
        if x%2 == 1:
            front.append(c)
        else:
            back.append(c)

a = "".join(front)
a = a[::-1]
b = "".join(back)
ans = "".join([a,s,b])
if cnt%2 == 1:
    ans = ans[::-1]
print(ans)



Measured memory_bytes: 70872
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
const int N=1005;
int n, m;
string s[N];
int dis[N][N]={};
bool valid(int x, int y)
{
    if(x<n&&x>=0&&y<m&&y>=0&&s[x][y]=='.') return true;
    return false;
}
void solve()
{
    int k,i=1,j,x,y,l,r,p,q,z;
    ll ans=0;
    cin>>n>>m;
    int x1,x2,y1,y2;
    cin>>x1>>y1;
    cin>>x2>>y2;
    x1--,x2--,y1--,y2--;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            dis[i][j]=1000000000;
    dis[x1][y1]=0;
    for(i=0;i<n;i++)
        cin>>s[i];
    deque <int> xs, ys;
    xs.pb(x1);
    ys.pb(y1);
    int dx[4]={1,-1,0,0};
    int dy[4]={0,0,1,-1};
    while(xs.size())
    {
        int curX=*xs.begin(), curY=*ys.begin();
        xs.pop_front(), ys.pop_front();
        //cout<<curX<<" "<<curY<<endl;
        for(int d=0; d<4; d++)
        {
            x = curX+dx[d], y = curY + dy[d];
            if(valid(x, y))
            {
                if(dis[x][y] > dis[curX][curY])
                {
                    dis[x][y]=dis[curX][curY];
                    xs.push_front(x);
                    ys.push_front(y);
                }
            }
        }
        for(p=curX-2; p<=curX+2; p++)
        {
            for(q=curY-2; q<=curY+2; q++)
            {
                if(valid(p, q))
                {
                    if(dis[p][q] > dis[curX][curY]+1)
                    {
                        dis[p][q]=dis[curX][curY]+1;
                        xs.push_back(p);
                        ys.push_back(q);
                    }
                }
            }
        }
    }
    if(dis[x2][y2]==1e9) cout<<-1;
    else cout<<dis[x2][y2];
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif 
    int t=1;
    //cin>>t;
    while(t--)solve();
    return 0;
}

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

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

// vector 操作  vector<int> data(10,5) 5が10個　data(10) 要素数10
// v.size(), v.empty(), v.insert(itr,値), v.erase(itr) (first,last),
// sort(itr), find(all(x),値),reverse(itr),accumulate(itr,0) 積算,
//v.swap
// stringも同じ itrがただの数字になる
// s.substr(n,m)n番目以降m文字取り出す　erase(n,m)も  s.find
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

// map 操作  map<string,int> mp キー=string 値=int型  pair< , >型
// 代入:mp["abc"]=123  mp.erase(キー)
// itr = mp.begin()のとき　itr->first = key, itr->second = val
// mp.find(key) itrを返す
typedef pair<int,int> P;  //q(p.first,p.second)で定義できる？

// lcm( , ) gcd( , ) 最大公約数　最小公倍数
//if(cin.eof()) break; 入力数が決まってないとき
//ifstream  whilwee(ifs>>data)

// 浮動小数点
// cout << fixed; 以下と組fみ合わせで小数点以下n桁
// cout << setprecision(n) << 値; n桁表記
// defaultfloat
int main (){
    int n;
    cin >> n;
    vei r(n);
    for(int i=0;i<n;i++){
        cin >> r[i];
    }

    // velli ans(n-1); 
    // velli r2 = r;
    // REP(i,n-1){
    //     r2.erase(r2.begin());
    //     velli r3 = r2;
    //     sort(all(r3));
    //     reverse(all(r3));
    //     ans[i] = r3[0]-r[i];
    // }
    // sort(all(ans));
    // reverse(all(ans));
    // cout << ans[0] << endl;
    int minv = r[0];
    int maxv = -2000000000;
    for(int j=1;j<n;j++){
        maxv = max(maxv,r[j]-minv);
        minv = min(r[j],minv);
        }
    cout << maxv <<endl;
}


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

int main()
{
	long long n;
	string s = "";
	cin >> n;

	bool ok = false;
	int x, y;
	while(n >= 1){
		if(n <= 26) ok = true;
		x = n / 26;
		y = n % 26;
		n = floor(n / 26);
		//cout << x << ' ' << y << ' ' << endl;
		if(y == 0) s += 'z', n--;
		else s += 'a' + y - 1;
		if(ok) break;
	}
	for(int i=s.size()-1; i>=0; i--) cout << s[i];



    return 0;
}


Measured memory_bytes: 3532
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC114_B();
        }

        static void ABC114_B()
        {
            var S = Console.ReadLine();
            var list = new List<int>();
            for (var i = 0; i < S.Length - 2; i++)
                list.Add(int.Parse($"{S[i]}{S[i + 1]}{S[i + 2]}"));
            Console.WriteLine(list.Select(x => Math.Abs(753 - x)).Min());
        }
    }
}

Measured memory_bytes: 11348
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string s,ss;
	int sum = 0;
	while(cin >>s){
		ss = s;
		reverse(s.begin(),s.end());
		if(s == ss){sum++;}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 0