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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int n,y;cin>>n>>y;
    vi v(3,0);
    v[2]=y/1000;
    int d=v[2]-n;
    if(d<0){
        rep(i,3){
            v[i]=-1;
            if(i==2){
                cout<<v[i]<<endl;
            }
            else{
                cout<<v[i]<<" ";
            }
        }
        return 0;
    }
    while(v[2]>=5&&d>=4){
        v[2]-=5;
        v[1]++;
        d-=4;
    }
    while(v[1]>=2&&d>=1){
        v[1]-=2;
        v[0]++;
        d--;
    }
    if(d>0){
        rep(i,3){
            v[i]=-1;
        }
    }
    rep(i,3){   
        if(i==2){
            cout<<v[i]<<endl;
        }
        else{cout<<v[i]<<" ";}
    }
}


Measured memory_bytes: 256
x, k, d = map(int, input().split())
x = abs(x)
a = x // d
b = x % d
c = b - d
#print(a, b, c)
if k < a:
  x -= d * k
  print(x)
else:
  k -= a
  k %= 2
  if k == 0:
    print(abs(b))
  else:
    print(abs(c))


Measured memory_bytes: 9116
#include<stdio.h>
#define Max(x,y) ((x>y)?x:y)
#define min(x,y) ((x<y)?x:y)
int main(){
	int i,j,x,y,n,ma,mi;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		ma=0;
		mi=500;
		while(n--){
			x=0;
			for(i=0;i<5;i++){
				scanf("%d",&y);
				x+=y;
			}
			ma=Max(ma,x);
			mi=min(mi,x);
		}
		printf("%d %d\n",ma,mi);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void)
{
	int m[12]={31,29,31,30,31,30,31,31,30,31,30,31};
	int man,day;
	int s;
	int i;
	
	scanf("%d %d",&man,&day);
	while(man!=0){
		s=0;
		if(man!=1){
			for(i=0;i<man-1;i++){
				s+=m[i];
			}
			s+=day;
		}
		else {
			s+=day;
		}
	//	printf("%d\n",s);
		s=s%7;
		if(s==0){
			printf("Wednesday\n");
		}
		else if(s==1){
			printf("Thursday\n");
		}
		else if(s==2){
			printf("Friday\n");
		}
		else if(s==3){
			printf("Saturday\n");
		}
		else if(s==4){
			printf("Sunday\n");
		}
		else if(s==5){
			printf("Monday\n");
		}
		else if(s==6){
			printf("Tuesday\n");
		}
		scanf("%d %d",&man,&day);
	}
	return 0;
}

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

int main(){
    long long n, k;
    cin >> n >> k;
    long long a[n];
    for (long long i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i] -= 1;//0からに変換
    }

    //このまちが何個めの町かの配列
    long long come[n];
    for (int i = 0; i < n; i++)
    {
        come[i] = -1;//-1が未訪問
    }

    //どっかで町をぐるぐるするからそのサイクルの数を変数でもっとく
    long long cicle;

    //現在地,最初は0番目の町
    int now = 0;
    //町1スタート
    come[0] = 0;

    //テレポート開始
    long long i = 0;
    for (i = 0; i < k; i++)
    {
        now = a[now];//移動

        if (come[now] == -1)//初町
        {
            come[now] = i + 1;

        }else{//二回め町
            break;
            //この時nowはサイクルのスタートの町番号、i+1-come[now]がサイクルの数
            //come[now]はサイクルに入るまでにしたワープ数、
        }
        
    }

    cicle = i + 1 - come[now];

    //ぐるぐるした後何個めの町か。
    long long after_cicle;

    after_cicle = (k - come[now]) % cicle;

    //何こ目に行った町か
    long long doko;
    doko = come[now] + after_cicle;

    //doko番目に行った町を探す
    for (int i = 0; i < n; i++)
    {
        if (come[i] == doko)
        {
            cout << i + 1 << endl;
            return 0;
        }
        
    }
    


    
    
    
    
}

Measured memory_bytes: 6748
// AtCoder Beginner Contest 153 C.cpp

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	long long n, k, sum = 0;
	cin >> n >> k;
	vector<long long>h(n);
	for (auto& i : h) {
		cin >> i;
	}
	sort(h.begin(), h.end(), std::greater<long long>());
	for (auto i : h) {
		if (k > 0) {
			k--;
		}
		else {
			sum += i;
		}
	}

	cout << sum << endl;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=1e9+7;


int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();
    
    string s,t;
    cin>>s>>t;
    ll ans=1e9,n=s.size(),m=t.size();
    for(int i=0;i<=n-m;i++){
        ll k=0;
        for(int j=0;j<m;j++){
            if(s[i+j]!=t[j])
                k++;
        }
        ans=min(ans,k);
    }
    cout<<ans;

    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

Measured memory_bytes: 3844
#include <iostream>
#include <string>

bool is_reversable(const std::string& str) {
    bool even = 0!=(str.length() & 1);
    {
        for (size_t i = 0; i < str.length() / 2; ++i) {
            if (str[i] != str[str.length() - 1 - i]) return false;
        }
        return true;
    }
}

int main()
{
    std::string base_str;
    std::cin >> base_str;

    if (is_reversable(base_str)) {
        auto before=base_str.substr(0, base_str.length() / 2);
        auto after = base_str.substr( ((base_str.length()+3) / 2)-1,base_str.length()/2);
        if (is_reversable(before)) {
            if (is_reversable(after)) {
                std::cout << "Yes" << std::endl;
                return 0;
            }
        }
    }
    
    std::cout << "No" << std::endl;

    return 0;

}

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

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

result = 'APPROVED'


        
for i in range(0,N):
  if a[i] %2 == 0:
     if (a[i] %3 != 0) and (a[i] %5 != 0):
        result ='DENIED'

        break
        
        
print (result)

Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

ll y[10000005];

int main() {
    ll n;
    cin >> n;
    ll ans = 0ll;
    for(ll i = 1ll; i * i < n; i++){
        if(n % i == 0 && n/i -1 != i) ans += n / i - 1ll;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
import sys
input = sys.stdin.readline
import math
import collections
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n=I()
Hs=(LI())
if n==1:
    print("Yes")
    sys.exit()
for i in range(1,n):
    #print(Hs[-i])
    if Hs[-i-1]==Hs[-i]+1:
        Hs[-i-1]-=1
    elif Hs[-i-1]>Hs[-i]+1:
        print("No")
        sys.exit()
if i==n-1:
    print("Yes")

Measured memory_bytes: 14636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846264338327950;
inline int newline() { putchar('\n'); return 0; }

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

    ll result = 1;
    bool flag = false;

    rep2(i, n) {
        ll temp;
        cin(temp);

        if (!temp) {
            print(0);
            return 0;
        }

        if (result > 1000000000000000000 / temp) {
            flag = true;
        }

        result *= temp;
    }

    print((flag ? -1 : result));
    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
const int N=1e2+5;
int dp[N][N],r,c;
char mp[N][N];
map<char,int>ch;
int main(){
	ch['#']=1,ch['.']=0;
	cin>>r>>c;
	for(int i=1;i<=r;i++)
		for(int j=1;j<=c;j++)	cin>>mp[i][j];
	memset(dp,0x3f,sizeof dp);
	dp[1][1]=ch[mp[1][1]];
	for(int i=1;i<=r;i++)
		for(int j=i==1?2:1;j<=c;j++)
			dp[i][j]=min(dp[i-1][j]+(!ch[mp[i-1][j]]&&ch[mp[i][j]]),dp[i][j-1]+(!ch[mp[i][j-1]]&&ch[mp[i][j]]));
	cout<<dp[r][c]<<endl;
	return 0; 
} 

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    int cnt = 0, haszero = 0;
    long long sum = 0;
    int mi = INF;
    for (int ai: a) {
        cnt += ai < 0;
        haszero += ai == 0;
        sum += abs(ai);
        mi = min(mi, abs(ai));
    }
    if (cnt % 2 == 0 || haszero) cout << sum << endl;
    else cout << sum - mi * 2 << endl;
    return 0;
}

Measured memory_bytes: 640
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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 MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi A(n);
  VIN(A)
  M memo;
  REP(i,n){
    if(memo[A[i]]==0){
      memo[A[i]]++;
    } else {
      memo[A[i]] = 0;
    }
  } 
  for(auto itr: memo){
    if(itr.second == 1) z++;
  }
  OUT(z);
}

Measured memory_bytes: 7296
#include<iostream>

using namespace std;

const long long INF = 1e18;

int main(){
    int n; cin >> n;
    int a[n+10], b[n+10], c[n+10];
    for (int i=0; i<n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    long long dp[101000][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for (int i=1; i<n; i++){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2])+a[i];
        dp[i][1] = max(dp[i-1][2], dp[i-1][0])+b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1])+c[i];
    }

    cout << max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]) << endl;

    return 0;
}

Measured memory_bytes: 3712
S = str(input())
S = S[:-1]
 
hantei = False
while hantei == False:
    if len(S) % 2 == 1:
        S = S[:-1]
    else:
        half = int(len(S)/2)
        last = int(len(S))
        if S[0:half] == S[half:last]:
            print(last)
            hantei = True
        else:
            S = S[0:-1]


Measured memory_bytes: 3060
#include <stdio.h>

int main()
{
    int n, m, A[100][100], B[100], C[100];
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            scanf("%d", &A[i][j]);
        }
    }
    for (int i = 0; i < m; i++)
    {
        scanf("%d", &B[i]);
    }
    for (int i = 0; i < n; i++)
    {
        C[i] = 0;
        for (int j = 0; j < m; j++)
        {
            C[i] = C[i] + A[i][j] * B[j];
        }
    }
    for (int i = 0; i < n; i++)
    {
        printf("%d\n", C[i]);
    }

    return 0;
}


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

int main(){
  string a;
  cin>>a;
  if(a=="A"){
  cout<<"T";
  }
  else if(a=="C"){
  cout<<"G";
  }
  else if(a=="G"){
  cout<<"C";
  }
  else if(a=="T"){
  cout<<"A";
  }
  

}

Measured memory_bytes: 256
string = input()
k = int(input())
if len(string) > k:
    substrs = set()
    ls = sorted(list(string))
    for i in range(k):
        for s, c in enumerate(string):
            if c == ls[i]:
                for l in range(1, k+1):
                    substrs.add(string[s:s+l])
    substrs = list(substrs)
    substrs.sort()
    print(substrs[k-1])

else:
    substrs = set()
    for leng in range(1, len(string) + 1):
        for s in range(0, len(string) - leng + 1):
            substrs.add(string[s:s+leng])
    substrs = list(substrs)
    substrs.sort()
    print(substrs[k-1])


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+5;
int f[N];
int n;
int getf(int x)
{
    return f[x]==x?x:f[x]=getf(f[x]);
}
void merge(int x,int y)
{
    int fx=getf(x);
    int fy=getf(y);
    if(fx!=fy)
    {
        f[fy]=fx;
        return ;
    }
}
void init()
{
    for(int i=1;i<=n;i++)
        f[i]=i;
}
set<int>s;
int main()
{
    int m;
    int x,y;
    scanf("%d%d",&n,&m);
    init();
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&x,&y);
        merge(x,y);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        s.insert(getf(i));
    }
    printf("%d",s.size()-1);
}


Measured memory_bytes: 8152
import bisect

N,K = map(int,input().split())
N = [int(n) for n in str(N)]
D = set(map(int,input().split()))
nums = []
for i in range(10):
  if i not in D:nums.append(i)
nums.sort()

i = len(N)-1
while i>=0:
  if N[i] not in nums:
    if nums[-1] < N[i]:
      prv_len = len(N)
      tmp_N = [int(s) for s in str(int(''.join([str(n) for n in N[:i]])) + 1)] if len(N[:i])>0 else [1]
      N = tmp_N + [nums[0] for _ in range(prv_len-i)]
      if len(N) > prv_len: i += 1
    else:
      j = bisect.bisect(nums,N[i])
      N[i:] = [nums[j]] + [nums[0] for _ in range(len(N)-i-1)]
  #print(i,N)
  i -= 1
print(''.join([str(n) for n in N]))
#print(N)

Measured memory_bytes: 38256
#include <algorithm>
#include <iostream>
#include <utility>
#include <unordered_map>
#include <vector>

using namespace std;

constexpr static int MAXN = 2e5;

int n;
vector <int> adj[MAXN];
bool vis[MAXN];
unordered_map <int, int> parity[MAXN];
// 1 = even
// 2 = odd

int calc(int u, int v) {
    if (parity[u].count(v))
        return parity[u][v];
    if (adj[v].size() == 1)
        return parity[u][v] = 1;

    int cnt1 = 0, cnt2 = 0;
    for (int w : adj[v]) {
        if (w == u)
            continue;
        int p = calc(v, w);
        if (p == 1)
            cnt1++;
        if (p == 2)
            cnt2++;
    }
    if (cnt1 >= 2) {
        cout << "First" << endl;
        exit(0);
    }
    if (cnt1 == 0)
        return parity[u][v] = 1;
    return parity[u][v] = 2;
}

int main() {
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i = 0; i < n; i++) {
        int cnt1 = 0, cnt2 = 0;
        for (int j : adj[i]) {
            int p = calc(i, j);
            if (p == 1)
                cnt1++;
            if (p == 2)
                cnt2++;
        }
        bool check = false;
        check |= (cnt1 >= 2);
        check |= (cnt2 == adj[i].size());
        if (check) {
            //cout << "CHOSE: " << i+1 << " " << adj[i].size() << endl;
            cout << "First" << endl;
            return 0;
        }
    }
    cout << "Second" << endl;
}


Measured memory_bytes: 29824
x, y = input().split()
if x == y:
  print('=')
elif x == 'A':
  print('<')
elif x == 'B':
  if y == 'A':
    print('>')
  else:
    print('<')
elif x == 'C':
  if y == 'A' or y == 'B':
    print('>')
  else:
    print('<')
elif x == 'D':
  if y == 'E' or y == 'F':
    print('<')
  else:
    print('>')
elif x == 'E':
  if y == 'F':
    print('<')
  else:
    print('>')
else:
  print('>')

Measured memory_bytes: 3064
#include <iostream>
#include <ctime>
#include <fstream>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <utility>
#include <cctype>
#include <list>
#include <bitset>
#include <unordered_set>

using namespace std;

#define FORALL(i,a,b) for(int i=(a);i<=(b);++i)
#define FOR(i,n) for(int i=0;i<(n);++i)
#define FORB(i,a,b) for(int i=(a);i>=(b);--i)

typedef long long ll;
typedef long double ld;
typedef complex<ld> vec;

typedef pair<ll,int> plli;
typedef pair<ll,int> pii;
typedef map<int,int> mii;

#define pb push_back
#define mp make_pair

#define MAXN 100005

ll X[MAXN];
ll V[MAXN];
ll right_bal[MAXN];
ll left_bal[MAXN];


int main() {
  int N; ll C;
  cin >> N >> C;
  FOR(i,N) cin >> X[i] >> V[i];

  ll ans = 0;
  priority_queue<pii> right_heap;
  priority_queue<pii> left_heap;

  // go in order
  ll v = 0;
  FOR(i,N) {
    ll x = X[i];
    v += V[i];
    right_bal[i] = v - x;
    ans = max(ans, right_bal[i]);
    right_heap.push(mp(right_bal[i],i));
  }

  // go backwards
  v = 0;
  FORB(i,N-1,0) {
    ll x = (C - X[i])%C;
    v += V[i];
    left_bal[i] = v - x;
    ans = max(ans, left_bal[i]);
    left_heap.push(mp(left_bal[i],i));
  }

  // go back then forward
  v = 0;
  FORB(i,N-1,0) {
    ll x = (C - X[i])%C;
    v += V[i];

    while(!right_heap.empty() && right_heap.top().second >= i) right_heap.pop();
    if (right_heap.empty()) break;
    ans = max(ans, right_heap.top().first + v - 2*x);
  }

  // go forward then back
  v = 0;
  FOR(i,N) {
    ll x = X[i];
    v += V[i];

    while(!left_heap.empty() && left_heap.top().second <= i) left_heap.pop();
    if (left_heap.empty()) break;
    ans = max(ans, left_heap.top().first + v - 2*x);
  }

  cout << ans << endl;
}














Measured memory_bytes: 7792
#include <stdio.h>

int main(void)
{
	int i, j;
	int height, width;

	while((height != 0) || (width != 0)){
		scanf("%d %d", &height, &width);
		if((height > 0) && (width > 0)){
			for(i = 0; i < height; i++){
				for(j = 0; j < width; j++){
					printf("#");
				}
				printf("\n");
			}
			printf("\n");
		}
	}

	return 0;
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int n=5;
    VI a(n);
    REP(i,n){
        cin>>a[i];
    }
    int k;cin>>k;

    if(a[n-1]-a[0] > k){
        cout<<":("<<endl;
    }
    else{
        cout<<"Yay!"<<endl;
    }
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

int main() {
    string T;
    cin >> T;

    for (int i = 0; i < T.length(); i++)
    {
        if (i == 0)
        {
            if (T[i] == '?')
            {
                if (T[i + 1] == 'D')
                {
                    T[i] = 'P';
                } else
                {
                    T[i] = 'D';
                }   
            }
            continue;
        }
        if (T[i] == '?')
        {
            T[i] = 'D';
            
        }
        
    }
    cout << T << endl;
  return 0;
}


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

using namespace std;

int N, dp[300009][20];
char sir[300009];
const int mod = 1e9 + 7;

int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int subtract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}
void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}

int nr, code[5][5][5], valK[20], valP[20], valQ[20], nxt[20][2], isFin[20];
void buildAutomaton ()
{
    for (int k=0; k<=2; k++)
        for (int p=0; p<=2; p++)
            for (int q=0; q<=1; q++)
                if (p >= q)
                    code[k][p][q] = ++nr, valK[nr] = k, valP[nr] = p, valQ[nr] = q;
    for (int k=0; k<=2; k++)
        for (int p=0; p<=2; p++)
            for (int q=0; q<=1; q++)
                for (int bit=0; bit<2; bit++)
                {
                    int nk = k, np = p, nq = q;
                    if (bit == 0)
                    {
                        if (q == 1) nq --;
                        else
                        {
                            np ++;
                            if (np == 3) np = 1;
                        }
                    }
                    else
                    {
                        if (p == 0)
                        {
                            nk ++;
                            if (nk > 2) nk = 2;
                        }
                        else
                        {
                            if (q == 0) nq = 1;
                            else
                            {
                                np --;
                                if (np == 0)
                                {
                                    nq = 0, nk ++;
                                    if (nk > 2) nk = 2;
                                }
                            }
                        }
                    }
                    nxt[code[k][p][q]][bit] = code[nk][np][nq];
                }
    for (int k=0; k<=2; k++)
        for (int p=0; p<=2; p++)
            for (int q=0; q<=1; q++)
            {
                bool outcome = 0;
                if (p == 0) outcome = 1;
                else
                if (p == 1 && (k + q) > 0) outcome = 1;
                else
                if (p == 2 && (k + q) >= 2) outcome = 1;
                isFin[code[k][p][q]] = outcome;
            }
}

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

scanf ("%s", sir + 1), N = strlen (sir + 1);
buildAutomaton ();
dp[0][1] = 1;
for (int i=0; i<N; i++)
    for (int bit=0; bit<2; bit++)
    {
        if (sir[i + 1] != '?' && sir[i + 1] - '0' != bit) continue;
        for (int j=1; j<=nr; j++)
            adto (dp[i + 1][nxt[j][bit]], dp[i][j]);
    }
int ans = 0;
for (int i=1; i<=nr; i++)
    if (isFin[i])
        adto (ans, dp[N][i]);
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 23936
io = STDIN
n=io.gets.chomp.to_i
ab=[]
n.times do |i|
  ab<<io.gets.chomp.split.map(&:to_i)
end
def calc(x,y)
  return 0 if x%y==0
  z=(x.to_f/y).ceil
  y*z-x
end
ans=0
ab.size.times do |no|
  a,b=ab[-1*no-1]
  ans+=calc(a+ans,b)
end
p ans

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

int main() {
  int n,ans = 0;
  vector<int> a;
  a = vector<int>(100010,0);
  cin >> n;
  for (int i = 0;i < n;++i) cin >> a[i+1];
  for (int i = 0;i < n;++i) {
    if (i+1 == a[a[i+1]]) ans++;
  }
  cout << ans/2 << endl;
  return 0;
}

Measured memory_bytes: 640
<?php
while(true) {
	$numData = trim(fgets(STDIN));
	if ($numData == 0) {
		break;
	}

	$data = array();
	for ($i = 0; $i < $numData; $i++) {
		$line = trim(fgets(STDIN));
		list($ind, $unit, $quantity) = explode(' ', $line);
		if (isset($data[$ind])) {
			$data[$ind] += $unit * $quantity;
		} else {
			$data[$ind] = $unit * $quantity;
		}
	}
	$found = false;
	foreach ($data as $ind => $total) {
		if ($total >= 1000000) {
			echo "$ind\n";
			$found = true;
		}
	}
	if (!$found) {
		echo "NA\n";
	}
}

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

int main() {
  int R;
  cin >> R;
  cout << fixed << setprecision(10) << 2*3.14159265358979*R << endl;
}

//cout << fixed << setprecision(10) << (long double)2*sum/(long double)N << endl;


Measured memory_bytes: 3788
#include<stdio.h>
#include<math.h>
int main()
{
	long long int sum,a=0,b=0;
	scanf("%lld",&sum);
	for(long long int i=sqrt(sum);i>1;i--)
	{
		if(sum%i==0){
			a=i;b=sum/a;break;
		}
	} 
	if(a==0)
	{printf("%lld",sum-1);return 0;
	}
	printf("%lld",a+b-2);
	return 0;
 } 

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

long long gcd(long long a,long long b){
	long long tmp;
	if(a > b){
		while(b != 0){
			tmp = b;
			b = a%b;
			a = tmp;
		}
		return a;
	}else{
		while(a != 0){
			tmp = a;
			a = b%a;
			b = tmp;
		}
		return b;
	}
}

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

int main(){
    long long a, b, c, d, cnt=0;
    cin >> a >> b >> c >> d;
    long long x = lcm(c,d);
    long long ans = (b-a+1) - ( (b/c - (a-1)/c) + ((b/d) - (a-1)/d) - (b/x-(a-1)/x) );
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1e9+7;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define fs first
#define sc second


const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T>
T ngcd(vector<T> a){
    T res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
 
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template<typename T>
T nlcm(vector<T> numbers) {
    T res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}

// 割り算の切り上げ処理
template<typename T>
T round_up(T a, T b) {
  return (a + b - 1) / b;
}

// 約数列挙
template<typename T>
vector<T> calc_divisor(T n) {
   vector<T> res;
   for (T i = 1LL; i*i <= n; ++i) {
       if (n % i == 0) {
           res.push_back(i);
           T j = n / i;
           if (j != i) res.push_back(j);
       }
   }
   sort(res.begin(), res.end());
   return res;
}

// 素数判定
template<typename T>
bool isPrime(T x){
    T i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;

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




int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int a,b;
    cin >> a >> b;
    int check[] = {1, 2, 3};
    rep(i, 3) if(check[i] != a && check[i] != b) print(check[i]);
}


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

int main() {
    int n;
    std::string s = "";
    std::string abc_str = "ABC";
    cin>>n;
    int n1 = 0;
    int n2 = 0;
    for ( int i=0; i<n; i++ ) {
        std::cin>>s;
    }
    for ( int i=0; i<n; i++ ) {
        //cout<<n1<<endl;
        if ( s[i] == abc_str[0] ) {
            n1 = 1;
        }
        else if ( n1 >= 1 & s[i] == abc_str[n1] ) {
            //cout<<s[i]<<endl;
            if ( n1==2 ) {
                n1 = 0;
                n2++;
            }
            else {
                n1++;
            }
        }
        else {
            n1 = 0;
        }
        //cout<<n1<<endl;
    }

    cout<<n2<<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;

int main()
{
    string s;
    cin >> s;
    
    bool flag = false;
    for (int i = 0; i < s.length(); i+=2)
    {
      if ('h' != s[i] || 'i' != s[i + 1])
      {
        flag = true;
      }
    } 

    if (flag)
    {
      printf("No");
    }
    else
    {
      printf("Yes");
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define Max 2000000
#define INFTY 1
int heap ;
int A[Max+1];
void MaxHeapify(int);
void swap(int *,int *);
int extract();
void increaseKey(int ,int);
void insert(int);
int main(){
  int key;
  char com[10];
  while(1){
    scanf("%s",com);
    if(strcmp(com,"end")==0)break;
    if(strcmp(com,"insert")==0){
      scanf("%d",&key);
      insert(key);
    }
    else{
      printf("%d\n",extract());
    }
  }
  return 0;
}

void MaxHeapify(int x){
  int left,right,maximum;
  left=2*x;
  right=2*x+1;
  if(left<=heap&&A[left]>A[x])maximum=left;
  else maximum=x;
  if(right<=heap&&A[right]>A[maximum])maximum=right;

  if(maximum !=x){
    swap(&A[x],&A[maximum]);
    MaxHeapify(maximum);
  }
}

void swap(int *a,int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}
int extract(){
  int maxv;
  if(heap<1)return -INFTY;
  maxv=A[1];
  A[1]=A[heap--];
  MaxHeapify(1);
  return maxv;
}
void increaseKey(int i,int key){
  int half;
  if(key<A[i])return ;
  A[i]=key;
  while(i>1&& A[i/2]<A[i]){
    swap(&A[i],&A[i/2]);
    i=i/2;
  }
}
void insert(int key){
  heap++;
  A[heap]=-INFTY;
  increaseKey(heap,key);
}

Measured memory_bytes: 4700
#include<bits/stdc++.h>
using namespace std;
const int maxs = 1e5 + 5;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n,i;
    cin >> n;
    int dp[n];
    memset(dp,0,sizeof dp);
    int a[n];
    for(i = 0;i < n;++i)
        cin >> a[i];
     dp[0] = 0;
     dp[1] = abs(a[0] - a[1]);
    
     for(i = 2;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 - 1];
    
}

Measured memory_bytes: 4392
#include <stdio.h>
#include <stdlib.h>
#define MAX 10000

void countingsort(int A[],int B[],int k,int n)
{
  int C[MAX+1],i,j;

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

}


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

  scanf("%d",&n);

  A=malloc(sizeof(int)*n+1);
  B=malloc(sizeof(int)*n+1);

  for(i=0;i<n;i++){
    scanf("%d",&A[i+1]);
  }
  countingsort(A,B,MAX,n);

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


  return 0;
}



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

typedef long long ll;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

int main(){
    ll A,B,x,r;
    cin >> A >> B;
    r = A % B;
    x = A*B;
    while(r!=0){
        A = B;
        B = r;
        r = A % B;
    }
    cout << x/B << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    //cin.tie(0);
    set<int> p;
    int n,m,ans=0;
    double sum=0;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        p.insert(a[i]);
    }
    sum = sum/(4*m);
    for(auto x:p)
    {
        if(x>=sum)
            ans++;
        if(ans == m)
            break;
    }
    if(ans==m)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define fi first
#define se second 

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

constexpr int ms = 4e3 + 13;

long long fat[ms], inv_fat[ms];

// End of template code!
int main() 
{
    buff(); 
    
    fat[0] = 1ll, inv_fat[0] = 1ll;
    for(long long i = 1; i < ms; ++i) 
    {
        fat[i] = (fat[i - 1] * i) % MOD;
        inv_fat[i] = pow_mod(fat[i], MOD - 2); 
    }

    int n, k;
    cin >> n >> k;
    vector<long long> ans(k + 1, 0);
    
    const int blue = k;
    const int red = (n - k);
    
    auto n_choose_k = [&] (int n, int k) 
    {
        long long res = fat[n];
        long long div = (fat[k] * fat[n - k]) % MOD;
        div = pow_mod(div, MOD - 2);
        long long ans = (res * div) % MOD;
        return ans;
    };

    auto sum_n_k_terms = [&] (int n, int k) 
    {
        return n_choose_k( (n + k - 1), (k - 1) );
    };

    for(int i = 1; i <= k; ++i) 
    {
        int fixed_red_groups = i - 1;
        int total_red_groups = fixed_red_groups + 2; // adding borders
        int free_red_balls = red - fixed_red_groups;
        int free_blue_balls = blue - i;
        if(free_red_balls < 0 || free_blue_balls < 0) ans[i] = 0;
        else 
        {
            // resolvendo a distribuicao de bolas vermelhas
            long long red_part = sum_n_k_terms(free_red_balls, total_red_groups);
            long long blue_part = sum_n_k_terms(free_blue_balls, i);
            ans[i] = (red_part * blue_part) % MOD;
        }
        cout << ans[i] << '\n';
    }


    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#define PB push_back
#define LI long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
using namespace std;
LI f(LI b,LI n){
    LI ans=0,n2=n;
    while(n2>0){
        ans+=n2%b;
        n2/=b;
    }
    return ans;
}

int main(void){
    LI n,s; cin>>n>>s;
    LI ans;
    bool fl=false;
    vector<LI> v;
    if(n==s){
        cout<<n+1<<endl;
        exit(0);
    }
    for(LI i=2;(i-1)*(i-1)<=n-s;i++){
        if((n-s)%(i-1)==0){
            v.PB(i);
            if((n-s)/(i-1)!=i-1) v.PB((n-s)/(i-1)+1);
        }
    }
    sort(v.begin(),v.end());
    for(auto i:v){
        if(f(i,n)==s){
            ans=i;
            fl=true;
            break;
        }
    }
    cout<<(fl?ans:-1)<<endl;
}


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

#define ll long long

using namespace std;

int main(){
    string s; int k; 
    cin>>s>>k; int c=0;
    int n = s.length();
    while(c<n && k>0){
	int df = 1+'z'-s[c];
//	cout<<df<<" "<<k;
	if(df<=k && df!=26){
	    s[c] = 'a'; k-=df;
	}
	c++;
    }
    if(k>0){
	int df = 1+'z'-s[n-1];
	if(df<=k){
	    s[n-1]='a'; k-=df;
	    s[n-1]+=k%26;
	}else{
	    s[n-1]+=k;
	}
    }
    cout<<s;

}

Measured memory_bytes: 512
bank = [1]
N = int(input())
for i in range(20):
    if 100000 >= 6**i:
        bank.append(6**i)
    if 100000 >= 9**i:
        bank.append(9**i)
# print(bank)
dp = [[10**10]*(N+1) for _ in range(len(bank)+1)]

dp[0][0] = 0
# i番目の引き出し方法を使う
for i in range(len(bank)):
    for j in range(N+1):
        # 使わない場合
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        # 使う場合
        if j + bank[i] > N:  # Nを超えるならcontinue
            continue
        dp[i+1][j+bank[i]] = min(dp[i][j]+1, dp[i+1][j]+1)
print(dp[len(bank)][N])


Measured memory_bytes: 52080
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    string s; cin >> s;

    rep(i,0,4) cout << s[i];
    cout << " ";
    rep(i,4,s.length()) cout << s[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <stdlib.h>
 
int main(void){
    int n, i, a, b, c, l0, l1, l2, l3, l4, l5, l6, l7, minmp = 32760, aa, bb, cc, mp;
    scanf("%d %d %d %d", &n, &a, &b, &c);
    int l[8];
    for(i=0; i<8; i++) l[i] = 0;
    for(i=0; i<n; i++) scanf("%d", &l[i]);
    
    for(l0=0; l0<4; l0++){
    for(l1=0; l1<4; l1++){
    for(l2=0; l2<4; l2++){
    for(l3=0; l3<4; l3++){
    for(l4=0; l4<4; l4++){
    for(l5=0; l5<4; l5++){
    for(l6=0; l6<4; l6++){
    for(l7=0; l7<4; l7++){
        mp = 50;
        aa = 0;
        bb = 0;
        cc = 0;
        if(l0 == 0) mp -= 10;
        if(l0 == 1) aa += l[0];
        if(l0 == 2) bb += l[0];
        if(l0 == 3) cc += l[0];
        if(l1 == 0) mp -= 10;
        if(l1 == 1) aa += l[1];
        if(l1 == 2) bb += l[1];
        if(l1 == 3) cc += l[1];
        if(l2 == 0) mp -= 10;
        if(l2 == 1) aa += l[2];
        if(l2 == 2) bb += l[2];
        if(l2 == 3) cc += l[2];
        if(l3 == 0) mp -= 10;
        if(l3 == 1) aa += l[3];
        if(l3 == 2) bb += l[3];
        if(l3 == 3) cc += l[3];
        if(l4 == 0) mp -= 10;
        if(l4 == 1) aa += l[4];
        if(l4 == 2) bb += l[4];
        if(l4 == 3) cc += l[4];
        if(l5 == 0) mp -= 10;
        if(l5 == 1) aa += l[5];
        if(l5 == 2) bb += l[5];
        if(l5 == 3) cc += l[5];
        if(l6 == 0) mp -= 10;
        if(l6 == 1) aa += l[6];
        if(l6 == 2) bb += l[6];
        if(l6 == 3) cc += l[6];
        if(l7== 0) mp -= 10;
        if(l7 == 1) aa += l[7];
        if(l7 == 2) bb += l[7];
        if(l7 == 3) cc += l[7];
 
        if(aa != 0&&bb != 0&&cc != 0){
 
        mp += abs(aa - a) + abs(bb - b) + abs(cc - c);
        if(mp<minmp) minmp = mp;
        }
    
 
    }}}}}}}}
    printf("%d", minmp);
    
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
using namespace std;

bool isACGT(char c)
{
	if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
		return true;
	}
	return false;
}

int main()
{
	string test;
	int size;
	int max, maxh;

	cin >> test;
	size = test.size();
	max = maxh = 0;

	for (int i = 0; i < size; i++) {
		if (isACGT(test[i])) {
			maxh++;
		} else {
			if (max < maxh) {
				max = maxh;
			}
			maxh = 0;
		}
	}

	if (max < maxh) {
		max = maxh;
	}

	printf("%d", max);

	return 0;
}

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

int main(){
  string n;
  cin >> n;
  for(int i=0;i<3;i++){
    if(n[i] == '1'){
      n[i] = '9';
    }else if(n[i] =='9'){
    n[i] = '1';
    }else{
      n = n;
    }
  }
  cout << n;
}


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

using namespace std;

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

    vector<int> b(N + 1, 0);
    vector<int> ans;
    for (int j = N; j >= 1; --j) {
        int sum = 0;
        for (int k = j; k <= N; k += j) {
            sum ^= b[k];
        }
        if (sum != a[j]) {
            b[j] = 1;
            ans.push_back(j);
        }
    }

    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); ++i) {
        if (i > 0) cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}



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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)

ll N,K,A[2222];
ll i, j, ans,ans2;
int main(){
    scanf("%lld%lld", &N,&K);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }
    fornum(i,0,N){
        fornum(j,0,i){
            if(A[j]>A[i]){
                ans++;
                ans2++;
            }
        }
        fornum(j,j+1,N){
            if(A[j]>A[i]){
                ans2++;
            }
        }
    }
    printf("%lld", (ans * K + ans2 * ((K - 1) * K / 2 % MOD)) % MOD);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
#define vpl vector<pair<long long,long long>>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
long long MOD = 1000000007;
const long double pi = 3.1415926535897932;
#define pb push_back
#define mp make_pair
#define mt make_tuple
//(mod m)でのaの逆元を計算する
//a/b(mod m)=a(mod m)*modinv(b,m)
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

//最大最小の入れ替え
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;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll N,M;
    cin>>N>>M;
    vl AC(N,0);
    vl WA(N,0);
    rep(i,M){
        ll a;
        string s;
        cin>>a>>s;
        if(AC[a-1]) continue;
        if(s=="WA"){
            WA[a-1]++;
        }else{
            AC[a-1]++;
        }
    }
    ll ac,wa;
    ac=wa=0;
    rep(i,N){
        if(AC[i]){
            ac++;
            wa+=WA[i];
        }
    }
    cout<<ac<<" "<<wa<<endl;
}

Measured memory_bytes: 1792