akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(2)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <assert.h>

using namespace std;

int id;
int dp[1005][1005];
char a[1005],b[1005];

string B;

int EditDis(string A)
{
/*
	id++;
    int len1 = A.size();
    int len2 = B.size();
    for (int i = 1;i <= len1;i++)
    	a[i] = A[i - 1];
    for (int i = 1;i <= len2;i++)
    	b[i] = B[i - 1];
    for(int i=1;i<=len1;i++)
        for(int j=1;j<=len2;j++)
            dp[i][j] = 1e9;
    for(int i=1;i<=len1;i++)
        dp[i][0] = i;
    for(int j=1;j<=len2;j++)
        dp[0][j] = j;
    for(int i=1;i<=len1;i++)
    {
        for(int j=1;j<=len2;j++)
        {
            int flag;
            if(a[i]==b[j])
                flag=0;
            else
                flag=1;
            dp[i][j]=min(dp[i-1][j]+1,min(dp[i][j-1]+1,dp[i-1][j-1]+flag));
        }
    }
    return dp[len1][len2];
    */
    cout << "? " << A << endl;
    cout.flush();
    int r = 0;
    cin >> r;
    return r;
}

vector<char> ab;

int L;
int mem[100];
int cnt[100];

string solve(int l,int r)
{
	if (l == r)
	{
		string tmp;
		while (cnt[l]--)
			tmp += ab[l];
		return tmp;
	}
	int mid = l + r >> 1;
	string res = solve(l,mid),add = solve(mid + 1,r);
	for (int i = 0;i < res.size() && add.size();i++)
	{
		string tmp = res;
		tmp.insert(tmp.begin() + i,add[0]);
		if (EditDis(tmp) == L - tmp.size())
		{
			res = tmp;
			add.erase(add.begin());
		}
	}
	return res + add;
}

int main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output1.txt","w",stdout);
	for (int i = 'a';i <= 'z';i++)
		ab.push_back(i);
	for (int i = 'A';i <= 'Z';i++)
		ab.push_back(i);
	for (int i = '0';i <= '9';i++)
		ab.push_back(i);
	for (int i = 0;i < ab.size();i++)
	{
		string tmp;
		for (int j = 0;j < 128;j++)
			tmp += ab[i];
		cnt[i] = 128 - EditDis(tmp);
		L += cnt[i];
	}
	string r = solve(0,ab.size() - 1);
	cout << "! " << r << endl;
	cout.flush();
	return 0;
}

Measured memory_bytes: 3796
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){

            int n = Integer.parseInt(sc.next());
            int k = Integer.parseInt(sc.next());

            ArrayList<Integer> list = new ArrayList<>();

            for(int i = 0; i < k; i++){
                int d = Integer.parseInt(sc.next());
                for(int j = 0; j < d; j++){
                    int a = Integer.parseInt(sc.next());
                    if(!list.contains(a)){
                        list.add(a);
                    }
                }
            }

            System.out.println(n - list.size());

        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

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

int bubblesort (int a[], int n){
    int flag = 1;
    int i = 0;
    int count = 0;
    while(flag){
        flag=0;
        for(int j=n-1;j>i;j--){
            if(a[j]<a[j-1]){
                swap(a[j], a[j-1]);
                flag=1;
                count += 1;
            }
        }
        i++;
    }
    return count;
}

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

    int count = bubblesort(a, n);

    for(int i=0;i<n;i++){
        cout << a[i];
        if(i<n-1)cout << " ";
        else cout << endl;
    }

    cout << count << endl;

}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  int n,m;
  cin>>n>>m;
  if(n<m){
	for(int i=0;i<m;i++)
	{
		cout<<n;
	}
  }else{
	for(int i=0;i<n;i++){
		cout<<m;
	}
  }
    return 0;
}

Measured memory_bytes: 256
//Robs Code

/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>

/***********MACROS***************/
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>

using namespace std;

const int N = 1e5 + 1;
int n,m,i,j,k,l,x,y,z,cnt[3],sum[3];

/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin >> n;
	if(n%10 == 2 || n%10 == 4 || n%10 == 5|| n%10 == 7|| n%10 == 9){
		cout << "hon";
	}else if(n%10 == 3){
		cout << "bon";
	}else{
		cout << "pon";
	}
}
//.........

Measured memory_bytes: 3668
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
typedef long long LL;

LL x, y;
int ans = 0;

int main()
{
	cin >> x >> y;
	for(LL i = x; i <= y; i *= 2) ans ++;
	cout << ans << endl;
	return 0;
}

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

int main() {
  ll n=1,k;cin>>k;
  while (k>0) {
    string s = to_string(n);
    bool flg=true;
    rep(i, s.size()-1) {
      if (abs((int)s[i] - (int)s[i+1]) > 1) {
        flg=false;
        n += max(1.0, pow(10, s.size()-i-2) );
        break;
      }
    }
    if (flg) {
      k--;
      n++;
    }
  }
  cout << n-1;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long 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 vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

int main(){
    int n;
    cin>>n;
    int imos[1000001];
    rep(i,1000001)imos[i]=0;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        imos[a]++;
        imos[b+1]--;
    }
    
    rep(i,1000000) imos[i+1] += imos[i];

    int ans = 0;
    rep(i,1000001)
        if(imos[i]+1>=i)
            ans = max<ll>(ans,i-1);
    
    cout<<ans<<endl;
}

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

int main()
{
	int s; cin >> s;
	vector<int> num(1000000,0);

	int n = s;
	num[n]++;

	int i = 1;
	while (true) {
		i++;
		if (n % 2 == 0) {
			n = n / 2;
			num[n]++;
		}
		else {
			n = 3 * n + 1;
			num[n]++;
		}		
		if (num[n] == 2) break;
	}	
	cout << i << endl;
	return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  bool OK = true;
  
  for(int i = 0; i < s.size(); i++) {
    if (s.at(i) != t.at(i)) OK = false;
  }
  
  if(OK) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n; cin >>n;
  vector<long long>a(n),b(n);
  long long kotae=0;
  for(long long i=0;i<n;i++){
    cin>>a[i];
    kotae^=a[i];
  }
  //sort(a.begin(),a.end());
  for(long long i=0;i<n;i++){
    b[i]=kotae^a[i];
  }
  for(long long i=0;i<n;i++){
    if(i!=n-1)cout<<b[i]<<" ";
    else cout<<b[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 6336
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
vector<int> V[100010];
void dfs(int x, int dist, vector<int> &v){
    if(v[x])return;
    v[x] = dist;
    for(auto next:V[x]){
        dfs(next, dist+1, v);
    }
}
main(){
    int N;
    cin >> N;
    rep(i,0,N-1){
        int a,b;
        cin >> a >> b;
        a--,b--;
        V[a].push_back(b);
        V[b].push_back(a);
    }
    vector<int> distA(N), distB(N);
    dfs(0, 1, distA);
    dfs(N-1, 1, distB);
    //for(auto i:distA)cout << i << " ";cout << endl;
    //for(auto i:distB)cout << i << " ";cout << endl;
    int cnt = 0;
    rep(i,0,N){
        cnt += (distA[i] <= distB[i] ? 1 : -1);
    }
    //cout << cnt << endl;
    if(cnt > 0)cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}

Measured memory_bytes: 11136
X,N= map(int, input().split())



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

if N==0:
    print(int(X))    

else:
    for i in range(0,101):
        if l.count(int(X))<1:
            print(int(X))
            break 


        elif l.count(int(X-i))<1:
            print(int(X-i))
            break 

    

        if X+i<=101:
            if l.count(int(X+i))<1:
                print(int(X+i))
                break 

Measured memory_bytes: 9204
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n;cin>>n;
	double a[n];
	ll p=1;
	For(i,0,n) {
		cin>>a[i];
		p = p*a[i];
	}
	double sum = 0;
	For(i,0,n){
		sum += (p/a[i]);
	}
	cout<<setprecision(6)<<fixed;
	cout<<(p/sum)<<endl;






























	
}

Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    int n,m,tmp;
    scanf("%d %d",&n,&m);
    int** A = new int*[n];
    for(int i = 0; i < n; i++) A[i] = new int[m];
    int b[m];
 
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            scanf("%d",&tmp);
            A[i][j] = tmp;
        }
    }
    for(int i = 0; i < m; i++){
        scanf("%d",&tmp);
        b[i] = tmp;
    }
    long long int sum;
    for(int i = 0; i < n; i++){
        sum = 0;
        for(int j = 0; j < m; j++){
            sum += A[i][j] * b[j];
        }
        printf("%lld\n",sum);
    }
 
    for(int i = 0; i < n; i++){
        delete[] A[i];
    }
    delete A;
}


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

int main(){
    int n, m, i, j, v;
    signed int h, l;
    char name[1600],c;

    l = 'a' - 'A';
    h = 'A' - 'a';
    scanf("%[^\n]", name);

    for(i=0;name[i] !='\0' ;i++) {
        if(name[i] >='a' && name[i] <='z'){
            name[i] += h;
        }
        else if(name[i] >='A' && name[i] <='Z'){
            name[i] += l;
        }
    }
    printf("%s\n", name);
    return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;
const int max_n= 10000;
int n,a=0,b,W,L,kk,m,V,e,r,ML, MD, E, v, H;
const int INF = 1e9+1;
const int mod = 1e9 + 7;
bool used[max_n][max_n];
string s1,s2;
int x[max_n],y[max_n],table[max_n][max_n],d[max_n][max_n],ppar[max_n],rrank[max_n],spf[max_n],c[max_n][max_n];
typedef pair<long , long> pii;
vector<long long> G[max_n];
vector<int> ls;
struct edge{
    int from,to,cost;
};
bool comp(const edge& e1, const edge& e2){
    return e1.cost < e2.cost;   
}
edge es[max_n];
typedef pair<int, int> P;
struct Cmp{
    bool operator()(const pii &a,const pii &b){
        return a.second > b.second;
    }
};
void warshall_floyd(){
    for(int k=0 ; k<10 ; k++){
        for(int i=0 ; i<10 ; i++){
            for(int j=0 ; j<10 ; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}
void solve(){
    long long count = 0;
    warshall_floyd();
    for(int i=0 ; i<H ; i++){
        long long mi = 0;
        for(int j=0 ; j<W ; j++){
            if(table[i][j] != -1){
                count += d[table[i][j]][1];
             }
        }
    }
    cout << count << endl;
}
int main(){
    cin >> H >> W;
    for(int i=0 ; i<10 ; i++){
        for(int j=0 ; j<10 ; j++){
           int xx;
           cin >> xx;
           d[i][j] = xx;
        }
    }
    for(int i=0 ; i<H ; i++){
        for(int j=0 ; j<W ; j++){
            cin >> table[i][j];
        }
    }
    solve();
    return 0;
}

Measured memory_bytes: 16896
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, m;
vector<int> a;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    if(n<1000)cout<<"ABC"<<"\n";
  else cout<<"ABD"<<"\n";
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        String str = "";
        if(a<b && b<c){
            str = "Yes";
        }else{
            str="No";
        }

        System.out.println(str);
    }

}


Measured memory_bytes: 26368
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
using ll=long long;
using namespace std;
//const int INF = 7+(1e+9);
ll GCD(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return GCD(y, x % y);
    }
}
ll LCM(ll x, ll y)
{
    return x / GCD(x, y) * y;
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
vector<vector<char>> vec(12,vector<char>(12));

int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};
int dfs(int y,int x){
    vec[y][x]='5';
    for(int i=0;i<4;i++){
        if(x+dx[i]<12&&x+dx[i]>=0&&y+dy[i]<12&&y+dy[i]>=0&&vec[dy[i]+y][dx[i]+x]=='1'){
            dfs(y+dy[i],x+dx[i]);
        }
    }
    return 0;
}

int main(){
    int n;cin>>n;
    vector<vector<int>> vec(n,vector<int>(2));
    vector<vector<int>> vec1(n,vector<int>(2));
    for(int i=0;i<n;i++){
        int x,y;cin>>x>>y;
        vec[i][0]=x;
        vec1[i][0]=y;
        vec[i][1]=i;
        vec1[i][1]=i;
    }
    sort(vec.begin(),vec.end());
    sort(vec1.begin(),vec1.end());
    for(int i=0;i<n;i++){
  //      cout<<vec[i][0]<<" "<<vec1[i][0]<<endl;
    }
    vector<vector<int>> dis(n*2,vector<int>(3));
    for(int i=0;i<n-1;i++){
        dis[i][0]=abs(vec[i][0]-vec[i+1][0]);
        dis[i][1]=vec[i][1];
        dis[i][2]=vec[i+1][1];
    }
    for(int i=0;i<n-1;i++){
        dis[i+n][0]=abs(vec1[i][0]-vec1[i+1][0]);
      //  cout<<dis[i+n][0]<<endl;
        dis[i+n][1]=vec1[i][1];
        dis[i+n][2]=vec1[i+1][1];
    }
    sort(dis.begin(),dis.end());
    for(int i=0;i<2*n;i++){
 //       cout<<dis[i][]
    }
    UnionFind tree(n);
    ll sum=0;
    for(int i=0;i<2*n;i++){
        if(!tree.same(dis[i][1],dis[i][2])){
            tree.unite(dis[i][1],dis[i][2]);
            sum += dis[i][0];
         //   cout<<dis[i][0]<<" "<<dis[i][1]<<" "<<dis[i][2]<<endl;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 23040
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ADiagonalString solver = new ADiagonalString();
        solver.solve(1, in, out);
        out.close();
    }

    static class ADiagonalString {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            char[][] c = new char[3][3];
            for (int i = 0; i < 3; i++) {
                c[i] = in.next().toCharArray();
            }
            out.printf("%c%c%c", c[0][0], c[1][1], c[2][2]);
        }

    }
}



Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 10000
using namespace std;

int main(){
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3, y3, x4, y4;
  x3 = y1-y2 + x2;
  y3 = -(x1-x2) + y2;
  x4 = -(y2-y1) + x1;
  y4 = x2-x1 + y1;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
  return 0;
}


Measured memory_bytes: 256
use std::cmp::*;
use std::io::*;

mod convolution {
    use std::f64::consts::PI;
    use std::ops::{Add, Mul};
    #[derive(Clone, Copy, Debug)]
    struct Complex {
        x: f64,
        y: f64,
    }
    impl Add for Complex {
        type Output = Complex;
        fn add(self, other: Complex) -> Complex {
            Complex {
                x: self.x + other.x,
                y: self.y + other.y,
            }
        }
    }
    impl Mul for Complex {
        type Output = Complex;
        fn mul(self, other: Complex) -> Complex {
            Complex {
                x: self.x * other.x - self.y * other.y,
                y: self.x * other.y + self.y * other.x,
            }
        }
    }
    fn fft(f: &mut [Complex], n: usize, sign: f64) {
        if n == 1 {
            return;
        }
        let mut group1 = Vec::new();
        let mut group2 = Vec::new();
        for i in 0..n / 2 {
            group1.push(f[i * 2]);
            group2.push(f[i * 2 + 1])
        }
        fft(&mut group1, n / 2, sign);
        fft(&mut group2, n / 2, sign);
        let zeta = Complex {
            x: (2.0 * PI / n as f64).cos(),
            y: (2.0 * PI / n as f64).sin() * sign,
        };
        let mut now = Complex { x: 1.0, y: 0.0 };
        for i in 0..n {
            f[i] = group1[i % (n / 2)] + now * group2[i % (n / 2)];
            now = now * zeta;
        }
    }
    pub fn convolve(a: &[usize], b: &[usize]) -> Vec<usize> {
        let n = (a.len() + b.len() - 1).next_power_of_two();
        let mut f = vec![Complex { x: 0.0, y: 0.0 }; n];
        let mut g = vec![Complex { x: 0.0, y: 0.0 }; n];
        for i in 0..a.len() {
            f[i] = Complex {
                x: a[i] as f64,
                y: 0.0,
            };
            g[i] = Complex {
                x: b[i] as f64,
                y: 0.0,
            };
        }
        fft(&mut f, n, 1.0);
        fft(&mut g, n, 1.0);
        for i in 0..n {
            f[i] = f[i] * g[i];
        }
        fft(&mut f, n, -1.0);
        f.iter()
            .map(|e| (e.x / n as f64).round() as usize)
            .collect()
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut m: usize = itr.next().unwrap().parse().unwrap();
    let o: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let mut a = vec![0; 100001];
    for i in 0..n {
        a[o[i]] += 1;
    }
    let b = a.clone();
    let c = convolution::convolve(&a, &b);

	// shukei
    let mut ans = 0;
    for i in (0..200001).rev() {
        if m == 0 {
            break;
        }
        ans += min(m, c[i]) * i;
        m -= min(m, c[i]);
    }
    println!("{}", ans);
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

string vow = "aeiou";

void solve ( int test_case )
{
    string s ; cin >> s ;

    deque < char > q ;
    for ( auto i : s )
    {
        if ( i == 'B' )
        {
            if ( q.empty() ) C ;
            q.pop_back() ;
            C ;
        }

        q.pb ( i ) ;

    }

    while ( !q.empty() )
    {
        cout << q.front() ;
        q.pop_front() ;
    }
}

int main()
{
    int t = 1;
    //cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N,M,A[1000007];
vector<int> l;
int main(void){
    // Your code here!
    cin >> N >> M;
    long long int allsum=0,count=0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        allsum += A[i];
        int k = A[i];
        while(k>0){
            l.push_back(k-k/2);
            count++;
            k = k/2;
        }
    }
    
    sort(l.begin(), l.end(), greater<int>());
    long long int sum=0;
    for(int i=0; i<M&&i<count; i++){
        sum += l[i];
    }
    cout << allsum-sum << "\n";
}

Measured memory_bytes: 18920
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    if (x >= a && x <= a + b) cout << "YES" << endl;
    else cout << "NO" << endl;
}





Measured memory_bytes: 256
N = gets.to_i
D = N.times.map{gets.split.map(&:to_i)}

count = 0
(N-2).times do |i|
  if D[i][0] == D[i][1]
    if D[i+1][0] == D[i+1][1]
      if D[i+2][0] == D[i+2][1]
    	count += 1
      end
    end
  end
end

if count > 0
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 14320
import sys

MAX_VALUE = 10 ** 5 + 100

def input():
    return sys.stdin.readline().strip()

def main():
    N,W = map(int,input().split())
    goods = [list(map(int,input().split())) for _ in range(N)]
    
    dp = [[float('inf') for _ in range(MAX_VALUE+1)] for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for v in range(MAX_VALUE):
            if v >= goods[i][1]:
                dp[i+1][v] = min(dp[i][v-goods[i][1]]+goods[i][0],dp[i][v])
            else:
                dp[i+1][v] = dp[i][v]
    for v in range(MAX_VALUE):
        if dp[N][v] <= W:
            ans = v
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 315928
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/10
 
using namespace std;
int MOD = 1000000007;

signed main(){
    int a,b,q;
    cin >> a >> b >> q;
    
    vector<int> s(a);
    vector<int> t(b);
    rep(i,a)cin >> s[i];
    rep(i,b)cin >> t[i];

    rep(i,q){
        int x;
        cin >> x;
        int ans = 0;
        auto itr1 = lower_bound(s.begin(),s.end(),x);
        auto itr2 = lower_bound(t.begin(),t.end(),x);
        int v1,v2;
        if(itr1 == s.end()) v1 = INF;
        else v1 = *itr1 - x;
        if(itr2 == t.end()) v2 = INF;
        else v2 = *itr2 - x;
        int v3,v4;
        ans = max(v1,v2);
        if(itr1 != s.begin()){
            itr1--;
            v3 = x - *itr1;
        }else{
            v3 = INF;
        }
        if(itr2 != t.begin()){
            itr2--;
            v4 = x - *itr2;
        }else{
            v4 = INF;
        }
        cerr << v1 << " " << v2 << " " << v3 << " " << v4 << endl;
        ans = min(ans,max(v3,v4));
        ans = min(ans,2*min(v1,v4)+max(v1,v4));
        ans = min(ans,2*min(v2,v3)+max(v2,v3));

        
        cout << ans << endl;
    }

    
    
    return 0;   
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://abc119.contest.atcoder.jp/tasks/abc119_a
// rm -r -f test;oj dl http://yahoo-procon2017-qual.contest.atcoder.jp/tasks/yahoo_procon2017_qual_c

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

int main() {
  string str;
  cin >> str;
  
  if (str[0] == '7'){
    cout << "Yes" << endl;
  }
  else if (str[1] == '7'){
    cout << "Yes" << endl;
  }
  else if (str[2] == '7'){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;

int main() {
  int n;cin>>n;int f = 0, t = 0, o = 0;
  rep(i,n){
    int aa;cin>>aa;
    if(aa % 4 == 0){
      f++;
    }else if(aa % 2 == 0){
      t++;
    }else{
      o++;
    }
  }
  if(f >= o || (f>=o-1 && t == 0)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;




public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7),n;
	static long cf = 998244353;
    static final int MAX = (int) 1e16;
    public static List<Edge>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fact,inv;
    public  static int[] prime; 
    public static long[] seg,lazy;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		edges = new ArrayList[n];
		for(int i=0;i<n;++i) edges[i] = new ArrayList<>();
		for(int i=1;i<n;++i) {
			int u = sc.nextInt()-1;
			int v = sc.nextInt()-1;
			edges[u].add(new Edge(v,i));
			edges[v].add(new Edge(u,i));
		}
		int m = sc.nextInt();
		long[] white = new long[m];
		long ans = 0;
		for(int i=0;i<m;++i) {
			int u = sc.nextInt()-1;
			int v = sc.nextInt()-1;
			cnt = 0;
			dfs(u,v,-1);
			white[i] = cnt;
		}
		for(int i=0;i<1L<<m;++i) {
			long temp = 0;
			for(int j=0;j<m;++j) {
				if((i&(1L<<j))!=0)
					temp|=white[j];
			}
			long C = Long.bitCount(temp);
			if((Integer.bitCount(i)&1) == 0) ans+=1L<<(n-1-C);
			else ans-=1L<<(n-1-C);
		
		
	}
		out.println(ans);
		out.close();
	}
	static long cnt;
	private static boolean dfs(int u, int v, int p) {
		if(u == v) return true;
		for(Edge e : edges[u]) {
			if(e.to != p) {
				if(dfs(e.to,v,u)) {
					cnt|=1L<<e.id;
					return true;
				}
			}
		}
		return false;
	}
	static class Edge{
		int to;
		int id;
		Edge(int to,int id){
			this.to = to;
			this.id = id;
		}
	}
}

Measured memory_bytes: 21716
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	string a,b,c;
	cin>>a>>b>>c;
	int x=a.size();
	int y=b.size();
	int z=c.size();
	for(int i=0;i<x&&i<y&&i<z;i++){
		if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	return 0;
}
}


Measured memory_bytes: 256
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val A = next()
    println(if (A == A.toUpperCase()) "A" else "a")
}

Measured memory_bytes: 34556
import sys

def solve(S):
    f = int(S[0:2])
    s = int(S[2:4])
    f_flag = False
    if 1 <= f <= 12:
        f_flag = True

    s_flag = False
    if 1 <= s <= 12:
        s_flag = True

    if f_flag and s_flag:
        return 'AMBIGUOUS'
    elif f_flag:
        return 'MMYY'
    elif s_flag:
        return 'YYMM'
    else:
        return 'NA'

if __name__ == '__main__':

    S = sys.stdin.readline().strip()
    print solve(S)

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

int main() 
{
   int A, B;
   cin >> A >> B;

   if (A == 1) A = 14;
   if (B == 1) B = 14;
   if (A > B) cout << "Alice" << endl;
   if (A < B) cout << "Bob" << endl;
   if (A == B) cout << "Draw" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second


struct unifo{
	int un;
	int uni[100005];
	void init(int n){
		rep(i,n)uni[i]=i;
		un=n;
	}
	int find(int p){
		if(uni[p]==p)return p;
		else return (uni[p]=find(uni[p]));
	}
	void mer(int p,int q){
		uni[find(p)]=find(q);
	}
	bool same(int p,int q){
		return find(p)==find(q);
	}
};

	
	
	
int n,m;

//vector<mp> vs[105];





int main(void){
	int n,m;
	scanf("%d%d",&n,&m);
	/*
	rep(i,m){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		vs[a].push_back(mp(b,c));
		//vs[b].push_back(mp(a,c));
	}*/
	unifo u;
	u.init(n);
	rep(i,m){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		if(a==0)u.mer(b,c);
		else{
			if(u.same(b,c))printf("1\n");
			else printf("0\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include<cstdio>
#include<stdlib.h>
/*http://climpet.hatenablog.com/entry/2013/01/01/225142#f5を参考*/
int main(int argc, char *argv[])
{
  int pow3[16],c[16];
  int n,m,i,j,k,d,x,y,p;

  pow3[0] = 1;
  for(i = 1;i <=15;i++){
    pow3[i] = pow3[i-1]*3;/*i枚#0から#2または#2から#0へ移動するのに必要なステップ数*/
}

  while(scanf("%d%d",&n,&m),n){
    for(i = 0;i < 3;++i){
      for(scanf("%d",&j);j > 0;--j){
	scanf("%d",&k);
	c[n-k] = i;/*番号付け替え,ハノイの塔に変換。大きいコップを小さい円盤にする*/
      }
    }
    p = 0;//全ての円盤が0の位置にあると仮定する
    x = 0;
    for(i = n-1;i >= 0;--i){//
      d = abs(p -c[i]);//移動させる円盤の距離を求める。
      /*n = 3の時、i = 2で円盤2を#1に移動させるには円盤1と円盤0を#2に移動させる*/
      x += pow3[i]*d;
      if(d == 1){
	p = 2-p;/*反対側に移動,距離がd = 1ならば0~i-1番の円盤を反対側に移動する。*/
      }
    }
    y = pow3[n] -1 -x;
    if(x > y){
      x = y;
    }
    printf("%d\n",x > m?-1:x);
  }
  return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using  namespace std;

int main(void){
    int n,m,d,e;
    cin>>n>>m>>d>>e;
    vector<int>x(n);
    vector<int>y(m);
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<m;i++){
        cin>>y[i];
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    int l=x[n-1];
    int r=y[0];
    bool ok=false;
    for(int i=l+1;i<=r;i++){
        if(i>d and i<=e){
            ok=true;
            break;
        }
    }
    if(ok){
        cout<<"No War"<<endl;
    }else{
        cout<<"War"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	ll ans = 0;
	int tmp;
	string s, t;
	cin >> s >> t;
	REP(i ,s.size()){
		if(s[i]!= t[i]) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3904
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod=1000000007;
const double PI = 3.14159265359;
#define pb  push_back
#define FOR(i,n) for(int i=0;i<(n);i++)
#define FORA(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define count_1(n)  __builtin_popcountll(n)
#define parity(n)   __builtin_parityll(n)   //Even parity 0 as output
void show    (int a[], int arraysize) { for (int i = 0; i < arraysize; ++i)  {cout << a[i] << " ";}	cout<<endl;}
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
void sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}
int main()
{FAST
ld x;
ld t=1,a=100,c=0;;
cin>>x;
while(a<x)
{
	a*=(1.01);
    a=floor(a);
	c++;
}
cout<<c<<endl;
 

return  0;
}




Measured memory_bytes: 3804
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTravelingPlan solver = new CTravelingPlan();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTravelingPlan {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n + 2];
            long sum = 0;
            for (int i = 0; i <= n + 1; i++) {
                if (i == 0) a[i] = 0;
                else if (i == n + 1) a[i] = 0;
                else a[i] = in.nextInt();
            }
            for (int i = 1; i <= n + 1; i++) {
                sum += Math.abs(a[i] - a[i - 1]);
            }

            for (int i = 1; i <= n; i++) {
                // iがいかない
                out.println(sum - Math.abs(a[i] - a[i - 1]) - Math.abs(a[i] - a[i + 1]) + Math.abs(a[i - 1] - a[i + 1]));
            }

        }

    }
}



Measured memory_bytes: 54340
N, Y= map(int, input().split())

for x in range(N + 1):
    for y in range(N - x + 1):
        z = N - (x + y)
        if Y == x * 10000 + y * 5000 + z * 1000:
            print(x, y, z)
            exit()
print('-1 -1 -1')


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr int MOD = 1000000007;
using namespace std;

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

VL prime_decomposition(ll n) {
	ll i = 2;
	VL table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace_back(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace_back(n);
		return table;
	}
}

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

	
		
	
	cout << a+b/2 << endl;
}

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

int main(int argc, char *argv[]){
  string str;
  cin >> str;
  int K;
  cin >> K;
  int N = str.length();
  int a[N];
  int i;
  for(i=0; i<N; ++i){
    a[i] = (int)str[i] - (int)'a';
  }
  for(i=0; i<N; ++i){
    if(a[i] != 0 && K >= 26 - a[i]){
      K -= 26 - a[i];
      a[i] = 0;
    }
  }
  K = K%26;
  for(i=N-1; i>=0; --i){
    if(a[i] != 0){
      a[i] += K;
      K = 0;
      break;
    }
  }
  if(K!=0){
    a[N-1] += K;
    K = 0;
  }
  
  for(i=0; i<N; ++i){
    cout << (char)((int)'a'+a[i]);
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#define ll long long
using namespace std;

bool Inter(pair<ll,ll> X, pair<ll,ll> Y) {
    if (X.second < Y.first || X.first > Y.second)
        return false;
    return true;
}

int main() {
    ll N,A,B,C,D;
    cin>>N>>A>>B>>C>>D;

    
    bool ok = false;
    for(int i=1;i<=N-2;i++) {
        pair<ll,ll> int1 = make_pair(A-i*D,A-i*C);
        pair<ll,ll> int2 = make_pair(A+i*C,A+i*D);
        
        
        int j = N-1-i;
        pair<ll,ll> int3 = make_pair(B-j*D,B-j*C);
        pair<ll,ll> int4 = make_pair(B+j*C,B+j*D);
        
        if (Inter(int1, int3) || Inter(int1, int4) || Inter(int2, int3) || Inter(int2,int4)) {
            ok=true;
            break;
        }
    }
    
    if (ok) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
    
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		int n = ni();
		char[] s = next().toCharArray();
		int result = 0;
		char tmp = '?';
		for(int i = 0; i < n; i++) {
			if(s[i] != tmp) {
				result++;
				tmp = s[i];
			}
		}
		System.out.println(result);
	}

	//Switch input source (stdin/file)
	private static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				scanner = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath)))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(scanner.nextLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

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

#define INF (100000*12+1)

int N, M, X;
int C[13][13] = {0};

// 戻り値-1は学習未達
int calc_cost(unsigned int book) {
  int cost = 0;
  int A[13] = {0};
  for (int i = 1; i <= N; i++) {
    if ((book&(1<<(i-1))) == 0) continue;

    for (int j = 1; j <= M; j++) {
      A[j] += C[i][j];
    }
    cost += C[i][0];
  }

  bool learned = true;
  for (int i = 1; i <= M; i++) {
    if (A[i] < X) learned = false;
  }

  if (!learned) cost = -1;
  return cost;
}

int main(void) {
  cin >> N >> M >> X;
  for (int i = 1; i <=N; i++) {
    for (int j = 0; j <= M; j++) {
      cin >> C[i][j];
    }
  }

  // N冊組み合わせ
  int ans = INF;
  for (unsigned int i = 0; i < (1<<N); i++) {
    int cost = calc_cost(i);
    if (cost != -1) {
      ans = min(ans, cost);
    }
  }

  if (ans==INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


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

int main(void){
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> AC(N + 1, 0);

    for(int i = 0; i < N; i++){
        if(S[i - 1] == 'A' && S[i] == 'C')
            AC[i + 1] = AC[i] + 1;
        else
            AC[i + 1] = AC[i];   
    }

    int start, end;
    for(int i = 0; i < Q; i++){
        cin >> start >> end;
        cout << AC[end] - AC[start] << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
from itertools import accumulate

n, q = map(int, input().split())

s = input()

problems = [list(map(int, input().split())) for _ in range(q)]


def count(total, i):
    return total + 1 if s[i-1:i+1] == 'AC' else total


cumsum = list(accumulate([0] + list(range(1, n)), count))

for l, r in problems:
    print(cumsum[r-1] - cumsum[l-1])


Measured memory_bytes: 33776
n = int(input())

A = []
B = []

for i in range(n):
    arr = input().split()
    A.append(arr)
    B.append(arr)

def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = [['x', 0]] * (n1 + 1)
    R = [['x', 0]] * (n2 + 1)

    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1][1] = 1.0e+9 + 1
    R[n2][1] = 1.0e+9 + 1
    i = 0
    j = 0
    for k in range(left, right):
        if int(L[i][1]) <= int(R[j][1]):
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1


def mergeSort(A, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)


def partition(A, p, r):
    x = int(A[r][1])
    i = p - 1
    for j in range(p, r):
        if int(A[j][1]) <= x:
            i = i + 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i + 1

def quicksort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quicksort(A, p, q-1)
        quicksort(A, q+1, r)


quicksort(A, 0, n-1)
mergeSort(B, 0, n)

stable = True
for i in range(n):
    if A[i] != B[i]:
        stable = False

if stable:
    print('Stable')
else:
    print('Not stable')

for i in range(n):
    print("{} {}".format(A[i][0], A[i][1]))




Measured memory_bytes: 29268