akhauriyash/Code-Regression huggingface dataset:
// 問題名: Rummy
// URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2102&lang=jp
// 所要時間: 20分
// --感想--
// 資料で問題のすぐ上にnext_permutationが紹介してあったため、早く気付くことができた。next_permutationはまだ使い慣れていない
// ので、そらで書けるように練習したい。

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

int main(){
    int T;
    cin >> T;
    for (; T > 0; T--){
        int n, k, x[100010], d[100010];
        cin >> n >> k;
        if(k>n)
            k = n;
        for (int i = 0; i < n; i++)
            cin >> x[i];
        for (int i = 0; i < n - 1;i++)
            d[i] = x[i + 1] - x[i];
        sort(d, d + n - 1);
        int ans = x[n - 1] - x[0];
        for (int i = 0; i < k - 1;i++)
            ans -= d[n - 2 - i];
        cout << ans << endl;
    }
}


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

int main(){
int a,b,c,d,k,l,m;
cin >> a >> b >> c >> d ;
if (a-b>=0) k=a-b;
else k=b-a;
if (b-c>=0) l=b-c;
else l=c-b;
if (a-c>=0) m=a-c;
else m=c-a;
if(k<=d && l<=d) cout << "Yes" <<endl;
else if(m<=d)cout <<"Yes"<<endl;
else cout << "No" <<endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod =1e+9+7;

int main(){
    string s; cin>>s;
    if(s=="RRS"||s=="SRR")cout<<2<<endl;
    else if(s=="RRR")cout<<3<<endl;
    else if(s=="SSS")cout<<0<<endl;
    else cout<<1<<endl;
}












































Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main()
{
  int n;string s;
  cin>>n>>s;int c=0;
  for(int i=0;i<n-2;i++)
  {
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
      c++;
  }
  cout<<c;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve(ll H, ll W, vector<string> a) {
  cout << string(W + 2, '#') << endl;
  for (string i: a) {
    cout << "#" << i << "#" << endl;
  }
  cout << string(W + 2, '#') << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll H;
	ll W;
	scanf("%lld", &H);
	vector<string> a(H-1+1);
	scanf("%lld", &W);
	for (int i = 0 ; i <= H-1 ; i++) {
	  cin >> a[i];
	}
	solve(H, W, a);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int main(){
	int n, sum = 0, result = 0,result2 = 0;
  	int arr[100];
  	float average;
    int average1,average2;
  	cin >> n;
  	for(int i = 0;i < n;++i){
    	int temp;
      	cin >> temp;
        arr[i] = temp;
      	sum = sum + temp;
    }
  	average = (sum * 1.0)/ n;
    average1 = ceil(average);
    average2 = floor(average);
  	for(int i = 0;i < n;++i){
      result = result + pow((arr[i] - average1),2);
      result2 = result2 + pow((arr[i] - average2),2);
    }
    if(result < result2)
      cout << result;
    else{
      cout << result2;
    }
}

Measured memory_bytes: 256
/*Lower_Rating*/
/*Ex*/
/*鑷棴*/
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#include<vector>
#include<queue>
#include<bitset>
#include<set>
using namespace std;

#define LL long long
#define DB double
#define MOD 1000000007
#define Pr pair<int,int>
#define X first
#define Y second
#define MAXN 100000
#define eps 1e-10
#define INF 1000000000000
#define mem(x,p) memset(x,p,sizeof(x))

LL read(){
  LL x=0,F=1;char c=getchar();
  while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
  return x*F;
}
int add(int a,int b){return (a+b>=MOD)?a+b-MOD:a+b;}
int dec(int a,int b){return (a-b<0)?a-b+MOD:a-b;}
int mul(LL a,int b){return a*b%MOD;}

int n,a[MAXN+5],p[MAXN+5];

struct BIT{
    int C[(MAXN<<1)+5];
    int lowbit(int x){return x&(-x);}
    void Init(){mem(C,0);}
    void Insert(int x,int v){
        while(x<=(MAXN<<1)){
            C[x]+=v;
            x+=lowbit(x);
        }
    }
    int Query(int x){
        int res=0;
        while(x){
            res+=C[x];
            x-=lowbit(x);
        }return res;
    }
}T;

bool check(int val){
    int sum=0;LL res=0,tot=1LL*n*(n+1)/2;
    T.Init();
    T.Insert(MAXN,1);
    for(int i=1;i<=n;i++){
        if(a[i]>=val)sum++;
        else sum--;
        res+=T.Query(sum+MAXN);
        T.Insert(sum+MAXN,1);
    }
    return res>=(tot-res);
}
int main(){
    //freopen("median.in","r",stdin);
    //freopen("median.out","w",stdout);
    n=read();
    for(int i=1;i<=n;i++)a[i]=read(),p[i]=a[i];
    sort(p+1,p+n+1);
    int l=1,r=n,ans=0;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(p[mid]))l=mid+1,ans=mid;
        else r=mid-1;
    }
    printf("%d",p[ans]);
}

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using chrono::system_clock;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
    ll A,B,C;
    cin>>A>>B>>C;
    int res = 0;

    auto start = system_clock::now();
    while(true)
    {
        auto now = system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(now-start).count();
        if(msec>1700)
        {
            cout << -1 << endl;
            goto end;
        }
        REP(i,10000)
        {
            if(A%2+B%2+C%2>0)
            {
                cout << res<< endl;
                goto end;
            }
            ll tmpa=(B+C)/2;
            ll tmpb=(A+C)/2;
            ll tmpc=(A+B)/2;
            A=tmpa;
            B=tmpb;
            C=tmpc;
            res++;
        }
    }
end:;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1000010;
int n,a[maxn],b[maxn],c[maxn],dp[maxn][5];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>c[i];
    dp[1][1]=a[1];dp[1][2]=b[1];dp[1][3]=c[1];
    for(int i=2;i<=n;i++){
        dp[i][1]+=max(dp[i-1][2],dp[i-1][3])+a[i];
        dp[i][2]+=max(dp[i-1][1],dp[i-1][3])+b[i];
        dp[i][3]+=max(dp[i-1][1],dp[i-1][2])+c[i];
    }
    cout<<max(dp[n][3],max(dp[n][1],dp[n][2]));
    return 0;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
bool h[270];
int ans,rans;
int main()
{
	int n;
	cin>>n;
	string a;
	cin>>a;
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<270;j++)
		{
			h[j]=0;
		}
		ans=0;
		for(int j=0;j<i;j++)
		{
			h[a[j]]=true;
		}
		for(int j=i;j<n;j++)
		{
			if(h[a[j]])
			{
				ans++;
				h[a[j]]=false;
			} 
		}
		rans=max(rans,ans);
	}
	cout<<rans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// typedef
using ll  = long long;
using str = string;
using PL  = pair<ll, ll>;
using P   = pair<int, int>;
using VL  = vector<ll>;
using VI  = vector<int>;
using VS  = vector<str>;
using VP  = vector<P>;
using VPL = vector<PL>;
using VVL = vector<VL>;
using VVI = vector<VI>;

// const num
const ll INF         = 1e18 + 18;
const ll MAX         = 100005;
const ll MOD         = 1000000007;
const long double PI = acosl(-1.0);

// loop
#define REP(i, a, b) for(ll(i) = (a); (i) < (b); (i)++)
#define RREP(i, a, b) for(ll(i) = (a); (i) >= (b); (i)--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)

// YesNo
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
// All
#define ALL(v) v.begin(), v.end()
#define deduplicate(v) (v).erase(unique(ALL(d)), (v).end())

int main(void) {
	int n, m;
	cin >> n >> m;
	int p;
	str s;
	int penalty  = 0;
	int answered = 0;
	vector<bool> AC(n + 1, false);
	VI WA(n + 1, false);
	rep(i, m) {
		cin >> p >> s;
		if(!AC[p] && s == "AC") {
			AC[p] = true;
			answered++;
			penalty += WA[p];
		}
		if(!AC[p] && s == "WA") {
			WA[p]++;
		}
	}
	cout << answered << ' ' << penalty << endl;
	return 0;
}

Measured memory_bytes: 3688
N, K = map(int,input().split())
S = list(input())
if S[K-1] == 'A':
    S[K-1] = 'a'
elif S[K-1] == 'B':
    S[K-1] = 'b'
else:
    S[K-1] = 'c'
T = ''.join(S)
print(T)

Measured memory_bytes: 3060
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
#[A, B] = list(map(int,input().split()))
#N = 2
#A = [1, 2]
#B = [50,50]
#C = [50]
ans = sum(B) 
for i in range(len(A)-1):
    if A[i] + 1 == A[i+1]:
        ans += C[A[i]-1]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N), RG(N);
    vector<int> R(N);
    rep(i, M) {
        int f, t;
        cin >> f >> t;
        f--; t--;
        G[f].push_back(t);
        RG[t].push_back(f);
        R[t]++;
    }
    
    vector<int> ts;
    queue<int> q;
    rep(i, N) {
        if(R[i] == 0) q.push(i);
    }
    
    while(!q.empty()) {
        int t = q.front();
        q.pop();
        ts.push_back(t);
        for(int v: G[t]) {
            R[v]--;
            if(R[v] == 0) q.push(v);
        }
    }

    vector<int> depth(N, -1);
    for(int v: ts) {
        int d = 0;
        for(int vv: RG[v]) {
            d = max(d, depth[vv] + 1);
        }
        depth[v] = d;
    }
    
    int ans = 0;
    rep(i, N) ans = max(ans, depth[i]);
    output(ans);
    
    return 0;
}


Measured memory_bytes: 12540
//abc066a
#include <stdio.h>
#include <stdlib.h>
int compar(const void *p0, const void *p1){
	const int a=*(const int*)p0, b=*(const int*)p1;
//	return a-b;
	return -(a-b);
}
void solve(void)
{
#if 0
	const int n=3;
	const int k=2;
#else
	int n, k;
#endif
	int a[100];
	int sum=0;
	int i;
	scanf("%d %d", &n,&k);
	for(i=0;i<n;++i){
		scanf("%d", a+i);
	}
	qsort(a, n, sizeof(*a), compar);
	for(i=0;i<k;++i){
		sum+=a[i];
	}
	printf("%d\n", sum);
}
int main(int argc, char **argv){
	solve();
	return 0;
}


Measured memory_bytes: 128
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] array = br.readLine().split(" ");
        int H = Integer.parseInt(array[0]);
        int W = Integer.parseInt(array[1]);
		while(H!=0&&W!=0){
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					System.out.print("#");
				}
				System.out.println("");
			}
			System.out.println("");
			array = br.readLine().split(" ");
	        H = Integer.parseInt(array[0]);
	        W = Integer.parseInt(array[1]);
		}
	}
}

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

int main() {
	string s;
	cin >> s;
	int n = s.size();
	vector<int> mod10(n); // 10^n mod 2019
	mod10[0] = 1;
	rep(i,n-1) mod10[i+1] = (10 * mod10[i]) % 2019;
	vector<int> t(n+1,0);
	for(int i=n-1;i>=0;i--) {
		t[i] = (mod10[n-1-i] * (s[i] - '0') + t[i+1]) % 2019;
		//cout <<i  <<" " << t[i] << endl;
	}
	vector<ll> cnt(2019,0);
	rep(i,n+1) cnt[t[i]]++;
	//rep(i,2019) if (cnt[i] != 0) cout << i << "," << cnt[i] << endl; 
	ll ans = 0;
	rep(i,2019) ans += cnt[i] * (cnt[i] - 1LL) / 2LL;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5212
N=int(input())
A=list(map(int,input().split()))
d={}
for a in A:
    if a not in d:
        d[a]=1
    else:
        d[a]+=1
ans=0
for k in d.keys():
    e=d[k]
    ans+=e*(e-1)//2
for a in A:
    keep=ans
    e=d[a]
    temp=e*(e-1)//2
    ans-=temp
    ans+=(e-1)*(e-2)//2
    print(ans)
    ans=keep

Measured memory_bytes: 86348
#include <stdio.h>

int main(void){
    char x[1000] = {};
    int sum = 0;
    int num[1000] = {};
    while(1){
        scanf("%s", x);
        if( x[0] == '0' )   break;
        for(int w = 0; w <= 1000; w++){
            num[w] = x[w] - '0'; if( num[w] < 0 )    num[w] = 0;
            sum = sum + num[w];
        }
        printf("%d\n", sum);
        sum = 0;
        for(int w = 0; w <= 1000; w++){
            x[w] = '0';
        }
    } 
    return 0;
}


Measured memory_bytes: 2148
s=input()[::-1]
a="dream"[::-1]
b="dreamer"[::-1]
c="erase"[::-1]
d="eraser"[::-1]
i=0
ans="YES"
while i<len(s):
    if a in s[i:i+5]:
        i+=5
    elif b in s[i:i+7]:
        i+=7
    elif c in s[i:i+5]:
        i+=5
    elif d in s[i:i+6]:
        i+=6
    else :
        ans="NO"
        break

print(ans)

Measured memory_bytes: 9260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(void)
{
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int,int>>> ken(n+1);
    
    REP(i,m){
        int p, y;
        cin >> p >> y;
        ken[p].push_back(pair<int, int>(y, i));
    }

    FOR(i,1,ken.size()){
        sort(all(ken[i]));
    }

    vector<string> id(m);
    FOR(i,1,ken.size()){
        for (int j = 0; j < ken[i].size(); j++)
        {
            char tmp[13];
            sprintf(tmp, "%06d%06d", (int)i,j + 1);
            id[ken[i][j].second] = tmp;
        }
    }

    REP(i,id.size()){
        cout << id[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 12416
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n, m; cin >> n >> m;
    vector<vector<ll>> P(m);
    rep(i, n){
        ll a, b; cin >> a >> b;
        if(a<=m)P[m-a].push_back(b);
    }
    ll sum = 0;
    priority_queue<ll, vector<ll>> que;
    for(int i=m-1; i>=0; i--){
        for(ll p: P[i]) que.push(p);
        if(!que.empty()){
            ll num = que.top();que.pop();
            sum += num;
        }
    }
    cout << sum << ln;
}


Measured memory_bytes: 8368
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) {
	if(a == 0){
		return b;
	} else if (b == 0){
		return a;
	} else {
	  if(a < b) return gcd(b, a);
	  ll r;
	  while ((r=a%b)) {
	    a = b;
	    b = r;
	  }
	  return b;
	}
}
ll sum(ll n) {
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

int main(){
	ll A, B, K;
	cin >> A >> B >> K;
	for(ll i = 0; i < K; i++){
		if (i % 2 == 0){
			if(A % 2 == 0){
				A /= 2;
				B += A;
			} else {
				A -= 1;
				A /= 2;
				B += A;
			}
		} else {
			if(B % 2 == 0){
				B /= 2;
				A += B;
			} else {
				B -= 1;
				B /= 2;
				A += B;
			}
		}
	}
	cout << A << " " << B << endl;
}

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

int main()
{
	int n, br1=0, br2=0, br3=0, a2, b;
	cin >> n;
	int p[n+1], q[n+1], a[n+1];
	for(int i=0; i<n; i++) cin >> p[i];
	for(int i=0; i<n; i++) cin >> q[i];

	for(int i=1; i<=n; i++) a[i-1] = i;

	do{
		br3++;
		for(int j=0; j<n; j++){
			if(a[j] != p[j]) br1++;
			if(a[j] != q[j]) br2++;
		}
		if(br1 == 0) a2 = br3;
		if(br2 == 0) b = br3;
		br1 = 0, br2 = 0;
	}while(next_permutation(a, a+n));

	cout << abs(a2-b);

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
N = int(input())

def digit_sum(n):
    return sum(map(int, list(str(n))))

ans = float('inf')
for i in range(1, N):
    a = digit_sum(i)
    if a > ans:
        continue
    ans = min(ans, a + digit_sum(N-i))
print(ans)

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

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

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

#define l first
#define r second

const int inf = 1000000037;
const int maxn = 100005;

int n, ans, lmx, rmn = inf, sec = inf;
pair < int, int > seg[maxn], sets[maxn];

bool cmp_my (pair < int, int > &x, pair < int, int > &y) {
	if (x.first == y.first)
		return x.second > y.second;
	return x.first < y.first;
}

signed main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d %d", &seg[i].l, &seg[i].r);
		lmx = max(lmx, seg[i].l), rmn = min(rmn, seg[i].r);
	}
	for (int i = 1; i <= n; ++i) {
		ans = max(ans, max(rmn - lmx + 1, 0) + seg[i].r - seg[i].l + 1);
		sets[i] = make_pair(max(seg[i].r - lmx + 1, 0), max(rmn - seg[i].l + 1, 0));
	}
	sort(sets + 1, sets + n + 1, cmp_my);
	for (int i = 1; i <= n; ++i) {
		if (sec != inf)
			ans = max(ans, sets[i].first + sec);
		sec = min(sec, sets[i].second);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 5384
import java.util.*;
 
public class Main {
	static Scanner scanner = new Scanner(System.in);
 
	public static void main(String[]$) {
		String a = scanner.next();
		String b = scanner.next();
		int compare1 = Integer.compare(a.length(), b.length());
		int compare2 = a.compareTo(b);
		if (a.equals(b)) {
			System.out.println("EQUAL");
		} else if (compare1 == 0) {
			System.out.println(0 < compare2 ? "GREATER" : "LESS");
		} else {
			System.out.println(0 < compare1 ? "GREATER" : "LESS");
		}
	}
}

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

int main(){
	int n,c; cin>>n>>c;
	int S[n], T[n], C[n];
	rep(i, n) cin>>S[i]>>T[i]>>C[i];
	int mx_t = 200002; // max time zone
	vector<int> R(mx_t, 0); // Recorder
	rep(cc, c){ // c candidate, cc:[0,C-1]->cc+1:[1,C]
		vector<int> TZ(mx_t, 0); // time zone
		rep(i, n)
			if(C[i] == cc+1){
				TZ[2*S[i] - 1]++;
				TZ[2*T[i]]--;
			}
		rep(i, mx_t - 1){
			TZ[i+1] += TZ[i];
			if(TZ[i+1] > 0) R[i+1]++;
		}
	}
	int ans = 0;
	rep(i, mx_t) ans = max(ans, R[i]);
	cout<< ans <<endl;
}


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

#define LINE_BUF_SIZE 1024
#define mod (int)(1e9+7)

int prime_factor_judge(int n){  /*引数が素数だったら1を返す*/
    int i;
    int judge = 1;
    for(i=2;i<n;i++){
        if(n % i == 0)judge = 0;
    }
    return judge;
}

int main(){

    int i,j,k;
    long long int N;
    char line[LINE_BUF_SIZE];
    
    fgets(line,sizeof(line),stdin);
    sscanf(line,"%lld", &N);

    long long int count = 1;
 
    int judge;
    int num=1;
    long int num_hold = 0;

    for(i=2;i<=N;i++){

        judge = prime_factor_judge(i);

        if(judge == 1){ /*iが素数であるかどうか*/

            for(j=i;j<=N;j++){
 
                while(j % (int)pow(i,num) == 0)num += 1;
            
                num_hold += num - 1;
                num = 1;

            }
        }

        count *= (num_hold + 1);
        count = count % mod;
        num = 1;
        num_hold = 0;

    }

    printf("%lld",count);

    return 0;

}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;


int a[1<<20][20];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int m = 1<<n;
    string s;
    cin>>s;
    rep(i,m){
        cin>>a[i][0];
        a[i+m][0]=a[i+2*m][0]=a[i+3*m][0]=a[i][0];
    }
    rep(j,n){
        rep(i,2*m){
            if(a[i+(1<<j)][j]==0)continue;
            if(s[abs(a[i][j]-a[i+(1<<j)][j])-1]=='1'){
                a[i][j+1]=max(a[i][j],a[i+(1<<j)][j]);
            }
            else {
                a[i][j+1]=min(a[i][j],a[i+(1<<j)][j]);
            }
        }
    }

    rep(i,m){
        cout<<a[i][n]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 85280
#include <bits/stdc++.h>
using namespace std;
#define Sz(a) ((int)(a).size())
const int maxn = 200009;
const int MOD = 1e9 + 7;
int main(){
#ifdef LOCAL
  freopen("a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  int n,k;cin>>n>>k;
  vector<int> A(n);
  for(int i=0;i<n;++i)cin>>A[i];
  sort(A.begin(),A.end());
  cout<<accumulate(A.begin(),A.begin()+k,0)<<'\n';
  
  return 0;
}
//2020.06.23 17:06:39


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

using namespace std;

typedef long long ll;

struct item{
    ll value;
    ll weight;
};

int n,w;
const ll inf = (ll)1e15;
item items[100005];
bool check[105][100005];
ll memo[105][100005];

ll dp(ll pos,ll we){
    if(we<0) return -inf;
    if(we==0||pos>n) return 0;

    if(check[pos][we])
        return memo[pos][we];

    ll op1= items[pos].value+dp(pos+1,we-items[pos].weight);
    ll op2= dp(pos+1,we);

    memo[pos][we]=max(op1,op2);
    //cout << pos << ' ' << we  << ' ' << op1 << ' ' << op2<<' '<<  memo[pos][we]<<endl;

    check[pos][we]=true;
    return memo[pos][we];


}

int main() {
    cin >> n >>w;
    for(int i = 1;i<=n;i++){
        cin>>items[i].weight>>items[i].value;
    }

    cout << dp(1,w);

    return 0;
}

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

int main(void)
{
  int sx, sy, tx, ty;
  cin>>sx>>sy>>tx>>ty;
  int x=tx-sx;
  int y=ty-sy;
  for(int i=1; i<=y; i++)
    cout<<'U';
  for(int i=1; i<=x; i++)
    cout<<'R';
  for(int i=1; i<=y; i++)
    cout<<'D';
  for(int i=1; i<=x; i++)
    cout<<'L';
  cout<<'L';
  for(int i=1; i<=y; i++)
    cout<<'U';
  cout<<"UR";
  for(int i=1; i<=x; i++)
    cout<<'R';
  cout<<"DR";
  for(int i=1; i<=y; i++)
    cout<<'D';
  cout<<"DL";
  for(int i=1; i<=x; i++)
    cout<<'L';
  cout<<'U'<<endl;
  return 0;
}


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

#define ll long long
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >

const int N = 2e5 + 7;
const int INF = 1e9 + 7;

int a, b, c;

main(){
    cin >> a >> b >> c;
    if (a == b && b == c)
        puts("Yes");
    else
        puts("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	cin >> n;
	vector<int> s(n);
	int sum = 0;
	REP(i, n){
		cin >> s[i];
		sum += s[i];
	}

	if (sum % 10){
		cout << sum << endl;
		return 0;
	}

	sort(ALL(s));

	REP(i, n){
		if (s[i] % 10){
			sum -= s[i];
			break;
		}
		else if (i == (n-1)){
			cout << 0 << endl;
			return 0;
		}
	}

	cout << sum << endl;




}


Measured memory_bytes: 256
n = gets.to_i
s = Array.new(n) { gets.chomp }
h = Hash.new(0)
s.shift.each_char { |c| h[c] += 1 }

s.each do |word|
  tmp = Hash.new(0)
  word.each_char { |c| tmp[c] += 1 }
  h.each { |k, v| h[k] = [tmp[k], v].min }
end

arr = h.keep_if { |k, v| v != 0 }.sort_by { |k, v| k }

puts arr.map { |k, v| k * v }.join

Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)

typedef long long ll;
typedef pair<int, int> P;



int main(int argc, const char * argv[]) {

	const int mod = 1000000007;
	string s;
	cin >> s;
	int str_size = s.size();
	reverse(s.begin(), s.end());
	vector< vector<long> > dp(str_size+1, vector<long> (13,0));
    int digit = 1;
    dp[0][0] = 1;
	rep(i, str_size){
		if (s[i] == '?'){
			rep(j,10){
				rep(k, 13){
					dp[i+1][(j * digit + k) % 13 ] += dp[i][k];

				}
			}
		}else{
			rep(k, 13){
				dp[i+1][( (s[i]- '0') * digit + k) % 13 ] += dp[i][k];
			}
		}
		rep(j, 13) dp[i+1][j] %= mod;
		
        digit *=10;
        digit %=13;
	}
	cout << dp[str_size][5] << endl;
  
	return 0;
}


Measured memory_bytes: 13632
r, g, b = map(int, input().split())
k = int(input())
# print(r,g,b)
# print(k)

# def gr(green,red):
#     # if g r: return Tree
#     # else: return False
#     return red < green
# def bg(brue,green):
#     # if g r: return Tree
#     # else: return False
#     return green < brue

def dfs(i ,r,g,b):
    if i>k:
        return False
    if r<g<b:
        return True
    if dfs(i+1,r*2,g,b): return True
    if dfs(i+1,r,g*2,b): return True
    if dfs(i+1,r,g,b*2): return True

    return False

if dfs(0,r,g,b):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9184
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;

int LCS(string s1, string s2){
    int l1 = s1.size();
    int l2 = s2.size();

    int dp[l1 + 1][l2 + 1];
    for(int i = 0; i < l1 + 1; i++){
        for(int j = 0; j < l2 + 1; j++){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
            }
            else if(s1[i - 1] == s2[j - 1]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }else{
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    return dp[l1][l2];
}

int main(void){
    int n;
    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        string s1, s2;
        cin >> s1;
        cin >> s2;
        printf("%d\n", LCS(s1, s2));
    }


    return 0;
}



Measured memory_bytes: 7272
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

#define MOD (1000000007)

int main() {
	int n, index[1001] = { 0 };
	bool table[1001] = { false };
	vector<int> prime;

	for (int i = 2; i <= 1000; ++i) {
		if (table[i] == false) {
			for (int j = i; j <= 1000; j += i) {
				table[j] = true;
			}
			prime.push_back(i);
		}
	}

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		int temp = i;
		for (int j = 0; j < prime.size(); ++j) {
			while (temp % prime[j] == 0) {
				index[prime[j]]++;
				temp /= prime[j];
			}
		}
	}
	long long ans = 1;
	for (int i = 0; i < 1001; ++i) {
		if (index[i] > 0) {
			ans = ans * (index[i] + 1) % MOD;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<chrono>
#include<climits>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
 
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {for(auto x : v) cout << x << ' '; cout << endl;}
#define printn(v, n) {for(int _i = 0; _i < n; _i++) cout << *(v + _i) << ' '; cout << endl;}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
 
const int MAXN = 1000 + 20;

int n, m;
double a;

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

    cin >> n;
    string s;
    cin >> s;
    if(n >= 3200) cout << s << endl;
    else cout << "red" << endl;


    return 0;
}











Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;


int main() {
  string S,T; cin>>S>>T;
  int s=S.size(),t=T.size(),ans=0;
  for(int i=0;i<=s-t;i++){
    int temp=0;
    rep(j,t){
      if(S.at(i+j)==T.at(j)) temp++;
    }
    ans=max(ans,temp);
  }
  cout<<t-ans;
}

Measured memory_bytes: 3604
#include <iostream>
        #include <vector>
        #include <string>
        using namespace std;
        int main(){
          string s;
          int a=0,b=2,x0,y0,xdp[20000]={},ydp[20000]={};
          vector<int> x,y;
          cin>>s;
          for(int i=0;i<(int)s.size();i++){
            if(s[i]=='F') a++;
            else {
              if(b%2) y.push_back(a);
              else x.push_back(a);
              b++;
              a=0;
            }
          }
          if(b%2) y.push_back(a);
          else x.push_back(a);
          /*  for(int i=0;i<x.size();i++) cout<<x[i]<<" ";                                                                             
          cout<<endl;                                                                                                                  
          for(int i=0;i<y.size();i++) cout<<y[i]<<" ";                                                                                 
          cout<<endl;                                                                                                                  
          */
          xdp[10000+x[0]]=1;ydp[10000]=1;
x.erase(x.begin());
          for(int i=0;i<(int)x.size();i++){
            int tmp[20000]={};
            for(int j=0;j<20000;j++) if(xdp[j]) tmp[j+x[i]]=tmp[j-x[i]]=1;
            for(int j=0;j<20000;j++) xdp[j]=tmp[j];
          }
          for(int i=0;i<(int)y.size();i++){
            int tmp[20000]={};
            for(int j=0;j<20000;j++) if(ydp[j]) tmp[j+y[i]]=tmp[j-y[i]]=1;
            for(int j=0;j<20000;j++) ydp[j]=tmp[j];
          }
          cin>>x0>>y0;
          if(-10000<=x0&&x0<10000&&-10000<=y0&&y0<10000&&xdp[x0+10000]*ydp[y0+10000]) cout<<"Yes"<<endl;
          else cout<<"No"<<endl;
          return 0;
        }

Measured memory_bytes: 512
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static boolean solve() {
		int n = in.nextInt();
		int r = in.nextInt();
		if (n + r == 0) return false;

		ArrayList<Integer> list = new ArrayList<Integer>();
		ArrayList<Integer> list2 = new ArrayList<Integer>();
		for (int i=1; i<=n; i++) {
			list.add(i);
		}
		while (r-- > 0) {
			int p = in.nextInt();
			int c = in.nextInt();
			for (int i=0; i<c; i++) {
				list2.add(list.get(n-p-i));
				list.remove(n-p-i);
			}
			for (int i=list2.size()-1; i>=0; i--) {
				list.add(list2.get(i));
			}
			list2.clear();
		}

		out.println(list.get(n-1));
		return true;
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while(solve());
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 37408
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Main {

	private static List<Integer>[] G;
	private static List<Integer>[] rG;
	private static ArrayList<Integer> vs = new ArrayList<Integer>();
	private static boolean[] used;
	private static int[] cmp;

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		int V = nextInt();
		int E = nextInt();

		G = new List[V];
		rG = new List[V];
		for (int i = 0; i < V; i++) {
			G[i] = new ArrayList<Integer>();
			rG[i] = new ArrayList<Integer>();
		}

		for (int i = 0; i < E; i++) {
			int from = nextInt();
			int to = nextInt();
			G[from].add(to);
			rG[to].add(from);
		}

		used = new boolean[V];
		cmp = new int[V];
		for (int i = 0; i < V; i++) {
			if (!used[i]) {
				dfs(i);
			}
		}

		used = new boolean[V];
		int k = 0;
		for (int i = vs.size() - 1; i >= 0; i--) {
			if (!used[vs.get(i)]) {
				rdfs(vs.get(i), k++);
			}
		}

		List<Integer>[] groups = new List[k];
		for (int i = 0; i < groups.length; i++) {
			groups[i] = new ArrayList<Integer>();
		}
		for (int i = 0; i < cmp.length; i++) {
			groups[cmp[i]].add(i);
		}

		int Q = nextInt();
		for (int i = 0; i < Q; i++) {
			int u = nextInt();
			int v = nextInt();
			if (cmp[u] == cmp[v]) {
				System.out.println(1);
			} else {
				System.out.println(0);
			}
		}

	}

	static void dfs(int v) {
		used[v] = true;
		for (int i = 0; i < G[v].size(); i++) {
			if (!used[G[v].get(i)]) {
				dfs(G[v].get(i));
			}
		}
		vs.add(v);
	}

	static void rdfs(int v, int k) {
		used[v] = true;
		cmp[v] = k;
		for (int i = 0; i < rG[v].size(); i++) {
			if (!used[rG[v].get(i)]) {
				rdfs(rG[v].get(i), k);
			}
		}
	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1;
	}

}

Measured memory_bytes: 43628
#include<stdio.h>
int main(){
  int a ,b ;
  scanf("%d%d",&a,&b);

  if(a+(a-1) > a+b && a+(a-1) > b+(b-1)){
    printf("%d",a+(a-1));
  }else if(b+(b-1) > a+b && b+(b-1) > a+(a-1)){
    printf("%d",b+(b-1));
  }else{
    printf("%d",a+b);
  }




}


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

typedef long long ll;
const int N = 5050, M = N * N;

ll n, a[2], b[2], c[2], dp[M];

void _max(ll &a, ll b) {
	a = max(a, b);
}

ll solve(ll n, int now, int nxt) {
	memset(dp, 0, sizeof dp);
	iota(dp, dp + n + 1, 0);
	for (int i = 1; i <= n; i++) {
		if(i >= a[now])
			_max(dp[i], dp[i - a[now]] + a[nxt]);
		if(i >= b[now])
			_max(dp[i], dp[i - b[now]] + b[nxt]);
		if(i >= c[now])
			_max(dp[i], dp[i - c[now]] + c[nxt]);
	}
	return dp[n];
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	cin >> a[0] >> b[0] >> c[0];
	cin >> a[1] >> b[1] >> c[1];
	n = solve(n, 0, 1);
	n = solve(n, 1, 0);
	cout << n;
	return 0;
}

Measured memory_bytes: 199680
#include <bits/stdc++.h>
using namespace std;
void alert(vector<int> vec){
  int64_t N = vec.size();
  for(int i=0; i<N-1; i++) cout << vec.at(i) << " ";
  cout << vec.at(N-1) << endl;
}

int main(){
  int64_t A, B, C, K;
  cin >> A >> B >> C >> K;
  int64_t ans = 0;
  if(K>A){
    K -= A;
    ans += A;
    if(K>B){
      K -= B;
      ans -= K;
    }
  }
  else ans = K;
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;

int main(){
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c,n,m;
	cin>>a>>b>>c;
	if((a+b+c)>=22)
		cout<<"bust"<<endl;
	else
		cout<<"win"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    string s;
    int ans=0;
    cin>>n>>s;
    for(int x=0;x<n;x++){
    string S=s.substr(x,n-x);
    
    vector<int> Z(S.size());
    Z[0] = S.size();
    int i = 1, j = 0;
    while(i < S.size()){
        while(i + j < S.size() && S[j] == S[i + j]) j++;
        Z[i] = j;
        if(j == 0) { i++; continue; }
        int k = 1;
        while(i + k < S.size() && k + Z[k] < j){
            Z[i + k] = Z[k];
            k++;
        }
        i += k; j -= k;
    }
    int m=n-x;
    for(int y=0;y<m;y++){
    	ans=max(ans,min(Z[y],y));
    }
}
   
    cout << ans <<endl;
    return 0;
}


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

using namespace std;

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))

template <class T> inline T bigmod(T p, T e, T m)
{
    T ret = 1;
    for (; e > 0; e >>= 1)
    {
        if (e & 1)
            ret = (ret * p) % m;
        p = (p * p) % m;
    }
    return (T)ret;
}

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1)
{
    cerr << name << " is " << arg1 << std::endl;
}
template < typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " is " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif

string s;

long long dp[100005][13];

long long recur(int pos,int rem)
{

    if(s.size()==pos)
    {
        if(rem==5)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
    if(dp[pos][rem]!=-1){
        return dp[pos][rem];
    }
    long long ans=0;

    if(s[pos]!='?'){
        ans+=recur(pos+1,(rem*10+s[pos]-'0')%13);
    }
    else{
        for(int i=0;i<=9;i++){
            ans+=recur(pos+1,(rem*10+i)%13);
        }
    }
    return dp[pos][rem]=ans%1000000007ll;
}

void solve()
{
    SET(dp);

    cin>>s;

    long long res=0;

    res=recur(0,0);

    cout<<res<<endl;
}

int main()
{
    int t=1;

    while (t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 18432
S = raw_input()
T = raw_input()
 
if len(S) < len(T):
  print 'UNRESTORABLE'
  exit()

answers = []

for i in xrange(len(S) - len(T) + 1):
    for j in xrange(len(T)):
        flag = True
        if S[i+j] != '?' and S[i+j] != T[j]:
            flag = False
            break
    if flag:
        answers.append((S[:i] + T + S[i+len(T):]).replace("?", "a"))

if len(answers) == 0:
    print 'UNRESTORABLE'
    exit()

answers.sort()
print answers[0]

Measured memory_bytes: 2692
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int x,y,n,warx,wary;
    while(cin>>x>>y){
        if(x==0&&y==0)break;
        int floor[100][100]={{0}},war[100][100]={{0}};
        floor[1][0]=1;
        cin>>n;
        while(n--){
            cin>>warx>>wary;
            war[warx][wary]=1;
        }
        for(int i=1;i<100;i++){
            for(int j=1;j<100;j++){
                if(war[i][j]!=1){
                    floor[i][j]=floor[i-1][j]+floor[i][j-1];
                }
            }
        }
        cout<<floor[x][y]<<endl;
    }

    return 0;
}

Measured memory_bytes: 1244
n,m = map(int,input().split())
avec = [[0 for i in range(m)]for j in range(n)]
bvec = [0 for i in range(m)]
for i in range(n):
    nums = [int(e) for e in input().split()]
    for j in range(m):
        avec[i][j] = nums[j]
        
for i in range(m):
    bvec[i] = int(input())

for i in range(n):
    cvec = 0
    for j in range(m):
        cvec = cvec + (avec[i][j] * bvec[j])
    print(cvec)


Measured memory_bytes: 5792
#include <cstdio>
int main() {
	int n;
	while (scanf("%d",&n)) {
		if (n == 0) break;
		int res = 0;
		for (int i=0; i<n/4; i++) {
			int in; scanf("%d",&in);
			res += in;
		}
		printf("%d\n",res);
	}
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

int main(){
	long i, n, m;
	scanf("%ld %ld", &n, &m);
	long x, y;
	long sumx = 0;
	for(i = 0; i < n; i++){
		scanf("%ld", &x);
		sumx += x*(i*2-(n-1));
	}
	sumx %= MOD;
	long sumy = 0;
	for(i = 0; i < m; i++){
		scanf("%ld", &y);
		sumy += y*(i*2-(m-1));
	}
	sumy %= MOD;
	printf("%ld\n", sumx*sumy%MOD);

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define SZ(x) ((int)(x).size)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

int main(){
    ll x=0,y,d=0,n,h,w,k,m,max=-100,ans=0,ptr=0,sum=0;
    string s,s1,s2;
    bool f=true;
    cin >> n;
    VI a(n);
    VI b(100000);
    rep(i,n){
        cin >> a[i];
        b[a[i]]++;
    }
    max = b[0] + b[1]; 
    for(int i=1;i<100000;i++){
        if(b[i-1]+b[i]+b[i+1] > max)
            max = b[i-1]+b[i]+b[i+1];
    }
    if(b[99998]+b[99999]+b[100000] > max)
        max = b[99998]+b[99998]+b[99999];
    
    cout << max << endl;
    return 0;
}

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

long N, ans;
vector<pair<long, long>> D;

int main(void) {

    cin >> N;

    for (long i = 2; i * i <= N; i++) {
        long e = 0;
        if (N % i) continue;

        while (N % i == 0) {
            e++;
            N /= i;
        }

        D.push_back({i, e});
    }
    D.push_back({N,1});

    for (auto d: D) {
        long k;
        if (d.first == 1) continue;
        for (k = 1; k * (k + 1) <= 2 * d.second; k++);
        ans += k-1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const ll INF=1LL<<60;
const ll mod=1E9+7;


int main(){
  int a,b,h,m;
  cin >> a >> b >> h >> m;
  double s=2*M_PI*abs(60*h-11*m)/double(60*12);
  s=min(s,2*M_PI-s);
  cout << fixed << setprecision(10) << sqrt(a*a+b*b-double(2*a*b*cos(s)));
}


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

using namespace std;

#define MAX 15

int H,W,px,py,bx,by,gx,gy;
int field[MAX][MAX];
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

struct State{
  int x1,y1,x2,y2,d;
  State(int x1,int y1,int x2,int y2,int d) : 
    x1(x1),y1(y1),x2(x2),y2(y2),d(d) {}
};

bool Valid(int x,int y){
  if(field[y][x] == 1) return false;
  return 0 <= x && x < W && 0 <= y && y < H;
}

int bfs(){
  bool visited[MAX][MAX][MAX][MAX];
  memset(visited,false,sizeof(visited));
  deque<State> Q;
  Q.push_front(State(px,py,bx,by,0));

  while(!Q.empty()){
    State s = Q.front(); Q.pop_front();
    if(s.x2 == gx && s.y2 == gy){
      return s.d;
    }
    if(visited[s.y1][s.x1][s.y2][s.x2]) continue;
    visited[s.y1][s.x1][s.y2][s.x2] = true;
    
    for(int i = 0 ; i < 4 ; i++){
      int nx = s.x1 + dx[i];
      int ny = s.y1 + dy[i];
      if(nx == s.x2 && ny == s.y2) continue;
      if(!Valid(nx,ny)) continue;
      Q.push_front(State(nx,ny,s.x2,s.y2,s.d));
    }
    for(int i = 0 ; i < 4 ; i++){
      int nx = s.x1 + dx[i];
      int ny = s.y1 + dy[i];
      int nnx = s.x2 + dx[i];
      int nny = s.y2 + dy[i];
      
      if(nx == s.x2 && ny == s.y2){
        if(Valid(nx,ny) && Valid(nnx,nny)){
          Q.push_back(State(nx,ny,nnx,nny,s.d+1));
        }
      }
    }
  }
  return -1;
}

int main(){
  while(cin >> W >> H, W){
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
        cin >> field[i][j];
        if(field[i][j] == 4){
          px = j; py = i;
        }else if(field[i][j] == 2){
          bx = j; by = i;
        }else if(field[i][j] == 3){
          gx = j; gy = i;
        }
      }
    }
    cout << bfs() << endl;
  }
  return 0;
}

Measured memory_bytes: 1256
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <iomanip>

using namespace std;

signed main() {
	int n, k;
	cin >> n >> k;
	if (k == 1) {
		cout << 0 << endl;
	}
	else
		cout << (n - k);
	return 0;
}


Measured memory_bytes: 256