akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")
#define pb(s) push_back(s)
#define SZ(x) ((int)(x).size())

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    ll a; cin >> a;
    string s; cin >> s;

    if(a>=3200){
      p(s);
    }else{
      p("red");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    ll n;
    cin>>n;
    cout<<n*(n-1)/2<<endl;
}


Measured memory_bytes: 256
//12;03
import java.util.Scanner;

public class Main {

	private static Scanner in;
	private static int n;
	private static int[] a;
	private static int k;
	private static int[] dp;
	private static final int MOD = (int)1e9+7;
	
	public static void main(String[] args) {
		in = new Scanner(System.in);
		n = in.nextInt();
		k = in.nextInt();
		a = new int[n];
		for(int i=0; i<n; i++) a[i] = in.nextInt();
		dp = new int[k+1];
		dp[0] = 1;
		
		for(int i=n-1; i>=0; i--) {
			int[] pre = new int[k+1];
			pre[0] = dp[0];
			for(int j=1; j<k+1; j++) {
				pre[j] = (pre[j-1]+dp[j])%MOD;
			}
			
			for(int kLeft=k; kLeft>=0; kLeft--) {
				// dp[kLeft] is the sum of dp[kLeft] to dp[kLeft-a[i]]
				dp[kLeft] = ((pre[kLeft]-(kLeft-a[i]-1>=0?pre[kLeft-a[i]-1]:0))%MOD+MOD)%MOD;
			}
		}
		System.out.println(dp[k]);
		
	}

}


Measured memory_bytes: 44884
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const ll INF = LLONG_MAX / 3;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	ll n; cin >> n;
	vi a(n); REP(i, n) cin >> a[i];
	ll lb = 0, ub = INF;
	while (ub - lb > 1)
	{
		ll mid = (ub + lb) / 2;
		bool ok = false, f = true;
		int div0, div1, div2;
		div0 = 0;
		int p = 0;
		ll tmpa = 0;
		while (tmpa < mid)
		{
			tmpa += a[p];
			p++;
			if (p == n)
			{
				f = false;
				break;
			}
		}
		ll tmpb = 0;
		if (f)
		{
			div1 = p;
			while (tmpb < mid)
			{
				tmpb += a[p];
				p++;
				if (p == n)
				{ 
					f = false;
					break;
				}
			}
		}
		div2 = p;
		ll tmpc = 0;
		FOR(i, p, n) tmpc += a[i];
		while (f)
		{
			if (tmpa >= mid && tmpb >= mid && tmpc >= mid)
			{
				ok = true;
				break;
			}
			if (div2 == n) break;
			tmpa -= a[div0];
			tmpc += a[div0];
			div0++;
			while (tmpa < mid)
			{
				tmpa += a[div1];
				tmpb -= a[div1];
				div1++;
				if (div1 == div2)
				{
					f = false;
					break;
				}
			}
			while (tmpb < mid)
			{
				if (div2 == n) break;
				tmpb += a[div2];
				tmpc -= a[div2];
				div2++;
				if (div2 == div0)
				{
					f = false;
					break;
				}
			}
		}
		if (ok) lb = mid;
		else ub = mid;
	}
	cout << lb << endl;
	return 0;
}

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

using ll = long long;
#define repi(n) for (int i = 0; i < n; i++)
#define repj(n) for (int j = 0; j < n; j++)
#define repk(n) for (int k = 0; j < n; k++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (auto i = a; i < b; i++)
#define repv(itr) for (auto&& v : itr)
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T countmod(T a, T b, T diviser, T mod = 0) {
  a += (mod - (a % diviser) + diviser) % diviser;
  return max(0, (b - a + diviser - 1) / diviser);
}

int re[100010];
int main() {
  string s;
  cin >> s;
  s += "R";
  int n = s.length();
  int lastS = 0;
  repi(n) {
    if (s[i - 1] == 'R' && s[i] == 'L') {
      // [lastS,i)がR
      re[i - 1] += countmod(lastS, i, 2, i % 2 + 1);
      re[i] += countmod(lastS, i, 2, i % 2);
      lastS = i;
    } else if (s[i - 1] == 'L' && s[i] == 'R') {
      // [lastS,i)がL
      re[lastS - 1] += countmod(lastS, i, 2, lastS % 2 + 1);
      re[lastS] += countmod(lastS, i, 2, lastS % 2);
      lastS = i;
    }
  }
  cout << re[0];
  repr(i, 1, n - 1) cout << " " << re[i];
}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int,input().split()))
abs_min = float("inf")
ans = 0
cnt = 0
for i in range(N):
	if A[i] < 0:
		cnt += 1
	tmp = abs(A[i])
	abs_min = min(abs_min, tmp)
	ans += tmp

if cnt % 2 == 0:
	print(ans)
else:
	print(ans - 2*abs_min)



Measured memory_bytes: 14412
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
typedef pair<int, int> P;
P A[100004];

int main() {
  INCANT;
  cin >> N;
  int a,b;
  rep(i, N) {
    cin >> a >> b;
    A[i]=P(a,b);
  }
  sort(A, A+N, greater<P>());
  cout << A[0].first+A[0].second << endl;
  return 0;
}

Measured memory_bytes: 4388
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
ll mygcd(ll a,ll b){
	if(b==0ll)return a;
	return mygcd(b,a%b);
}
int N;
ll A[100100];
vector<ll> ps;
int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> A[i];
		if(A[i]!=1ll)ps.pb(A[i]);
	}
	for(ll i=2;i*i<=1000000000ll;i++){
		for(int j=0;j<N;j++){
			if(A[j]%i==0ll){
				ps.pb(i);
				break;
			}
		}
	}
	sort(ps.begin(),ps.end());
	ps.erase(unique(ps.begin(),ps.end()),ps.end());
	ll ans = 0ll;
	for(int i=0;i<ps.size();i++){
		ll sum = 0ll;
		for(int j=0;j<N;j++){
			if(A[j]%ps[i]==0ll)sum += A[j];
		}
		ans = max(ans,sum);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3208
def selectionSort(A, N):
    swap = 0

    for i in range(N):
        minj = i

        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j

        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            swap += 1

    print(" ".join(list(map(str, A))))
    print(swap)

def main():
    N = int(input())
    A = [int(i) for i in input().split()]

    selectionSort(A, N)

main()




Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define double long double
#define ll long long
#define INF LLONG_MAX/3
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
#define ggr getchar();getchar();return 0
using namespace std;
signed main(){
	int n,a,ma=0;
	cin>>n;
	int ans=0;
	rep(i,n){
		cin>>a;
		if(a>=ma)ans++;
		ma=max(ma,a);
	}
	cout<<ans<<endl;
	ggr;
}

Measured memory_bytes: 256
import sys,math,collections,itertools,copy
input = sys.stdin.readline

N=int(input())
D=list(map(int,input().split()))
time_list = [0]*13
time_list[0] = 1 #-高橋君-#
#-時差の精査 同じ時差が3つあれば0-#
for d in D:
    time_list[d] += 1
    if time_list[d]>=3:
        print(0)
        exit()

#- 時差が2種類あるものから先に置いていく -#
time24list=[]
singlelist=[]
for jisa,cnt in enumerate(time_list):
    if cnt == 0:
        continue
    elif cnt==2:
        time24list.append(jisa)
        time24list.append(24-jisa)
    elif jisa ==0 or jisa == 12:
        time24list.append(jisa)
    else:
        singlelist.append(jisa)

#- singleリストを全探索 -#
lst = len(singlelist)
bit = 2**lst
ans = 0
for bi in range(bit):
    tmp = copy.deepcopy(time24list)
    min_jisa = 12 
    for j in range(lst):
        if bi>>j & 1:
            tmp.append(singlelist[j])
        else:
            tmp.append(24-singlelist[j])
    tmp.sort()
    tmp.append(24)
    for i in range(len(tmp)-1):
        dtime = tmp[i+1]-tmp[i]
        min_jisa = min(dtime,min_jisa)
    ans = max(ans,min_jisa)
print(ans)


Measured memory_bytes: 9612
import math

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

    n_list=[0 for i in range(N)]

    for i in range(1,N):
        counter=1
        while counter*i<=N-1:
            n_list[counter*i]+=1
            counter+=1
    res=sum(n_list)
    print(res)
if __name__=="__main__":
    main()

Measured memory_bytes: 147608
def check(bc,hw)
  if hw == $h + $w
    return
  elsif hw == $h
    $d = $c.map{|e| e.chars}.transpose.map{|e| e.join("")}
  end
  if hw < $h
    cc = $c[hw].count('#')
  else
    cc = $d[hw-$h].count('#')
  end
  if bc - cc >= $k
    if bc - cc == $k
      $ans += 1
    end
    if hw < $h
      $c[hw].tr!('#','*')
    else
      $d[hw-$h].tr!('#','&')
    end
    check(bc-cc,hw+1)
    if hw < $h
      $c[hw].tr!('*','#')
    else
      $d[hw-$h].tr!('&','#')
    end
  end
  check(bc,hw+1)
end

$h, $w, $k = gets.strip.split.map(&:to_i)
$c = []
bmax = 0
$h.times do
  t = gets.strip
  $c.push t
  bmax += t.count('#')
end

if bmax == $k
  $ans = 1
else
  $ans = 0
end
if bmax >= $k
  check(bmax,0)
end
p $ans


Measured memory_bytes: 14324
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

inline ld dist(ld &x1, ld &y1, ld &x2, ld &y2)
{
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

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

  int n;
  cin >> n;
  set<int> st;
  rep(i, n)
  {
    int a;
    cin >> a;
    if (!st.count(a))
    {
      st.insert(a);
    }
    else
    {
      st.erase(a);
    }
  }
  cout << st.size() << endl;
  return 0;
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int height[(int)1e5 + 5], N, k, diff = INF;

int main(){
  FAST_IO

  cin >> N >> k;
  for(int rep = 0; rep < N; ++rep) cin >> height[rep];
  sort(height, height + N);

  for(int idx = k - 1; idx < N; ++idx){
    min_self(diff, height[idx] - height[idx - k + 1]);
  }

  cout << diff << '\n';
  return 0;
}


Measured memory_bytes: 640
N = int(input())
A = [int(i) for i in input().split(" ")]
B = [int(i) for i in input().split(" ")]

point = 0
i = 0
while (i < N):
  if A[i] >= B[i]:
    point += B[i]
  else:
    if(A[i] + A[i+1]) > B[i]:
      point += B[i]
      A[i+1] -= (B[i] - A[i])
    else:
      point += (A[i] + A[i+1])
      A[i+1] = 0
  i += 1
print(point)


Measured memory_bytes: 19156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool p(char x[110])
{
    int len=strlen(x);
    for(int i=0;i<=len/2;i++)
        if(x[i]!=x[len-i-1])
        return false;
    return true;
}
char a[110],b[110],c[110];
int main()
{
    cin>>a;
    int n=strlen(a);
    for(int i=0;i<(n-1)/2;i++)
    b[i]=a[i];
    int l=0;
    for(int i=(n+3)/2-1;i<n;i++)
    c[l++]=a[i];
    if(p(a)&&p(b)&&p(c))
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
count = 0
ans = 0
for i in range(1, N):
  for j in range(i):
    if H[j] <= H[i]:
      count += 1
  if count == i:
    ans += 1
  count = 0
print(ans+1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int N, M; 
int par[200010]; 
int depth[200010]; 
int siz[200010];  
void init(){
	for(int i = 0; i < N; i++){
		par[i] = i; depth[i] = 0; siz[i] = 1; 
	}
}
int find(int x){
	if(par[x] == x) return x;
	else return par[x] = find(par[x]); 
}
void unite(int x, int y){
	x = find(x); 
	y = find(y); 
	if(x == y) return;
	else if(depth[x] < depth[y]){
		par[x] = y; 
		siz[y] += siz[x]; 
	}else{
		par[y] = x; 
		siz[x] += siz[y];  
		if(depth[x] == depth[y]) depth[x] ++; 
	}
}
bool same(int x, int y){
	return find(x) == find(y); 
}
int sz(int x){
	return siz[find(x)]; 
}
int main(){
	cin >> N >> M; init(); 
	for(int i = 0; i < M; i++){
		int a, b; cin >> a >> b; 
		a--; b--; 
		unite(a, b); 
	}
	int ans = 0; 
	for(int i = 0; i < N; i++){
		ans = max(ans, sz(i)); 
	}
	cout << ans << "\n"; 
}

Measured memory_bytes: 5960
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import qualified Data.IntMap as I
import qualified Data.Map as M
 
main = do
    s <- getLine
    k <- readLn
    putStrLn $ solve s k
 
solve :: String -> Int -> String
solve s k = (sort (allsub k s)) !! (k-1)
 
allsub :: Int -> String -> [String]
allsub k str = concat $ map (subuniq str) [1..k]
 
subuniq :: String -> Int -> [String]
subuniq str w = nub $ subs str w
 
subs :: String -> Int -> [String]
subs str w | length str < w = []
           | otherwise = (take w str) : subs (tail str) w

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

int main(void){
  int A, B, C;
  cin >> A >> B >> C;
  int sum = A + B + C;
  if(A * 2 == sum || B * 2 == sum || C * 2 == sum){
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:

    Int rec(Int n) {
        if (n <= 0) return 0;
        if (n == 1) return 1;
        Int ret = rec(n / 2) * 2 + 1;
        return ret;
    }

    void solve() {
        Int H;

        cin >> H;
        Int ans = rec(H);
        cout << ans << endl;

    }

};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

string  n;

int main(){

    cin >> n;

    int f = 0;
    rep(i,1,sz(n)){
        if(f == 0){
            if(n[i] != '9'){
                n[i-1] = '0'+((n[i-1]-'0')-1);
                n[i] = '9';
                f = 1;
            }
        }else{
            n[i] = '9';
        }
    }
    
    //P(n);
    
    ll ans = 0;
	rep(i,0,sz(n))ans+= (int)(n[i]-'0');
	P(ans);
	return  0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	int ans = 0, M = 0;
	for (int i = 0; i < n; ++ i) {
		int x;
		scanf("%d", &x);
		ans = __gcd(ans, x);
		M = max(M, x);
	}
	puts(m % ans == 0 && m <= M? "POSSIBLE" : "IMPOSSIBLE");
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	
        Scanner sc = new Scanner(System.in);
        double x1, y1, x2, y2, d;
        
        x1 = sc.nextDouble();
        y1 = sc.nextDouble();
        x2 = sc.nextDouble();
        y2 = sc.nextDouble();
        
        d = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
        d = Math.sqrt(d);
        
        System.out.println(d);
        
    }
}


Measured memory_bytes: 27968
#include<iostream>


using namespace std;


int main(){
	int a=0,b=0,c,i;

	while(cin >> a >> b){
		i=1;
		c = a+b;
	
		while(c>=10){
			c = c/10;
			i++;
		}
	cout << i << endl;

	}
}

Measured memory_bytes: 1160
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() 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 gcd(x, y int) int {
	if x == 0 {
		return y
	} else if y == 0 {
		return x
	}

	r := x % y
	for r > 0 {
		x, y = y, r
		r = x % y
	}

	return y
}

func main() {
	sc.Split(bufio.ScanWords)

	N := nextInt()
	var A []int
	for i := 0; i < N; i++ {
		A = append(A, nextInt())
	}

	var l, r = make([]int, N+1), make([]int, N+1)
	for i := 0; i < N; i++ {
		l[i+1] = gcd(l[i], A[i])
	}
	for i := N-1; i >= 0; i-- {
		r[i] = gcd(r[i+1], A[i])
	}
	
	max := 0
	for i := 0; i < N; i++ {
		g := gcd(l[i], r[i+1])
		if max < g {
			max = g
 		}
	}

	fmt.Println(max)
}


Measured memory_bytes: 7424
#!/usr/bin/perl

my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);

my $s = 0;
for(my $i=1;$i<=$n;$i++){
  next if( ( $i % 3 == 0 ) || ( $i % 5 == 0 ) ) ;
  $s += $i;
}
print "$s\n";


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

int main()
{
    int A, B, C, X, Y;

    cin >> A >> B >> C >> X >> Y;
    int ans = 0;
    
    if (C * 2 < A + B) {
        int i = min(X,Y);
        ans += i*C*2;
        X -= i;
        Y -= i;
    }
    if (C * 2 < A) A = C*2;
    if (C * 2 < B) B = C*2;
    ans += A * X + B * Y;
    cout << ans << endl;
}

Measured memory_bytes: 256
S = input()
T = input()

lens = len(S)
lent = len(T)

cur_ans = 999999999999

for i in range(lens - lent + 1):
    local_ans = 0
    for j in range(lent):
        if T[j] != S[i+j]:
            local_ans += 1
    
    cur_ans = min(cur_ans, local_ans)

print(cur_ans)

Measured memory_bytes: 9108
#include<bits/stdc++.h>
using namespace std ; 
# define pb push_back
# define ll long long
# define mp make_pair 
# define endl "\n"
# define vi vector<int>
# define vc vector<char>
# define vll vector<ll> 
# define pi pair<int,int> 
const int MOD = 1e9 + 7 ; 
const ll inf = 1e18 ; 



int main() {
	int n ; 
	cin >> n ; 
	vll a(n) ; 
	for(int i = 0 ; i < n ; ++i)
		cin >> a[i] ;
	ll ans = 1000LL ; 
	//int max_so_far = 0 ; 
	for(int i = 1 ; i < n ; ++i) {
		if(a[i] >= a[i-1]) {
			//ans %= a[i-1] ; 
			ll tmp = ans / a[i-1] ; 
			ans %= a[i-1] ; 
			ans += (ll)tmp*a[i] ; 
		}
		//cout << ans << endl ; 
	}
	cout << ans ; 
	return 0; 
}


Measured memory_bytes: 3628
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, K) = read!(usize, i64);
    let mut A = read![[i64]];
    let mut F = read![[i64]];

    A.sort();
    F.sort();
    F.reverse();

    let mut M = 0;
    for i in 0..N {
        M += A[i] * F[i];
    }

    let m = {
        let mut l = -1; // ng
        let mut r = M + 1; // ok

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

            let mut k = 0;
            let mut ok = true;

            for i in 0..N {
                k += max(0, A[i] - m / F[i]);

                if k > K {
                    ok = false;
                    break;
                }
            }

            if ok {
                r = m;
            } else {
                l = m;
            }
        }

        r
    };

    println!("{}", m);
}


Measured memory_bytes: 12800
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: u128 = sc.cin();
    let mut ans: u128 = 0;
    for k in 1..=n {
        let mut p = 0;
        loop {
            p += k;
            if p > n {
                break;
            }
            ans += p;
        }
    }
    put!(ans);
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 2172
#!/usr/bin/env python3
from collections import deque

def main():
    N, M = map(int, input().split())
    adj = [[] for _ in range(N)]
    for i in range(M):
        a, b = map(int, input().split())
        adj[a-1].append(b-1)
        adj[b-1].append(a-1)

    queue = deque([0])
    visit = [-1] * N
    visit[0] = 0# 部屋1の親はないので

    while queue:
        now = queue.popleft()
        for u in adj[now]:
            if visit[u] < 0:
                queue.append(u)
                visit[u] = now
    if -1 in visit:
        print('No')
    else:
        print('Yes')
        [print(v+1) for v in visit[1:]]

if __name__ == "__main__":
    main()


Measured memory_bytes: 35764
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

# A, B, C = LI()
# K = int(input())

# for k in range(K):
#     if A < B:
#         C *= 2
#     else:
#         B *= 2

# if A < B and B < C:
#     print("Yes")
# else:
#     print("No")
A, B, C = LI()
K = int(input())

for k in range(K):
    if A >= B:
        B *= 2
    else:
        C *= 2

if A < B < C:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 10760
#include<stdio.h>
int main()
{
    int a,b,c,h,m,s;
    scanf("%d",&a);
    {
       h=a/3600;
       b=a%3600;
       m=b/60;
       s=b%60;

    }
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
int h, w, k;
char a[10][10];
int r[10], c[10];
int main()
{
	scanf("%d%d%d", &h, &w, &k);
	int sum = 0;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			scanf(" %c", &a[i][j]);
			if (a[i][j] == '#') sum++;
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (a[i][j] == '#') r[i]++;
		}
	}
	for (int i = 1; i <= w; i++) {
		for (int j = 1; j <= h; j++) {
			if (a[j][i] == '#') c[i]++;
		}
	}
	long long ans = 0;
	for (int i = 0; i < (1<<h); i++) {
		for (int j = 0; j < (1<<w); j++) {
			bitset<8> b1(i), b2(j);
			int tmp = sum;
			for (int ii = 0; ii < 6; ii++) if (b1.test(ii)) tmp -= r[ii+1];
			for (int ii = 0; ii < 6; ii++) if (b2.test(ii)) tmp -= c[ii+1];
			for (int ii = 0; ii < 6; ii++) {
				for (int jj = 0; jj < 6; jj++) {
					if (b1.test(ii) && b2.test(jj) && a[ii+1][jj+1] == '#') tmp++;
				}
			}
			if (tmp == k)
				ans++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3824
#include <stdio.h>

int main(void){
    int S, h, m, s;

    scanf("%d", &S);

    h = S / 3600;
    m = (S - h * 3600) / 60;
    s = S - (h * 3600) - (m * 60);

    printf("%d:%d:%d\n", h, m, s);

    return 0;
}

Measured memory_bytes: 1848
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
using pii = pair<int, int>;
const int MOD = 1000000007;

int main()
{
    // read
    int N;
    cin >> N;
    vector<pii> values;
    rep(i, 0, 2*N)
    {
        int v;
        cin >> v;
        int ab = (i<N)?1:-1;
        values.emplace_back(v, ab);
    }

    // sort
    sort(values.begin(), values.end());

    // calc
    ll res = 1;
    stack<int> stk;
    for (auto v_ab: values)
    {

        if (stk.size()>0 and stk.top()+v_ab.second==0)
        {
            res *= stk.size();
            res %= MOD;
            stk.pop();
        }
        else
            stk.push(v_ab.second);
    }
    cout << res << endl;
    return 0;
}


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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int s;

void read() {
  cin >> s;
}
bitset <1000002> bs;
void solve() {
  bs[s] = 1;
  int cnt = 1;
  while(true) {
    s = (1 - s % 2) * s / 2 + (s % 2) * (3 * s + 1);
    ++cnt;
    if (bs[s]) {
      cout << cnt;
      return;
    } else bs[s] = 1;
  }
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
//  cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    int ans=0;
    for(int i=0;i<a.size();i++){
        if(a[i]=='C'){
            ans=1;
        }
        if(a[i]=='F'&&ans==1){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}

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


char sentence[100];

int main(void) {
scanf("%s", sentence);
sentence[0] = '2';
sentence[1] = '0';
sentence[2] = '1';
sentence[3] = '8';
printf("%s\n", sentence);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
// ceil (a + (b - 1)) / b

using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    int A,B,C,D; cin >> A >> B >> C >> D;
    int res = 0;
    for(int i=0; i<=D; i+=A){
        for(int j=0; j<=D; j+=B){
            if(D-i-j>=0 && (D-i-j)%C==0) res++;
        }
    }
    pr(res);

}


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

const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());

  combination c(n + 5);

  mint ans = 0;
  rep(i, n) {
    mint now = c(i, k - 1);
    ans += (mint)a[i] * now;
  }
  reverse(a.begin(), a.end());
  rep(i, n) {
    mint now = -c(i, k - 1);
    ans += (mint)a[i] * now;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i;
	ll x, k, d, ans;
	cin >> x >> k >> d;
	x = abs(x);
	if (x / d >= k)
		ans = x - k * d;
	else {
		k -= x / d;
		ans = x % d;
		if (k & 1)
			ans = abs(d - ans);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3644
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    a,b = map(int,input().split())
    ans = a + b
    if ans>=10:
        print("error")
    else:
        print(ans)
    return

if __name__=='__main__':
    main()


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

int main(){ 
  int N, K;
  vector<int64_t> A(20), highest(20, 0);

  cin >> N >> K;
  for(int i=1; i<=N; i++){
    cin >> A[i];
    highest[i] = max(highest[i-1], A[i]);
  }

  int64_t ans = 1e15;
  for(int bits=0; bits<(1<<N); bits++){
    if(bitset<20>(bits).count() != K) continue;

    vector<int64_t> B = highest; int64_t cur = 0;
    for(int i=1; i<=N; i++){
      if(bits >> (i-1) & 1){
        if(A[i] <= B[i-1]){
          cur += B[i-1]-A[i]+1;
          B[i] = B[i-1]+1;
        }
      } else {
        B[i] = max(B[i-1], A[i]);
      } 
    }
    ans = min(ans, cur);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

const int N = 100000 + 7;

int n, k;
struct permutation {
	int p[N];
} a[7], g;

void init(permutation& a) {
	for (int i = 1; i <= n; ++i) a.p[i] = i;
}
permutation mul(const permutation& a, const permutation& b) {
	permutation c;
	for (int i = 1; i <= n; ++i) c.p[i] = a.p[b.p[i]];
	return c;
}
permutation mul(const permutation a, const permutation b, const permutation c) {
	return mul(mul(a, b), c);
}
permutation inv(const permutation& a) {
	permutation c;
	for (int i = 1; i <= n; ++i) c.p[a.p[i]] = i;
	return c;
}
permutation pow(permutation a, int k) {
	permutation c;
	init(c);
	for (; k; a = mul(a, a), k >>= 1) if (k & 1) c = mul(c, a);
	return c;
}

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i)
		scanf("%d ", &a[1].p[i]);
	for (int i = 1; i <= n; ++i)
		scanf("%d ", &a[2].p[i]);
	a[3] = mul(a[2], inv(a[1]));
	a[4] = mul(a[3], inv(a[2]));
	g = mul(a[4], a[1]);

	if (k <= 4)
		g = a[k];
	else {
		int t = (k - 4 - 1) / 3 + 1;
		if (t & 1)
			g = mul(pow(g, t / 2 + 1), inv(a[k - 3 * t]), pow(inv(g), t / 2));
		else
			g = mul(pow(g, t / 2), a[k - 3 * t], pow(inv(g), t / 2));
	}
	for (int i = 1; i <= n; ++i) printf("%d ", g.p[i]);

	return 0;
}


Measured memory_bytes: 11392
N = int(input())
S = [ord(s) for s in input()]
# N = 5000
# S = "abcdefg" + "k"*4993

c = 0
for i in range(1, N):
    d = 0
    for s_j, t_j in zip(S, S[i:]):
        if s_j == t_j:
            d += 1
        else:
            c = max(c, min(d, i))
            d = 0
    c = max(c, min(d, i))

# print(S, t)
print(c)


Measured memory_bytes: 45212
#include <stdio.h>
#define N 4
#define MAX 15
typedef struct{
    int A[N][N];

}Pazzle;
Pazzle P;
int d_x[4]={0,1,0,-1};
int d_y[4]={1,0,-1,0};
void swap(int *,int *);
int check(Pazzle);
int dfs(int ,int ,int ,int,int );

int main(void){
    Pazzle t_P;
    int  i,j,ans;
    int x0,y0;

    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            scanf("%d",&P.A[i][j]);
            if(P.A[i][j]==0){
                x0=j;
                y0=i;
                
            }
            
        }
    }
    t_P=P;
    for(i=1;i<46;i++){
        P=t_P;
    ans=dfs(x0,y0,i,0,-1);
    if(ans!=-1){printf("%d\n",ans); break;}
    }
    return 0;
}

int dfs(int x,int y,int max,int cnt,int m){
         int i;
  int heau;
  int x_0,y_0;
  int ans=-1;   
  heau=check(P);
  if(heau==0) return cnt;
  if(cnt+heau>max) return -1; 
  for(i=0;i<4;i++){
    x_0=x+d_x[i];
    y_0=y+d_y[i];      
   
    if((m!=-1&&i==(m+2)%4)||!(0<=x_0 && x_0<N && 0<=y_0 && y_0<N)) continue;    
    swap(&P.A[y][x],&P.A[y_0][x_0]);
    ans=dfs(x_0,y_0,max,cnt+1,i);
    if(ans!=-1) return ans;       
     swap(&P.A[y][x],&P.A[y_0][x_0]);
  }   
  return -1;
}

void swap(int *A,int *B){
 int hoge;
 hoge=*A;
 *A=*B;
 *B=hoge;
 
 
}
int check(Pazzle P){
    int sum=0,i,j,hy,hx;
    for(i=0;i<N;i++){
 
    for(j=0;j<N;j++){
        if(P.A[i][j]==0)
        continue;
        hy=(P.A[i][j]-1)/N-i;
        hx=(P.A[i][j]-1)%N-j;
        if(hy<0)
        sum-=hy;
        else
        sum+=hy;
        if(hx<0)
        sum-=hx;
        else
        sum+=hx;
 
 
}
}
 
return sum;
}


Measured memory_bytes: 2108