akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(){
    long long int N,R=0,G=0,B=0,ans=0;
    cin >> N;
    vector<long long int> sumg(N),sumr(N),sumb(N);
    string S;
    cin >> S;

    if(S[0]=='R'){
        sumr[0] = 1;
        sumg[0] = 0;
        sumb[0] = 0;
        R++;
    }else if(S[0]=='G'){
        sumr[0] = 0;
        sumg[0] = 1;
        sumb[0] = 0;
        G++;
    }else{
        sumr[0] = 0;
        sumg[0] = 0;
        sumb[0] = 1;
        B++;
    }

    for(int i=1;i<N;i++){
        if(S[i]=='R'){
            sumr[i] = sumr[i-1]+1;
            sumg[i] = sumg[i-1];
            sumb[i] = sumb[i-1];
            R++;
        }else if(S[i]=='G'){
            sumr[i] = sumr[i-1];
            sumg[i] = sumg[i-1]+1;
            sumb[i] = sumb[i-1];
            G++;
        }else{
            sumr[i] = sumr[i-1];
            sumg[i] = sumg[i-1];
            sumb[i] = sumb[i-1]+1;
            B++;
        }
    }

    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(S[i]=='R' && S[j]=='G'){
                if(j+(j-i)<N && S[j+(j-i)]=='B'){
                    ans += B-sumb[j]-1;
                }else{
                    ans += B-sumb[j];
                }
            }else if(S[i]=='R' && S[j]=='B'){
                if(j+(j-i)<N && S[j+(j-i)]=='G'){
                    ans += G-sumg[j]-1;
                }else{
                    ans += G-sumg[j];
                }
            }else if(S[i]=='B' && S[j]=='R'){
                if(j+(j-i)<N && S[j+(j-i)]=='G'){
                    ans += G-sumg[j]-1;
                }else{
                    ans += G-sumg[j];
                }
            }else if(S[i]=='B' && S[j]=='G'){
                if(j+(j-i)<N && S[j+(j-i)]=='R'){
                    ans += R-sumr[j]-1;
                }else{
                    ans += R-sumr[j];
                }
            }else if(S[i]=='G' && S[j]=='R'){
                if(j+(j-i)<N && S[j+(j-i)]=='B'){
                    ans += B-sumb[j]-1;
                }else{
                    ans += B-sumb[j];
                }
            }else if(S[i]=='G' && S[j]=='B'){
                if(j+(j-i)<N && S[j+(j-i)]=='R'){
                    ans += R-sumr[j]-1;
                }else{
                    ans += R-sumr[j];
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long int
#define ll long int
#define rep(i,l,n) for(int i = l; i < n; ++i)

int main(){
    int a,ans = 0;

    int k = 0;

    rep(i,0,5){
        cin >> a;
        if(a % 10 != 0 && 10 - a % 10 > k){
            k = 10 - a % 10;
        }
        if(a % 10 != 0)ans += (a + 10 - a % 10);
        else ans += a;
    }

    cout << ans - k << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    const int N=2e5+9;
    int main()
    {
        int x,y,a,b,c;
        ll ans=0;
        vector<int>v,v1,v2,v3;
        cin>>x>>y>>a>>b>>c;
        v1.resize(a);
        for(int i=0;i<a;i++){ 
            cin>>v1[i];
        }
        v2.resize(b);
        for(int i=0;i<b;i++){ 
            cin>>v2[i];
        }
        v3.resize(c);
        for(int i=0;i<c;i++){ 
            cin>>v3[i];
        }
        sort(v1.rbegin(),v1.rend());
        sort(v2.rbegin(),v2.rend());
        sort(v3.rbegin(),v3.rend());
        for(int i=0;i<x;i++)v.push_back(v1[i]);
        for(int i=0;i<y;i++)v.push_back(v2[i]);
        for(int i=0;i<c;i++)v.push_back(v3[i]);
        sort(v.rbegin(),v.rend());
        for(int i=0;i<x+y;i++){
              ans+=v[i];
        }
        cout<<ans<<'\n';
     
        return 0;
    }

Measured memory_bytes: 3572
N, S = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S):
        dp[i+1][j] += dp[i][j]
        
        if j+A[i]<=S:
            dp[i+1][j+A[i]] += dp[i][j]
            
            if j==0:
                dp[i+1][j+A[i]] += i
        
    for j in range(S+1):
        dp[i+1][j] %= MOD

ans = 0

for i in range(1, N+1):
    ans += dp[i][S]*(N-i+1)
    ans %= MOD

print(ans)

Measured memory_bytes: 113116
def get_tousa(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans

N = int(input())
s = [input() for i in range(N)]

s_hash = {}

for i in s:
    tmp = sorted(i)
    tmp = ''.join(tmp) 
    if tmp in s_hash:
        s_hash[tmp] += 1
    else:
        s_hash[tmp] = 0
s_hash = sorted(s_hash.items(), key = lambda x: x[1])


ans = 0
for i in s_hash:
    ans += get_tousa(i[1])
print(ans)

Measured memory_bytes: 30476
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "YES" : "NO") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

vector<string> split(string,string);

int main()
{
    int N;
    cin >> N;
    float ans;
    if(N%2==0)
        ans = float(N/2)/float(N);
    else
        ans = float((N+1)/2)/float(N);
    cout << ans;
    
}

Measured memory_bytes: 256
#include<stdio.h>
 int main(void)
 {
     int a,b,i;
     scanf("%d%d",&a,&b);
   
     if(a>b){
       for(i=0;i<a;i++)
       printf("%d",b);
       printf("\n");
     }
     
     else if(a<b){
       for(i=0;i<b;i++)
       printf("%d",a);
       printf("\n");
     }
   
     else if(a==b){
       for(i=0;i<a;i++)
       printf("%d",b);
       printf("\n");
     }
   return 0;
 }
   

Measured memory_bytes: 128
#include <iostream>

using namespace std;
const int LIMIT = 1e4;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int a,b,c;
	cin >> a >> b >> c;
	int time = 0,minute;
	while(true){
		minute = time % 60;
		if(minute <= c && c <= a + minute){
			time += c - minute;
			break;
		}else{
			time += a+b;
		}
		if(time > LIMIT){
			time = -1;
			break;
		}
	}
	cout << time << endl;
  return 0;
}

Measured memory_bytes: 3236
import sys

input = sys.stdin.readline


def main():
    MAX_NUM = 10 ** 5
    Q = int(input())
    lr = [None] * Q
    for i in range(Q):
        lr[i] = tuple(map(int, input().split()))

    is_prime = [True] * (MAX_NUM + 1)
    is_prime[0] = False
    for i in range(4, MAX_NUM + 1, 2):
        is_prime[i] = False

    is_prime[1] = False
    for i in range(3, MAX_NUM + 1, 2):
        for j in range(3 * i, MAX_NUM + 1, 2 * i):
            is_prime[j] = False

    S = {}
    S[-1] = 0
    for i in range(1, MAX_NUM + 1, 2):
        if is_prime[i] and is_prime[(i + 1) // 2]:
            S[i] = S[i - 2] + 1
        else:
            S[i] = S[i - 2]

    for l, r in lr:
        print(S[r] - S[l - 2])


if __name__ == "__main__":
    main()


Measured memory_bytes: 28408
#include<cstdio>
#include<queue>
using namespace std;
static const int INF=(1<<21);
static const int MAXN=101;
int main()
{
	int n,m[MAXN][MAXN],i,j,u,k,v,l,t[MAXN],c;
	queue<int> q;
	bool used[MAXN]={};
	scanf("%d",&n);
	for(i=1;i<n+1;i++){
		for(j=1;j<n+1;j++){
			m[i][j]=INF;
		}
	}
	for(i=0;i<n;i++){
		scanf("%d %d",&u,&k);
		for(j=0;j<k;j++){
			scanf("%d",&v);
			m[u][v]=1;
		}
	}
	t[1]=0;
	used[1]=true;
	q.push(1);
	while(!q.empty()){
		l=q.front();
		q.pop();
		for(i=1;i<n+1;i++){
			if(m[l][i]==1&&used[i]==false){
				q.push(i);
				used[i]=true;
				t[i]=t[l]+1;
			}
		}
	}
	for(i=1;i<n+1;i++){
		if(used[i]==true){
			printf("%d %d\n",i,t[i]);
		}
		else{
			printf("%d -1\n",i);
		}
	}
	return 0;
}

Measured memory_bytes: 1072
#include<cmath>
#include<iostream>
#include<algorithm>
#include <string>
#include <stdexcept>
using namespace std; 
int main(){
 long long int a,b[120],c=0,d,e; 
 	cin >>a;
  for(int i=0;i<a;i++){
 	cin >> b[i];
  }
 sort(b,b+a);
  cout <<b[a-1]-b[0];
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <string>
#include <sstream>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<ll> VL;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)

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

  int N, K;
  string s;
  cin >> N >> K >> s;

  s[K - 1] = tolower(s[K - 1]);
  cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main()
{
    char in[1000];
    while (true)
    {
		int s = 0; 
		int i = 0;
        cin >> in;
        if (in[i] == '0')
        {
            break;
        }
        while (in[i])
        {
            s = s + in[i] - '0';
            i++;
        }
        cout << s << endl;
    }
   return 0;
}

Measured memory_bytes: 3084
sa = list(input())
sb = list(input())
sc = list(input())

card = 'a'

while True:
    if card == 'a':
        if not sa:
            print('A')
            break
        card = sa[0]
        sa.pop(0)
    elif card == 'b':
        if not sb:
            print('B')
            break
        card = sb[0]
        sb.pop(0)
    else:
        if not sc:
            print('C')
            break
        card = sc[0]
        sc.pop(0)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int n;
  cin >> n;

  int ans = -1;
  for (int i = 0; i <= n; i++) {
    int p = i * 108 / 100;
    if (p == n) ans = i;
  }

  if (ans == -1) cout << ":(" << endl;
  else cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# https://www.nayuki.io/page/smallest-enclosing-circle


import math
import random


_MULTIPLICATIVE_EPSILON = 1 + 1e-14


def make_circle(points):
	shuffled = [(float(x), float(y)) for (x, y) in points]
	random.shuffle(shuffled)
	c = None
	for (i, p) in enumerate(shuffled):
		if c is None or not is_in_circle(c, p):
			c = _make_circle_one_point(shuffled[ : i + 1], p)
	return c

def _make_circle_one_point(points, p):
	c = (p[0], p[1], 0.0)
	for (i, q) in enumerate(points):
		if not is_in_circle(c, q):
			if c[2] == 0.0:
				c = make_diameter(p, q)
			else:
				c = _make_circle_two_points(points[ : i + 1], p, q)
	return c

def _make_circle_two_points(points, p, q):
	circ = make_diameter(p, q)
	left  = None
	right = None
	px, py = p
	qx, qy = q
	for r in points:
		if is_in_circle(circ, r):
			continue
		cross = _cross_product(px, py, qx, qy, r[0], r[1])
		c = make_circumcircle(p, q, r)
		if c is None:
			continue
		elif cross > 0.0 and (left is None or _cross_product(px, py, qx, qy, c[0], c[1]) > _cross_product(px, py, qx, qy, left[0], left[1])):
			left = c
		elif cross < 0.0 and (right is None or _cross_product(px, py, qx, qy, c[0], c[1]) < _cross_product(px, py, qx, qy, right[0], right[1])):
			right = c
	if left is None and right is None:
		return circ
	elif left is None:
		return right
	elif right is None:
		return left
	else:
		return left if (left[2] <= right[2]) else right

def make_diameter(a, b):
	cx = (a[0] + b[0]) / 2.0
	cy = (a[1] + b[1]) / 2.0
	r0 = math.hypot(cx - a[0], cy - a[1])
	r1 = math.hypot(cx - b[0], cy - b[1])
	return (cx, cy, max(r0, r1))

def make_circumcircle(a, b, c):
	ox = (min(a[0], b[0], c[0]) + max(a[0], b[0], c[0])) / 2.0
	oy = (min(a[1], b[1], c[1]) + max(a[1], b[1], c[1])) / 2.0
	ax = a[0] - ox;  ay = a[1] - oy
	bx = b[0] - ox;  by = b[1] - oy
	cx = c[0] - ox;  cy = c[1] - oy
	d = (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by)) * 2.0
	if d == 0.0:
		return None
	x = ox + ((ax*ax + ay*ay) * (by - cy) + (bx*bx + by*by) * (cy - ay) + (cx*cx + cy*cy) * (ay - by)) / d
	y = oy + ((ax*ax + ay*ay) * (cx - bx) + (bx*bx + by*by) * (ax - cx) + (cx*cx + cy*cy) * (bx - ax)) / d
	ra = math.hypot(x - a[0], y - a[1])
	rb = math.hypot(x - b[0], y - b[1])
	rc = math.hypot(x - c[0], y - c[1])
	return (x, y, max(ra, rb, rc))

def is_in_circle(c, p):
	return c is not None and math.hypot(p[0] - c[0], p[1] - c[1]) <= c[2] * _MULTIPLICATIVE_EPSILON

def _cross_product(x0, y0, x1, y1, x2, y2):
	return (x1 - x0) * (y2 - y0) - (y1 - y0) * (x2 - x0)

N = int(input())

points = []

for n in range(N):
    x, y = map(int, input().split())
    points.append([x, y])

print(make_circle(points)[-1])


Measured memory_bytes: 4464
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>

#define loop(i, times) for(int i = 0; i < times; i++)
#define seloop(i, start_index, end_index) for(int i = start_index; i < end_index; i++)
#define eqseloop(i, start_index, end_index) for(int i = start_index; i <= end_index; i++)

using namespace std;

struct Town
{
	int line_;
	int prefectures_;
	long time_;
	string id_;
};

int main()
{
	int n;  cin >> n;
	int m;	cin >> m;
	vector<Town> town_collection;
	town_collection.resize(m + 1);

	Town town;
	loop(i, m)
	{	// 街のデータ入力
		town_collection[i].line_ = i;
		cin >> town_collection[i].prefectures_ >> town_collection[i].time_;
	}

	// 街が出来た時間でソートするためのコンテナを作る
	vector<vector<pair<int, Town*>>> time_collection;
	time_collection.resize(n + 1);
	loop(i, m)
		time_collection[town_collection[i].prefectures_].push_back(std::make_pair(town_collection[i].time_, &town_collection[i]));

	string p;
	string x;
	for (int i = 1; i < n + 1; i++)
	{	// 街が出来た時間でソートして認識番号を作る
		sort(time_collection[i].begin(), time_collection[i].end());

		int j = 1;
		for (const auto& e : time_collection[i])
		{
			p.resize(6, '0');
			p.replace(6 - to_string(i).size(), to_string(i).size(), to_string(i));
			x.resize(6, '0');
			x.replace(6 - to_string(j).size(), to_string(j).size(), to_string(j));
			e.second->id_ = p + x;
			p.clear();
			x.clear();
			j++;
		}
	}

	// 結果出力
	for (const auto& e : town_collection)
		cout << e.id_ << endl;
}


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

int main(){
    string S;
    cin >> S;
    bool app[26];
    for(int i=0; i<26; i++){
        app[i] = false;
    }
    for(int i=0; S[i] != '\0'; i++) {
        app[S[i] - 'a'] = true;
    }
    for(int i=0; i<26; i++){
        if(!app[i]){
            printf("%c\n", (char)(i + 'a'));
            return 0;
        }
    }
    cout << "None" << endl;
    
    return 0;
}


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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll N, M;
ll p;
string s;
bool used[100010];
ll tmpWA[100010];
ll WA, AC;
int main(){
	cin >> N >> M;
	REP(i,0,M){
		cin >> p >> s;
		if(used[p]) continue;
		if(s == "AC"){
			AC++;
			WA+=tmpWA[p];
			used[p] = true;
		}else{
			tmpWA[p]++;
		}
	}
	p2(AC, WA);
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
long int dp[100001]={0};
int main()
{
  long int n,k,i,j,ans,mi;
  cin>>n>>k;
  long int arr[n];
  for(i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  dp[0]=0;
  dp[1]=abs(arr[1]-arr[0]);
  for(i=2;i<n;i++)                                            
  {
      mi=INT_MAX;
    for(j=1;j<=min(i,k);j++)
    {
      ans=dp[i-j]+abs(arr[i]-arr[i-j]);
      if(ans<mi)
        mi=ans;
    }
      dp[i]=mi;
  }
  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    vector<int> x(5);
    int ans;
    for(int i=0; i<5; i++){
        cin >> x.at(i);
        if(x.at(i)==0) ans = i+1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
	long long t;
	scanf("%d %lld", &n, &t);
	long long pre = 0, sum = 0;
	for(int i = 1; i <= n; i++){
		long long m;
		scanf("%lld", &m);
		if(m - pre <= t) sum = m + sum - pre;
		else{
			sum = sum + t;
		}
		pre = m;
	}	
	printf("%lld\n", sum + t);
	return 0;
}

Measured memory_bytes: 256
/* Filename: ARC062C.java
 * Author: Mushiyo
 */

import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

		while (input.hasNext()) {
			int N = input.nextInt();
			long T = input.nextLong(), A = input.nextLong();
			
			for(int i = 2; i <= N; ++i){
				int Ti = input.nextInt();
				int Ai = input.nextInt();
				long mul = Math.max(T / Ti, A / Ai);
				
				long newT = Ti * mul;
				long newA = Ai * mul;
				if(newT < T || newA < A){
					newT += Ti;
					newA += Ai;
				}
				
				
				T = newT;
				A = newA;
			}
			
			System.out.println(T + A);
		}
	}

}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,ans=0;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(l.begin(),l.end());
    for(int i=0;i<n-2;++i){
        bool ok=false;
        for(int j=i+1;j<n-1;++j){
            for(int k=j+1;k<n;++k){
                if(l[k]<l[i]+l[j]){
                    ++ans;
                }else{
                    ok=true;
                }
                if(ok){
                    ok=false;
                    break;
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}   

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

using namespace std;

typedef long long ll;

int main()
{
    #if DEBUG
        // freopen("/Users/khr.buddy/Documents/Projects/Problems/input.txt", "r", stdin);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m; cin >> n >> m;
    vector<vector<int>> v;
    for (int i = 0; i < n; i++) {
        vector<int> tmp(m);
        for (int j = 0; j < m; j++) cin >> tmp[j];
        v.push_back(tmp);
    }
    int ans = 0;
    for (int a = 0; a < n; a++) {
        for (int b = a + 1; b < n; b++) {
            ll sum = 0LL;
            for (int j = 0; j < m; j++) sum += (v[a][j] - v[b][j]) * (v[a][j] - v[b][j]);
            // cout << sum << endl;
            ll low = 0;
            ll high = 1e9;
            bool ok = false;
            while (high >= low) {
                ll mid = (low + high) / 2LL;
                if (mid * mid == sum) {
                    ok = true;
                    break;
                }
                if (mid * mid > sum) high = mid - 1LL;
                if (mid * mid < sum) low = mid + 1LL;
                //cout << mid << endl;
            }
            if (ok) ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;
int h,w,m1;
int hm,wm;
int bomb[300001][2] = {};
map<pair<int,int>,int> m;
int maxh=0, maxw=0;

int main(){
    scanf("%d%d%d", &h,&w,&m1);
    while(m1--){
        scanf("%d%d", &hm, &wm);
        pair<int,int> p={hm,wm};
        m[p] = 1;
        bomb[hm][0]++;
        bomb[wm][1]++;
        if(maxh <= bomb[hm][0]) maxh = bomb[hm][0];
        if(maxw <= bomb[wm][1]) maxw = bomb[wm][1];
    }
    vector<int> vech, vecw;
    for(int i= 1 ; i <= h ; ++i){
        if(bomb[i][0] == maxh) vech.emplace_back(i);
    }
    for(int j = 1 ; j <= w ; ++j){
        if(bomb[j][1] == maxw) vecw.emplace_back(j);
    }
    for(auto& it_h : vech){
        for(auto& it_w : vecw){
            pair<int,int> p={it_h,it_w};
            if(!m[p]){
                printf("%d", maxh+maxw);
                return 0;
            }
        }
    }
    
    printf("%d", maxh+maxw-1);
    
    return 0;
}

Measured memory_bytes: 28496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000

ll kaijyo[2001010];
ll gaijyo[2001010];

ll powe(ll a, ll b){//aのb乗のmod
    ll ret = 1;
    while(0 < b){
        if((b%2) == 0){
            a = (a*a)%MOD;
            b >>= 1;
        }
        else{
            ret = (ret*a)%MOD;
            b--;
        }
    }
    return ret;
}

void runfirst(){ //必ず回す!!
    kaijyo[0] = 1;
    gaijyo[0] = 1;
    FOR(i,1,2001009) {
        kaijyo[i] = (kaijyo[i-1]*i)%MOD;
        gaijyo[i] = powe(kaijyo[i],MOD-2);
    }
}

ll C(ll m, ll n){
    return (kaijyo[m]*((powe(kaijyo[m-n],MOD-2) * powe(kaijyo[n],MOD-2))%MOD)%MOD);
}

int main(){
    runfirst();
    ll r1, c1, r2, c2, ans1, ans2, ans3, ans4; cin >> r1 >> c1 >> r2 >> c2;
    ans1 = C(r2+c2+2,c2+1);
    ans2 = MOD-C(r2+c1+1,c1);
    ans3 = MOD-C(r1+c2+1,r1);
    ans4 = C(r1+c1,c1);
    cout << (ans1+ans2+ans3+ans4)%MOD << endl;
}

Measured memory_bytes: 31488
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctime>
//#define ivorysi
#define MAXN 2005
#define eps 1e-7
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
int N,a[MAXN * 2];
char c[MAXN * 2][5];
int tr[2][MAXN],cost[2][MAXN][MAXN],dp[MAXN][MAXN];
int lowbit(int x) {return x & (-x);}
void Insert(int id,int x) {
    while(x <= N) {
	tr[id][x]++;
	x += lowbit(x);
    }
}
int Query(int id,int x) {
    int res = 0;
    while(x > 0) {
	res += tr[id][x];
	x -= lowbit(x);
    }
    return res;
}
void Solve() {
    scanf("%d",&N);
    for(int i = 1 ; i <= 2 * N ; ++i) {
	scanf("%s%d",c[i] + 1,&a[i]);
    }
    for(int i = 1 ; i <= 2 * N ; ++i) {
	if(c[i][1] == 'W') {
	    for(int j = 0 ; j <= N ; ++j) {
		cost[0][a[i] - 1][j] = (i - 1) - Query(0,a[i] - 1) - Query(1,j);
	    }
	    Insert(0,a[i]);
	}
	else {
	    for(int j = 0 ; j <= N ; ++j) {
		cost[1][j][a[i] - 1] =  (i - 1) - Query(0,j) - Query(1,a[i] - 1);
	    }
	    Insert(1,a[i]);
	}
    }
    for(int i = 0 ; i <= N ; ++i) {
	for(int j = 0 ; j <= N ; ++j) {
	    if(i == 0 && j == 0) continue;
	    dp[i][j] = 0x7fffffff;
	    if(i != 0) {
		dp[i][j] = min(dp[i][j],dp[i - 1][j] + cost[0][i - 1][j]);
	    }
	    if(j != 0) {
		dp[i][j] = min(dp[i][j],dp[i][j - 1] + cost[1][i][j - 1]);
	    }
	}
    }
    printf("%d\n",dp[N][N]);
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 47360
inputs = Array.new
while line = $stdin.gets
  inputs << line.chomp
end

limit = 1e18

n = inputs[0].to_i
a = inputs[1].split(" ").map(&:to_i)

if a.find{|v| v == 0}
  puts 0
  return
end

cnt = 1;
a.each do |v|
  cnt *= v
  if cnt > limit
    puts -1
    return
  end
end

puts cnt
return


Measured memory_bytes: 23428
#include <bits/stdc++.h>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF=INT_MAX;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

int main(){
	int W,D;
	while(cin>>W>>D){
		if(W==0&&D==0)break;
		vector<int>h1(W),h2(D);
		REP(i,W)cin>>h1[i];
		REP(i,D)cin>>h2[i];
		SORT(h1);SORT(h2);
		int res=0;
		while(!h1.empty()&&!h2.empty()){
			if(h1.back()==h2.back()){
				res+=h1.back();
				h1.pop_back();h2.pop_back();
			}else if(h1.back()>h2.back()){
				res+=h1.back();
				h1.pop_back();
			}else{
				res+=h2.back();
				h2.pop_back();
			}
		}
		REP(i,SZ(h1))res+=h1[i];
		REP(i,SZ(h2))res+=h2[i];
		cout<<res<<endl;
	}
	return 0;
}

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

int n, a[100010];

int main(){
  cin >> n;
  for (int i=1; i<=n; ++i)
    cin >> a[i];
  int tmp=a[n];
  bool kq=true;
  for (int i=n-1; i>0; i--)
  	if (a[i]-tmp>1){
      kq=false;
      break;
    }
  	else if(a[i]<tmp) tmp=a[i];
  if (kq) cout << "Yes";
  else cout << "No";
  return 0;
}

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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int N = 123456;
VI edges[N];


int dfs(int v, int par) {
  int sum = 0;
  REP(i, 0, edges[v].size()) {
    int w = edges[v][i];
    if (w == par) { continue; }
    int res = dfs(w, v);
    sum ^= res + 1;
  }
  return sum;
}

int main(void){
  int n;
  cin >> n;
  REP(i, 0, n - 1) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    edges[x].push_back(y);
    edges[y].push_back(x);
  }
  cout << (dfs(0, -1) == 0 ? "Bob" : "Alice") << endl;
}


Measured memory_bytes: 11008
import math
N = int(input())
ans = 100000
for k in range(2,math.floor(math.sqrt(N))+1):
    if N % k == 0:
        ans = min(ans,max(len(str(k)),len(str(N//k))))
if ans == 100000:
    print(len(str(N)))
else:
    print(ans)


Measured memory_bytes: 38768
def partition(p, r):
    i = p
    for j in range(p, r):
        if A[r][1] >= A[j][1]:
            A[i], A[j] = A[j], A[i]
            i += 1
    A[r], A[i] = A[i], A[r]
    return i

def quick_sort(p, r):
    if p < r:
        q = partition(p, r)
        quick_sort(p, q-1)
        quick_sort(q+1, r)

def merge(left, mid, right):
    L = merge_list[left:mid]
    R = merge_list[mid:right]
    L.append(["", INFTY])
    R.append(["", INFTY])
    i, j = 0, 0
    for k in range(left, right):
        if L[i][1] <= R[j][1]:
            merge_list[k] = L[i]
            i += 1
        else:
            merge_list[k] = R[j]
            j += 1

def merge_sort(left, right):
    if left+1 < right:
        mid = int( (left+right)/2 )
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right)

INFTY = 1000000001

N = int(input())
A = []
for _ in range(N):
    suit, num = input().split()
    num = int(num)
    A.append([suit, num])
merge_list = A[:]

quick_sort(0, N-1)
merge_sort(0, N)

is_stable = True
for i in range(N):
    if A[i][0] != merge_list[i][0]:
        print("Not stable")
        is_stable = False
        break
if is_stable:
    print("Stable")

for card in A:
    print("%s %d" % (card[0], card[1]))



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

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i = 0; i < n; i++){
    cin >> s.at(i);
  }
  
  int a = 0;
  int w = 0;
  int t = 0;
  int r = 0;
  
  for(int i = 0; i < n; i++){
    if(s.at(i) == "AC"){
      a++;
    }
    else if(s.at(i) == "WA"){
      w++;
    }
    else if(s.at(i) == "TLE"){
      t++;
    }
    else{
      r++;
    }
  }
  cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
int main(){
    int N;
    cin >> N;
    long long cnt = 0, cntb = 0;
    vector<long long> A(N,0);
    rep(i,N){
        cin >> A[i];
    }
    long long sum = 0;
    rep(i,61){
        cnt = 0;
        cntb = 0;
        rep(j,N){
            ((A[j] >> i) & (long long)1 == (long long)1)? (cnt++):(cntb++);
        }
        sum += (cnt*(cntb*(((long long)1 << i)%mo)%mo)%mo) % mo;
        sum = sum % mo;
    }
    //cout << mo << endl;
    cout << sum << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

int main() {
	ll a, b;
	cin >> a >> b;

	int ans = 0;
	int n = 1;

	while (n < b) {
		--n;
		n += a;
		ans++;
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharp_AtCoder
{

    
    class Program
    {      

        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int N = input[0];
            int W = input[1];

            //w[i] := i番目の品の重さ
            //v[i] := i番目の品の価値
            int[] w = new int[N + 1];
            int[] v = new int[N + 1];
            for(int i = 1; i <= N; i++)
            {
                input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                w[i] = input[0];
                v[i] = input[1];
            }

            // dp[i, j] := i番目までの品、重さ制限w
            long[,] dp = new long[N + 1, W + 1];
            for(int i = 1; i <= N; i++)
            {
                for(int j = 1; j <= W; j++)
                {
                    dp[i, j] = dp[i - 1, j];
                    if(j - w[i] >= 0) dp[i, j] = Math.Max(dp[i, j], (long)v[i] + dp[i - 1, j - w[i]]);
                }
            }

            Console.WriteLine(dp[N, W]);
        }
    }
}


Measured memory_bytes: 89184
//Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prinp(p) cout<<p.first<<" "<<p.second<<endl
#define prinv(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7,MAX = 1e6+5;
const ll INF = 1e18+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
///////////////////PnC/////////////////////
vl Fac(MAX),Inv(MAX);
void CalcFac()
{
	Fac[0]=Inv[0]=1;
	for(int i=1;i<MAX;i++)
	{
		Fac[i]=(Fac[i-1]*i)%MOD;
		Inv[i]=powN(Fac[i],MOD-2);
	}
}

ll NCR(int n,int r)
{
	if(r>n) return 0;
	return (((Fac[n]*Inv[r])%MOD)*Inv[n-r])%MOD;
}
///////////////////PnC/////////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vi MinDiv(MAX);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
    		MinDiv[i]=i;
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
				MinDiv[j]=i;
    		}
    	}
	}
	for(int i=2;i<=MAX;i++) if(is_prime[i]) MinDiv[i]=i;
}
//////////////////Sieve////////////////////

int main()
{
	int n;
	cin>>n;
	vector<string> V(n);
	take(V,0,n);
	vi A(4);
	map<string,int> M;
	for(auto s:{"AC","WA","TLE","RE"})
	{
		M[s]=0;
	}
	for(auto s:V)
	{
		M[s]++;
	}
	for(auto s:{"AC","WA","TLE","RE"})
	{
		cout<<s<<" x "<<M[s]<<endl;
	}
}	

Measured memory_bytes: 25936
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = readline().decode().rstrip()

res = 0
b_cnt = 0

for c in S:
    if c == 'B':
        b_cnt += 1
    elif c == 'W':
        res += b_cnt

print(res)


Measured memory_bytes: 21896
import java.util.*;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int r = sc.nextInt();

    if (n < 10) {
      int h = 100 * (10 - n) + r ;
      System.out.println(h);
    } else {
      System.out.println(r);
    }
  }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int ,int> P;
 
int main(){
    int n,m,t[1000],p,x;
    ll sum=0;
    cin>>n;
    for(int i=0;i<n;i++){ cin>>t[i]; sum+=t[i];}
    cin>>m;
    for(int i=0;i<m;i++){ 
        cin>>p>>x; p--;
        cout<<sum+x-t[p]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
#define P(a,b) make_pair(a,b);
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

ll A[10];

int main(){
    rep(i,7) cin >> A[i];
    ll I = A[0],L = A[3],J = A[4],ans = I + L + J;
    if(J > L) swap(J,L);
    if(I % 2 == 1){
        if(L % 2 == 1 && J % 2 == 1) ans = I + L + J;
        if(L % 2 == 0 && J % 2 == 0) ans--;
        if((L % 2) ^ (J % 2) == 1){
            if(L == 0 || J == 0) ans -= 2;
            else ans--;
        }
    }else{
        if(I == 0){
            if(L % 2 == 1 && J % 2 == 1) ans -= 2;
            if(L % 2 == 0 && J % 2 == 0) ans = I + L + J;
            if((L % 2) ^ (J % 2) == 1) ans--;
        }else{
            if(L % 2 == 1 && J % 2 == 1) ans--;
            if(L % 2 == 0 && J % 2 == 0) ans = I + L + J;
            if((L % 2) ^ (J % 2) == 1) ans--;
        }
    }
    cout << ans + A[1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class C>constexpr int sz(const C&c){return int(c.size());}
using ll=long long;constexpr const char nl='\n',sp=' ';

int main() {
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // freopen("err.txt", "w", stderr);
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int N;
  cin >> N;
  set<ll> X, Y;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    ll x = a + b, y = a - b;
    if (!X.empty()) {
      ans = max(ans, abs(*X.begin() - x));
      ans = max(ans, abs(*X.rbegin() - x));
    }
    if (!Y.empty()) {
      ans = max(ans, abs(*Y.begin() - y));
      ans = max(ans, abs(*Y.rbegin() - y));
    }
    X.insert(x);
    Y.insert(y);
  }
  cout << ans << nl;
  return 0;
}


Measured memory_bytes: 22368
# ABC096D - Five, Five Everywhere
def get_primes(n: int) -> list:
    # return a list of primes < n
    sieve = [1] * n
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i]:
            sieve[i * i :: 2 * i] = [0] * ((n - i * i - 1) // (2 * i) + 1)
    return [2] + [i for i in range(3, n, 2) if sieve[i]]


def main():
    N = int(input())
    primes = get_primes(55556)
    ans = []
    for p in primes:
        if p % 5 == 1:
            ans.append(p)
            if len(ans) == N:
                break
    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
 
signed main(){
    string S;
    cin>>S;
    if(S[0]=='7'||S[1]=='7'||S[2]=='7') cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main(){
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  if(n<=k){
    printf("%d\n", x*n);
  }else{
    printf("%d\n", x*k+(n-k)*y);
  }
  
  return 0;
}

Measured memory_bytes: 256
h, w, k = gets.split(' ').map(&:to_i)
css = Array.new(h, [])
h.times do |i|
  css[i] = gets.chomp.chars.map { |c| c == '#' }
end
res = 0
(0...(1 << h)).each do |hi|
  (0...(1 << w)).each do |wi|
    count = 0
    (0...h).each do |i|
      (0...w).each do |j|
        count += 1 if css[i][j] && hi[i] != 0 && wi[j] != 0
      end
    end
    res += 1 if count == k
  end
end
p res


Measured memory_bytes: 14296
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int a,b;
    cin>>a>>b;
    int ans=1000000001;

    if(a<b){
        ans=b-a;
    }


    if(a*-1==b){
        ans=1;
        cout<<1<<endl;
        return 0;
    }

    if(a==b){
        ans=0;
        cout<<0<<endl;
        return 0;
    }


    int aa=-a;
    int k=1;

    if(aa<b){
        k+=b-aa;
        ans=min(ans,k);
    }else if(aa<abs(b)){
        k+=abs(b)-aa;
        if(b<0)k++;
        ans=min(k,ans);
    }

    int bb=-b;
    int h=1;

    if(a<bb){
        h+=bb-a;
        ans=min(h,ans);
    }else if(abs(a)<bb){
        if(a<0)h++;
        h+=bb-abs(a);
        ans=min(h,ans);
    }


    cout<<ans<<endl;




    return 0;
}


Measured memory_bytes: 256
import java.io.*;


public class Main {

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in = br.readLine().split(" ");
    long a = Long.parseLong(in[0]);
    long b = Long.parseLong(in[1]);
    long c = Long.parseLong(in[2]);

    br.close();

    boolean ok = true;
    if(c <= a + b) ok = false;
    else {
      ok = (4 * a * b < (c - a - b) * (c - a - b));
    }

    System.out.println(ok ? "Yes" : "No");
  }
}

Measured memory_bytes: 22864
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  set<char> list;
  for (int i=0; i<s.size(); i++) {
    list.insert(s.at(i));
  }
  if (list.size() == s.size()) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
}

Measured memory_bytes: 256
def who_says_a_pun(n, s)
  i, j = 0, 0
  ans = 0
  while j < n
    s1 = s[i..j]
    s2 = s[(j + 1)..-1]
    if s2.include?(s1)
      ans = [ans, s1.size].max
      j += 1
    else
      i += 1
      j += 1
    end
  end
  ans
end

n = gets.to_i
s = gets.chomp
puts who_says_a_pun(n, s)


Measured memory_bytes: 4732
#include<iostream>
using namespace std;
int main()
{
int a;
int i[10][3];
i[0][2]=1;
i[1][2]=2;
i[2][2]=4;
i[3][2]=8;
i[4][2]=16;
i[5][2]=32;
i[6][2]=64;
i[7][2]=128;
i[8][2]=256;
i[9][2]=512;
while(cin>>a)
{
	for(int h=0;h<10;h++)
	{
		i[h][0]=0;
		i[h][1]=0;
	}
	for(i[0][0]=0;i[0][0]<=1;i[0][0]++)
	{
	for(i[1][0]=0;i[1][0]<=2;i[1][0]+=2)
	{
	for(i[2][0]=0;i[2][0]<=4;i[2][0]+=4)
	{
	for(i[3][0]=0;i[3][0]<=8;i[3][0]+=8)
	{
	for(i[4][0]=0;i[4][0]<=16;i[4][0]+=16)
	{
	for(i[5][0]=0;i[5][0]<=32;i[5][0]+=32)
	{
	for(i[6][0]=0;i[6][0]<=64;i[6][0]+=64)
	{
	for(i[7][0]=0;i[7][0]<=128;i[7][0]+=128)
	{
	for(i[8][0]=0;i[8][0]<=256;i[8][0]+=256)
	{
	for(i[9][0]=0;i[9][0]<=512;i[9][0]+=512)
	{
	if(i[0][0]+i[1][0]+i[2][0]+i[3][0]+i[4][0]+i[5][0]+i[6][0]+i[7][0]+i[8][0]+i[9][0]==a)
	{
	for(int j=0;j<10;j++)
	{
	if(i[j][0]!=0)
	{
	i[j][1]++;
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	int l=0;
	for(int k=0;k<10;k++)
	{
	if(l==0&&i[k][1]>0)
	{
	cout<<i[k][2];
	l++;
	}
	else if(i[k][1]>0)
	{
	cout<<" "<<i[k][2];
	}
	}
	cout<<endl;
}
return 0;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using i64 = int64_t;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(int i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(int i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
#define vvv(T) v(v(v(T)))
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  string T;
  cin >> T;
  int N;
  N = T.size();

  rep(i,N){
    if(T[i]=='?') cout << "D";
    else cout << T[i];
  }
  cout << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 3792
# 初期入力
N,K = (int(x) for x in input().split(" "))
H = list(map(int, input().split()))
tuujou_attack = 1

# N種類のモンスター、K回の必殺技、モンスターは　H　の体力
# 体力の多いモンスターから必殺技で倒す。必殺技が使えなくなったら通常攻撃
nokori_kaisu = 0
H_sorted = sorted(H)
if N <= K:
    nokori_kaisu = 0
else:
    nokori_hissatuwaza = N -K
    # del H_sorted[nokori_hissatuwaza:]
    nokori_kaisu = sum( H_sorted[:nokori_hissatuwaza] ) # 体力少ないほうから　N-K　まで、通常攻撃「１」

print(nokori_kaisu)
# print(H_sorted)

Measured memory_bytes: 26024
N, M = map(int, input().split())
X = list(map(int, input().split()))

if N >= M:
    print(0)
else:
    X.sort()
    L = []
    for i in range(M-1):
        L.append(X[i+1]-X[i])
    L.sort(reverse=True)
    print(X[M-1]-X[0]-sum(L[:N-1]))


Measured memory_bytes: 13960
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define len(s) s.length()
#define forp(i,a,b) for( i=a;i<=b;i++)
#define rep(i,n)    for( i=0;i<n;i++)
#define ren(i,n)    for( i=n-1;i>=0;i--)
#define forn(i,a,b) for( i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define b(v) v.begin()
#define e(v) v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define pll pair<long long,long long>
#define vii vector<int>
#define vll vector<long long>
#define gl(cin,s)  getline(cin,s);
#define bitc(n) __builtin_popcountll(n)
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 

#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define SIZE 100001

typedef long long  ll;
typedef unsigned long long ull;
typedef long double  ldo;
typedef double  db ;
using namespace std;
int N,K;
int H[SIZE];
int dp[SIZE];
int main()
{  	
	/* #ifndef ONLINE_JUDGE
	freopen(fi, "r", stdin);
	#endif */
	//freopen("route.in","r",stdin);
	//freopen("route.out","w",stdout);
	//cin.ignore();
	//cin.clear();
	boost;
	//cin.tie(0);
	//cout<<"Case "<<tt<<": ";
	cin>>N>>K;
	for(int i=1;i<=N;i++){
	    cin>>H[i];
	}
	for(int i=1;i<=N;i++){
	    dp[i] = INT_MAX;
	}
	dp[1] = 0;
	for(int i=2;i<=N;i++){
	    for(int j=1;j<=K;j++){
	        if(i-j < 1)
	        break;
	        dp[i] = min(dp[i],dp[i-j]+abs(H[i]-H[i-j]));
	    }
	}
	cout<<dp[N]<<endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
public class Main {

	static Scanner inp= new Scanner(System.in);
	static PrintWriter out= new PrintWriter(System.out);
	public static void main(String args[]) {		    	
	   	Main g=new Main();
	   	g.main();
	   	out.close();
	}

	int n;
	int m;
	int c=0;
	int dp[][];
	char s[][];
	int dx[]= {1,0,-1,0};
	int dy[]= {0,1,0,-1};
	static int INF=1_000_000_000;
	
	@SuppressWarnings("unchecked")
	//Main
	void main() {
		
		n=inp.nextInt();
		m=inp.nextInt();
		int x1=inp.nextInt()-1;
		int y1=inp.nextInt()-1;
		int x2=inp.nextInt()-1;
		int y2=inp.nextInt()-1;
		s=new char[n][m];
		dp=new int[n][m];
		for(int i=0;i<n;i++) {
			Arrays.fill(dp[i], INF);
		}
		
		for(int i=0;i<n;i++) {
			s[i]=inp.next().toCharArray();
		}
		ArrayDeque<Integer> xs = new ArrayDeque<Integer>();
		ArrayDeque<Integer> ys = new ArrayDeque<Integer>();
		xs.add(x1);
		ys.add(y1);
		dp[x1][y1]=0;
		while(!xs.isEmpty()) {
			int x=xs.removeFirst();
			int y=ys.removeFirst();
			for(int i=0;i<4;i++) {
				int nx=x+dx[i];
				int ny=y+dy[i];
				if(isValid(nx,ny)) {
					if(dp[nx][ny]>dp[x][y]) {
						dp[nx][ny]=dp[x][y];
						xs.addFirst(nx);
						ys.addFirst(ny);
					}
				}
			}
			for(int nx=x-2;nx<=x+2;nx++) {
				for(int ny=y-2;ny<=y+2;ny++) {
					if(isValid(nx,ny)) {
						if(dp[nx][ny]>dp[x][y]+1) {
							dp[nx][ny]=dp[x][y]+1;
							xs.addLast(nx);
							ys.addLast(ny);
						}
					}
				}
			}
		}
		System.out.println(dp[x2][y2]==INF?-1:dp[x2][y2]);
	}
    
    
    
    boolean isValid(int i, int j) {
    	return i>=0 && i<n && j>=0 && j<m && s[i][j]=='.';
    }
		
}


Measured memory_bytes: 65396
def f(n, m):
    aa = [int(ak) % m for ak in input().split()]
    mod = {}
    ans = 0
    zi = 0
    for a in aa:
        zi = (zi - a) % m
        ai = (zi + a) % m
        mod.setdefault(ai, 0)
        mod[ai] += 1
        ans += mod.get(zi, 0)
    print(ans)


n, m = map(int, input().split())
f(n, m)


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

int N,A[2010];

int main(){
    cin >> N;
    int sum = 0;
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum += A[i];
    }
    bitset<4000010> dp;
    dp.set(0);
    for(int i=0;i<N;i++){
        bitset<4000010> pre;
        pre |= dp;
        pre |= (dp<<A[i]);
        swap(dp,pre);
    }
    for(int i=(sum+1)/2;i<=4000000;i++){
        if(dp[i]){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 2176
n = int(input())
a = input().split()

a_cnts = {}
a_sum = 0
for an in a:
    if an in a_cnts.keys():
        a_cnts[an] += 1
    else:
        a_cnts[an] = 1
    a_sum += int(an)

q = int(input())

for i in range(q):
    (b, c) = input().split()

    if b in a_cnts.keys():
        hit_cnt = a_cnts[b]
        del a_cnts[b]
        if c in a_cnts.keys():
            a_cnts[c] += hit_cnt
        else:
            a_cnts[c] = hit_cnt
        a_sum += (int(c) - int(b))*hit_cnt

    print(a_sum)


Measured memory_bytes: 22396