akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

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

        long k = sc.nextLong();
        long[] res = new long[50];
        for (int i = 0; i < 50; i++)
            res[i] = k / 50 + 49;
        int rem = (int)(k % 50);
        for (int i = 0; i < rem; i++) {
            res[i] += 50;
            for (int j = 0; j < 50; j++)
                if (i != j) res[j]--;
        }
        out.println(50);
        for (int i = 0; i < 50; i++) {
            if (i > 0) out.print(" ");
            out.print(res[i]);
        }
        out.println();
        out.close();
    }
























    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

Measured memory_bytes: 23124
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
b = Array.new(10**5+1, 0)
a.each do |i|
  b[i] += 1
end
ret = 0
b.each_cons(3) do |v1, v2, v3|
  ret = [ret, v1 + v2 + v3].max
end
puts ret

Measured memory_bytes: 12036
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	int ans = 0, pre = 0;
	REP(i, N) {
		int x;
		cin >> x;
		if (pre == 0) {
			ans += x - 1;
			pre++;
		}
		else if (x == pre + 1) {
			pre++;
		}
		else if (x > pre + 1) {
			ans += (x - 1) / (pre + 1);
		}
	}
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	char s[8];
	scanf("%s", s);
	if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R')
		printf("3\n");
	else if (s[0] == 'R' && s[1] == 'R')
		printf("2\n");
	else if (s[1] == 'R' && s[2] == 'R')
		printf("2\n");
	else if (s[0] == 'S' && s[1] == 'S' && s[2] == 'S')
		printf("0\n");
	else
		printf("1\n");
	return 0;
}

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

using namespace std;

using u32 = uint32_t;
using u64 = uint64_t;
using i64 = int64_t;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = (b-1); i >= a; i--)
#define RF0(i,b) RFO(i,0,b)

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

  int L;
  cin >> L;

  double d = ((double)L) / 3;

  cout << fixed << setprecision(15) << (d * d * d);
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <random>
#include <bitset>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define x  first
#define y  second
#define mp make_pair
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

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

#ifndef ONLINE_JUDGE
	// #include "debug.h"
#else
// #define debug(...) 42
#endif

const int mxN=100;
const ld PI=acos(-1);
const int MD=1e9+7;

int main() {
	fast_cin();
	int t=1;
	// cin>>t;
	while(t--)
	{
		int x;
		cin>>x;
		if(x>=30) cout<<"Yes";
		else cout<<"No";
	}
	return 0;	
}

Measured memory_bytes: 3568
#include<iostream>

using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)

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

  int a[N];
  REP(i,N) cin >> a[i];
  int oddcount=0;
  int fourcount=0;

  REP(i, N) {
    if(a[i]%2 != 0) ++oddcount;
    else if(a[i]%4 == 0) ++fourcount;
  }

  if(oddcount <= fourcount) cout << "Yes" << '\n';
  else if(oddcount == 1 + fourcount && oddcount + fourcount == N)cout << "Yes" << '\n';
  else cout << "No"<< '\n';

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <stdlib.h> //rand() 0~RAND_MAX2147483647
#include <math.h>
#include <time.h>   //srand((unsigned int)time(NULL));
#include <unistd.h> //sleep
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <unordered_map>
#include <set>
#include <cassert> //assart
#include <numeric>
#include <iterator>
#include <list>
#include <tuple>

using namespace std;
#define ll long long int
#define FOR(i,min,max) for(int i=(min);i<(max);i++)
#define FOReq(i,min,max) for(int i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(int i=(max)-1;i>=(min);i--)
#define FORREVeq(i,max,min) for(int i=(max);i>=(min);i--)
const int MOD=1e9+7;
const int MOD2=998244353;
const int not0=1;
const int INF=2000000001;
const ll INFll=2e18;
//const int MAX_V=10000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INFll || MOD2 || not0){;}
    return 0;
}

#define pf printf
#define sf scanf
#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
#define br printf("\n");
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}
#define elif else if

#define issame(a,b,c,d) ((a)==(b) and (b)==(c) and (c)==(d))
#define isdiff3(a,b,c) ((a)!=(b) and (b)!=(c) and (c)!=(a))
#define isdiff4(a,b,c,d) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c))
#define isdiff5(a,b,c,d,e) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c) and (e)!=(a) and (e)!=(b) and (e)!=(c) and (e)!=(d))
#define Func3(f,a,b,c) (f)((f)((a),(b)),(c))
#define Func4(f,a,b,c,d) (f)((f)((f)((a),(b)),(c)),(d))

inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
inline ll  gcd(ll a,ll b){ if(b==0)return a;else return gcd(b,a%b);}//最大公約数 なお一方が0なら答えは他方になるので番兵は０で良い また、負の数もOK -4%3=-1となるため
inline ll  lcm(ll a,ll b){return a*b/gcd(a,b);}//MODやオーバーフローには注意！
//inline ll  ceil(double a){return (ll)a+1;}
//ans = accumulate(A, A+N, 0, [](int a, int b) {return gcd(a,b);});
//auto count = std::count_if(v.begin(), v.end(), [](int x) { return x == 1 || x == 3; } );




//Eと名のつくのはデバッグ用！
int EintN(ll array[],const ll num){
    for(int i=0;i<num;i++){cerr<<array[i]<<" ";}
    br;
    return 0;
}
//int EintNN(const int heighth,const int width,int array[heighth][width]){
//    FOR(i, 0, heighth){
//        FOR(k, 0, width){
//            {cerr<<array[i][k]<<" ";}
//        }
//        br;
//    }
//    br;
//    return 0;
//}
int Eint(string str,const ll num){
    cerr<<str<<" is "<<num<<" now."<<endl;
    return 0;
}












ll probA(){
    ll ans;ans=0;
    string S,T;
    cin>>S>>T;
    FOR(i,0 , 3){
        if(S[i]==T[i])ans++;
    }
    OutputAndReturn0(ans);
    return 0;
}

ll probB(){
    ll ans;ans=0;
    ll A,B;
    cin>>A>>B;
    while(ans*A-(ans-1)<B)ans++;
    OutputAndReturn0(ans);
    return 0;
}

ll probC(){
    ll ans;ans=0;
    
    OutputAndReturn0("Yes");
    return 0;
}

ll probD(){
    ll ans;ans=0;
    
    OutputAndReturn0("Yes");
    return 0;
}

signed main(){
    probB();
    return 0;
}


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

int main() {

    string N;

    cin >> N;

    string ans = "No";

    if(N.at(0) == '7' || N.at(1) == '7' || N.at(2) == '7') ans = "Yes";

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

Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <algorithm>

typedef long long LL;
const int MN = 200005;
const int ML = 1000005;
const int Sig = 26;

int N;
char s[ML];
int Key[MN], Cha[MN];

int tr[ML][Sig], num[ML][Sig], buk[Sig], cnt;

inline void Insert(int id, int len) {
	static int stk[ML];
	for (int j = 0; j < Sig; ++j) buk[j] = 0;
	stk[0] = 1;
	for (int i = 1; i <= len; ++i) {
		int w = stk[i - 1], c = s[i] - 'a';
		if (!tr[w][c]) tr[w][c] = ++cnt;
		stk[i] = tr[w][c];
		buk[c] = i;
	}
	Key[id] = stk[len - 1];
	Cha[id] = s[len] - 'a';
	for (int j = 0; j < Sig; ++j) if (buk[j])
		++num[stk[buk[j] - 1]][j];
}

int main() {
	scanf("%d", &N), cnt = 1;
	for (int i = 1; i <= N; ++i) {
		scanf("%s", s + 1);
		int len = strlen(s + 1);
		std::reverse(s + 1, s + len + 1);
		Insert(i, len);
	}
	for (int i = cnt; i >= 1; --i)
		for (int j = 0; j < Sig; ++j) if (tr[i][j]) {
			int v = tr[i][j];
//			printf("(%d) ----%c---> (%d)\n", i, 'a' + j, v);
			for (int k = 0; k < Sig; ++k)
				num[i][k] += num[v][k];
		}
	LL Ans = 0;
	for (int i = 1; i <= N; ++i)
		Ans += num[Key[i]][Cha[i]] - 1;
	printf("%lld\n", Ans);
	return 0;
}

Measured memory_bytes: 207148
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <ctime>
#include <map>
#include <cmath>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

typedef long long LL;
const int N = 100010;
const int N0 = 2200;

int prime[N], cnt;
bool isnotprime[N];

void get_prime()
{
	for (int i = 2; i <= N0; i ++) {
		if (!isnotprime[i]) prime[++ cnt] = i;
		for (int j = 1; j <= cnt && i * prime[j] <= N0; j ++) {
			isnotprime[i * prime[j]] = true;
			if (!(i % prime[j])) break;
		}
	}
}

map<LL, int> m;

LL t1[N], t2[N];
bool val[N];

int main()
{
	
	int n;
	scanf("%d", &n);
	get_prime();
	Rep(i, n) {
		LL x, x1 = 1, x2 = 1;
		scanf("%lld", &x);
		Rep(j, cnt){
			int tmp = 0;
			while (!(x % prime[j])) x /= prime[j], tmp ++;
			tmp %= 3;
			if (tmp == 1) x1 *= prime[j], x2 *= prime[j] * prime[j];
			else if (tmp == 2) x1 *= prime[j] * prime[j], x2 *= prime[j];
			if (x2 > 1e10) { val[i] = true; break;}
		}
		if (!val[i] && x != 1) {
			LL tx = sqrt(x);
			if (tx * tx == x) x1 *= x, x2 *= tx;
			else if (log10(x2) + log10(x) + log10(x) <= 11) x1 *= x, x2 *= x * x;
			else val[i] = true;
		}
		if (!val[i]) m[x1] ++, t1[i] = x1, t2[i] = x2;
	}
	int ans = 0, ans0 = 0;
	Rep(i, n) {
		if (t1[i] == 1) continue;
		if (val[i]) ans ++;
		else {
			if (m[t2[i]] < m[t1[i]]) ans ++;
			else if (m[t2[i]] == m[t1[i]]) ans0 ++;
		}
	}
	if (m[1]) ans ++;
	printf("%d\n", ans + ans0 / 2);
	
	return 0;
}

Measured memory_bytes: 12032
# YouTube1

def main():
    n = int(input())
    a = [list(map(lambda x: int(x) - 1, input().split()))[::-1] for _ in range(n)]
    #    print(a)
    gam = []  # １日のgames
    # 初期化
    for i in range(n):
        ii = a[i][-1]
        if ii < i: continue
        if a[ii][-1] == i:
            gam.append([i, ii])
    days = 0
    fin = [False] * n
    fin_cnt = 0
    #    print(gam)
    while 1:
        days += 1
        pla = []  # 今日試合があったplayers
        for i, ii in gam:
            a[i].pop()
            a[ii].pop()
            pla.append(i)
            pla.append(ii)
        gam = []
        dec = set()
        for i in pla:
            if fin[i]: continue
            if not a[i]:
                fin[i] = True
                fin_cnt += 1
                if fin_cnt == n:
                    print(days)
                    exit()
                continue
            if i in dec: continue
            ii = a[i][-1]
            if a[ii][-1] == i:
                gam.append([i, ii])
                dec.add(ii)
        if not gam:
            print(-1)
            exit()

main()


Measured memory_bytes: 34676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n, m;
    cin >> n >> m;
    vvint g(n, vint());
    rep(i, m)
    {
        int f, t;
        cin >> f >> t;
        f--;
        t--;
        g[f].emplace_back(t);
        g[t].emplace_back(f);
    }

    queue<int> q;
    q.push(0);
    vint p(n, -1);
    p[0] = 0;
    while (q.size())
    {
        int v = q.front();
        q.pop();
        for (int nv : g[v])
        {
            if (p[nv] != -1)
            {
                continue;
            }
            p[nv] = v;
            q.push(nv);
        }
    }
    cout << "Yes" << endl;
    rep(i, n - 1)
    {
        cout << p[i + 1] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 10108
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

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

  int w = min(B, D) - max(A, C);
  if (C > B || A > D) {
    w = 0;
  }
  if (w < 0) {
    w = 0;
  }
  cout << w << endl;
}

Measured memory_bytes: 256
import sys


def calc(i1, i2):

    a = i1
    b = i2
    if (i1 < i2):
        a = i2
        b = i1
    
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b

    gcd = b
    lcm = (i1 * i2) / gcd

    return gcd, lcm


for line in sys.stdin:
    datas =line.split()
    if (len(datas)):

        li = list(map(int, datas)) 
        a = li[0]
        b = li[1]

        x, y = calc(a, b)

        print("%d %d" % (x, y))

    else:
        break

Measured memory_bytes: 7604
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define coyes cout << "Yes" << endl;
#define cono cout << "No" << endl;
#define coYes cout << "YES" << endl;
#define coNo cout << "NO" << endl;
using namespace std;
using ll = long long int;
string large_al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string small_al = "abcdefghijklmnopqrstuvwxyz";
using Graph = vector<vector<int>>;

int main() {
  string s;
  cin >> s;
  int s_size = s.size();
  int count = 0;
  if (s_size % 2 == 0) {
    rep(i, s_size / 2) {
      if (s.at(i) != s.at(s_size-i-1)) {
        count++;
      }
    }
  }
  else {
    rep(i, s_size / 2) {
      if (s.at(i) != s.at(s_size-i-1)) {
        count++;
      }
    }
  }
  cout << count << endl;
}
    
    
  


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

void push(int);
int pop(void);
void initialize(void);
int isEmpty(void);
int isFull(void);

int top=0,a[101];

int main(){
  int x,x1;
  char s[101];

  initialize();
  while( scanf("%s",s) != EOF ){
    if ( s[0] == '+' ){
      x=pop()+pop();
      push(x);
    } else if ( s[0] == '-' ){
      x=pop();
      x1=pop();
      x = x1 - x;
      push(x);
    } else if ( s[0] == '*' ){
      x=pop()*pop();
      push(x);
    } else {
      x = atoi(s);
      push(x);
    }

  }

  printf("%d\n",a[0]);

  return 0;
}

void push(int x){
  if(isFull()) return;
  a[top]=x;
  top++;
}

int pop(void){
  if(isEmpty()) return isEmpty();
  top--;
  return a[top];
}

void initialize(void){
  top=0;
  a[top]=0;
}

int isEmpty(void){
  return top==0;
}

int isFull(void){
  return top > 100-1;
}

Measured memory_bytes: 548
#include<bits/stdc++.h>
using namespace std;
int ans;
string s;
int main(){
  cin>>s;
  int len=s.length();
  for(int i=0;i<len/2;++i)
    ans+=(s[i]!=s[len-i-1]);
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include "stdio.h"
#include "math.h"

int main()
{
    double r;
    double len;
    double s;

    scanf("%lf",&r);

    if((r < 0) || (r > 10000))
    {
        return 0;
    }

    s = r*r*M_PI;
    len = 2.0*r*M_PI;

   printf("%lf %lf", s, len);

   return 0;
}


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

int main() 
{
	int s,k,ans=0;
	cin>>k>>s;
	for(int i=0;i<=k;i++)
		for(int j=0;j<=k;j++)
			if(s-i-j<=k && s-i-j>=0)
				ans++;
	cout << ans;
	return 0;
}

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

int main() {
  int K, S;
  cin >> K >> S;
  int ans{};
  for (int i{}; i <= K; ++i) {
    for (int j{}; j <= min(K, S - i); ++j) {
      if (S - i - j <= K)
        ++ans;
    }
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
int solve(vector<int>ar,int n,int k){
    vector<int>dp(n+1);
    dp[1] = 0;
    for(int i=2;i<=n;i++){
        dp[i] = inf;
        for(int j = i-1;j>=1 && (i-j) <= k;j--){
            dp[i] = min(dp[i],abs(ar[i] - ar[j]) + dp[j]);
        }
    }
    return dp[n];
    
}
int main(){
    int n,k;
    cin>>n>>k;
    std::vector<int>ar(n+1);
    for(int i=1;i<=n;i++){
        cin>>ar[i];
    }
    cout<<solve(ar,n,k);
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int to, cost; };

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

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

signed main()
{
   int N; cin >> N;
   vec<int> a(N);
   rep(i, 0, N) {
      cin >> a[i];
   }

   SORT(a);
   if (a[N-1] - a[0] > 1) {
      cout << "No" << endl;
      return 0;
   }

   int n = UB(a, a[0]);
   int m = N - n;

   bool ans;
   if (m == 0) {
      ans = (a[0] == N-1 || N/2 >= a[0]);
   } else {
      ans = (m >= 2 &&
             m/2 >= a[0]+1-n &&
             a[0]+1-n >= 1);
   }

   if (ans) {
      cout << "Yes" << endl;
   } else {
      cout << "No" << endl;
   }

   return 0;
}


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

using namespace std;

char s1[110000];
int main(){
	int n,A,B,C;
	bool flag = true;
	cin>>n>>A>>B>>C;
	string s[110000];
	for(int i = 1;i <= n;i++)
	{
		cin>>s[i];
	}
	for(int i =1;i <= n;i++)
	{
		if(s[i]=="AB")
		{
			if(A>B){
				A--;
				B++;
				s1[i]='B';
			}
			else
			if(A<B)
			{
				A++;
				B--;
				s1[i]='A';
			}
			else
			if(A==B)
			{   
				int j = i;
				while(s[j]=="AB")
				{
					j++;
				}
				if(s[j]=="BC")
				{
					B++;
					A--;
					s1[i]='B';
				}
				if(s[j]=="AC")
				{
					A++;
					B--;
					s1[i]='A';
				}
				if(j>n)
				{
					A--;
					B++;
					s1[i]='B';
				}
				
			}
		
		if(A<0||B<0){
			flag = false;
			cout<<"No"<<endl;
			break;
		}
		}
		if(s[i]=="BC")
		{
			if(B>C)
			{
				B--;
				C++;
				s1[i]='C';
			}
			else
			if(B<C)
			{
				C--;
				B++;
				s1[i]='B';
			}
			else
			if(B==C)
			{   
				int j = i;
				while(s[j]=="BC")
				j++;
				if(s[j]=="AB")
				{
					B++;
					C--;
					s1[i]='B';
				}
				if(s[j]=="AC")
				{
					B--;
					C++;
					s1[i]='C';
				}
				if(j>n)
				{
					C++;
					B--;
					s1[i]='C';
				}
				
			}
			if(B<0||C<0)
			{
				cout<<"No";
				flag = false;
				break;
			}
		}
		if(s[i]=="AC")
		{
			if(A<C)
			{
				A++;
				C--;
				s1[i]='A';
			}
			else
			if(A>C)
		    {
		    	A--;
		    	C++;
		    	s1[i]='C';
			}
			else
			if(A==C)
			{  int j = i;
				while(s[j]=="AC")
				{
					j++;
				}
				if(s[j]=="AB")
				{
					A++;
					C--;
					s1[i] = 'A';
			 	}
			 	if(s[j]=="BC")
			 	{
		           A--;
		           C++;
		           s1[i] = 'C';
				}
			    if(j>n)
			    {
			    	A--;
			    	C++;
			    	s1[i]='C';
				}
			}
		  if(A<0||C<0)
		  {
		  	flag = false;
		  	cout<<"No"<<endl;
		  	break;
		  }
		}
		
	}
   if(flag ==true)
   {cout<<"Yes"<<endl;
   	for(int i = 1;i<= n;i++)
   	  cout<<s1[i]<<endl;
   }
   return 0;
}

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

typedef long long ll;
constexpr ll MOD = ll(1e9+7);

ll dp[200005][2][2];

int main(){
    string s, t;
    cin >> s >> t;
    int n = s.size();
    dp[0][0][1] = 1;
    for(int i=0;i<n;i++){
        int sd = s[i]-'0';
        if(t[i]=='?'){
            for(int j=0;j<2;j++){
                for(int d=0;d<=(j?9:sd);d++){
                    dp[i+1][j||(sd>d)][0] += dp[i][j][0] * 10 + dp[i][j][1] * d;
                    dp[i+1][j||(sd>d)][0] %= MOD;
                    dp[i+1][j||(sd>d)][1] += dp[i][j][1];
                    dp[i+1][j||(sd>d)][1] %= MOD;
                }
            }
        }
        else{
            int td = t[i]-'0';
            for(int j=0;j<2;j++){
                if(sd < td &&j == 0) continue;
                dp[i+1][j||(sd>td)][0] += dp[i][j][0] * 10 + dp[i][j][1] * td;
                dp[i+1][j||(sd>td)][0] %= MOD;
                dp[i+1][j||(sd>td)][1] += dp[i][j][1];
                dp[i+1][j||(sd>td)][1] %= MOD;
            
            }
        }
    }
    ll ans = 0;
    ans = (dp[n][1][0] + dp[n][0][0]) % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9764
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	string s, t; cin >> s >> t;
    int n = (int)s.size();
    for(int i = 0; i < n; ++ i) {
        if(s == t) {
            cout << "Yes" << endl;
            return;
        }
        s = s.back() + s.substr(0, n - 1);
    }
    cout << "No" << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3552
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

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

    cout << *s.begin() << s.size() - 2 << *s.rbegin() << endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N;
    cin>>N;
    string S[3];
    rep(i,3)cin>>S[i];


    int ans=0;
    rep(j,N){
        set<char>s;
        rep(i,3){
            s.insert(S[i][j]);
        }
        ans+=s.size()-1;
    }
    cout<<ans<<endl;
    return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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; }

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n;
	cin >> n;

	int sum = 0;
	int num = n;
	while(num != 0){
		sum += num % 10;
		num /= 10;
	}

	cout << (n % sum == 0 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

ll c[5][5], cpr[5][5];
ll a[3],b[3];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  rep(i,3)rep(j,3){
    cin >> c[i][j];
  }

  
  rep(i,c[0][0]+1)rep(j,c[1][1]+1)rep(k,c[2][2]+1){
    a[0]=i, a[1] = j, a[2] = k;
    b[0]=c[0][0]-a[0];
    b[1]=c[1][1]-a[1];
    b[2]=c[2][2]-a[2];

    bool flag = true;
    rep(m,3)rep(n,3){
      if(c[m][n] != a[m]+b[n]){
	m=4,n=4;
	flag = false;
      }
    }
    if(flag){
      cout <<"Yes" << endl;
      return 0;
    }
  }
  cout <<"No" << endl;
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


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

#define Set(n,pos) (n|(1<<pos))
#define reset(n,pos) (n&~(1<<pos))
#define check(n,pos) (bool)(n&(1<<pos))
int s[16],t[16],n;
int main(int argc, char const *argv[])
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int a,x,y;
		scanf("%d",&a);
		for(int j=0;j<a;j++)
		{
			scanf("%d %d",&x,&y);
			s[i]=Set(s[i],x-1);
			if(y)t[i]=Set(t[i],x-1);
		}
	}
	int ma=0;
	for(int p=1;p<(1<<n);p++)
	{
		int ff=1;
		for(int i=0;i<n;i++)
		{
			if(check(p,i))
			{
				for(int j=0;j<n;j++)
				{
					if(check(s[i],j))
					{
						if(check(p,j)!=check(t[i],j))
						{
							ff=0;
							break;
						}
					}
				}
			}
			if(!ff)break;
		}
		if(ff)ma=max(ma,__builtin_popcount(p));
	}
	printf("%d\n",ma);
	return 0;
}

Measured memory_bytes: 256
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long llong;
#define int llong
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int x,n,l;
vs in;
int f(int a){
	if(!a)return 0;
	rep(i,99)if(a&1<<i)return 1<<i;
}
void dfs(int a,int L,int R){
	if(R<=L)return;
	if(L+1==R&&in[L].size()==a)return;
	int t=R;
	loop(i,L,R)if(in[i][a]=='1'){
		t=i;break;
	}
	if(t==L)x^=f(l-a);
	if(t==R)x^=f(l-a);
	dfs(a+1,L,t);
	dfs(a+1,t,R);
}
signed main(){
	cin>>n>>l;
	in=vs(n);
	rep(i,n)cin>>in[i];
	sort(all(in));
	dfs(0,0,n);
	if(x)cout<<"Alice"<<endl;
	else cout<<"Bob"<<endl;
}















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

#define loop(i, x, y) for (i = x; i < y; i++)
#define loopr(i, x, y) for (i = x; i > y; i--)

//use *it instead of it
#define vloop(it, x) for (auto it = x.begin(); it != x.end(); it++)
#define vloopr(it, x) for (auto it = x.end() - 1; it != x.begin() - 1; it--)

#define yes printf("YES\n")
#define no printf("NO\n")
#define pb push_back
#define mp make_pair

#define debug(x) cerr << #x << ":" << x << endl
#define yo cerr << "yo" << endl

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;

const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;

#define test(t) \
    ll t;       \
    cin >> t;   \
    while (t--)

//use double
#define precision(x)       \
    cout.setf(ios::fixed); \
    cout << setprecision(10) << x << endl;

// ll gcd(ll x_f, ll y_f)
// {
//     if (x_f == 0)
//         return y_f;
//     return gcd(y_f % x_f, x_f);
// }

// ll power(ll x_f, ll y_f, ll m_f)
// {
//     ll res_f = 1;

//     x_f = x_f% m_f;
//     while (y_f)
//     {
//         if (y_f & 1)
//             res_f = (res_f * x_f) % m_f;
//         y_f = y_f >> 1;
//         x_f = (x_f * x_f) % m_f;
//     }
//     return res_f;
// }

// ll less(ll x_f, ll y_f)
// {
//     return (x_f > y_f) ? y_f : x_f;
// }
// ll more(ll x_f, ll y_f)
// {
//     return (x_f < y_f) ? y_f : x_f;
// }

ll fac(ll x_f)
{
    ll fac_f = 1;
    for (ll i = 1; i <= x_f; i++)
    {
        fac_f *= i;
        fac_f = fac_f % MOD;
    }
    return fac_f;
}

bool composite[1000007] = {false};
void seive(ll x)
{
    composite[0] = true;
    composite[1] = true;
    for (ll i = 2; i <= x; i++)
    {
        if (!composite[i])
        {
            for (ll j = 2 * i; j <= x; j += i)
            {
                composite[j] = true;
            }
        }
    }
}

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

    char s[1007], t[1007];
    cin >> s;
    ll len = strlen(s);
    if (s[len - 1] == 's')
    {
        // s[len] = 'e';
        // s[len + 1] = 's';
        // s[len + 2] = '\0';
        strcat(s, "es");
    }
    else
    {
        // s[len] = 's';
        // s[len + 1] = '\0';
        strcat(s, "s");
    }

    cout << s;
    return 0;
}

Measured memory_bytes: 3648
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')




def solve():
    n = f()[0]
    s = input()

    ans = 0
    for i in range(n):
        ans = max(ans, len(set(s[:i])&set(s[i:n])))
    print(ans)

solve()


Measured memory_bytes: 3060
import sys
N = int(input())
A=list(map(int,input().split()))
A.sort()
maxi=10**18
ans=1
for i in A:
    ans*=i
    if ans==0:
        print(0)
        sys.exit()
    if ans>maxi:
        print(-1)
        sys.exit()
print(ans)

Measured memory_bytes: 84692
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
			while(sc.hasNext()) {
				int R=sc.nextInt();
				int W=sc.nextInt();
				int C=sc.nextInt();
				int r=sc.nextInt();
				if(R==0 && W==0 && C==0 && r==0) {
					break;
				}
				int a=0;
				for(int i=0;; i++) {
					if(W*C<=R+r*i) {
						a=i;
						break;
					}
				}
				System.out.println(a);
			}
		
	}
}


Measured memory_bytes: 26268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,x;
  cin >> n >> x;
  int dist = 0;
  vector<int> ls;
  ls.push_back(0);
  while(n>0){
    int l;
    cin >> l;
    dist+=l;
    ls.push_back(dist);
    n--;
  }
  int ans = 0;
  for(auto l:ls){
    if(l<=x) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{	
	int n,a[3005],i;
	while(scanf("%d",&n)!=EOF){
		int s=0;
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(i=0;i<n;i++)
			s=s+a[i]-1;
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i;
  vector<int> a(n);
  for(i=0;i<n;i++) cin >> a[i];
  vector<bool> b(8);
  int cnt = 0;
  for(i=0;i<n;i++){
    if(a[i]>=3200) cnt++;
    else if(a[i]>=2800) b[0]=true;
    else if(a[i]>=2400) b[1]=true;
    else if(a[i]>=2000) b[2]=true;
    else if(a[i]>=1600) b[3]=true;
    else if(a[i]>=1200) b[4]=true;
    else if(a[i]>=800) b[5]=true;
    else if(a[i]>=400) b[6]=true;
    else if(a[i]>=1) b[7]=true;
  }
  int cnt2 = 0;
  for(i=0;i<8;i++) if(b[i] == true) cnt2++;
  if(cnt2==0) cout << 1 << "\n";
  else cout << cnt2 << "\n";
  cout << cnt2+cnt << "\n";
  return 0;
}   

Measured memory_bytes: 256
H, W, K = map(int, input().split())
cw = []
black_all = 0
for _ in range(H):
  s = input()
  cw.append(s)
  black_all += s.count("#")

ans = 0
for i in range(2 ** H):
  for j in range(2 ** W):
    bl = black_all
    for h in range(H):
      for w in range(W):
        if cw[h][w] == "#" and ((i // (2 ** h)) % 2 == 1 or (j // (2 ** w)) % 2 == 1):
          bl -= 1
    if bl == K:
      ans += 1
print(ans)

Measured memory_bytes: 9184
#include <iostream>
#include <algorithm>

using namespace std;

#define MAX_M 16
#define MAX_N 20010
#define INF 1e8

int N, M, C[MAX_M], x[MAX_N];
int dp[MAX_N][256];

int main(){
  while(cin >> N >> M , (N | M)){
    for(int i = 0 ; i < M ; i++){
      cin >> C[i];
    }
 
    for(int i = 1 ; i <= N ; i++){
      cin >> x[i];
    }
    int ans = INF;
    fill(dp[0], dp[MAX_N], INF);
    dp[0][128] = 0;
    for(int i = 1 ; i <= N ; i++){
      for(int j = 0 ; j <= 255 ; j++){
        for(int k = 0 ; k < M ; k++){
          int t = j + C[k];
          if(t < 0) t = 0;
          if(t > 255) t = 255;
          dp[i][t] = min(dp[i][t], dp[i-1][j] + (t-x[i])*(t-x[i]));
        }
      }
    }
    for(int i = 0 ; i <= 255 ; i++){
      ans = min(ans, dp[N][i]);
    } 
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 21248
n = int(input())
ps = [int(i) for i in input().split()]

cnt = 0
for i in range(len(ps) - 2):
    if ps[i] < ps[i+1] <= ps[i+2] or ps[i] >= ps[i+1] > ps[i+2]:
        cnt += 1

print(cnt)

Measured memory_bytes: 3060
s = input()
k = int(input())

alph = "abcdefghijklmnopqrstuvwxyz"
memo = {}
for i, char in enumerate(alph):
    memo[char] = 26 - i
memo["a"] = 0

ans = []
for char in s:
    if memo[char] <= k:
        ans.append("a")
        k -= memo[char]
    else:
        ans.append(char)
ans[-1] = alph[(26 - memo[ans[-1]] + k) % 26]
print("".join(map(str, ans)))

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

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

    while(true){
        int h, w;
        std::cin >> h >> w;
        if(h==0 && w==0) break;
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                std::cout << ((i==0 || i==h-1 || j==0 || j==w-1)?"#":".");
            }
            std::cout << "\n";
        }
        std::cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 3104
# -*- coding: utf-8 -*-

NUMS = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(NUMS[int(input())-1])


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;

//逆元(素数MOD)
long long inverse(long long b){
    /*
    Copyright (c) 2020 0214sh7
    https://github.com/0214sh7/library/
    */
  long long r=1,e=MOD-2;
  while(e){
      if(e&1){
          r=(r*b)%MOD;
      }
      b=(b*b)%MOD;
      e >>=1;
  }
  return r;
}

signed main(void){
    
    long long S;
    long long Ans=0;
    cin >> S;
    
    for(long long i=1;i<=S/3;i++){
        //iは数列の長さ
        //自由に割り振れるのはremain個
        long long remain = S - 3*i;
        
        //長さiの数列で条件を満たすのはcomb(M+i-1,M)個
        long long num = 1;
        for(long long j=1;j<=i-1;j++){
            num = (num*(remain+i-j))%MOD;
            num = (num*inverse(j))%MOD;
        }
        
        Ans = (Ans+num)%MOD;
        
    }
    cout << Ans << endl;
    
    return 0;
}


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

#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <ll> vi;
typedef vector<vi> vvi;
typedef pair <ll, ll> ii;
typedef pair<ll, pair<ll,ll> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

ll n,w;
ll dp[100001][101]; 

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
	cin>>n>>w;
	ll ww[n+1],vv[n+1];
	for(ll i=1;i<=n;i++)
	{
	  cin>>ww[i]>>vv[i];	
	}
	for(ll j=1;j<=n;j++)
	{
		for(ll i=0;i<=w;i++)
		{
			dp[i][j] = dp[i][j-1];
		}
		for(ll i=0;i<=w;i++)
		{
			if((i-ww[j])>=0)
			{
			  ll temee= dp[i-ww[j]][j-1] + vv[j];
			  dp[i][j] = max(dp[i][j],temee);
		    }
		}
	}
	ll ans = 0;
	for(ll i=0;i<=w;i++)
	{
		ans = max(ans,dp[i][n]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 79232
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include<algorithm>
#include <iomanip>
#include <math.h>

using namespace std;
typedef long long ll;
///定義場所///
int i, j, k, l, m, n;
int N, M, K;
ll MOD = 1000000007;
int ans = 0;

//関数リスト//
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
//(注)pairの型・比較する場所(first/second)は毎回変えて使用する
bool pairCompare(const pair<int ,int> firstElof, pair<int,int> secondElof)
{
	return firstElof.second > secondElof.second;
}
int Keta(ll F) {
	int keta = 1;
	while (F/10 > 0) {
		keta++;
		F /= 10;
	}
	return keta;
}
//////////////

int main()
{
	int P, Q, R;
	cin >> P >> Q >> R;
	if (P >= Q && P >= R) {
		cout << Q + R;
	}
	else if (Q >= P && Q >= R) {
		cout << P + R;
	}
	else {
		cout << P + Q;
	}
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

const int mod = (int) 1e9 + 7;

int mul(int a, int b) {
  return (long long) a * b % mod;
}

void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

const int maxn = (int) 1e7 + 5, maxa = 5005;
int f[maxn], inv[maxn], finv[maxn];

void precalc() {
  f[0] = 1;
  for (int i = 1; i < maxn; i++) {
    f[i] = mul(f[i - 1], i);
  }
  inv[1] = 1;
  for (int i = 2; i < maxn; i++) {
    inv[i] = (mod - (long long) (mod / i) * inv[mod % i] % mod) % mod;
  }
  finv[0] = 1;
  for (int i = 1; i < maxn; i++) {
    finv[i] = mul(finv[i - 1], inv[i]);
  }
}

int n, a;

bool read() {
  if (scanf("%d%d", &n, &a) < 2) {
    return false;
  }
  return true;
}

int dp[maxa][maxa];
int cnt[maxa][maxa];

void solve() {
  for (int j = 0; j <= a; j++) {
    cnt[a][j] = 0;
  }
  for (int i = a - 1; i >= 0; i--) {
    for (int j = 0; i + j <= a; j++) {
      auto &cur = cnt[i][j];
      if (!j) {
        cur = mul(f[n - i - 1], finv[a - i - 1]);
        continue;
      }
      cur = cnt[i][j - 1];
      add(cur, mod - cnt[i + 1][j - 1]);
    }
  }
  memset(dp, 0, sizeof(dp));
  add(dp[a][0], f[a]);
  add(dp[a - 1][0], mod - f[a]);
  int res = 0;
  for (int i = a; i >= 0; i--) {
    for (int j = 0; j <= a; j++) {
      {
        auto &cur = dp[i][j];
        add(cur, dp[i + 1][j]);
        if (!cur) {
          continue;
        }
      }
      auto cur = dp[i][j];
      cur = mul(cur, finv[i]);
      int val = mul(cur, f[max(0, i - 1)]);
      add(res, mul(val, cnt[i][j]));
      if (!i) {
        continue;
      }
      add(dp[i - 1][j + 1], val);
      if (i >= 2) {
        add(dp[i - 2][j + 1], mod - val);
        add(dp[i - 2][j], val);
      }
    }
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 285724