akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<(#a)<<':'<<(a)<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

bool isOk(ll key,ll value){
  return key < value;
}

int binary_search(vector<ll> a,ll key){
  ll ok = a.size();
  ll ng = -1;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  string str;cin>>str;
  vector<char> chars;
  int ans = 0;
  rep(i,n){
    int tmp = 0;
    vector<char> tmpc;
    bool exist = false;
    rep(j,chars.size()){
      exist |= (chars[j] == str[i]);
    }
    if(!exist)chars.pb(str[i]);

    for(int j = i+1;j < n;++j){
      rep(k,chars.size()){
        if(str[j] == chars[k]){
          exist = false;
          rep(l,tmpc.size()){
            exist |= tmpc[l] == chars[k];
          }
          if(exist)break;
          tmp++;
          tmpc.pb(chars[k]);
        }
      }
    }
    ans = max(tmp,ans);
  }
  print(ans);
  return 0;
} 


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>

#include <algorithm>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <string>
#include <unistd.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define INF (1 << 30)
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back

#if DEBUG
#define _DEBUG(x) cout << #x << ": " << x << endl
#define _DDEBUG(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl
#else
#define _DEBUG(x) ;
#define _DDEBUG(x, y) ;
#endif

#define ll long long
#define ull unsigned long long
#define MOD 1000000007

/** FOR VECTOR DEBUG */
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  if (!v.empty()) {
    out << '[';
    copy(v.begin(), v.end(), ostream_iterator<T>(out, ", "));
    out << "\b\b]";
  }
  return out;
}

/* template end */

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

  int N, K;
  cin >> N >> K;

  deque<int> v(N);
  REP(i, N) { cin >> v[i]; }

  int ans = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= (K - i); j++) {
      vector<int> a;
      int cnt = 0;
      for (int l = 0; l < i; l++) {
        if (l < N) {
          a.push_back(v[l]);
          cnt++;
        } else {
          break;
        }
      }
      int limit = max(0, i);
      for (int l = 0; l < j; l++) {
        if (N - 1 - l >= limit) {
          a.push_back(v[N - 1 - l]);
          cnt++;
        } else {
          break;
        }
      }
      sort(a.begin(), a.end());
      int gomi = K - cnt;
      int tans = 0;
      for (int l = 0; l < a.size(); l++) {
        if (a[l] < 0 && gomi > 0) {
          gomi--;
        } else {
          tans += a[l];
        }
      }
      ans = max(ans, tans);
    }
  }

#if DEBUG
  cout << "** RESULT **" << endl; // debug
#endif
  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<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N,T;
    cin >> N >> T;
    vector<ll> A(N), B(N), C(N+1);
    rep(i,N){
        cin >> A[i] >> B[i];
    }
    vector<vector<ll>> dp(N+1, vector<ll>(T+1)), dp2(N+1, vector<ll>(T+1));
    rep(i,N){
        rep(j,T){
            if(j+A[i] <= T){
                dp[i+1][j+A[i]]=max(dp[i+1][j+A[i]], dp[i][j]+B[i]);
            }
            dp[i+1][j+1]=max(dp[i+1][j+1], dp[i+1][j]);
            dp[i+1][j+1]=max(dp[i+1][j+1], dp[i][j+1]);
        }
    }
    for(ll i=N;i>0;i--){
        rep(j,T){
            if(j+A[i-1] <= T){
            	dp2[i-1][j+A[i-1]]=max(dp2[i-1][j+A[i-1]], dp2[i][j]+B[i-1]);
            }
            dp2[i-1][j+1]=max({dp2[i-1][j+1], dp2[i][j+1], dp2[i-1][j]});
        }
    }
    ll ans = 0;
    REP(i,0,N){
        rep(j,T){
            cmax(ans, dp[i][j] + B[i] + dp2[i+1][T-1-j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 144160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
constexpr int INF = 1e9, MOD = 1e9 + 7;
constexpr int64_t LINF = 5e18, LMOD = 998244353;
// #include <atcoder/all>
// using namespace atcoder;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int64_t n; cin >> n;
	int ans = 0;
	for(int64_t a = 1; a <= n; ++a) {
		for(int64_t b = 1; a * b < n; ++b) {
			int64_t c = n - a * b;
			if(c > 0) ++ans;
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

void solve()
{
	int N;
	cin>>N;

	vector<ll>V;

	for(int i = 0; i < N; i++)
	{
		ll inp;
		cin>>inp;
		V.pb(inp);
	}

	int count = 0;

	for(int i = 0; i < N ; i++)
	{
		for(int j = i + 1; j < N ; j++)
		{
			for(int k = j + 1; k < N ; k++)
			{
				if(V[i] + V[j] > V[k] && V[i] + V[k] > V[j] && V[k] + V[j] > V[i] && (V[i] != V[j]) && (V[k] != V[j]) && (V[k] != V[i])) 
				{
					//cout<<V[i]<<" "<<V[j]<<" "<<V[k]<<endl;
					count++;
				}
			}
		}
	}

	cout<<count<<endl;
}

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

	solve();

	return 0;
} 

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
 
int main(){
  ll a, b, k;
  cin >> a >> b >> k;

  if(a>k)        cout << a-k << " " << b     << endl;
  else if(b>k-a) cout << 0   << " " << a+b-k << endl;
  else           cout << 0   << " " << 0     << endl;
  
  return 0;
}


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

int main(){
    long long h, w, ans;
    cin >> h >> w;
    if(h==1 || w==1) ans=1;
    else if(h%2==1 && w%2==1) ans=h*w/2+1;
    else ans=h*w/2;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] L = new int[N+1];
		for (int i = 1; i <= N; i++) {
			L[i] = sc.nextInt();
		}

		sc.close();

		int ans = 1;
		int d = 0;

		for (int i = 2; i <= N+1; i++) {
			d = d + L[i-1];
			if(d<=X) {
				ans++;
			}
		}

		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 21844
n=int(input())
a=[int(input()) for i in range(n)]

al= {}
ans=0
for ai in a:
  if ai - 1 in al.keys():
    al[ai]=al[ai-1]+1
    ans=max(ans,al[ai-1]+1)   
    del al[ai-1]
  else:
    al[ai]=0
    if ai + 1 in al.keys():
      del al[ai]
print(n-ans-1)

Measured memory_bytes: 20260
import java.util.*;
	
	public class Main {
	    public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        int n = sc.nextInt();
	        Set<String> set = new HashSet<>();
			while(n-->0) set.add(sc.next());
			System.out.println(set.size());
	}
}
	

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

string words[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
  string S;
  cin >> S;
  
  reverse(S.begin(), S.end());
  for(int i = 0; i < 4; i++){
    reverse(words[i].begin(), words[i].end());
  }
  
  bool can = true;
  
  for(int i = 0; i < S.size();){
    bool can2 = false;
    for(int j = 0; j < 4; j++){
      string d = words[j];
      if(S.substr(i, d.size()) == d){
        can2 = true;
        i += d.size();
      }
    }
    if(!can2){
      can = false;
      break;
    }
    
  }
  
  if(can) cout << "YES" << endl;
  if(!can) cout << "NO" << endl;
}






Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l,A[200005],dp[200005][22],maxx;
int main() {
           cin>>a>>b>>c>>d;
           while(true) {
                      c-=b;
                      if(c<=0) { cout<<"Yes"; return 0; }
                      a-=d;
                      if(a<=0) { cout<<"No"; return 0; }
           }
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N;
    cin >> N;
    cout << ((999 + N) / 1000) * 1000 - N << '\n';
}

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


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

int main(){
  int H, W;
  cin >> H >> W;
  string x(W+2, '#');
  vector<vector<char>> v(H, vector<char>(W));

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> v.at(i).at(j);
    }
  }

  for(int i = 0; i < W+2; i++){
    cout << '#';
  }
  cout << endl;
  for(int i = 0; i < H; i++){
    cout << '#';
    for(int j = 0; j < W; j++){
      cout << v.at(i).at(j);
    }
    cout << '#' << endl;
  }
  for(int i = 0; i < W+2; i++){
    cout << '#';
  }

  return 0;
}


Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func solve(N, K int) int {
	ans := 0
	for i := 1; i <= N; i++ {
		if i >= K {
			ans += N / i * (i - K)
			ans += max(0, N%i-K+1)
		}
	}
	return ans
}

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

	N, K := getInt(), getInt()

	if K == 0 {
		out(N * N)
		return
	}
	out(solve(N, K))
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>

int n;
char str[16][12];
int nstr[16][10];
int flag[27],flag2[27];
int cnt,nz[11],num[27],used[11],len[11],all;

void dfs(int v){
	if(v!=all){
		for(int i=0;i<=9;i++){
			if(i==0 && nz[v]==1)continue;
			if(!used[i]){
				used[i]=1;
				num[v]=i;
				dfs(v+1);
				used[i]=0;
			}
		}
	}else{
		int ans=0,nownum=0;
		for(int j=0;j<len[n-1];j++){
			ans=ans*10+num[nstr[n-1][j]];
		}
		for(int i=0;i<n-1;i++){
			nownum=0;
			for(int j=0;j<len[i];j++){
				nownum=nownum*10+num[nstr[i][j]];
			}
			ans-=nownum;
			if(ans<0)break;
		}
		if(ans==0)cnt++;
	}
}
int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		all=cnt=0;
		memset(flag,0,sizeof(flag));
		memset(nz,0,sizeof(nz));
		memset(flag2,0,sizeof(flag2));
		for(int i=0;i<n;i++){
			scanf("%s",str[i]);
			len[i]=strlen(str[i]);
			for(int j=0;j<len[i];j++){
				flag[str[i][j]-'A']=1;
				if(j==0 && len[i]>1)flag2[str[i][j]-'A']=1;
			}
		}
		for(int i=0;i<26;i++){
			if(flag[i]){
				num[i]=all;
				if(flag2[i])nz[all]=1;
				all++;
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<len[i];j++){
				nstr[i][j]=num[str[i][j]-'A'];
			}
		}
		dfs(0);
		printf("%d\n",cnt);
	}
	return 0;
}

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

using namespace std;

int main()
{
    long n,i;
    cin>>n;
    double a[n],min=0,sum=0,diff=0;
    double avg=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        sum = sum + a[i];
    }
    avg = round(sum/n);
    //cout<<avg<<" ";
    for(i=0;i<n;i++)
    {
        diff = a[i] - avg;
        min =min + (diff*diff);
    }
    cout<<min;


    return 0;
}


Measured memory_bytes: 256
ls=["AC","TLE","RE","WA"]
n=int(input())
a=b=c=d=0
for i in range(n):
  s=input()
  if s==ls[0]:
    a+=1
  elif s==ls[1]:
    b+=1
  elif s==ls[2]:
    c+=1
  else:
    d+=1
print(ls[0]+" x",a)
print(ls[3]+" x",d)
print(ls[1]+" x",b)
print(ls[2]+" x",c)

Measured memory_bytes: 9144
x, y = map(int, input().split())
X, Y = abs(x), abs(y)

if x == y:
    print(0)
elif x*y == 0:
    if x > y:
        print(X+Y+1)
    else:
        print(X+Y)
elif x*y > 0:
    if x > y:
        print(abs(x-y)+2)
    else:
        print(abs(x-y))
else:
    print(abs(x+y)+1)


Measured memory_bytes: 3060
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, q; cin >> n;
    string s; cin >> s;
    cin >> q;
    vll k(q);
    for (ll i = 0; i < q; i++) cin >> k[i];

    for (ll _q = 0; _q < q; _q++) {
        ll tmpk = k[_q];
        ll cntd = 0, cntm = 0, cntdm = 0;
        ll ans = 0;
        for (int j = 0; j < s.size(); j++) {
            if (s[j] == 'D') cntd++;
            else if (s[j] == 'M') {
                cntdm += cntd;
                cntm++;
            } else if (s[j] == 'C') ans += cntdm;

            if (j - tmpk + 1 >= 0) {
                if (s[j - tmpk + 1] == 'M') cntm--;
                else if (s[j - tmpk + 1] == 'D') cntd--, cntdm -= cntm;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}


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

int main()
{
    int n1, n2, n3, mayor, suma, auxiliar,maximo,aux2;
    cin>>n1 >> n2>> n3;

    if ( n3>=n2 && n3>=n1 ){
        mayor=n3;
        auxiliar=n1+n2;
        aux2=mayor-1;
        if(auxiliar>=aux2){
            maximo=n3+n2;
        }
        else{
             maximo=auxiliar+1+n2;
        } 
    }
    else{
        maximo=n3+n2;
    }
    
    cout<<maximo;

}

Measured memory_bytes: 3588
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
ans = 0

for i in range(n):
    if i > 0 and b[i-1] != 0:
        if a[i] > b[i-1]:
            ans += b[i-1]
            a[i] = a[i] - b[i-1]
        elif a[i] > 0:
            ans += a[i]
            a[i] = 0
    if a[i] <= 0:
        continue
    elif a[i] > b[i]:
        ans += b[i]
        b[i] = 0
    else:
        ans += a[i]
        b[i] = b[i] - a[i]

if b[n-1] != 0:
    if a[n] > b[n-1]:
        ans += b[n-1]
    else:
        ans += a[n]

print(ans)


Measured memory_bytes: 19648
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
int main()
{
    char ss[5][5];
    int i,j,k=0;
    for(i=0;i<2;++i)
    scanf("%s",ss[i]);
    for(i=0;i<2;++i)
    {
        for(j=0;j<3;++j)
        {
            if(ss[i][j]!=ss[1-i][2-j])
            {
                k=1;
                break;
            }
        }
    }
    if(k)
        printf("NO\n");
    else printf("YES\n");
 return 0;
}


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

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int map[21][21];
int x;
int y;
int sum;

void move(int dir,int dd){
  for(int i=1;i<=dd;i++){
    x += dx[dir];
    y += dy[dir];
    if (map[x][y]==1){
      map[x][y]=0;
      sum+=1;
    }
  }
}


int maindo(void){
  sum=0;
  x=10;
  y=10;
  for(int s=0;s<21;s++){
    for(int t=0;t<21;t++){
      map[s][t]=0;
    }
  }
  int n,m;
  cin >> n;
  if (n==0) return 0;
  for(int i=0;i<n;i++){
    int s,t;
    cin >> s >> t;
    map[s][t]=1;
  }
  cin >> m;
  for(int i=0;i<m;i++){
    string dir;
    int dirint;
    int dd;
    cin >> dir >> dd;
    if (dir=="E") dirint=0;
    else if(dir=="N") dirint=1;
    else if(dir=="W") dirint=2;
    else if(dir=="S") dirint=3;
    move(dirint,dd);
  }
  if (sum==n) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 1;
}

int main(){
  while(1){
    int k=maindo();
    if (k==0) return 0;
  }
}

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

int main(void){
	int n, m;
	while(1){
		cin >> n >> m;
		if(!n&&!m) break;
		vector<int> c(m), x(n);
		for(int i = 0; i < m; ++i){
			cin >> c[i];
		}
		for(int i = 0; i < n; ++i){
			cin >> x[i];
		}
		vector<vector <int>> dp(n+2);
		for(int i = 0; i < n+2; ++i){
			dp[i].resize(256);
			for(int j = 0; j < 256; ++j){
				dp[i][j] = INT_MAX;
			}
		}
		dp[0][128]=0;
		for(int i = 1; i <= n; ++i){
			for(int j = 0; j < m; ++j){
				for(int k = 0; k < 256; ++k){
					if(dp[i-1][k]==INT_MAX) continue;
					int next = k+c[j];
					if(next > 255) next = 255;
					if(next < 0) next = 0;
					dp[i][next] = min(dp[i][next], dp[i-1][k] + (int)pow(x[i-1]-next,2));
				}
			}
		}
		int ans = INT_MAX;
		for(int i = 0; i < 256; ++i){
			ans = min(ans, dp[n][i]);
			//cout << dp[n][i] << " ";
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 23768
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int N;
	long[][] A, dist;
	long result = 0;

	static class Edge {
		int src, dst;
		long length;

		Edge(int src, int dst, long length) {
			this.src = src;
			this.dst = dst;
			this.length = length;
		}
	}

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		A = new long[N][N];
		dist = new long[N][N];
		for (int i = 0; i < N; ++i) {
			String[] tokens = in.readLine().split(" ");
			for (int j = 0; j < N; ++j) {
				A[i][j] = Long.parseLong(tokens[j]);
				dist[i][j] = A[i][j];
			}
		}
	}

	/**
	 * ワーシャルフロイドで最短距離を求める
	 */
	void calcDist() {
		for (int k = 0; k < N; ++k) {
			for (int i = 0; i < N; ++i) {
				for (int j = 0; j < N; ++j) {
					dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}
	}

	boolean isNecessary(Edge edge) {
		boolean necessary = true;
		for (int i = 0; i < N; ++i) {
			if (i == edge.src || i == edge.dst) {
				continue;
			} else if (edge.length == dist[edge.src][i] + dist[i][edge.dst]) {
				necessary = false;
				break;
			}
		}
		return necessary;
	}

	void calc() {
		calcDist();
		Queue<Edge> que = new PriorityQueue<>(new Comparator<Edge>() {
			@Override
			public int compare(Edge o1, Edge o2) {
				return Long.compare(o1.length, o2.length);
			}
		});
		for (int i = 0; i + 1 < N; ++i) {
			for (int j = i + 1; j < N; ++j) {
				que.add(new Edge(i, j, A[i][j]));
			}
		}
		while (!que.isEmpty()) {
			Edge edge = que.poll();
			if (dist[edge.src][edge.dst] == edge.length) {
				if (isNecessary(edge)) {
					result += edge.length;
				}
			} else {
				result = -1;
				break;
			}
		}
	}

	void showResult() {
		System.out.println(result);
	}
}

Measured memory_bytes: 47876
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

vector<ll> groupcounter(100005,0);
ll groups=0;
void dfs(ll n, ll groups,vvl &friendlist, vector<ll> &whichgroup){
    whichgroup[n]=groups;
    groupcounter[groups]++;
    for(ll i=0;i<friendlist[n].size();i++){
        ll k=friendlist[n][i];
        if(whichgroup[friendlist[n][i]]==-1)
        dfs(k,groups,friendlist,whichgroup);
    }
}

int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    ll K;
    cin >> K;
    vector<ll> A(M,0);
    vector<ll> B(M,0);
    vector<ll> C(K,0);
    vector<ll> D(K,0);

    for(ll i=0;i<M;i++){
        cin>>A[i]>>B[i]
    ;}
    for(ll i=0;i<K;i++){
        cin>>C[i]>>D[i]
    ;}
    vector<vector<ll>> friendlist(N+1, vector<ll>(0));
    for(ll i=0;i<M;i++){
        friendlist[A[i]].emplace_back(B[i]);
        friendlist[B[i]].emplace_back(A[i])
    ;}

    vector<ll> whichgroup(N+1,-1);

    for(ll i=1;i<N+1;i++){
        if(whichgroup[i]==-1){
            groups++;
            dfs(i,groups,friendlist,whichgroup);
        }
    ;}
    vector<ll> ans(N+1,0);

    for(ll i=1;i<=N;i++){
        ans[i]=groupcounter[whichgroup[i]]-1
    ;}
    for(ll i=0;i<M;i++){
        if(whichgroup[A[i]]==whichgroup[B[i]]){
            ans[A[i]]--;
            ans[B[i]]--;
        }
    ;}
    for(ll i=0;i<K;i++){
        if(whichgroup[C[i]]==whichgroup[D[i]]){
            ans[C[i]]--;
            ans[D[i]]--;
        }
    ;}
    for(ll i=1;i<N+1;i++){
        cout<<ans[i];
        if(i<N)cout<<" ";
    ;}
    cout<<endl;


return 0;
}


Measured memory_bytes: 13312
def nCk(n, k, mod):
    nu = 1
    de = 1 
    for i in range(1, k+1):
        nu *= (n-i+1)
        de *= i
        nu = nu % mod
        de = de % mod
    ans = nu * pow(de, mod-2, mod) % mod
    return ans

n, a, b = map(int, input().split())
mod = 10**9+7
ans = (pow(2, n, mod) - 1 - nCk(n, a, mod) - nCk(n, b, mod)) % mod
print(ans)

Measured memory_bytes: 9204
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define repit(i,a) for(__typeof((a).begin()) i=(a).begin();i!=(a).end();i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

const int N = 210;
const double eps = 1e-8;

typedef complex<double> point;

int n;
double x[N], y[N], r[N], d[N][N];
point c[N], p[N];

void generate()
{
    rep(i, n) c[i] = point(x[i], y[i]);

    p[0] = c[0];
    rep(i, n - 1) {
        double d = abs(c[i + 1] - c[i]);
        double th = arg(c[i + 1] - c[i]);
        double dth = acos((r[i] * r[i] + d * d - r[i + 1] * r[i + 1]) / (2 * r[i] * d));
        p[2 * i + 1] = c[i] + polar(r[i], th - dth);
        p[2 * i + 2] = c[i] + polar(r[i], th + dth);
    }
    p[2 * n - 1] = c[n - 1];
}

double cross(point a, point b) { return imag(conj(a) * b); }

bool reachable(int i, int j)
{
    repi(k, i + 1, j) {
        if (k % 2 == 1 and cross(p[j] - p[i], p[k] - p[i]) > eps) return false;            
        if (k % 2 == 0 and cross(p[j] - p[i], p[k] - p[i]) < eps) return false;
    }
    return true;
}

void prepare()
{
    rep(i, 2 * n) rep(j, 2 * n) {
        d[i][j] = 1e9;
    }
    rep(i, 2 * n) d[i][i] = 0.0;
    rep(i, 2 * n) repi(j, i + 1, 2 * n) {
        if (reachable(i, j)) {
            d[i][j] = abs(p[j] - p[i]);
        }
    }
}

void solve()
{
    generate();
    prepare();

    rep(k, 2 * n) rep(i, 2 * n) rep(j, 2 * n) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
    printf("%.6f\n", d[0][2 * n - 1]);
}

int main()
{
    while (cin >> n and n) {
        rep(i, n) cin >> x[i] >> y[i] >> r[i];
        solve();
    }

    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T>
void print(T& x){printf("%d\n", x);}
void printvec(vector<int> a){
    rep(i, a.size()-1){
        printf("%d ", a[i]);
    }
    printf("%d\n", a[a.size()-1]);
}
 
int main()
{
    int n;
    cin >> n;
    n = n%10;
    if(n==3){
        printf("bon\n");
    }else if(n==2 || n==4 || n==5 || n==7 || n==9){
        printf("hon\n");
    }else{
        printf("pon\n");
    }
    return 0;
}

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

const int M = 1e9+7;


int main(){
	int n,m;
	cin>>n>>m;

	ll lt = 1;
	ll rt = 1;
	for(int i=1;i<=n;i++) lt = (lt*i)%M;
	for(int i=1;i<=m;i++) rt = (rt*i)%M;

	if(n==m){ cout<<(ll)(2*lt*rt)%M;}
	else if(abs(n-m) == 1) cout<<(ll)(lt*rt)%M;
	else cout<<0;

}

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

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

/* define const */
const long long INF = (1LL << 60);
/* end defineing */

int main()
{
    int n, m, c;
    int b[20], a[400];

    cin >> n >> m >> c;

    for (int i = 0; i < m; i++)
    {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i * m + j];
        }
    }

    int count = 0;
    for (int i = 0; i < n; i++)
    {
        int tmp = 0;
        for (int j = 0; j < m; j++)
        {
            tmp += (a[i * m + j] * b[j]);
        }
        tmp += c;

        if (tmp > 0)
            count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<stdio.h>
#include <cstdio>
#include <cstring>
#include <string>


using namespace std;

#define ld long double
#define ll long long
#define ff first
#define ss second
#define sz(a) (int)a.size()
#define mem(a, b) memset((a), (b), sizeof(a))
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define pii pair<int ,int >
#define pll pair<ll ,ll >
#define mp make_pair
#define vi vector<int >
#define vii vector<pii>
#define vvi vector < vi >
#define vll vector < ll >
#define vllll vector < pll >
#define vvll vector < vll >
#define forn(i,n) for(int i=0;i<(n);i++)
#define fori(i,s,e) for(int i=s,i<n;i++)
#define qi  queue <int >
#define qll  queue <ll >
#define in_r(x,y,n,m) (x>=0 && x<n && y>=0 && y<m)
#define maxn 1000009


void fast(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

const ll MOD = 1e9 + 7;
const double EPS = (1e-8);
const int OO = (int) 1e9 + 7;
const ll OOO = (ll) 1e15 + 7;
//double const PI = 3.1415926535897932384626433832795;
const int mxn = 1000009;
char c1, c2, c3, c4;
string s, s1, s2, s3;
int   n, m, k, t = 1, q, a, b, c, d, e, x, y, z; int sol = 0;

bool pri[8198];
int cnt[8198];

void pre(){}


void solve() {
	cin >> a >> b >> c >> d >> k;
	
	if (a == c) {
		if (b < d) x = d - b;
		else x = 24 * 6 - (b - d);
	}else {
		x = 60 - b + d; x += (c - a - 1) * 60;
	}
	if (a>c) x = 24 * 60 - x;
	k %= x;
	if (k == 0)cout << 0;
	else cout << x - k << endl;
	
}


int main(){
	fast();
	pre();
	


	//cin >> t; 
	while (t--){

		solve();

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

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
ll d[15][15][15]; // 开头   位数   末尾数字
ll sum[15][15];  // 开头   位数 
ll all[15];
void work(int st)
{
	memset(d,0,sizeof(d));
	d[st][0][st]=1;
	for (int i=0;i<12;i++)
	{
		for (int j=0;j<10;j++)
		{
			//if (i<5) cout <<st<<" "<<i<<" "<<j<<" "<<d[st][i][j]<<" ##\n";
			if (!d[st][i][j]) continue;
			if (j) d[st][i+1][j-1]+=d[st][i][j];
			if (j!=9) d[st][i+1][j+1]+=d[st][i][j];
			d[st][i+1][j]+=d[st][i][j];
			sum[st][i]+=d[st][i][j];
		}
		if (st) all[i]+=sum[st][i];
		//cout <<i<<" "<<sum[st][i]<<" "<<all[i]<<" ##\n"; 
	}
} 
int main()
{
	cin >>n;
	for (int i=0;i<10;i++) work(i);
	/*for (int i=0;i<10;i++)
	{
		for (int j=0;j<3;j++) cout <<sum[i][j]<<" ";
		cout <<"\n";
	}*/
	for (int i=1;i<=12;i++) all[i]+=all[i-1];
	int tac=0;
	while (all[tac]<n) tac++;
	int b=-1;
	n-=all[tac-1];
	for (int i=tac;i>=0;i--)
	{
		//cout <<i<<" ##################\n";
		for (int j=(i==tac ? 1 : 0);j<10;j++)
		{
			//cout <<j<<" "<<sum[j][i]<<" "<<n<<" ##\n";
			if (b!=-1 && abs(b-j)>1) continue;
			if (sum[j][i]<n) n-=sum[j][i];
			else
			{
				b=j,cout <<j;
				break;
			}
		}
	}
	return 0;
}

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

int main(){

    int n, m, l; cin >> n >> m >> l;
    long long A[100][100], B[100][100], ans[100][100];

    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin >> A[i][j];
        }
    }

    for(int i=0; i<m; i++){
        for(int j=0; j<l; j++){
            cin >> B[i][j];
        }
    }

    for(int x=0; x<n; x++){
        for(int y=0; y<l; y++){  
            ans[x][y]=0;                  
            for(int i=0; i<m; i++){
                ans[x][y] += A[x][i]*B[i][y];
            }
        }
    }

    for(int i=0; i<n; i++){
        for(int j=0; j<l; j++){
            if(j) cout << " ";
            cout << ans[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3240
//g++  7.4.0

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s; cin>>s;
    if(s[s.length() - 1] == 's')
        s += "es";
    else
        s += 's';
    
    cout<<s<<endl;
}

Measured memory_bytes: 3676
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long d = sc.NextLong();
        long[] c = sc.LongArray();
        long[,] s = new long[d, 26];
        for (int i = 0; i < d; i++)
        {
            for (int j = 0; j < 26; j++)
            {
                s[i, j] = sc.NextLong();
            }
        }

        long[] last = new long[26];

        for (int i = 0; i < d; i++)
        {
            long maxDiff = long.MinValue;
            long answerIndex = 0;
            for (int j = 0; j < 26; j++)
            {
                long diff = 0;
                diff += s[i, j];
                diff -= c[j] * (i + 1 - last[j]);
                if (diff > maxDiff)
                {
                    maxDiff = diff;
                    answerIndex = j;
                }
            }
            last[answerIndex] = i;
            Console.WriteLine(answerIndex + 1);

            //long afterCost = 0; 
            //for (int j = 0; j < 26; j++)
            //{
            //    var cost = c[j] * (i + 1 - last[j]);
            //    afterCost += cost;
            //}

            //satisfy += s[i, answerIndex];
            //satisfy -= afterCost;

        }

        //long[] sums = new long[26];
        //for (int i = 0; i < 26; i++)
        //{
        //    long sum = 0;
        //    for (int j = 0; j < d; j++)
        //    {
        //        sum += s[j, i];
        //    }
        //    sums[i] = sum;
        //}

        //long maxDay = 0;
        //long max = 0;
        //for (int i = 0; i < 26; i++)
        //{
        //    if (sums[i] > max)
        //    {
        //        max = sums[i];
        //        maxDay = i;
        //    }
        //}
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 28836
#include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;
         
        typedef long long ll;
        typedef long double LD;
        #define int ll
        #define double LD
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define Test(){int t;cin >> t;for(int i=1;i<=t;i++){cout << "Case #" << i << ": ";solve();}}
        #define test(){int t; cin>>t; for(int i=1;i<=t;i++){solve();}}
        #define vi vector<int>
        #define vii vector<pair<int,int> > 
        #define vci vector<pair<char,int> >
        #define vic vector<pair<int,char> > 
        #define N 200005
        #define pb push_back
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
	
		void solve()
		{
			string s;
			cin>>s;
			int ans=0;
			loop(i,s.size())
			{
				ans+=(s[i]-'0');
			}
			if(ans%9)
			cout<<"No";
			else
			cout<<"Yes";
		}
		signed main()
		{
		//	test();
		solve();
		}

Measured memory_bytes: 3744
n = int(input())
csf = [[int(item) for item in input().split()] for _ in range(n-1)]

for i in range(n):
    total_time = 0
    for c, s, f in csf[i:]:
        time = 0
        # wait for start
        if total_time < s:
            time += s - total_time
        # wait for next train
        else:
            time += (f - total_time % f) % f
        # take train
        time += c
        total_time += time
    print(total_time)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
using namespace std;

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

    int A[N];
    int ans[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        ans[A[i] - 1] = i + 1;
    }

    for (int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] h = new long[n];
        for (int i = 0; i < h.length; i++) {
            h[i] = sc.nextLong();
        }
        Arrays.sort(h);
        long ans = Long.MAX_VALUE;
        for (int i = 0; i < n - k + 1; i++) {
            long tmp = h[i + k - 1] - h[i];
            ans = Math.min(ans, tmp);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 60312
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n,b;
	vector<int>a;
	while (1){
		int max_v = -1000000;
		a.clear();
		cin >> n;
		if (n == 0)break;
		a.push_back(0);
		for (int i = 0; i < n; i++){
			cin >> b;
			a.push_back(b);
		}
		for (int i = 1; i <= n; i++){
			a[i] = max(a[i - 1] + a[i], a[i]);
			if (a[i]>max_v){
				max_v = a[i];
			}
		}
		cout << max_v << endl;
	}
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef unsigned long long ull;
#define pb(x) push_back(x) 
vector<int> str[N];
vector<ull> ha[N];

ull base[N];
map<ull,vector<int>> mp;
int cnt[26];
ull GetHash(int i,int x,int y){
    return ha[i][y]-ha[i][x-1]*base[y-x+1];
}
int main(){
    base[0]=1;
    for(int i=1;i<N;++i)base[i]=base[i-1]*133331;
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        str[i].pb(0);
        int ch;
        do{
            ch=getchar();
        }while(isspace(ch));
        do{
            str[i].pb(ch-'a');
        }while(!isspace(ch=getchar()));
        ha[i].resize(str[i].size(),0);

        for(int j=1;j<str[i].size();++j){
            ha[i][j]=ha[i][j-1]*133331+str[i][j]+17;
        }
        ull hash;
        if(str[i].size()==2)
            hash=0;
        else 
            hash=GetHash(i,2,str[i].size()-1);
            
        if(mp.find(hash)==mp.end())
            mp[hash]=vector<int>(26,0);
        ++mp[hash][str[i][1]];
    }
    ull ans=0;
    for(int i=1;i<=n;++i){
        memset(cnt,0,sizeof(cnt));
        for(unsigned int j=1;j<str[i].size();++j)
            ++cnt[str[i][j]];
        for(unsigned int j=str[i].size();j>1;--j){
            ull hash=0;
            if(j!=str[i].size()){
                hash=GetHash(i,j,str[i].size()-1);
                --cnt[str[i][j]];
            }
            if(mp.find(hash)==mp.end())continue;
            vector<int> &tmp=mp[hash];
            for(int k=0;k<26;++k)
                if(cnt[k]>0){
                    assert(tmp[k]<=1);
                    ans+=tmp[k];
                }
        }
    }
    ans-=n;
    printf("%llu",ans);
    return 0;
}


Measured memory_bytes: 104768
#include <stdio.h>
int main(){
    int X, T, N;
    scanf("%d",&N);
    scanf("%d",&X);
    scanf("%d",&T);
    if(N%X == 0){
        printf("%d", (N/X)*T);
    }
    else{
        printf("%d", (N/X)*T + T);
    }
}

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


void solve(long long K, long long N, std::vector<long long> A){
    long long most  = 0;
    for(int i=1;i<N;i++){
        long long a = (A[i]-A[i-1])% K;
        long long d = min(a,K-a);
        most = max(most,d);
    }
    long long a0 = (A[N-1]-A[0]) % K;
    long long d0 = min(a0,K-a0);
    most = max(most,d0);
    cout << K-most << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(K, N, std::move(A));
    return 0;
}


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

using namespace std;
using ll = long long;

ll burger(ll N,ll X);
ll a[55],p[55];

int main(){
    ll N,X;
    cin>>N>>X;
    a[0]=1;
    p[0]=1;
    for(int i=0;i<N;i++){
        a[i+1]= a[i]*2 + 3;
        p[i+1]= p[i]*2 + 1;
        //cout<<"a["<<i<<"]"<<a[i]<<endl;
        //cout<<"p["<<i<<"]"<<p[i]<<endl;
    }
    cout<<burger(N,X)<<endl;
    return 0;
}
ll burger(ll N, ll X){
    if(N==0){
        return X;
    }
    else{
        //cout<<"a["<<N-1<<"]="<<a[N-1]<<endl;
        //cout<<"X="<<X<<endl;
        if(X==1){ return 0; }
        else if(X <= (1 + a[N-1])){ return burger(N-1,X-1); }
        else if(X == (2 + a[N-1])){  return 1+burger(N-1,a[N-1]); }
        else if(X <= (2 + 2*a[N-1])){  return burger(N-1,a[N-1]) + 1 + burger(N-1,X-2-a[N-1]); }
        else if(X == (3 + 2*a[N-1])){  return 1+2*burger(N-1,a[N-1]); }
    }
    return -1;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
      n: usize,
      k: usize,
    );
    let mut i: u32 = 0;
    loop {
        if n < k.pow(i) {
            break
        }
        i += 1u32;
    }
    println!("{}", i)
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//#include <boost/lexical_cast.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define mp make_pair
#define endl '\n'
#define PI acos(-1)
#define bitcount(a) __builtin_popcountll(a)
#define P pair<int,int>
typedef tree<int,null_type,less_equal <int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

long mod=1e9+7;
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	--n;
	int ans=0;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ans+=a[n-1];
	for(int i=n-2;i>=0;--i)
	{
		if(a[i]<=a[i+1])
		{
			ans+=a[i];
		}
		else
		{
			ans+=a[i+1];
		}
	}
	ans+=a[0];
	cout<<ans;
	return 0;
}

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

using namespace std;

typedef long long lint;
const lint N = 2e5+7, mod = 1e9+7;
lint n, k;

int main(){
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

	scanf("%lld %lld", &n, &k);
	
	lint sum = 0;

	lint m = 0, M = 0;


	for (lint i = k; i <= n+1; i++){
		m = (i-1)*(i)/2;
		M = (n)*(n+1)/2 - (n-i)*(n-i+1)/2;
		//cout << M << " " << m << endl;
		sum = (sum%mod + (M-m+1)%mod)%mod;
		
	}
		

	printf("%lld\n", sum);

	return 0;
}

Measured memory_bytes: 3832
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String N = br.readLine();
        int tmp = Integer.parseInt(N.substring(N.length() - 1));

        if (tmp == 2 || tmp == 4 || tmp == 5 || tmp == 7 || tmp == 9) {
            System.out.print("hon");
        } else if (tmp == 0 ||tmp == 1 ||tmp == 6 ||tmp == 8) {
            System.out.print("pon");
        } else {
            System.out.print("bon");
        }
    }
}

Measured memory_bytes: 32456
import itertools

def fff(x):
    dp=[0]*k
    dp[0]=1
    for u in itertools.chain(a[:x],a[x+1:]):
        h=dp[:]
        for i in range(u,k):
            h[i]=h[i]|dp[i-u]
        dp=h
    cnt=0
    for i in range(max(0,k-a[x]),k):
        cnt+=dp[i]
    if cnt==0:
        return True
    else:
        return False

n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
low=0
high=n-1
while high-low>1:
    mid=(high+low)//2
    if fff(mid):    #不必要
        low=mid
    else:
        high=mid

if fff(high):
    print(high+1)
elif fff(low):
    print(low+1)
else:
    print(0)

Measured memory_bytes: 62300