akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    vl vec(n);
    REP(i,n){
        cin>>vec[i];
        vec[i]-=i+1;
    }
    sort(all(vec));
    ll ans=0;
    REP(i,n){
        ans+=abs(vec[(n-1)/2]-vec[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
bool prime[1000000];
void sieve() {
    fill_n(prime, 1000000, true);
    prime[0] = false;
    prime[1] = false;
    for (int i=2; i<=1000; ++i) {
        if (prime[i]) {
            for (int j=i*i; j<1000000; j+=i) {
                prime[j] = false;
            }
        }
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    sieve();

    int memo[1000000];
    for (int i=1; i<1000000; ++i) {
        memo[i] = memo[i-1]; 
        if (prime[i]) {
            memo[i] ++; 
        }
    }

    int n;
    while (cin >> n) {
        cout << memo[n] << "\n";
    }
    return 0;
}

Measured memory_bytes: 6076
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int qqq(int r, int g, int b)
{
	if (r == string::npos)
	{
		if (g == string::npos)return 1;
		if (b == string::npos)return 1;
	}
	if (g== string::npos)
	{
		if (b == string::npos)return 1;
	}
	return 0;

}
string ch(char a, char b){
	if (a == b)return "0";
	if (a == 'r')
	{
		if (b == 'g')return "bb";
		else return "gg";
	}
	if (a == 'g')
	{
		if (b == 'r')return "bb";
		else return "rr";
	}
	if (a == 'b')
	{
		if (b == 'r')return "gg";
		else return "rr";
	}

}
int main()
{
	while (1)
	{
		string musi;
		queue<string> now;
		map<string, int> cou;

		cin >> musi;		if (musi == "0")break;

		cou[musi] = 0;
		now.push(musi);

		while (1)
		{
			string ss = now.front();
			int r, g, b;
			r = ss.find("r", 0);
			g = ss.find("g", 0);
			b = ss.find("b", 0);
			if (qqq(r, g, b)){
				cout << cou[ss] << endl;
				cou.clear();
				while (!now.empty())now.pop();
				break;
			}
			int siz = ss.size();

			for (int i = 0; i < siz - 1; i++)
			{
				if (ch(ss.at(i), ss.at(i + 1)) == "0")continue;
				string hoge=ss;
				hoge.replace(i, 2, ch(ss.at(i), ss.at(i + 1)));
				if (!cou.count(hoge)){
					cou[hoge] = cou[ss] + 1;
					now.push(hoge);
				}
			}
			now.pop();
			if (now.empty()){ cout << "NA" << endl; break; }
		}
	}
	return 0;
}

Measured memory_bytes: 2784
#include<bits/stdc++.h>
using namespace std;
int main(){
	char ch;
	string a,b,c;
	cin>>a>>b>>c;
ch=a[0];

	if(ch>='a' &&ch<='z')
	ch=ch-32;
	
	cout<<ch;
ch=b[0];

	if(ch>='a' &&ch<='z')
	ch=ch-32;
	
	cout<<ch;
	
	
ch=c[0];

	if(ch>='a' &&ch<='z')
	ch=ch-32;
	
	cout<<ch;
		
	
	
	
	
	
	
	
	
	
	
	
	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

#define rep(countName, left, right, up) for (ll countName = left; countName < right; countName += up)
#define rev(countName, right, left, down) for (ll countName = right - 1; countName >= left; countName -= down)

auto solve1(void)
{
    char c;
    cin >> c;
    return ++c;
}

int main(void)
{
    cout << solve1() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;
using llong = long long;
const int MOD=1000000007;


int calc_sum(int a){
    int ret = 0;
    while (a != 0){
        ret += a % 10;
        a /= 10;
    }

    return ret;
}


int main(int argc, char**argv){
    int n, a, b;
    cin >> n >> a >> b;

    int ans = 0;
    for (int i = 1; i <= n; i++){
        // cout << i << " " << calc_sum(i) << endl;
        if (a <= calc_sum(i) && calc_sum(i) <= b){
            ans += i;
        }

    }
    cout << ans << endl;

    return 0;
}







Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


# --------------------------------------------

dp = None


def main():
    N = int(input())
    S = input()

    open, close = 0, 0

    for i in range(N):
        if S[i] == "(":
            open += 1
        else:
            if open == 0:
                close += 1
            else:
                open -= 1

    print("(" * close + S + ")" * open)


main()


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

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

Measured memory_bytes: 3632
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.05.11 20:50:15
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

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

int main() {
    int r, g, b, n;
    scanf("%d%d%d%d", &r, &g, &b, &n);

    int ret = 0;
    rep(i, 3001) {
        rep(j, 3001) {
            int t = r * i + g * j;
            int nokori = n - t;
            if (nokori == 0) {
                ret++;
            } else if (nokori > 0 && nokori % b == 0) {
                ret++;
            }
        }
    }
    printf("%d\n", ret);

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    ll N, D, A;//N : monsterNum,D: attackRange,A: Damage
    cin >> N >> D >> A;
    vector<P> monster(N);
    vector<ll>X(N), H(N);
    vector<ll> damage(N, 0);
    rep(i, N) {
        cin >> X[i] >> H[i];
        monster[i] = mp(X[i], H[i]);
    }
    sort(monster.begin(), monster.end());
    sort(X.begin(), X.end());
    ll ans = 0;
    rep(i, N) {
        if(damage[i] < monster[i].second) {
            ans += ll((monster[i].second - damage[i] - 1) / A + 1);
            ll dmg = ll((monster[i].second - damage[i] - 1) / A + 1) * A;
            damage[i] += dmg;
            damage[(upper_bound(all(X), 2 * D + monster[i].first)) - X.begin()] -= dmg;
        }
        damage[i + 1] += damage[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 6528
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int N;
	cin >> N;
	set<int> paper;
	for(int i=0; i<N; i++){
		int A;
		cin >> A;
		if(paper.count(A) == 0) paper.insert(A);
		else paper.erase(A);
	}
	cout << paper.size() << endl;

	return 0;
}


Measured memory_bytes: 4992
N = int(input())

a = []
for _ in range(N):
    a.append(int(input()))

ans = 1
button = a[0]
for i in range(N):
    if button == 2:
        break
    button = a[button-1]
    ans += 1
    
if ans >= N+1:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 7084
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#include "bits/stdc++.h"

namespace adaptor = boost::adaptors;

int64_t A[200000], n;

int64_t partition(int64_t p, int64_t r) {
    int64_t x, i, j;
    x = A[r];
    i = p - 1;
    for (j = p; j < r; j++) {
        if (A[j] <= x) {
            i++;
            std::swap(A[i], A[j]);
        }
    }
    std::swap(A[i + 1], A[r]);
    return i + 1;
}

void solve() {
    std::cin >> n;
    for (int64_t i = 0; i < n; i++) {
        std::cin >> A[i];
    }

    int64_t q;
    q = partition(0, n - 1);

    for (int64_t i = 0; i < n; i++) {
        if (i > 0) std::cout << " ";
        if (i == q) std::cout << "[";
        std::cout << A[i];
        if (i == q) std::cout << "]";
    }
    std::cout << std::endl;

    return;
}

int main() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}



Measured memory_bytes: 3832
read a b c k

min() {
	min=$1
    shift
    
    for i in $@
    do
    	if (( "$i" < "$min" )); then
        	min=$i
        fi
    done
    
    echo "$min"
}

max() {
	max=$1
    shift
    
    for i in $@
    do
    	if (( "$i" > "$max" )); then
        	max=$i
        fi
    done
    
    echo "$max"
}

echo $(( "$(min "$a" "$k")" - "$(max 0 $(("$k" - "$a" - "$b")))" ))


Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N, M;
  cin >> N >> M;
  vector<int> data(N);
  int a, b;
  for(int i = 0; i < M; i++) {
    cin >> a >> b;
    a--;
    b--;
    data.at(a)++;
    data.at(b)++;
  }
  for(int i = 0; i < N; i++) {
    cout << data.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <complex>
#include <map>
#include <set>


#define forin(i, f, t) for(ll i = f; i < t; i++)

using namespace std;
using ll = long long;
using ULL = unsigned long long;
using Pair = pair<ll, ll>;

int main() {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    
    auto error = []() {
        cout << "NO" << endl;
        return 0;
    };
    
    if ((a + b) * 2 > m * n ||
        a > n * (m / 2) ||
        b > m * (n / 2))
        return error();
    
    vector<string> grid(n, string(m, '.'));
    
    auto setA = [&](int y, int x) {
        grid[y][x] = '<';
        grid[y][x + 1] = '>';
        a--;
    };
    
    auto setB = [&](int y, int x) {
        grid[y][x] = '^';
        grid[y + 1][x] = 'v';
        b--;
    };
    
    bool nodd = n % 2 == 1;
    bool modd = m % 2 == 1;
    if (nodd) {
        for (auto i = 0; i < m - (modd ? 3 : 1); i += 2) {
            if (a > 0)
            setA(n - 1, i);
        }
    }
    
    if (modd) {
        for (auto i = 0; i < n - (nodd ? 3 : 1); i += 2) {
            if (b > 0)
            setB(i, m - 1);
        }
    }
    
    auto maxN = nodd ? n - 1 : n;
    auto maxM = modd ? m - 1 : m;
    {
        auto minA = nodd && modd ? 1 : 0;
        auto minB = nodd && modd ? 1 : 0;
        for (auto j = 0; j < maxM; j += 2) {
            for (auto i = 0; i < maxN; i += 2) {
                if (nodd && modd && j == maxM - 2 && i == maxN - 2)
                    break;
                if (a >= b && a > minA) {
                    setA(i, j);
                    if (a > 0)
                        setA(i + 1, j);
                } else if (b > minB) {
                    setB(i, j);
                    if (b > 0)
                        setB(i, j + 1);
                } else {
                    break;
                }
            }
        }
    }
    
    if (nodd && modd) {
        auto i = n - 3;
        auto j = m - 3;
        if (a == 2 && b == 2) {
            setA(i + 2, j + 1);
            setB(i + 1, j);
            setA(i, j);
            setB(i, j + 2);
        } else {
            if (a > 0)
                setA(i + 2, j);
            if (b > 0)
                setB(i, j + 2);
            if (a > 0) {
                setA(i, j);
                if (a > 0)
                    setA(i + 1, j);
            } else if (b > 0) {
                setB(i, j);
                if (b > 0)
                    setB(i, j + 1);
            }
        }
    }
    
    if (a > 0 || b > 0)
        return error();
    
    cout << "YES" << endl;
    for (auto s : grid)
        cout << s << endl;
    
    
}



Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//
 
int N;
multiset<int> ss;
int M;
int T[212345];
 
int main() {
	cin >> N;
	REP(i, N) {
		int a;
		scanf("%d", &a);
		ss.insert(a);
	}
	
	cin >> M;
	REP(i, M) scanf("%d", T + i);
	
	bool ans = true;
	REP(i, M) {
		if (ss.empty() || ss.find(T[i]) == ss.end()) {
			ans = false;
			break;
		}
		ss.erase(ss.find(T[i]));
	}
	
	puts(ans ? "YES" : "NO");
	
	return 0;
}

Measured memory_bytes: 10368
h, w = gets.chomp.split(' ').map(&:to_i)
s = []
h.times do
  s << gets.chomp + '.'
end
s << '.' * (w + 1)
 
h.times do |i_h|
  w.times do |i_w|
    next if s[i_h][i_w] == '#'
    n = 0
    (-1..1).each do |j_h|
      (-1..1).each do |j_w|
        n += s[i_h - j_h][i_w - j_w] == '#' ? 1 : 0
      end
    end
    s[i_h][i_w] = n.to_s
  end
end
 
h.times do |i_h|
  puts s[i_h][0...w]
end

Measured memory_bytes: 3836
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			while(sc.hasNext()) {
				int n=sc.nextInt();
				if(n==0) break;
				double[] x=new double[n+1];
				double[] y=new double[n+1];
				for(int i=0; i<n; i++) {
					x[i]=sc.nextDouble();
					y[i]=sc.nextDouble();
				}
				int count=0;
				int max=1;
				for(int i=0; i<n; i++) {
					for(int j=i+1; j<n; j++) {
						double d=Math.sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]));
						
						if(d<=2.0) {
							double cx=(x[i]+x[j])/2.0;//2点の真ん中
							double cy=(y[i]+y[j])/2.0;
							double vx=(y[j]-y[i])/d;//法線ベクトルの単位ベクトル
							double vy=-((x[j]-x[i])/d);
							double e=Math.sqrt(1.0-d*d/4.0);//交点cx,cyから中心までの距離
							
							double px=cx+e*vx;//中心座標(円1) 
							double py=cy+e*vy;
							for(int k=0; k<n; k++) {
								if(k==i || k==j || Math.sqrt((x[k]-px)*(x[k]-px)+(y[k]-py)*(y[k]-py))<=1.0) {
									count++;
								}
							}
							max=Math.max(count, max);
							count=0;
							
							px=cx-e*vx;//(円2)
							py=cy-e*vy;
							for(int k=0; k<n; k++) {
								if(k==i || k==j || Math.sqrt((x[k]-px)*(x[k]-px)+(y[k]-py)*(y[k]-py))<=1.0000) {
									count++;
								}
							}
							max=Math.max(count, max);
							count=0;
						}
						
					}
				}
				System.out.println(max);
			}
		}
	}
}


Measured memory_bytes: 63316
#include <stdio.h>

int main(void)
{
	int n;
	int k;
	int i;
	
	scanf("%d", &n);
	scanf("%d", &k);
	while (k-- > 0){
		int a, b;
		int mini;
		
		scanf("%d %d", &a, &b);
		if (a > (n + 1) / 2) a = n - a + 1;
		if (b > (n + 1) / 2) b = n - b + 1;
		mini = a < b ? a : b;
		printf("%d\n", (mini - 1) % 3 + 1);
	}
	
	return 0;
}

Measured memory_bytes: 596
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().split())
    A = [0] + list(map(int, readline().split()))
    visit = [0]*(N+1)
    nx = 1
    count = 0
    while True:
        now = nx
        nx = A[now]
        count += 1
        if visit[nx] == 0:
            if count == K:
                print(nx)
                break
            else:
                visit[nx] = count
                continue
        else:
            move = (K - visit[nx]) % (count - visit[nx])
            city = visit.index(visit[nx] + move)
            print(city)
            break






if __name__ == '__main__':
    main()

Measured memory_bytes: 29832
#include <bits/stdc++.h> 
using namespace std;
#define ll long long
#define endl "\n"
#define M 1000000007
#define boost
template<class _T>inline void read(_T &_a)
{
    bool f=0; char _c=getchar(); _a=0;
    while(_c<'0'||_c>'9'){ if(_c=='-') f=1; _c=getchar(); }
    while(_c>='0'&&_c<='9'){ _a=(_a<<3)+(_a<<1)-'0'+_c; _c=getchar(); }
    if(f) _a=-_a;
}

ll T;
string s1;
string s2;
int dp[3001][3001];
int lcs(int i,int j)
{
    if(i==0 || j==0)
    return 0;

    if(dp[i][j]!=-1)
    return dp[i][j];

    if(s1[i-1]==s2[j-1])
    {      
        return dp[i][j]=1+lcs(i-1,j-1);
    }

    return dp[i][j]=max(lcs(i-1,j),lcs(i,j-1));
}


int main()
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
   
    cin>>s1;
    cin>>s2;
    string ans;
    memset(dp,-1,sizeof(dp));
   lcs(s1.size(),s2.size());
    int i=s1.size();
    int j=s2.size();
    while(i>0 && j>0)
    {
        if(s1[i-1]==s2[j-1])
        {
              ans.push_back(s1[i-1]);
              i--;
              j--;
        }
        else if(dp[i][j-1]>dp[i-1][j])
        {
            j--;
        }
        else
        {
            i--;
        }
    }
      reverse(ans.begin(),ans.end());
      //ans.erase(0,1);
    cout<<ans<<endl;


return 0;
}

Measured memory_bytes: 39056
#include<cstdio>
using namespace std;
int a[1000005];
int abs1(int x){
	if (x<0) return -x;
	return x;
}
int main(){
	int n;
	scanf("%d",&n);
	a[0]=0;
	for (int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	a[n+1]=0;
	int anss=0;
	for (int i=0; i<=n; i++)
		anss+=abs1(a[i]-a[i+1]);
	for (int i=1; i<=n; i++){
		printf("%d\n",anss-abs1(a[i]-a[i-1])-abs1(a[i+1]-a[i])+abs1(a[i-1]-a[i+1]));
	}
	return 0;
} 

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;
const int MAXN = 100005;

int k;

vector<int> G[MAXN];
ll ans;
int children[MAXN];
bool visited[MAXN];

void dfs(int u) {
  if (visited[u]) return;
  visited[u] = true;
  ll res = k - 1;
  if (u != 0) res--;
  rep(i, children[u]) {
    ans *= res--;
    ans %= mod;
  }
  for (int v: G[u]) {
    dfs(v);
  }
}

int main() {
  int n;
  cin >> n >> k;
  int a, b;
  rep(i, n - 1) {
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }

  children[0] = G[0].size();
  FOR(i, 1, n) children[i] = G[i].size() - 1;

  ans = k;
  dfs(0);

  cout << ans << endl;



  


  
  return 0;
}

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

using namespace std;

int main(){
    char ch;
    int a[26] = {0};
    while ( cin>> ch){
        int num;
        if(isupper(ch)){
            ch = tolower(ch);
            
        }
        num = ch - 'a';
        a[num]++;
        
    }
    for(int i=0; i<26; i++){
        ch = 'a' + i;
        cout << ch << " : "<<a[i]<< endl;
        
    }
    return 0;
}



Measured memory_bytes: 3088
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	A, B, C, K := nextInt(), nextInt(), nextInt(), nextInt()
	xa := MinOf(A, K)
	K -= xa
	xb := MinOf(B, K)
	K -= xb
	xc := MinOf(C, K)
	fmt.Println(xa - xc)
}

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define cc(a) cout << a << endl;
#define msg(a,b) cout << a << " : " << b << endl;
#define msg2(a,b,c) cout << a << " : " << b << " : " << c << endl;
#define msg3(a,b,c,d) cout << a << " : " << b << " : " << c << " : " << d << endl;

string makeString(long long int n){
    stringstream ss;
    string str;
    ss << n;
    ss >> str;
    if(str.size() == 1){
        return "00000" + str;
    }else if(str.size() == 2){
        return "0000" + str;
    }else if(str.size() == 3){
        return "000" + str;
    }else if(str.size() == 4){
        return "00" + str;
    }else if(str.size() ==5){
        return "0" + str;
    }else if(str.size() == 6){
        return str;
    }

}

int main(){
    long long int n,m,a,b;
    string ans;
    vector< pair<long long int , long long int> > vec2;
    vector<long long int> vec[100004];
    map<pair<long long int, long long int> , string> mp;
    cin >> n >> m;
    while(m--){
        cin >> a >> b;
        vec[a].push_back(b);
        vec2.push_back(make_pair(a,b));
    }
    for(int i=0;i<=n;i++){
        sort(vec[i].begin(),vec[i].end());
    }
    for(int i=1;i<=n;i++){
        for(int j =0;j<vec[i].size();j++){
            ans = makeString(i) + makeString(j+1);
            mp[ make_pair(i, vec[i][j]) ] = ans;
        }
    }
    for(int i=0;i<vec2.size();i++){
        cout << mp[ make_pair( vec2[i].first, vec2[i].second ) ] << endl;
    }

    return 0;
}


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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
	    cin>>a[i];
	}
	long dp[n];
	dp[0]=0;
	dp[1]=abs(a[0]-a[1]);
	for(int i=2;i<n;i++){
	    int opt1=abs(a[i]-a[i-1])+dp[i-1];
	    int opt2=abs(a[i]-a[i-2])+dp[i-2];
	    dp[i]=min(opt1,opt2);
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 4736
#include <cstdio>
#include <string>
#include <map>
#include <cmath>
#include <complex>
#include <vector>
using namespace std;

#define EPS 1e-8
typedef complex<double> P;

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}

double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}


bool intersectSS(const L &s, const L &t) 
{		
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

bool isequal(P a, P b)
{
	return (fabs(a.real()-b.real()) < EPS && fabs(a.imag()-b.imag()) < EPS);
}

bool isOnePoint(const L &l, const L &m) 
{
	bool xp=false;
	for(int i=0; i<2; i++)
	for(int j=0; j<2; j++)
	{
		if(isequal(l[i],m[j])) xp=true;
	}
	if(!xp) return false;
	for(int i=0; i<2; i++)
	for(int j=0; j<2; j++)
	{
		if(isequal(l[i], m[j]))
		{
			if(!intersectSP(l, m[(j+1)%2])&&!intersectSP(m,l[(i+1)%2])) return true;
			else return false;
		}
	}
	
	return false;
}

typedef vector<L> Terr;
typedef vector<Terr> Cont;
typedef vector<int> Adj;

bool isAdj(Cont& a, Cont& b)
{
	for(int i=0; i<a.size(); i++)
	for(int j=0; j<b.size(); j++)
	{
		for(int k=0; k<a[i].size(); k++)
		for(int l=0; l<b[j].size(); l++)
		{
			if(intersectSS(a[i][k],b[j][l]))
			{
				if(!isOnePoint(a[i][k], b[j][l])) return true;
			}
		}
	}
	
	return false;
}

int cr[10];
Cont cont[10];
Adj adj[10];

bool isconf(int p)
{
	for(int i=0; i<adj[p].size(); i++)
	{
		if(cr[adj[p][i]]==cr[p]) return true;
	}
	
	return false;
}

bool paint(int p, int c, int cnt)
{
	if(p==cnt) return true;
	
	for(int i=1; i<=c; i++)
	{
		cr[p]=i;
		if(!isconf(p)) if(paint(p+1, c, cnt)) return true;
		cr[p]=0;
	}
	
	return false;
}

int main()
{
	int N;
	while(scanf("%d", &N) , N)
	{
		for(int i=0; i<10; i++)
		{
			cont[i].clear();
			adj[i].clear();
			cr[i]=0;
		}
		
		int cnt=0;
		map<string, int> d;
		while(N--)
		{
			int id;
			char n[15];
			scanf("%s", n);
			map<string, int>::iterator it=d.find(string(n));
			if(it != d.end())
			{
				id=it->second;
			}
			else
			{
				id=cnt;
				d.insert(make_pair(string(n), cnt));
				cnt++;
			}
			int x,y;
			Terr t;
			vector<P> pt;
			while(scanf("%d", &x), x!=-1)
			{
				scanf("%d", &y);
				pt.push_back(P(x,y));
			}
			
			for(int i=0; i<pt.size(); i++)
				t.push_back(L(pt[i], pt[(i+1)%pt.size()]));
				
			cont[id].push_back(t);
		}
		
		for(int i=0; i<cnt; i++)
		for(int j=i+1; j<cnt; j++)
		{
			if(isAdj(cont[i], cont[j]))
			{
				adj[i].push_back(j);
				adj[j].push_back(i);
			}
		}
		
		for(int i=1; ; i++)
		{
			if(paint(0, i, cnt))
			{
				printf("%d\n", i);
				break;
			}
		}
	}
}

Measured memory_bytes: 912
N=int(input())
S=str(input())
T=str(input())
mod=10**9+7
answer=1
if S[0]==T[0]:
  answer=3
else:
  answer=6
for i in range(1,N):
  if S[i]==T[i]:
    if S[i-1]==T[i-1]:
      answer=(answer*2)%mod
  else:
    if not S[i]==S[i-1]:
      if S[i-1]==T[i-1]:
        answer=(answer*2)%mod
      else:
        answer=(answer*3)%mod
print(answer)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <queue>
#include <set>

using namespace std;

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

const LL inf = 1000000000000000;
const LL mod = 1000000007;

int main()
{
	LL m1, m2, d1, d2;
	cin >> m1 >> d1 >> m2 >> d2;

	if (m2 == m1+1) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}

}

Measured memory_bytes: 256
/*	
	Over ice, I'm freezing
	Beautiful eyes, deceiving
	We may die this evening
	Coughing, wheezing, bleeding...
*/	
#include <bits/stdc++.h>
using namespace std;

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

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define mp make_pair

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=2e3+10, maxm=2e3+10, lg=18, mod=1e9+7, inf=1e18;

ll n,dp[3*maxn][maxn],M;

void add(ll &x,ll y){
	x+=y;
	if(x>=M) x-=M;
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin>>n>>M;
	dp[0][0]=1;
	for(int i=0;i<3*n;i++)for(int j=0;j<=n;j++){
		add(dp[i+1][j],dp[i][j]);
		add(dp[i+2][j+1],dp[i][j]*(i+1)%M);
		add(dp[i+3][j+1],dp[i][j]*(i+1)%M*(i+2)%M);
	}
	ll ans=0; for(int i=0;i<=n;i++) ans+=dp[3*n][i];
	cout<<ans%M;
	
	return 0;
}




Measured memory_bytes: 97840
S = input()
S = list(S)
S.reverse()
T = []
n = len(S)
for i in range(n):
  T.append(S[i])
  mojiretu = ''.join(T)
  m = len(mojiretu)
  if mojiretu == "maerd" or mojiretu == "remaerd" or mojiretu == "esare" or mojiretu == "resare":
    T =[]
  elif m==8:
      break
N = len(T)
if N == 0:
  print("YES")
else:
  print("NO")


Measured memory_bytes: 3956
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <intrin.h>
//#include <chrono>
//#include <random>
//#include <unordered_map>

using namespace std;

typedef long long ll;

void solve() {
	char a;
	cin >> a;
	if (isupper(a))
		cout << "A";
	else
		cout << 'a';
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 3648
from collections import deque
from operator import itemgetter


n = int(input())
a = list(map(int, input().split()))

ans = [-1] * (n**2)
for i in range(n):
    ans[a[i] - 1] = i + 1

a_ind = [(j, a[j]) for j in range(n)]
a_ind = sorted(a_ind, key = itemgetter(1))
pos = 0
for j, _ in a_ind:
    k = j
    while True:
        if j == 0:
            break
        if ans[pos] != -1:
            pos += 1
        else:
            ans[pos] = k + 1
            pos += 1
            j -= 1

used = [False] * n
q = deque([])
cnt = [0] * n
for i in range(n**2):
    if ans[i] != -1:
        cnt[ans[i] - 1] += 1
        if cnt[ans[i] - 1] == ans[i]:
            for _ in range(n - ans[i]):
                q.append(ans[i])
            used[ans[i] - 1] = True
    else:
        if not q:
            print("No")
            exit()
        else:
            tmp = q.pop()
            ans[i] = tmp
      
cnt = [0] * n
for i in range(n**2):
    cnt[ans[i] - 1] += 1
    if cnt[ans[i] - 1] == ans[i]:
        if a[ans[i] - 1] != i + 1:
            print("No")
            exit()
print("Yes")
print(*ans)

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

int main() {
  int n;
  cin >> n;
  int W = 0;
  vector<int> w(n);
  for(int i=0; i<n; i++) {
    cin >> w.at(i);
    W += w.at(i);
  }
  
  int s = 0;
  int S = 0;
  
  for(int i=0; i<n; i++) {
    S += w.at(i);
    if(2 * S >= W) {
      s = S - w.at(i);
      cout << min(2*S-W, W-2*s) << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int n,i,a[100];
void dfs(int dep,int now)
{
	if (dep==n+1){
		for (i=1;i<=n;i++) printf("%c",a[i]+'a'-1);
		puts("");return;
	}
	for (int ii=1;ii<now;ii++){
		a[dep]=ii;dfs(dep+1,now);
	}a[dep]=now;dfs(dep+1,now+1);
}
int main()
{
	scanf("%d",&n);
	dfs(1,1);
	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<string.h>
int main(void){
  int i,len,count=0;
  char str1[210000];
  char str2[210000];
  
  scanf("%s",str1);
  scanf("%s",str2);
  
  len=strlen(str1);
  
  for(i=0;i<len;i++){
    if(str1[i]!=str2[i]){
      count++;
    }
  }
  printf("%d",count);
  return 0;
}

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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N, ll K, std::vector<ll> A) {
  sort(all(A));

  ll l = 0, r = 1e9;
  while (r - l > 1) {
    int x = (l + r) / 2;
    auto f = [&](int x) {
      ll now = 0;
      rep(i, N) now += (A.at(i) - 1) / x;
      return now <= K;
    };
    if (f(x))
      r = x;
    else
      l = x;
  }

  cout << r << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  ll K;
  scanf("%lld", &K);
  std::vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, K, std::move(A));
  return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define INF 10000000001
#define DIM 200001
#define mod 1000000007
#define PI 3.1415926535897932384626433
#define se second
#define fi first
#define pb push_back
#define T true
#define F false
#define endl "\n"
typedef char ch;
typedef bool boll;
typedef string st;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef set < string > sst;
typedef set < long long > sl;
typedef queue < long long > que;
typedef vector < long long > vec;
typedef map < long long, long long > mll;
typedef pair < long long, long long > pll;
typedef vector < pair < long long, long long > > vpl;
typedef pair < long long, unsigned long long > pul;
ll t,n,s,k;
ld a[200001],b[200001],x,z;
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>x;
        z=(x*(x+1))/2;
        a[i]=z/x;
    }
    for(int i=1;i<=n;i++)b[i]=b[i-1]+a[i];
    ld ss=-1;
    for(int i=k;i<=n;i++)
      ss=max(ss,b[i]-b[i-k]);
    cout<<fixed<<setprecision(10)<<ss<<endl;

}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }





int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    
    vector<int> rec(n);
    rec[0] = 1;
    int ans = 1;
    rep3(i, 1, n) {
        if (v[i] <= v[i - 1]) { rec[i] = rec[i - 1] + 1; chmax(ans, rec[i]); }
        else rec[i] = 1;
    }
    cout << ans - 1 << endl;
    // rep(i, n) cout << rec[i] << " "; cout << endl;
    
}


Measured memory_bytes: 1024
n = int(input())
d = sorted(list(map(int, input().split())))
l = []
r = []
for elm in d:
  if len(l) < n / 2 or l[-1] == elm:
    l.append(elm)
  else:
    r.append(elm)

if len(l) != len(r):
  print(0)
else:
  ans = r[0] - l[-1]
  print(ans)


Measured memory_bytes: 14008
import java.util.*;

public class Main
{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int[][] countSum = new int[10][101];

	countSumFunc(0, 0, 0, countSum);
	while(sc.hasNext()){
	    int n = sc.nextInt();
	    int s = sc.nextInt();

	    if(n == 0 && s == 0){
		break;
	    }

	    System.out.println(String.valueOf(countSum[n][s]));
	}
    }

    private static void countSumFunc(int p, int num, int sum, int[][] countSum){
	if(p == 10 || sum > 100) return;
	++countSum[p][sum];

	for(int i = num; i < 10; ++i){
	    countSumFunc(p+1, i+1, sum+i, countSum);
	}
    }
}

Measured memory_bytes: 15380
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MOD (ll)1000000007

ll a[200001], sum[200001];

int main(void)
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", &a[i]);
		sum[i] = (a[i] + sum[i - 1]) % MOD;
	}

	ll ans = 0;
	for (int i = n; i >= 1; i--)
		ans = (ans + a[i] * sum[i - 1]) % MOD;
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 4832
N, M = map(int, input().split())

# 繋がってるスイッチの情報
S = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))

# print(S)
# print(P)

ans = 0

for i in range(1 << N):
    # print(i)
    for m in range(M):
        cnt = 0
        for s in S[m]:  # Sは繋がっているスイッチの情報
            if i & (1 << (s-1)) != 0:
                cnt += 1
        if cnt % 2 != P[m]:
            break
    else:
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <vector>
#include <numeric>
#include <algorithm>
#include <functional>
#include <math.h>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

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

  vi a(n);
  vi b(n);

  for (int i=0;i<n;++i) {
    scanf("%d %d", &a[i], &b[i]);
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  if (n % 2 == 1) {
    int index = (n + 1) / 2 - 1;
    printf("%d", b[index] - a[index] + 1);
    return 0;
  }

  int min_first = a[n / 2 - 1];
  int max_first = b[n / 2 - 1];
  int min_second = a[n / 2];
  int max_second = b[n / 2];

  //printf("%d %d %d %d\n", min_first, max_first, min_second, max_second);

  int len_first = max_first - min_first + 1;
  int len_second = max_second - min_second;

  //printf("%d %d\n", len_first, len_second);

  printf("%d", len_first + len_second); 




  return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  string s;
  cin>>s;
  s[0]='2';s[1]='0';s[2]='1';s[3]='8';
  cout<<s<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int n;
	cin >> n;
	int num;
	string ans = "No\n";
	rep(i,3){
		num = n%10;
		n /= 10;
		if(num == 7){
			ans = "Yes\n";
			break;
		}
	}
	cout << ans ;

	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
ll n, t, a;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  t = a = 1;
  FOR(i, 0, n){
    ll _t, _a;
    cin >> _t >> _a;
    if(((t-1)/_t+1)*_a >= a){
      t = ((t-1)/_t+1)*_t;
      a = (t/_t)*_a;
    }else{
      a = ((a-1)/_a+1)*_a;
      t = (a/_a)*_t;
    }
  }
  cout << a+t << endl;
  return 0;
}

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

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = scanner.nextInt();
        }
        int ans = 0;
        for (int i = 0; i < n - 2; i++) {
            int[] b = new int[]{a[i], a[i+1], a[i+2]};
            Arrays.sort(b);
            if (b[1] == a[i+1]) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


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

using namespace std;

const int INF = 1e9;
int dp[30][30];
int n, m, s, g, V, P;

void warshallFloyd() {
    for (int k = 0; k < n; k++)
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
}

int main(void) {
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            if (i == j) dp[i][j] = 0;
            else dp[i][j] = INF;
        }

    int a, b, c, d;
    for (int i = 0; i < m; i++) {
        scanf("%d,%d,%d,%d", &a, &b, &c, &d);
        dp[a - 1][b - 1] = c;
        dp[b - 1][a - 1] = d;
    }
    scanf("%d,%d,%d,%d", &s, &g, &V, &P);

    warshallFloyd();

    cout << V - P - dp[s - 1][g - 1] - dp[g - 1][s - 1] << endl;
        
    return 0;
}


Measured memory_bytes: 3104
from functools import reduce
import math

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    factor = []
    f = math.factorial(N)
    dict = {}
    ans = 1
    for num in range(2,1000):
        while f % num == 0:
            f //= num
            factor.append(num)
            if num in dict:
                dict[num] += 1
            else:
                dict[num] = 1
    for v in dict.values():
        ans *= v + 1

    print(ans % (10**9 + 7))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <stdio.h>


int main(void){
    long long h, w, ans;
    scanf("%lld %lld", &h, &w);
    ans = 0;
    ans += h * w / 2;
    if(h * w % 2 == 1){
        ans++;
    }
    if(h == 1 || w == 1){
        printf("1\n");
    }
    else{
        printf("%lld\n", ans);
    }


    return 0;
}

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

using namespace std;

typedef struct n
{
    int z;
    char c;
}c;

bool com(c a,c b){

    if(a.z>=b.z)return true;
    else return false;

}
int main()
{
    c ar[3];
    cin>>ar[0].z>>ar[1].z>>ar[2].z;
    ar[0].c='A';
    ar[1].c='B';
    ar[2].c='C';
    sort(ar,ar+3,com);
    cout<<ar[0].c<<endl;
    return 0;
}



Measured memory_bytes: 3120