akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict

N = int(input())
S = [input() for _ in range(N)]

d = defaultdict(int)

for s in S:
    d[s] += 1
    
mx = max(d.values())
for k, v in sorted(d.items(), key=lambda x: x[0]):
    if v == mx:
        print(k)

Measured memory_bytes: 48404
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}
int main(){
  ll A,B;
  cin>>A>>B;
  string S;
  cin>>S;
  ll a=0;
  for (int i = 0; i < S.size(); i++){
  if (S[i] == '-') {a++;}
  }
  if(a==1&&S[A]=='-')
  cout<<"Yes"<<endl;
  else
  cout<<"No"<<endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int32_t main()
{
  long long n,m,sum=0;cin>>n>>m;
  vector<long long>a(m);
  for(long long i=0;i<m;i++)cin>>a[i],sum+=a[i];
  if(sum>n)cout<<-1;
  else cout<<(n-sum);
  return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
using namespace std;
ll binpow(ll x,ll y)/* (x^y)%p in O(log y) */{ll res=1;while (y > 0){if(y&1)res=(res*x);y = y>>1;x=(x*x);}return res;}
ll binpowmod(ll x,ll y,ll p)/* (x^y)%p in O(log y) */{ll res=1;x=x%p;while (y > 0){if(y&1)res=(res*x)%p;y = y>>1;x=(x*x)%p;}return res;}
ll mod_inverse(ll n,ll p)/* Returns n^(-1) mod p */{return binpowmod(n,p-2,p);}
ull gcd(ull x,ull y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}
bool comp(pair<ll,ll> x,pair<ll,ll> y)
{
    return x.first>y.first;
}
bool comp_pairs_by_s(pair<ll,ll> &x ,pair<ll,ll> &y)
{
    return x.second<y.second;
}
bool isPowerOfTwo (ll x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}

class cmp      //comparator for priority_queue 
{               //declaration: priority_queue<int,vector<int>,cmp>
public:         
    bool operator()(pair<int,int> A,pair<int,int> B)
    {
        if(abs(A.first-A.second)==abs(B.first-B.second))
            return A.first>B.first;
        return abs(A.first-A.second)<abs(B.first-B.second);
    }
};
// int prime[100005]={0};
// void sieve(void)
// {
//  int i,j;
//  for(i=0;i<100005;i++)
//         prime[i]=1;
//  prime[0]=0,prime[1]=0;
//  for(i=2;i<=sqrt(100005);i++){
//      if(prime[i]){
//          for(j=i*i;j<100005;j+=i){
//              prime[j]=0;
//          }
//      }
//  }
    
// }
void swap(int &x,int &y){
    int temp=x;
    x=y;
    y=temp;
}

void solve()
{   
   int k,a,b;
   cin>>k>>a>>b;
   if(a%k==0 || b%k==0)
        cout<<"OK";
   else if((a/k+1)*k<=b)
    cout<<"OK";
    else
        cout<<"NG";
    cout<<"\n";
    
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n;
	cin >> n;
	vector<int> a;
	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		a.pb(t);
	}

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

	ll sum = 0;
	for(int i=0; i<n-1; i++){
		sum += a[i+1] - a[i];
	}

	cout << sum << endl;
	
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod=10**9+7

n=I()

fac = [1] * (n + 1)
inv = [1] * (n + 1)
for j in range(1, n + 1):
    fac[j] = fac[j-1] * j % mod

inv[n] = pow(fac[n], mod-2, mod)
for j in range(n-1, -1, -1):
    inv[j] = inv[j+1] * (j+1) % mod


def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod



G=[[]for _ in range(n)]
for _ in range(n-1):
    a,b=LI()
    G[a-1]+=[b-1]
    G[b-1] += [a-1]

cnt=[-1]*n
par=[-1]*n
def f(x):
    ret=1
    for y in G[x]:
        if par[x]==y:
            continue
        par[y]=x
        ret+=f(y)
    cnt[x]=ret
    return ret

f(0)
D=[0]*n
def tree_dp(x):
    c = 1
    remain_v = cnt[x] - 1
    for y in G[x]:
        if y == par[x]:
            continue
        c = c * tree_dp(y) * comb(remain_v, cnt[y]) % mod
        remain_v -= cnt[y]
    D[x] = c
    if x: return c

tree_dp(0)
ans=[0]*n
ans[0]=D[0]



q=deque([0])
while q:
    e=q.popleft()
    for d in G[e]:
        if d==par[e]:
            continue
        ans[d]=pow(comb(n-1,cnt[d])*D[d],mod-2,mod)*ans[e]*comb(n-1,cnt[d]-1)*D[d]%mod
        q+=[d]

print(*ans,sep="\n")

Measured memory_bytes: 190036
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

void solve() {
  int n, k; cin >> n >> k;
  if (n == 0) exit(0);
  vector<int> s(n); REP (i, n) cin >> s[i];
  int ng = 1e18, ok = s[0] - 1;
  while (abs(ok - ng) > 1) {
    int m = (ok + ng) / 2;
    int L = 1, cnt = 0;
    while (1) {
      cnt++;
      if (s.back() < L + m) break;
      auto it1 = lower_bound(ALL(s), L);
      int tmp = abs(L - *it1);
      if (it1 != s.begin()) {
        chmin(tmp, abs(L - *(it1 - 1)));
      }
      L += max(1LL, m - tmp);
    }
    (cnt >= k ? ok : ng) = m;
  }
  cout << (ok == s[0] - 1 ? -1 : ok) << endl;
}
signed main() {
  while (1) solve();
}


Measured memory_bytes: 3888
import java.util.*;

public class Main
{
  static int h, w;
  static long mod = (long)1e9+7;
  static char[][] G;
  static Long[][] memo;
  public static void main(String[] args)
  {
    Scanner in = new Scanner(System.in);
    h = in.nextInt();
    w = in.nextInt();
    G = new char[h][w];
    for (int i = 0; i < h; i++)
      G[i] = in.next().toCharArray();
    memo = new Long[h][w];
    System.out.println(dp(0, 0));
    in.close();
  }
  
  public static long dp(int r, int c)
  {
    if (r == h-1 && c == w-1)
      return 1;
    if (memo[r][c] != null)
      return memo[r][c];
    long ans = 0;
    if (r+1 < h && G[r+1][c] != '#')
      ans += dp(r+1, c);
    ans %= mod;
    if (c+1 < w && G[r][c+1] != '#')
      ans += dp(r, c+1);
    ans %= mod;
    return memo[r][c] = ans;
 }
}

Measured memory_bytes: 70452
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String s1 = sc.next();
		String s2 = sc.next();
		String s3 = sc.next();
		System.out.print(s1.charAt(0));
		System.out.print(s2.charAt(1));
		System.out.print(s3.charAt(2));
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int n, k;
const int MOD = 1e9 + 7;
const int N = 1000000;
int ans[N], finans;
vector <int> V;
int powi(int a, int b)
{
    int c = 1;
    for (; b; b >>= 1, a = 1ll * a * a % MOD)
        if (b & 1) c = 1ll * c * a % MOD;
    return c;
}
int main()
{
    cin >> n >> k;
    for (int i = 1; i * i <= n; ++ i)
        if (n % i == 0)
        {
            V.push_back(i);
            if (i * i != n) V.push_back(n / i);
        }
    sort(V.begin(), V.end());
    for (int i = 0; i < V.size(); ++ i)
    {
        ans[i] = powi(k, (V[i] + 1) / 2);
        for (int j = 0; j < i; ++ j) if (V[i] % V[j] == 0)
            ans[i] = (ans[i] - ans[j] + MOD) % MOD;
        finans = (finans + 1ll * ans[i] * (V[i] & 1? V[i]: V[i] / 2)) % MOD;
    }
    cout << finans << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void){
int i,j,k,l,m,n,o;
scanf("%d %d",&i,&j);
do{
k=0;
for(l=1;l<=i-2;l++)
for(m=l+1;m<=i-1;m++)
for(n=m+1;n<=i;n++){
o=l+m+n;
if(o==j)k+=1;
}
printf("%d\n",k);
scanf("%d %d",&i,&j);
}
while(i!=0 && j!=0);
return 0;
}

Measured memory_bytes: 600
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

using namespace std;

ll mypow(ll a, int k)
{	
	ll res = 1;
	forn(i, k)
		res *= a;
	return res;
}

ll calc(ll l, ll r, ll x1, ll x2)
{
	return min(x1 - l + 1 + x2 - l + 1, r - x1 + 1 + r - x2 + 1);
}

ll solve()
{
	ll x1, y1, x2, y2;
	scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
	if (x1 > x2)
		swap(x1, x2);
	if (y1 > y2)
		swap(y1, y2);
	for (int i = 30; i >= 0; i--)
	{
		ll sz = mypow(3, i);	
		ll l1 = ((x1 - 1) / sz) * sz + 1;
		ll r1 = l1 + sz -1 ;
		ll l2 = ((y1 - 1) / sz) * sz + 1;
		ll r2 = l2 + sz - 1;
		if (((x1 - 1) / sz) % 3 == 1 && r1 >= x2)
		{
			if ((r2 < y2 && (r2 / sz) % 3 == 1) || (r2 + sz < y2 && (r2 / sz) % 3 == 0))
				return y2 - y1 + calc(l1, r1, x1, x2);
		}
		if (((y1 - 1) / sz) % 3 == 1 && r2 >= y2)
		{	
			if ((r1 < x2 && (r1 / sz) % 3 == 1) || (r1 + sz < x2 && (r1 / sz) % 3 == 0))
				return x2 - x1 + calc(l2, r2, y1, y2); 
		}
	}
	return x2 - x1 + y2 - y1;
}

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	int T;
	scanf("%d", &T);
	while(T--)
	{
		printf("%lld\n", solve());
	}

	return 0;
}



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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}


vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code
ll arr[N];

int main()
{
  int n;
  cin>>n;
  ll a, b;
  cin>>a>>b;
  rep(i, 0, n) cin>>arr[i];
  ll l = 0;
  ll r = 1e9;
  while(r-l >1)
  {
    ll mid = (l + r) / 2;
    ll cnt = 0;
    rep(i, 0, n)
    {
      cnt += (max<ll>(arr[i] - mid*b + a - b - 1, 0)) / (a - b);
    }
    if(cnt > mid) l =mid;
    else r = mid;
  }
  cout<<r<<endl;
  return 0;
}


Measured memory_bytes: 14848
#include<iostream>
#include<vector>
#include<algorithm>
#define LL long long 
using namespace std;
int n, m, d1, d2, dp[100005], vis[100005];
vector<int>v[100005];
int dfs(int x, int k){
//	cout << x << " " << k << "\n";
	int MMM=0;
	if (dp[x]!=0) return dp[x]+k;
	if (v[x].empty()) return k;
	for (auto i:v[x]){
//		cout << x << " " << i << "\n";
		dp[i]=dfs(i, k+1);
		MMM=max(dp[i], MMM);
		dp[i]-=(k+1);
	}
	return MMM;
}
int main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin >> n >> m;
	for (int i=0;i<m;i++){
		cin >> d1 >> d2, v[d2].push_back(d1);
	}
	int Max=0;
	for (int i=1;i<=n;i++){
		dp[i]=dfs(i, 0);
		Max=max(dp[i], Max);
	}
	cout << Max;
}

Measured memory_bytes: 10624
#include<iostream>
using namespace std;
typedef long long int Int;
int main(){
  Int n,k;cin >> n >> k;
  if(k&1){
    Int a = n/k;
    cout << a*a*a << endl;
  }else{
    Int a = n/k;
    Int b = (n+(k/2))/k;
    cout << a*a*a+b*b*b << endl;
  }
}


Measured memory_bytes: 256
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

a, b, c, d = map(int, input().split())
ac, bc, ad, bd = 0, 0, 0, 0
if a % c == 0 and a % c == 0:
  ac = a // c - 1
  ad = a // d
else:
  if a % c != 0:
    ac = a // c
  else:
    ac = a // c - 1
  if a % d != 0:
    ad = a // d
  else:
    ad = a // d - 1
bc = b // c
bd = b // d
a_cd_dup = a // (lcm(c, d))
b_cd_dup = b // (lcm(c, d))
divisible_count = (bc - ac) + (bd - ad) - (b_cd_dup - a_cd_dup)
ans = (b - a + 1) - divisible_count
print(ans)

Measured memory_bytes: 5076
main(){
	int c,y,t,o,p;
	char a[9];
	scanf("%d",&c);
	for(y=0;y<c;y++){
		for(t=o=p=0;;){
			scanf("%s",a);
			if(a[0]=='H')t++;
			else o++;
			if(a[1]=='O'){p+=t;t=0;}
			if(t>3){p++;t--;}
			if(o>2)break;
		}
		printf("%d\n",p);
	}return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

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

        int N = scanner.nextInt();

        if (N == 1){
            System.out.println("Hello World");
        } else if (N == 2){
            int A = scanner.nextInt();
            int B = scanner.nextInt();
            System.out.println(A + B);
        } else throw new IllegalArgumentException();
    }
}


Measured memory_bytes: 22996
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions 

#endif


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

    int N; cin >> N;
    vl A(N); REP(i,N) cin >> A[i];
    vl B(N); REP(i,N) cin >> B[i];

    vl x = B;

    priority_queue<pll> pq;
    REP(i, N) pq.push(pll(x[i], i));

    ll ans = 0;
    while(!pq.empty()) {
        int i = pq.top().second; pq.pop();

        if (x[i] < A[i]) break;
        if (x[i] == A[i]) continue;

        ll dx = (x[(i - 1 + N) % N] + x[(i + 1) % N]);
        if (dx == 0) break;

        ll cnt = (x[i] - A[i]) / dx;
        x[i] -= dx * cnt;

        if (cnt > 0) pq.push(pll(x[i], i));
        ans += cnt;
    }

    bool match = true;
    REP(i, N) if (x[i] != A[i]) match = false;

    if (ans > 0 && match) cout << ans << endl;
    else cout << -1 << endl;

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  n -= 1;
  int64_t l0, l1, l2;
  l0 = 2; l1 = 1, l2 = 1;
  for (int i = 0; i < n; i++) {
    l2 = l0 + l1;
    swap(l2, l1);
    swap(l2, l0);
  }
  cout << l1 << endl;
}

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

using namespace std;

int main(){
  string str;
  cin>>str;
  for(int i=0;i<str.length();i++){
         if(str[i]=='D'){
      str[i]='A';
    }
    else if(str[i]=='E'){
      str[i]='B';
    }
    else if(str[i]=='F'){
      str[i]='C';
    }
    else if(str[i]=='G'){
      str[i]='D';
    }
    else if(str[i]=='H'){
      str[i]='E';
    }
    else if(str[i]=='I'){
      str[i]='F';
    }
    else if(str[i]=='J'){
      str[i]='G';
    }
    else if(str[i]=='K'){
      str[i]='H';
    }
    else if(str[i]=='L'){
      str[i]='I';
    }
    else if(str[i]=='M'){
      str[i]='J';
    }
    else if(str[i]=='N'){
      str[i]='K';
    }
    else if(str[i]=='O'){
      str[i]='L';
    }
    else if(str[i]=='P'){
      str[i]='M';
    }
    else if(str[i]=='Q'){
      str[i]='N';
    }
    else if(str[i]=='R'){
      str[i]='O';
    }
    else if(str[i]=='S'){
      str[i]='P';
    }
    else if(str[i]=='T'){
      str[i]='Q';
    }
    else if(str[i]=='U'){
      str[i]='R';
    }
    else if(str[i]=='V'){
      str[i]='S';
    }
    else if(str[i]=='W'){
      str[i]='T';
    }
    else if(str[i]=='X'){
      str[i]='U';
    }
    else if(str[i]=='Y'){
      str[i]='V';
    }
    else if(str[i]=='Z'){
      str[i]='W';
    }
    else if(str[i]=='A'){
      str[i]='X';
    }
    else if(str[i]=='B'){
      str[i]='Y';
    }
    else if(str[i]=='C'){
      str[i]='Z';
    }
  }
  cout<<str<<endl;
}

Measured memory_bytes: 1180
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#include <list>
#include <cassert>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;

int main() {
	int N, C; cin >> N >> C;
	const int cst = 100003;
	vector<vector<int>> vec(C, vi(2 * cst+1));
	for (int i = 0; i < N; i++) {
		int s, t, c; cin >> s >> t >> c;
		--c;
		for (int ind = 2 * s-1 ; ind < 2 *t; ind++) {
			vec[c][ind] = 1;
		}
	}
	int M = 0;
	for (int pos = 0; pos < vec[0].size(); pos++) {
		int tmp = 0;
		for (int channel = 0; channel < C; channel++) {
			tmp += vec[channel][pos];
		}
		M = max(M, tmp);
	}
	cout << M << endl;
}

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

int main() {
  string S, T;
  cin >> S >> T;

  int ans = 0;
  rep(i, S.size()) {
    if (S[i] != T[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3856
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main() {
    int n;
    cin>>n;
    int a;
    a =n%10;
    if(a==3) cout <<"bon"<< endl;
    else if (a==0||a==1||a==6||a==8) cout <<"pon"<<endl;
    else cout <<"hon"<<endl;
}

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

int main(){
    int n,l;
    cin>>n>>l;
    int sum=(l-1)*n+n*(n+1)/2;

    int a=1e9,b=0;
    for(int i=1;i<=n;i++){
        if(a>abs(l+i-1)){
            a=abs(l+i-1);
            b=i;
        }
    }
    cout<<sum-(l+b-1)<<endl;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; ++i)
#define RANGE(i, x, n) for(ll i = x; i < n; ++i)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

void accelerate()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    accelerate();
    int n;
    cin >> n;
    vector<string> s(n);
    ll ans = 0;
    REP(i, n) {
        cin >> s[i];
        REP(j, s[i].size()-1) {
            if(s[i][j] == 'A' && s[i][j+1] == 'B') ++ans;
        }
    }

    int cnt_a = 0, cnt_b = 0;
    int flg = 0;
    REP(i, n) {
        if(s[i][0] == 'B' && s[i][s[i].size()-1] == 'A') {
            cnt_a++;
            cnt_b++;
        }else if(s[i][0] == 'B') {
            cnt_b++;
            flg = 1;
        }else if(s[i][s[i].size()-1] == 'A') {
            cnt_a++;
            flg = 1;
        }
    }
    if(flg) {
        ans += min(cnt_a, cnt_b);
    }else {
        ans += max(cnt_a-1, 0);
    }
    cout << ans << endl;
}


Measured memory_bytes: 768
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var c = o.a();
  var b = o.l();
  var ans = 0;
  for(var i = 0; i < n; i++){
    var a = o.l();
    var s = c;
    for(var j = 0; j < m; j++){
      s += a[j] * b[j];
    }
    if(s > 0)ans++;
  }
  return ans;
}

Measured memory_bytes: 21064
#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  int a[n+1], b[n]; long int ans = 0;
  for (size_t i = 0; i < n+1; i++) {
    scanf("%d", a+i);
  }
  for (size_t i = 0; i < n; i++) {
    scanf("%d", b+i);
  }
  for (size_t i = 0; i < n; i++) {
    if (a[i] <= b[i]) {
      ans += a[i];
      b[i] -= a[i];
      if (a[i+1] <= b[i]) {
        ans += a[i+1];
        a[i+1] = 0;
      }else {
        ans += b[i];
        a[i+1] -= b[i];
      }
    }else {
      ans += b[i];
    }
  }
  printf("%ld\n", ans);
  return 0;
}


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

int main(){
int i, j, h, w;

while(1) {
cin >> h >> w;
if ( h == 0 && w == 0) break;
for ( i = 0; i < h; i++ ){
	for ( j = 0; j < w; j++ ){
		if ( i == 0 || i == h - 1 || j == 0 || j == w - 1 )  
			cout << "#" ;
		else 
			cout << ".";
	}
	cout << endl;
}
cout << endl;
}
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
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; }

const long long INF = 1LL << 60;

int main() {
  long long h[100010];
  long long dp[100010];
  int N;
  cin >> N;
  for(int i=0;i<N;++i) {
    cin >> h[i];
  }
  for(int i=1;i<N;++i) {
    dp[i]=INF;
  }
  dp[0]=0;
  for(int i=0;i<N;++i) {
    chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
  cout << dp[N-1] << endl;
}


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

int main() {
  int N;
  cin >> N;

  string type = "Three";

  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    
    if (S == "Y") {
      type = "Four";
      break;
    }
  }

  cout << type << endl;
}


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

int main() {
  int n, answer;
  cin >> n;
  if (n == 1) answer = 1;
  else {
    answer = 2;
    vector<int> v;
    for (int i = 2 ; i <= n; i += 2) {
      v.push_back(i);
    }
    for (int i = 0; i < v.size(); i++) {
      if (v[i] % 4 == 0) {
        answer = v[i];
        break;
      }
    }
    for (int i = 0; i < v.size(); i++) {
      if (v[i] % 8 == 0) {
        answer = v[i];
        break;
      }
    }
    for (int i = 0; i < v.size(); i++) {
      if (v[i] % 16 == 0) {
        answer = v[i];
        break;
      }
    }
    for (int i = 0; i < v.size(); i++) {
      if (v[i] % 32 == 0) {
        answer = v[i];
        break;
      }
    }
    for (int i = 0; i < v.size(); i++) {
      if (v[i] % 64 == 0) {
        answer = v[i];
        break;
      }
    }
  }
  cout << answer;
}

Measured memory_bytes: 256
import numpy as np
import itertools
n,m,x=map(int,input().split())
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))
# a.sort()

result = []

for n in range(1,len(a)+1):
    for conb in itertools.combinations(a, n):
        result.append(np.array(conb)) #タプルをリスト型に変換

count = 0

ans = []

for i in range(len(result)):
    t = sum(result[i])
    # print(t)
    for k in range(1,len(t)):
        # print(t[k])
        if t[k] >= x:
            count += 1
        else:
            count = 0
            break
    if count == m:
        ans.append(t[0])
        count = 0
        
    
if len(ans) > 0:
    # print(ans)
    
    print(min(ans))
    
else:
    print(-1)


Measured memory_bytes: 30056
n = int(input())
words = [input() for _ in range(n)]
s = set(words)
if len(s) == len(words):
    flag = 0
    word = words[0]
    for w in words[1:]:
        if w[0] != word[-1]:
            flag = 1
        word = w
else:
    flag = 1
if flag == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <functional>

template <class Data, class Operator>
class SegmentTree {
    using DataMerger = std::function<Data(Data, Data)>;
    using Applier = std::function<Data(Operator, Data)>;

private:
    int length;
    std::vector<Data> dat;
    Data dat_id;        // データの単位元
    DataMerger dmerge;  // データをマージする関数
    Applier app;        // データに作用素を適用する関数

    Data query(int ql, int qr, int nidx, int nl, int nr) {
        if (nr <= ql || qr <= nl) return dat_id;
        if (ql <= nl && nr <= qr) return dat[nidx];
        Data vl = query(ql, qr, nidx * 2, nl, (nl + nr) / 2);
        Data vr = query(ql, qr, nidx * 2 + 1, (nl + nr) / 2, nr);
        return dmerge(vl, vr);
    }

public:
    explicit SegmentTree(int N, Data dat_id, DataMerger dmerge, Applier app)
        : length(1), dat_id(dat_id), dmerge(dmerge), app(app) {
        while (length < N) length <<= 1;
        dat.assign(length * 2, dat_id);
    }

    // half-open interval [ql, qr)
    Data query(int ql, int qr) { return query(ql, qr, 1, 0, length); }

    void update(int idx, Operator e) {
        int nidx = idx + length;
        dat[nidx] = app(e, dat[nidx]);
        while (nidx > 0) {
            nidx >>= 1;
            dat[nidx] = dmerge(dat[nidx * 2], dat[nidx * 2 + 1]);
        }
    }
};

constexpr int INF = 1 << 30;

int main() {
    int n, m;
    std::string s;
    std::cin >> n >> m >> s;

    std::vector<int> nxt(n + 1);

    SegmentTree<std::pair<int, int>, std::pair<int, int>>
        seg(
            n + 1, std::make_pair(INF, INF),
            [](auto a, auto b) { return std::min(a, b); },
            [](auto e, auto a) { return e; });
    seg.update(n, std::make_pair(0, n));

    for (int i = n - 1; i >= 0; --i) {
        if (s[i] == '1') continue;
        auto p = seg.query(i + 1, i + m + 1);
        nxt[i] = p.second;
        seg.update(i, std::make_pair(p.first + 1, i));
    }

    auto p = seg.query(0, 1);
    if (p.first > n) {
        std::cout << -1 << std::endl;
    } else {
        int i = 0;
        while (i < n) {
            std::cout << nxt[i] - i << ' ';
            i = nxt[i];
        }
        std::cout << std::endl;
    }
    return 0;
}


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

int main(){
  int M, D;
  int d1, d10, m, count=0;
  cin >> M >> D;
  for(int i=1; i<=M; i++){
    for(int j=1; j<=D; j++){
      d1 = j/10;
      d10 = j%10;
      if(d1>=2 && d10>=2 && d1*d10==i) count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
import sys


INF = sys.maxsize
H, W = map(int, input().split())
m = []

for i in range(H):
  m.append([x for x in input()])

dp = [[INF] * W for _ in range(H)]
dp[0][0] = 0 if m[0][0] == '.' else 1

for i in range(H):
  for j in range(W):    
    for di, dj in [(0, 1), (1, 0)]:
      ni = i + di
      nj = j + dj
      if ni < H and nj < W:
        dp[ni][nj] = min(
          dp[ni][nj],
          dp[i][j] + 1 if m[i][j] == '.' and m[ni][nj] == '#' else dp[i][j],
        )

print(dp[-1][-1])        

Measured memory_bytes: 41584
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

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

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	int n;
	cin>>n;
	VI cnt(n,0);
	rep(i,n-1){
		int a;
		cin>>a;
		a--;
		cnt[a]++;
	}
	rep(i,n){
		cout<<cnt[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 4060
N = int(input())
A = [int(a) for a in input().split()]

count = [0,0,0,0,0,0,0,0,0]

for a in A:
    if a<= 399:
        count[0] = 1
    elif a<= 799:
        count[1] = 1
    elif a<= 1199:
        count[2] = 1
    elif a<= 1599:
        count[3] = 1
    elif a<= 1999:
        count[4] = 1
    elif a<= 2399:
        count[5] = 1
    elif a<= 2799:
        count[6] = 1
    elif a<= 3199:
        count[7] = 1
    else:
        count[8] += 1

print(max(1,sum(count[:-1])),sum(count))


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)
const ll INF = 10010001010;
const int inf = 1000034000;
typedef vector<ll> vecl;
typedef vector<int> veci;
typedef tuple<string, int, int> TUP;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

uintmax_t combination(unsigned int n, unsigned int r)
{
    if (r * 2 > n)
        r = n - r;
    uintmax_t dividend = 1;
    uintmax_t divisor = 1;
    for (unsigned int i = 1; i <= r; ++i)
    {
        dividend *= (n - i + 1);
        divisor *= i;
    }
    return dividend / divisor;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(15);
    int N;
    cin >> N;
    vecl A(N);
    vecl B(N);
    map<ll, ll> M;
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        M[A[i]]++;
    }
    B = A;
    sort(all(B));
    for (auto iter = M.begin(); iter != M.end();iter++)
    {
        
        if(iter->second > 1)ans += combination(iter->second,2);
    }
    for (int i = 0; i < N;i++)
    {
        cout << ans - M[A[i]]+1 << endl;
    }
}


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

using namespace std;

int n;
string s[100005];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> s[i];
	
	int ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j+2 < s[i].size(); j++){
			if(s[i].substr(j, 3) == "AOR") ans++;
		}
	}
	
	int Ocnt = 0, _A = 0, _AO = 0, R_ = 0, OR_ = 0, R_A = 0, OR_A = 0, R_AO = 0, OR_AO = 0;
	for(int i = 1; i <= n; i++){
		int l = s[i].size();
		if(s[i] == "O") Ocnt++;
		if(s[i].substr(l-1, 1) == "A")_A++;
		if(l >= 2 && s[i].substr(l-2, 2) == "AO") _AO++;
		if(s[i].substr(0, 1) == "R") R_++;
		if(l >= 2 && s[i].substr(0, 2) == "OR") OR_++;
		if(l >= 2 && s[i].substr(0, 1) == "R" && s[i].substr(l-1, 1) == "A") R_A++;
		if(l >= 3 && s[i].substr(0, 2) == "OR" && s[i].substr(l-1, 1) == "A") OR_A++;
		if(l >= 3 && s[i].substr(0, 1) == "R" && s[i].substr(l-2, 2) == "AO") R_AO++;
		if(l >= 4 && s[i].substr(0, 2) == "OR" && s[i].substr(l-2, 2) == "AO") OR_AO++;
	}
	int gomi = _A+_AO+R_+OR_ - (R_A+OR_A+R_AO+OR_AO) + Ocnt;
	gomi = n - gomi;
	
	int mx = 0;
	for(int i = 0; i <= min(Ocnt, _A); i++){
		int tmp1 = min(_A-i, OR_);
		if(tmp1 && OR_A == _A && OR_A == OR_ && i == 0) tmp1--;
		
		int tmp2 = min(_AO+i, R_);
		if(tmp2 && R_AO == _AO && R_AO == R_ && i == 0) tmp2--;
		
		mx = max(mx, tmp1+tmp2);
		//cout << tmp1 << " " << tmp2 << endl;
	}
	if(mx && mx == n-(Ocnt+gomi)) mx--;
	ans += mx;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 9920
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<math.h>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>
// 追加１
#include <fstream>



using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 2019;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()



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

    if (s == "ABC")
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "ABC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
int main(void){
  int i,n,r,p,c;
  int a[50],tmp[50];
 
  while(1){
    scanf("%d%d",&n,&r);
    if(n==0 && r==0) break;
    for(i=0;i<n;i++){
      a[i] = n-i;
    }
 
    while(r--){
      scanf("%d%d",&p,&c);
      for(i=0;i<p-1;i++){
        tmp[i+c] = a[i];
      }
      for(;i<p+c-1;i++){
        tmp[i-p+1] = a[i];
      }
      for(;i<n;i++){
        tmp[i] = a[i];
      }
      for(i=0;i<n;i++){
        a[i] = tmp[i];
      }
    }
    printf("%d\n",a[0]);
  }
 
  return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long lint;

int main()
{
	int L, a, b, c, d;
	
	scanf("%d %d %d %d %d", &L, &a, &b, &c, &d);
	
	printf("%d\n", L - max((a + c - 1) / c, (b + d - 1) / d));
	
	return (0);
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))

int main(){
    FAST
    int n; cin >> n;
    map<string, int> cnt;
    while(n -- ){
        string s; cin >> s;
        cnt[s]++;
    }
    string arr[4] = {"AC", "WA", "TLE", "RE"};
    for(int i = 0; i < 4; i++){
        cout << arr[i] << " x " << cnt[arr[i]] << endl;
    }
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){int b=0;for(auto itr :a){if(b++!=0)cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
#define int ll
signed main(){
    map<int,int>mp;
    int n; cin >> n;
    for(int i = 0; i<=n;i++){
        int b = n-i;
        string s = to_string(b);
        string u = to_string(i);
        int _s = 0,_u = 0;
        if(mp[b] == 0){
            rep(i,s.size())_s+=s[i]-'0';
            mp[b] = _s;
        }
        if(mp[i] == 0){
            rep(k,u.size())_u+=u[k]-'0';
            mp[i] = _u;
        }
    }
    int ans = INF;
    for(int i = 1; i<=n-1;i++)cmin(ans,mp[i]+mp[n-i]);
    cout << ans << endl;
}



Measured memory_bytes: 6528
n = int(input())
for i in range(1,3501):
    for j in range(i, 3501):
        top = n*i*j
        bot = 4*i*j - n*(i+j)
        if bot > 0 and top%bot == 0:
            w = top//bot
            if w > 0:
                print(i, j, w)
                exit()

Measured memory_bytes: 3060
#include <cstdio>
#include <vector>

using namespace std;

int len;
char s[222222];
char qs[22];
typedef unsigned long long Hash;
const Hash B = 1000000007;
Hash ha[26][222222];
Hash pow[222222];

struct Lazy {
  int v;
  int len;
  Lazy(int v, int len) : v(v), len(len) {
  }
};

struct segtree {
  int n;
  vector<Hash> d;
  vector<Lazy> lazy;
  void init(int l, int r, int k) {
    if (r-l == 1) {
      // printf("%d %d %d\n", l, r, k);
      d[k] = l < len ? s[l] : 0;
    } else {
      init(l, (l+r)/2, k*2+1);
      init((l+r)/2, r, k*2+2);
      d[k] = d[k*2+1]*pow[(r-l)/2] + d[k*2+2];
    }
  }

  void init(int n_) {
    n = 1;
    while (n < n_) n *= 2;
    d.resize(n*2 - 1);
    lazy.resize(n*2 - 1, Lazy(0, -1));
    init(0, n, 0);
  }

  void push(int k) {
    if (lazy[k].len >= 0) {
      d[k] = ha[lazy[k].v][lazy[k].len];
      if (lazy[k].len > 1) {
        lazy[k*2+1] = Lazy(lazy[k].v, lazy[k].len/2);
        lazy[k*2+2] = Lazy(lazy[k].v, lazy[k].len/2);
      }
      lazy[k].len = -1;
    }
  }
  
  void update(int i, int j, int l, int r, int k, int v) {
    push(k);
    if (j <= l || r <= i) {
      return;
    }
    if (l <= i && j <= r) {
      lazy[k] = Lazy(v, j-i);
      push(k);
      return;
    }
    update(i, (i+j)/2, l, r, k*2+1, v);
    update((i+j)/2, j, l, r, k*2+2, v);
    d[k] = d[k*2+1]*pow[(j-i)/2] + d[k*2+2];
  }

  void update(int l, int r, int v) {
    update(0, n, l, r, 0, v-'a');
  }

  pair<Hash, int> h(int i, int j, int l, int r, int k) {
    push(k);
    if (j <= l || r <= i) {
      return {0, 0};
    }
    if (l <= i && j <= r) {
      return {d[k], j-i};
    }
    auto lh = h(i, (i+j)/2, l, r, k*2+1);
    auto rh = h((i+j)/2, j, l, r, k*2+2);
    return {lh.first*pow[rh.second]+rh.first, lh.second+rh.second};
  }
  
  Hash h(int l, int r) {
    return h(0, n, l, r, 0).first;
  }
};

segtree t;

int main(void) {
  scanf("%d%s", &len, s);
  pow[0] = 1;
  for (int i = 0; i <= len; i++) {
    pow[i+1] = pow[i]*B;
  }
  for (int i = 0; i < 26; i++) {
    ha[i][0] = 0;
    for (int j = 1; j <= len; j++) {
      ha[i][j] = (i+'a') + ha[i][j-1] * B;
    }
  }
  t.init(len);

  int q; scanf("%d", &q);

  for (int ii = 0; ii < q; ii++) {
    scanf("%s", qs);
    if (*qs == 's') {
      int x, y; char z;
      scanf("%d%d %c", &x, &y, &z); --x;
      t.update(x, y, z);
    } else {
      int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); --a; --c;
      int lb, mb, rb;
      lb = 0;
      rb = min(d-c, b-a)+1;
      while (rb-lb > 1) {
        mb = (lb+rb)/2;
        if (t.h(a, a+mb) == t.h(c, c+mb)) {
          lb = mb;
        } else {
          rb = mb;
        }
      }
      
      if (lb == d-c && lb == b-a) {
        puts("e");
      } else if (b-a == lb || (d-c != lb && t.h(a+lb, a+lb+1) < t.h(c+lb, c+lb+1))) {
        puts("s");
      } else {
        puts("t");
      }
    }
    /*
    for (int i = 0; i < len; i++) {
      printf("%c", char(t.h(i, i+1)));
    }
    puts("");
    */
  }
  return 0;
}

Measured memory_bytes: 52996
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

constexpr int MAXN = 2e5 + 42;

int val[MAXN], succ[MAXN], last[MAXN], pos[MAXN], in[MAXN];

int main() {
  int N;
  ll K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> val[i];
    last[val[i]] = i;
  }
  for (int i = 0; i < N; i++) {
    succ[last[val[i]]] = i;
    last[val[i]] = i;
  }

  int x = 0, t = 0;
  do {
    if (succ[x] <= x) {
      pos[t++] = x;
    }
    x = (succ[x] + 1) % N;
  } while (x != 0);

  K = (K - 1) % (t + 1);

  vector<int> stk;
  for (int i = pos[K]; i < N; i++) {
    if (in[val[i]]) {
      while(stk.back() != val[i]) {
        in[stk.back()] = 0;
        stk.pop_back();
      }
      stk.pop_back();
    } else {
      stk.push_back(val[i]);
    }
    in[val[i]] ^= 1;
  }

  for (int i : stk) {
    cout << i << ' ';
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 6260
#include <bits/stdc++.h>
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


bool betemp(string sleft, string sright, int left, int right) {
    if (sleft == sright) return (right - left) % 2 == 1;
    else return (right - left) % 2 == 0;
}

void solve(int N) {
    string vac = "Vacant";
    string sleft, sright, str;
    int left = 0, right = N/2;
    cout << left << endl;
    cin >> sleft;
    if (sleft == vac) return;
    cout << right << endl;
    cin >> sright;
    if (sright == vac) return;

    if (!betemp(sleft, sright, left, right)) {
        swap(sleft, sright), left = right, right = N;
    }
    while (right - left > 1) {
        int mid = (left + right) / 2;
        cout << mid << endl;
        cin >> str;
        if (str == vac) return;


        //COUT(left); COUT(right); COUT(mid); COUT(sleft); COUT(sright); COUT(str);
        
        if (betemp(sleft, str, left, mid)) sright = str, right = mid;
        else sleft = str, left = mid;
    }
}

int main() {
    int N;
    while (cin >> N) solve(N);
}


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

bool solve() {
    ll N;
    cin >> N;
    int c = 0, p;
    for ( int i = 1; i <= N; i++ ) {
        cin >> p;
        if ( p != i ) c++;
    }
    return c == 2 || c == 0;
}

int main() {
    string ans = solve() ? "YES" : "NO";
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>


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

typedef long long ll;

using namespace std;

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

   ll sum = 0;

   for(int i = 1; i <= n; i++) {
      if(i%3 == 0 && i%5 == 0)  {
         cout << "";
      } else if (i%3 == 0) {
         cout << "";
      } else if (i%5 == 0){
         cout << "";
      } else {
         sum += i;
      }
   }

   cout << sum << endl;
}



Measured memory_bytes: 3636