akhauriyash/Code-Regression huggingface dataset:
N = int(input())
S = input()

ans = 0
while S:
    Z = [0] * N
    i = 1
    j = 0
    while i < N:
        while i + j < N and S[j] == S[i + j]:
            j += 1

        Z[i] = j

        if j == 0:
            i += 1
        else:
            k = 1
            while k < j and k + Z[k] < j:
                Z[i + k] = Z[k]
                k += 1
            i += k
            j -= k    

    ans = max(ans, max(min(i, z) for i, z in enumerate(Z)))

    S = S[1:]
    N -= 1

print(ans)

Measured memory_bytes: 77320
s = input()
n = len(s)
m = (n-1)//2
l = (n+3)//2
s_1 = s[0:m]
s_2 = s[l-1:n+1]
ans1 = s == s[::-1]
ans2 = s_1 == s_1[::-1]
ans3 = s_2 == s_2[::-1]
if ans1 and ans2 and ans3:
    print('Yes')
else:
	print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  stack<char> s;
  string a;
  cin>>a;
  for(auto c:a){
    if(c!='B')s.push(c);
    else if(!s.empty())s.pop();
  }
  string res="";
  while(!s.empty()){
    res=s.top()+res;
    s.pop();
  }
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<vin> vvin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())

int main(){
  int n,m;
  cin>>n>>m;
  cout<<(n*(n-1)+m*(m-1))/2<<endl;
  
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll D,C[30];
ll S[400][30];
ll ANS[400];
ll PS[30];

void Put_Score(){
  ll SUM=0;
  rep(i,D){
    SUM+=S[i][ANS[i]-1];
    rep(j,26){
      if(ANS[i]-1!=j){
        PS[j]++;
        SUM-=C[j]*PS[j];
      }
      else{
        PS[j]=0;
      }
    }
    cout << SUM << endl;
  }
}

int main(){
  cin>>D;
  rep(i,26){
    cin >> C[i];
  }
  rep(i,D){
    rep(j,26){
      cin >> S[i][j];
    }
  }
  rep(i,D){
    cin >> ANS[i];
    //cout << ANS[i]+1 << endl;
  }
  Put_Score();
}

Measured memory_bytes: 3672
# 2020/04/04
# AtCoder Beginner Contest 161 - D

runsu = list()

def makerunrun(s):

    if int(s) > 3234566667:
        return 0

    runsu.append(int(s))
    lketa = int(s[len(s)-1])
    if lketa > 0:
        wks = s + str(lketa - 1)
        makerunrun(wks)
    
    wks = s + str(lketa)
    makerunrun(wks)
    
    if lketa < 9:
        wks = s + str(lketa + 1)
        makerunrun(wks)
    
# Input
k = int(input())

# Make Runrun List
for i in range(1, 10):
    makerunrun(str(i))

runsu.sort()

# Output
print(runsu[k-1])


Measured memory_bytes: 7472
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  vector<ll> h(n);
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  ll left=-1,right=1e9+5;
  while(left+1<right){
    ll mid=(left+right)/2;
    ll sum=0;
    for(int i=0;i<n;i++){
      if(h[i]-b*mid>0){
        sum+=(h[i]-b*mid+a-b-1)/(a-b);
      }
    }
    if(sum<=mid){
      right=mid;
    }
    else{
      left=mid;
    }
  }
  cout << right << endl;
}

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

int main() {
	// your code goes here
	ll h, w;
	cin >> h >> w;
	ll ans = (ll)ceil((h * w) / 2.0);
	if(h == 1 || w == 1) ans = 1;
	cout << ans << endl;
	return 0;
}


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

struct s {
	int a;
	long b;
};

int compare(const void *x, const void *y)
{
	return ((s*)x)->a - ((s*)y)->a;
}

int main() {
	int N, i;
	long K, sum = 0;
	s array[100000];
	cin >> N >> K;
	for (i = 0; i < N; ++i) cin >> array[i].a >> array[i].b;
	qsort(array, N, sizeof(s), compare);
	for (i = 0; sum < K; ++i) sum += array[i].b;
	cout << array[i - 1].a;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> V(0);
  
  if(N==0){
    cout << 0 << endl;
    return 0;
  }

  int i=-1;
  while(N!=0){
    i++;
    V.push_back(N%(-2));
    N /= -2;
    if(V[i]==-1){
      V[i] = 1;
      N += 1;
    }
  }
  
  for(int j=i;j>=0;j--) cout << V[j];
  cout << endl;
  return 0;
}


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

int main() {
  int N, S, C = 1;
  
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    S = 0;

    while(x % 2 == 0){
	  x /= 2;
      S++;
    	}
    if (i == 0){
   		C = S;
    }
    if (C > S){
	    C = S;
	  }else{
      continue;
    }
  }
  cout << C << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<string>
#include<map>
#include<queue>

using namespace std;

int main(void){

    int h, w;
    cin >> h >> w;
    int vec[4][2] = {
        {0, -1}, {1, 0}, {0, 1}, {-1, 0}
    };
    vector<vector<char>> s(h, vector<char>(w));

    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            cin >> s[i][j];
        }
    }

    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(s[i][j] == '#'){
                int flag = 0;
                for(int k = 0;k < 4;k++){
                    if(0 <= j+vec[k][0] && j+vec[k][0] < w && 0 <= i+vec[k][1] && i+vec[k][1] < h){
                        if(s[i+vec[k][1]][j+vec[k][0]] == '#') {
                            flag = 1;
                        }
                    }
                }

                if(flag == 0) {
                    cout << "No" << endl;
                    return 0;
                }
            }
            
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <assert.h>

using namespace std;

int tempmarge[1000100];

int N, A[10000000];

bool bsearch(const int array[], int left, int right, int value) {
	while (left + 1 < right) {
		int med = (left + right) / 2;
		if (array[med] > value)right = med;
		else left = med;
	}
	return left < right  && array[left] == value;
}

long long int MargeSort(int x[], int left, int right) {
	long long int mid, i, j, k, cl, cr, c;

	if (left >= right)
		return 0;

	mid = (left + right) / 2;
	cl = MargeSort(x, left, mid);
	cr = MargeSort(x, mid + 1, right);


	for (i = left; i <= mid; i++)
		tempmarge[i] = x[i];
	for (i = mid + 1, j = right; i <= right; i++, j--)
		tempmarge[i] = x[j];

	i = left;
	j = right;
	c = 0;
	for (k = left; k <= right; k++)
		if (tempmarge[i] <= tempmarge[j])
			x[k] = tempmarge[i++];
		else {
			c += mid + 1 - i;
			x[k] = tempmarge[j--];
		}

	return c + cl + cr;
}

int main() {
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> A[i];

	cout << MargeSort(A, 0, N - 1) << endl;

	return 0;
}

Measured memory_bytes: 4644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

template<class T,class E> struct LSeg{
    typedef function<T(T,T)> F;
    typedef function<T(T,E)> G;
    typedef function<E(E,E)> H;
    typedef function<E(E,int)> P;
    int n;F f;G g;H h;T et;E ee;P p;
    vector<T> dat;
    vector<E> lazy;
    LSeg(int n_,F f_,G g_,H h_,T et_,E ee_,P p_=[](E a,int b){return a;}){
        f=f_;g=g_;h=h_;et=et_;ee=ee_;p=p_;
        n=1;
        while(n<n_) n*=2;
        dat.resize(2*n-1,et);
        lazy.resize(2*n-1,ee);
    }
    inline void prop(int k,int l,int r){
        if(lazy[k]==ee) return;
        dat[k]=g(dat[k],lazy[k]);
        if(r-l>1){
            lazy[k*2+1]=h(lazy[k*2+1],p(lazy[k],-1));
            lazy[k*2+2]=h(lazy[k*2+2],p(lazy[k],-1));
        }
        lazy[k]=ee;
    }
    void ud(int be,int en,E t,int k,int l,int r){
        prop(k,l,r);
        if(r<=be||en<=l) return;
        if(be<=l&&r<=en){
            lazy[k]=h(lazy[k],p(t,r-l));
            prop(k,l,r);
            return;
        }
        ud(be,en,t,k*2+1,l,(l+r)/2);
        ud(be,en,t,k*2+2,(l+r)/2,r);
        dat[k]=f(dat[2*k+1],dat[k*2+2]);
    }
    void ud(int be,int en,E t){
        ud(be,en,t,0,0,n);
    }
    T gt(int be,int en,int k,int l,int r){
        prop(k,l,r);
        if(r<=be||en<=l) return et;
        if(be<=l&&r<=en) return dat[k];
        return f(gt(be,en,k*2+1,l,(l+r)/2),gt(be,en,k*2+2,(l+r)/2,r));
    }
    T gt(int be,int en){
        return gt(be,en,0,0,n);
    }
};

template<class T> void cc(vector<T> a,map<T,int>& nm,vector<int>& c){
    sort(a.begin(),a.end());
    fr(i,a.size()){
        if(i<a.size()-1&&a[i]==a[i+1]) continue;
        nm[a[i]]=c.size();
        c.pb(a[i]);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N=0,M,q,A,B,C;
    map<ll,int> nm;vector<ll> a;vector<int> c;
    cin>>M>>q;
    vector<ll> d(q);
    vector<pair<ll,pair<ll,ll>>> xst;
    fr(i,M){
        cin>>A>>B>>C;
        if(B<C) continue;
        if(A<C) A=C;
        xst.emplace_back(C,mp(A,B));
        if(A>C) a.pb(A-C);
        a.pb(B-C);
        N++;
    }
    fr(i,q){
        cin>>d[i];
        a.pb(d[i]);
    }
    a.pb(0);
    sort(a.begin(),a.end());
    cc(a,nm,c);
    auto mn=[](int a,int b){return min(a,b);};
    LSeg<int,int> sg(c.size(),mn,mn,mn,INT_MAX,INT_MAX);
    fr(i,N){
        sg.ud(nm[-(xst[i].ft-xst[i].sd.ft)],nm[-(xst[i].ft-xst[i].sd.sd)],xst[i].ft);
    }
    fr(i,q){
        ll ans=sg.gt(nm[d[i]],nm[d[i]]+1);
        if(ans==INT_MAX) cout<<-1<<endl;
        else cout<<ans<<endl;
    }
}

Measured memory_bytes: 72392
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int k;
  cin>>s>>k;
  set<string> ss;
  for(int w=1;w<=k;w++)
    for(int i=0;i+w-1<s.size();i++)
      ss.insert(s.substr(i,w));
  for(int i=1;i<k;i++)
    ss.erase(*ss.begin());
  cout<<*ss.begin()<<endl;
}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
#include<algorithm>
#include<numeric>
#define int long long
#define all(x) x.begin(),x.end()
#define what_is(x) cerr << #x << " is " << x << endl;
const int MOD = 1e9 + 7;
using namespace std;
string abc="abcdefghijklmnopqrstuvwxyz";
int powmod(int a, int b, int MOD = MOD){
    if(!a and !b)    return 1ll;
    if(!a)    return a;
    int res = 1ll;
    b %= (MOD - 1ll), a %= MOD;
    while(b){
        if(b%2 == 1)    res = (res * a) % MOD;
        a = (a * a) % MOD;
        b /= 2;
    }
    return res;
}
int popcount(uint32_t n)
{
    n = n - ((n >> 1) & 0x55555555);
    n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
    return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
bool check(int n) {return (((double)sqrt(n)-floor((double)sqrt(n)))==0);}
void solve() {
  int n;
  cin>>n;
  if(n%10==2 or n%10==4 or n%10==5 or n%10==7 or n%10==9) cout<<"hon";
  else if(n%10==0 or n%10==1 or n%10==6 or n%10==8) cout<<"pon";
  else cout<<"bon";
}
int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    //cout<<"Hello World"<<"\n";
    //int t;cin>>t;while(t--)
        solve();

}

Measured memory_bytes: 3652
function Main(input) {
	input = input.trim();
	//input = input.trim().split(" ");
	//input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	input = input.trim().split("\n").map((a)=>Number(a));
  	var N = input[0];
  var A = input[1];
  if((N % 500) - A <= 0){
     console.log("Yes");
     }else{
      console.log("No"); 
     }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(((x>=r)&&(x<=(W-r)))&&((y>=r)&&(y<=(H-r)))){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 3072
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<map>
#include<numeric>
//#include <bits/stdc++.h>
#include<cstring>
#include<iostream>
#include<functional>
using namespace std;
int main() {

	int N;
	cin >> N;

	int tot = 0;
	int remain = N;
	while (remain != 0) {
		tot += remain % 10;
		remain /= 10;
	}
	if (N % tot == 0)
		cout << "Yes\n";
	else
		cout << "No\n";

	//cin >> N;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric> 
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1e9 + 5;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
///////////////////////////////////////////////////////////////////////

string s, t;

int main() {
    cin >> s >> t;
    int n = s.length(), m = t.length();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    for (int i = 1; i < n + 1; ++i) {
        for (int j = 1; j < m + 1; ++j) {
            if (s[i - 1] == t[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
            else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }

    int len = dp[n][m];
    string res = "";
    while (n > 0 && m > 0) {
        if (dp[n][m] == dp[n - 1][m]) n--;
        else if (dp[n][m] == dp[n][m - 1]) m--;
        else res = s[n - 1] + res, n--, m--;
    }
    cout << res << endl;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	string s;
	cin >> s;
	rep(i, s.size()) {
		if (i % 2 == 0)cout << s[i];
	}
	cout << endl;
	return 0;
}

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

public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s = br.readLine().split(" ");
		int Y = Integer.parseInt(s[0]);
		int X = Integer.parseInt(s[1])+2;
		String line =  "";
		for(int i = 0;i<X;i++){
		    line = line + "#";
		}
		System.out.println(line);
	    
	    for(int i = 0;i<Y;i++){
	        System.out.println("#" + br.readLine() + "#");
	    }
	    System.out.println(line);
	}
	
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main(void){
    int n, x; cin >> n >> x;
  vector<int> m(n);
  int min_m = 200000;
  for(int i = 0; i < n; i++){
  	int m; cin >> m;
    x -= m;
    min_m = min(min_m, m);
  }
  
  int ans = n;
  ans += (x / min_m);
  cout << ans << endl;
  
    return 0;
}

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

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

Measured memory_bytes: 3600
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring> 
#include <iostream>
#include <algorithm>
using namespace std;

char s[1005], t[1005];

int main()
{
	scanf("%s%s", s + 1, t + 1);
	int ls = strlen(s + 1), lt = strlen(t + 1);
	int ans = ls;
	for(int i = 1;i <= ls - lt + 1;++i)
	{
		int cnt = 0;
		for(int j = 1;j <= lt;++j)
		{
			if(s[i + j - 1] != t[j])
				++cnt;
		}
		if(cnt < ans)
			ans = cnt;
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 3820
import bisect
# from collections import Counter, deque, OrderedDict
# from copy import copy, deepcopy # pythonのみ．copyは1次元，deepcopyは多次元．
# from functools import reduce
# from heapq import heapify, heappop, heappush
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    N = int(input())

    import math

    # cf. https://qiita.com/suecharo/items/14137fb74c26e2388f1f

    def make_prime_list_2(num):
        if num < 2:
            return []

        # 0のものは素数じゃないとする
        prime_list = [i for i in range(num + 1)]
        prime_list[1] = 0  # 1は素数ではない
        num_sqrt = math.sqrt(num)

        for prime in prime_list:
            if prime == 0:
                continue
            if prime > num_sqrt:
                break

            for non_prime in range(2 * prime, num, prime):
                prime_list[non_prime] = 0

        return [prime for prime in prime_list if prime != 0]

    def prime_factorization_2(num):
        """numの素因数分解
        素因数をkeyに乗数をvalueに格納した辞書型dict_counterを返す"""

        if num <= 1:
            # 例えば1を食ったときの対処の仕方は問題によって違うと思うのでそのつど考える。
            # cf. https://atcoder.jp/contests/abc110/submissions/12688244
            return False
        else:
            num_sqrt = math.floor(math.sqrt(num))
            prime_list = make_prime_list_2(num_sqrt)

            dict_counter = {}  # 何度もこの関数を呼び出して辞書を更新したい時はこれを引数にして
            # cf. https://atcoder.jp/contests/arc034/submissions/12251452

            for prime in prime_list:
                while num % prime == 0:
                    if prime in dict_counter:
                        dict_counter[prime] += 1
                    else:
                        dict_counter[prime] = 1
                    num //= prime
            if num != 1:
                if num in dict_counter:
                    dict_counter[num] += 1
                else:
                    dict_counter[num] = 1

            return dict_counter
    d = prime_factorization_2(N)
    num = [i for i in range(1, 40)]

    # 累積和を格納したリスト．A[l:r]の総和はB[r] - B[l]
    num = list(accumulate(num))
    cnt = 0
    if not d:
        print(0)
    else:
        for v in d.values():
            cnt += bisect.bisect_right(num, v)
        print(cnt)


resolve()

Measured memory_bytes: 141936
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

int N, K;
ll h[1 << 17], dp[1 << 17];

int main()
{
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        cin >> h[i + 1];
    }

    dp[1] = 0;

    for (int i = 2; i <= N; i++)
    {
        dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
        for (int j = 2; j <= K && i - j > 0; j++)
        {
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }

    cout << dp[N] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
ll a[55];
ll ans = 0ll;
priority_queue<ll> p,q;
void solve(){
	while(q.top()>=N){
		ans++;
		p.push(q.top()-N);
		q.pop();
		while(!q.empty()){
			p.push(q.top()+1);
			q.pop();
		}
		swap(p,q);
	}
}
int main(){
	cin >> N;
	for(int i=0;i<N;i++)cin >> a[i];
	for(int i=0;i<N;i++)q.push(a[i]);
	while(1){
		ll L = q.top();
		vector<ll> v;
		ll cnt = 0ll;
		while(!q.empty()&&L-q.top()<=N+1){
			v.pb(q.top());
			q.pop();
			cnt++;
		}
		if(!q.empty()){
			ll op = (L-q.top())/(N+1ll);
			if(q.top()+op*cnt<N){
				for(int i=0;i<v.size();i++)q.push(v[i]);
				solve();
				break;
			}
			ans += op*cnt;
			while(!q.empty()){
				p.push(q.top()+op*cnt);
				q.pop();
			}
			for(int i=0;i<v.size();i++){
				p.push(v[i]-(N+1ll-cnt)*op);
			}
			swap(p,q);
		}else{
			if(L>N*N){
				ans += (L-N*N)*N;
				for(int i=0;i<v.size();i++)q.push(v[i]-(L-N*N));
			}else{
				for(int i=0;i<v.size();i++)q.push(v[i]);
				solve();
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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


int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	
	
	auto solve = [&] (int x) {
		int cnt = 0;
		rep(i, n) {
			// x = 3
			// a: 1, 2, 3, 4, 5, 6, 7...
			// b: 0, 0, 0, 1, 1, 1, 2... 
			cnt += (a[i] -1) / x;
		}
		
		if(cnt <= k) return true;
		else return false;
	};
	int ok = 1e9;	// 解が存在する値
	int ng = 0;	// 解が存在しない値
	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;
		if(solve(mid)) {
			ok = mid;
		} else {
			ng = mid;
		}
	}
	cout << ok << endl;
	return 0;
}

Measured memory_bytes: 4812
// by https://atcoder.jp/contests/abc070/tasks/abc070_c
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func gcd(a int64, b int64) int64 {
	var aa = a
	var bb = b
	for bb > 0 {
		var tmp = bb
		bb = aa % bb
		aa = tmp
	}
	return aa
}

// 最小公倍数
func lcm(a int64, b int64) int64 {
	return a / gcd(a, b) * b
}

func main() {
	var clockNum int
	// 最初の値が時計の数
	clockNum, _ = strconv.Atoi(nextLine())

	var clockPeriods []int64
	for i := 0; i < clockNum; i++ {
		var tmp, _ = strconv.Atoi(nextLine())
		clockPeriods = append(clockPeriods, int64(tmp))
	}

	var tmpLcm = clockPeriods[0]
	for i := 1; i < clockNum; i++ {
		tmpLcm = lcm(clockPeriods[i], tmpLcm)
	}

	fmt.Printf("%d", tmpLcm)
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
int du[100010];
int main(){
	int N,M;
	scanf("%d%d",&N,&M);
	for(int i = 1;i <= M;i++){
		int a,b;scanf("%d%d",&a,&b);du[a]++;du[b]++;
	}
	int sum = 0;
	for(int i = 1;i <= N;i++){
		if(du[i] % 2 != 0)sum++;
	}
	if(sum > 1)puts("NO");
	else puts("YES");
	return 0;
}

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

int main() {
    int a,b; cin >> a >> b;
    vector<int> n = {a,b,a-1,b-1};
    sort(n.begin(),n.end());
    cout << n[2]+n[3] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define all(v) v.begin(),v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl 

const int N = 1e3;
ll dp[N][N];
char c[N][N];
int n , m;
const ll mod = 1e9+7;

ll calc (int i , int j){

    if (i >= n || j >= m)
        return 0;

    if (i == n-1 && j == m-1)
        return 1;

    if (c[i][j] == '#')
        return 0;

    ll &ret = dp[i][j];
    if (~ret)
        return ret;

    ret = calc (i+1,j) + calc(i,j+1);
    return ret % mod;

} 

void Suhaib_Sawalha (){

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

    memset(dp,-1,sizeof dp);
    cout << calc(0,0);

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}

Measured memory_bytes: 12528
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int x;
  std::cin >> x;
  bool flag = false;
  do{
    flag = false;
    for (int i = 2; i*i <= x; i++) {
      if(x%i==0){
        x++;
        flag = true;
        break;
      }
    }
  } while(flag);

  std::cout << x << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define all(x) (x).begin(), (x).end() 

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

long long INF=numeric_limits<long long>::max();

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int n,a,b;
    cin >> n >> a >> b;
    if(n*a>b)cout << b << endl;
    else cout << n*a << endl;
}	


Measured memory_bytes: 256
//Problem: ABC 170C
//Progress:
#include <iostream>
#include <map>
typedef long long int ll;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t, k;
    cin >> t >> k;
    map<ll, bool> mp;
    ll inp;
    for(ll i=0; i<k; i++){
    	cin >> inp;
    	mp[inp] = 1;
    }
    for(ll i=0; ; i++){
    	if(mp[t-i] == 0){
    		cout << t-i;
    		break;
    	}
    	if(mp[t+i] == 0){
    		cout << t+i;
    		break;
    	}
    }
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);	
    vector<int> two;
    vector<int> two_and_four;
    vector<int> none;
    
    int n ;
    cin>>n;
    while(n--)
    {
        int a;
        cin>>a;
        if(a%2==0)
        {
            if(a%4==0)
            {
                two_and_four.push_back(a);
            }
            else
            {
                two.push_back(a);
            }
        }
        else
        {
            none.push_back(a);
        }
    }
    
    bool isOk = false;
    if(two.size() >  0)
    {
        if(none.size() <= two_and_four.size())
        {
            isOk = true;
        }
    }
    else
    {
        if(none.size() <= two_and_four.size() + 1)
        {
            isOk = true;
        }
    }
    
    
    if(isOk)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
	
	
    return 0;
}

Measured memory_bytes: 1020
n = int(input())
w_0 = input()
words = {w_0}
now = w_0[-1]
ans = "Yes"
for _ in range(n-1):
    w = input()
    if now == w[0] and not (w in words):
        now = w[-1]
        words.add(w)
    else:
        ans = "No"
        break

print(ans)

Measured memory_bytes: 3060
n, m = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
a.sort(reverse=True)

s = []
for i in range(m):
    s.append([int(_) for _ in input().split()])
s.append([0,0])
s.sort(reverse=True, key=lambda x:x[1])

ida = 0
ids = 0
ans = 0
cnt = 0
while cnt < n:
    if a[ida] >= s[ids][1]:
        ans += a[ida]
        ida += 1
        cnt += 1
    else:
        an = min(n - cnt, s[ids][0])
        ans += s[ids][1] * an
        ids += 1
        cnt += an
print(ans)


Measured memory_bytes: 27000
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>

#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807
#define LLMIN       -9223372036854775808
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;

using namespace std;

int solve(LL H,LL W){
    LL b=H/2;
    LL r=LLMAX;
    for(LL a=max((LL)0,W/3-1);a<=min(W,W/3+2);a++){
        LL rr=max(H*a,max(b*(W-a),(H-b)*(W-a)))-min(H*a,min(b*(W-a),(H-b)*(W-a)));
        r=min(r,rr);
    }
    if(W%3==0)
        r=0;
    else
        r=min(r,H);
    return r;
}

int main(void){
    LL H,W;
    cin>>H>>W;
    LL ans=min(solve(H,W),solve(W,H));
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<pair<int,int>> v[n];
        int a, b, c;
        while(m-- > 0){
            cin >> a >> b >> c;
            a--, b--;
            v[a].push_back({b,c});
            v[b].push_back({a,c});
        }
        vector<vector<int>> dp(2, vector<int>(n, 1<<30));
        priority_queue<pair<int, pair<int,int>>> pq;
        pq.push({-0, {0, 0}});
        // 0 - before using ticket, 1 - after 
        while(!pq.empty()){
            auto p = pq.top();  pq.pop();
            int cost = -p.first, pos = p.second.first, stat = p.second.second;
            if(dp[stat][pos] <= cost)   continue;
            dp[stat][pos] = cost;
            for(pair<int,int> next : v[pos]){
                if(dp[stat][next.first] > cost + next.second){
                    pq.push({-(cost+next.second), {next.first, stat}});
                }
                if(stat == 0){
                    int npos = next.first;
                    for(pair<int,int> q : v[npos]){
                        if(dp[1][q.first] > cost){
                            pq.push({-cost, {q.first, 1}});
                        }
                    }
                }
            }
        }
        cout << min(dp[0][n-1], dp[1][n-1]) << endl;
    }
    return 0;
}


Measured memory_bytes: 3176
n = int(input())
list_v = list(map(int, input().split()))
list_c = list(map(int, input().split()))
print(sum(map(lambda i: 0 if (list_v[i] - list_c[i]) < 0 else (list_v[i] - list_c[i]), range(len(list_v)))))


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

int main(int argc, char *argv[])
{
    int n;
    std::string s;
    int ans = 0;

    std::cin >> n;
    std::cin >> s;

    const int len = s.length();

    for (int i = 0; i < len; i++) {
        if (s.substr(i, 3) == "ABC") {ans++;}
    }

    std::cout << ans << std::endl;

    return 0;
}


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

int main(void) {
    int n;
    scanf("%d", &n);
    int v[n], c[n];
    for (int i=0; i<n; i++) {
        cin>>v[i];
    }
    for (int i=0; i<n; i++) {
        cin>>c[i];
    }
    int sum = 0;
    for (int i=0; i<n; i++) {
        if (v[i] > c[i]) {
            sum+=(v[i]-c[i]);
        }
    }
    cout << sum << endl; 

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

long pow5(long p){
  return(p*p*p*p*p);
}

int main(){
  long x,i,j;
  scanf("%ld",&x);
  for(i=-120;i<121;i++){
    for(j=-120;j<121;j++){
      if(pow5(i)-pow5(j)==x) break;
    }
    if(j!=121) break;
  }
  printf("%ld %ld",i,j);
  return(0);
}


Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((a*b)>(c*d))
    cout << a*b << endl;
  else if((a*b)<(c*d))
    cout << c*d << endl;
  else
    cout << a*b << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

N, M = map(int, input().split())
a, b = [None] * M, [None] * M
for i in range(M):
    a[i], b[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1


def dfs(u, graph, visited):
    visited[u] = True
    for v in graph[u]:
        if not visited[v]:
            dfs(v, graph, visited)


cnt = 0
for i in range(M):
    idx = list(range(0, i)) + list(range(i + 1, M))
    graph = defaultdict(list)
    for u, v in zip(a[:i] + a[i + 1:], b[:i] + b[i + 1:]):
        graph[u].append(v)
        graph[v].append(u)

    visited = [False] * N
    dfs(u, graph, visited)
    if False in visited:
        cnt += 1
print(cnt)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    ll n, m, k;
    cin >> n >> m >> k;
    if(k == n * m){
        cout << "Yes" << endl;
        return 0;
    } 
    REP(i, n){
        REP(j, m){
            ll p = i + 1, q = j + 1;
            ll res = q * (n - p) + p * (m - q);
            if(k == res){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

using namespace std;

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int rem = x;
  int ans = 0;
  for (auto e : a) {
    rem -= e;
    if (rem < 0) {
      break;
    }
    ans++;
  }
  if (rem > 0) ans--;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main() {
    int N;
    int p[50];
    cin >> N;
    for (int i=0; i<N; i++) cin >> p[i];
    int fail = 0;
    for (int i=0; i<N; i++) {
        if (i+1 != p[i]) fail++;
    }
    if (fail <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 256
class Factorial():
    def __init__(self,n,mod):
        self.mod = mod
        self.factorial = [0 for _ in range(n+1)]
        self.inv = [0 for _ in range(n+1)]
        self.factorial[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.factorial[i+1] = self.factorial[i]*(i+1)%mod
        self.inv[n] = pow(self.factorial[n],mod-2,mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i+1]*(i+1)%mod


    def comb(self,m,k): #組み合わせ 0<=k<=m<=n
        return self.factorial[m]*self.inv[k]*self.inv[m-k]%self.mod

def solve():

    MOD = 1000000007

    r1,c1,r2,c2 = map(int,input().split())

    f = Factorial(2000010,MOD)

    ans = 0

    for i in range(r2-r1+1):
        ans += f.comb(r1+c2+i+1,r1+i+1)-f.comb(r1+c1+i,r1+i+1)
        ans %= MOD

    print(ans)

solve()

Measured memory_bytes: 133552
n = int(input())
k = list(str(n))
p = k[-1]
x= int(p)
if(x == 2 or x == 4 or x == 5 or x == 7 or x == 9):
    print("hon")
if(x == 0 or x == 1 or x == 6 or x == 8):
    print("pon")
if(x==3):
    print("bon")

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define ll long long
#define INF (1LL << 60)
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

ll dp[MAX_N][3];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi a(n);
    vs s(n);
    s[0] = "+";
    rep(i,n-1){
        cin >> a[i] >> s[i+1];
    }
    cin >> a[n-1];
    rep(i,n+1){
        rep(j,3){
            dp[i][j] = -INF;
        }
    }
    dp[0][0] = 0;
    rep(i,n){
        rep(j,3){
            if(s[i] == "+"){
                if(j == 0){
                    cmx(dp[i+1][j],dp[i][j]+a[i]);
                }else if(j == 1){
                    cmx(dp[i+1][j],dp[i][j]-a[i]);
                    cmx(dp[i+1][j-1],dp[i][j]-a[i]);
                }else{
                    cmx(dp[i+1][j],dp[i][j]+a[i]);
                    cmx(dp[i+1][j-1],dp[i][j]+a[i]);
                    cmx(dp[i+1][j-2],dp[i][j]+a[i]);
                }
            }else{
                if(j == 0){
                    cmx(dp[i+1][j],dp[i][j]-a[i]);
                    cmx(dp[i+1][j+1],dp[i][j]-a[i]);
                }else if(j == 1){
                    cmx(dp[i+1][j],dp[i][j]+a[i]);
                    cmx(dp[i+1][j+1],dp[i][j]+a[i]);
                    cmx(dp[i+1][j-1],dp[i][j]+a[i]);
                }else{
                    cmx(dp[i+1][j],dp[i][j]-a[i]);
                    cmx(dp[i+1][j-1],dp[i][j]-a[i]);
                    cmx(dp[i+1][j-2],dp[i][j]-a[i]);
                }
            }
        }
    }
    // rep(i,n+1){
    //     cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << "\n";
    // }
    cout << dp[n][0] << "\n";
    return 0;
}


Measured memory_bytes: 8448
import sys

ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lines = sys.stdin.readlines()

H, W = lines[0].strip().split(" ")

h = 0
w = 0
for line in lines[1:]:
    h += 1
    w = 0
    for word in line.strip().split(" "):
        if word == 'snuke':
            print "%s%s" % (ALPHABET[w], h)
            exit
        else:
            w += 1


Measured memory_bytes: 2572
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,K;
LL P[1000];

LL ans = 0;

void solve(){
	sort(P,P+N);
	for(int i=0;i<K;i++) ans += P[i];
}

int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) cin >> P[i];

    solve();

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

Measured memory_bytes: 3204
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <sstream>

#include <boost/range/irange.hpp>
using boost::irange;

using namespace std;

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

    size_t k;
    string s;
    cin >> s >> k;
    
    set<string> substrs;
    
    for(size_t l = 1; l <= s.size(); ++l)
    {
       for(size_t i = 0; i < s.size() - l + 1; ++i)
        {
            const auto ss = s.substr(i, l);
            //cout << '(' << i << ',' << l << ')' << ' ' << ss << '\n';
            if(substrs.size() < k)
            {
                substrs.insert(ss);                
            }
            else if(ss < *--end(substrs))
            {
                substrs.insert(ss);
                substrs.erase(--end(substrs));
            }
            //copy(begin(substrs), end(substrs), ostream_iterator<string>(std::cout, " ")); cout << endl;
        }
    }
    
    cout << *next(begin(substrs), k-1) << '\n';

    return 0;
}



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

int main()
{
  int n;
  
  cin >> n;
  
  int isAproved = 0;
  
  for (int i=0; i < n; i++)
  {
    int a;
    cin >> a;
    if (a % 2 == 0)
    {
      	if (a % 3 != 0 && a % 5 != 0) isAproved = 1;
    }
  }
  if (isAproved == 0) cout << "APPROVED" << endl;
  else                cout << "DENIED" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    const int dx[4] = {-1, 1, 0, 0};
    const int dy[4] = {0, 0, -1, 1};
    auto inside     = [&](int y, int x) { return 0 <= y && y < h && 0 <= x && x < w; };
    int ret         = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '#')
                continue;
            int sy = i;
            int sx = j;
            vvi dist(h, vi(w, -1));
            dist[sy][sx] = 0;
            queue<pii> q;
            q.push({sy, sx});
            while (!q.empty()) {
                auto p = q.front();
                q.pop();
                int y = p.first;
                int x = p.second;
                for (int k = 0; k < 4; ++k) {
                    int ny = y + dy[k];
                    int nx = x + dx[k];
                    if (inside(ny, nx) && s[ny][nx] == '.' && dist[ny][nx] == -1) {
                        dist[ny][nx] = 1 + dist[y][x];
                        q.push({ny, nx});
                    }
                }
            }
            for (int k = 0; k < h; ++k) {
                for (int l = 0; l < w; ++l) {
                    if (dist[k][l] != -1) {
                        chmax(ret, dist[k][l]);
                    }
                }
            }
        }
    }
    cout << ret << "\n";
    return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int q = cin.nextInt();
		int[] flag = new int[100009];
		int[] a = new int[100009];
		Arrays.fill(flag, 0);
		flag[1] = 1; 
		for(int i=2; i<=100000; i++) {
			for(int j=2*i; j<=100000; j+=i) {
				flag[j] = 1;
			}
		}
		for(int i=1; i<=100000; i++) {
			if(flag[i]==0 && flag[(i+1)/2]==0 && i!=2) {
				a[i] = a[i-1] + 1;
			}else
				a[i] = a[i-1];
		}
		while((q--)>0) {
			int l = cin.nextInt();
			int r = cin.nextInt();
			System.out.println(a[r]-a[l-1]);
		}
	}
}


Measured memory_bytes: 65312