akhauriyash/Code-Regression huggingface dataset:
// Problem : E - Dist Max
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ff         first
#define ss         second
#define endl       '\n'
#define pb         push_back
#define int        long long
#define vi         vector<int>
#define mii        map<int, int>
#define pii        pair<int, int>
#define all(x)     (x).begin(), (x).end()
#define fill(a,b)  memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define px(a)      for(auto x: a) cout<<x<<" "; cout<<'\n';
#define pxy(a,n)   rep(i,0,n) {px(a[i])};
/*_________________________________________________________*/

const long long MOD=1e9+7,N=1e5+5;
int solve()
{
	int n,ans=0;
	cin>>n;
	int x[n],y[n];
	int a[]={INT_MIN,INT_MAX,INT_MIN,INT_MAX};
	rep(i,0,n){
		int xx,yy;
		cin>>xx>>yy;
		x[i]=xx-yy;
		y[i]=xx+yy;
		a[0]=max(a[0],x[i]);
		a[1]=min(a[1],x[i]);
		a[2]=max(a[2],y[i]);
		a[3]=min(a[3],y[i]);
	}
	ans=max(abs(a[0]-a[1]),abs(a[2]-a[3]));
 	return ans;
}
int32_t main()
{	
	std::ios::sync_with_stdio(false); 
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1; 
	//cin>>t;
	while(t--)
	cout<<solve()<<endl;
}

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

int main() {
	// your code goes here
	int n;
	int arr[100100];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&arr[i]);
	}
	sort(arr,arr+n);
	bool found = false;
	int curr = 0;
	long long pertama = 0;
	long long kedua = 0;
	long long sisi = 0;
	for(int i=n-1;i>=1;i--){
		//printf("%d\n",i);
		if(arr[i]==arr[i-1]){
			//printf("%d %d\n",arr[i],arr[i-1]);
			if(pertama!=0){
				kedua = arr[i];
				break;
			}
			else{
				pertama = arr[i];	
				i--;
			}
			
		}
		
	}
	long long ans = pertama*kedua;
	cout<<ans;
	
	return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

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

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

    ll K;
    string S;
    cin >> K>>S;

    if(S.size()<=K){
        cout << S << endl;
    }
    else{
        string ans;
        REP(i,K){
            ans += S.at(i);
        }
        cout << ans << "..." << endl;
    }
}


Measured memory_bytes: 3652
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int a=sc.nextInt();
        int b=sc.nextInt();
        int[] p=new int[n];
        for (int i = 0; i < n; i++) {
            p[i]=sc.nextInt();
        }
        int ac=0,bc=0,cc=0;
        for (int i = 0; i < n; i++) {
            if(p[i]<=a)ac++;
            else if(p[i]<=b)bc++;
            else cc++;
        }
        out.println(min(ac,min(bc,cc)));
    }
    //a文字目とb文字目を入れ替え（1-indexed）
    static String swap(String s,int a,int b){
        StringBuilder t=new StringBuilder(s);
        char A=s.charAt(a-1);
        char B=s.charAt(b-1);
        t.setCharAt(a-1,B);
        t.setCharAt(b-1,A);
        return t.toString();
    }
    static long power(long x,int n){
        long mod=1000000007;
        long ans=1;
        while (n>0) {
            if((n&1)==1){
                ans=(ans*x)%mod;
            }
            x=(x*x)%mod;
            n>>=1;
        }
        return ans;
    }
    //最大公約数
    static int gcd (int a,int b) {
        int temp;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return b;
    }
    //※最小公倍数はa*b/gcd(a,b)である
    static class UF{
        static int size=51;
        static int[] par=new int[size];
        //初期化
        static void init(){
            for (int i = 1; i <size ; i++) {
                par[i]=i;
            }
        }
        //根をたどる
        static int root(int x){
            if(par[x]==x){
                return x;
            }else{
                return par[x]=root(par[x]);
            }
        }
        //同じ根をもつか(同じ集合に属するか)判定
        static boolean same(int x,int y){
            return root(x)==root(y);
        }
        //合体
        static void unite(int x,int y){
            x=root(x);
            y=root(y);
            if(x==y)return;
            par[x]=y;
        }
    }
}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
typedef vector<int> vi;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


int arr[maxii];
int arr2[maxii];
int gcd(int a,int b)
{
    if(b==0){
      return a;
     }
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    int res=(a*b)/gcd(a,b);
    return res;
}
int po(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2!=0)
        {
            res*=a;
            b--;
        }
        else
        {
            a*=a;
            b/=2;
        }
    }
    return res;
}

lln modMul(lln  a, lln b,lln mod){
    lln ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
lln powerMod(lln a,lln b,lln mod){
	if(b==0)return 1LL%mod;
	lln x=powerMod( a,b/2,mod );
	x = ( x%mod * x%mod ) % mod;
	if( b%2==1 )x = ( x%mod * a%mod ) % mod;
	return x%mod;
}

int main()
{
    int n;
    cin>>n;
    int ans=n%1000;
    if(ans==0)cout<<0;
    else
    cout<<1000-ans;

}






Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define  ll long long
int main() {
  ll n, m, l = 0;
  cin >> n;
  m = n;
  while(m) {
    ll tmp = m%10;
    l += tmp;
    m /= 10;
  }
  if(n%l == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
// atcoder/abc060/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, c;
  while (cin >> a >> b >> c) {
    set<int> vis;
    int x = 0;
    while (true) {
      x += a;
      if (vis.count(x % b)) break;
      vis.insert(x % b);
    }
    cout << (vis.count(c) ? "YES" : "NO") << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef long double ld;


int main() {
    ll N, M;
    cin >> N >> M;
    rep(i,M){
        ll tmp;
        cin >> tmp;
        N -= tmp;
    }
    cout << max(N, -1LL) << endl;
}

Measured memory_bytes: 3604
#include <stdio.h>

int main(void)
{
	int x,y;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0){
			break;
		}
		if(x<y){
			printf("%d %d\n",x,y);
		}
		else {
			printf("%d %d\n",y,x);
		}

	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, N_1000, N_100, N_10, N_1;
  cin >> N;

  N_1000 = N / 1000;
  N_100 = (N - 1000 * N_1000) / 100;
  N_10 = (N - 1000 * N_1000 - 100 * N_100) / 10;
  N_1 = N - 1000 * N_1000 - 100 * N_100 - 10 * N_10;

  if (N_1000 == N_100 && N_100 == N_10) {
    cout << "Yes" << endl;
  }
  else if (N_100 == N_10 && N_10 == N_1){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> N9;
  vector<int> N6;
  N9.pb(1);
  N6.pb(1);
  for(int i=1;;i++){
    int yen = N9[i-1]*9;
    if(yen>100000)break;
    N9.pb(yen);
  }
  for(int i=1;;i++){
    int yen = N6[i-1]*6;
    if(yen>100000)break;
    N6.pb(yen);
  }
  /*
  for(auto y:N9) cout << y << " ";
  cout << endl;
  for(auto y:N6) cout << y << " ";
  */
  int ans = 1e9;
  for(int n9=0;n9*9<=N;n9++){
    int preans=0;
    int n9_ = n9;
    rep(j,5){
      preans += n9_%9;
      n9_ /= 9;
    }
    int n = N-9*n9;
    if(n%6!=0){
      preans += n%6;
      n -= n%6;
    }
    int n6_ = n/6;
    rep(j,6){
      preans += n6_%6;
      n6_ /= 6;
    }
    ans = min(ans,preans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())

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

    if(isupper(s))cout << "A" << endl;
    else cout << "a" << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll d[MAXn];
int main(){
    IOS();
    ll n;
    cin >> n;
    priority_queue<ll,vector<ll>,greater<ll> > pq;
    REP (i,n) {
        cin >> d[i];
        pq.emplace(d[i]);
    }
    while (SZ(pq) > 1) {
        ll cur = pq.top();
        pq.pop();
        while (SZ(pq) && pq.top()%cur == 0) pq.pop();
        if (SZ(pq)) {
            ll tmp = pq.top();
            pq.pop();
            tmp %= cur;
            pq.emplace(tmp);
        }
        pq.emplace(cur);
    }
    cout << pq.top() << endl;
}


Measured memory_bytes: 1912
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;
using std::lower_bound;
using std::upper_bound;
using std::find_if;
using std::copy;
using std::copy_if;

vector<int> a;

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

    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        a.push_back(x);
    }

    int score=std::abs(w-a[n-1]);

    for(int i=0;i<n-1;i++){
        int y=std::abs(a[i]-a[n-1]);
        for(int j=n-2;j>i;j--){
            int _y=std::abs(a[j]-a[n-1]);
            if(y>_y){
                y=_y;
            }
        }
        if(y>score){
            score=y;
        }
    }

    cout << score << endl;
    return 0;
}



Measured memory_bytes: 256
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(i,n):
        if i==j:
            continue
        dp = 10**9+1
        for k in range(n):
            if k==j or k==i:
                continue
            dp = min(dp,a[i][k]+a[k][j])
        if a[i][j]<dp:
            ans += a[i][j]
        elif a[i][j]>dp:
            print(-1)
            exit()
print(ans)

Measured memory_bytes: 44508
n=int(input())
a=list(map(int,input().split()))
print(' '.join(map(str,a)))
for i in range(1,n):
    v=a[i]
    j=i-1
    while j>=0 and a[j]>v:
        a[j+1]=a[j]
        j-=1
    a[j+1]=v
    print(' '.join(map(str,a)))



Measured memory_bytes: 5600
import sys
sys.setrecursionlimit(10**7)

def f(a,b):
    if a==b:return a
    if not a<b:a,b=b,a
    return 2*(b//a)*a+f(a,b%a) if b%a else 2*(b//a)*a-a

N,X=map(int,input().split())
print(f(X,N-X)+N)

Measured memory_bytes: 3060
#include <stdio.h>
int isprime(int n){
  for(int i = 2 ; i*i<=n ;i++){
    if(n%i==0)return 0;
}
 return 1;
}
int main(){
  int n ,i , fir ,sec;
  while(scanf("%d" ,&n)){
    if(n==0)break;
    fir = 0 ,sec = 0;
    for(i=n ;i>3 ;i--){
      if(isprime(i) && isprime(i-2)){
        fir = i-2;
        sec = i;
        break;
      }
    }
    printf("%d %d\n" ,fir ,sec);
  }
  return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
long long n,x,i,a[100000],z=0,k;
int main(){
	cin>>n>>x;
	for(i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>x){
			z+=a[i]-x;
			a[i]=x;
		}
	}
	for(i=0;i<n-1;i++){
		if(a[i]+a[i+1]>x){
			k=a[i]+a[i+1]-x;
			z+=k;
			a[i+1]-=k;
		}
	}
	cout<<z<<endl;
	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        String a = stdin.readLine();

        long[] c = new long[26];
        for (char ch : a.toCharArray()) {
            c[ch - 'a']++;
        }

        long len = (long)a.length();
        long ans = len * (len - 1L) / 2L + 1L;
        for (long v : c) {
            ans -= v * (v - 1L) / 2L;
        }
        stdout.println(ans);
    }

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}

Measured memory_bytes: 25684
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

fun main() {
    diverta2019c()
}

fun diverta2019c() {
    val n = readLine()!!.toInt()
    var bxx = 0
    var xxa = 0
    var bxxa = 0
    var count = 0
    repeat(n) {
        val s = readLine()!!
        count += "AB".toRegex().findAll(s).count()
        when {
            s.first() == 'B' && s.last() == 'A' -> bxxa++
            s.first() == 'B' -> bxx++
            s.last() == 'A' -> xxa++
        }
    }
    if (bxxa == 0) {
        // どっちかしかないなら少ない方分しかペアを作れない
        count += min(bxx, xxa)
    } else if (bxx == 0 && xxa == 0) {
        // bxxaしかないならbxxaの数-1個ペアが作れる（自身のBもしくはAが1つ無駄になって使えないから）
        count += bxxa - 1
    } else {
        // bxxaはどっちにも使えるからややこしい
        if (xxa >= bxx + bxxa) {
            // bxxaをbで始まるものとして扱うとしてもなおAで終わるものの数が多いのであれば、
            // Bで始まるものの個数だけABを作れる
            count += bxx + bxxa
        } else if (bxxa + xxa < bxx) {
            // bxxaをaで終わるものとして扱うとしてもなおBで始まるものの数が多いのであれば
            // Bで始まるものの個数分だけABを作れる
            count += bxxa + xxa
        } else {
            // bxxaが単独で余る場合、少ない方にbxxaを充足してやればbxxもしくはxxaの大きい方の個数だけABを作れる
            // あとは充足してもなお余ったbxxaの数 - 1個分だけABを作れるが、
            // 充足したbxxaを使ってもう1つペアを作れるので結局あまったbxxa分ペアを作れるということになる
            val bigger = max(bxx, xxa)
            count += bigger + bxxa - abs(bxx - xxa)
        }
    }
    println(count)
}

Measured memory_bytes: 53264
#include <bits/stdc++.h>
#define X first
#define Y second
#define mp make_pair
using namespace std;
typedef pair<int,int> PII;
const int N = 500010;
char s[N];
int n,m,x,y,f[N][30],a[N];
bool ans[100010];
PII q[100010];
bool pd[N];
vector<int> v[N],Q[N]; 
void dfs(int x){
	pd[x]=true;
	int t;
	for(int i=Q[x].size()-1;i>=0;i--) {
		if(pd[q[t=Q[x][i]].Y]) ans[t]=true;
	//	printf("%d %d %d\n",x,Q[x][i],ans[Q[x][i]]);
	}
	for(int i=v[x].size()-1;i>=0;i--) dfs(v[x][i]);
	pd[x]=false;
}
int S[N],tail,now[N];
void work(){
	S[1] = n+1;
	tail = 1;
	int tmp,t;
	for(int i=1;i<=n+1;i++) now[i]=v[i].size();
	while(tail){
		t = S[tail];
		pd[t]=true;
		if(now[t]){
			S[++tail] = v[t][--now[t]];
			
		} else{
			for(int i=Q[t].size()-1;i>=0;i--)
				if(pd[q[tmp=Q[t][i]].Y]) ans[tmp]=true;
			pd[t]=false;
			tail--;
		}
	}
}
int main(){
	//gets(s+1);
	scanf("%s",s+1);
	n = strlen(s+1);
	for(int i=1;i<=n;i++) a[i]=s[i]-'a';
	for(int i=0;i<=26;i++) f[n+2][i]=f[n+1][i]=n+1;
	//cout<<n<<endl;
	for(int i=n;i>0;i--){
		f[i][a[i]]=i;
		for(int j=a[i]+1;j<=26;j++) f[i][j]=f[f[i][j-1]+1][j-1];
		for(int j=0;j<a[i];j++) f[i][j]=f[f[i][26]+1][j];
		if(f[i][26]<=n) 
			v[f[f[i][26]+1][26]].push_back(f[i][26]);
	}
//	for(int i=1;i<=n;i++) printf("%d ",f[i][26]); puts("");
	scanf("%d",&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		q[i] = mp(x,y);
		if(f[x][26]<=n) Q[f[x][26]].push_back(i);
	}
//	dfs(n+1);
work();
	for(int i=1;i<=m;i++) if(ans[i]) puts("Yes"); else puts("No");
	return 0;
}
/*
yzyyyzyzyyyz
8
1 6
7 12
1 12
6 11
1 1
1 3
4 9
3 8
*/

Measured memory_bytes: 108800
#include <iostream>
#include <cstdio>

using namespace std;
using ll=long long;

int main()
{
    int A, B;
    
    cin >> A >> B;
    
    bool isDistribution = false;
    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
    {
        isDistribution = true;
    }
    
    printf("%s\n", isDistribution ? "Possible" : "Impossible");
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 static List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int A = sc.nextInt();
	        int B = sc.nextInt();
	        int Q = sc.nextInt();
	        long[] s = new long[A+2];
	        s[0]=-Long.MAX_VALUE/5;
	        for (int i=1 ; i<=A; i++) {
	            s[i] = Long.parseLong(sc.next());
	        }
	        s[A+1]=Long.MAX_VALUE/5;
	        long[] t = new long[B+2];
	        t[0]=-Long.MAX_VALUE/5;
	        for (int i=1 ; i<=B; i++) {
	            t[i] = Long.parseLong(sc.next());
	        }
	        t[B+1]=Long.MAX_VALUE/5;
	        long[] x = new long[Q];
	        for (int i=0 ; i<Q; i++) {
	            x[i] = Long.parseLong(sc.next());
	        }
	        
	        	        
	        for(int i=0;i<Q;i++) {
	        	int left = 0;
	        	int right = A+1;
	        	while(right-left>1) {
	        		int mid = left+(right-left)/2;
	        		if(s[mid]>=x[i]) {
	        			right=mid;
	        		} else {
	        			left=mid;
	        		}
	        	}
	        	long t1 = Math.min(x[i]-s[left], s[right]-x[i]);
	        	
	        	int left2 = 0;
	        	int right2 = B+1;
	        	while(right2-left2>1) {
	        		int mid = left2+(right2-left2)/2;
	        		if(t[mid]>=x[i]) {
	        			right2=mid;
	        		} else {
	        			left2=mid;
	        		}
	        	}
	        	
	        	long sl=s[left];
	        	long sr=s[right];
	        	long tl=t[left2];
	        	long tr=t[right2];
	        	
	        	long ans= x[i]-Math.min(s[left], t[left2]);
	        	ans=Math.min(ans, Math.max(s[right], t[right2])-x[i]);
	        	ans=Math.min(ans, Math.min(sr-x[i], x[i]-tl)+sr-tl);
	        	ans=Math.min(ans, Math.min(tr-x[i], x[i]-sl)+t[right2]-s[left]);
	        	System.out.println(ans);
	        }
	        
		 }
		 
	 
	}

Measured memory_bytes: 78696
s = $stdin.gets.chomp

rest = ('a'..'z').to_a - s.split('')
if rest.length > 0
    print s + rest.first
else
    pool = []
    loop do
        pool.push(s[-1])
        s = s.chop
        if s.length == 0
            print '-1'
            exit
        end
        if s[-1] < pool.max
            add = pool.select{|c| c > s[-1]}.min
            print s[0...-1] + add
            exit
        end
    end
end

Measured memory_bytes: 1788
let NK: [Int] = readLine()!.split(separator: " ").map { Int($0)! }
let N: Int = NK[0]
let K: Int = NK[1]
var seqNow: [Int] = readLine()!.split(separator: " ").map { Int($0)! }

for _ in 0..<K {
    var seqNext = Array(repeating: 0, count: N+1)

    for (i, a) in seqNow.enumerated() {
        let left: Int = max(0, i-a)
        let right: Int = min(N, i+1+a)
        
        seqNext[left] += 1
        seqNext[right] += -1
    }
    for i in 1..<N {
        seqNext[i] = seqNext[i] + seqNext[i-1]
    }
    if seqNow[0..<N] == seqNext[0..<N] { break }
    seqNow[0..<N] = seqNext[0..<N]
}
var res: String = ""
for s in seqNow[0..<N-1]{
    res += "\(s) "
}
print(res + String(seqNow[N-1]))

Measured memory_bytes: 19228
/*
author : nit1n
*/
#include<bits/stdc++.h>
#define int long long
using namespace std ;


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

	string s , t ; 
	cin >> s >> t; 
	int mx = 1e9 ; 
	for(int i = 0; i <= s.size() -t.size() ; ++i)
	{
		int x = i ; 
		int cnt = 0 ; 
		for(int j = 0 ; j < t.size() ; ++j)
		{
			if(s[x] != t[j])
				cnt++ ; 
			x++;
		}
		mx = min(mx , cnt) ; 
	}
	cout << mx ;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <climits>

using namespace std;

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

    vector<int> e;
    vector<int> w;

    int en, wn; en = wn = 0;
    for (int i = 0; i < n; ++i) {
        if (str[i] == 'E') {
            if (i) {
                e.push_back(e[i-1]+1);
                w.push_back(w[i-1]);

            } else {
                e.push_back(1);
                w.push_back(0);
            }

        } else {
            if (i) {
                e.push_back(e[i-1]);
                w.push_back(w[i-1]+1);

            } else {
                e.push_back(0);
                w.push_back(1);
            }
        }
    }

    int ans = INT_MAX;
    for (int i = 0; i < n; ++i) ans = min(ans, ((e[n-1] - e[i]) + w[i-1]));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4080
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, k = LI()

if k % 2 == 1:
    print((n // k) ** 3)
else:
    print((n // k) ** 3 + (((n // (k // 2)) - (n // k)) ** 3))


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
  int money,bell;
  while(1){
    cin >> money;
    if(money==0){
      break;
    }
    for(int i=0;i<9;i++){
      cin >> bell;
      money-=bell;
    }
    cout << money << endl;
  }
}

Measured memory_bytes: 1160
import java.util.*;
// import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    System.out.println(main.solve());
  }

  long a;
  long v;
  long b;
  long w;
  long t;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      a = sc.nextLong();
      v = sc.nextLong();
      b = sc.nextLong();
      w = sc.nextLong();
      t = sc.nextLong();
    } finally {
      sc.close();
    }
  }

  String solve() {
    return possible() ? "YES" : "NO";
  }

  boolean possible() {
    if (Math.abs(a - b) <= t * (v - w)) return true;
    return false;
  }
}


Measured memory_bytes: 35728
L, R = map(int, input().split())

ans = 2*10**9+1
for i in range(L, min(R, L+2019)+1):
    for j in range(i+1, min(R, L+2019)+1):
        i %= 2019
        j %= 2019
        ans = min(ans, (i*j)%2019)
print(ans)


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

#define N_MAX 100
#define W_MAX 10000

int dp[W_MAX+1];
int v[N_MAX];
int w[N_MAX];

int main () {
  int N, W;
  cin >> N >> W;
  REP(i,N) cin >> v[i] >> w[i];
  fill(dp, dp + W_MAX + 1, 0);

  REP(i,N) {
    for(int j = W; j >= 0; j--) {
      if(j - w[i] >= 0) dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
    }
  }
  cout << dp[W] << endl;

  return 0;
}

Measured memory_bytes: 3136
#include <stdio.h>
int main(void){
  int x[6];
  int i;
  for(i=0;i<5;i++){
    scanf("%d",&x[i]);
  }
  for(i=0;i<5;i++){
    if(x[i]==0){
      printf("%d",i+1);
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 1724
H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input()[::-1]
T = input()[::-1]

l, r, u, d = 0, 0, 0, 0

for i in range(N):
    if T[i] == 'L' and r > 0:
        r -= 1
    elif T[i] == 'R' and l > 0:
        l -= 1
    elif T[i] == 'U' and d > 0:
        d -= 1
    elif T[i] == 'D' and u > 0:
        u -= 1

    if S[i] == 'L':
        l += 1
    elif S[i] == 'R':
        r += 1
    elif S[i] == 'U':
        u += 1
    elif S[i] == 'D':
        d += 1

    if l+r == W or u+d == H:
        print('NO')
        exit()

if l < sc and sc <= W-r and u < sr and sr <= H-d:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 46512
#include<iostream>                    
using namespace std;
int main(){
 
  int n,a[10000],i,s(1000000),b(-1000000);
  long long w=0;
  cin>>n;
  for(int i=0;i<n; i++)
  {
         cin>>a[i];
 
           w+=a[i];
		   
         if(s>a[i])
         {
	       s=a[i];
         }
        if(b<a[i])
         {      

	         b=a[i];

		}
  
  }
  cout<<s<<" "<<b<<" "<<w<<endl;


  return 0;
  }  



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

const int MAXN = 60;
const long long MOD = 1e9 + 7;

struct matrix{
	int n, m;
	long long v[MAXN][MAXN];
	matrix(int _n = 0, int _m = 0){
		n = _n;
		m = _m;
		memset(v, 0LL, sizeof(v));
	}
	void id(){
		memset(v, 0LL, sizeof(v));
		for(int i = 1; i <= n; i++)
			v[i][i] = 1;
	}
	matrix operator * (matrix a){
		matrix ret (n, a.m);
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= a.m; j++)
				for(int k = 1; k <= m; k++){
					ret.v[i][j] += v[i][k] * a.v[k][j];
					ret.v[i][j] %= MOD;
				}
		return ret;
	}
	int sum(){
		int ret = 0;
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= m; j++){
				ret += v[i][j];
				ret %= MOD;
			}
		return ret;
	}
	void scan(){
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= m; j++)
				scanf("%lld", &v[i][j]);
	}
	void print(){
		printf("\n");
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= m; j++)
				printf("%lld ", v[i][j]);
			printf("\n");
		}
	}
}dp;

int tam;
long long k;

matrix fexp(matrix a, long long exp);

int main(){
	scanf("%d %lld", &tam, &k);
	dp = matrix(tam, tam);
	dp.scan();
	matrix ans = fexp(dp, k);
	printf("%d\n", ans.sum());
}

matrix fexp(matrix a, long long exp){
	matrix ret(tam, tam);
	ret.id();
	// ret.print();
	for(long long k = 60; k >= 0; k--){
		ret = ret * ret;
		if((1LL<<k)&exp) ret = ret * a;
	}
	// ret.print();
	return ret;
}

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

int memo[1111];

int solve(int n){
  
  if(!n) return 0;
  if(n<0) return 1<<28;
  if(memo[n]) return memo[n];
  
  int ans = 1<<28;
  ans = min(solve(n-500)+1, min(solve(n-100)+1, min(solve(n-50)+1, min(solve(n-10)+1, min(solve(n-5)+1, solve(n-1)+1)))));
  
  return memo[n] = ans;
}

int main(){
  
  for(int i=0;i<1111;i++) solve(i);

  int n;
  while(cin >> n, n) cout << solve(1000-n) << endl;
  
}

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

int main()
{
	int a[100000], i, I;
	for(i = 0 ;  ; i++)
	{
		scanf("%d", &a[i]);
		if(a[i] == 0)
		{
			for(I = 0 ; I < i ; I++)
			{
				printf("Case %d: %d\n", I+1, a[I]);
			}
			exit(0);
		}
	}
	return 0;
}


Measured memory_bytes: 1988
#include <bits/stdc++.h>
#include<chrono>
using namespace std;
using ll = long long;

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> P(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> P[i][j];
    }
  }
  int count = 0;
  for (int i = 0; i< N; i++) {
    for (int j = i+1; j < N; j++) {
      int d = 0;
      for (int k = 0; k < D; k++) {
        int diff = abs(P[i][k] - P[j][k]);
        d += diff*diff;
      }
      bool check = false;
      for (int k = 0; k <= d; k++) {
        if (k*k == d) {
          check = true;
        }
      }
      if (check) {
        count++;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-13 20:49:27 +0900
# LastModified: 2020-09-13 21:20:34 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    N = int(input())
    no_0 = 9**N
    no_9 = 9**N
    no_09 = 8**N
    total = 10**N
    print((total-no_0-no_9+no_09)%1000000007)


if __name__ == "__main__":
    main()


Measured memory_bytes: 11952
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> a(N);
	for (Int i = 0; i < N; i++) {
		cin >> a[i];
	}

	vector<Int> sum(N + 1);
	sum[0] = abs(a[0]);

	for (Int i = 1; i < N; i++) {
		sum[i] = sum[i - 1] + abs(a[i] - a[i - 1]);
	}
	sum[N] = sum[N - 1] + abs(a[N - 1]);


	Int temp = 0;
	for (Int i = 0; i < N; i++) {
		if (i == 0) {
			temp = sum[N] - sum[1] + abs(a[1]);
			printf("%lld\n", temp);
			continue;
		}
		if (i == N - 1) {
			temp = sum[N - 2] + abs(a[N - 2]);
			printf("%lld\n", temp);
			continue;
		}
		
			temp = sum[i - 1] + sum[N] - sum[i + 1] + abs(a[i - 1] - a[i + 1]);
				printf("%lld\n", temp);
		
	}

}

Measured memory_bytes: 2816
import sys
sys.setrecursionlimit(2147483647)

N, M, K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
Asum = [0]
Bsum = [0]
count = 0
for p in A:
    count += p
    Asum.append(count)
count = 0
for p in B:
    count += p
    Bsum.append(count)
best = 0
Blast = M
for t in range(N+1):
    if Asum[t] > K:
        break
    if best < t:
        best=t
    for s in reversed(range(0,Blast+1)):
        if Asum[t]+Bsum[s]<=K:
            if best < t+s:
                best=t+s
            Blast = s
            break
print(best)



Measured memory_bytes: 47180
import itertools
import math

N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))

X = sorted(P)

Y = itertools.permutations(X)

a = 0
b = 0
cnt = 1
for i in Y :
    if P == Q :
        break
    if P == i :
        a = cnt+1
    elif Q == i :
        b = cnt+1

    cnt = cnt + 1

print(abs(a-b))



Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
  string a;
  cin >> a;
  for(int i=0; i<a.size(); i++){
    for(int j=i+1; j<a.size();j++){
      if(a[i]==a[j]){
        cout << "no" << endl;
        return 0;
      }
    }
  }
  cout << "yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
using namespace std;
typedef long long ll;

int main(){
  ll n;
  cin >> n;
  ll dp[n][3];
  ll happiness[n][3];
  REP(i,n){
    REP(j,3){
      cin >> happiness[i][j];
    }
  }
  REP(j,3) dp[0][j] = happiness[0][j];
  for(ll i = 1; i < n; i++){
    REP(j,3){
      dp[i][j] = max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]) + happiness[i][j];
    }
  }
  cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    b.at(a.at(i)-1)=i+1;
  }
  for(int i=0;i<n;i++){
    cout << b.at(i) << ' ';
  }
  cout << endl;
}



Measured memory_bytes: 4040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
	    int b = sc.nextInt();
	    int x = a*b;
	    int y = a+a+b+b;
	    System.out.println(x+" "+y);
	     
	    sc.close();

	}

}

Measured memory_bytes: 25884
#include <stdio.h>

int main(void)
{
    int x, y, i = 1;
    while(i <= 3000) {
        scanf("%d %d", &x, &y);
        if ((x == 0 && y == 0) || x < 0 || x > 10000 || y < 0 || y > 10000) break; 
        if (x < y) printf("%d %d\n", x, y);
        else printf("%d %d\n", y, x);
        i++;
    };
    
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

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';
	}
	cout << n << endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int cnt = 0;
  for(int i=0; i<n; ++i){
    int a, b;
    cin >> a >> b;
    if(a == b) ++cnt;
    else cnt = 0;
    if(cnt == 3){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3620
using System;

namespace A___Diagonal_String
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine();
            var b = Console.ReadLine();
            var c = Console.ReadLine();
            Console.WriteLine($"{a[0]}{b[1]}{c[2]}");
        }
    }
}

Measured memory_bytes: 11092
import heapq
N, M = map(int, input().split())

L = [[int(i) for i in input().split()] for i in range(N)]
L = sorted(L, key=lambda x: -x[0])

h = []
ans = 0
j = N-1
for i in range(M-1, -1, -1):
    while j >= 0 and L[j][0] <= M - i:
        heapq.heappush(h, -L[j][1])
        j -= 1
    if len(h) == 0:
        continue
    ans += -heapq.heappop(h)
print(ans)


Measured memory_bytes: 77912
#include <iostream> 

using namespace std;

int main(){

 int n;
 cin >> n;
 if( n == 0 ) cout << 1 << endl;
 else 
 if( n == 1 ) cout << 2 << endl;
 else 
 if( n == 2 ) cout << 1 << endl;
 else
 cout << 0 << endl;
 

}

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

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  string N;
  cin >> N;
  bool ju = false;
  
  rep(i, 3){
    if(N[i] == '7'){
      ju = true;
      break;
    }
  }
  if(ju) cout << "Yes" << "\n";
  else cout << "No" << "\n";

  return 0;
}




Measured memory_bytes: 3672
def main():
  from collections import deque
  n,m,*t=map(int,open(0).read().split())
  i=[0]*n
  o=[[]for _ in range(n)]
  for a,b in zip(*[iter(t)]*2):
    o[a-1]+=b-1,
    i[b-1]+=1
  q=deque(v for v,f in enumerate(i)if f<1)
  r=[]
  while q:
    v=q.popleft()
    r+=v,
    for w in o[v]:
      i[w]-=1
      if i[w]==0:q+=w,
  print(-(len(r)==n))
main()

Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
         
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007  
const int N = 100001; 


void solve(){
    int n,x,t;cin>>n>>x>>t;
    int ans=(n+x-1)/x;
    cout<<ans*t;
    return;
}
         
signed main(){
        IOS;    
      
        int t=1;
        // cin>>t;
        // fac[0] = 1; 
        // for (int i=1 ; i<=2000001; i++) fac[i] = fac[i-1]*i%mod; 
        rep(i,0,t){
            solve();
            cout<<"\n";
        //   cout<<" * "<<t<<"\n";
        }
    //    return 0;
}

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

using namespace std;

using ll = long long;

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

    map<string, ll> cnt;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());

        ans += cnt[s];
        cnt[s]++;
    }

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

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

int main() {
	int n;
	scanf("%d", &n);
	
	char arr[255];
	scanf("%s", &arr);
	
	int len = strlen(arr);
	if(len > n){
		for(int i = 0; i < n; i++){
			printf("%c", arr[i]);
		}
		printf("...\n");
	}
	
	else{
		printf("%s\n", arr);
	}
	return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
char sz[5001];
string str;
int k;
set<string> set_substring;
string s1;
string minstr;
set<string>::iterator it;
void ProcessSubstring(string s,int len)
{
	int i,j;
	for(i=0;i<len;i++)
	{
		for(j=0;j<len-i;j++)
		{
			set_substring.insert(s.substr(j,i+1));
		}	
	}
}
int main()
{
	int n,m,i,j;
	scanf("%s",sz);
	scanf("%d",&k);
	str=sz;
	minstr=str;
	if(str.length()>=k)
	{
		for(i=0;i<str.length()-k;i++)
		{
			s1=str.substr(i,k);
			if(s1<minstr)
			{
				minstr=s1;
				ProcessSubstring(s1,k);
			}
		}
		s1=str.substr(str.length()-k,k);
		ProcessSubstring(s1,k);
	}
	else
	{
		ProcessSubstring(str,str.length());
	}
	it=set_substring.begin();
	for(i=0;i<k-1;i++)
	{
		it++;
	}
	printf("%s",(*it).c_str());
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define PP pop_back()
#define set(x,y) memset(x,y,sizeof(x))
#define MIN3(x,y,z) min(min(x,y),z)
#define MAX3(x,y,z) max(max(x,y),z)
#define ALL(x) x.begin(),x.end()
#define sz(x) (int) x.size()
#define sag node*2+1
#define sol node*2
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define ROF(i,j,k) for(int i=j;i>=k;i--)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define ii pair<int,int>
#define pll pair<ll,ll>
#define st first
#define nd second
#define ll long long
#define llu long long unsigned
#define lf double
#define orta (bas+son)/2
#define MOD 1000000007
#define inf 200000000000001
#define N 100005
using namespace std;

char s[N];
int n,m;

int main() {

  scanf("%s %d",s+1,&m);
  n=strlen(s+1);
  FOR(i,1,n) {
    int mov=s[i]=='a'?0:'z'-s[i]+1;
    if(mov<=m) {
      s[i]='a';
      m-=mov;
    }
  }
  m%=26;
  if(m) {
    s[n]='a'+(s[n]+m-'a')%26;
  }
  printf("%s",s+1);

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

using ld = long double;
int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint L; cin >> L;
    ld ans = L * L * L / (ld)27;
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define loop(i,n) for(int i = 0; i < (n); i++)
#define loops(i,f,n) for(int i = (f); i < (n); i++)
#define INF 100000000
int main()
{
	int n, k;
	while (cin >> n >> k)
	{
		if (n == 0 && k == 0)break;
		vector<int> cards(k);
		loop(i, k)cin >> cards[i];
		sort(cards.begin(), cards.end());
		if (cards[0] != 0)
		{
			int count = 1;
			int ans = 0;
			for (int i = 1; i < k; i++)
			{
				if (cards[i] - 1 == cards[i - 1])count++;
				else count = 1;
				ans = max(ans, count);
			}
			cout << ans << endl;
		}
		else
		{
			cards.erase(cards.begin());
			int ans = 0, count = 1;
			bool skipped = false;
			//cout << cards[0] << " " << count << " " << ans << endl;
			for (int i = 1; i < k - 1; i++)
			{
				if (cards[i] - 1 == cards[i - 1])
				{
					count++;
					ans = max(ans, count);
				}
				else if (cards[i] - 2 == cards[i - 1] && skipped == false)
				{
					skipped = true;
					count += 2;
					ans = max(ans, count);
					if (!cards[i + 1] == cards[i] + 1)count = 1;
				}
				else
				{
					count = 1;
					skipped = false;
				}
				//cout << cards[i] << " " << count << " " << ans << endl;
			}
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 3152
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include<set>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
llfor;///////////////////////////////////////////////////////////
int main(){
 ll n;sc(n);
 ll a[n],b[n];
 ll ans=1;
 rep(i,0,n){
  sc(a[i]);
 }
 rep(i,0,n-1){
   if(a[i]<a[i+1])b[i]=0;
   else if(a[i]>a[i+1])b[i]=1;
   else b[i]=b[i-1];
   if((b[i-1]==1&&b[i]==0)||(b[i-1]==0&&b[i]==1)){
    ans++;
   // cout<<b[i-1]<<" "<<b[i]<<" "<<i<<endl;
    b[i]=2;
   }
 }
 pr(ans);
 
return 0;}

Measured memory_bytes: 5168
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var (
	n      int
	w      int
	weight []int
	value  []int
)

const MAXN = 110
const MAXV = 100100

var dp [MAXN][MAXV]float64

func main() {
	sc.Split(bufio.ScanWords)

	n, w = nextInt(), nextInt()
	weight = make([]int, n)
	value = make([]int, n)
	for i := 0; i < n; i++ {
		weight[i] = nextInt()
		value[i] = nextInt()
	}

	for i := 0; i < MAXN; i++ {
		for j := 0; j < MAXV; j++ {
			dp[i][j] = math.Inf(1)
		}
	}

	dp[0][0] = 0

	for i := 0; i < n; i++ {
		for sumv := 0; sumv < MAXV; sumv++ {
			// i番目の品物を選ぶ
			if sumv-value[i] >= 0 {
				chmin(&dp[i+1][sumv], (dp[i][sumv-value[i]] + float64(weight[i])))
			}
			// i番目の品物を選ばない
			chmin(&dp[i+1][sumv], dp[i][sumv])

		}
	}

	// 最適値の出力
	res := 0
	for sumv := 0; sumv < MAXV; sumv++ {
		if dp[n][sumv] <= float64(w) {
			res = int(sumv)
		}
	}

	fmt.Println(res)
}

func chmin(a *float64, b float64) bool {
	if *a > b {
		*a = b
		return true
	}
	return false
}

func chmax(a *float64, b float64) bool {
	if *a < b {
		*a = b
		return true
	}
	return false
}


Measured memory_bytes: 86656