akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 100000+10;
const ll inf = 1e15;
ll sum1[M], sum2[M];
int n, m;
ll ans;
int a[M];

void update1(int l,int r) {
	if (l>r) return;
	sum1[l] += 1, sum1[r+1] += -1;
	sum2[r+1] -= r-l+1;
}

void update2 (int l,int r,int x) {
	if (l>r) return;
	sum2[l] += x, sum2[r+1] -= x;
}

int main () {
	scanf ("%d%d", &n,&m);
	ll tot = 0;
	for (int i=0; i<n; ++i) {
		scanf ("%d", a+i);
        if (i) {
			tot += (a[i]-a[i-1]+m)%m;
			if (a[i-1]<a[i]) {
				update1 (a[i-1]+1, a[i]);
				update2 (a[i-1]+1, a[i], -1);
			} else {
				update1 (a[i-1]+1, m);
				update2 (a[i-1]+1, m, -1);
				update2 (1, a[i], m-a[i-1]-1);
				update1 (1, a[i]);
			}
        }
	}
	for (int i=1; i<=m; ++i) sum1[i] += sum1[i-1];
	for (int i=1; i<=m; ++i) sum1[i] += sum1[i-1];
	for (int i=1; i<=m; ++i) sum2[i] += sum2[i-1];
	ll minn = inf;
	for (int i=1; i<=m; ++i) {
		minn = min(minn, tot-sum1[i]-sum2[i]);
	}
	printf ("%lld\n", minn);
	return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long
#define INF INT_MAX
#define mod 1000000007
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll pw(ll a, ll b) {
    if (b == 0) return 1;
    ll t = pw(a, b / 2);
    if (b % 2 == 0) return (t * t)%mod;
    else return ((t * t)%mod * a)%mod;
}
int main()
{
	string s;
	cin>>s;
	int ans=0;
	for(char ch:s)
	{
		if(ch=='+')ans++;
		else ans--;
	}
	cout<<ans;
	
}


Measured memory_bytes: 3568
import sys
sys.setrecursionlimit(500000)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    s = input()
    n = len(s)
    for i in range(n):
        if s[i] == 'A':
            break
    for j in range(n-1, -1, -1):
        if s[j] == 'Z':
            break
    print(j-i+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 64684
def input_n
    gets.to_i               # 単一整数
end
def input_s
    gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end
def input_a
    gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end
def input_o(num)
    num.times.map{gets.to_i}  # 縦に並んだ複数の整数。たまにある
end
def output_f(num)
    puts sprintf("%.12f", num)
end

n = input_n
output_f(n * 2 * Math::PI)

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end(), greater<int>());
    int alice = 0, bob = 0;
    for (int i = 0; i < n; i++)
    {
        if (i & 1)
        {
            bob += a.at(i);
        }
        else
        {
            alice += a.at(i);
        }
    }
    cout << alice - bob << endl;
}

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

using namespace std;

typedef long long ll;
const ll inf = 0x3f3f3f3f;
#define case(i) "Case #" << i << ": "
 
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
    out << '(' << p.first << ", " << p.second << ')';
    return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
    ll l = v.size();
    for (ll i = 0; i < l - 1; i++) out << v[i] << ' ';
    if (l > 0) out << v[l - 1];
    return out;
}

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

    int x, y;
    cin >> x >> y;

    bool ok = false;
    for(int i = 0; i <= x; ++i) {
        int a = i;
        int b = x - i;
        if(2 * a + 4 * b == y) ok = true;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

string tos(int a) {
  stringstream ss;
  ss << a;
  return ss.str();
}

int main() {
  string a;
  int L;
  while(cin >> a >> L && !(a == "0" && L == 0)) {
    map<string, int> m;
    m[a] = 0;
    for(int i = 1; ; ++i) {
      while(a.size() < L) a = "0" + a;
      sort(a.begin(), a.end());
      string maxi = a, mini = a;
      do {
        maxi = max(maxi, a);
        mini = min(mini, a);
      } while(next_permutation(a.begin(), a.end()));
      a = tos(atoi(maxi.c_str()) - atoi(mini.c_str()));
      if(m.count(a)) {
        cout << m[a] << " " << atoi(a.c_str()) << " " << i - m[a] << endl;
        break;
      }
      m[a] = i;
    }
  }
  return 0;
}

Measured memory_bytes: 1264
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    n = int(input())
    a = [0] + [int(x) for x in input().split()]
    b = [0] * (n + 1)

    for i in range(n, 0, -1):
        tot = 0
        for j in range(2 * i, n + 1, i):
            tot += b[j]
        tot %= 2
        b[i] = tot if a[i] == 0 else 1 - tot

    for i in range(1, n + 1):
        tot = 0
        for j in range(i, n + 1, i):
            tot += b[j]
        if tot % 2 != a[i]:
            print(-1)
            return

    res = []
    for i in range(1, n + 1):
        if b[i]:
            res.append(i)

    print(len(res))
    print(*res)


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 59688
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#include <sstream>

int main(void)
{
    int64_t W, H, x, y;
    std::cin >> W >> H >> x >> y;

    double area = (W * H) / 2.0;
    std::string multi = ((2*x) == W && (2*y) == H) ? "1" : "0";

    std::cout << std::setprecision(9) << area << " ";
    std::cout << multi << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
    FAST
    int a,b;
    cin>>a>>b;
    cout<<max(0,a-2*b);
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define int long long
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define mod 1e9
int32_t main() {
	int n,x,c;
	cin>>n>>x;
	int ans=0;

	while(!(x&1))
	{
		ans++;
		x>>=1;
	}
	n--;
	while(n--)
	{
		cin>>x;
		int c=0;
		
		while(!(x&1))
		{
			c++;
			x>>=1;
		}
		ans=min(ans,c);
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int A, B, X; cin >> A >> B >> X;
  if (X < A || A + B < X) cout << "NO" << endl;
  else                    cout << "YES" << endl;
}


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

#define INF 100009

int N;
int P[1010],X[1010];
int dp[1010][5010] = {0};
bool F = false;

int main()
{
    scanf("%d",&N);
    for(int i = 2; i <= N; i++)scanf("%d",P + i);
    for(int i = 1; i <= N; i++)scanf("%d",X + i);

    for(int i = N; i > 0; i--)
    {
        int MIN = INF;
        for(int j = 0; j <= X[i]; j++)MIN = min(MIN,dp[i][j]);
        if(MIN == INF)F = true;

        int par = P[i];

        for(int j = X[par]; j >= 0; j--)
        {
            int cost = INF;
            if(j >= MIN)cost = dp[par][j - MIN] + X[i];
            if(j >= X[i])cost = min(cost,dp[par][j - X[i]] + MIN);
            dp[par][j] = cost;
        }
    }


    if(F)printf("IMPOSSIBLE\n");
    else printf("POSSIBLE\n");

    return 0;
}


Measured memory_bytes: 18432
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9)cout<<"hon";
  else if(n%10==0||n%10==1||n%10==6||n%10==8)cout<<"pon";
  else {cout<<"bon";}
  return 0;
}

Measured memory_bytes: 3632
n = int(input())
p = []
for i in range(n):
    p.append(int(input()))
p.sort()
p.reverse()
ans = 0
for i in range(n):
    if i == 0:
        ans = p[i]/2
    else:
        ans += p[i]
if ans - int(ans) != 0:
    print(ans)
else :
    print(int(ans))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define m 1e18
using namespace std;

int main()
{
    ll n, k, r, s, p, i, sum = 0;
    string t;

    cin >> n >> k >> r >> s >> p >> t;

    for(i = 0; i < n; i++){
        if(t[i] == 'r') t[i] = 'p';
        else if(t[i] == 's') t[i] = 'r';
        else t[i] = 's';
    }

    for(i = k; i < n; i++){
        if(t[i] == t[i - k]) t[i] = '0';
    }

    for(i = 0; i < n; i++){
        if(t[i] != '0'){
            if(t[i] == 'r') sum += r;
            else if(t[i] == 's') sum += s;
            else sum += p;
        }
    }

    ///cout << t << endl;
    cout << sum << endl;

    return 0;
}


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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N, M; cin >> N >> M;
  ll allsum = 0;

  vector<ll> reduce;
  for (int i = 0; i < N; i++) {
    ll a; cin >> a;
    allsum += a;
    while (a > 0) {
      ll nxtA = a / 2;
      ll red = a - nxtA;
      reduce.push_back(red);
      a = nxtA;
    }
  }
  sort(reduce.begin(), reduce.end(),
       [&](int x, int y) { return x > y; });
  ll redsum = 0;
  int rs = reduce.size();
  int lim = min(M, rs);
  for (int i = 0; i < lim; i++) {
    redsum += reduce.at(i);
  }
  cout << (allsum - redsum) << endl;

  return 0;
}



Measured memory_bytes: 35044
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // input
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) { cin >> a[i]; }
    // output
    int ans = 0;
    rep(i, n) { ans ^= a[i]; }
    if (ans == 0) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 640
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 10
#define maxc 55
typedef long long ll;

int n,c; ll cnt,ans;
int l[maxn],a[maxn];
ll f[maxn*maxc][maxn*maxc];

inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

ll solve(){
	memset(f,0,sizeof(f)),f[l[n]*n+1][0]=1;
	for (int i=1;i<=n*c;i++)
		for (int j=i;j<=n*c+1;j++)
			for (int k=0;k<(1<<(n-1));k++)
				if (((i-1)%n)&&(~k>>((i-1)%n-1)&1))
					f[min(max(j,i+l[a[(i-1)%n]]*n),n*c+1)][k|1<<((i-1)%n-1)]+=f[j][k];
	return f[n*c+1][(1<<(n-1))-1];
}

int main(){
	n=read(),c=read();
	for (int i=1;i<=n;i++) l[i]=read(),a[i]=i; sort(l+1,l+n+1);
	do{ans+=solve(),++cnt;}while (next_permutation(a+1,a+n));
	for (int i=1;i<n;i++) cnt*=c;
	printf("%.20f\n",(double)ans/cnt);
	return 0;
}


Measured memory_bytes: 2688
import java.util.Scanner;

public class Main {

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

		int H[]=new int[256];
		int W[]=new int[256];

		int i=0;
		while(true){
			H[i]=sc.nextInt();
			W[i]=sc.nextInt();

			if(H[i]==0&&W[i]==0)	break;
			i++;
		}

		for(int x=0;x<i;x++){
			for(int j=0;j<H[x];j++){
				for(int k=0;k<W[x];k++){
					if(j==0||j==H[x]-1||k==0||k==W[x]-1)	System.out.print("#");
					else	System.out.print(".");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 33976
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
  int N; cin >> N;
  vector<long long> a(N + 1); for (int i = 1; i <= N; i++) cin >> a[i];
  for (int i = 2; i <= N; i++) a[i] += a[i - 1];
  long long ans = 200000000000001;
  for (int i = 1; i < N; i++) ans = min(abs(a[i] - (a[N] - a[i])), ans);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define pb push_back
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define F first
#define S second
#define MP make_pair
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

multiset<ll> s;

int main()
{jizz
	ll ans=0,n,x;
	cin >> n;
	while(n--)
		cin >> x,s.insert(x);
	while(s.size()>=2)
	{
		x=*s.rbegin(),s.erase(--s.end());
		n=1<<__lg(x)+1;
		if(s.find(n-x)!=s.end())
			s.erase(s.find(n-x)),++ans;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 9600
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>

int main(void)
{
    int M,D,d1,d10;
    int i;
    int count=0;
    
    scanf("%d %d",&M, &D);
    
    for(i=22; i<=D; i++){
        d1 = i%10;
        d10 = i/10;
        if((d1 >= 2) && (d10 >= 2)){
            if(d1*d10 <= M){
            count++;
            }
        }
    }
    
    printf("%d\n",count);
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        SumOfDigits solver = new SumOfDigits();
        solver.solve(1, in, out);
        out.close();
    }

    static class SumOfDigits {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();

            long s = Integer.MAX_VALUE;
            for (int i = 1; i < n; i++) {
                int d = n - i;
                int j = i;

                long ds = 0L;
                while (d != 0) {
                    ds += d % 10;
                    d /= 10;
                }

                long js = 0L;
                while (j != 0) {
                    js += j % 10;
                    j /= 10;
                }

                s = Math.min(s, ds + js);
            }

            out.printf("%d\n", s);
        }

    }
}



Measured memory_bytes: 21204
S = input()
N = len(S)

ans = [0] * N
R = 0
L = 0
L_flag = 0
ind = 0
flag = 1


def ppp(R, L, ind):
    if R % 2:
        ans[ind - 1] += 1
    if L % 2:
        ans[ind] += 1
    ans[ind] += R // 2 + L // 2
    ans[ind - 1] += R // 2 + L // 2


for i in range(N):
    if S[i] == 'R':
        if L_flag:
            ppp(R, L, ind)
            L_flag = 0
            R = 0
            L = 0
            flag = 1
        R += 1
    else:
        if flag:
            ind = i
            flag = 0
        L += 1
        L_flag = 1

if L_flag:
    ppp(R, L, ind)

[print(i, end=' ') for i in ans]


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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a==5&&b==5&&c==7){
    cout<<"YES"<<endl;
  }
  else  if(a==5&&b==7&&c==5){
    cout<<"YES"<<endl;
  }
  else if(a==7&&b==5&&c==5){
    cout<<"YES"<<endl;
  }
  else {
    cout<<"NO"<<endl;
  }
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a + b > c + d) cout << "Left" << endl;
  else if(a + b == c + d) cout << "Balanced" << endl;
  else cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

int N;
struct Edge {
    int to, cost;
    Edge(int to, int cost) : to(to), cost(cost) {}
};
const int INF = 1e9;
using P = pair<int, int>;
vector<Edge> G[21];
int dp[21][21];

void solve() {
    rep(i, 21) rep(j, 21) dp[i][j] = INF;
    rep(i, 21) dp[i][i] = 0;
    rep(i, 21) G[i].clear();

    rep(i, N - 1) {
        int a, b, t;
        cin >> a >> b >> t;
        a--, b--;
        G[a].push_back(Edge(b, t));
        G[b].push_back(Edge(a, t));
        dp[a][b] = t;
        dp[b][a] = t;
    }
    rep(k, N) rep(i, N) rep(j, N) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
    int ans = 0;
    rep(i, N) {
        for (auto e : G[i]) {
            if ((i == 0 || G[i].size() != 1) &&
                (e.to == 0 || G[e.to].size() != 1)) {
                // printf("debug: %d %d %d\n", i, e.to, e.cost);
                ans += e.cost;
            }
        }
    }
    // cout << ans << endl;
    int maxi = 0;
    rep(i, N) {
        if (G[i].size() == 1) {
            maxi = max(maxi, dp[0][G[i][0].to]);
        }
    }
    ans -= maxi;
    cout << ans << endl;
}
int main() {
    while (cin >> N) {
        if (N == 0) break;
        solve();
    }
}

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

int e[100010];
int o[100010];
int ev[100010];
int ov[100010];

bool cmp(int x, int y) {
    return x > y;
}

int main() {
    int n;
    int maxo, maxe, counte = 0, counto = 0;
    
    scanf("%d", &n);
    for (int i = 1; i <= n/2; i++) {
        scanf("%d", &o[i]);
        ov[o[i]]++;

        scanf("%d", &e[i]);
        ev[e[i]]++;
    }
    
    for (int i = 1; i <= n/2; i++) {
        if (ov[o[i]] > counto) {
            counto = ov[o[i]];
            maxo = o[i];
        }
        if (ev[e[i]] > counte) {
            counte = ev[e[i]];
            maxe = e[i];
        }
    }
    sort(ev+1, ev+100010, cmp);
    sort(ov+1, ov+100010, cmp);

    if (maxo != maxe)
        cout << n - (ev[1] + ov[1]) << endl;
    else
        cout << min(n - (ev[1] + ov[2]), n-(ev[2] + ov[1])) << endl;
    
    return 0;
}

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

using namespace std;

string s;
char ck[]={'k','e','y','e','n','c','e'};
int cnt,c;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>s;
	if(s.size()<7)
		cout<<"NO";
	else
	{
		for(int i=0;i<s.size();i++)
		{
			if(s[i]!=ck[cnt])
				break;
			cnt++;
		}
		int dcnt=6;
		for(int i=s.size()-1;i>=0;i--)
		{
			if(s[i]!=ck[dcnt])
				break;
			dcnt--;
		}
		if(cnt>dcnt)
			cout<<"YES";
		else
			cout<<"NO";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//{
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
};
//{
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);
//}

int main() {
		make(x);
		complex<double> pos(0.,0.);
		double eps = 1e-5;
		complex<double> kat(1., 0.);
		complex<double> kat2(cos(x*1./180 * M_PI), sin(x*1./180*M_PI));
		int ans = 0;
		do {
			pos += kat;
			kat *= kat2;
			ans++;
			//debug() << imie(pos);
		} while (abs(pos.real()) + abs(pos.imag()) > eps); 
		printf("%d\n", ans);
}


Measured memory_bytes: 3996
N=int(input())
n=list(str(N))
if len(n)==6:
    print(9+900+90000)
elif len(n)==5:
    print(9+900+N-9999)
elif len(n)==4:
    print(909)
elif len(n)==3:
    print(N-99+9)
elif len(n)==2:
    print(9)
else:
    print(N)

Measured memory_bytes: 9012
#include<stdio.h>
int main(void){
	int a,b,c,d,e,f;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	a+=b*5+c*10+d*50+e*100+f*500;
	if(a>=1000)
		printf("1\n");
	else 
		printf("0\n");
}

Measured memory_bytes: 1012
#配るDP
n,k=map(int,input().split())
l=[0]*k
r=[0]*k
for j in range(k):
  l[j],r[j] = map(int,input().split())
p=998244353
dp=[0]*(n+max(r)+100)
dp[1]=1
dp[2]=-1
for i in range(1,n+1):
  dp[i] += dp[i-1]
  dp[i] %= p
  
  for lj,rj in zip(l,r):
    dp[i+lj] += dp[i]
    dp[i+lj] %= p
    dp[i+rj+1] -= dp[i]
    dp[i+rj+1] %= p
print(dp[n])


Measured memory_bytes: 71396
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    cin.tie(0);
    int a,b,am,bm;
    cin >> a >> b;

    if((a+b)%2==0){
        cout << (a+b)/2 << endl;
        return 0;
    }else{
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

}

Measured memory_bytes: 256
// -- Nitin
#include <bits/stdc++.h>
#define pb push_back
#define mkp make_pair
#define llu unsigned long long int
#define ll long long
#define ld long double
#define foi(a,n) for(int i = a; i < (int)n; i++)
#define foj(a,n) for(int j = a; j < (int)n; j++)
#define foin(a,n) for(int i = n; i >= a; i--)
#define fojn(a,n) for(int j = n; j >= a; j--)
#define bug(x) cerr << #x << " is " << x << endl;
#define isp2(x) x&&(!(x&(x-1)))
#define ln '\n'
#define ee 1000000007
#define eem 998244353
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define cases int tests; cin >> tests; while(tests--)

using namespace std;

ll fast(ll n,ll k){
    ll res = 1;
    n = n;
    while(k > 0){
        if ((k&1) == 1)
            res = (res * n);
        k = k>>1;
        n = (n * n);
    }
    return res;
}
 
//~ ll strsum(string s){
    //~ ll sm = 0, r = s.size();
    //~ foi(0,r)    sm += int(s[i]-'a');
    //~ return sm;
//~ }
 
//~ set <ll, greater <ll> > ss; //Prime Factors
//~ void pF(ll n)  {    
    //~ while (n % 2 == 0)  {  
        //~ ss.insert(2);  
        //~ n = n/2;  
    //~ }  
    //~ for (int i = 3; i <= sqrt(n); i = i + 2)  {   
        //~ while (n % i == 0)  {  
            //~ ss.insert(i); 
            //~ n = n/i;  
        //~ }  
    //~ }    
    //~ if (n > 2)  ss.insert(n);  
//~ }

//~ ll pre[1001][1001];

//~ ll go(ll n, ll k){
	//~ if(n==1) return 1;
	//~ else {
		//~ pre[n][k] = (go(n - 1, k) + k - 1) % n + 1;
		//~ return pre[n][k];
	//~ }
//~ }

//~ int dp[1002][1002];
//~ bool pal(string s){
	//~ for(int i = 0, j = s.size() - 1; i < s.size(); i++, j--){
		//~ if(s[i] != s[j]) return 0;
	//~ }
	//~ return 1;
//~ }

//~ void solve(){
	//~ int n;
	//~ cin >> n;		
//~ }


void go(){
	int n;
	string s;
	cin >> s;
	int x =0, ans = 0;
	for(int i = 0; i < 3; i++){
		if(s[i] == 'R'){
			x++;
			ans = max(ans, x);
		}
		else{
			ans = max(ans, x);
			x = 0;
		}
	}
			
	cout << ans;
	return;
}

int main(){
    fio;
	//~ ll q, n, x, m , y;
	//~ string t;
	//~ for(int i = 1; i <= 1000; i++){
		//~ pre[1][i]=1;
		//~ go(1000,i);
	//~ }
	ll n, m, k;
    //~ cases
    {	
		go();
		cout << "\n";
	}
}
       
        


Measured memory_bytes: 3648
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll A, B, C, D, N, c, d, n;
  cin >> A >> B >> C >> D;

  ll x, y = C, z = D;
  if (z > y) swap(y, z);
  while (z != 0) {
    x = y;
    y = z;
    z = x % y;
  }
  N = (C * D) / y;

  c = B / C - (A - 1) / C;
  d = B / D - (A - 1) / D;
  n = B / N - (A - 1) / N;

  cout << B - A + 1 - c - d + n << endl;
}


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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var p = Input();
		var a = p[0].ToLong();
		var b = p[1].ToLong();
		var c = p[2].ToLong();
		if((decimal)(a+b+2*Sqrt((decimal)a*b)) < (decimal)c)
		{
			Console.WriteLine("Yes");
		}
		else
		{
			Console.WriteLine("No");
		
		}
	}
	
	public static decimal Sqrt(decimal x, decimal epsilon = 0.0M)
	{
	    if (x < 0) throw new OverflowException("Cannot calculate square root from a negative number");

	    decimal current = (decimal)Math.Sqrt((double)x), previous;
	    do
	    {
	        previous = current;
	        if (previous == 0.0M) return 0;
	        current = (previous + x / previous) / 2;
	    }
	    while (Math.Abs(previous - current) > epsilon);
	    return current;
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 13268
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

int A[100000];
int N, M, b, c;
ll res;

//降順ソート
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first > b.first;
    }
}

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

    vector<pair<int,int> > V(M);
    for (int i = 0; i < M; i++) {
        cin >> b >> c;
        V[i] = make_pair(b,c);
    }
    sort(A,A+N);
    sort(V.begin(),V.end(),compare_by_b);

    int j = 0;
    for (int i = 0; i < N; i++) {
        while (j < M && (V[j].first <= 0 || V[j].second <= A[i])) {
            j++;
        }
        if (j < M) {
            res += (ll)V[j].second;
            V[j].first -= 1;
        } else {
            res += (ll)A[i];
        }
    }

    cout << res << endl;

}

Measured memory_bytes: 1408
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;



void main() {
    int N; long M;
    scan(N, M);
    auto a = readln.split.to!(long[]);
    auto b = a.map!(ai => ai / 2).array;
    auto c = new int[](N);
    foreach (i ; 0 .. N) {
        auto bi = b[i];
        while (bi % 2 == 0) {
            c[i]++;
            bi /= 2;
        }
    }

    if (iota(N).any!(i => c[i] != c[0])) {
        writeln(0);
        return;
    }

    long lc = 1;
    foreach (i ; 0 .. N) {
        lc = lcm(lc, b[i]);
        if (lc > M) {
            writeln(0);
            return;
        }
    }

    debug {
        writeln(lc);
    }

    auto ans = M / lc - M / (2 * lc);
    writeln(ans);
}

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


void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}

Measured memory_bytes: 6700
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) (vec).begin(),(vec).end()
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
string s;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s;
	if(s=="SSS"){
		cout<<0<<endl;
		return 0;
	}
	if(s=="SSR"){
		cout<<1<<endl;
		return 0;
	}
	if(s=="SRS"){
		cout<<1<<endl;
		return 0;
	}
	if(s=="SRR"){
		cout<<2<<endl;
		return 0;
	}
	if(s=="RSS"){
		cout<<1<<endl;
		return 0;
	}
	if(s=="RSR"){
		cout<<1<<endl;
		return 0;
	}
	if(s=="RRS"){
		cout<<2<<endl;
		return 0;
	}
	if(s=="RRR"){
		cout<<3<<endl;
		return 0;
	}
	return 0;
}


Measured memory_bytes: 3608
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <bitset>
#include <map>

#define rep(i, l, r) for(int i=l; i<=r; i++)
#define dow(i, l, r) for(int i=l; i>=r; i--)
#define clr(x, c) memset(x, c, sizeof(x))
#define travel(x) for(edge *p=fir[x]; p; p=p->n)
#define all(x) (x).begin,(x).end
#define pb push_back
#define fi first
#define se second
#define l(x) Left[x]
#define r(x) Right[x]
#define lowbit(x) (x&-x)

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,int> Pli;
typedef long double ld;
typedef unsigned long long ull;

inline int read()
{
	int x=0; bool f=0; char ch=getchar();
	while (ch<'0' || '9'<ch) f|=ch=='-', ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0', ch=getchar();
	return f?-x:x;
}

int main()
{
	ll n=read(), a=read(), b=read(); if (a>b) puts("0"); else if (n==1 && a!=b) puts("0"); else printf("%lld\n", (b*n-(b-a))-(a*n+(b-a))+1);
	return 0;
}

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

int main(){
  int n, A=0, B=0, max=0;
  cin >> n;
  vector<int> pt(n), sort(n);
  for(int i=0; i<n; i++)
    cin >> pt.at(i);
  
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      if(pt.at(max)<pt.at(j))
        max = j;
    }
    sort.at(i) = pt.at(max);
    pt.at(max)=0;
  }
  
  for(int i=0; i<n; i++){
    if(i%2) B += sort.at(i);
    else A += sort.at(i);
  }
  cout << A - B << endl;
         
        
}

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

using namespace std;

#define dbg(x) cerr << #x"=" << x << endl;
typedef long long LL;

int main(){
	//freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    LL r,D,x;
    cin >> r >> D >> x;
    for(int i = 1; i <= 10; ++i){
        LL y = r*x-D;
        cout << y << endl;
        x = y;
    }
	return 0;
}



Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあって そんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/pavan/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

long long ans = 0;

long long eval(string s){
	long long res = 0, curr = 0;
	for(int i = 0;i < s.size(); i++){
		if(s[i] == '+'){
			res += curr;
			curr = 0;
		}
		else curr = curr * 10 + s[i] - '0';
	}
	res += curr;
	return res;
}

int main(){
	FIO
	
	string s;cin >> s;
	for(int mask = 0; mask < (1 << (s.size() - 1)); mask++){
		string now = "";
		for(int i = 0; i < s.size() - 1;i++){
			now += s[i];
			if(mask & (1 << i))now += '+';
		}
		now += s[s.size() - 1];
		deb(now);
		ans += eval(now);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import javax.lang.model.util.ElementScanner6;

public class Main {

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

        // 入力
        int n = sc.nextInt();
        int[] x = new int[n];
        int max = 1;
        for (int i = 0; i < n; i++){
            x[i] = sc.nextInt();
            max = max < x[i] ? x[i] : max;
        }

        // 処理
        int hp_max = 0;
        for (int i = 1; i <= max; i++){
            int hp_tmp = 0;
            for (int j = 0; j < n; j++){
                hp_tmp += Math.pow((i - x[j]), 2);
            }
            if (i == 1){
                hp_max = hp_tmp;
            } else {
                hp_max = hp_max > hp_tmp ? hp_tmp : hp_max;
            }
        }
        int out = hp_max;


        // 出力
        System.out.println(out);
    }

}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}

int main(){
  int h,w;
  cin>>h>>w;
  vector<string>s(h+2);
  Rep(i,1,h+1){cin>>s[i];s[i]="."+s[i]+".";}
  string tmp="";
  rep(i,w+2)tmp=tmp+".";
  s[0]=tmp;
  s[h+1]=tmp;
  vector<vector<int>>mine(h,vector<int>(w));
  Rep(i,1,h+1){
    Rep(j,1,w+1){
      int tmpmi=0;
      if(s[i][j]=='#'){mine[i-1][j-1]=-1;continue;}
      if(s[i-1][j-1]=='#')tmpmi++;      
      if(s[i][j-1]=='#')tmpmi++;
      if(s[i+1][j-1]=='#')tmpmi++;
      if(s[i-1][j]=='#')tmpmi++;
      if(s[i+1][j]=='#')tmpmi++;
      if(s[i-1][j+1]=='#')tmpmi++;
      if(s[i][j+1]=='#')tmpmi++;
      if(s[i+1][j+1]=='#')tmpmi++;
      mine[i-1][j-1]=tmpmi;
      
    }}

  rep(i,h){rep(j,w){
      if(mine[i][j]==-1)cout<<"#";
      else cout<<mine[i][j];

    }cout<<endl;}
    
  return 0;
}


Measured memory_bytes: 3620
// only miss the sun when it starts to snow

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

#define f(a,b) cout<<a<<" "<<b<<"\n"

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e5+10,mod=1e9+7;
const ll inf=1e18;

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

    int n; cin>>n;

    if( (n&(-n)) == n ) return cout<<"No\n",0;
    cout<<"Yes\n";

    if(n&1){
	f(1+n,3);
	for(int i=2;i<n;i+=2)
	    f(1,i), f(i,i+1), f(1,i+1+n), f(i+1+n, i+n);
    }
    else{
	int tw=1<<(31-__builtin_clz(n));

	f(1,tw+1);
	f(tw+1,tw);
	f(tw,tw+2);
	f(tw,1+n);
	f(tw+1,3);
	f(1+n,tw+1+n);
	f(tw,2);
	f(2,tw+2+n);
	f(tw+2+n,tw+n);
	f(tw+n,2+n);
	f(2+n,3+n);

	for(int i=4;i<tw;i+=2)
	    f(1,i), f(i,i+1), f(1,i+1+n), f(i+1+n, i+n);
	for(int i=tw+3;i<n;i+=2){
	    int x= i ^ (i+1);
	    f(x,i), f(i,i+1), f(x,i+1+n), f(i+1+n, i+n);
	}
    }
    return 0;
}
// Deathly mistakes:
//  * Read the problem curfully.
//  * Check maxn.
//  * Overflows.


// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


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

/*------------------------------------------------------------------*/

#define ll long long int
#define mp make_pair
#define pb push_back
#define MOD 1000000007

bool isvowel(char c)
{
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        return true;
        return false;
}
ll isprime(ll n)
{
    ll ans=1;
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            ans = i;
    }
    return ans;
}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    if(b==1)
        return a%m;
    ll temp=power(a,b/2,m);
    if(b%2==0)
        return ((temp%m)*(temp%m))%m;
    else
        return ((((temp%m)*(temp%m))%m)*a%m)%m;
}

/*-----------------------------------------------------------------------------*/

ll c(ll n, ll k)
{
    ll C[n + 1][k + 1];
    ll i, j;

    for (i = 0; i <= n; i++)
    {
        for (j = 0; j <= min(i, k); j++)
        {

            if (j == 0 || j == i)
                C[i][j] = 1;

            else
                C[i][j] = (C[i - 1][j - 1]%MOD +
                          C[i - 1][j])%MOD;
        }
    }
    return C[n][k]%MOD;
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {

        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;


        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;

    return x;
}
ll func(ll n)
{
    ll ans=0;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            if(i/10==0)
                ans+=1+func(i)*func(n/i);
            else
                ans+=func(i)*func(n/i);
        }
    }
    return ans;
}
ll dp[205][205][205];
ll check(ll red[],ll gre[],ll blu[],ll r,ll g,ll b,ll i,ll j,ll k)
{
   if(dp[i][j][k]!=-1)
    return dp[i][j][k]; 
   if(i<r&&j<g&&k<b)
   {
       return dp[i][j][k]=max(red[i]*gre[j]+check(red,gre,blu,r,g,b,i+1,j+1,k),max(gre[j]*blu[k]+check(red,gre,blu,r,g,b,i,j+1,k+1),blu[k]*red[i]+check(red,gre,blu,r,g,b,i+1,j,k+1)));
   }
   else if(i<r&&j<g) 
   {
       return dp[i][j][k]=red[i]*gre[j]+check(red,gre,blu,r,g,b,i+1,j+1,k);
   }
   else if(j<g&&k<b)
   {
       return dp[i][j][k]=gre[j]*blu[k]+check(red,gre,blu,r,g,b,i,j+1,k+1);
   }
   else if(i<r&&k<b)
   {
       return dp[i][j][k]=red[i]*blu[k]+check(red,gre,blu,r,g,b,i+1,j,k+1);
   }
   else
   {
       return 0;
   }
}
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    //freopen("1.txt","rt",stdin);
    //freopen("output.txt","wwt",stdout);

    ll t;
    t=1;
    //cin>>t;
    //ll t1=0;
    while(t--)
    {
        ll n;
        cin>>n;
        string s;
        cin>>s;
        if(s.length()<=n)
         cout<<s;
        else
        {
            string s1=s.substr(0,n);
            cout<<s1<<"...";
        }
         
    }
}


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

int a[200000],b[200000];
int used[200000];

int main(){
	int n;scanf("%d",&n);
	vector<P>v;
	ll sumA=0,sumB=0;
	rep(i,n){
		scanf("%d%d",&a[i],&b[i]);
		v.push_back(P(a[i],i));
		v.push_back(P(b[i],i+n));
		sumA+=a[i];
		sumB+=b[i];
	}
	sort(v.begin(),v.end());
	ll sum=0;
	bool flag=false;
	rep(i,n){
		if(used[v[i].second%n]){
			flag=true;
		}
		sum+=v[i].first;
		used[v[i].second%n]++;
	}
	ll Min=min(sumA,sumB);
	if(flag)Min=min(Min,sum);
	else{
		sum=0;
		set<int>se;
		rep(i,n-2)sum+=v[i].first,se.insert(v[i].second);
		rep(i,n){
			int cnt=0;
			ll sum2=sum;
			if(!se.count(i))sum2+=a[i],cnt++;
			if(!se.count(i+n))sum2+=b[i],cnt++;
			rep(j,2-cnt){
				sum2+=v[n-2+j].first;
			}
			Min=min(Min,sum2);
		}
	}
	cout<<Min<<endl;
}

Measured memory_bytes: 7664
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define eps 1e-9
#define mp make_pair

int k,s,ans,tmp;

int main () {
	scanf("%d%d",&k,&s);
	FOE(i,0,k) {
		FOE(j,0,k) {
			if (i+j>s) break;
			if (s-i-j<=k) ++ans;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int ctoi(int n) {
    return n - '0';
}

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

    while(x != "0") {
        int x_total = 0;
        for(int i=0; i<x.size(); ++i) {
            x_total += ctoi(x[i]);
        }

        cout << x_total << endl;
        cin >> x;
    }

    return 0;
}


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

int main(){
  int n, k;
  cin >> n >> k;
  int cnt = 0, hig;
  for(int i=0; i<n; ++i){
    cin >> hig;
    if(hig >= k) ++cnt;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3632
h,w = map(int, input().split())
aaa = [input().replace('#','1').replace('.','0') for _ in range(h)]

ans = 'Impossible'
for i in range(h-1):
    # check up-down
    updown = bin(int(aaa[i],2) & int(aaa[i+1],2))
    if updown.count('1') >1:
        # print('updown')
        break
    # check left move
    # print(aaa[i+1], aaa[i+1].index('1') , aaa[i], aaa[i].rindex('1'))
    if aaa[i+1].index('1') < aaa[i].rindex('1'):
    # int(aaa[i+1]) > int(aaa[i]):
        # print('left')
        break
else:
    ans = 'Possible'
print(ans)

# for a in aaa:
#     print(a)

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

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

	ll s = a + b;
	ll result = 1LL * (n / s) * a;
	n %= s;
	result += min(n, a);
	cout<<result;
}

Measured memory_bytes: 256
sr_list = list(input())
r_count = sr_list.count('R')
if r_count == 0:
  print('0')
elif r_count == 1:
  print('1')
elif r_count ==3:
  print('3')
else:
  if sr_list[1] == 'S':
    print('1')
  else:
    print('2')

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N, K;
    cin >> N >> K;
    vector<double> p(N);
    REP(i, N) {
        int pi;
        cin >> pi;
        p[i] = (double)(pi + 1)/2;
    }
    double res = 0;
    REP(i, K) {
        res += p[i];
    }
    double sum = res;
    FOR(i, K, N) {
        sum += p[i] - p[i - K];
        res = max(res, sum);
    }
    printf("%.12f\n", res);
    return 0;
}



Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int a[8005],dp[8005][16005],k;
void DP(int x){
	dp[x][a[x]+8000]=1;
	for(int i=x+2;i<=k;i+=2)
		for(int j=0;j<=16000;j++){
			if(j+a[i]<=16000)
				dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
				dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
}
int main(){
	string s;
	int x,y,n,w=0,ans;
	cin>>s>>x>>y;
	n=s.size();
	for(int i=0;i<n;i++){
		if(s[i]=='F')
			w++;
		else{
			a[++k]=w;
			w=0;
		}
	}
	a[++k]=w;
	DP(1);
	DP(0);
	if(k%2==0)
		ans=dp[k][y+8000]&&dp[k-1][x+8000];
	else
		ans=dp[k][x+8000]&&dp[k-1][y+8000];
	if(ans==1)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 497792