akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INF 1e18
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD
#define MAX_N 200002

using namespace std;

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

ll max(ll a, ll b) {
  return (a < b) ? b : a;
}
ll min(ll a, ll b) {
  return (a < b) ? a : b;
}

ll sum[MAX_N];
ll s(int a, int b) {
  return (sum[b] - sum[a - 1]);
}
ll x(int a, int b, int m) {
  return abs(s(a, m) - s(m+1, b));
}

int binary(int a, int b) {
  int l = a - 1, r = b + 1, mid = -1;
  ll cur = INF;

  while (r - l > 1) {
    mid = (l + r) / 2;

    cur = s(mid + 1, b) - s(a, mid);

    if (cur > 0) {
      l = mid;
    } else {
      r = mid;
    }
  }

  if (x(a, b, l) < x(a, b, r)) {
    return l;
  } else {
    return r;
  }
}



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

  ll score = INF;
  for (int i = 2; i <= N-2; ++i) {

    // printf("¥ni: %d¥n", i);

    int mid1 = binary(1, i);
    int mid2 = binary(i+1, N);

    // printf("mid1: %d, mid2: %d¥n", mid1, mid2);

    ll M = max(max(s(1, mid1), s(mid1 + 1, i)),
                max(s(i+1, mid2), s(mid2 + 1, N)));
    ll m = min(min(s(1, mid1), s(mid1 + 1, i)),
                min(s(i+1, mid2), s(mid2 + 1, N)));

    // printf("M - m: %lld¥n", M - m);

    score = min(score, M - m);
  }

  cout << score << endl;

  return 0;
}


Measured memory_bytes: 2560
MM = input()
listM = list(MM)
xx = len(listM)
saisyo =0
saigo  =xx
xx = len(listM)
for i in range(0,xx-1,1):
  
  if listM[i]=='A':
    saisyo = i
    
    break
for i in range(xx-1,0,-1):
  
  if listM[i]=='Z':
    saigo = i
    
    break
ans = saigo -saisyo
print(ans+1)

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

int main()
{
	auto& in = cin;
	int N;
	in >> N;
	int N_ = N - 1;
	int num = 0;
	for (int i = 1; i <= N_; ++i) {
		num += N_ / i;
	}
	cout << num;

	return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		sc.close();
		for(int i = 0;i < N;i++) {
			for(int j = 0; j < N;j++) {
				if(i * 4 + j * 7 == N) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 23380
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define bg begin()
#define end end()
#define sz size()
#define vi vector<int>
#define vl vector<long long int>
int main(){
	fast;
	ll f[10000005] {};
	for(int i = 1; i <= 10000000; ++i) {
		for(int j = i; j <= 10000000; j += i) {
			f[j]++;
		}
	}
	ll n;
	
	cin >> n;
	
	ll sm = 0;
	
	for(int i = 1; i <= n; ++i) {
		sm += i*f[i];
	}
	
	cout <<sm;
	return 0;
}



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

int main() {
  ll n,k,d=1e9+7;
  cin>>n>>k;
  vector<ll> h(n);
  for(int i=0; i<n; i++) cin>>h[i];
  sort(h.begin(),h.end());
  for(int i=0; i<n-k+1; i++){
    d = min(d,abs(h[i]-h[k-1+i]));
  }
  cout<<d;
}

Measured memory_bytes: 1024
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.14159265358979323846;
const ll MOD = 1e9 + 7;


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	ll mi, ma;
	if (n % 2 == 0) {
		mi = a[n / 2] + a[n / 2 - 1];
		ma = b[n / 2] + b[n / 2 - 1];
	}
	else {
		mi = a[n / 2], ma = b[n / 2];
	}
	cout << ma - mi + 1;
}

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

int main ( void )
{
	int X, fzz, f, total;
	cin >> X;

	if ( ( X < 0 ) || ( 1000000000 < X ) ){
		cout << "ERROR!\n";
		return 0;
	}

	fzz = X / 500;
	X %= 500;
	f = X / 5;

	total = ( 1000 * fzz ) + ( 5 * f );

	cout << total << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
void func(int);

int main(void)
{
	int n,i,j,a[100],flg,cnt;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&a[i]);
	cnt=0;
	flg=1;
	while(flg==1)	{
		flg=0;
		for(j=n-1;j>0;j--)	{
			if(a[j]<a[j-1])	{
				swap(a[j],a[j-1]);
				cnt++;
				flg=1;
			}
		}
	}
	printf("%d",a[0]);
	for(i=1;i<n;i++)printf(" %d",a[i]);
	printf("\n");
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 2760
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>
#include<string.h>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<deque>
#include<string>
#include<stack>
using namespace  std;

signed main() {
	int a, b, c; cin >> a >> b >> c;
	if (a == b)cout << c << endl;
	else if (b == c)cout << a << endl;
	else cout << b << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a+b >= c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23892
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
int gogo[100000];
int main(){
	int n;
	cin >> n;
	REP(i, n) {
		cin >> gogo[i];
	}
	vector<int> answer;
	for (int i = 0;; ++i) {
		long long geko = (i + n - 1) % n;
		if (geko != n - 1) {
			if (gogo[geko] > gogo[i%n]) {
				swap(gogo[i%n], gogo[geko]);
				answer.push_back(n - 1);
			}
		}
		int ok = 1;
		for (int q = 0; q < n; ++q) {
			if (gogo[q] != q) {
				ok = 0;
				break;
			}
		}
		if (ok == 1&&i % n == 0) {
			cout << answer.size() << endl;
			REP(q, answer.size()) {
				cout << answer[q] << endl;
			}
			return 0;
		}
		answer.push_back(1);
	}
}

Measured memory_bytes: 764
N = int(input())
n = list(map(int, input().split()))
M = int(input())
m = list(map(int, input().split()))

a = 0
b = 0
n.sort()
m.sort()
while a <= N-1 and b <= M-1:
  if m[b] == n[a]:
    a += 1
    b += 1
  else:
    a += 1
if b == M:
  print("YES")
else:
  print("NO")
  
  

Measured memory_bytes: 35556
from itertools import combinations_with_replacement
n,m,q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]

num = list(combinations_with_replacement(range(1,m+1), n))

ans = 0
for i in num:
  t = 0
  for j in abcd:
    if i[j[1]-1] - i[j[0]-1] == j[2]:
      t += j[3]
  ans = max(ans, t)
  
print(ans)

Measured memory_bytes: 21548
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal, ROUND_HALF_UP
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = np.array(LIST(), np.int64)
tmp = Decimal(sum(a)/N).quantize(Decimal("1"), rounding=ROUND_HALF_UP)
print(((a-tmp)**2).sum())


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

long long dp[2][100005];

const int mod = 1e9 + 7;
long long a[101];
int main(){
	long long n, k;
	cin >> n >> k;
	
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}

	
	for(int i = k; i >= k - a[0]; i--){
		dp[0][i] = 1LL;
	}
	for(int i = 1; i <= k; i++){
		dp[0][i] = (dp[0][i] + dp[0][i - 1]) % mod;
	}
	bool t = 1;
	for(int i = 1; i < n; i++, t = !t){
		dp[t][0] = dp[!t][a[i]];
	
		for(int j = 1; j <= k; j++){
			dp[t][j] = ((dp[t][j - 1] + dp[!t][min(k, j + a[i])] - dp[!t][j - 1]) % mod + mod) % mod;
		}
	}
	
	cout << dp[!t][0] % mod;
}




Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
using namespace std;
const int mod=998244353;
const int N=2e6+10;
int inv[N],fac[N];
int n,m,Ans;
int mul(int x,int y){return (ll)x*y%mod;}
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int dec(int x,int y){return x-y<0?x-y+mod:x-y;}
int ksm(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=mul(x,x)) if (y&1) ans=mul(ans,x);
	return ans;
}
void init(){
	fac[0]=1;
	for (int i=1;i<N;i++) fac[i]=mul(fac[i-1],i);
	inv[0]=inv[1]=1;
	for (int i=2;i<N;i++) inv[i]=mul(mod-mod/i,inv[mod%i]);
	for (int i=2;i<N;i++) inv[i]=mul(inv[i],inv[i-1]);
}
int C(int x,int y){
	if (x<y||x<0||y<0) return 0;
	return mul(mul(fac[x],inv[y]),inv[x-y]);
}
int main(){
	scanf("%d%d",&n,&m);
	Ans=0; init();
	for (int i=0;i<=min(n,m);i++) 
	if ((m*3-i)%2==0){
		int x=(m*3-i)/2;
		int s=C(n+x-1,n-1);
		s=dec(s,mul(n,C(n+x-m-1,n-1)));
		s=add(s,mul(n-i,C(n+x-m-2,n-2)));
		s=mul(s,C(n,i));
		Ans=add(Ans,s);
	}
	printf("%d\n",Ans);
}

Measured memory_bytes: 15872
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define N 800002
const int p=200003;
struct px
{
	double x,y;
	friend px operator+(px a,px b){return (px){a.x+b.x,a.y+b.y};}
	friend px operator-(px a,px b){return (px){a.x-b.x,a.y-b.y};}
	friend px operator*(px a,px b)
	{return (px){a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x};}
};
int rev[N],bin[N],lg[N],n,a[N];
ll ans;
px ta[N];
double pi=acos(-1.0);
void fft(px x[],int len,double mde)
{
	for(int i=0;i<len;i++)if(i<rev[i])swap(x[i],x[rev[i]]);
	for(int i=2;i<=len;i<<=1)
	{
		px wn=(px){cos(2.0*pi/(double)i),sin(mde*pi/(double)i)};
		for(int j=0,stp=i>>1;j<len;j+=i)
		{px w=(px){1,0};
			for(int k=j;k<j+stp;k++)
			{
				px t1=x[k],t2=x[k+stp]*w;
				x[k]=t1+t2,x[k+stp]=t1-t2;w=w*wn;
			}
		}
	}if(mde<0)for(int i=0;i<len;i++)x[i].x/=(double)len;
}
int main()
{
	bin[0]=1;lg[1]=0;
	for(int i=1;i<p-1;i++)bin[i]=2*bin[i-1]%p,lg[bin[i]]=i;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;scanf("%d",&x);a[i]=x;
		if(x)ta[lg[x]].x+=1;
	}
	int tle=1;while(tle<(p<<1))tle<<=1;
	for(int i=1;i<=tle;i++)
	{
		rev[i]=rev[i>>1]>>1;
		if(i&1)rev[i]|=tle>>1;
	}
	fft(ta,tle,2.0);
	for(int i=0;i<tle;i++)ta[i]=ta[i]*ta[i];
	fft(ta,tle,-2.0);
	for(int i=p-1;i<2*p;i++)ta[i-(p-1)].x+=ta[i].x;
	for(int i=0;i<p-1;i++)
	{
		ans+=((ll)(ta[i].x+0.5))*bin[i];
	}
	for(int i=1;i<=n;i++)ans-=1ll*a[i]*a[i]%p;
	printf("%lld\n",ans/2);
}
/*
4
2019 0 2020 200002
*/

Measured memory_bytes: 16180
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back

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

  map<char, bool> mp;

  for (auto itr : s) mp[itr] = true;

  if (s.size() < 26) {
    for (char ch = 'a'; ch <= 'z'; ++ch) {
      if (!mp[ch]) {
        s.pb(ch);
        break;
      }
    }
    cout << s << endl;
  } else {
    string t = s;
    if (!next_permutation(s.begin(), s.end())) {
      cout << -1 << endl;
      return 0;
    }

    for (int i = 0; i < 26; ++i) {
      if (t[i] == s[i]) {
        cout << t[i];
      } else {
        cout << s[i];
        break;
      }
    }

    END;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<double>prob(N + 1);
    double dp[N+1][N+1], res = 0;
    for(int i = 1; i <= N; i++) cin >> prob[i];

    // dp[i][j] is the probablilty of getting i heads from the first j throws
    // 0 heads from 0 throws
    for(int i = 0; i <=N ; i++)
    {
        for(int j = 0; j <= N; j++)
        {
            dp[i][j] = 0;
        }
    }
    // 0 heads from i throws is just the multiplication of individula probablitiies
    dp[0][1] = 1.0- prob[1];
    for(int i = 2; i <= N; i++)
    {
        dp[0][i] = dp[0][i-1]*(1.0 - prob[i]);
    }

    dp[1][1] = prob[1];
    for(int i = 2; i <= N; i++)
    {
        dp[i][i] = dp[i-1][i-1]*prob[i];
    }

    for(int j = 1; j <= N; j++)
    {
        for(int i = 1; i < j; i++)
        {
            dp[i][j] = dp[i-1][j-1]*(prob[j]) + dp[i][j-1]*(1.0 - prob[j]);
        }
    }

    for(int i = N / 2 + 1; i <= N; ++i)
        res += dp[i][N];

    printf("%0.10f", res);

}

Measured memory_bytes: 70528
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
void chmin(LL& a, LL b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////
class UnionFind {
public:
	int cNum;//要素数
	vector<int> parent;
	vector<int> count;
	vector< vector<int> > GList;
	UnionFind(int n) {
		cNum = n;
		parent = vector<int>(n);
		count = vector<int>(n, 1);
		GList.resize(n);
		for (int i = 0; i < n; ++i) {
			parent[i] = i;
			GList[i].push_back(i);
		}
	}
	int find(int x) {
		if (parent[x] == x) { return x; }
		return parent[x] = find(parent[x]);
	}
	bool same(int x, int y) { return find(x) == find(y); }
	int Count(int x) { return count[find(x)]; }
	void add(int x, int y) {//union
		x = find(x);
		y = find(y);
		if (x == y)return;
		parent[x] = y;

		count[y] += count[x];
		if (GList[y].size() < GList[x].size()) {
			swap(GList[x], GList[y]);
		}
		GList[y].insert(GList[y].end(),
			GList[x].begin(), GList[x].end());
	}
};

void solve() {
	int N, M, K;
	cin >> N >> M >> K;
	UnionFind uf(N);
	vector<int> F(N, -1);
	for (int i = 0; i < M; ++i) {//フレちゃん
		int a, b;
		cin >> a >> b;
		--a; --b;
		F[a]--;
		F[b]--;
		uf.add(a, b);
	}
	for (int i = 0; i < N; ++i) {
		F[i] += uf.Count(i);//グループの人数
	}
	for (int i = 0; i < K; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		if (uf.same(a, b)) {
			F[a]--;
			F[b]--;
		}
	}
	for (int i = 0; i < N; ++i) {
		if (i)cout << " ";
		cout <<F[i];
	}
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 8476
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for _ in range(Q):
    b,c = map(int, input().split())
    B.append(b)
    C.append(c)


counter = defaultdict(int)
now_sum = 0

for a in A:
    counter[a] += 1
    now_sum += a

for i in range(Q):
    b = B[i]
    c = C[i]

    changed_count = counter[b]
    changed_sum = changed_count * (c - b)
    now_sum += changed_sum
    
    counter[c] += counter[b]
    counter[b] = 0

    print(now_sum)



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

#define V vector
#define PB push_back
#define P pair
#define MP make_pair
#define F first
#define S second

#define int int32_t

int n; 
int p[300000];
int calc_left(int a) {
    return p[a - 1];
}

int calc_right(int a) {
    return (n - 1) - a - (p[n - 1] - p[a]);
}

int32_t main() {
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	fill(p, p + n, 0); 
	for (int i = 0; i < n; i++) {
	    char d; cin >> d;
	    p[i] = (i == 0 ? 0 : p[i - 1]) + (d == 'W' ? 1 : 0);
	}
	
	int res = INT_MAX;
	for (int i = 0; i < n; i++)
	    res = min(res, calc_left(i) + calc_right(i));
	
	cout << res << "\n";
	
    return 0;
}

Measured memory_bytes: 1408
#import<cstdio>
int main(){int i,j,k,a,b,c,d,n,m,D[21][21];for(i=0;i<21;i++)for(j=0;j<21;j++)D[i][j]=1e+9;scanf("%d%d",&n,&m);for(i=0;i<m;i++)scanf("%d,%d,%d,%d", &a, &b, &c, &d),D[a][b]=c,D[b][a]=d;for(k=1;k<=n;k++)for(i=1;i<=n;i++)for(j=1;j<=n;j++)D[i][j]=(D[i][j]<D[i][k]+D[k][j])?D[i][j]:D[i][k]+D[k][j];scanf("%d,%d,%d,%d",&a,&b,&c,&d);printf("%d\n",c-d-D[a][b]-D[b][a]);}

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

using namespace std;
const int maxn = 1e5+10;

int n, k;
int niz[maxn];
long long pref[maxn];
long long pref2[maxn];

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++)
		scanf("%d", niz+i);

	for (int i = 0; i < n; i++)
		pref[i + 1] = pref[i] + max(0, niz[i]);

	for (int i = 0; i < n; i++)
		pref2[i + 1] = pref2[i] + niz[i];

	long long sol = 0;
	for (int i = 0; i <= n - k; i++) {
		sol = max(sol, pref[i] + pref[n] - pref[i + k] + max(pref2[i + k] - pref2[i], 0LL));
		//printf("%lld %lld %lld -> %lld\n", pref[i], pref[n] - pref[i + k], max(pref2[i + k] - pref2[i], 0LL), pref[i] + pref[n] - pref[i + k] + max(pref2[i + k] - pref2[i], 0LL));
	}
	printf("%lld", sol);
	return 0;
}


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

int main() {
	int N;
	string S;
    
    int p = 0; // Pink
    int w = 0; // White 
    int g = 0; // Green  
    int y = 0; // Yellow  
  
    int i = 0;
    bool Four = false;

    cin >> N;  
      
    for (; i < N; i++){
    
    cin >> S;
      
	    if (S == "P"){
	      p++; // ping counter
	    }
      
    	if (S == "W"){
      	w++; // white counter
	    }
    
    	if (S == "G"){
      	g++; // green counter
    	}

    	if (S == "Y"){
      	y++; // yellow counter
	    }
 
    }  
    	if (p >= 1 && w >= 1 && g >= 1 && y >= 1){ // check if 4
    	cout << "Four" << endl;
    	}

    	else if (p >= 1 && w >= 1 && g >= 1){
        	cout << "Three" << endl;
        	}
      
    	else if (p >= 1 && w >= 1 && y >= 1){
        	cout << "Three" << endl;
        	}      

    	else if (p >= 1 && g >= 1 && y >= 1){
        	cout << "Three" << endl;
        	}
      
    	else if (y >= 1 && w >= 1 && g >= 1){
        	cout << "Three" << endl;
        	}              
}


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

#define rep(i,a,b) for(auto i=(a);i<(b);++i)
#define all(a) begin(a),end(a)

const int MAXN = 3000;
const int MOD = 1000000007;
int dp[MAXN + 5]; // dp[j] at iteration i = # of ways to place up to i-th element inclusive
                  //                        s.t. last element is the j-th smallest element so far (so 0 <= j <= i)
int psum[MAXN + 5];

auto sadd(auto& a, auto b){
  a += b;
  if (a >= MOD) a -= MOD;
}
template <typename T>
T add(T a, T b){return (a + b) % MOD;}
template <typename T>
T sub(T a, T b){return (a - b + MOD) % MOD;}

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

  int n;
  cin >> n;
  string s;
  cin >> s;

  auto sum = [&](int i, int j){return i ? sub(psum[j], psum[i - 1]) : psum[j];};

  dp[0] = 1;
  rep(i, 1, n) {
    partial_sum(all(dp), begin(psum), add<int>);
    memset(dp, 0, sizeof(dp));
    rep(j, 0, i + 1) {
      if (s[i - 1] == '<')
	sadd(dp[j], sum(0, j - 1));
      else
	sadd(dp[j], sum(j, i - 1));
    }
  }
  auto res = accumulate(all(dp), 0, add<int>);
  cout << res << '\n';
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>

typedef long long LL;

const LL kInf64 = 0x3f3f3f3f3f3f3f3f;

struct Stat {
	int l, xl, r, xr;
	bool operator<(const Stat & s) const {
		return l != s.l ? l < s.l :
			(r != s.r ? r < s.r : 
			 (xl != s.xl ? xl < s.xl : xr < s.xr));
	}
};

int n;
int A[20];
std::map<Stat, LL> DP;

LL Solve(int l, int xl, int r, int xr);

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", A + i);

	printf("%lld\n", Solve(0, 1, n - 1, 1) + A[0] + A[n - 1]);
	return 0;
}

LL Solve(int l, int xl, int r, int xr) {
	if (r - l <= 1) return 0;
	Stat cur = (Stat){l, xl, r, xr};
	auto it = DP.find(cur);
	if (it != DP.end()) return it->second;
	LL res = kInf64;
	for (int i = l + 1; i < r; i++) {	
		res = std::min(res, Solve(l, xl, i, xl + xr) +
							Solve(i, xl + xr, r, xr) +
							(LL)A[i] * (xl + xr));
	}
	return DP[cur] = res;
}


Measured memory_bytes: 16640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#define pi 3.14159265358979323846264338327950

int main() {
	int A, B, M; std::cin >> A >> B >> M;
	int mina = 100000000;
	std::vector<int> a(A);
	for (auto& r : a) {
		std::cin >> r;
		if (mina > r) mina = r;
	}
	int minb = 100000000;
	std::vector<int> b(B);
	for (auto& r : b) {
		std::cin >> r;
		if (minb > r) minb = r;
	}
	std::vector<int> x(M);
	std::vector<int> y(M);
	std::vector<int> c(M);
	int min = 100000000;
	for (int i{ 0 }; i < M; ++i) {
		std::cin >> x[i] >> y[i] >> c[i];
		if (x[i] - 1 > A || x[i] - 1 > B) continue;
		int total = a[x[i] - 1] + b[y[i] - 1] - c[i];
		if (total < min) min = total;
	}

	std::cout << std::min(min, (mina + minb)) << std::endl;

	return 0;
}

Measured memory_bytes: 5048
n = int(input())
exprs = []

for _ in range(n):
    exprs.append([int(i) for i in input().split()])

exprs = sorted(exprs, key=lambda x: -x[2])

for cx in range(0, 101):
    for cy in range(0, 101):
        x0, y0, h0 = exprs[0]
        ch = h0 + abs(x0 - cx) + abs(y0 - cy)
        for x, y, h in exprs[1:]:
            if h != max(ch - abs(x - cx) - abs(y - cy), 0):
                break
        else:
            print(cx, cy, ch)
            quit()


Measured memory_bytes: 73712
#include <bits/stdc++.h>
using namespace std;
const long INF=1000000000000000;

int main() {
    long N;
    cin>>N;
    
    vector<double> A(N);
    for(int i=0;i<N;i++) cin>>A.at(i);
    
    double ans=0;
    for(int i=0;i<N;i++){
        ans+=1.0/A.at(i);
    }
    
    cout<<setprecision(15)<<1.0/ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define M_PI 3.14159265358979323846
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

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

    double a,b,h,m;
    cin >> a >> b >> h >> m;

    double h0,m0;

    h0 = (h+(m/60))*M_PI/6;
    m0 = m*M_PI/30;

    // cout << h0 << endl << m0 << endl;

    double dif0 = abs(h0-m0);
    // cout << dif0;

    double ans;

    ans = a*a + b*b - 2*a*b*cos(dif0);
    // cout <<ans << endl;

    // cout << pow(4.56425719433005567605,2) << endl;

    cout << fixed << setprecision(20)<< pow(ans,0.5) << endl; 


    return 0;
}

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

namespace ConsoleApp5
{

    class Program
    {
        static void Main(string[] args)
        {

            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            int res = 0;
            int WP = 0;


            for (int i=0; i<N; i++)
            {
                if (S[i] == '#')
                {
                    res++;
                }

            }

            int ans = res;
           
            for(int i=N-1; i>=0; i--)
            {
                if(S[i] == '#')
                {
                    res = res - 1 + WP;
                    WP = 0;
                    if(res < ans)
                    {
                        ans = res;
                    }
                }
                else
                {
                    WP++;
                }
                
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13112
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

void solve(){
    ll N; cin >> N;
    int X, m;
    cin >> X >> m;
    map<int, int> pos;
    pos[X] = 0;
    int start = -1;
    int x = X;
    for(int i = 1; i < 2 * m; ++i){
        x = (1LL * x * x) % m;
        if(pos.count(x)){
            start = x;
            break;
        }
        pos[x] = i;
    }
    assert(start != -1);
    vector<int> seq = {start};
    while(true){
        int cur = (1LL * seq.back() * seq.back()) % m;
        if(cur == start)
            break;
        seq.push_back(cur);
    }
    vector<ll> pref = {seq[0]};
    for(int i = 1; i < (int)seq.size(); ++i){
        pref.push_back(pref.back() + seq[i]);
    }
    int u = (int)seq.size();
    if(N <= m){
        int cur = X;
        int sum = cur % m;
        for(int i = 1; i < N; ++i){
            cur = (1LL * cur * cur) % m;
            sum += cur;
        }
        cout << sum << endl;
        return;
    }
    int cur = X;
    ll sum_before = 0;
    for(int i = 0; i < m; ++i){
        sum_before += cur;
        if(cur == start){
            sum_before -= cur;
            N -= i;
            break;
        }
        cur = (1LL * cur * cur) % m;
    }
    ll sum = sum_before + 1LL * (N/u) * pref.back() + 1LL * (N % u == 0 ? 0 : pref[N % u - 1]);
    cout << sum << endl;




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

    solve();
}


Measured memory_bytes: 6444
#require 'prime'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
x=gi
d=x/11
m=x%11
add=
 if m==0
  0
 elsif m<=6
  1
 else
  2
 end
puts d*2+add

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
int main() 
{
    int n;
    cin >> n;

    long long pow=1;
    REP(i,n){
        pow *= i;
        pow = pow%1000000007;
    }

    cout << pow%1000000007 << endl;
}

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

int main() {
  int64_t n;
  cin>>n;

  int64_t start = int64_t(sqrt(n));
  // if(start*start == n) {
  //   cout<<2*(start-1)<<endl;
  //   return 1;
  // }

  while(n%start != 0) start--;

  int64_t ans = (start-1) + (n/start-1);

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const int MAX_N = 100;
int N;
int a[MAX_N];

int solve() {
    int answer = 0;
    int i = 0;
    while(i < N-1) {
        if (a[i] == a[i+1]) {
            answer++;
            i += 2;
        } else {
            i++;
        }
    }
    return answer;
}

signed main() {
    // to shorten execution time for iostream
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    REP(i,0,N) cin >> a[i];
    cout << solve() << "\n";
    return 0;
}



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

void solve()
{
    int n, m;
    cin >> n >> m;
    int ans = (n - 1) * (m - 1);
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

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

int main()
{
    string S; //文字列
    int K; //入れ物

    cin >> K;
    cin >> S;

    int lengthS = S.length();

    if(K >= lengthS ){
        cout << S << endl;
    }else{
        string min = S.erase(K);
        string ans = min + "...";
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3132
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define all(v) (v).begin(),(v).end()
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 
const ll inf=1LL<<60;

int main() {
  ll i,j,k,N,ans=0;
  cin>>N;
  string s;
  mat G(N),g(N,vec(N));
  vec color(N,-1);
  rep(i,N){
    cin>>s;
    rep(j,N){
      g[i][j]=(s[j]=='1')?1:inf;
      if(g[i][j]==1){
        G[i].push_back(j);
      }
    }
    g[i][i]=0;
  }
  /*judge*/
  color[0]=0;
  queue<ll> que;
  que.push(0);
  while(!que.empty()){
    auto x=que.front();que.pop();
    for(auto i:G[x]){
      if(color[i]<0){
        color[i]=1-color[x];
        que.push(i);
      }else if(color[i]==color[x]){
        cout<<-1<<endl;
        return 0;
      }
    }
  }
  /*solve*/
  rep(k,N)rep(i,N)rep(j,N)chmin(g[i][j],g[i][k]+g[k][j]);
  rep(i,N)chmax(ans,*max_element(all(g[i])));
  cout<<ans+1<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int,int>;
using ll = long long;


int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int x,y;
    x = ( c - 1 )/b;
    y = ( a - 1 )/d;
    if (x > y){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3572
#ABCがBCAになる
#ADがDAになる
s = input()
s = s.replace("BC", "D")

c_A = 0
ans = 0
for v in s:
  if v == "A":
    c_A += 1
  elif v == "D":
    ans += c_A
  else:
    c_A = 0
print(ans)

Measured memory_bytes: 3500
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>

struct vertex {
  int k;
  int dis;
  int definite;
  int **vlist;
};

int H;
struct vertex *adj;

void insert(int *A, int i);
int extractMin(int *A);
void upHeap(int *A, int i);
void downHeap(int *A, int i);

int main(int argc, char *argv[])
{
  int n, i, j, id;
  int minv, op, cost;
  int *heap;

  H = 0;

  scanf("%d", &n);
  adj = (struct vertex *)malloc(sizeof(struct vertex) * n);
  heap = (int *)malloc(sizeof(int) * (n + 1));

  for (i = 0; i < n; i++) {
    scanf("%d", &id);
    scanf("%d", &(adj[id].k));
    adj[id].vlist = (int **)malloc(sizeof(int *) * adj[id].k);
    for (j = 0; j < adj[id].k; j++) {
      adj[id].vlist[j] = (int *)malloc(sizeof(int) * 2);
      scanf("%d", &(adj[id].vlist[j][0]));
      scanf("%d", &(adj[id].vlist[j][1]));
    }
    adj[id].dis = INT_MAX;
    adj[id].definite = 0;

    heap[H+1] = id;
    H++;
    insert(heap, H);
  }

  adj[0].dis = 0;
  while (H != 0) {
    minv = extractMin(heap);
    adj[minv].definite = 1;
    for (i = 0; i < adj[minv].k; i++) {
      op = adj[minv].vlist[i][0];
      cost = adj[minv].vlist[i][1];
      if (adj[op].definite == 0 && adj[op].dis > adj[minv].dis + cost) {
	adj[op].dis = adj[minv].dis + cost;
	for (j = 1; j <= H; j++) {
	  if (heap[j] == op) {
	    upHeap(heap, j);
	    break;
	  }
	}
      }
    }
  }

  for (i = 0; i < n; i++) printf("%d %d\n", i, adj[i].dis);

  return 0;
}

void insert(int *A, int i)
{
  int p, tmp;

  if (H == 1) return;
  else upHeap(A, i);
}

int extractMin(int *A)
{
  int x = A[1], tmp;
  int i, l, r;

  A[1] = A[H--];

  downHeap(A, 1);

  return x;
}

void upHeap(int *A, int i)
{
  int p;
  int tmp;

  p = (int)floor(i / 2);

  while (p != 0 && adj[A[p]].dis > adj[A[i]].dis) {
    tmp = A[p];
    A[p] = A[i];
    A[i] = tmp;
    i = p;
    p = (int)floor(i / 2);
  }
}

void downHeap(int *A, int i)
{
  int l, r, smallest;
  int tmp;

  l = 2 * i;
  r = 2 * i + 1;

  smallest = i;
  if (l <= H && adj[A[l]].dis < adj[A[i]].dis) smallest = l;
  if (r <= H && adj[A[r]].dis < adj[A[smallest]].dis) smallest = r;

  if (smallest != i) {
    tmp = A[smallest];
    A[smallest] = A[i];
    A[i] = tmp;
    downHeap(A, smallest);
  }
}

Measured memory_bytes: 20136
function ab_count(array){
  var result=0;
  for(var i=0;i<array.length-1;i++){
    if(array[i]=='A' && array[i+1]=='B'){result++;}
  }
  return result;
}

function main(input){
  const lines = input.split('\n');
  const N = lines[0].split(' ').map(x => parseInt(x))[0];
  lines.shift();
  const S = lines;

  var result = 0;
  var head=0;
  var tail=0;
  var sum=0;
  for(var i=0;i<N;i++){
    var current_s = S[i].split('');
    if(current_s[0]=='B'){head++;}
    if(current_s[current_s.length-1]=='A'){tail++;}
    if(current_s[0]=='B' || current_s[current_s.length-1]=='A'){sum++;}
    result += ab_count(current_s);
//    console.log([current_s,ab_count(current_s)]);
  }
  const addition = Math.min(tail,head, Math.max(0,sum-1));

  console.log(result+addition);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 23224
n,t=input().split()
n,t,a,b=int(n),int(t),[],10000
for i in range(n):
    a.append(list(map(int,input().split())))
for i in range(n):
    if a[i][1]<=t:
        b=min(b,a[i][0])
if b==10000:
    print('TLE')
else:
    print(b)

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

constexpr int MAX_N = 110;
constexpr int MAX_V = 100100;
constexpr long long INF = (1LL<<60);

int main() {
    int n;
    long long weight;
    cin >> n >> weight;
    vector<long long> w(n), v(n);
    for (int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
    }
    
    long long dp[MAX_N][MAX_V];
    for (int i = 0; i < MAX_N; i++) {
        for (int j = 0; j < MAX_V; j++) {
            dp[i][j] = INF;
        }
    }
    
    dp[0][0] = 0;
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < MAX_V; j++) {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            if (j - v[i] >= 0) {
                dp[i+1][j] = min(dp[i+1][j], dp[i][j-v[i]] + w[i]);
            }
        }
    }
    
    long long ans = 0;
    for (int i = MAX_V - 1; i >= 0; i--) {
        if (dp[n][i] <= weight) {
            ans = i;
            break;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 86272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const ll inf  = 1e6+5;
int main() {
  int n; cin >> n;
  unordered_map<string, int> mp;
  for (int i = 0; i < n; i++){
      string s; cin >> s;
      if (mp.find(s) == mp.end()){
          mp.insert({s, 1});
      }
      else{
          mp[s]++;
      }
  }
  int max = 0;
  vector<string> freq;
  for (auto &a : mp){
      if (a.second > max){
          max = a.second;
          freq.clear();
          freq.push_back(a.first);
      }
      else if (a.second == max){
          freq.push_back(a.first);
      }
  }
  sort(freq.begin(), freq.end());
  for (string s : freq){
      cout << s << '\n';
  }
}

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

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 998244353
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 200005;

int N;
int X[MAX_N];
int dp[MAX_N][5];

int getA(int i, int a)
{
  if(i == 0 || i == 4) {
    return a;
  } else if(i==1 || i == 3) {
    if(a==0) return 2;
    else return a%2;
  } else {
    return (a+1)%2;
  }
}

signed main()
{
  cin >> N;
  REP(n,N) {
    cin >> X[n];
  }

  REP(n,N+1) {
    REP(mode,5) {
      dp[n][mode] = INF;
    }
  }

  REP(mode, 5) {
    dp[0][mode] = 0;
  }

  REP(n,N) {
    REP(mode,5) {
      if(mode<4) dp[n][mode+1] = min(dp[n][mode+1], dp[n][mode]);
      dp[n+1][mode] = min(dp[n+1][mode], dp[n][mode] + getA(mode,X[n]));
    }
  }

  int ans = INF;
  REP(n,5) {
    ans = min(ans, dp[N][n]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 9600
N, X = map(int, input().split())
a,p = [1],[1]

for i in range(N):
  a.append(2 * a[i] + 3)
  p.append(2 * p[i] + 1)
  
def runrun(N,X):
  if N == 0:
    return 0 if X <= 0 else 1
  elif X<= 1 + a[N-1]:
    return runrun(N-1, X-1)
  else:
    return p[N-1] + 1 + runrun(N-1, X-a[N-1]-2)
    
    
print(runrun(N,X))
          

Measured memory_bytes: 38384
MOD = 10**9+7
N = int(input())
x = list(map(int, input().split()))

def mod_pow(x, n, mod):
	res = 1
	while n > 0 : 
		if n&1 : 
			res = res * x % mod
		x = x * x % mod
		n >>= 1
	return res

prob = []
a = 0
for i in range(1, N):
	a += mod_pow(i, MOD-2, MOD)
	a %= MOD
	prob.append(a)
ans = 0
for i in range(1, N):
	ans += prob[i-1] * (x[i] - x[i-1])
	ans %= MOD
for i in range(1, N):
	ans = ans * i % MOD
print(ans)

Measured memory_bytes: 14480
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
#include<cassert>
using namespace std;
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fil(a,b) memset((a),(b),sizeof(a))
#define cl(a) fil(a,0)
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define rep(i,a,b) for (int i=(a),_ed=(b);i<_ed;i++)
#define per(i,a,b) for (int i=(b)-1,_ed=(a);i>=_ed;i--)
#define forg(i,gu) for (int i=gu;~i;i=e[i].next)
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
void getre(){int x=0;printf("%d\n",1/x);}
void gettle(){int res=1;while(1)res<<=1;printf("%d\n",res);}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}
template<typename N,typename PN>inline N flo(N a,PN b){return a>=0?a/b:-((-a-1)/b)-1;}
template<typename N,typename PN>inline N cei(N a,PN b){return a>0?(a-1)/b+1:-(-a/b);}
template<typename N>N gcd(N a,N b){return b?gcd(b,a%b):a;}
template<typename N>inline int sgn(N a){return a>0?1:(a<0?-1:0);}
#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld "%I64d"
#else
#define lld "%lld"
#endif
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
#ifdef JCVB
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
typedef long long ll;
typedef double db;
inline ll sqr(ll a){return a*a;}
inline db sqrf(db a){return a*a;}
const int inf=0x3f3f3f3f;
const db pi=3.14159265358979323846264338327950288L;
const db eps=1e-6;
//const int mo=0;
//int qp(int a,ll b){int n=1;do{if(b&1)n=1ll*n*a%mo;a=1ll*a*a%mo;}while(b>>=1);return n;}

char s[17]="CODEFESTIVAL2016";
char t[17];
int main()
{
#ifdef JCVB
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	int _time_jc=clock();
#endif

	gs(t);
	int an=0;
	rep(i,0,16)if(s[i]!=t[i])an++;
	printf("%d\n",an);


#ifdef JCVB
	debug("time: %d\n",int(clock()-_time_jc));
#endif
	return 0;
}




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

int main(){
    int64_t x;
    cin >> x;
    int64_t kane = 100;
    int64_t ans = 0;
    while(kane<x){
        kane += kane * 0.01;
        ans++;

    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    if n == 1 && m == 1 {
        println!("1");
        return;
    } else if n == 1 || m == 1 {
        println!("{}", max(n, m) - 2);
        return;
    }
    println!("{}", (n - 2) * (m - 2));
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

using namespace std;

string lcs(string s,string t){
    string result="";
    int m=s.length();
    int n=t.length();
    int lcs[m+1][n+1],i,j;
    for(i=0;i<m+1;i++)
        lcs[i][0]=0;
    for(i=0;i<n+1;i++)
        lcs[0][i]=0;
    for(i=1;i<m+1;i++){
        for(j=1;j<n+1;j++){
            if(s[i-1]==t[j-1]){
                lcs[i][j]=lcs[i-1][j-1]+1;
            }
            else{
                lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
            }
        }
    }
    //Get the lcs string
    i=m,j=n;
    while(i>0 && j>0){
        if(s[i-1]==t[j-1]){
            result+=s[i-1];
            i--,j--;
        }
        else{
            if(lcs[i-1][j]>lcs[i][j-1])
                i--;
            else
                j--;
        }
    }
    return result;
}

int main()
{
    string s,t;
    cin>>s>>t;
    string result = lcs(s,t);
    reverse(result.begin(),result.end());
    cout<<result<<"\n";
    return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int dist(int a, int b){
  return pow(a-b,2);
}

int main(){
  int n;
  cin >> n;
  vector<int> X(n);
  rep(i,n) cin >> X[i];
  sort(X);
  int ans = pow(10,9);
  for(int i=X[0];i<=X[n-1];i++){
    int tmp = 0;
    rep(j,n){
      tmp += dist(i,X[j]);
    }
    ans = min(ans,tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
n=int(input())
t=[0]*(n+1)
x=[0]*(n+1)
y=[0]*(n+1)
t[0]=0
x[0]=0
y[0]=0
for i in range(1,n+1):
    t[i],x[i],y[i] = map(int,input().split())
    if i!=0:
        if abs(x[i]-x[i-1])+abs(y[i]-y[i-1])>t[i]-t[i-1]:
            print("No")
            sys.exit()
        if ((x[i-1]+y[i-1])%2==0 and (x[i]+y[i])%2==0) or ((x[i-1]+y[i-1])%2==1 and (x[i]+y[i])%2==1):
            if (t[i]-t[i-1])%2!=0:
                print("No")
                sys.exit()
        else:
            if (t[i]-t[i-1])%2==0:
                print("No")
                sys.exit()

                
print("Yes")

Measured memory_bytes: 11732